6.1.22 pwn HITCONCTF2016 Sleepy_Holder
้ข็ฎๅค็ฐ
$ file SleepyHolder
SleepyHolder: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.24, BuildID[sha1]=46f0e70abd9460828444d7f0975a8b2f2ddbad46, stripped
$ checksec -f SleepyHolder
RELRO STACK CANARY NX PIE RPATH RUNPATH FORTIFY Fortified Fortifiable FILE
Partial RELRO Canary found NX enabled No PIE No RPATH No RUNPATH Yes 0 2 SleepyHolder
$ strings libc-2.23.so | grep "GNU C"
GNU C Library (Ubuntu GLIBC 2.23-0ubuntu3) stable release version 2.23, by Roland McGrath et al.
Compiled by GNU CC version 5.3.1 20160413.64 ไฝ็จๅบ๏ผๅผๅฏไบ Canary ๅ NX๏ผ้ป่ฎคๅผๅฏ ASLRใ
ๅจ Ubuntu-16.04 ไธ็ฉไธไธ๏ผ
$ ./SleepyHolder
Waking Sleepy Holder up ...
Hey! Do you have any secret?
I can help you to hold your secrets, and no one will be able to see it :)
1. Keep secret
2. Wipe secret
3. Renew secret
1
What secret do you want to keep?
1. Small secret
2. Big secret
3. Keep a huge secret and lock it forever
1
Tell me your secret:
AAAA
1. Keep secret
2. Wipe secret
3. Renew secret
1
What secret do you want to keep?
1. Small secret
2. Big secret
3. Keep a huge secret and lock it forever
3
Tell me your secret:
CCCC
1. Keep secret
2. Wipe secret
3. Renew secret
3
Which Secret do you want to renew?
1. Small secret
2. Big secret
1
Tell me your secret:
BBBB
1. Keep secret
2. Wipe secret
3. Renew secret
2
Which Secret do you want to wipe?
1. Small secret
2. Big secret
1่ฟไธ้ข็่ตทๆฅๅไธไธ้ข Secret_Holder ๅทฎไธๅคใๅๆ ทๆฏ smallใbigใhuge ไธ็ง secret๏ผไธๅ็ๆฏ่ฟ้็ huge secret ๆฏไธๅฏไฟฎๆนๅๅ ้ค็ใ
้ข็ฎ่งฃๆ
ไธ้ขๆไปฌ้ไธชๆฅ้ๅ่ฟไบๅ่ฝใ
Keep secret
่ฟๆฏไธๆ ท็๏ผ่ฏฅๅฝๆฐไฝฟ็จ calloc() ไธบไธ็ง secret ๅๅซไบไธๅๅคงๅฐ็ chunk๏ผsmall secret ๅฑไบ small chunk๏ผbig secret ๅ huge secret ๅฑไบ large chunkใๅจๅ้
ๅ๏ผไผๆฃๆฅๅฏนๅบ็ secret ๆฏๅฆๅทฒ็ปๅญๅจ๏ผๅณๆฏ็ง chunk ๅช่ฝๆไธไธชใๅฆๅค็ๅฝๆฐๅผๅคด้จๅ๏ผhuge secret ๆพ็ถๅๅฐไบ็นๆฎๅค็ใ
small secret: small chunk, 40 bytes
small_ptr: 0x006020d0
small_flag: 0x006020e0
big secret: large chunk, 4000 bytes
big_ptr: 0x006020c0
big_flag: 0x006020d8
huge secret: large chunk, 400000 bytes
huge_ptr: 0x006020c8
huge_flag: 0x006020dc
Wipe secret
่ฏฅๅฝๆฐๅช่ฝ้ๆพ small secret ๅ big secretใ้ๆพ็่ฟ็จ้ฆๅ ๅฐๅฏนๅบ็ chunk ้ๆพๆ๏ผ็ถๅ่ฎพ็ฝฎๅฏนๅบ flag ไธบ 0ใๆผๆดๅพๆๆพ๏ผๅฐฑๆฏๆฒกๆๅฐ chunk ๆ้ๆธ ็ฉบ๏ผๅญๅจๆฌๆ้๏ผๅฏ่ฝๅฏผ่ด use-after-free๏ผ็ถๅๅจ้ๆพๅ๏ผไนๆฒกๆๆฃๆฅ flag๏ผๅฏ่ฝๅฏผ่ด double-freeใ
Renew secret
่ฏฅๅฝๆฐๅช่ฝๅฏน small secret ๅ big secret ่ฟ่กไฟฎๆน๏ผๆไปฅ huge secret ๅฐฑๆฏไธๆฌกๅ้ ๏ผๆฐธ่ฟๅญๅจไธๅ ๅฎนไธๅฏไฟฎๆนไบใ่ฟ็จๆฏ้ฆๅ ๅคๆญๅฏนๅบ็ flag ๆฏๅฆไธบ 1๏ผๅณ secret ๆฏๅฆๅทฒ็ปๅญๅจ๏ผๅฆๆไธๅญๅจ๏ผๅ่ฏปๅ ฅ secret๏ผๅฆๅๅฝๆฐ็ดๆฅ่ฟๅใ
ๆผๆดๅฉ็จ
ๆป็ปไธไธๆไปฌ็ฅ้็ไธ่ฅฟ๏ผ
small secret: small chunk, 40 bytes
small_ptr: 0x006020d0
small_flag: 0x006020e0
big secret: large chunk, 4000 bytes
big_ptr: 0x006020c0
big_flag: 0x006020d8
huge secret: large chunk, 400000 bytes
huge_ptr: 0x006020c8
huge_flag: 0x006020dc
ๆผๆด๏ผ
double-free๏ผๅจ free chunk ็ไฝ็ฝฎ calloc ๅฆไธไธช chunk๏ผๅณๅฏๅๆฌก free ่ฟไธช chunk
use-after-free๏ผ็ฑไบ double-free๏ผcalloc ๅบๆฅ็้ฃไธช chunk ่ขซ่ฎคไธบๆฏ free ็๏ผไฝๅฏไปฅไฝฟ็จ
็ๅฐ่ฟ้่ฏฅ้ขไธไธไธ้ข็ๅทฎๅซๅพๆๆพไบ๏ผๅฐฑๆฏๆไปฌๆฒกๆๅๆณๅ้่ฟ keep(huge) -> wipe(huge) -> keep(huge) ๆฅๅฉ็จ brk() ๅ้
ๅ
ๅญ๏ผๅถ้ unsafe unlinkใ
็ถๅๆไปฌๅๅจ _int_malloc() ไธญๅ็ฐไบๅฆไธไธชไธ่ฅฟ๏ผ
ๅฝ้ๆฑ chunk ๆฏไธไธช large chunk ๆถ๏ผglibc ไผๅฐๆ fastbins ไธญ็ chunk ็งป้ค๏ผ่ฎพ็ฝฎ PREV_INUSE ไธบ 0๏ผๅๅนถ free chunk๏ผ็ถๅๆพๅฐ unsorted binใๆฅ็ glibc ๅฐ่ฏไป unsorted bin ไธญๅๅบ chunk๏ผ็ฑไบๅคงๅฐไธๅ้๏ผ่ฟไบ chunk ๅ่ขซๆพๅฐ small bin ไธญ๏ผ
่ฟๆถๅฐฑๅฏไปฅๅๆฌก้ๆพ small secret ่ไธ่งฆๅ double-free ็ๆฃๆตใ
้ฃไนไธบไปไนไธๅฎ่ฆๅฐ small secret ๆพ่ฟ small bin ๅข๏ผๅ ไธบๅฝ chunk ่ขซๆพ่ฟ small bin ๆถ๏ผไผ็ธๅบ็ไฟฎๆน next chunk๏ผๅณbig secret๏ผ็ chunk header๏ผ่ฎพ็ฝฎprev_size๏ผPREV_INUSE็ฝฎ0๏ผ๏ผ่ๅฝ chunk ่ขซๆพ่ฟ fastbins ๆถๆฏไธไผๆ่ฟๆ ท็ๆไฝ็ใๆฅไธๆฅๆไปฌ้่ฆ้่ฟ double-free ๅฐ small secret ๅๆฌกๆพ่ฟ fastbins๏ผ่ฟๆถsmall secretๅๆถๅญๅจไบfastbinsๅsmall binไธญ๏ผ๏ผๅไป fastbins ไธญๅๅบ small secret๏ผๅๅ ๅไธ้ข็ฑปไผผ๏ผไป fastbins ไธญๅๅบ chunk ไธไผ่ฎพ็ฝฎ next chunk ็ chunk headerใ่ฟๆ ทๆไปฌๆ่ฝๆญฃ็กฎๅฐ่งฆๅ unlinkใ
unsafe unlink
ๅถ้ double-free๏ผ
ไธ้ข็่ฟ็จไธๆน้ข้่ฟ malloc_consolidate ่ฎพ็ฝฎไบ big secret ็ PREV_INUSE๏ผๅฆไธๆน้ข้่ฟ double-free ๅฐ small secret ๆพ่ฟ fastbinsใ
ๅจ small secret ไธญๅธ็ฝฎไธไธไธช fake chunk๏ผ
้ๆพ big secret ๅณๅฏ่งฆๅ unsafe unlink๏ผ
ไบๆฏๆไปฌๅฐฑ่ทๅพไบไฟฎๆน .bss ๆฎต็่ฝๅใ
ๅ้ข็่ฟ็จๅฐฑๅไธไธ้ขๅฎๅ จไธๆ ทไบใ
leak libc
pwn
ๅผๅฏ ASLR๏ผBingo!!!
exploit
ๅฎๆด็ exp ๅฆไธ๏ผ
ๅ่่ตๆ
Last updated