관리-도구
편집 파일: patcher.cpython-311.pyc
� ����N�S_��B�������������������������d�Z�ddlZddlZddlZddlZddlZddlZddlmZ�ddl m Z mZmZm Z mZ�ddlmZ�ddlmZ�ddlmZ�ddlmZ�dd lmZ�dd lmZmZmZmZmZmZ��ej ��������e!������������Z"dd�Z#�G�d��d e������������Z$�G�d��de������������Z%�G�d��de������������Z&dee'e(f���������de(fd�Z)�G�d��de*������������Z+�G�d��de e'e+f���������������������Z,�G�d��d������������Z-dS�)u �� This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>. Copyright © 2019 Cloud Linux Software Inc. This software is also available under ImunifyAV commercial license, see <https://www.imunify360.com/legal/eula> �����N)�suppress)�Dict�List�Optional�Tuple�Union)�MalwareSignatures)�MessageType��base64_encode_filename)�MalwareTune)�VulnerabilityHit)�DeletionType� ErrorType�RescanResultType�RevisiumCSVFile�RevisiumJsonFile�RevisiumTempFilec������������������Z�����t�����������j��������rt����������|�|������������S�t����������|�|������������S��N)r ����USE_JSON_REPORTr���r�����tempdir�modes��� �\/opt/imunify360/venv/lib/python3.11/site-packages/imav/malwarelib/vulnerabilities/patcher.py�patcher_result_instancer���0���s-�������"��/����.�.�.��7�D�)�)�)�����c�������������������������e�Zd�ZdS�)�VulnerabilityPatcherLogN��__name__� __module__�__qualname__��r���r���r���r���6�������������������Dr���r���c�������������������������e�Zd�ZdS�)�VulnerabilityPatcherProgressNr ���r$���r���r���r'���r'���:���r%���r���r'���c�������������������������e�Zd�Zd��ZdS�)�VulnerabilityPatchFileListc�����������������������|�j������������������������������d������������5�}|���������������������d��|D����������������������������d�d�d��������������d�S�#�1�swxY�w�Y���d�S�)N�wbc��������������3����:���K����|�]}t����������|������������d�z���V����dS�)���� Nr���)�.0�fs��� r���� <genexpr>z3VulnerabilityPatchFileList.write.<locals>.<genexpr>A���s0����������M�M�q�/��2�2�U�:�M�M�M�M�M�Mr���)�_path�open� writelines)�self�filelist�ws��� r����writez VulnerabilityPatchFileList.write?���s������� �Z�_�_�T� "� "�� N�a� �L�L�M�M�H�M�M�M�M�M�M� N�� N�� N�� N�� N�� N�� N�� N�� N�� N�� N�� N����� N�� N�� N�� N�� N�� Ns���� A�A�AN)r!���r"���r#���r7���r$���r���r���r)���r)���>���s(��������������N��N��N��N��Nr���r)����value�returnc������������������D����� �t����������|�������������S�#�t����������$�r�Y�dS�w�xY�w)zbConvert str|int to int, in case errors return -2 -1 used as default value when storing CH ���)�int� ValueError)r8���s��� r���� _parse_intr>���D���s5��������5�z�z�����������r�r����s������ �c��������������������\�������e�Zd�Zdeeeeef���������f���������f��fd�Zd��Zd��Z d��Z d��Z��xZS�)�PatchResultEntry�datac�����������������������t���������������������������������������������t����������|���������������������dd������������������������t����������|���������������������dd������������������������|d���������|d���������t����������|���������������������dd������������������������t����������|���������������������dd������������������������t����������|���������������������dd������������������������|���������������������d d ������������|���������������������dd �������������� ��� ���������d�S�) N�d����e�sr/����r�mb�ma�hb���ha) rC���rE���rF���r/���rG����mtime_before�mtime_after�hash_before� hash_after)�super�__init__r>����get)r4���rA���� __class__s��� �r���rR���zPatchResultEntry.__init__O���s��������� ���������#�r�*�*�+�+�����#�r�*�*�+�+��3�i��3�i�����#�r�*�*�+�+�#�D�H�H�T�2�$6�$6�7�7�"�4�8�8�D�"�#5�#5�6�6�����r�*�*��x�x��b�)�)�� �� �� �� �� �� r���c������������������ ����|�������������������������������������s|������������������������������������rdS�|�d���������t����������j��������k����r#t�������������������������������d|�d����������������������dS�|�d���������t����������j��������k����o|�d���������t����������j��������k����S�)NFrE���z2File has changed, assuming that it was patched: %sr/���TrC���) � is_failed�requires_myimunify_protectionr���� NOT_CLEANEDUP�logger�warning�NO_ERRORr���� PATCH_APPLIED�r4���s��� r���� is_patchedzPatchResultEntry.is_patchede���s��������N�N��� � $� B� B� D� D� ���5���9� �/�/�/��N�N�D�d�3�i� �� �� ���4�� ��I��+�+�� 8��S� �\�7�7� r���c������������������.�����|�d���������t�����������j��������k����S��NrG���)r����DETECTEDr]���s��� r���rV���zPatchResultEntry.is_failedv���s��������I�)�2�2� r���c������������������.�����|�d���������t�����������j��������k����S�r`���)r����REQUIRED_ADVANCED_SIGNATURESr]���s��� r���rW���z.PatchResultEntry.requires_myimunify_protection{���s�������C�y�,�I�I�Ir���c������������������X�����|��������������������������������������o|�d���������t����������j��������k����S�)NrE���)rV���r����FILE_NOT_EXISTSr]���s��� r���� not_existzPatchResultEntry.not_exist~���s&�������>�>�#�#�#�N��S� �Y�5N�(N�Nr���) r!���r"���r#���r����strr���r<���rR���r^���rV���rW���rf���� __classcell__�rT���s���@r���r@���r@���N���s���������������� �T�#�u�S�#�X��"6�7�� �� �� �� �� �� �, �� �� �" �� �� � J��J��J�O��O��O��O��O��O��Or���r@���c���������������������������e�Zd�ZdZd ��fd� Zedeeef���������defd���������������Z deeef���������f��fd�Z deeef���������f��fd�Z��xZS�) �PatchResultz5 Cleanup result container for result entries Nc������������������f������|r-t���������������������������������������������d��|D����������������������������d�S�d�S�)Nc������������������:�����i�|�]}|d����������t����������|��������������S�)r/���)r@���)r.���rE���s��� r���� <dictcomp>z(PatchResult.__init__.<locals>.<dictcomp>����s'������J�J�J�a�a��f�&6�q�&9�&9�J�J�Jr���)rQ���rR���)r4����reportrT���s��� �r���rR���zPatchResult.__init__����sE��������� L��G�G���J�J�6�J�J�J�K�K�K�K�K� L�� Lr����hitr9���c������������������$�����t����������|�d|�������������S�)N� orig_file)�getattr)rp���s��� r����__keyzPatchResult.__key����s�������s�K��-�-�-r���c������������������l������t���������������������������������������������|����������������������|������������������������S�r���)rQ����__contains__�_PatchResult__key�r4���rp���rT���s��� �r���rv���zPatchResult.__contains__����s%��������w�w�#�#�D�J�J�s�O�O�4�4�4r���c������������������l������t���������������������������������������������|����������������������|������������������������S�r���)rQ����__getitem__rw���rx���s��� �r���rz���zPatchResult.__getitem__����s%��������w�w�"�"�4�:�:�c�?�?�3�3�3r���r���) r!���r"���r#����__doc__rR����staticmethodr���rg���r���rw���rv���rz���rh���ri���s���@r���rk���rk�������s�������������������L��L��L��L��L��L���.�5��.�.�/��.�C��.��.��.���\�.�5��c�+;�&;� <��5��5��5��5��5��5�4�u�S�*:�%:�;��4��4��4��4��4��4��4��4��4��4r���rk���c��������������������������e�Zd�ZdZej��������Zdd�Zdd�d�Zede de e���������d ed e e���������de e���������f d���������������Zd efd�Zdeee e���������e e���������f���������fd�ZdS�)�VulnerabilityPatcherz/opt/ai-bolit/procu2.phpNc������������������L�����|r|nt����������j����������������������|�_��������||�_��������d�S�r���)�asyncio�get_event_loop�_loop�_sink)r4����loop�sinks��� r���rR���zVulnerabilityPatcher.__init__����s&������!�?�T�T�w�'=�'?�'?�� ��� � � r���T)�use_csvc���������� �������T����d|�j���������ddddd|z��dd|z��d d |z��d|z��g}|r|���������������������d|z��g�������������n|���������������������d |z��g�������������t����������j�����������������������������|�j��������������������r/|���������������������d�������������|���������������������|�j���������������������|S�)Nz/opt/ai-bolit/wrapperz --deobfuscatez --nobackupz--patch-vulnerabilitiesz--rescanz --list=%sz--input-fn-b64-encodedz --username=%sz--report-hashesz--log=%sz --progress=%sz--csv_result=%sz--result=%sz--avdb)� PROCU_PATH�extend�os�path�exists�PROCU_DB�append)r4����filename� progress_path�result_path�log_path�usernamer�����cmds��� r����_cmdzVulnerabilityPatcher._cmd����s�������� $��O���%���(�"�$��h�&����!��m�+� ����� 6��J�J�)�K�7�8�9�9�9�9��J�J� ��3�4�5�5�5� �7�>�>�$�-�(�(�� &��J�J�x� � � ��J�J�t�}�%�%�%�� r����excr����� returncode�stdout�stderrc����������� ������������t����������|�j��������j��������|||�|���������������������d�������������nd|�|���������������������d�������������nd�������������S�)N�replace)�errorsrK���)� exception�return_code�command�out�err)�dictrT���r!����decode)r����r����r����r����r����s��� r����_get_patcher_error_infoz,VulnerabilityPatcher._get_patcher_error_info����s_���������m�,�"��39�3E�� � �Y� �/�/�/�2�39�3E�� � �Y� �/�/�/�2� �� �� �� r����infoc�������������������B��K����|�j���������r� �t����������j��������i�|�dt����������t ����������j����������������������������������i�������������}|�j������������������������������|��������������d�{V����d�S�#�t����������j��������$�r���t����������$�r�t����������� ��������������������d�������������Y�d�S�w�xY�wd�S�)N� timestampz+Exception while sending PatchFailed message)r����r ����VulnerabilityPatchFailedr<����time�process_messager�����CancelledError� ExceptionrY���r����)r4���r�����msgs��� r����_send_failed_messagez)VulnerabilityPatcher._send_failed_message����s������������:�� P� P�!�:�?�t�?��S�����-=�-=�>�?�������j�0�0��5�5�5�5�5�5�5�5�5�5�5���)�� �� �� ���� P�� P�� P�� � �!N�O�O�O�O�O�O� P���� P�� Ps����AA%��%3B�Br9���c�������������������>��K����t����������j����������������������}t����������|�������������}t����������|t����������������������}t����������|d�������������5�}t����������|d�������������5��t ����������|�������������5�}|5�}t����������|�������������5�} |���������������������|�������������|�� ��������������������|j ��������|j ��������|j ��������| j ��������||�������������} t�������������������������������dd� ��������������������| �������������������������d\��}}d�} �t����������j��������j��������| t����������j��������t����������j��������d����d�{V���} | �������������������������������������d�{V���\��}}|�����������������������������������}�n�#�t����������j��������$�rD�| r@t+����������t,����������������������5��| ������������������������������������d�d�d��������������n#�1�swxY�w�Y�����t0����������$��r&}|����������������������|| | r| j��������nd ||�������������}t�������������������������������d |���������������������d��������������d�|���������������������d ��������������d|���������������������d���������������i�|�d|i���������������|����������������������i�|�t=����������t?����������|����������������������������������������d�{V����tA������������������������tC����������|������������| fcY�d�}~cd�d�d��������������cd�d�d��������������cd�d�d��������������cd�d�d��������������cd�d�d��������������S�d�}~ww�xY�wtA����������|������������d�| fcd�d�d��������������cd�d�d��������������cd�d�d��������������cd�d�d��������������cd�d�d��������������S�#�1�swxY�w�Y���d�d�d��������������n#�1�swxY�w�Y���d�d�d��������������n#�1�swxY�w�Y���d�d�d��������������n#�1�swxY�w�Y���d�d�d��������������d�S�#�1�swxY�w�Y���d�S�)N)r���i���r���)r����r����zExecuting %s� )r���r���)r����r�����~���z'Patch vulnerabilities failed exit_code=r����z: %sr����r����r����)�extra)�message)"�tempfile� gettempdirr���� isinstancer���r)���r'���r���r7���r����r����rY����debug�joinr����� subprocess�create_subprocess_exec�PIPE�communicate�readr����r����ProcessLookupError� terminater����r����r�����errorrS���r����r����rg���rk����repr)r4����userr5���r����result_filer�����flist�progress�result�logr����r����r�����procro���r����r����s��� r����startzVulnerabilityPatcher.start����s���������� ��%�'�'��-�g�>�>�>���[�/�:�:�� '��%� �� �� ��7 2� �.��%� �� �� �7 2��7 2��(�� �� �� � 7 2���{� 7 2��'-�.E��/ ��/ ��/ � 7 2����K�K��!�!�!��)�)����!������� ������C�� �L�L�����#���7�7�7��H�C���D� 5�$�/�F��%�?�%�?������������������� �"&�!1�!1�!3�!3�3�3�3�3�3�3���S����������)�� �� �� ���)�!�"4�5�5��)��)����(�(�(�)��)��)��)��)��)��)��)��)��)��)�����)��)��)��)���� 5�� 5�� 5��3�3���'+�4�D�O�O�����4����������@�"&�(�(�=�"9�"9�@��@��@��x�x����:�:����%���:�:�4�T�4�;��4�4� ����������/�/�6�t�6�t�C��H�H�5�5�5�6�������������������#�}�}�d�3�i�i��4�4�4�4�4�4�k7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2�����F 5����(��v�&�&��c�1�o7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2�����7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2�����7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2�����7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2�����7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2��7 2�����7 2��7 2��7 2��7 2��7 2��7 2s#���N�M:�/M#�2M �A:L5�>A"E" � L5�"%K$ �F(�K$ �(F,�,K$ �/F,�0K$ �>CK �K$ �L5�"M �.M#�:M:�N�K$ �$L5�8M �M#�M:�N�5L9�9M �<L9�=M ��M#�M �M#�M �M#�M:�#M'�'M:�*M'�+M:�.N�:M> �>N�M> �N�N�N�NN)r!���r"���r#���r����r ���r����rR���r����r|���r����r���rg���r<���r����bytesr����r����r����r���rk���r����r$���r���r���r~���r~�������s�������������+�J� �)�H����������!��!��!��!��!�F�� � � � �#�Y� ��� ����� � ���� �� �� ���\� � P�t�� P�� P�� P�� P�@2�� �{�H�S�M�4��9�4� 5� @2��@2��@2��@2��@2��@2r���r~���r����).r{���r�����loggingr����r����r����r����� contextlibr����typingr���r���r���r���r���� defence360agent.contracts.configr ����"defence360agent.contracts.messagesr ����defence360agent.utilsr����imav.contracts.configr ����imav.malwarelib.modelr����imav.malwarelib.utils.revisiumr���r���r���r���r���r���� getLoggerr!���rY���r���r���r'���r)���rg���r<���r>���r����r@���rk���r~���r$���r���r����<module>r�������s��������*����������� � � � ��������������������������������5��5��5��5��5��5��5��5��5��5��5��5��5��5��>��>��>��>��>��>��:��:��:��:��:��:��8��8��8��8��8��8��-��-��-��-��-��-��2��2��2��2��2��2��������������������������������� �� �8� $� $��*��*��*��*� �� �� �� �� �.�� �� �� � �� �� �� �� �#3�� �� �� �N��N��N��N��N�!1��N��N��N��e�C��H�o���#���������1O��1O��1O��1O��1O�t��1O��1O��1O�h4��4��4��4��4�$�s�,�,�-��4��4��4�(G2��G2��G2��G2��G2��G2��G2��G2��G2��G2r���