Commit 7ea9ec0b authored by Robert David Graham's avatar Robert David Graham
Browse files

udp banner default

parent 83fbdf6f
Loading
Loading
Loading
Loading
+1 −1
Changes for src/masscan-version.h: 1 added line, 1 removed line.
Original line number Diff line number Diff line
#ifndef MASSCAN_VERSION

#define MASSCAN_VERSION "1.0.4"
#define MASSCAN_VERSION "1.0.6"

#endif
+1
Changes for src/proto-banner1.c: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -273,6 +273,7 @@ banner1_create(void)
    b->tcp_payloads[9050] = (void*)&banner_ssl;  /* Tor */
    b->tcp_payloads[8140] = (void*)&banner_ssl;  /* puppet */

    b->tcp_payloads[11211] = (void*)&banner_memcached;

    return b;
}
+11 −5
Changes for src/proto-memcached.c: 11 added lines, 5 removed lines.
Original line number Diff line number Diff line
@@ -11,6 +11,7 @@
#include "proto-interactive.h"
#include "proto-preprocess.h"
#include "proto-ssl.h"
#include "proto-udp.h"
#include "syn-cookie.h"
#include "templ-port.h"
#include <ctype.h>
@@ -193,6 +194,7 @@ memcached_tcp_parse(
                    banout_append(banout, PROTO_MEMCACHED, memcached_stats[id].pattern, AUTO_LEN);
                    if (px[i] == '\n')
                        state = 0;
                    else
                        state = 200;
                    banout_append_char(banout, PROTO_MEMCACHED, '=');
                    break;
@@ -246,7 +248,7 @@ memcached_init(struct Banner1 *b)
            smack_add_pattern(
                          b->memcached_responses,
                          tmp,
                          len+1,
                          (unsigned)len+1,
                          memcached_responses[i].id,
                          memcached_responses[i].is_anchored);
        }
@@ -276,7 +278,7 @@ memcached_init(struct Banner1 *b)
            smack_add_pattern(
                          b->memcached_stats,
                          tmp,
                          len+1,
                          (unsigned)len+1,
                          memcached_stats[i].id,
                          memcached_stats[i].is_anchored);
        }
@@ -330,15 +332,15 @@ memcached_udp_parse(struct Output *out, time_t timestamp,

    /* Ignore high sequence numbers. This should be zero normally */
    if (sequence_num > 100)
        return 0;
        goto not_memcached;

    /* Ignore too many dgrams, should be one normally */
    if (total_dgrams > 100)
        return 0;
        goto not_memcached;

    /* Make sure reserved field is zero */
    if (reserved != 0)
        return 0;
        goto not_memcached;

    /* Grab IP addresses */
    ip_them = parsed->ip_src[0]<<24 | parsed->ip_src[1]<<16
@@ -385,6 +387,9 @@ memcached_udp_parse(struct Output *out, time_t timestamp,
    banout_release(banout);

    return 0;
    
not_memcached:
    return default_udp_parse(out, timestamp, px, length, parsed, entropy);
}

/****************************************************************************
@@ -428,3 +433,4 @@ const struct ProtocolParserStream banner_memcached = {
    memcached_init,
    memcached_tcp_parse,
};
                             
+40 −1
Changes for src/proto-udp.c: 40 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -13,6 +13,41 @@
#include "unusedparm.h"


/****************************************************************************
 * When the "--banner" command-line option is selected, this will
 * will take up to 64 bytes of a response and display it. Other UDP
 * protocol parsers may also default to this function when they detect
 * a response is not the protocol they expect. For example, if a response
 * to port 161 obbvioiusly isn't ASN.1 formatted, the SNMP parser will
 * call this function instead. In such cases, the protcool identifier will
 * be [unknown] rather than [snmp].
 ****************************************************************************/
unsigned
default_udp_parse(struct Output *out, time_t timestamp,
           const unsigned char *px, unsigned length,
           struct PreprocessedInfo *parsed,
           uint64_t entropy)
{
    unsigned ip_them;
    //unsigned ip_me;
    unsigned port_them = parsed->port_src;
    //unsigned port_me = parsed->port_dst;
    
    ip_them = parsed->ip_src[0]<<24 | parsed->ip_src[1]<<16 | parsed->ip_src[2]<< 8 | parsed->ip_src[3]<<0;
    //ip_me = parsed->ip_dst[0]<<24 | parsed->ip_dst[1]<<16 | parsed->ip_dst[2]<< 8 | parsed->ip_dst[3]<<0;

    if (length > 64)
        length = 64;
    
    output_report_banner(
                         out, timestamp,
                         ip_them, 17, port_them,
                         PROTO_NONE,
                         parsed->ip_ttl,
                         px, length);

    return 0;
}

/****************************************************************************
 ****************************************************************************/
@@ -54,7 +89,11 @@ handle_udp(struct Output *out, time_t timestamp,
        case 16471:
            status = handle_zeroaccess(out, timestamp, px, length, parsed, entropy);
            break;
            
        default:
            px += parsed->app_offset;
            length = parsed->app_length;
            status = default_udp_parse(out, timestamp, px, length, parsed, entropy);
            break;
    }

    if (status == 0)
+11
Changes for src/proto-udp.h: 11 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -17,4 +17,15 @@ handle_udp(struct Output *out, time_t timestamp,
    struct PreprocessedInfo *parsed,
    uint64_t entropy);

/**
 * Default banner for UDP, consisting of the first 64 bytes, when it isn't
 * detected as the appropriate protocol
 */
unsigned
default_udp_parse(struct Output *out, time_t timestamp,
                  const unsigned char *px, unsigned length,
                  struct PreprocessedInfo *parsed,
                  uint64_t entropy);


#endif
Loading