plohmann@cs.uni-bonn.de IDA Pro with families malware against Patchwork Stitching Daniel Plohmann © 2014 Fraunhofer FKIE myself about words student Some  2 RE) mitigation malware for and botnet toolkit) of Reverse Engineering at University of Bonn & Fraunhofer FKIE analysis sandboxing (IDA Pro enhancements and researcher (python focus: malware projects FKIE Research focus: Efficiency Work PhD   [1] PyBox [2] IDAscope Personal background  Related   http://code.google.com/p/pyboxed https://idascope.pnx.tf  [1] [2] ©2014 Fraunhofer 3 FKIE Patchwork Motivation ©2014 Fraunhofer functions of convenience [1] + set (IDA)PyEmu = refurbished in progress in a nutshell Patchwork Work Driving    Patchwork …   analysis static aiding approach transformations data snippets-per-case allows that the (throwaway-) caring! from is ideas: away A flexible framework Get Sharing  4 (2009 / 2012) FKIE [1] https://github.com/codypierce/pyemu ©2014 Fraunhofer 5 IDA: with native code scriptable opcodes) target‘s (= no debugging, AppCall, PIN, …) plugin, no extendability sed, fully compatible common IDA code with run to most of analysis solutions of 2009) (limited (state actually / generalization integration emulation don‘t FKIE Incomplete Outdated But [1] Ida-x86emu: standalone [2] (IDA)PyEmu: python-ba   Seamless Instrumentalization  Reusability Notable   http://www.idabook.com/ida-x86emu https://github.com/codypierce/pyemu Patchwork Wishlist     [1] [2] ©2014 Fraunhofer :) (IDA)PyEmu Workflow   6 memory) ic results, transformed + EIP) (algorithm / registers memory state state (stack virtual step by modified + fill emulation context step with FKIE straight-forward Allocate Create Pretty Set initial   Emulate Proceed   ©2014 Fraunhofer A „stitch“: Patchwork Workflow  Criteria: • sequence sequence target wildcards) Match stored 3) Validate • against (with ins of executed ResultCallbacks Up to ins Store sequence Execute 2) Emulate • • • (RegEx) -> Function -> Offset offset RegEx fixed Offset Groupdict Xrefs Xrefs • • • • • 1) Select Stores: 7 results of earlier advantage etc. taking for patching function functions (IDA)python FKIE Arbitrary Convenience 4) Transform • • ©2014 Fraunhofer 8 irrelevant fields) to subfunction) of many n redirection) (delegated [1] obfuscated (call/jmp usage family (introductio 26/nymaim-obfuscation-chronicles/ usage malware obfuscation stack/register stack flow API calls / Ransom in assembler, heavily FKIE Control Obfuscated Obfuscated Hashed Dropper Written     http://www.welivesecurity.com/2013/08/ Patchwork Example: Nymaim   [1] ©2014 Fraunhofer 9 address address return 1 (0xB0B48F89) 0 (0x4F4AD544) address part part placed original return offset to de offset address to return for prologue displacement displacement Arg_0: Displacement Arg_4: Displacement Arg_8: Placeholder Function Save original return Calculate Apply Clean up and detour (Control Flow Obfuscation) FKIE Patchwork Example: Nymaim ©2014 Fraunhofer (Control Flow Obfuscation) Patchwork Example: Nymaim 10 ©2014 Fraunhofer FKIE (Control Flow Obfuscation) Patchwork Example: Nymaim 11 ©2014 Fraunhofer FKIE (Control Flow Obfuscation) Patchwork Example: Nymaim 12 ©2014 Fraunhofer FKIE (Control Flow Obfuscation) Patchwork Example: Nymaim 13 ©2014 Fraunhofer FKIE (Control Flow Obfuscation) Patchwork Example: Nymaim 14 ©2014 Fraunhofer FKIE (Control Flow Obfuscation) Patchwork Example: Nymaim 15 ©2014 Fraunhofer FKIE (Control Flow Obfuscation) Patchwork Example: Nymaim 16 ©2014 Fraunhofer FKIE (Control Flow Obfuscation) Patchwork Example: Nymaim 17 ©2014 Fraunhofer FKIE (Control Flow Obfuscation) Patchwork Example: Nymaim 18 ©2014 Fraunhofer FKIE (Control Flow Obfuscation) Patchwork Example: Nymaim 19 ©2014 Fraunhofer FKIE (Control Flow Obfuscation) Patchwork Example: Nymaim 20 ©2014 Fraunhofer FKIE (Control Flow Obfuscation) Patchwork Example: Nymaim 21 ©2014 Fraunhofer FKIE (Control Flow Obfuscation) Patchwork Example: Nymaim 22 ©2014 Fraunhofer FKIE (Control Flow Obfuscation) Patchwork Example: Nymaim 23 ©2014 Fraunhofer FKIE (Control Flow Obfuscation) Patchwork Example: Nymaim 24 ©2014 Fraunhofer FKIE (Control Flow Obfuscation) Patchwork Example: Nymaim 25 ©2014 Fraunhofer FKIE (Control Flow Obfuscation) Patchwork Example: Nymaim 26 ©2014 Fraunhofer FKIE push_push_call_regex = ( ) (Deobfuscation) Select: Patchwork Example: Nymaim   r"\x68(?P[\S\s]{4})" r"\x68(?P[\S\s]{4})" r"\xE8" instruction ret / retn first Until Emulate:  27 ©2014 Fraunhofer FKIE 28 (Deobfuscation) and -> add, sub, xor FKIE 'push dword', 'push dword', 'push ebp', 'mov ebp,esp', 'push eax', 'mov eax,[ebp+0x4]', 'mov [ebp+0x10],eax', 'mov eax,[ebp+0xc]', '', # contains the oper 'add [ebp+0x4],eax', 'pop eax', 'leave'], "call_detour": [ ppc_validators = { Validate: Patchwork Example: Nymaim  ©2014 Fraunhofer 29 emulation.cbResult) ct.pack("I", (call_offset) & 0xffffffff) .selectionOffset .cbResult - (obf_start_addr + 10 + 5) (Deobfuscation) selection ur(self, validation): emulation FKIE obf_start_addr = validation. call_offset = validation. deobf_call = "\x90" * 10 + "\xE8" + stru ida_lib.patch_bytes(obf_start_addr, deobf_call) self.updateCallXref(obf_start_addr + 10, validation. def _deobfuscate_call_deto Transform: Patchwork Example: Nymaim  ©2014 Fraunhofer (Deobfuscation) time recognition: 463 -> 920 all deobfuscations: ~2 min run 4443 transformations Functions Applying     Patchwork Example: Nymaim  Before: After: Crypted strings / functions 30 ©2014 Fraunhofer FKIE 31 up stack) blown Nymaim‘s to IDA / capstone (deobfuscate engine cases of opcodes (VM-based) decryption analysis use PyEmu usage coverage at more / patch FKIE Memory KINS BaseConfig Import reconstruction Change disassembly Increase Looking    Extend   Patchwork Future plans   ©2014 Fraunhofer 32 iel_plohmann/idapatchwork) improvement! for plohmann@cs.uni-bonn.de / ideas http://patchwork.pnx.tf or at https://bitbucket.org/dan :) to: a try FKIE (points it Repository  patchwork@pnx.tf Give  Send feedback  Patchwork Conclusion   ©2014 Fraunhofer