Skip to content

Instantly share code, notes, and snippets.

@leonjza
Last active January 17, 2024 06:46
Show Gist options
  • Save leonjza/adc69cadc3d8a5d4c068 to your computer and use it in GitHub Desktop.
Save leonjza/adc69cadc3d8a5d4c068 to your computer and use it in GitHub Desktop.
Python Netcat Shell Connect
#!/usr/bin/python
import socket
host = "127.0.0.1"
port = 4444
# try and connect to a bind shell
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((host, port))
try :
print "[+] Connected to bind shell!\n"
while 1:
cmd = raw_input("(py-shell) $ ");
s.send(cmd + "\n");
result = s.recv(1024).strip();
if not len(result) :
print "[+] Empty response. Dead shell / exited?"
s.close();
break;
print(result);
except KeyboardInterrupt:
print "\n[+] ^C Received, closing connection"
s.close();
except EOFError:
print "\n[+] ^D Received, closing connection"
s.close();
except socket.error:
print "[+] Unable to connect to bind shell."
@0xdeadbeer
Copy link

add import socket or else it gives an error on line 30

the 'import socket' is already in the python script, by adding another one will cause errors i think

@chr1s-uni
Copy link

why python 2.............

@leonjza
Copy link
Author

leonjza commented Dec 12, 2020

@chr1s-uni this is a 6 your old gist.

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