File: tcpflow.1.in

package info (click to toggle)
tcpflow 1.6.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,732 kB
  • sloc: cpp: 18,138; sh: 780; ansic: 347; makefile: 226; python: 55
file content (645 lines) | stat: -rw-r--r-- 18,227 bytes parent folder | download | duplicates (2)
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
.\"edit the file tcpflow.1.in, not tcpflow.1"
.\""
.\""
.TH tcpflow 1 "2013-04-13" "tcpflow @VERSION@" "tcpflow @VERSION@"
.SH NAME
tcpflow \- TCP flow recorder 
.SH SYNOPSIS
.na
.B tcpflow
[\c
.BI \-aBcCDIpsZ\fR\c
]
[\c
.BI \-b \ max_bytes\fR\c
]
[\c
.BI \-d \ debug_level\fR\c
]
[\c
.BI \-[eE] \ scanner\fR\c
]
[\c
.BI \-f \ max_fds\fR\c
]
[\c
.BI \-F[ctTXMkmg]\fR\c
]
[\c
.BI \-h\fR\c
|\c
.BI \--help\fR\c
]
[\c
.BI \-i \ iface\fR\c
]
[\c
.BI \-l \ file1.pcap\ file2.pcap...\fR\c
]
[\c
.BI \-L \ semlock\fR\c
]
[\c
.BI \-m \ min_bytes\fR\c
]
[\c
.BI \-o \ outdir\fR\c
]
[\c
.BI \-r \ file1.pcap\fR\c
]
[\c
.BI \-R \ file0.pcap\fR\c
]
[\c
.BI \-S \ name=value\fR\c
]
[\c
.BI \-T[filename\ template]\fR\c
]
[\c
.BI \-U\fR\c
|\c
.BI \--relinquish-privileges \ username\fR\c
]
[\c
.BI \-v\fR\c
|\c
.BI \--verbose\fR\c
]
[\c
.BI \-V\fR\c
|\c
.BI \--version\fR\c
]
[\c
.BI \-w \ file\fR\c
]
[\c
.BI \-x \ scanner\fR\c
]
[\c
.BI \-X \ file.xml\fR\c
]
[\c
.BI \-z\fR\c
|\c
.BI \--chroot \ directory\fR\c
]
[\c
.BI expression\fR\c
]
.SH DESCRIPTION
.LP
.B tcpflow
is a program that captures data transmitted as part of TCP connections
(flows), and stores the data in a way that is convenient for protocol
analysis or debugging.  Rather than showing packet-by-packet information, \fBtcpflow\fP
reconstructs the actual data streams and stores each flow in a
separate file for later analysis.  \fBtcpflow\fP understands TCP sequence
numbers and will correctly reconstruct data streams regardless of
retransmissions or out-of-order delivery. \fBtcpflow\fP provides control over filenames
for automatic binning of connections by protocol, IP address or connection number, and has a sophisticated
plug-in system for decompressing compressed HTTP connections, undoing MIME encoding, or calling user-provided
programs for post-processing.
.LP
By default \fBtcpflow\fP stores all captured data in files that have names of the form:
.in +.5i
.nf

\fB192.168.101.102.02345-010.011.012.013.45103\fP

.fi
.in -.5i
\,...where the contents of the above file would be data transmitted from
host 192.168.101.102 port 2345, to host 10.11.12.13 port 45103.
.LP
If you want to simply process a few hundred thousand packets and see what you have, try this:
.in +.5i
.nf

\fBtcpflow -a -o outdir -Fk -r packets.pcap\fP

.fi
.in -.5i
This will cause \fBtcpflow\fP to perform (-a) all processing, store the output in a directory
called 
.BI outdir,
bin the output in directories of 1000 connections each, and read its input from the file
\fBpackets.pcap\fP. More sophisticated processing is possible, of course.
.SH OPTIONS
.TP
.B \-a
Enable all processing. Same as 
.B \-e all.
.TP
.B \-B
Force binary output even when printing to console with 
.B -C 
or 
.B -c.
.TP
.B \-b \fImax_bytes\fP
Specifies the maximum size of a captured flow.  Any bytes beyond \fImax_bytes\fP from the
first byte captured will be discarded.  The default is to store an
unlimited number of bytes per flow. \fBNote:\fP before version 1.4, \fBtcpflow\fP could only store
a maximum of 4GiB per flow.
.TP
.B \-c
Console print.  Print the contents of packets to stdout as they
are received, without storing any captured data to files (implies \fB\-s\fP).
.TP
.B \-C
Console print without the packet source and destination details being printed.  Print the contents of packets to stdout as they
are received, without storing any captured data to files (implies \fB\-s\fP).
.TP
.B \-D
Console output should be in hex. 
.TP
.B \-d
Debug level.  Set the level of debugging messages printed to stderr to
\fIdebug_level\fP.  Higher numbers produce more messages.
.B \-d 0
causes completely silent operation.
.B \-d 1
, the default, produces minimal status messages.
.B \-d 10
produces verbose output equivalent to
.B \-v .
Numbers higher than 10 can produce a large
amount of debugging information useful only to developers.
.TP
.B \-E name
Disable all scanners and then enable scanner
.B name
.TP
.B \-e name
Enable scanner 
.B name.
.TP
.B \-e all
Enables all scanners. Same as 
.B \-a
.TP
.B \-e http
Perform HTTP post-processing ("After" processing). If the output file is
.in +.5i
.nf

\fB208.111.153.175.00080-192.168.001.064.37314,\fP

.fi
.in -.5i
Then the post-processing will create the files:
.in +.5i
.nf

\fB208.111.153.175.00080-192.168.001.064.37314-HTTP\fP
\fB208.111.153.175.00080-192.168.001.064.37314-HTTPBODY\fP

.fi
.in -.5i
If the HTTPBODY was compressed with GZIP, you may get a 
third file as well:
.in +.5i
.nf

\fB208.111.153.175.00080-192.168.001.064.37314-HTTPBODY-GZIP\fP

.fi
.in -.5i
Additional information about these streams, such as their MD5
hash value, is also written to the
.B DFXML report
file.
.TP
.B \-e python \-S py_path=path \-S py_module=module \-S py_function=foo
Post-process TCP payload by an external python function.
.RS
.PP
The python function must take a single string parameter.
The python function can return a string (else the function does must not return).
The returned string (if any) is written in the
.B DFXML report
file inside the XML tag \fB<scan_python_result>...</scan_python_result>\fP.
A sample python script is available within the tcpflow source code
in directory \fBpython/plugins\fP.
.PP
Example:
.PP
.nf
    \fBtcpflow -r my.cap -e python -S py_path=python/plugins -S py_module=samplePlugin -S py_function=sampleFunction\fP
.fi
.RE
.TP
.B \-F[format]
Specifies format for output filenames.
.RS
.TP
Format specifiers:
.TP
.B c
Appends the connection counter to ALL filenames.
.TP
.B t
Prepends each filename with a Unix timestamp (seconds since epoch).
.TP
.B T
Prepends each filename with an ISO-8601 timestamp.
.TP
.B X
Do not output any files (other than the 
.B DFXML report
file).
.RE
.TP
.B \-FM
Include MD5 of each flow in the
.B DFXML report
file.
.TP
.B \-FX
Suppresses file output entirely,
.B DFXML report
file is still produced.
.TP
.B \-Fk
bin output in 1K directories
.TP
.B \-Fm
bin output in 1M directories (2 levels)
.TP
.B \-Fg
bin output in 1G directories (3 levels)
.TP
.B \-f\fImax_fds\fP
Max file descriptors used.  Limit the number of file descriptors used
by \fBtcpflow\fP to \fImax_fds\fP.  Higher numbers use more system
resources, but usually perform better.  If the underlying operating
system supports the
.B setrlimit()
system call, the OS will be asked to enforce the requested limit.  The
default is for \fBtcpflow\fP to use the maximum number of file descriptors
allowed by the OS.  The
.B \-v
option will report how many file descriptors \fBtcpflow\fP is using.
.TP
.B \-g
Output flow information to console in multiple colors. (Blue for client to server flows, red for server to client flows, green for undecided flows.)
Note: This option was different from \fBtcpflow\fP 1.3 (-e) and 1.4.4 (-J).
.TP
.B \-h \--help
Help.  Print usage information and exit.
.TP
.B \-hh
More help.  Print more usage information and exit.
.TP
.B \-i \fIiface\fP
Interface name.  Capture packets from the network interface
named \fIiface\fP.  If no interface is specified with
.B \-i
, a reasonable default will be used by libpcap automatically.
.TP
.B \-I
Store the reception timestamps (of TCP packets) in a companion file \fB*.findx\fP.
Therefore each flow will have two files: (1) the usual file containing payload bytes
and (2) the text file containing the corresponding timestamps.
This last file \fB*.findx\fP has three columns using the pipe \fB'|'\fP as separator:
.nf

    \fBbyte-index|timestamp|length\fP

.fi
The \fBbyte-index\fP column is the postion within the file containing the payload bytes.
The \fBtimestamp\fP column represents the number of seconds since epoch as a floating point number.
The precision is the microsecond but may also be the nanosecond in a future \fBtcpflow\fP version.
The \fBlength\fP column is the number of successive bytes concerned by \fBtimestamp\fP
and can include several TCP frames (TCP packets).
The extension \fBfindx\fP may become from the fact that the timestamps are \fBframe indexed\fP.
.TP
.B \-L \fIsemlock_name\fP
Specifies that \fIsemlock_name\fP should be used as a Unix semaphore to prevent two different copies
of \fBtcpflow\fP running in two different processes but outputting to the same standard output from printing
on top of each other. This is an application of Unix named semaphores; bet you have never seen
one before.
.TP
.B \-l
Treat the following arguments as filenames with an assumed \fB-r\fP command before each one. 
This allows you to read a lot of files at once with shell globbing. For example, to process
all of the pcap files in the current directory, use this:
.in +.5i
.nf

\fBtcpflow -o out -a -l *.pcap\fP

.fi
.in -.5i
.TP
.B \-m \fImin_size\fP
Forces a new connection output file when there is a skip in the TCP session
of \fImin_size\fP bytes or more.
.TP
.B \-o \fIoutdir\fP
Specifies the output directory where the transcript files will be written.
.TP
.B \-P
No purge. Normally \fBtcpflow\fP removes connections from the hash table
after the connection is closed with a FIN. This conserves memory but
takes additional CPU time. Selecting this option causes the
std::tr1:unordered_map to grow without bounds, as \fBtcpflow\fP did prior to
version 1.1. That makes \fBtcpflow\fP run faster if there are less than 10
million connections, but can lead to out-of-memory errors.
.TP
.B \-p
No promiscuous mode.  Normally, \fBtcpflow\fP attempts to put the network
interface into promiscuous mode before capturing packets.  The
\fB-p\fP option tells \fBtcpflow\fP \fInot\fP to put the interface into
promiscuous mode.  Note that it might already be in promiscuous mode
for some other reason.
.TP
.B \-q
Quiet mode --- don't print warnings. Currently the only warning that \fBtcpflow\fP
prints is a warning when more than 10,000 files are created that the user should
have provided the \fB-Fk\fP, \fB-Fm\fP, or \fB-Fg\fP options. We might have other warnings
in the future.
.TP
.B \--relinquish-privileges\fB=\fIusername\fP
When \fBtcpflow\fP is run as root, this option changes
the user ID and group ID to write files owned by \fIusername\fP.
The group ID is the first one from the \fIusername\fP groups list.
This operation is performed just after opening
the capture device or just after opening the first input PCAP file.
This option does not support multi root-only readable input files
as the root privileges are dropped after opening the first file
(e.g.
.B \-r \fIroot-only-access.pcap\fP
.B \-R \fIroot-only.pcap\fP
.B \-l \fIroot-only*.pcap\fP\c
).
This option has the same behaviour as the
.IR tcpdump (1)
option having the same name
.B \--relinquish-privileges\fB
.
.TP
.B \-r
Read from file.  Read packets from \fIfile\fP, which was created using the
.B \-w
option of
.IR tcpdump (1).
This option may be repeated any number of times. Standard input is used if \fIfile\fP is "-".
Note that for this option to be useful, tcpdump's
.B \-s
option should be used to set the snaplen to the MTU of the interface
(e.g., 1500) while capturing packets.
.TP
.B \-R
Read from a file, but only to complete TCP flows. This option is used when 
.IR tcpflow
is used to process a series of files that are captured over time.
For each time period
\fIn,\fP file  \fIfile(n).pcap\fP should be processed with  \fB-R \fIfile(n).pcap\fP,
while \fIfile(n-1).pcap\fP should be processed with \fI-r file(n-1).pcap.\fP
.TP
.B \-S\fIname\fB=\fIvalue\fP
Sets a \fIname\fP parameter to be equal to \fIvalue\fP for a plug-in. 
Use \fB-hh\fP to find out all of the settable parameters.
.TP
.B \-s
Strip non-printables.  Convert all non-printable characters to the
"." character before printing packets to the console or storing them
to a file.
.TP
.B \-T[format]
Specifies an arbitrary template for filenames.
.RS
.TP
.B %A
expands to source IP address.
.TP
.B %a
expands to source IP port.
.TP
.B %B
expands to destination IP address.
.TP
.B %b
expands to destination IP port.
.TP
.B %T
expands to timestamp in ISO8601 format.
.TP
.B %t
expands to timestamp in Unix time_t format.
.TP
.B %V
expands to "--" if a VLAN is present.
.TP
.B %v
expands to the VLAN number if a VLAN is present.
.TP
.B %C
expands to "c" if the connection count>0.
.TP
.B %c
expands to the connection count if the connection count>0.
.TP
.B %#
always expands to the connection count.
.TP
.B %N
(connection_number )             % 1000
.TP
.B %K
(connection_number / 1000)       % 1000
.TP
.B %M
(connection_number / 1000000)    % 1000
.TP
.B %G
(connection_number / 1000000000) % 1000
.TP
.B %%
prints a "%".
.TP
.RE
When the option \fB\-T\fP is used, \fBtcpflow\fP ignores options \fB\-Fk\fP, \fB\-Fm\fP and \fB\-Fg\fP.
However, the option \fB\-T\fP handles \fB'/'\fP within the filename template patern to create sub-directories.
For example the following line will create a directory tree \fBout/IP-src/port-src/IP-dst/port-dst\fP.
.nf

    \fBtcpflow -r packets.pcap -o out -T %A/%a/%B/%b/%c%N.flow\fP
.fi
.TP
.B \-V \--version
Print the version number and exit.
.TP
.B \-v \--verbose
Verbose operation.  Verbosely describe \fBtcpflow\fP's operation.
Equivalent to \fB \-d 10\fP.
.TP
.B \-w \fIfilename.pcap\fP
Write packets that were not processed to \fIfilename.pcap\fP. Typically this will be 
UDP packets.
.TP
.B \-X \fIfilename.xml\fP
Write a
.B DFXML report
to \fIfilename.xml\fP. The file contains a record of every
tcp connection, how the \fBtcpflow\fP program was compiled, and the computer on which \fBtcpflow\fP was run.
By default
.B tcpflow
writes the
.B DFXML report
in file \fIreport.xml\fP.
.TP
.B \-Z
Don't decompress gzip-compressed streams. 
.\"START -- tcpdump excerpt"
.B \-K
Retain per flow isolated pcap structure.
.TP
\fIexpression\fP
selects which packets will be captured.  If no \fIexpression\fP
is given, all packets on the net will be captured.  Otherwise,
only packets for which \fIexpression\fP is `true' will be captured.
.IP
For the \fIexpression\fP syntax, see
.BR pcap-filter (7).
.IP
The \fIexpression\fP argument can be passed to \fItcpflow\fP as either a single
Shell argument, or as multiple Shell arguments, whichever is more convenient.
Generally, if the expression contains Shell metacharacters, such as
backslashes used to escape protocol names, it is easier to pass it as
a single, quoted argument rather than to escape the Shell metacharacters.
Multiple arguments are concatenated with spaces before being parsed.

.SH DFXML report
.LP
The
.B DFXML report
is the XML file written by
.B tcpflow
to provide
.B tcpflow
build details, command line arguments
and information about processed flows.
.LP
By default the
.B DFXML file
is named \fIreport.xml\fP.
But this filename can be changed
using command line option \fB\-X\fP.
.LP
.B DFXML file
respects the
.B DFXML schema
defined by project
\fIhttps://github.com/dfxml-working-group/dfxml_schema\fP.
.br
Moreover
.B tcpflow
adds two extra XML tags,
as illustrated by the following example:
.RS
.nf

\fB
<tcpflow startime='2017-07-22T00:12:21.962782Z' endtime='2017-07-22T00:12:22.097591Z'
         family='2' mac_daddr='40:3d:78:57:ed:d4' mac_saddr='00:c5:42:d2:cb:f2'
         src_ipn='141.134.34.12' dst_ipn='192.168.0.40' srcport='80' dstport='38797'
         packets='4' len='677' caplen='611' />

<tcpflow:result scanner="python" path="python/plugins" module="samplePlugin"
                function="sampleFunction">bla bla bla</tcpflow:result>
\fP
.fi
.RE
.LP
The first XML tag \fB<tcpflow>\fP provide information about the captured flow.
This tag should be renamed \fB<tcpflow:cap>\fP in a future version
in order to conform better to \fBDFXML schema\fP.
.LP
The second XML tag \fB<tcpflow:result>\fP collects processing results.
For the moment, only the scanner \fIpython\fP uses this feature.
.PP
The XML attributes of \fB<tcpflow>\fP are:
.IP \(bu
\fBstartime\fP Reception time of first packet
.IP \(bu
\fBendtime\fP Reception time of last packet
.IP \(bu
\fBfamily\fP
.IP \(bu
\fBmac_daddr\fP Destination MAC address of first packet (printed if any)
.IP \(bu
\fBmac_saddr\fP Source MAC address of first packet (printed if any)
.IP \(bu
\fBsrc_ipn\fP IP source
.IP \(bu
\fBdst_ipn\fP IP destination
.IP \(bu
\fBsrcport\fP TCP port source
.IP \(bu
\fBdstport\fP TCP port destination
.IP \(bu
\fBpackets\fP Nummber of packets
.IP \(bu
\fBout_of_order_count\fP Number of times
.B tcpflow
has replaced missing payload by zeros in the flow file,
for example when capture does not contain the TCP session begin (printed if any)
.IP \(bu
\fBviolations\fP Number of protocol violations (printed if any)
.IP \(bu
\fBlen\fP Sum of un-truncated length of all packet data
(including headers, see https://stackoverflow.com/q/1491660)
.IP \(bu
\fBcaplen\fP Sum of captured bytes of all packet data
(including headers, printed if different from \fBlen\fP)
.PP
The XML attributes of \fB<tcpflow:result>\fP are:
.IP \(bu
\fBscanner\fP Name of the scanner
.IP \(bu
\fBpath\fP Directory of the scanner module (printed if relevant)
.IP \(bu
\fBmodule\fP Module name (printed if relevant, used to indicate the python script)
.IP \(bu
\fBfunction\fP Function name (printed if relevant,
used to indicate the function within the python module)
.SH EXAMPLES
.LP
To record all packets arriving at or departing from \fIsundown\fP and extract all of the HTTP attachments:
.RS
.nf
\fBtcpflow -e http -o outdir host sundown\fP
.fi
.RE
.LP
To record traffic between \fIhelios\fR and either \fIhot\fR or \fIace\fR and bin the results into 1000 files per directory and calculate the MD5 of each flow:
.RS
.nf
\fBtcpflow -X report.xml -e md5 -o outdir -Fk host helios and \\( hot or ace \\)\fP
.fi
.SH BUGS
Please send bug reports to simsong@acm.org.
.LP
\fBtcpflow\fP currently does not understand IP fragments.  Flows containing
IP fragments will not be recorded correctly.
.SH AUTHORS
Originally by Jeremy Elson <jelson@circlemud.org>.
Substantially modified and maintained by Simson L. Garfinkel <simsong@acm.org>.
Network visualization code by Michael Shick <mike@shick.in>
.LP
The current version of this software is available at
.RS
.I http://digitalcorpora.org/downloads/tcpflow/
.LP
.RE
An announcement mailing list for this program is at:
.RS
.I http://groups.google.com/group/tcpflow-users
.RE
.SH "SEE ALSO"
tcpdump(1), nit(4P), bpf(4), pcap(3), pcap-savefile(5), pcap-filter(7)