[wolfman@localhost wolfman]$ cat darkelf.c
/*
The Lord of the BOF : The Fellowship of the BOF
- darkelf
- egghunter + buffer hunter + check length of argv[1]
*/
#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);
}
// 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 길이체크 48이상이면 프로그램이 종료된다.
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[1]의 길이를 체크하기 때문에 argv[2]를 이용하기로 한다.
[wolfman@localhost wolfman]$ gdb darkel1
(gdb) set disassembly-flavor intel
(gdb) disas main
Dump of assembler code for function main:
생 략
0x80485ae <main+174>: mov %esi,%esi
0x80485b0 <main+176>: mov %eax,DWORD PTR [%ebp+12]
0x80485b3 <main+179>: add %eax,4
0x80485b6 <main+182>: mov %edx,DWORD PTR [%eax]
0x80485b8 <main+184>: push %edx
0x80485b9 <main+185>: call 0x80483f0 <strlen>
0x80485be <main+190>: add %esp,4
0x80485c1 <main+193>: mov %eax,%eax
0x80485c3 <main+195>: cmp %eax,48
0x80485c6 <main+198>: jbe 0x80485e0 <main+224>
0x80485c8 <main+200>: push 0x8048699
0x80485cd <main+205>: call 0x8048410 <printf>
0x80485d2 <main+210>: add %esp,4
0x80485d5 <main+213>: push 0
0x80485d7 <main+215>: call 0x8048420 <exit>
0x80485dc <main+220>: add %esp,4
0x80485df <main+223>: nop
0x80485e0 <main+224>: mov %eax,DWORD PTR [%ebp+12]
0x80485e3 <main+227>: add %eax,4
---Type <return> to continue, or q <return> to quit---
0x80485e6 <main+230>: mov %edx,DWORD PTR [%eax]
0x80485e8 <main+232>: push %edx
0x80485e9 <main+233>: lea %eax,[%ebp-40]
0x80485ec <main+236>: push %eax
0x80485ed <main+237>: call 0x8048440 <strcpy>
0x80485f2 <main+242>: add %esp,8 //bp
0x80485f5 <main+245>: lea %eax,[%ebp-40]
0x80485f8 <main+248>: push %eax
0x80485f9 <main+249>: push 0x80486b0
생 략
<<낮은주소--- 버퍼(40) | sfp(4) | ret(4) | argv[2](nop*200+쉘코드) ---높은주소>>
argv[1] ret을 덮을 부분에 nop주소중 한 부분을 넣어주면 쉘코드가 실행 될것이다.
'System Hacking > Lord of Buffer overflow' 카테고리의 다른 글
08.lob orge->troll (0) | 2018.01.08 |
---|---|
07.lob darkelf->orge (0) | 2018.01.08 |
05.lob orc->wolfman (0) | 2018.01.07 |
04.lob goblin->orc (0) | 2018.01.06 |
03.lob cobolt->goblin (0) | 2018.01.05 |