THCbindinfo.c 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. /*
  2. * THC/2004
  3. *
  4. * This is just a quick and dirty hack to grab the Version of ISC bind 8+9
  5. * nameservers. It detects the difference between bind 8+9 even if the version
  6. * has been disguised.
  7. * The code is 2 years old and i never shared it before, but as we
  8. * opened a tool section now, i think it's worth to share it to the public.
  9. *
  10. * COMPILE (with Microsoft C++):
  11. * cl THCbindinfo.c
  12. *
  13. * RUN:
  14. * C:\ccode\THCbindinfo>THCbindinfo.exe 10.65.57.153
  15. *
  16. * ----------------------------------------
  17. * DNS Version Query for BIND 8+9 Servers
  18. * coding jcyberpunk@thc.org
  19. * ----------------------------------------
  20. *
  21. * Query for : 10.65.57.153 in progress...pleaze wait!
  22. *
  23. * ahh...that must be a bind 8...trying to get more details...
  24. *
  25. * DNS Version : BIND 8.3.4
  26. *
  27. * Enjoy,
  28. *
  29. * http://www.thc.org
  30. */
  31. #include <stdlib.h>
  32. #include <stdio.h>
  33. #include <string.h>
  34. #include <winsock2.h>
  35. #define TIMEOUT 5
  36. #define errno WSAGetLastError()
  37. #define STATUS_FAILED 0xFFFF
  38. #pragma comment(lib, "ws2_32.lib")
  39. void usage();
  40. main(int argc,char **argv)
  41. {
  42. struct sockaddr_in myudp;
  43. struct hostent * hp;
  44. SOCKET udpsock;
  45. unsigned short port=53;
  46. unsigned int addr=0;
  47. fd_set r;
  48. struct timeval mytimeout;
  49. char data[30]= {0x00,0x06,0x01,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0x76,0x65,0x72,0x73,0x69,0x6f,0x6e,0x04,0x62,0x69,0x6e,0x64,0x00,0x00,0x10,0x00,0x03};
  50. unsigned char *dataout;
  51. unsigned int error, open;
  52. WSADATA wsaData;
  53. printf("\n----------------------------------------\n");
  54. printf("DNS Version Query for BIND 8+9 Servers\n");
  55. printf(" coding jcyberpunk@thc.org\n");
  56. printf("----------------------------------------\n\n");
  57. if(argc != 2)
  58. {
  59. usage();
  60. exit(-1);
  61. }
  62. if (WSAStartup(MAKEWORD(2,1),&wsaData) != 0)
  63. {
  64. fprintf(stderr,"WSAStartup failed: %d\n",GetLastError());
  65. ExitProcess(STATUS_FAILED);
  66. }
  67. memset(&myudp,0,sizeof(myudp));
  68. hp = gethostbyname(argv[1]);
  69. if (!hp){
  70. addr = inet_addr(argv[1]);
  71. }
  72. if ((!hp) && (addr == INADDR_NONE) )
  73. {
  74. fprintf(stderr,"Unable to resolve %s\n",argv[1]);
  75. ExitProcess(STATUS_FAILED);
  76. }
  77. if (hp != NULL)
  78. memcpy(&(myudp.sin_addr),hp->h_addr,hp->h_length);
  79. else
  80. myudp.sin_addr.s_addr = addr;
  81. if (hp)
  82. myudp.sin_family = hp->h_addrtype;
  83. else
  84. myudp.sin_family = AF_INET;
  85. printf("Query for : %s in progress...pleaze wait!\n\n",inet_ntoa(myudp.sin_addr));
  86. dataout=(char*)malloc(100);
  87. memset(dataout,0,sizeof(*dataout));
  88. mytimeout.tv_sec = TIMEOUT;
  89. mytimeout.tv_usec = 0;
  90. myudp.sin_port = htons(port);
  91. if ((udpsock = socket (PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
  92. {
  93. printf("error binding socket!\n");
  94. exit(0);
  95. }
  96. if (connect (udpsock, (struct sockaddr *) &myudp, sizeof (
  97. struct sockaddr_in)) == 0)
  98. {
  99. FD_ZERO (&r);
  100. FD_SET (udpsock, &r);
  101. mytimeout.tv_sec = TIMEOUT;
  102. mytimeout.tv_usec = 0;
  103. send (udpsock, data, sizeof data, 0);
  104. error = select ((udpsock + 1), &r, NULL, NULL, &mytimeout);
  105. if (error==0)
  106. {
  107. printf("Port 53 udp is up, but i haven't received data within 5 seconds.\n");
  108. printf("it seems that this is not a bind 8 or 9 ! :(\n");
  109. exit(-1);
  110. }
  111. if (error==-1)
  112. {
  113. printf("select error : %d\n",errno);
  114. exit(-1);
  115. }
  116. open = recv(udpsock, dataout, 100, 0);
  117. if (open==-1)
  118. {
  119. printf("sorry, no nameserver running :(\n");
  120. exit(-1);
  121. }
  122. dataout[open]=0;
  123. if ((dataout[3]&127)==0)
  124. {
  125. if(dataout[30]==192)
  126. {
  127. printf ("ahh...that must be a bind 9...trying to get more details...\n\n");
  128. printf ("DNS Version : %s\n",dataout+43);
  129. }
  130. else
  131. {
  132. printf ("ahh...that must be a bind 8...trying to get more details...\n\n");
  133. printf("DNS Version : %s\n",dataout+55);
  134. }
  135. }
  136. else
  137. printf("DNS Version : unknown\n");
  138. shutdown(udpsock,1);
  139. closesocket(udpsock);
  140. }
  141. else
  142. printf("connect () error : %d\n",errno);
  143. free(dataout);
  144. exit(0);
  145. }
  146. void usage()
  147. {
  148. printf("Gimme <Hostname|IP-Address>\n");
  149. exit(-1);
  150. }