본문 바로가기

Malware Analysis

pcode2code 설치 및 간단한 실습

pcode2code 설치

 

pcode2code 레포지토리를 clone하고 setup.py를 실행하여 설치하는 방법이 있다.

pip를 이용하여 해당 모듈을 설치하는 방법이 존재한다.

 

github.com/Big5-sec/pcode2code

 

Big5-sec/pcode2code

a vba pcode decompiler based on pcodedmp. Contribute to Big5-sec/pcode2code development by creating an account on GitHub.

github.com

 

나는 첫 번째 방법을 이용해서 설치했다.

 

 

setup.py를 이용해서 설치를 진행하려고 했지만 코드에 ','가 빠져서 에러가 일어났다.

 

 

코드를 수정하여 에러를 제거하고 설치를 진행하면 pcode2code 설치를 완료할 수 있다.

 

더보기

(수정전)

#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""The setup script."""

from setuptools import setup, find_packages

with open('README.md') as readme_file:
    readme = readme_file.read()

#with open('HISTORY.rst') as history_file:
#    history = history_file.read()

requirements = ["pcodedmp"]

setup_requirements = [ ]

test_requirements = [ ]

setup(
    author="Nicolas Zilio",
    author_email='nicolas.zilio@hotmail.fr',
    python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*',
    classifiers=[
        'Development Status :: 2 - Pre-Alpha',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
        'Natural Language :: English',
        "Programming Language :: Python :: 2",
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.5',
        'Programming Language :: Python :: 3.6',
        'Programming Language :: Python :: 3.7',
    ],
    description="a vba p-code decompiler based on pcodedmp",
    entry_points={
        'console_scripts': [
            'pcode2code=pcode2code.pcode2code:main',
        ],
    },
    install_requires=requirements,
    license="GNU General Public License v3",
    long_description=readme + '\n\n', # + history,
    long_description_content_type = 'text/markdown'
    include_package_data=True,
    keywords='pcode2code',
    name='pcode2code',
    packages=find_packages(include=['pcode2code', 'pcode2code.*']),
    setup_requires=setup_requirements,
    test_suite='tests',
    tests_require=test_requirements,
    url='https://github.com/Big5_sec/pcode2code',
    version='0.1.1',
    zip_safe=False,
)

 

(수정후)

#!/usr/bin/env python
# -*- coding: utf-8 -*-

"""The setup script."""

from setuptools import setup, find_packages

with open('README.md') as readme_file:
    readme = readme_file.read()

#with open('HISTORY.rst') as history_file:
#    history = history_file.read()

requirements = ["pcodedmp"]

setup_requirements = [ ]

test_requirements = [ ]

setup(
    author="Nicolas Zilio",
    author_email='nicolas.zilio@hotmail.fr',
    python_requires='>=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, !=3.4.*',
    classifiers=[
        'Development Status :: 2 - Pre-Alpha',
        'Intended Audience :: Developers',
        'License :: OSI Approved :: GNU General Public License v3 (GPLv3)',
        'Natural Language :: English',
        "Programming Language :: Python :: 2",
        'Programming Language :: Python :: 2.7',
        'Programming Language :: Python :: 3',
        'Programming Language :: Python :: 3.5',
        'Programming Language :: Python :: 3.6',
        'Programming Language :: Python :: 3.7',
    ],
    description="a vba p-code decompiler based on pcodedmp",
    entry_points={
        'console_scripts': [
            'pcode2code=pcode2code.pcode2code:main',
        ],
    },
    install_requires=requirements,
    license="GNU General Public License v3",
    long_description=readme + '\n\n', # + history,
    long_description_content_type = 'text/markdown',
    include_package_data=True,
    keywords='pcode2code',
    name='pcode2code',
    packages=find_packages(include=['pcode2code', 'pcode2code.*']),
    setup_requires=setup_requirements,
    test_suite='tests',
    tests_require=test_requirements,
    url='https://github.com/Big5_sec/pcode2code',
    version='0.1.1',
    zip_safe=False,
)

 

 

업로드한 파일을 다운로드받아 setup.py 파일만 교체하고 실행하면 정상적으로 모듈이 설치된다.

 

setup.py
0.00MB

 

(설치장면1)

 

 

(설치장면2)

 

 


pcode2code 실습

 

어제 vba stomping 관련 포스트를 올렸는데, 마침 pcode2code 실습을 하니 직접 사용해보자.

 

vba stomping이 적용된 문서 파일을 대상으로 실습을 진행해봤다.

 

OfficeMalScanner를 이용하여 문서 파일 내에 저장된 소스코드를 추출했고

pcode2code를 이용하여 문서 파일 내에 저장된 P-코드(바이트코드)를 디컴파일한 결과를 따로 파일로 저장했다.

(tistory 코드 블럭이 visual baisc 소스코드는 지원하지 않는 것 같다.)

 

원본 소스코드

 

Sub AutoOpen()
  MsgBox "ABC"
End Sub

 

pcode2code 결과

 

'''stream : VBA/ThisDocument - 932 bytes


'''########################################





'''stream : VBA/Module1 - 1020 bytes

'''########################################



Sub AutoOpen()

  MsgBox "ABC"

End Sub

 

OfficeMalScanner 결과

 

Attribute VB_Name = "Module1"
Sub AutoOpen()
    MsgBox "XYZ"
End Sub

 

확실히 저번 포스트의 vba stomping이 적용된 문서를 대상으로 좋은 결과물을 뽑아냈다.

다른 vba stomping이 적용된 문서형 악성코드 샘플,

vba stomping 적용을 도와주는 도구를 사용한 문서 샘플들도 한 번 적용시켜봐야겠다.