PE Tree is a Python module for viewing Portable Executable (PE) files in a tree-view using pefile and PyQt5. Can also be used with IDA Pro to dump in-memory PE files and reconstruct imports.
Features
Application
Requirements
Installation
Install directly from GitHub using a fresh virtual environment and pip:
Windows
> virtualenv env
> env\Scripts\activate
> pip install –upgrade pip
> pip install git+https://github.com/blackberry/pe_tree.git
Mac/Linux
$ python3 -m venv env
$ source ./env/bin/activate
$ pip install –upgrade pip
$ pip install git+https://github.com/blackberry/pe_tree.git
For Developers
Git clone the repository and setup for development:
Windows
> git clone https://github.com/blackberry/pe_tree.git
> cd pe_tree
> virtualenv env
> env\Scripts\activate
> pip install -e .
Mac/Linux
$ git clone https://github.com/blackberry/pe_tree.git
$ cd pe_tree
$ python3 -m venv env
$ source ./env/bin/activate
$ pip install -e .
Usage
Run PE Tree and use the GUI to select a file to view:
$ pe-tree
Run PE Tree and view the specified file/folder:
$ pe-tree <path>
Dark-Mode
Dark-mode can be enabled by installing QDarkStyle:
$ pip install qdarkstyle
IDAPython
Requirements
Installation
To install and run as an IDAPython plugin you can either use setuptools or install manually.
Using Setup Tools
$ git clone https://github.com/blackberry/pe_tree.git $ cd pe_tree $ python setup.py develop --ida
Install Manually
$ git clone https://github.com/blackberry/pe_tree.git $ cd pe_tree $ pip install -r requirements.txt
./pe_tree/
to your IDA plugins folderFor Developers
To simply run as a script under IDA first install the pe_tree package requirements for the global Python installation:
$ pip install -r requirements.txt
Then run pe_tree_ida.py under IDA:
File -> Script file... -> pe_tree_ida.py -> Open
IDA Plugins Folder
OS | Plugins folder |
---|---|
Windows | %ProgramFiles%\IDA Pro 7.X\plugins |
Linux | /opt/ida-7.X/plugins |
Mac | ~/.idapro/plugins |
Usage
Manual Load
and Load Resources
for best results!)Edit -> Plugins -> PE Tree
Examples
Below are the basic steps to dump a packed PE file (for example MPRESS or UPX) and rebuild imports (assuming the image base/entry-point is fairly standard):
Manual Load
and Load Resources
)Options -> General -> Analysis -> Reanalyze program
Add PE -> Search IDB
HEADER-0x00400000
(or appropriate module) and select Dump...
AddressOfEntryPoint
(typically 0x1000)Rebuild imports
is selectedA new executable will be created using the unpacked section data obtained from memory/IDB, and a new section named .idata containing the rebuilt IAT, hint name table and IDT will be appended to the PE file. If the entry-point memory segment has been marked writable during execution (via VirtualProtect for example) then the EP section characteristics will also be marked writable. Finally, the BASERELOC, BOUND_IMPORT and SECURITY data directories are marked null, and the OPTIONAL_HEADER checksum is recalculated (if enabled via config)
Using the above approach it is possible to dump many in-memory PE files that have either been unpacked, remotely injected, reflectively loaded or hollowed etc.
Configuration
The configuration is stored in an INI file and defaults to the following values:
[config]
debug = False
fonts = Consolas,Monospace,Courier
virustotal_url = https://www.virustotal.com/gui/search
cyberchef_url = https://gchq.github.io/CyberChef
[dump]
enable = True
recalculate_pe_checksum = False
Options
Section | Option | Type | Description |
---|---|---|---|
config | debug | boolean | Print pefile.dump() to output |
config | fonts | string | Comma-separated list of font names for UI |
config | virustotal_url | string | VirusTotal search URL |
config | cyberchef_url | string | CyberChef URL |
dump | enable | boolean | Enable process dumping/IAT rebuilding in IDA |
dump | recalculate_pe_checksum | boolean | Recalculate PE header checksum (slow!) |
Location
Type | OS | Path |
---|---|---|
Application | Windows | %TEMP%\pe_tree.ini |
Application | Linux/Mac | /tmp/pe_tree.ini |
IDAPython | Windows | %APPDATA%\HexRays\IDA Pro\pe_tree.ini |
IDAPython | Linux/Mac | ~/.idapro/pe_tree.ini |
3rd Party Data Sharing
The following information will be shared with 3rd party web-applications (depending on configuration) under the following conditions:
Virus Total
If the VirusTotal URL is specified in the configuration then metadata such as file hashes, timestamps, etc will be sent to VirusTotal for processing when the user clicks on highlighted links or selects “VirusTotal search” from the right-click context menu.
CyberChef
If the CyberChef URL is present in the configuration then any file data will be base64 encoded and sent to CyberChef for processing when the user selects “CyberChef” from the right-click context menu.
Troubleshooting
AttributeError: module ‘pip’ has no attribute ‘main’
or
PyQt5 fails to install under Linux
$ pip install –upgrade pip
Try uninstalling and reinstalling PyQt5 as follows:
pip uninstall PyQt5
pip uninstall PyQt5-sip
pip install PyQt5 PyQt5-sip
Ensure IDA has found and disassembled all code:
Options -> General -> Analysis -> Reanalyze program
After this is completed try to dump/rebuild imports again.
Developer Documentation
To build documentation from source using Sphinx:
$ pip install sphinx
$ sphinx-apidoc -o ./doc/source/ .
$ sphinx-build -b html ./doc/source ./doc/build -E
To view the documentation open ./doc/build/index.html
in a web-browser.
Kali Linux 2024.4, the final release of 2024, brings a wide range of updates and…
This Go program applies a lifetime patch to PowerShell to disable ETW (Event Tracing for…
GPOHunter is a comprehensive tool designed to analyze and identify security misconfigurations in Active Directory…
Across small-to-medium enterprises (SMEs) and managed service providers (MSPs), the top priority for cybersecurity leaders…
The free and open-source security platform SecHub, provides a central API to test software with…
Don't worry if there are any bugs in the tool, we will try to fix…