You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+110-1Lines changed: 110 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,11 +4,13 @@ This repository contains some scripts for statically decrypting Python scripts p
4
4
5
5
Blog post for further reading: https://cyber.wtf/2025/02/12/unpacking-pyarmor-v8-scripts/
6
6
7
+
Please also take note of the [Disclaimer](#disclaimer) section below before you continue.
8
+
7
9
## Usage
8
10
9
11
Initial preparation: Go into `py312` and run `docker build -t pyarmor312 .`. Also create a virtual env where you install `pycryptodome`.
10
12
11
-
1. Open up the native Pyarmor module in IDA, find the MD5 key derivation function, adjust `ida_getkey.py` and run it in IDAPython. Adjust `decrypt_gcm.py` with the key you obtained.
13
+
1. Open up the native Pyarmor module in IDA, find the MD5 key derivation function, adjust `ida_getkey.py` and run it in IDAPython. Adjust `decrypt_gcm.py` with the key you obtained. Alternatively, a Binary Ninja version of the script is available (`bn_getkey.py`).
12
14
1. Run `python decrypt_gcm.py /path/to/malware/malware.py`
13
15
1. Run `docker run --rm -u $(id -u):$(id -g) -v $(pwd)/analyze_crypted_code.py:/script.py:ro -v /path/to/malware:/data -it pyarmor312 /script.py /data/malware.py.dec`
14
16
1. Run `python decrypt_gcm.py /path/to/malware/malware.py.dec` - it will now use the json file generated by the step above to decrypt individual functions and generate a `dec2` file
@@ -24,6 +26,97 @@ Go to the PyInit export and scroll almost all the way down, until you see a plac
24
26
Inside that function you'll find the necessary details for `ida_getkey.py`.
25
27
26
28
29
+
## BCC mode
30
+
31
+
If the script you're analyzing is protected with BCC mode, step 2 will additionally yield an ELF file (`.dec.elf`).
32
+
This ELF contains Python functions that were compiled to native code.
33
+
34
+
You can use the `bcc_info.py` script with the custom Python interpreter for obtaining further details about the BCC functions.
35
+
That includes:
36
+
* Function offsets in the ELF
37
+
* Suggested function names
38
+
* List of constants used by the native code
39
+
40
+
This information is also written to a json file, which can be used with the IDAPython script `ida_annotate_bcc.py` in order to import the data into IDA.
41
+
42
+
**Note:** The ELF format is only followed in the broadest strokes, and IDA may refuse to load the file as ELF. In that case, simply load it as binary file. For Windows targets, you should make sure to set the compiler to Visual C++ so that the correct ABI will be used.
43
+
44
+
45
+
You may find the following reverse engineered definitions (Pyarmor v9, Python 3.11/3.12) helpful when looking at BCC code:
46
+
```c
47
+
enumGLOBAL_OPS
48
+
{
49
+
GLOBAL_DELETE = 0x0,
50
+
GLOBAL_GET = 0x1,
51
+
GLOBAL_RETURN_GLOBALS = 0x2,
52
+
GLOBAL_SPECIAL_ENTER = 0x4, /*__enter__*/
53
+
GLOBAL_SPECIAL_EXIT = 0x5, /*__exit__*/
54
+
GLOBAL_SET_MIN = 0x10, /* anything above means Set (pointer value instead of int) */
The Docker image builds a custom Python version that is able to read objects serialized by Pyarmor.
@@ -35,3 +128,19 @@ The patch introduces an `armor` flag into `RFILE` so that we can only apply the
35
128
Otherwise, Python breaks because it cannot unmarshal its builtin objects.
36
129
37
130
**If you have a protected version that utilizes a different Python version, you need to build that specific version and possibly adjust the patch.**
131
+
132
+
133
+
# Disclaimer
134
+
135
+
This repository contains tools developed by G DATA Advanced Analytics GmbH intended strictly for malware analysis and related security research.
136
+
137
+
**Important Notice**
138
+
- These tools are designed for legitimate purposes only, such as analyzing malicious software in controlled environments.
139
+
- Use of these tools for any unauthorized or illegal activities, including the analysis of non-malicious software, is strictly prohibited.
140
+
- Users are solely responsible for ensuring compliance with all applicable local, national, and international laws and regulations.
141
+
142
+
**No Warranty**
143
+
144
+
This software is provided "as is", without warranty of any kind, express or implied, including but not limited to the warranties of merchantability, fitness for a particular purpose, and non-infringement. In no event shall the authors or copyright holders be liable for any claim, damages, or other liability arising from, out of, or in connection with the software or the use or other dealings in the software.
0 commit comments