-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsend_socket.py
24 lines (24 loc) · 1.43 KB
/
send_socket.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import socket
import argparse
def send_shellcode(sock, shellcode):
print("Sending shellcode...")
# Remove the next lines hashtag to print 'hello world' instead of the default
# shellcode = b"\x68\x65\x6C\x6C\x6F\x20\x77\x6F\x72\x6C\x64"
sock.sendall(shellcode)
def parse_shellcode(shellcode_str):
if shellcode_str.startswith('"') and shellcode_str.endswith('"'):
shellcode_str = shellcode_str[1:-1]
shellcode_bytes = shellcode_str.encode().decode('unicode_escape').encode('latin1')
return shellcode_bytes
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="send shellcode to a target socket (ip and port)")
parser.add_argument("-i", "--ip", type=str, default="127.0.0.1", help="target ip address (default: 127.0.0.1)")
parser.add_argument("-p", "--port", type=int, default=1111, help="target tcp socket port (default: 1111)")
parser.add_argument("-s", "--shellcode", required=False, type=str, default="\\x46\\x31\\x33", help="shellcode hex to send in format: \\x00\\x00\\x00\\...etc (default: F13)")
args, unknown = parser.parse_known_args()
target_ip = args.ip
target_port = args.port
shellcode = parse_shellcode(args.shellcode) if args.shellcode else default_shellcode
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
sock.connect((target_ip, target_port))
send_shellcode(sock, shellcode)