[Javanetsim-cvs] IceScan portdef.h, NONE, 1.1 udpscan.h, NONE, 1.1 csubtarget.h, 1.25, 1.26 icedisc
Status: Beta
Brought to you by:
darkkey
From: QweR <qw...@us...> - 2006-12-16 00:29:21
|
Update of /cvsroot/javanetsim/IceScan In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv27015 Modified Files: csubtarget.h icediscover.h iceparams.h icescan.cc Added Files: portdef.h udpscan.h Log Message: Index: icescan.cc =================================================================== RCS file: /cvsroot/javanetsim/IceScan/icescan.cc,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** icescan.cc 15 Dec 2006 21:04:55 -0000 1.23 --- icescan.cc 16 Dec 2006 00:29:16 -0000 1.24 *************** *** 163,166 **** --- 163,170 ---- break; + case 'U': + par->scan_type = UDP_SCAN; + break; + default: std::cout << "Invalid scan type: -S" << argv[i][2] << std::endl; *************** *** 215,225 **** }else{ IceRegex re("(\\d+(-\\d+)?),?"); icestring var = "", var2 = ""; ! re.match(argv[i+1]); re.findReset(); //re.Consume(&input, &var, &var2) while(re.findNext()){ var2 = ""; var = ""; re.group(1,var); --- 219,231 ---- }else{ IceRegex re("(\\d+(-\\d+)?),?"); + icestring var = "", var2 = ""; ! re.match(argv[i+1]); re.findReset(); //re.Consume(&input, &var, &var2) while(re.findNext()){ + var2 = ""; var = ""; re.group(1,var); Index: csubtarget.h =================================================================== RCS file: /cvsroot/javanetsim/IceScan/csubtarget.h,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** csubtarget.h 15 Dec 2006 17:46:18 -0000 1.25 --- csubtarget.h 16 Dec 2006 00:29:15 -0000 1.26 *************** *** 7,10 **** --- 7,11 ---- #include <vector> #include <errno.h> + #include "portdef.h" #include "iceoutput.h" #include "iceparams.h" *************** *** 12,15 **** --- 13,17 ---- #include "nbt_wrapper.h" #include "iceprotocol.h" + #include "udpscan.h" #define CONNECT_TIMEOUT 14 *************** *** 23,34 **** #define MAX_CLOSED 7 - enum port_status { PORT_UNKNOWN = -1, PORT_OPEN = 0, PORT_CLOSED = 1, PORT_FILTERED = 2, PORT_OPEN_FILTERED = 3, PORT_UNFILTERED = 4 }; - - class scanned_port{ - public: - int port_number; - enum port_status status; - }; - struct scan_socket{ int sid; --- 25,28 ---- *************** *** 37,49 **** }; - class scanning_port{ - public: - int port_number; - bool done; - long time; - int socket_ptr; - int attempt; - }; - class csubtarget{ --- 31,34 ---- *************** *** 108,111 **** --- 93,97 ---- if(par->scan_type == ACK_SCAN) raw_tcp_scan("ACK"); if(par->scan_type == SYN_SCAN) raw_tcp_scan("SYN"); + if(par->scan_type == UDP_SCAN) udp_scan(); } *************** *** 191,195 **** crawsocket rawsend(AF_INET, (int) SOCK_RAW, IPPROTO_RAW); ! crawsocket rawrecv(AF_INET, (int) SOCK_RAW, IPPROTO_TCP); rawrecv.nonblock(true); --- 177,181 ---- crawsocket rawsend(AF_INET, (int) SOCK_RAW, IPPROTO_RAW); ! crawsocket rawrecv(AF_INET, (int) SOCK_RAW, IPPROTO_TCP); rawrecv.nonblock(true); *************** *** 335,339 **** } ! int connect_scan(){ --- 321,352 ---- } ! int udp_scan(){ ! // connect scan, -SU ! ! char output_buf[255]; ! char local_hostname[80]; ! icestring local_hn; ! ! std::map <int, scanning_port> scanning_ports; ! init_scanning_ports(hostname, par, (int) SOCK_DGRAM, scanning_ports); ! ! if(par->verbose>0){ ! sprintf(output_buf, "Starting UDP scan against %s...", hostname.c_str()); ! out->line(output_buf); ! } ! ! if(gethostname(local_hostname,79)) exit(-1); ! local_hn.assign(local_hostname); ! ! udpscan(local_hn, hostname, scanning_ports, par, out); ! // udpscan2(local_hn, hostname, scanning_ports,hostname.c_str(), par, out); ! ! show_ports(); ! ! if(par->verbose>0) ! out->line("UDP scan finished."); ! ! scanning_ports.clear(); ! } int connect_scan(){ *************** *** 359,362 **** --- 372,377 ---- while( ! do_select_round_connect(scanning_ports, subtarget_ports) ) iceusleep(1000); + // DBGOUTPUT("end do_select_round"); + show_ports(); *************** *** 593,598 **** int curtime = time(0); ! for(i = scanning_ports.begin(); i!= scanning_ports.end(); ++i){ if((*i).second.done) continue; if( (*i).second.socket_ptr == -1){ --- 608,616 ---- int curtime = time(0); ! // DBGOUTPUT(" 509 "); + for(i = scanning_ports.begin(); i!= scanning_ports.end(); ++i){ + // DBGOUTPUT(" 512 "); + if((*i).second.done) continue; if( (*i).second.socket_ptr == -1){ *************** *** 601,605 **** continue; } ! enum port_status status = PORT_UNKNOWN; if(s >= 0 && (FD_ISSET(scan_sockets[(*i).second.socket_ptr].sid, &fd_rtmp) || --- 619,626 ---- continue; } ! ! // DBGOUTPUT( (*i).second.socket_ptr); ! // DBGOUTPUT(" 522 "); ! enum port_status status = PORT_UNKNOWN; if(s >= 0 && (FD_ISSET(scan_sockets[(*i).second.socket_ptr].sid, &fd_rtmp) || *************** *** 607,611 **** FD_ISSET(scan_sockets[(*i).second.socket_ptr].sid, &fd_xtmp))){ ! //DBGOUTPUT( (*i).second.socket_ptr); csocket c(AF_INET, (int) domain, scan_sockets[(*i).second.socket_ptr].sid); --- 628,632 ---- FD_ISSET(scan_sockets[(*i).second.socket_ptr].sid, &fd_xtmp))){ ! // DBGOUTPUT( (*i).second.socket_ptr); csocket c(AF_INET, (int) domain, scan_sockets[(*i).second.socket_ptr].sid); *************** *** 670,675 **** done &= true; } ! ! //DBGOUTPUT(done); return done; } --- 691,696 ---- done &= true; } ! // DBGOUTPUT("done"); ! // DBGOUTPUT(done); return done; } Index: icediscover.h =================================================================== RCS file: /cvsroot/javanetsim/IceScan/icediscover.h,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** icediscover.h 15 Dec 2006 21:04:55 -0000 1.15 --- icediscover.h 16 Dec 2006 00:29:16 -0000 1.16 *************** *** 34,38 **** } ! bool icmp_ping(const char *hostname, iceparams *par, iceoutput *out, enum Icmp_type icmp_type){ #ifndef __CYGWIN__ if(!getuid() || par->forceuid){ --- 34,38 ---- } ! bool icmp_ping(const char *hostname, iceparams *par, iceoutput *out, enum Icmp_type icmp_type){ #ifndef __CYGWIN__ if(!getuid() || par->forceuid){ *************** *** 45,49 **** char *t_hostname = (char *) malloc(strlen(hostname) + 1); strcpy(t_hostname, hostname); ! if(par->verbose>0) out->line("Starting icmp ping host discovery..."); --- 45,49 ---- char *t_hostname = (char *) malloc(strlen(hostname) + 1); strcpy(t_hostname, hostname); ! if(par->verbose>0) out->line("Starting icmp ping host discovery..."); Index: iceparams.h =================================================================== RCS file: /cvsroot/javanetsim/IceScan/iceparams.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** iceparams.h 15 Dec 2006 17:46:18 -0000 1.10 --- iceparams.h 16 Dec 2006 00:29:16 -0000 1.11 *************** *** 12,17 **** }; ! enum Scan_type {NO_SCAN, TCP_CONNECT_SCAN, NBT_SCAN, PROT_SCAN, FIN_SCAN, NULL_SCAN, XMAS_SCAN, WINDOW_SCAN, ACK_SCAN, SYN_SCAN}; ! // -S0 -ST -SB -SI -SF -SN -SX -SW -SA -SS --- 12,17 ---- }; ! enum Scan_type {NO_SCAN, TCP_CONNECT_SCAN, NBT_SCAN, PROT_SCAN, FIN_SCAN, NULL_SCAN, XMAS_SCAN, WINDOW_SCAN, ACK_SCAN, SYN_SCAN, UDP_SCAN}; ! // -S0 -ST -SB -SI -SF -SN -SX -SW -SA -SS -SU *************** *** 125,129 **** const int ranges_cnt = 2; ! int ranges[ranges_cnt][2] = { {20, 25}, {135, 136} }; //int ranges[ranges_cnt][2] = { {1, 1024}, {3388, 3390} }; --- 125,129 ---- const int ranges_cnt = 2; ! int ranges[ranges_cnt][2] = { {20, 25}, {130, 200} }; //int ranges[ranges_cnt][2] = { {1, 1024}, {3388, 3390} }; --- NEW FILE: udpscan.h --- #ifndef _udpscan_H #define _udpscan_H #include <cstdio> #include <cstdlib> #include <map> #include <vector> #include <errno.h> #include <pthread.h> #include "portdef.h" #include "icesockets/csocket.h" #include "icesockets/sock_types.h" #include "icesockets/sock_err.h" #define ZSIZE 0 #define RECVSIZE 150 char recvpackettest[70] = {0x00,0x11,0xd8,0x5e,0xea,0x44,0x00,0x17,0x95,0xee,0x26,0x1a,0x08,0x00,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,0x90,0x00,0x08,0x5c,0xc9}; void udpscan(icestring hostname, icestring destname, std::map <int, scanning_port> scanning_ports, iceparams *par, iceoutput *out){ #ifndef __CYGWIN__ if(!getuid() || par->forceuid){ #else if(par->forceuid){ #endif int repeats; int rep2; csocket sudp(PF_INET, SOCK_DGRAM); crawsocket sicmp(AF_INET, SOCK_RAW, IPPROTO_ICMP); char zmsg[ZSIZE]; char recvmsg[RECVSIZE]; memset(zmsg, 0, ZSIZE); int recvbytes; struct icmp* icmppacket; // struct ip *ip bool p; int recvsize = RECVSIZE; sudp.bind(hostname.c_str(), sudp.getMagicPort(), 0); sudp.nonblock(true); sicmp.nonblock(true); sicmp.setsockopt(SOL_SOCKET, SO_RCVBUF, &recvsize, sizeof(recvsize)); // sicmp.setsockopt(SOL_SOCKET, SO_RCVBUF, &recvsize, sizeof(recvsize)); for(repeats = 0; repeats < 10; 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, ZSIZE, 0); iceusleep(10000); } } for(rep2 = 0; rep2 < 10; ){ recvbytes = sudp.recvfrom(recvmsg, RECVSIZE, 0, NULL, NULL); p = recvbytes > 0; recvbytes = sicmp.recvfrom(recvmsg, RECVSIZE, 0, NULL); // recvbytes = recvfrom(sicmp.get_socketid(), recvmsg, RECVSIZE, 0, NULL, NULL); if(recvbytes > 0){ DBGOUTPUT("Data portion:\n"); for(int i=0; i < recvbytes; i++) printf("%2X%c", recvmsg[i], (++i%16)? ' ' : '\n'); printf("\n"); // ip = (struct ip *) buf; // int hdrlen = ip->ip_hl << 2; // icmppacket = (struct icmp *) (buf + hdrlen); // int icmplen = len - hdrlen; // // bool result = false; // // if(icmp->icmp_type == ICMP_UNREACH && icmp->icmp_code == ICMP_UNREACH_PORT){ // result = true; // if(par->verbose>0) // out->line("Recieved icmp port unreachable."); // // char *buf; // // uint32_t t = ntohl(icmp->icmp_rtime); // // DBGOUTPUT(t); // // DBGOUTPUT(make_uptime(t)); // } // if(result){ // free(t_hostname); // r.shutdown(); // r.close(); // return true; // } p = true; } else if(recvbytes != -1){ DBGOUTPUT("NO DATA..."); DBGOUTPUT(recvbytes); } iceusleep(10000); if(!p) rep2++; } } }else out->line("UID isn't 0, so can't create raw socket => no ICMP ping..."); } bool udpscan2(icestring hostname2, icestring destname2, std::map <int, scanning_port> scanning_ports, const char *hostname, iceparams *par, iceoutput *out){ #ifndef __CYGWIN__ if(!getuid() || par->forceuid){ #else if(par->forceuid){ #endif //we're root, so can work with raw sockets icestring hostname_(hostname); char *t_hostname = (char *) malloc(strlen(hostname) + 1); strcpy(t_hostname, hostname); if(par->verbose>0) out->line("Starting icmp ping host discovery..."); crawsocket r(AF_INET, SOCK_RAW, IPPROTO_ICMP); int size = 60 * 1024; int attempts = 0; r.setsockopt(SOL_SOCKET, SO_RCVBUF, &size, sizeof(size)); r.nonblock(true); int at = 1; int len; csocket sudp(AF_INET, SOCK_DGRAM); sudp.bind(hostname, sudp.getMagicPort(), 0); sudp.nonblock(true); while(attempts++ < 100){ if(at++<=ATTEMPTS){ short int msg_type = ICMP_ECHO; char buf[sizeof(struct timeval) + 1]; if(par->verbose>0) out->line("Sending icmp timestamp host discovery request..."); bzero(buf, sizeof(struct timeval) + 1); msg_type = ICMP_TSTAMP; // r.send_icmp_packet(hostname, msg_type, 0, getpid(), at, 0, buf, sizeof(struct timeval)); char zmsg[ZSIZE]; 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(destname2.c_str(), (*i).first, zmsg, ZSIZE, 0); iceusleep(10000); } } iceusleep(200000); } char hostname[ICEMAXHOSTNAME]; char buf[1500]; //1500 == standart IP Packet size do{ len = recvfrom(r.get_socketid(), buf, sizeof(buf), 0, NULL, NULL); if(len > 0){ struct ip *ip = (struct ip *) buf; int hdrlen = ip->ip_hl << 2; struct icmp *icmp = (struct icmp *) (buf + hdrlen); int icmplen = len - hdrlen; bool result = false; if(icmp->icmp_id == getpid() && icmplen > 16){ if(icmp->icmp_type == ICMP_TSTAMPREPLY){ result = true; if(par->verbose>0) out->line("Recieved icmp timestamp host discovery reply."); char *buf; uint32_t t = ntohl(icmp->icmp_rtime); DBGOUTPUT(t); DBGOUTPUT(make_uptime(t)); } if(result){ free(t_hostname); r.shutdown(); r.close(); return true; } } } else iceusleep(50000); }while(len > 0); } r.shutdown(); r.close(); free(t_hostname); }else out->line("UID isn't 0, so can't create raw socket => no ICMP ping..."); return false; } #endif /* _udpscan_H */ --- NEW FILE: portdef.h --- #ifndef _portdef_H #define _portdef_H enum port_status { PORT_UNKNOWN = -1, PORT_OPEN = 0, PORT_CLOSED = 1, PORT_FILTERED = 2, PORT_OPEN_FILTERED = 3, PORT_UNFILTERED = 4 }; class scanned_port{ public: int port_number; enum port_status status; }; class scanning_port{ public: int port_number; bool done; long time; int socket_ptr; int attempt; }; #endif /* _portdef_H */ |