-
Notifications
You must be signed in to change notification settings - Fork 0
/
exasol.py
133 lines (89 loc) · 4.1 KB
/
exasol.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import socket, ssl
import random, string
import hashlib, crypt
authdata = ""
host = 'srv.exatest.dynu.net'
port = 3335
cert_file = 'certchain.pem'
key_file = 'private.key'
# def random_string():
# return ''.join(random.choice(string.ascii_letters + string.digits + string.punctuation) for _ in range(8))
def hash_function(authdata, difficulty):
while True:
suffix_string = crypt.mksalt()
string_to_hash = authdata + suffix_string
cksum_in_hex = hashlib.sha1(string_to_hash.encode('utf-8')).hexdigest()
if cksum_in_hex.startswith("0" * difficulty):
break
return suffix_string
def message_encrypt(authdata, args_1, message):
return hashlib.sha1(authdata + args_1 + " " + message + "\n").hexdigest().encode('utf-8')
# CREATE SOCKET
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# sock.settimeout(10)
# WRAP SOCKET
wrappedSocket = ssl.wrap_socket(sock, keyfile=key_file, certfile=cert_file, ssl_version=ssl.PROTOCOL_TLSv1_2)
# CONNECT TO THE SERVER
wrappedSocket.connect((host, port))
#args = wrappedSocket.read().decode('utf-8').strip().split(' ')
while True:
args = wrappedSocket.read().decode('utf-8').strip().split(' ')
# CHECK RESPONSE FROM SERVER
if args[0] == "HELO":
wrappedSocket.sendall("EHLO\n".encode('utf-8'))
elif args[0] == "ERROR":
print("ERROR: " + " ".join(args[1:]))
break
elif args[0] == "POW":
print("POW recieved: " + args[1])
authdata, difficulty = args[1], int(args[2])
suffix = hash_function(authdata, difficulty)
wrappedSocket.sendall((suffix + "\n").encode('utf-8'))
print("Suffix string is: " + suffix + "\n")
elif args[0] == "END":
# if you get this command, then your data was submitted
wrappedSocket.sendall("OK\n".encode('utf-8'))
print("All data has been sent")
break
elif args[0] == "NAME":
# as the response to the NAME request you should send your full name
# including first and last name separated by single space
print("Sending the Name")
message_to_send = message_encrypt(authdata, args[1], "Mahmoud Mahdi")
wrappedSocket.sendall(message_to_send)
elif args[0] == "MAILNUM":
# here you specify, how many email addresses you want to send
# each email is asked separately up to the number specified in MAILNUM
message_to_send = message_encrypt(authdata, args[1], "1")
wrappedSocket.sendall(message_to_send)
elif args[0] == "MAIL1":
message_to_send = message_encrypt(authdata, args[1], "[email protected]")
wrappedSocket.sendall(message_to_send)
elif args[0] == "SKYPE":
# here please specify your Skype account for the interview, or N/A
# in case you have no Skype account
message_to_send = message_encrypt(authdata, args[1], "mahmoud.abdelgalel")
wrappedSocket.sendall(message_to_send)
elif args[0] == "BIRTHDATE":
# here please specify your birthdate in the format %d.%m.%Y
message_to_send = message_encrypt(authdata, args[1], "01.01.1987")
wrappedSocket.sendall(message_to_send)
elif args[0] == "COUNTRY":
# country where you currently live and where the specified address is
# please use only the names from this web site:
# https://www.countries-ofthe-world.com/all-countries.html
message_to_send = message_encrypt(authdata, args[1], "Czechia")
wrappedSocket.sendall(message_to_send)
elif args[0] == "ADDRNUM":
# specifies how many lines your address has, this address should
# be in the specified country
message_to_send = message_encrypt(authdata, args[1], "2")
wrappedSocket.sendall(message_to_send)
elif args[0] == "ADDRLINE1":
message_to_send = message_encrypt(authdata, args[1], "Purkynova 83")
wrappedSocket.sendall(message_to_send)
elif args[0] == "ADDRLINE2":
message_to_send = message_encrypt(authdata, args[1], "61200 Brno")
wrappedSocket.sendall(message_to_send)
# CLOSE SOCKET CONNECTION
wrappedSocket.close()