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
|
.\" netsniff-ng - the packet sniffing beast
.\" Copyright 2013 Daniel Borkmann.
.\" Subject to the GPL, version 2.
.TH NETSNIFF-NG 8 "03 March 2013" "Linux" "netsniff-ng toolkit"
.SH NAME
netsniff-ng \- the packet sniffing beast
.SH SYNOPSIS
\fB netsniff-ng\fR { [\fIoptions\fR] [\fIfilter-expression\fR] }
.SH DESCRIPTION
netsniff-ng is a fast, minimal tool to i) analyze network packets, ii) capture
pcap files, iii) replay pcap files or iv) redirect traffic between interfaces
with the help of zero-copy packet(7) sockets. netsniff-ng uses both, Linux
specific RX_RING and TX_RING interfaces to perform zero-copy, that is, to avoid
copies and system call overhead between kernel and user address space. At the
time, we started hacking on netsniff-ng, the pcap(3) library did not use this
zero-copy facility.
netsniff-ng is Linux specific only, meaning there is no support for other
operating systems, thus we can keep the code footprint quite minimal and to
the point. Linux' packet(7) sockets and its RX_RING and TX_RING interfaces
bypass the normal packet processing path through the networking stack. Thus,
this is the fastest one can get out of the box in terms of capturing or
transmission performance from user space, without having to load unsupported
or non-mainline third-party kernel modules. We explicitly refuse to build
netsniff-ng on top of ntop/PF_RING. Not because we do not like it (we do find
it interesting), but because of the fact that it is not part of the mainline
kernel. Therefore, the ntop project has to maintain/sync out-of-tree drivers
to adapt them to their DNA. Eventually, we went for untainted Linux kernel,
since its code has a higher rate of reviews, maintenance, security and bug
fixes.
netsniff-ng also supports early packet filtering in the kernel. It has support
for low-level and high-level packet filters that are translated into Berkeley
Packet Filter instructions.
netsniff-ng can capture pcap files in several different pcap formats that
are interoperable with other tools. It has different pcap I/O methods supported
(scatter-gather, mmap(2), read(2)/write(2)) for efficient to-disc capturing.
netsniff-ng is also able to rotate pcap files based on data size or time
intervals, thus, making it a useful backend tool for subsequent traffic
analysis.
netsniff-ng itself also supports analysis, dumping or replay of raw 802.11
frames. For online or offline analysis netsniff-ng has a built-in packet
dissector for currently 802.3 (Ethernet), 802.11* (WLAN), ARP, MPLS, 802.1Q
(VLAN), 802.1QinQ, LLDP, IPv4, IPv6, ICMPv4, ICMPv6, IGMP, TCP and UDP,
including GeoIP location analysis. Since netsniff-ng does not establish any
state or reassembly during packet dissection, its memory footprint is quite
low, thus, making netsniff-ng quite efficient for offline analysis of large
pcap files as well.
.SH OPTIONS
.\" -i|-d|--dev|--in <dev|pcap|-> Input source as netdev, pcap or pcap stdin
.\" -o|--out <dev|pcap|dir|cfg|-> Output sink as netdev, pcap, directory, trafgen, or stdout
.\" -f|--filter <bpf-file|expr> Use BPF filter file from bpfc or tcpdump-like expression
.\" -t|--type <type> Filter for: host|broadcast|multicast|others|outgoing
.\" -F|--interval <size|time> Dump interval if -o is a dir: <num>KiB/MiB/GiB/s/sec/min/hrs
.\" -J|--jumbo-support Support for 64KB Super Jumbo Frames (def: 2048B)
.\" -R|--rfraw Capture or inject raw 802.11 frames
.\" -n|--num <0|uint> Number of packets until exit (def: 0)
.\" -P|--prefix <name> Prefix for pcaps stored in directory
.\" -T|--magic <pcap-magic> Pcap magic number/pcap format to store, see -D
.\" -D|--dump-pcap-types Dump pcap types and magic numbers and quit
.\" -B|--dump-bpf Dump generated BPF assembly
.\" -r|--rand Randomize packet forwarding order (dev->dev)
.\" -M|--no-promisc No promiscuous mode for netdev
.\" -A|--no-sock-mem Don't tune core socket memory
.\" -m|--mmap Mmap(2) pcap file i.e., for replaying pcaps
.\" -G|--sg Scatter/gather pcap file I/O
.\" -c|--clrw Use slower read(2)/write(2) I/O
.\" -S|--ring-size <size> Specify ring size to: <num>KiB/MiB/GiB
.\" -k|--kernel-pull <uint> Kernel pull from user interval in us (def: 10us)
.\" -b|--bind-cpu <cpu> Bind to specific CPU
.\" -u|--user <userid> Drop privileges and change to userid
.\" -g|--group <groupid> Drop privileges and change to groupid
.\" -H|--prio-high Make this high priority process
.\" -Q|--notouch-irq Do not touch IRQ CPU affinity of NIC
.\" -s|--silent Do not print captured packets
.\" -q|--less Print less-verbose packet information
.\" -X|--hex Print packet data in hex format
.\" -l|--ascii Print human-readable packet data
.SS -U, --update
If geographical IP locationing should be used, the built-in database update
mechanism will be invoked to get Maxmind's latest database. To configure
search locations for databases, the file /etc/netsniff-ng/geoip.conf contains
possible addresses. Thus, to save bandwidth or for mirroring Maxmind's
databases (to bypass their traffic limit policy), different hosts or IP
addresses can be placed into geoip.conf, separated by a newline.
.SS -V, --verbose
Be more verbose during startup, i.e. show detailled ring setup information.
.SS -v, --version
Show versioning information.
.SS -h, --help
Show user help.
.SH USAGE EXAMPLE
.SS netsniff-ng
The most simple command is to just run ``netsniff-ng''. This will start
listening on all available networking devices in promiscuous mode and dump
the packet dissector output to the terminal. No files will be recorded.
.SS netsniff-ng --in eth0 --out dump.pcap -s -T 0xa1e2cb12 -b 0 tcp or udp
Capture TCP or UDP traffic from the networking device eth0 into the pcap file
named dump.pcap, which has netsniff-ng specific pcap extensions (see
``netsniff-ng -D'' for capabilities). Also, do not print the content to the
terminal and pin the process and NIC IRQ affinity to CPU 0. The pcap write
method is scatter-gather I/O.
.SS netsniff-ng --in wlan0 --rfraw --out dump.pcap --silent --bind-cpu 0
Put the wlan0 device into monitoring mode and capture all raw 802.11 frames
into the file dump.pcap. Do not dissect and print the content to the terminal
and pin the process and NIC IRQ affinity to CPU 0. The pcap write method is
scatter-gather I/O.
.SS netsniff-ng --in dump.pcap --mmap --out eth0 -k1000 --silent --bind-cpu 0
Replay the pcap file dump.pcap which is read through mmap(2) I/O and send
the packets out via the eth0 networking device. Do not dissect and print the
content to the terminal and pin the process and NIC IRQ affinity to CPU 0.
Also trigger the kernel every 1000us to traverse the TX_RING instead of every
10us. Note that the pcap magic type is detected automatically from the pcap
file header.
.SS netsniff-ng --in eth0 --out eth1 --silent --bind-cpu 0 --type host -r
Redirect network traffic from the networking device eth0 to eth1 for traffic
that is destined to our host, thus ignore broadcast, multicast and promiscuous
traffic. Randomize the order of packets for the outgoing device and do not
print any packet contents to the terminal. Also, pin the process and NIC IRQ
affinity to CPU 0.
.SS netsniff-ng --in team0 --out /opt/probe/ -s -m -J --interval 100MiB -b 0
Capture on an aggregated team0 networkoing device and dump packets into multiple
pcap files that are split into 100MiB each. Use mmap(2) I/O as a pcap write
method, enable support for super jumbo frames up to 64KB, and do not print
the captured data to the terminal. Pin netsniff-ng to and NIC IRQ affinity to
CPU 0. The default pcap magic type is 0xa1b2c3d4 (tcpdump-capable pcap).
.SS netsniff-ng --in vlan0 --out dump.pcap -c -u `id -u bob` -g `id -g bob`
Capture network traffic on device wlan0 into a pcap file called dump.pcap
by using normal read(2), write(2) I/O for the pcap file (slower but less
latency). Also, after setting up the RX_RING for capture, drop priviledges
from root to the user/group ``bob''. Invoke the packet dissector and print
packet contents to the terminal for further analysis.
.SS netsniff-ng --in any --filter http.bpf -B --jumbo-support --ascii -V
Capture from all available networking interfaces and install a low-level
filter that was previously compiled by bpfc(8) into http.bpf in order to
filter HTTP traffic. Enable super jumbo frame support and only print
human readable packet data to the terminal, be also more verbose during
setup phase. Moreover, dump BPF disassembly from http.bpf.
.SS netsniff-ng --in dump.pcap --out dump.cfg --silent
Convert the pcap file dump.pcap into a trafgen(8) configuration file dump.cfg.
Do not print pcap contents to the terminal.
.SS netsniff-ng -i dump.pcap -f beacon.bpf -o -
Convert the pcap file dump.pcap into a trafgen(8) configuration file to
stdout. However, do not dump all of its content, but only the one that
passes the low-level filter for raw 802.11 from beacon.bpf. The BPF engine
here is invoked in user space inside of netsniff-ng, so Linux extensions
are not available.
.SS cat foo.pcap | netsniff-ng -i - -o -
Read a pcap file from stdin and convert it into a trafgen(8) configuration
file to stdout.
.SH FILTER EXAMPLE
netsniff-ng supports both, low-level and high-level filters that are
attached to its packet(7) socket. Low-level filters are described in
the bpfc(8) man page.
Low-level filters can be used with netsniff-ng in the following way:
1. bpfc foo > bar
2. netsniff-ng -f bar
Here, foo is the bpfc program that will be translated into a netsniff-ng
readable ``opcodes'' file and passed to netsniff-ng through the -f option.
Similarly, high-level filter can be either passed through the -f option,
e.g. -f "tcp or udp" or at the end of all options without the ``-f''.
The filter syntax is the same as in tcpdump(8), which is described in
the man page pcap-filter(7). Just to quote some examples from pcap-filter(7):
.SS host sundown
To select all packets arriving at or departing from sundown.
.SS host helios and \( hot or ace \)
To select traffic between helios and either hot or ace.
.SS ip host ace and not helios
To select all IP packets between ace and any host except helios.
.SS net ucb-ether
To select all traffic between local hosts and hosts at Berkeley.
.SS gateway snup and (port ftp or ftp-data)
To select all ftp traffic through internet gateway snup.
.SS ip and not net localnet
To select traffic neither sourced from nor destined for local hosts (if you
gateway to one other net, this stuff should never make it onto your local net).
.SS tcp[tcpflags] & (tcp-syn|tcp-fin) != 0 and not src and dst net localnet
To select the start and end packets (the SYN and FIN packets) of each TCP
conversation that involve a non-local host.
.SS tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)
To select all IPv4 HTTP packets to and from port 80, i.e. print only packets
that contain data, not, for example, SYN and FIN packets and ACK-only packets.
(IPv6 is left as an exercise for the reader.)
.SS gateway snup and ip[2:2] > 576
To select IP packets longer than 576 bytes sent through gateway snup.
.SS ether[0] & 1 = 0 and ip[16] >= 224
To select IP broadcast or multicast packets that were not sent via Ethernet
broadcast or multicast.
.SS icmp[icmptype] != icmp-echo and icmp[icmptype] != icmp-echoreply
To select all ICMP packets that are not echo requests/replies (i.e., not
ping packets).
.SH NOTE
For introducing bit errors, delays with random variation and more
while replaying pcaps, make use of tc(8) with its disciplines such
as netem.
netsniff-ng does only some basic, architecture generic tuning on
startup. If you are considering to do high performance capturing,
you need to carefully tune your machine, hardware and software-wise.
Simply letting netsniff-ng run without thinking about your underlying
system might not necessarily give you the desired performance. Note
that tuning your system is always a tradeoff and fine-grained
balancing act (e.g. throughput vs. latency). You should know what
you're doing!
One recommendation for software-based tuning is tuned(8). Besides
that, there are many other things to consider. Just to throw you
a few things that you might want to look at: NAPI networking drivers,
tickless kernel, I/OAT DMA engine, Direct Cache Access, RAM-based
file systems, multi-queues, and many more things. Also, you might
want to read the kernel's Documentation/networking/scaling.txt file
regarding technologies such as RSS, RPS, RFS, aRFS and XPS. Also
check your ethtool(8) settings, e.g. regarding offloading.
Moreover, to get a deeper understanding of netsniff-ng internals
and how it interacts with the Linux kernel, the kernel documentation
under Documentation/networking/{packet_mmap.txt, filter.txt,
multiqueue.txt} might be of interest.
If you do not need to dump all possible traffic, you have to consider
running netsniff-ng with a BPF filter for the ingress path. For that
purpose, read the bpfc(8) man page.
Also, to aggregate multiple NICs that you want to capture on, you
should consider using team devices, further explained in libteam resp.
teamd(8).
The following netsniff-ng pcap magic numbers are compatible with other
tools, at least tcpdump or Wireshark:
0xa1b2c3d4 (tcpdump-capable pcap)
0xa1b23c4d (tcpdump-capable pcap with ns resolution)
0xa1b2cd34 (Alexey Kuznetzov's pcap)
Pcap files with different meta data endianess are supported by netsniff-ng
as well.
.SH BUGS
When replaying pcap files, the timing information from the pcap packet
header is currently ignored.
Also, when replaying pcap files, demultiplexing traffic among multiple
networking interfaces does not work. Currently, it is only sent via the
interface that is given by the --out parameter.
.SH LEGAL
netsniff-ng is licensed under the GNU GPL version 2.0.
.SH HISTORY
.B netsniff-ng
was originally written for the netsniff-ng toolkit by Daniel Borkmann. Bigger
contributions were made by Emmanuel Roullit, Markus Amend, Tobias Klauser and
Christoph Jaeger. It is currently maintained by Tobias Klauser
<tklauser@distanz.ch> and Daniel Borkmann <dborkma@tik.ee.ethz.ch>.
.SH SEE ALSO
.BR trafgen (8),
.BR mausezahn (8),
.BR ifpps (8),
.BR bpfc (8),
.BR flowtop (8),
.BR astraceroute (8),
.BR curvetun (8)
.SH AUTHOR
Manpage was written by Daniel Borkmann.
|