CasperSecurity

Current Path : /lib/python3/dist-packages/uaclient/clouds/__pycache__/
Upload File :
Current File : //lib/python3/dist-packages/uaclient/clouds/__pycache__/aws.cpython-310.pyc

o

��Jh��@s�ddlZddlZddlmZmZddlmZmZmZm	Z	m
Z
ddlmZdZ
dZe
efZdZdZd	Zd
ZdZdZd
ZdZedZe�e
�e��ZGdd�de�ZdS)�N)�Any�Dict)�
exceptions�http�secret_manager�system�util)�PublicCloudAutoAttachInstancez169.254.169.254z[fd00:ec2::254]zhttp://{}/latest/api/tokenz0http://{}/latest/dynamic/instance-identity/pkcs7z3http://{}/latest/dynamic/instance-identity/documentz/sys/hypervisor/uuidz /sys/class/dmi/id/product_serialz/sys/class/dmi/id/product_uuid�21600zX-aws-ec2-metadata-tokenz-ttl-secondsc@s�eZdZdZdZdefdd�Zeej	e
jgd�d�deee
ffdd	���Zej	e
jgd�d�defd
d��Zedefdd
��Zdd�Zej	e
jgd�d�dd��Zedefdd��Zedefdd��Zdefdd�Zdedefdd�ZdS)�AWSAutoAttachInstanceN�urlcCs2tj||dd�}|jdkr|jStj|j|jd��)N�)�headers�timeout����code�body)r�readurlrrr�CloudMetadataError)�selfrr�response�r�5/usr/lib/python3/dist-packages/uaclient/clouds/aws.py�_get_imds_url_responses
�z,AWSAutoAttachInstance._get_imds_url_response)g�?r
r
)�retry_sleeps�returncCs6|��}t�|j�}|j||d�}tj�|�d|iS)N�r�pkcs7)�_request_imds_v2_token_headers�IMDS_URL�format�_ip_addressrr�secrets�
add_secret)rrr�imds_url_responserrr�identity_doc*s
z"AWSAutoAttachInstance.identity_docc
Csf|��}t�|j�}z
t�|j||d��}W|Stjy2}zt�	d|�iWYd}~Sd}~ww)a
        Get the instance identity doc associated with the current instance.

        See
        https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/retrieve-iid.html
        for more context.

        @return: Dict containing the instance identity document.
        rz-Error decoding instance identity document: %sN)
r�
_IMDS_IID_URLr!r"�json�loadsr�JSONDecodeError�LOG�debug)rrr�ii_doc�errr�_get_ii_doc3s����z!AWSAutoAttachInstance._get_ii_doccCs0|��}|�dd�}|�dd�}t|�pt|�S)a
        Determines if the instance is likely Ubuntu Pro.

        Criteria: if any billing-product or marketplace-product-code is
        present, then is likely a Pro instance.

        @return: Boolean indicating if the instance is likely pro or not.
        �billingProductsN�marketplaceProductCodes)r/�get�bool)rr-�billing_products�marketplace_product_codesrrr�
is_likely_proIs
z#AWSAutoAttachInstance.is_likely_procCs|tD]+}z|j|d�}Wnty)}zt�d|t|dd��WYd}~qd}~ww||_|jdur<tjd�	t�d��|S)N)�
ip_addressz*Could not reach AWS IMDS at http://%s: %s
�reason�z, )�	addresses)
�IMDS_IP_ADDRESS�_get_imds_v2_token_headers�	Exceptionr+�warning�getattrr"r�AWSNoValidIMDS�join)r�addressrr.rrrrXs$
���
�z4AWSAutoAttachInstance._request_imds_v2_token_headers)r
��cCs�|jdkrdS|jrt|jiStjt�|�dttidd�}|jdkr2|j	|_t
j�|j�t|jiS|jdkr<d|_dSt
j|j|j	d��)N�IMDSv1�PUTr
)�methodrrri�r)�
_api_token�AWS_TOKEN_PUT_HEADERrr�IMDS_V2_TOKEN_URLr!�AWS_TOKEN_REQ_HEADER�AWS_TOKEN_TTL_SECONDSrrrr#r$rr)rr7rrrrr<ks(

�


�z0AWSAutoAttachInstance._get_imds_v2_token_headerscC�dS)N�awsr�rrrr�
cloud_type��z AWSAutoAttachInstance.cloud_typecCs�zt�t�}d|dd�krWdSWn	tyYnwt�t���}t�t���}d|dd�kr=|dd�kr@dSdSdS)z$This machine is a viable AWSInstance�ec2r�TF)r�	load_file�SYS_HYPERVISOR_PRODUCT_UUID�FileNotFoundError�DMI_PRODUCT_UUID�lower�DMI_PRODUCT_SERIAL)r�hypervisor_uuid�dmi_uuid�
dmi_serialrrr�	is_viable�s
��"�zAWSAutoAttachInstance.is_viablecCrM)�UnsupportedFrrOrrr�should_poll_for_pro_license�rQz1AWSAutoAttachInstance.should_poll_for_pro_license�wait_for_changecCst���)N)r�InPlaceUpgradeNotSupportedError)rr`rrr�is_pro_license_present�sz,AWSAutoAttachInstance.is_pro_license_present)�__name__�
__module__�__qualname__rHr"�strr�propertyr�retryrrrrr&r/r3r6rr<rPr]r_rbrrrrrs(
r)r(�logging�typingrr�uaclientrrrrr�uaclient.cloudsr	�IMDS_IPV4_ADDRESS�IMDS_IPV6_ADDRESSr;rJr r'rUrYrWrLrIrK�	getLogger�replace_top_level_logger_namercr+rrrrr�<module>s&
Hacker Blog, Shell İndir, Sql İnjection, XSS Attacks, LFI Attacks, Social Hacking, Exploit Bot, Proxy Tools, Web Shell, PHP Shell, Alfa Shell İndir, Hacking Training Set, DDoS Script, Denial Of Service, Botnet, RFI Attacks, Encryption
Telegram @BIBIL_0DAY