企业资产监控

监控企业外部域名、端口

子域名监控

我的做法是,
对大量的SRC厂商列表,用sublert监控,旨在发现新上线业务
对针对性的SRC,利用 teemo + subDomainsBrute ,旨在发现更全的业务
在渗透中,可以用teemo + subDomainsBrute + JSFinder + Altdns,进行收集、旨在发现更多隐藏的子域

sublert

https://github.com/yassineaboukir/sublert
Sublert是一个安全侦察工具,这个工具利用了证书透明原则,利用目标组织的TLS/SSL证书从而监控部署的新子域。
在原工具基础上,修改了slack的输出 , 添加title 和server

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
def GetBanner(domain):
banner, server = '', ''
try:
url = 'https://' + domain
r = requests.get(url, timeout=10, verify=False, allow_redirects=True)
encoding = 'utf-8'
if r.encoding == 'ISO-8859-1':
encodings = requests.utils.get_encodings_from_content(r.text)
if encodings:
encoding = encodings[0]
else:
encoding = r.apparent_encoding
encode_content = r.content.decode(encoding, 'replace').encode('utf-8', 'replace')
content = encode_content
server = r.headers.get('Server') if r.headers.get('Server')!=None else ''
m = re.search(r'<title>(.*)</title>', content, flags=re.I)
if m:
banner = m.group(1)
r.close()
except Exception, e:
pass
#traceback.print_exc()
finally:
return banner, server

teemo + subDomainsBrute

https://github.com/bit4woo/teemo # 从搜索接口 + ssl证书获取
https://github.com/lijiejie/subDomainsBrute # 暴力枚举

teemo 中带的subDomainsBrute 模块效率太低,lijiejie大佬在2019-05-19重构了subDomainsBrute,效率颇高,
于是整合了这两工具到一起,teemo负责用搜索api获取子域名,subDomainsBrute负责DNS暴力枚举
结果处理
(1) subDomainsBrute 结果保存在 output/xxx_sub.txt
(2) teemo 结果保存在 output/xxx_teemo.txt
(3) 重新整合处理后生成在 output/subdomains/xxx.txt
(4) 网段信息保存在 output/net/xxx_net.txt

后续添加 JSFinder + Altdns
https://github.com/SkewwG/SkeSubDomain #通过爬取主站的链接获取子域
https://github.com/Threezh1/JSFinder #从js中爬取
https://github.com/infosec-au/altdns # 对子域名运用置换,扫描新的的子域发现

实现子域名去重整合输出 子域名列表 和 网段列表

ESD

https://github.com/FeeiCN/esd
某位大佬也使用了ESD做子域名资产监控 https://github.com/coco413/Domain-monitor

公网端口资产

通过上面子域名搜集得到的网段信息, 排除掉 aliyun 、 tengxunyun 、内网地址等

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
def check_ip(ips): # pass aliyun  tencentyun
ip_net = []
scan_ips = []
for iprange,num in ips.items():
ip = iprange.split('/')[0]
try:
text = requests.get('https://api.ip.sb/geoip/{0}'.format(ip)).text
res = json.loads(text)
if res.has_key('organization'):
if res['organization'].find('Alibaba') == -1 and res['organization'].find('Tencent') == -1:
res = {'iprange':iprange,'organization':res['organization'],'num':num}
ip_net.append(res)
scan_ips.append(iprange)
else:
ip_net[iprange] = "null"
except Exception,e:
res = {'iprange':iprange,'organization':'null','num':num}
ip_net.append(res)
return ip_net,scan_ips

if __name__ == '__main__':
print(check_ip(["101.72.77.0/24"]))

将整理后的网段 生成 ip 列表 ip.txt

用nmap ping 扫描存活主机并导出 ip_alive.txt

1
2
3
# 主机发现,生成存活主机列表
$ nmap -sn -T4 -oG Discovery.gnmap -iL IP.txt
$ grep "Status: Up" Discovery.gnmap | cut -f 2 -d ' ' > ip_alive.txt

好了,存活的ip已经处理完成,但是还有以下问题

1
2
1. 当扫描数数万个目标的时候,Nmap的速度很慢。
2. Masscan在高速(rates)扫描大端口范围时的不准确性

参考 https://xz.aliyun.com/t/6001
得到的解决思路是:

1
2
#用masscan扫描ip_alive.txt 的开放端口
首先运行2或3个并发的Masscan任务,所有的65535个端口分为4-5个更小的范围;

用python-nmap 识别 端口对应服务、组件、http title

获取主机列表以及Masscan扫描出的开放端口的组合列表,使用这些列表作为Nmap的扫描目标并执行常规Nmap扫描。

用nmap 识别 端口对应服务、组件、http title,结果存储到数据库

调用kunpeng做POC Scan

根据端口对应的服务、组件、http title 作为关键key从数据库中取出内容,进入kunpeng做POC扫描

编译kunpeng

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
go get -d github.com/opensec-cn/kunpeng  
cd $GOPATH/src/github.com/opensec-cn/kunpeng

# 静态资源打包进工程的小程序
sudo -s
source /etc/profile
go install ./vendor/github.com/mjibson/esc

安装esc不成功,执行
go get -v github.com/mjibson/esc 发现是golang.org/x/tools 获取失败,可以从github下
cd $GOPATH/src/
mkdir golang.org/x
cd golang.org/x/
git clone https://github.com/golang/tools
之后再执行安装
go get -v github.com/mjibson/esc

# 打包JSON插件到项目代码中
esc -include='\.json$' -o plugin/json/JSONPlugin.go -pkg jsonplugin plugin/json/

# 编译c版本(所有语言均可使用)
go build -buildmode=c-shared --ldflags="-w -s -X main.VERSION=20190226" -o kunpeng_c.so

# 编译Go专用版本(不支持win)
go build -buildmode=plugin --ldflags="-w -s -X main.VERSION=20190226" -o kunpeng_go.so

待更。

下一步是什么?

使用所有这些枚举数据/主机,您可以执行以下操作:

检查子域名接管(aquatone)
检查所有正在运行的服务(kunpeng)
获取运行Web服务的主机的屏幕截图(pyppeteer)
运行目录暴力攻击(BBscan,Dirsearch)
等等

安全建设