Coverage Report

Created: 2026-09-28 06:52

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wireshark/epan/dissectors/packet-smtp.c
Line
Count
Source
1
/* packet-smtp.c
2
 * Routines for SMTP packet disassembly
3
 *
4
 * Copyright (c) 2000 by Richard Sharpe <rsharpe@ns.aus.com>
5
 *
6
 * Added RFC 4954 SMTP Authentication
7
 *     Michael Mann * Copyright 2012
8
 * Added RFC 2920 Pipelining and RFC 3030 BDAT Pipelining
9
 *     John Thacker <johnthacker@gmail.com>
10
 *
11
 * Wireshark - Network traffic analyzer
12
 * By Gerald Combs <gerald@wireshark.org>
13
 * Copyright 1999 Gerald Combs
14
 *
15
 * SPDX-License-Identifier: GPL-2.0-or-later
16
 */
17
18
#include "config.h"
19
20
#include <stdlib.h>
21
22
#include <epan/packet.h>
23
#include <epan/conversation.h>
24
#include <epan/prefs.h>
25
#include <epan/strutil.h>
26
#include <epan/reassemble.h>
27
#include <epan/proto_data.h>
28
#include <epan/credentials.h>
29
30
#include <tap.h>
31
32
#include <wsutil/str_util.h>
33
#include "packet-tls.h"
34
#include "packet-tls-utils.h"
35
36
/* RFC 2821 */
37
16
#define TCP_PORT_SMTP      "25"
38
16
#define TCP_PORT_SSL_SMTP 465
39
40
/* RFC 4409 */
41
16
#define TCP_PORT_SUBMISSION 587
42
43
void proto_register_smtp(void);
44
void proto_reg_handoff_smtp(void);
45
46
static int proto_smtp;
47
48
static int credentials_tap;
49
50
static int hf_smtp_req;
51
static int hf_smtp_rsp;
52
static int hf_smtp_message;
53
static int hf_smtp_command_line;
54
static int hf_smtp_req_command;
55
static int hf_smtp_req_parameter;
56
static int hf_smtp_response;
57
static int hf_smtp_rsp_code;
58
static int hf_smtp_rsp_parameter;
59
static int hf_smtp_username;
60
static int hf_smtp_password;
61
static int hf_smtp_username_password;
62
static int hf_smtp_eom;
63
64
static int hf_smtp_data_fragments;
65
static int hf_smtp_data_fragment;
66
static int hf_smtp_data_fragment_overlap;
67
static int hf_smtp_data_fragment_overlap_conflicts;
68
static int hf_smtp_data_fragment_multiple_tails;
69
static int hf_smtp_data_fragment_too_long_fragment;
70
static int hf_smtp_data_fragment_error;
71
static int hf_smtp_data_fragment_count;
72
static int hf_smtp_data_reassembled_in;
73
static int hf_smtp_data_reassembled_length;
74
75
static int ett_smtp;
76
static int ett_smtp_cmdresp;
77
78
static int ett_smtp_data_fragment;
79
static int ett_smtp_data_fragments;
80
81
static expert_field ei_smtp_base64_decode;
82
static expert_field ei_smtp_rsp_code;
83
84
static bool    smtp_auth_parameter_decoding_enabled;
85
/* desegmentation of SMTP command and response lines */
86
static bool    smtp_desegment              = true;
87
static bool    smtp_data_desegment         = true;
88
89
static reassembly_table smtp_data_reassembly_table;
90
91
static const fragment_items smtp_data_frag_items = {
92
  /* Fragment subtrees */
93
  &ett_smtp_data_fragment,
94
  &ett_smtp_data_fragments,
95
  /* Fragment fields */
96
  &hf_smtp_data_fragments,
97
  &hf_smtp_data_fragment,
98
  &hf_smtp_data_fragment_overlap,
99
  &hf_smtp_data_fragment_overlap_conflicts,
100
  &hf_smtp_data_fragment_multiple_tails,
101
  &hf_smtp_data_fragment_too_long_fragment,
102
  &hf_smtp_data_fragment_error,
103
  &hf_smtp_data_fragment_count,
104
  /* Reassembled in field */
105
  &hf_smtp_data_reassembled_in,
106
  /* Reassembled length field */
107
  &hf_smtp_data_reassembled_length,
108
  /* Reassembled data field */
109
  NULL,
110
  /* Tag */
111
  "DATA fragments"
112
};
113
114
static  dissector_handle_t smtp_handle;
115
static  dissector_handle_t tls_handle;
116
static  dissector_handle_t imf_handle;
117
static  dissector_handle_t ntlmssp_handle;
118
static  dissector_handle_t data_text_lines_handle;
119
120
/*
121
 * A CMD is an SMTP command, MESSAGE is the message portion, and EOM is the
122
 * last part of a message
123
 */
124
1.77k
#define SMTP_PDU_CMD     0
125
1.90k
#define SMTP_PDU_MESSAGE 1
126
0
#define SMTP_PDU_EOM     2
127
128
struct smtp_proto_data {
129
  uint16_t pdu_type;
130
  uint16_t conversation_id;
131
  bool more_frags;
132
  unsigned end_offset;
133
  struct smtp_proto_data *next;
134
};
135
136
/*
137
 * State information stored with a conversation.
138
 */
139
typedef enum {
140
  SMTP_STATE_START,                     /* Start of SMTP conversion */
141
  SMTP_STATE_READING_CMDS,              /* reading commands */
142
  SMTP_STATE_READING_DATA,              /* reading message data */
143
  SMTP_STATE_AWAITING_STARTTLS_RESPONSE /* sent STARTTLS, awaiting response */
144
} smtp_state_t;
145
146
typedef enum {
147
  SMTP_AUTH_STATE_NONE,               /*  No authentication seen or used */
148
  SMTP_AUTH_STATE_START,              /* Authentication started, waiting for username */
149
  SMTP_AUTH_STATE_USERNAME_REQ,       /* Received username request from server */
150
  SMTP_AUTH_STATE_USERNAME_RSP,       /* Received username response from client */
151
  SMTP_AUTH_STATE_PASSWORD_REQ,       /* Received password request from server */
152
  SMTP_AUTH_STATE_PASSWORD_RSP,       /* Received password request from server */
153
  SMTP_AUTH_STATE_PLAIN_START_REQ,    /* Received AUTH PLAIN command from client*/
154
  SMTP_AUTH_STATE_PLAIN_CRED_REQ,     /* Received AUTH PLAIN command including creds from client*/
155
  SMTP_AUTH_STATE_PLAIN_REQ,          /* Received AUTH PLAIN request from server */
156
  SMTP_AUTH_STATE_PLAIN_RSP,          /* Received AUTH PLAIN response from client */
157
  SMTP_AUTH_STATE_NTLM_REQ,           /* Received ntlm negotiate request from client */
158
  SMTP_AUTH_STATE_NTLM_CHALLANGE,     /* Received ntlm challenge request from server */
159
  SMTP_AUTH_STATE_NTLM_RSP,           /* Received ntlm auth request from client */
160
  SMTP_AUTH_STATE_SUCCESS,            /* Password received, authentication successful, start decoding */
161
  SMTP_AUTH_STATE_FAILED              /* authentication failed, no decoding */
162
} smtp_auth_state_t;
163
164
typedef enum {
165
  SMTP_MULTILINE_NONE,
166
  SMTP_MULTILINE_START,
167
  SMTP_MULTILINE_CONTINUE,
168
  SMTP_MULTILINE_END
169
170
} smtp_multiline_state_t;
171
172
struct smtp_session_state {
173
  smtp_state_t smtp_state;      /* Current state */
174
  smtp_auth_state_t auth_state; /* Current authentication state */
175
  /* Values that need to be saved because state machine can't be used during tree dissection */
176
  uint32_t first_auth_frame;    /* First frame involving authentication. */
177
  uint32_t username_frame;      /* Frame containing client username */
178
  uint32_t password_frame;      /* Frame containing client password */
179
  uint32_t last_auth_frame;     /* Last frame involving authentication. */
180
  char*    username;            /* The username in the authentication. */
181
  bool crlf_seen;           /* Have we seen a CRLF on the end of a packet */
182
  bool data_seen;           /* Have we seen a DATA command yet */
183
  uint32_t msg_read_len;        /* Length of BDAT message read so far */
184
  uint32_t msg_tot_len;         /* Total length of BDAT message */
185
  bool msg_last;            /* Is this the last BDAT chunk */
186
  uint32_t username_cmd_frame;  /* AUTH command contains username */
187
  uint32_t user_pass_cmd_frame; /* AUTH command contains username and password */
188
  uint32_t user_pass_frame;     /* Frame contains username and password */
189
  uint32_t ntlm_req_frame;      /* Frame containing NTLM request */
190
  uint32_t ntlm_cha_frame;      /* Frame containing NTLM challenge. */
191
  uint32_t ntlm_rsp_frame;      /* Frame containing NTLM response. */
192
};
193
194
/*
195
 * See
196
 *
197
 *      http://support.microsoft.com/default.aspx?scid=kb;[LN];812455
198
 *
199
 * for the Exchange extensions.
200
 */
201
static const struct {
202
  const char *command;
203
  int len;
204
} commands[] = {
205
  { "STARTTLS", 8 },            /* RFC 2487 */
206
  { "X-EXPS", 6 },              /* Microsoft Exchange */
207
  { "X-LINK2STATE", 12 },       /* Microsoft Exchange */
208
  { "XEXCH50", 7 }              /* Microsoft Exchange */
209
};
210
211
8.55k
#define NCOMMANDS       array_length(commands)
212
213
/* The following were copied from RFC 2821 */
214
static const value_string response_codes_vs[] = {
215
  { 211, "System status, or system help reply" },
216
  { 214, "Help message" },
217
  { 220, "<domain> Service ready" },
218
  { 221, "<domain> Service closing transmission channel" },
219
  { 235, "Authentication successful" },
220
  { 250, "Requested mail action okay, completed" },
221
  { 251, "User not local; will forward to <forward-path>" },
222
  { 252, "Cannot VRFY user, but will accept message and attempt delivery" },
223
  { 334, "AUTH input" },
224
  { 354, "Start mail input; end with <CRLF>.<CRLF>" },
225
  { 421, "<domain> Service not available, closing transmission channel" },
226
  { 432, "A password transition is needed" },
227
  { 450, "Requested mail action not taken: mailbox unavailable" },
228
  { 451, "Requested action aborted: local error in processing" },
229
  { 452, "Requested action not taken: insufficient system storage" },
230
  { 454, "Temporary authentication failed" },
231
  { 500, "Syntax error, command unrecognized" },
232
  { 501, "Syntax error in parameters or arguments" },
233
  { 502, "Command not implemented" },
234
  { 503, "Bad sequence of commands" },
235
  { 504, "Command parameter not implemented" },
236
  { 530, "Authentication required" },
237
  { 534, "Authentication mechanism is too weak" },
238
  { 535, "Authentication credentials invalid" },
239
  { 538, "Encryption required for requested authentication mechanism" },
240
  { 550, "Requested action not taken: mailbox unavailable" },
241
  { 551, "User not local; please try <forward-path>" },
242
  { 552, "Requested mail action aborted: exceeded storage allocation" },
243
  { 553, "Requested action not taken: mailbox name not allowed" },
244
  { 554, "Transaction failed" },
245
  { 0, NULL }
246
};
247
static value_string_ext response_codes_vs_ext = VALUE_STRING_EXT_INIT(response_codes_vs);
248
249
static struct smtp_proto_data*
250
append_pdu(struct smtp_proto_data *spd_frame_data)
251
0
{
252
0
  DISSECTOR_ASSERT(spd_frame_data && spd_frame_data->next == NULL);
253
0
  struct smtp_proto_data *new_pdu = wmem_new0(wmem_file_scope(), struct smtp_proto_data);
254
0
  new_pdu->conversation_id = spd_frame_data->conversation_id;
255
0
  new_pdu->more_frags = true;
256
0
  spd_frame_data->next = new_pdu;
257
258
0
  return new_pdu;
259
0
}
260
261
static bool
262
line_is_smtp_command(const char *command, int commandlen)
263
1.74k
{
264
1.74k
  size_t i;
265
266
  /*
267
   * To quote RFC 821, "Command codes are four alphabetic
268
   * characters".
269
   *
270
   * However, there are some SMTP extensions that involve commands
271
   * longer than 4 characters and/or that contain non-alphabetic
272
   * characters; we treat them specially.
273
   *
274
   * XXX - should we just have a table of known commands?  Or would
275
   * that fail to catch some extensions we don't know about?
276
   */
277
1.74k
  if (commandlen == 4 && g_ascii_isalpha(command[0]) &&
278
1.74k
      g_ascii_isalpha(command[1]) && g_ascii_isalpha(command[2]) &&
279
1.74k
      g_ascii_isalpha(command[3])) {
280
    /* standard 4-alphabetic command */
281
38
    return true;
282
38
  }
283
284
  /*
285
   * Check the list of non-4-alphabetic commands.
286
   */
287
8.55k
  for (i = 0; i < NCOMMANDS; i++) {
288
6.84k
    if (commandlen == commands[i].len &&
289
103
        g_ascii_strncasecmp(command, commands[i].command, commands[i].len) == 0)
290
0
      return true;
291
6.84k
  }
292
1.71k
  return false;
293
1.71k
}
294
295
static void
296
dissect_smtp_data(tvbuff_t *tvb, unsigned offset, proto_tree *smtp_tree)
297
0
{
298
0
  unsigned next_offset;
299
300
0
  if (smtp_tree) {
301
0
    while (tvb_offset_exists(tvb, offset)) {
302
      /*
303
       * Find the end of the line.
304
       */
305
0
      tvb_find_line_end_remaining(tvb, offset, NULL, &next_offset);
306
307
      /*
308
       * Put this line.
309
       */
310
0
      proto_tree_add_item(smtp_tree, hf_smtp_message, tvb,
311
0
                          offset, next_offset - offset, ENC_ASCII);
312
313
      /*
314
       * Step to the next line.
315
       */
316
0
      offset = next_offset;
317
0
    }
318
0
  }
319
0
}
320
321
static void
322
dissect_ntlm_auth(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
323
                  const char *line)
324
0
{
325
0
    tvbuff_t *ntlm_tvb;
326
327
0
    ntlm_tvb = base64_to_tvb(tvb, line);
328
0
    if(tvb_strneql(ntlm_tvb, 0, "NTLMSSP", 7) == 0) {
329
0
      add_new_data_source(pinfo, ntlm_tvb, "NTLMSSP Data");
330
0
      call_dissector(ntlmssp_handle, ntlm_tvb, pinfo, tree);
331
0
    }
332
0
}
333
334
static void
335
decode_plain_auth(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
336
                  int a_offset, int a_linelen)
337
0
{
338
0
  int                        returncode;
339
0
  int                        length_user1;
340
0
  int                        length_user2;
341
0
  int                        length_pass;
342
0
  char                      *decrypt   = NULL;
343
0
  proto_item                *ti;
344
0
  size_t                     len = 0;
345
346
0
  decrypt = (char*)tvb_get_string_enc(pinfo->pool, tvb, a_offset, a_linelen, ENC_ASCII);
347
0
  if (smtp_auth_parameter_decoding_enabled) {
348
0
    if (strlen(decrypt) > 1) {
349
0
      g_base64_decode_inplace(decrypt, &len);
350
0
      decrypt[len] = 0;
351
0
    }
352
0
    returncode = (int)len;
353
0
    if (returncode) {
354
0
      char* username;
355
0
      length_user1 = (int)strlen(decrypt);
356
0
      if (returncode >= (length_user1 + 1)) {
357
0
        length_user2 = (int)strlen(decrypt + length_user1 + 1);
358
0
        proto_tree_add_string(tree, hf_smtp_username, tvb,
359
0
                              a_offset, a_linelen, decrypt + length_user1 + 1);
360
0
        username = format_text(pinfo->pool, decrypt + length_user1 + 1, length_user2);
361
0
        col_append_fstr(pinfo->cinfo, COL_INFO, "User: %s", username);
362
363
0
        if (returncode >= (length_user1 + 1 + length_user2 + 1)) {
364
0
          length_pass = (int)strlen(decrypt + length_user1 + length_user2 + 2);
365
0
          proto_tree_add_string(tree, hf_smtp_password, tvb,
366
0
                                a_offset, length_pass, decrypt + length_user1 + length_user2 + 2);
367
0
          col_append_str(pinfo->cinfo, COL_INFO, " ");
368
0
          col_append_fstr(pinfo->cinfo, COL_INFO, " Pass: %s",
369
0
                          format_text(pinfo->pool, decrypt + length_user1 + length_user2 + 2, length_pass));
370
371
0
          tap_credential_t* auth = wmem_new0(pinfo->pool, tap_credential_t);
372
0
          auth->num = pinfo->num;
373
0
          auth->username_num = pinfo->num;
374
0
          auth->password_hf_id = hf_smtp_password;
375
0
          auth->username = username;
376
0
          auth->proto = "SMTP";
377
0
          tap_queue_packet(credentials_tap, pinfo, auth);
378
0
        }
379
0
      }
380
0
    }
381
0
  }
382
0
  else {
383
0
    ti = proto_tree_add_item(tree, hf_smtp_username_password, tvb,
384
0
                          a_offset, a_linelen, ENC_ASCII);
385
0
    expert_add_info(pinfo, ti, &ei_smtp_base64_decode);
386
0
    col_append_str(pinfo->cinfo, COL_INFO, format_text(pinfo->pool, decrypt, a_linelen));
387
0
  }
388
0
}
389
390
static int
391
dissect_smtp_request(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, proto_tree *smtp_tree, struct smtp_session_state *session_state, struct smtp_proto_data *spd_frame_data, bool first_pdu)
392
72
{
393
72
  proto_item                *ti, *hidden_item;
394
72
  proto_tree                *cmdresp_tree = NULL;
395
72
  unsigned                   offset = 0;
396
72
  unsigned                   next_offset;
397
72
  unsigned                   linelen   = 0;
398
72
  int                        length_remaining;
399
72
  int                        cmdlen;
400
72
  fragment_head             *frag_msg  = NULL;
401
72
  tvbuff_t                  *next_tvb;
402
72
  char                      *decrypt   = NULL;
403
72
  size_t                     decrypt_len  = 0;
404
72
  char                      *base64_string   = NULL;
405
406
72
  switch (spd_frame_data->pdu_type) {
407
408
51
  case SMTP_PDU_MESSAGE:
409
    /* Column Info */
410
51
    length_remaining = tvb_reported_length_remaining(tvb, offset);
411
51
    if (first_pdu)
412
51
        col_append_str(pinfo->cinfo, COL_INFO, "C: ");
413
0
    else
414
0
        col_append_str(pinfo->cinfo, COL_INFO, " | ");
415
51
    col_append_str(pinfo->cinfo, COL_INFO, smtp_data_desegment ? "DATA fragment" : "Message Body");
416
51
    col_append_fstr(pinfo->cinfo, COL_INFO, ", %d byte%s", length_remaining,
417
51
                      plurality (length_remaining, "", "s"));
418
419
51
    if (smtp_data_desegment) {
420
51
      frag_msg = fragment_add_seq_next(&smtp_data_reassembly_table, tvb, 0,
421
51
                                       pinfo, spd_frame_data->conversation_id, NULL,
422
51
                                       tvb_reported_length(tvb),
423
51
                                       spd_frame_data->more_frags);
424
51
      if (spd_frame_data->more_frags) {
425
        /* Show the text lines within this PDU fragment
426
         * Calling this on the last fragment would interfere with
427
         * process reassembled data below, by changing the layer number.
428
         * (We'll display the data anyway as part of the reassembly.)
429
         */
430
51
        call_dissector(data_text_lines_handle, tvb, pinfo, smtp_tree);
431
51
      }
432
51
    } else {
433
      /*
434
       * Message body.
435
       * Put its lines into the protocol tree, a line at a time.
436
       */
437
0
      dissect_smtp_data(tvb, offset, smtp_tree);
438
0
    }
439
51
    break;
440
441
0
  case SMTP_PDU_EOM:
442
    /*
443
     * End-of-message-body indicator.
444
     */
445
0
    if (first_pdu)
446
0
        col_append_str(pinfo->cinfo, COL_INFO, "C: ");
447
0
    else
448
0
        col_append_str(pinfo->cinfo, COL_INFO, " | ");
449
0
    col_append_str(pinfo->cinfo, COL_INFO, ".");
450
451
0
    proto_tree_add_none_format(smtp_tree, hf_smtp_eom, tvb, offset, 3, "C: .");
452
453
0
    break;
454
455
21
  case SMTP_PDU_CMD:
456
    /*
457
     * Command.
458
     */
459
460
432
    while (tvb_offset_exists(tvb, offset)) {
461
      /*
462
       * Find the end of the line.
463
       */
464
411
      tvb_find_line_end_remaining(tvb, offset, &linelen, &next_offset);
465
466
      /* Column Info */
467
411
      if (first_pdu && offset == 0)
468
21
          col_append_str(pinfo->cinfo, COL_INFO, "C: ");
469
390
      else
470
390
          col_append_str(pinfo->cinfo, COL_INFO, " | ");
471
472
411
      hidden_item = proto_tree_add_boolean(smtp_tree, hf_smtp_req, tvb,
473
411
                                           0, 0, true);
474
411
      proto_item_set_hidden(hidden_item);
475
476
411
      if (session_state->username_frame == pinfo->num) {
477
0
        if (decrypt == NULL) {
478
          /* This line wasn't already decrypted through the state machine */
479
0
          decrypt = (char*)tvb_get_string_enc(pinfo->pool, tvb, offset, linelen, ENC_ASCII);
480
0
          decrypt_len = linelen;
481
0
          if (smtp_auth_parameter_decoding_enabled) {
482
0
            if (strlen(decrypt) > 1) {
483
0
              g_base64_decode_inplace(decrypt, &decrypt_len);
484
0
              decrypt[decrypt_len] = 0;
485
0
            } else {
486
0
              decrypt_len = 0;
487
0
            }
488
0
            if (decrypt_len == 0) {
489
              /* Go back to the original string */
490
0
              decrypt = (char*)tvb_get_string_enc(pinfo->pool, tvb, offset, linelen, ENC_ASCII);
491
0
              decrypt_len = linelen;
492
0
            }
493
0
          }
494
0
        }
495
496
0
        if (!session_state->username)
497
0
          session_state->username = wmem_strdup(wmem_file_scope(), decrypt);
498
0
        proto_tree_add_string(smtp_tree, hf_smtp_username, tvb,
499
0
                              offset, linelen, decrypt);
500
0
        col_append_fstr(pinfo->cinfo, COL_INFO, "User: %s", format_text(pinfo->pool, decrypt, decrypt_len));
501
411
      } else if (session_state->password_frame == pinfo->num) {
502
0
        if (decrypt == NULL) {
503
          /* This line wasn't already decrypted through the state machine */
504
0
          decrypt = (char*)tvb_get_string_enc(pinfo->pool, tvb, offset, linelen, ENC_ASCII);
505
0
          decrypt_len = linelen;
506
0
          if (smtp_auth_parameter_decoding_enabled) {
507
0
            if (strlen(decrypt) > 1) {
508
0
              g_base64_decode_inplace(decrypt, &decrypt_len);
509
0
              decrypt[decrypt_len] = 0;
510
0
            } else {
511
0
              decrypt_len = 0;
512
0
            }
513
0
            if (decrypt_len == 0) {
514
              /* Go back to the original string */
515
0
              decrypt = (char*)tvb_get_string_enc(pinfo->pool, tvb, offset, linelen, ENC_ASCII);
516
0
              decrypt_len = linelen;
517
0
            }
518
0
          }
519
0
        }
520
0
        proto_tree_add_string(smtp_tree, hf_smtp_password, tvb,
521
0
                              offset, linelen, decrypt);
522
0
        col_append_fstr(pinfo->cinfo, COL_INFO, "Pass: %s", format_text(pinfo->pool, decrypt, decrypt_len));
523
524
0
        tap_credential_t* auth = wmem_new0(pinfo->pool, tap_credential_t);
525
0
        auth->num = pinfo->num;
526
0
        auth->username_num = session_state->username_frame;
527
0
        auth->password_hf_id = hf_smtp_password;
528
0
        auth->username = session_state->username;
529
0
        auth->proto = "SMTP";
530
0
        auth->info = wmem_strdup_printf(pinfo->pool, "Username in packet %u", auth->username_num);
531
0
        tap_queue_packet(credentials_tap, pinfo, auth);
532
411
      } else if (session_state->ntlm_rsp_frame == pinfo->num) {
533
0
        decrypt = (char*)tvb_get_string_enc(pinfo->pool, tvb, offset, linelen, ENC_ASCII);
534
0
        decrypt_len = linelen;
535
0
        if (smtp_auth_parameter_decoding_enabled) {
536
0
          if (strlen(decrypt) > 1) {
537
0
            g_base64_decode_inplace(decrypt, &decrypt_len);
538
0
            decrypt[decrypt_len] = 0;
539
0
          } else {
540
0
            decrypt_len = 0;
541
0
          }
542
0
          if (decrypt_len == 0) {
543
            /* Go back to the original string */
544
0
            decrypt = (char*)tvb_get_string_enc(pinfo->pool, tvb, offset, linelen, ENC_ASCII);
545
0
            decrypt_len = linelen;
546
0
            col_append_str(pinfo->cinfo, COL_INFO, format_text(pinfo->pool, decrypt, linelen));
547
0
            proto_tree_add_item(smtp_tree, hf_smtp_command_line, tvb,
548
0
                                offset, linelen, ENC_ASCII);
549
0
          }
550
0
          else {
551
0
            base64_string = (char*)tvb_get_string_enc(pinfo->pool, tvb, offset, linelen, ENC_ASCII);
552
0
            dissect_ntlm_auth(tvb, pinfo, smtp_tree, base64_string);
553
0
          }
554
0
        }
555
0
        else {
556
0
          col_append_str(pinfo->cinfo, COL_INFO, format_text(pinfo->pool, decrypt, linelen));
557
0
          proto_tree_add_item(smtp_tree, hf_smtp_command_line, tvb,
558
0
                              offset, linelen, ENC_ASCII);
559
0
        }
560
411
      } else if (session_state->user_pass_frame == pinfo->num) {
561
0
        decode_plain_auth(tvb, pinfo, smtp_tree, offset, linelen);
562
411
      } else {
563
564
411
        if (linelen >= 4)
565
175
          cmdlen = 4;
566
236
        else
567
236
          cmdlen = linelen;
568
569
        /*
570
         * Put the command line into the protocol tree.
571
         */
572
411
        ti =  proto_tree_add_item(smtp_tree, hf_smtp_command_line, tvb,
573
411
                        offset, next_offset - offset, ENC_ASCII);
574
411
        cmdresp_tree = proto_item_add_subtree(ti, ett_smtp_cmdresp);
575
576
411
        proto_tree_add_item(cmdresp_tree, hf_smtp_req_command, tvb,
577
411
                          offset, cmdlen, ENC_ASCII);
578
579
411
        if ((linelen > 5) && (session_state->username_cmd_frame == pinfo->num) ) {
580
0
          proto_tree_add_item(cmdresp_tree, hf_smtp_req_parameter, tvb,
581
0
                            offset + 5, linelen - 5, ENC_ASCII);
582
583
0
          if (linelen >= 11) {
584
0
            if (decrypt == NULL) {
585
              /* This line wasn't already decrypted through the state machine */
586
0
               decrypt = (char*)tvb_get_string_enc(pinfo->pool, tvb, offset + 11, linelen - 11, ENC_ASCII);
587
0
               decrypt_len = linelen - 11;
588
0
               if (smtp_auth_parameter_decoding_enabled) {
589
0
                 if (strlen(decrypt) > 1) {
590
0
                   g_base64_decode_inplace(decrypt, &decrypt_len);
591
0
                   decrypt[decrypt_len] = 0;
592
0
                 } else {
593
0
                   decrypt_len = 0;
594
0
                 }
595
0
                 if (decrypt_len == 0) {
596
                   /* Go back to the original string */
597
0
                   decrypt = (char*)tvb_get_string_enc(pinfo->pool, tvb, offset + 11, linelen - 11, ENC_ASCII);
598
0
                   decrypt_len = linelen - 11;
599
0
                 }
600
0
               }
601
0
            }
602
0
            proto_tree_add_string(cmdresp_tree, hf_smtp_username, tvb, offset + 11, linelen - 11, decrypt);
603
0
            col_append_str(pinfo->cinfo, COL_INFO,
604
0
                           tvb_format_text(pinfo->pool, tvb, offset, 11));
605
0
            col_append_fstr(pinfo->cinfo, COL_INFO, "User: %s", format_text(pinfo->pool, decrypt, decrypt_len));
606
0
          }
607
0
        }
608
411
        else if ((linelen > 5) && (session_state->ntlm_req_frame == pinfo->num) ) {
609
0
          proto_tree_add_item(cmdresp_tree, hf_smtp_req_parameter, tvb,
610
0
                            offset + 5, linelen - 5, ENC_ASCII);
611
0
          if (linelen >= 10) {
612
0
            decrypt = (char*)tvb_get_string_enc(pinfo->pool, tvb, offset + 10, linelen - 10, ENC_ASCII);
613
0
            decrypt_len = linelen - 10;
614
0
            if (smtp_auth_parameter_decoding_enabled) {
615
0
              if (strlen(decrypt) > 1) {
616
0
                g_base64_decode_inplace(decrypt, &decrypt_len);
617
0
                decrypt[decrypt_len] = 0;
618
0
              } else {
619
0
                decrypt_len = 0;
620
0
              }
621
0
              if (decrypt_len == 0) {
622
                /* Go back to the original string */
623
0
                decrypt = (char*)tvb_get_string_enc(pinfo->pool, tvb, offset + 10, linelen - 10, ENC_ASCII);
624
0
                decrypt_len = linelen - 10;
625
0
                col_append_str(pinfo->cinfo, COL_INFO,
626
0
                               tvb_format_text(pinfo->pool, tvb, offset, 10));
627
0
                col_append_str(pinfo->cinfo, COL_INFO, format_text(pinfo->pool, decrypt, linelen - 10));
628
0
              }
629
0
              else {
630
0
                base64_string = (char*)tvb_get_string_enc(pinfo->pool, tvb, offset + 10, linelen - 10, ENC_ASCII);
631
0
                col_append_str(pinfo->cinfo, COL_INFO,
632
0
                               tvb_format_text(pinfo->pool, tvb, offset, 10));
633
0
                dissect_ntlm_auth(tvb, pinfo, cmdresp_tree, format_text(pinfo->pool, base64_string, linelen - 10));
634
0
              }
635
0
            }
636
0
            else {
637
0
              col_append_str(pinfo->cinfo, COL_INFO,
638
0
                             tvb_format_text(pinfo->pool, tvb, offset, 10));
639
0
              col_append_str(pinfo->cinfo, COL_INFO, format_text(pinfo->pool, decrypt, linelen - 10));
640
0
            }
641
0
          }
642
0
        }
643
411
        else if ((linelen > 5) && (session_state->user_pass_cmd_frame == pinfo->num) ) {
644
0
          proto_tree_add_item(cmdresp_tree, hf_smtp_req_parameter, tvb,
645
0
                            offset + 5, linelen - 5, ENC_ASCII);
646
0
          col_append_str(pinfo->cinfo, COL_INFO,
647
0
                         tvb_format_text(pinfo->pool, tvb, offset, 11));
648
0
          decode_plain_auth(tvb, pinfo, cmdresp_tree, offset + 11, linelen - 11);
649
0
        }
650
411
        else if (linelen > 5) {
651
125
          proto_tree_add_item(cmdresp_tree, hf_smtp_req_parameter, tvb,
652
125
                            offset + 5, linelen - 5, ENC_ASCII);
653
125
          col_append_str(pinfo->cinfo, COL_INFO,
654
125
                         tvb_format_text(pinfo->pool, tvb, offset, linelen));
655
125
        }
656
286
        else {
657
286
          col_append_str(pinfo->cinfo, COL_INFO,
658
286
                         tvb_format_text(pinfo->pool, tvb, offset, linelen));
659
286
        }
660
661
411
        if (smtp_data_desegment && !spd_frame_data->more_frags) {
662
          /* terminate the desegmentation */
663
0
          frag_msg = fragment_end_seq_next(&smtp_data_reassembly_table,
664
0
                                           pinfo, spd_frame_data->conversation_id, NULL);
665
0
        }
666
411
      }
667
      /*
668
       * Step past this line.
669
       */
670
411
      offset = next_offset;
671
411
    }
672
72
  }
673
674
72
  if (smtp_data_desegment && (spd_frame_data->pdu_type == SMTP_PDU_MESSAGE || spd_frame_data->more_frags == false) ) {
675
    /* XXX: fragment_add_seq_next() only supports one PDU with a given ID
676
     * being completed in a frame.
677
     *
678
     * RFCs 2920 and 3030 imply that even with pipelining, a frame only
679
     * contains one message that ends, as the client needs to handle
680
     * responses. If it does happen, we need to track message numbers within
681
     * the conversation and use those as part of the frag ID.
682
     */
683
51
    next_tvb = process_reassembled_data(tvb, offset, pinfo, "Reassembled SMTP",
684
51
                                        frag_msg, &smtp_data_frag_items, NULL, smtp_tree);
685
51
    if (next_tvb) {
686
      /* XXX: this is presumptuous - we may have negotiated something else */
687
0
      if (imf_handle) {
688
0
        call_dissector(imf_handle, next_tvb, pinfo, tree);
689
0
      } else {
690
        /*
691
         * Message body.
692
         * Put its lines into the protocol tree, a line at a time.
693
         */
694
0
        dissect_smtp_data(tvb, offset, smtp_tree);
695
0
      }
696
697
0
      pinfo->fragmented = false;
698
51
    } else {
699
51
      pinfo->fragmented = true;
700
51
    }
701
51
  }
702
72
  return tvb_captured_length(tvb);
703
72
}
704
705
static int
706
dissect_smtp_response(tvbuff_t *tvb, packet_info *pinfo, proto_tree *smtp_tree, struct smtp_session_state *session_state)
707
36
{
708
36
  proto_item                *ti, *hidden_item;
709
36
  proto_tree                *cmdresp_tree = NULL;
710
36
  unsigned                   offset = 0;
711
36
  unsigned                   next_offset;
712
36
  unsigned                   linelen   = 0;
713
36
  uint32_t                   code;
714
36
  uint8_t                    line_code[3];
715
36
  char                      *decrypt   = NULL;
716
36
  size_t                     decrypt_len  = 0;
717
36
  char                      *base64_string   = NULL;
718
719
  /*
720
   * Process the response, a line at a time, until we hit a line
721
   * that doesn't have a continuation indication on it.
722
   */
723
36
  hidden_item = proto_tree_add_boolean(smtp_tree, hf_smtp_rsp, tvb, 0, 0, true);
724
36
  proto_item_set_hidden(hidden_item);
725
726
  //Multiline information
727
36
  smtp_multiline_state_t multiline_state = SMTP_MULTILINE_NONE;
728
36
  uint32_t multiline_code = 0;
729
36
  proto_item* code_item = NULL;
730
731
810
  while (tvb_offset_exists(tvb, offset)) {
732
    /*
733
     * Find the end of the line.
734
     */
735
774
    tvb_find_line_end_remaining(tvb, offset, &linelen, &next_offset);
736
737
774
    if (offset == 0)
738
36
        col_append_str(pinfo->cinfo, COL_INFO, "S: ");
739
738
    else
740
738
        col_append_str(pinfo->cinfo, COL_INFO, " | ");
741
742
774
    if (linelen >= 3) {
743
276
        line_code[0] = tvb_get_uint8(tvb, offset);
744
276
        line_code[1] = tvb_get_uint8(tvb, offset+1);
745
276
        line_code[2] = tvb_get_uint8(tvb, offset+2);
746
276
        if (g_ascii_isdigit(line_code[0]) && g_ascii_isdigit(line_code[1])
747
276
            && g_ascii_isdigit(line_code[2])) {
748
          /*
749
           * We have a 3-digit response code.
750
           */
751
63
          code = (line_code[0] - '0')*100 + (line_code[1] - '0')*10 + (line_code[2] - '0');
752
63
          if ((linelen > 3) && (tvb_get_uint8(tvb, offset + 3) == '-')) {
753
0
            if (multiline_state == SMTP_MULTILINE_NONE) {
754
0
              multiline_state = SMTP_MULTILINE_START;
755
0
              multiline_code = code;
756
0
            } else {
757
0
              multiline_state = SMTP_MULTILINE_CONTINUE;
758
0
            }
759
63
          } else if ((multiline_state == SMTP_MULTILINE_START) || (multiline_state == SMTP_MULTILINE_CONTINUE)) {
760
0
            multiline_state = SMTP_MULTILINE_END;
761
0
          }
762
763
          /*
764
           * If we're awaiting the response to a STARTTLS code, this
765
           * is it - if it's 220, all subsequent traffic will
766
           * be TLS, otherwise we're back to boring old SMTP.
767
           */
768
63
          if (session_state->smtp_state == SMTP_STATE_AWAITING_STARTTLS_RESPONSE) {
769
0
            if (code == 220) {
770
              /* This is the last non-TLS frame. */
771
0
              ssl_starttls_ack(tls_handle, pinfo, smtp_handle);
772
0
            }
773
0
            session_state->smtp_state =  SMTP_STATE_READING_CMDS;
774
0
          }
775
776
63
          if (code == 334) {
777
0
              switch(session_state->auth_state)
778
0
              {
779
0
              case SMTP_AUTH_STATE_START:
780
0
                  session_state->auth_state = SMTP_AUTH_STATE_USERNAME_REQ;
781
0
                  break;
782
0
              case SMTP_AUTH_STATE_USERNAME_RSP:
783
0
                  session_state->auth_state = SMTP_AUTH_STATE_PASSWORD_REQ;
784
0
                  break;
785
0
              case SMTP_AUTH_STATE_PLAIN_REQ:
786
0
                  session_state->auth_state = SMTP_AUTH_STATE_PLAIN_RSP;
787
0
                  break;
788
0
              case SMTP_AUTH_STATE_PLAIN_START_REQ:
789
0
                  session_state->auth_state = SMTP_AUTH_STATE_PLAIN_REQ;
790
0
                  break;
791
0
              case SMTP_AUTH_STATE_NTLM_REQ:
792
0
                  session_state->auth_state = SMTP_AUTH_STATE_NTLM_CHALLANGE;
793
0
                  break;
794
0
              case SMTP_AUTH_STATE_NONE:
795
0
              case SMTP_AUTH_STATE_USERNAME_REQ:
796
0
              case SMTP_AUTH_STATE_PASSWORD_REQ:
797
0
              case SMTP_AUTH_STATE_PASSWORD_RSP:
798
0
              case SMTP_AUTH_STATE_PLAIN_RSP:
799
0
              case SMTP_AUTH_STATE_PLAIN_CRED_REQ:
800
0
              case SMTP_AUTH_STATE_NTLM_RSP:
801
0
              case SMTP_AUTH_STATE_NTLM_CHALLANGE:
802
0
              case SMTP_AUTH_STATE_SUCCESS:
803
0
              case SMTP_AUTH_STATE_FAILED:
804
                  /* ignore */
805
0
                  break;
806
0
              }
807
63
          } else if ((session_state->auth_state == SMTP_AUTH_STATE_PASSWORD_RSP) ||
808
63
                     ( session_state->auth_state == SMTP_AUTH_STATE_PLAIN_RSP) ||
809
63
                     ( session_state->auth_state == SMTP_AUTH_STATE_NTLM_RSP) ||
810
63
                     ( session_state->auth_state == SMTP_AUTH_STATE_PLAIN_CRED_REQ) ) {
811
0
              if (code == 235) {
812
0
                session_state->auth_state = SMTP_AUTH_STATE_SUCCESS;
813
0
              } else {
814
0
                session_state->auth_state = SMTP_AUTH_STATE_FAILED;
815
0
              }
816
0
              session_state->last_auth_frame = pinfo->num;
817
0
          }
818
819
          /*
820
           * Put the response code and parameters into the protocol tree.
821
           * Only create a new response tree when not in the middle of multiline response.
822
           */
823
63
          if ((multiline_state != SMTP_MULTILINE_CONTINUE) &&
824
63
              (multiline_state != SMTP_MULTILINE_END))
825
63
          {
826
63
            ti = proto_tree_add_item(smtp_tree, hf_smtp_response, tvb,
827
63
              offset, next_offset - offset, ENC_ASCII);
828
63
            cmdresp_tree = proto_item_add_subtree(ti, ett_smtp_cmdresp);
829
830
63
            code_item = proto_tree_add_uint(cmdresp_tree, hf_smtp_rsp_code, tvb, offset, 3, code);
831
63
          } else if (multiline_code != code) {
832
0
            expert_add_info_format(pinfo, code_item, &ei_smtp_rsp_code, "Unexpected response code %u in multiline response. Expected %u", code, multiline_code);
833
0
          }
834
835
63
          decrypt = NULL;
836
63
          if (linelen >= 4) {
837
63
              if ((smtp_auth_parameter_decoding_enabled) && (code == 334)) {
838
0
                  decrypt = (char*)tvb_get_string_enc(pinfo->pool, tvb, offset + 4, linelen - 4, ENC_ASCII);
839
0
                  if (strlen(decrypt) > 1 && (g_base64_decode_inplace(decrypt, &decrypt_len)) && decrypt_len > 0) {
840
0
                    decrypt[decrypt_len] = 0;
841
0
                    if (g_ascii_strncasecmp(decrypt, "NTLMSSP", 7) == 0) {
842
0
                      base64_string = (char*)tvb_get_string_enc(pinfo->pool, tvb, offset + 4, linelen - 4, ENC_ASCII);
843
0
                      col_append_fstr(pinfo->cinfo, COL_INFO, "%d ", code);
844
0
                      proto_tree_add_string(cmdresp_tree, hf_smtp_rsp_parameter, tvb,
845
0
                                        offset + 4, linelen - 4, base64_string);
846
0
                      dissect_ntlm_auth(tvb, pinfo, cmdresp_tree, base64_string);
847
0
                    }
848
0
                    else {
849
0
                      proto_tree_add_string(cmdresp_tree, hf_smtp_rsp_parameter, tvb,
850
0
                                        offset + 4, linelen - 4, decrypt);
851
852
0
                      col_append_fstr(pinfo->cinfo, COL_INFO, "%d %s", code, format_text(pinfo->pool, decrypt, decrypt_len));
853
0
                    }
854
0
                  } else {
855
0
                    decrypt = NULL;
856
0
                  }
857
0
              }
858
859
63
              if (decrypt == NULL) {
860
63
                  proto_tree_add_item(cmdresp_tree, hf_smtp_rsp_parameter, tvb,
861
63
                                    offset + 4, linelen - 4, ENC_ASCII);
862
863
63
                  if ((multiline_state != SMTP_MULTILINE_CONTINUE) &&
864
63
                      (multiline_state != SMTP_MULTILINE_END)) {
865
63
                    col_append_str(pinfo->cinfo, COL_INFO,
866
63
                                  tvb_format_text(pinfo->pool, tvb, offset, linelen));
867
63
                  } else {
868
0
                    col_append_str(pinfo->cinfo, COL_INFO,
869
0
                      tvb_format_text(pinfo->pool, tvb, offset+4, linelen-4));
870
0
                  }
871
63
              }
872
63
          } else {
873
0
             col_append_str(pinfo->cinfo, COL_INFO,
874
0
                            tvb_format_text(pinfo->pool, tvb, offset, linelen));
875
0
          }
876
63
        }
877
878
        //Clear multiline state if this is the last line
879
276
        if (multiline_state == SMTP_MULTILINE_END)
880
0
          multiline_state = SMTP_MULTILINE_NONE;
881
276
    }
882
    /*
883
     * Step past this line.
884
     */
885
774
    offset = next_offset;
886
887
774
  }
888
36
  return offset;
889
36
}
890
891
static int
892
dissect_smtp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
893
108
{
894
108
  struct smtp_proto_data    *spd_frame_data;
895
108
  proto_tree                *smtp_tree = NULL;
896
108
  proto_item                *ti;
897
108
  unsigned                   offset    = 0;
898
108
  int                        request   = 0;
899
108
  conversation_t            *conversation;
900
108
  struct smtp_session_state *session_state;
901
108
  const char                *line;
902
108
  unsigned                   linelen   = 0;
903
108
  bool                       eom_seen  = false;
904
108
  unsigned                   next_offset;
905
108
  unsigned                   loffset   = 0;
906
108
  int                        cmdlen;
907
108
  char                      *decrypt   = NULL;
908
108
  size_t                     decrypt_len  = 0;
909
910
  /* As there is no guarantee that we will only see frames in the
911
   * the SMTP conversation once, and that we will see them in
912
   * order - in Wireshark, the user could randomly click on frames
913
   * in the conversation in any order in which they choose - we
914
   * have to store information with each frame indicating whether
915
   * it contains commands or data or an EOM indication.
916
   *
917
   * XXX - what about frames that contain *both*?  TCP is a
918
   * byte-stream protocol, and there are no guarantees that
919
   * TCP segment boundaries will correspond to SMTP commands
920
   * or EOM indications.
921
   *
922
   * We only need that for the client->server stream; responses
923
   * are easy to manage.
924
   *
925
   * If we have per frame data, use that, else, we must be on the first
926
   * pass, so we figure it out on the first pass.
927
   */
928
929
  /*
930
   * Find or create the conversation for this.
931
   */
932
108
  conversation = find_or_create_conversation(pinfo);
933
934
  /*
935
   * Is there a request structure attached to this conversation?
936
   */
937
108
  session_state = (struct smtp_session_state *)conversation_get_proto_data(conversation, proto_smtp);
938
108
  if (!session_state) {
939
    /*
940
     * No - create one and attach it.
941
     */
942
66
    session_state                    = wmem_new0(wmem_file_scope(), struct smtp_session_state);
943
66
    session_state->smtp_state        = SMTP_STATE_START;
944
66
    session_state->auth_state        = SMTP_AUTH_STATE_NONE;
945
66
    session_state->msg_last          = true;
946
947
66
    conversation_add_proto_data(conversation, proto_smtp, session_state);
948
66
  }
949
950
  /* Is this a request or a response? */
951
108
  request = pinfo->destport == pinfo->match_uint;
952
953
  /*
954
   * Is there any data attached to this frame?
955
   */
956
108
  spd_frame_data = (struct smtp_proto_data *)p_get_proto_data(wmem_file_scope(), pinfo, proto_smtp, 0);
957
958
108
  if (!spd_frame_data) {
959
960
    /*
961
     * No frame data.
962
     */
963
107
    if (request) {
964
965
      /*
966
       * Create a frame data structure and attach it to the packet.
967
       */
968
71
      spd_frame_data = wmem_new0(wmem_file_scope(), struct smtp_proto_data);
969
970
71
      spd_frame_data->conversation_id = conversation->conv_index;
971
71
      spd_frame_data->more_frags = true;
972
71
      spd_frame_data->end_offset = tvb_reported_length(tvb);
973
974
71
      p_add_proto_data(wmem_file_scope(), pinfo, proto_smtp, 0, spd_frame_data);
975
976
71
    }
977
978
    /*
979
     * Get the first line from the buffer.
980
     *
981
     * Note that "tvb_find_line_end_remaining()" will, if it doesn't find a
982
     * line ending, set linelen to a value that is no longer than what's in
983
     * the buffer, so the "tvb_get_string_enc()" call won't throw an exception.
984
     */
985
107
    loffset = offset;
986
2.63k
    while (tvb_offset_exists(tvb, loffset)) {
987
2.52k
      if (!tvb_find_line_end_remaining(tvb, loffset, &linelen, &next_offset)) {
988
        /* We didn't find a line ending. */
989
101
        if (smtp_desegment && pinfo->can_desegment) {
990
          /*
991
           * We didn't find a line ending, and we're doing desegmentation;
992
           * tell the TCP dissector where the data for this message starts
993
           * in the data it handed us, and tell it we need more bytes.
994
           */
995
0
          pinfo->desegment_offset = loffset;
996
0
          pinfo->desegment_len = DESEGMENT_ONE_MORE_SEGMENT;
997
0
          return tvb_captured_length(tvb);
998
0
        }
999
101
      }
1000
1001
      /*
1002
       * Check whether or not this packet is an end of message packet
1003
       * We should look for CRLF.CRLF and they may be split.
1004
       * We have to keep in mind that we may see what we want on
1005
       * two passes through here ...
1006
       */
1007
2.52k
      if (request) {
1008
        /*
1009
         * The order of these is important ... We want to avoid
1010
         * cases where there is a CRLF at the end of a packet and a
1011
         * .CRLF at the beginning of the same packet.
1012
         */
1013
1.74k
        if (session_state->crlf_seen && tvb_strneql(tvb, loffset, ".\r\n", 3) == 0)
1014
4
          eom_seen = true;
1015
1016
1.74k
        if (tvb_strneql(tvb, next_offset-2, "\r\n", 2) == 0) {
1017
112
          session_state->crlf_seen = true;
1018
1.63k
        } else {
1019
1.63k
          session_state->crlf_seen = false;
1020
1.63k
        }
1021
1.74k
      }
1022
1023
      /*
1024
       * OK, Check if we have seen a DATA request. We do it here for
1025
       * simplicity, but we have to be careful below.
1026
       */
1027
2.52k
      if (request) {
1028
1.74k
        if (session_state->smtp_state == SMTP_STATE_READING_DATA) {
1029
          /*
1030
           * This is message data.
1031
           */
1032
0
          if (eom_seen) { /* Seen the EOM */
1033
            /*
1034
             * EOM.
1035
             * Everything that comes before it is a message.
1036
             * Everything that comes after it is commands.
1037
             */
1038
0
            spd_frame_data->pdu_type = SMTP_PDU_MESSAGE;
1039
0
            spd_frame_data->more_frags = false;
1040
0
            spd_frame_data->end_offset = loffset;
1041
1042
0
            spd_frame_data = append_pdu(spd_frame_data);
1043
0
            spd_frame_data->pdu_type = SMTP_PDU_EOM;
1044
0
            spd_frame_data->end_offset = next_offset;
1045
1046
0
            spd_frame_data = append_pdu(spd_frame_data);
1047
0
            spd_frame_data->end_offset = tvb_reported_length(tvb);
1048
1049
0
            session_state->smtp_state = SMTP_STATE_READING_CMDS;
1050
0
          } else {
1051
            /*
1052
             * Message data with no EOM.
1053
             */
1054
0
            spd_frame_data->pdu_type = SMTP_PDU_MESSAGE;
1055
1056
0
            if (session_state->msg_tot_len > 0) {
1057
              /*
1058
               * We are handling a BDAT message.
1059
               * Check if we have reached end of the data chunk.
1060
               */
1061
1062
0
              uint32_t msg_len = MIN((uint32_t)tvb_reported_length_remaining(tvb, loffset), (session_state->msg_tot_len - session_state->msg_read_len));
1063
0
              session_state->msg_read_len += msg_len;
1064
              /*
1065
               * Since we're grabbing the rest of the packet or the data chunk,
1066
               * update the offset accordingly.
1067
               */
1068
0
              next_offset = loffset + msg_len;
1069
0
              spd_frame_data->end_offset = next_offset;
1070
1071
0
              if (session_state->msg_read_len == session_state->msg_tot_len) {
1072
                /*
1073
                 * We have reached end of BDAT data chunk.
1074
                 * Everything that comes after this is commands.
1075
                 */
1076
1077
0
                if (session_state->msg_last) {
1078
                  /*
1079
                   * We have found the LAST data chunk.
1080
                   * The message can now be reassembled.
1081
                   */
1082
0
                  spd_frame_data->more_frags = false;
1083
0
                }
1084
1085
0
                spd_frame_data = append_pdu(spd_frame_data);
1086
0
                spd_frame_data->end_offset = tvb_reported_length(tvb);
1087
1088
0
                session_state->smtp_state = SMTP_STATE_READING_CMDS;
1089
0
              }
1090
0
            }
1091
0
          }
1092
1.74k
        } else {
1093
          /*
1094
           * This is commands - unless the capture started in the
1095
           * middle of a session, and we're in the middle of data.
1096
           *
1097
           * Commands are not necessarily 4 characters; look
1098
           * for a space or the end of the line to see where
1099
           * the putative command ends.
1100
           */
1101
1.74k
          line = (char*)tvb_get_string_enc(pinfo->pool, tvb, loffset, linelen, ENC_ASCII);
1102
1.74k
          if ((session_state->auth_state != SMTP_AUTH_STATE_NONE) &&
1103
0
              (pinfo->num >= session_state->first_auth_frame) &&
1104
0
              ((session_state->last_auth_frame == 0) || (pinfo->num <= session_state->last_auth_frame))) {
1105
0
            decrypt = (char*)tvb_get_string_enc(pinfo->pool, tvb, loffset, linelen, ENC_ASCII);
1106
0
            if ((smtp_auth_parameter_decoding_enabled) &&
1107
0
                (strlen(decrypt) > 1) &&
1108
0
                (g_base64_decode_inplace(decrypt, &decrypt_len)) &&
1109
0
                (decrypt_len > 0)) {
1110
0
              decrypt[decrypt_len] = 0;
1111
0
              line = decrypt;
1112
0
              linelen = (int)decrypt_len;
1113
0
            } else {
1114
0
              decrypt_len = linelen;
1115
0
            }
1116
0
          }
1117
1118
1.74k
          cmdlen = (int)strcspn(line, " ");
1119
1.74k
          if (line_is_smtp_command(line, cmdlen) &&
1120
38
               ( session_state->auth_state != SMTP_AUTH_STATE_PASSWORD_REQ )) {
1121
38
            if (g_ascii_strncasecmp(line, "DATA", 4) == 0) {
1122
              /*
1123
               * DATA command.
1124
               * This is a command, but everything that comes after it,
1125
               * until an EOM, is data.
1126
               */
1127
0
              spd_frame_data->pdu_type = SMTP_PDU_CMD;
1128
0
              session_state->smtp_state = SMTP_STATE_READING_DATA;
1129
0
              session_state->data_seen = true;
1130
38
            } else if ((linelen > 5) && (g_ascii_strncasecmp(line, "BDAT", 4) == 0)) {
1131
              /*
1132
               * BDAT command.
1133
               * This is a command, but everything that comes after it,
1134
               * until given length is received, is data.
1135
               */
1136
0
              uint32_t msg_len;
1137
1138
0
              msg_len = (uint32_t)strtoul (line+5, NULL, 10);
1139
1140
0
              spd_frame_data->pdu_type = SMTP_PDU_CMD;
1141
1142
0
              session_state->data_seen = true;
1143
0
              session_state->msg_tot_len += msg_len;
1144
1145
0
              if (g_ascii_strncasecmp(line+linelen-4, "LAST", 4) == 0) {
1146
                /*
1147
                 * This is the last data chunk.
1148
                 */
1149
0
                session_state->msg_last = true;
1150
1151
0
                if (msg_len == 0) {
1152
                  /*
1153
                   * No more data to expect.
1154
                   * The message can now be reassembled.
1155
                   */
1156
0
                  spd_frame_data->more_frags = false;
1157
0
                }
1158
0
              } else {
1159
0
                session_state->msg_last = false;
1160
0
              }
1161
1162
0
              if (msg_len == 0) {
1163
                /* No data to read, next will be another command */
1164
0
                session_state->smtp_state = SMTP_STATE_READING_CMDS;
1165
0
              } else {
1166
0
                session_state->smtp_state = SMTP_STATE_READING_DATA;
1167
0
                spd_frame_data->end_offset = next_offset;
1168
1169
0
                spd_frame_data = append_pdu(spd_frame_data);
1170
0
                spd_frame_data->end_offset = tvb_reported_length(tvb);
1171
0
              }
1172
38
            } else if (g_ascii_strncasecmp(line, "RSET", 4) == 0) {
1173
              /*
1174
               * RSET command.
1175
               * According to RFC 3030, the RSET command clears all BDAT
1176
               * segments and resets the transaction. It is possible to
1177
               * use DATA and BDAT in the same session, so long as they
1178
               * are not mixed in the same transaction.
1179
               */
1180
0
              spd_frame_data->pdu_type = SMTP_PDU_CMD;
1181
0
              session_state->msg_last = true;
1182
0
              session_state->msg_tot_len = 0;
1183
0
              session_state->msg_read_len = 0;
1184
38
            } else if ((g_ascii_strncasecmp(line, "AUTH LOGIN", 10) == 0) && (linelen <= 11)) {
1185
              /*
1186
               * AUTH LOGIN command.
1187
               * Username is in a separate frame
1188
               */
1189
0
              spd_frame_data->pdu_type        = SMTP_PDU_CMD;
1190
0
              session_state->smtp_state       = SMTP_STATE_READING_CMDS;
1191
0
              session_state->auth_state       = SMTP_AUTH_STATE_START;
1192
0
              session_state->first_auth_frame = pinfo->num;
1193
38
            } else if ((g_ascii_strncasecmp(line, "AUTH LOGIN", 10) == 0) && (linelen > 11)) {
1194
              /*
1195
               * AUTH LOGIN command.
1196
               * Username follows the 'AUTH LOGIN' string
1197
               */
1198
0
              spd_frame_data->pdu_type        = SMTP_PDU_CMD;
1199
0
              session_state->smtp_state       = SMTP_STATE_READING_CMDS;
1200
0
              session_state->auth_state       = SMTP_AUTH_STATE_USERNAME_RSP;
1201
0
              session_state->first_auth_frame = pinfo->num;
1202
0
              session_state->username_cmd_frame = pinfo->num;
1203
38
            } else if ((g_ascii_strncasecmp(line, "AUTH PLAIN", 10) == 0) && (linelen <= 11)) {
1204
              /*
1205
               * AUTH PLAIN command.
1206
               * Username and Password is in one separate frame
1207
               */
1208
0
              spd_frame_data->pdu_type        = SMTP_PDU_CMD;
1209
0
              session_state->smtp_state       = SMTP_STATE_READING_CMDS;
1210
0
              session_state->auth_state       = SMTP_AUTH_STATE_PLAIN_START_REQ;
1211
0
              session_state->first_auth_frame = pinfo->num;
1212
38
            } else if ((g_ascii_strncasecmp(line, "AUTH PLAIN", 10) == 0) && (linelen > 11)) {
1213
              /*
1214
               * AUTH PLAIN command.
1215
               * Username and Password follows the 'AUTH PLAIN' string
1216
               */
1217
0
              spd_frame_data->pdu_type        = SMTP_PDU_CMD;
1218
0
              session_state->smtp_state       = SMTP_STATE_READING_CMDS;
1219
0
              session_state->auth_state       = SMTP_AUTH_STATE_PLAIN_CRED_REQ;
1220
0
              session_state->first_auth_frame = pinfo->num;
1221
0
              session_state->user_pass_cmd_frame = pinfo->num;
1222
38
            } else if ((g_ascii_strncasecmp(line, "AUTH NTLM", 9) == 0) && (linelen > 10)) {
1223
              /*
1224
               * AUTH NTLM command with nlmssp request
1225
               */
1226
0
              spd_frame_data->pdu_type        = SMTP_PDU_CMD;
1227
0
              session_state->smtp_state       = SMTP_STATE_READING_CMDS;
1228
0
              session_state->auth_state       = SMTP_AUTH_STATE_NTLM_REQ;
1229
0
              session_state->ntlm_req_frame = pinfo->num;
1230
38
            } else if (g_ascii_strncasecmp(line, "STARTTLS", 8) == 0) {
1231
              /*
1232
               * STARTTLS command.
1233
               * This is a command, but if the response is 220,
1234
               * everything after the response is TLS.
1235
               */
1236
0
              session_state->smtp_state = SMTP_STATE_AWAITING_STARTTLS_RESPONSE;
1237
0
              spd_frame_data->pdu_type = SMTP_PDU_CMD;
1238
38
            } else {
1239
              /*
1240
               * Regular command.
1241
               */
1242
38
              spd_frame_data->pdu_type = SMTP_PDU_CMD;
1243
38
            }
1244
1.71k
          } else if (session_state->auth_state == SMTP_AUTH_STATE_USERNAME_REQ) {
1245
0
              session_state->auth_state = SMTP_AUTH_STATE_USERNAME_RSP;
1246
0
              session_state->username_frame = pinfo->num;
1247
1.71k
          } else if (session_state->auth_state == SMTP_AUTH_STATE_PASSWORD_REQ) {
1248
0
              session_state->auth_state = SMTP_AUTH_STATE_PASSWORD_RSP;
1249
0
              session_state->password_frame = pinfo->num;
1250
1.71k
          } else if (session_state->auth_state == SMTP_AUTH_STATE_PLAIN_REQ) {
1251
0
              session_state->auth_state = SMTP_AUTH_STATE_PLAIN_RSP;
1252
0
              session_state->user_pass_frame = pinfo->num;
1253
1.71k
          } else if (session_state->auth_state == SMTP_AUTH_STATE_NTLM_CHALLANGE) {
1254
0
              session_state->auth_state = SMTP_AUTH_STATE_NTLM_RSP;
1255
0
              session_state->ntlm_rsp_frame = pinfo->num;
1256
0
          }
1257
1.71k
          else {
1258
1259
            /*
1260
             * Assume it's message data.
1261
             */
1262
1.71k
            spd_frame_data->pdu_type = (session_state->data_seen || (session_state->smtp_state == SMTP_STATE_START)) ? SMTP_PDU_MESSAGE : SMTP_PDU_CMD;
1263
1.71k
          }
1264
1.74k
        }
1265
1.74k
      }
1266
1267
      /*
1268
       * Step past this line.
1269
       */
1270
2.52k
      loffset = next_offset;
1271
2.52k
    }
1272
107
  }
1273
1274
1275
  /*
1276
   * From here, we simply add items to the tree and info to the info
1277
   * fields ...
1278
   */
1279
1280
108
  col_set_str(pinfo->cinfo, COL_PROTOCOL, "SMTP");
1281
108
  col_clear(pinfo->cinfo, COL_INFO);
1282
1283
108
  ti = proto_tree_add_item(tree, proto_smtp, tvb, offset, -1, ENC_NA);
1284
108
  smtp_tree = proto_item_add_subtree(ti, ett_smtp);
1285
1286
108
  if (request) {
1287
    /*
1288
     * Check out whether or not we can see a command in there ...
1289
     * What we are looking for is not data_seen and the word DATA
1290
     * and not eom_seen.
1291
     *
1292
     * We will see DATA and session_state->data_seen when we process the
1293
     * tree view after we have seen a DATA packet when processing
1294
     * the packet list pane.
1295
     *
1296
     * On the first pass, we will not have any info on the packets
1297
     * On second and subsequent passes, we will.
1298
     */
1299
72
    spd_frame_data = (struct smtp_proto_data *)p_get_proto_data(wmem_file_scope(), pinfo, proto_smtp, 0);
1300
72
    offset = 0;
1301
144
    while (spd_frame_data != NULL && tvb_reported_length_remaining(tvb, offset)) {
1302
72
      DISSECTOR_ASSERT_CMPINT(offset, <=, spd_frame_data->end_offset);
1303
72
      dissect_smtp_request(tvb_new_subset_length(tvb, offset, spd_frame_data->end_offset - offset), pinfo, tree, smtp_tree, session_state, spd_frame_data, (offset == 0));
1304
72
      offset = spd_frame_data->end_offset;
1305
72
      spd_frame_data = spd_frame_data->next;
1306
72
    }
1307
72
  } else {
1308
36
    dissect_smtp_response(tvb, pinfo, smtp_tree, session_state);
1309
36
  }
1310
1311
108
  return tvb_captured_length(tvb);
1312
108
}
1313
1314
1315
/* Register all the bits needed by the filtering engine */
1316
1317
void
1318
proto_register_smtp(void)
1319
16
{
1320
16
  static hf_register_info hf[] = {
1321
16
    { &hf_smtp_req,
1322
16
      { "Request", "smtp.req",
1323
16
        FT_BOOLEAN, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1324
1325
16
    { &hf_smtp_rsp,
1326
16
      { "Response", "smtp.rsp",
1327
16
        FT_BOOLEAN, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1328
1329
16
    { &hf_smtp_message,
1330
16
      { "Message", "smtp.message",
1331
16
        FT_STRING,  BASE_NONE, NULL, 0x0, NULL, HFILL }},
1332
1333
16
    { &hf_smtp_command_line,
1334
16
      { "Command Line", "smtp.command_line",
1335
16
        FT_STRING,  BASE_NONE, NULL, 0x0, NULL, HFILL }},
1336
1337
16
    { &hf_smtp_req_command,
1338
16
      { "Command", "smtp.req.command",
1339
16
        FT_STRING,  BASE_NONE, NULL, 0x0, NULL, HFILL }},
1340
1341
16
    { &hf_smtp_req_parameter,
1342
16
      { "Request parameter", "smtp.req.parameter",
1343
16
        FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1344
1345
16
    { &hf_smtp_response,
1346
16
      { "Response", "smtp.response",
1347
16
        FT_STRING,  BASE_NONE, NULL, 0x0, NULL, HFILL }},
1348
1349
16
    { &hf_smtp_rsp_code,
1350
16
      { "Response code", "smtp.response.code",
1351
16
        FT_UINT32, BASE_DEC|BASE_EXT_STRING, &response_codes_vs_ext, 0x0, NULL, HFILL }},
1352
1353
16
    { &hf_smtp_rsp_parameter,
1354
16
      { "Response parameter", "smtp.rsp.parameter",
1355
16
        FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1356
1357
16
    { &hf_smtp_username,
1358
16
      { "Username", "smtp.auth.username",
1359
16
        FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1360
1361
16
    { &hf_smtp_password,
1362
16
      { "Password", "smtp.auth.password",
1363
16
        FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1364
1365
16
    { &hf_smtp_username_password,
1366
16
      { "Username/Password", "smtp.auth.username_password",
1367
16
        FT_STRING, BASE_NONE, NULL, 0x0, NULL, HFILL }},
1368
1369
16
    { &hf_smtp_eom,
1370
16
      { "EOM", "smtp.eom",
1371
16
        FT_NONE, BASE_NONE, NULL, 0x00, NULL, HFILL } },
1372
1373
    /* Fragment entries */
1374
16
    { &hf_smtp_data_fragments,
1375
16
      { "DATA fragments", "smtp.data.fragments",
1376
16
        FT_NONE, BASE_NONE, NULL, 0x00, "Message fragments", HFILL } },
1377
1378
16
    { &hf_smtp_data_fragment,
1379
16
      { "DATA fragment", "smtp.data.fragment",
1380
16
        FT_FRAMENUM, BASE_NONE, NULL, 0x00, "Message fragment", HFILL } },
1381
1382
16
    { &hf_smtp_data_fragment_overlap,
1383
16
      { "DATA fragment overlap", "smtp.data.fragment.overlap", FT_BOOLEAN,
1384
16
        BASE_NONE, NULL, 0x0, "Message fragment overlap", HFILL } },
1385
1386
16
    { &hf_smtp_data_fragment_overlap_conflicts,
1387
16
      { "DATA fragment overlapping with conflicting data",
1388
16
        "smtp.data.fragment.overlap.conflicts", FT_BOOLEAN, BASE_NONE, NULL,
1389
16
        0x0, "Message fragment overlapping with conflicting data", HFILL } },
1390
1391
16
    { &hf_smtp_data_fragment_multiple_tails,
1392
16
      { "DATA has multiple tail fragments", "smtp.data.fragment.multiple_tails",
1393
16
        FT_BOOLEAN, BASE_NONE, NULL, 0x0, "Message has multiple tail fragments", HFILL } },
1394
1395
16
    { &hf_smtp_data_fragment_too_long_fragment,
1396
16
      { "DATA fragment too long", "smtp.data.fragment.too_long_fragment",
1397
16
        FT_BOOLEAN, BASE_NONE, NULL, 0x0, "Message fragment too long", HFILL } },
1398
1399
16
    { &hf_smtp_data_fragment_error,
1400
16
      { "DATA defragmentation error", "smtp.data.fragment.error",
1401
16
        FT_FRAMENUM, BASE_NONE, NULL, 0x00, "Message defragmentation error", HFILL } },
1402
1403
16
    { &hf_smtp_data_fragment_count,
1404
16
      { "DATA fragment count", "smtp.data.fragment.count",
1405
16
        FT_UINT32, BASE_DEC, NULL, 0x00, NULL, HFILL } },
1406
1407
16
    { &hf_smtp_data_reassembled_in,
1408
16
      { "Reassembled DATA in frame", "smtp.data.reassembled.in",
1409
16
        FT_FRAMENUM, BASE_NONE, NULL, 0x00, "This DATA fragment is reassembled in this frame", HFILL } },
1410
1411
16
    { &hf_smtp_data_reassembled_length,
1412
16
      { "Reassembled DATA length", "smtp.data.reassembled.length",
1413
16
        FT_UINT32, BASE_DEC, NULL, 0x00, "The total length of the reassembled payload", HFILL } },
1414
16
  };
1415
16
  static int *ett[] = {
1416
16
    &ett_smtp,
1417
16
    &ett_smtp_cmdresp,
1418
16
    &ett_smtp_data_fragment,
1419
16
    &ett_smtp_data_fragments,
1420
1421
16
  };
1422
1423
16
  static ei_register_info ei[] = {
1424
16
    { &ei_smtp_base64_decode, { "smtp.base64_decode", PI_PROTOCOL, PI_WARN, "base64 decode failed or is not enabled (check SMTP preferences)", EXPFILL }},
1425
16
    { &ei_smtp_rsp_code,{ "smtp.response.code.unexpected", PI_PROTOCOL, PI_WARN, "Unexpected response code in multiline response", EXPFILL } },
1426
16
  };
1427
1428
16
  module_t *smtp_module;
1429
16
  expert_module_t* expert_smtp;
1430
1431
16
  proto_smtp = proto_register_protocol("Simple Mail Transfer Protocol",
1432
16
                                       "SMTP", "smtp");
1433
1434
16
  proto_register_field_array(proto_smtp, hf, array_length(hf));
1435
16
  proto_register_subtree_array(ett, array_length(ett));
1436
16
  expert_smtp = expert_register_protocol(proto_smtp);
1437
16
  expert_register_field_array(expert_smtp, ei, array_length(ei));
1438
16
  reassembly_table_register(&smtp_data_reassembly_table,
1439
16
                        &addresses_ports_reassembly_table_functions);
1440
1441
  /* Allow dissector to find be found by name. */
1442
16
  smtp_handle = register_dissector("smtp", dissect_smtp, proto_smtp);
1443
1444
  /* Preferences */
1445
16
  smtp_module = prefs_register_protocol(proto_smtp, NULL);
1446
16
  prefs_register_bool_preference(smtp_module, "desegment_lines",
1447
16
                                 "Reassemble SMTP command and response lines spanning multiple TCP segments",
1448
16
                                 "Whether the SMTP dissector should reassemble command and response lines"
1449
16
                                 " spanning multiple TCP segments. To use this option, you must also enable "
1450
16
                                 "\"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
1451
16
                                 &smtp_desegment);
1452
1453
16
  prefs_register_bool_preference(smtp_module, "desegment_data",
1454
16
                                 "Reassemble SMTP DATA commands spanning multiple TCP segments",
1455
16
                                 "Whether the SMTP dissector should reassemble DATA command and lines"
1456
16
                                 " spanning multiple TCP segments. To use this option, you must also enable "
1457
16
                                 "\"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
1458
16
                                 &smtp_data_desegment);
1459
1460
16
  prefs_register_bool_preference(smtp_module, "decryption",
1461
16
                                 "Decode Base64 encoded AUTH parameters",
1462
16
                                 "Whether the SMTP dissector should decode Base64 encoded AUTH parameters",
1463
16
                                 &smtp_auth_parameter_decoding_enabled);
1464
1465
16
  credentials_tap = register_tap("credentials"); /* credentials tap */
1466
16
}
1467
1468
/* The registration hand-off routine */
1469
void
1470
proto_reg_handoff_smtp(void)
1471
16
{
1472
16
  dissector_add_uint_range_with_preference("tcp.port", TCP_PORT_SMTP, smtp_handle);
1473
16
  ssl_dissector_add(TCP_PORT_SSL_SMTP, smtp_handle);
1474
  /* No "auto" preference since handle is shared with SMTP */
1475
16
  dissector_add_uint("tcp.port", TCP_PORT_SUBMISSION, smtp_handle);
1476
1477
  /* find the IMF dissector */
1478
16
  imf_handle = find_dissector_add_dependency("imf", proto_smtp);
1479
1480
  /* find the TLS dissector */
1481
16
  tls_handle = find_dissector_add_dependency("tls", proto_smtp);
1482
1483
  /* find the NTLM dissector */
1484
16
  ntlmssp_handle = find_dissector_add_dependency("ntlmssp", proto_smtp);
1485
1486
  /* find the data-text-lines dissector */
1487
16
  data_text_lines_handle = find_dissector_add_dependency("data-text-lines", proto_smtp);
1488
16
}
1489
1490
/*
1491
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
1492
 *
1493
 * Local variables:
1494
 * c-basic-offset: 2
1495
 * tab-width: 8
1496
 * indent-tabs-mode: nil
1497
 * End:
1498
 *
1499
 * vi: set shiftwidth=2 tabstop=8 expandtab:
1500
 * :indentSize=2:tabSize=8:noTabs=true
1501
 */