Loading Makefile +12 −0 Original line number Diff line number Diff line PREFIX ?= /usr BINDIR ?= $(PREFIX)/bin SYS := $(shell gcc -dumpmachine) GITVER := $(shell git describe --tags) ifeq ($(GITVER),) GITVER = "unknown" endif # LINUX # The automated regression tests run on Linux, so this is the one Loading Loading @@ -67,6 +72,11 @@ CFLAGS = -g -ggdb $(FLAGS2) $(INCLUDES) $(DEFINES) -Wall -O3 all: bin/masscan tmp/main-conf.o: src/main-conf.c src/*.h $(CC) $(CFLAGS) -c $< -o $@ -DGIT=\"$(GITVER)\" # just compile everything in the 'src' directory. Using this technique # means that include file dependencies are broken, so sometimes when # the program crashes unexpectedly, 'make clean' then 'make' fixes the Loading @@ -74,9 +84,11 @@ all: bin/masscan tmp/%.o: src/%.c src/*.h $(CC) $(CFLAGS) -c $< -o $@ SRC = $(wildcard src/*.c) OBJ = $(addprefix tmp/, $(notdir $(addsuffix .o, $(basename $(SRC))))) bin/masscan: $(OBJ) $(CC) $(CFLAGS) -o $@ $(OBJ) $(LDFLAGS) $(LIBS) Loading src/in-binary.c +46 −0 Original line number Diff line number Diff line Loading @@ -146,6 +146,7 @@ parse_banner3(struct Output *out, unsigned char *buf, size_t buf_length) 6, /* this is always TCP */ record.port, record.app_proto, 0, /* ttl */ buf+12, (unsigned)buf_length-12 ); } Loading @@ -159,6 +160,9 @@ parse_banner4(struct Output *out, unsigned char *buf, size_t buf_length) { struct MasscanRecord record; if (buf_length < 13) return; /* * Parse the parts that are common to most records */ Loading @@ -181,10 +185,49 @@ parse_banner4(struct Output *out, unsigned char *buf, size_t buf_length) record.ip_proto, /* TCP=6, UDP=17 */ record.port, record.app_proto, /* HTTP, SSL, SNMP, etc. */ 0, /* ttl */ buf+13, (unsigned)buf_length-13 ); } /*************************************************************************** ***************************************************************************/ static void parse_banner9(struct Output *out, unsigned char *buf, size_t buf_length) { struct MasscanRecord record; if (buf_length < 14) return; /* * Parse the parts that are common to most records */ record.timestamp = buf[0]<<24 | buf[1]<<16 | buf[2]<<8 | buf[3]; record.ip = buf[4]<<24 | buf[5]<<16 | buf[6]<<8 | buf[7]; record.ip_proto = buf[8]; record.port = buf[9]<<8 | buf[10]; record.app_proto = buf[11]<<8 | buf[12]; record.ttl = buf[13]; if (out->when_scan_started == 0) out->when_scan_started = record.timestamp; /* * Now print the output */ output_report_banner( out, record.timestamp, record.ip, record.ip_proto, /* TCP=6, UDP=17 */ record.port, record.app_proto, /* HTTP, SSL, SNMP, etc. */ record.ttl, /* ttl */ buf+13, (unsigned)buf_length-14 ); } /*************************************************************************** * Read in the file, one record at a time. ***************************************************************************/ Loading Loading @@ -321,6 +364,9 @@ parse_file(struct Output *out, const char *filename) case 7: /* STATUS: closed */ parse_status2(out, PortStatus_Closed, buf, bytes_read); break; case 9: parse_banner9(out, buf, bytes_read); break; case 'm': /* FILEHEADER */ //goto end; break; Loading src/main-conf.c +94 −4 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ */ #include "masscan.h" #include "masscan-version.h" #include "ranges.h" #include "string_s.h" #include "logger.h" Loading Loading @@ -55,6 +56,88 @@ masscan_usage(void) exit(1); } /*************************************************************************** ***************************************************************************/ static void print_version() { const char *cpu = "unknown"; const char *compiler = "unknown"; const char *compiler_version = "unknown"; const char *os = "unknown"; printf("\n"); printf("Masscan version %s ( %s )\n", MASSCAN_VERSION, "https://github.com/robertdavidgraham/masscan" ); printf("Compiled on: %s %s\n", __DATE__, __TIME__); #if defined(_MSC_VER) #if defined(_M_AMD64) || defined(_M_X64) cpu = "x86"; #elif defined(_M_IX86) cpu = "x86"; #elif defined (_M_ARM_FP) cpu = "arm"; #endif { int msc_ver = _MSC_VER; compiler = "VisualStudio"; if (msc_ver < 1500) compiler_version = "pre2008"; else if (msc_ver == 1500) compiler_version = "2008"; else if (msc_ver == 1600) compiler_version = "2010"; else if (msc_ver == 1700) compiler_version = "2012"; else if (msc_ver == 1800) compiler_version = "2013"; else compiler_version = "post-2013"; } #elif defined(__GNUC__) compiler = "gcc"; compiler_version = __VERSION__; #if defined(i386) || defined(__i386) || defined(__i386__) cpu = "x86"; #endif #if defined(__corei7) || defined(__corei7__) cpu = "x86-Corei7"; #endif #endif #if defined(WIN32) os = "Windows"; #elif defined(__linux__) os = "Linux"; #elif defined(__APPLE__) os = "Apple"; #elif defined(__MACH__) os = "MACH"; #elif defined(__FreeBSD__) os = "FreeBSD"; #elif defined(unix) || defined(__unix) || defined(__unix__) os = "Unix"; #endif printf("Compiler: %s %s\n", compiler, compiler_version); printf("OS: %s\n", os); printf("CPU: %s (%u bits)\n", cpu, (unsigned)(sizeof(void*))*8); #if defined(GIT) printf("GIT version: %s\n", GIT); #endif } /*************************************************************************** ***************************************************************************/ static void Loading Loading @@ -1293,6 +1376,8 @@ masscan_set_parameter(struct Masscan *masscan, } else if (EQUALS("randomize-hosts", name)) { /* already do that */ ; } else if (EQUALS("readrange", name) || EQUALS("readranges", name)) { masscan->op = Operation_ReadRange; } else if (EQUALS("reason", name)) { masscan->output.is_reason = 1; } else if (EQUALS("redis", name)) { Loading Loading @@ -1452,6 +1537,9 @@ masscan_set_parameter(struct Masscan *masscan, } else { masscan->nmap.ttl = x; } } else if (EQUALS("version", name)) { print_version(); exit(1); } else if (EQUALS("version-intensity", name)) { fprintf(stderr, "nmap(%s): unsupported\n", name); exit(1); Loading Loading @@ -1485,7 +1573,8 @@ is_singleton(const char *name) { static const char *singletons[] = { "echo", "selftest", "self-test", "regress", "system-dns", "traceroute", "version-light", "system-dns", "traceroute", "version", "version-light", "version-all", "version-trace", "osscan-limit", "osscan-guess", "badsum", "reason", "open", "open-only", Loading @@ -1497,6 +1586,7 @@ is_singleton(const char *name) "banners", "banner", "nobanners", "nobanner", "offline", "ping", "ping-sweep", "arp", "infinite", "interactive", "read-range", "read-ranges", "readrange", "read-ranges", 0}; size_t i; Loading Loading @@ -1559,9 +1649,9 @@ masscan_command_line(struct Masscan *masscan, int argc, char *argv[]) * -- name value */ if (argv[i][0] == '-' && argv[i][1] == '-') { if (strcmp(argv[i], "--help") == 0) if (strcmp(argv[i], "--help") == 0) { masscan_help(); else if (EQUALS("readscan", argv[i]+2)) { } else if (EQUALS("readscan", argv[i]+2)) { /* Read in a binary file instead of scanning the network*/ masscan->op = Operation_ReadScan; Loading Loading @@ -1856,7 +1946,7 @@ masscan_command_line(struct Masscan *masscan, int argc, char *argv[]) } break; case 'V': /* print version and exit */ exit(1); masscan_set_parameter(masscan, "version", ""); break; case 'W': masscan->op = Operation_List_Adapters; Loading src/main.c +10 −3 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ #include "pixie-backtrace.h" #include "proto-sctp.h" #include "script.h" #include "main-readrange.h" #include <assert.h> #include <limits.h> Loading Loading @@ -717,6 +718,7 @@ receive_thread(void *v) seqno_them = TCP_SEQNO(px, parsed.transport_offset); seqno_me = TCP_ACKNO(px, parsed.transport_offset); switch (parsed.ip_protocol) { case 132: /* SCTP */ cookie = syn_cookie(ip_them, port_them | (Proto_SCTP<<16), ip_me, port_me, entropy) & 0xFFFFFFFF; Loading Loading @@ -838,7 +840,8 @@ receive_thread(void *v) tcb = tcpcon_create_tcb(tcpcon, ip_me, ip_them, port_me, port_them, seqno_me, seqno_them+1); seqno_me, seqno_them+1, parsed.ip_ttl); (*status_tcb_count)++; } Loading Loading @@ -925,7 +928,7 @@ receive_thread(void *v) 6, /* ip proto = tcp */ port_them, px[parsed.transport_offset + 13], /* tcp flags */ px[parsed.ip_offset + 8] /* ttl */ parsed.ip_ttl ); /* Loading Loading @@ -1492,6 +1495,10 @@ int main(int argc, char *argv[]) rawsock_selftest_if(masscan->nic[i].ifname); return 0; case Operation_ReadRange: main_readrange(masscan); return 0; case Operation_ReadScan: { unsigned start; Loading src/masscan-version.h +1 −1 Original line number Diff line number Diff line #ifndef MASSCAN_VERSION #define MASSCAN_VERSION "1.0.2" #define MASSCAN_VERSION "1.0.3" #endif Loading
Makefile +12 −0 Original line number Diff line number Diff line PREFIX ?= /usr BINDIR ?= $(PREFIX)/bin SYS := $(shell gcc -dumpmachine) GITVER := $(shell git describe --tags) ifeq ($(GITVER),) GITVER = "unknown" endif # LINUX # The automated regression tests run on Linux, so this is the one Loading Loading @@ -67,6 +72,11 @@ CFLAGS = -g -ggdb $(FLAGS2) $(INCLUDES) $(DEFINES) -Wall -O3 all: bin/masscan tmp/main-conf.o: src/main-conf.c src/*.h $(CC) $(CFLAGS) -c $< -o $@ -DGIT=\"$(GITVER)\" # just compile everything in the 'src' directory. Using this technique # means that include file dependencies are broken, so sometimes when # the program crashes unexpectedly, 'make clean' then 'make' fixes the Loading @@ -74,9 +84,11 @@ all: bin/masscan tmp/%.o: src/%.c src/*.h $(CC) $(CFLAGS) -c $< -o $@ SRC = $(wildcard src/*.c) OBJ = $(addprefix tmp/, $(notdir $(addsuffix .o, $(basename $(SRC))))) bin/masscan: $(OBJ) $(CC) $(CFLAGS) -o $@ $(OBJ) $(LDFLAGS) $(LIBS) Loading
src/in-binary.c +46 −0 Original line number Diff line number Diff line Loading @@ -146,6 +146,7 @@ parse_banner3(struct Output *out, unsigned char *buf, size_t buf_length) 6, /* this is always TCP */ record.port, record.app_proto, 0, /* ttl */ buf+12, (unsigned)buf_length-12 ); } Loading @@ -159,6 +160,9 @@ parse_banner4(struct Output *out, unsigned char *buf, size_t buf_length) { struct MasscanRecord record; if (buf_length < 13) return; /* * Parse the parts that are common to most records */ Loading @@ -181,10 +185,49 @@ parse_banner4(struct Output *out, unsigned char *buf, size_t buf_length) record.ip_proto, /* TCP=6, UDP=17 */ record.port, record.app_proto, /* HTTP, SSL, SNMP, etc. */ 0, /* ttl */ buf+13, (unsigned)buf_length-13 ); } /*************************************************************************** ***************************************************************************/ static void parse_banner9(struct Output *out, unsigned char *buf, size_t buf_length) { struct MasscanRecord record; if (buf_length < 14) return; /* * Parse the parts that are common to most records */ record.timestamp = buf[0]<<24 | buf[1]<<16 | buf[2]<<8 | buf[3]; record.ip = buf[4]<<24 | buf[5]<<16 | buf[6]<<8 | buf[7]; record.ip_proto = buf[8]; record.port = buf[9]<<8 | buf[10]; record.app_proto = buf[11]<<8 | buf[12]; record.ttl = buf[13]; if (out->when_scan_started == 0) out->when_scan_started = record.timestamp; /* * Now print the output */ output_report_banner( out, record.timestamp, record.ip, record.ip_proto, /* TCP=6, UDP=17 */ record.port, record.app_proto, /* HTTP, SSL, SNMP, etc. */ record.ttl, /* ttl */ buf+13, (unsigned)buf_length-14 ); } /*************************************************************************** * Read in the file, one record at a time. ***************************************************************************/ Loading Loading @@ -321,6 +364,9 @@ parse_file(struct Output *out, const char *filename) case 7: /* STATUS: closed */ parse_status2(out, PortStatus_Closed, buf, bytes_read); break; case 9: parse_banner9(out, buf, bytes_read); break; case 'm': /* FILEHEADER */ //goto end; break; Loading
src/main-conf.c +94 −4 Original line number Diff line number Diff line Loading @@ -12,6 +12,7 @@ */ #include "masscan.h" #include "masscan-version.h" #include "ranges.h" #include "string_s.h" #include "logger.h" Loading Loading @@ -55,6 +56,88 @@ masscan_usage(void) exit(1); } /*************************************************************************** ***************************************************************************/ static void print_version() { const char *cpu = "unknown"; const char *compiler = "unknown"; const char *compiler_version = "unknown"; const char *os = "unknown"; printf("\n"); printf("Masscan version %s ( %s )\n", MASSCAN_VERSION, "https://github.com/robertdavidgraham/masscan" ); printf("Compiled on: %s %s\n", __DATE__, __TIME__); #if defined(_MSC_VER) #if defined(_M_AMD64) || defined(_M_X64) cpu = "x86"; #elif defined(_M_IX86) cpu = "x86"; #elif defined (_M_ARM_FP) cpu = "arm"; #endif { int msc_ver = _MSC_VER; compiler = "VisualStudio"; if (msc_ver < 1500) compiler_version = "pre2008"; else if (msc_ver == 1500) compiler_version = "2008"; else if (msc_ver == 1600) compiler_version = "2010"; else if (msc_ver == 1700) compiler_version = "2012"; else if (msc_ver == 1800) compiler_version = "2013"; else compiler_version = "post-2013"; } #elif defined(__GNUC__) compiler = "gcc"; compiler_version = __VERSION__; #if defined(i386) || defined(__i386) || defined(__i386__) cpu = "x86"; #endif #if defined(__corei7) || defined(__corei7__) cpu = "x86-Corei7"; #endif #endif #if defined(WIN32) os = "Windows"; #elif defined(__linux__) os = "Linux"; #elif defined(__APPLE__) os = "Apple"; #elif defined(__MACH__) os = "MACH"; #elif defined(__FreeBSD__) os = "FreeBSD"; #elif defined(unix) || defined(__unix) || defined(__unix__) os = "Unix"; #endif printf("Compiler: %s %s\n", compiler, compiler_version); printf("OS: %s\n", os); printf("CPU: %s (%u bits)\n", cpu, (unsigned)(sizeof(void*))*8); #if defined(GIT) printf("GIT version: %s\n", GIT); #endif } /*************************************************************************** ***************************************************************************/ static void Loading Loading @@ -1293,6 +1376,8 @@ masscan_set_parameter(struct Masscan *masscan, } else if (EQUALS("randomize-hosts", name)) { /* already do that */ ; } else if (EQUALS("readrange", name) || EQUALS("readranges", name)) { masscan->op = Operation_ReadRange; } else if (EQUALS("reason", name)) { masscan->output.is_reason = 1; } else if (EQUALS("redis", name)) { Loading Loading @@ -1452,6 +1537,9 @@ masscan_set_parameter(struct Masscan *masscan, } else { masscan->nmap.ttl = x; } } else if (EQUALS("version", name)) { print_version(); exit(1); } else if (EQUALS("version-intensity", name)) { fprintf(stderr, "nmap(%s): unsupported\n", name); exit(1); Loading Loading @@ -1485,7 +1573,8 @@ is_singleton(const char *name) { static const char *singletons[] = { "echo", "selftest", "self-test", "regress", "system-dns", "traceroute", "version-light", "system-dns", "traceroute", "version", "version-light", "version-all", "version-trace", "osscan-limit", "osscan-guess", "badsum", "reason", "open", "open-only", Loading @@ -1497,6 +1586,7 @@ is_singleton(const char *name) "banners", "banner", "nobanners", "nobanner", "offline", "ping", "ping-sweep", "arp", "infinite", "interactive", "read-range", "read-ranges", "readrange", "read-ranges", 0}; size_t i; Loading Loading @@ -1559,9 +1649,9 @@ masscan_command_line(struct Masscan *masscan, int argc, char *argv[]) * -- name value */ if (argv[i][0] == '-' && argv[i][1] == '-') { if (strcmp(argv[i], "--help") == 0) if (strcmp(argv[i], "--help") == 0) { masscan_help(); else if (EQUALS("readscan", argv[i]+2)) { } else if (EQUALS("readscan", argv[i]+2)) { /* Read in a binary file instead of scanning the network*/ masscan->op = Operation_ReadScan; Loading Loading @@ -1856,7 +1946,7 @@ masscan_command_line(struct Masscan *masscan, int argc, char *argv[]) } break; case 'V': /* print version and exit */ exit(1); masscan_set_parameter(masscan, "version", ""); break; case 'W': masscan->op = Operation_List_Adapters; Loading
src/main.c +10 −3 Original line number Diff line number Diff line Loading @@ -53,6 +53,7 @@ #include "pixie-backtrace.h" #include "proto-sctp.h" #include "script.h" #include "main-readrange.h" #include <assert.h> #include <limits.h> Loading Loading @@ -717,6 +718,7 @@ receive_thread(void *v) seqno_them = TCP_SEQNO(px, parsed.transport_offset); seqno_me = TCP_ACKNO(px, parsed.transport_offset); switch (parsed.ip_protocol) { case 132: /* SCTP */ cookie = syn_cookie(ip_them, port_them | (Proto_SCTP<<16), ip_me, port_me, entropy) & 0xFFFFFFFF; Loading Loading @@ -838,7 +840,8 @@ receive_thread(void *v) tcb = tcpcon_create_tcb(tcpcon, ip_me, ip_them, port_me, port_them, seqno_me, seqno_them+1); seqno_me, seqno_them+1, parsed.ip_ttl); (*status_tcb_count)++; } Loading Loading @@ -925,7 +928,7 @@ receive_thread(void *v) 6, /* ip proto = tcp */ port_them, px[parsed.transport_offset + 13], /* tcp flags */ px[parsed.ip_offset + 8] /* ttl */ parsed.ip_ttl ); /* Loading Loading @@ -1492,6 +1495,10 @@ int main(int argc, char *argv[]) rawsock_selftest_if(masscan->nic[i].ifname); return 0; case Operation_ReadRange: main_readrange(masscan); return 0; case Operation_ReadScan: { unsigned start; Loading
src/masscan-version.h +1 −1 Original line number Diff line number Diff line #ifndef MASSCAN_VERSION #define MASSCAN_VERSION "1.0.2" #define MASSCAN_VERSION "1.0.3" #endif