Commit 13f79f6f authored by robertdavidgraham's avatar robertdavidgraham
Browse files

#81 --open only is now the default, use --show closed to see RSTs

parent 2edbd47b
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -120,11 +120,13 @@ one port.
  * `--http-user-agent <user-agent>`: replaces the existing user-agent field
    with the indicated value when doing HTTP requests.

  * `--open-only`: report only open ports, not closed ports.



  * `--show [open,closed]`: tells which port status to display, such
    as 'open' for those ports that respond with a SYN-ACK on TCP, or
	'closed' for those ports that repsond with RST. The default is
	only to display 'open' ports.

  * `--noshow [open,closed]`: disables a port status to display, such
    as to no longer display 'open' ports.

  * `--pcap <filename>`: saves received packets (but not transmitted
    packets) to the libpcap-format file.
+81 −8
Original line number Diff line number Diff line
@@ -249,8 +249,13 @@ masscan_echo(struct Masscan *masscan, FILE *fp)
        fprintf(fp, "output-format = unknown(%u)\n", masscan->output.format);
        break;
    }
    fprintf(fp, "output-status = %s\n",
            masscan->output.is_open_only?"open":"all");
    fprintf(fp, "show = %s,%s,%s\n",
            masscan->output.is_show_open?"open":"",
            masscan->output.is_show_closed?"closed":"",
            masscan->output.is_show_host?"host":""
            );
    if (!masscan->output.is_show_open)
        fprintf(fp, "noshow = open\n");
    fprintf(fp, "output-filename = %s\n", masscan->output.filename);
    if (masscan->output.is_append)
        fprintf(fp, "output-append = true\n");
@@ -680,6 +685,36 @@ EQUALS(const char *lhs, const char *rhs)
    }
}

static int
EQUALSx(const char *lhs, const char *rhs, size_t rhs_length)
{
    for (;;) {
        while (*lhs == '-' || *lhs == '.' || *lhs == '_')
            lhs++;
        while (*rhs == '-' || *rhs == '.' || *rhs == '_')
            rhs++;
        if (*lhs == '\0' && *rhs == '[')
            return 1; /*arrays*/
        if (tolower(*lhs & 0xFF) != tolower(*rhs & 0xFF))
            return 0;
        if (*lhs == '\0')
            return 1;
        lhs++;
        rhs++;
        if (--rhs_length == 0)
            return 1;
    }
}

static unsigned
INDEX_OF(const char *str, char c)
{
    unsigned i;
    for (i=0; str[i] && str[i] != c; i++)
        ;
    return i;
}

static unsigned
ARRAY(const char *rhs)
{
@@ -1170,11 +1205,49 @@ masscan_set_parameter(struct Masscan *masscan,
         * it's not */
        masscan->is_offline = 1;
    } else if (EQUALS("open", name) || EQUALS("open-only", name)) {
        masscan->output.is_open_only = 1;
    } else if (EQUALS("output-status", name)) {
        if (EQUALS("open", value))
            masscan->output.is_open_only = 1;

        masscan->output.is_show_open = 1;
        masscan->output.is_show_closed = 0;
        masscan->output.is_show_host = 0;
    } else if (EQUALS("output-status", name) || EQUALS("show", name)) {
        for (;;) {
            const char *val2 = value;
            unsigned val2_len = INDEX_OF(val2, ',');
            if (val2_len == 0)
                break;
            if (EQUALSx("open", val2, val2_len))
                masscan->output.is_show_open = 1;
            else if (EQUALSx("closed", val2, val2_len) || EQUALSx("close", val2, val2_len))
                masscan->output.is_show_closed = 1;
            else if (EQUALSx("open", val2, val2_len))
                masscan->output.is_show_host = 1;
            else {
                LOG(0, "FAIL: unknown 'show' spec: %.*s\n", val2_len, val2);
                exit(1);
            }
            value += val2_len;
            while (*value == ',')
                value++;
        }
    } else if (EQUALS("noshow", name)) {
        for (;;) {
            const char *val2 = value;
            unsigned val2_len = INDEX_OF(val2, ',');
            if (val2_len == 0)
                break;
            if (EQUALSx("open", val2, val2_len))
                masscan->output.is_show_open = 0;
            else if (EQUALSx("closed", val2, val2_len) || EQUALSx("close", val2, val2_len))
                masscan->output.is_show_closed = 0;
            else if (EQUALSx("open", val2, val2_len))
                masscan->output.is_show_host = 0;
            else {
                LOG(0, "FAIL: unknown 'show' spec: %.*s\n", val2_len, val2);
                exit(1);
            }
            value += val2_len;
            while (*value == ',')
                value++;
        }
    } else if (EQUALS("osscan-limit", name)) {
        fprintf(stderr, "nmap(%s): OS scanning unsupported\n", name);
        exit(1);
@@ -1415,7 +1488,7 @@ is_singleton(const char *name)
        "system-dns", "traceroute", "version-light",
        "version-all", "version-trace",
        "osscan-limit", "osscan-guess",
        "badsum", "reason", "open",
        "badsum", "reason", "open", "open-only",
        "packet-trace", "release-memory",
        "log-errors", "append-output", "webxml", "no-stylesheet",
        "no-stylesheet",
+5 −3
Original line number Diff line number Diff line
@@ -889,12 +889,13 @@ receive_thread(void *v)

        }

        if (TCP_IS_SYNACK(px, parsed.transport_offset)) {
        if (TCP_IS_SYNACK(px, parsed.transport_offset)
            || TCP_IS_RST(px, parsed.transport_offset)) {
            /* figure out the status */
            status = PortStatus_Unknown;
            if ((px[parsed.transport_offset+13] & 0x2) == 0x2)
            if (TCP_IS_SYNACK(px, parsed.transport_offset))
                status = PortStatus_Open;
            if ((px[parsed.transport_offset+13] & 0x4) == 0x4) {
            if (TCP_IS_RST(px, parsed.transport_offset)) {
                status = PortStatus_Closed;
            }

@@ -1377,6 +1378,7 @@ int main(int argc, char *argv[])
     * Initialize those defaults that aren't zero
     */
    memset(masscan, 0, sizeof(*masscan));
    masscan->output.is_show_open = 1; /* default: show syn-ack, not rst */
    masscan->seed = get_entropy(); /* entropy for randomness */
    masscan->wait = 10; /* how long to wait for responses when done */
    masscan->max_rate = 100.0; /* max rate = hundred packets-per-second */
+16 −2
Original line number Diff line number Diff line
@@ -248,9 +248,23 @@ struct Masscan
        
        /**
         * --open
         * Whether to show only open ports (not closed ports)
         * --open-only
         * --show open
         * Whether to show open ports
         */
        unsigned is_open_only:1;
        unsigned is_show_open:1;
        
        /**
         * --show closed
         * Whether to show closed ports (i.e. RSTs)
         */
        unsigned is_show_closed:1;
        
        /**
         * --show host
         * Whether to show host messages other than closed ports
         */
        unsigned is_show_host:1;
        
        /**
         * print reason port is open, which is redundant for us 
+10 −5
Original line number Diff line number Diff line
@@ -383,7 +383,9 @@ output_create(const struct Masscan *masscan, unsigned thread_index)
    out->is_banner = masscan->is_banners;
    out->is_gmt = masscan->is_gmt;
    out->is_interactive = masscan->output.is_interactive;
    out->is_open_only = masscan->output.is_open_only;
    out->is_show_open = masscan->output.is_show_open;
    out->is_show_closed = masscan->output.is_show_closed;
    out->is_show_host = masscan->output.is_show_host;
    out->is_append = masscan->output.is_append;
    out->xml.stylesheet = duplicate_string(masscan->output.stylesheet);
    out->rotate.directory = duplicate_string(masscan->output.rotate.directory);
@@ -628,7 +630,9 @@ output_report_status(struct Output *out, time_t timestamp, int status,

    /* if "--open"/"--open-only" parameter specified on command-line, then
     * don't report the status of closed-ports */
    if (out->is_open_only && status == PortStatus_Closed)
    if (!out->is_show_closed && status == PortStatus_Closed)
        return;
    if (!out->is_show_open && status == PortStatus_Open)
        return;

    /* If in "--interactive" mode, then print the banner to the command
@@ -691,6 +695,8 @@ output_report_status(struct Output *out, time_t timestamp, int status,
                out->counts.sctp.open++;
                break;
            }
            if (!out->is_show_open)
                return;
            break;
        case PortStatus_Closed:
            switch (ip_proto) {
@@ -704,7 +710,7 @@ output_report_status(struct Output *out, time_t timestamp, int status,
                out->counts.sctp.closed++;
                break;
            }
            if (out->is_open_only)
            if (!out->is_show_closed)
                return;
            break;
        case PortStatus_Arp:
@@ -712,7 +718,6 @@ output_report_status(struct Output *out, time_t timestamp, int status,
            break;
        default:
            LOG(0, "unknown status type: %u\n", status);
            if (out->is_open_only)
            return;
    }

Loading