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

📄 output.cc

📁 Ubuntu packages of security software。 相当不错的源码
💻 CC
📖 第 1 页 / 共 5 页
字号:
/*************************************************************************** * output.cc -- Handles the Nmap output system.  This currently involves   * * console-style human readable output, XML output, Script |<iddi3         * * output, and the legacy greppable output (used to be called "machine     * * readable").  I expect that future output forms (such as HTML) may be    * * created by a different program, library, or script using the XML        * * output.                                                                 * *                                                                         * ***********************IMPORTANT NMAP LICENSE TERMS************************ *                                                                         * * The Nmap Security Scanner is (C) 1996-2006 Insecure.Com LLC. Nmap is    * * also a registered trademark of Insecure.Com LLC.  This program is free  * * software; you may redistribute and/or modify it under the terms of the  * * GNU General Public License as published by the Free Software            * * Foundation; Version 2 with the clarifications and exceptions described  * * below.  This guarantees your right to use, modify, and redistribute     * * this software under certain conditions.  If you wish to embed Nmap      * * technology into proprietary software, we sell alternative licenses      * * (contact sales@insecure.com).  Dozens of software vendors already       * * license Nmap technology such as host discovery, port scanning, OS       * * detection, and version detection.                                       * *                                                                         * * Note that the GPL places important restrictions on "derived works", yet * * it does not provide a detailed definition of that term.  To avoid       * * misunderstandings, we consider an application to constitute a           * * "derivative work" for the purpose of this license if it does any of the * * following:                                                              * * o Integrates source code from Nmap                                      * * o Reads or includes Nmap copyrighted data files, such as                * *   nmap-os-fingerprints or nmap-service-probes.                          * * o Executes Nmap and parses the results (as opposed to typical shell or  * *   execution-menu apps, which simply display raw Nmap output and so are  * *   not derivative works.)                                                *  * o Integrates/includes/aggregates Nmap into a proprietary executable     * *   installer, such as those produced by InstallShield.                   * * o Links to a library or executes a program that does any of the above   * *                                                                         * * The term "Nmap" should be taken to also include any portions or derived * * works of Nmap.  This list is not exclusive, but is just meant to        * * clarify our interpretation of derived works with some common examples.  * * These restrictions only apply when you actually redistribute Nmap.  For * * example, nothing stops you from writing and selling a proprietary       * * front-end to Nmap.  Just distribute it by itself, and point people to   * * http://insecure.org/nmap/ to download Nmap.                             * *                                                                         * * We don't consider these to be added restrictions on top of the GPL, but * * just a clarification of how we interpret "derived works" as it applies  * * to our GPL-licensed Nmap product.  This is similar to the way Linus     * * Torvalds has announced his interpretation of how "derived works"        * * applies to Linux kernel modules.  Our interpretation refers only to     * * Nmap - we don't speak for any other GPL products.                       * *                                                                         * * If you have any questions about the GPL licensing restrictions on using * * Nmap in non-GPL works, we would be happy to help.  As mentioned above,  * * we also offer alternative license to integrate Nmap into proprietary    * * applications and appliances.  These contracts have been sold to dozens  * * of software vendors, and generally include a perpetual license as well  * * as providing for priority support and updates as well as helping to     * * fund the continued development of Nmap technology.  Please email        * * sales@insecure.com for further information.                             * *                                                                         * * As a special exception to the GPL terms, Insecure.Com LLC grants        * * permission to link the code of this program with any version of the     * * OpenSSL library which is distributed under a license identical to that  * * listed in the included Copying.OpenSSL file, and distribute linked      * * combinations including the two. You must obey the GNU GPL in all        * * respects for all of the code used other than OpenSSL.  If you modify    * * this file, you may extend this exception to your version of the file,   * * but you are not obligated to do so.                                     * *                                                                         * * If you received these files with a written license agreement or         * * contract stating terms other than the terms above, then that            * * alternative license agreement takes precedence over these comments.     * *                                                                         * * Source is provided to this software because we believe users have a     * * right to know exactly what a program is going to do before they run it. * * This also allows you to audit the software for security holes (none     * * have been found so far).                                                * *                                                                         * * Source code also allows you to port Nmap to new platforms, fix bugs,    * * and add new features.  You are highly encouraged to send your changes   * * to fyodor@insecure.org for possible incorporation into the main         * * distribution.  By sending these changes to Fyodor or one the            * * Insecure.Org development mailing lists, it is assumed that you are      * * offering Fyodor and Insecure.Com LLC the unlimited, non-exclusive right * * to reuse, modify, and relicense the code.  Nmap will always be          * * available Open Source, but this is important because the inability to   * * relicense code has caused devastating problems for other Free Software  * * projects (such as KDE and NASM).  We also occasionally relicense the    * * code to third parties as discussed above.  If you wish to specify       * * special license conditions of your contributions, just say so when you  * * send them.                                                              * *                                                                         * * This program is distributed in the hope that it will be useful, but     * * WITHOUT ANY WARRANTY; without even the implied warranty of              * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       * * General Public License for more details at                              * * http://www.gnu.org/copyleft/gpl.html , or in the COPYING file included  * * with Nmap.                                                              * *                                                                         * ***************************************************************************//* $Id: output.cc 4228 2006-12-08 03:01:08Z fyodor $ */#include "output.h"#include "osscan.h"#include "NmapOps.h"#include "NmapOutputTable.h"#include "MACLookup.h"#include <string>/* Workaround for lack of namespace std on HP-UX 11.00 */namespace std {};using namespace std;extern NmapOps o;static char *logtypes[LOG_NUM_FILES]=LOG_NAMES;/* Used in creating skript kiddie style output.  |<-R4d! */static void skid_output(char *s){  int i;  for (i=0;s[i];i++)    if (rand()%2==0)      /* Substitutions commented out are not known to me, but maybe look nice */      switch(s[i])	{	case 'A': s[i]='4'; break;	  /*	case 'B': s[i]='8'; break;	 	case 'b': s[i]='6'; break;	        case 'c': s[i]='k'; break;	        case 'C': s[i]='K'; break; */	case 'e':	case 'E': s[i]='3'; break;	case 'i':	case 'I': s[i]="!|1"[rand()%3]; break;	  /*      case 'k': s[i]='c'; break;	        case 'K': s[i]='C'; break;*/	case 'o':	case 'O': s[i]='0'; break;	case 's':	case 'S': 	  if (s[i+1] && !isalnum((int) s[i+1])) 	    s[i] = 'z';	  else s[i] = '$';	  break;	case 'z': s[i]='s'; break;	case 'Z': s[i]='S'; break;	}      else      {	if (s[i]>='A' && s[i]<='Z' && (rand()%3==0)) s[i]+='a'-'A';	else if (s[i]>='a' && s[i]<='z' && (rand()%3==0)) s[i]-='a'-'A';      }}/* Remove all "\nSF:" from fingerprints */static char* xml_sf_convert (const char* str) {  char *temp = (char *) safe_malloc(strlen(str) + 1);  char *dst = temp, *src = (char *)str;  char *ampptr = 0;  int charcount = 0;  while(*src && charcount < 2035) { /* 2048 - 14 */    if (strncmp(src, "\nSF:", 4) == 0) {      src += 4;      continue;    }    /* Needed so "&something;" is not truncated midway */    if (*src == '&') {      ampptr = dst;    }    else if (*src == ';') {      ampptr = 0;    }    *dst++ = *src++;    charcount++;  }  if (ampptr != 0) {    *ampptr = '\0';  }  else {    *dst = '\0';  }  return temp;}// Creates an XML <service> element for the information given in// serviceDeduction.  It will be 0-length if none is neccessary.// returns 0 for success.static int getServiceXMLBuf(struct serviceDeductions *sd, char *xmlbuf, 		     unsigned int xmlbuflen) {  string versionxmlstring;  char rpcbuf[128];  char *xml_product = NULL, *xml_version = NULL, *xml_extrainfo = NULL;  char *xml_hostname = NULL, *xml_ostype = NULL, *xml_devicetype = NULL;  char *xml_servicefp = NULL, *xml_servicefp_temp = NULL;  if (xmlbuflen < 1) return -1;  xmlbuf[0] = '\0';    if (!sd->name && !sd->service_fp) return 0;  if (sd->product) {    xml_product = xml_convert(sd->product);    versionxmlstring += " product=\"";    versionxmlstring += xml_product;    free(xml_product); xml_product = NULL;    versionxmlstring += '\"';  }  if (sd->version) {    xml_version = xml_convert(sd->version);    versionxmlstring += " version=\"";    versionxmlstring += xml_version;    free(xml_version); xml_version = NULL;    versionxmlstring += '\"';  }  if (sd->extrainfo) {    xml_extrainfo = xml_convert(sd->extrainfo);    versionxmlstring += " extrainfo=\"";    versionxmlstring += xml_extrainfo;    free(xml_extrainfo); xml_extrainfo = NULL;    versionxmlstring += '\"';  }  if (sd->hostname) {    xml_hostname = xml_convert(sd->hostname);    versionxmlstring += " hostname=\"";    versionxmlstring += xml_hostname;    free(xml_hostname); xml_hostname = NULL;    versionxmlstring += '\"';  }  if (sd->ostype) {    xml_ostype = xml_convert(sd->ostype);    versionxmlstring += " ostype=\"";    versionxmlstring += xml_ostype;    free(xml_ostype); xml_ostype = NULL;    versionxmlstring += '\"';  }  if (sd->devicetype) {    xml_devicetype = xml_convert(sd->devicetype);    versionxmlstring += " devicetype=\"";    versionxmlstring += xml_devicetype;    free(xml_devicetype); xml_devicetype = NULL;    versionxmlstring += '\"';  }  if (sd->service_fp) {    xml_servicefp_temp = xml_convert(sd->service_fp);    xml_servicefp = xml_sf_convert(xml_servicefp_temp);    versionxmlstring += " servicefp=\"";    versionxmlstring += xml_servicefp;    free(xml_servicefp_temp); xml_servicefp_temp = NULL;    free(xml_servicefp); xml_servicefp = NULL;    versionxmlstring += '\"';  }  if (o.rpcscan && sd->rpc_status == RPC_STATUS_GOOD_PROG) {    snprintf(rpcbuf, sizeof(rpcbuf), 	     " rpcnum=\"%li\" lowver=\"%i\" highver=\"%i\" proto=\"rpc\"", 	     sd->rpc_program, sd->rpc_lowver, sd->rpc_highver);  } else rpcbuf[0] = '\0';  snprintf(xmlbuf, xmlbuflen, 	   "<service name=\"%s\"%s %smethod=\"%s\" conf=\"%d\"%s />", 	   sd->name? sd->name : "unknown",	   versionxmlstring.c_str(),	   (sd->service_tunnel == SERVICE_TUNNEL_SSL)? "tunnel=\"ssl\" " : "",	   (sd->dtype == SERVICE_DETECTION_TABLE)? "table" : "probed", 	   sd->name_confidence, rpcbuf);  return 0;}/* Print a detailed list of Nmap interfaces and routes to   normal/skiddy/stdout output */int print_iflist(void) {  int numifs = 0, numroutes = 0;  struct interface_info *iflist;  struct sys_route *routes;  NmapOutputTable *Tbl = NULL;  iflist = getinterfaces(&numifs);  int i;  /* First let's handle interfaces ... */  if (numifs == 0) {    log_write(LOG_NORMAL|LOG_SKID|LOG_STDOUT, "INTERFACES: NONE FOUND(!)\n");  } else {    int devcol=0, shortdevcol=1, ipcol=2, typecol = 3, upcol = 4, maccol = 5;    Tbl = new NmapOutputTable( numifs+1, 6 );    Tbl->addItem(0, devcol, false, "DEV", 3);    Tbl->addItem(0, shortdevcol, false, "(SHORT)", 7);    Tbl->addItem(0, ipcol, false, "IP/MASK", 7);    Tbl->addItem(0, typecol, false, "TYPE", 4);    Tbl->addItem(0, upcol, false, "UP", 2);    Tbl->addItem(0, maccol, false, "MAC", 3);    for(i=0; i < numifs; i++) {      Tbl->addItem(i+1, devcol, false, iflist[i].devfullname);      Tbl->addItemFormatted(i+1, shortdevcol, "(%s)", iflist[i].devname);      Tbl->addItemFormatted(i+1, ipcol, "%s/%d", inet_ntop_ez(&(iflist[i].addr), sizeof(iflist[i].addr)), iflist[i].netmask_bits);      if (iflist[i].device_type == devt_ethernet) {	Tbl->addItem(i+1, typecol, false, "ethernet");	Tbl->addItemFormatted(i+1, maccol, "%02X:%02X:%02X:%02X:%02X:%02X",  iflist[i].mac[0], iflist[i].mac[1], iflist[i].mac[2], iflist[i].mac[3], iflist[i].mac[4], iflist[i].mac[5]);	      }      else if (iflist[i].device_type == devt_loopback)	Tbl->addItem(i+1, typecol, false, "loopback");      else if (iflist[i].device_type == devt_p2p)	Tbl->addItem(i+1, typecol, false, "point2point");      else Tbl->addItem(i+1, typecol, false, "other");      Tbl->addItem(i+1, upcol, false, (iflist[i].device_up? "up" : "down"));    }    log_write(LOG_NORMAL|LOG_SKID|LOG_STDOUT, "************************INTERFACES************************\n");    log_write(LOG_NORMAL|LOG_SKID|LOG_STDOUT, "%s\n", Tbl->printableTable(NULL));    log_flush_all();    delete Tbl;  }  /* OK -- time to handle routes */  routes = getsysroutes(&numroutes);  u32 mask_nbo;  u16 nbits;  struct in_addr ia;  if (numroutes == 0) {    log_write(LOG_NORMAL|LOG_SKID|LOG_STDOUT, "ROUTES: NONE FOUND(!)\n");

⌨️ 快捷键说明

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