forked from shellntel-acct/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spin-up
865 lines (717 loc) · 33.9 KB
/
spin-up
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
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
#!/usr/bin/python
############################
# Author: Hans Lakhan
#
############################
# Requirements
# 1) pip install ipgetter
# 2) pip install boto
# 3) pip install requests
#
############################
# To Do spin-up
# 1) Read from Config
# a) xterm vs gterm
#
# To Do Empire
# 1) Read from Config
# a) Use RNG for STAGING_KEY
# 2) Grab cert and use that for api calls
# 3) Kill PowerShell window & Delete file
#
# To do MSF
# 1) Configure Database
#
# To do WWW
# 1) Config to choose type of www server (python, apache)
#
############################
import boto.ec2
import boto.route53
from boto.route53.record import ResourceRecordSets
import argparse
import ConfigParser
import os
import datetime
import sys
import signal
import time
import hashlib
import subprocess
import requests
import json
import ipgetter
#############################################################################################
# Handle Colored Output
#############################################################################################
class bcolors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
def error(msg):
print "[" + bcolors.FAIL + "!" + bcolors.ENDC + "] " + msg
def success(msg):
print "[" + bcolors.OKGREEN + "*" + bcolors.ENDC + "] " + msg
def warning(msg):
print "[" + bcolors.WARNING + "~" + bcolors.ENDC + "] " + msg
def debug(msg):
if args.verbose:
timestamp = datetime.datetime.now()
print "[i] " + bcolors.BOLD + str(timestamp) + bcolors.ENDC + " : " + msg
#############################################################################################
# Handle SigTerm & Clean up
#############################################################################################
def cleanup(signal, frame):
# Time to clean up
print "\n"
success("Roger that! Shutting down")
# Connect to EC2 and return list of reservations
try:
success("Connecting to Amazon's EC2...")
cleanup_conn = boto.ec2.connect_to_region(region_name=args.region, aws_access_key_id=AWS_KEY_ID, aws_secret_access_key=AWS_ACCESS_KEY)
except Exception as e:
error("Failed to connect to Amazon EC2 because: %s" % e)
cleanup_reservations = cleanup_conn.get_all_instances(filters={"tag:Name" : nameTag, "instance-state-name" : "running"})
# Grab list of public IP's assigned to instances that were launched
allInstances = []
for reservation in cleanup_reservations:
for instance in reservation.instances:
if instance.ip_address not in allInstances:
if (instance.ip_address):
allInstances.append(instance.ip_address)
debug("Public IP's for all instances: " + str(allInstances))
ip_address = ''.join(allInstances)
# Terminate instance
success("Terminating Instances")
for reservation in cleanup_reservations:
for instance in reservation.instances:
instance.terminate()
warning("Pausing for 90 seconds so instances can properly terminate")
time.sleep(90)
# Remove Security Groups
success("Deleting Amazon Security Groups")
try:
cleanup_conn.delete_security_group(name=securityGroup)
except Exception as e:
error("Deletion of security group failed because %s" % e)
# Remove Key Pairs
success("Removing SSH keys")
try:
cleanup_conn.delete_key_pair(key_name=keyName)
except Exception as e:
error("Deletion of key pair failed because %s" % e)
if args.dns:
fqdn = args.dns + '.' + ZONE_NAME
success("Removing A record")
try:
dnsconn = boto.route53.connect_to_region(region_name=args.region, aws_access_key_id=AWS_KEY_ID, aws_secret_access_key=AWS_ACCESS_KEY)
except Exception as e:
error("Failed to connect to Amazon EC2 because: %s" % e)
exit()
debug("Removing DNS Record " + fqdn + " => " + ip_address)
changes = ResourceRecordSets(dnsconn, ZONE_ID)
change = changes.add_change("DELETE", fqdn, "A")
change.add_value(ip_address)
result = changes.commit()
success("Done!")
sys.exit(0)
#############################################################################################
# Config Section Mapping
#############################################################################################
def ConfigSectionMap(section):
dict1 = {}
options = config.options(section)
for option in options:
try:
dict1[option] = config.get(section, option)
if dict1[option] == -1:
DebugPrint("skip: %s" % option)
except:
print("exception on %s!" % option)
dict1[option] = None
return dict1
#############################################################################################
# System and Program Arguments
#############################################################################################
AWS_KEY_ID = ''
AWS_ACCESS_KEY = ''
ZONE_NAME = ''
ZONE_ID = ''
parser = argparse.ArgumentParser()
parser.add_argument('-id', '--image-id', nargs='?', default='ami-d05e75b8', help="Amazon ami image ID. Example: ami-d05e75b8. If not set, ami-d05e75b8.")
parser.add_argument('-t', '--image-type', nargs='?', default='t2.nano', help="Amazon ami image type Example: t2.nano. If not set, defaults to t2.nano.")
parser.add_argument('--region', nargs='?', default='us-east-1', help="Select the region: Example: us-east-1. If not set, defaults to us-east-1.")
parser.add_argument('key_id', nargs='?', help="Amazon Access Key ID.")
parser.add_argument('access_key', nargs='?', help="Amazon's Secret Key Access.")
parser.add_argument('app', type=str, choices=['plain', 'empire', 'dirb', 'msf', 'www', 'ptf'], help="Select from: plain, empire, dirb, msf, www, ptf")
parser.add_argument('-p', '--port', nargs='?', default='443', help="Select which port to listen on. Default 443")
parser.add_argument("-v", "--verbose", action='store_true', help="Enable verbose logging. All cmd's should be printed to stdout")
parser.add_argument('--config', type=str, help="Read from config file")
parser.add_argument('--dns', type=str, help="Hostname to assign the host.")
args = parser.parse_args()
# Parse Config
if (args.config):
debug("CONFIG FILE: " + args.config)
config = ConfigParser.ConfigParser()
# TO DO CHECK IF FILE EXISTS
config.read(args.config)
AWS_KEY_ID = ConfigSectionMap("AWS")['access_key_id']
AWS_ACCESS_KEY = ConfigSectionMap("AWS")['secret_access_key']
ZONE_NAME = ConfigSectionMap("DNS")['zone_name']
ZONE_ID = ConfigSectionMap("DNS")['zone_id']
else:
AWS_KEY_ID = args.key_id
AWS_ACCESS_KEY = args.access_key
debug("AWS_KEY_ID: -->" + AWS_KEY_ID + "<--")
debug("AWS_ACCESS_KEY: -->" + AWS_ACCESS_KEY + "<--")
debug("ZONE_NAME: -->" + ZONE_NAME + "<--")
debug("ZONE_ID: -->" + ZONE_ID + "<--")
if (args.dns and not args.config):
error("--dns requires --config")
sys.exit('-1')
# Check to make sure we have the minimum hardware requirements
if args.app == 'msf' or args.app == 'ptf':
if args.image_type == 't2.nano' or args.image_type == 't2.micro':
error(args.app + " requires '-t m3.medium' or larger")
sys.exit(0)
# Terminal
terminal_path = "/usr/bin/gnome-terminal"
# Define SigTerm Handler
signal.signal(signal.SIGINT, cleanup)
# Generate "Random" String
pid = os.getpid()
stamp = time.time()
m = hashlib.md5()
tempstring = str(pid + stamp)
m.update(tempstring)
# Define Security Group Name
securityGroup = "SU_" + m.hexdigest()
# Define SSH Key Name
keyName = "SU_" + m.hexdigest()
# Define AMI Tag Name
nameTag = "SU_" + m.hexdigest()
# PS Payload file
psPayload = "SU_ps_" + m.hexdigest()
# system variables;
homeDir = os.getenv("HOME")
FNULL = open(os.devnull, 'w')
debug("Homedir: " + homeDir)
address_to_tunnel = {}
# Grab public WAN IP
pubip = ipgetter.myip()
#############################################################################################
# Remote SSH CMD
#############################################################################################
def remote_ssh(user, ip, cmd):
debug("Running Remote SSH Command")
retry_cnt = 0
retcode = 0
sshcmd = "ssh -i %s/.ssh/%s.pem -o StrictHostKeyChecking=no %s@%s '%s'" % (homeDir, keyName, user, ip, cmd)
debug("SSH CMD: " + sshcmd)
while ((retcode == 1) or (retry_cnt < 6)):
retcode = subprocess.call(sshcmd, shell=True, stdout=FNULL, stderr=subprocess.STDOUT)
if retcode:
warning("Failed to execute SSH command on %s. Retrying..." % ip)
retry_cnt = retry_cnt + 1
time.sleep(1)
else:
retry_cnt = 6 # probably a better way to do this
if retry_cnt == 5:
error("Giving up")
cleanup("foo", "bar")
#############################################################################################
# Remote SCP CMD
#############################################################################################
def remote_scp(user, ip, src, dst):
debug("Running Remote SCP Command")
retry_cnt = 0
retcode = 0
sshcmd = "scp -i %s/.ssh/%s.pem %s %s@%s:'%s'" % (homeDir, keyName, src, user, ip, dst)
debug("SCP CMD: " + sshcmd)
while ((retcode == 1) or (retry_cnt < 6)):
retcode = subprocess.call(sshcmd, shell=True, stdout=FNULL, stderr=subprocess.STDOUT)
if retcode:
warning("Failed to execute SCP command on %s. Retrying..." % ip)
retry_cnt = retry_cnt + 1
time.sleep(1)
else:
retry_cnt = 6 # probably a better way to do this
if retry_cnt == 5:
error("Giving up")
cleanup("foo", "bar")
#############################################################################################
# Provision DNS server on Amazons route53
#############################################################################################
def provision_dns(ip_address, dns_name):
fqdn = dns_name + '.' + ZONE_NAME
debug("Attempting to connect to route53 service")
try:
conn = boto.route53.connect_to_region(region_name=args.region, aws_access_key_id=AWS_KEY_ID, aws_secret_access_key=AWS_ACCESS_KEY)
except Exception as e:
error("Failed to connect to Amazon EC2 because: %s" % e)
exit()
debug("Adding new record: " + fqdn + " => " + ip_address)
changes = ResourceRecordSets(conn, ZONE_ID)
change = changes.add_change("CREATE", fqdn, "A")
change.add_value(ip_address)
result = changes.commit()
#############################################################################################
# Launch Instance
#############################################################################################
def launch_instance():
success("Connecting to Amazon's EC2")
try:
conn = boto.ec2.connect_to_region(region_name=args.region, aws_access_key_id=AWS_KEY_ID, aws_secret_access_key=AWS_ACCESS_KEY)
except Exception as e:
error("Failed to connect to Amazon EC2 because: %s" % e)
exit()
# Generate KeyPair
success("Generating ssh keypairs")
keypair = conn.create_key_pair(keyName)
time.sleep(5)
keypair.save("%s/.ssh" % homeDir)
debug("SSH Key Pair Name " + keyName)
success("Generating Amazon Security Group")
try:
sg = conn.create_security_group(name=securityGroup, description="Used for spin-up")
except Exception as e:
error("Generating Amazon Security Group failed because: %s" % e)
exit()
try:
sg.authorize(ip_protocol="tcp", from_port=22, to_port=22, cidr_ip=str(pubip) + "/32")
if args.port:
sg.authorize(ip_protocol="tcp", from_port=args.port, to_port=args.port, cidr_ip="0.0.0.0/0")
if args.app == 'empire':
sg.authorize(ip_protocol="tcp", from_port=1337, to_port=1337, cidr_ip=str(pubip)+ "/32")
except Exception as e:
error("Generating Amazon Security Group failed because: %s" % e)
exit()
debug("Security Group Name: " + securityGroup)
# Launch Amazon Instances
try:
reservations = conn.run_instances(args.image_id, key_name=keyName, min_count='1', max_count='1', instance_type=args.image_type, security_groups=[securityGroup])
except Exception as e:
error("Failed to start new instance: %s" % e)
cleanup("null", "null")
warning("Starting instance, please give about 4 minutes for it to fully boot")
#sleep for 4 minutes while booting images
for i in range(21):
sys.stdout.write('\r')
sys.stdout.write("[%-20s] %d%%" % ('='*i, 5*i))
sys.stdout.flush()
time.sleep(11.5)
print "\n"
# Add tag name to instance for better management
for instance in reservations.instances:
instance.add_tag("Name", nameTag)
debug("Tag Name: " + nameTag)
# Grab list of public IP's assigned to instances that were launched
reservations = conn.get_all_instances(filters={"tag:Name" : nameTag, "instance-state-name" : "running"})
for reservation in reservations:
for instance in reservation.instances:
if (instance.ip_address):
if args.dns:
success("Provisioning DNS")
provision_dns(instance.ip_address, args.dns)
return instance.ip_address
else:
error("Failed to allocate address")
cleanup("foo", "Bar")
#############################################################################################
# Launch Empire
#############################################################################################
def launch_empire():
# Launch Instance
debug("Launching Empire Instance")
ip_address = launch_instance()
# Provision instance
success("Provisioning Instance")
# Permit Root Logon
success("Enabling Root Logon")
cmd = "sudo sed -i \"s/PermitRootLogin without-password/PermitRootLogin yes/\" /etc/ssh/sshd_config"
remote_ssh('ubuntu', ip_address, cmd)
# Copy Keys
success("Updating SSH Keys")
cmd = "sudo cp /home/ubuntu/.ssh/authorized_keys /root/.ssh/"
remote_ssh('ubuntu', ip_address, cmd)
# Restarting Service to take new config (you'd think a simple reload would be enough)
success("Restarting SSH service")
cmd = "sudo service ssh restart"
remote_ssh('ubuntu', ip_address, cmd)
# Provision Empire
success('Installing dependencies')
cmd = "apt-get update; apt-get install screen git sqlite3 python-setuptools python-dev swig swig2.0 build-essential -y"
remote_ssh('root', ip_address, cmd)
success('Even more dependencies')
cmd = 'easy_install pip; pip install --upgrade virtualenv'
remote_ssh('root', ip_address, cmd)
success('Cloning github repo')
cmd = 'git clone https://github.com/PowerShellEmpire/Empire'
remote_ssh('root', ip_address, cmd)
success('Setting STAGING_KEY and Installing Empire')
cmd = 'cd Empire/setup; export STAGING_KEY="DEADBEEFDEADBEEFDEADBEEF"; ./install.sh'
remote_ssh('root', ip_address, cmd)
success('Changing root profile')
cmd = 'echo "screen -x" >> /root/.profile'
remote_ssh('root', ip_address, cmd)
retcode = 0
# Start REST Server (we do this seperately since we need to background it)
success('Starting REST server')
remote_ssh('root', ip_address, cmd)
sshcmd = "ssh -i %s/.ssh/%s.pem -o StrictHostKeyChecking=no root@%s 'cd /root/Empire/; ./empire --rest --password \'POTATOFACE\''&" % (homeDir, keyName, ip_address)
debug("SHELL CMD: " + sshcmd)
retry_cnt = 0
while ((retcode == 1) or (retry_cnt < 6)):
retcode = subprocess.call(sshcmd, shell=True, stdout=FNULL, stderr=subprocess.STDOUT)
if retcode:
warning("ERROR: Failed to start REST server %s. Retrying..." % ip_address)
retry_cnt = retry_cnt + 1
time.sleep(1)
else:
retry_cnt = 6 # probably a better way to do this
if retry_cnt == 5:
error("Giving up")
cleanup("foo", "bar")
time.sleep(5)
# Get Session
success('Obtaining session id')
url = "https://%s:1337/api/admin/login" % ip_address
debug("URL: " + url)
headers = {'content-type': 'application/json'}
data = {'username':'empireadmin', 'password':'POTATOFACE'}
debug("DATA: " + str(data))
# import requests
response = requests.post(url, data=json.dumps(data), verify=False, headers=headers)
debug("RESPONSE CODE: " + str(response.status_code))
jdata = json.loads(response.content)
API_TOKEN = jdata['token']
# Start Listener
success('Starting Empire listener')
url = "https://%s:1337/api/listeners?token=%s" % (ip_address, API_TOKEN)
if args.dns:
listener_url = 'http://' + args.dns + '.' + ZONE_NAME + ':' + args.port
else:
listener_url = 'http://' + ip_address + ':' + args.port
data = {'Name':'https', 'Host':listener_url, 'CertPath':'./data/empire.pem'}
debug("DATA: " + str(data))
response = requests.post(url, data=json.dumps(data), verify=False, headers=headers)
debug("RESPONSE CODE: " + str(response.status_code))
jdata = json.loads(response.content)
# Get Powershell stager
success('Obtaining PowerShell stager')
url = "https://%s:1337/api/stagers?token=%s" % (ip_address, API_TOKEN)
data = {'StagerName':'launcher', 'Listener':'https'}
debug("DATA: " + str(data))
response = requests.post(url, data=json.dumps(data), verify=False, headers=headers)
debug("RESPONSE CODE: " + str(response.status_code))
jdata = json.loads(response.content)
# Write launcher to tmp file
f = open("/tmp/" + psPayload, 'w')
f.write(str(jdata['launcher'][u'Output']))
f.close()
# We now have to kill the empire --rest instance because it hijacks notifications. such a fucking hack
success('Killing Empire REST server, because its being dumb and doesnt play well with others')
sshcmd = "ssh -i %s/.ssh/%s.pem -o StrictHostKeyChecking=no root@%s 'killall -9 /usr/bin/python'" % (homeDir, keyName, ip_address)
debug("SHELL CMD: " + sshcmd)
retry_cnt = 0
while ((retcode == 1) or (retry_cnt < 6)):
retcode = subprocess.call(sshcmd, shell=True, stdout=FNULL, stderr=subprocess.STDOUT)
if retcode:
warning("ERROR: Failed to kill Empire Rest server on %s. Retrying..." % ip_address)
retry_cnt = retry_cnt + 1
time.sleep(1)
else:
retry_cnt = 6 # probably a better way to do this
if retry_cnt == 5:
error("Giving up")
cleanup("foo", "bar")
# Launch Empire on remote host, but backgrounded as a screen session
success('Starting Remote Empire Instance')
cmd = 'screen -d -m bash -c "cd /root/Empire/; ./empire; exec bash"'
remote_ssh('root', ip_address, cmd)
success('Launching Powershell window')
terminalcmd = "%s --geometry=104x28+960+540 --title='Powershell' -e 'vi /tmp/%s'" % (terminal_path, psPayload)
debug("Terminal CMD: " + terminalcmd)
subprocess.call(terminalcmd, shell=True, stdout=FNULL, stderr=subprocess.STDOUT)
# Launch xterm window
success('Launching Empire console')
sshcmd = "/usr/bin/ssh -i %s/.ssh/%s.pem -o StrictHostKeyChecking=no -o TCPKeepAlive=yes -o ServerAliveInterval=50 root@%s" % (homeDir, keyName, ip_address)
debug("SHELL CMD: " + sshcmd)
terminalcmd = "%s --geometry=104x28+960+0 --title='Empire on %s' -e '%s'" % ( terminal_path, ip_address, sshcmd)
debug("Terminal CMD: " + terminalcmd)
subprocess.call(terminalcmd, shell=True, stdout=FNULL, stderr=subprocess.STDOUT)
success('Done!')
#############################################################################################
# Launch Dirb
#############################################################################################
def launch_dirb():
# Custom wordlist
warning("[optional] Enter /path/wordlist to be upload. Enter for none.")
wordlist = raw_input("wordlist: ")
# Launch instances
debug('Launching dirb instance')
ip_address = launch_instance()
# Provision instance
success("Provisioning instance")
# Permit Root Logon
success("Enabling root logon")
cmd = "sudo sed -i \"s/PermitRootLogin without-password/PermitRootLogin yes/\" /etc/ssh/sshd_config"
remote_ssh('ubuntu', ip_address, cmd)
# Copy Keys
success("Updating SSH keys")
cmd = "sudo cp /home/ubuntu/.ssh/authorized_keys /root/.ssh/"
remote_ssh('ubuntu', ip_address, cmd)
# Restarting Service to take new config (you'd think a simple reload would be enough)
success("Restarting SSH service")
cmd = "sudo service ssh restart"
remote_ssh('ubuntu', ip_address, cmd)
# Install Dependencies
success('Installing dependencies')
cmd = "apt-get update; apt-get install libcurl4-gnutls-dev make -y"
remote_ssh('root', ip_address, cmd)
# Downloading dirb and extracting bundle
success('Aquiring dib')
cmd = 'wget https://sourceforge.net/projects/dirb/files/latest/download?source=files -O dirb.tgz; tar -xzf dirb.tgz'
remote_ssh('root', ip_address, cmd)
# Installing Dirb
success('Installing dirb')
cmd = 'cd dirb222; chmod +x configure; ./configure; make; make install'
remote_ssh('root', ip_address, cmd)
# Moving wordlist
success('Moving wordlist')
cmd = 'mv dirb222/wordlists wordlists'
remote_ssh('root', ip_address, cmd)
if (len(wordlist) > 0):
success('Uploading custom wordlist')
wordlist_filename = wordlist.split('/')
remote_scp('root', ip_address, wordlist, './wordlists/' + wordlist_filename[-1])
# Launch xterm window
success('Launching dirb console')
sshcmd = "/usr/bin/ssh -i %s/.ssh/%s.pem -o StrictHostKeyChecking=no -o TCPKeepAlive=yes -o ServerAliveInterval=50 root@%s" % (homeDir, keyName, ip_address)
debug("SHELL CMD: " + sshcmd)
terminalcmd = "%s --geometry=104x28+960+0 --title='Dirb on %s' -e '%s'" % ( terminal_path, ip_address, sshcmd)
debug("Terminal CMD: " + terminalcmd)
subprocess.call(terminalcmd, shell=True, stdout=FNULL, stderr=subprocess.STDOUT)
success('Done!')
#############################################################################################
# Launch Metasploit Console
#############################################################################################
def launch_msf():
# Custom Resource Script
warning("Enter /path/rc file to be upload. Enter for none.")
metasploitrc = raw_input("Metasploit RC: ")
# Launch instances
debug('Launching metasploit instance')
ip_address = launch_instance()
# Provision instance
success("Provisioning instance")
# Permit Root Logon
success("Enabling root logon")
cmd = "sudo sed -i \"s/PermitRootLogin without-password/PermitRootLogin yes/\" /etc/ssh/sshd_config"
remote_ssh('ubuntu', ip_address, cmd)
# Copy Keys
success("Updating SSH keys")
cmd = "sudo cp /home/ubuntu/.ssh/authorized_keys /root/.ssh/"
remote_ssh('ubuntu', ip_address, cmd)
# Restarting Service to take new config (you'd think a simple reload would be enough)
success("Restarting SSH service")
cmd = "sudo service ssh restart"
remote_ssh('ubuntu', ip_address, cmd)
# Installing Dependencies for MSF
success('Installing dependencies')
cmd = "apt-get update; apt-get install subversion build-essential libreadline-dev libssl-dev libpq5 libpq-dev libreadline5 libsqlite3-dev libpcap-dev openjdk-7-jre git-core autoconf postgresql pgadmin3 curl zlib1g-dev libxml2-dev libxslt1-dev vncviewer libyaml-dev curl zlib1g-dev rbenv git -y"
remote_ssh('root', ip_address, cmd)
# Install Ruby
success('Installing ruby')
cmd = 'gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3'
remote_ssh('root', ip_address, cmd)
cmd = 'curl -sSL https://get.rvm.io | bash -s stable --ruby'
remote_ssh('root', ip_address, cmd)
cmd = 'echo "source /usr/local/rvm/scripts/rvm" >> .bashrc'
remote_ssh('root', ip_address, cmd)
cmd = 'source /usr/local/rvm/scripts/rvm; rvm install ruby-2.3.1; rvm use 2.3.1 --default'
remote_ssh('root', ip_address, cmd)
# Install nmap
success('Installing nmap (from source)')
cmd = 'cd /usr/src; svn co https://svn.nmap.org/nmap; cd nmap; ./configure; make; make install; make clean'
remote_ssh('root', ip_address, cmd)
# Install Metasploit
success('Installing Metasploit (please wait)')
cmd = 'source /usr/local/rvm/scripts/rvm; rvm use 2.3.1 --default; ruby -v; cd /opt; git clone https://github.com/rapid7/metasploit-framework.git; chown -R root /opt/metasploit-framework; cd metasploit-framework; gem install bundler; bundle install'
remote_ssh('root', ip_address, cmd)
if (len(metasploitrc) > 0):
success('Uploading custom metasploit rc file')
metasploitrc_filename = metasploitrc.split('/')
remote_scp('root', ip_address, metasploitrc, './' + metasploitrc_filename[-1])
# Update login profile
success('Updating profile')
if (len(metasploitrc) > 0):
cmd = 'echo "cd /opt/metasploit-framework; ./msfconsole -r /root/%s" >> .bashrc' % metasploitrc_filename[-1]
else:
cmd = 'echo "cd /opt/metasploit-framework; ./msfconsole" >> .bashrc'
remote_ssh('root', ip_address, cmd)
# Launch xterm window
success('Launching msf console')
sshcmd = "/usr/bin/ssh -i %s/.ssh/%s.pem -o StrictHostKeyChecking=no -o TCPKeepAlive=yes -o ServerAliveInterval=50 root@%s" % (homeDir, keyName, ip_address)
debug("SHELL CMD: " + sshcmd)
terminalcmd = "%s --geometry=104x56+960+0 --title='MSF on %s' -e '%s'" % ( terminal_path, ip_address, sshcmd)
debug("Terminal CMD: " + terminalcmd)
subprocess.call(terminalcmd, shell=True, stdout=FNULL, stderr=subprocess.STDOUT)
success('Done!')
#############################################################################################
# Launch Plain Console
#############################################################################################
def launch_plain():
# Launch instances
debug('Launching plain instance')
ip_address = launch_instance()
# Launch xterm window
success('Launching console console')
sshcmd = "/usr/bin/ssh -i %s/.ssh/%s.pem -o StrictHostKeyChecking=no -o TCPKeepAlive=yes -o ServerAliveInterval=50 ubuntu@%s" % (homeDir, keyName, ip_address)
debug("SHELL CMD: " + sshcmd)
terminalcmd = "%s --geometry=104x56+960+0 --title='SSH on %s' -e '%s'" % ( terminal_path, ip_address, sshcmd)
debug("Terminal CMD: " + terminalcmd)
subprocess.call(terminalcmd, shell=True, stdout=FNULL, stderr=subprocess.STDOUT)
success('Done!')
#############################################################################################
# Launch WWW Console
#############################################################################################
def launch_www():
# Custom Resource Script
warning("Enter /path/payload.exe file to be upload/hosted. Enter for none.")
payload = raw_input("Payload: ")
# Launch instances
debug('Launching www instance')
ip_address = launch_instance()
# Provision instance
success("Provisioning Instance")
# Permit Root Logon
success("Enabling Root Logon")
cmd = "sudo sed -i \"s/PermitRootLogin without-password/PermitRootLogin yes/\" /etc/ssh/sshd_config"
remote_ssh('ubuntu', ip_address, cmd)
# Copy Keys
success("Updating SSH Keys")
cmd = "sudo cp /home/ubuntu/.ssh/authorized_keys /root/.ssh/"
remote_ssh('ubuntu', ip_address, cmd)
# Restarting Service to take new config (you'd think a simple reload would be enough)
success("Restarting SSH service")
cmd = "sudo service ssh restart"
remote_ssh('ubuntu', ip_address, cmd)
# Install Dependencies
success('Installing dependencies')
cmd = "apt-get update; apt-get install screen -y"
remote_ssh('root', ip_address, cmd)
# create hosting dir
success('Setting up www root')
cmd = "mkdir /var/www; chown ubuntu /var/www;"
remote_ssh('root', ip_address, cmd)
if (len(payload) > 0):
success('Uploading payload for hosting')
payload_filename = payload.split('/')
remote_scp('root', ip_address, payload, '/var/www/' + payload_filename[-1])
# Launch python simpler server on remote host, but backgrounded as a screen session
success('Starting python SimpleHTTPServer Instance')
cmd = 'screen -d -m bash -c "cd /var/www/; sudo python -m SimpleHTTPServer ' + args.port + '; exec bash"'
remote_ssh('ubuntu', ip_address, cmd)
# Update ubuntu profile
success('Changing ubuntu profile')
cmd = 'echo "screen -x" >> .profile'
remote_ssh('ubuntu', ip_address, cmd)
# Launch xterm window
success('Launching console console')
sshcmd = "/usr/bin/ssh -i %s/.ssh/%s.pem -o StrictHostKeyChecking=no -o TCPKeepAlive=yes -o ServerAliveInterval=50 ubuntu@%s" % (homeDir, keyName, ip_address)
debug("SHELL CMD: " + sshcmd)
terminalcmd = "%s --geometry=104x56+960+0 --title='www on %s' -e '%s'" % ( terminal_path, ip_address, sshcmd)
debug("Terminal CMD: " + terminalcmd)
subprocess.call(terminalcmd, shell=True, stdout=FNULL, stderr=subprocess.STDOUT)
success('Done!')
if (len(payload) > 0):
success("File hosted at: http://" + args.dns + "." + ZONE_NAME + ":" + args.port + "/" + payload_filename[-1])
else:
success("Webserver started at: http://" + args.dns + "." + ZONE_NAME + ":" + args.port + "/")
#############################################################################################
# Launch Pentetration Testers Framework (PTF)
#############################################################################################
def launch_ptf():
# Launch instances
debug('Launching Penetration Testers Framework (PTF) instance')
ip_address = launch_instance()
# Provision instance
success("Provisioning instance")
# Permit Root Logon
success("Enabling root logon")
cmd = "sudo sed -i \"s/PermitRootLogin without-password/PermitRootLogin yes/\" /etc/ssh/sshd_config"
remote_ssh('ubuntu', ip_address, cmd)
# Copy Keys
success("Updating SSH keys")
cmd = "sudo cp /home/ubuntu/.ssh/authorized_keys /root/.ssh/"
remote_ssh('ubuntu', ip_address, cmd)
# Restarting Service to take new config (you'd think a simple reload would be enough)
success("Restarting SSH service")
cmd = "sudo service ssh restart"
remote_ssh('ubuntu', ip_address, cmd)
# Installing Dependencies for PTF
success('Installing dependencies')
cmd = "apt-get update; apt-get install subversion python-setuptools python-dev screen git git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev -y"
remote_ssh('root', ip_address, cmd)
success('Even more dependencies')
cmd = 'easy_install pip; pip install --upgrade virtualenv'
remote_ssh('root', ip_address, cmd)
# Install Ruby
success('Installing ruby')
cmd = 'gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3'
remote_ssh('root', ip_address, cmd)
cmd = 'curl -sSL https://get.rvm.io | bash -s stable --ruby'
remote_ssh('root', ip_address, cmd)
cmd = 'echo "source /usr/local/rvm/scripts/rvm" >> .bashrc'
remote_ssh('root', ip_address, cmd)
cmd = 'source /usr/local/rvm/scripts/rvm; rvm install ruby-2.3.1; rvm use 2.3.1 --default'
remote_ssh('root', ip_address, cmd)
# Install ptf
success('Installing PTF')
cmd = 'git clone https://github.com/trustedsec/ptf'
remote_ssh('root', ip_address, cmd)
# Launch PTF on remote host, but backgrounded as a screen session
success('Starting python SimpleHTTPServer Instance')
cmd = 'screen -d -m bash -c "cd ptf; ./ptf; exec bash"'
remote_ssh('root', ip_address, cmd)
# Update ubuntu profile
success('Changing ubuntu profile')
cmd = 'echo "screen -x" >> .profile'
remote_ssh('root', ip_address, cmd)
# Launch xterm window
success('Launching console console')
sshcmd = "/usr/bin/ssh -i %s/.ssh/%s.pem -o StrictHostKeyChecking=no -o TCPKeepAlive=yes -o ServerAliveInterval=50 root@%s" % (homeDir, keyName, ip_address)
debug("SHELL CMD: " + sshcmd)
terminalcmd = "%s --geometry=104x56+960+0 --title='ptf on %s' -e '%s'" % ( terminal_path, ip_address, sshcmd)
debug("Terminal CMD: " + terminalcmd)
subprocess.call(terminalcmd, shell=True, stdout=FNULL, stderr=subprocess.STDOUT)
success('Done!')
#############################################################################################
# Main
#############################################################################################
if args.app == "empire":
launch_empire()
elif args.app == "dirb":
launch_dirb()
elif args.app == "msf":
launch_msf()
elif args.app == "plain":
launch_plain()
elif args.app == "www":
launch_www()
elif args.app == "ptf":
launch_ptf()
else:
sys.exit(-1)
print "\n+++++++++++++++++++++++++++++"
print "+ Leave this terminal open! +"
print "+++++++++++++++++++++++++++++\n"
print "[" + bcolors.WARNING + "~" + bcolors.ENDC +"] Press " + bcolors.BOLD + "ctrl + c" + bcolors.ENDC + " to terminate the script gracefully."
while 1:
null = raw_input()