-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathrce_proxy.py
38 lines (37 loc) · 1.23 KB
/
rce_proxy.py
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
import socket
import sys
def socket_create():
try:
global host
global port
global s
host = '127.0.0.1'
port = 8888
s = socket.socket()
except socket.error as msg:
print("Socket creation error: " + str(msg))
try:
print("Binding socket to port: " + str(port))
s.bind((host, port))
s.listen(5)
except socket.error as msg:
print("Socket binding error: " + str(msg) + "\n" + "Retrying...")
bind_socket()
def socket_accept():
conn, address = s.accept()
print("Connection has been established |" + " IP " + address[0] + " | Port" + str(address[1]))
send_commands(conn)
conn.close()
def send_commands(conn):
while True:
cmd = input()
if cmd == 'quit':
conn.close()
s.close()
sys.exit()
if len(str.encode(cmd)) > 0:
conn.send(str.encode(cmd))
response = str(conn.recv(1024), "utf-8")
print(response, end="")
socket_create()
socket_accept()