-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathhttp-post.py
More file actions
37 lines (31 loc) · 1.08 KB
/
http-post.py
File metadata and controls
37 lines (31 loc) · 1.08 KB
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
27
28
29
30
31
32
33
34
35
36
37
import socket
import sys
def sendPost(host, port):
httpHeader = ''
httpHeader += 'POST / HTTP/1.1\r\n'
httpHeader += 'Host: {host}\r\n'.format(host = host)
httpHeader += 'Connection: keep-alive\r\n'
httpHeader += 'Content-Type: application/x-www-form-urlencoded\r\n'
httpHeader += 'User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3223.8 Safari/537.36\r\n'
httpHeader += 'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8\r\n'
httpHeader += 'Referer: http://{host}/register.ghp\r\n'.format(host = host)
httpHeader += 'Accept-Encoding: gzip, deflate\r\n'
httpHeader += 'Accept-Language: en-US,en;q=0.9\r\n\r\n'
httpHeader += 'postdata=somedata\r\n'
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
s.send(httpHeader)
data = s.recv(4096)
print(data)
s.close()
except:
print('Unable to establish connection.')
sys.exit(-1)
def main():
host = '127.0.0.1'
port = 80
sendPost(host, port)
sys.exit(0)
if __name__ == '__main__':
sys.exit(main())