Commit 1a41cab2 authored by robertdavidgraham's avatar robertdavidgraham
Browse files

modularized output

parent 173c47cd
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -209,7 +209,7 @@ masscan_save_state(struct Masscan *masscan)
    int err;


    strcpy_s(filename, sizeof(filename), "paused.scan");
    strcpy_s(filename, sizeof(filename), "paused.conf");
    fprintf(stderr, "                                   "
                    "                                   \r");
    fprintf(stderr, "saving resume file to: %s\n", filename);
@@ -1071,7 +1071,7 @@ masscan_command_line(struct Masscan *masscan, int argc, char *argv[])
                    masscan->nmap.format = Output_JSON;
                    break;
                case 'N':
                    masscan->nmap.format = Output_Normal;
                    masscan->nmap.format = Output_Nmap;
                    fprintf(stderr, "nmap(%s): unsupported output format\n", argv[i]);
                    exit(1);
                    break;
+5 −4
Original line number Diff line number Diff line
@@ -282,7 +282,7 @@ transmit_thread(void *v) /*aka. scanning_thread() */
             * namely packets/second.
             */
            if ((i & status.timer) == status.timer)
                status_print(&status, i-start, end-start);
                status_print(&status, i, end);

        } /* end of batch */

@@ -313,7 +313,7 @@ transmit_thread(void *v) /*aka. scanning_thread() */
        unsigned j;
        for (j=0; j<masscan->wait && !control_c_pressed; j++) {
            unsigned k;
            status_print(&status, i++ - start, end-start);
            status_print(&status, i++, end);

            for (k=0; k<1000; k++) {
                /* Transmit packets from other thread */
@@ -385,7 +385,8 @@ receive_thread(struct Masscan *masscan,
            masscan->packet_buffers,
            masscan->pkt_template,
            output_report_banner,
            out
            out,
            masscan->tcb.timeout
            );
    }

@@ -593,7 +594,7 @@ receive_thread(struct Masscan *masscan,
            /*
             * This is where we do the output
             */
            output_report(
            output_report_status(
                        out,
                        status,
                        ip_them,
+13 −9
Original line number Diff line number Diff line
@@ -25,17 +25,18 @@ enum {
};

enum OutpuFormat {
    Output_Interactive = 0,
    Output_Normal,
    Output_XML,
    Output_ScriptKiddie,
    Output_Grepable,
    Output_Binary,
    Output_JSON,
    Output_All,
    Output_List /* specific to Masscan */
    Output_Interactive  = 0x0001,
    Output_List         = 0x0002,
    Output_Binary       = 0x0004,
    Output_XML          = 0x0008,
    Output_JSON         = 0x0010,
    Output_Nmap         = 0x0020,
    Output_ScriptKiddie = 0x0040,
    Output_Grepable     = 0x0080,
    Output_All          = 0xFFBF,
};


enum PortStatus {
    Port_Unknown,
    Port_Open,
@@ -164,6 +165,9 @@ struct Masscan
    PACKET_QUEUE *packet_buffers;
    PACKET_QUEUE *transmit_queue;

    struct {
        unsigned timeout;
    } tcb;
};


src/out-binary.c

0 → 100644
+143 −0
Original line number Diff line number Diff line
#include "output.h"
#include "masscan.h"

/****************************************************************************
 ****************************************************************************/
static void
binary_out_open(struct Output *out, FILE *fp)
{
    char firstrecord[2+'a'];

    UNUSEDPARM(out);


    memset(firstrecord, 0, 2+'a');
    sprintf_s(firstrecord, 2+'a', "masscan/1.1");
    fwrite( firstrecord, 1, 2+'a', fp);
}


/****************************************************************************
 ****************************************************************************/
static void
binary_out_close(struct Output *out, FILE *fp)
{
    char firstrecord[2+'a'];

    UNUSEDPARM(out);

    memset(firstrecord, 0, 2+'a');
    sprintf_s(firstrecord, 2+'a', "masscan/1.1");
    fwrite( firstrecord, 1, 2+'a', fp);
}

/****************************************************************************
 ****************************************************************************/
static void
binary_out_status(struct Output *out, FILE *fp, int status, unsigned ip, unsigned port, unsigned reason, unsigned ttl)
{
    unsigned char foo[256];

    UNUSEDPARM(out);

    /* [TYPE] field */
    switch (status) {
    case Port_Open:
        foo[0] = 1;
        break;
    case Port_Closed:
        foo[0] = 2;
        break;
    default:
        return;
    }

    /* [LENGTH] field */
    foo[1] = 12;

    /* [TIMESTAMP] field */
    foo[2] = (unsigned char)(global_now>>24);
    foo[3] = (unsigned char)(global_now>>16);
    foo[4] = (unsigned char)(global_now>> 8);
    foo[5] = (unsigned char)(global_now>> 0);

    foo[6] = (unsigned char)(ip>>24);
    foo[7] = (unsigned char)(ip>>16);
    foo[8] = (unsigned char)(ip>> 8);
    foo[9] = (unsigned char)(ip>> 0);

    foo[10] = (unsigned char)(port>>8);
    foo[11] = (unsigned char)(port>>0);

    foo[12] = (unsigned char)reason;
    foo[13] = (unsigned char)ttl;



    fwrite(&foo, 1, 14, fp);
}


/****************************************************************************
 ****************************************************************************/
static void
binary_out_banner(struct Output *out, FILE *fp, unsigned ip, unsigned port,
        unsigned proto, const unsigned char *px, unsigned length)
{
    unsigned char foo[256];
    unsigned i;

    UNUSEDPARM(out);

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

    /* [LENGTH] field */
    if (length >= 128 * 128 - 12)
        return;
    if (length <= 128 - 12) {
        foo[1] = (unsigned char)(length + 12);
        i = 2;
    } else {
        foo[1] = (unsigned char)((length + 12)>>7) | 0x80;
        foo[2] = (unsigned char)((length + 12) & 0x7F);
        i = 2;
    }

    /* [TIMESTAMP] field */
    foo[i+0] = (unsigned char)(global_now>>24);
    foo[i+1] = (unsigned char)(global_now>>16);
    foo[i+2] = (unsigned char)(global_now>> 8);
    foo[i+3] = (unsigned char)(global_now>> 0);

    foo[i+4] = (unsigned char)(ip>>24);
    foo[i+5] = (unsigned char)(ip>>16);
    foo[i+6] = (unsigned char)(ip>> 8);
    foo[i+7] = (unsigned char)(ip>> 0);

    foo[i+8] = (unsigned char)(port>>8);
    foo[i+9] = (unsigned char)(port>>0);

    foo[i+10] = (unsigned char)(proto>>8);
    foo[i+11] = (unsigned char)(proto>>0);

    /* Banner */
    memcpy(foo+i+12, px, length);


    fwrite(&foo, 1, length+i+12, fp);
}


/****************************************************************************
 ****************************************************************************/
const struct OutputType binary_output = {
    "scan",
    0,
    binary_out_open,
    binary_out_close,
    binary_out_status,
    binary_out_banner,
};

src/out-null.c

0 → 100644
+67 −0
Original line number Diff line number Diff line
#include "output.h"
#include "masscan.h"

/****************************************************************************
 ****************************************************************************/
static void
null_out_open(struct Output *out, FILE *fp)
{
    UNUSEDPARM(out);
    UNUSEDPARM(fp);
}

/****************************************************************************
 ****************************************************************************/
static void
null_out_close(struct Output *out, FILE *fp)
{
    UNUSEDPARM(out);
    UNUSEDPARM(fp);
}

/****************************************************************************
 ****************************************************************************/
static void
null_out_status(struct Output *out, FILE *fp, 
    int status, unsigned ip, unsigned port, unsigned reason, unsigned ttl)
{
    UNUSEDPARM(out);
    UNUSEDPARM(fp);
    UNUSEDPARM(status);
    UNUSEDPARM(ip);
    UNUSEDPARM(port);
    UNUSEDPARM(reason);
    UNUSEDPARM(ttl);

}

/****************************************************************************
 ****************************************************************************/
static void
null_out_banner(struct Output *out, FILE *fp, unsigned ip, unsigned port, 
        unsigned proto, const unsigned char *px, unsigned length)
{
    UNUSEDPARM(out);
    UNUSEDPARM(fp);
    UNUSEDPARM(ip);
    UNUSEDPARM(port);
    UNUSEDPARM(proto);
    UNUSEDPARM(px);
    UNUSEDPARM(length);

}


/****************************************************************************
 ****************************************************************************/
const struct OutputType null_output = {
    "null",
    0,
    null_out_open,
    null_out_close,
    null_out_status,
    null_out_banner
};


Loading