[Javanetsim-cvs] IceScan csubtarget.h, 1.48, 1.49 udpscan.h, 1.16, 1.17
Status: Beta
Brought to you by:
darkkey
From: QweR <qw...@us...> - 2006-12-19 00:01:30
|
Update of /cvsroot/javanetsim/IceScan In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv32201 Modified Files: csubtarget.h udpscan.h Log Message: Index: csubtarget.h =================================================================== RCS file: /cvsroot/javanetsim/IceScan/csubtarget.h,v retrieving revision 1.48 retrieving revision 1.49 diff -C2 -d -r1.48 -r1.49 *** csubtarget.h 18 Dec 2006 08:40:01 -0000 1.48 --- csubtarget.h 19 Dec 2006 00:01:26 -0000 1.49 *************** *** 517,521 **** if(response){ ip = (struct iphdr *) response; ! if(ip->saddr = saddress.sin_addr.s_addr && ip->protocol == IPPROTO_TCP){ tcp = (struct tcphdr *) (response + 4 * ip->ihl); --- 517,521 ---- if(response){ ip = (struct iphdr *) response; ! if(ip->saddr == saddress.sin_addr.s_addr && ip->protocol == IPPROTO_TCP){ tcp = (struct tcphdr *) (response + 4 * ip->ihl); Index: udpscan.h =================================================================== RCS file: /cvsroot/javanetsim/IceScan/udpscan.h,v retrieving revision 1.16 retrieving revision 1.17 diff -C2 -d -r1.16 -r1.17 *** udpscan.h 18 Dec 2006 08:40:01 -0000 1.16 --- udpscan.h 19 Dec 2006 00:01:26 -0000 1.17 *************** *** 16,20 **** ! int parse_icmp_udp_packet(char* recvmsg, int recvbytes, iceparams *par, iceoutput *out){ int port = 0; --- 16,20 ---- ! int parse_icmp_udp_packet(char* recvmsg, int recvbytes, struct sockaddr_in &saddress, iceparams *par, iceoutput *out){ int port = 0; *************** *** 24,43 **** int icmplen = recvbytes - hdrlen; ! if(icmppacket->icmp_type == ICMP_UNREACH && icmppacket->icmp_code == ICMP_UNREACH_PORT){ ! ! ip = (struct iphdr*) (&icmppacket->icmp_ip); ! hdrlen = ip->ihl << 2; ! if(ip->protocol == SOL_UDP && ((char*)ip+hdrlen+sizeof(udphdr))-recvmsg<=recvbytes){ ! struct udphdr* udp = (struct udphdr *) ((char*)ip + hdrlen); ! port = ntohs(udp->dest); ! if(par->verbose>2) *out << "Recieved icmp port " << port << " unreachable." << iceoutput::endl; ! return port; ! } ! else{ ! //DBGOUTPUT("incorrect length of packet"); } - } return 0; } --- 24,44 ---- int icmplen = recvbytes - hdrlen; ! if(ip->saddr == saddress.sin_addr.s_addr){ ! if(icmppacket->icmp_type == ICMP_UNREACH && icmppacket->icmp_code == ICMP_UNREACH_PORT){ ! ip = (struct iphdr*) (&icmppacket->icmp_ip); ! hdrlen = ip->ihl << 2; ! if(ip->protocol == SOL_UDP && ((char*)ip+hdrlen+sizeof(udphdr))-recvmsg<=recvbytes){ ! struct udphdr* udp = (struct udphdr *) ((char*)ip + hdrlen); ! port = ntohs(udp->dest); ! if(par->verbose>2) *out << "Recieved icmp port " << port << " unreachable." << iceoutput::endl; ! return port; ! } ! else{ ! //DBGOUTPUT("incorrect length of packet"); ! } ! } } return 0; } *************** *** 75,82 **** char hostname[80]; bool next = true; - int recvsize = UDP_SCAN_RECVSIZE; if(gethostname(hostname,79)) exit(-1); //int pppp = sudp.getMagicPort(SOCK_DGRAM, 100); --- 76,88 ---- char hostname[80]; bool next = true; int recvsize = UDP_SCAN_RECVSIZE; + struct timeval tv1,tv2; + struct sockaddr_in saddress; if(gethostname(hostname,79)) exit(-1); + if(make_sockname(saddress, destname.c_str(), 0, PF_INET)!=sizeof(saddress)){ + DBGOUTPUT("make_sockname!=sizeof"); + return false; + } //int pppp = sudp.getMagicPort(SOCK_DGRAM, 100); *************** *** 90,94 **** } char filter_exp[256]; ! sprintf(filter_exp, "host %s icmp", destname.c_str()); pcap_filter(p, filter_exp); //sicmp.nonblock(true); --- 96,100 ---- } char filter_exp[256]; ! sprintf(filter_exp, "icmp", destname.c_str()); pcap_filter(p, filter_exp); //sicmp.nonblock(true); *************** *** 99,145 **** for(repeats = 1; repeats <= UDP_SCAN_REPEATS && next; repeats++){ for(std::map <int, scanning_port>::iterator i = scanning_ports.begin(); i!= scanning_ports.end() && next; ++i){ ! if(! (*i).second.done ){ ! sudp.sendto(destname.c_str(), (*i).first, zmsg, UDP_SCAN_ZSIZE, 0); ! iceusleep(50000*repeats); ! } ! do{ ! recvbytes = sudp.recvfrom(recvmsg, UDP_SCAN_RECVSIZE, 0, NULL, NULL); ! if(recvbytes > 0){ ! struct udphdr* udp = (struct udphdr*) recvmsg; ! port = ntohs(udp->source); ! if(port!=0 && !scanning_ports[port].done && scanning_ports.find(port) != scanning_ports.end()){ ! if(isscan){ ! scanning_ports[port].done = true; ! subtarget->set_port_status(port, PORT_OPEN, "udp"); ! } ! else{ ! result = true; ! next = false; } } ! } ! else{ ! for(int k=0; k<5; k++){ ! response = readip_pcap(p, &len, NULL); ! if(response){ ! recvbytes = len; ! port = parse_icmp_udp_packet(response, len, par, out); ! if(port!=0 && !scanning_ports[port].done && !(scanning_ports.find(port) == scanning_ports.end())){ ! if(isscan){ ! scanning_ports[port].done = true; ! subtarget->set_port_status(port, PORT_CLOSED, "udp"); ! } ! else{ ! result = true; ! next = false; } } ! } ! iceusleep(10000*repeats); } ! } ! iceusleep(50000*repeats); ! }while(recvbytes > 0 && next); } } --- 105,153 ---- for(repeats = 1; repeats <= UDP_SCAN_REPEATS && next; repeats++){ for(std::map <int, scanning_port>::iterator i = scanning_ports.begin(); i!= scanning_ports.end() && next; ++i){ ! if(! (*i).second.done ){ ! sudp.sendto(destname.c_str(), (*i).first, zmsg, UDP_SCAN_ZSIZE, 0); ! iceusleep(50000*repeats); ! } ! do{ ! recvbytes = sudp.recvfrom(recvmsg, UDP_SCAN_RECVSIZE, 0, NULL, NULL); ! if(recvbytes > 0){ ! struct udphdr* udp = (struct udphdr*) recvmsg; ! port = ntohs(udp->source); ! if(port!=0 && !scanning_ports[port].done && scanning_ports.find(port) != scanning_ports.end()){ ! if(isscan){ ! scanning_ports[port].done = true; ! subtarget->set_port_status(port, PORT_OPEN, "udp"); ! } ! else{ ! result = true; ! next = false; ! } } } ! else{ ! gettimeofday(&tv1, 0); ! do{ ! response = readip_pcap(p, &len, NULL); ! if(response){ ! recvbytes = len; ! port = parse_icmp_udp_packet(response, len, saddress, par, out); ! if(port!=0 && !scanning_ports[port].done && !(scanning_ports.find(port) == scanning_ports.end())){ ! if(isscan){ ! scanning_ports[port].done = true; ! subtarget->set_port_status(port, PORT_CLOSED, "udp"); ! } ! else{ ! result = true; ! next = false; ! } } } ! iceusleep(1); ! gettimeofday(&tv2, 0); ! }while(SUB_TIMEVALS(tv2,tv1) < 50000*repeats); } ! iceusleep(50000*repeats); ! }while(recvbytes > 0 && next); } } |