Commit 3de2dbdf authored by robertdavidgraham's avatar robertdavidgraham
Browse files

banners

parent 144fe5cc
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -133,6 +133,7 @@ masscan_echo(struct Masscan *masscan, FILE *fp)
    case Output_List:       fprintf(fp, "output-format = list\n"); break;
    case Output_XML:        fprintf(fp, "output-format = xml\n"); break;
    case Output_Binary:     fprintf(fp, "output-format = binary\n"); break;
    case Output_JSON:       fprintf(fp, "output-format = json\n"); break;
    default:
        fprintf(fp, "output-format = unknown(%u)\n", masscan->nmap.format);
        break;
@@ -688,6 +689,7 @@ masscan_set_parameter(struct Masscan *masscan,
        else if (EQUALS("interactive", value))  masscan->nmap.format = Output_Interactive;
        else if (EQUALS("xml", value))          masscan->nmap.format = Output_XML;
        else if (EQUALS("binary", value))       masscan->nmap.format = Output_Binary;
        else if (EQUALS("json", value))       masscan->nmap.format = Output_JSON;
        else {
            fprintf(stderr, "error: %s=%s\n", name, value);
        }
@@ -1037,6 +1039,14 @@ masscan_command_line(struct Masscan *masscan, int argc, char *argv[])
                switch (argv[i][2]) {
                case 'A':
                    masscan->nmap.format = Output_All;
                    fprintf(stderr, "nmap(%s): unsupported output format\n", argv[i]);
                    exit(1);
                    break;
                case 'B':
                    masscan->nmap.format = Output_Binary;
                    break;
                case 'J':
                    masscan->nmap.format = Output_JSON;
                    break;
                case 'N':
                    masscan->nmap.format = Output_Normal;
+2 −0
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ enum OutpuFormat {
    Output_ScriptKiddie,
    Output_Grepable,
    Output_Binary,
    Output_JSON,
    Output_All,
    Output_List /* specific to Masscan */
};
@@ -93,6 +94,7 @@ struct Masscan
    unsigned is_sendq:1;        /* --sendq */
    unsigned is_banners:1;      /* --banners */
    unsigned is_offline:1;      /* --offline */
    unsigned is_interactive:1;  /* --interactive */

    /**
     * Wait forever for responses, instead of the default 10 seconds
+18 −5
Original line number Diff line number Diff line
@@ -614,6 +614,20 @@ output_report_banner(struct Output *out, unsigned ip, unsigned port, unsigned pr
            return;
    }

    if (masscan->is_interactive) {
         fprintf(fp, "%s tcp %u %u.%u.%u.%u %u %.*s\n",
            "banner",
            port,
            (ip>>24)&0xFF,
            (ip>>16)&0xFF,
            (ip>> 8)&0xFF,
            (ip>> 0)&0xFF,
            (unsigned)global_now,
            length, px
            );
    }


    switch (masscan->nmap.format) {
    case Output_List:
        fprintf(fp, "%s tcp %u %u.%u.%u.%u %u %.*s\n",
@@ -654,16 +668,16 @@ output_report_banner(struct Output *out, unsigned ip, unsigned port, unsigned pr
        break;
    case Output_Binary:
        {
            unsigned foo[256];
            unsigned char foo[256];

            if (length > 255 - 12)
                length = 255 - 12;
            if (length > 127 - 10)
                length = 127 - 10;

            /* [TYPE] field */
            foo[0] = 3; /*banner*/

            /* [LENGTH] field */
            foo[1] = length + 12;
            foo[1] = (unsigned char)(length + 10);

            /* [TIMESTAMP] field */
            foo[2] = (unsigned char)(global_now>>24);
@@ -679,7 +693,6 @@ output_report_banner(struct Output *out, unsigned ip, unsigned port, unsigned pr
            foo[10] = (unsigned char)(port>>8);
            foo[11] = (unsigned char)(port>>0);

            printf("banner: %.*s\n", length, px);
            /* Banner */
            memcpy(foo+12, px, length);

+9 −5
Original line number Diff line number Diff line
@@ -60,7 +60,7 @@
 other records, it contains a timestamp, IP address, and port number.
 The length of the banner-text is the length
 +--------+
 |  0x01  |
 |  0x03  |
 +--------+ . . . .
 |? length:        :
 +--------+--------+--------+--------+
@@ -74,6 +74,8 @@
 +--------+--------+ . . . . . .  .  .  .   .   .   .    .    .     .

*/
#define _CRT_SECURE_NO_WARNINGS
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -176,6 +178,8 @@ const char *
normalize_string(unsigned char *px, size_t offset, size_t length, size_t max)
{
    size_t i=0;
    px += offset;
    max -= offset;
    
    for (i=offset; i<length; i++) {
        unsigned char c = px[i];
@@ -207,7 +211,6 @@ void parse_banner(unsigned char *buf, size_t buf_length)
    struct MasscanRecord record;
    char timebuf[80];
    char addrbuf[20];
    char reasonbuf[80];
    
    /* parse record */        
    record.timestamp = buf[0]<<24 | buf[1]<<16 | buf[2]<<8 | buf[3];
@@ -231,11 +234,12 @@ void parse_banner(unsigned char *buf, size_t buf_length)
    
    
    /* output string */
    printf("%s %-15s :%5u %s\n",
    if (buf_length > 10)
    printf("%s %-15s :%5u -- \"%s\"\n",
           timebuf,
           addrbuf,
           record.port,
           normalize_string(buf, 10, buf_length, BUF_MAX)
           normalize_string(buf, 10, buf_length-10, BUF_MAX)
           );
}

@@ -323,7 +327,7 @@ void parse_file(const char *filename)
            case 3: /* BANNER */
                parse_banner(buf, bytes_read);
                break;
            case 'a': /* FILEHEADER */
            case 'm': /* FILEHEADER */
                goto end;
            default:
                fprintf(stderr, "file corrupt: unknown type %u\n", type);