Skip to content

Commit

Permalink
Merge pull request #743 from robertdavidgraham/integration
Browse files Browse the repository at this point in the history
Integration
  • Loading branch information
robertdavidgraham authored Nov 16, 2023
2 parents b246710 + 53e50d5 commit 87a363d
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 24 deletions.
1 change: 1 addition & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1843,6 +1843,7 @@ int main(int argc, char *argv[])
x += zeroaccess_selftest();
x += nmapserviceprobes_selftest();
x += rstfilter_selftest();
x += masscan_app_selftest();


if (x != 0) {
Expand Down
49 changes: 42 additions & 7 deletions src/masscan-app.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ masscan_app_to_string(enum ApplicationProtocol proto)
case PROTO_VULN: return "vuln";
case PROTO_HEARTBLEED: return "heartbleed";
case PROTO_TICKETBLEED: return "ticketbleed";
case PROTO_VNC_RFB: return "vnc";
case PROTO_VNC_INFO: return "vnc-info";
case PROTO_VNC_OLD: return "vnc";
case PROTO_SAFE: return "safe";
case PROTO_MEMCACHED: return "memcached";
case PROTO_SCRIPTING: return "scripting";
Expand All @@ -44,9 +43,11 @@ masscan_app_to_string(enum ApplicationProtocol proto)
case PROTO_TELNET: return "telnet";
case PROTO_RDP: return "rdp";
case PROTO_HTTP_SERVER: return "http.server";
case PROTO_MC: return "minecraft";

case PROTO_ERROR: return "error";
case PROTO_MC: return "minecraft";
case PROTO_VNC_RFB: return "vnc";
case PROTO_VNC_INFO: return "vnc-info";

case PROTO_ERROR: return "error";

default:
sprintf_s(tmp, sizeof(tmp), "(%u)", proto);
Expand Down Expand Up @@ -85,8 +86,7 @@ masscan_string_to_app(const char *str)
{"vuln", PROTO_VULN},
{"heartbleed", PROTO_HEARTBLEED},
{"ticketbleed", PROTO_TICKETBLEED},
{"vnc", PROTO_VNC_RFB},
{"vnc", PROTO_VNC_INFO},
{"vnc-old", PROTO_VNC_OLD},
{"safe", PROTO_SAFE},
{"memcached", PROTO_MEMCACHED},
{"scripting", PROTO_SCRIPTING},
Expand All @@ -96,6 +96,8 @@ masscan_string_to_app(const char *str)
{"rdp", PROTO_RDP},
{"http.server", PROTO_HTTP_SERVER},
{"minecraft", PROTO_MC},
{"vnc", PROTO_VNC_RFB},
{"vnc-info", PROTO_VNC_INFO},
{0,0}
};
size_t i;
Expand All @@ -106,3 +108,36 @@ masscan_string_to_app(const char *str)
}
return 0;
}

int
masscan_app_selftest(void) {
static const struct {
unsigned enumid;
unsigned expected;
} tests[] = {
{PROTO_SNMP, 7},
{PROTO_X509_CERT, 15},
{PROTO_HTTP_SERVER, 31},
{0,0}
};
size_t i;

/* The ENUM contains fixed values in external files,
* so programmers should only add onto its end, not
* the middle. This self-test will verify that
* a programmer hasn't made this mistake.
*/
for (i=0; tests[i].enumid != 0; i++) {
unsigned enumid = tests[i].enumid;
unsigned expected = tests[i].expected;

/* YOU ADDED AN ENUM IN THE MIDDLE INSTEAD ON THE END OF THE LIST */
if (enumid != expected) {
fprintf(stderr, "[-] %s:%u fail\n", __FILE__, (unsigned)__LINE__);
fprintf(stderr, "[-] enum expected=%u, found=%u\n", 30, PROTO_HTTP_SERVER);
return 1;
}
}

return 0;
}
38 changes: 21 additions & 17 deletions src/masscan-app.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,34 +13,35 @@ enum ApplicationProtocol {
PROTO_HTTP,
PROTO_FTP,
PROTO_DNS_VERSIONBIND,
PROTO_SNMP, /* simple network management protocol, udp/161 */
PROTO_NBTSTAT, /* netbios, udp/137 */
PROTO_SNMP, /* 7 - simple network management protocol, udp/161 */
PROTO_NBTSTAT, /* 8 - netbios, udp/137 */
PROTO_SSL3,
PROTO_SMB, /* SMB tcp/139 and tcp/445 */
PROTO_SMTP,
PROTO_POP3,
PROTO_IMAP4,
PROTO_SMB, /* 10 - SMB tcp/139 and tcp/445 */
PROTO_SMTP, /* 11 - transfering email */
PROTO_POP3, /* 12 - fetching email */
PROTO_IMAP4, /* 13 - fetching email */
PROTO_UDP_ZEROACCESS,
PROTO_X509_CERT,
PROTO_X509_CERT, /* 15 - just the cert */
PROTO_X509_CACERT,
PROTO_HTML_TITLE,
PROTO_HTML_FULL,
PROTO_NTP, /* network time protocol, udp/123 */
PROTO_NTP, /* 19 - network time protocol, udp/123 */
PROTO_VULN,
PROTO_HEARTBLEED,
PROTO_TICKETBLEED,
PROTO_VNC_RFB,
PROTO_VNC_INFO,
PROTO_VNC_OLD,
PROTO_SAFE,
PROTO_MEMCACHED,
PROTO_MEMCACHED, /* 25 - memcached */
PROTO_SCRIPTING,
PROTO_VERSIONING,
PROTO_COAP, /* constrained app proto, udp/5683, RFC7252 */
PROTO_TELNET,
PROTO_RDP, /* Microsoft Remote Desktop Protocol tcp/3389 */
PROTO_HTTP_SERVER, /* HTTP "Server:" field */
PROTO_MC, /* Minecraft server */

PROTO_COAP, /* 28 - constrained app proto, udp/5683, RFC7252 */
PROTO_TELNET, /* 29 - ye old remote terminal */
PROTO_RDP, /* 30 - Microsoft Remote Desktop Protocol tcp/3389 */
PROTO_HTTP_SERVER, /* 31 - HTTP "Server:" field */
PROTO_MC, /* 32 - Minecraft server */
PROTO_VNC_RFB,
PROTO_VNC_INFO,

PROTO_ERROR,

PROTO_end_of_list /* must be last one */
Expand All @@ -52,4 +53,7 @@ masscan_app_to_string(enum ApplicationProtocol proto);
enum ApplicationProtocol
masscan_string_to_app(const char *str);

int
masscan_app_selftest(void);

#endif

0 comments on commit 87a363d

Please sign in to comment.