Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new interactive keyboard command (o) to show open ports during a scan #1390

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Add new interactive keyboard command (o), show open ports
  • Loading branch information
matrix committed Nov 14, 2018
commit cbc840fb1a7f4f0099c5aa03e61d5d47b05f6107
2 changes: 2 additions & 0 deletions nmap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,7 @@ struct ftpinfo ftp = get_default_ftpinfo();
static std::vector<std::string> route_dst_hosts;

struct scan_lists ports = { 0 };
std::vector<Target *> *extTargets;

/* This struct is used is a temporary storage place that holds options that
can't be correctly parsed and interpreted before the entire command line has
Expand Down Expand Up @@ -1763,6 +1764,7 @@ void nmap_free_mem() {
int nmap_main(int argc, char *argv[]) {
int i;
std::vector<Target *> Targets;
extTargets = &Targets;
time_t now;
struct hostent *target = NULL;
time_t timep;
Expand Down
4 changes: 4 additions & 0 deletions nmap_tty.cc
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,9 @@ bool keyWasPressed()
} else if (c == 'V') {
if (o.verbose > 0) o.verbose--;
log_write(LOG_STDOUT, "Verbosity Decreased to %d.\n", o.verbose);
} else if (c == 'o') {
log_write(LOG_STDOUT, "Scanning %d host(s)\n", o.numhosts_scanning);
printOpenPorts();
} else if (c == 'd') {
if (o.debugging < 10) o.debugging++;
log_write(LOG_STDOUT, "Debugging Increased to %d.\n", o.debugging);
Expand All @@ -341,6 +344,7 @@ bool keyWasPressed()
log_write(LOG_STDOUT,
"Interactive keyboard commands:\n"
"? Display this information\n"
"o Show open ports\n"
"v/V Increase/decrease verbosity\n"
"d/D Increase/decrease debugging\n"
"p/P Enable/disable packet tracing\n"
Expand Down
22 changes: 22 additions & 0 deletions output.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2479,6 +2479,28 @@ void printtimes(Target *currenths) {
}
}

void printOpenPorts() {
Port *p = NULL;
Port port;
std::vector<Target *> t = *extTargets;
unsigned int x = 0, y = t.size();

for (x = 0; x < y; x++) {
log_write(LOG_STDOUT, "Target %s\n", t[x]->targetipstr());
if (t[x]->ports.hasOpenPorts()) {
log_write(LOG_STDOUT, "Found open port(s):");
p = NULL;
while ((p = t[x]->ports.nextPort(p, &port, TCPANDUDPANDSCTP, PORT_OPEN))) {
log_write(LOG_STDOUT, " %d/%s", p->portno, IPPROTO2STR(p->proto));
}
log_write(LOG_STDOUT, "\n");
} else {
log_write(LOG_STDOUT, "No open port yet.\n");
}
log_write(LOG_STDOUT, "\n");
}
}

/* Prints a status message while the program is running */
void printStatusMessage() {
// Pre-computations
Expand Down
5 changes: 5 additions & 0 deletions output.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,9 @@ void printtimes(Target *currenths);
normal/skiddy/stdout output */
int print_iflist(void);

/* Print open ports founds during scan */
void printOpenPorts();

/* Prints a status message while the program is running */
void printStatusMessage();

Expand All @@ -299,5 +302,7 @@ void printdatafilepaths();
void nmap_adjust_loglevel(bool trace);
void nmap_nsock_stderr_logger(const struct nsock_log_rec *rec);

extern std::vector<Target *> *extTargets;

#endif /* OUTPUT_H */