-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttps.py
More file actions
executable file
·38 lines (37 loc) · 1.35 KB
/
https.py
File metadata and controls
executable file
·38 lines (37 loc) · 1.35 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
38
#-*- coding:utf-8 -*-
import ssl,socket,gevent,time,urllib
header = b'HTTP/1.0 200 OK\r\n'
header += b'Content-Type: text/html\r\nConnection:keep-alive\r\ncharset=UTF-8\r\n\r\n'
if __name__ == "__main__":
context = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
context.load_cert_chain(certfile='cert.pem', keyfile='key.pem')
bindsocket = socket.socket()
bindsocket.bind(('',8000))
while True:
bindsocket.listen(5)
newsocket, fromaddr = bindsocket.accept()
if True:
connstream = context.wrap_socket(newsocket, server_side=True)
data = connstream.recv(1024)
data=urllib.unquote(data)
print "1"
print(data)
method=data.split(' ')[0]
url=data.split(' ')[1]
if method == 'POST':
f=open('index.html','a')
f.write("<p>"+data.split('=')[-1])
f.close()
f=open('index.html','rb')
index=f.read()
f.close()
#index=index.decode(encoding)
urllib.quote(index)
x="document.write('<p>asdf</p>');"
if url=='/':
connstream.send(header+index)
else :
connstream.send(x)
connstream.shutdown(socket.SHUT_RDWR)
connstream.close()
newsocket.close()