forked from rebootuser/LinEnum
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LinEnum.sh
executable file
·1340 lines (1146 loc) · 44.6 KB
/
LinEnum.sh
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
#!/bin/bash
#A script to enumerate local information from a Linux host
version="version 0.96"
#@rebootuser
#help function
usage ()
{
echo -e "\n\e[00;31m#########################################################\e[00m"
echo -e "\e[00;31m#\e[00m" "\e[00;33mLocal Linux Enumeration & Privilege Escalation Script\e[00m" "\e[00;31m#\e[00m"
echo -e "\e[00;31m#########################################################\e[00m"
echo -e "\e[00;33m# www.rebootuser.com | @rebootuser \e[00m"
echo -e "\e[00;33m# $version\e[00m\n"
echo -e "\e[00;33m# Example: ./LinEnum.sh -k keyword -r report -e /tmp/ -t \e[00m\n"
echo "OPTIONS:"
echo "-k Enter keyword"
echo "-e Enter export location"
echo "-s Supply user password for sudo checks (INSECURE)"
echo "-t Include thorough (lengthy) tests"
echo "-r Enter report name"
echo "-h Displays this help text"
echo -e "\n"
echo "Running with no options = limited scans/no output file"
echo -e "\e[00;31m#########################################################\e[00m"
}
header()
{
echo -e "\n\e[00;31m#########################################################\e[00m"
echo -e "\e[00;31m#\e[00m" "\e[00;33mLocal Linux Enumeration & Privilege Escalation Script\e[00m" "\e[00;31m#\e[00m"
echo -e "\e[00;31m#########################################################\e[00m"
echo -e "\e[00;33m# www.rebootuser.com\e[00m"
echo -e "\e[00;33m# $version\e[00m\n"
}
debug_info()
{
echo "[-] Debug Info"
if [ "$keyword" ]; then
echo "[+] Searching for the keyword $keyword in conf, php, ini and log files"
fi
if [ "$report" ]; then
echo "[+] Report name = $report"
fi
if [ "$export" ]; then
echo "[+] Export location = $export"
fi
if [ "$thorough" ]; then
echo "[+] Thorough tests = Enabled"
else
echo -e "\e[00;33m[+] Thorough tests = Disabled\e[00m"
fi
sleep 2
if [ "$export" ]; then
mkdir $export 2>/dev/null
format=$export/LinEnum-export-`date +"%d-%m-%y"`
mkdir $format 2>/dev/null
fi
if [ "$sudopass" ]; then
echo -e "\e[00;35m[+] Please enter password - INSECURE - really only for CTF use!\e[00m"
read -s userpassword
echo
fi
who=`whoami` 2>/dev/null
echo -e "\n"
echo -e "\e[00;33mScan started at:"; date
echo -e "\e[00m\n"
}
# useful binaries (thanks to https://gtfobins.github.io/)
binarylist='nmap\|perl\|awk\|find\|bash\|sh\|man\|more\|less\|vi\|emacs\|vim\|nc\|netcat\|python\|ruby\|lua\|irb\|tar\|zip\|gdb\|pico\|scp\|git\|rvim\|script\|ash\|csh\|curl\|dash\|ed\|env\|expect\|ftp\|sftp\|node\|php\|rpm\|rpmquery\|socat\|strace\|taskset\|tclsh\|telnet\|tftp\|wget\|wish\|zsh\|ssh$\|ip$\|arp\|mtr'
system_info()
{
echo -e "\e[00;33m### SYSTEM ##############################################\e[00m"
#basic kernel info
unameinfo=`uname -a 2>/dev/null`
if [ "$unameinfo" ]; then
echo -e "\e[00;31m[-] Kernel information:\e[00m\n$unameinfo"
echo -e "\n"
fi
procver=`cat /proc/version 2>/dev/null`
if [ "$procver" ]; then
echo -e "\e[00;31m[-] Kernel information (continued):\e[00m\n$procver"
echo -e "\n"
fi
#search all *-release files for version info
release=`cat /etc/*-release 2>/dev/null`
if [ "$release" ]; then
echo -e "\e[00;31m[-] Specific release information:\e[00m\n$release"
echo -e "\n"
fi
#target hostname info
hostnamed=`hostname 2>/dev/null`
if [ "$hostnamed" ]; then
echo -e "\e[00;31m[-] Hostname:\e[00m\n$hostnamed"
echo -e "\n"
fi
}
user_info()
{
echo -e "\e[00;33m### USER/GROUP ##########################################\e[00m"
#current user details
currusr=`id 2>/dev/null`
if [ "$currusr" ]; then
echo -e "\e[00;31m[-] Current user/group info:\e[00m\n$currusr"
echo -e "\n"
fi
#last logged on user information
lastlogedonusrs=`lastlog 2>/dev/null |grep -v "Never" 2>/dev/null`
if [ "$lastlogedonusrs" ]; then
echo -e "\e[00;31m[-] Users that have previously logged onto the system:\e[00m\n$lastlogedonusrs"
echo -e "\n"
fi
#who else is logged on
loggedonusrs=`w 2>/dev/null`
if [ "$loggedonusrs" ]; then
echo -e "\e[00;31m[-] Who else is logged on:\e[00m\n$loggedonusrs"
echo -e "\n"
fi
#lists all id's and respective group(s)
grpinfo=`for i in $(cut -d":" -f1 /etc/passwd 2>/dev/null);do id $i;done 2>/dev/null`
if [ "$grpinfo" ]; then
echo -e "\e[00;31m[-] Group memberships:\e[00m\n$grpinfo"
echo -e "\n"
fi
#added by phackt - look for adm group (thanks patrick)
adm_users=$(echo -e "$grpinfo" | grep "(adm)")
if [[ ! -z $adm_users ]];
then
echo -e "\e[00;31m[-] It looks like we have some admin users:\e[00m\n$adm_users"
echo -e "\n"
fi
#checks to see if any hashes are stored in /etc/passwd (depreciated *nix storage method)
hashesinpasswd=`grep -v '^[^:]*:[x]' /etc/passwd 2>/dev/null`
if [ "$hashesinpasswd" ]; then
echo -e "\e[00;33m[+] It looks like we have password hashes in /etc/passwd!\e[00m\n$hashesinpasswd"
echo -e "\n"
fi
#contents of /etc/passwd
readpasswd=`cat /etc/passwd 2>/dev/null`
if [ "$readpasswd" ]; then
echo -e "\e[00;31m[-] Contents of /etc/passwd:\e[00m\n$readpasswd"
echo -e "\n"
fi
if [ "$export" ] && [ "$readpasswd" ]; then
mkdir $format/etc-export/ 2>/dev/null
cp /etc/passwd $format/etc-export/passwd 2>/dev/null
fi
#checks to see if the shadow file can be read
readshadow=`cat /etc/shadow 2>/dev/null`
if [ "$readshadow" ]; then
echo -e "\e[00;33m[+] We can read the shadow file!\e[00m\n$readshadow"
echo -e "\n"
fi
if [ "$export" ] && [ "$readshadow" ]; then
mkdir $format/etc-export/ 2>/dev/null
cp /etc/shadow $format/etc-export/shadow 2>/dev/null
fi
#checks to see if /etc/master.passwd can be read - BSD 'shadow' variant
readmasterpasswd=`cat /etc/master.passwd 2>/dev/null`
if [ "$readmasterpasswd" ]; then
echo -e "\e[00;33m[+] We can read the master.passwd file!\e[00m\n$readmasterpasswd"
echo -e "\n"
fi
if [ "$export" ] && [ "$readmasterpasswd" ]; then
mkdir $format/etc-export/ 2>/dev/null
cp /etc/master.passwd $format/etc-export/master.passwd 2>/dev/null
fi
#all root accounts (uid 0)
superman=`grep -v -E "^#" /etc/passwd 2>/dev/null| awk -F: '$3 == 0 { print $1}' 2>/dev/null`
if [ "$superman" ]; then
echo -e "\e[00;31m[-] Super user account(s):\e[00m\n$superman"
echo -e "\n"
fi
#pull out vital sudoers info
sudoers=`grep -v -e '^$' /etc/sudoers 2>/dev/null |grep -v "#" 2>/dev/null`
if [ "$sudoers" ]; then
echo -e "\e[00;31m[-] Sudoers configuration (condensed):\e[00m$sudoers"
echo -e "\n"
fi
if [ "$export" ] && [ "$sudoers" ]; then
mkdir $format/etc-export/ 2>/dev/null
cp /etc/sudoers $format/etc-export/sudoers 2>/dev/null
fi
#can we sudo without supplying a password
sudoperms=`echo '' | sudo -S -l -k 2>/dev/null`
if [ "$sudoperms" ]; then
echo -e "\e[00;33m[+] We can sudo without supplying a password!\e[00m\n$sudoperms"
echo -e "\n"
fi
#check sudo perms - authenticated
if [ "$sudopass" ]; then
if [ "$sudoperms" ]; then
:
else
sudoauth=`echo $userpassword | sudo -S -l -k 2>/dev/null`
if [ "$sudoauth" ]; then
echo -e "\e[00;33m[+] We can sudo when supplying a password!\e[00m\n$sudoauth"
echo -e "\n"
fi
fi
fi
##known 'good' breakout binaries (cleaned to parse /etc/sudoers for comma separated values) - authenticated
if [ "$sudopass" ]; then
if [ "$sudoperms" ]; then
:
else
sudopermscheck=`echo $userpassword | sudo -S -l -k 2>/dev/null | xargs -n 1 2>/dev/null|sed 's/,*$//g' 2>/dev/null | grep -w $binarylist 2>/dev/null`
if [ "$sudopermscheck" ]; then
echo -e "\e[00;33m[-] Possible sudo pwnage!\e[00m\n$sudopermscheck"
echo -e "\n"
fi
fi
fi
#known 'good' breakout binaries (cleaned to parse /etc/sudoers for comma separated values)
sudopwnage=`echo '' | sudo -S -l -k 2>/dev/null | xargs -n 1 2>/dev/null | sed 's/,*$//g' 2>/dev/null | grep -w $binarylist 2>/dev/null`
if [ "$sudopwnage" ]; then
echo -e "\e[00;33m[+] Possible sudo pwnage!\e[00m\n$sudopwnage"
echo -e "\n"
fi
#who has sudoed in the past
whohasbeensudo=`find /home -name .sudo_as_admin_successful 2>/dev/null`
if [ "$whohasbeensudo" ]; then
echo -e "\e[00;31m[-] Accounts that have recently used sudo:\e[00m\n$whohasbeensudo"
echo -e "\n"
fi
#checks to see if roots home directory is accessible
rthmdir=`ls -ahl /root/ 2>/dev/null`
if [ "$rthmdir" ]; then
echo -e "\e[00;33m[+] We can read root's home directory!\e[00m\n$rthmdir"
echo -e "\n"
fi
#displays /home directory permissions - check if any are lax
homedirperms=`ls -ahl /home/ 2>/dev/null`
if [ "$homedirperms" ]; then
echo -e "\e[00;31m[-] Are permissions on /home directories lax:\e[00m\n$homedirperms"
echo -e "\n"
fi
#looks for files we can write to that don't belong to us
if [ "$thorough" = "1" ]; then
grfilesall=`find / -writable ! -user \`whoami\` -type f ! -path "/proc/*" ! -path "/sys/*" -exec ls -al {} \; 2>/dev/null`
if [ "$grfilesall" ]; then
echo -e "\e[00;31m[-] Files not owned by user but writable by group:\e[00m\n$grfilesall"
echo -e "\n"
fi
fi
#looks for files that belong to us
if [ "$thorough" = "1" ]; then
ourfilesall=`find / -user \`whoami\` -type f ! -path "/proc/*" ! -path "/sys/*" -exec ls -al {} \; 2>/dev/null`
if [ "$ourfilesall" ]; then
echo -e "\e[00;31m[-] Files owned by our user:\e[00m\n$ourfilesall"
echo -e "\n"
fi
fi
#looks for hidden files
if [ "$thorough" = "1" ]; then
hiddenfiles=`find / -name ".*" -type f ! -path "/proc/*" ! -path "/sys/*" -exec ls -al {} \; 2>/dev/null`
if [ "$hiddenfiles" ]; then
echo -e "\e[00;31m[-] Hidden files:\e[00m\n$hiddenfiles"
echo -e "\n"
fi
fi
#looks for world-reabable files within /home - depending on number of /home dirs & files, this can take some time so is only 'activated' with thorough scanning switch
if [ "$thorough" = "1" ]; then
wrfileshm=`find /home/ -perm -4 -type f -exec ls -al {} \; 2>/dev/null`
if [ "$wrfileshm" ]; then
echo -e "\e[00;31m[-] World-readable files within /home:\e[00m\n$wrfileshm"
echo -e "\n"
fi
fi
if [ "$thorough" = "1" ]; then
if [ "$export" ] && [ "$wrfileshm" ]; then
mkdir $format/wr-files/ 2>/dev/null
for i in $wrfileshm; do cp --parents $i $format/wr-files/ ; done 2>/dev/null
fi
fi
#lists current user's home directory contents
if [ "$thorough" = "1" ]; then
homedircontents=`ls -ahl ~ 2>/dev/null`
if [ "$homedircontents" ] ; then
echo -e "\e[00;31m[-] Home directory contents:\e[00m\n$homedircontents"
echo -e "\n"
fi
fi
#checks for if various ssh files are accessible - this can take some time so is only 'activated' with thorough scanning switch
if [ "$thorough" = "1" ]; then
sshfiles=`find / \( -name "id_dsa*" -o -name "id_rsa*" -o -name "known_hosts" -o -name "authorized_hosts" -o -name "authorized_keys" \) -exec ls -la {} 2>/dev/null \;`
if [ "$sshfiles" ]; then
echo -e "\e[00;31m[-] SSH keys/host information found in the following locations:\e[00m\n$sshfiles"
echo -e "\n"
fi
fi
if [ "$thorough" = "1" ]; then
if [ "$export" ] && [ "$sshfiles" ]; then
mkdir $format/ssh-files/ 2>/dev/null
for i in $sshfiles; do cp --parents $i $format/ssh-files/; done 2>/dev/null
fi
fi
#is root permitted to login via ssh
sshrootlogin=`grep "PermitRootLogin " /etc/ssh/sshd_config 2>/dev/null | grep -v "#" | awk '{print $2}'`
if [ "$sshrootlogin" = "yes" ]; then
echo -e "\e[00;31m[-] Root is allowed to login via SSH:\e[00m" ; grep "PermitRootLogin " /etc/ssh/sshd_config 2>/dev/null | grep -v "#"
echo -e "\n"
fi
}
environmental_info()
{
echo -e "\e[00;33m### ENVIRONMENTAL #######################################\e[00m"
#env information
envinfo=`env 2>/dev/null | grep -v 'LS_COLORS' 2>/dev/null`
if [ "$envinfo" ]; then
echo -e "\e[00;31m[-] Environment information:\e[00m\n$envinfo"
echo -e "\n"
fi
#check if selinux is enabled
sestatus=`sestatus 2>/dev/null`
if [ "$sestatus" ]; then
echo -e "\e[00;31m[-] SELinux seems to be present:\e[00m\n$sestatus"
echo -e "\n"
fi
#phackt
#current path configuration
pathinfo=`echo $PATH 2>/dev/null`
if [ "$pathinfo" ]; then
echo -e "\e[00;31m[-] Path information:\e[00m\n$pathinfo"
echo -e "\n"
fi
#lists available shells
shellinfo=`cat /etc/shells 2>/dev/null`
if [ "$shellinfo" ]; then
echo -e "\e[00;31m[-] Available shells:\e[00m\n$shellinfo"
echo -e "\n"
fi
#current umask value with both octal and symbolic output
umaskvalue=`umask -S 2>/dev/null & umask 2>/dev/null`
if [ "$umaskvalue" ]; then
echo -e "\e[00;31m[-] Current umask value:\e[00m\n$umaskvalue"
echo -e "\n"
fi
#umask value as in /etc/login.defs
umaskdef=`grep -i "^UMASK" /etc/login.defs 2>/dev/null`
if [ "$umaskdef" ]; then
echo -e "\e[00;31m[-] umask value as specified in /etc/login.defs:\e[00m\n$umaskdef"
echo -e "\n"
fi
#password policy information as stored in /etc/login.defs
logindefs=`grep "^PASS_MAX_DAYS\|^PASS_MIN_DAYS\|^PASS_WARN_AGE\|^ENCRYPT_METHOD" /etc/login.defs 2>/dev/null`
if [ "$logindefs" ]; then
echo -e "\e[00;31m[-] Password and storage information:\e[00m\n$logindefs"
echo -e "\n"
fi
if [ "$export" ] && [ "$logindefs" ]; then
mkdir $format/etc-export/ 2>/dev/null
cp /etc/login.defs $format/etc-export/login.defs 2>/dev/null
fi
}
job_info()
{
echo -e "\e[00;33m### JOBS/TASKS ##########################################\e[00m"
#are there any cron jobs configured
cronjobs=`ls -la /etc/cron* 2>/dev/null`
if [ "$cronjobs" ]; then
echo -e "\e[00;31m[-] Cron jobs:\e[00m\n$cronjobs"
echo -e "\n"
fi
#can we manipulate these jobs in any way
cronjobwwperms=`find /etc/cron* -perm -0002 -type f -exec ls -la {} \; -exec cat {} 2>/dev/null \;`
if [ "$cronjobwwperms" ]; then
echo -e "\e[00;33m[+] World-writable cron jobs and file contents:\e[00m\n$cronjobwwperms"
echo -e "\n"
fi
#contab contents
crontabvalue=`cat /etc/crontab 2>/dev/null`
if [ "$crontabvalue" ]; then
echo -e "\e[00;31m[-] Crontab contents:\e[00m\n$crontabvalue"
echo -e "\n"
fi
crontabvar=`ls -la /var/spool/cron/crontabs 2>/dev/null`
if [ "$crontabvar" ]; then
echo -e "\e[00;31m[-] Anything interesting in /var/spool/cron/crontabs:\e[00m\n$crontabvar"
echo -e "\n"
fi
anacronjobs=`ls -la /etc/anacrontab 2>/dev/null; cat /etc/anacrontab 2>/dev/null`
if [ "$anacronjobs" ]; then
echo -e "\e[00;31m[-] Anacron jobs and associated file permissions:\e[00m\n$anacronjobs"
echo -e "\n"
fi
anacrontab=`ls -la /var/spool/anacron 2>/dev/null`
if [ "$anacrontab" ]; then
echo -e "\e[00;31m[-] When were jobs last executed (/var/spool/anacron contents):\e[00m\n$anacrontab"
echo -e "\n"
fi
#pull out account names from /etc/passwd and see if any users have associated cronjobs (priv command)
cronother=`cut -d ":" -f 1 /etc/passwd | xargs -n1 crontab -l -u 2>/dev/null`
if [ "$cronother" ]; then
echo -e "\e[00;31m[-] Jobs held by all users:\e[00m\n$cronother"
echo -e "\n"
fi
# list systemd timers
if [ "$thorough" = "1" ]; then
# include inactive timers in thorough mode
systemdtimers="$(systemctl list-timers --all 2>/dev/null)"
info=""
else
systemdtimers="$(systemctl list-timers 2>/dev/null |head -n -1 2>/dev/null)"
# replace the info in the output with a hint towards thorough mode
info="\e[2mEnable thorough tests to see inactive timers\e[00m"
fi
if [ "$systemdtimers" ]; then
echo -e "\e[00;31m[-] Systemd timers:\e[00m\n$systemdtimers\n$info"
echo -e "\n"
fi
}
networking_info()
{
echo -e "\e[00;33m### NETWORKING ##########################################\e[00m"
#nic information
nicinfo=`/sbin/ifconfig -a 2>/dev/null`
if [ "$nicinfo" ]; then
echo -e "\e[00;31m[-] Network and IP info:\e[00m\n$nicinfo"
echo -e "\n"
fi
#nic information (using ip)
nicinfoip=`/sbin/ip a 2>/dev/null`
if [ ! "$nicinfo" ] && [ "$nicinfoip" ]; then
echo -e "\e[00;31m[-] Network and IP info:\e[00m\n$nicinfoip"
echo -e "\n"
fi
arpinfo=`arp -a 2>/dev/null`
if [ "$arpinfo" ]; then
echo -e "\e[00;31m[-] ARP history:\e[00m\n$arpinfo"
echo -e "\n"
fi
arpinfoip=`ip n 2>/dev/null`
if [ ! "$arpinfo" ] && [ "$arpinfoip" ]; then
echo -e "\e[00;31m[-] ARP history:\e[00m\n$arpinfoip"
echo -e "\n"
fi
#dns settings
nsinfo=`grep "nameserver" /etc/resolv.conf 2>/dev/null`
if [ "$nsinfo" ]; then
echo -e "\e[00;31m[-] Nameserver(s):\e[00m\n$nsinfo"
echo -e "\n"
fi
nsinfosysd=`systemd-resolve --status 2>/dev/null`
if [ "$nsinfosysd" ]; then
echo -e "\e[00;31m[-] Nameserver(s):\e[00m\n$nsinfosysd"
echo -e "\n"
fi
#default route configuration
defroute=`route 2>/dev/null | grep default`
if [ "$defroute" ]; then
echo -e "\e[00;31m[-] Default route:\e[00m\n$defroute"
echo -e "\n"
fi
#default route configuration
defrouteip=`ip r 2>/dev/null | grep default`
if [ ! "$defroute" ] && [ "$defrouteip" ]; then
echo -e "\e[00;31m[-] Default route:\e[00m\n$defrouteip"
echo -e "\n"
fi
#listening TCP
tcpservs=`netstat -antp 2>/dev/null`
if [ "$tcpservs" ]; then
echo -e "\e[00;31m[-] Listening TCP:\e[00m\n$tcpservs"
echo -e "\n"
fi
tcpservsip=`ss -t 2>/dev/null`
if [ ! "$tcpservs" ] && [ "$tcpservsip" ]; then
echo -e "\e[00;31m[-] Listening TCP:\e[00m\n$tcpservsip"
echo -e "\n"
fi
#listening UDP
udpservs=`netstat -anup 2>/dev/null`
if [ "$udpservs" ]; then
echo -e "\e[00;31m[-] Listening UDP:\e[00m\n$udpservs"
echo -e "\n"
fi
udpservsip=`ip -u 2>/dev/null`
if [ ! "$udpservs" ] && [ "$udpservsip" ]; then
echo -e "\e[00;31m[-] Listening UDP:\e[00m\n$udpservsip"
echo -e "\n"
fi
}
services_info()
{
echo -e "\e[00;33m### SERVICES #############################################\e[00m"
#running processes
psaux=`ps aux 2>/dev/null`
if [ "$psaux" ]; then
echo -e "\e[00;31m[-] Running processes:\e[00m\n$psaux"
echo -e "\n"
fi
#lookup process binary path and permissisons
procperm=`ps aux 2>/dev/null | awk '{print $11}'|xargs -r ls -la 2>/dev/null |awk '!x[$0]++' 2>/dev/null`
if [ "$procperm" ]; then
echo -e "\e[00;31m[-] Process binaries and associated permissions (from above list):\e[00m\n$procperm"
echo -e "\n"
fi
if [ "$export" ] && [ "$procperm" ]; then
procpermbase=`ps aux 2>/dev/null | awk '{print $11}' | xargs -r ls 2>/dev/null | awk '!x[$0]++' 2>/dev/null`
mkdir $format/ps-export/ 2>/dev/null
for i in $procpermbase; do cp --parents $i $format/ps-export/; done 2>/dev/null
fi
#anything 'useful' in inetd.conf
inetdread=`cat /etc/inetd.conf 2>/dev/null`
if [ "$inetdread" ]; then
echo -e "\e[00;31m[-] Contents of /etc/inetd.conf:\e[00m\n$inetdread"
echo -e "\n"
fi
if [ "$export" ] && [ "$inetdread" ]; then
mkdir $format/etc-export/ 2>/dev/null
cp /etc/inetd.conf $format/etc-export/inetd.conf 2>/dev/null
fi
#very 'rough' command to extract associated binaries from inetd.conf & show permisisons of each
inetdbinperms=`awk '{print $7}' /etc/inetd.conf 2>/dev/null |xargs -r ls -la 2>/dev/null`
if [ "$inetdbinperms" ]; then
echo -e "\e[00;31m[-] The related inetd binary permissions:\e[00m\n$inetdbinperms"
echo -e "\n"
fi
xinetdread=`cat /etc/xinetd.conf 2>/dev/null`
if [ "$xinetdread" ]; then
echo -e "\e[00;31m[-] Contents of /etc/xinetd.conf:\e[00m\n$xinetdread"
echo -e "\n"
fi
if [ "$export" ] && [ "$xinetdread" ]; then
mkdir $format/etc-export/ 2>/dev/null
cp /etc/xinetd.conf $format/etc-export/xinetd.conf 2>/dev/null
fi
xinetdincd=`grep "/etc/xinetd.d" /etc/xinetd.conf 2>/dev/null`
if [ "$xinetdincd" ]; then
echo -e "\e[00;31m[-] /etc/xinetd.d is included in /etc/xinetd.conf - associated binary permissions are listed below:\e[00m"; ls -la /etc/xinetd.d 2>/dev/null
echo -e "\n"
fi
#very 'rough' command to extract associated binaries from xinetd.conf & show permisisons of each
xinetdbinperms=`awk '{print $7}' /etc/xinetd.conf 2>/dev/null |xargs -r ls -la 2>/dev/null`
if [ "$xinetdbinperms" ]; then
echo -e "\e[00;31m[-] The related xinetd binary permissions:\e[00m\n$xinetdbinperms"
echo -e "\n"
fi
initdread=`ls -la /etc/init.d 2>/dev/null`
if [ "$initdread" ]; then
echo -e "\e[00;31m[-] /etc/init.d/ binary permissions:\e[00m\n$initdread"
echo -e "\n"
fi
#init.d files NOT belonging to root!
initdperms=`find /etc/init.d/ \! -uid 0 -type f 2>/dev/null |xargs -r ls -la 2>/dev/null`
if [ "$initdperms" ]; then
echo -e "\e[00;31m[-] /etc/init.d/ files not belonging to root:\e[00m\n$initdperms"
echo -e "\n"
fi
rcdread=`ls -la /etc/rc.d/init.d 2>/dev/null`
if [ "$rcdread" ]; then
echo -e "\e[00;31m[-] /etc/rc.d/init.d binary permissions:\e[00m\n$rcdread"
echo -e "\n"
fi
#init.d files NOT belonging to root!
rcdperms=`find /etc/rc.d/init.d \! -uid 0 -type f 2>/dev/null |xargs -r ls -la 2>/dev/null`
if [ "$rcdperms" ]; then
echo -e "\e[00;31m[-] /etc/rc.d/init.d files not belonging to root:\e[00m\n$rcdperms"
echo -e "\n"
fi
usrrcdread=`ls -la /usr/local/etc/rc.d 2>/dev/null`
if [ "$usrrcdread" ]; then
echo -e "\e[00;31m[-] /usr/local/etc/rc.d binary permissions:\e[00m\n$usrrcdread"
echo -e "\n"
fi
#rc.d files NOT belonging to root!
usrrcdperms=`find /usr/local/etc/rc.d \! -uid 0 -type f 2>/dev/null |xargs -r ls -la 2>/dev/null`
if [ "$usrrcdperms" ]; then
echo -e "\e[00;31m[-] /usr/local/etc/rc.d files not belonging to root:\e[00m\n$usrrcdperms"
echo -e "\n"
fi
initread=`ls -la /etc/init/ 2>/dev/null`
if [ "$initread" ]; then
echo -e "\e[00;31m[-] /etc/init/ config file permissions:\e[00m\n$initread"
echo -e "\n"
fi
# upstart scripts not belonging to root
initperms=`find /etc/init \! -uid 0 -type f 2>/dev/null |xargs -r ls -la 2>/dev/null`
if [ "$initperms" ]; then
echo -e "\e[00;31m[-] /etc/init/ config files not belonging to root:\e[00m\n$initperms"
echo -e "\n"
fi
systemdread=`ls -lthR /lib/systemd/ 2>/dev/null`
if [ "$systemdread" ]; then
echo -e "\e[00;31m[-] /lib/systemd/* config file permissions:\e[00m\n$systemdread"
echo -e "\n"
fi
# systemd files not belonging to root
systemdperms=`find /lib/systemd/ \! -uid 0 -type f 2>/dev/null |xargs -r ls -la 2>/dev/null`
if [ "$systemdperms" ]; then
echo -e "\e[00;33m[+] /lib/systemd/* config files not belonging to root:\e[00m\n$systemdperms"
echo -e "\n"
fi
}
software_configs()
{
echo -e "\e[00;33m### SOFTWARE #############################################\e[00m"
#sudo version - check to see if there are any known vulnerabilities with this
sudover=`sudo -V 2>/dev/null| grep "Sudo version" 2>/dev/null`
if [ "$sudover" ]; then
echo -e "\e[00;31m[-] Sudo version:\e[00m\n$sudover"
echo -e "\n"
fi
#mysql details - if installed
mysqlver=`mysql --version 2>/dev/null`
if [ "$mysqlver" ]; then
echo -e "\e[00;31m[-] MYSQL version:\e[00m\n$mysqlver"
echo -e "\n"
fi
#checks to see if root/root will get us a connection
mysqlconnect=`mysqladmin -uroot -proot version 2>/dev/null`
if [ "$mysqlconnect" ]; then
echo -e "\e[00;33m[+] We can connect to the local MYSQL service with default root/root credentials!\e[00m\n$mysqlconnect"
echo -e "\n"
fi
#mysql version details
mysqlconnectnopass=`mysqladmin -uroot version 2>/dev/null`
if [ "$mysqlconnectnopass" ]; then
echo -e "\e[00;33m[+] We can connect to the local MYSQL service as 'root' and without a password!\e[00m\n$mysqlconnectnopass"
echo -e "\n"
fi
#postgres details - if installed
postgver=`psql -V 2>/dev/null`
if [ "$postgver" ]; then
echo -e "\e[00;31m[-] Postgres version:\e[00m\n$postgver"
echo -e "\n"
fi
#checks to see if any postgres password exists and connects to DB 'template0' - following commands are a variant on this
postcon1=`psql -U postgres template0 -c 'select version()' 2>/dev/null | grep version`
if [ "$postcon1" ]; then
echo -e "\e[00;33m[+] We can connect to Postgres DB 'template0' as user 'postgres' with no password!:\e[00m\n$postcon1"
echo -e "\n"
fi
postcon11=`psql -U postgres template1 -c 'select version()' 2>/dev/null | grep version`
if [ "$postcon11" ]; then
echo -e "\e[00;33m[+] We can connect to Postgres DB 'template1' as user 'postgres' with no password!:\e[00m\n$postcon11"
echo -e "\n"
fi
postcon2=`psql -U pgsql template0 -c 'select version()' 2>/dev/null | grep version`
if [ "$postcon2" ]; then
echo -e "\e[00;33m[+] We can connect to Postgres DB 'template0' as user 'psql' with no password!:\e[00m\n$postcon2"
echo -e "\n"
fi
postcon22=`psql -U pgsql template1 -c 'select version()' 2>/dev/null | grep version`
if [ "$postcon22" ]; then
echo -e "\e[00;33m[+] We can connect to Postgres DB 'template1' as user 'psql' with no password!:\e[00m\n$postcon22"
echo -e "\n"
fi
#apache details - if installed
apachever=`apache2 -v 2>/dev/null; httpd -v 2>/dev/null`
if [ "$apachever" ]; then
echo -e "\e[00;31m[-] Apache version:\e[00m\n$apachever"
echo -e "\n"
fi
#what account is apache running under
apacheusr=`grep -i 'user\|group' /etc/apache2/envvars 2>/dev/null |awk '{sub(/.*\export /,"")}1' 2>/dev/null`
if [ "$apacheusr" ]; then
echo -e "\e[00;31m[-] Apache user configuration:\e[00m\n$apacheusr"
echo -e "\n"
fi
if [ "$export" ] && [ "$apacheusr" ]; then
mkdir --parents $format/etc-export/apache2/ 2>/dev/null
cp /etc/apache2/envvars $format/etc-export/apache2/envvars 2>/dev/null
fi
#installed apache modules
apachemodules=`apache2ctl -M 2>/dev/null; httpd -M 2>/dev/null`
if [ "$apachemodules" ]; then
echo -e "\e[00;31m[-] Installed Apache modules:\e[00m\n$apachemodules"
echo -e "\n"
fi
#htpasswd check
htpasswd=`find / -name .htpasswd -print -exec cat {} \; 2>/dev/null`
if [ "$htpasswd" ]; then
echo -e "\e[00;33m[-] htpasswd found - could contain passwords:\e[00m\n$htpasswd"
echo -e "\n"
fi
#anything in the default http home dirs (a thorough only check as output can be large)
if [ "$thorough" = "1" ]; then
apachehomedirs=`ls -alhR /var/www/ 2>/dev/null; ls -alhR /srv/www/htdocs/ 2>/dev/null; ls -alhR /usr/local/www/apache2/data/ 2>/dev/null; ls -alhR /opt/lampp/htdocs/ 2>/dev/null`
if [ "$apachehomedirs" ]; then
echo -e "\e[00;31m[-] www home dir contents:\e[00m\n$apachehomedirs"
echo -e "\n"
fi
fi
}
interesting_files()
{
echo -e "\e[00;33m### INTERESTING FILES ####################################\e[00m"
#checks to see if various files are installed
echo -e "\e[00;31m[-] Useful file locations:\e[00m" ; which nc 2>/dev/null ; which netcat 2>/dev/null ; which wget 2>/dev/null ; which nmap 2>/dev/null ; which gcc 2>/dev/null; which curl 2>/dev/null
echo -e "\n"
#limited search for installed compilers
compiler=`dpkg --list 2>/dev/null| grep compiler |grep -v decompiler 2>/dev/null && yum list installed 'gcc*' 2>/dev/null| grep gcc 2>/dev/null`
if [ "$compiler" ]; then
echo -e "\e[00;31m[-] Installed compilers:\e[00m\n$compiler"
echo -e "\n"
fi
#manual check - lists out sensitive files, can we read/modify etc.
echo -e "\e[00;31m[-] Can we read/write sensitive files:\e[00m" ; ls -la /etc/passwd 2>/dev/null ; ls -la /etc/group 2>/dev/null ; ls -la /etc/profile 2>/dev/null; ls -la /etc/shadow 2>/dev/null ; ls -la /etc/master.passwd 2>/dev/null
echo -e "\n"
#search for suid files
findsuid=`find / -perm -4000 -type f -exec ls -la {} 2>/dev/null \;`
if [ "$findsuid" ]; then
echo -e "\e[00;31m[-] SUID files:\e[00m\n$findsuid"
echo -e "\n"
fi
if [ "$export" ] && [ "$findsuid" ]; then
mkdir $format/suid-files/ 2>/dev/null
for i in $findsuid; do cp $i $format/suid-files/; done 2>/dev/null
fi
#list of 'interesting' suid files - feel free to make additions
intsuid=`find / -perm -4000 -type f -exec ls -la {} \; 2>/dev/null | grep -w $binarylist 2>/dev/null`
if [ "$intsuid" ]; then
echo -e "\e[00;33m[+] Possibly interesting SUID files:\e[00m\n$intsuid"
echo -e "\n"
fi
#lists word-writable suid files
wwsuid=`find / -perm -4002 -type f -exec ls -la {} 2>/dev/null \;`
if [ "$wwsuid" ]; then
echo -e "\e[00;33m[+] World-writable SUID files:\e[00m\n$wwsuid"
echo -e "\n"
fi
#lists world-writable suid files owned by root
wwsuidrt=`find / -uid 0 -perm -4002 -type f -exec ls -la {} 2>/dev/null \;`
if [ "$wwsuidrt" ]; then
echo -e "\e[00;33m[+] World-writable SUID files owned by root:\e[00m\n$wwsuidrt"
echo -e "\n"
fi
#search for sgid files
findsgid=`find / -perm -2000 -type f -exec ls -la {} 2>/dev/null \;`
if [ "$findsgid" ]; then
echo -e "\e[00;31m[-] SGID files:\e[00m\n$findsgid"
echo -e "\n"
fi
if [ "$export" ] && [ "$findsgid" ]; then
mkdir $format/sgid-files/ 2>/dev/null
for i in $findsgid; do cp $i $format/sgid-files/; done 2>/dev/null
fi
#list of 'interesting' sgid files
intsgid=`find / -perm -2000 -type f -exec ls -la {} \; 2>/dev/null | grep -w $binarylist 2>/dev/null`
if [ "$intsgid" ]; then
echo -e "\e[00;33m[+] Possibly interesting SGID files:\e[00m\n$intsgid"
echo -e "\n"
fi
#lists world-writable sgid files
wwsgid=`find / -perm -2002 -type f -exec ls -la {} 2>/dev/null \;`
if [ "$wwsgid" ]; then
echo -e "\e[00;33m[+] World-writable SGID files:\e[00m\n$wwsgid"
echo -e "\n"
fi
#lists world-writable sgid files owned by root
wwsgidrt=`find / -uid 0 -perm -2002 -type f -exec ls -la {} 2>/dev/null \;`
if [ "$wwsgidrt" ]; then
echo -e "\e[00;33m[+] World-writable SGID files owned by root:\e[00m\n$wwsgidrt"
echo -e "\n"
fi
#list all files with POSIX capabilities set along with there capabilities
fileswithcaps=`getcap -r / 2>/dev/null || /sbin/getcap -r / 2>/dev/null`
if [ "$fileswithcaps" ]; then
echo -e "\e[00;31m[+] Files with POSIX capabilities set:\e[00m\n$fileswithcaps"
echo -e "\n"
fi
if [ "$export" ] && [ "$fileswithcaps" ]; then
mkdir $format/files_with_capabilities/ 2>/dev/null
for i in $fileswithcaps; do cp $i $format/files_with_capabilities/; done 2>/dev/null
fi
#searches /etc/security/capability.conf for users associated capapilies
userswithcaps=`grep -v '^#\|none\|^$' /etc/security/capability.conf 2>/dev/null`
if [ "$userswithcaps" ]; then
echo -e "\e[00;33m[+] Users with specific POSIX capabilities:\e[00m\n$userswithcaps"
echo -e "\n"
fi
if [ "$userswithcaps" ] ; then
#matches the capabilities found associated with users with the current user
matchedcaps=`echo -e "$userswithcaps" | grep \`whoami\` | awk '{print $1}' 2>/dev/null`
if [ "$matchedcaps" ]; then
echo -e "\e[00;33m[+] Capabilities associated with the current user:\e[00m\n$matchedcaps"
echo -e "\n"
#matches the files with capapbilities with capabilities associated with the current user
matchedfiles=`echo -e "$matchedcaps" | while read -r cap ; do echo -e "$fileswithcaps" | grep "$cap" ; done 2>/dev/null`
if [ "$matchedfiles" ]; then
echo -e "\e[00;33m[+] Files with the same capabilities associated with the current user (You may want to try abusing those capabilties):\e[00m\n$matchedfiles"
echo -e "\n"
#lists the permissions of the files having the same capabilies associated with the current user
matchedfilesperms=`echo -e "$matchedfiles" | awk '{print $1}' | while read -r f; do ls -la $f ;done 2>/dev/null`
echo -e "\e[00;33m[+] Permissions of files with the same capabilities associated with the current user:\e[00m\n$matchedfilesperms"
echo -e "\n"
if [ "$matchedfilesperms" ]; then
#checks if any of the files with same capabilities associated with the current user is writable
writablematchedfiles=`echo -e "$matchedfiles" | awk '{print $1}' | while read -r f; do find $f -writable -exec ls -la {} + ;done 2>/dev/null`
if [ "$writablematchedfiles" ]; then
echo -e "\e[00;33m[+] User/Group writable files with the same capabilities associated with the current user:\e[00m\n$writablematchedfiles"
echo -e "\n"
fi
fi
fi
fi
fi
#look for private keys - thanks djhohnstein
if [ "$thorough" = "1" ]; then
privatekeyfiles=`grep -rl "PRIVATE KEY-----" /home 2>/dev/null`
if [ "$privatekeyfiles" ]; then
echo -e "\e[00;33m[+] Private SSH keys found!:\e[00m\n$privatekeyfiles"
echo -e "\n"
fi
fi
#look for AWS keys - thanks djhohnstein
if [ "$thorough" = "1" ]; then
awskeyfiles=`grep -rli "aws_secret_access_key" /home 2>/dev/null`
if [ "$awskeyfiles" ]; then
echo -e "\e[00;33m[+] AWS secret keys found!:\e[00m\n$awskeyfiles"
echo -e "\n"
fi
fi
#look for git credential files - thanks djhohnstein
if [ "$thorough" = "1" ]; then
gitcredfiles=`find / -name ".git-credentials" 2>/dev/null`
if [ "$gitcredfiles" ]; then
echo -e "\e[00;33m[+] Git credentials saved on the machine!:\e[00m\n$gitcredfiles"
echo -e "\n"
fi
fi
#list all world-writable files excluding /proc and /sys
if [ "$thorough" = "1" ]; then
wwfiles=`find / ! -path "*/proc/*" ! -path "/sys/*" -perm -2 -type f -exec ls -la {} 2>/dev/null \;`
if [ "$wwfiles" ]; then
echo -e "\e[00;31m[-] World-writable files (excluding /proc and /sys):\e[00m\n$wwfiles"
echo -e "\n"
fi
fi
if [ "$thorough" = "1" ]; then
if [ "$export" ] && [ "$wwfiles" ]; then
mkdir $format/ww-files/ 2>/dev/null
for i in $wwfiles; do cp --parents $i $format/ww-files/; done 2>/dev/null
fi
fi
#are any .plan files accessible in /home (could contain useful information)
usrplan=`find /home -iname *.plan -exec ls -la {} \; -exec cat {} 2>/dev/null \;`
if [ "$usrplan" ]; then
echo -e "\e[00;31m[-] Plan file permissions and contents:\e[00m\n$usrplan"
echo -e "\n"
fi
if [ "$export" ] && [ "$usrplan" ]; then
mkdir $format/plan_files/ 2>/dev/null
for i in $usrplan; do cp --parents $i $format/plan_files/; done 2>/dev/null
fi
bsdusrplan=`find /usr/home -iname *.plan -exec ls -la {} \; -exec cat {} 2>/dev/null \;`
if [ "$bsdusrplan" ]; then
echo -e "\e[00;31m[-] Plan file permissions and contents:\e[00m\n$bsdusrplan"
echo -e "\n"
fi
if [ "$export" ] && [ "$bsdusrplan" ]; then