Self-Improvement

Python의 Requests 모듈의 multipart/form-data(파일 전송) 형식 본문

프로그래밍/Python

Python의 Requests 모듈의 multipart/form-data(파일 전송) 형식

JoGeun 2020. 7. 16. 10:06

첫번째 코드

파일과 파일의 내용을 정해서 전송

1
2
3
4
5
import requests
 
#proxies = {"http":"http://127.0.0.1:8080"}
requests.post("http://192.168.0.1/test", \
files={"userfile":("pwn.txt",'one,two,zap,zap\none,two,three,Uppercut')})
cs

 

Request

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
POST /test HTTP/1.1
Host: 192.168.0.1
Connection: close
Accept-Encoding: gzip, deflate
Accept: */*
User-Agent: python-requests/2.21.0
Content-Length: 185
Content-Type: multipart/form-data; boundary=8456e94ea127480baa10be00aeb67268
 
--8456e94ea127480baa10be00aeb67268
Content-Disposition: form-data; name="userfile"; filename="pwn.txt"
 
one,two,zap,zap
one,two,three,Uppercut
--8456e94ea127480baa10be00aeb67268--
cs

 


두번째 코드

파일과 그 외의 데이터를 전송

1
2
3
4
5
6
7
import requests
 
#proxies = {"http":"http://127.0.0.1:8080"}
 
values = {'DB''photcat''OUT''csv''SHORT''short'}
requests.post("http://192.168.0.1/test", \
files={"userfile":("pwn.txt",'one,two,zap,zap\one,two,three,Uppercut')}, data=values)
cs

 

Request

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
POST /test HTTP/1.1
Host: 192.168.0.1
Connection: close
Accept-Encoding: gzip, deflate
Accept: */*
User-Agent: python-requests/2.21.0
Content-Length: 453
Content-Type: multipart/form-data; boundary=7c8531b951b54a3e895b03109a54cd4b
 
--7c8531b951b54a3e895b03109a54cd4b
Content-Disposition: form-data; name="SHORT"
 
short
--7c8531b951b54a3e895b03109a54cd4b
Content-Disposition: form-data; name="DB"
 
photcat
--7c8531b951b54a3e895b03109a54cd4b
Content-Disposition: form-data; name="OUT"
 
csv
--7c8531b951b54a3e895b03109a54cd4b
Content-Disposition: form-data; name="userfile"; filename="pwn.txt"
 
one,two,zap,zap\one,two,three,Uppercut
--7c8531b951b54a3e895b03109a54cd4b--
cs

 

 


세번째 코드

원래 있던 파일을 전송하는 방법

1
2
3
4
5
6
import requests
 
#proxies = {"http":"http://127.0.0.1:8080"}
 
requests.post("http://192.168.0.1/test", \
files={"userfile":open("pwn.txt",'rb')})
cs

 

Request

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
POST /test HTTP/1.1
Host: 192.168.0.1
Connection: close
Accept-Encoding: gzip, deflate
Accept: */*
User-Agent: python-requests/2.21.0
Content-Length: 155
Content-Type: multipart/form-data; boundary=41c510d2cdb5479c9fc617d8d15ad27f
 
--41c510d2cdb5479c9fc617d8d15ad27f
Content-Disposition: form-data; name="userfile"; filename="pwn.txt"
 
pwnable
 
--41c510d2cdb5479c9fc617d8d15ad27f--
 
cs