http rfc7578协议中并未规定boundary后Type和Disposition的顺序,通过抓包发现大部分系统都是有以下顺序传输文件
C:\fakepath\web_up.dat^M
------WebKitFormBoundaryZ0LELBsfCGAkpKSZ^M
Content-Disposition: form-data; name="filename"; filename="web_up.dat"^M
Content-Type: application/octet-stream^M
那么我想将type更换到前面去按理说是可以的,并且这个请求也应该是通用的。
于是查找python curllib3底层库,在fields.py中找到了sort_keys,于是改变它的顺序
于是用python 程序模拟了一下,
import urllib3
flag = 1
#urllib3
def connect():
with open('python_up.dat',encoding='utf-8') as fp:
file_data = fp.read()
http = urllib3.PoolManager()
if flag == 0:
r = http.request('GET',
'http://xxxxxxxxx/check_auth.jsp?_ajax=1&_username=adm&_passwd=123456',
headers={
'_ajax' : '1',
'_username' : 'adm',
'_passwd' : '123456',
}
)
else:
r = http.request('POST','http://xxxxxxxxx:80/upload.cgi',
headers={'Content-Type': "application/octet-stream; boundary=----------------------------246805051776340189008411",
'Cookie' : 'web_session=1aa666c1',
'Content-Disposition': 'form-data',
},
multipart_boundary = 'boundary=----------------------------246805051776340189008411',
fields = {'filefield':('python_up.dat',file_data,
'application/octet-stream'),}
)
print (r.status)
print (r.headers)
print (r.data)
connect()
通过抓包,完成结果
小小记录一下