Skip to content

Commit ae4b908

Browse files
oproto
1 parent 0e17953 commit ae4b908

20 files changed

+310
-86
lines changed

Diff for: .gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
paused.conf
22
.Makefile.swp
3-
3+
.vscode

Diff for: src/main-conf.c

+21-6
Original file line numberDiff line numberDiff line change
@@ -1787,6 +1787,13 @@ masscan_set_parameter(struct Masscan *masscan,
17871787
if (masscan->op == 0)
17881788
masscan->op = Operation_Scan;
17891789
}
1790+
else if (EQUALS("oprotos", name) || EQUALS("oproto", name)) {
1791+
unsigned is_error = 0;
1792+
masscan->scan_type.oproto = 1;
1793+
rangelist_parse_ports(&masscan->ports, value, &is_error, Templ_Oproto_first);
1794+
if (masscan->op == 0)
1795+
masscan->op = Operation_Scan;
1796+
}
17901797
else if (EQUALS("tcp-ports", name) || EQUALS("tcp-port", name)) {
17911798
unsigned is_error = 0;
17921799
masscan->scan_type.tcp = 1;
@@ -2300,8 +2307,10 @@ masscan_load_database_files(struct Masscan *masscan)
23002307
if (filename) {
23012308
if (masscan->payloads.udp == NULL)
23022309
masscan->payloads.udp = payloads_udp_create();
2303-
2304-
payloads_read_pcap(filename, masscan->payloads.udp);
2310+
if (masscan->payloads.oproto == NULL)
2311+
masscan->payloads.oproto = payloads_udp_create();
2312+
2313+
payloads_read_pcap(filename, masscan->payloads.udp, masscan->payloads.oproto);
23052314
}
23062315

23072316
/*
@@ -2626,9 +2635,9 @@ masscan_command_line(struct Masscan *masscan, int argc, char *argv[])
26262635
case 'N':
26272636
fprintf(stderr, "nmap(%s): NULL scan not yet supported\n", argv[i]);
26282637
exit(1);
2629-
case 'O':
2630-
fprintf(stderr, "nmap(%s): IP proto scan not yet supported\n", argv[i]);
2631-
exit(1);
2638+
case 'O': /* Other IP protocols (not ICMP, UDP, TCP, or SCTP) */
2639+
masscan->scan_type.oproto = 1;
2640+
break;
26322641
case 'S': /* TCP SYN scan - THIS IS WHAT WE DO! */
26332642
masscan->scan_type.tcp = 1;
26342643
break;
@@ -2720,7 +2729,8 @@ masscan_command_line(struct Masscan *masscan, int argc, char *argv[])
27202729
* If no other "scan type" found, then default to TCP
27212730
*/
27222731
if (masscan->scan_type.udp == 0 && masscan->scan_type.sctp == 0
2723-
&& masscan->scan_type.ping == 0 && masscan->scan_type.arp == 0)
2732+
&& masscan->scan_type.ping == 0 && masscan->scan_type.arp == 0
2733+
&& masscan->scan_type.oproto == 0)
27242734
masscan->scan_type.tcp = 1;
27252735

27262736
/*
@@ -2798,6 +2808,11 @@ masscan_echo(struct Masscan *masscan, FILE *fp, unsigned is_echo_all)
27982808
rrange.end -= Templ_UDP;
27992809
fprintf(fp,"U:");
28002810
range.begin = Templ_SCTP;
2811+
} else if (Templ_Oproto_first <= rrange.begin && rrange.begin <= Templ_Oproto_last) {
2812+
rrange.begin -= Templ_Oproto_first;
2813+
rrange.end -= Templ_Oproto_first;
2814+
fprintf(fp, "O:");
2815+
range.begin = Templ_Oproto_first;
28012816
} else
28022817
range.begin = Templ_UDP;
28032818
rrange.end = min(rrange.end, 65535);

Diff for: src/main.c

+7
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include "crypto-base64.h" /* base64 encode/decode */
5555
#include "pixie-backtrace.h"
5656
#include "proto-sctp.h"
57+
#include "proto-oproto.h" /* Other protocols on top of IP */
5758
#include "vulncheck.h" /* checking vulns like monlist, poodle, heartblee */
5859
#include "main-readrange.h"
5960
#include "scripting.h"
@@ -829,6 +830,9 @@ receive_thread(void *v)
829830
case FOUND_SCTP:
830831
handle_sctp(out, secs, px, length, cookie, &parsed, entropy);
831832
break;
833+
case FOUND_OPROTO: /* other IP proto */
834+
handle_oproto(out, secs, px, length, &parsed, entropy);
835+
break;
832836
case FOUND_TCP:
833837
/* fall down to below */
834838
break;
@@ -1141,6 +1145,7 @@ main_scan(struct Masscan *masscan)
11411145
* makes lookups faster at high packet rates.
11421146
*/
11431147
payloads_udp_trim(masscan->payloads.udp, &masscan->ports);
1148+
payloads_oproto_trim(masscan->payloads.oproto, &masscan->ports);
11441149

11451150
/* Optimize target selection so it's a quick binary search instead
11461151
* of walking large memory tables. When we scan the entire Internet
@@ -1204,6 +1209,7 @@ main_scan(struct Masscan *masscan)
12041209
parms->adapter_mac,
12051210
parms->router_mac,
12061211
masscan->payloads.udp,
1212+
masscan->payloads.oproto,
12071213
rawsock_datalink(masscan->nic[index].adapter),
12081214
masscan->seed);
12091215

@@ -1503,6 +1509,7 @@ int main(int argc, char *argv[])
15031509
masscan->shard.of = 1;
15041510
masscan->min_packet_size = 60;
15051511
masscan->payloads.udp = payloads_udp_create();
1512+
masscan->payloads.oproto = payloads_oproto_create();
15061513
strcpy_s( masscan->output.rotate.directory,
15071514
sizeof(masscan->output.rotate.directory),
15081515
".");

Diff for: src/masscan.h

+5-3
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,11 @@ struct Masscan
9797

9898
struct {
9999
unsigned tcp:1;
100-
unsigned udp:1;
100+
unsigned udp:1; /* -sU */
101101
unsigned sctp:1;
102-
unsigned ping:1; /* --ping, ICMP echo */
103-
unsigned arp:1; /* --arp, local ARP scan */
102+
unsigned ping:1; /* --ping, ICMP echo */
103+
unsigned arp:1; /* --arp, local ARP scan */
104+
unsigned oproto:1; /* -sO */
104105
} scan_type;
105106

106107
/**
@@ -369,6 +370,7 @@ struct Masscan
369370
char *nmap_service_probes_filename;
370371

371372
struct PayloadsUDP *udp;
373+
struct PayloadsUDP *oproto;
372374
struct TcpCfgPayloads *tcp;
373375
struct NmapServiceProbeList *probes;
374376
} payloads;

Diff for: src/out-grepable.c

+15-9
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
/****************************************************************************
1111
****************************************************************************/
1212
static unsigned
13-
count_type(const struct RangeList *ports, int type)
13+
count_type(const struct RangeList *ports, int start_type, int end_type)
1414
{
15-
unsigned min_port = type;
16-
unsigned max_port = type + 65535;
15+
unsigned min_port = start_type;
16+
unsigned max_port = end_type;
1717
unsigned i;
1818
unsigned result = 0;
1919

@@ -84,22 +84,28 @@ grepable_out_open(struct Output *out, FILE *fp)
8484
fprintf(fp, "# Masscan " MASSCAN_VERSION " scan initiated %s\n",
8585
timestamp);
8686

87-
count = count_type(&out->masscan->ports, Templ_TCP);
87+
count = count_type(&out->masscan->ports, Templ_TCP, Templ_TCP_last);
8888
fprintf(fp, "# Ports scanned: TCP(%u;", count);
8989
if (count)
9090
print_port_list(&out->masscan->ports, Templ_TCP, fp);
9191

92-
count = count_type(&out->masscan->ports, Templ_UDP);
92+
count = count_type(&out->masscan->ports, Templ_UDP, Templ_UDP_last);
9393
fprintf(fp, ") UDP(%u;", count);
9494
if (count)
9595
print_port_list(&out->masscan->ports, Templ_UDP, fp);
96-
97-
count = count_type(&out->masscan->ports, Templ_SCTP);
96+
97+
98+
count = count_type(&out->masscan->ports, Templ_SCTP, Templ_SCTP_last);
9899
fprintf(fp, ") SCTP(%u;", count);
99100
if (count)
100101
print_port_list(&out->masscan->ports, Templ_SCTP, fp);
101102

102-
fprintf(fp, ") PROTOCOLS(0;)\n");
103+
count = count_type(&out->masscan->ports, Templ_Oproto_first, Templ_Oproto_last);
104+
fprintf(fp, ") PROTOCOLS(%u;", count);
105+
if (count)
106+
print_port_list(&out->masscan->ports, Templ_Oproto_first, fp);
107+
108+
fprintf(fp, ")\n");
103109
}
104110

105111
/****************************************************************************
@@ -145,7 +151,7 @@ grepable_out_status(struct Output *out, FILE *fp, time_t timestamp,
145151
else if (ip_proto == 17)
146152
service = udp_service_name(port);
147153
else
148-
service = "";
154+
service = oproto_service_name(ip_proto);
149155

150156
fprintf(fp, "Timestamp: %lu", timestamp);
151157

Diff for: src/out-tcp-services.c

+18-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
static char *tcp_services[65536];
1717
static char *udp_services[65536];
18-
18+
static char *oproto_services[256];
1919

2020

2121
const char *
@@ -82,3 +82,20 @@ udp_service_name(int port)
8282
}
8383
#endif
8484
}
85+
86+
const char *
87+
oproto_service_name(int port)
88+
{
89+
if (oproto_services[port])
90+
return oproto_services[port];
91+
{
92+
struct protoent *result;
93+
94+
result = getprotobynumber(port);
95+
96+
if (result == 0)
97+
return "unknown";
98+
99+
return oproto_services[port] = strdup(result->p_name);
100+
}
101+
}

Diff for: src/out-tcp-services.h

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
const char *tcp_service_name(int port);
55
const char *udp_service_name(int port);
6+
const char *oproto_service_name(int protocol_number);
67

78
#endif
89

Diff for: src/output.c

+3
Original file line numberDiff line numberDiff line change
@@ -793,6 +793,9 @@ output_report_status(struct Output *out, time_t timestamp, int status,
793793
case 132:
794794
out->counts.sctp.open++;
795795
break;
796+
default:
797+
out->counts.oproto.open++;
798+
break;
796799
}
797800
if (!out->is_show_open)
798801
return;

Diff for: src/output.h

+4
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ struct Output
106106
struct {
107107
uint64_t open;
108108
} arp;
109+
struct {
110+
uint64_t open;
111+
uint64_t closed;
112+
} oproto;
109113
} counts;
110114

111115
struct {

Diff for: src/proto-oproto.c

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include "proto-oproto.h"
2+
3+
void
4+
handle_oproto(struct Output *out, time_t timestamp,
5+
const unsigned char *px, unsigned length,
6+
struct PreprocessedInfo *parsed,
7+
uint64_t entropy)
8+
{
9+
10+
}

Diff for: src/proto-oproto.h

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/*
2+
Other IP protocol (not TCP, UDP, TCP, ICMP
3+
Specificaly for scanning things like GRE.
4+
*/
5+
#ifndef PROTO_OPROTO_H
6+
#define PROTO_OPROTO_H
7+
#include <stdint.h>
8+
#include <time.h>
9+
struct Output;
10+
struct PreprocessedInfo;
11+
12+
13+
/**
14+
* Parse an incoming response.
15+
* @param entropy
16+
* The random seed, used in calculating syn-cookies.
17+
*/
18+
void
19+
handle_oproto(struct Output *out, time_t timestamp,
20+
const unsigned char *px, unsigned length,
21+
struct PreprocessedInfo *parsed,
22+
uint64_t entropy);
23+
24+
#endif
25+

Diff for: src/proto-preprocess.c

+3-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ preprocess_frame(const unsigned char *px, unsigned length, unsigned link_type,
127127
case 6: goto parse_tcp;
128128
case 17: goto parse_udp;
129129
case 132: goto parse_sctp;
130-
default: return 0; /* todo: should add more protocols, like ICMP */
130+
default:
131+
VERIFY_REMAINING(0, FOUND_OPROTO);
132+
return 0; /* todo: should add more protocols, like ICMP */
131133
}
132134
}
133135

Diff for: src/proto-preprocess.h

+1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ enum {
2222
FOUND_LLC,
2323
FOUND_ARP,
2424
FOUND_SLL, /* Linux SLL */
25+
FOUND_OPROTO, /* some other IP protocol */
2526
};
2627
struct PreprocessedInfo {
2728
const unsigned char *mac_src;

Diff for: src/ranges.c

+8-1
Original file line numberDiff line numberDiff line change
@@ -784,6 +784,9 @@ rangelist_parse_ports(struct RangeList *ports, const char *string, unsigned *is_
784784
case 'S': case 's':
785785
proto_offset = Templ_SCTP;
786786
break;
787+
case 'O': case 'o':
788+
proto_offset = Templ_Oproto_first;
789+
break;
787790
case 'I': case 'i':
788791
proto_offset = Templ_ICMP_echo;
789792
break;
@@ -805,7 +808,11 @@ rangelist_parse_ports(struct RangeList *ports, const char *string, unsigned *is_
805808
end = (unsigned)strtoul(p, &p, 0);
806809
}
807810

808-
if (port > 0xFFFF || end > 0xFFFF || end < port) {
811+
if (port > 0xFF && proto_offset == Templ_Oproto_first) {
812+
fprintf(stderr, "bad ports: %u-%u\n", port, end);
813+
*is_error = 2;
814+
return p;
815+
} else if (port > 0xFFFF || end > 0xFFFF || end < port) {
809816
fprintf(stderr, "bad ports: %u-%u\n", port, end);
810817
*is_error = 2;
811818
return p;

0 commit comments

Comments
 (0)