Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate...

52
Dissec&ng complex codereuse a4acks with ROPMEMU Mariano Graziano Cisco Talos

Transcript of Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate...

Page 1: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

Dissec&ng  complex  code-­‐reuse  a4acks  with  ROPMEMU

Mariano  Graziano  Cisco  Talos  

Page 2: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

whoami

§ Security researcher at Cisco Talos § Ph.D. from Telecom ParisTech/Eurecom § Hackademic § Malware analysis / Memory forensics / Mitigations

Page 3: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

CODE  INJECTION  ATTACKS

Page 4: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

CODE  INJECTION  ATTACKS

Page 5: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

CODE  INJECTION  ATTACKS

A0ackers  inject  or  load  malicious  code    (or  modify  the  exis=ng  one)  

Page 6: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

CODE-­‐REUSE  ATTACKS  -­‐  ROP

Page 7: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

CODE-­‐REUSE  ATTACKS  -­‐  ROP

SP  =  0xFFFF88001B800000  

0x00)  

0x30)  

Page 8: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

CODE-­‐REUSE  ATTACKS  -­‐  ROP

SP  =  0xFFFF88001B800000  

0x00)  

0x30)  

Page 9: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

CODE-­‐REUSE  ATTACKS  -­‐  ROP

SP  =  0xFFFF88001B800000  

0x00)  

0x30)  

Page 10: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

CODE-­‐REUSE  ATTACKS  -­‐  ROP

SP  =  0xFFFF88001B800000  

0x00)  

0x30)  

Page 11: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

CODE-­‐REUSE  ATTACKS  -­‐  ROP

SP  =  0xFFFF88001B800000  

0x00)  

0x30)  

Page 12: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

CODE-­‐REUSE  ATTACKS  -­‐  ROP

SP  =  0xFFFF88001B800000  

0x00)  

0x30)  

Page 13: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

CODE-­‐REUSE  ATTACKS  -­‐  ROP

SP  =  0xFFFF88001B800000  

0x00)  

0x30)  

Page 14: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

CODE-­‐REUSE  ATTACKS  -­‐  ROP

SP  =  0xFFFF88001B800000  

0x00)  

0x30)  

Page 15: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

CODE-­‐REUSE  ATTACKS  -­‐  ROP

SP  =  0xFFFF88001B800000  

0x00)  

0x30)  

?!?  

Page 16: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

MOTIVATION

HW and OS countermeasures forced ROP adoption

Page 17: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

MOTIVATION

HW and OS countermeasures forced ROP adoption

§ Persistent ROP rootkit – Vogl et al. [NDSS 14] § ROP as an obfuscation technique (malware in the wild) § All existing tools cope with injected code § No tools to dissect ROP payloads

Page 18: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

ROP  ROOTKITS

Page 19: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

CHUCK  -­‐  CHALLENGES

§ Memory region for the persistent control structure

§ Overwrites protection: §  Interrupts

§ Self-overwriting

§ Resume original/normal control flow

§ Activate the persistent component

Page 20: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

CHUCK  -­‐  CHALLENGES

§ Memory region for the persistent memory region

§ Overwrites protection: §  Interrupts

§ Self-overwriting

§ Resume original/normal control flow

§ Activate the persistent component

Page 21: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

CHUCK  -­‐  PERSISTENCE

§ CVE-2013-2094

§ sysenter § IA32_SYSENTER_ESP (0x175) § IA32_SYSENTER_EIP (0x176)

Page 22: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

CHUCK  -­‐  PERSISTENCE

§ CVE-2013-2094

§ sysenter § IA32_SYSENTER_ESP (0x175) – Copy chain

§ IA32_SYSENTER_EIP (0x176) - ret

Page 23: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

CHUCK  

§ PoC1: §  LPE: CVE-2013-2094 §  OS: Ubuntu Server 3.8 with secure boot

§ Hooks: §  sys_read §  sys_getdents

§ Chains: §  Copy chain (persistent) §  Dispatcher chain §  Payload chain

1  h0ps://www.sec.in.tum.de/persistent-­‐data-­‐only-­‐malware/  

Page 24: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

CHALLENGES

Page 25: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

CHALLENGES

[C1] Verbosity

Page 26: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

CHALLENGES

[C1] Verbosity [C2] Lack of immediate values

Page 27: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

CHALLENGES

[C1] Verbosity [C2] Lack of immediate values [C3] Stack based instruction chaining

Page 28: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

CHALLENGES

[C1] Verbosity [C2] Lack of immediate values [C3] Stack based instruction chaining [C4] Conditional branches

Page 29: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

CHALLENGES

[C1] Verbosity [C2] Lack of immediate values [C3] Stack based instruction chaining [C4] Conditional branches [C5] Return to functions

Page 30: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

CHALLENGES

[C1] Verbosity [C2] Lack of immediate values [C3] Stack based instruction chaining [C4] Conditional branches [C5] Return to functions [C6] Dynamically generated chains

Page 31: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

CHALLENGES

[C1] Verbosity [C2] Lack of immediate values [C3] Stack based instruction chaining [C4] Conditional branches [C5] Return to functions [C6] Dynamically generated chains [C7] Stop condition

Page 32: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

CHALLENGES

[C1] Verbosity [C2] Lack of immediate values [C3] Stack based instruction chaining [C4] Conditional branches [C5] Return to functions [C6] Dynamically generated chains [C7] Stop condition

Page 33: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

CHALLENGES

[C1] Verbosity [C2] Lack of immediate values [C3] Stack based instruction chaining [C4] Conditional branches [C5] Return to functions [C6] Dynamically generated chains [C7] Stop condition

-­‐  Lu  et  al.  –  ACSAC12  -­‐  Yadegari  et  al.  –  S&P15  

-­‐  Stancill  et  al.  –  RAID13  -­‐  Lu  et  al.  –  ACSAC12  

Page 34: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

APPROACH

§ ROPMEMU framework adopts many techniques:

§ Memory forensics

§ Code emulation

§ Multi-path exploration

§ CFG recovery

§ Compiler transformations

Page 35: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

IMPLEMENTATION

§ Volatility plugins (ropemu and unchain) depend on:

§ Capstone

§ Unicorn

§ nasm

§ Standalone scripts (bash and python): § GDB python

§ pygraphviz

Page 36: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

ROPMEMU

Page 37: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

ROPMEMU

Page 38: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

DEMO  0x01

DEMO 0x01

Page 39: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

ROPMEMU

Page 40: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

DEMO  0x02

DEMO 0x02

Page 41: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

ROPMEMU

Page 42: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

DEMO  0x03

DEMO 0x03

Page 43: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

ROPMEMU

Page 44: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

ROPMEMU

Page 45: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

EXPERIMENT

CHAINS INSTRUCTIONS GADGETS BLOCKS BRANCHES FUNCTIONS CALLS

COPY 414275 184126 1   -­‐   - -

DISPATCHER 63515 18874 7   3   1 5

PAYLOAD 6320 2913 34   26   9 17

Page 46: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

RESULTS  -­‐  CFG

Page 47: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

RESULTS  -­‐  CFG

Page 48: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

RESULTS  -­‐  IDA

Page 49: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

DEMO  0x04

DEMO 0x04

Page 50: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

LIMITATIONS

§ Prone to anti-acquisition

§ Prone to anti-emulation

§ Lack of completeness on arbitrary inputs

Page 51: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

CONCLUSIONS

§ Source code: https://github.com/vrtadmin/ROPMEMU

§ First public tool to analyze code-reuse payloads

§ Tested on the most complex public threat

Page 52: Dissec&ng)complex) code0reuse)a4acks) withROPMEMU · Resume original/normal control flow ! Activate the persistent component. CHUCKCHALLENGES ! Memory region for the persistent memory

QUESTIONS? Mariano  Graziano  

@emd3l  [email protected]