A Glance at Interpreted Language Bytecode Trickery
summary
Researcher encounters a product of compiled Python 2.7 packaged with py2exe whose .pyc files break uncompyle6 with an unknown magic number 62216. Investigation shows opcodes are remapped (e.g. 111→131, 64→4), so a recursive routine rewrites co_code and constants, rebuilds a .pyc with a documented magic number and decompiles successfully. For PHP SourceGuardian, the vld extension is modified to dump at the second zend_execute, five opcode handlers are replaced to deobfuscate operands and dump unused classes/functions. Code and writeups live on the Tenable tech blog.
AI-written summary · about
chapters (30)
- 0:00Start
- 1:10Background
- 1:50Topics
- 3:07Python Opcode Remapping
- 3:17Druva inSync is built with py2exe
- 4:43What's a .pyc file?
- 5:24It won't decompile!
- 5:55pyc file format
- 7:02Magic Number List
- 9:17Code object is executable
- 10:03Disassembling Code Object in hello.pyc
- 11:58More Nested Code Objects
- 13:10Remap the Opcodes in Code Objects
- 15:44PHP - SourceGuardian
- 17:52PHP Bytecode
- 18:48PHP Hooks and Extensions
- 20:16Vulcan Logic Dumper (VLD) Extension
- 22:21VLD-Zend_compile_file() hook -sg-load
- 22:46Visualizing the Hook
- 23:452nd zend_execute() hook - no opcodes!?
- 25:19But why? ... Time to debug
- 27:28Another sample...
- 30:19Debugger: JMP Handler
- 30:30Enter the SG JMP Handler
- 31:56SourceGuardian JMP Handler
- 32:34Solution: Fix each zend_op
- 33:29Solution: Fix The Op Array
- 35:395 SourceGuardian Opcode Handlers
- 36:59Classes and functions: 'main'
- 38:35Dump it All - ClassOne
related talks
38mThere and Back Again: Reverse Engineering Python Binaries
45m"Advanced Malware Threat: handling obfuscated code using..."
01h 09mDeobfuscate UEFI/BIOS Malware And Virtualized Packers
21mDemystify Today's Binary Disassembling and How Modern ABI Makes it Easier
25mCommSec D1 - A Deep Dive Into Malicious Documents
30mThe Hidden ART Of Rolling Shellcode Decryption
32mYou Can Run, but You Can't Hide - Finding the Footprints of Hidden Shellcode
11mcompilers HATE him: use this ONE WEIRD TRICK to hide a message...!
