class 'AssertionError'>; co_code should be one of the types (<class 'str'>, <class 'bytes'>, <class 'list'>, <class 'tuple'>); is type <class 'NoneType'>와 같은 다른 오류가 발생할 수 있습니다.
이는 아마도 매직 넘버를 올바르게 추가하지 않았거나 올바른 매직 넘버를 사용하지 않았다는 것을 의미합니다. 따라서 올바른 것을 사용했는지 확인하십시오 (또는 새로운 것을 시도하십시오).
이전 오류 문서를 확인하십시오.
자동 도구
python-exe-unpacker 도구는 py2exe 및 pyinstaller로 작성된 실행 파일을 언패킹하고 디컴파일하는 데 도움이 되도록 설계된 여러 커뮤니티에서 제공하는 도구의 조합으로 작동합니다. 이는 실행 파일이 Python 기반인지 식별하기 위한 YARA 규칙을 포함하고 생성 도구를 확인합니다.
ImportError: 파일 이름: 'unpacked/malware_3.exe/pycache/archive.cpython-35.pyc'이(가) 존재하지 않음
일반적으로 발생하는 문제는 unpy2exe 또는 pyinstxtractor를 사용하여 언패킹 프로세스 중에 발생하는 불완전한 Python 바이트 코드 파일로 인해, 이후 uncompyle6에서 Python 바이트 코드 버전 번호가 누락되어 인식되지 않는 것입니다. 이를 해결하기 위해 필요한 Python 바이트 코드 버전 번호를 추가하는 prepend 옵션이 추가되었으며, 이는 디컴파일 프로세스를 용이하게 합니다.
문제의 예시:
# Error when attempting to decompile without the prepend optiontest@test: uncompyle6 unpacked/malware_3.exe/archive.pyTraceback (most recent call last):...ImportError: File name:'unpacked/malware_3.exe/__pycache__/archive.cpython-35.pyc' doesn't exist
# Successful decompilation after using the prepend optiontest@test:python python_exe_unpack.py -p unpacked/malware_3.exe/archive[*] On Python 2.7[+] Magic bytes are already appended.# Successfully decompiled file[+] Successfully decompiled.
Python 어셈블리 분석
이전 단계를 따라서 파이썬 "원본" 코드를 추출할 수 없었다면 어셈블리를 추출해 볼 수 있습니다(하지만 그렇게 구체적이지 않으므로 다시 원본 코드를 추출해 보세요). 여기에서 .pyc 바이너리를 분해하는 매우 간단한 코드를 찾았습니다(코드 흐름을 이해하는 데 행운을 빕니다). 만약 _.pyc_가 python2에서 생성된 것이라면, python2를 사용하세요:
>>> importdis>>> importmarshal>>> importstruct>>> importimp>>>>>> withopen('hello.pyc','r') asf:# Read the binary file...magic=f.read(4)...timestamp=f.read(4)...code=f.read()...>>>>>> # Unpack the structured content and un-marshal the code>>> magic=struct.unpack('<H',magic[:2])>>> timestamp=struct.unpack('<I',timestamp)>>> code=marshal.loads(code)>>> magic,timestamp,code((62211,), (1425911959,),<code object <module> at 0x7fd54f90d5b0, file "hello.py", line 1>)>>>>>> # Verify if the magic number corresponds with the current python version>>> struct.unpack('<H', imp.get_magic()[:2]) == magicTrue>>>>>> # Disassemble the code object>>> dis.disassemble(code)10LOAD_CONST0 (<code objecthello_worldat0x7f31b7240eb0,file"hello.py",line1>)3MAKE_FUNCTION06STORE_NAME0 (hello_world)9LOAD_CONST1 (None)12RETURN_VALUE>>>>>> # Also disassemble that const being loaded (our function)>>> dis.disassemble(code.co_consts[0])20LOAD_CONST1 ('Hello {0}')3LOAD_ATTR0 (format)6LOAD_FAST0 (name)9CALL_FUNCTION112PRINT_ITEM13PRINT_NEWLINE14LOAD_CONST0 (None)17RETURN_VALUE
파이썬을 실행 파일로 변환하기
먼저, 페이로드가 py2exe 및 PyInstaller에서 컴파일될 수 있는 방법을 보여드리겠습니다.