最近有个漏洞,上传点,路径可控,POST一个路径,生成一个ID,通过访问ID的链接可显示目录是否存在或者直接读取指定格式文件;第二个数据包的传输格式为在burp的宏中不被支持,遂想通过脚本爆破,主要是POST multipart/form数据的问题。如下:
#coding:utf8
import binascii
import requests
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
headers={
}
def encode_multipart_formdata(fields):
#boundary = binascii.hexlify(os.urandom(16)).decode('ascii')
boundary ='----WebKitFormBoundary0jx6gjxsnsoprBX1'
body = (
"".join("--%s\r\n"
"Content-Disposition: form-data; name=\"submit\""
"\r\n"
"\r\n"
"submit"
"\r\n"
"--%s\r\n"
"Content-Disposition: form-data; name=\"%s\"; filename=\"te1st.jpg\"\r\n"
"Content-Type: image/jpeg"
"\r\n"
"\r\n"
"%s\r\n" % (boundary,boundary, field, value)
for field, value in fields.items()) +
"--%s--\r\n" % boundary
)
content_type = "multipart/form-data; boundary=%s" % boundary
return body#, content_type
def main():
files_new={"upload_file":"123"}
files= encode_multipart_formdata(files_new)
print files
url='http://******/index.php'
html=requests.post(url,data=files,headers=headers).text
print html
if __name__ == '__main__':
main()
注:1、该种方法boundary可控;2、boundary后的参数要注意横杠数量;3、POST中的boundary需要与content-type中的boundary一致
另外网上还有一种办法是利用
request.post(url,files=files)
但测试中发现boundary不可控,且格式比较混乱,POST的时候容易出问题,摘抄如下:
#coding:utf8
import requests
import json
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
headers={
*****
}
def main():
url='http://***/index.php'
#postdata={"submit":("submit")}
files={
"submit":(None,"submit"),
"upload_file":("test.jpg",open('d://test.jpg','rb'),'image/jpeg')
}
print files
#requests.get('https://baidu.com')
html=requests.post(url,files=files,headers=headers).text
print html
if __name__ == '__main__':
main()