Loading src/main.c +6 −23 Original line number Diff line number Diff line Loading @@ -28,6 +28,8 @@ #include "proto-arp.h" /* for responding to ARP requests */ #include "proto-banner1.h" /* for snatching banners from systems */ #include "proto-tcp.h" /* for TCP/IP connection table */ #include "proto-preprocess.h" /* quick parse of packets */ #include "proto-icmp.h" /* handle ICMP responses */ #include "syn-cookie.h" /* for SYN-cookies on send */ #include "output.h" /* for outputing results */ #include "rte-ring.h" /* producer/consumer ring buffer */ Loading @@ -35,7 +37,6 @@ #include "smack.h" /* Aho-corasick state-machine pattern-matcher */ #include "pixie-timer.h" /* portable time functions */ #include "pixie-threads.h" /* portable threads */ #include "proto-preprocess.h" /* quick parse of packets */ #include "templ-payloads.h" /* UDP packet payloads */ #include <string.h> Loading Loading @@ -475,26 +476,7 @@ receive_thread(struct Masscan *masscan, LOG(4, "found udp 0x%08x\n", parsed.ip_dst); continue; case FOUND_ICMP: seqno_me = px[parsed.transport_offset+4]<<24 | px[parsed.transport_offset+5]<<16 | px[parsed.transport_offset+6]<<8 | px[parsed.transport_offset+7]<<0; if (syn_hash(ip_them, 65536*3+0) == seqno_me ) { LOG(4, "%u.%u.%u.%u - ICMP echo response: 0x%08x\n", (ip_them>>24)&0xff, (ip_them>>16)&0xff, (ip_them>>8)&0xff, (ip_them>>0)&0xff, seqno_me); output_report_status( out, Port_IcmpEchoResponse, ip_them, 0, 0, 0); } handle_icmp(out, px, length, &parsed); continue; case FOUND_TCP: /* fall down to below */ Loading Loading @@ -730,7 +712,8 @@ main_scan(struct Masscan *masscan) /* * Reconfigure the packet template according to command-line options */ if (masscan->adapter_port < 0x10000) if (masscan->adapter_port == 0x10000) masscan->adapter_port = 40000 + time(0) % 20000; template_set_source_port(tmplset, masscan->adapter_port); if (masscan->nmap.ttl) template_set_ttl(tmplset, masscan->nmap.ttl); Loading src/proto-preprocess.c +2 −0 Original line number Diff line number Diff line Loading @@ -167,6 +167,8 @@ parse_udp: parse_icmp: { VERIFY_REMAINING(4, FOUND_ICMP); info->port_src = px[offset+0]; info->port_dst = px[offset+1]; return 1; } Loading src/templ-payloads.c +4 −5 Original line number Diff line number Diff line Loading @@ -30,7 +30,7 @@ struct NmapPayloads { }; struct Payload2 hard_coded_payloads[] = { {161, 65536, 56, 0, {161, 65536, 57, 0, "\x30" "\x37" "\x02\x01\x00" /* version */ "\x04\x06" "public" /* community = public */ Loading @@ -51,7 +51,7 @@ struct Payload2 hard_coded_payloads[] = { "\x03" "www" "\x05" "yahoo" "\x03" "com" "\x00" "\x00\x01\x00\x01" /* A IN */ }, {5060, 65536, -1, 0, {5060, 65536, 0xFFFFFFFF, 0, "OPTIONS sip:carol@chicago.com SIP/2.0\r\n" "Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bKhjhs8ass877\r\n" "Max-Forwards: 70\r\n" Loading Loading @@ -184,7 +184,6 @@ is_comment(const char *line) return 1; else return 0; return 0; } /*************************************************************************** Loading Loading @@ -519,8 +518,8 @@ payloads_create() range.end = range.begin; length = hard_coded_payloads[i].length; if (length == -1) length = strlen(hard_coded_payloads[i].buf); if (length == 0xFFFFFFFF) length = (unsigned)strlen(hard_coded_payloads[i].buf); /* Add this to our real payloads. This will get overwritten * if the user adds their own with the same port */ Loading src/templ-pkt.c +58 −37 Original line number Diff line number Diff line Loading @@ -18,7 +18,7 @@ #include <assert.h> #include <string.h> #include <stdlib.h> #include <WinSock.h> static unsigned char default_tcp_template[] = "\0\1\2\3\4\5" /* Ethernet: destination */ "\6\7\x8\x9\xa\xb" /* Ethernet: source */ Loading Loading @@ -241,6 +241,8 @@ tcp_checksum(struct TemplatePacket *tmpl) return xsum; } /*************************************************************************** ***************************************************************************/ unsigned Loading @@ -251,7 +253,7 @@ udp_checksum2(const unsigned char *px, unsigned offset_ip, unsigned i; /* pseudo checksum */ xsum = 6; xsum = 17; xsum += tcp_length; xsum += px[offset_ip + 12] << 8 | px[offset_ip + 13]; xsum += px[offset_ip + 14] << 8 | px[offset_ip + 15]; Loading Loading @@ -280,7 +282,7 @@ udp_checksum(struct TemplatePacket *tmpl) tmpl->packet, tmpl->offset_ip, tmpl->offset_tcp, tmpl->length - tmpl->offset_app); tmpl->length - tmpl->offset_tcp); } /*************************************************************************** Loading Loading @@ -406,6 +408,32 @@ tcp_create_packet( return new_length; } /*************************************************************************** ***************************************************************************/ static void udp_payload_fixup(struct TemplatePacket *tmpl, unsigned port, unsigned seqno) { const unsigned char *px2 = 0; unsigned length2 = 0; unsigned source_port2 = 0x1000; uint64_t xsum2 = 0; unsigned char *px = tmpl->packet; payloads_lookup(tmpl->payloads, port, &px2, &length2, &source_port2, &xsum2); memcpy( px+tmpl->offset_app, px2, length2); tmpl->length = tmpl->offset_app + length2; } /*************************************************************************** * Here we take a packet template, parse it, then make it easier to work * with. Loading Loading @@ -434,6 +462,7 @@ template_set_target( else if (port < 65536*2) { tmpl = &tmplset->pkts[Proto_UDP]; port &= 0xFFFF; udp_payload_fixup(tmpl, port, seqno); } else if (port < 65536*3) { tmpl = &tmplset->pkts[Proto_SCTP]; port &= 0xFFFF; Loading @@ -460,6 +489,11 @@ template_set_target( * Fill in the empty fields in the IP header and then re-calculate * the checksum. */ { unsigned total_length = tmpl->length - tmpl->offset_ip; px[offset_ip+2] = (unsigned char)(total_length>>8); px[offset_ip+3] = (unsigned char)(total_length>>0); } px[offset_ip+4] = (unsigned char)(ip_id >> 8); px[offset_ip+5] = (unsigned char)(ip_id & 0xFF); px[offset_ip+16] = (unsigned char)((ip >> 24) & 0xFF); Loading @@ -468,6 +502,7 @@ template_set_target( px[offset_ip+19] = (unsigned char)((ip >> 0) & 0xFF); xsum = tmpl->checksum_ip; xsum += tmpl->length - tmpl->offset_app; xsum += (ip_id&0xFFFF); xsum += ip; xsum = (xsum >> 16) + (xsum & 0xFFFF); Loading Loading @@ -504,39 +539,25 @@ template_set_target( px[offset_tcp+17] = (unsigned char)(xsum >> 0); break; case Proto_UDP: { const unsigned char *px2; unsigned length2 = 0; unsigned source_port2; payloads_lookup(tmpl->payloads, port, &px2, &length2, &source_port2, &xsum); if (length2) { memcpy(&px[tmpl->offset_app], px2, length2); } else xsum = 0; tmpl->length = offset_tcp + length2 + 8; px[offset_tcp+ 2] = (unsigned char)(port >> 8); px[offset_tcp+ 3] = (unsigned char)(port & 0xFF); px[offset_tcp+ 4] = (unsigned char)((length2+8)>>8); px[offset_tcp+ 5] = (unsigned char)((length2+8)&0xFF); xsum += (uint64_t)tmpl->checksum_tcp px[offset_tcp+ 4] = (unsigned char)((tmpl->length - tmpl->offset_app + 8)>>8); px[offset_tcp+ 5] = (unsigned char)((tmpl->length - tmpl->offset_app + 8)&0xFF); px[offset_tcp+6] = (unsigned char)(0); px[offset_tcp+7] = (unsigned char)(0); xsum = udp_checksum(tmpl); /*xsum += (uint64_t)tmpl->checksum_tcp + (uint64_t)ip + (uint64_t)port + (uint64_t)length2; + (uint64_t)2*(tmpl->length - tmpl->offset_app); xsum = (xsum >> 16) + (xsum & 0xFFFF); xsum = (xsum >> 16) + (xsum & 0xFFFF); xsum = (xsum >> 16) + (xsum & 0xFFFF); printf("%04x\n", xsum);*/ xsum = ~xsum; px[offset_tcp+6] = (unsigned char)(xsum >> 8); px[offset_tcp+7] = (unsigned char)(xsum >> 0); } break; case Proto_SCTP: break; Loading vs10/masscan.vcxproj +2 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ <ClCompile Include="..\src\out-text.c" /> <ClCompile Include="..\src\out-xml.c" /> <ClCompile Include="..\src\proto-banner1.c" /> <ClCompile Include="..\src\proto-icmp.c" /> <ClCompile Include="..\src\proto-tcp.c" /> <ClCompile Include="..\src\logger.c" /> <ClCompile Include="..\src\main-conf.c" /> Loading Loading @@ -74,6 +75,7 @@ <ClInclude Include="..\src\pixie-timer.h" /> <ClInclude Include="..\src\proto-arp.h" /> <ClInclude Include="..\src\proto-banner1.h" /> <ClInclude Include="..\src\proto-icmp.h" /> <ClInclude Include="..\src\proto-preprocess.h" /> <ClInclude Include="..\src\proto-tcp.h" /> <ClInclude Include="..\src\rand-blackrock.h" /> Loading Loading
src/main.c +6 −23 Original line number Diff line number Diff line Loading @@ -28,6 +28,8 @@ #include "proto-arp.h" /* for responding to ARP requests */ #include "proto-banner1.h" /* for snatching banners from systems */ #include "proto-tcp.h" /* for TCP/IP connection table */ #include "proto-preprocess.h" /* quick parse of packets */ #include "proto-icmp.h" /* handle ICMP responses */ #include "syn-cookie.h" /* for SYN-cookies on send */ #include "output.h" /* for outputing results */ #include "rte-ring.h" /* producer/consumer ring buffer */ Loading @@ -35,7 +37,6 @@ #include "smack.h" /* Aho-corasick state-machine pattern-matcher */ #include "pixie-timer.h" /* portable time functions */ #include "pixie-threads.h" /* portable threads */ #include "proto-preprocess.h" /* quick parse of packets */ #include "templ-payloads.h" /* UDP packet payloads */ #include <string.h> Loading Loading @@ -475,26 +476,7 @@ receive_thread(struct Masscan *masscan, LOG(4, "found udp 0x%08x\n", parsed.ip_dst); continue; case FOUND_ICMP: seqno_me = px[parsed.transport_offset+4]<<24 | px[parsed.transport_offset+5]<<16 | px[parsed.transport_offset+6]<<8 | px[parsed.transport_offset+7]<<0; if (syn_hash(ip_them, 65536*3+0) == seqno_me ) { LOG(4, "%u.%u.%u.%u - ICMP echo response: 0x%08x\n", (ip_them>>24)&0xff, (ip_them>>16)&0xff, (ip_them>>8)&0xff, (ip_them>>0)&0xff, seqno_me); output_report_status( out, Port_IcmpEchoResponse, ip_them, 0, 0, 0); } handle_icmp(out, px, length, &parsed); continue; case FOUND_TCP: /* fall down to below */ Loading Loading @@ -730,7 +712,8 @@ main_scan(struct Masscan *masscan) /* * Reconfigure the packet template according to command-line options */ if (masscan->adapter_port < 0x10000) if (masscan->adapter_port == 0x10000) masscan->adapter_port = 40000 + time(0) % 20000; template_set_source_port(tmplset, masscan->adapter_port); if (masscan->nmap.ttl) template_set_ttl(tmplset, masscan->nmap.ttl); Loading
src/proto-preprocess.c +2 −0 Original line number Diff line number Diff line Loading @@ -167,6 +167,8 @@ parse_udp: parse_icmp: { VERIFY_REMAINING(4, FOUND_ICMP); info->port_src = px[offset+0]; info->port_dst = px[offset+1]; return 1; } Loading
src/templ-payloads.c +4 −5 Original line number Diff line number Diff line Loading @@ -30,7 +30,7 @@ struct NmapPayloads { }; struct Payload2 hard_coded_payloads[] = { {161, 65536, 56, 0, {161, 65536, 57, 0, "\x30" "\x37" "\x02\x01\x00" /* version */ "\x04\x06" "public" /* community = public */ Loading @@ -51,7 +51,7 @@ struct Payload2 hard_coded_payloads[] = { "\x03" "www" "\x05" "yahoo" "\x03" "com" "\x00" "\x00\x01\x00\x01" /* A IN */ }, {5060, 65536, -1, 0, {5060, 65536, 0xFFFFFFFF, 0, "OPTIONS sip:carol@chicago.com SIP/2.0\r\n" "Via: SIP/2.0/UDP pc33.atlanta.com;branch=z9hG4bKhjhs8ass877\r\n" "Max-Forwards: 70\r\n" Loading Loading @@ -184,7 +184,6 @@ is_comment(const char *line) return 1; else return 0; return 0; } /*************************************************************************** Loading Loading @@ -519,8 +518,8 @@ payloads_create() range.end = range.begin; length = hard_coded_payloads[i].length; if (length == -1) length = strlen(hard_coded_payloads[i].buf); if (length == 0xFFFFFFFF) length = (unsigned)strlen(hard_coded_payloads[i].buf); /* Add this to our real payloads. This will get overwritten * if the user adds their own with the same port */ Loading
src/templ-pkt.c +58 −37 Original line number Diff line number Diff line Loading @@ -18,7 +18,7 @@ #include <assert.h> #include <string.h> #include <stdlib.h> #include <WinSock.h> static unsigned char default_tcp_template[] = "\0\1\2\3\4\5" /* Ethernet: destination */ "\6\7\x8\x9\xa\xb" /* Ethernet: source */ Loading Loading @@ -241,6 +241,8 @@ tcp_checksum(struct TemplatePacket *tmpl) return xsum; } /*************************************************************************** ***************************************************************************/ unsigned Loading @@ -251,7 +253,7 @@ udp_checksum2(const unsigned char *px, unsigned offset_ip, unsigned i; /* pseudo checksum */ xsum = 6; xsum = 17; xsum += tcp_length; xsum += px[offset_ip + 12] << 8 | px[offset_ip + 13]; xsum += px[offset_ip + 14] << 8 | px[offset_ip + 15]; Loading Loading @@ -280,7 +282,7 @@ udp_checksum(struct TemplatePacket *tmpl) tmpl->packet, tmpl->offset_ip, tmpl->offset_tcp, tmpl->length - tmpl->offset_app); tmpl->length - tmpl->offset_tcp); } /*************************************************************************** Loading Loading @@ -406,6 +408,32 @@ tcp_create_packet( return new_length; } /*************************************************************************** ***************************************************************************/ static void udp_payload_fixup(struct TemplatePacket *tmpl, unsigned port, unsigned seqno) { const unsigned char *px2 = 0; unsigned length2 = 0; unsigned source_port2 = 0x1000; uint64_t xsum2 = 0; unsigned char *px = tmpl->packet; payloads_lookup(tmpl->payloads, port, &px2, &length2, &source_port2, &xsum2); memcpy( px+tmpl->offset_app, px2, length2); tmpl->length = tmpl->offset_app + length2; } /*************************************************************************** * Here we take a packet template, parse it, then make it easier to work * with. Loading Loading @@ -434,6 +462,7 @@ template_set_target( else if (port < 65536*2) { tmpl = &tmplset->pkts[Proto_UDP]; port &= 0xFFFF; udp_payload_fixup(tmpl, port, seqno); } else if (port < 65536*3) { tmpl = &tmplset->pkts[Proto_SCTP]; port &= 0xFFFF; Loading @@ -460,6 +489,11 @@ template_set_target( * Fill in the empty fields in the IP header and then re-calculate * the checksum. */ { unsigned total_length = tmpl->length - tmpl->offset_ip; px[offset_ip+2] = (unsigned char)(total_length>>8); px[offset_ip+3] = (unsigned char)(total_length>>0); } px[offset_ip+4] = (unsigned char)(ip_id >> 8); px[offset_ip+5] = (unsigned char)(ip_id & 0xFF); px[offset_ip+16] = (unsigned char)((ip >> 24) & 0xFF); Loading @@ -468,6 +502,7 @@ template_set_target( px[offset_ip+19] = (unsigned char)((ip >> 0) & 0xFF); xsum = tmpl->checksum_ip; xsum += tmpl->length - tmpl->offset_app; xsum += (ip_id&0xFFFF); xsum += ip; xsum = (xsum >> 16) + (xsum & 0xFFFF); Loading Loading @@ -504,39 +539,25 @@ template_set_target( px[offset_tcp+17] = (unsigned char)(xsum >> 0); break; case Proto_UDP: { const unsigned char *px2; unsigned length2 = 0; unsigned source_port2; payloads_lookup(tmpl->payloads, port, &px2, &length2, &source_port2, &xsum); if (length2) { memcpy(&px[tmpl->offset_app], px2, length2); } else xsum = 0; tmpl->length = offset_tcp + length2 + 8; px[offset_tcp+ 2] = (unsigned char)(port >> 8); px[offset_tcp+ 3] = (unsigned char)(port & 0xFF); px[offset_tcp+ 4] = (unsigned char)((length2+8)>>8); px[offset_tcp+ 5] = (unsigned char)((length2+8)&0xFF); xsum += (uint64_t)tmpl->checksum_tcp px[offset_tcp+ 4] = (unsigned char)((tmpl->length - tmpl->offset_app + 8)>>8); px[offset_tcp+ 5] = (unsigned char)((tmpl->length - tmpl->offset_app + 8)&0xFF); px[offset_tcp+6] = (unsigned char)(0); px[offset_tcp+7] = (unsigned char)(0); xsum = udp_checksum(tmpl); /*xsum += (uint64_t)tmpl->checksum_tcp + (uint64_t)ip + (uint64_t)port + (uint64_t)length2; + (uint64_t)2*(tmpl->length - tmpl->offset_app); xsum = (xsum >> 16) + (xsum & 0xFFFF); xsum = (xsum >> 16) + (xsum & 0xFFFF); xsum = (xsum >> 16) + (xsum & 0xFFFF); printf("%04x\n", xsum);*/ xsum = ~xsum; px[offset_tcp+6] = (unsigned char)(xsum >> 8); px[offset_tcp+7] = (unsigned char)(xsum >> 0); } break; case Proto_SCTP: break; Loading
vs10/masscan.vcxproj +2 −0 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ <ClCompile Include="..\src\out-text.c" /> <ClCompile Include="..\src\out-xml.c" /> <ClCompile Include="..\src\proto-banner1.c" /> <ClCompile Include="..\src\proto-icmp.c" /> <ClCompile Include="..\src\proto-tcp.c" /> <ClCompile Include="..\src\logger.c" /> <ClCompile Include="..\src\main-conf.c" /> Loading Loading @@ -74,6 +75,7 @@ <ClInclude Include="..\src\pixie-timer.h" /> <ClInclude Include="..\src\proto-arp.h" /> <ClInclude Include="..\src\proto-banner1.h" /> <ClInclude Include="..\src\proto-icmp.h" /> <ClInclude Include="..\src\proto-preprocess.h" /> <ClInclude Include="..\src\proto-tcp.h" /> <ClInclude Include="..\src\rand-blackrock.h" /> Loading