%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/sos/cleaner/mappings/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/sos/cleaner/mappings/__pycache__/ip_map.cpython-312.pyc

�

i��d���6�ddlZddlZddlmZGd�de�Zy)�N)�SoSMapc�\�eZdZdZgd�ZiZdZgd�ZdZd�Z	d�Z
d�Zd	�Zd
�Z
d�Zd�Zd
�Zy)�SoSIPMapa�A mapping store for IP addresses

    Each IP address added to this map is chcked for subnet membership. If that
    subnet already exists in the map, then IP addresses are deterministically
    generated sequentially within that subnet. For example, if a given IP is
    matched to subnet 192.168.1.0/24 then 192.168.1 may be obfuscated to
    100.11.12.0/24. Each IP address in the original 192.168.1.0/24 subnet
    will then be assigned an address in 100.11.12.0/24 sequentially, such as
    100.11.12.1, 100.11.12.2, etc...


    Internally, the ipaddress library is used to manipulate the address objects
    however, when retrieved by SoSCleaner any values will be strings.
    )z127.*z::1z0\.(.*)?z1\.(.*)?z8.8.8.8z8.8.4.4z	169.254.*z255.*�d)�127�169�172�192Fc��|jj�D]6}t|�jd�d|jd�dk(s�6yy)aThere are multiple ways in which an ip address could be handed to us
        in a way where we're matching against a previously obfuscated address.

        Here, match the ip address to any of the obfuscated addresses we've
        already created
        �/rTF)�dataset�values�str�split)�self�ipaddr�_ips   �=/usr/lib/python3/dist-packages/sos/cleaner/mappings/ip_map.py�
ip_in_datasetzSoSIPMap.ip_in_dataset1sQ���<�<�&�&�(�	�C��6�{� � ��%�a�(�C�I�I�c�N�1�,=�=��	��c���d}|j|�r |jdj|��}||jj	�vr|j|S|j|�s|j
|�r|Sd|vrS|jj	�D]6}|j|�s�|j|jd�dcS|j|�S)zEnsure that when requesting an obfuscated address, we return a str
        object instead of an IPv(4|6)Address object
        )r�=�]�)�rr)	�
startswith�lstrip�joinr
�keys�ignore_itemrr�add)rr�
filt_start�keys    r�getzSoSIPMap.get=s���*�
����Z�(��]�]�2�7�7�:�#6�7�F��T�\�\�&�&�(�(��<�<��'�'����F�#�t�'9�'9�&�'A��M�
�f���|�|�(�(�*�
;���>�>�&�)��<�<��,�2�2�3�7��:�:�
;�
�x�x���rc���g}|jD]D}|j|jk(r	||_y|j|vs�4|j	|��F|r|jd�d��|d|_yy)a/Determine if a given address is in a subnet of an already obfuscated
        network and if it is, then set the address' network to the network
        object we're tracking. This allows us to match ip addresses with or
        without a CIDR notation and maintain proper network relationships.
        Nc��|jS)N)�	prefixlen)�ns r�<lambda>z;SoSIPMap.set_ip_cidr_from_existing_subnet.<locals>.<lambda>hs
��A�K�K�rT)r#�reverser)�	_networks�ip�broadcast_address�network�append�sort)r�addr�nets�nets    r� set_ip_cidr_from_existing_subnetz)SoSIPMap.set_ip_cidr_from_existing_subnetVsu�����>�>�	!�C��w�w�#�/�/�/�"�����w�w�#�~����C� �	!���I�I�/��I�>���7�D�L�rc�0�	tj|�}|j
}t
|j�dk(r|j|�n|j|�|j|�S#t$r|jj	|��wxYw)ziGiven an IP address, sanitize it to an obfuscated network or host
        address as appropriate
        z255.255.255.255)�	ipaddress�ip_interface�
ValueError�ignore_matchesr/r.r�netmaskr4�sanitize_network�sanitize_ipaddr)r�itemr1r.s    r�
sanitize_itemzSoSIPMap.sanitize_itemks���
	��)�)�$�/�D�
�,�,���w����#4�4�
�1�1�$�7�

�!�!�'�*��#�#�D�)�)��!�	����&�&�t�,��	�s�A/�/&Bc�D�||jvr|j|�yy)zObfuscate the network address provided, and if there are host bits
        in the address then obfuscate those as well
        N)r+�_new_obfuscated_network)rr.s  rr;zSoSIPMap.sanitize_network�s#��
�$�.�.�(��(�(��1�)rc�x�|j|jvr�|j|j}|j|jjk(rt	|j�S|j�D]/}|j
|�r�t	|��d|j��cS|j�S)zEObfuscate the IP address within the known obfuscated network
        r)	r.r+r,r-r�hostsrr'�_new_obfuscated_single_address)rr1�_obf_networkrs    rr<zSoSIPMap.sanitize_ipaddr�s����<�<�4�>�>�)��>�>�$�,�,�7�L�
�w�w�$�,�,�8�8�8��<�9�9�:�:�$�)�)�+�
H���)�)�#�.�'*�#�h��0F�0F�G�G�	
H��2�2�4�4rc�r�d�}|�}||jj�vr|j�S|S)Nc��g}tdd�D]'}|jtjdd���)dt	|�zS)Nr���cz%s.%s.%s.%s)�ranger/�random�randint�tuple)�_octets�is  r�_gen_addressz=SoSIPMap._new_obfuscated_single_address.<locals>._gen_address�sB���G��1�a�[�
7�����v�~�~�b�"�5�6�
7� �5��>�1�1r)r
rrC)rrP�_addrs   rrCz'SoSIPMap._new_obfuscated_single_address�s9��	2�����D�L�L�'�'�)�)��6�6�8�8��rc���d}t|tj�r�|j|jvr|xjdz
c_d|jz}|j
j
d�d}tj|�d|���}|xjdz
c_t|tj�r	|r1||j|<t|�|jt|�<yy)a Generate an obfuscated network address for the network address given
        which will allow us to maintain network relationships without divulging
        actual network details

        Positional arguments:

            :param network:     An ipaddress.IPv{4|6)Network object
        N�z%s.0.0.0r)�
isinstancer6�IPv4Network�network_first_octet�skip_network_octets�with_netmaskr�IPv6Networkr+rr
)rr.rD�_obf_address�	_obf_masks     rr@z SoSIPMap._new_obfuscated_network�s������g�y�4�4�5��'�'�4�+C�+C�C��(�(�A�-�(�%��(@�(@�@�L��,�,�2�2�3�7��:�I�$�0�0�'��3��L�
�$�$��)�$��g�y�4�4�5���&2�D�N�N�7�#�),�\�):�D�L�L��W��&�rN)�__name__�
__module__�__qualname__�__doc__r9r+rVrW�compile_regexesrr$r4r>r;r<rCr@�rrrrsN��
�	�N��I���6���O�
� �2#�**�22�5�0
�;rr)r6rK�sos.cleaner.mappingsrrrarr�<module>rcs���
�'�z;�v�z;r

Zerion Mini Shell 1.0