-
Notifications
You must be signed in to change notification settings - Fork 0
/
send.py
executable file
·57 lines (44 loc) · 1.36 KB
/
send.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python3
"""
Copyright (c) 2015 Jacob Martin
A command for sending TauNet Messages.
"""
import sys
import os
import socket
from subprocess import call
from taunet import *
args = sys.argv
# Helpful usage hints.
if len(args) != 3:
print("usage:")
print("\tpython3 client.py <username> <message>")
exit()
to_username = args[1]
message = args[2]
# Fetch the target host from the client table using the username argument.
try:
target_host = client_table.clients[to_username]
except KeyError:
print("That client does not exist in the table.")
exit()
# Construct the full message complete with headers.
full_message = "version: " + version + "\r\n"
full_message += "from: " + client_table.username + "\r\n"
full_message += "to: " + to_username + "\r\n\r\n"
full_message += message
# Write the message to a file.
with open("message", "w") as messageFile:
messageFile.write(full_message)
# Encrypt the message file then delete the original file.
call(["./cs2", "encrypt", client_table.key, "message", "encrypted"])
os.remove("message")
# Connect to the target.
target = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
target.connect((target_host, port))
# Send the encrypted file.
with open("encrypted", "rb") as encryptedFile:
target.send(encryptedFile.read(1024))
# Close the connection and delete the encrypted file.
target.close()
os.remove("encrypted")