2020-06-02 14:15:03 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
|
2020-01-28 22:15:42 +01:00
|
|
|
import sys
|
2020-02-06 23:27:29 +01:00
|
|
|
import os
|
2020-06-02 14:15:03 +02:00
|
|
|
import util
|
2023-10-05 13:00:16 +02:00
|
|
|
import argparse
|
2020-01-28 22:15:42 +01:00
|
|
|
|
2023-10-05 13:00:16 +02:00
|
|
|
def serve_file(listen_sock, path, forever=False):
|
|
|
|
try:
|
|
|
|
while True:
|
|
|
|
print('[ ] Waiting for a connection')
|
|
|
|
connection, client_address = listen_sock.accept()
|
2020-01-28 22:15:42 +01:00
|
|
|
|
2023-10-05 13:00:16 +02:00
|
|
|
try:
|
|
|
|
print('[+] Connection from', client_address)
|
2020-01-28 22:15:42 +01:00
|
|
|
|
2023-10-05 14:01:50 +02:00
|
|
|
with open(path, "rb") as f:
|
2023-10-05 13:00:16 +02:00
|
|
|
content = f.read()
|
|
|
|
connection.sendall(content)
|
2020-01-28 22:15:42 +01:00
|
|
|
|
2023-10-05 13:00:16 +02:00
|
|
|
print("[+] File Transfer succeeded")
|
|
|
|
finally:
|
|
|
|
connection.close()
|
2020-01-28 22:15:42 +01:00
|
|
|
|
2023-10-05 13:00:16 +02:00
|
|
|
if not forever:
|
|
|
|
break
|
2020-01-28 22:15:42 +01:00
|
|
|
finally:
|
2023-10-05 13:00:16 +02:00
|
|
|
listen_sock.close()
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser(description="File Transfer using netcat")
|
|
|
|
parser.add_argument("--port", type=int, required=False, default=None, help="Listening port")
|
2023-10-05 14:01:50 +02:00
|
|
|
parser.add_argument(type=str, dest="path", help="Path to the file you wish to upload")
|
2023-10-05 13:00:16 +02:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
path = args.path
|
|
|
|
if not os.path.isfile(path):
|
|
|
|
print("[-] File not found:", path)
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
address = util.get_address()
|
2023-10-05 14:01:50 +02:00
|
|
|
listen_sock = util.open_server(address, args.port)
|
|
|
|
if not listen_sock:
|
2023-10-05 13:00:16 +02:00
|
|
|
exit(1)
|
|
|
|
|
|
|
|
print("[+] Now listening, download file using:")
|
2023-10-05 14:01:50 +02:00
|
|
|
print('nc %s %d > %s' % (address, listen_sock.getsockname()[1], os.path.basename(path)))
|
2023-10-05 13:00:16 +02:00
|
|
|
print()
|
|
|
|
|
|
|
|
serve_file(listen_sock, path, forever=True)
|