Open aiastia opened 3 years ago
此脚本全复制自cloudfront_nodecat,这里仅做为备份和参考。
https://github.com/fork-bak/cloudfront_nodecat
# coding=utf-8
import threading
import requests
import queue
import sys
import re
import os
import numpy as np
#
def bThread(iplist):
threadl = []
global q
q = queue.Queue()
for host in iplist:
q.put(host)
for x in range(0, int(SETTHREAD)):
threadl.append(tThread(q))
for t in threadl:
t.start()
for t in threadl:
t.join()
#create thread
class tThread(threading.Thread):
def __init__(self, queue):
threading.Thread.__init__(self)
self.queue = q
def run(self):
while not self.queue.empty():
host = self.queue.get()
try:
checkServer(host)
except:
continue
def checkalive():
print('\n[Step1] Scanning alive servers:\n')
zmap = os.popen('zmap -w ' + SETIPLIST + ' -p 443 -B 30M')
global IPLIST
IPLIST = zmap.read().splitlines()
def checkServer(host):
header ={'user-agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36'}
aimurl = "http://"+host+":443"
response = requests.get(url=aimurl,headers=header,timeout=10)
serverText = response.headers['server']
if (serverText == "CloudFront"):
print("NewNode:" + host +" has been catched!\n")
if MUTEX.acquire(3):
with open("result.txt","a+") as file:
file.write(host+"\n")
file.close()
MUTEX.release()
if __name__ == '__main__':
os.system("clear")
print('\n############# Cloud Front Scan ################')
print('# Author Madlifer|blog:https://vicho.me #')
print('###############################################\n')
global SETIPLIST
global SETTHREAD
global MUTEX
MUTEX = threading.Lock()
SETIPLIST = sys.argv[1]
SETTHREAD = sys.argv[2]
checkalive()
print('\n[Step2] Start Scanning edge nodes:\n')
bThread(IPLIST)
print('\n[WOW] Winner Winner Chicken Dinner!\n')
在脚本的同级目录下新建iplist.txt,将CF的IP段放进去。运行:
python3 scan.py iplist.txt 200
上面的200表示python检测Server字段的多进程数量,越大进程越大速度越快。你还可以修改扫描脚本scan.py第43行内,把-B 30M参数调到更大,那么zmap工具扫描的更快。速度快能减省时间但牺牲准确度,这个度自己把握。速度越快有可能会被你的服务商视为扫描攻击,有劝退的风险。
国内IP段 IPIP制作中国大陆地区ip列表 每2月更新一次 省市级划分大陆地区ip列表 自测zmap这工具不太准,有很多IP的443端口开着的但却扫不到。zmap速度是快但是丢掉了准确率,可以使用其他替代工具masscan和nmap。
nmap工具 nmap工具可以提供很详细的扫描情况但是速度最慢,如果需要提高速度就用如下参数,这是我自己试验出来的速度不错,这段命令是可以直接放到扫描脚本scan.py的第43行替换zmap。虽然速度有所提升但是还是比较慢,还有就是没有扫描进度。
nmap -sS -Pn --open --min-hostgroup 100 --min-parallelism 100 -n -T4 -iL iplist.txt -p443 -vv | awk '/Discovered open port 443\/tcp/{print $6}'
nmap安装 可以直接安装。
masscan工具 masscan速度处于zmap和nmap两者之间,准确度也处于两者之间。masscan可以兼容部分nmap参数。以下命令也可以直接替换zmap。
masscan/bin/masscan -sS -Pn -n -p443 --rate 500 -iL iplist.txt | awk '{print $6}'
masscan安装
CentOS
yum install git gcc make libpcap-devel
git clone https://github.com/robertdavidgraham/masscan
cd masscan
make
Debian/Ubuntu
apt-get install git gcc make libpcap-dev
git clone https://github.com/robertdavidgraham/masscan
cd masscan
make
masscan工具在masscan目录下的bin/masscan中。
给几个IP段 CF的国内IP质量挺高,有很多idc机房和大厂,但是断流你说难不难。给几个IP段自己去扫吧,很多都是我12月份自己扫的,新鲜的很。话说我为什么这么无私?不断流速度直接拉顶,断流让你欲哭无泪,谁用谁知道。 网宿 CDN段 江苏电信 58.221.56.0/24 58.221.36.0/24
湖南联通 58.20.0.0/16
Ucloud BGP段 北京BGP 106.75.4.162 106.75.16.214 106.75.34.130 106.75.90.226 106.75.99.152 106.75.119.188 106.75.120.201
广州BGP 106.75.130.199 106.75.136.107 106.75.139.38 106.75.141.189 106.75.146.128 106.75.173.101 106.75.145.227
上海BGP 106.75.213.165 106.75.226.254 106.75.216.223 106.75.231.127 106.75.231.151 106.75.231.132 106.75.231.139 106.75.231.172
国通数据中心 上海BGP 211.148.0.0/16
亚马逊 BGP段 宁夏BGP 52.82.0.0/16 很多
广州电信 广州广东 119.147.182.0/24 几乎全D段
上海联通 漕河泾IDC 210.51.40.0/24
上海联通 211.95.52.157 211.95.52.172
12月24日扫到两个Ucloud广州BGP:106.75.167.14、106.75.173.101
原理 CF的节点打开,在响应的header里Server字段值为CloudFront,利用这方法我们可以用脚本自动检测CF的IP。
脚本的大致思路是找到CF的所有IP段,然后用zmap工具检测这些IP的443端口通不通,保留通的IP再进行header里Server字段值的判断,值为CloudFront即为CF。
扫描脚本 脚本运行条件:python3环境、numpy和requests模块、另加zmap工具。python3环境可以改为python环境,只需要把脚本的queue模块名改成Queue,第十四行也改成Queue。zmap工具也可以是masscan或者nmap,这两种工具下面有介绍。
Ubuntu/Debian系统
CentOS系统