-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.py
222 lines (202 loc) · 6.88 KB
/
main.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
########################################################################
# UFT - 2 - CLIENT - CLI
# Author : Merwin M.M
########################################################################
import socket
import os
import sys
import rsa
import time
import requests as r
import hashlib
from rich import print
from rich.table import Table
from rich.progress import track
table_commands = Table(title="Commands")
table_commands.add_column("Command", style="cyan", no_wrap=True)
table_commands.add_column("Use", style="magenta")
table_commands.add_column("No", justify="right", style="green")
table_commands.add_row("help", "Get info about the commands.", "1")
table_commands.add_row("upload (filename) (password)", "Upload a file.", "2")
table_commands.add_row("download (filename) (output) ", "Download a file.", "3")
table_commands.add_row("delete (filename) (password) ","Delete a file which is present in the server.","4")
table_commands.add_row("replace (filename) (password)","Replace a existing file.","5")
def read_public_key():
with open("pub_key.txt", "rb") as f:
pub_key = rsa.PublicKey.load_pkcs1(f.read())
f.close()
return pub_key
def encrypt(msg,public_key):
return rsa.encrypt(msg.encode("ascii"),public_key)
def decrypt(msg,private_key):
try:
return rsa.decrypt(msg,private_key).decode("ascii")
except:
return False
def send_large(file_path,cli,max_chunk = 65536):
f = open(file_path,"rb")
size = os.path.getsize(file_path)
if int(size) < max_chunk:
cli.send("1".encode())
rev = 1
else:
rev = size/max_chunk
if int(rev) < rev:
rev = int(rev+1)
cli.send(str(int(rev)).encode())
cli.recv(1024).decode()
for step in track(range(int(rev)),description="Uploading..."):
data = f.read(max_chunk)
if data == b'':
cli.send("done".encode())
f.close()
break
else:
cli.send(data)
cli.recv(1024).decode()
step
while True:
data = f.read(max_chunk)
if data == b'':
cli.send("done".encode())
f.close()
break
else:
cli.send(data)
cli.recv(1024).decode()
def recv_large(filename,cli,max_chunk = 65536):
f = open(filename,"wb")
rev = cli.recv(1024).decode()
rev = int(rev)
cli.send(".".encode())
data_chunks = b''
for step in track(range(rev),description="Downloading..."):
data = cli.recv(max_chunk)
if data.decode() == "done":
break
else:
data_chunks+=data
cli.send(".".encode())
step
while True:
data = cli.recv(max_chunk)
if data.decode() == "done":
break
else:
data_chunks += data
cli.send(".".encode())
f.write(data_chunks)
f.close()
def hash_salt(password):
dk = hashlib.pbkdf2_hmac('sha512', str(password).encode(), b'asxdjkjkhrafkn.ker//', 10000)
final = dk.hex()
return final.encode()
def get_key():
os_type = sys.platform.lower()
if "win" in os_type:
command = "wmic bios get serialnumber"
elif "linux" in os_type:
command = "sudo dmidecode -s system-serial-number"
elif "darwin" in os_type:
command = "ioreg -l | grep IOPlatformSerialNumber"
sn = os.popen(command).read().replace("\n","").replace(" ","").replace(" ","")
key = r.get("https://serververifier.darkmash.repl.co/generatekey",headers={"cpu":sn}).text
if key == "0":
print("[red] [-] Server Denied Connection[/red]")
quit()
return key
recv_chunks = []
send_chunks = []
# Getting server info
server_stat_url = "https://raw.githubusercontent.com/darkmash-org/UFT/main/status.txt"
server_stats = r.get(server_stat_url).text
server_stats = server_stats.replace("\n","")
if server_stats == "DOWN":
print("[bold red] [-] The server is DOWN. Try later..[/bold red]")
quit()
# setting connection to server
server_stats = server_stats.split(":")
port = int(server_stats[1])
add = socket.gethostbyname(server_stats[0])
print(f"[bold green] You are connecting to : {add} [/bold green]")
client = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
function = sys.argv[1]
try:
client.connect((add, port))
key = get_key()
client.send(key.encode())
if client.recv(1024).decode() == "0":
quit()
print("[green] Got Connected To Server [/green]")
if function == "help":
print(table_commands)
elif function == "download":
a = time.time()
client.send("download".encode())
client.recv(1024).decode()
file_name = sys.argv[2]
new_name = sys.argv[3]
client.send(file_name.encode())
res = client.recv(1024).decode()
if res == "yes":
client.send(".".encode())
recv_large(new_name,client)
b = time.time()-a
print(f" [blue]Time Taken : {b}s[/blue]")
else:
print("[red] File Not Found...[/red]")
elif function == "upload":
file_name = sys.argv[2]
try:
a = os.path.exists(file_name)
if a:
b = os.path.isfile(file_name)
if b:
uploadable = True
else:
uploadable = False
else:
uploadable = False
except:
uploadable = False
if uploadable:
file_password = sys.argv[3]
file_password = hash_salt(file_password)
client.send("upload".encode())
client.recv(1024).decode()
client.send(file_name.encode())
res = client.recv(1024).decode()
if res == "__++":
print("[red] File already exists , Try using other filename. [/red]")
else:
client.send(file_password)
client.recv(1024).decode()
send_large(file_name,client)
print("[green] UPLOADED[/green]")
else:
print("[red] File Error[/red]")
elif function == "delete":
client.send("delete".encode())
client.recv(1024).decode()
filename = sys.argv[2]
password = sys.argv[3]
password = hash_salt(password)
client.send(filename.encode())
client.recv(1024).decode()
client.send(password)
res = client.recv(1024).decode()
if res == "deleted":
print("[green] Deleted...[/green]")
else:
print("[red] Password Incorrect / File Error...[/red]")
elif function == "replace":
file_name = sys.argv[2]
pwd = sys.argv[3]
os.system(f"uft delete {file_name} {pwd}")
os.system(f"uft upload {file_name} {pwd}")
else:
print("[red] Command Not Found...[/red]")
client.close()
print("[red] Disconnected[/red]")
except:
print("[red] Connection Error [/red]")