1 2 /*************************************************************************** 3 * output.h -- Handles the Nmap output system. This currently involves * 4 * console-style human readable output, XML output, Script |<iddi3 * 5 * output, and the legacy grepable output (used to be called "machine * 6 * readable"). I expect that future output forms (such as HTML) may be * 7 * created by a different program, library, or script using the XML * 8 * output. * 9 * * 10 ***********************IMPORTANT NMAP LICENSE TERMS************************ 11 * * 12 * The Nmap Security Scanner is (C) 1996-2020 Insecure.Com LLC ("The Nmap * 13 * Project"). Nmap is also a registered trademark of the Nmap Project. * 14 * * 15 * This program is distributed under the terms of the Nmap Public Source * 16 * License (NPSL). The exact license text applying to a particular Nmap * 17 * release or source code control revision is contained in the LICENSE * 18 * file distributed with that version of Nmap or source code control * 19 * revision. More Nmap copyright/legal information is available from * 20 * https://nmap.org/book/man-legal.html, and further information on the * 21 * NPSL license itself can be found at https://nmap.org/npsl. This header * 22 * summarizes some key points from the Nmap license, but is no substitute * 23 * for the actual license text. * 24 * * 25 * Nmap is generally free for end users to download and use themselves, * 26 * including commercial use. It is available from https://nmap.org. * 27 * * 28 * The Nmap license generally prohibits companies from using and * 29 * redistributing Nmap in commercial products, but we sell a special Nmap * 30 * OEM Edition with a more permissive license and special features for * 31 * this purpose. See https://nmap.org/oem * 32 * * 33 * If you have received a written Nmap license agreement or contract * 34 * stating terms other than these (such as an Nmap OEM license), you may * 35 * choose to use and redistribute Nmap under those terms instead. * 36 * * 37 * The official Nmap Windows builds include the Npcap software * 38 * (https://npcap.org) for packet capture and transmission. It is under * 39 * separate license terms which forbid redistribution without special * 40 * permission. So the official Nmap Windows builds may not be * 41 * redistributed without special permission (such as an Nmap OEM * 42 * license). * 43 * * 44 * Source is provided to this software because we believe users have a * 45 * right to know exactly what a program is going to do before they run it. * 46 * This also allows you to audit the software for security holes. * 47 * * 48 * Source code also allows you to port Nmap to new platforms, fix bugs, * 49 * and add new features. You are highly encouraged to submit your * 50 * changes as a Github PR or by email to the dev@nmap.org mailing list * 51 * for possible incorporation into the main distribution. Unless you * 52 * specify otherwise, it is understood that you are offering us very * 53 * broad rights to use your submissions as described in the Nmap Public * 54 * Source License Contributor Agreement. This is important because we * 55 * fund the project by selling licenses with various terms, and also * 56 * because the inability to relicense code has caused devastating * 57 * problems for other Free Software projects (such as KDE and NASM). * 58 * * 59 * The free version of Nmap is distributed in the hope that it will be * 60 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of * 61 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. Warranties, * 62 * indemnification and commercial support are all available through the * 63 * Npcap OEM program--see https://nmap.org/oem. * 64 * * 65 ***************************************************************************/ 66 67 /* $Id: output.h 38078 2020-10-02 16:12:22Z dmiller $ */ 68 69 #ifndef OUTPUT_H 70 #define OUTPUT_H 71 72 #include <nbase.h> // __attribute__ 73 74 #define LOG_NUM_FILES 4 /* # of values that actual files (they must come first */ 75 #define LOG_FILE_MASK 15 /* The mask for log types in the file array */ 76 #define LOG_NORMAL 1 77 #define LOG_MACHINE 2 78 #define LOG_SKID 4 79 #define LOG_XML 8 80 #define LOG_STDOUT 1024 81 #define LOG_STDERR 2048 82 #define LOG_SKID_NOXLT 4096 83 #define LOG_MAX LOG_SKID_NOXLT /* The maximum log type value */ 84 85 #define LOG_PLAIN LOG_NORMAL|LOG_SKID|LOG_STDOUT 86 87 #define LOG_NAMES {"normal", "machine", "$Cr!pT |<!dd!3", "XML"} 88 89 #define PCAP_OPEN_ERRMSG "Call to pcap_open_live() failed three times. "\ 90 "There are several possible reasons for this, depending on your operating "\ 91 "system:\nLINUX: If you are getting Socket type not supported, try "\ 92 "modprobe af_packet or recompile your kernel with PACKET enabled.\n "\ 93 "*BSD: If you are getting device not configured, you need to recompile "\ 94 "your kernel with Berkeley Packet Filter support. If you are getting "\ 95 "No such file or directory, try creating the device (eg cd /dev; "\ 96 "MAKEDEV <device>; or use mknod).\n*WINDOWS: Nmap only supports "\ 97 "ethernet interfaces on Windows for most operations because Microsoft "\ 98 "disabled raw sockets as of Windows XP SP2. Depending on the reason for "\ 99 "this error, it is possible that the --unprivileged command-line argument "\ 100 "will help.\nSOLARIS: If you are trying to scan localhost or the "\ 101 "address of an interface and are getting '/dev/lo0: No such file or "\ 102 "directory' or 'lo0: No DLPI device found', complain to Sun. I don't "\ 103 "think Solaris can support advanced localhost scans. You can probably "\ 104 "use \"-Pn -sT localhost\" though.\n\n" 105 106 #include "scan_lists.h" 107 #ifndef NOLUA 108 #include "nse_main.h" 109 #endif 110 class PortList; 111 class Target; 112 113 #include <stdarg.h> 114 #include <string> 115 116 #if TIME_WITH_SYS_TIME 117 # include <sys/time.h> 118 # include <time.h> 119 #else 120 # if HAVE_SYS_TIME_H 121 # include <sys/time.h> 122 # else 123 # include <time.h> 124 # endif 125 #endif 126 127 #ifdef WIN32 128 /* Show a fatal error explaining that an interface is not Ethernet and won't 129 work on Windows. Do nothing if --send-ip (PACKET_SEND_IP_STRONG) was used. */ 130 void win32_fatal_raw_sockets(const char *devname); 131 #endif 132 133 /* Prints the familiar Nmap tabular output showing the "interesting" 134 ports found on the machine. It also handles the Machine/Grepable 135 output and the XML output. It is pretty ugly -- in particular I 136 should write helper functions to handle the table creation */ 137 void printportoutput(Target *currenths, PortList *plist); 138 139 /* Prints the MAC address if one was found for the target (generally 140 this means that the target is directly connected on an ethernet 141 network. This only prints to human output -- XML is handled by a 142 separate call ( print_MAC_XML_Info ) because it needs to be printed 143 in a certain place to conform to DTD. */ 144 void printmacinfo(Target *currenths); 145 146 char *logfilename(const char *str, struct tm *tm); 147 148 /* Write some information (printf style args) to the given log stream(s). 149 Remember to watch out for format string bugs. */ 150 void log_write(int logt, const char *fmt, ...) 151 __attribute__ ((format (printf, 2, 3))); 152 153 /* This is the workhorse of the logging functions. Usually it is 154 called through log_write(), but it can be called directly if you 155 are dealing with a vfprintf-style va_list. Unlike log_write, YOU 156 CAN ONLY CALL THIS WITH ONE LOG TYPE (not a bitmask full of them). 157 In addition, YOU MUST SANDWICH EACH EXECUTION OF THIS CALL BETWEEN 158 va_start() AND va_end() calls. */ 159 void log_vwrite(int logt, const char *fmt, va_list ap); 160 161 /* Close the given log stream(s) */ 162 void log_close(int logt); 163 164 /* Flush the given log stream(s). In other words, all buffered output 165 is written to the log immediately */ 166 void log_flush(int logt); 167 168 /* Flush every single log stream -- all buffered output is written to the 169 corresponding logs immediately */ 170 void log_flush_all(); 171 172 /* Open a log descriptor of the type given to the filename given. If 173 append is nonzero, the file will be appended instead of clobbered if 174 it already exists. If the file does not exist, it will be created */ 175 int log_open(int logt, bool append, char *filename); 176 177 /* Output the list of ports scanned to the top of machine parseable 178 logs (in a comment, unfortunately). The items in ports should be 179 in sequential order for space savings and easier to read output */ 180 void output_ports_to_machine_parseable_output(struct scan_lists *ports); 181 182 /* Return a std::string containing all n strings separated by whitespace, and 183 individually quoted if needed. */ 184 std::string join_quoted(const char * const strings[], unsigned int n); 185 186 /* Similar to output_ports_to_machine_parseable_output, this function 187 outputs the XML version, which is scaninfo records of each scan 188 requested and the ports which it will scan for */ 189 void output_xml_scaninfo_records(struct scan_lists *ports); 190 191 /* Writes a heading for a full scan report ("Nmap scan report for..."), 192 including host status and DNS records. */ 193 void write_host_header(Target *currenths); 194 195 /* Writes host status info to the log streams (including STDOUT). An 196 example is "Host: 10.11.12.13 (foo.bar.example.com)\tStatus: Up\n" to 197 machine log. */ 198 void write_host_status(Target *currenths); 199 200 /* Writes host status info to the XML stream wrapped in a <hosthint> tag */ 201 void write_xml_hosthint(Target *currenths); 202 203 /* Prints the formatted OS Scan output to stdout, logfiles, etc (but only 204 if an OS Scan was performed */ 205 void printosscanoutput(Target *currenths); 206 207 /* Prints the alternate hostname/OS/device information we got from the 208 service scan (if it was performed) */ 209 void printserviceinfooutput(Target *currenths); 210 211 #ifndef NOLUA 212 std::string protect_xml(const std::string s); 213 214 /* Use this function to report NSE_PRE_SCAN and NSE_POST_SCAN results */ 215 void printscriptresults(ScriptResults *scriptResults, stype scantype); 216 217 void printhostscriptresults(Target *currenths); 218 #endif 219 220 /* Print a table with traceroute hops. */ 221 void printtraceroute(Target *currenths); 222 223 /* Print "times for host" output with latency. */ 224 void printtimes(Target *currenths); 225 226 /* Print a detailed list of Nmap interfaces and routes to 227 normal/skiddy/stdout output */ 228 int print_iflist(void); 229 230 /* Prints a status message while the program is running */ 231 void printStatusMessage(); 232 233 void print_xml_finished_open(time_t timep, const struct timeval *tv); 234 235 void print_xml_hosts(); 236 237 /* Prints the statistics and other information that goes at the very end 238 of an Nmap run */ 239 void printfinaloutput(); 240 241 /* Prints the names of data files that were loaded and the paths at which they 242 were found. */ 243 void printdatafilepaths(); 244 245 /* nsock logging interface */ 246 void nmap_adjust_loglevel(bool trace); 247 void nmap_set_nsock_logger(); 248 249 #endif /* OUTPUT_H */ 250 251