Commit 4692c303 authored by robertdavidgraham's avatar robertdavidgraham
Browse files

readscan

parent 2483db5a
Loading
Loading
Loading
Loading
+41 −5
Changes for src/output.c: 41 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -27,6 +27,10 @@
    work -- it's just that the first rotated file will contain several
    periods of data.
*/

/* Needed for Linux to make offsets 64 bits */
#define _FILE_OFFSET_BITS 64

#include "output.h"
#include "masscan.h"
#include "masscan-status.h"
@@ -42,6 +46,18 @@
#include <ctype.h>
#include <string.h>

/*****************************************************************************
 *****************************************************************************/
static int64_t ftell_x(FILE *fp)
{
#if defined(WIN32) && defined(__GNUC__)
    return ftello64(fp);
#elif defined(WIN32) && defined(_MSC_VER)
    return _ftelli64(fp);
#else
    return ftello(fp);
#endif
}

/*****************************************************************************
 * The 'status' variable contains both the open/closed info as well as the
@@ -544,6 +560,23 @@ output_do_rotate(struct Output *out, int is_closing)
     * happen. */
    err = 0;
again:
    if (out->rotate.filesize) {
        size_t x_off=0, x_len=0;
        if (strrchr(filename, '.')) {
            x_off = strrchr(filename, '.') - filename;
            x_len = strlen(filename + x_off);
        } else {
            x_off = strlen(filename);
            x_len = 0;
        }
        sprintf_s(new_filename, new_filename_size,
                      "%s/%.*s-%05u%.*s",
                dir,
                (unsigned)x_off, filename,
                out->rotate.filecount++,
                (unsigned)x_len, filename + x_off
                );
    } else {
        sprintf_s(new_filename, new_filename_size,
                  "%s/%02u%02u%02u-%02u%02u%02u" "-%s",
            dir,
@@ -559,6 +592,7 @@ again:
            if (err++ == 0)
                goto again;
        }
    }
    filename = out->filename;

    /*
@@ -610,14 +644,14 @@ again:
/***************************************************************************
 ***************************************************************************/
static int
is_rotate_time(const struct Output *out, time_t now)
is_rotate_time(const struct Output *out, time_t now, FILE *fp)
{
    if (out->is_virgin_file)
        return 0;
    if (now >= out->rotate.next)
        return 1;
    if (out->rotate.filesize != 0 &&
        out->rotate.bytes_written >= out->rotate.filesize)
        ftell_x(fp) >= out->rotate.filesize)
        return 1;
    return 0;
}
@@ -680,7 +714,7 @@ output_report_status(struct Output *out, time_t timestamp, int status,
     * file, rather than in a separate thread right at the time interval.
     * Thus, if results are coming in slowly, the rotation won't happen
     * on precise boundaries */
    if (is_rotate_time(out, now)) {
    if (is_rotate_time(out, now, fp)) {
        fp = output_do_rotate(out, 0);
        if (fp == NULL)
            return;
@@ -800,7 +834,7 @@ output_report_banner(struct Output *out, time_t now,
     * file, rather than in a separate thread right at the time interval.
     * Thus, if results are coming in slowly, the rotation won't happen
     * on precise boundaries */
    if (is_rotate_time(out, now)) {
    if (is_rotate_time(out, now, fp)) {
        fp = output_do_rotate(out, 0);
        if (fp == NULL)
            return;
@@ -834,8 +868,10 @@ output_destroy(struct Output *out)

    /* If rotating files, then do one last rotate of this file to the
     * destination directory */
    if (out->rotate.period)
    if (out->rotate.period || out->rotate.filesize) {
        LOG(1, "doing finale rotate\n");
        output_do_rotate(out, 1);
    }

    /* If not rotating files, then simply close this file. Remember
     * that some files will write closing information before closing
+1
Changes for src/output.h: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -68,6 +68,7 @@ struct Output
        unsigned offset;
        uint64_t filesize;
        uint64_t bytes_written;
        unsigned filecount; /* filesize rotates */
        char *directory;
    } rotate;

+7
Changes for src/proto-arp.c: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -22,6 +22,13 @@ handle_arp(struct Output *out, time_t timestamp, const unsigned char *px,
    ip_them = parsed->ip_src[0]<<24 | parsed->ip_src[1]<<16
            | parsed->ip_src[2]<< 8 | parsed->ip_src[3]<<0;

    LOG(3, "ARP %u.%u.%u.%u = [%02X:%02X:%02X:%02X:%02X:%02X]\n",
        parsed->ip_src[0], parsed->ip_src[1],
        parsed->ip_src[2], parsed->ip_src[3],
        parsed->mac_src[0], parsed->mac_src[1], parsed->mac_src[2], 
        parsed->mac_src[3], parsed->mac_src[4], parsed->mac_src[5]);


    output_report_status(
                    out,
                    timestamp,
+6 −6
Changes for src/proto-ssl.c: 6 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -1006,22 +1006,22 @@ ssl_hello_heartbeat_template = ssl_hello_heartbeat_templatex;
 * Figure out the Hello message size by parsing the data
 *****************************************************************************/
unsigned
ssl_hello_size(const void *template)
ssl_hello_size(const void *templ)
{
    const unsigned char *px = (const unsigned char *)template;
    const unsigned char *px = (const unsigned char *)templ;
    size_t template_size;
    
    template_size = (px[3]<<8 | px[4]) + 5;
    
    return template_size;
    return (unsigned)template_size;
}
    
/*****************************************************************************
 *****************************************************************************/
char *
ssl_hello(const void *template)
ssl_hello(const void *templ)
{
    unsigned char *px = (unsigned char *)template;
    unsigned char *px = (unsigned char *)templ;
    unsigned now = (unsigned)time(0);
    unsigned i;
    
@@ -1030,7 +1030,7 @@ ssl_hello(const void *template)
    
    /* allocate memory for that size and copy */
    px = malloc(template_size);
    memcpy(px, template, template_size);
    memcpy(px, templ, template_size);
    
    /* set the new timestamp and randomize buffer */
    px[11] = (unsigned char)(now>>24);