Loading src/masscan-app.c +2 −3 Changes for src/masscan-app.c: 2 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -16,8 +16,7 @@ masscan_app_to_string(enum ApplicationProtocol proto) case PROTO_SSH1: return "ssh"; case PROTO_SSH2: return "ssh"; case PROTO_HTTP: return "http"; case PROTO_FTP1: return "ftp"; case PROTO_FTP2: return "ftp"; case PROTO_FTP: return "ftp"; case PROTO_DNS_VERSIONBIND: return "dns-ver"; case PROTO_SNMP: return "snmp"; case PROTO_NBTSTAT: return "nbtstat"; Loading Loading @@ -52,7 +51,7 @@ masscan_string_to_app(const char *str) {"ssh2", PROTO_SSH2}, {"ssh", PROTO_SSH2}, {"http", PROTO_HTTP}, {"ftp", PROTO_FTP1}, {"ftp", PROTO_FTP}, {"dns-ver", PROTO_DNS_VERSIONBIND}, {"snmp", PROTO_SNMP}, {"ssh2", PROTO_SSH2}, Loading src/masscan-app.h +1 −2 Changes for src/masscan-app.h: 1 added line, 2 removed lines. Original line number Diff line number Diff line Loading @@ -11,8 +11,7 @@ enum ApplicationProtocol { PROTO_SSH1, PROTO_SSH2, PROTO_HTTP, PROTO_FTP1, PROTO_FTP2, PROTO_FTP, PROTO_DNS_VERSIONBIND, PROTO_SNMP, /* simple network management protocol, udp/161 */ PROTO_NBTSTAT, /* netbios, udp/137 */ Loading src/proto-banner1.c +15 −5 Changes for src/proto-banner1.c: 15 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ #include "proto-http.h" #include "proto-ssl.h" #include "proto-ssh.h" #include "proto-ftp.h" #include "proto-vnc.h" #include "masscan-app.h" #include <ctype.h> Loading @@ -22,8 +23,8 @@ struct Patterns patterns[] = { {"SSH-1.", 6, PROTO_SSH1, SMACK_ANCHOR_BEGIN}, {"SSH-2.", 6, PROTO_SSH2, SMACK_ANCHOR_BEGIN}, {"HTTP/1.", 7, PROTO_HTTP, SMACK_ANCHOR_BEGIN}, {"220-", 4, PROTO_FTP1, SMACK_ANCHOR_BEGIN}, {"220 ", 4, PROTO_FTP2, SMACK_ANCHOR_BEGIN}, {"220-", 4, PROTO_FTP, SMACK_ANCHOR_BEGIN, 0}, {"220 ", 4, PROTO_FTP, SMACK_ANCHOR_BEGIN, 1}, {"+OK ", 4, PROTO_POP3, SMACK_ANCHOR_BEGIN}, {"* OK ", 5, PROTO_IMAP4, SMACK_ANCHOR_BEGIN}, {"\x16\x03\x00",3, PROTO_SSL3, SMACK_ANCHOR_BEGIN}, Loading Loading @@ -88,9 +89,11 @@ banner1_parse( /* Kludge: patterns look confusing, so add port info to the * pattern */ switch (proto) { case PROTO_FTP2: case PROTO_FTP: if (patterns[x].extra == 0) { if (tcb_state->port == 25 || tcb_state->port == 587) proto = PROTO_SMTP; } break; case PROTO_VNC_RFB: tcb_state->sub.vnc.version = patterns[x].extra; Loading Loading @@ -125,10 +128,17 @@ banner1_parse( banout_append(banout, PROTO_HEUR, px, length); } break; case PROTO_FTP: banner_ftp.parse( banner1, banner1->http_fields, tcb_state, px, length, banout, more); break; case PROTO_SSH1: case PROTO_SSH2: case PROTO_FTP1: case PROTO_FTP2: case PROTO_SMTP: case PROTO_POP3: case PROTO_IMAP4: Loading src/proto-banner1.h +6 Changes for src/proto-banner1.h: 6 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -93,6 +93,11 @@ struct VNCSTUFF { struct PIXEL_FORMAT pixel; }; struct FTPSTUFF { unsigned code; unsigned is_last:1; }; struct ProtocolState { unsigned state; unsigned remaining; Loading @@ -105,6 +110,7 @@ struct ProtocolState { union { struct SSLRECORD ssl; struct VNCSTUFF vnc; struct FTPSTUFF ftp; } sub; }; Loading src/proto-ftp.c +147 Changes for src/proto-ftp.c: 147 added lines, 0 removed lines. Original line number Diff line number Diff line #include "proto-ftp.h" #include "proto-banner1.h" #include "unusedparm.h" #include "masscan-app.h" #include "proto-interactive.h" #include "proto-ssl.h" #include <ctype.h> #include <string.h> /*************************************************************************** ***************************************************************************/ static void ftp_parse( const struct Banner1 *banner1, void *banner1_private, struct ProtocolState *pstate, const unsigned char *px, size_t length, struct BannerOutput *banout, struct InteractiveData *more) { unsigned state = pstate->state; unsigned i; struct FTPSTUFF *ftp = &pstate->sub.ftp; UNUSEDPARM(banner1_private); UNUSEDPARM(banner1); for (i=0; i<length; i++) { switch (state) { case 0: case 100: ftp->code = 0; state++; /* fall through */ case 1: case 2: case 3: case 101: case 102: case 103: if (!isdigit(px[i]&0xFF)) { state = STATE_DONE; } else { ftp->code *= 10; ftp->code += (px[i] - '0'); state++; banout_append_char(banout, PROTO_FTP, px[i]); } break; case 4: case 104: if (px[i] == ' ') { ftp->is_last = 1; state++; banout_append_char(banout, PROTO_FTP, px[i]); } else if (px[i] == '-') { ftp->is_last = 0; state++; banout_append_char(banout, PROTO_FTP, px[i]); } else { state = STATE_DONE; } break; case 5: if (px[i] == '\r') continue; else if (px[i] == '\n') { if (ftp->is_last) { more->payload = "AUTH TLS\r\n"; more->length = 10; state = 100; banout_append_char(banout, PROTO_FTP, px[i]); } else { banout_append_char(banout, PROTO_FTP, px[i]); state = 0; } } else if (px[i] == '\0' || !isprint(px[i])) { state = STATE_DONE; continue; } else { banout_append_char(banout, PROTO_FTP, px[i]); } break; case 105: if (px[i] == '\r') continue; else if (px[i] == '\n') { if (ftp->code == 234) { /* change the state here to SSL */ unsigned port = pstate->port; memset(pstate, 0, sizeof(*pstate)); pstate->app_proto = PROTO_SSL3; pstate->is_sent_sslhello = 1; pstate->port = port; state = 0; more->payload = banner_ssl.hello; more->length = banner_ssl.hello_length; } else { state = STATE_DONE; } } else if (px[i] == '\0' || !isprint(px[i])) { state = STATE_DONE; continue; } else { banout_append_char(banout, PROTO_FTP, px[i]); } break; default: i = (unsigned)length; break; } } pstate->state = state; } /*************************************************************************** ***************************************************************************/ static void * ftp_init(struct Banner1 *banner1) { UNUSEDPARM(banner1); return 0; } /*************************************************************************** ***************************************************************************/ static int ftp_selftest(void) { return 0; } /*************************************************************************** ***************************************************************************/ const struct ProtocolParserStream banner_ftp = { "ftp", 21, 0, 0, 0, ftp_selftest, ftp_init, ftp_parse, }; Loading
src/masscan-app.c +2 −3 Changes for src/masscan-app.c: 2 added lines, 3 removed lines. Original line number Diff line number Diff line Loading @@ -16,8 +16,7 @@ masscan_app_to_string(enum ApplicationProtocol proto) case PROTO_SSH1: return "ssh"; case PROTO_SSH2: return "ssh"; case PROTO_HTTP: return "http"; case PROTO_FTP1: return "ftp"; case PROTO_FTP2: return "ftp"; case PROTO_FTP: return "ftp"; case PROTO_DNS_VERSIONBIND: return "dns-ver"; case PROTO_SNMP: return "snmp"; case PROTO_NBTSTAT: return "nbtstat"; Loading Loading @@ -52,7 +51,7 @@ masscan_string_to_app(const char *str) {"ssh2", PROTO_SSH2}, {"ssh", PROTO_SSH2}, {"http", PROTO_HTTP}, {"ftp", PROTO_FTP1}, {"ftp", PROTO_FTP}, {"dns-ver", PROTO_DNS_VERSIONBIND}, {"snmp", PROTO_SNMP}, {"ssh2", PROTO_SSH2}, Loading
src/masscan-app.h +1 −2 Changes for src/masscan-app.h: 1 added line, 2 removed lines. Original line number Diff line number Diff line Loading @@ -11,8 +11,7 @@ enum ApplicationProtocol { PROTO_SSH1, PROTO_SSH2, PROTO_HTTP, PROTO_FTP1, PROTO_FTP2, PROTO_FTP, PROTO_DNS_VERSIONBIND, PROTO_SNMP, /* simple network management protocol, udp/161 */ PROTO_NBTSTAT, /* netbios, udp/137 */ Loading
src/proto-banner1.c +15 −5 Changes for src/proto-banner1.c: 15 added lines, 5 removed lines. Original line number Diff line number Diff line Loading @@ -9,6 +9,7 @@ #include "proto-http.h" #include "proto-ssl.h" #include "proto-ssh.h" #include "proto-ftp.h" #include "proto-vnc.h" #include "masscan-app.h" #include <ctype.h> Loading @@ -22,8 +23,8 @@ struct Patterns patterns[] = { {"SSH-1.", 6, PROTO_SSH1, SMACK_ANCHOR_BEGIN}, {"SSH-2.", 6, PROTO_SSH2, SMACK_ANCHOR_BEGIN}, {"HTTP/1.", 7, PROTO_HTTP, SMACK_ANCHOR_BEGIN}, {"220-", 4, PROTO_FTP1, SMACK_ANCHOR_BEGIN}, {"220 ", 4, PROTO_FTP2, SMACK_ANCHOR_BEGIN}, {"220-", 4, PROTO_FTP, SMACK_ANCHOR_BEGIN, 0}, {"220 ", 4, PROTO_FTP, SMACK_ANCHOR_BEGIN, 1}, {"+OK ", 4, PROTO_POP3, SMACK_ANCHOR_BEGIN}, {"* OK ", 5, PROTO_IMAP4, SMACK_ANCHOR_BEGIN}, {"\x16\x03\x00",3, PROTO_SSL3, SMACK_ANCHOR_BEGIN}, Loading Loading @@ -88,9 +89,11 @@ banner1_parse( /* Kludge: patterns look confusing, so add port info to the * pattern */ switch (proto) { case PROTO_FTP2: case PROTO_FTP: if (patterns[x].extra == 0) { if (tcb_state->port == 25 || tcb_state->port == 587) proto = PROTO_SMTP; } break; case PROTO_VNC_RFB: tcb_state->sub.vnc.version = patterns[x].extra; Loading Loading @@ -125,10 +128,17 @@ banner1_parse( banout_append(banout, PROTO_HEUR, px, length); } break; case PROTO_FTP: banner_ftp.parse( banner1, banner1->http_fields, tcb_state, px, length, banout, more); break; case PROTO_SSH1: case PROTO_SSH2: case PROTO_FTP1: case PROTO_FTP2: case PROTO_SMTP: case PROTO_POP3: case PROTO_IMAP4: Loading
src/proto-banner1.h +6 Changes for src/proto-banner1.h: 6 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -93,6 +93,11 @@ struct VNCSTUFF { struct PIXEL_FORMAT pixel; }; struct FTPSTUFF { unsigned code; unsigned is_last:1; }; struct ProtocolState { unsigned state; unsigned remaining; Loading @@ -105,6 +110,7 @@ struct ProtocolState { union { struct SSLRECORD ssl; struct VNCSTUFF vnc; struct FTPSTUFF ftp; } sub; }; Loading
src/proto-ftp.c +147 Changes for src/proto-ftp.c: 147 added lines, 0 removed lines. Original line number Diff line number Diff line #include "proto-ftp.h" #include "proto-banner1.h" #include "unusedparm.h" #include "masscan-app.h" #include "proto-interactive.h" #include "proto-ssl.h" #include <ctype.h> #include <string.h> /*************************************************************************** ***************************************************************************/ static void ftp_parse( const struct Banner1 *banner1, void *banner1_private, struct ProtocolState *pstate, const unsigned char *px, size_t length, struct BannerOutput *banout, struct InteractiveData *more) { unsigned state = pstate->state; unsigned i; struct FTPSTUFF *ftp = &pstate->sub.ftp; UNUSEDPARM(banner1_private); UNUSEDPARM(banner1); for (i=0; i<length; i++) { switch (state) { case 0: case 100: ftp->code = 0; state++; /* fall through */ case 1: case 2: case 3: case 101: case 102: case 103: if (!isdigit(px[i]&0xFF)) { state = STATE_DONE; } else { ftp->code *= 10; ftp->code += (px[i] - '0'); state++; banout_append_char(banout, PROTO_FTP, px[i]); } break; case 4: case 104: if (px[i] == ' ') { ftp->is_last = 1; state++; banout_append_char(banout, PROTO_FTP, px[i]); } else if (px[i] == '-') { ftp->is_last = 0; state++; banout_append_char(banout, PROTO_FTP, px[i]); } else { state = STATE_DONE; } break; case 5: if (px[i] == '\r') continue; else if (px[i] == '\n') { if (ftp->is_last) { more->payload = "AUTH TLS\r\n"; more->length = 10; state = 100; banout_append_char(banout, PROTO_FTP, px[i]); } else { banout_append_char(banout, PROTO_FTP, px[i]); state = 0; } } else if (px[i] == '\0' || !isprint(px[i])) { state = STATE_DONE; continue; } else { banout_append_char(banout, PROTO_FTP, px[i]); } break; case 105: if (px[i] == '\r') continue; else if (px[i] == '\n') { if (ftp->code == 234) { /* change the state here to SSL */ unsigned port = pstate->port; memset(pstate, 0, sizeof(*pstate)); pstate->app_proto = PROTO_SSL3; pstate->is_sent_sslhello = 1; pstate->port = port; state = 0; more->payload = banner_ssl.hello; more->length = banner_ssl.hello_length; } else { state = STATE_DONE; } } else if (px[i] == '\0' || !isprint(px[i])) { state = STATE_DONE; continue; } else { banout_append_char(banout, PROTO_FTP, px[i]); } break; default: i = (unsigned)length; break; } } pstate->state = state; } /*************************************************************************** ***************************************************************************/ static void * ftp_init(struct Banner1 *banner1) { UNUSEDPARM(banner1); return 0; } /*************************************************************************** ***************************************************************************/ static int ftp_selftest(void) { return 0; } /*************************************************************************** ***************************************************************************/ const struct ProtocolParserStream banner_ftp = { "ftp", 21, 0, 0, 0, ftp_selftest, ftp_init, ftp_parse, };