Skip to content

Commit dfb1472

Browse files
committed
pop3: add credentials to tap.
Change-Id: I0779a4c11451ee63be8d10ee78a7f920f519f77a Reviewed-on: https://code.wireshark.org/review/33799 Reviewed-by: Pascal Quantin <[email protected]> Petri-Dish: Pascal Quantin <[email protected]> Tested-by: Petri Dish Buildbot Reviewed-by: Dario Lombardo <[email protected]>
1 parent aec8480 commit dfb1472

File tree

1 file changed

+74
-33
lines changed

1 file changed

+74
-33
lines changed

epan/dissectors/packet-pop.c

Lines changed: 74 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
#include <wsutil/str_util.h>
2828
#include <wsutil/strtoi.h>
2929

30+
#include <ui/tap-credentials.h>
31+
#include <tap.h>
32+
3033
#include "packet-tls.h"
3134
#include "packet-tls-utils.h"
3235

@@ -35,6 +38,8 @@ void proto_reg_handoff_pop(void);
3538

3639
static int proto_pop = -1;
3740

41+
static int credentials_tap = -1;
42+
3843
static int hf_pop_response = -1;
3944
static int hf_pop_response_indicator = -1;
4045
static int hf_pop_response_description = -1;
@@ -109,9 +114,15 @@ struct pop_data_val {
109114
guint32 msg_read_len; /* Length of RETR message read so far */
110115
guint32 msg_tot_len; /* Total length of RETR message */
111116
gboolean stls_request; /* Received STLS request */
117+
gchar* username;
118+
guint username_num;
112119
};
113120

114-
121+
typedef enum {
122+
pop_arg_type_unknown,
123+
pop_arg_type_username,
124+
pop_arg_type_password
125+
} pop_arg_type_t;
115126

116127
static gboolean response_is_continuation(const guchar *data);
117128

@@ -134,6 +145,7 @@ dissect_pop(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
134145
conversation_t *conversation = NULL;
135146
struct pop_data_val *data_val = NULL;
136147
gint length_remaining;
148+
pop_arg_type_t pop_arg_type = pop_arg_type_unknown;
137149

138150
col_set_str(pinfo->cinfo, COL_PROTOCOL, "POP");
139151

@@ -276,6 +288,14 @@ dissect_pop(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
276288
if (g_ascii_strncasecmp(line, "STLS", 4) == 0) {
277289
data_val->stls_request = TRUE;
278290
}
291+
292+
if (g_ascii_strncasecmp(line, "USER", 4) == 0) {
293+
pop_arg_type = pop_arg_type_username;
294+
}
295+
296+
if (g_ascii_strncasecmp(line, "PASS", 4) == 0) {
297+
pop_arg_type = pop_arg_type_password;
298+
}
279299
} else {
280300
if (data_val->msg_request) {
281301
/* this is a response to a RETR or TOP command */
@@ -305,43 +325,62 @@ dissect_pop(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
305325
}
306326

307327

308-
if (tree) {
309-
/*
310-
* Add the rest of the first line as request or
311-
* reply param/description.
312-
*/
313-
if (linelen != 0) {
314-
proto_tree_add_item(reqresp_tree,
315-
(is_request) ?
316-
hf_pop_request_parameter :
317-
hf_pop_response_description,
318-
tvb, offset, linelen, ENC_ASCII|ENC_NA);
328+
/*
329+
* Add the rest of the first line as request or
330+
* reply param/description.
331+
*/
332+
if (linelen != 0) {
333+
tap_credential_t* auth;
334+
proto_tree_add_item(reqresp_tree,
335+
(is_request) ?
336+
hf_pop_request_parameter :
337+
hf_pop_response_description,
338+
tvb, offset, linelen, ENC_ASCII|ENC_NA);
339+
switch (pop_arg_type) {
340+
case pop_arg_type_username:
341+
if (!data_val->username && linelen > 0) {
342+
data_val->username = tvb_get_string_enc(wmem_file_scope(), tvb, offset, linelen, ENC_NA|ENC_ASCII);;
343+
data_val->username_num = pinfo->num;
344+
}
345+
break;
346+
case pop_arg_type_password:
347+
auth = wmem_new0(wmem_packet_scope(), tap_credential_t);
348+
auth->num = pinfo->num;
349+
auth->username_num = data_val->username_num;
350+
auth->password_hf_id = hf_pop_request_parameter;
351+
auth->username = data_val->username;
352+
auth->proto = "POP3";
353+
auth->info = wmem_strdup_printf(wmem_packet_scope(), "Username in packet %u", data_val->username_num);
354+
tap_queue_packet(credentials_tap, pinfo, auth);
355+
break;
356+
default:
357+
break;
319358
}
320-
offset = next_offset;
359+
}
360+
offset = next_offset;
321361

362+
/*
363+
* Show the rest of the request or response as text,
364+
* a line at a time.
365+
*/
366+
while (tvb_offset_exists(tvb, offset)) {
322367
/*
323-
* Show the rest of the request or response as text,
324-
* a line at a time.
368+
* Find the end of the line.
325369
*/
326-
while (tvb_offset_exists(tvb, offset)) {
327-
/*
328-
* Find the end of the line.
329-
*/
330-
tvb_find_line_end(tvb, offset, -1, &next_offset, FALSE);
370+
tvb_find_line_end(tvb, offset, -1, &next_offset, FALSE);
331371

332-
/*
333-
* Put this line.
334-
*/
335-
proto_tree_add_string_format(pop_tree,
336-
(is_request) ?
337-
hf_pop_request_data :
338-
hf_pop_response_data,
339-
tvb, offset,
340-
next_offset - offset,
341-
"", "%s",
342-
tvb_format_text(tvb, offset, next_offset - offset));
343-
offset = next_offset;
344-
}
372+
/*
373+
* Put this line.
374+
*/
375+
proto_tree_add_string_format(pop_tree,
376+
(is_request) ?
377+
hf_pop_request_data :
378+
hf_pop_response_data,
379+
tvb, offset,
380+
next_offset - offset,
381+
"", "%s",
382+
tvb_format_text(tvb, offset, next_offset - offset));
383+
offset = next_offset;
345384
}
346385
return tvb_captured_length(tvb);
347386
}
@@ -456,6 +495,8 @@ proto_register_pop(void)
456495

457496
expert_pop = expert_register_protocol(proto_pop);
458497
expert_register_field_array(expert_pop, ei, array_length(ei));
498+
499+
credentials_tap = register_tap("credentials");
459500
}
460501

461502
void

0 commit comments

Comments
 (0)