Yuri Slobodyanyuk Blog on Information Security 2024年09月12日
Capture packets at IOS Cisco router or finally we have a sniffer
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

Cisco IOS 12.4(20)版本引入Embedded Packet Capture功能,可在路由器上捕获数据包并离线分析,文章介绍了其配置步骤、限制及应用情况。

🎉Cisco IOS平台的Embedded Packet Capture(EPC)功能可捕获通过路由器的任何流量,并以PCAP格式存储在DRAM中,方便后续离线分析,且任何协议分析器都能识别该文件。

💡配置EPC涉及5个步骤,包括在路由器内存中创建命名捕获缓冲区(可设置过滤器)、创建命名捕获点(可同时多个活跃)、将捕获缓冲区与捕获点关联、启动/停止捕获以及将捕获的数据包导出为PCAP文件或在路由器上以原始格式查看。

🚧该功能存在一些限制,如CEF须在路由器上启用、捕获存储在DRAM中需有足够空间、未明确最大捕获缓冲区或数据包大小(可能取决于平台)、IOS须为12.4(20)或更高版本。

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 andstore it to the memory buffer A while the same traffic going outbound on outgoing interface capture to another buffer B and have thisway 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://rumba@216.163.142.1:/capture.cap

Writing capture.capPassword: Sink: C0644 309346 capture.cap!!Eldorado#

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

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... 

Follow me on https://www.linkedin.com/in/yurislobodyanyuk/ not to miss what I publish on Linkedin, Github, blog, and more.

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

Cisco IOS Embedded Packet Capture 网络分析 数据包捕获
相关文章