OneForAll cdn识别逻辑
OneForAll cdn识别逻辑
git clone --depth=1 https://github.com/shmilylty/OneForAll.git
识别规则
目录oneforall\data\
下
cdn_asn_list.json
cdn_cname_keywords.json
cdn_header_keys.json
cdn_ip_cidr.json
数据库
oneforall\data\ip2location.zip
oneforall\data\ip2region.db
数据获取
在接下来的判断cdn逻辑中,需要用到
子域名
cname
ip
asn
cidr
header
其中 子域名;cname;ip;可以通过正常解析获取,重点就是asn,cidr 和header
asn
oneforall中内置了数据库,可以通过ip查询到所属的自治系统号(ASN),查询方法可以参考oneforall\common\ipasn.py
cidr
oneforall中内置了数据库,可以通过ip查询到ip对应cidr,查询方法可以参考oneforall\common\ipasn.py
header
通过查询到的子域名进行请求(80,443端口),获取返回头
获取asn和cidr
oneforall\common\ipasn.py
class IPAsnInfo(Database):
def __init__(self):
path = get_db_path()
Database.__init__(self, path)
def find(self, ip):
info = {
'cidr': '', 'asn': '', 'org': ''}
if isinstance(ip, (int, str)):
ip = ip_to_int(ip)
else:
return info
sql = f'SELECT * FROM asn WHERE ip_from <= {
ip} AND ip_to >= {
ip} LIMIT 1;'
result = self.query(sql)
if not hasattr(result, 'dataset'):
return info
asn = result.as_dict()
info['cidr'] = asn[0]['cidr']
info['asn'] = f"AS{
asn[0]['asn']}"
info['org'] = asn[0]['as']
return info
判断逻辑
通过查看调用逻辑,在oneforall\oneforall.py
第214行调用Enrich类
在oneforall\modules\enrich.py
文件中
class Enrich(object):
def __init__(self, domain):
self.domain = domain
def get_data