man: netsniff-ng: include known bug from docs
[netsniff-ng.git] / man / netsniff-ng.8
blob6f576e87c119091f27d2e107f3a98ef21a77ca06
1 .\" netsniff-ng - the packet sniffing beast
2 .\" Copyright 2013 Daniel Borkmann.
3 .\" Subject to the GPL, version 2.
5 .TH NETSNIFF-NG 8 "03 March 2013" "Linux" "netsniff-ng toolkit"
6 .SH NAME
7 netsniff-ng \- the packet sniffing beast
9 .SH SYNOPSIS
11 \fB netsniff-ng\fR { [\fIoptions\fR] [\fIfilter-expression\fR] }
13 .SH DESCRIPTION
15 netsniff-ng is a fast, minimal tool to i) analyze network packets, ii) capture
16 pcap files, iii) replay pcap files or iv) redirect traffic between interfaces
17 with the help of zero-copy packet(7) sockets. netsniff-ng uses both, Linux
18 specific RX_RING and TX_RING interfaces to perform zero-copy, that is, to avoid
19 copies and system call overhead between kernel and user address space. At the
20 time, we started hacking on netsniff-ng, the pcap(3) library did not use this
21 zero-copy facility.
23 netsniff-ng is Linux specific only, meaning there is no support for other
24 operating systems, thus we can keep the code footprint quite minimal and to
25 the point. Linux' packet(7) sockets and its RX_RING and TX_RING interfaces
26 bypass the normal packet processing path through the networking stack. Thus,
27 this is the fastest one can get out of the box in terms of capturing or
28 transmission performance from user space, without having to load unsupported
29 or non-mainline third-party kernel modules. We explicitly refuse to build
30 netsniff-ng on top of ntop/PF_RING. Not because we do not like it (we do find
31 it interesting), but because of the fact that it is not part of the mainline
32 kernel. Therefore, the ntop project has to maintain/sync out-of-tree drivers
33 to adapt them to their DNA. Eventually, we went for untainted Linux kernel,
34 since its code has a higher rate of reviews, maintenance, security and bug
35 fixes.
37 netsniff-ng also supports early packet filtering in the kernel. It has support
38 for low-level and high-level packet filters that are translated into Berkeley
39 Packet Filter instructions.
41 netsniff-ng can capture pcap files in several different pcap formats that
42 are interoperable with other tools. It has different pcap I/O methods supported
43 (scatter-gather, mmap(2), read(2)/write(2)) for efficient to-disc capturing.
44 netsniff-ng is also able to rotate pcap files based on data size or time
45 intervals, thus, making it a useful backend tool for subsequent traffic
46 analysis.
48 netsniff-ng itself also supports analysis, dumping or replay of raw 802.11
49 frames. For online or offline analysis netsniff-ng has a built-in packet
50 dissector for currently 802.3 (Ethernet), 802.11* (WLAN), ARP, MPLS, 802.1Q
51 (VLAN), 802.1QinQ, LLDP, IPv4, IPv6, ICMPv4, ICMPv6, IGMP, TCP and UDP,
52 including GeoIP location analysis. Since netsniff-ng does not establish any
53 state or reassembly during packet dissection, its memory footprint is quite
54 low, thus, making netsniff-ng quite efficient for offline analysis of large
55 pcap files as well.
57 .SH OPTIONS
59 .SS -i <dev|pcap|->, -d <dev|pcap|->, --in <dev|pcap|->, --dev <dev|pcap|->
60 Defines an input device, that can either be a networking device, a pcap file
61 or stdin (``-''). In case of a pcap file, the pcap type (``-D'' option) is
62 determined automatically by the pcap file magic. In case of stdin, it is
63 assumed that the input stream is a pcap file.
65 .SS -o <dev|pcap|dir|cfg|->, --out <dev|pcap|dir|cfg|->
66 Defines the output device, that can either be a networking device, a pcap file,
67 a folder, a trafgen(8) configuration file or stdout (``-''). In case of a pcap
68 file, that should not have the default pcap type (0xa1b2c3d4), the additional
69 option ``-T'' must be provided. If a directory is given, then, instead of a
70 single pcap file, multiple pcap files are generated with rotation based on
71 maximum file size or a given interval (``-F'' option). A trafgen configuration
72 file can currently only be specified if the input device is a pcap file. If
73 stdout is given as a device, then a trafgen configuration will be written to
74 stdout if the input device is a pcap file, or a pcap file if the input device
75 is a networking device.
77 .SS -f, --filter <bpf-file|expr>
78 Specifies to not dump all traffic, but to filter the network packet haystack.
79 As a filter, either a bpfc(8) compiled file can be passed as a parameter or
80 a tcpdump(1)-like filter expression in quotes. For details regarding the
81 bpf-file have a look at bpfc(8), for details regarding a tcpdump(1)-like filter
82 have a look at section ``filter example'' or at pcap-filter(7). A filter
83 expression may also be passed to netsniff-ng without option ``-f'' in case
84 there is no subsequent option following after the command-line filter expression.
86 .SS -t, --type <type>
87 This defines some sort of filtering mechanisms in terms of addressing. Possible
88 values for type are ``host'' (to us), ``broadcast'' (to all), ``multicast'' (to
89 group), ``others'' (promiscuous mode) or ``outgoing'' (from us).
91 .SS -F, --interval <size|time>
92 If the output device is a folder, with ``-F'' it is possible to define the pcap
93 file rotation interval either in terms of size or time. Thus, when the interval
94 limit has been reached, a new pcap file will be started. As size parameter, the
95 following values are possible ``<num>KiB/MiB/GiB'' while as a time parameter
96 it can be ``<num>s/sec/min/hrs''.
98 .SS -J, --jumbo-support
99 On default netsniff-ng's ring buffer frames are of a fixed size of 2048 bytes.
100 This means that if you're expecting jumbo frames or even super jumbo frames to
101 pass your line, then you need to enable support for that with the help of this
102 option. However, this has the disadvantage of a performance regression and a
103 bigger memory footprint for the ring buffer.
105 .SS -R, --rfraw
106 In case the input or output networking device is a wireless device, it is
107 possible with netsniff-ng to turn this into monitor mode and create a mon<X>
108 device that netsniff-ng will be listening on instead of wlan<X>, for instance.
109 This enables netsniff-ng to analyze, dump, or even replay raw 802.11 frames.
111 .SS -n <0|uint>, --num <0|uint>
112 Process a number of packets and then exit. If the number of packets is 0, then
113 this is equivalent to infinite packets resp. processing until interrupted.
114 Otherwise, a number given as an unsigned integer will limit processing.
116 .SS -P <name>, --prefix <name>
117 When dumping pcap files into a folder, a file name prefix can be defined with
118 this option. If not otherwise specified, the default prefix is ``dump-'' followed
119 by a unix timestamp.
121 .SS -T <pcap-magic>, --magic <pcap-magic>
122 Specify a pcap type for storage. Different pcap types with their various meta
123 data capabilities are shown with option ``-D''. If not otherwise specified, the
124 pcap-magic 0xa1b2c3d4, also known as a standard tcpdump-capable pcap format, is
125 used. Pcap files with swapped endianess are also supported.
127 .SS -D, --dump-pcap-types
128 Dump all available pcap types with their capabilities and magic numbers that
129 can be used with option ``-T'' and exit.
131 .SS -B, --dump-bpf
132 If a Berkeley Packet Filter is given, e.g. via option ``-f'', then dump the BPF
133 disassembly to stdout during ring setup. This only serves for informative or
134 verification purposes.
136 .SS -r, --rand
137 If the input and output device are both networking devices, then this option will
138 randomize packet order in the output ring buffer.
140 .SS -M, --no-promisc
141 The networking interface will not be put into promiscuous mode. On default,
142 promiscuous mode is turned on.
144 .SS -A, --no-sock-mem
145 On startup (and shutdown), netsniff-ng is trying to increase socket read and
146 write buffers if appropriate. This option will prevent netsniff-ng from doing
147 that.
149 .SS -m, --mmap
150 Use mmap(2) as pcap file I/O. This is default in case of replaying pcap files.
152 .SS -G, --sg
153 Use scatter-gather as pcap file I/O. This is default in case when capturing
154 pcap files.
156 .SS -c, --clrw
157 Use slower read(2)/write(2) I/O. This is not the default case anywhere, but in
158 some situations it could be preferred as it has a lower latency on write-back
159 to disc.
161 .SS -S <size>, --ring-size <size>
162 Manually define the RX_RING resp. TX_RING size in ``<num>KiB/MiB/GiB''. On
163 default the size is being determined based on the network connectivity rate.
165 .SS -k <uint>, --kernel-pull <uint>
166 Manually define 
168 .SS -b <cpu>, --bind-cpu <cpu>
169 Pin netsniff-ng to a specific CPU and also pin resp. migrate the NIC's IRQ
170 CPU affinity to this CPU. This option should be preferred in combination with
171 ``-s'' in case a middle till high packet rate is expected.
173 .SS -u <uid>, --user <uid> resp. -g <gid>, --group <gid>
174 After ring setup drop privileges to a non-root user/group combination.
176 .SS -H, --prio-high
177 Set this process as a high priority process in order to achieve a higher
178 scheduling rate resp. CPU time. This is however not default setting, since
179 it could lead to starvation of other processes, e.g. low priority kernel
180 threads.
182 .SS -Q, --notouch-irq
183 Do not reassign the NIC's IRQ CPU affinity settings.
185 .SS -s, --silent
186 Do not enter the packet dissector at all and do not print any packet information
187 to the terminal. Just shut up and be silent. This option should be preferred in
188 combination with pcap recording or replay, since it will not flood your terminal
189 which causes a significant performance regression.
191 .SS -q, --less
192 Print a less verbose one-line information for each packet to the terminal.
194 .SS -X, --hex
195 Only dump packets in hex format to the terminal.
197 .SS -l, --ascii
198 Only display ASCII prinable characters.
200 .SS -U, --update
201 If geographical IP locationing should be used, the built-in database update
202 mechanism will be invoked to get Maxmind's latest database. To configure
203 search locations for databases, the file /etc/netsniff-ng/geoip.conf contains
204 possible addresses. Thus, to save bandwidth or for mirroring Maxmind's
205 databases (to bypass their traffic limit policy), different hosts or IP
206 addresses can be placed into geoip.conf, separated by a newline.
208 .SS -V, --verbose
209 Be more verbose during startup, i.e. show detailled ring setup information.
211 .SS -v, --version
212 Show versioning information.
214 .SS -h, --help
215 Show user help.
217 .SH USAGE EXAMPLE
219 .SS netsniff-ng
220 The most simple command is to just run ``netsniff-ng''. This will start
221 listening on all available networking devices in promiscuous mode and dump
222 the packet dissector output to the terminal. No files will be recorded.
224 .SS  netsniff-ng --in eth0 --out dump.pcap -s -T 0xa1e2cb12 -b 0 tcp or udp
225 Capture TCP or UDP traffic from the networking device eth0 into the pcap file
226 named dump.pcap, which has netsniff-ng specific pcap extensions (see
227 ``netsniff-ng -D'' for capabilities). Also, do not print the content to the
228 terminal and pin the process and NIC IRQ affinity to CPU 0. The pcap write
229 method is scatter-gather I/O.
231 .SS  netsniff-ng --in wlan0 --rfraw --out dump.pcap --silent --bind-cpu 0
232 Put the wlan0 device into monitoring mode and capture all raw 802.11 frames
233 into the file dump.pcap. Do not dissect and print the content to the terminal
234 and pin the process and NIC IRQ affinity to CPU 0. The pcap write method is
235 scatter-gather I/O.
237 .SS  netsniff-ng --in dump.pcap --mmap --out eth0 -k1000 --silent --bind-cpu 0
238 Replay the pcap file dump.pcap which is read through mmap(2) I/O and send
239 the packets out via the eth0 networking device. Do not dissect and print the
240 content to the terminal and pin the process and NIC IRQ affinity to CPU 0.
241 Also trigger the kernel every 1000us to traverse the TX_RING instead of every
242 10us. Note that the pcap magic type is detected automatically from the pcap
243 file header.
245 .SS  netsniff-ng --in eth0 --out eth1 --silent --bind-cpu 0 --type host -r
246 Redirect network traffic from the networking device eth0 to eth1 for traffic
247 that is destined for our host, thus ignore broadcast, multicast and promiscuous
248 traffic. Randomize the order of packets for the outgoing device and do not
249 print any packet contents to the terminal. Also, pin the process and NIC IRQ
250 affinity to CPU 0.
252 .SS  netsniff-ng --in team0 --out /opt/probe/ -s -m -J --interval 100MiB -b 0
253 Capture on an aggregated team0 networking device and dump packets into multiple
254 pcap files that are split into 100MiB each. Use mmap(2) I/O as a pcap write
255 method, enable support for super jumbo frames up to 64KB, and do not print
256 the captured data to the terminal. Pin netsniff-ng to and NIC IRQ affinity to
257 CPU 0. The default pcap magic type is 0xa1b2c3d4 (tcpdump-capable pcap).
259 .SS  netsniff-ng --in vlan0 --out dump.pcap -c -u `id -u bob` -g `id -g bob`
260 Capture network traffic on device wlan0 into a pcap file called dump.pcap
261 by using normal read(2), write(2) I/O for the pcap file (slower but less
262 latency). Also, after setting up the RX_RING for capture, drop privileges
263 from root to the user/group ``bob''. Invoke the packet dissector and print
264 packet contents to the terminal for further analysis.
266 .SS  netsniff-ng --in any --filter http.bpf -B --jumbo-support --ascii -V
267 Capture from all available networking interfaces and install a low-level
268 filter that was previously compiled by bpfc(8) into http.bpf in order to
269 filter HTTP traffic. Enable super jumbo frame support and only print
270 human readable packet data to the terminal, and also be more verbose during
271 setup phase. Moreover, dump a BPF disassembly of http.bpf.
273 .SS  netsniff-ng --in dump.pcap --out dump.cfg --silent
274 Convert the pcap file dump.pcap into a trafgen(8) configuration file dump.cfg.
275 Do not print pcap contents to the terminal.
277 .SS netsniff-ng -i dump.pcap -f beacon.bpf -o -
278 Convert the pcap file dump.pcap into a trafgen(8) configuration file and write
279 it to stdout. However, do not dump all of its content, but only the one that
280 passes the low-level filter for raw 802.11 from beacon.bpf. The BPF engine
281 here is invoked in user space inside of netsniff-ng, so Linux extensions
282 are not available.
284 .SS cat foo.pcap | netsniff-ng -i - -o -
285 Read a pcap file from stdin and convert it into a trafgen(8) configuration
286 file to stdout.
288 .SH CONFIG FILES
290 Under /etc/netsniff-ng/ there are the following files stored that are used
291 by netsniff-ng and can be extended if wished:
293     * oui.conf - OUI/MAC vendor database
294     * ether.conf - Ethernet type descriptions
295     * tcp.conf - TCP port/services map
296     * udp.conf - UDP port/services map
298 .SH FILTER EXAMPLE
300 netsniff-ng supports both, low-level and high-level filters that are
301 attached to its packet(7) socket. Low-level filters are described in
302 the bpfc(8) man page.
304 Low-level filters can be used with netsniff-ng in the following way:
306     1. bpfc foo > bar
307     2. netsniff-ng -f bar
309 Here, foo is the bpfc program that will be translated into a netsniff-ng
310 readable ``opcodes'' file and passed to netsniff-ng through the -f option.
312 Similarly, high-level filter can be either passed through the -f option,
313 e.g. -f "tcp or udp" or at the end of all options without the ``-f''.
315 The filter syntax is the same as in tcpdump(8), which is described in
316 the man page pcap-filter(7). Just to quote some examples from pcap-filter(7):
318 .SS host sundown
319 To select all packets arriving at or departing from sundown.
321 .SS host helios and \( hot or ace \)
322 To select traffic between helios and either hot or ace.
324 .SS ip host ace and not helios
325 To select all IP packets between ace and any host except helios.
327 .SS net ucb-ether
328 To select all traffic between local hosts and hosts at Berkeley.
330 .SS gateway snup and (port ftp or ftp-data)
331 To select all ftp traffic through internet gateway snup.
333 .SS ip and not net localnet
334 To select traffic neither sourced from nor destined for local hosts (if you
335 gateway to one other net, this stuff should never make it onto your local net).
337 .SS tcp[tcpflags] & (tcp-syn|tcp-fin) != 0 and not src and dst net localnet
338 To select the start and end packets (the SYN and FIN packets) of each TCP
339 conversation that involve a non-local host.
341 .SS tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)
342 To select all IPv4 HTTP packets to and from port 80, i.e. print only packets
343 that contain data, not, for example, SYN and FIN packets and ACK-only packets.
344 (IPv6 is left as an exercise for the reader.)
346 .SS gateway snup and ip[2:2] > 576
347 To select IP packets longer than 576 bytes sent through gateway snup.
349 .SS ether[0] & 1 = 0 and ip[16] >= 224
350 To select IP broadcast or multicast packets that were not sent via Ethernet
351 broadcast or multicast.
353 .SS icmp[icmptype] != icmp-echo and icmp[icmptype] != icmp-echoreply
354 To select all ICMP packets that are not echo requests/replies (i.e., not
355 ping packets).
357 .SH NOTE
358 For introducing bit errors, delays with random variation and more
359 while replaying pcaps, make use of tc(8) with its disciplines such
360 as netem.
362 netsniff-ng does only some basic, architecture generic tuning on
363 startup. If you are considering to do high performance capturing,
364 you need to carefully tune your machine, hardware and software-wise.
365 Simply letting netsniff-ng run without thinking about your underlying
366 system might not necessarily give you the desired performance. Note
367 that tuning your system is always a tradeoff and fine-grained
368 balancing act (e.g. throughput vs. latency). You should know what
369 you're doing!
371 One recommendation for software-based tuning is tuned(8). Besides
372 that, there are many other things to consider. Just to throw you
373 a few things that you might want to look at: NAPI networking drivers,
374 tickless kernel, I/OAT DMA engine, Direct Cache Access, RAM-based
375 file systems, multi-queues, and many more things. Also, you might
376 want to read the kernel's Documentation/networking/scaling.txt file
377 regarding technologies such as RSS, RPS, RFS, aRFS and XPS. Also
378 check your ethtool(8) settings, e.g. regarding offloading.
380 Moreover, to get a deeper understanding of netsniff-ng internals
381 and how it interacts with the Linux kernel, the kernel documentation
382 under Documentation/networking/{packet_mmap.txt, filter.txt,
383 multiqueue.txt} might be of interest.
385 How do you sniff in a switched environment? I rudely refer to dSniff's
386 documentation that says:
388 The easiest route is simply to impersonate the local gateway, stealing
389 client traffic en route to some remote destination. Of course, the traffic
390 must be forwarded by your attacking machine, either by enabling kernel IP
391 forwarding or with a userland program that acccomplishes the same
392 (fragrouter -B1).
394 Several people have reportedly destroyed connectivity on their LAN to the
395 outside world by arpspoof'ing the gateway, and forgetting to enable IP
396 forwarding on the attacking machine. Don't do this. You have been warned.
398 If you do not need to dump all possible traffic, you have to consider
399 running netsniff-ng with a BPF filter for the ingress path. For that
400 purpose, read the bpfc(8) man page.
402 Also, to aggregate multiple NICs that you want to capture on, you
403 should consider using team devices, further explained in libteam resp.
404 teamd(8).
406 The following netsniff-ng pcap magic numbers are compatible with other
407 tools, at least tcpdump or Wireshark:
409     0xa1b2c3d4 (tcpdump-capable pcap)
410     0xa1b23c4d (tcpdump-capable pcap with ns resolution)
411     0xa1b2cd34 (Alexey Kuznetzov's pcap)
413 Pcap files with different meta data endianess are supported by netsniff-ng
414 as well.
416 .SH BUGS
418 When replaying pcap files, the timing information from the pcap packet
419 header is currently ignored.
421 Also, when replaying pcap files, demultiplexing traffic among multiple
422 networking interfaces does not work. Currently, it is only sent via the
423 interface that is given by the --out parameter.
425 When performing traffic capture on the Ethernet interface, the pcap file
426 is created and packets are received but without a 802.1Q header. When one
427 uses tshark, all headers are visible, but netsniff-ng removes 802.1Q
428 headers. Is that normal behavior?
430 Yes and no. The way how VLAN headers are handled in PF_PACKET sockets by the
431 kernel is somewhat ``problematic'' [1]. The problem in the Linux kernel is that
432 some drivers already handle VLAN, others not. Those who handle it can have
433 different implementations, i.e. hardware acceleration and so on. So in some
434 cases the VLAN tag is even stripped before entering the protocol stack, in
435 some cases probably not. Bottom line is that a "hack" was introduced in
436 PF_PACKET so that a VLAN ID is visible in some helper data structure that is
437 accessible from the RX_RING.
439 And then it gets really messy in the user space to artificially put the VLAN
440 header back into the right place. Not mentioning about the resulting performance
441 implications on that of all libpcap(3) tools since parts of the packet need to
442 be copied for reassembly via memmove(3).
444 A user reported the following, just to demonstrate this mess: some tests were
445 made with two machines, and it seems that results depends on the driver ...
446     AR8131:
447       ethtool -k eth0 gives "rx-vlan-offload: on"
448       - wireshark gets the vlan header
449       - netsniff-ng doesn't get the vlan header
450       ethtool -K eth0 rxvlan off
451       - wireshark gets a QinQ header even though noone sent QinQ
452       - netsniff-ng gets the vlan header
453     RTL8111/8168B:
454       ethtool -k eth0 gives "rx-vlan-offload: on"
455       - wireshark gets the vlan header
456       - netsniff-ng doesn't get the vlan header
457       ethtool -K eth0 rxvlan off
458       - wireshark gets the vlan header
459       - netsniff-ng doesn't get the vlan header
460 Even if we would agree on doing the same workaround as libpcap, we still will
461 not be able to see QinQ, for instance, due to the fact that only one VLAN tag
462 is stored in the kernel helper data structure. We think that there should be
463 a good consensus on the kernel space side about what gets transferred to the
464 userland first.
466 Update (28.11.2012): the Linux kernel and also bpfc(8) has built-in support
467 for hardware accelerated VLAN filtering, even though tags might not be visible
468 in the payload itself as reported here. However, the filtering for VLANs works
469 reliable if your NIC supports it. See bpfc(8) for an example.
471    [1] http://lkml.indiana.edu/hypermail/linux/kernel/0710.3/3816.html
473 .SH LEGAL
474 netsniff-ng is licensed under the GNU GPL version 2.0.
476 .SH HISTORY
477 .B netsniff-ng
478 was originally written for the netsniff-ng toolkit by Daniel Borkmann. Bigger
479 contributions were made by Emmanuel Roullit, Markus Amend, Tobias Klauser and
480 Christoph Jaeger. It is currently maintained by Tobias Klauser
481 <tklauser@distanz.ch> and Daniel Borkmann <dborkma@tik.ee.ethz.ch>.
483 .SH SEE ALSO
484 .BR trafgen (8),
485 .BR mausezahn (8),
486 .BR ifpps (8),
487 .BR bpfc (8),
488 .BR flowtop (8),
489 .BR astraceroute (8),
490 .BR curvetun (8)
492 .SH AUTHOR
493 Manpage was written by Daniel Borkmann.