ciscoconfparse2是一款针对思科IOS风格配置的安全审计工具,该工具是一个Python库,可以帮助广大研究人员快速解析、审计、查询、构建和修改 Arista / Cisco / Juniper / Palo Alto / F5 配置。
ciscoconfparse2可以帮助您快速回答有关 Cisco 配置的以下问题:
1、哪些接口已关闭?
2、哪些接口处于中继模式?
3、每个接口分配了什么地址和子网掩码?
4、哪些接口缺少关键命令?
5、此配置是否缺少标准配置行?
它可以帮助您:
1、审核现有的路由器 / 交换机 / 防火墙 / WLC 配置;
2、修改现有配置;
3、构建新配置;
一般来说,该库会检查 IOS 样式的配置并将其分解为一组相互关联的父/子关系。您可以针对这些关系执行复杂的查询:
Python 3
attrs
passlib
tomlkit
dnspython
hier_config
PyYAML
pyparsing
typeguard
loguru
由于该工具基于Python 3.7开发,因此我们首先需要在本地设备上安装并配置好最新版本的Python 3.7+环境。
接下来,广大研究人员可以直接使用下列命令将该项目源码克隆至本地:
git clone git://github.com/mpenning/ciscoconfparse2
然后切换到项目目录中,执行安装脚本完成工具安装:
cd ciscoconfparse2/
python -m pip install .
或者直接使用pip完成安装:
python -m pip install ciscoconfparse2
假设您的配置中有一堆接口。如何找到哪些接口已关闭?
一种方法是手动读取整个 Cisco IOS-XE 配置,另一个选项是ciscoconfparse2:
> from ciscoconfparse2 import CiscoConfParse
>
>>> parse = CiscoConfParse('/path/to/config/file')
'interface', 'shutdown']) > intf_cmds = parse.find_parent_objects([
>
>>> shut_intf_names = [" ".join(cmd.split()[1:]) for cmd in intf_cmds]
>
>>> shut_intf_names
['GigabitEthernet1/5', 'TenGigabitEthernet2/2', 'TenGigabitEthernet2/3']
>
假设您有以下 IOS-XR bgp 配置:
router bgp 65534
bgp router-id 10.0.0.100
address-family ipv4 unicast
!
neighbor 10.0.0.37
remote-as 64000
route-policy EBGP_IN in
route-policy EBGP_OUT out
!
neighbor 10.0.0.1
remote-as 65534
update-source Loopback0
route-policy MANGLE_IN in
route-policy MANGLE_OUT out
next-hop-self
!
neighbor 10.0.0.34
remote-as 64000
route-policy EBGP_IN in
route-policy EBGP_OUT out
您可以使用此脚本快速生成 EBGP 对等体的列表:
from ciscoconfparse2 import CiscoConfParse
parse = CiscoConfParse('/path/to/config/file') # Or read directly from a list of strings
# Get all neighbor configuration branches
branches = parse.find_object_branches(('router bgp',
'neighbor',
'remote-as'))
# Get the local BGP ASN
bgp_cmd = branches[0][0]
local_asn = bgp_cmd.split()[-1]
# Find EBGP neighbors for any number of peers
for branch in branches:
neighbor_addr = branch[1].split()[-1]
remote_asn = branch[2].split()[-1]
if local_asn != remote_asn:
print("EBGP NEIGHBOR", neighbor_addr)
当你运行它时,你会看到:
python example.py
EBGP NEIGHBOR 10.0.0.37
EBGP NEIGHBOR 10.0.0.34
$
本项目的开发与发布遵循GPL-3.0开源许可协议。
ciscoconfparse2:
https://github.com/mpenning/ciscoconfparse2
原文始发于微信公众号(FreeBuf):ciscoconfparse2:一款针对思科IOS风格配置的安全审计工具
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论