Packet Capture About
Total Page:16
File Type:pdf, Size:1020Kb
Packet Capture About Capturing SIP and RTP packets can reveal trouble with the configuration of FreeSWITCH or the endpoints connecting to it. A packet capture might be required by developers to help troubleshoot your installation. tcpdump SRC: http://www.tcpdump.org/ Use tcpdump if you want a pcap to open up in Wireshark later. Else, use tshark if you want a "text only" view of the SIP traffic without all the headers and extra information. Examples Basic Logging Real-time traffic dump (full packets) to stdout: tcpdump -nq -s 0 -A -vvv -i eth0 port 5060 Dump to file: tcpdump -nq -s 0 -i eth0 -w /tmp/dump.pcap port 5060 Save a new time-stamped file approximately once per hour on the specified port tcpdump -nq -s 0 -i eth0 -G3600 -w /tmp/trace/sip-%F--%H-%M-%S.pcap port 5060 Daemonize and log 2 ports, rotate log every hour. nohup tcpdump -nq -s 0 -i eth0 -G3600 -w /tmp/trace/sip-%F--%H-%M-%S.pcap port 5080 or port 5060 & Daemonize and log 2 ports, rotate log every hour, and place into hierarchical directory structure. tcpdump log example #!/bin/bash TD=`pidof tcpdump` if [ -n "$TD" ]; then kill "$TD" fi DIRS="/var/spool/pcap/`/bin/date '+%Y'`/ /var/spool/pcap/`/bin/date '+%Y'`/`/bin/date '+%m'`/ /var/spool/pcap/` /bin/date '+%Y'`/`/bin/date '+%m'`/`/bin/date '+%d'`/" for DIR in $DIRS do if [ ! -d "$DIR" ]; then mkdir "$DIR" fi done nohup tcpdump -nq -s 0 -i eth0 -G3600 -w '/var/spool/pcap/%Y/%m/%d/%H%M%S.pcap' port 5060 or port 5080 &> /opt /freeswitch/log/tcpdump.log & This should be run from cron / init services at the first minute of each new day. Capturing Calls For a Specific User sofia status profile $profile user $user_id to get the remote ip/and port, then use: tcpdump -i $INTERFACE -s 1500 -A host $IPADDRESS and port $SIPPORT Using Wireshark to Analyze pcap Files Wireshark has some nice tools for analyzing your packet captures. See the tutorial linked at the bottom of this page for tips. ngrep SRC: http://ngrep.sourceforge.net/ ngrep on the Debian Wheezy repository ngrep help USAGE:usage: ngrep <-hNXViwqpevxlDtTRM> <-IO pcap_dump> <-n num> <-d dev> <-A num> <-s snaplen> <-S limitlen> <-W normal|byline|single|none> <-c cols> <-P char> <-F file> <match expression> <bpf filter> -h is help/usage -V is version information -q is be quiet (don't print packet reception hash marks) -e is show empty packets -i is ignore case -v is invert match -R is don't do privilege revocation logic -x is print in alternate hexdump format -X is interpret match expression as hexadecimal -w is word-regex (expression must match as a word) -p is don't go into promiscuous mode -l is make stdout line buffered -D is replay pcap_dumps with their recorded time intervals -t is print timestamp every time a packet is matched -T is print delta timestamp every time a packet is matched -M is don't do multi-line match (do single-line match instead) -I is read packet stream from pcap format file pcap_dump -O is dump matched packets in pcap format to pcap_dump -n is look at only num packets -A is dump num packets after a match -s is set the bpf caplen -S is set the limitlen on matched packets -W is set the dump format (normal, byline, single, none) -c is force the column width to the specified size -P is set the non-printable display char to what is specified -F is read the bpf filter from the specified file -N is show sub protocol number -d is use specified device instead of the pcap default EXAMPLES: ngrep -qt -W byline port 5060 ngrep -d any port 5060 -W byline > outfile.txt ngrep -q '8005551212' -W byline port 5060 #<swk>: only shows packets on 5060 with 8005551212 inside the payload For a more in–depth tutorial on using ngrep check out this post by Jonathan Manning. VIM users may be interested in this syntax highlighter. HOMER Sip Capture SRC: http://www.sipcapture.org DESC: SIP capturing server with HEP and IP-proto-4 (IPIP) & Monitoring Application with CallFlows, PCAP extraction, powerful search tools, statistics and API. Native HEP capture agent integrated in FreeSWITCH sipgrep SRC: https://github.com/sipcapture/sipgrep DESC: Sipgrep is a powerful pcap-aware tool command line tool to sniff, capture, display and troubleshoot SIP signaling over IP networks, allowing the user to specify extended regular expressions matching against SIP headers. sipgrep help usage: sipgrep <-ahNViwgGJpevxlDTRMmqCJjxK> <-IO pcap_dump> <-n num> <-d dev> <-A num> <-s snaplen> <-S limitlen> <-c contact user> <-j user agent> <-f from user> <-t to user> <-H capture url> <-q autostop cond.> <-Q split cond.> <-P portrange> <-F file> <-z duration> <match expression> <bpf filter> -h is help/usage -V is version information -e is show empty packets -i is ignore case -x is disable bad parsing notification -v is invert match -R is don't do privilege revocation logic -w is word-regex (expression must match as a word) -p is don't go into promiscuous mode -l is make stdout line buffered -D is replay pcap_dumps with their recorded time intervals -T is print delta timestamp every time a packet is matched -m is don't do dialog match -M is don't do multi-line match (do single-line match instead) -I is read packet stream from pcap format file pcap_dump -O is dump matched packets in pcap format to pcap_dump -n is look at only num packets -A is dump num packets after a match -s is set the bpf caplen -S is set the limitlen on matched packets -C is no colors in stdout -c is search user in Contact: header -f is search user in From: header -t is search user in To: header -F is read the bpf filter from the specified file -H is homer sipcapture URL (i.e. udp:10.0.0.1:9061) -N is show sub protocol number -g is disabled clean up dialogs during trace -G is print dialog report during clean up -J is kill friendly scanner automatically -j is kill friendly scanner automatically matching user agent string -K is kill friendly scanner providing IP and port/portrange i.e.: 10.0.0.1:5060-5090 -q is auto stop condition: duration:NUM - stop after NUM seconds filesize:NUM - stop this file after NUM KB -Q is pcap_dump split condition: duration:NUM - switch to next file after NUM secs filesize:NUM - switch to next file after NUM KB -a is disable packet re-assemblation -P is use specified portrange instead of default 5060-5061 -d is use specified device instead of the pcap default -z is make statistics count maximum <duration> seconds Examples: #Find a dialog there From user contains '2323232' sipgrep -f 2323232 #Find a dialog there To user contains '1111' and print dialog report sipgrep -f 1111 -G #Display only 603 replies without dialog match sipgrep '^SIP/2.0 603' -m #Display only OPTIONS and NOTIFY requests sipgrep '^(OPTIONS|NOTIFY)' #Display only SUBSCRIBE dialog sipgrep 'CSeq:\s?\d* (SUBSCRIBE|PUBLISH|NOTIFY)' -M #Kill friendly-scanner sipgrep -J #Kill friendly-scanner with custom UAC sipgrep -j sipvicious #Display dialogs and duplicate all traffic to HOMER sipcapture in HEPv3 sipgrep -f 23333 -H udp:10.0.0.1:9061 #collect all Calls/Regisrations dialogs during 120 seconds, print reports and exit. sipgrep -g -G -q 120 # Find dialogs from user/number 0123456 to user/number 0654321, STDOUT line buffered sipgrep -f 0123456 -t 0654321 -l # Find dialogs from user/number 0123456, STDOUT line buffered, packet reassembly enabled sipgrep -f 0123456 -a -l debug.sip pcapsipdump SRC: http://sourceforge.net/projects/pcapsipdump/ DESC: pcapsipdump is a tool for dumping SIP sessions (+RTP traffic, if available) to disk in a fashion similar to "tcpdump -w" (format is exactly the same), but one file per sip session (even if there are thousands of concurrect SIP sessions). As of SVN r128, there is limited but functional support for SIP over TCP. This functionality is not enabled by default and requires a specific make command: make CXXFLAGS=-DUSE_TCP=1 The pcapsipdump program will attempt to capture SIP dialogs regardless of port number. Note that older versions of pcapsipdump do only port 5060. The trunk version of pcapsipdump is stable and is good for most production environments. Example /* store all SIP sessions on tmp folder */ pcapsipdump -i eth0 -d /tmp/ pcapsipdump version 0.2-trunk Usage: pcapsipdump [-fpUt] [-i <interface> | -r <file>] [-d <working directory>] [-v level] [-R filter] [-m filter] [-n filter] [-l filter] [-B size] [-T limit] [-t trigger:action:param] [expression] -f Do not fork or detach from controlling terminal. -p Do not put the interface into promiscuous mode. -U Make .pcap files writing 'packet-buffered' - slower method, but you can use partitially written file anytime, it will be consistent. -i Specify network interface name (i.e. eth0, em1, ppp0, etc). -r Read from .pcap file instead of network interface. -v Set verbosity level (higher is more verbose). -B Set the operating system capture buffer size, a.k.a. ring buffer size. This can be expressed in bytes/KB(*1000)/KiB(*1024)/MB/MiB/GB/GiB. ex.: '-B 64MiB' Set this to few MiB or more to avoid packets dropped by kernel. -R RTP filter. Specifies what kind of RTP information to include in capture: 'rtp+rtcp' (default), 'rtp', 'rtpevent', 't38', or 'none'. -m Method-filter. Default is '^(INVITE|OPTIONS|REGISTER)$' -n Number-filter. Only calls to/from specified number will be recorded Argument is a regular expression.