Commit 77ce691d authored by Robert David Graham's avatar Robert David Graham
Browse files

duh! fix

parent 37ae4d40
Loading
Loading
Loading
Loading
+8 −6
Original line number Diff line number Diff line
@@ -73,6 +73,7 @@ static unsigned global_wait = 10;
uint64_t foo_timestamp = 0;
uint64_t foo_count = 0;


/***************************************************************************
 * We create a pair of transmit/receive threads for each network adapter.
 * This structure contains the parameters we send to each pair.
@@ -174,6 +175,7 @@ flush_packets(struct Adapter *adapter,
            break; /* queue is empty, nothing to send */
        }


        /*
         * Actually send the packet
         */
@@ -245,7 +247,7 @@ transmit_thread(void *v) /*aka. scanning_thread() */
    struct BlackRock blackrock;
    uint64_t count_ips = rangelist_count(&masscan->targets);
    struct Throttler *throttler = parms->throttler;
    struct TemplateSet *pkt_template = parms->tmplset;
    struct TemplateSet pkt_template = templ_copy(parms->tmplset);
    unsigned *picker = parms->picker;
    struct Adapter *adapter = parms->adapter;
    uint64_t packets_sent = 0;
@@ -363,7 +365,7 @@ transmit_thread(void *v) /*aka. scanning_thread() */
                    ip_me, port_me,
                    (unsigned)cookie,
                    !batch_size, /* flush queue on last packet in batch */
                    pkt_template
                    &pkt_template
                    );
            batch_size--;
			packets_sent++;
+2 −1
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@
    TCP connection table
*/
#include "proto-tcp.h"
#include <assert.h>
#include <ctype.h>
#include <stdio.h>
#include <stdint.h>
@@ -157,6 +158,7 @@ tcpcon_set_parameter(struct TCP_ConnectionTable *tcpcon,
    }
}


/***************************************************************************
 ***************************************************************************/
struct TCP_ConnectionTable *
@@ -228,7 +230,6 @@ tcpcon_create_table( size_t entry_count,

    tcpcon->report_banner = report_banner;
    tcpcon->out = out;

    return tcpcon;
}

+19 −0
Original line number Diff line number Diff line
@@ -316,6 +316,25 @@ icmp_checksum(struct TemplatePacket *tmpl)
}


struct TemplateSet templ_copy(const struct TemplateSet *templ)
{
    struct TemplateSet result;
    unsigned i;

    memcpy(&result, templ, sizeof(result));

    assert(sizeof(templ->pkts)/sizeof(templ->pkts[0]) == 8);

    for (i=0; i<6; i++) {
        const struct TemplatePacket *p1 = &templ->pkts[i];
        struct TemplatePacket *p2 = &result.pkts[i];
        p2->packet = malloc(p2->length);
        memcpy(p2->packet, p1->packet, p2->length);
    }

    return result;
}

/***************************************************************************
 ***************************************************************************/
size_t
+2 −0
Original line number Diff line number Diff line
@@ -48,6 +48,8 @@ struct TemplateSet
    struct TemplatePacket pkts[8];
};

struct TemplateSet templ_copy(const struct TemplateSet *templ);

/**
 * Initialize the "template" packets. As we spew out probes, we simply make
 * minor adjustments to the template, such as changing the target IP 
+17 −80
Original line number Diff line number Diff line
@@ -81,7 +81,11 @@
#include <string.h>
#include <time.h>
#include <stdint.h>

#include "scanout.h"
#include "scanout-redis.h"
#include "scanout-text.h"
#include "scan-conf.h"
#include "scandb.h"

enum {
    PROTO_UNKNOWN,
@@ -93,14 +97,6 @@ enum {
    PROTO_DNS_VERSIONBIND,
};

struct Configuration {
    unsigned do_ssh;
    unsigned do_http;
    unsigned do_dns_version;
    unsigned do_xml;
    unsigned is_quiet;
};


struct MasscanRecord {
    unsigned timestamp;
@@ -113,73 +109,11 @@ struct MasscanRecord {

static const size_t BUF_MAX = 1024*1024;

struct BannerRecord {
    unsigned count;
    unsigned length;
    struct BannerRecord *next;
    char str[1];
};

#define BUCKET_COUNT (1024*1024)
struct BannerDB
{
    struct BannerRecord *records[BUCKET_COUNT];
} *mydb;




void
db_print(const struct BannerDB *db)
{
    unsigned i;
    for (i=0; i<BUCKET_COUNT; i++) {
        struct BannerRecord *rec = db->records[i];
        while (rec) {
            printf("%8u %.*s\n", rec->count, rec->length, rec->str);
            rec = rec->next;
        }
    }
}

/***************************************************************************
 * used for some banners to keep track of the most popular ones
 ***************************************************************************/
void
db_lookup(struct BannerDB *db, const char *str, unsigned length)
{
    struct BannerRecord *rec;
    uint64_t hash = 0;
    unsigned i;

    for (i=0; i<length; i++) {
        hash += str[i];
        hash += str[i]<<8;
        hash ^= str[i]<<4;
    }

    /* lookup */
    rec = db->records[hash & (BUCKET_COUNT-1)];
    while (rec) {
        if (rec->length == length && memcmp(rec->str, str, length) == 0)
            break;
        else
            rec = rec->next;
    }
    if (rec == NULL) {
        rec = (struct BannerRecord *)malloc(sizeof(*rec) + length);
        if (rec == NULL)
            exit(1);
        rec->count = 0;
        rec->length = length;
        memcpy(rec->str, str, length);

        rec->next = db->records[hash & (BUCKET_COUNT-1)];
        db->records[hash & (BUCKET_COUNT-1)] = rec;
    }

    rec->count++;
}



@@ -469,8 +403,11 @@ parse_banner4(const struct Configuration *conf, unsigned char *buf, size_t buf_l
    
    /* output string */
    if (buf_length > 13) {


        const char *s;
        s = normalize_string(buf, 13, buf_length-13, BUF_MAX);

         if (!conf->is_quiet)
        printf("%s %-15s :%5u %s \"%s\"\n",
               timebuf,
@@ -599,7 +536,7 @@ parse_file(const struct Configuration *conf, const char *filename)
        
        /* get the remainder fo the record */
        bytes_read = fread(buf, 1, length, fp);
        if (bytes_read < length)
        if (bytes_read < (int)length)
            break; /* eof */

        /* Depending on record type, do something different */
@@ -640,6 +577,7 @@ end:
    return total_records;
}


/***************************************************************************
 ***************************************************************************/
int
@@ -649,8 +587,11 @@ main(int argc, char *argv[])
    uint64_t total_records = 0;
    struct Configuration conf[1];
    

    memset(conf, 0, sizeof(conf[0]));

    conf->out = (void*)&text_output;
    
    if (argc <= 1) {
        printf("usage:\n masscan2text <scanfile>\ndecodes and prints text\n");
        return 1;
@@ -670,17 +611,13 @@ main(int argc, char *argv[])
            conf->do_dns_version = 1;
        else if (strcmp(argv[i], "--xml") == 0)
            conf->do_xml = 1;
        else if (memcmp(argv[i], "--redis", 7) == 0)
            parse_redis_option(conf, argv[i] + strlen("--redis"));
        else if (argv[i][0] == '\0')
            fprintf(stderr, "%s: unknown option\n", argv[i]);
    }
    
    /*
     * Create a table for storing banners
     */
    mydb = (struct BannerDB*)malloc(sizeof(*mydb));
    if (mydb == NULL)
        exit(1);
    memset(mydb, 0, sizeof(*mydb));


    
    fprintf(stderr, "--- scan2text for masscan/1.1 format ---\n");
Loading