Skip to content

Commit e141110

Browse files
author
Nick Moore
committed
Merge PR last-byte#32 (COM persistence: Library files + Junction Folder) into standard
2 parents a8d63b9 + e89fe9a commit e141110

File tree

1 file changed

+60
-2
lines changed

1 file changed

+60
-2
lines changed

PersistenceSniper/PersistenceSniper.psm1

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,8 @@ function Find-AllPersistence {
158158
'BootExecute',
159159
'NetshHelperDLL',
160160
'SetupExecute',
161-
'PlatformExecute'
161+
'PlatformExecute',
162+
'LibraryAbuseCOM'
162163
)]
163164
$PersistenceMethod = 'All',
164165

@@ -2293,6 +2294,57 @@ function Find-AllPersistence {
22932294
Write-Verbose -Message ''
22942295
}
22952296

2297+
function Get-LibraryAbuseCOM {
2298+
Write-Verbose -Message "$hostname - Checking if users' start menu folder contains .library-ms or junction folder artifacts..."
2299+
$userDirectories = Get-ChildItem -Path "$env:SystemDrive:\Users\"
2300+
foreach ($directory in $userDirectories) {
2301+
$fullPath = $directory.FullName
2302+
$starMenuDirectory = Get-ChildItem -Path "$fullPath\AppData\Roaming\Microsoft\Windows\Start Menu\" -Recurse -ErrorAction SilentlyContinue
2303+
foreach ($entry in $starMenuDirectory) {
2304+
$CLSID = $null
2305+
$entryName = $entry.Name
2306+
$entryPath = $entry.FullName
2307+
2308+
$match = [regex]::Match($entryName, "\.\{[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}\}", [Text.RegularExpressions.RegexOptions]::IgnoreCase)
2309+
if ($entry.PSIsContainer -and $match.Success) {
2310+
Write-Verbose -Message "$hostname - [!] Found a folder: $entryPath!"
2311+
$matchPattern = $match.Value
2312+
$CLSID = $matchPattern.Substring(1, $matchPattern.length-1)
2313+
}
2314+
2315+
if (!$entry.PSIsContainer -and $entryName.ToLower().EndsWith('.library-ms')) {
2316+
$fileContent = Get-Content -Path $entryPath
2317+
$match = [regex]::Match($fileContent, "\<url\>.*(shell:::|knownfolder:::|\.)\{[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}\}\<\/url\>", [Text.RegularExpressions.RegexOptions]::IgnoreCase)
2318+
if ($match.Success) {
2319+
Write-Verbose -Message "$hostname - [!] Found a file: $entryPath!"
2320+
$matchPattern = $match.Value
2321+
$clsidMatch = [regex]::Match($matchPattern, "\{[a-f0-9]{8}(?:-[a-f0-9]{4}){3}-[a-f0-9]{12}\}", [Text.RegularExpressions.RegexOptions]::IgnoreCase)
2322+
$CLSID = $clsidMatch.Value
2323+
}
2324+
}
2325+
if ($null -ne $CLSID) {
2326+
$objUser = New-Object System.Security.Principal.NTAccount($hostname, $directory.Name)
2327+
$userID = $objUser.Translate([System.Security.Principal.SecurityIdentifier]).Value
2328+
if ($null -ne $userID -or $userID -ne "") {
2329+
$rootPath = "Registry::HKEY_USERS\$userID"
2330+
}
2331+
else {
2332+
$rootPath = "Registry::HKEY_LOCAL_MACHINE"
2333+
}
2334+
$dll = Get-CLSIDPayload -RootPath $rootPath -CLSID $CLSID
2335+
if ($dll -ne "") {
2336+
$value = $dll
2337+
}
2338+
else {
2339+
$value = $CLSID
2340+
}
2341+
$PersistenceObject = New-PersistenceObject -Hostname $hostname -Technique 'Library Abuse COM' -Classification 'MITRE ATT&CK T1546.015' -Path "$entryPath" -Value "$value" -AccessGained 'User' -Note "The library file or junction folder under .\AppData\Roaming\Microsoft\Windows\Start Menu\ in a user's folder is accessed by explorer.exe every time that user logs in and interacts with the Start Menu. This behavior could be abused to achieve persistence using the Component Object Model." -Reference 'https://attack.mitre.org/techniques/T1546/015/'
2342+
$null = $persistenceObjectArray.Add($PersistenceObject)
2343+
}
2344+
}
2345+
}
2346+
Write-Verbose -Message ''
2347+
}
22962348

22972349
function Out-EventLog {
22982350

@@ -2366,6 +2418,7 @@ function Find-AllPersistence {
23662418
'NetshHelperDLL' = $null
23672419
'SetupExecute' = $null
23682420
'PlatformExecute' = $null
2421+
'LibraryAbuseCOM' = $null
23692422
}
23702423

23712424
# Collect the keys in a separate list
@@ -2457,7 +2510,8 @@ function Find-AllPersistence {
24572510
Get-NetshHelperDLL
24582511
Get-SetupExecute
24592512
Get-PlatformExecute
2460-
2513+
Get-LibraryAbuseCOM
2514+
24612515
if ($IncludeHighFalsePositivesChecks.IsPresent) {
24622516
Write-Verbose -Message "$hostname - You have used the -IncludeHighFalsePositivesChecks switch, this may generate a lot of false positives since it includes checks with results which are difficult to filter programmatically..."
24632517
Get-AppPaths
@@ -2705,6 +2759,10 @@ function Find-AllPersistence {
27052759
Get-PlatformExecute
27062760
break
27072761
}
2762+
'LibraryAbuseCOM' {
2763+
Get-LibraryAbuseCOM
2764+
break
2765+
}
27082766
}
27092767
}
27102768

0 commit comments

Comments
 (0)