~ubuntu-branches/ubuntu/oneiric/nmap/oneiric

« back to all changes in this revision

Viewing changes to output.cc

  • Committer: Bazaar Package Importer
  • Author(s): LaMont Jones, fyodor, Davide
  • Date: 2008-05-31 22:55:14 UTC
  • mfrom: (1.2.10 upstream) (3.1.2 lenny)
  • Revision ID: james.westby@ubuntu.com-20080531225514-dej22l1clq3nj2o3
Tags: 4.62-1
[fyodor]

* new upstream release

[Davide]

* create an desktop file for zenmap.  Closes: #457799
* remove useless file /usr/bin/uninstall_zenmap.  Closes: #474511

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
 * These restrictions only apply when you actually redistribute Nmap.  For *
43
43
 * example, nothing stops you from writing and selling a proprietary       *
44
44
 * front-end to Nmap.  Just distribute it by itself, and point people to   *
45
 
 * http://insecure.org/nmap/ to download Nmap.                             *
 
45
 * http://nmap.org to download Nmap.                                       *
46
46
 *                                                                         *
47
47
 * We don't consider these to be added restrictions on top of the GPL, but *
48
48
 * just a clarification of how we interpret "derived works" as it applies  *
81
81
 * Source code also allows you to port Nmap to new platforms, fix bugs,    *
82
82
 * and add new features.  You are highly encouraged to send your changes   *
83
83
 * to fyodor@insecure.org for possible incorporation into the main         *
84
 
 * distribution.  By sending these changes to Fyodor or one the            *
 
84
 * distribution.  By sending these changes to Fyodor or one of the         *
85
85
 * Insecure.Org development mailing lists, it is assumed that you are      *
86
86
 * offering Fyodor and Insecure.Com LLC the unlimited, non-exclusive right *
87
87
 * to reuse, modify, and relicense the code.  Nmap will always be          *
101
101
 *                                                                         *
102
102
 ***************************************************************************/
103
103
 
104
 
/* $Id: output.cc 6633 2007-12-22 06:32:03Z fyodor $ */
 
104
/* $Id: output.cc 7179 2008-04-23 22:42:41Z david $ */
105
105
 
106
106
#include "output.h"
107
107
#include "osscan.h"
123
123
using namespace std;
124
124
 
125
125
extern NmapOps o;
126
 
static char *logtypes[LOG_NUM_FILES]=LOG_NAMES;
 
126
static const char *logtypes[LOG_NUM_FILES]=LOG_NAMES;
127
127
 
128
128
/* Used in creating skript kiddie style output.  |<-R4d! */
129
129
static void skid_output(char *s)
430
430
  char grepvers[256];
431
431
  char grepown[64];
432
432
  char *p;
433
 
  char *state;
 
433
  const char *state;
434
434
  char serviceinfo[64];
435
435
  char *name=NULL;
436
436
  int i;
761
761
 
762
762
        int line = 0;
763
763
#ifdef WIN32
764
 
        char* sep = "\r\n";
 
764
        const char* sep = "\r\n";
765
765
#else
766
 
        char* sep = "\n";
 
766
        const char* sep = "\n";
767
767
#endif
768
768
        std::string line_prfx = "|  ";
769
769
        
794
794
}
795
795
#endif /* NOLUA */
796
796
 
 
797
 
 
798
/* Note that this escapes newlines, which is generally needed in
 
799
   attributes to avoid parser normalization, but might not be needed
 
800
   or desirable in XML content outside of attributes.  So if we find
 
801
   some cases where we don't want \r\n\t escaped, we'll have to add a
 
802
   parameter to control this. */
797
803
char* xml_convert (const char* str) {
798
804
  char *temp, ch=0, prevch = 0, *p;
799
805
  int strl = strlen(str);
800
806
  temp = (char *) safe_malloc(strl*6+1);
801
807
  char *end = temp + strl * 6 + 1;
802
808
  for (p = temp;(prevch = ch, ch = *str);str++) {
803
 
    char *a;
 
809
    const char *a;
804
810
    switch (ch) {
 
811
    case '\t':
 
812
      a = "&#x9;";
 
813
      break;
 
814
    case '\r':
 
815
      a = "&#xd;";
 
816
      break;
 
817
    case '\n':
 
818
      a = "&#xa;";
 
819
      break;
805
820
    case '<':
806
821
      a = "&lt;";
807
822
      break;
1131
1146
}
1132
1147
 
1133
1148
/* Simple helper function for output_xml_scaninfo_records */
1134
 
static void doscaninfo(char *type, char *proto, unsigned short *ports, 
 
1149
static void doscaninfo(const char *type, const char *proto, unsigned short *ports, 
1135
1150
                  int numports) {
1136
1151
  log_write(LOG_XML, "<scaninfo type=\"%s\" protocol=\"%s\" numservices=\"%d\" services=\"", type, proto, numports);
1137
1152
  output_rangelist_given_ports(LOG_XML, ports, numports);
1344
1359
    // Now to create the fodder for normal output
1345
1360
    for (classno=0; classno < OSR->OSC_num_matches; classno++) {
1346
1361
      /* We have processed enough if any of the following are true */
1347
 
      if (!guess && OSR->OSC_Accuracy[classno] < 1.0 ||
 
1362
      if ((!guess && OSR->OSC_Accuracy[classno] < 1.0) ||
1348
1363
          OSR->OSC_Accuracy[classno] <= OSR->OSC_Accuracy[0] - 0.1 ||
1349
 
          OSR->OSC_Accuracy[classno] < 1.0 && classno > 9)
 
1364
          (OSR->OSC_Accuracy[classno] < 1.0 && classno > 9))
1350
1365
        break;
1351
1366
      if (addtochararrayifnew(types, &numtypes, MAX_OS_CLASSMEMBERS, OSR->OSC[classno]->Device_Type) == -1)
1352
1367
        overflow = 1;
1437
1452
  char numlst[512]; /* For creating lists of numbers */
1438
1453
  char *p; /* Used in manipulating numlst above */
1439
1454
  FingerPrintResults *FPR;
1440
 
  int osscanSys = 0;
1441
1455
  int distance = -1;
1442
1456
  int osscan_flag;
1443
1457
  
1444
1458
  if (!(osscan_flag = currenths->osscanPerformed()))
1445
1459
    return;
1446
1460
   
1447
 
  if (currenths->FPR == NULL && currenths->FPR1 == NULL) {
 
1461
  if (currenths->FPR == NULL)
1448
1462
    return;
1449
 
  } else if (currenths->FPR != NULL && currenths->FPR1 == NULL) {
1450
 
    osscanSys = 2;
1451
 
    FPR = currenths->FPR;
1452
 
  } else if (currenths->FPR == NULL && currenths->FPR1 != NULL) {
1453
 
    osscanSys = 1;
1454
 
    FPR = currenths->FPR1;
1455
 
  }
1456
 
  else {
1457
 
    /* Neither is NULL. This happens when new OS scan system fails to
1458
 
       get a perfect match and falls back on the old OS scan
1459
 
       system. */
1460
 
    if (currenths->FPR->num_perfect_matches > 0) {
1461
 
      osscanSys = 2;
1462
 
      FPR = currenths->FPR; /* Just an ensurance. */
1463
 
    } else if (currenths->FPR1->num_perfect_matches > 0) {
1464
 
      osscanSys = 1;
1465
 
      FPR = currenths->FPR1;
1466
 
    } else if (currenths->FPR->overall_results == OSSCAN_SUCCESS) {
1467
 
      osscanSys = 2;
1468
 
      FPR = currenths->FPR;
1469
 
    } else if (currenths->FPR1->overall_results == OSSCAN_SUCCESS) {
1470
 
      osscanSys = 1;
1471
 
      FPR = currenths->FPR1;
1472
 
    } else {
1473
 
      /* Both fails. */
1474
 
      osscanSys = 2;
1475
 
      FPR = currenths->FPR;
1476
 
    }
1477
 
  }
 
1463
  FPR = currenths->FPR;
1478
1464
 
1479
1465
  if (currenths->distance != -1)
1480
1466
        distance = currenths->distance;
1566
1552
        }
1567
1553
        log_write(LOG_PLAIN, "\n");
1568
1554
      }
1569
 
      if (osscanSys == 2 && !reason) {
1570
 
        log_write(LOG_NORMAL|LOG_SKID_NOXLT|LOG_STDOUT,"No exact OS matches for host (If you know what OS is running on it, see http://insecure.org/nmap/submit/ ).\nTCP/IP fingerprint:\n%s\n",
 
1555
      if (!reason) {
 
1556
        log_write(LOG_NORMAL|LOG_SKID_NOXLT|LOG_STDOUT,"No exact OS matches for host (If you know what OS is running on it, see http://nmap.org/submit/ ).\nTCP/IP fingerprint:\n%s\n",
1571
1557
                  mergeFPs(FPR->FPs, FPR->numFPs, true,
1572
1558
                           currenths->v4hostip(), distance, currenths->MACAddress(),
1573
1559
                           FPR->osscan_opentcpport, FPR->osscan_closedtcpport, FPR->osscan_closedudpport,
1578
1564
          log_write(LOG_NORMAL|LOG_SKID_NOXLT|LOG_STDOUT,"No exact OS matches for host (test conditions non-ideal).");
1579
1565
          if (o.verbose > 1 || o.debugging)
1580
1566
            log_write(LOG_NORMAL|LOG_SKID_NOXLT|LOG_STDOUT, 
1581
 
                      "\nTCP/IP fingerprint by osscan system #%d:\n%s",
1582
 
                      osscanSys, mergeFPs(FPR->FPs, FPR->numFPs, false,
 
1567
                      "\nTCP/IP fingerprint:\n%s",
 
1568
                      mergeFPs(FPR->FPs, FPR->numFPs, false,
1583
1569
                                          currenths->v4hostip(), distance, currenths->MACAddress(),
1584
1570
                                          FPR->osscan_opentcpport, FPR->osscan_closedtcpport, FPR->osscan_closedudpport,
1585
1571
                                          false));
1601
1587
    const char *reason = FPR->OmitSubmissionFP();
1602
1588
    if ((o.verbose > 1 || o.debugging) && reason)
1603
1589
      log_write(LOG_NORMAL|LOG_SKID_NOXLT|LOG_STDOUT,"OS fingerprint not ideal because: %s\n", reason);
1604
 
    if (osscanSys == 2 && !reason) {
1605
 
      log_write(LOG_NORMAL|LOG_SKID_NOXLT|LOG_STDOUT,"No OS matches for host (If you know what OS is running on it, see http://insecure.org/nmap/submit/ ).\nTCP/IP fingerprint:\n%s\n",
 
1590
    if (!reason) {
 
1591
      log_write(LOG_NORMAL|LOG_SKID_NOXLT|LOG_STDOUT,"No OS matches for host (If you know what OS is running on it, see http://nmap.org/submit/ ).\nTCP/IP fingerprint:\n%s\n",
1606
1592
                mergeFPs(FPR->FPs, FPR->numFPs, true,
1607
1593
                         currenths->v4hostip(), distance, currenths->MACAddress(),
1608
1594
                         FPR->osscan_opentcpport, FPR->osscan_closedtcpport, FPR->osscan_closedudpport,
1610
1596
    } else {
1611
1597
      log_write(LOG_NORMAL|LOG_SKID_NOXLT|LOG_STDOUT,"No OS matches for host\n");
1612
1598
      if (o.verbose > 1)
1613
 
        log_write(LOG_NORMAL|LOG_SKID_NOXLT|LOG_STDOUT, "\nTCP/IP fingerprint by osscan system #%d:\n%s",
1614
 
                  osscanSys, mergeFPs(FPR->FPs, FPR->numFPs, false,
 
1599
        log_write(LOG_NORMAL|LOG_SKID_NOXLT|LOG_STDOUT, "\nTCP/IP fingerprint:\n%s",
 
1600
                  mergeFPs(FPR->FPs, FPR->numFPs, false,
1615
1601
                                      currenths->v4hostip(), distance, currenths->MACAddress(),
1616
1602
                                      FPR->osscan_opentcpport, FPR->osscan_closedtcpport, FPR->osscan_closedudpport,
1617
1603
                                      false));
1619
1605
  } else if (FPR->overall_results == OSSCAN_TOOMANYMATCHES || (FPR->num_perfect_matches > 8 && !o.debugging)) {
1620
1606
    log_write(LOG_PLAIN,"Too many fingerprints match this host to give specific OS details\n");
1621
1607
    if (o.debugging || o.verbose > 1) {
1622
 
      log_write(LOG_PLAIN,"TCP/IP fingerprint by osscan system #%d:\n%s",
1623
 
                osscanSys, mergeFPs(FPR->FPs, FPR->numFPs, false,
 
1608
      log_write(LOG_PLAIN,"TCP/IP fingerprint:\n%s",
 
1609
                mergeFPs(FPR->FPs, FPR->numFPs, false,
1624
1610
                                    currenths->v4hostip(), distance, currenths->MACAddress(),
1625
1611
                                    FPR->osscan_opentcpport, FPR->osscan_closedtcpport, FPR->osscan_closedudpport,
1626
1612
                                    false));
1628
1614
  } else { assert(0); }
1629
1615
  
1630
1616
  if (o.debugging || o.verbose) {
1631
 
    char *xml_osfp = xml_convert(mergeFPs(FPR->FPs, FPR->numFPs, false,
 
1617
    char *xml_osfp = xml_convert(mergeFPs(FPR->FPs, FPR->numFPs, !reason,
1632
1618
                                 currenths->v4hostip(), distance, currenths->MACAddress(),
1633
1619
                                 FPR->osscan_opentcpport, FPR->osscan_closedtcpport, FPR->osscan_closedudpport,
1634
 
                                 false));
1635
 
    log_write(LOG_XML,"<osfingerprint fingerprint=\"\n%s\" />\n", xml_osfp);
 
1620
                                 !reason));
 
1621
    log_write(LOG_XML,"<osfingerprint fingerprint=\"%s\" />\n", xml_osfp);
1636
1622
    free(xml_osfp);
1637
1623
  }
1638
1624
  
1663
1649
      while(*p) p++;
1664
1650
    }
1665
1651
    
1666
 
    log_write(LOG_XML, "<tcpsequence index=\"%li\" class=\"%s\" difficulty=\"%s\" values=\"%s\" />\n", (long) currenths->seq.index, seqclass2ascii(currenths->seq.seqclass), seqidx2difficultystr(currenths->seq.index), numlst); 
1667
 
    if (o.verbose) {
1668
 
      if (osscanSys == 1)
1669
 
        log_write(LOG_PLAIN,"%s", seqreport1(&(currenths->seq)));
1670
 
      else if(osscanSys == 2)
1671
 
        log_write(LOG_PLAIN,"%s", seqreport(&(currenths->seq)));
1672
 
    }
 
1652
    log_write(LOG_XML, "<tcpsequence index=\"%li\" difficulty=\"%s\" values=\"%s\" />\n", (long) currenths->seq.index, seqidx2difficultystr(currenths->seq.index), numlst); 
 
1653
    if (o.verbose)
 
1654
      log_write(LOG_PLAIN,"%s", seqreport(&(currenths->seq)));
1673
1655
    
1674
1656
    log_write(LOG_MACHINE,"\tSeq Index: %d", currenths->seq.index);
1675
1657
  }
1723
1705
  char hostname_tbl[MAX_SERVICE_INFO_FIELDS][MAXHOSTNAMELEN];
1724
1706
  char ostype_tbl[MAX_SERVICE_INFO_FIELDS][64];
1725
1707
  char devicetype_tbl[MAX_SERVICE_INFO_FIELDS][64];
1726
 
  char *delim;
 
1708
  const char *delim;
1727
1709
 
1728
1710
  for (i=0; i<MAX_SERVICE_INFO_FIELDS; i++)
1729
1711
    hostname_tbl[i][0] = ostype_tbl[i][0] = devicetype_tbl[i][0] = '\0';
1842
1824
  
1843
1825
  log_write(LOG_STDOUT, 
1844
1826
            "Stats: %d:%02d:%02d elapsed; %d hosts completed (%d up), %d undergoing %s\n", 
1845
 
            time/60/24, time/60 % 24, time % 60, o.numhosts_scanned - o.numhosts_scanning, 
 
1827
            time/60/60, time/60 % 60, time % 60, o.numhosts_scanned - o.numhosts_scanning, 
1846
1828
            o.numhosts_up, o.numhosts_scanning, scantype2str(o.current_scantype));
1847
1829
}
1848
1830
 
1869
1851
    log_write(LOG_STDOUT, "Note: Host seems down. If it is really up, but blocking our ping probes, try -PN\n");
1870
1852
  else if (o.numhosts_up > 0) {
1871
1853
    if (o.osscan && o.servicescan)
1872
 
      log_write(LOG_PLAIN, "OS and Service detection performed. Please report any incorrect results at http://insecure.org/nmap/submit/ .\n");
 
1854
      log_write(LOG_PLAIN, "OS and Service detection performed. Please report any incorrect results at http://nmap.org/submit/ .\n");
1873
1855
    else if (o.osscan)
1874
 
      log_write(LOG_PLAIN, "OS detection performed. Please report any incorrect results at http://insecure.org/nmap/submit/ .\n");
 
1856
      log_write(LOG_PLAIN, "OS detection performed. Please report any incorrect results at http://nmap.org/submit/ .\n");
1875
1857
    else if (o.servicescan)
1876
 
      log_write(LOG_PLAIN, "Service detection performed. Please report any incorrect results at http://insecure.org/nmap/submit/ .\n");
 
1858
      log_write(LOG_PLAIN, "Service detection performed. Please report any incorrect results at http://nmap.org/submit/ .\n");
1877
1859
  }
1878
1860
 
1879
1861
  log_write(LOG_STDOUT|LOG_SKID, "Nmap done: %d %s (%d %s up) scanned in %.3f seconds\n", o.numhosts_scanned, (o.numhosts_scanned == 1)? "IP address" : "IP addresses", o.numhosts_up, (o.numhosts_up == 1)? "host" : "hosts",  o.TimeSinceStartMS(&tv) / 1000.0);
1975
1957
    /* If all the files were from the same directory and we're in verbose mode,
1976
1958
       print a brief message unless we are also in debugging mode. */
1977
1959
    log_write(LOG_PLAIN, "Read data files from: %s\n", dir.c_str());
1978
 
  } else if (num_dirs == 1 && o.debugging || num_dirs > 1) {
 
1960
  } else if ( (num_dirs == 1 && o.debugging) || num_dirs > 1) {
1979
1961
    /* If files were read from more than one directory, or if they were read
1980
1962
       from one directory and we are in debugging mode, display all the files
1981
1963
       grouped by directory. */