diff -Nraupb nmap-4.20ALPHA4/gse/gse.cc nmap-4.20ALPHA4-gse/gse/gse.cc --- nmap-4.20ALPHA4/gse/gse.cc 1970-01-01 01:00:00.000000000 +0100 +++ nmap-4.20ALPHA4-gse/gse/gse.cc 2006-07-17 04:30:48.000000000 +0200 @@ -0,0 +1,193 @@ + +#include +#include "../nmap.h" +#include "host.h" +#include "gse.h" +#include "gse_connection.h" + +using namespace std; + + +void gse_scan_target( + CHAIN *chain, int chainlen, + HOST *target, int conn_max, + u16 *portarr,int portarrlen, u8 protocol) +{ + + GSEConnection **conn_poll = (GSEConnection **)safe_zalloc(sizeof(GSEConnection*) * conn_max); + + int portnum=0; // pointer to ports already scanned or beeing scanned + int null_connections = 0; + + assert(chainlen>0); + + static nsock_pool nsp; + nsp = nsp_new(&nsp); + + struct timeval now; + gettimeofday(&now, NULL); +#if DEBUG > 0 + nsp_settrace(nsp, DEBUG, &now); +#else + nsp_settrace(nsp, DEBUG, &now); +#endif + + do{ + null_connections = 0; + int any_changed = 0; + for(int i=0; iget_state()){ + case GSS_DEAD: + error("WARNING: Connection #%i: removing (dead)", i); + delete conn_poll[i]; + conn_poll[i] = NULL; + break; + case GSS_WAITING_FOR_INPUT: + // Are we in the last hop? + if(conn->chain_built()){ // last hop -> query for target! + // some ports left to scan + if(portnum < portarrlen){ + error("WARNING: Connection #%i: succeded, scanning host %s:%c%i", i, + target->tostr() , protocol==IPPROTO_TCP?'T':'U', portarr[portnum]); + conn->querynewport(target, portarr[portnum++], protocol); + }else{ + error("WARNING: Connection #%i: succeded, no more ports to scan. removing", i); + delete conn_poll[i]; + conn_poll[i] = NULL; + } + }else{ // middle hop + error("WARNING: Connection #%i: connecting to next hop", i); + conn->query_nexthop(); + } + break; + case GSS_WAITING_FOR_OUTPUT: + // read the status. + ggt = conn->getportstatus(); + + // is event from the last hop? + if(conn->chain_built()){ + error("WARNING: CONNECTION #%i: SCANNED HOST %s:%c%i is %s:%s", i, + ggt.hostname, ggt.protocol==IPPROTO_TCP?'T':'U', ggt.port, + gse_reason_tostr(ggt.reason), ggt.reason_txt); + }else{ + if(ggt.reason != GSER_OPENED) + error("WARNING: Connection #%i: hop is in state %s:%s", + i, gse_reason_tostr(ggt.reason), ggt.reason_txt); + } + if(ggt.reason == GSER_GW_ERROR){ + error("Sorry, you have some problems with proxies"); + abort(); + } + break; + case GSS_ALIVE: // connected!!! +// error("WARNING: Connection #%i: alive", i); + // is event from the last hop? + if(conn->chain_built()){ // last hop -> just kill connection + delete conn_poll[i]; + conn_poll[i] = NULL; + }else{ // middle hop, go to the next one :) + conn->jump_nexthop(); + } + break; + default: + sth_changed = false; + } // switch + sth_changed = false; + + any_changed++; + } //while sth_changed + } // for i + if(any_changed+null_connections<=conn_max) + nsock_loop(nsp, 400); + }while(null_connections != conn_max);// any more descriptors in poll? + error("WARNING: Scan sucessfully completed."); + nsp_delete(nsp); +} + + + + +void gse_generic_handler(nsock_pool nsp, nsock_event nse, void *ud){ + nsock_iod nsi = nse_iod(nse); + enum nse_status status = nse_status(nse); + enum nse_type type = nse_type(nse); + + GSEProxy_Interface *gpi = (GSEProxy_Interface*) ud; + GSEConnection *conn = (GSEConnection *)nsi_getud(nsi); + assert(gpi); + + switch(status){ + case NSE_STATUS_SUCCESS: + switch(type){ + case NSE_TYPE_CONNECT: + gpi->handler(GSEE_CONNECT, nse); + break; + case NSE_TYPE_READ: + gpi->handler(GSEE_READ, nse); + break; + case NSE_TYPE_WRITE: + break; + default: + break; + } + break; + case NSE_STATUS_EOF: + gpi->handler(GSEE_EOF, nse); + break; + case NSE_STATUS_ERROR: + switch(type){ + case NSE_TYPE_CONNECT: + gpi->handler(GSEE_EOF, nse); + break; + default: + error("WARN: generic_handler: BAD CALLBACK type %s with status %s on %s (%s %s)", nse_type2str(type), nse_status2str(status), + gpi->tostr(), nse_type2str(type), strerror(socket_errno())); + }; + break; + case NSE_STATUS_TIMEOUT: + gpi->handler(GSEE_TIMEOUT, nse); + break; + case NSE_STATUS_KILL: + case NSE_STATUS_CANCELLED: + break; + default: // which includes NSE_STATUS_ERROR: + assert(0); + } +} + + + + +char *gse_reason_tostr(enum gse_reasons reason){ + switch(reason){ + case GSER_OPENED: + return("opened"); + case GSER_CLOSED: + return("closed"); + case GSER_FILTERED: + return("filtered"); + case GSER_GW_ERROR: + return("gateway_error"); + case GSER_GW_FILTERED: + return("gateway_filtered"); + case GSER_NONE: + return("none"); + } + return("unknown"); +} + diff -Nraupb nmap-4.20ALPHA4/gse/gse_connection.h nmap-4.20ALPHA4-gse/gse/gse_connection.h --- nmap-4.20ALPHA4/gse/gse_connection.h 1970-01-01 01:00:00.000000000 +0100 +++ nmap-4.20ALPHA4-gse/gse/gse_connection.h 2006-07-17 04:30:48.000000000 +0200 @@ -0,0 +1,82 @@ +#ifndef GSE_CONNECITON_H_ +#define GSE_CONNECITON_H_ + +#include "gse.h" +#include "gsei__interface.h" +#include "gsei_nsock.h" +#include "gsei_httpconnect.h" + + +class GSEConnection{ + private: + GSEProxy_Interface **proxy_poll; // array of pointers + int proxy_poll_len; + int proxy_current; + CHAIN *chain; + + nsock_pool nsp; + nsock_iod nsi; + public: + enum gse_states get_state(){ + return(proxy_poll[proxy_current]->state); + } + bool chain_built(){ + if(proxy_current >= proxy_poll_len-1) + return(true); + return(false); + } + void query_nexthop(){ + assert(proxy_current+1 < proxy_poll_len); + querynewport( chain[proxy_current+1].px_host, + chain[proxy_current+1].px_port, + IPPROTO_TCP); + }; + void jump_nexthop(){ + build_hop(++proxy_current); // :) + }; + + void querynewport(HOST *host, u16 port, u8 proto){ + proxy_poll[proxy_current]->querynewport(host, port, proto); + } + + struct gse_gps_tmp getportstatus(){ + return(proxy_poll[proxy_current]->getportstatus()); + } + private: + void build_hop(int i){ + GSEProxy_Interface *iface = NULL; + switch(chain[i].engine){ + case GSEENG_NSOCK: + assert(i==0); + iface = new GSEProxy_NSock(&nsi, &nsp); + break; + case GSEENG_HTTPCONNECT: + iface = new GSEProxy_HttpConnect(&nsi, &nsp); + break; + default: + assert(0); + } + iface->set_chain(&chain[i]); + proxy_poll[i] = iface; + } + public: + GSEConnection(CHAIN *nchain, int chainlen, nsock_pool nnsp){ + assert(nchain); + assert(nnsp); + proxy_poll = (class GSEProxy_Interface **)malloc(sizeof(class GSEProxy_Interface*)*chainlen); + proxy_poll_len = chainlen; + chain = nchain; + proxy_current = 0; + nsp = nnsp; + nsi = nsi_new(nnsp, this); + build_hop(0); + } + ~GSEConnection(){ + for(int i=0;i +void error(const char *fmt, ...); + +/* +Chain: array of GSE_Chain (CHAIN) objects. + This contains addresses and types of hops. + This is what user specified. + +Connection: object GSEConnection + It's used handle exacly one socket descriptor + and many GSEProxy_Interface objects + +Proxy: object that's used for making connection to specified type + of proxy. + + + +*/ + +// Available scanning engines. +enum gse_engines{ + GSEENG_UNINITIALISED, + GSEENG_NSOCK, + GSEENG_HTTPCONNECT, +}; + + +// +enum gse_states{ + GSS_UNINITIALISED= 0, // state when proxy was not initialised + GSS_INTERNAL_STATE_0, + GSS_INTERNAL_STATE_1, + GSS_INTERNAL_STATE_2, + GSS_INTERNAL_STATE_3, + GSS_WAITING_FOR_INPUT, // we are waiting for 'querynewport()' + GSS_WAITING_FOR_OUTPUT, // we are waiting for 'getportstatus()' + GSS_DEAD, // socket needs to be closed + GSS_ALIVE, // socket is connected now to the target's port. +}; +enum gse_reasons{ + GSER_NONE, + GSER_GW_ERROR, // gateway unreachable or bad credentials + GSER_GW_FILTERED,// gateway is blocking connection to this port + GSER_CLOSED, // port is closed + GSER_OPENED, // port is opened + GSER_FILTERED, // port is filtered (packets are lost) +}; + + + +typedef struct GSE_Chain CHAIN; +struct GSE_Chain{ + // THIS PROXY DATA + u16 px_port; // port number, only TCP + HOST *px_host; // host address + + long timeout_ms; // timeout for that proxy + enum gse_engines engine; // engine type +}; + + + + + + + + +// Main scanning command. +void gse_scan_target( + CHAIN *chain, int chainlen, + HOST *target, int conn_max, + u16 *portarr,int portarrlen, u8 protocol); + +char *gse_reason_tostr(enum gse_reasons reason); + +void gse_generic_handler(nsock_pool nsp, nsock_event nse, void *ud); + +#endif /*GSE_H_*/ diff -Nraupb nmap-4.20ALPHA4/gse/gsei_httpconnect.cc nmap-4.20ALPHA4-gse/gse/gsei_httpconnect.cc --- nmap-4.20ALPHA4/gse/gsei_httpconnect.cc 1970-01-01 01:00:00.000000000 +0100 +++ nmap-4.20ALPHA4-gse/gse/gsei_httpconnect.cc 2006-07-17 04:30:48.000000000 +0200 @@ -0,0 +1,135 @@ +#include "../nmap.h" +#include "host.h" +#include "gse.h" +#include "gsei__interface.h" +#include "gsei_httpconnect.h" + +/* http://ai.pjwstk.edu.pl/~majek/private/nmap/state-httpconnect.png */ + +void GSEProxy_HttpConnect::handler(enum gse_events event,nsock_event nse){ + char *rec; + char buf[256]; + int rec_len=0; + int http_code; + + switch(state){ + case GSS_INTERNAL_STATE_0: + assert(event == GSEE_NOEVENT); + state = GSS_WAITING_FOR_INPUT; + break; + case GSS_INTERNAL_STATE_1: + switch(event){ + case GSEE_NOEVENT:{ + snprintf(buf, sizeof(buf), + "CONNECT %s:%i HTTP/1.1\n" + "Proxy-Connection: Keep-Alive\n" + "Host: %s:%i\n" + "\n", + target_host->tostr(), target_port, + target_host->tostr(), target_port); + nsock_write(*nsp, *nsi, + gse_generic_handler, chain->timeout_ms, + this, buf, strlen(buf)); + + nsock_read(*nsp, *nsi, + gse_generic_handler, chain->timeout_ms, + this);// two lines + } + break; + case GSEE_EOF: + assert(chain); + snprintf(reason_txt, sizeof(reason_txt), "Gateway %s:%i closed connection!", chain->px_host->tostr(), chain->px_port); + reason = GSER_GW_ERROR; + state = GSS_WAITING_FOR_OUTPUT; + break; + case GSEE_TIMEOUT: + assert(chain); + snprintf(reason_txt, sizeof(reason_txt), "Gateway %s:%i timeouted!", chain->px_host->tostr(), chain->px_port); + reason = GSER_GW_ERROR; + state = GSS_WAITING_FOR_OUTPUT; + break; + case GSEE_READ: + state = GSS_INTERNAL_STATE_2; + handler(GSEE_NOEVENT, nse); + break; + default: + assert(0); + } + + break; + case GSS_INTERNAL_STATE_2: + assert(event == GSEE_NOEVENT); + // data is ready for reading + assert(nse); + rec = nse_readbuf(nse, &rec_len); + if(rec_len<12){ + reason = GSER_GW_ERROR; + state = GSS_WAITING_FOR_OUTPUT; + break; + } + + // maybe we should use regexp? + http_code = atoi(&rec[9]); + if(http_code == 403){ + reason = GSER_GW_FILTERED; + state = GSS_WAITING_FOR_OUTPUT; + }else if(http_code == 503){ + reason = GSER_CLOSED; + state = GSS_WAITING_FOR_OUTPUT; + }else if(http_code == 200){ + reason = GSER_OPENED; + state = GSS_WAITING_FOR_OUTPUT; + }else{ + assert(chain); + snprintf(reason_txt, sizeof(reason_txt), "I can't understand HTTP code %i on gateway %s:%i!", http_code, chain->px_host->tostr(), chain->px_port); + reason = GSER_GW_ERROR; + state = GSS_DEAD; + } + break; + case GSS_WAITING_FOR_OUTPUT: + case GSS_WAITING_FOR_INPUT: + case GSS_DEAD: + case GSS_ALIVE: + default: + assert(0); + break; + } +} + +void GSEProxy_HttpConnect::querynewport(HOST *host, u16 port, u8 proto){ + assert(state == GSS_WAITING_FOR_INPUT); + + assert(proto == IPPROTO_TCP); + GSEProxy_Interface::querynewport(host, port, proto); + + state = GSS_INTERNAL_STATE_1; + // execute INTERNAL_STATE_1 + handler(GSEE_NOEVENT, NULL); +} + +struct gse_gps_tmp GSEProxy_HttpConnect::getportstatus(){ + struct gse_gps_tmp ggt; + assert(state == GSS_WAITING_FOR_OUTPUT); + + + if(reason==GSER_GW_FILTERED){ + // we can repeat probe :) + state = GSS_WAITING_FOR_INPUT; + + }else if(reason==GSER_OPENED){ + state = GSS_ALIVE; + }else + state = GSS_DEAD; + ggt = GSEProxy_Interface::getportstatus(); + if(state == GSS_WAITING_FOR_INPUT){ + target_port = 0; + target_proto = 0; + if(target_host){ +// delete target_host; + target_host = NULL; + } + } + + return(ggt); +} + diff -Nraupb nmap-4.20ALPHA4/gse/gsei_httpconnect.h nmap-4.20ALPHA4-gse/gse/gsei_httpconnect.h --- nmap-4.20ALPHA4/gse/gsei_httpconnect.h 1970-01-01 01:00:00.000000000 +0100 +++ nmap-4.20ALPHA4-gse/gse/gsei_httpconnect.h 2006-07-17 04:30:48.000000000 +0200 @@ -0,0 +1,24 @@ +#ifndef GSEI_HTTPCONNECT_H_ +#define GSEI_HTTPCONNECT_H_ + +#include "gsei__interface.h" + +/* http://ai.pjwstk.edu.pl/~majek/private/nmap/state-httpconnect.png */ + +class GSEProxy_HttpConnect: public GSEProxy_Interface{ + +public: + void handler(enum gse_events event,nsock_event nse); + void querynewport(HOST *host, u16 port, u8 proto); + struct gse_gps_tmp getportstatus(); + +public: + GSEProxy_HttpConnect(nsock_iod *ni, nsock_pool *np): GSEProxy_Interface(ni,np){ + state = GSS_INTERNAL_STATE_0; + handler(GSEE_NOEVENT, NULL); + }; + ~GSEProxy_HttpConnect(){}; + +}; + +#endif /*GSEI_HTTPCONNECT_H_*/ diff -Nraupb nmap-4.20ALPHA4/gse/gsei__interface.cc nmap-4.20ALPHA4-gse/gse/gsei__interface.cc --- nmap-4.20ALPHA4/gse/gsei__interface.cc 1970-01-01 01:00:00.000000000 +0100 +++ nmap-4.20ALPHA4-gse/gse/gsei__interface.cc 2006-07-17 04:30:48.000000000 +0200 @@ -0,0 +1,53 @@ +#include "../nmap.h" +#include "host.h" +#include "gse.h" +#include "gsei__interface.h" + + +void GSEProxy_Interface::handler(enum gse_events event, nsock_event nse){ + error("This handler never should be runned directly!"); + assert(0); +} + +void GSEProxy_Interface::querynewport(HOST *host, u16 port, u8 proto){ + assert(state == GSS_WAITING_FOR_INPUT); + + assert(host); + + target_proto = IPPROTO_TCP; + target_port = port; + target_host = host; +} + +struct gse_gps_tmp GSEProxy_Interface::getportstatus(){ + struct gse_gps_tmp ggt; + memset(&ggt, 0, sizeof(ggt)); + + strncpy(ggt.hostname, target_host->tostr(), sizeof(ggt.hostname)); + ggt.port = target_port; + ggt.protocol = target_proto; + ggt.reason = reason; + strncpy(ggt.reason_txt, reason_txt, sizeof(ggt.reason_txt)); + + //clean up + reason_txt[0]='\0'; + reason = GSER_NONE; + + return(ggt); +} + + +void GSEProxy_Interface::set_chain(CHAIN *nchain){ + chain = nchain; +} + +GSEProxy_Interface::GSEProxy_Interface(nsock_iod *ni, nsock_pool *np){ + nsi = ni; + nsp = np; + reason = GSER_NONE; + reason_txt[0] = '\0'; +} +GSEProxy_Interface::~GSEProxy_Interface(){ + //if(target_host) + // delete target_host; +} diff -Nraupb nmap-4.20ALPHA4/gse/gsei__interface.h nmap-4.20ALPHA4-gse/gse/gsei__interface.h --- nmap-4.20ALPHA4/gse/gsei__interface.h 1970-01-01 01:00:00.000000000 +0100 +++ nmap-4.20ALPHA4-gse/gse/gsei__interface.h 2006-07-17 04:30:48.000000000 +0200 @@ -0,0 +1,58 @@ +#ifndef GSEI__INTERFACE_H_ +#define GSEI__INTERFACE_H_ + +enum gse_events{ + GSEE_NOEVENT, // event handler executed 'by hand', from program (beware dead loops!) + GSEE_READ, // some data received + GSEE_TIMEOUT, // timeouted + GSEE_EOF, + GSEE_CONNECT, +}; + +struct gse_gps_tmp{ + char hostname[32]; + u16 port; + u8 protocol; + enum gse_reasons reason; + char reason_txt[64]; +}; + + +class GSEProxy_Interface{ +protected: + // TARGET'S DATA + u8 target_proto; // IPPROTO_TCP or IPPROTO_UDP + u16 target_port; // port number + HOST *target_host; // host address + nsock_iod *nsi; + nsock_pool *nsp; + + enum gse_reasons reason; // is port opened or closed? + char reason_txt[64]; // description (for errors) + +public: + // + enum gse_states state; // current state + + char *tostr(){ + static char a[64]; + snprintf(a,sizeof(a),"%s:%c%i", + target_host->tostr(), target_proto==IPPROTO_TCP?'T':'U', target_port); + return(a); + } + // WARN: don't free this! + struct GSE_Chain *chain; +public: + /* THESE THRE MUST BE OVERLOADED */ + virtual void handler(enum gse_events event,nsock_event nse); + virtual void querynewport(HOST *host, u16 port, u8 proto); + virtual struct gse_gps_tmp getportstatus(); + + // you don't have to overload this + void set_chain(CHAIN *nchain); +public: + GSEProxy_Interface(nsock_iod *ni,nsock_pool *np); + virtual ~GSEProxy_Interface(); +}; + +#endif /*GSEI__INTERFACE_H_*/ diff -Nraupb nmap-4.20ALPHA4/gse/gsei_nsock.cc nmap-4.20ALPHA4-gse/gse/gsei_nsock.cc --- nmap-4.20ALPHA4/gse/gsei_nsock.cc 1970-01-01 01:00:00.000000000 +0100 +++ nmap-4.20ALPHA4-gse/gse/gsei_nsock.cc 2006-07-17 04:30:48.000000000 +0200 @@ -0,0 +1,81 @@ +#include "../nmap.h" +#include "host.h" +#include "gse.h" +#include "gsei__interface.h" +#include "gsei_nsock.h" + +/* http://ai.pjwstk.edu.pl/~majek/private/nmap/state-nsock.png */ + +void GSEProxy_NSock::handler(enum gse_events event,nsock_event nse){ + + switch(state){ + case GSS_INTERNAL_STATE_0: + assert(event == GSEE_NOEVENT); + state = GSS_WAITING_FOR_INPUT; + break; + case GSS_INTERNAL_STATE_1: + switch(event){ + case GSEE_NOEVENT: + assert(target_host); + assert(chain); + nsock_connect_tcp( + *nsp, *nsi, + gse_generic_handler, + chain->timeout_ms, + this, /* user data ! */ + target_host->get_sa(), + target_host->get_sa_size(), + target_port); + reason = GSER_NONE; + break; + case GSEE_TIMEOUT: + snprintf(reason_txt, sizeof(reason_txt), "%s timeouted!", tostr()); + reason = GSER_FILTERED; + state = GSS_WAITING_FOR_OUTPUT; + break; + case GSEE_EOF: + reason = GSER_CLOSED; + state = GSS_WAITING_FOR_OUTPUT; + break; + case GSEE_CONNECT: + reason = GSER_OPENED; + state = GSS_WAITING_FOR_OUTPUT; + break; + default: + assert(0); + } + break; + case GSS_WAITING_FOR_OUTPUT: + case GSS_WAITING_FOR_INPUT: + case GSS_DEAD: + case GSS_ALIVE: + default: + assert(0); + break; + } +} + +void GSEProxy_NSock::querynewport(HOST *host, u16 port, u8 proto){ + assert(state == GSS_WAITING_FOR_INPUT); + + assert(proto == IPPROTO_TCP); + GSEProxy_Interface::querynewport(host, port, proto); + + state = GSS_INTERNAL_STATE_1; + // execute INTERNAL_STATE_1 + handler(GSEE_NOEVENT, NULL); +} + +struct gse_gps_tmp GSEProxy_NSock::getportstatus(){ + struct gse_gps_tmp ggt; + assert(state == GSS_WAITING_FOR_OUTPUT); + + if(reason == GSER_OPENED) + state = GSS_ALIVE; + else + state = GSS_DEAD; + + ggt = GSEProxy_Interface::getportstatus(); + return(ggt); +} + diff -Nraupb nmap-4.20ALPHA4/gse/gsei_nsock.h nmap-4.20ALPHA4-gse/gse/gsei_nsock.h --- nmap-4.20ALPHA4/gse/gsei_nsock.h 1970-01-01 01:00:00.000000000 +0100 +++ nmap-4.20ALPHA4-gse/gse/gsei_nsock.h 2006-07-17 04:30:48.000000000 +0200 @@ -0,0 +1,25 @@ +#ifndef GSEI_NSOCK_H_ +#define GSEI_NSOCK_H_ + +#include "gsei__interface.h" + +/* http://ai.pjwstk.edu.pl/~majek/private/nmap/state-nsock.png */ + +class GSEProxy_NSock: public GSEProxy_Interface{ + +public: + void handler(enum gse_events event,nsock_event nse); + void querynewport(HOST *host, u16 port, u8 proto); + struct gse_gps_tmp getportstatus(); + +public: + GSEProxy_NSock(nsock_iod *ni, nsock_pool *np): GSEProxy_Interface(ni,np){ + state = GSS_INTERNAL_STATE_0; + handler(GSEE_NOEVENT, NULL); + }; + ~GSEProxy_NSock(){}; + +}; + + +#endif /*GSEI_NSOCK_H_*/ diff -Nraupb nmap-4.20ALPHA4/gse/host.cc nmap-4.20ALPHA4-gse/gse/host.cc --- nmap-4.20ALPHA4/gse/host.cc 1970-01-01 01:00:00.000000000 +0100 +++ nmap-4.20ALPHA4-gse/gse/host.cc 2006-07-17 04:30:48.000000000 +0200 @@ -0,0 +1 @@ + diff -Nraupb nmap-4.20ALPHA4/gse/host.h nmap-4.20ALPHA4-gse/gse/host.h --- nmap-4.20ALPHA4/gse/host.h 1970-01-01 01:00:00.000000000 +0100 +++ nmap-4.20ALPHA4-gse/gse/host.h 2006-07-17 04:30:48.000000000 +0200 @@ -0,0 +1,88 @@ +#ifndef HOST_H_ +#define HOST_H_ + +class Host{ +private: + int af; // AF_UNKNOWN, AF_INET, AF_INET6 + u8 *ip; // ip. 4 bytes used for ipv4, 16 bytes used for ipv6 + char *hostname; // not resolved dns name. + + void resolve(){ + char tmp[16]; + assert(hostname); + if(ip) + return; + if(inet_pton(AF_INET, hostname, &tmp)>0){ + af = AF_INET; + ip = (u8*) malloc(4); + memcpy(ip, &tmp, 4); + return; + } + if(inet_pton(AF_INET6, hostname, &tmp)>0){ + af = AF_INET6; + ip = (u8*) malloc(16); + memcpy(ip, &tmp, 16); + return; + } + error("Resolving hostnames is not possible yet"); + abort(); + } +public: + sockaddr* get_sa(){ + static struct sockaddr_in sin; + static struct sockaddr_in6 sin6; + if(!ip) + resolve(); + if(!ip) + return(0); + if(af==AF_INET){ + sin.sin_family = AF_INET; + memcpy(&sin.sin_addr, ip, 4); + return((sockaddr*)&sin); + } + if(af==AF_INET6){ + sin6.sin6_family = AF_INET6; + memcpy(&sin6.sin6_addr, ip, 16); + return((sockaddr*)&sin6); + } + return(NULL); + } + size_t get_sa_size(){ + if(!ip) + resolve(); + if(!ip) + return(0); + if(af==AF_INET6) + return(sizeof(struct sockaddr_in6)); + return(sizeof(struct sockaddr_in)); + } + char *tostr(){ + static char sip[128]; + + + if(ip){ + assert(af==AF_INET || af==AF_INET6); + if(inet_ntop(af, ip, sip, sizeof(sip))==NULL) + assert(0); + return(sip); + } + return(hostname); + } + char *get_hostname(){ + return(hostname); + } + +public: + Host(char * nhostname){ + hostname = strdup(nhostname); + ip=NULL; + } + ~Host(){ +// if(hostname) +// free(hostname); + } +}; +typedef Host HOST; + + +#endif /*HOST_H_*/ diff -Nraupb nmap-4.20ALPHA4/gse/main.cc nmap-4.20ALPHA4-gse/gse/main.cc --- nmap-4.20ALPHA4/gse/main.cc 1970-01-01 01:00:00.000000000 +0100 +++ nmap-4.20ALPHA4-gse/gse/main.cc 2006-07-17 04:30:48.000000000 +0200 @@ -0,0 +1,49 @@ + +#include +#include "../nmap.h" +#include "host.h" +#include "gse.h" + +void error(const char *fmt, ...) { + va_list ap; + char buf[128]; + va_start(ap, fmt); + vsnprintf(buf, sizeof(buf),fmt,ap); + va_end(ap); + + printf("%s\n",buf); + return; +} + + +int main(){ + struct GSE_Chain chain[5]; + + chain[0].engine = GSEENG_NSOCK; + chain[0].timeout_ms = 1000; + + chain[1].px_port = 8080; + chain[1].px_host = new HOST("192.168.1.1"); + chain[1].engine = GSEENG_HTTPCONNECT; + chain[1].timeout_ms = 1000; + + chain[2].px_port = 8080; + chain[2].px_host = new HOST("192.168.1.4"); + chain[2].engine = GSEENG_HTTPCONNECT; + chain[2].timeout_ms = 1000; + + chain[3].px_port = 8080; + chain[3].px_host = new HOST("192.168.1.1"); + chain[3].engine = GSEENG_HTTPCONNECT; + chain[3].timeout_ms = 1000; + + // this chain struct would be linked somewhere + // in the memory!!! + u16 portarr[] = {1,2,3,4,5,22,80,443,8080}; + + gse_scan_target(chain, 4, + new HOST("192.168.1.1"), 1, + portarr, sizeof(portarr)/sizeof(u16), + IPPROTO_TCP); +} + diff -Nraupb nmap-4.20ALPHA4/gse/make nmap-4.20ALPHA4-gse/gse/make --- nmap-4.20ALPHA4/gse/make 1970-01-01 01:00:00.000000000 +0100 +++ nmap-4.20ALPHA4-gse/gse/make 2006-07-17 04:34:38.000000000 +0200 @@ -0,0 +1,5 @@ +#!/bin/sh +g++ -g -O2 -DHAVE_CONFIG_H -W -Wall -I.. \ +-I../libdnet-stripped/include -I../libpcre -I../libpcap -I../nbase -I../nsock/include -I.. \ +gsei_httpconnect.cc gse.cc host.cc gsei__interface.cc gsei_nsock.cc main.cc \ +-L../nsock/src -lnsock -lssl -L../nbase -lnbase -DDEBUG=0 -o gse