基于 Windows 的其他持久化技术
主机账户
PowerShell 侧写
每当用户运行 PowerShell.exe 的时候,PowerShell 侧写文件会被加载。我们可以通过执行命令 $Profile | select* 来查询所有的 PowerShell 侧写,共有 4 个可能的位置:
C:\Windows\System32\WindowsPowerShell\v1.0\profile.ps1
C:\Windows\System32\WindowsPowerShell\v1.0\Microsoft.PowerShell_profile.ps1
C:\Users\<用户名>\Documents\WindowsPowerShell\profile.ps1
C:\Users\<用户名>\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
但是,显示出来的位置并不一定有现存的 profile.ps1 文件,我们可以自己新建一个。考虑到用户 serveradm 对 Web02 具有本地管理员权限,所以我们可以来到 AllUsersAllHosts 所对应的侧写目录:
为了验证概念,我们在侧写中运行 calc.exe,然后移动到该目录下。运行一个新的 PowerShell 进程,会发现计算器弹出来了。
终端侧写
如果当前主机安装了 Windows Terminal,在版本较新的个人主机上会相对常见,我们可以修改终端的侧写文件从而实现持久化,原理类似 PowerShell 侧写。Windows Terminal 是 Windows 10 以及更新版本中替代 Command Prompt 的,并集成了多种 Shell,包括 CMD,PowerShell,Azure Shell 等。
我们定位到 C:\Users\<用户名>\AppData\Local\Packages\Microsoft.WindowsTerminal_<Package ID>\LocalState 中,编辑 settings.json。
我们注意一下 defaultProfile,即默认侧写的 GUID。下面,包含了各种 Shell 的配置,其中 PowerShell 作为目前默认的 Shell。我们可以插入恶意的程序作为后门,这样每次用户打开 Terminal,就会触发指向的应用程序。这里,我们还指定了以提升特权运行。
{
"guid": "{与<defaultProfile> GUID 值相同}",
"name": "Proof Of Concept",
"commandline": "%SystemRoot%\\System32\\calc.exe",
"elevate": true
},