[Javanetsim-cvs] IceScan iceparams.h, 1.3, 1.4 icescan.cc, 1.6, 1.7 ctarget.h, 1.3, 1.4 icedebug.h,
Status: Beta
Brought to you by:
darkkey
From: Alexander B. <da...@us...> - 2006-12-12 19:59:22
|
Update of /cvsroot/javanetsim/IceScan In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv28891 Modified Files: iceparams.h icescan.cc ctarget.h icedebug.h csubtarget.h Log Message: no message Index: icescan.cc =================================================================== RCS file: /cvsroot/javanetsim/IceScan/icescan.cc,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** icescan.cc 30 Nov 2006 12:27:35 -0000 1.6 --- icescan.cc 12 Dec 2006 19:59:15 -0000 1.7 *************** *** 169,173 **** } }else{ ! //DBGOUTPUT("Target is: " << argv[i]); par->target = (char *) malloc( strlen(argv[i]) ); strcpy(par->target, argv[i]); --- 169,173 ---- } }else{ ! // DBGOUTPUT("Target is: " << argv[i]); par->target = (char *) malloc( strlen(argv[i]) ); strcpy(par->target, argv[i]); *************** *** 227,230 **** --- 227,231 ---- ftime(&tp1); + ts.add_subtargets(par.target); *************** *** 233,236 **** --- 234,240 ---- } + + DBGOUTPUT("!!!!!!!!!!"); + if(discover) ts.scan(); Index: iceparams.h =================================================================== RCS file: /cvsroot/javanetsim/IceScan/iceparams.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** iceparams.h 30 Nov 2006 06:43:50 -0000 1.3 --- iceparams.h 12 Dec 2006 19:59:15 -0000 1.4 *************** *** 105,111 **** void init_default_ports(){ ! const int ranges_cnt = 1; ! int ranges[ranges_cnt][2] = { {1, 1024} }; if(ports.empty()){ --- 105,112 ---- void init_default_ports(){ ! const int ranges_cnt = 2; ! //int ranges[ranges_cnt][2] = { {1, 24}, {630, 632} }; ! int ranges[ranges_cnt][2] = { {1, 1024}, {3388, 3390} }; if(ports.empty()){ Index: csubtarget.h =================================================================== RCS file: /cvsroot/javanetsim/IceScan/csubtarget.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** csubtarget.h 30 Nov 2006 06:43:50 -0000 1.5 --- csubtarget.h 12 Dec 2006 19:59:15 -0000 1.6 *************** *** 5,8 **** --- 5,9 ---- #include <cstdlib> #include <map> + #include <vector> #include <errno.h> #include <pthread.h> *************** *** 19,23 **** enum port_status { PORT_UNKNOWN = -1, PORT_OPEN = 0, PORT_CLOSED = 1, PORT_FILTERED = 2 }; ! struct scanned_port{ public: int port_number; --- 20,24 ---- enum port_status { PORT_UNKNOWN = -1, PORT_OPEN = 0, PORT_CLOSED = 1, PORT_FILTERED = 2 }; ! class scanned_port{ public: int port_number; *************** *** 25,36 **** }; ! class scan_socket{ ! public: ! csocket *c; ! bool busy; ! ! scan_socket(){ ! c = NULL; ! } }; --- 26,33 ---- }; ! struct scan_socket{ ! int sid; ! bool busy; ! int domain; }; *************** *** 39,55 **** char hostname[24]; int port_number; - csocket *c; bool done; long time; int socket_ptr; - - scanning_port(){ - c = NULL; - } }; class csubtarget{ ! iceoutput *out; --- 36,47 ---- char hostname[24]; int port_number; bool done; long time; int socket_ptr; }; class csubtarget{ ! iceoutput *out; *************** *** 61,64 **** --- 53,65 ---- ice_service_name_database *isnd; + + // *****scan parameters***** + bool raw; + + int domain; + + struct scan_socket* scan_sockets; + + // *****scan parameters***** public: *************** *** 68,72 **** std::vector<scanned_port> subtarget_ports; ! csubtarget(char *hostname, char *reverse_hostname, iceparams *par, iceoutput *out, ice_service_name_database *isnd){ this->hostname = (char *) malloc(strlen(hostname) + 1); strcpy(this->hostname, hostname); --- 69,82 ---- std::vector<scanned_port> subtarget_ports; ! csubtarget(const char *hostname, const char *reverse_hostname, iceparams *par, iceoutput *out, ice_service_name_database *isnd){ ! ! DBGOUTPUT("!!!!"); ! ! struct scanned_port sp; ! ! subtarget_ports.push_back(sp); ! ! DBGOUTPUT("!!!!"); ! this->hostname = (char *) malloc(strlen(hostname) + 1); strcpy(this->hostname, hostname); *************** *** 77,81 **** --- 87,94 ---- this->isnd = isnd; discovered = false; + DBGOUTPUT("!!!!"); init_scan_sockets(); + + DBGOUTPUT("!!!!"); } *************** *** 130,138 **** char output_buf[255]; ! ! //DBGOUTPUT("!!!"); std::map <int, scanning_port> scanning_ports; init_scanning_ports(hostname, par, (int) SOCK_STREAM, scanning_ports); if(par->verbose>0){ sprintf(output_buf, "Starting tcp connect() scan against %s...", hostname); --- 143,156 ---- char output_buf[255]; ! ! raw = false; ! domain = (int) SOCK_STREAM; ! ! ! DBGOUTPUT("!!!"); std::map <int, scanning_port> scanning_ports; init_scanning_ports(hostname, par, (int) SOCK_STREAM, scanning_ports); + if(par->verbose>0){ sprintf(output_buf, "Starting tcp connect() scan against %s...", hostname); *************** *** 158,180 **** fd_set fd_r, fd_w, fd_x; - std::vector<scan_socket> scan_sockets; int free_sockets; int maxfd; void init_scan_sockets(){ ! for(int i = 0; i< ICE_FD_SETSIZE*2/3; i++){ ! struct scan_socket st; ! st.c = NULL; ! st.busy = false; ! scan_sockets.push_back(st); ! } ! free_sockets = 0; } int get_first_free_socket(){ int f; ! ! for(f = 0; f < scan_sockets.size(); f++) ! if(!scan_sockets.at(f).busy && scan_sockets.at(f).c == NULL) return f; --- 176,200 ---- fd_set fd_r, fd_w, fd_x; int free_sockets; int maxfd; + int sockets_size; void init_scan_sockets(){ ! sockets_size = ICE_FD_SETSIZE*2/3; ! ! scan_sockets = (struct scan_socket *) malloc(sockets_size); ! ! for(int i = 0; i < sockets_size; i++){ ! scan_sockets[i].busy = false; ! scan_sockets[i].sid = -1; ! } ! free_sockets = sockets_size; } int get_first_free_socket(){ int f; ! ! for(f = 0; f < sockets_size; f++) ! if(!scan_sockets[f].busy && scan_sockets[f].sid < 0) return f; *************** *** 201,215 **** for(i = scanning_ports.begin(), j = 0; i!= scanning_ports.end(); ++i, j++){ ! if(j < scan_sockets.size()){ ! scan_sockets[j].c = new csocket(AF_INET, domain); ! (*i).second.c = scan_sockets[j].c; ! maxfd = scan_sockets[j].c->get_socketid(); ! scan_sockets[j].busy = true; (*i).second.socket_ptr = j; }else{ ! (*i).second.c = NULL; ! (*i).second.socket_ptr = -1; } } } --- 221,237 ---- for(i = scanning_ports.begin(), j = 0; i!= scanning_ports.end(); ++i, j++){ ! if(j < sockets_size){ ! csocket c(AF_INET, domain); ! scan_sockets[j].domain = domain; ! scan_sockets[j].sid = c.get_socketid(); ! maxfd = scan_sockets[j].sid; ! scan_sockets[j].busy = true; (*i).second.socket_ptr = j; + free_sockets--; }else{ ! (*i).second.socket_ptr = -1; } } + } *************** *** 223,237 **** for(i = scanning_ports.begin(); i!= scanning_ports.end(); ++i){ //check FD_SET ! if((*i).second.c != NULL){ ! ! (*i).second.c->nonblock(true); ! ! FD_SET((*i).second.c->get_socketid(), &fd_w); ! FD_SET((*i).second.c->get_socketid(), &fd_r); ! FD_SET((*i).second.c->get_socketid(), &fd_x); (*i).second.time = time(0); ! int rc = (*i).second.c->connect((*i).second.hostname, (*i).first, 0); ! free_sockets--; ! } } --- 245,260 ---- for(i = scanning_ports.begin(); i!= scanning_ports.end(); ++i){ //check FD_SET ! if((*i).second.socket_ptr != -1){ ! j = (*i).second.socket_ptr; ! csocket c(AF_INET, scan_sockets[j].domain, scan_sockets[j].sid); ! ! c.nonblock(true); ! ! FD_SET(scan_sockets[j].sid, &fd_w); ! FD_SET(scan_sockets[j].sid, &fd_r); ! FD_SET(scan_sockets[j].sid, &fd_x); (*i).second.time = time(0); ! int rc = c.connect((*i).second.hostname, (*i).first, 0); ! } } *************** *** 240,260 **** } ! void shutdown_scansocket(csocket *c, int ptr){ ! //DBGOUTPUT("ptr = " << ptr); ! FD_CLR(c->get_socketid(), &fd_w); ! FD_CLR(c->get_socketid(), &fd_r); ! FD_CLR(c->get_socketid(), &fd_x); ! //DBGOUTPUT(c->get_socketid() << " shutdowned."); ! ! c->shutdown(); ! c->close(); ! ! delete c; ! free_sockets++; ! scan_sockets[ptr].busy = false; ! scan_sockets[ptr].c = NULL; ! //DBGOUTPUT("Freeing socket " << ptr); } --- 263,279 ---- } ! void shutdown_scansocket(int j){ ! csocket c(AF_INET, scan_sockets[j].domain, scan_sockets[j].sid); ! ! FD_CLR(c.get_socketid(), &fd_w); ! FD_CLR(c.get_socketid(), &fd_r); ! FD_CLR(c.get_socketid(), &fd_x); ! c.shutdown(); ! c.close(); ! free_sockets++; ! scan_sockets[j].busy = false; ! scan_sockets[j].sid = -1; } *************** *** 265,269 **** for(i = --scanning_ports.end(); i!= scanning_ports.begin(); --i){ ! if((*i).second.c == NULL && (! (*i).second.done)) return (*i).first; } --- 284,288 ---- for(i = --scanning_ports.end(); i!= scanning_ports.begin(); --i){ ! if((*i).second.socket_ptr == -1 && (! (*i).second.done)) return (*i).first; } *************** *** 274,296 **** void idle_status_dispatcher(std::map <int, scanning_port> &scanning_ports, int prt){ ! if(prt>=0 && free_sockets < 1){ ! int f = get_first_free_socket(); ! //DBGOUTPUT(f << " " << free_sockets); if(f < 0) return; ! //if(scan_sockets[f].c ) return; ! scan_sockets[f].c = new csocket(AF_INET, (int) SOCK_STREAM); scan_sockets[f].busy = true; ! scanning_ports[prt].c = scan_sockets[f].c; free_sockets--; - scanning_ports[prt].socket_ptr = f; //DBGOUTPUT(prt); ! scanning_ports[prt].c->nonblock(true); //DBGOUTPUT("!!!"); ! FD_SET(scanning_ports[prt].c->get_socketid(), &fd_w); ! FD_SET(scanning_ports[prt].c->get_socketid(), &fd_r); ! FD_SET(scanning_ports[prt].c->get_socketid(), &fd_x); scanning_ports[prt].time = time(0); //DBGOUTPUT(scanning_ports[prt].hostname); ! int rc = scanning_ports[prt].c->connect(scanning_ports[prt].hostname, prt, 0); switch(rc){ --- 293,313 ---- void idle_status_dispatcher(std::map <int, scanning_port> &scanning_ports, int prt){ ! if(prt>=0 && free_sockets > 1){ ! int f = get_first_free_socket(); if(f < 0) return; ! csocket c(AF_INET, (int) domain); ! scan_sockets[f].sid = c.get_socketid(); scan_sockets[f].busy = true; ! scanning_ports[prt].socket_ptr = f; free_sockets--; //DBGOUTPUT(prt); ! c.nonblock(true); //DBGOUTPUT("!!!"); ! FD_SET(c.get_socketid(), &fd_w); ! FD_SET(c.get_socketid(), &fd_r); ! FD_SET(c.get_socketid(), &fd_x); scanning_ports[prt].time = time(0); //DBGOUTPUT(scanning_ports[prt].hostname); ! int rc = c.connect(scanning_ports[prt].hostname, prt, 0); switch(rc){ *************** *** 358,362 **** if((*i).second.done) continue; ! if( (*i).second.c == NULL){ idle_status_dispatcher(scanning_ports, (*i).first); done = false; --- 375,379 ---- if((*i).second.done) continue; ! if( (*i).second.socket_ptr == -1){ idle_status_dispatcher(scanning_ports, (*i).first); done = false; *************** *** 364,386 **** } enum port_status status = PORT_UNKNOWN; ! //DBGOUTPUT("..."); ! if(s >= 0 && (FD_ISSET((*i).second.c->get_socketid(), &fd_rtmp) || ! FD_ISSET((*i).second.c->get_socketid(), &fd_wtmp) || ! FD_ISSET((*i).second.c->get_socketid(), &fd_xtmp))){ ! (*i).second.c->getsockopt(SOL_SOCKET, SO_ERROR, (char *) &sopt, (socklen_t *) &soptlen); switch(sopt){ case 0: ! if(FD_ISSET((*i).second.c->get_socketid(), &fd_r)){ status = PORT_OPEN; }else{ ! //DBGOUTPUT("WRITE"); usleep(20000); ! res = (*i).second.c->write("", 0, 0); ! //DBGOUTPUT("/WRITE" << res); if(res < 0){ status = PORT_CLOSED; --- 381,408 ---- } + enum port_status status = PORT_UNKNOWN; ! if(s >= 0 && (FD_ISSET(scan_sockets[(*i).second.socket_ptr].sid, &fd_rtmp) || ! FD_ISSET(scan_sockets[(*i).second.socket_ptr].sid, &fd_wtmp) || ! 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); ! c.getsockopt(SOL_SOCKET, SO_ERROR, (char *) &sopt, (socklen_t *) &soptlen); + DBGOUTPUT("!!!!"); + switch(sopt){ case 0: ! if(FD_ISSET(scan_sockets[(*i).second.socket_ptr].sid, &fd_r)){ status = PORT_OPEN; }else{ ! DBGOUTPUT("WRITE"); usleep(20000); ! res = c.write("", 0, 0); ! DBGOUTPUT("/WRITE" << res); if(res < 0){ status = PORT_CLOSED; *************** *** 405,421 **** status = PORT_UNKNOWN; } ! struct scanned_port sp; sp.port_number = (*i).first; sp.status = status; subtarget_ports.push_back(sp); ! ! print_port_status((*i).first, status); ! (*i).second.done = true; ! shutdown_scansocket((*i).second.c, (*i).second.socket_ptr); ! (*i).second.c = NULL; ! //DBGOUTPUT("Erasing... :" << status); //scanning_ports.erase(i++); --- 427,448 ---- status = PORT_UNKNOWN; } ! struct scanned_port sp; sp.port_number = (*i).first; + + DBGOUTPUT("!!!!"); + sp.status = status; subtarget_ports.push_back(sp); ! ! DBGOUTPUT("very well"); ! ! print_port_status(sp.port_number, status); ! (*i).second.done = true; ! shutdown_scansocket((*i).second.socket_ptr); ! (*i).second.socket_ptr = -1; ! DBGOUTPUT("Erasing... :" << status); //scanning_ports.erase(i++); *************** *** 432,439 **** print_port_status((*i).first, sp.status); ! shutdown_scansocket((*i).second.c, (*i).second.socket_ptr); ! (*i).second.c = NULL; ! //scanning_ports.erase(i++); ! //idle_status_dispatcher(scanning_ports, get_first_idle_scanning_port(scanning_ports)); }else done &= false; --- 459,464 ---- print_port_status((*i).first, sp.status); ! shutdown_scansocket((*i).second.socket_ptr); ! (*i).second.socket_ptr = -1; }else done &= false; *************** *** 512,516 **** free(hostname); free(reversed_hostname); ! scan_sockets.clear(); subtarget_ports.clear(); //DBGOUTPUT("Leaving destructor..."); --- 537,541 ---- free(hostname); free(reversed_hostname); ! free(scan_sockets); subtarget_ports.clear(); //DBGOUTPUT("Leaving destructor..."); Index: icedebug.h =================================================================== RCS file: /cvsroot/javanetsim/IceScan/icedebug.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** icedebug.h 28 Nov 2006 17:57:54 -0000 1.1 --- icedebug.h 12 Dec 2006 19:59:15 -0000 1.2 *************** *** 4,8 **** #include <iostream> ! #define DBGOUTPUT(TEXT) std::cout << TEXT << std::endl #endif --- 4,8 ---- #include <iostream> ! #define DBGOUTPUT(TEXT) std::cout << __FILE__ << " " << __LINE__ << ": " << TEXT << std::endl #endif Index: ctarget.h =================================================================== RCS file: /cvsroot/javanetsim/IceScan/ctarget.h,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ctarget.h 30 Nov 2006 06:43:50 -0000 1.3 --- ctarget.h 12 Dec 2006 19:59:15 -0000 1.4 *************** *** 13,17 **** std::vector <csubtarget *> subtargets; //subtargets (e.g. aliases for domain name, multiple ips per hostname, e.t.c.) ! std::vector <char *> subtargets_addresses; //subtarget ips as string public: --- 13,17 ---- std::vector <csubtarget *> subtargets; //subtargets (e.g. aliases for domain name, multiple ips per hostname, e.t.c.) ! std::vector <icestring> subtargets_addresses; //subtarget ips as string public: *************** *** 38,60 **** int st = get_ips_byhost(hostname, subtargets_addresses); ! char *rev_hostname = new char[ICEMAXHOSTNAME]; ! ! if((!is_domainname(hostname)) && par->reverse_dns) ! get_host_byip(hostname, rev_hostname, ICEMAXHOSTNAME); ! else ! strcpy(rev_hostname, hostname); ! for(int i=0; i<st; i++){ ! char *subtarget_hostname; ! subtarget_hostname = subtargets_addresses[i]; ! ! csubtarget *cst = new csubtarget(subtarget_hostname, rev_hostname, par, out, isnd); ! ! subtargets.push_back(cst); ! } ! delete rev_hostname; ! return st; } --- 38,58 ---- int st = get_ips_byhost(hostname, subtargets_addresses); ! icestring rev_hostname(hostname); ! //if((!is_domainname(hostname)) && par->reverse_dns){ ! // get_host_byip(hostname, rev_hostname, ICEMAXHOSTNAME); ! //}else{ ! //strcpy(rev_hostname, hostname); ! //} ! DBGOUTPUT(rev_hostname); ! for(int i=0; i<st; i++){ ! csubtarget *cst = new csubtarget(subtargets_addresses[i].c_str(), rev_hostname.c_str(), par, out, isnd); ! DBGOUTPUT(subtargets_addresses[i].c_str()); ! subtargets.push_back(cst); ! } ! ! return st; } *************** *** 83,87 **** for(int i=0; i<subtargets.size(); i++){ delete subtargets[i]; - delete subtargets_addresses[i]; } } --- 81,84 ---- |