Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get the Windows virtual machine administrator password? #4284

Closed
yuqingkj opened this issue Sep 30, 2024 · 2 comments
Closed

How to get the Windows virtual machine administrator password? #4284

yuqingkj opened this issue Sep 30, 2024 · 2 comments
Assignees
Labels
closed-for-staleness documentation This is a problem with documentation. ec2 p2 This is a standard priority issue response-requested Waiting on additional information or feedback.

Comments

@yuqingkj
Copy link

Describe the issue

def list_instances(ec2_resource, ec2_client):
try:
instances = ec2_resource.instances.all()
if not instances:
print("没有找到任何 EC2 实例。")
return

    for instance in instances:
        instance_id = instance.id
        instance_type = instance.instance_type
        ami_id = instance.image_id
        private_ip = instance.private_ip_address or '无'
        public_ip = instance.public_ip_address or '无'
        state = instance.state['Name']

        print(f"Instance ID: {instance_id}")
        print(f"Instance Type: {instance_type}")
        print(f"AMI ID: {ami_id}")
        print(f"State: {state}")
        print(f"Private IP: {private_ip}")
        print(f"Public IP: {public_ip}")

        # 获取密码数据
        password_data = ec2_client.get_password_data(InstanceId=instance_id)
        if password_data['PasswordData']:
            # 解密密码
            with open('public_key/my_rsa_key.pem', 'r') as key_file:
                private_key = RSA.import_key(key_file.read())

            # 创建解密器
            cipher = PKCS1_OAEP.new(private_key)
            decoded_data = base64.b64decode(password_data['PasswordData'])

            # 解密
            decrypted_password = cipher.decrypt(decoded_data)
            print(f"解密后的密码: {decrypted_password.decode()}")
        else:
            print("不需要获取密码")

        print("=" * 40)  # 分隔符

except ClientError as e:
    print(f"无法获取实例列表: {e}")

Unable to obtain the decrypted password, is the decryption method wrong?

Links

NO

@yuqingkj yuqingkj added documentation This is a problem with documentation. needs-triage This issue or PR still needs to be triaged. labels Sep 30, 2024
@tim-finnigan tim-finnigan self-assigned this Oct 1, 2024
@tim-finnigan
Copy link
Contributor

Thanks for reaching out. Here is the get_password_data command documentation for reference: https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/ec2/client/get_password_data.html

Can you provide more details on this issue? Are you getting an error or what is the behavior? If you can share your debug logs (with any sensitive info redacted) by adding boto3.set_stream_logger('') to your script then we can look into this further.

@tim-finnigan tim-finnigan added response-requested Waiting on additional information or feedback. ec2 p2 This is a standard priority issue and removed needs-triage This issue or PR still needs to be triaged. labels Oct 1, 2024
Copy link

Greetings! It looks like this issue hasn’t been active in longer than five days. We encourage you to check if this is still an issue in the latest release. In the absence of more information, we will be closing this issue soon. If you find that this is still a problem, please feel free to provide a comment or upvote with a reaction on the initial post to prevent automatic closure. If the issue is already closed, please feel free to open a new one.

@github-actions github-actions bot added closing-soon This issue will automatically close in 4 days unless further comments are made. closed-for-staleness and removed closing-soon This issue will automatically close in 4 days unless further comments are made. labels Oct 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
closed-for-staleness documentation This is a problem with documentation. ec2 p2 This is a standard priority issue response-requested Waiting on additional information or feedback.
Projects
None yet
Development

No branches or pull requests

2 participants