Windows

Invoke-AESEncryption.ps1

Invoke-AESEncryption.ps1 Powershellスクリプト

使い方

  1. ペネトレーションテストでターゲット環境に Invoke-AESEncryption.ps1 を転送し、PowerShell でモジュールとして読み込む。
Import-Module .\Invoke-AESEncryption.ps1
  1. テキストの暗号化
Invoke-AESEncryption -Mode Encrypt -Key "p@ssw0rd" -Text "Secret Text"
  1. テキストの復号化
Invoke-AESEncryption -Mode Decrypt -Key "p@ssw0rd" -Text "LtxcRelxrDLrDB9rBD6JrfX/czKjZ2CUJkrg++kAMfs="
  1. ファイルの暗号化
Invoke-AESEncryption -Mode Encrypt -Key "p@ssw0rd" -Path .\scan-results.txt

暗号化後のファイルリスト

│── Invoke-AESEncryption.ps1
│── scan-results.txt
│── scan-results.txt.aes  <-- 暗号化されたファイル
  1. ファイルの復号化
Invoke-AESEncryption -Mode Decrypt -Key "p@ssw0rd" -Path .\scan-results.txt.aes

重要ポイント

Linux

OpenSSL

使い方

ファイルの暗号化

AES-256でファイルを暗号化

openssl enc -aes-256-cbc -pbkdf2 -iter 100000 -salt -in plaintext.txt -out encrypted.txt.aes
オプション 説明
enc 暗号化を実行
-aes-256-cbc AES-256(CBCモード)を使用
-pbkdf2 PBKDF2アルゴリズムを使用(より安全なキー生成)
-iter 100000 キー導出の反復回数を10万回に設定(ブルートフォース攻撃対策)
-salt 暗号化時にランダムなソルトを追加(セキュリティ強化)
-in plaintext.txt 暗号化するファイル
-out encrypted.txt.aes 出力する暗号化ファイル

実行後、パスワードを入力すると暗号化が完了!


ファイルの復号化

openssl enc -aes-256-cbc -pbkdf2 -iter 100000 -d -in encrypted.txt.aes -out decrypted.txt
オプション 説明
-d 復号化を実行
-in encrypted.txt.aes 復号するファイル
-out decrypted.txt 出力する復号化後のファイル

暗号化時と同じパスワードを入力すれば復号できる!

📌 なぜ -pbkdf2-iter 100000 を使うのか?

  1. PBKDF2(Password-Based Key Derivation Function 2) を使うことで、パスワードの強度を向上
  2. 反復回数(-iter 100000)を増やすと、ブルートフォース攻撃に強くなる
    • デフォルトの回数は少ないため、より安全な値に変更するのが推奨

シンプルで安全