mirror of
https://github.com/nmap/nmap.git
synced 2025-12-17 13:09:02 +00:00
Adding Snprintf() and Vsnprintf() to nbase/nbase_str.c. This is because of Windows' stupid implementation where it doesn't write a NULL byte at the end of the buffer if the result is truncated. I would've just #defined snprintf and vsnprintf to some wrapper function for Windows, but this doesn't work as libdnet and libpcap (and libpcap includes under mswin32) define snprintf to _snprintf and vsnprintf to _vsnprintf like we do, and through the many defines they end up being available in the Nmap sources. Vsnprintf() uses vsnprintf() (and writes a NULL byte at the end if truncated), and Snprintf uses Vsnprintf().
This commit is contained in:
@@ -146,7 +146,7 @@ const char *FingerPrintResults::OmitSubmissionFP() {
|
|||||||
static char reason[128];
|
static char reason[128];
|
||||||
|
|
||||||
if (o.scan_delay > 500) { // This can screw up the sequence timing
|
if (o.scan_delay > 500) { // This can screw up the sequence timing
|
||||||
snprintf(reason, sizeof(reason), "Scan delay (%d) is greater than 500", o.scan_delay);
|
Snprintf(reason, sizeof(reason), "Scan delay (%d) is greater than 500", o.scan_delay);
|
||||||
return reason;
|
return reason;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -164,17 +164,17 @@ const char *FingerPrintResults::OmitSubmissionFP() {
|
|||||||
used to mean the distance is unknown, though there's a chance it could
|
used to mean the distance is unknown, though there's a chance it could
|
||||||
have come from the distance calculation. */
|
have come from the distance calculation. */
|
||||||
if (distance < -1) {
|
if (distance < -1) {
|
||||||
snprintf(reason, sizeof(reason), "Host distance (%d network hops) appears to be negative", distance);
|
Snprintf(reason, sizeof(reason), "Host distance (%d network hops) appears to be negative", distance);
|
||||||
return reason;
|
return reason;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (distance > 5) {
|
if (distance > 5) {
|
||||||
snprintf(reason, sizeof(reason), "Host distance (%d network hops) is greater than five", distance);
|
Snprintf(reason, sizeof(reason), "Host distance (%d network hops) is greater than five", distance);
|
||||||
return reason;
|
return reason;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (maxTimingRatio > 1.4) {
|
if (maxTimingRatio > 1.4) {
|
||||||
snprintf(reason, sizeof(reason), "maxTimingRatio (%e) is greater than 1.4", maxTimingRatio);
|
Snprintf(reason, sizeof(reason), "maxTimingRatio (%e) is greater than 1.4", maxTimingRatio);
|
||||||
return reason;
|
return reason;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -248,7 +248,7 @@ void NmapOps::Initialize() {
|
|||||||
#if WIN32
|
#if WIN32
|
||||||
Strncpy(tmpxsl, "nmap.xsl", sizeof(tmpxsl));
|
Strncpy(tmpxsl, "nmap.xsl", sizeof(tmpxsl));
|
||||||
#else
|
#else
|
||||||
snprintf(tmpxsl, sizeof(tmpxsl), "%s/nmap.xsl", NMAPDATADIR);
|
Snprintf(tmpxsl, sizeof(tmpxsl), "%s/nmap.xsl", NMAPDATADIR);
|
||||||
#endif
|
#endif
|
||||||
if (xsl_stylesheet) free(xsl_stylesheet);
|
if (xsl_stylesheet) free(xsl_stylesheet);
|
||||||
xsl_stylesheet = strdup(tmpxsl);
|
xsl_stylesheet = strdup(tmpxsl);
|
||||||
|
|||||||
@@ -199,7 +199,7 @@ void NmapOutputTable::addItemFormatted(unsigned int row,
|
|||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap,fmt);
|
va_start(ap,fmt);
|
||||||
char buf[4096];
|
char buf[4096];
|
||||||
res = vsnprintf(buf, sizeof(buf), fmt, ap);
|
res = Vsnprintf(buf, sizeof(buf), fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
if (res > sizeof(buf))
|
if (res > sizeof(buf))
|
||||||
|
|||||||
@@ -317,7 +317,7 @@ const char *Target::NameIP(char *buf, size_t buflen) {
|
|||||||
assert(buf);
|
assert(buf);
|
||||||
assert(buflen > 8);
|
assert(buflen > 8);
|
||||||
if (hostname) {
|
if (hostname) {
|
||||||
snprintf(buf, buflen, "%s (%s)", hostname, targetipstring);
|
Snprintf(buf, buflen, "%s (%s)", hostname, targetipstring);
|
||||||
} else Strncpy(buf, targetipstring, buflen);
|
} else Strncpy(buf, targetipstring, buflen);
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -398,7 +398,7 @@ static void initialize_idleproxy(struct idle_proxy_info *proxy, char *proxyName,
|
|||||||
|
|
||||||
p = strdup(proxy->host.targetipstr());
|
p = strdup(proxy->host.targetipstr());
|
||||||
q = strdup(inet_ntoa(proxy->host.v4source()));
|
q = strdup(inet_ntoa(proxy->host.v4source()));
|
||||||
snprintf(filter, sizeof(filter), "tcp and src host %s and dst host %s and src port %hu", p, q, proxy->probe_port);
|
Snprintf(filter, sizeof(filter), "tcp and src host %s and dst host %s and src port %hu", p, q, proxy->probe_port);
|
||||||
free(p);
|
free(p);
|
||||||
free(q);
|
free(q);
|
||||||
set_pcap_filter(proxy->host.deviceName(), proxy->pd, filter);
|
set_pcap_filter(proxy->host.deviceName(), proxy->pd, filter);
|
||||||
@@ -978,7 +978,7 @@ void idle_scan(Target *target, u16 *portarray, int numports,
|
|||||||
int portsleft;
|
int portsleft;
|
||||||
time_t starttime;
|
time_t starttime;
|
||||||
char scanname[32];
|
char scanname[32];
|
||||||
snprintf(scanname, sizeof(scanname), "Idlescan against %s", target->NameIP());
|
Snprintf(scanname, sizeof(scanname), "Idlescan against %s", target->NameIP());
|
||||||
ScanProgressMeter SPM(scanname);
|
ScanProgressMeter SPM(scanname);
|
||||||
|
|
||||||
if (numports == 0) return; /* nothing to scan for */
|
if (numports == 0) return; /* nothing to scan for */
|
||||||
@@ -1032,7 +1032,7 @@ void idle_scan(Target *target, u16 *portarray, int numports,
|
|||||||
|
|
||||||
|
|
||||||
char additional_info[14];
|
char additional_info[14];
|
||||||
snprintf(additional_info, sizeof(additional_info), "%d ports", numports);
|
Snprintf(additional_info, sizeof(additional_info), "%d ports", numports);
|
||||||
SPM.endTask(NULL, additional_info);
|
SPM.endTask(NULL, additional_info);
|
||||||
|
|
||||||
/* Now we go through the ports which were not determined were scanned
|
/* Now we go through the ports which were not determined were scanned
|
||||||
|
|||||||
4
main.cc
4
main.cc
@@ -193,7 +193,7 @@ int main(int argc, char *argv[]) {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ((cptr = getenv("NMAP_ARGS"))) {
|
if ((cptr = getenv("NMAP_ARGS"))) {
|
||||||
if (snprintf(command, sizeof(command), "nmap %s", cptr) >= (int) sizeof(command)) {
|
if (Snprintf(command, sizeof(command), "nmap %s", cptr) >= (int) sizeof(command)) {
|
||||||
error("Warning: NMAP_ARGS variable is too long, truncated");
|
error("Warning: NMAP_ARGS variable is too long, truncated");
|
||||||
}
|
}
|
||||||
/* copy rest of command-line arguments */
|
/* copy rest of command-line arguments */
|
||||||
@@ -322,7 +322,7 @@ int main(int argc, char *argv[]) {
|
|||||||
if (endptr) {
|
if (endptr) {
|
||||||
*endptr = '\0';
|
*endptr = '\0';
|
||||||
}
|
}
|
||||||
snprintf(nmappath, sizeof(nmappath), "%s/%s", pptr, nmapcalledas);
|
Snprintf(nmappath, sizeof(nmappath), "%s/%s", pptr, nmapcalledas);
|
||||||
if (stat(nmappath, &st) != -1)
|
if (stat(nmappath, &st) != -1)
|
||||||
break;
|
break;
|
||||||
nmappath[0] = '\0';
|
nmappath[0] = '\0';
|
||||||
|
|||||||
32
nmap.cc
32
nmap.cc
@@ -824,11 +824,11 @@ int nmap_main(int argc, char *argv[]) {
|
|||||||
xmlfilename = optarg;
|
xmlfilename = optarg;
|
||||||
} else if (strcmp(long_options[option_index].name, "oA") == 0) {
|
} else if (strcmp(long_options[option_index].name, "oA") == 0) {
|
||||||
char buf[MAXPATHLEN];
|
char buf[MAXPATHLEN];
|
||||||
snprintf(buf, sizeof(buf), "%s.nmap", optarg);
|
Snprintf(buf, sizeof(buf), "%s.nmap", optarg);
|
||||||
normalfilename = strdup(buf);
|
normalfilename = strdup(buf);
|
||||||
snprintf(buf, sizeof(buf), "%s.gnmap", optarg);
|
Snprintf(buf, sizeof(buf), "%s.gnmap", optarg);
|
||||||
machinefilename = strdup(buf);
|
machinefilename = strdup(buf);
|
||||||
snprintf(buf, sizeof(buf), "%s.xml", optarg);
|
Snprintf(buf, sizeof(buf), "%s.xml", optarg);
|
||||||
xmlfilename = strdup(buf);
|
xmlfilename = strdup(buf);
|
||||||
} else if (strcmp(long_options[option_index].name, "thc") == 0) {
|
} else if (strcmp(long_options[option_index].name, "thc") == 0) {
|
||||||
printf("!!Greets to Van Hauser, Plasmoid, Skyper and the rest of THC!!\n");
|
printf("!!Greets to Van Hauser, Plasmoid, Skyper and the rest of THC!!\n");
|
||||||
@@ -1390,7 +1390,7 @@ int nmap_main(int argc, char *argv[]) {
|
|||||||
char xslline[1024];
|
char xslline[1024];
|
||||||
if (xslfname) {
|
if (xslfname) {
|
||||||
char *p = xml_convert(xslfname);
|
char *p = xml_convert(xslfname);
|
||||||
snprintf(xslline, sizeof(xslline), "<?xml-stylesheet href=\"%s\" type=\"text/xsl\"?>\n", p);
|
Snprintf(xslline, sizeof(xslline), "<?xml-stylesheet href=\"%s\" type=\"text/xsl\"?>\n", p);
|
||||||
free(p);
|
free(p);
|
||||||
} else xslline[0] = '\0';
|
} else xslline[0] = '\0';
|
||||||
log_write(LOG_XML, "<?xml version=\"1.0\" ?>\n%s<!-- ", xslline);
|
log_write(LOG_XML, "<?xml version=\"1.0\" ?>\n%s<!-- ", xslline);
|
||||||
@@ -2283,7 +2283,7 @@ f --spoof \"/usr/local/bin/pico -z hello.c\" -sS -oN e.log example.com/24\n\n");
|
|||||||
char *seqreport1(struct seq_info *seq) {
|
char *seqreport1(struct seq_info *seq) {
|
||||||
static char report[512];
|
static char report[512];
|
||||||
|
|
||||||
snprintf(report, sizeof(report), "TCP Sequence Prediction: Difficulty=%d (%s)\n", seq->index, seqidx2difficultystr1(seq->index));
|
Snprintf(report, sizeof(report), "TCP Sequence Prediction: Difficulty=%d (%s)\n", seq->index, seqidx2difficultystr1(seq->index));
|
||||||
return report;
|
return report;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2296,7 +2296,7 @@ const char *seqidx2difficultystr1(unsigned long idx) {
|
|||||||
char *seqreport(struct seq_info *seq) {
|
char *seqreport(struct seq_info *seq) {
|
||||||
static char report[512];
|
static char report[512];
|
||||||
|
|
||||||
snprintf(report, sizeof(report), "TCP Sequence Prediction: Difficulty=%d (%s)\n", seq->index, seqidx2difficultystr(seq->index));
|
Snprintf(report, sizeof(report), "TCP Sequence Prediction: Difficulty=%d (%s)\n", seq->index, seqidx2difficultystr(seq->index));
|
||||||
return report;
|
return report;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2452,7 +2452,7 @@ int ftp_anon_connect(struct ftpinfo *ftp) {
|
|||||||
pfatal("recv problem from ftp bounce server");
|
pfatal("recv problem from ftp bounce server");
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(command, 511, "USER %s\r\n", ftp->user);
|
Snprintf(command, 511, "USER %s\r\n", ftp->user);
|
||||||
|
|
||||||
send(sd, command, strlen(command), 0);
|
send(sd, command, strlen(command), 0);
|
||||||
res = recvtime(sd, recvbuf, sizeof(recvbuf) - 1,12, NULL);
|
res = recvtime(sd, recvbuf, sizeof(recvbuf) - 1,12, NULL);
|
||||||
@@ -2465,7 +2465,7 @@ int ftp_anon_connect(struct ftpinfo *ftp) {
|
|||||||
fatal("Your ftp bounce server doesn't like the username \"%s\"", ftp->user);
|
fatal("Your ftp bounce server doesn't like the username \"%s\"", ftp->user);
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(command, 511, "PASS %s\r\n", ftp->pass);
|
Snprintf(command, 511, "PASS %s\r\n", ftp->pass);
|
||||||
|
|
||||||
send(sd, command, strlen(command), 0);
|
send(sd, command, strlen(command), 0);
|
||||||
res = recvtime(sd, recvbuf, sizeof(recvbuf) - 1,12, NULL);
|
res = recvtime(sd, recvbuf, sizeof(recvbuf) - 1,12, NULL);
|
||||||
@@ -2625,14 +2625,14 @@ int nmap_fetchfile(char *filename_returned, int bufferlen, char *file) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (o.datadir) {
|
if (o.datadir) {
|
||||||
res = snprintf(filename_returned, bufferlen, "%s/%s", o.datadir, file);
|
res = Snprintf(filename_returned, bufferlen, "%s/%s", o.datadir, file);
|
||||||
if (res > 0 && res < bufferlen) {
|
if (res > 0 && res < bufferlen) {
|
||||||
foundsomething = fileexistsandisreadable(filename_returned);
|
foundsomething = fileexistsandisreadable(filename_returned);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!foundsomething && (dirptr = getenv("NMAPDIR"))) {
|
if (!foundsomething && (dirptr = getenv("NMAPDIR"))) {
|
||||||
res = snprintf(filename_returned, bufferlen, "%s/%s", dirptr, file);
|
res = Snprintf(filename_returned, bufferlen, "%s/%s", dirptr, file);
|
||||||
if (res > 0 && res < bufferlen) {
|
if (res > 0 && res < bufferlen) {
|
||||||
foundsomething = fileexistsandisreadable(filename_returned);
|
foundsomething = fileexistsandisreadable(filename_returned);
|
||||||
}
|
}
|
||||||
@@ -2641,7 +2641,7 @@ int nmap_fetchfile(char *filename_returned, int bufferlen, char *file) {
|
|||||||
if (!foundsomething) {
|
if (!foundsomething) {
|
||||||
pw = getpwuid(getuid());
|
pw = getpwuid(getuid());
|
||||||
if (pw) {
|
if (pw) {
|
||||||
res = snprintf(filename_returned, bufferlen, "%s/.nmap/%s", pw->pw_dir, file);
|
res = Snprintf(filename_returned, bufferlen, "%s/.nmap/%s", pw->pw_dir, file);
|
||||||
if (res > 0 && res < bufferlen) {
|
if (res > 0 && res < bufferlen) {
|
||||||
foundsomething = fileexistsandisreadable(filename_returned);
|
foundsomething = fileexistsandisreadable(filename_returned);
|
||||||
}
|
}
|
||||||
@@ -2649,7 +2649,7 @@ int nmap_fetchfile(char *filename_returned, int bufferlen, char *file) {
|
|||||||
if (!foundsomething && getuid() != geteuid()) {
|
if (!foundsomething && getuid() != geteuid()) {
|
||||||
pw = getpwuid(geteuid());
|
pw = getpwuid(geteuid());
|
||||||
if (pw) {
|
if (pw) {
|
||||||
res = snprintf(filename_returned, bufferlen, "%s/.nmap/%s", pw->pw_dir, file);
|
res = Snprintf(filename_returned, bufferlen, "%s/.nmap/%s", pw->pw_dir, file);
|
||||||
if (res > 0 && res < bufferlen) {
|
if (res > 0 && res < bufferlen) {
|
||||||
foundsomething = fileexistsandisreadable(filename_returned);
|
foundsomething = fileexistsandisreadable(filename_returned);
|
||||||
}
|
}
|
||||||
@@ -2666,20 +2666,20 @@ int nmap_fetchfile(char *filename_returned, int bufferlen, char *file) {
|
|||||||
for(i = res - 1; i >= 0 && fnbuf[i] != '/' && fnbuf[i] != '\\'; i--);
|
for(i = res - 1; i >= 0 && fnbuf[i] != '/' && fnbuf[i] != '\\'; i--);
|
||||||
if(i >= 0) /* we found it */
|
if(i >= 0) /* we found it */
|
||||||
fnbuf[i] = 0;
|
fnbuf[i] = 0;
|
||||||
res = snprintf(filename_returned, bufferlen, "%s\\%s", fnbuf, file);
|
res = Snprintf(filename_returned, bufferlen, "%s\\%s", fnbuf, file);
|
||||||
if(res > 0 && res < bufferlen) {
|
if(res > 0 && res < bufferlen) {
|
||||||
foundsomething = fileexistsandisreadable(filename_returned);
|
foundsomething = fileexistsandisreadable(filename_returned);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
if (!foundsomething) {
|
if (!foundsomething) {
|
||||||
res = snprintf(filename_returned, bufferlen, "%s/%s", NMAPDATADIR, file);
|
res = Snprintf(filename_returned, bufferlen, "%s/%s", NMAPDATADIR, file);
|
||||||
if (res > 0 && res < bufferlen) {
|
if (res > 0 && res < bufferlen) {
|
||||||
foundsomething = fileexistsandisreadable(filename_returned);
|
foundsomething = fileexistsandisreadable(filename_returned);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (foundsomething && (*filename_returned != '.')) {
|
if (foundsomething && (*filename_returned != '.')) {
|
||||||
res = snprintf(dot_buffer, sizeof(dot_buffer), "./%s", file);
|
res = Snprintf(dot_buffer, sizeof(dot_buffer), "./%s", file);
|
||||||
if (res > 0 && res < bufferlen) {
|
if (res > 0 && res < bufferlen) {
|
||||||
if (fileexistsandisreadable(dot_buffer)) {
|
if (fileexistsandisreadable(dot_buffer)) {
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
@@ -2693,7 +2693,7 @@ int nmap_fetchfile(char *filename_returned, int bufferlen, char *file) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!foundsomething) {
|
if (!foundsomething) {
|
||||||
res = snprintf(filename_returned, bufferlen, "./%s", file);
|
res = Snprintf(filename_returned, bufferlen, "./%s", file);
|
||||||
if (res > 0 && res < bufferlen) {
|
if (res > 0 && res < bufferlen) {
|
||||||
foundsomething = fileexistsandisreadable(filename_returned);
|
foundsomething = fileexistsandisreadable(filename_returned);
|
||||||
}
|
}
|
||||||
|
|||||||
16
nmap_dns.cc
16
nmap_dns.cc
@@ -874,7 +874,7 @@ void win32_read_registry(char *controlset) {
|
|||||||
char buf[2048], keyname[2048], *p;
|
char buf[2048], keyname[2048], *p;
|
||||||
DWORD sz, i;
|
DWORD sz, i;
|
||||||
|
|
||||||
snprintf(keybasebuf, sizeof(keybasebuf), "SYSTEM\\%s\\Services\\Tcpip\\Parameters", controlset);
|
Snprintf(keybasebuf, sizeof(keybasebuf), "SYSTEM\\%s\\Services\\Tcpip\\Parameters", controlset);
|
||||||
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, keybasebuf,
|
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, keybasebuf,
|
||||||
0, KEY_READ, &hKey) != ERROR_SUCCESS) {
|
0, KEY_READ, &hKey) != ERROR_SUCCESS) {
|
||||||
if (firstrun) error("mass_dns: warning: Error opening registry to read DNS servers. Try using --system-dns or specify valid servers with --dns-servers");
|
if (firstrun) error("mass_dns: warning: Error opening registry to read DNS servers. Try using --system-dns or specify valid servers with --dns-servers");
|
||||||
@@ -891,14 +891,14 @@ void win32_read_registry(char *controlset) {
|
|||||||
|
|
||||||
RegCloseKey(hKey);
|
RegCloseKey(hKey);
|
||||||
|
|
||||||
snprintf(keybasebuf, sizeof(keybasebuf), "SYSTEM\\%s\\Services\\Tcpip\\Parameters\\Interfaces", controlset);
|
Snprintf(keybasebuf, sizeof(keybasebuf), "SYSTEM\\%s\\Services\\Tcpip\\Parameters\\Interfaces", controlset);
|
||||||
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, keybasebuf,
|
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, keybasebuf,
|
||||||
0, KEY_ENUMERATE_SUB_KEYS, &hKey) == ERROR_SUCCESS) {
|
0, KEY_ENUMERATE_SUB_KEYS, &hKey) == ERROR_SUCCESS) {
|
||||||
|
|
||||||
sz = sizeof(buf);
|
sz = sizeof(buf);
|
||||||
for (i=0; RegEnumKeyEx(hKey, i, buf, &sz, NULL, NULL, NULL, NULL) != ERROR_NO_MORE_ITEMS; i++) {
|
for (i=0; RegEnumKeyEx(hKey, i, buf, &sz, NULL, NULL, NULL, NULL) != ERROR_NO_MORE_ITEMS; i++) {
|
||||||
|
|
||||||
snprintf(keyname, sizeof(keyname), "SYSTEM\\%s\\Services\\Tcpip\\Parameters\\Interfaces\\%s", controlset, buf);
|
Snprintf(keyname, sizeof(keyname), "SYSTEM\\%s\\Services\\Tcpip\\Parameters\\Interfaces\\%s", controlset, buf);
|
||||||
|
|
||||||
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, keyname,
|
if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, keyname,
|
||||||
0, KEY_READ, &hKey2) == ERROR_SUCCESS) {
|
0, KEY_READ, &hKey2) == ERROR_SUCCESS) {
|
||||||
@@ -1093,11 +1093,11 @@ static void etchosts_init(void) {
|
|||||||
has_backslash = (windows_dir[strlen(windows_dir)-1] == '\\');
|
has_backslash = (windows_dir[strlen(windows_dir)-1] == '\\');
|
||||||
|
|
||||||
// Windows 95/98/Me:
|
// Windows 95/98/Me:
|
||||||
snprintf(tpbuf, sizeof(tpbuf), "%s%shosts", windows_dir, has_backslash ? "" : "\\");
|
Snprintf(tpbuf, sizeof(tpbuf), "%s%shosts", windows_dir, has_backslash ? "" : "\\");
|
||||||
parse_etchosts(tpbuf);
|
parse_etchosts(tpbuf);
|
||||||
|
|
||||||
// Windows NT/2000/XP/2K3:
|
// Windows NT/2000/XP/2K3:
|
||||||
snprintf(tpbuf, sizeof(tpbuf), "%s%ssystem32\\drivers\\etc\\hosts", windows_dir, has_backslash ? "" : "\\");
|
Snprintf(tpbuf, sizeof(tpbuf), "%s%ssystem32\\drivers\\etc\\hosts", windows_dir, has_backslash ? "" : "\\");
|
||||||
parse_etchosts(tpbuf);
|
parse_etchosts(tpbuf);
|
||||||
|
|
||||||
#else
|
#else
|
||||||
@@ -1133,7 +1133,7 @@ static void nmap_mass_rdns_core(Target **targets, int num_targets) {
|
|||||||
if (((currenths->flags & HOST_UP) || o.resolve_all) && !o.noresolve) stat_actual++;
|
if (((currenths->flags & HOST_UP) || o.resolve_all) && !o.noresolve) stat_actual++;
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(spmobuf, sizeof(spmobuf), "System DNS resolution of %d host%s.", num_targets, num_targets-1 ? "s" : "");
|
Snprintf(spmobuf, sizeof(spmobuf), "System DNS resolution of %d host%s.", num_targets, num_targets-1 ? "s" : "");
|
||||||
SPM = new ScanProgressMeter(spmobuf);
|
SPM = new ScanProgressMeter(spmobuf);
|
||||||
|
|
||||||
for(i=0, hostI = targets; hostI < targets+num_targets; hostI++, i++) {
|
for(i=0, hostI = targets; hostI < targets+num_targets; hostI++, i++) {
|
||||||
@@ -1214,7 +1214,7 @@ static void nmap_mass_rdns_core(Target **targets, int num_targets) {
|
|||||||
|
|
||||||
read_timeout_index = MIN(sizeof(read_timeouts)/sizeof(read_timeouts[0]), servs.size()) - 1;
|
read_timeout_index = MIN(sizeof(read_timeouts)/sizeof(read_timeouts[0]), servs.size()) - 1;
|
||||||
|
|
||||||
snprintf(spmobuf, sizeof(spmobuf), "Parallel DNS resolution of %d host%s.", num_targets, num_targets-1 ? "s" : "");
|
Snprintf(spmobuf, sizeof(spmobuf), "Parallel DNS resolution of %d host%s.", num_targets, num_targets-1 ? "s" : "");
|
||||||
SPM = new ScanProgressMeter(spmobuf);
|
SPM = new ScanProgressMeter(spmobuf);
|
||||||
|
|
||||||
while (total_reqs > 0) {
|
while (total_reqs > 0) {
|
||||||
@@ -1245,7 +1245,7 @@ static void nmap_mass_rdns_core(Target **targets, int num_targets) {
|
|||||||
log_write(LOG_STDOUT, "Performing system-dns for %d domain names that use CNAMEs\n", (int) cname_reqs.size());
|
log_write(LOG_STDOUT, "Performing system-dns for %d domain names that use CNAMEs\n", (int) cname_reqs.size());
|
||||||
|
|
||||||
if (cname_reqs.size()) {
|
if (cname_reqs.size()) {
|
||||||
snprintf(spmobuf, sizeof(spmobuf), "System CNAME DNS resolution of %u host%s.", (unsigned) cname_reqs.size(), cname_reqs.size()-1 ? "s" : "");
|
Snprintf(spmobuf, sizeof(spmobuf), "System CNAME DNS resolution of %u host%s.", (unsigned) cname_reqs.size(), cname_reqs.size()-1 ? "s" : "");
|
||||||
SPM = new ScanProgressMeter(spmobuf);
|
SPM = new ScanProgressMeter(spmobuf);
|
||||||
|
|
||||||
for(i=0, reqI = cname_reqs.begin(); reqI != cname_reqs.end(); reqI++, i++) {
|
for(i=0, reqI = cname_reqs.begin(); reqI != cname_reqs.end(); reqI++, i++) {
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ int auxiliar_tostring(lua_State *L) {
|
|||||||
lua_pushstring(L, "class");
|
lua_pushstring(L, "class");
|
||||||
lua_gettable(L, -2);
|
lua_gettable(L, -2);
|
||||||
if (!lua_isstring(L, -1)) goto error;
|
if (!lua_isstring(L, -1)) goto error;
|
||||||
snprintf(buf, 31, "%p", lua_touserdata(L, 1));
|
Snprintf(buf, 31, "%p", lua_touserdata(L, 1));
|
||||||
lua_pushfstring(L, "%s: %s", lua_tostring(L, -1), buf);
|
lua_pushfstring(L, "%s: %s", lua_tostring(L, -1), buf);
|
||||||
return 1;
|
return 1;
|
||||||
error:
|
error:
|
||||||
@@ -75,7 +75,7 @@ void *auxiliar_checkclass(lua_State *L, const char *classname, int objidx) {
|
|||||||
void *data = auxiliar_getclassudata(L, classname, objidx);
|
void *data = auxiliar_getclassudata(L, classname, objidx);
|
||||||
if (!data) {
|
if (!data) {
|
||||||
char msg[45];
|
char msg[45];
|
||||||
snprintf(msg, 44, "%.35s expected", classname);
|
Snprintf(msg, 44, "%.35s expected", classname);
|
||||||
luaL_argerror(L, objidx, msg);
|
luaL_argerror(L, objidx, msg);
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
@@ -89,7 +89,7 @@ void *auxiliar_checkgroup(lua_State *L, const char *groupname, int objidx) {
|
|||||||
void *data = auxiliar_getgroupudata(L, groupname, objidx);
|
void *data = auxiliar_getgroupudata(L, groupname, objidx);
|
||||||
if (!data) {
|
if (!data) {
|
||||||
char msg[45];
|
char msg[45];
|
||||||
snprintf(msg, 44, "%.35s expected", groupname);
|
Snprintf(msg, 44, "%.35s expected", groupname);
|
||||||
luaL_argerror(L, objidx, msg);
|
luaL_argerror(L, objidx, msg);
|
||||||
}
|
}
|
||||||
return data;
|
return data;
|
||||||
|
|||||||
@@ -799,7 +799,7 @@ static int l_nsock_ncap_open(lua_State* l){
|
|||||||
|
|
||||||
/* create key */
|
/* create key */
|
||||||
char key[8192];
|
char key[8192];
|
||||||
snprintf(key, sizeof(key), "%s|%i|%i|%u|%s",
|
Snprintf(key, sizeof(key), "%s|%i|%i|%u|%s",
|
||||||
pcapdev,
|
pcapdev,
|
||||||
snaplen, promisc,
|
snaplen, promisc,
|
||||||
(unsigned int)strlen(bpf),
|
(unsigned int)strlen(bpf),
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ extern "C" {
|
|||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include <pcre.h>
|
#include <pcre.h>
|
||||||
|
|
||||||
|
#include "nbase.h"
|
||||||
#include "pcre.h"
|
#include "pcre.h"
|
||||||
|
|
||||||
static void L_lua_error(lua_State *L, const char *message)
|
static void L_lua_error(lua_State *L, const char *message)
|
||||||
@@ -50,11 +51,11 @@ static int udata_tostring (lua_State *L, const char* type_handle,
|
|||||||
void *udata = luaL_checkudata(L, 1, type_handle);
|
void *udata = luaL_checkudata(L, 1, type_handle);
|
||||||
|
|
||||||
if(udata) {
|
if(udata) {
|
||||||
(void)snprintf(buf, 255, "%s (%p)", type_name, udata);
|
(void)Snprintf(buf, 255, "%s (%p)", type_name, udata);
|
||||||
lua_pushstring(L, buf);
|
lua_pushstring(L, buf);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
(void)snprintf(buf, 255, "must be userdata of type '%s'", type_name);
|
(void)Snprintf(buf, 255, "must be userdata of type '%s'", type_name);
|
||||||
(void)luaL_argerror(L, 1, buf);
|
(void)luaL_argerror(L, 1, buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,7 +141,7 @@ static int Lpcre_comp(lua_State *L)
|
|||||||
|
|
||||||
ud->pr = pcre_compile(pattern, cflags, &error, &erroffset, tables);
|
ud->pr = pcre_compile(pattern, cflags, &error, &erroffset, tables);
|
||||||
if(!ud->pr) {
|
if(!ud->pr) {
|
||||||
(void)snprintf(buf, 255, "%s (pattern offset: %d)", error, erroffset+1);
|
(void)Snprintf(buf, 255, "%s (pattern offset: %d)", error, erroffset+1);
|
||||||
/* show offset 1-based as it's common in Lua */
|
/* show offset 1-based as it's common in Lua */
|
||||||
L_lua_error(L, buf);
|
L_lua_error(L, buf);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
#ifndef PCRE_H
|
#ifndef PCRE_H
|
||||||
#define PCRE_H
|
#define PCRE_H
|
||||||
|
|
||||||
#ifdef WIN32
|
|
||||||
#define snprintf _snprintf
|
|
||||||
#endif /* WIN32 */
|
|
||||||
#define NSE_PCRELIBNAME "pcre"
|
#define NSE_PCRELIBNAME "pcre"
|
||||||
|
|
||||||
LUALIB_API int luaopen_pcre(lua_State *L);
|
LUALIB_API int luaopen_pcre(lua_State *L);
|
||||||
|
|||||||
16
osscan.cc
16
osscan.cc
@@ -563,7 +563,7 @@ static FingerPrint *get_fingerprint(Target *target, struct seq_info *si) {
|
|||||||
if (o.debugging > 1)
|
if (o.debugging > 1)
|
||||||
log_write(LOG_STDOUT, "Wait time is %dms\n", (ossofttimeout +500)/1000);
|
log_write(LOG_STDOUT, "Wait time is %dms\n", (ossofttimeout +500)/1000);
|
||||||
|
|
||||||
snprintf(filter, sizeof(filter), "dst host %s and (icmp or (tcp and src host %s))", inet_ntoa(target->v4source()), target->targetipstr());
|
Snprintf(filter, sizeof(filter), "dst host %s and (icmp or (tcp and src host %s))", inet_ntoa(target->v4source()), target->targetipstr());
|
||||||
|
|
||||||
set_pcap_filter(target->deviceName(), pd, filter);
|
set_pcap_filter(target->deviceName(), pd, filter);
|
||||||
target->osscanSetFlag(OS_PERF); /* Let Nmap know that we did try an OS scan */
|
target->osscanSetFlag(OS_PERF); /* Let Nmap know that we did try an OS scan */
|
||||||
@@ -1600,24 +1600,24 @@ static void WriteSInfo(char *ostr, int ostrlen, bool isGoodFP,
|
|||||||
|
|
||||||
otbuf[0] = '\0';
|
otbuf[0] = '\0';
|
||||||
if(openTcpPort != -1)
|
if(openTcpPort != -1)
|
||||||
snprintf(otbuf, sizeof(otbuf), "%d", openTcpPort);
|
Snprintf(otbuf, sizeof(otbuf), "%d", openTcpPort);
|
||||||
ctbuf[0] = '\0';
|
ctbuf[0] = '\0';
|
||||||
if(closedTcpPort != -1)
|
if(closedTcpPort != -1)
|
||||||
snprintf(ctbuf, sizeof(ctbuf), "%d", closedTcpPort);
|
Snprintf(ctbuf, sizeof(ctbuf), "%d", closedTcpPort);
|
||||||
cubuf[0] = '\0';
|
cubuf[0] = '\0';
|
||||||
if(closedUdpPort != -1)
|
if(closedUdpPort != -1)
|
||||||
snprintf(cubuf, sizeof(cubuf), "%d", closedUdpPort);
|
Snprintf(cubuf, sizeof(cubuf), "%d", closedUdpPort);
|
||||||
|
|
||||||
dsbuf[0] = '\0';
|
dsbuf[0] = '\0';
|
||||||
if(distance != -1) {
|
if(distance != -1) {
|
||||||
snprintf(dsbuf, sizeof(dsbuf), "%%DS=%d", distance);
|
Snprintf(dsbuf, sizeof(dsbuf), "%%DS=%d", distance);
|
||||||
}
|
}
|
||||||
|
|
||||||
macbuf[0] = '\0';
|
macbuf[0] = '\0';
|
||||||
if (mac)
|
if (mac)
|
||||||
snprintf(macbuf, sizeof(macbuf), "%%M=%02X%02X%02X", mac[0], mac[1], mac[2]);
|
Snprintf(macbuf, sizeof(macbuf), "%%M=%02X%02X%02X", mac[0], mac[1], mac[2]);
|
||||||
|
|
||||||
snprintf(ostr, ostrlen, "SCAN(V=%s%%D=%d/%d%%OT=%s%%CT=%s%%CU=%s%%PV=%c%s%%G=%c%s%%TM=%X%%P=%s)",
|
Snprintf(ostr, ostrlen, "SCAN(V=%s%%D=%d/%d%%OT=%s%%CT=%s%%CU=%s%%PV=%c%s%%G=%c%s%%TM=%X%%P=%s)",
|
||||||
NMAP_VERSION, ltime->tm_mon + 1, ltime->tm_mday,
|
NMAP_VERSION, ltime->tm_mon + 1, ltime->tm_mday,
|
||||||
otbuf, ctbuf, cubuf, isipprivate(addr)?'Y':'N', dsbuf, isGoodFP?'Y':'N',
|
otbuf, ctbuf, cubuf, isipprivate(addr)?'Y':'N', dsbuf, isGoodFP?'Y':'N',
|
||||||
macbuf, (int) timep, NMAP_PLATFORM);
|
macbuf, (int) timep, NMAP_PLATFORM);
|
||||||
@@ -1909,7 +1909,7 @@ memset(str, 0, sizeof(str));
|
|||||||
if (!FP) return "(None)";
|
if (!FP) return "(None)";
|
||||||
|
|
||||||
if(FP->OS_name && *(FP->OS_name)) {
|
if(FP->OS_name && *(FP->OS_name)) {
|
||||||
len = snprintf(str, 128, "FingerPrint %s\n", FP->OS_name);
|
len = Snprintf(str, 128, "FingerPrint %s\n", FP->OS_name);
|
||||||
if (len < 0) fatal("OS name too long");
|
if (len < 0) fatal("OS name too long");
|
||||||
p += len;
|
p += len;
|
||||||
}
|
}
|
||||||
|
|||||||
10
osscan2.cc
10
osscan2.cc
@@ -3264,7 +3264,7 @@ static void begin_sniffer(HostOsScan *HOS, vector<Target *> &Targets) {
|
|||||||
|
|
||||||
if (doIndividual) {
|
if (doIndividual) {
|
||||||
for(targetno = 0; targetno < Targets.size(); targetno++) {
|
for(targetno = 0; targetno < Targets.size(); targetno++) {
|
||||||
len = snprintf(dst_hosts + filterlen,
|
len = Snprintf(dst_hosts + filterlen,
|
||||||
sizeof(dst_hosts) - filterlen,
|
sizeof(dst_hosts) - filterlen,
|
||||||
"%ssrc host %s", (targetno == 0)? "" : " or ",
|
"%ssrc host %s", (targetno == 0)? "" : " or ",
|
||||||
Targets[targetno]->targetipstr());
|
Targets[targetno]->targetipstr());
|
||||||
@@ -3272,7 +3272,7 @@ static void begin_sniffer(HostOsScan *HOS, vector<Target *> &Targets) {
|
|||||||
fatal("ran out of space in dst_hosts");
|
fatal("ran out of space in dst_hosts");
|
||||||
filterlen += len;
|
filterlen += len;
|
||||||
}
|
}
|
||||||
len = snprintf(dst_hosts + filterlen, sizeof(dst_hosts) - filterlen, ")))");
|
len = Snprintf(dst_hosts + filterlen, sizeof(dst_hosts) - filterlen, ")))");
|
||||||
if (len < 0 || len + filterlen >= (int) sizeof(dst_hosts))
|
if (len < 0 || len + filterlen >= (int) sizeof(dst_hosts))
|
||||||
fatal("ran out of space in dst_hosts");
|
fatal("ran out of space in dst_hosts");
|
||||||
}
|
}
|
||||||
@@ -3281,10 +3281,10 @@ static void begin_sniffer(HostOsScan *HOS, vector<Target *> &Targets) {
|
|||||||
HOS->pd = my_pcap_open_live(Targets[0]->deviceName(), 8192, (o.spoofsource)? 1 : 0, pcap_selectable_fd_valid()? 200 : 2);
|
HOS->pd = my_pcap_open_live(Targets[0]->deviceName(), 8192, (o.spoofsource)? 1 : 0, pcap_selectable_fd_valid()? 200 : 2);
|
||||||
|
|
||||||
if (doIndividual)
|
if (doIndividual)
|
||||||
len = snprintf(pcap_filter, sizeof(pcap_filter), "dst host %s and (icmp or (tcp and (%s",
|
len = Snprintf(pcap_filter, sizeof(pcap_filter), "dst host %s and (icmp or (tcp and (%s",
|
||||||
inet_ntoa(Targets[0]->v4source()), dst_hosts);
|
inet_ntoa(Targets[0]->v4source()), dst_hosts);
|
||||||
else
|
else
|
||||||
len = snprintf(pcap_filter, sizeof(pcap_filter), "dst host %s and (icmp or tcp)",
|
len = Snprintf(pcap_filter, sizeof(pcap_filter), "dst host %s and (icmp or tcp)",
|
||||||
inet_ntoa(Targets[0]->v4source()));
|
inet_ntoa(Targets[0]->v4source()));
|
||||||
if (len < 0 || len >= (int) sizeof(pcap_filter))
|
if (len < 0 || len >= (int) sizeof(pcap_filter))
|
||||||
fatal("ran out of space in pcap filter");
|
fatal("ran out of space in pcap filter");
|
||||||
@@ -3848,7 +3848,7 @@ static int os_scan_2(vector<Target *> &Targets) {
|
|||||||
bool plural = (OSI->numIncompleteHosts() != 1);
|
bool plural = (OSI->numIncompleteHosts() != 1);
|
||||||
if (!plural) {
|
if (!plural) {
|
||||||
(*(OSI->incompleteHosts.begin()))->target->NameIP(targetstr, sizeof(targetstr));
|
(*(OSI->incompleteHosts.begin()))->target->NameIP(targetstr, sizeof(targetstr));
|
||||||
} else snprintf(targetstr, sizeof(targetstr), "%d hosts", (int) OSI->numIncompleteHosts());
|
} else Snprintf(targetstr, sizeof(targetstr), "%d hosts", (int) OSI->numIncompleteHosts());
|
||||||
log_write(LOG_PLAIN, "%s OS detection (try #%d) against %s\n", (itry == 0)? "Initiating" : "Retrying", itry + 1, targetstr);
|
log_write(LOG_PLAIN, "%s OS detection (try #%d) against %s\n", (itry == 0)? "Initiating" : "Retrying", itry + 1, targetstr);
|
||||||
log_flush_all();
|
log_flush_all();
|
||||||
}
|
}
|
||||||
|
|||||||
48
output.cc
48
output.cc
@@ -269,12 +269,12 @@ static int getServiceXMLBuf(struct serviceDeductions *sd, char *xmlbuf,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (o.rpcscan && sd->rpc_status == RPC_STATUS_GOOD_PROG) {
|
if (o.rpcscan && sd->rpc_status == RPC_STATUS_GOOD_PROG) {
|
||||||
snprintf(rpcbuf, sizeof(rpcbuf),
|
Snprintf(rpcbuf, sizeof(rpcbuf),
|
||||||
" rpcnum=\"%li\" lowver=\"%i\" highver=\"%i\" proto=\"rpc\"",
|
" rpcnum=\"%li\" lowver=\"%i\" highver=\"%i\" proto=\"rpc\"",
|
||||||
sd->rpc_program, sd->rpc_lowver, sd->rpc_highver);
|
sd->rpc_program, sd->rpc_lowver, sd->rpc_highver);
|
||||||
} else rpcbuf[0] = '\0';
|
} else rpcbuf[0] = '\0';
|
||||||
|
|
||||||
snprintf(xmlbuf, xmlbuflen,
|
Snprintf(xmlbuf, xmlbuflen,
|
||||||
"<service name=\"%s\"%s %smethod=\"%s\" conf=\"%d\"%s />",
|
"<service name=\"%s\"%s %smethod=\"%s\" conf=\"%d\"%s />",
|
||||||
sd->name? sd->name : "unknown",
|
sd->name? sd->name : "unknown",
|
||||||
versionxmlstring.c_str(),
|
versionxmlstring.c_str(),
|
||||||
@@ -400,10 +400,10 @@ static void getNmapServiceName(struct serviceDeductions *sd, int state,
|
|||||||
if (sd->name && (sd->service_tunnel != SERVICE_TUNNEL_SSL ||
|
if (sd->name && (sd->service_tunnel != SERVICE_TUNNEL_SSL ||
|
||||||
sd->dtype == SERVICE_DETECTION_PROBED)) {
|
sd->dtype == SERVICE_DETECTION_PROBED)) {
|
||||||
if (o.servicescan && state == PORT_OPEN && sd->name_confidence <= 5)
|
if (o.servicescan && state == PORT_OPEN && sd->name_confidence <= 5)
|
||||||
len = snprintf(dst, lenremaining, "%s?", sd->name);
|
len = Snprintf(dst, lenremaining, "%s?", sd->name);
|
||||||
else len = snprintf(dst, lenremaining, "%s", sd->name);
|
else len = Snprintf(dst, lenremaining, "%s", sd->name);
|
||||||
} else {
|
} else {
|
||||||
len = snprintf(dst, lenremaining, "%s", "unknown");
|
len = Snprintf(dst, lenremaining, "%s", "unknown");
|
||||||
}
|
}
|
||||||
if (len > lenremaining || len < 0) goto overflow;
|
if (len > lenremaining || len < 0) goto overflow;
|
||||||
dst += len;
|
dst += len;
|
||||||
@@ -508,9 +508,9 @@ void printportoutput(Target *currenths, PortList *plist) {
|
|||||||
else log_write(LOG_PLAIN, ", ");
|
else log_write(LOG_PLAIN, ", ");
|
||||||
char desc[32];
|
char desc[32];
|
||||||
if (o.ipprotscan)
|
if (o.ipprotscan)
|
||||||
snprintf(desc, sizeof(desc), (plist->getStateCounts(istate) == 1)? "protocol" : "protocols");
|
Snprintf(desc, sizeof(desc), (plist->getStateCounts(istate) == 1)? "protocol" : "protocols");
|
||||||
else
|
else
|
||||||
snprintf(desc, sizeof(desc), (plist->getStateCounts(istate) == 1)? "port" : "ports");
|
Snprintf(desc, sizeof(desc), (plist->getStateCounts(istate) == 1)? "port" : "ports");
|
||||||
log_write(LOG_PLAIN, "%d %s %s", plist->getStateCounts(istate), statenum2str(istate), desc);
|
log_write(LOG_PLAIN, "%d %s %s", plist->getStateCounts(istate), statenum2str(istate), desc);
|
||||||
prevstate = istate;
|
prevstate = istate;
|
||||||
}
|
}
|
||||||
@@ -572,7 +572,7 @@ void printportoutput(Target *currenths, PortList *plist) {
|
|||||||
Tbl->addItem(rowno, reasoncol, true, port_reason_str(current->reason));
|
Tbl->addItem(rowno, reasoncol, true, port_reason_str(current->reason));
|
||||||
state = statenum2str(current->state);
|
state = statenum2str(current->state);
|
||||||
proto = nmap_getprotbynum(htons(current->portno));
|
proto = nmap_getprotbynum(htons(current->portno));
|
||||||
snprintf(portinfo, sizeof(portinfo), "%s",
|
Snprintf(portinfo, sizeof(portinfo), "%s",
|
||||||
proto?proto->p_name: "unknown");
|
proto?proto->p_name: "unknown");
|
||||||
Tbl->addItemFormatted(rowno, portcol, false, "%d", current->portno);
|
Tbl->addItemFormatted(rowno, portcol, false, "%d", current->portno);
|
||||||
Tbl->addItem(rowno, statecol, true, state);
|
Tbl->addItem(rowno, statecol, true, state);
|
||||||
@@ -599,7 +599,7 @@ void printportoutput(Target *currenths, PortList *plist) {
|
|||||||
if (!first) log_write(LOG_MACHINE,", ");
|
if (!first) log_write(LOG_MACHINE,", ");
|
||||||
else first = 0;
|
else first = 0;
|
||||||
strcpy(protocol,(current->proto == IPPROTO_TCP)? "tcp": "udp");
|
strcpy(protocol,(current->proto == IPPROTO_TCP)? "tcp": "udp");
|
||||||
snprintf(portinfo, sizeof(portinfo), "%d/%s", current->portno, protocol);
|
Snprintf(portinfo, sizeof(portinfo), "%d/%s", current->portno, protocol);
|
||||||
state = statenum2str(current->state);
|
state = statenum2str(current->state);
|
||||||
current->getServiceDeductions(&sd);
|
current->getServiceDeductions(&sd);
|
||||||
if (sd.service_fp && saved_servicefps.size() <= 8)
|
if (sd.service_fp && saved_servicefps.size() <= 8)
|
||||||
@@ -621,21 +621,21 @@ void printportoutput(Target *currenths, PortList *plist) {
|
|||||||
break;
|
break;
|
||||||
case RPC_STATUS_GOOD_PROG:
|
case RPC_STATUS_GOOD_PROG:
|
||||||
name = nmap_getrpcnamebynum(sd.rpc_program);
|
name = nmap_getrpcnamebynum(sd.rpc_program);
|
||||||
snprintf(rpcmachineinfo, sizeof(rpcmachineinfo), "(%s:%li*%i-%i)", (name)? name : "", sd.rpc_program, sd.rpc_lowver, sd.rpc_highver);
|
Snprintf(rpcmachineinfo, sizeof(rpcmachineinfo), "(%s:%li*%i-%i)", (name)? name : "", sd.rpc_program, sd.rpc_lowver, sd.rpc_highver);
|
||||||
if (!name) {
|
if (!name) {
|
||||||
snprintf(rpcinfo, sizeof(rpcinfo), "(#%li (unknown) V%i-%i)", sd.rpc_program, sd.rpc_lowver, sd.rpc_highver);
|
Snprintf(rpcinfo, sizeof(rpcinfo), "(#%li (unknown) V%i-%i)", sd.rpc_program, sd.rpc_lowver, sd.rpc_highver);
|
||||||
} else {
|
} else {
|
||||||
if (sd.rpc_lowver == sd.rpc_highver) {
|
if (sd.rpc_lowver == sd.rpc_highver) {
|
||||||
snprintf(rpcinfo, sizeof(rpcinfo), "(%s V%i)", name, sd.rpc_lowver);
|
Snprintf(rpcinfo, sizeof(rpcinfo), "(%s V%i)", name, sd.rpc_lowver);
|
||||||
} else
|
} else
|
||||||
snprintf(rpcinfo, sizeof(rpcinfo), "(%s V%i-%i)", name, sd.rpc_lowver, sd.rpc_highver);
|
Snprintf(rpcinfo, sizeof(rpcinfo), "(%s V%i-%i)", name, sd.rpc_lowver, sd.rpc_highver);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fatal("Unknown rpc_status %d", sd.rpc_status);
|
fatal("Unknown rpc_status %d", sd.rpc_status);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
snprintf(serviceinfo, sizeof(serviceinfo), "%s%s%s", (sd.name)? sd.name : ((*rpcinfo)? "" : "unknown"), (sd.name)? " " : "", rpcinfo);
|
Snprintf(serviceinfo, sizeof(serviceinfo), "%s%s%s", (sd.name)? sd.name : ((*rpcinfo)? "" : "unknown"), (sd.name)? " " : "", rpcinfo);
|
||||||
} else {
|
} else {
|
||||||
getNmapServiceName(&sd, current->state, serviceinfo, sizeof(serviceinfo));
|
getNmapServiceName(&sd, current->state, serviceinfo, sizeof(serviceinfo));
|
||||||
rpcmachineinfo[0] = '\0';
|
rpcmachineinfo[0] = '\0';
|
||||||
@@ -879,7 +879,7 @@ void log_vwrite(int logt, const char *fmt, va_list ap) {
|
|||||||
while ((l&1)==0) { fileidx++; l>>=1; }
|
while ((l&1)==0) { fileidx++; l>>=1; }
|
||||||
assert(fileidx < LOG_NUM_FILES);
|
assert(fileidx < LOG_NUM_FILES);
|
||||||
if (o.logfd[fileidx]) {
|
if (o.logfd[fileidx]) {
|
||||||
len = vsnprintf(writebuf, writebuflen, fmt, ap);
|
len = Vsnprintf(writebuf, writebuflen, fmt, ap);
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
va_end(apcopy);
|
va_end(apcopy);
|
||||||
return;
|
return;
|
||||||
@@ -894,9 +894,9 @@ void log_vwrite(int logt, const char *fmt, va_list ap) {
|
|||||||
writebuflen *= 100;
|
writebuflen *= 100;
|
||||||
}
|
}
|
||||||
writebuf = (char *) safe_realloc(writebuf, writebuflen);
|
writebuf = (char *) safe_realloc(writebuf, writebuflen);
|
||||||
len = vsnprintf(writebuf, writebuflen, fmt, apcopy);
|
len = Vsnprintf(writebuf, writebuflen, fmt, apcopy);
|
||||||
if (len <= 0 || len >= writebuflen) {
|
if (len <= 0 || len >= writebuflen) {
|
||||||
fatal("%s: vnsprintf failed. Even after increasing bufferlen to %d, vsnprintf returned %d (logt == %d). Please email this message to fyodor@insecure.org. Quitting.", __func__, writebuflen, len, logt);
|
fatal("%s: vnsprintf failed. Even after increasing bufferlen to %d, Vsnprintf returned %d (logt == %d). Please email this message to fyodor@insecure.org. Quitting.", __func__, writebuflen, len, logt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (logt == LOG_SKID && !skid_noxlate)
|
if (logt == LOG_SKID && !skid_noxlate)
|
||||||
@@ -1107,11 +1107,11 @@ static void print_MAC_XML_Info(Target *currenths) {
|
|||||||
|
|
||||||
if (mac) {
|
if (mac) {
|
||||||
const char *macvendor = MACPrefix2Corp(mac);
|
const char *macvendor = MACPrefix2Corp(mac);
|
||||||
snprintf(macascii, sizeof(macascii), "%02X:%02X:%02X:%02X:%02X:%02X",
|
Snprintf(macascii, sizeof(macascii), "%02X:%02X:%02X:%02X:%02X:%02X",
|
||||||
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||||
if (macvendor) {
|
if (macvendor) {
|
||||||
xml_mac = xml_convert(macvendor);
|
xml_mac = xml_convert(macvendor);
|
||||||
snprintf(vendorstr, sizeof(vendorstr), " vendor=\"%s\"", xml_mac);
|
Snprintf(vendorstr, sizeof(vendorstr), " vendor=\"%s\"", xml_mac);
|
||||||
free(xml_mac);
|
free(xml_mac);
|
||||||
} else vendorstr[0] = '\0';
|
} else vendorstr[0] = '\0';
|
||||||
log_write(LOG_XML, "<address addr=\"%s\" addrtype=\"mac\"%s />\n", macascii, vendorstr);
|
log_write(LOG_XML, "<address addr=\"%s\" addrtype=\"mac\"%s />\n", macascii, vendorstr);
|
||||||
@@ -1173,9 +1173,9 @@ void write_host_status(Target *currenths, int resolve_all) {
|
|||||||
else if (o.pingscan) {
|
else if (o.pingscan) {
|
||||||
|
|
||||||
if(o.reason && currenths->flags & HOST_UP)
|
if(o.reason && currenths->flags & HOST_UP)
|
||||||
snprintf(reasonbuf, 512, "%s.\n", target_reason_str(currenths));
|
Snprintf(reasonbuf, 512, "%s.\n", target_reason_str(currenths));
|
||||||
else
|
else
|
||||||
snprintf(reasonbuf, 512, ".\n");
|
Snprintf(reasonbuf, 512, ".\n");
|
||||||
|
|
||||||
write_xml_initial_hostinfo(currenths,
|
write_xml_initial_hostinfo(currenths,
|
||||||
(currenths->flags & HOST_UP)? "up" : "down");
|
(currenths->flags & HOST_UP)? "up" : "down");
|
||||||
@@ -1258,7 +1258,7 @@ static void printosclassificationoutput(const struct OS_Classification_Results *
|
|||||||
for (classno=0; classno < OSR->OSC_num_matches; classno++) {
|
for (classno=0; classno < OSR->OSC_num_matches; classno++) {
|
||||||
// Because the OS_Generation filed is optional
|
// Because the OS_Generation filed is optional
|
||||||
if (OSR->OSC[classno]->OS_Generation) {
|
if (OSR->OSC[classno]->OS_Generation) {
|
||||||
snprintf(tmpbuf, sizeof(tmpbuf), " osgen=\"%s\"", OSR->OSC[classno]->OS_Generation);
|
Snprintf(tmpbuf, sizeof(tmpbuf), " osgen=\"%s\"", OSR->OSC[classno]->OS_Generation);
|
||||||
} else tmpbuf[0] = '\0';
|
} else tmpbuf[0] = '\0';
|
||||||
{
|
{
|
||||||
char *xml_type, *xml_vendor, *xml_class;
|
char *xml_type, *xml_vendor, *xml_class;
|
||||||
@@ -1285,7 +1285,7 @@ static void printosclassificationoutput(const struct OS_Classification_Results *
|
|||||||
// If family and vendor names are the same, no point being redundant
|
// If family and vendor names are the same, no point being redundant
|
||||||
if (strcmp(OSR->OSC[classno]->OS_Vendor, OSR->OSC[classno]->OS_Family) == 0)
|
if (strcmp(OSR->OSC[classno]->OS_Vendor, OSR->OSC[classno]->OS_Family) == 0)
|
||||||
Strncpy(tmpbuf, OSR->OSC[classno]->OS_Family, sizeof(tmpbuf));
|
Strncpy(tmpbuf, OSR->OSC[classno]->OS_Family, sizeof(tmpbuf));
|
||||||
else snprintf(tmpbuf, sizeof(tmpbuf), "%s %s", OSR->OSC[classno]->OS_Vendor, OSR->OSC[classno]->OS_Family);
|
else Snprintf(tmpbuf, sizeof(tmpbuf), "%s %s", OSR->OSC[classno]->OS_Vendor, OSR->OSC[classno]->OS_Family);
|
||||||
|
|
||||||
|
|
||||||
// Let's see if it is already in the array
|
// Let's see if it is already in the array
|
||||||
@@ -1353,7 +1353,7 @@ void printmacinfo(Target *currenths) {
|
|||||||
|
|
||||||
if (mac) {
|
if (mac) {
|
||||||
const char *macvendor = MACPrefix2Corp(mac);
|
const char *macvendor = MACPrefix2Corp(mac);
|
||||||
snprintf(macascii, sizeof(macascii), "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
Snprintf(macascii, sizeof(macascii), "%02X:%02X:%02X:%02X:%02X:%02X", mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||||
log_write(LOG_PLAIN, "MAC Address: %s (%s)\n", macascii, macvendor? macvendor : "Unknown");
|
log_write(LOG_PLAIN, "MAC Address: %s (%s)\n", macascii, macvendor? macvendor : "Unknown");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
10
portlist.cc
10
portlist.cc
@@ -336,11 +336,11 @@ void Port::setRPCProbeResults(int rpcs, unsigned long rpcp,
|
|||||||
serviceprobe_service = strdup(newsvc);
|
serviceprobe_service = strdup(newsvc);
|
||||||
serviceprobe_product = strdup(newsvc);
|
serviceprobe_product = strdup(newsvc);
|
||||||
if (rpc_lowver == rpc_highver)
|
if (rpc_lowver == rpc_highver)
|
||||||
snprintf(verbuf, sizeof(verbuf), "%i", rpc_lowver);
|
Snprintf(verbuf, sizeof(verbuf), "%i", rpc_lowver);
|
||||||
else
|
else
|
||||||
snprintf(verbuf, sizeof(verbuf), "%i-%i", rpc_lowver, rpc_highver);
|
Snprintf(verbuf, sizeof(verbuf), "%i-%i", rpc_lowver, rpc_highver);
|
||||||
serviceprobe_version = strdup(verbuf);
|
serviceprobe_version = strdup(verbuf);
|
||||||
snprintf(verbuf, sizeof(verbuf), "rpc #%li", rpc_program);
|
Snprintf(verbuf, sizeof(verbuf), "rpc #%li", rpc_program);
|
||||||
serviceprobe_extrainfo = strdup(verbuf);
|
serviceprobe_extrainfo = strdup(verbuf);
|
||||||
} else if (rpc_status == RPC_STATUS_UNKNOWN) {
|
} else if (rpc_status == RPC_STATUS_UNKNOWN) {
|
||||||
if (serviceprobe_service)
|
if (serviceprobe_service)
|
||||||
@@ -403,7 +403,7 @@ int PortList::addPort(u16 portno, u8 protocol, char *owner, int state) {
|
|||||||
|
|
||||||
if ((state == PORT_OPEN && o.verbose) || (o.debugging > 1)) {
|
if ((state == PORT_OPEN && o.verbose) || (o.debugging > 1)) {
|
||||||
if (owner && *owner) {
|
if (owner && *owner) {
|
||||||
snprintf(msg, sizeof(msg), " (owner: %s)", owner);
|
Snprintf(msg, sizeof(msg), " (owner: %s)", owner);
|
||||||
} else msg[0] = '\0';
|
} else msg[0] = '\0';
|
||||||
|
|
||||||
log_write(LOG_STDOUT, "Discovered %s port %hu/%s%s%s\n",
|
log_write(LOG_STDOUT, "Discovered %s port %hu/%s%s%s\n",
|
||||||
@@ -489,7 +489,7 @@ void PortList::setIdStr(const char *id) {
|
|||||||
len = strlen(id);
|
len = strlen(id);
|
||||||
len += 5; // " on " + \0
|
len += 5; // " on " + \0
|
||||||
idstr = (char *) safe_malloc(len);
|
idstr = (char *) safe_malloc(len);
|
||||||
snprintf(idstr, len, " on %s", id);
|
Snprintf(idstr, len, " on %s", id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -367,7 +367,7 @@ char *target_reason_str(Target *t) {
|
|||||||
static char reason[128];
|
static char reason[128];
|
||||||
memset(reason,'\0', 128);
|
memset(reason,'\0', 128);
|
||||||
assert(t->reason.reason_id != ER_NORESPONSE);
|
assert(t->reason.reason_id != ER_NORESPONSE);
|
||||||
snprintf(reason, 128, ", received %s",reason_str(t->reason.reason_id, SINGULAR));
|
Snprintf(reason, 128, ", received %s",reason_str(t->reason.reason_id, SINGULAR));
|
||||||
return reason;
|
return reason;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -377,7 +377,7 @@ char *target_reason_str(Target *t) {
|
|||||||
char *port_reason_str(state_reason_t r) {
|
char *port_reason_str(state_reason_t r) {
|
||||||
static char reason[128];
|
static char reason[128];
|
||||||
memset(reason,'\0', 128);
|
memset(reason,'\0', 128);
|
||||||
snprintf(reason, 128, "%s%s%s", reason_str(r.reason_id, SINGULAR),
|
Snprintf(reason, 128, "%s%s%s", reason_str(r.reason_id, SINGULAR),
|
||||||
(r.ip_addr.s_addr==0)?"":" from ",
|
(r.ip_addr.s_addr==0)?"":" from ",
|
||||||
(r.ip_addr.s_addr==0)?"":inet_ntoa(r.ip_addr));
|
(r.ip_addr.s_addr==0)?"":inet_ntoa(r.ip_addr));
|
||||||
return reason;
|
return reason;
|
||||||
|
|||||||
@@ -611,17 +611,17 @@ static char *probespec2ascii(probespec *pspec, char *buf, unsigned int bufsz) {
|
|||||||
if (pspec->pd.tcp.flags & TH_CWR) *f++ = 'C'; /* rfc 2481/3168 */
|
if (pspec->pd.tcp.flags & TH_CWR) *f++ = 'C'; /* rfc 2481/3168 */
|
||||||
*f++ = '\0';
|
*f++ = '\0';
|
||||||
}
|
}
|
||||||
snprintf(buf, bufsz, "tcp to port %hu; flags: %s", pspec->pd.tcp.dport,
|
Snprintf(buf, bufsz, "tcp to port %hu; flags: %s", pspec->pd.tcp.dport,
|
||||||
flagbuf);
|
flagbuf);
|
||||||
break;
|
break;
|
||||||
case PS_UDP:
|
case PS_UDP:
|
||||||
snprintf(buf, bufsz, "udp to port %hu", pspec->pd.udp.dport);
|
Snprintf(buf, bufsz, "udp to port %hu", pspec->pd.udp.dport);
|
||||||
break;
|
break;
|
||||||
case PS_PROTO:
|
case PS_PROTO:
|
||||||
snprintf(buf, bufsz, "protocol %u", (unsigned int) pspec->proto);
|
Snprintf(buf, bufsz, "protocol %u", (unsigned int) pspec->proto);
|
||||||
break;
|
break;
|
||||||
case PS_ARP:
|
case PS_ARP:
|
||||||
snprintf(buf, bufsz, "ARP");
|
Snprintf(buf, bufsz, "ARP");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fatal("Unexpected %s type encountered", __func__);
|
fatal("Unexpected %s type encountered", __func__);
|
||||||
@@ -2675,11 +2675,11 @@ static bool do_one_select_round(UltraScanInfo *USI, struct timeval *stime) {
|
|||||||
case ENETDOWN:
|
case ENETDOWN:
|
||||||
case ENETRESET:
|
case ENETRESET:
|
||||||
case ECONNABORTED:
|
case ECONNABORTED:
|
||||||
snprintf(buf, sizeof(buf), "Strange SO_ERROR from connection to %s (%d - '%s') -- bailing scan", host->target->targetipstr(), optval, strerror(optval) );
|
Snprintf(buf, sizeof(buf), "Strange SO_ERROR from connection to %s (%d - '%s') -- bailing scan", host->target->targetipstr(), optval, strerror(optval) );
|
||||||
pfatal(buf);
|
pfatal(buf);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
snprintf(buf, sizeof(buf), "Strange read error from %s (%d - '%s')", host->target->targetipstr(), optval, strerror(optval));
|
Snprintf(buf, sizeof(buf), "Strange read error from %s (%d - '%s')", host->target->targetipstr(), optval, strerror(optval));
|
||||||
perror(buf);
|
perror(buf);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -3258,7 +3258,7 @@ static void begin_sniffer(UltraScanInfo *USI, vector<Target *> &Targets) {
|
|||||||
|
|
||||||
if (doIndividual) {
|
if (doIndividual) {
|
||||||
for(targetno = 0; targetno < Targets.size(); targetno++) {
|
for(targetno = 0; targetno < Targets.size(); targetno++) {
|
||||||
len = snprintf(dst_hosts + filterlen,
|
len = Snprintf(dst_hosts + filterlen,
|
||||||
sizeof(dst_hosts) - filterlen,
|
sizeof(dst_hosts) - filterlen,
|
||||||
"%ssrc host %s", (targetno == 0)? "" : " or ",
|
"%ssrc host %s", (targetno == 0)? "" : " or ",
|
||||||
Targets[targetno]->targetipstr());
|
Targets[targetno]->targetipstr());
|
||||||
@@ -3273,11 +3273,11 @@ static void begin_sniffer(UltraScanInfo *USI, vector<Target *> &Targets) {
|
|||||||
|
|
||||||
if (USI->tcp_scan || USI->udp_scan) {
|
if (USI->tcp_scan || USI->udp_scan) {
|
||||||
if (doIndividual)
|
if (doIndividual)
|
||||||
len = snprintf(pcap_filter, sizeof(pcap_filter),
|
len = Snprintf(pcap_filter, sizeof(pcap_filter),
|
||||||
"dst host %s and (icmp or (%s and (%s)))",
|
"dst host %s and (icmp or (%s and (%s)))",
|
||||||
inet_ntoa(Targets[0]->v4source()),
|
inet_ntoa(Targets[0]->v4source()),
|
||||||
(USI->tcp_scan)? "tcp" : "udp", dst_hosts);
|
(USI->tcp_scan)? "tcp" : "udp", dst_hosts);
|
||||||
else len = snprintf(pcap_filter, sizeof(pcap_filter),
|
else len = Snprintf(pcap_filter, sizeof(pcap_filter),
|
||||||
"dst host %s and (icmp or %s)",
|
"dst host %s and (icmp or %s)",
|
||||||
inet_ntoa(Targets[0]->v4source()),
|
inet_ntoa(Targets[0]->v4source()),
|
||||||
(USI->tcp_scan)? "tcp" : "udp");
|
(USI->tcp_scan)? "tcp" : "udp");
|
||||||
@@ -3286,11 +3286,11 @@ static void begin_sniffer(UltraScanInfo *USI, vector<Target *> &Targets) {
|
|||||||
filterlen = len;
|
filterlen = len;
|
||||||
} else if (USI->prot_scan) {
|
} else if (USI->prot_scan) {
|
||||||
if (doIndividual)
|
if (doIndividual)
|
||||||
len = snprintf(pcap_filter, sizeof(pcap_filter),
|
len = Snprintf(pcap_filter, sizeof(pcap_filter),
|
||||||
"dst host %s and (icmp or (%s))",
|
"dst host %s and (icmp or (%s))",
|
||||||
inet_ntoa(Targets[0]->v4source()), dst_hosts);
|
inet_ntoa(Targets[0]->v4source()), dst_hosts);
|
||||||
else
|
else
|
||||||
len = snprintf(pcap_filter, sizeof(pcap_filter), "dst host %s",
|
len = Snprintf(pcap_filter, sizeof(pcap_filter), "dst host %s",
|
||||||
inet_ntoa(Targets[0]->v4source()));
|
inet_ntoa(Targets[0]->v4source()));
|
||||||
if (len < 0 || len >= (int) sizeof(pcap_filter))
|
if (len < 0 || len >= (int) sizeof(pcap_filter))
|
||||||
fatal("ran out of space in pcap filter");
|
fatal("ran out of space in pcap filter");
|
||||||
@@ -3298,7 +3298,7 @@ static void begin_sniffer(UltraScanInfo *USI, vector<Target *> &Targets) {
|
|||||||
} else if (USI->ping_scan_arp) {
|
} else if (USI->ping_scan_arp) {
|
||||||
const u8 *mac = Targets[0]->SrcMACAddress();
|
const u8 *mac = Targets[0]->SrcMACAddress();
|
||||||
assert(mac);
|
assert(mac);
|
||||||
len = snprintf(pcap_filter, sizeof(pcap_filter),
|
len = Snprintf(pcap_filter, sizeof(pcap_filter),
|
||||||
"arp and ether dst host %02X:%02X:%02X:%02X:%02X:%02X",
|
"arp and ether dst host %02X:%02X:%02X:%02X:%02X:%02X",
|
||||||
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||||
if (len < 0 || len >= (int) sizeof(pcap_filter))
|
if (len < 0 || len >= (int) sizeof(pcap_filter))
|
||||||
@@ -3456,7 +3456,7 @@ void ultra_scan(vector<Target *> &Targets, struct scan_lists *ports,
|
|||||||
bool plural = (Targets.size() != 1);
|
bool plural = (Targets.size() != 1);
|
||||||
if (!plural) {
|
if (!plural) {
|
||||||
(*(Targets.begin()))->NameIP(targetstr, sizeof(targetstr));
|
(*(Targets.begin()))->NameIP(targetstr, sizeof(targetstr));
|
||||||
} else snprintf(targetstr, sizeof(targetstr), "%d hosts", (int) Targets.size());
|
} else Snprintf(targetstr, sizeof(targetstr), "%d hosts", (int) Targets.size());
|
||||||
log_write(LOG_STDOUT, "Scanning %s [%d port%s%s]\n", targetstr, USI->gstats->numprobes, (USI->gstats->numprobes != 1)? "s" : "", plural? "/host" : "");
|
log_write(LOG_STDOUT, "Scanning %s [%d port%s%s]\n", targetstr, USI->gstats->numprobes, (USI->gstats->numprobes != 1)? "s" : "", plural? "/host" : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -3508,10 +3508,10 @@ void ultra_scan(vector<Target *> &Targets, struct scan_lists *ports,
|
|||||||
if (o.verbose) {
|
if (o.verbose) {
|
||||||
char additional_info[128];
|
char additional_info[128];
|
||||||
if (USI->gstats->num_hosts_timedout == 0)
|
if (USI->gstats->num_hosts_timedout == 0)
|
||||||
snprintf(additional_info, sizeof(additional_info), "%lu total %s",
|
Snprintf(additional_info, sizeof(additional_info), "%lu total %s",
|
||||||
(unsigned long) USI->gstats->numprobes * Targets.size(),
|
(unsigned long) USI->gstats->numprobes * Targets.size(),
|
||||||
(scantype == PING_SCAN_ARP)? "hosts" : "ports");
|
(scantype == PING_SCAN_ARP)? "hosts" : "ports");
|
||||||
else snprintf(additional_info, sizeof(additional_info), "%d %s timed out",
|
else Snprintf(additional_info, sizeof(additional_info), "%d %s timed out",
|
||||||
USI->gstats->num_hosts_timedout,
|
USI->gstats->num_hosts_timedout,
|
||||||
(USI->gstats->num_hosts_timedout == 1)? "host" : "hosts");
|
(USI->gstats->num_hosts_timedout == 1)? "host" : "hosts");
|
||||||
USI->SPM->endTask(NULL, additional_info);
|
USI->SPM->endTask(NULL, additional_info);
|
||||||
@@ -3540,7 +3540,7 @@ void bounce_scan(Target *target, u16 *portarray, int numports,
|
|||||||
|
|
||||||
if (! numports) return; /* nothing to scan for */
|
if (! numports) return; /* nothing to scan for */
|
||||||
|
|
||||||
snprintf(targetstr, 20, "%d,%d,%d,%d,", UC(t[0]), UC(t[1]), UC(t[2]), UC(t[3]));
|
Snprintf(targetstr, 20, "%d,%d,%d,%d,", UC(t[0]), UC(t[1]), UC(t[2]), UC(t[3]));
|
||||||
|
|
||||||
starttime = time(NULL);
|
starttime = time(NULL);
|
||||||
if (o.verbose || o.debugging) {
|
if (o.verbose || o.debugging) {
|
||||||
@@ -3557,7 +3557,7 @@ void bounce_scan(Target *target, u16 *portarray, int numports,
|
|||||||
portno = htons(portarray[i]);
|
portno = htons(portarray[i]);
|
||||||
p1 = ((unsigned char *) &portno)[0];
|
p1 = ((unsigned char *) &portno)[0];
|
||||||
p2 = ((unsigned char *) &portno)[1];
|
p2 = ((unsigned char *) &portno)[1];
|
||||||
snprintf(command, 512, "PORT %s%i,%i\r\n", targetstr, p1,p2);
|
Snprintf(command, 512, "PORT %s%i,%i\r\n", targetstr, p1,p2);
|
||||||
if (o.debugging) log_write(LOG_STDOUT, "Attempting command: %s", command);
|
if (o.debugging) log_write(LOG_STDOUT, "Attempting command: %s", command);
|
||||||
if (send(sd, command, strlen(command), 0) < 0 ) {
|
if (send(sd, command, strlen(command), 0) < 0 ) {
|
||||||
gh_perror("send in %s", __func__);
|
gh_perror("send in %s", __func__);
|
||||||
@@ -3830,7 +3830,7 @@ void pos_scan(Target *target, u16 *portarray, int numports, stype scantype) {
|
|||||||
// no RPC ports need scanning.
|
// no RPC ports need scanning.
|
||||||
if (!SPM) {
|
if (!SPM) {
|
||||||
char scanname[48];
|
char scanname[48];
|
||||||
snprintf(scanname, sizeof(scanname), "%s against %s", scantype2str(scantype), target->NameIP());
|
Snprintf(scanname, sizeof(scanname), "%s against %s", scantype2str(scantype), target->NameIP());
|
||||||
scanname[sizeof(scanname) - 1] = '\0';
|
scanname[sizeof(scanname) - 1] = '\0';
|
||||||
SPM = new ScanProgressMeter(scanname);
|
SPM = new ScanProgressMeter(scanname);
|
||||||
}
|
}
|
||||||
@@ -3990,7 +3990,7 @@ void pos_scan(Target *target, u16 *portarray, int numports, stype scantype) {
|
|||||||
numports = rpcportsscanned;
|
numports = rpcportsscanned;
|
||||||
if (SPM && o.verbose && (numports > 0)) {
|
if (SPM && o.verbose && (numports > 0)) {
|
||||||
char scannedportsstr[14];
|
char scannedportsstr[14];
|
||||||
snprintf(scannedportsstr, sizeof(scannedportsstr), "%d %s", numports, (numports > 1)? "ports" : "port");
|
Snprintf(scannedportsstr, sizeof(scannedportsstr), "%d %s", numports, (numports > 1)? "ports" : "port");
|
||||||
SPM->endTask(NULL, scannedportsstr);
|
SPM->endTask(NULL, scannedportsstr);
|
||||||
}
|
}
|
||||||
posscan_timedout:
|
posscan_timedout:
|
||||||
|
|||||||
@@ -1411,12 +1411,12 @@ void ServiceNFO::addToServiceFingerprint(const char *probeName, const u8 *resp,
|
|||||||
if (servicefplen == 0) {
|
if (servicefplen == 0) {
|
||||||
timep = time(NULL);
|
timep = time(NULL);
|
||||||
ltime = localtime(&timep);
|
ltime = localtime(&timep);
|
||||||
servicefplen = snprintf(servicefp, spaceleft, "SF-Port%hu-%s:V=%s%s%%I=%d%%D=%d/%d%%Time=%X%%P=%s", portno, proto2ascii(proto, true), NMAP_VERSION, (tunnel == SERVICE_TUNNEL_SSL)? "%T=SSL" : "", o.version_intensity, ltime->tm_mon + 1, ltime->tm_mday, (int) timep, NMAP_PLATFORM);
|
servicefplen = Snprintf(servicefp, spaceleft, "SF-Port%hu-%s:V=%s%s%%I=%d%%D=%d/%d%%Time=%X%%P=%s", portno, proto2ascii(proto, true), NMAP_VERSION, (tunnel == SERVICE_TUNNEL_SSL)? "%T=SSL" : "", o.version_intensity, ltime->tm_mon + 1, ltime->tm_mday, (int) timep, NMAP_PLATFORM);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note that we give the total length of the response, even though we
|
// Note that we give the total length of the response, even though we
|
||||||
// may truncate
|
// may truncate
|
||||||
len = snprintf(buf, sizeof(buf), "%%r(%s,%X,\"", probeName, resplen);
|
len = Snprintf(buf, sizeof(buf), "%%r(%s,%X,\"", probeName, resplen);
|
||||||
addServiceString(buf, servicewrap);
|
addServiceString(buf, servicewrap);
|
||||||
|
|
||||||
// Now for the probe response itself ...
|
// Now for the probe response itself ...
|
||||||
@@ -1446,7 +1446,7 @@ void ServiceNFO::addToServiceFingerprint(const char *probeName, const u8 *resp,
|
|||||||
} else {
|
} else {
|
||||||
addServiceChar('\\', servicewrap);
|
addServiceChar('\\', servicewrap);
|
||||||
addServiceChar('x', servicewrap);
|
addServiceChar('x', servicewrap);
|
||||||
snprintf(buf, sizeof(buf), "%02x", resp[srcidx]);
|
Snprintf(buf, sizeof(buf), "%02x", resp[srcidx]);
|
||||||
addServiceChar(*buf, servicewrap);
|
addServiceChar(*buf, servicewrap);
|
||||||
addServiceChar(*(buf+1), servicewrap);
|
addServiceChar(*(buf+1), servicewrap);
|
||||||
}
|
}
|
||||||
@@ -2394,7 +2394,7 @@ int service_scan(vector<Target *> &Targets) {
|
|||||||
bool plural = (Targets.size() != 1);
|
bool plural = (Targets.size() != 1);
|
||||||
if (!plural) {
|
if (!plural) {
|
||||||
(*(Targets.begin()))->NameIP(targetstr, sizeof(targetstr));
|
(*(Targets.begin()))->NameIP(targetstr, sizeof(targetstr));
|
||||||
} else snprintf(targetstr, sizeof(targetstr), "%u hosts", (unsigned) Targets.size());
|
} else Snprintf(targetstr, sizeof(targetstr), "%u hosts", (unsigned) Targets.size());
|
||||||
|
|
||||||
log_write(LOG_STDOUT, "Scanning %u %s on %s\n",
|
log_write(LOG_STDOUT, "Scanning %u %s on %s\n",
|
||||||
(unsigned) SG->services_remaining.size(),
|
(unsigned) SG->services_remaining.size(),
|
||||||
@@ -2430,11 +2430,11 @@ int service_scan(vector<Target *> &Targets) {
|
|||||||
if (o.verbose) {
|
if (o.verbose) {
|
||||||
char additional_info[128];
|
char additional_info[128];
|
||||||
if (SG->num_hosts_timedout == 0)
|
if (SG->num_hosts_timedout == 0)
|
||||||
snprintf(additional_info, sizeof(additional_info), "%u %s on %u %s",
|
Snprintf(additional_info, sizeof(additional_info), "%u %s on %u %s",
|
||||||
(unsigned) SG->services_finished.size(),
|
(unsigned) SG->services_finished.size(),
|
||||||
(SG->services_finished.size() == 1)? "service" : "services",
|
(SG->services_finished.size() == 1)? "service" : "services",
|
||||||
(unsigned) Targets.size(), (Targets.size() == 1)? "host" : "hosts");
|
(unsigned) Targets.size(), (Targets.size() == 1)? "host" : "hosts");
|
||||||
else snprintf(additional_info, sizeof(additional_info), "%u %s timed out",
|
else Snprintf(additional_info, sizeof(additional_info), "%u %s timed out",
|
||||||
SG->num_hosts_timedout,
|
SG->num_hosts_timedout,
|
||||||
(SG->num_hosts_timedout == 1)? "host" : "hosts");
|
(SG->num_hosts_timedout == 1)? "host" : "hosts");
|
||||||
SG->SPM->endTask(NULL, additional_info);
|
SG->SPM->endTask(NULL, additional_info);
|
||||||
|
|||||||
@@ -1215,7 +1215,7 @@ while(pt->block_unaccounted) {
|
|||||||
newstate = HOST_DOWN;
|
newstate = HOST_DOWN;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
snprintf (buf, sizeof(buf), "Strange read error from %s", hostbatch[hostindex]->targetipstr());
|
Snprintf (buf, sizeof(buf), "Strange read error from %s", hostbatch[hostindex]->targetipstr());
|
||||||
error("%s: %s", buf, strerror(sock_err));
|
error("%s: %s", buf, strerror(sock_err));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1612,7 +1612,7 @@ static void massping(Target *hostbatch[], int num_hosts,
|
|||||||
= 104 byte snaplen */
|
= 104 byte snaplen */
|
||||||
pd = my_pcap_open_live(hostbatch[0]->deviceName(), 104, o.spoofsource, pcap_selectable_fd_valid()? 200 : 15);
|
pd = my_pcap_open_live(hostbatch[0]->deviceName(), 104, o.spoofsource, pcap_selectable_fd_valid()? 200 : 15);
|
||||||
|
|
||||||
snprintf(filter, sizeof(filter), "(icmp and dst host %s) or ((tcp or udp) and dst host %s and ( dst port %d or dst port %d or dst port %d or dst port %d or dst port %d))",
|
Snprintf(filter, sizeof(filter), "(icmp and dst host %s) or ((tcp or udp) and dst host %s and ( dst port %d or dst port %d or dst port %d or dst port %d or dst port %d))",
|
||||||
inet_ntoa(hostbatch[0]->v4source()),
|
inet_ntoa(hostbatch[0]->v4source()),
|
||||||
inet_ntoa(hostbatch[0]->v4source()),
|
inet_ntoa(hostbatch[0]->v4source()),
|
||||||
sportbase , sportbase + 1, sportbase + 2, sportbase + 3,
|
sportbase , sportbase + 1, sportbase + 2, sportbase + 3,
|
||||||
|
|||||||
94
tcpip.cc
94
tcpip.cc
@@ -187,10 +187,10 @@ static char *ll2shortascii(unsigned long long bytes, char *buf, int buflen) {
|
|||||||
if (buflen < 2 || !buf) fatal("Bogus parameter passed to %s", __func__);
|
if (buflen < 2 || !buf) fatal("Bogus parameter passed to %s", __func__);
|
||||||
|
|
||||||
if (bytes > 1000000) {
|
if (bytes > 1000000) {
|
||||||
snprintf(buf, buflen, "%.3fMB", bytes / 1000000.0);
|
Snprintf(buf, buflen, "%.3fMB", bytes / 1000000.0);
|
||||||
} else if (bytes > 10000) {
|
} else if (bytes > 10000) {
|
||||||
snprintf(buf, buflen, "%.3fKB", bytes / 1000.0);
|
Snprintf(buf, buflen, "%.3fKB", bytes / 1000.0);
|
||||||
} else snprintf(buf, buflen, "%uB", (unsigned int) bytes);
|
} else Snprintf(buf, buflen, "%uB", (unsigned int) bytes);
|
||||||
|
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
@@ -204,7 +204,7 @@ char *getFinalPacketStats(char *buf, int buflen) {
|
|||||||
if (buflen <= 10 || !buf)
|
if (buflen <= 10 || !buf)
|
||||||
fatal("%s called with woefully inadequate parameters", __func__);
|
fatal("%s called with woefully inadequate parameters", __func__);
|
||||||
|
|
||||||
snprintf(buf, buflen,
|
Snprintf(buf, buflen,
|
||||||
#if WIN32
|
#if WIN32
|
||||||
"Raw packets sent: %I64u (%s) | Rcvd: %I64u (%s)",
|
"Raw packets sent: %I64u (%s) | Rcvd: %I64u (%s)",
|
||||||
#else
|
#else
|
||||||
@@ -252,10 +252,10 @@ void PacketTrace::traceArp(pdirection pdir, const u8 *frame, u32 len,
|
|||||||
if (frame[21] == 1) /* arp REQUEST */ {
|
if (frame[21] == 1) /* arp REQUEST */ {
|
||||||
inet_ntop(AF_INET, frame+38, who_has, sizeof(who_has));
|
inet_ntop(AF_INET, frame+38, who_has, sizeof(who_has));
|
||||||
inet_ntop(AF_INET, frame+28, tell, sizeof(tell));
|
inet_ntop(AF_INET, frame+28, tell, sizeof(tell));
|
||||||
snprintf(arpdesc, sizeof(arpdesc), "who-has %s tell %s", who_has, tell);
|
Snprintf(arpdesc, sizeof(arpdesc), "who-has %s tell %s", who_has, tell);
|
||||||
} else { /* ARP REPLY */
|
} else { /* ARP REPLY */
|
||||||
inet_ntop(AF_INET, frame+28, who_has, sizeof(who_has));
|
inet_ntop(AF_INET, frame+28, who_has, sizeof(who_has));
|
||||||
snprintf(arpdesc, sizeof(arpdesc),
|
Snprintf(arpdesc, sizeof(arpdesc),
|
||||||
"reply %s is-at %02X:%02X:%02X:%02X:%02X:%02X", who_has,
|
"reply %s is-at %02X:%02X:%02X:%02X:%02X:%02X", who_has,
|
||||||
frame[22], frame[23], frame[24], frame[25], frame[26], frame[27]);
|
frame[22], frame[23], frame[24], frame[25], frame[26], frame[27]);
|
||||||
}
|
}
|
||||||
@@ -283,13 +283,13 @@ static void tcppacketoptinfo(u8 *optp, int len, char *result, int bufsize) {
|
|||||||
ch = '<';
|
ch = '<';
|
||||||
|
|
||||||
while(len > 0 && bufsize > 2) {
|
while(len > 0 && bufsize > 2) {
|
||||||
snprintf(p, bufsize, "%c", ch);
|
Snprintf(p, bufsize, "%c", ch);
|
||||||
bufsize--;
|
bufsize--;
|
||||||
p++;
|
p++;
|
||||||
opcode=*q++;
|
opcode=*q++;
|
||||||
if (!opcode) { /* End of List */
|
if (!opcode) { /* End of List */
|
||||||
|
|
||||||
snprintf(p, bufsize, "eol");
|
Snprintf(p, bufsize, "eol");
|
||||||
bufsize -= strlen(p);
|
bufsize -= strlen(p);
|
||||||
p += strlen(p);
|
p += strlen(p);
|
||||||
|
|
||||||
@@ -297,7 +297,7 @@ static void tcppacketoptinfo(u8 *optp, int len, char *result, int bufsize) {
|
|||||||
|
|
||||||
} else if (opcode == 1) { /* No Op */
|
} else if (opcode == 1) { /* No Op */
|
||||||
|
|
||||||
snprintf(p, bufsize, "nop");
|
Snprintf(p, bufsize, "nop");
|
||||||
bufsize -= strlen(p);
|
bufsize -= strlen(p);
|
||||||
p += strlen(p);
|
p += strlen(p);
|
||||||
|
|
||||||
@@ -311,7 +311,7 @@ static void tcppacketoptinfo(u8 *optp, int len, char *result, int bufsize) {
|
|||||||
q++;
|
q++;
|
||||||
memcpy(&tmpshort, q, 2);
|
memcpy(&tmpshort, q, 2);
|
||||||
|
|
||||||
snprintf(p, bufsize, "mss %u", ntohs(tmpshort));
|
Snprintf(p, bufsize, "mss %u", ntohs(tmpshort));
|
||||||
bufsize -= strlen(p);
|
bufsize -= strlen(p);
|
||||||
p += strlen(p);
|
p += strlen(p);
|
||||||
|
|
||||||
@@ -325,7 +325,7 @@ static void tcppacketoptinfo(u8 *optp, int len, char *result, int bufsize) {
|
|||||||
|
|
||||||
q++;
|
q++;
|
||||||
|
|
||||||
snprintf(p, bufsize, "wscale %u", *q);
|
Snprintf(p, bufsize, "wscale %u", *q);
|
||||||
bufsize -= strlen(p);
|
bufsize -= strlen(p);
|
||||||
p += strlen(p);
|
p += strlen(p);
|
||||||
|
|
||||||
@@ -337,7 +337,7 @@ static void tcppacketoptinfo(u8 *optp, int len, char *result, int bufsize) {
|
|||||||
if(len<2)
|
if(len<2)
|
||||||
break; /* SACK permitted option has 2 bytes */
|
break; /* SACK permitted option has 2 bytes */
|
||||||
|
|
||||||
snprintf(p, bufsize, "sackOK");
|
Snprintf(p, bufsize, "sackOK");
|
||||||
bufsize -= strlen(p);
|
bufsize -= strlen(p);
|
||||||
p += strlen(p);
|
p += strlen(p);
|
||||||
|
|
||||||
@@ -353,17 +353,17 @@ static void tcppacketoptinfo(u8 *optp, int len, char *result, int bufsize) {
|
|||||||
q++;
|
q++;
|
||||||
|
|
||||||
if((sackoptlen-2) % 8 != 0) {
|
if((sackoptlen-2) % 8 != 0) {
|
||||||
snprintf(p, bufsize, "malformed sack");
|
Snprintf(p, bufsize, "malformed sack");
|
||||||
bufsize -= strlen(p);
|
bufsize -= strlen(p);
|
||||||
p += strlen(p);
|
p += strlen(p);
|
||||||
} else {
|
} else {
|
||||||
snprintf(p, bufsize, "sack %d ", (sackoptlen-2)/8);
|
Snprintf(p, bufsize, "sack %d ", (sackoptlen-2)/8);
|
||||||
bufsize -= strlen(p);
|
bufsize -= strlen(p);
|
||||||
p += strlen(p);
|
p += strlen(p);
|
||||||
for(int i = 0; i < sackoptlen - 2; i += 8) {
|
for(int i = 0; i < sackoptlen - 2; i += 8) {
|
||||||
memcpy(&tmpword1, q + i, 4);
|
memcpy(&tmpword1, q + i, 4);
|
||||||
memcpy(&tmpword2, q + i + 4, 4);
|
memcpy(&tmpword2, q + i + 4, 4);
|
||||||
snprintf(p, bufsize, "{%u:%u}", tmpword1, tmpword2);
|
Snprintf(p, bufsize, "{%u:%u}", tmpword1, tmpword2);
|
||||||
bufsize -= strlen(p);
|
bufsize -= strlen(p);
|
||||||
p += strlen(p);
|
p += strlen(p);
|
||||||
}
|
}
|
||||||
@@ -381,7 +381,7 @@ static void tcppacketoptinfo(u8 *optp, int len, char *result, int bufsize) {
|
|||||||
memcpy(&tmpword1, q, 4);
|
memcpy(&tmpword1, q, 4);
|
||||||
memcpy(&tmpword2, q+4, 4);
|
memcpy(&tmpword2, q+4, 4);
|
||||||
|
|
||||||
snprintf(p, bufsize, "timestamp %u %u", ntohl(tmpword1), ntohl(tmpword2));
|
Snprintf(p, bufsize, "timestamp %u %u", ntohl(tmpword1), ntohl(tmpword2));
|
||||||
bufsize -= strlen(p);
|
bufsize -= strlen(p);
|
||||||
p += strlen(p);
|
p += strlen(p);
|
||||||
|
|
||||||
@@ -398,7 +398,7 @@ static void tcppacketoptinfo(u8 *optp, int len, char *result, int bufsize) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(p, bufsize, ">");
|
Snprintf(p, bufsize, ">");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Returns a buffer of ASCII information about a packet that may look
|
/* Returns a buffer of ASCII information about a packet that may look
|
||||||
@@ -433,11 +433,11 @@ static const char *ippackethdrinfo(const u8 *packet, u32 len) {
|
|||||||
frag_off = 8 * (ntohs(ip->ip_off) & 8191) /* 2^13 - 1 */;
|
frag_off = 8 * (ntohs(ip->ip_off) & 8191) /* 2^13 - 1 */;
|
||||||
more_fragments = ntohs(ip->ip_off) & IP_MF;
|
more_fragments = ntohs(ip->ip_off) & IP_MF;
|
||||||
if (frag_off || more_fragments) {
|
if (frag_off || more_fragments) {
|
||||||
snprintf(fragnfo, sizeof(fragnfo), " frag offset=%d%s", frag_off, more_fragments ? "+" : "");
|
Snprintf(fragnfo, sizeof(fragnfo), " frag offset=%d%s", frag_off, more_fragments ? "+" : "");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
snprintf(ipinfo, sizeof(ipinfo), "ttl=%d id=%d iplen=%d%s %s%s%s",
|
Snprintf(ipinfo, sizeof(ipinfo), "ttl=%d id=%d iplen=%d%s %s%s%s",
|
||||||
ip->ip_ttl, ntohs(ip->ip_id), ntohs(ip->ip_len), fragnfo,
|
ip->ip_ttl, ntohs(ip->ip_id), ntohs(ip->ip_len), fragnfo,
|
||||||
ip->ip_hl==5?"":"ipopts={",
|
ip->ip_hl==5?"":"ipopts={",
|
||||||
ip->ip_hl==5?"":print_ip_options((u8*)ip + sizeof(struct ip), MIN((ip->ip_hl-5)*4,len-sizeof(struct ip))),
|
ip->ip_hl==5?"":print_ip_options((u8*)ip + sizeof(struct ip), MIN((ip->ip_hl-5)*4,len-sizeof(struct ip))),
|
||||||
@@ -451,7 +451,7 @@ static const char *ippackethdrinfo(const u8 *packet, u32 len) {
|
|||||||
|
|
||||||
tcp = (struct tcp_hdr *) (packet + ip->ip_hl * 4);
|
tcp = (struct tcp_hdr *) (packet + ip->ip_hl * 4);
|
||||||
if (frag_off > 8 || len < (u32) ip->ip_hl * 4 + 8)
|
if (frag_off > 8 || len < (u32) ip->ip_hl * 4 + 8)
|
||||||
snprintf(protoinfo, sizeof(protoinfo), "TCP %s:?? > %s:?? ?? %s (incomplete)", srchost, dsthost, ipinfo);
|
Snprintf(protoinfo, sizeof(protoinfo), "TCP %s:?? > %s:?? ?? %s (incomplete)", srchost, dsthost, ipinfo);
|
||||||
else if (frag_off == 8) {// at least we can get TCP flags and ACKn
|
else if (frag_off == 8) {// at least we can get TCP flags and ACKn
|
||||||
tcp = (struct tcp_hdr *)((u8 *) tcp - frag_off); // ugly?
|
tcp = (struct tcp_hdr *)((u8 *) tcp - frag_off); // ugly?
|
||||||
p = tflags;
|
p = tflags;
|
||||||
@@ -462,7 +462,7 @@ static const char *ippackethdrinfo(const u8 *packet, u32 len) {
|
|||||||
if (tcp->th_flags & TH_PUSH) *p++ = 'P';
|
if (tcp->th_flags & TH_PUSH) *p++ = 'P';
|
||||||
if (tcp->th_flags & TH_ACK) {
|
if (tcp->th_flags & TH_ACK) {
|
||||||
*p++ = 'A';
|
*p++ = 'A';
|
||||||
snprintf(tcpinfo, sizeof(tcpinfo), " ack=%lu",
|
Snprintf(tcpinfo, sizeof(tcpinfo), " ack=%lu",
|
||||||
(unsigned long) ntohl(tcp->th_ack));
|
(unsigned long) ntohl(tcp->th_ack));
|
||||||
}
|
}
|
||||||
if (tcp->th_flags & TH_URG) *p++ = 'U';
|
if (tcp->th_flags & TH_URG) *p++ = 'U';
|
||||||
@@ -473,7 +473,7 @@ static const char *ippackethdrinfo(const u8 *packet, u32 len) {
|
|||||||
if((u32) tcp->th_off * 4 > sizeof(struct tcp_hdr)) {
|
if((u32) tcp->th_off * 4 > sizeof(struct tcp_hdr)) {
|
||||||
// tcp options
|
// tcp options
|
||||||
if(len < (u32) ip->ip_hl * 4 + (u32) tcp->th_off * 4 - frag_off) {
|
if(len < (u32) ip->ip_hl * 4 + (u32) tcp->th_off * 4 - frag_off) {
|
||||||
snprintf(tcpoptinfo, sizeof(tcpoptinfo), "option incomplete");
|
Snprintf(tcpoptinfo, sizeof(tcpoptinfo), "option incomplete");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
tcppacketoptinfo((u8*) tcp + sizeof(struct tcp_hdr),
|
tcppacketoptinfo((u8*) tcp + sizeof(struct tcp_hdr),
|
||||||
@@ -482,15 +482,15 @@ static const char *ippackethdrinfo(const u8 *packet, u32 len) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(protoinfo, sizeof(protoinfo), "TCP %s:?? > %s:?? %s %s %s %s",
|
Snprintf(protoinfo, sizeof(protoinfo), "TCP %s:?? > %s:?? %s %s %s %s",
|
||||||
srchost, dsthost, tflags, ipinfo, tcpinfo, tcpoptinfo);
|
srchost, dsthost, tflags, ipinfo, tcpinfo, tcpoptinfo);
|
||||||
} else if (len < (u32) ip->ip_hl * 4 + 16) { // we can get ports and seq
|
} else if (len < (u32) ip->ip_hl * 4 + 16) { // we can get ports and seq
|
||||||
snprintf(tcpinfo, sizeof(tcpinfo), "seq=%lu (incomplete)", (unsigned long) ntohl(tcp->th_seq));
|
Snprintf(tcpinfo, sizeof(tcpinfo), "seq=%lu (incomplete)", (unsigned long) ntohl(tcp->th_seq));
|
||||||
snprintf(protoinfo, sizeof(protoinfo), "TCP %s:%d > %s:%d ?? %s %s",
|
Snprintf(protoinfo, sizeof(protoinfo), "TCP %s:%d > %s:%d ?? %s %s",
|
||||||
srchost, ntohs(tcp->th_sport), dsthost, ntohs(tcp->th_dport), ipinfo, tcpinfo);
|
srchost, ntohs(tcp->th_sport), dsthost, ntohs(tcp->th_dport), ipinfo, tcpinfo);
|
||||||
} else { // at least first 16 bytes of TCP header are there
|
} else { // at least first 16 bytes of TCP header are there
|
||||||
|
|
||||||
snprintf(tcpinfo, sizeof(tcpinfo), "seq=%lu win=%hu",
|
Snprintf(tcpinfo, sizeof(tcpinfo), "seq=%lu win=%hu",
|
||||||
(unsigned long) ntohl(tcp->th_seq),
|
(unsigned long) ntohl(tcp->th_seq),
|
||||||
ntohs(tcp->th_win));
|
ntohs(tcp->th_win));
|
||||||
p = tflags;
|
p = tflags;
|
||||||
@@ -501,7 +501,7 @@ static const char *ippackethdrinfo(const u8 *packet, u32 len) {
|
|||||||
if (tcp->th_flags & TH_PUSH) *p++ = 'P';
|
if (tcp->th_flags & TH_PUSH) *p++ = 'P';
|
||||||
if (tcp->th_flags & TH_ACK) {
|
if (tcp->th_flags & TH_ACK) {
|
||||||
*p++ = 'A';
|
*p++ = 'A';
|
||||||
snprintf(buf, sizeof(buf), " ack=%lu",
|
Snprintf(buf, sizeof(buf), " ack=%lu",
|
||||||
(unsigned long) ntohl(tcp->th_ack));
|
(unsigned long) ntohl(tcp->th_ack));
|
||||||
strncat(tcpinfo, buf, sizeof(tcpinfo) - strlen(tcpinfo) - 1);
|
strncat(tcpinfo, buf, sizeof(tcpinfo) - strlen(tcpinfo) - 1);
|
||||||
}
|
}
|
||||||
@@ -513,7 +513,7 @@ static const char *ippackethdrinfo(const u8 *packet, u32 len) {
|
|||||||
if((u32) tcp->th_off * 4 > sizeof(struct tcp_hdr)) {
|
if((u32) tcp->th_off * 4 > sizeof(struct tcp_hdr)) {
|
||||||
// tcp options
|
// tcp options
|
||||||
if(len < (u32) ip->ip_hl * 4 + (u32) tcp->th_off * 4) {
|
if(len < (u32) ip->ip_hl * 4 + (u32) tcp->th_off * 4) {
|
||||||
snprintf(tcpoptinfo, sizeof(tcpoptinfo), "option incomplete");
|
Snprintf(tcpoptinfo, sizeof(tcpoptinfo), "option incomplete");
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
tcppacketoptinfo((u8*) tcp + sizeof(struct tcp_hdr),
|
tcppacketoptinfo((u8*) tcp + sizeof(struct tcp_hdr),
|
||||||
@@ -522,20 +522,20 @@ static const char *ippackethdrinfo(const u8 *packet, u32 len) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
snprintf(protoinfo, sizeof(protoinfo), "TCP %s:%d > %s:%d %s %s %s %s",
|
Snprintf(protoinfo, sizeof(protoinfo), "TCP %s:%d > %s:%d %s %s %s %s",
|
||||||
srchost, ntohs(tcp->th_sport), dsthost, ntohs(tcp->th_dport),
|
srchost, ntohs(tcp->th_sport), dsthost, ntohs(tcp->th_dport),
|
||||||
tflags, ipinfo, tcpinfo, tcpoptinfo);
|
tflags, ipinfo, tcpinfo, tcpoptinfo);
|
||||||
}
|
}
|
||||||
} else if (ip->ip_p == IPPROTO_UDP && frag_off) {
|
} else if (ip->ip_p == IPPROTO_UDP && frag_off) {
|
||||||
snprintf(protoinfo, sizeof(protoinfo), "UDP %s:?? > %s:?? fragment %s (incomplete)", srchost, dsthost, ipinfo);
|
Snprintf(protoinfo, sizeof(protoinfo), "UDP %s:?? > %s:?? fragment %s (incomplete)", srchost, dsthost, ipinfo);
|
||||||
} else if (ip->ip_p == IPPROTO_UDP) {
|
} else if (ip->ip_p == IPPROTO_UDP) {
|
||||||
udp = (struct udp_hdr *) (packet + sizeof(struct ip));
|
udp = (struct udp_hdr *) (packet + sizeof(struct ip));
|
||||||
|
|
||||||
snprintf(protoinfo, sizeof(protoinfo), "UDP %s:%d > %s:%d %s",
|
Snprintf(protoinfo, sizeof(protoinfo), "UDP %s:%d > %s:%d %s",
|
||||||
srchost, ntohs(udp->uh_sport), dsthost, ntohs(udp->uh_dport),
|
srchost, ntohs(udp->uh_sport), dsthost, ntohs(udp->uh_dport),
|
||||||
ipinfo);
|
ipinfo);
|
||||||
} else if (ip->ip_p == IPPROTO_ICMP && frag_off) {
|
} else if (ip->ip_p == IPPROTO_ICMP && frag_off) {
|
||||||
snprintf(protoinfo, sizeof(protoinfo), "ICMP %s > %s fragment %s (incomplete)", srchost, dsthost, ipinfo);
|
Snprintf(protoinfo, sizeof(protoinfo), "ICMP %s > %s fragment %s (incomplete)", srchost, dsthost, ipinfo);
|
||||||
} else if (ip->ip_p == IPPROTO_ICMP) {
|
} else if (ip->ip_p == IPPROTO_ICMP) {
|
||||||
char icmptype[128];
|
char icmptype[128];
|
||||||
char *ip2dst;
|
char *ip2dst;
|
||||||
@@ -558,19 +558,19 @@ static const char *ippackethdrinfo(const u8 *packet, u32 len) {
|
|||||||
ip2dst = inet_ntoa(ip2->ip_dst);
|
ip2dst = inet_ntoa(ip2->ip_dst);
|
||||||
switch (ping->code) {
|
switch (ping->code) {
|
||||||
case 0:
|
case 0:
|
||||||
snprintf(icmptype, sizeof icmptype, "network %s unreachable", ip2dst);
|
Snprintf(icmptype, sizeof icmptype, "network %s unreachable", ip2dst);
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
snprintf(icmptype, sizeof icmptype, "host %s unreachable", ip2dst);
|
Snprintf(icmptype, sizeof icmptype, "host %s unreachable", ip2dst);
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
snprintf(icmptype, sizeof icmptype, "protocol %u unreachable", ip2->ip_p);
|
Snprintf(icmptype, sizeof icmptype, "protocol %u unreachable", ip2->ip_p);
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
if (ip2->ip_p == IPPROTO_UDP)
|
if (ip2->ip_p == IPPROTO_UDP)
|
||||||
snprintf(icmptype, sizeof icmptype, "port %u unreachable", ntohs(udp->uh_dport));
|
Snprintf(icmptype, sizeof icmptype, "port %u unreachable", ntohs(udp->uh_dport));
|
||||||
else if (ip2->ip_p == IPPROTO_TCP)
|
else if (ip2->ip_p == IPPROTO_TCP)
|
||||||
snprintf(icmptype, sizeof icmptype, "port %u unreachable", ntohs(tcp->th_dport));
|
Snprintf(icmptype, sizeof icmptype, "port %u unreachable", ntohs(tcp->th_dport));
|
||||||
else
|
else
|
||||||
strcpy(icmptype, "port unreachable");
|
strcpy(icmptype, "port unreachable");
|
||||||
break;
|
break;
|
||||||
@@ -581,25 +581,25 @@ static const char *ippackethdrinfo(const u8 *packet, u32 len) {
|
|||||||
strcpy(icmptype, "source route failed");
|
strcpy(icmptype, "source route failed");
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
snprintf(icmptype, sizeof icmptype, "destination network %s unknown", ip2dst);
|
Snprintf(icmptype, sizeof icmptype, "destination network %s unknown", ip2dst);
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
snprintf(icmptype, sizeof icmptype, "destination host %s unknown", ip2dst);
|
Snprintf(icmptype, sizeof icmptype, "destination host %s unknown", ip2dst);
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
strcpy(icmptype, "source host isolated");
|
strcpy(icmptype, "source host isolated");
|
||||||
break;
|
break;
|
||||||
case 9:
|
case 9:
|
||||||
snprintf(icmptype, sizeof icmptype, "destination network %s administratively prohibited", ip2dst);
|
Snprintf(icmptype, sizeof icmptype, "destination network %s administratively prohibited", ip2dst);
|
||||||
break;
|
break;
|
||||||
case 10:
|
case 10:
|
||||||
snprintf(icmptype, sizeof icmptype, "destination host %s administratively prohibited", ip2dst);
|
Snprintf(icmptype, sizeof icmptype, "destination host %s administratively prohibited", ip2dst);
|
||||||
break;
|
break;
|
||||||
case 11:
|
case 11:
|
||||||
snprintf(icmptype, sizeof icmptype, "network %s unreachable for TOS", ip2dst);
|
Snprintf(icmptype, sizeof icmptype, "network %s unreachable for TOS", ip2dst);
|
||||||
break;
|
break;
|
||||||
case 12:
|
case 12:
|
||||||
snprintf(icmptype, sizeof icmptype, "host %s unreachable for TOS", ip2dst);
|
Snprintf(icmptype, sizeof icmptype, "host %s unreachable for TOS", ip2dst);
|
||||||
break;
|
break;
|
||||||
case 13:
|
case 13:
|
||||||
strcpy(icmptype, "communication administratively prohibited by filtering");
|
strcpy(icmptype, "communication administratively prohibited by filtering");
|
||||||
@@ -664,10 +664,10 @@ static const char *ippackethdrinfo(const u8 *packet, u32 len) {
|
|||||||
strcpy(icmptype, "Unknown type"); break;
|
strcpy(icmptype, "Unknown type"); break;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
snprintf(protoinfo, sizeof(protoinfo), "ICMP %s > %s %s (type=%d/code=%d) %s",
|
Snprintf(protoinfo, sizeof(protoinfo), "ICMP %s > %s %s (type=%d/code=%d) %s",
|
||||||
srchost, dsthost, icmptype, ping->type, ping->code, ipinfo);
|
srchost, dsthost, icmptype, ping->type, ping->code, ipinfo);
|
||||||
} else {
|
} else {
|
||||||
snprintf(protoinfo, sizeof(protoinfo), "Unknown protocol (%d) %s > %s: %s",
|
Snprintf(protoinfo, sizeof(protoinfo), "Unknown protocol (%d) %s > %s: %s",
|
||||||
ip->ip_p, srchost, dsthost, ipinfo);
|
ip->ip_p, srchost, dsthost, ipinfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -735,7 +735,7 @@ void PacketTrace::traceConnect(u8 proto, const struct sockaddr *sock,
|
|||||||
if (connectrc == 0)
|
if (connectrc == 0)
|
||||||
Strncpy(errbuf, "Connected", sizeof(errbuf));
|
Strncpy(errbuf, "Connected", sizeof(errbuf));
|
||||||
else {
|
else {
|
||||||
snprintf(errbuf, sizeof(errbuf), "%s", strerror(connect_errno));
|
Snprintf(errbuf, sizeof(errbuf), "%s", strerror(connect_errno));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sin->sin_family == AF_INET) {
|
if (sin->sin_family == AF_INET) {
|
||||||
@@ -2456,7 +2456,7 @@ void set_pcap_filter(const char *device,
|
|||||||
fatal("Failed to lookup subnet/netmask for device (%s): %s", device, err0r);
|
fatal("Failed to lookup subnet/netmask for device (%s): %s", device, err0r);
|
||||||
|
|
||||||
va_start(ap, bpf);
|
va_start(ap, bpf);
|
||||||
if (vsnprintf(buf, sizeof(buf), bpf, ap) >= (int) sizeof(buf))
|
if (Vsnprintf(buf, sizeof(buf), bpf, ap) >= (int) sizeof(buf))
|
||||||
fatal("%s called with too-large filter arg\n", __func__);
|
fatal("%s called with too-large filter arg\n", __func__);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
|
|||||||
@@ -940,9 +940,9 @@ Traceroute::addConsolidationMessage(NmapOutputTable *Tbl, unsigned short row_cou
|
|||||||
char *ip = inet_ntoa(ref_ipaddr);
|
char *ip = inet_ntoa(ref_ipaddr);
|
||||||
|
|
||||||
if(ttl == 1)
|
if(ttl == 1)
|
||||||
len = snprintf(mbuf, 64, "Hop 1 is the same as for %s", ip);
|
len = Snprintf(mbuf, 64, "Hop 1 is the same as for %s", ip);
|
||||||
else
|
else
|
||||||
len = snprintf(mbuf, 64, "Hops 1-%d are the same as for %s", ttl, ip);
|
len = Snprintf(mbuf, 64, "Hops 1-%d are the same as for %s", ttl, ip);
|
||||||
|
|
||||||
assert(len);
|
assert(len);
|
||||||
Tbl->addItem(row_count, HOP_COL, true, "-", 1);
|
Tbl->addItem(row_count, HOP_COL, true, "-", 1);
|
||||||
@@ -1061,7 +1061,7 @@ Traceroute::outputTarget (Target * t) {
|
|||||||
|
|
||||||
/* normal hop output (rtt, ip and hostname) */
|
/* normal hop output (rtt, ip and hostname) */
|
||||||
if (!tp->timing.consolidated && !last_consolidation) {
|
if (!tp->timing.consolidated && !last_consolidation) {
|
||||||
snprintf(timebuf, 16, "%.2f", (float)
|
Snprintf(timebuf, 16, "%.2f", (float)
|
||||||
TIMEVAL_SUBTRACT (tp->timing.recvTime, tp->timing.sendTime) / 1000);
|
TIMEVAL_SUBTRACT (tp->timing.recvTime, tp->timing.sendTime) / 1000);
|
||||||
Tbl->addItemFormatted (row_count, HOP_COL, false, "%d", tp->ttl);
|
Tbl->addItemFormatted (row_count, HOP_COL, false, "%d", tp->ttl);
|
||||||
if (tp->timing.getState () != P_TIMEDOUT) {
|
if (tp->timing.getState () != P_TIMEDOUT) {
|
||||||
@@ -1340,9 +1340,9 @@ const char *TraceProbe::nameIP(void) {
|
|||||||
hostnameip = (char *) safe_zalloc(NAMEIPLEN);
|
hostnameip = (char *) safe_zalloc(NAMEIPLEN);
|
||||||
|
|
||||||
if(hostname == NULL || *hostname == NULL)
|
if(hostname == NULL || *hostname == NULL)
|
||||||
snprintf(hostnameip, NAMEIPLEN, "%s", inet_ntoa(ipreplysrc));
|
Snprintf(hostnameip, NAMEIPLEN, "%s", inet_ntoa(ipreplysrc));
|
||||||
else
|
else
|
||||||
snprintf(hostnameip, NAMEIPLEN, "%s (%s)",*hostname, inet_ntoa(ipreplysrc));
|
Snprintf(hostnameip, NAMEIPLEN, "%s (%s)",*hostname, inet_ntoa(ipreplysrc));
|
||||||
|
|
||||||
return hostnameip;
|
return hostnameip;
|
||||||
}
|
}
|
||||||
@@ -1489,8 +1489,8 @@ hostStr (u32 ip) {
|
|||||||
memset (nameipbuf, '\0', MAXHOSTNAMELEN + INET6_ADDRSTRLEN);
|
memset (nameipbuf, '\0', MAXHOSTNAMELEN + INET6_ADDRSTRLEN);
|
||||||
addr.s_addr = ip;
|
addr.s_addr = ip;
|
||||||
if((hname = lookup_cached_host(ip)) == "")
|
if((hname = lookup_cached_host(ip)) == "")
|
||||||
snprintf(nameipbuf, MAXHOSTNAMELEN+INET6_ADDRSTRLEN, "%s", inet_ntoa(addr));
|
Snprintf(nameipbuf, MAXHOSTNAMELEN+INET6_ADDRSTRLEN, "%s", inet_ntoa(addr));
|
||||||
else
|
else
|
||||||
snprintf (nameipbuf, MAXHOSTNAMELEN + INET6_ADDRSTRLEN, "%s (%s)", hname, inet_ntoa (addr));
|
Snprintf (nameipbuf, MAXHOSTNAMELEN + INET6_ADDRSTRLEN, "%s (%s)", hname, inet_ntoa (addr));
|
||||||
return nameipbuf;
|
return nameipbuf;
|
||||||
}
|
}
|
||||||
|
|||||||
10
utils.cc
10
utils.cc
@@ -745,19 +745,19 @@ void bintohexstr(char *buf, int buflen, char *src, int srclen){
|
|||||||
int bp=0;
|
int bp=0;
|
||||||
int i;
|
int i;
|
||||||
for(i=0; i<srclen; i++){
|
for(i=0; i<srclen; i++){
|
||||||
bp += snprintf(buf+bp, buflen-bp, "\\x%02hhx",src[i]);
|
bp += Snprintf(buf+bp, buflen-bp, "\\x%02hhx",src[i]);
|
||||||
if(bp >= buflen)break;
|
if(bp >= buflen)break;
|
||||||
if(i%16==7){
|
if(i%16==7){
|
||||||
bp += snprintf(buf+bp, buflen-bp," ");
|
bp += Snprintf(buf+bp, buflen-bp," ");
|
||||||
if(bp >= buflen)break;
|
if(bp >= buflen)break;
|
||||||
}
|
}
|
||||||
if(i%16==15){
|
if(i%16==15){
|
||||||
bp += snprintf(buf+bp, buflen-bp,"\n");
|
bp += Snprintf(buf+bp, buflen-bp,"\n");
|
||||||
if(bp >= buflen)break;
|
if(bp >= buflen)break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(i%16!=0 && bp < buflen)
|
if(i%16!=0 && bp < buflen)
|
||||||
bp += snprintf(buf+bp, buflen-bp,"\n");
|
bp += Snprintf(buf+bp, buflen-bp,"\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline char* STRAPP(char *fmt, ...) {
|
static inline char* STRAPP(char *fmt, ...) {
|
||||||
@@ -772,7 +772,7 @@ static inline char* STRAPP(char *fmt, ...) {
|
|||||||
return buf;
|
return buf;
|
||||||
va_list ap;
|
va_list ap;
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
bp += vsnprintf (buf+bp, left, fmt, ap);
|
bp += Vsnprintf (buf+bp, left, fmt, ap);
|
||||||
va_end(ap);
|
va_end(ap);
|
||||||
|
|
||||||
return(buf);
|
return(buf);
|
||||||
|
|||||||
Reference in New Issue
Block a user