forked from MrAnde7son/PowerShell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGet-WritableAutoruns.ps1
41 lines (36 loc) · 1.22 KB
/
Get-WritableAutoruns.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
function Get-WritableAutoruns
{
<#
.SYNOPSIS
Get all writable autoruns in order to detect potential privesc.
Author: Itamar Mizrahi (@MrAnde7son)
License: GNU v3
Required Dependencies: None
Optional Dependencies: None
.DESCRIPTION
.PARAMETER
.EXAMPLE
PS C:\> Get-WriteableAutoruns
#>
Add-Type -AssemblyName System.IO.Compression.FileSystem
# Downloads and extracts autorunsc
Invoke-WebRequest https://download.sysinternals.com/files/Autoruns.zip -OutFile autoruns.zip
[System.IO.Compression.ZipFile]::ExtractToDirectory("autoruns.zip",".\autoruns")
Set-Location .\autoruns
# Search for all writable autoruns' files.
$autoruns = ConvertFrom-Csv (autorunsc.exe -nobanner -a * -c)
foreach ($obj in $autoruns){
$location = $obj.'Entry Location' + "\" + $obj.Entry
$imagepath = $obj.'Image Path'
if ($imagepath -match "c:\\"){
Try {
[System.IO.File]::OpenWrite($imagepath).close()
$obj
}
Catch{}
}
}
Set-Location .\..\
Remove-Item autoruns.zip -Force
Remove-Item autoruns -Recurse -Force
}