LoginSignup
2
0

More than 5 years have passed since last update.

EC2 Windows インスタンスの Administrator パスワードを取得する

Last updated at Posted at 2017-01-17

AWS CLI の場合

$ aws ec2 get-password-data --instance-id  i-1234567890abcdef0 --priv-launch-key /path/to/mykey.pem

AWS SDK for Ruby の場合

SDK は復号化までしてくれないので CLI のソースを参考に自分でやる。

require "aws-sdk"
require "base64"
require "openssl"

ec2_resource = Aws::EC2::Resource.new
instance = ec2_resource.instance "i-1234567890abcdef0"
password_encrypted = instance.password_data.password_data
private_key = OpenSSL::PKey::RSA.new(File.read(File.expand_path("/path/to/mykey.pem")))

p private_key.private_decrypt(Base64.decode64(password_encrypted))

ec2ctl の場合

拙作のツールです。

$ ec2ctl --attributes instance_id,tag:Name,password --private-key-file "/path/to/mykey.pem"
{
  "time": "2017-01-17 12:18:07 +0900",
  "severity": "INFO",
  "ec2_instances_summary": [
    {
      "instance_id": "i-1234567890abcdef1",
      "tag:Name": "test_win1",
      "password": "5z(bo%%o5w$eiR2L!$=H6(jB=5VqUGrV"
    },
    {
      "instance_id": "i-1234567890abcdef2",
      "tag:Name": "test_win2",
      "password": "*HQTw2brpMGXO)dh9%rlXWTvGh@=b&GQ"
    }
  ]
}
2
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
2
0