forked from robertdavidgraham/masscan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproto-pop3.c
171 lines (153 loc) · 5 KB
/
proto-pop3.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
/*
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 = (unsigned short)port;
state = 0;
more->payload = banner_ssl.hello;
more->length = (unsigned)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,
};