大家好,在前面的内容中,我们已经学习了如何编写侦察脚本。但是作者仅仅讲解举例了自动化crt.sh、nmap端口爆破和Dirsearch爆破url。
本文我们给出爆破子域名的自动化脚本domain.sh代码。
domain.sh代码功能
输入要爆破的顶级域名,使用crt.sh、SubBrute、Sublist3r、Gobuster依次爆破子域名,去重收集各个扫描器的结果。
使用curl筛选结果中有效可访问的子域名,最后将爆破后的有效子域名存储进/recon/code/facebook.com_240719/subDomain_report1(示例文件)中。
代码运行的准备工作
-
新建目录/recon/tools/,此目录存放了下载安装好的subbrute和Sublist3r
-
gobuster需要爆破域名的字典,请准备好将字典路径放入Dir变量中,gobuster 为kali系统自带,无需下载。
-
新建目录/recon/code。
-
把subbrute的resolvers.txt复制到/recon/code/目录中
-
在/recon/code编写domain.sh文件
-
需要挂代理,使用proxychains将windows系统的代理转发到kali系统中。
windows代理服务器设置如下:
kali /etc/proxychains.conf主要配置如下:
socks4 windows_ip 10810
socks5 windows_ip 10810
运行示例
./domain.sh -d google.com
domain.sh代码内容如下:
#得到输入外网域名的所有可访问的有效子域名
echo "请输入域名或网站网址,例如 ./domain.sh -d google.com"
sublist3r_path="/recon/tools/Sublist3r"
subbrute_path="/recon/tools/subbrute"
Dir="/recon/dirs/domains-1million-top.txt"
#扫描子域名
Tool_Scan()
{
#在https://crt.sh网站获取子域名
echo "----运行crt.sh..."
curl "https://crt.sh/?q=$Domain&output=json" -o $Directory/crt
jq -r ".[] | .name_value" $Directory/crt > $Directory/crt_results
#python2 ./subbrute.py google.com 不用挂代理
echo "----运行SubBrute...结果很慢,请耐心等待"
python2 $subbrute_path/subbrute.py $Domain -o $Directory/subbrute_results
#python2 -m pip install -r requirements.txt 安装sublist的依赖
#python2 sublist3r.py -d google.com 不用挂代理
echo "----运行Sublist3r..."
python2 $sublist3r_path/sublist3r.py -d $Domain -o $Directory/sublist3r_results
#gobuster为kali自带,无需安装
#-w是爆破的字典
echo "----运行Gobuster..."
gobuster dns -d $Domain -w $Dir --no-color --threads 30 -o $Directory/gobuster_results
}
#subDomain_report存储了最终的扫描报告,这是生成最终扫描报告的函数
Scan_Domain()
{
#创建一个名为输入域名的目录
Today=$(date +%y%m%d)
Domain=$1
Directory="${Domain}_${Today}"
echo "创建目录 $Directory."
mkdir $Directory
#调用子域名工具
Tool_Scan $1
#subDomain_report存储了最终的扫描报告
#对扫描出的域名进行去重操作
#排序命令行工具sort会对文本文件的行进行排序。当给定多个文件时,它将对所有文件进行排序,并将输出写入终端。-u选项告诉sort,只返回排序列表中的唯一项
cat $Directory/crt_results $Directory/sublist3r_results $Directory/subbrute_results $Directory/gobuster_results
| sort -u > $Directory/subDomain
Dele
echo "域名扫描结果存储在$Directory/subDomain_report中"
Access_Domain
}
#*.vp.video.l.google.com 删除结果带*号的子域名
#www.google.com341205232341205232341205232341.phreedom.org 删除带有的行
#Found: mcdata-plus.google.com 删除Found:
#-e '/^*/d' 删除所有以星号(*)开头的行。
#-e '/\/d' 删除所有含有反斜杠()的行。每个反斜杠都需要转义一次,而sed命令中的正则表达式也需要一个反斜杠来转义反斜杠字符。
#-e 's/Found://g' 将所有"Found: "字符串替换为空。s命令用于替换,g标志表示全局替换,即在每一行中所有匹配到的"Found:"都会被替换。
Dele()
{
# 使用sed命令删除以*开头的行
sed -e '/^*/d' -e '/\/d' -e 's/Found: //g' "$Directory/subDomain" > "$Directory/subDomain_report"
}
#确认当前$Directory/subDomain_report中的域名是否可以访问
#使用curl测试域名是否可以访问
Access_Domain()
{
echo "aaa"
# 遍历域名列表Directory/subDomain_report
while IFS= read -r domain; do
# 尝试使用 curl 访问域名,使用 HEAD 请求以减少带宽消耗
# proxychains是梯子代理
if proxychains curl --silent --head --fail --connect-timeout 5 "http://$domain" > /dev/null; then
# 如果域名可访问,追加到输出文件
echo "$domain" >> "$Directory/subDomain_report1"
fi
done < "$Directory/subDomain_report"
echo "可以访问的域名被写进了$Directory/subDomain_report1中"
}
#将-d后面的域名传入scan_Domain函数
while getopts "d:" OPTION; do
Scan_Domain $OPTARG
done
原文始发于微信公众号(SecurityBug):侦察脚本编写之爆破子域名
免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论