-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathknock_test.py
30 lines (26 loc) · 899 Bytes
/
knock_test.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
25
26
27
28
29
30
import socket
import sys
import argparse
def main():
parser = argparse.ArgumentParser(description="Send to the Crackme")
parser.add_argument('--port', dest="port", default="1337", help="Port to connect")
parser.add_argument('--buf', dest="buf", default="9", help="Buffer to send")
args = parser.parse_args()
my_port = int(args.port)
print('[+] Connecting to port: ' + str(my_port))
key = args.buf.encode()
try:
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('127.0.0.1', my_port))
s.send(key)
result = s.recv(512)
if result is not None:
print("[+] Response: " + str(result))
s.close()
except socket.error:
print("Could not connect to the socket. Is the crackme running?")
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
sys.exit(0)