Add SSL support
This commit is contained in:
parent
1140ac45fe
commit
0894920492
|
@ -30,6 +30,10 @@ timeout = 15 # timeout in seconds
|
|||
connection = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
|
||||
unbufferedStdout = os.fdopen(sys.stdout.fileno(),"wb",0) # Make unbuffered stdout
|
||||
useSSL = False
|
||||
sslIgnoreCert = False
|
||||
if "fstream_ssl" in os.environ and os.environ["fstream_ssl"] == "1": useSSL = True
|
||||
if "fstream_ssl_ignoreCert" in os.environ and os.environ["fstream_ssl_ignoreCert"] == "1": sslIgnoreCert = True
|
||||
|
||||
def listToCommand(lst):
|
||||
cmd = ""
|
||||
|
@ -99,13 +103,30 @@ def stringToAddressTuple(addr):
|
|||
return rtn
|
||||
|
||||
def main():
|
||||
global serverAddr
|
||||
global serverAddr, useSSL, sslIgnoreCert, connection
|
||||
serverAddr = stringToAddressTuple(sys.argv[1])
|
||||
global bufferSize
|
||||
if useSSL: import ssl
|
||||
|
||||
eprint("Connecting to server...")
|
||||
connection.settimeout(timeout)
|
||||
connection.connect(serverAddr)
|
||||
if useSSL:
|
||||
eprint("Performing SSL handshake...")
|
||||
if sys.version_info >= (3,10):
|
||||
proto = ssl.PROTOCOL_TLS_CLIENT
|
||||
else:
|
||||
proto = ssl.PROTOCOL_TLS
|
||||
|
||||
ctx = ssl.SSLContext(proto)
|
||||
if sslIgnoreCert:
|
||||
ctx.check_hostname = False
|
||||
ctx.verify_mode = ssl.CERT_NONE
|
||||
|
||||
connection = ctx.wrap_socket(
|
||||
connection,
|
||||
server_side = False
|
||||
)
|
||||
|
||||
eprint("Sending payload...")
|
||||
connection.sendall("\n\n".encode("ascii"))
|
||||
sendResponse(connection,sys.argv[2].encode("utf-8"))
|
||||
|
|
Loading…
Reference in New Issue