Commit 903f7fb8 authored by Robert David Graham's avatar Robert David Graham
Browse files

VPN tunnel adapters

parent 833933a5
Loading
Loading
Loading
Loading
+27 −24
Original line number Diff line number Diff line
@@ -57,7 +57,7 @@ masscan_initialize_adapter(
     * IP ADDRESS
     *
     * We need to figure out that IP address to send packets from. This
     * is done by queryin the adapter (or configured by user). If the
     * is done by querying the adapter (or configured by user). If the
     * adapter doesn't have one, then the user must configure one.
     */
    adapter_ip = masscan->nic[index].src.ip.first;
@@ -74,9 +74,11 @@ masscan_initialize_adapter(
        masscan->nic[index].src.ip.range = 1;
    }
    if (adapter_ip == 0) {
        fprintf(stderr, "FAIL: failed to detect IP of interface \"%s\"\n", ifname);
        fprintf(stderr, "FAIL: failed to detect IP of interface \"%s\"\n", 
                        ifname);
        fprintf(stderr, " [hint] did you spell the name correctly?\n");
        fprintf(stderr, " [hint] if it has no IP address, manually set with \"--adapter-ip 192.168.100.5\"\n");
        fprintf(stderr, " [hint] if it has no IP address, manually set with "
                        "\"--adapter-ip 192.168.100.5\"\n");
        return -1;
    }

@@ -88,10 +90,11 @@ masscan_initialize_adapter(
     * try to use the hardware address in the network card.
     */
    memcpy(adapter_mac, masscan->nic[index].my_mac, 6);
    if (masscan->nic[index].my_mac_count == 0) {
        if (memcmp(adapter_mac, "\0\0\0\0\0\0", 6) == 0) {
        unsigned is_error;
            
        is_error = rawsock_get_adapter_mac(ifname, adapter_mac);
            rawsock_get_adapter_mac(ifname, adapter_mac);
            
            LOG(2, "auto-detected: adapter-mac=%02x-%02x-%02x-%02x-%02x-%02x\n",
                adapter_mac[0],
                adapter_mac[1],
@@ -101,14 +104,14 @@ masscan_initialize_adapter(
                adapter_mac[5]
                );
        }
    if (memcmp(adapter_mac, "\0\0\0\0\0\0", 6) == 0 
            && masscan->nic[index].my_mac_count == 0) {
        if (memcmp(adapter_mac, "\0\0\0\0\0\0", 6) == 0) {
            fprintf(stderr, "FAIL: failed to detect MAC address of interface:" 
                    " \"%s\"\n", ifname);
            fprintf(stderr, " [hint] try something like " 
                    "\"--adapter-mac 00-11-22-33-44-55\"\n");
            return -1;
        }
    }
    
    /*
     * START ADAPTER
+6 −13
Original line number Diff line number Diff line
@@ -503,6 +503,7 @@ receive_thread(void *v)
    struct ThreadPair *parms = (struct ThreadPair *)v;
    const struct Masscan *masscan = parms->masscan;
    struct Adapter *adapter = parms->adapter;
    int data_link = rawsock_datalink(adapter);
    struct Output *out;
    struct DedupTable *dedup;
    struct PcapFile *pcapfile = NULL;
@@ -524,7 +525,8 @@ receive_thread(void *v)
            cpu -= cpu_count;
            cpu++;
        }
        pixie_cpu_set_affinity(cpu);
        //TODO:
        //pixie_cpu_set_affinity(cpu);
    }

    /*
@@ -643,7 +645,7 @@ receive_thread(void *v)
         * figure out where the TCP/IP headers are and the locations of
         * some fields, like IP address and port numbers.
         */
        x = preprocess_frame(px, length, 1, &parsed);
        x = preprocess_frame(px, length, data_link, &parsed);
        if (!x)
            continue; /* corrupt packet */
        ip_me = parsed.ip_dst[0]<<24 | parsed.ip_dst[1]<<16
@@ -1040,7 +1042,8 @@ main_scan(struct Masscan *masscan)
                    parms->tmplset,
                    parms->adapter_mac,
                    parms->router_mac,
                    masscan->payloads);
                    masscan->payloads,
                    rawsock_datalink(masscan->nic[index].adapter));

        /*
         * Set the "source port" of everything we transmit.
@@ -1054,16 +1057,6 @@ main_scan(struct Masscan *masscan)

        parms->src = masscan->nic[index].src;

#if 0
        if (masscan->nic[index].adapter_port == 0x10000)
            masscan->nic[index].adapter_port = 40000 + now % 20000;
        template_set_source_port(   parms->tmplset,
                                    masscan->nic[index].adapter_port);
        /*
         * Read back what we've set
         */
        parms->adapter_port = template_get_source_port(parms->tmplset);
#endif

        /*
         * Set the "TTL" (IP time-to-live) of everything we send.
+1 −0
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ struct Masscan
        unsigned char my_mac[6];
        unsigned char router_mac[6];
        unsigned router_ip;
        int link_type; /* libpcap definitions */
        unsigned char my_mac_count;
    } nic[8];
    unsigned nic_count;
+3 −1
Original line number Diff line number Diff line
@@ -53,7 +53,8 @@
/****************************************************************************
 ****************************************************************************/
unsigned
preprocess_frame(const unsigned char *px, unsigned length, unsigned link_type, struct PreprocessedInfo *info)
preprocess_frame(const unsigned char *px, unsigned length, unsigned link_type, 
                 struct PreprocessedInfo *info)
{
    unsigned offset = 0;
    unsigned ethertype = 0;
@@ -422,6 +423,7 @@ parse_linktype:
     */
    switch (link_type) {
    case 1:     goto parse_ethernet;
    case 12:    goto parse_ipv4;
    case 0x69:  goto parse_wifi;
    case 119:   goto parse_prism_header;
    case 127:   goto parse_radiotap_header;
+13 −6
Original line number Diff line number Diff line
@@ -758,10 +758,17 @@ handle_ack(
}


/***************************************************************************
 ***************************************************************************/
/*****************************************************************************
 * Handles incoming events, like timeouts and packets, that cause a change
 * in the TCP control block "state".
 *
 * This is the part of the code that implements the famous TCP state-machine
 * you see drawn everywhere, where they have states like "TIME_WAIT". Only
 * we don't really have those states.
 *****************************************************************************/
void
tcpcon_handle(struct TCP_ConnectionTable *tcpcon, struct TCP_Control_Block *tcb,
tcpcon_handle(struct TCP_ConnectionTable *tcpcon, 
              struct TCP_Control_Block *tcb,
              int what, const void *vpayload, size_t payload_length,
              unsigned secs, unsigned usecs,
              unsigned seqno_them)
Loading