python

自动化资产信息收集:CNVD 漏洞报送辅助工具

2026-07-06 #渗透测试#信息收集#python

做漏洞报送最头疼的不是挖漏洞,而是资产信息收集——ICP 备案、百度权重、子域名、开放端口、Whois……每项都要手动查一遍。这个工具把信息收集自动化,输入域名,输出一份结构化的 CSV 资产清单。


收集哪些信息

维度 数据 来源
备案信息 ICP 备案号、备案主体、备案性质 ICP 备案查询 API
SEO 信息 百度权重、关键词排名、预估流量 爱站/站长工具
域名信息 注册时间、到期时间、注册商 Whois 查询
IP 信息 服务器 IP、归属地、运营商 IP 查询 API
子域名 已知子域名列表 证书透明日志
开放端口 常见 Web 端口是否开放 端口扫描

模块一:ICP 备案查询

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import requests
from bs4 import BeautifulSoup
import re

def query_icp(domain):
"""查询域名 ICP 备案信息"""
# 使用工信部公开查询接口
url = 'https://beian.miit.gov.cn/'

# 模拟浏览器访问
session = requests.Session()
session.headers.update({
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) ...',
})

try:
# 先获取 token(工信部网站有反爬)
resp = session.get(url, timeout=15)

# 提取 authKey
auth_key = re.search(r'authKey\s*=\s*"([^"]+)"', resp.text)
if not auth_key:
return {'icp': None, 'note': '无法获取 authKey'}

# 查询备案
query_url = 'https://hlwicpfwc.miit.gov.cn/icpproject_query/api/icp'
data = {
'domain': domain,
'authKey': auth_key.group(1),
}

resp = session.post(query_url, json=data, timeout=15)
result = resp.json()

if result.get('success'):
info = result['params']['list'][0]
return {
'icp_number': info.get('icp', ''),
'unit_name': info.get('unitName', ''),
'nature': info.get('natureName', ''),
'approved_date': info.get('time', ''),
}
except Exception as e:
return {'icp': None, 'note': str(e)}

模块二:百度权重查询

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
def query_baidu_weight(domain):
"""查询百度权重(通过第三方工具)"""
# 使用爱站网的百度权重查询
url = f'https://baidurank.aizhan.com/baidu/{domain}/'

try:
resp = requests.get(url, timeout=15,
headers={'User-Agent': 'Mozilla/5.0 ...'})
soup = BeautifulSoup(resp.text, 'html.parser')

# 提取百度权重
weight_img = soup.find('img', {'alt': re.compile(r'百度权重')})
weight = 0
if weight_img:
weight_text = weight_img.get('alt', '')
weight_match = re.search(r'(\d)', weight_text)
if weight_match:
weight = int(weight_match.group(1))

# 提取预估流量
traffic_elem = soup.find(string=re.compile(r'预估流量'))
traffic = 0
if traffic_elem:
traffic_match = re.search(r'(\d+[\.,\d]*)', traffic_elem.parent.text)
if traffic_match:
traffic = traffic_match.group(1)

return {
'baidu_weight': weight,
'estimated_traffic': traffic,
}
except:
return {'baidu_weight': 0, 'estimated_traffic': 0}

模块三:Whois 查询

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import whois

def query_whois(domain):
"""查询域名 Whois 信息"""
try:
w = whois.whois(domain)

return {
'registrar': w.registrar if isinstance(w.registrar, str) else '',
'creation_date': str(w.creation_date),
'expiration_date': str(w.expiration_date),
'name_servers': ', '.join(w.name_servers) if w.name_servers else '',
'registrant': w.name if isinstance(w.name, str) else '',
}
except Exception as e:
return {'note': f'Whois 查询失败: {e}'}

模块四:IP 及 CDN 信息

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import socket

def query_ip_info(domain):
"""查询域名 IP 及归属地"""
try:
ip = socket.gethostbyname(domain)

# IP 归属地查询
resp = requests.get(f'http://ip-api.com/json/{ip}?lang=zh-CN',
timeout=10)
data = resp.json()

if data['status'] == 'success':
return {
'ip': ip,
'country': data['country'],
'region': data['regionName'],
'city': data['city'],
'isp': data['isp'],
}
except:
pass

return {'ip': 'unknown'}

主流程:批量收集并输出 CSV

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import csv

def collect_asset_info(domains):
"""批量收集资产信息"""
results = []

for i, domain in enumerate(domains):
print(f"[{i+1}/{len(domains)}] 收集: {domain}")

info = {'domain': domain}

# 1. ICP 备案
icp_info = query_icp(domain)
info.update(icp_info)

# 2. 百度权重
baidu_info = query_baidu_weight(domain)
info.update(baidu_info)

# 3. Whois
whois_info = query_whois(domain)
info.update(whois_info)

# 4. IP 信息
ip_info = query_ip_info(domain)
info.update(ip_info)

results.append(info)

# 输出 CSV
if results:
fieldnames = ['domain', 'icp_number', 'unit_name', 'nature',
'baidu_weight', 'estimated_traffic', 'ip',
'country', 'city', 'isp', 'registrar',
'creation_date', 'expiration_date']

output_file = f'asset_report_{time.strftime("%Y%m%d_%H%M%S")}.csv'
with open(output_file, 'w', newline='', encoding='utf-8-sig') as f:
writer = csv.DictWriter(f, fieldnames=fieldnames,
extrasaction='ignore')
writer.writeheader()
writer.writerows(results)

print(f"\n报告已生成: {output_file}")
print(f"共收集 {len(results)} 个域名")

return results

CNVD 漏洞报送流程中如何使用

CNVD 漏洞报送要求提供:

  • 漏洞目标单位名称 → 来自 ICP 备案主体
  • 漏洞目标 URL → 域名本身
  • 漏洞目标 IP → IP 查询结果
  • 漏洞证明(截图)

这个工具帮你快速完成前三条的信息收集,剩下的挖漏洞和截图才是真本事。


总结

资产信息收集的关键价值是把重复劳动自动化。查一个域名要 5 分钟,查 100 个要 500 分钟——工具 30 秒跑完。省下来的时间拿去挖漏洞。


评论
分享