Loading src/proto-banner1.c +10 −1 Changes for src/proto-banner1.c: 10 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -11,6 +11,7 @@ #include "proto-ssh.h" #include "proto-ftp.h" #include "proto-smtp.h" #include "proto-pop3.h" #include "proto-vnc.h" #include "masscan-app.h" #include <ctype.h> Loading Loading @@ -146,9 +147,17 @@ banner1_parse( more); break; case PROTO_POP3: banner_pop3.parse( banner1, banner1->http_fields, tcb_state, px, length, banout, more); break; case PROTO_SSH1: case PROTO_SSH2: case PROTO_POP3: case PROTO_IMAP4: /* generic text-based parser * TODO: in future, need to split these into separate protocols, 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 @@ -104,6 +104,11 @@ struct SMTPSTUFF { unsigned is_last:1; }; struct POP3STUFF { unsigned code; unsigned is_last:1; }; struct ProtocolState { unsigned state; unsigned remaining; Loading @@ -118,6 +123,7 @@ struct ProtocolState { struct VNCSTUFF vnc; struct FTPSTUFF ftp; struct SMTPSTUFF smtp; struct POP3STUFF pop3; } sub; }; Loading src/proto-interactive.c +8 Changes for src/proto-interactive.c: 8 added lines, 0 removed lines. Original line number Diff line number Diff line #include "proto-interactive.h" void tcp_transmit(struct InteractiveData *more, const void *payload, size_t length) { more->payload = payload; more->length = length; } src/proto-interactive.h +4 Changes for src/proto-interactive.h: 4 added lines, 0 removed lines. Original line number Diff line number Diff line #ifndef PROTO_INTERACTIVE_H #define PROTO_INTERACTIVE_H #include <stdio.h> struct InteractiveData { const void *payload; unsigned length; }; void tcp_transmit(struct InteractiveData *more, const void *data, size_t length); #endif src/proto-pop3.c +171 Changes for src/proto-pop3.c: 171 added lines, 0 removed lines. Original line number Diff line number Diff line /* POP3 banner checker */ #include "proto-pop3.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 pop3_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; UNUSEDPARM(banner1_private); UNUSEDPARM(banner1); for (i=0; i<length; i++) { if (px[i] == '\r') continue; switch (state) { case 0: case 1: case 2: banout_append_char(banout, PROTO_POP3, px[i]); if ("+OK"[state] != px[i]) state = STATE_DONE; else state++; break; case 3: banout_append_char(banout, PROTO_POP3, px[i]); if (px[i] == '\n') { tcp_transmit(more, "CAPA\r\n", 6); state++; } break; case 4: case 204: banout_append_char(banout, PROTO_POP3, px[i]); if (px[i] == '-') state = 100; else if (px[i] == '+') state++; else { state = STATE_DONE; } break; case 5: case 205: banout_append_char(banout, PROTO_POP3, px[i]); if (px[i] == 'O') state++; else state = STATE_DONE; break; case 6: case 206: banout_append_char(banout, PROTO_POP3, px[i]); if (px[i] == 'K') state += 2; /* oops, I had too many states here */ else state = STATE_DONE; break; case 8: if (px[i] == '\r') continue; banout_append_char(banout, PROTO_POP3, px[i]); if (px[i] == '\n') state++; break; case 9: if (px[i] == '\r') continue; banout_append_char(banout, PROTO_POP3, px[i]); if (px[i] == '.') state++; else if (px[i] == '\n') continue; else state--; break; case 10: if (px[i] == '\r') continue; banout_append_char(banout, PROTO_POP3, px[i]); if (px[i] == '\n') { tcp_transmit(more, "STLS\r\n", 6); state = 204; } else { state = 8; } break; case 208: if (px[i] == '\r') continue; banout_append_char(banout, PROTO_POP3, px[i]); if (px[i] == '\n') { /* 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; break; } break; case 100: if (px[i] == '\r') continue; banout_append_char(banout, PROTO_POP3, px[i]); if (px[i] == '\n') state = STATE_DONE; break; default: i = (unsigned)length; break; } } pstate->state = state; } /*************************************************************************** ***************************************************************************/ static void * pop3_init(struct Banner1 *banner1) { UNUSEDPARM(banner1); return 0; } /*************************************************************************** ***************************************************************************/ static int pop3_selftest(void) { return 0; } /*************************************************************************** ***************************************************************************/ const struct ProtocolParserStream banner_pop3 = { "pop3", 21, 0, 0, 0, pop3_selftest, pop3_init, pop3_parse, }; Loading
src/proto-banner1.c +10 −1 Changes for src/proto-banner1.c: 10 added lines, 1 removed line. Original line number Diff line number Diff line Loading @@ -11,6 +11,7 @@ #include "proto-ssh.h" #include "proto-ftp.h" #include "proto-smtp.h" #include "proto-pop3.h" #include "proto-vnc.h" #include "masscan-app.h" #include <ctype.h> Loading Loading @@ -146,9 +147,17 @@ banner1_parse( more); break; case PROTO_POP3: banner_pop3.parse( banner1, banner1->http_fields, tcb_state, px, length, banout, more); break; case PROTO_SSH1: case PROTO_SSH2: case PROTO_POP3: case PROTO_IMAP4: /* generic text-based parser * TODO: in future, need to split these into separate protocols, 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 @@ -104,6 +104,11 @@ struct SMTPSTUFF { unsigned is_last:1; }; struct POP3STUFF { unsigned code; unsigned is_last:1; }; struct ProtocolState { unsigned state; unsigned remaining; Loading @@ -118,6 +123,7 @@ struct ProtocolState { struct VNCSTUFF vnc; struct FTPSTUFF ftp; struct SMTPSTUFF smtp; struct POP3STUFF pop3; } sub; }; Loading
src/proto-interactive.c +8 Changes for src/proto-interactive.c: 8 added lines, 0 removed lines. Original line number Diff line number Diff line #include "proto-interactive.h" void tcp_transmit(struct InteractiveData *more, const void *payload, size_t length) { more->payload = payload; more->length = length; }
src/proto-interactive.h +4 Changes for src/proto-interactive.h: 4 added lines, 0 removed lines. Original line number Diff line number Diff line #ifndef PROTO_INTERACTIVE_H #define PROTO_INTERACTIVE_H #include <stdio.h> struct InteractiveData { const void *payload; unsigned length; }; void tcp_transmit(struct InteractiveData *more, const void *data, size_t length); #endif
src/proto-pop3.c +171 Changes for src/proto-pop3.c: 171 added lines, 0 removed lines. Original line number Diff line number Diff line /* POP3 banner checker */ #include "proto-pop3.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 pop3_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; UNUSEDPARM(banner1_private); UNUSEDPARM(banner1); for (i=0; i<length; i++) { if (px[i] == '\r') continue; switch (state) { case 0: case 1: case 2: banout_append_char(banout, PROTO_POP3, px[i]); if ("+OK"[state] != px[i]) state = STATE_DONE; else state++; break; case 3: banout_append_char(banout, PROTO_POP3, px[i]); if (px[i] == '\n') { tcp_transmit(more, "CAPA\r\n", 6); state++; } break; case 4: case 204: banout_append_char(banout, PROTO_POP3, px[i]); if (px[i] == '-') state = 100; else if (px[i] == '+') state++; else { state = STATE_DONE; } break; case 5: case 205: banout_append_char(banout, PROTO_POP3, px[i]); if (px[i] == 'O') state++; else state = STATE_DONE; break; case 6: case 206: banout_append_char(banout, PROTO_POP3, px[i]); if (px[i] == 'K') state += 2; /* oops, I had too many states here */ else state = STATE_DONE; break; case 8: if (px[i] == '\r') continue; banout_append_char(banout, PROTO_POP3, px[i]); if (px[i] == '\n') state++; break; case 9: if (px[i] == '\r') continue; banout_append_char(banout, PROTO_POP3, px[i]); if (px[i] == '.') state++; else if (px[i] == '\n') continue; else state--; break; case 10: if (px[i] == '\r') continue; banout_append_char(banout, PROTO_POP3, px[i]); if (px[i] == '\n') { tcp_transmit(more, "STLS\r\n", 6); state = 204; } else { state = 8; } break; case 208: if (px[i] == '\r') continue; banout_append_char(banout, PROTO_POP3, px[i]); if (px[i] == '\n') { /* 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; break; } break; case 100: if (px[i] == '\r') continue; banout_append_char(banout, PROTO_POP3, px[i]); if (px[i] == '\n') state = STATE_DONE; break; default: i = (unsigned)length; break; } } pstate->state = state; } /*************************************************************************** ***************************************************************************/ static void * pop3_init(struct Banner1 *banner1) { UNUSEDPARM(banner1); return 0; } /*************************************************************************** ***************************************************************************/ static int pop3_selftest(void) { return 0; } /*************************************************************************** ***************************************************************************/ const struct ProtocolParserStream banner_pop3 = { "pop3", 21, 0, 0, 0, pop3_selftest, pop3_init, pop3_parse, };