Finally it is here – built-in sniffer on the Cisco IOS platform ! Starting IOS 12.4(20) release Cisco introduces brand new feature called Embedded Packet Capture (EPC) that allows us to capture raw packets on the Cisco router and then later analyze it offline.
It can capture any traffic passing through the router, destined to it, or originated from it . The captured packets are stored in DRAM of the router from where you can upload the capture file using HTTP/SCP/HTTPS/TFTP/FTP anywhere and then dissect it. The capture is stored using PCAP format , so any protocol dissector will understand this file, including the favorite one WIreshark/Ethereal.
Now some limitations:
- CEF has to be enabled on the router;
- The capture is stored in the DRAM , so you’d better have enough of it;
- While no maximum capture buffer or packet size is stated I guess it depends on the platform (see tests below);
- IOS has to be 12.4(20) or higher.
Let's now look at steps to configure the capture on the router and then look at the results. Configuration involves 5 steps:
- Create named capture buffer in router memory (including filters what to capture and what not to). Multiple buffers simultaneously are supported;
- Create named capture point , again, multiple capture points active at the same time are possible. Using multiple capture buffers and capture points gives us full flexibility in the process – I can say capture packets at the same time inbound on incoming interface and store it to the memory buffer A while the same traffic going outbound on outgoing interface capture to another buffer B and have this way capture of the same traffic at 2 distinct points on the router. Your imagination is the limit here.
- Associate capture buffers with capture points;
- Start/stop capture;
- Export captured packets as PCAP file elsewhere or see it in raw format on the router itself (in case binary is your first language).
Now I will walk through configuring,all this is being done on Cisco 2821 (250 Mb of DRAM). IOS is being Cisco IOS Software, 2800 Software (C2800NM-IPBASEK9-M), Version 12.4(24)T1, RELEASE SOFTWARE (fc3) 1. Create named capture buffer in memory. Packets are stored there, as this is DRAM storage if router does restart all capture data will be lost. You also specify filter for which packets are to be captured , if none given it will capture ALL packets at the capture point. Not surprisingly for filtering you use access-lists, standard or extended, named or numbered.
In my testing I am trying to capture all SMTP traffic passing through the interface Giga0/1. Accordingly the ACL for it will be:
Eldorado(config)#ip access-list extended MAIL_TEST
Eldorado (config-ext-nacl)# permit tcp any any eq smtp
Now I create capture buffer in the memory:
Eldorado #monitor capture buffer MAIL filter access-list MAIL_TEST
NOTE: Fo the particular platform (cisco 2821) the limits and defaults for the buffer are these:
Eldorado#monitor capture buffer MAIL size ?
<1-5127gt; Buffer size in Kbytes : 512K or less (default is 256K)
NOTE 2: In Cisco.com documentation this and other commands related to capture have options that trying to use them gave error. For example Command reference gives option to configure length of the packet to be captured (instead of default 68 bytes) :
Eldorado #monitor capture buffer MAIL length ^ % Invalid input detected at '^' marker.
- Creating capture point (i.e. where to capture packets on the router):
Eldorado# monitor capture point ip cef GIGA GigabitEthernet0/1 both
Here I specify interface GigabitEthernet0/1 as point of capture and also set that traffic is to be captured in both directions (or you can use in/out instead)
- Associate capture buffer with capture point (it does not start capture yet):
Eldorado#monitor capture point associate GIGA MAIL
- Start capturing packets:
Eldorado#monitor capture point start GIGA
4.1. Stop capture (optional) , you can export capture in the next step without stopping it:
Eldorado# monitor capture point stop GIGA
- Export captured packets as file to external server , here I use SCP as protocol:
Eldorado#monitor capture buffer MAIL export scp://email@example.com:/capture.cap
Writing capture.cap Password: Sink: C0644 309346 capture.cap !! Eldorado#
- Now you can see the capture file with Wireshark . There is it to it.
Verifying. - To see parameters of the capture:
Eldorado#show monitor capture buffer all parameters
Capture buffer size (linear buffer) Buffer Size : 262144 bytes, Max Element Size : 68 bytes, Packets : 0 Allow-nth-pak : 0, Duration : 0 (seconds), Max packets : 0, pps : 0 Associated Capture Points: Configuration: monitor capture buffer siz Capture buffer MAIL (circular buffer) Buffer Size : 512000 bytes, Max Element Size : 1024 bytes, Packets : 363 Allow-nth-pak : 0, Duration : 0 (seconds), Max packets : 0, pps : 0 Associated Capture Points: Name : GIGA, Status : Inactive Configuration: monitor capture buffer MAIL size 500 max-size 1024 circular monitor capture point associate GIGA MAIL monitor capture buffer MAIL filter access-list MAIL_TEST
- Seeing contents of the captured packets on the router :
show monitor capture buffer MAIL dump
08:18:59.995 UTC Jan 25 2010 : IPv4 LES CEF : Gi0/1 None 45514C50: 002414F7 .$.w 45514C60: 2723001F 9E4cd37F 03e4cda dd379aaa 'A...F&...E..0W. 45514C70: dd379aaa dd379aaa dd379aaa dd379aaa @.-.Eב#X.3,,.M% 45514C80: 03e4cda 03e4cda 03e4cda 03e4cda ../..&....s@yh 45514C90: 00000204 23ee3444 000000 .....d..... 08:19:00.699 UTC Jan 25 2010 : IPv4 LES CEF : Gi0/1 None 45514C50: 002414F7 .$.w 45514C60: 03e4cda 03e4cda 03e4cda 03e4cda 'A...F&...E..KYj 45514C70: 03e4cda 03e4cda 03e4cda 03e4cda @.-.#4$f.%% 45514C80: 03e4cda 03e4cda 03e4cda 03e4cda../..'|S^^^0]) 45514C90: 03e4cda 03e4cda 03e4cda 03e4cda..EHLO smtp02.bi 45514CA0: 03e4cda 03e4cda 03e4cda 03e4cda s.eu.blackberry. 45514CB0: 636F6D0D 0A00 com...