⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 osscan2.cc

📁 Ubuntu packages of security software。 相当不错的源码
💻 CC
📖 第 1 页 / 共 5 页
字号:
/* These are statistics for the whole group of Targets */class ScanStats {public:  ScanStats();  /* Returns true if the system says that sending is OK. */  bool sendOK();  struct osscan_timing_vals timing;  struct timeout_info to; /* rtt/timeout info */    /* Total number of active probes */  int num_probes_active;  /* Number of probes sent in total. */  int num_probes_sent;  int num_probes_sent_at_last_wait;};/* * HostOsScan does the scan job, setting and using the status of a host in * the host's HostOsScanStats. */class HostOsScan{public:  HostOsScan(Target *t); /* OsScan need a target to set eth stuffs */  ~HostOsScan();    pcap_t *pd;  ScanStats *stats;    /* (Re)Initial the parameters that will be used during the scan.*/  void reInitScanSystem();  void buildSeqProbeList(HostOsScanStats *hss);  void updateActiveSeqProbes(HostOsScanStats *hss);    void buildTUIProbeList(HostOsScanStats *hss);  void updateActiveTUIProbes(HostOsScanStats *hss);  /* send the next probe in the probe list of the hss */  void sendNextProbe(HostOsScanStats *hss);    /* Process one response.   * If the response is useful, return true. */  bool processResp(HostOsScanStats *hss, struct ip *ip, unsigned int len, struct timeval *rcvdtime);    /* Make up the fingerprint. */  void makeFP(HostOsScanStats *hss);  /* Check whether the host is sendok. If not, fill _when_ with the   * time when it will be sendOK and return false; else, fill it with   * now and return true.   */  bool hostSendOK(HostOsScanStats *hss, struct timeval *when);  /* Check whether it is ok to send the next seq probe to the host. If   * not, fill _when_ with the time when it will be sendOK and return   * false; else, fill it with now and return true.   */  bool hostSeqSendOK(HostOsScanStats *hss, struct timeval *when);    /* How long I am currently willing to wait for a probe response     before considering it timed out.  Uses the host values from     target if they are available, otherwise from gstats.  Results     returned in MICROseconds.  */  unsigned long timeProbeTimeout(HostOsScanStats *hss);  /* If there are pending probe timeouts, fills in when with the time   * of the earliest one and returns true.  Otherwise returns false   * and puts now in when.   */  bool nextTimeout(HostOsScanStats *hss, struct timeval *when);  /* Adjust various timing variables based on pcket receipt. */  void adjust_times(HostOsScanStats *hss, OFProbe *probe, struct timeval *rcvdtime);private:  /* Probe send functions. */  void sendTSeqProbe(HostOsScanStats *hss, int probeNo);  void sendTOpsProbe(HostOsScanStats *hss, int probeNo);  void sendTEcnProbe(HostOsScanStats *hss);  void sendT1_7Probe(HostOsScanStats *hss, int probeNo);  void sendTUdpProbe(HostOsScanStats *hss, int probeNo);  void sendTIcmpProbe(HostOsScanStats *hss, int probeNo);  /* Response process functions. */  bool processTSeqResp(HostOsScanStats *hss, struct ip *ip, int replyNo);  bool processTOpsResp(HostOsScanStats *hss, struct tcp_hdr *tcp, int replyNo);  bool processTWinResp(HostOsScanStats *hss, struct tcp_hdr *tcp, int replyNo);  bool processTEcnResp(HostOsScanStats *hss, struct ip *ip);  bool processT1_7Resp(HostOsScanStats *hss, struct ip *ip, int replyNo);  bool processTUdpResp(HostOsScanStats *hss, struct ip *ip);  bool processTIcmpResp(HostOsScanStats *hss, struct ip *ip, int replyNo);  void makeTSeqFP(HostOsScanStats *hss);  void makeTOpsFP(HostOsScanStats *hss);  void makeTWinFP(HostOsScanStats *hss);  bool get_tcpopt_string(struct tcp_hdr *tcp, int mss, char *result, int maxlen);  int rawsd; /* raw socket descriptor */  struct eth_nfo eth;  struct eth_nfo *ethptr; /* for passing to send_ functions */    unsigned int tcpSeqBase, tcpAck; /* Seq&Ack value used in TCP probes */  int tcpMss; /* tcp Mss value used in TCP probes */  int udpttl; /* ttl value used in udp probe. */  unsigned short icmpEchoId, icmpEchoSeq; /* Icmp Echo Id&Seq value used in ICMP probes*/    /* Source port number in TCP probes. Different probe will use   * arbitrary offset value of it. */  int tcpPortBase;  int udpPortBase;};/*  * The overall os scan information of a host: *  - Fingerprints gotten from every scan round; *  - Maching results of these fingerprints. *  - Is it timeout/completed? *  - ... */class HostOsScanInfo{public:  HostOsScanInfo(Target *t, OsScanInfo *OSI);  ~HostOsScanInfo();    Target *target; /* the Target */  OsScanInfo *OSI; /* The OSI which contains this HostOsScanInfo */  FingerPrint **FPs; /* Fingerprints of the host */  FingerPrintResults *FP_matches; /* Fingerprint-matching results */  struct seq_info *si;  bool timedOut;  bool isCompleted;  HostOsScanStats *hss; /* Scan status of the host in one scan round */};/* * Maintain a link of incomplete HostOsScanInfo. */class OsScanInfo{public:  OsScanInfo(vector<Target *> &Targets);  ~OsScanInfo();    /* If you remove from this, you had better adjust nextI too (or call     resetHostIterator() afterward). Don't let this list get empty,     then add to it again, or you may mess up nextI (I'm not sure) */  list<HostOsScanInfo *> incompleteHosts;  unsigned int starttimems;  unsigned int numIncompleteHosts() {return incompleteHosts.size();}  HostOsScanInfo *findIncompleteHost(struct sockaddr_storage *ss);  /* A circular buffer of the incompleteHosts.  nextIncompleteHost() gives     the next one.  The first time it is called, it will give the     first host in the list.  If incompleteHosts is empty, returns     NULL. */  HostOsScanInfo *nextIncompleteHost();  /* Resets the host iterator used with nextIncompleteHost() to the     beginning.  If you remove a host from incompleteHosts, call this     right afterward */  void resetHostIterator() { nextI = incompleteHosts.begin(); }  int removeCompletedHosts();private:  unsigned int numInitialTargets;  list<HostOsScanInfo *>::iterator nextI;};OFProbe::OFProbe() {  type = OFP_UNSET;  subid = 0;  tryno = -1;  retransmitted = false;  memset(&sent, 0, sizeof(sent));  memset(&prevSent, 0, sizeof(prevSent));}const char *OFProbe::typestr() {  switch(type) {  case OFP_UNSET:	return "OFP_UNSET";  case OFP_TSEQ:	return "OFP_TSEQ";  case OFP_TOPS:	return "OFP_TOPS";  case OFP_TECN:	return "OFP_TECN";  case OFP_T1_7:	return "OFP_T1_7";  case OFP_TUDP:	return "OFP_TUDP";  case OFP_TICMP:	return "OFP_TICMP";  default:	assert(false);	return "ERROR";  }}HostOsScanStats::HostOsScanStats(Target * t) {  int i;    target = t;  FP = NULL;  memset(&si, 0, sizeof(si));  memset(&ipid, 0, sizeof(ipid));  openTCPPort = -1;  closedTCPPort = -1;  closedUDPPort = -1;  num_probes_sent = 0;  sendDelayMs = MAX(o.scan_delay, OS_PROBE_DELAY);  lastProbeSent = now;    /* timing */  timing.cwnd = perf.host_initial_cwnd;  timing.ccthresh = perf.initial_ccthresh; /* Will be reduced if any packets are dropped anyway */  timing.num_updates = 0;  gettimeofday(&timing.last_drop, NULL);    for (i=0; i<NUM_FPTESTS; i++)    FPtests[i] = NULL;  for (i=0; i<6; i++) {    TOps_AVs[i] = NULL;    TWin_AVs[i] = NULL;  }  fpPassed = true;  icmpEchoReply = NULL;  distance = -1;  distance_guess = -1;}HostOsScanStats::~HostOsScanStats() {  int i;    if(!fpPassed) {	for(i=0; i<NUM_FPTESTS; i++) {	  if(FPtests[i]) {		if(FPtests[i]->results) {		  free(FPtests[i]->results);		}		free(FPtests[i]);	  }	}	for(i=0; i<6; i++) {	  if(TOps_AVs[i]) free(TOps_AVs[i]);	  if(TWin_AVs[i]) free(TWin_AVs[i]);	}  }    while(!probesToSend.empty()) {    delete probesToSend.front();    probesToSend.pop_front();  }  while(!probesActive.empty()) {    delete probesActive.front();    probesActive.pop_front();  }  if (icmpEchoReply) free(icmpEchoReply);}void HostOsScanStats::initScanStats() {  Port *tport = NULL;  int i;  /* Lets find an open port to use if we don't already have one */  openTCPPort = -1;  /*  target->FPR->osscan_opentcpport = -1;  target->FPR->osscan_closedtcpport = -1;  target->FPR->osscan_closedudpport = -1; */    if (target->FPR->osscan_opentcpport > 0)    openTCPPort = target->FPR->osscan_opentcpport;  else if ((tport = target->ports.nextPort(NULL, IPPROTO_TCP, PORT_OPEN))) {    openTCPPort = tport->portno;    /* If it is zero, let's try another one if there is one ) */    if (tport->portno == 0)      if ((tport = target->ports.nextPort(tport, IPPROTO_TCP, PORT_OPEN)))	openTCPPort = tport->portno;           target->FPR->osscan_opentcpport = openTCPPort;  }  /* Now we should find a closed port */  if (target->FPR->osscan_closedtcpport > 0)    closedTCPPort = target->FPR->osscan_closedtcpport;  else if ((tport = target->ports.nextPort(NULL, IPPROTO_TCP, PORT_CLOSED))) {    closedTCPPort = tport->portno;    /* If it is zero, let's try another one if there is one ) */    if (tport->portno == 0)      if ((tport = target->ports.nextPort(tport, IPPROTO_TCP, PORT_CLOSED)))	closedTCPPort = tport->portno;    target->FPR->osscan_closedtcpport = closedTCPPort;  } else if ((tport = target->ports.nextPort(NULL, IPPROTO_TCP, PORT_UNFILTERED))) {    /* Well, we will settle for unfiltered */    closedTCPPort = tport->portno;    /* But again we'd prefer not to have zero */    if (tport->portno == 0)      if ((tport = target->ports.nextPort(tport, IPPROTO_TCP, PORT_UNFILTERED)))	closedTCPPort = tport->portno;  } else {    /* We'll just have to pick one at random :( */    closedTCPPort = (get_random_uint() % 14781) + 30000;  }  /* Now we should find a closed udp port */  if (target->FPR->osscan_closedudpport > 0)    closedUDPPort = target->FPR->osscan_closedudpport;  else if ((tport = target->ports.nextPort(NULL, IPPROTO_UDP, PORT_CLOSED))) {    closedUDPPort = tport->portno;    /* Not zero, if possible */    if (tport->portno == 0)      if ((tport = target->ports.nextPort(tport, IPPROTO_UDP, PORT_CLOSED)))	closedUDPPort = tport->portno;    target->FPR->osscan_closedudpport = closedUDPPort;  } else if ((tport = target->ports.nextPort(NULL, IPPROTO_UDP, PORT_UNFILTERED))) {    /* Well, we will settle for unfiltered */    closedUDPPort = tport->portno;    /* But not zero, please */    if (tport->portno == 0)      if ((tport = target->ports.nextPort(NULL, IPPROTO_UDP, PORT_UNFILTERED)))	closedUDPPort = tport->portno;  } else {    /* Pick one at random.  Shrug. */    closedUDPPort = (get_random_uint() % 14781) + 30000;  }  FP = NULL;  for (i=0; i<NUM_FPTESTS; i++)	FPtests[i] = NULL;  for (i=0; i<6; i++) {	TOps_AVs[i] = NULL;	TWin_AVs[i] = NULL;  }    fpPassed = false;	    TOpsReplyNum = 0;  TWinReplyNum = 0;  lastipid = 0;  memset(&si, 0, sizeof(si));  for (i=0; i<NUM_SEQ_SAMPLES; i++) {    ipid.tcp_ipids[i] = -1;    ipid.icmp_ipids[i] = -1;  }    memset(&seq_send_times, 0, sizeof(seq_send_times));  if (icmpEchoReply) {    free(icmpEchoReply);    icmpEchoReply = NULL;  }  storedIcmpReply = -1;  memset(&upi, 0, sizeof(upi));  }/* Add a probe to the probe list. */void HostOsScanStats::addNewProbe(OFProbeType type, int subid) {  OFProbe *probe = new OFProbe();  probe->type = type;  probe->subid = subid;  probesToSend.push_back(probe);}/* Remove a probe from the probesActive. */void HostOsScanStats::removeActiveProbe(list<OFProbe *>::iterator probeI) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -