[Javanetsim-cvs] IceScan csubtarget.h,1.31,1.32 udpscan.h,1.4,1.5
Status: Beta
Brought to you by:
darkkey
From: QweR <qw...@us...> - 2006-12-16 11:39:24
|
Update of /cvsroot/javanetsim/IceScan In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv30153 Modified Files: csubtarget.h udpscan.h Log Message: Index: csubtarget.h =================================================================== RCS file: /cvsroot/javanetsim/IceScan/csubtarget.h,v retrieving revision 1.31 retrieving revision 1.32 diff -C2 -d -r1.31 -r1.32 *** csubtarget.h 16 Dec 2006 10:39:10 -0000 1.31 --- csubtarget.h 16 Dec 2006 11:39:17 -0000 1.32 *************** *** 13,17 **** #include "nbt_wrapper.h" #include "iceprotocol.h" - #include "udpscan.h" #define CONNECT_TIMEOUT 14 --- 13,16 ---- *************** *** 25,28 **** --- 24,30 ---- #define MAX_CLOSED 7 + class csubtarget; + void udpscan(icestring, icestring, std::map <int, scanning_port>, iceparams*, iceoutput*, csubtarget*); + struct scan_socket{ int sid; *************** *** 164,168 **** local_hn.assign(local_hostname); ! udpscan(local_hn, hostname, scanning_ports); // udpscan2(local_hn, hostname, scanning_ports,hostname.c_str(), par, out); --- 166,170 ---- local_hn.assign(local_hostname); ! udpscan(local_hn, hostname, scanning_ports, par, out, this); // udpscan2(local_hn, hostname, scanning_ports,hostname.c_str(), par, out); *************** *** 207,317 **** } ! void udpscan(icestring hostname, icestring destname, std::map <int, scanning_port> scanning_ports){ ! //char recvpackettest[56] = {0x45,0x00,0x00,0x38,0x36,0xd8,0x00,0x00,0xf2,0x01,0x0b,0x5e,0x52,0x8c,0x67,0x12, ! // 0x57,0xed,0x75,0x03,0x03,0x03,0x83,0xa5,0x00,0x00,0x00,0x00,0x45,0x00,0x00,0x1c, ! // 0x43,0x23,0x00,0x00,0x73,0x11,0x7e,0x1f,0x57,0xed,0x75,0x03,0x52,0x8c,0x67,0x12, ! // 0x1a,0xf6,0x01,0xBC,0x00,0x08,0x5c,0xc9}; ! //char recvpackettest2[8] = {0x01,0xBD,0x1a,0xf6,0x00,0x08,0x5c,0xc9}; ! //bool alreadyscan = false; ! //bool alreadyscan2 = false; ! ! #ifndef __CYGWIN__ ! if(!getuid() || par->forceuid){ ! #else ! if(par->forceuid){ ! #endif ! #define UDP_SCAN_ZSIZE 0 ! #define UDP_SCAN_RECVSIZE 150 ! #define UDP_SCAN_REPEATS 5 ! int repeats; ! int rep2; ! csocket sudp(PF_INET, SOCK_DGRAM); ! crawsocket sicmp(AF_INET, SOCK_RAW, IPPROTO_ICMP); ! char zmsg[UDP_SCAN_ZSIZE]; ! char recvmsg[UDP_SCAN_RECVSIZE]; ! memset(zmsg, 0, UDP_SCAN_ZSIZE); ! int recvbytes; ! bool p; ! int port; ! ! int recvsize = UDP_SCAN_RECVSIZE; ! ! sudp.bind(hostname.c_str(), 0, 0); ! sudp.nonblock(true); ! sicmp.nonblock(true); ! ! int size = 60 * 1024; ! sicmp.setsockopt(SOL_SOCKET, SO_RCVBUF, &size, sizeof(size)); ! ! //sicmp.setsockopt(SOL_SOCKET, SO_RCVBUF, &recvsize, sizeof(recvsize)); ! // sicmp.setsockopt(SOL_SOCKET, SO_RCVBUF, &recvsize, sizeof(recvsize)); ! for(repeats = 0; repeats < UDP_SCAN_REPEATS; repeats++){ ! // DBGOUTPUT("STARTING..."); ! for(std::map <int, scanning_port>::iterator i = scanning_ports.begin(); i!= scanning_ports.end(); ++i){ ! if(! (*i).second.done ){ ! //DBGOUTPUT((*i).first); ! sudp.sendto(destname.c_str(), (*i).first, zmsg, UDP_SCAN_ZSIZE, 0); ! iceusleep(100000); ! //recvbytes = sicmp.recvfrom(recvmsg, UDP_SCAN_RECVSIZE, 0, NULL); ! } ! // alreadyscan = false; ! // alreadyscan2 = false; ! do{ ! recvbytes = sudp.recvfrom(recvmsg, UDP_SCAN_RECVSIZE, 0, NULL, NULL); ! // if((*i).first == 445 && !alreadyscan2){ ! // recvbytes = 8; ! // memcpy(recvmsg, recvpackettest2, 8); ! // alreadyscan2 = true; ! // } ! p = recvbytes > 0; ! if(p){ ! struct udphdr* udp = (struct udphdr*) recvmsg; ! port = ntohs(udp->source); ! if(port!=0 && !scanning_ports[port].done && scanning_ports.find(port) != scanning_ports.end()){ ! scanning_ports[port].done = true; ! set_port_status(port, PORT_OPEN, "udp"); ! } ! } ! else{ ! int att = 0; ! while(att++ < 5 && recvbytes <= 0){ ! recvbytes = sicmp.recvfrom(recvmsg, UDP_SCAN_RECVSIZE, 0, NULL); ! iceusleep(100000); ! } ! ! // if((*i).first == 444 && !alreadyscan){ ! // recvbytes = 56; ! // memcpy(recvmsg, recvpackettest, 56); ! // alreadyscan = true; ! // } ! ! // recvbytes = recvfrom(sicmp.get_socketid(), recvmsg, RECVSIZE, 0, NULL, NULL); ! if(recvbytes > 0){ ! port = parse_icmp_udp_packet(recvmsg, recvbytes, par, out); ! if(port!=0 && !scanning_ports[port].done && !(scanning_ports.find(port) == scanning_ports.end())){ ! scanning_ports[port].done = true; ! set_port_status(port, PORT_CLOSED, "udp"); ! } ! p = true; ! } ! else if(recvbytes != -1){ ! //DBGOUTPUT("NO DATA..."); ! //DBGOUTPUT(recvbytes); ! } ! if(!p) rep2++; ! } ! iceusleep(100000); ! }while(recvbytes > 0); ! } ! } ! for(std::map <int, scanning_port>::iterator i = scanning_ports.begin(); i!= scanning_ports.end(); ++i){ ! if(! (*i).second.done ){ ! port = (*i).first; ! scanning_ports[port].done = true; ! set_port_status(port, PORT_OPEN_FILTERED, "udp"); ! } ! } ! }else out->line("UID isn't 0, so can't create raw socket => no UDP scan..."); ! } --- 209,218 ---- } ! void set_port_status(int port, enum port_status status, char* protocol){ ! struct scanned_port sp; ! sp.port_number = port; ! sp.status = status; ! subtarget_ports.push_back(sp); ! print_port_status(sp.port_number, status, protocol); } *************** *** 810,821 **** } - void set_port_status(int port, enum port_status status, char* protocol){ - struct scanned_port sp; - sp.port_number = port; - sp.status = status; - subtarget_ports.push_back(sp); - print_port_status(sp.port_number, status, protocol); - } - void show_ports(){ int filtered = 0, closed = 0, open = 0, total = 0; --- 711,714 ---- *************** *** 891,893 **** --- 784,788 ---- }; + #include "udpscan.h" + #endif Index: udpscan.h =================================================================== RCS file: /cvsroot/javanetsim/IceScan/udpscan.h,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** udpscan.h 16 Dec 2006 10:23:07 -0000 1.4 --- udpscan.h 16 Dec 2006 11:39:17 -0000 1.5 *************** *** 12,15 **** --- 12,16 ---- #include "icesockets/sock_types.h" #include "icesockets/sock_err.h" + #include "csubtarget.h" *************** *** 18,21 **** --- 19,23 ---- #define UDP_SCAN_REPEATS 5 + int parse_icmp_udp_packet(char* recvmsg, int recvbytes, iceparams *par, iceoutput *out){ int port = 0; *************** *** 39,43 **** if(ip->ip_p == SOL_UDP && ((char*)ip+hdrlen+sizeof(udphdr))-recvmsg<=recvbytes){ struct udphdr* udp = (struct udphdr *) ((char*)ip + hdrlen); ! port = ntohs(udp->dest); if(par->verbose>0) out->line("Recieved icmp port unreachable."); --- 41,45 ---- if(ip->ip_p == SOL_UDP && ((char*)ip+hdrlen+sizeof(udphdr))-recvmsg<=recvbytes){ struct udphdr* udp = (struct udphdr *) ((char*)ip + hdrlen); ! port = ntohs(udp->uh_dport); if(par->verbose>0) out->line("Recieved icmp port unreachable."); *************** *** 52,55 **** --- 54,167 ---- } + void udpscan(icestring hostname, icestring destname, std::map <int, scanning_port> scanning_ports, iceparams *par, iceoutput *out, csubtarget* subtarget){ + //char recvpackettest[56] = {0x45,0x00,0x00,0x38,0x36,0xd8,0x00,0x00,0xf2,0x01,0x0b,0x5e,0x52,0x8c,0x67,0x12, + // 0x57,0xed,0x75,0x03,0x03,0x03,0x83,0xa5,0x00,0x00,0x00,0x00,0x45,0x00,0x00,0x1c, + // 0x43,0x23,0x00,0x00,0x73,0x11,0x7e,0x1f,0x57,0xed,0x75,0x03,0x52,0x8c,0x67,0x12, + // 0x1a,0xf6,0x01,0xBC,0x00,0x08,0x5c,0xc9}; + //char recvpackettest2[8] = {0x01,0xBD,0x1a,0xf6,0x00,0x08,0x5c,0xc9}; + //bool alreadyscan = false; + //bool alreadyscan2 = false; + + #ifndef __CYGWIN__ + if(!getuid() || par->forceuid){ + #else + if(par->forceuid){ + #endif + #define UDP_SCAN_ZSIZE 0 + #define UDP_SCAN_RECVSIZE 150 + #define UDP_SCAN_REPEATS 5 + int repeats; + int rep2; + csocket sudp(PF_INET, SOCK_DGRAM); + crawsocket sicmp(AF_INET, SOCK_RAW, IPPROTO_ICMP); + char zmsg[UDP_SCAN_ZSIZE]; + char recvmsg[UDP_SCAN_RECVSIZE]; + memset(zmsg, 0, UDP_SCAN_ZSIZE); + int recvbytes; + bool p; + int port; + + int recvsize = UDP_SCAN_RECVSIZE; + + sudp.bind(hostname.c_str(), 0, 0); + sudp.nonblock(true); + sicmp.nonblock(true); + + int size = 60 * 1024; + sicmp.setsockopt(SOL_SOCKET, SO_RCVBUF, &size, sizeof(size)); + + //sicmp.setsockopt(SOL_SOCKET, SO_RCVBUF, &recvsize, sizeof(recvsize)); + // sicmp.setsockopt(SOL_SOCKET, SO_RCVBUF, &recvsize, sizeof(recvsize)); + for(repeats = 0; repeats < UDP_SCAN_REPEATS; repeats++){ + // DBGOUTPUT("STARTING..."); + for(std::map <int, scanning_port>::iterator i = scanning_ports.begin(); i!= scanning_ports.end(); ++i){ + if(! (*i).second.done ){ + //DBGOUTPUT((*i).first); + sudp.sendto(destname.c_str(), (*i).first, zmsg, UDP_SCAN_ZSIZE, 0); + iceusleep(100000); + //recvbytes = sicmp.recvfrom(recvmsg, UDP_SCAN_RECVSIZE, 0, NULL); + } + // alreadyscan = false; + // alreadyscan2 = false; + do{ + recvbytes = sudp.recvfrom(recvmsg, UDP_SCAN_RECVSIZE, 0, NULL, NULL); + // if((*i).first == 445 && !alreadyscan2){ + // recvbytes = 8; + // memcpy(recvmsg, recvpackettest2, 8); + // alreadyscan2 = true; + // } + p = recvbytes > 0; + if(p){ + struct udphdr* udp = (struct udphdr*) recvmsg; + port = ntohs(udp->uh_sport); + if(port!=0 && !scanning_ports[port].done && scanning_ports.find(port) != scanning_ports.end()){ + scanning_ports[port].done = true; + subtarget->set_port_status(port, PORT_OPEN, "udp"); + } + } + else{ + int att = 0; + while(att++ < 5 && recvbytes <= 0){ + recvbytes = sicmp.recvfrom(recvmsg, UDP_SCAN_RECVSIZE, 0, NULL); + iceusleep(100000); + } + + // if((*i).first == 444 && !alreadyscan){ + // recvbytes = 56; + // memcpy(recvmsg, recvpackettest, 56); + // alreadyscan = true; + // } + + // recvbytes = recvfrom(sicmp.get_socketid(), recvmsg, RECVSIZE, 0, NULL, NULL); + if(recvbytes > 0){ + port = parse_icmp_udp_packet(recvmsg, recvbytes, par, out); + if(port!=0 && !scanning_ports[port].done && !(scanning_ports.find(port) == scanning_ports.end())){ + scanning_ports[port].done = true; + subtarget->set_port_status(port, PORT_CLOSED, "udp"); + } + p = true; + } + else if(recvbytes != -1){ + //DBGOUTPUT("NO DATA..."); + //DBGOUTPUT(recvbytes); + } + if(!p) rep2++; + } + iceusleep(100000); + }while(recvbytes > 0); + } + } + for(std::map <int, scanning_port>::iterator i = scanning_ports.begin(); i!= scanning_ports.end(); ++i){ + if(! (*i).second.done ){ + port = (*i).first; + scanning_ports[port].done = true; + subtarget->set_port_status(port, PORT_OPEN_FILTERED, "udp"); + } + } + }else out->line("UID isn't 0, so can't create raw socket => no UDP scan..."); + + } + + bool udpscan2(icestring hostname2, icestring destname2, std::map <int, scanning_port> scanning_ports, const char *hostname, iceparams *par, iceoutput *out){ #ifndef __CYGWIN__ |