Current File : //proc/self/root/lib/python3/dist-packages/sos/cleaner/__pycache__/__init__.cpython-312.pyc
�

-�_g���2�ddlZddlZddlZddlZddlZddlZddlZddlmZddl	m	Z	ddl
mZddlm
Z
ddlZddlmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlm Z m!Z!m"Z"m#Z#ddl$m%Z%m&Z&ddl'm(Z(ddl)m*Z*m+Z+m,Z,Gd�de�Z-y)�N)�ThreadPoolExecutor)�datetime)�getpwuid)�fill)�__version__)�SoSComponent)�SoSIPParser)�SoSMacParser)�SoSHostnameParser)�SoSKeywordParser)�SoSUsernameParser)�
SoSIPv6Parser)�SoSReportArchive�SoSReportDirectory�SoSCollectorArchive�SoSCollectorDirectory)�DataDirArchive�TarballArchive)�InsightsArchive)�get_human_readable�
import_module�ImporterHelperc
�2��eZdZdZdZdgggdgdddddgd	�Z		d,�fd
�	Zd-d�Zd-d�Zd-d
�Z	d-d�Z
d�Zed��Z
d�Zd�Zed��Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd.d�Zd�Zd�Zd �Zd!�Zd"�Zd#�Z d$�Z!d%�Z"d/d&�Z#d'�Z$d(�Z%d)�Z&d-d*�Z'd+�Z(�xZ)S)0�
SoSCleanera
    This function is designed to obfuscate potentially sensitive information
    from an sos report archive in a consistent and reproducible manner.

    It may either be invoked during the creation of a report by using the
    --clean option in the report command, or may be used on an already existing
    archive by way of 'sos clean'.

    The target of obfuscation are items such as IP addresses, MAC addresses,
    hostnames, usernames, and also keywords provided by users via the
    --keywords and/or --keyword-file options.

    For every collection made in a report the collection is parsed for such
    items, and when items are found SoS will generate an obfuscated replacement
    for it, and in all places that item is found replace the text with the
    obfuscated replacement mapped to it. These mappings are saved locally so
    that future iterations will maintain the same consistent obfuscation
    pairing.

    In the case of IP addresses, support is for IPv4 and IPv6 - effort is made
    to keep network topology intact so that later analysis is as accurate and
    easily understandable as possible. If an IP address is encountered that we
    cannot determine the netmask for, a random IP address is used instead.

    For IPv6, note that IPv4-mapped addresses, e.g. ::ffff:10.11.12.13, are
    NOT supported currently, and will remain unobfuscated.

    For hostnames, domains are obfuscated as whole units, leaving the TLD in
    place.

    For instance, 'example.com' may be obfuscated to 'obfuscateddomain0.com'
    and 'foo.example.com' may end up being 'obfuscateddomain1.com'.

    Users will be notified of a 'mapping' file that records all items and the
    obfuscated counterpart mapped to them for ease of reference later on. This
    file should be kept private.
    z6Obfuscate sensitive networking information in a report�auto�N� /etc/sos/cleaner/default_mappingF�)�archive_type�domains�disable_parsers�skip_cleaning_files�jobs�keywords�keyword_file�map_file�	no_update�keep_binary_files�target�	usernamesc	���|st�|�|||�d|_n�|d|_|d|_|d|_|d|_|d|_d|_t|jd�sd	|j_	d
|j_
tjd�|_
tjd�|_tj tj"j%|jd
�d��|j'�|j)�|_tj,d�||_|jj1�|_|jj4j7d
�|_|jj:}t=|j*|�t?|j*|�tA|j*|�tC|j*|�tE|j*|�tG|j*|�g|_$|jjJD]�}|jHD]�}|jLjO�jQdd��d}	|	jS�}
|jO�jS�|
k(s�c|jUd|
���|jjWd|�d��|jHjY|�����tZt\t^t`tbtdtfg|_4d|_5|jUd|j���y)NT�options�tmpdir�sys_tmp�policy�manifestFr#rr�sos�sos_ui�cleaner��exist_ok�?�parser�)�maxsplitrzDisabling parser: zDisabling the 'zP' parser. Be aware that this may leave sensitive plain-text data in the archive.z#Cleaner initialized. From cmdline: )6�super�__init__�from_cmdline�optsr-r.r/r0�hasattrr#r�logging�	getLogger�soslog�ui_log�os�makedirs�path�join�review_parser_values�
load_map_file�cleaner_mapping�umask�in_place�get_preferred_hash_name�	hash_name�
components�add_section�
cleaner_mdr"rr	rr
rr
�parsersr!�name�lower�split�strip�log_info�warning�removerrrrrrr�
archive_types�nested_archive)�selfr7�args�cmdlinerK�hook_commonsr"�_parser�_loaded�_temp�_loaded_name�	__class__s           ��6/usr/lib/python3/dist-packages/sos/cleaner/__init__.pyr;zSoSCleaner.__init__bs������G��V�T�7�3� $�D��
%�Y�/�D�I�&�x�0�D�K�'�	�2�D�L�&�x�0�D�K�(��4�D�M� %�D���4�9�9�f�-�!"��	�	��%+�D�I�I�"�!�+�+�E�2�D�K�!�+�+�H�5�D�K�
�K�K������T�[�[�)�<�t�L��!�!�#�#�1�1�3���
����� ��
����<�<�>����-�-�2�2�>�>�y�I���"�i�i�;�;���d�2�2�4G�H���,�,�.A�B��$�.�.�0C�D���-�-�/B�C��T�1�1�3F�G��d�2�2�4G�H�

����y�y�0�0�
	1�G��<�<�	
1�����*�*�,�2�2�8�a�2�H��K��$�{�{�}���=�=�?�(�(�*�l�:��M�M�$6�|�n�"E�F��K�K�'�'�)�'��3O�O���L�L�'�'��0�	
1�
	1�
��!�����	
���#����
�
�1�$�2C�2C�1D�E�	G�c� �d|rd|��nd�d|��S)Nz[cleaner�:rz] ��r[�msg�callers   rd�_fmt_log_msgzSoSCleaner._fmt_log_msg�s ���&�A�f�X�,�b�9��C�5�A�Arec�Z�|jj|j||��y�N)rA�debugrlris   rd�	log_debugzSoSCleaner.log_debug��!�������$�+�+�C��8�9rec�Z�|jj|j||��yrn)rA�inforlris   rdrVzSoSCleaner.log_info�s!��������*�*�3��7�8rec�Z�|jj|j||��yrn)rA�errorrlris   rd�	log_errorzSoSCleaner.log_error�rqrec�`�d}d}|j�D]}|t||d��zdz}�|S)N�PrF)�replace_whitespace�
)�
splitlinesr)r[rj�width�_fmt�lines     rd�_fmt_msgzSoSCleaner._fmt_msg�sA�������N�N�$�	M�D��$�t�U�u�E�E��L�D�	M��rec�\�|jd�|j|j�y)NzSoS Cleaner Detailed Help)�	set_title�add_text�__doc__)�cls�sections  rd�display_helpzSoSCleaner.display_help�s#�����5�6�������%rec��i}d}tjj|jj�r#td|jj�d���tjj
|jj�sD|jj|k7r)|jd|jj�d��|St|jjdd��5}	tj|�}ddd�|S#tj$r|jd	�Y�0t
$r5}|jd
|jj�d|���Yd}~�hd}~wwxYw#1swY|SxYw)
z�Verifies that the map file exists and has usable content.

        If the provided map file does not exist, or it is empty, we will print
        a warning and continue on with cleaning building a fresh map
        rzRequested map file z is a directoryzERROR: map file z6 does not exist, will not load any obfuscation matches�r�utf-8��encodingzOERROR: Unable to parse map file, json is malformed. Will not load any mappings.zERROR: Could not load '�': N)rCrE�isdirr=r&�	Exception�existsrv�open�json�load�JSONDecodeError)r[�_conf�default_map�mf�errs     rdrHzSoSCleaner.load_map_file�se����8��
�7�7�=�=����+�+�,��1�$�)�)�2D�2D�1E�F(�(�)�
)��w�w�~�~�d�i�i�0�0�1��y�y�!�!�[�0����&�t�y�y�'9�'9�&:�;<�<�=����d�i�i�(�(�#��@�
E�B�E� �I�I�b�M�E�
E����
�+�+�M��N�N�$L�M� �E��N�N�$'�'+�y�y�'9�'9�&:�#�c�U�$D�E�E��E��

E���s<�4E;�6D�$E8�9E;�;E8�+E3�.E;�3E8�8E;�;Fc��|jd�}|jjdt�d��|jj|�|jj
s
	t
d�yy#t$r/|jjd�|jd�Yyt$r}|jd|�Yd}~yd}~wwxYw)	z�When we are directly running `sos clean`, rather than hooking into
        SoSCleaner via report or collect, print a disclaimer banner
        a�This command will attempt to obfuscate information that is generally considered to be potentially sensitive. Such information includes IP addresses, MAC addresses, domain names, and any user-provided keywords.

Note that this utility provides a best-effort approach to data obfuscation, but it does not guarantee that such obfuscation provides complete coverage of all such data in the archive, or that any obfuscation is provided to data that does not fit the description above.

Users should review any resulting data and/or archives generated or processed by this utility for remaining sensitive content before being passed to a third party.
z
sos clean (version z)
z-
Press ENTER to continue, or CTRL-C to quit.
z
Exiting on user cancel�r8N)
rrBrsrr=�batch�input�KeyboardInterrupt�_exitr�)r[rj�es   rd�print_disclaimerzSoSCleaner.print_disclaimer�s����m�m�
�
��	
�����0��
�S�A�B���������y�y���
!��G�H���%�
 ���� � �!;�<��
�
�3���
!��
�
�1�a� � ��
!�s�'A4�45C�+C�3C
�
Cc�H�d|_|jdd�}|jddd��|jdd	gd
�d��|jd
dgd��|jddgdd��|jdddgdd��|jdddtd��|jddgdd ��|jd!dd"d#�$�|jd%d&d'd(�)�|jd*d+d,d-d.�/�|jd0d,d-d1d2�3�|jd4d5gdd6�/�y)7Nzsos clean|mask TARGET [options]zCleaner/Masking Optionsz7These options control how data obfuscation is performedr)�TARGETz%The directory or archive to obfuscate)�metavar�helpz--archive-typer)r�report�collect�insightszdata-dir�tarballz8Specify what kind of archive the target was generated as)�default�choicesr�z	--domains�extendz!List of domain names to obfuscate)�actionr�r�z--disable-parsersr!zCDisable specific parsers, so that those elements are not obfuscated)r�r��destr�z--skip-cleaning-filesz--skip-masking-filesr"zBList of files to skip/ignore during cleaning. Globs are supported.z-jz--jobsrz&Number of concurrent archives to clean)r��typer�z
--keywordsr$zList of keywords to obfuscatez--keyword-filer%z&Provide a file a keywords to obfuscate)r�r�r�z
--map-filer&rz;Provide a previously generated mapping file for obfuscation)r�r�r�z--no-updater'F�
store_truez<Do not update the --map-file with new mappings from this run)r�r�r�r�z--keep-binary-filesr(zGKeep unprocessable binary files in the archive instead of removing them)r�r�r�r�z--usernamesr*zList of usernames to obfuscate)�usage�add_argument_group�add_argument�int)r�r7�	clean_grps   rd�add_parser_optionszSoSCleaner.add_parser_options�s���8����-�-�%�E�
�	�	���x��$K�	�	M����/��(K�&8�	�	:�
	���{�8�R�$G�	�	I����2�8�')�0A�&C�	�	E�	���6�8N�&.��$9�&F�	�	H�
	���t�X�q�s�$L�	�	N����|�H�b�$.�$C�	�	E�	���/��$2�$L�	�	N�	���|�*�'I�&<�	�	>�	���}�;��&2�%=�	�	>�	���4�e�&2�$7�%G�	�	H�
	���}�;��&.�$D�	�	Frec�&�||j_y)z�For use by report and collect to set the TARGET option appropriately
        so that execute() can be called just as if we were running `sos clean`
        directly from the cmdline.
        N)r=r))r[rEs  rd�set_target_pathzSoSCleaner.set_target_path,s��
 ��	�	�rec�$�d}|jjdk7ro|jjjdd�}|jD]9}|j|k(s�||jj
|j�}�;n_|jD]P}|j|jj
�s�)||jj
|j�}n|sy|jj|�|jrK|jj|j��|jj|�||_|jr&|jj|j_yy)z�The target path is not a directory, so inspect it for being an
        archive or an archive of archives.

        In the event the target path is not an archive, abort.
        Nr�-�_)r=r�replacerY�	type_namer)r-�
check_is_type�report_paths�append�	is_nestedr��get_nested_archivesrXrZ�description�ui_name)r[�_arc�
check_type�archive�arcs     rd�inspect_target_archivez!SoSCleaner.inspect_target_archive3sH�����9�9�!�!�V�+����/�/�7�7��S�A�J��-�-�
B���$�$�
�2�"�4�9�9�#3�#3�T�[�[�A�D�
B��)�)�
���$�$�T�Y�Y�%5�%5�6��t�y�y�/�/����=�D��
������ � ��&��>�>����$�$�T�%=�%=�%?�@�
���$�$�T�*�"&�D�����*.�*=�*=�*I�*I�D���'�rec�(�|jjD].}t|jd��dks�!t	d|�d���|jj
D�cgc]}t
j|���c}|j_ycc}w)z�Check any values passed to the parsers via the commandline:
        - For the --domains option, ensure that they are valid for the parser
          in question.
        - Convert --skip-cleaning-files from globs to regular expressions.
        �.�zInvalid value 'z0' given: --domains values must be actual domainsN)r=r �lenrTr�r"�fnmatch�	translate)r[�_dom�ps   rdrGzSoSCleaner.review_parser_valuesPs����I�I�%�%�	�D��4�:�:�c�?�#�a�'��%�d�V�,%�%���	�*.���)F�)F�)H�!��):�):�1�)=�)H��	�	�%��)Hs� Bc�	�|jjjd�djd�d|_|jr|j�g|_tjj|jj�sC|jjd|jj���|jd�|j�|js,|jjd�|jd�g|_|jD],}|j dk(s�|j"j%��.|j'�|j)�|j+�|js9|j,ry	|jj/d
�|jd�|jj/dt1|j��d��|j3�}|j5|�}|j7|�|j9�|j,r'|jD�cgc]}|j:��}}||fSd	}t1|j�dkDr|j=�}n�|jd}|j:}|j?|j:�}	|	��|jA|jd�d�d
|jB���}
tEtjjG|jH|
�dd��5}|jK|	�d	d	d	�|jM�tjjG|jH|jA|jd�d��}tOjP||�tjR|�}|jj/d|���|jj/d|�d��|jj/dtU|jV����|jj/dtY|jZ�j\�d��|jj/d�|j_�y	cc}w#1swY��kxYw)a,SoSCleaner will begin by inspecting the TARGET option to determine
        if it is a directory, archive, or archive of archives.

        In the case of a directory, the default behavior will be to edit the
        data in place. For an archive will we unpack the archive, iterate
        over the contents, and then repack the archive. In the case of an
        archive of archives, such as one from SoSCollector, each archive will
        be unpacked, cleaned, and repacked and the final top-level archive will
        then be repacked as well.
        �/���z.tarrz*Invalid target: no such file or directory r8z'No valid archives or directories found
zHostname ParserNz#No reports obfuscated, aborting...
z
Successfully obfuscated z report(s)
r��wr�r�z2A mapping of obfuscated elements is available at
	z)
The obfuscated archive is available at
	rzz	Size	z	Owner	zcPlease send the obfuscated archive to your support representative and keep the mapping file private)0r=r)rT�arc_namer<r�r�rCrEr�rBrur�r��completed_reportsrQrR�mapping�set_initial_counts�preload_all_archives_into_maps�generate_parser_item_regexes�obfuscate_report_pathsrKrsr��compile_mapping_dict�write_map_for_archive�write_map_for_config�write_stats_to_manifest�final_archive_path�rebuild_nested_archive�get_new_checksum�obfuscate_stringrMr�rFr.�write�write_cleaner_log�shutil�move�statr�st_sizer�st_uid�pw_name�cleanup)
r[r7�_map�map_path�a�	arc_paths�
final_path�arc_pathr��checksum�chksum_name�cf�arcstats
             rd�executezSoSCleaner.execute_s����	�	�(�(�.�.�s�3�B�7�=�=�f�E�a�H��
�����!�!�#�����w�w�~�~�d�i�i�.�.�/��K�K���J�!%���!1�!1� 2�4�
5��J�J�q�M��#�#�%�� � ��K�K���H�I��J�J�q�M�"$����l�l�	4�F��{�{�/�/����1�1�3�	4�	
�+�+�-��)�)�+��#�#�%��%�%��}�}���K�K���C�D��J�J�q�M������5��� 6� 6�7�8��F�	G��(�(�*���-�-�d�3���!�!�$�'��$�$�&��=�=�7;�7M�7M�N�!��-�-�N�I�N��Y�&�&��
��t�%�%�&��*��2�2�4�H��(�(��+�C��-�-�H��,�,�S�-C�-C�D�H��#�"�3�3��~�~�c�*�2�.�/�q����0@�A����"�'�'�,�,�t�|�|�[�A�3�#*�,�'�/1��H�H�X�&�'�
�"�"�$��W�W�\�\��L�L��!�!�(�.�.��"5�b�"9�:�
�
�	���H�j�)��'�'�*�%��
	
�����B�8�*�M�	
�	
�����:�:�,�b�I�	
�	
�����8�$6�w���$G�#H�I�J������9�X�g�n�n�%=�%E�%E�$F�b�I�J������L�	M�	
������UO�'�'�s�&S�
S�Sc�F�|jdz}|j|��|jD]m}|jj	d�d}|j|j�}|��?d|�d|j��}|jj||���otj|jj�D]�\}}}|D]�}	tjj||	�}
|
j	|jj�d}|jd�}|jj!|
|��tj"|
�����|j%d�	�|jj'|j(j*�S)
z�Handles repacking the nested tarball, now containing only obfuscated
        copies of the reports, log files, manifest, etc...
        z-obfuscated)rRr�r�z
checksums/r��r�T)r�)r��
setup_archiver�r�rTr�rMr��
add_stringrC�walkrZ�extracted_pathrErF�lstrip�add_filerXr��finalizer=�compression_type)r[r�r��arc_destr��dname�dirnr��files�filename�fnames           rdr�z!SoSCleaner.rebuild_nested_archive�sn��
�=�=�=�0�������)��-�-�	>�G��1�1�7�7��<�R�@�H��,�,�W�-G�-G�H�H��#�$�X�J�a����/?�@�����'�'��u�'�=�	>�!�g�g�d�&9�&9�&H�&H�I�	!�N�D�!�U�!�
!�������T�8�4�����D�$7�$7�$F�$F�G��K�����S�)�����%�%�e�%�%�8��	�	�%� �

!�	!�	
���t��,��|�|�$�$�T�Y�Y�%?�%?�@�@rec��i}|jD]=}i||j<||jj|j���?|S)aBuild a dict that contains each parser's map as a key, with the
        contents as that key's value. This will then be written to disk in the
        same directory as the obfuscated report so that sysadmins have a way
        to 'decode' the obfuscation locally
        )rQ�map_file_key�update�get_map_contents)r[r�r7s   rdr�zSoSCleaner.compile_mapping_dict�sW�����l�l�	H�F�(*�D��$�$�%���$�$�%�,�,�V�-D�-D�-F�G�	H��rec��t|dd��5}|jtj|d���ddd�|S#1swY|SxYw)zjWrite the mapping to a file on disk that is in the same location as
        the final archive(s).
        r�r�r�r)�indentN)r�r�r��dumps)r[r�rEr�s    rd�write_map_to_filezSoSCleaner.write_map_to_file�sC���$��g�
.�	1�"��H�H�T�Z�Z��Q�/�0�	1���	1���s�'A�A
c��	tjj|j|j	|j
�d���}|j
||�S#t$r}|jd|���Yd}~yd}~wwxYw)Nz-private_mapz"Could not write private map file: )	rCrErFr.r�r�rr�rv)r[r�r�r�s    rdr�z SoSCleaner.write_map_for_archive�su��	��w�w�|�|�����%�%�����|�&D�E��H��)�)�$��9�9���	��N�N�?��u�E�F���	�s�AA�	B�#A<�<Bc���|jjr�|jjs�tjj|jj�}	tj|d��|j||jj�|jd|jj���yyy#t$r}|jd|���Yd}~yd}~wwxYw)z}Write the mapping to the config file so that subsequent runs are
        able to provide the same consistent mapping
        Tr4zWrote mapping to z&Could not update mapping config file: N)r=r&r'rCrE�dirnamerDrrpr�rv)r[r��cleaner_dirr�s    rdr�zSoSCleaner.write_map_for_config�s����9�9���d�i�i�&9�&9��'�'�/�/�$�)�)�*<�*<�=�K�
O����K�$�7��&�&�t�T�Y�Y�-?�-?�@����!2�4�9�9�3E�3E�2F�G�H�':����
O����!G��u�M�N�N��
O�s�!A%C	�		C0�C+�+C0c��tjj|j|j�d��}t|dd��5}|jjd�|jj�D]}|j|��	ddd�|r/|j|�|jj|d��yy#1swY�;xYw)	z�When invoked via the command line, the logging from SoSCleaner will
        not be added to the archive(s) it processes, so we need to write it
        separately to disk
        z-obfuscation.logr�r�r�rNzsos_logs/cleaner.logr�)
rCrErFr.r�r��sos_log_file�seek�	readlinesr��obfuscate_filer�r�)r[r��log_name�logfiler~s     rdr�zSoSCleaner.write_cleaner_logs���
�7�7�<�<��L�L�T�]�]�O�+;�<�
���(�C�'�
2�	$�g����"�"�1�%��)�)�3�3�5�
$���
�
�d�#�
$�	$�
�����)��L�L�!�!�(�1G�!�H��	$�	$�s
�AC
�
Cc�R�	d}t|d�5}tj|j�}	|j	|�}|sn|j|��&|j
�dzcddd�S#1swYyxYw#t$r}|jd|���Yd}~yd}~wwxYw)zvCalculate a new checksum for the obfuscated archive, as the previous
        checksum will no longer be valid
        i�rbrzNz!Could not generate new checksum: )	r��hashlib�newrM�readr	�	hexdigestr�rp)r[�archive_path�	hash_size�
archive_fp�digest�hashdatar�s       rdr�zSoSCleaner.get_new_checksums���	F��I��l�D�)�
1�Z� ���T�^�^�4���)���y�9�H�#���M�M�(�+�	�
�'�'�)�D�0�
1�
1�
1����	F��N�N�>�s�e�D�E�E���	F�s5�A?�AA3�)	A?�3A<�8A?�<A?�?	B&�B!�!B&c��	dt|j��d|jj�d�}|jj|�|jjr|jjd�t|jj�}|j|j|jd��|jd��|jr,|j�|j|j�yy#t$r3|jjd	�tj d
�YywxYw)z�Perform the obfuscation for each archive or sos directory discovered
        during setup.

        Each archive is handled in a separate thread, up to self.opts.jobs will
        be obfuscated concurrently.
        zFound z. total reports to obfuscate, processing up to z concurrently
zpWARNING: binary files that potentially contain sensitive information will NOT be removed from the final archive
r8)�	chunksizeT)�waitzExiting on user cancelr�N)r�r�r=r#rBrsr(rWr�map�obfuscate_report�shutdownrZ�_replace_obfuscated_archivesr�rCr�)r[rj�pools   rdr�z!SoSCleaner.obfuscate_report_paths)s��	���T�.�.�/�0�1$�$(�I�I�N�N�#3�?�D�
�
�K�K���S�!��y�y�*�*����#�#�O��&�d�i�i�n�n�5�D��H�H�T�*�*�D�,=�,=��H�K��M�M�t�M�$��"�"��1�1�3��%�%�d�&9�&9�:�#��!�	��K�K���5�6��H�H�S�M�	�s�DD�9E�Ec�Z�|jD]�}tj|j�|jj
}|jjd�d}tjj||�}tj|j|�||_��y)z�When we have a nested archive, we need to rebuild the original
        archive, which entails replacing the existing archives with their
        obfuscated counterparts
        r�r�N)r�rCrXr rZr�r�rTrErFr�r�)r[r�r�r��	dest_names     rdr+z'SoSCleaner._replace_obfuscated_archivesFs���
�-�-�	3�G��I�I�g�*�*�+��&�&�5�5�D��0�0�6�6�s�;�B�?�G������T�7�3�I��K�K��2�2�D�9�)2�G�&�
	3rec�F�|jD]}|j��y)z�For the parsers that use prebuilt lists of items, generate those
        regexes now since all the parsers should be preloaded by the archive(s)
        as well as being handed cmdline options and mapping file configuration.
        N)rQ�generate_item_regexes)r[r7s  rdr�z'SoSCleaner.generate_parser_item_regexesSs#��
�l�l�	+�F��(�(�*�	+rec���|jD�]8}|jj�j�dj	�}|j||�D]a}|j
|�}|s�|jd|�d|�d|j���|j�D]}	|j|���c|j||�}	|	rC|jd|�d	|j���|	D]}
|jj|
��|j|D]}|jj!|����;y#t$r$}|jd|�d|�d|���Yd}~��d}~wwxYw)
a*
        For each archive we've determined we need to operate on, pass it to
        each prepper so that we can extract necessary files and/or items for
        direct regex replacement. Preppers define these methods per parser,
        so it is possible that a single prepper will read the same file for
        different parsers/mappings. This is preferable to the alternative of
        building up monolithic lists of file paths, as we'd still need to
        manipulate these on a per-archive basis.

        :param archive: The archive we are currently using to prepare our
                        mappings with
        :type archive:  ``SoSObfuscationArchive`` subclass

        :param prepper: The individual prepper we're using to source items
        :type prepper:  ``SoSPrepper`` subclass
        rz	Prepping z parser with file z from zFailed to prep z
 map from �: Nz mapping with items from )rQrRrSrTrU�get_parser_file_list�get_file_contentrpr�r{�
parse_liner��get_items_for_mapr��add�regex_items�add_regex_item)r[r��prepperr_�pname�_file�contentr~r��	map_items�item�ritems            rd�_prepare_archive_with_prepperz(SoSCleaner._prepare_archive_with_prepper[s���"�|�|�	6�G��L�L�&�&�(�.�.�0��3�9�9�;�E� �5�5�e�W�E�
��!�2�2�5�9��������5�'�1C�E�7�K'�'.���&7� 9�:�#�.�.�0��D���*�*�4�0��

� �1�1�%��A�I������5�'�1J�")�/�/�!2� 4�5�%�.�D��O�O�'�'��-�.�!�,�,�U�3�
6�����.�.�u�5�
6�-	6��%�����-�e�W�J�u�g�R��u�M�����s�+E
�
	E7	�E2	�2E7	c#�
K�ttjj�}g}|j	�D]}|jt
d|�����!t|d���D]}||j�����y�w)a
        Discover all locally available preppers so that we can prepare the
        mappings with obfuscation matches in a controlled manner

        :returns: All preppers that can be leveraged locally
        :rtype:   A generator of `SoSPrepper` items
        zsos.cleaner.preppers.c��|jSrn)�priority)�xs rd�<lambda>z)SoSCleaner.get_preppers.<locals>.<lambda>�s
��1�:�:�re)�key)r,N)	rr1r3�preppers�get_modulesr�r�sortedr=)r[�helper�preps�_prepr:s     rd�get_prepperszSoSCleaner.get_preppers�sz���� ���� 4� 4�5�����'�'�)�	I�E��L�L��)>�u�g�'F�G�H�	I��e�)=�>�	-�G��$�)�)�,�,�	-�s�BBc��|jd�|j�D]%}|jD]}|j||���'y)aBefore doing the actual obfuscation, if we have multiple archives
        to obfuscate then we need to preload each of them into the mappings
        to ensure that node1 is obfuscated in node2 as well as node2 being
        obfuscated in node1's archive.
        z.Pre-loading all archives into obfuscation mapsN)rVrNr�rA)r[r:r�s   rdr�z)SoSCleaner.preload_all_archives_into_maps�sR��	
�
�
�F�G��(�(�*�	E�G��,�,�
E���2�2�7�G�D�
E�	Erec�^�	|jj|j�}tj�}|jd|�|js|j�|jd�|j�D]�}|j|jdz�d}|j|�r�6|jjs#|j|�r|j|��o	|j!|||j�}|r|j#||���	|j)|�	|j-|�|j.sz|j1�}|rM|jd�	|j3|j5|j��|j7|�|j8j;|�tj�}	|jd|	�|jd|	|z
�|jdt=|j>��|jd|j@�d}
|jBrd}
|
|jBz}
|jd|
���y#t$$r"}|j'd|�d|���Yd}~��#d}~wwxYw#t$$r+}|j+d|��|j�	�Yd}~���d}~wwxYw#t$$r+}|j+d
|��|j�	�Yd}~���d}~wwxYw#t$$r?}|j'd|j�d
|���|jd|���Yd}~yd}~wwxYw#t$$r5}|jDjGd|j�d|���Yd}~yd}~wwxYw)z�Individually handle each archive or directory we've discovered by
        running through each file therein.

        Positional arguments:

            :param report str:      Filepath to the directory or archive
        �
start_timezBeginning obfuscation...r�r8zUnable to parse file r2Nz!Failed to obfuscate directories: �rkzFailed to obfuscate symlinks: zRe-compressing...zArchive z failed to compress: zFailed to re-compress archive: �end_time�run_time�files_obfuscated�total_substitutionsrz! [removed %s unprocessable files]zObfuscation completedzException while processing )$rPrO�archive_namer�now�	add_field�is_extracted�extract�
report_msg�
get_file_listrT�should_skip_filer=r(�should_remove_file�remove_filer�update_sub_countr�rp�obfuscate_directory_namesrV�obfuscate_symlinksr��get_compression�rename_top_dirr��compressr�r�r��
file_sub_list�total_sub_count�removed_file_countrBrs)r[r��arc_mdrQr�
short_name�countr��methodrS�rmsgs           rdr)zSoSCleaner.obfuscate_report�s���D	?��_�_�0�0��1E�1E�F�F�!����J����\�:�6��'�'����!����9�:� �.�.�0�
P��"�[�[��)=�)=��)C�D�Q�G�
��+�+�J�7���	�	�3�3��2�2�:�>��'�'�
�3��P� �/�/��z�07�0D�0D�F�E���0�0��U�C��
P� 
;��.�.�w�7�

;��'�'��0��$�$� �0�0�2����&�&�':�;�
��.�.� �1�1�'�2F�2F�G�� �(�(��0��&�&�-�-�g�6��|�|�~�H����Z��2����Z��J�)>�?����/��W�5J�5J�1K�L����2�G�4K�4K�L��D��)�)�:���g�8�8�8�����!6�t�f�=�>��U!�P��N�N�%:�:�,�b���#N�O�O��P��
�
;��
�
� A�#��G�%,�%9�%9��;�;��
;���
;��
�
� >�s�e�D�%,�%9�%9��;�;��
;��%������'�2F�2F�1G�H8�8;�u�(>�?��*�*�=�c�U�C�E�����&�	?��K�K���:� '� 4� 4�5�R��u�>�
?�
?��	?�s��C7M.�:1J�+M.�.J5�K,�/M.�;L#�<C
M.�	J2�J-�'M.�-J2�2M.�5	K)�> K$�M.�$K)�)M.�,	L �5 L�M.�L � M.�#	M+�,5M&�!M.�&M+�+M.�.	N,�7+N'�'N,c
�T��|syd}�s|jd�d�tjj|��s|jD�cgc]"}t�fd�|jD��s|��$}}|s|jd�xs|�d��y|jd�xs|��|�	�tjd
|j��5}t|dd
d��5}|D].}		|j|	|�\}	}
||
z
}|j|	��0	ddd�|jd�|r t!j"|j$|�ddd�|j'�jd�d�}�j)�jd�d|�}
|
�k7r�|j��d}tjj+||
�}tjj|�stj,||�|S|j'tj.|��}tj0|�tj2||�|Scc}w#t$r$}|jd��d|��|�	�Yd}~���d}~wwxYw#1swY���xYw#1swY��TxYw)a5Obfuscate and individual file, line by line.

        Lines processed, even if no substitutions occur, are then written to a
        temp file without our own tmpdir. Once the file has been completely
        iterated through, if there have been substitutions then the temp file
        overwrites the original file. If there are no substitutions, then the
        original file is left in place.

        Positional arguments:

            :param filename str:        Filename relative to the extracted
                                        archive root
        Nrr�r�c3�@�K�|]}|j�����y�wrn��match)�.0�_skiprks  �rd�	<genexpr>z,SoSCleaner.obfuscate_file.<locals>.<genexpr>s������05�E�K�K�
�+����zSkipping obfuscation of z" due to matching file skip patternzObfuscating rRr�)�mode�dirr�r�r�)r��errorszUnable to obfuscate rg)rTrCrE�islinkrQ�any�
skip_patternsrp�tempfile�NamedTemporaryFiler-r��obfuscate_liner�r�rr��copyfilerRr�r�rF�rename�readlinkrX�symlink)r[rrkr��subs�_p�_parsers�tfilerr~rlr��_ob_short_name�_ob_filenamer��_ob_path�
_target_obs  `              rdrzSoSCleaner.obfuscate_file�s���������!����,�R�0�J��w�w�~�~�h�'�"�\�\�����9;�9I�9I�����H������.�z�/E�X�.F�G1�2����N�N�\�*�*@��)A�B�"*�
�
,��,�,�#�4�;�;�G�
:���(�C�'�!*�,�	F�/4� %�F��F�*.�*=�*=�d�H�*M�K�D�%� �E�M�D�!�K�K��-�	F�	F��
�
�1�
���O�O�E�J�J��9�
:� �.�.�z�/?�/?��/D�R�/H�I��!�)�)�*�*:�*:�3�*?��*C�*8�:���:�%��~�~�j�1�!�4�H��w�w�|�|�H�l�;�H��7�7�>�>�(�+��	�	�(�H�-���"�2�2�2�;�;�x�3H�I�
��	�	�(�#��
�
�:�x�0����i��. )�F� �N�N�-A�*��Q�.1�U�,4�<D�+�F�F��F��	F�	F��
:�
:�sT�'I�J�J�"+I �
J�;J� 	J
	�)J	�J�J
	�
J�J	�J�J'c�6�	�|jd|j��|j�D�]4}	|j|j�djd��	|jD�cgc]"}t�	fd�|jD��s|��$}}|s|jd�	�d����|jd�	��|j��tj|�}tjj|j|j�	��}|j|�}||k7s||k7r+tj|�tj ||���7ycc}w#t"$r"}|jd	|�d
|���Yd}~��dd}~wwxYw)a�Iterate over symlinks in the archive and obfuscate their names.
        The content of the link target will have already been cleaned, and this
        second pass over just the names of the links is to ensure we avoid a
        possible race condition dependent on the order in which the link or the
        target get obfuscated.

        :param archive:     The archive being obfuscated
        :type archive:      ``SoSObfuscationArchive``
        zObfuscating symlink namesrRr8r�c3�@�K�|]}|j�����y�wrnrq)rsrt�_syms  �rdruz0SoSCleaner.obfuscate_symlinks.<locals>.<genexpr>Ns�����H�e����D�)�H�rvz Skipping obfuscation of symlink z due to skip pattern matchzObfuscating symlink zError obfuscating symlink 'r�N)rVrW�get_symlinksrTr�r�rQr{r|rprCr�rErFr�rXr�r�)
r[r�r�r�r��_target�_ob_sym_name�
_ob_targetr�r�s
         @rdrczSoSCleaner.obfuscate_symlinks;s����	
�
�
�1�'�:N�:N�
�O��+�+�-�!	O�G� 
O��}�}�W�%;�%;�<�Q�?�F�F�s�K��"&������H�r�7G�7G�H�H����� ��N�N�:�4�&�A(�)������!5�d�V�<�&-�&:�&:��<��+�+�g�.�� "�w�w�|�|�G�,B�,B�,0�,A�,A�$�,G� I��"�2�2�7�;�
�!�G�+��w�1F��I�I�g�&��J�J�z�<�8��?!	O����4�
O��
�
� ;�G�9�C��u�M�N�N��
O�s0�;E-�/'E(�E-�0B4E-�(E-�-	F�6F�Fc�`�|jd|j���t|j�d��D]�}t	j
|�D]�}tjj||�}|j|j�d}tjj|�s�a|j|�}||k7s�x|j|�}tjj|j|jd�|�}t	j||�����y)z�For all directories that exist within the archive, obfuscate the
        directory name if it contains sensitive strings found during execution
        z'Obfuscating directory names in archive T)�reverser�r�N)rVrWrJ�get_directory_listrC�listdirrErFrTr�r�r��rstripr�r�)r[r��dirpath�_name�_dirname�_arc_dir�_ob_dirname�_ob_arc_dirs        rdrbz$SoSCleaner.obfuscate_directory_namesis���	
�
�
�?� �-�-�.�0�	1��g�8�8�:�D�I�
	9�G����G�,�
9���7�7�<�<���7��#�>�>�'�*@�*@�A�"�E���7�7�=�=��*�"&�"7�"7��">�K�"�e�+�&.�o�o�e�&<��&(�g�g�l�l�#�2�2�'�.�.�s�3�'�'��
�	�	�(�K�8�
9�
	9rec��|jD]}	|j|�}�|S#t$r}|jd|���Yd}~�;d}~wwxYw)NzError obfuscating string data: )rQ�parse_string_for_keysr�rV)r[�string_datar7r�s    rdr�zSoSCleaner.obfuscate_string~s`���l�l�	G�F�
G�$�:�:�;�G��	G�
����
G��
�
� ?��u�E�F�F��
G�s�&�	A
�A�A
c��d}|j�s||fS|�|j}|D]}	|j|�\}}||z
}�||fS#t$r)}|j	d|��|j
�Yd}~�Pd}~wwxYw)a�Run a line through each of the obfuscation parsers, keeping a
        cumulative total of substitutions done on that particular line.

        Positional arguments:

            :param line str:        The raw line as read from the file being
                                    processed
            :param parsers:         A list of parser objects to obfuscate
                                    with. If None, use all.

        Returns the fully obfuscated line and the number of substitutions made
        rNzfailed to parse line: )rUrQr5r�rprR)r[r~rQrlr7�_countr�s       rdrzSoSCleaner.obfuscate_line�s������z�z�|���;���?��l�l�G��	L�F�
L�%�0�0��6���f�����	L��U�{����
L����!7��u�=�v�{�{�K�K��
L�s�A
�
	A<�A7�7A<c�H�|jjd�}|jD]x}|j|jj	dd�j��}|j
dt|jjj����zy)zLWrite some cleaner-level, non-report-specific stats to the manifest
        rQ� r��entriesN)rPrOrQrRr�rSrYr�r��dataset�keys)r[�	parse_secr7�_secs    rdr�z"SoSCleaner.write_stats_to_manifest�s}���O�O�/�/�	�:�	��l�l�	J�F��(�(����)<�)<�S�#�)F�)L�)L�)N�O�D��N�N�9�c�&�.�.�*@�*@�*E�*E�*G�&H�I�	Jre)NNNFNrn)F)NN)*�__name__�
__module__�__qualname__r��desc�arg_defaultsr;rlrprVrvr�classmethodr�rHr�r�r�r�rGr�r�r�rr�r�r�r�r�r+r�rArNr�r)rrcrbr�rr��
__classcell__)rcs@rdrr*s'���$�LD�D����!����6��"���
�L�GL�"�EG�NB�:�9�:���&��&��8!�:�/F��/F�b �J�:
H�^�@A�0��	�
O�I�"�$�:3�+�(6�T
-�	E�L?�\L�\,O�\9�*��8Jrer).rr�r?rCr�r}r��concurrent.futuresrr�pwdr�textwrapr�sos.cleaner.preppersr1r�
sos.componentr�sos.cleaner.parsers.ip_parserr	�sos.cleaner.parsers.mac_parserr
�#sos.cleaner.parsers.hostname_parserr�"sos.cleaner.parsers.keyword_parserr�#sos.cleaner.parsers.username_parserr
�sos.cleaner.parsers.ipv6_parserr�sos.cleaner.archives.sosrrrr�sos.cleaner.archives.genericrr�sos.cleaner.archives.insightsr�
sos.utilitiesrrrrrhrerd�<module>r�sl�����	�
���1������&�5�7�A�?�A�9�=�=�H�9�K�K�~
J��~
Jre
¿Qué es la limpieza dental de perros? - Clínica veterinaria


Es la eliminación del sarro y la placa adherida a la superficie de los dientes mediante un equipo de ultrasonidos que garantiza la integridad de las piezas dentales a la vez que elimina en profundidad cualquier resto de suciedad.

A continuación se procede al pulido de los dientes mediante una fresa especial que elimina la placa bacteriana y devuelve a los dientes el aspecto sano que deben tener.

Una vez terminado todo el proceso, se mantiene al perro en observación hasta que se despierta de la anestesia, bajo la atenta supervisión de un veterinario.

¿Cada cuánto tiempo tengo que hacerle una limpieza dental a mi perro?

A partir de cierta edad, los perros pueden necesitar una limpieza dental anual o bianual. Depende de cada caso. En líneas generales, puede decirse que los perros de razas pequeñas suelen acumular más sarro y suelen necesitar una atención mayor en cuanto a higiene dental.


Riesgos de una mala higiene


Los riesgos más evidentes de una mala higiene dental en los perros son los siguientes:

  • Cuando la acumulación de sarro no se trata, se puede producir una inflamación y retracción de las encías que puede descalzar el diente y provocar caídas.
  • Mal aliento (halitosis).
  • Sarro perros
  • Puede ir a más
  • Las bacterias de la placa pueden trasladarse a través del torrente circulatorio a órganos vitales como el corazón ocasionando problemas de endocarditis en las válvulas. Las bacterias pueden incluso acantonarse en huesos (La osteomielitis es la infección ósea, tanto cortical como medular) provocando mucho dolor y una artritis séptica).

¿Cómo se forma el sarro?

El sarro es la calcificación de la placa dental. Los restos de alimentos, junto con las bacterias presentes en la boca, van a formar la placa bacteriana o placa dental. Si la placa no se retira, al mezclarse con la saliva y los minerales presentes en ella, reaccionará formando una costra. La placa se calcifica y se forma el sarro.

El sarro, cuando se forma, es de color blanquecino pero a medida que pasa el tiempo se va poniendo amarillo y luego marrón.

Síntomas de una pobre higiene dental
La señal más obvia de una mala salud dental canina es el mal aliento.

Sin embargo, a veces no es tan fácil de detectar
Y hay perros que no se dejan abrir la boca por su dueño. Por ejemplo…

Recientemente nos trajeron a la clínica a un perro que parpadeaba de un ojo y decía su dueño que le picaba un lado de la cara. Tenía molestias y dificultad para comer, lo que había llevado a sus dueños a comprarle comida blanda (que suele ser un poco más cara y llevar más contenido en grasa) durante medio año. Después de una exploración oftalmológica, nos dimos cuenta de que el ojo tenía una úlcera en la córnea probablemente de rascarse . Además, el canto lateral del ojo estaba inflamado. Tenía lo que en humanos llamamos flemón pero como era un perro de pelo largo, no se le notaba a simple vista. Al abrirle la boca nos llamó la atención el ver una muela llena de sarro. Le realizamos una radiografía y encontramos una fístula que llegaba hasta la parte inferior del ojo.

Le tuvimos que extraer la muela. Tras esto, el ojo se curó completamente con unos colirios y una lentilla protectora de úlcera. Afortunadamente, la úlcera no profundizó y no perforó el ojo. Ahora el perro come perfectamente a pesar de haber perdido una muela.

¿Cómo mantener la higiene dental de tu perro?
Hay varias maneras de prevenir problemas derivados de la salud dental de tu perro.

Limpiezas de dientes en casa
Es recomendable limpiar los dientes de tu perro semanal o diariamente si se puede. Existe una gran variedad de productos que se pueden utilizar:

Pastas de dientes.
Cepillos de dientes o dedales para el dedo índice, que hacen más fácil la limpieza.
Colutorios para echar en agua de bebida o directamente sobre el diente en líquido o en spray.

En la Clínica Tus Veterinarios enseñamos a nuestros clientes a tomar el hábito de limpiar los dientes de sus perros desde que son cachorros. Esto responde a nuestro compromiso con la prevención de enfermedades caninas.

Hoy en día tenemos muchos clientes que limpian los dientes todos los días a su mascota, y como resultado, se ahorran el dinero de hacer limpiezas dentales profesionales y consiguen una mejor salud de su perro.


Limpiezas dentales profesionales de perros y gatos

Recomendamos hacer una limpieza dental especializada anualmente. La realizamos con un aparato de ultrasonidos que utiliza agua para quitar el sarro. Después, procedemos a pulir los dientes con un cepillo de alta velocidad y una pasta especial. Hacemos esto para proteger el esmalte.

La frecuencia de limpiezas dentales necesaria varía mucho entre razas. En general, las razas grandes tienen buena calidad de esmalte, por lo que no necesitan hacerlo tan a menudo e incluso pueden pasarse la vida sin requerir una limpieza. Sin embargo, razas pequeñas como el Yorkshire o el Maltés, deben hacérselas todos los años desde cachorros si se quiere conservar sus piezas dentales.

Otro factor fundamental es la calidad del pienso. Algunas marcas han diseñado croquetas que limpian la superficie del diente y de la muela al masticarse.

Ultrasonido para perros

¿Se necesita anestesia para las limpiezas dentales de perros y gatos?

La limpieza dental en perros no es una técnica que pueda practicarse sin anestesia general , aunque hay veces que los propietarios no quieren anestesiar y si tiene poco sarro y el perro es muy bueno se puede intentar…… , pero no se va a poder pulir ni acceder a todas la zona de la boca …. Además los limpiadores dentales van a irrigar agua y hay riesgo de aspiración a vías respiratorias si no se realiza una anestesia correcta con intubación traqueal . En resumen , sin anestesia no se va hacer una correcta limpieza dental.

Tampoco sirve la sedación ya que necesitamos que el animal esté totalmente quieto, y el veterinario tenga un acceso completo a todas sus piezas dentales y encías.

Alimentos para la limpieza dental

Hay que tener cierto cuidado a la hora de comprar determinados alimentos porque no todos son saludables. Algunos tienen demasiado contenido graso, que en exceso puede causar problemas cardiovasculares y obesidad.

Los mejores alimentos para los dientes son aquellos que están elaborados por empresas farmacéuticas y llevan componentes químicos con tratamientos específicos para el diente del perro. Esto implica no solo limpieza a través de la acción mecánica de morder sino también un tratamiento antibacteriano para prevenir el sarro.

Conclusión

Si eres como la mayoría de dueños, por falta de tiempo , es probable que no estés prestando la suficiente atención a la limpieza dental de tu perro. Por eso te animamos a que comiences a limpiar los dientes de tu perro y consideres atender a su higiene bucal con frecuencia.

Estas simples medidas pueden conllevar a que tu perro tenga una vida más larga y mucho más saludable.

Si te resulta imposible introducir un cepillo de dientes a tu perro en la boca, pásate con él por clínica Tus Veterinarios y te explicamos cómo hacerlo.

Necesitas hacer una limpieza dental profesional a tu mascota?
Llámanos al 622575274 o contacta con nosotros

Deja un comentario

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

¡Hola!