Skip to content

Commit

Permalink
Replace time(2) calls in bounce scan with ScanProgressMeter. Related to
Browse files Browse the repository at this point in the history
  • Loading branch information
bonsaiviking committed Jan 13, 2016
1 parent a205e0c commit e5767c2
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 13 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Nmap Changelog ($Id$); -*-text-*-

o Use the same ScanProgressMeter for FTP bounce scan (-b) as for the other scan
types, allowing periodic status updates with --stats-every or keypress
events. [Daniel Miller]

o [GH#274] Use a shorter pcap_select timeout on OpenBSD, just as we do for OS
X, old FreeBSD, and Solaris, which use BPF for packet capture and do not have
properly select-able fds. Fix by OpenBSD port maintainer [David Carlier]
Expand Down
39 changes: 26 additions & 13 deletions nmap_ftp.cc
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
#include "nmap_error.h"
#include "tcpip.h"
#include "Target.h"
#include "nmap_tty.h"
extern NmapOps o;

struct ftpinfo get_default_ftpinfo(void) {
Expand Down Expand Up @@ -256,14 +257,13 @@ void bounce_scan(Target *target, u16 *portarray, int numports,
struct ftpinfo *ftp) {
o.current_scantype = BOUNCE_SCAN;

time_t starttime;
ScanProgressMeter *SPM;
int res , sd = ftp->sd, i = 0;
const char *t = (const char *)target->v4hostip();
int retriesleft = FTP_RETRIES;
char recvbuf[2048];
char targetstr[20];
char command[512];
char hostname[1200];
unsigned short portno, p1, p2;
int timedout;

Expand All @@ -272,17 +272,16 @@ void bounce_scan(Target *target, u16 *portarray, int numports,

Snprintf(targetstr, 20, "%d,%d,%d,%d,", UC(t[0]), UC(t[1]), UC(t[2]), UC(t[3]));

starttime = time(NULL);
if (o.verbose || o.debugging) {
struct tm *tm = localtime(&starttime);
assert(tm);
log_write(LOG_STDOUT, "Initiating TCP FTP bounce scan against %s at %02d:%02d\n", target->NameIP(hostname, sizeof(hostname)), tm->tm_hour, tm->tm_min );
}
SPM = new ScanProgressMeter(scantype2str(BOUNCE_SCAN));
for (i = 0; i < numports; i++) {

/* Check for timeout */
if (target->timedOut(NULL))
if (target->timedOut(NULL)) {
Snprintf(recvbuf, sizeof(recvbuf), "Target timed out");
SPM->endTask(NULL, recvbuf);
delete SPM;
return;
}

portno = htons(portarray[i]);
p1 = ((unsigned char *) &portno)[0];
Expand All @@ -298,14 +297,21 @@ void bounce_scan(Target *target, u16 *portarray, int numports,
retriesleft--;
close(sd);
ftp->sd = ftp_anon_connect(ftp);
if (ftp->sd < 0)
if (ftp->sd < 0) {
Snprintf(recvbuf, sizeof(recvbuf), "Error connecting");
SPM->endTask(NULL, recvbuf);
delete SPM;
return;
}
sd = ftp->sd;
i--;
} else {
error("Our socket descriptor is dead and we are out of retries. Giving up.");
close(sd);
ftp->sd = -1;
Snprintf(recvbuf, sizeof(recvbuf), "Max retries exceeded");
SPM->endTask(NULL, recvbuf);
delete SPM;
return;
}
} else { /* Our send is good */
Expand Down Expand Up @@ -374,10 +380,17 @@ void bounce_scan(Target *target, u16 *portarray, int numports,
}
}
}
if (SPM->mayBePrinted(NULL)) {
SPM->printStatsIfNecessary((double) i / numports, NULL);
}
else if (keyWasPressed()) {
SPM->printStats((double) i / numports, NULL);
log_flush(LOG_STDOUT);
}
}

if (o.debugging || o.verbose)
log_write(LOG_STDOUT, "Scanned %d ports in %ld seconds via the Bounce scan.\n",
numports, (long) time(NULL) - starttime);
Snprintf(recvbuf, sizeof(recvbuf), "%d total ports", numports);
SPM->endTask(NULL, recvbuf);
delete SPM;
return;
}

0 comments on commit e5767c2

Please sign in to comment.