ThwarVng Memory Disclosure Apacks using DestrucVve Code Reads

1 downloads 69 Views 1MB Size Report
DestrucVve Code Reads. DetecVng read operaVons into executable memory. RAM. Bytes intended as code. Bytes intended as da
HEISENBYTE:    

Thwar/ng  Memory  Disclosure  A>acks   using  Destruc/ve  Code  Reads   Adrian  Tang    

Simha  Sethumadhavan   Salvatore  Stolfo  

CCS  2015  -­‐  Oct  12-­‐16,  Denver,  US  

Key  Idea:  Destruc/ve  Code  Reads   Problem    

Executable  memory  can  be  read     Memory  disclosure  bugs     Dynamic  code  reuse  a>acks  

Our  Solu,on   Make  executable  memory  indeterminate  aRer  it  has  been  read   1/21  

Our  Inspira/on   Observer  Effect:    

 “The  act  of  observing  a  system  inevitably  changes          the  state  of  the  system.”  

HEISENBYTE’s  destruc/ve  code  reads:    “Reading  executable  memory  changes  the                              executable  state  of  the  read  memory.”  

Werner  Heisenberg,  in  1933   (German  theore6cal  physicist)    

Image  credits:  Wikipedia  

2/21  

Execu/ng  memory  aRer  reading  it  yields     unpredictable  behavior  

HEISENBYTE  in  a  Slide   Dynamic     Code  Reuse  A8ack  

Prior  Defenses  

Our  Work  

Memory  disclosure  

Memory  disclosure  

Memory  disclosure  

+  

Scan  memory  at   run/me  for  gadgets  

+  

+  

XnR  (CCS’14)   Scan  memory  at   HideM  (CODASPY’15)   run/me  for  gadgets   Readactor  (Oakland’15)  

+  

+  

Scan  memory  at   run/me  for  gadgets  

+  

Chain  gadgets  to   generate  shellcode  

Chain  gadgets  to   generate  shellcode  

Chain  gadgets  to   generate  shellcode  

Redirect  control   flow  

Redirect  control   flow  

Redirect   control   HEISENBYTE     flow   (This   talk)  

+  

+  

Tolerates  discovery  of  code  reuse  gadgets,  but     prevents  them  from  being  used  as  intended  

3/21  

Extends  the  benefits  of  execute-­‐only  memory  to     closed  source  COTS  binaries,  especially  on  Windows  

+  

Why  defend  at  Step          ?   Extends  the  benefits  of  execute-­‐only  memory  to    closed  source  COTS  binaries,  especially  on  Windows   1)  Addresses  the  problem  of  incomplete  separa/on  of  data   from  code  in  (Windows)  COTS  binaries     2)  Protects  transparently  legacy  programs  that  mix  data  and   code  in  executable  JIT  dynamic  code  

4/21  

Outline   •  Destruc/ve  Code  Reads   •  System  Implementa/on   •  Evalua/on     •  Future  Work  

Destruc/ve  Code  Reads   Detec/ng  read  opera/ons  into  executable  memory   RAM  

Bytes  intended   as  data  

Bytes  intended   as  code  

5/21  

Destruc/ve  Code  Reads   Detec/ng  read  opera/ons  into  executable  memory   RAM  

Mark  this   memory  page  as     execute-­‐only  

5/21  

Destruc/ve  Code  Reads   Detec/ng  read  opera/ons  into  executable  memory   RAM  

5/21  

Destruc/ve  Code  Reads   Detec/ng  read  opera/ons  into  executable  memory   RAM  

Instruc/on  is   fetched  into  CPU  

5/21  

Destruc/ve  Code  Reads   Detec/ng  read  opera/ons  into  executable  memory   Virtual                      Physical   0x100 à 0x100

RAM  

5/21  

Destruc/ve  Code  Reads   Detec/ng  read  opera/ons  into  executable  memory   Virtual                      Physical   0x100 à 0x100

RAM  

CPU  tries  to  read   from  execute-­‐only   memory   Read  into  executable  memory  detected   5/21  

Destruc/ve  Code  Reads   “Destroying”  the  executable  byte  that  is  read   Virtual                      Physical   0x100 à 0x100

RAM  

5/21  

Destruc/ve  Code  Reads   “Destroying”  the  executable  byte  that  is  read   Virtual                      Physical   0x100 à 0x100

RAM  

Duplicate  original  executable  memory  page   5/21  

Destruc/ve  Code  Reads   “Destroying”  the  executable  byte  that  is  read   Virtual                      Physical   0x100 à 0x100

RAM   FF  

Destroy  the  original  executable  byte   5/21  

Destruc/ve  Code  Reads   “Destroying”  the  executable  byte  that  is  read   Virtual                      Physical   0x100 à 0x1100

RAM   FF  

5/21  

Destruc/ve  Code  Reads   “Destroying”  the  executable  byte  that  is  read   Virtual                      Physical   0x100 à 0x1100

RAM   FF  

Service  the  original  read  opera/on   5/21  

Destruc/ve  Code  Reads   “Destroying”  the  executable  byte  that  is  read   Virtual                      Physical   0x100 à 0x100

RAM   FF  

Restore  MMU  transla/on   5/21  

Destruc/ve  Code  Reads   Stopping  a  dynamic  code  reuse  a>ack   Virtual                      Physical   0x100 à 0x100

RAM   FF  

5/21  

Assume  memory  at  0x100  was  disclosed  as  part  of  an  a>ack  

Destruc/ve  Code  Reads   Stopping  a  dynamic  code  reuse  a>ack   Virtual                      Physical   0x100 à 0x100

RAM   FF  

5/21  

A>acker  assumes  that  he  found  a  stack  pivot  gadget  

Destruc/ve  Code  Reads   Stopping  a  dynamic  code  reuse  a>ack   Virtual                      Physical   0x100 à 0x100

RAM   FF  

5/21  

The  desired  gadget  was  not  executed  

Outline   •  Destruc/ve  Code  Reads   •  System  Implementa/on   •  Evalua/on     •  Future  Work  

System  Implementa/on   Offline  Sta/c  Binary  Rewri/ng  

Ini/aliza/on  of  Executable  Memory  

Ac/ve  Monitoring  Mode  

6/21  

System  Implementa/on   Offline  Sta/c  Binary  Rewri/ng  

Configure  Execute-­‐only  Memory  

Ac/ve  Monitoring  Mode  

6/21  

Key  Requirements  for  Destruc/ve  Code  Reads   “When”  to  mediate?      Detect  read  opera/ons  into  executable    memory     “How”  to  mediate?      Maintain  separate  code/data  views      for  same  (virtual)  memory  address   Hardware-­‐Assisted  Nested  Paging  is  a  key  enabler   7/21  

Hardware-­‐Assisted  Nested  Paging   Hardware  feature  to  improve  virtualiza/on  performance:      Translate  guest  to  host  addresses  in  hardware     Different   implementa/ons:      Intel  EPT*    AMD  RVI   Virtual (V) Addr

Physical (P) Addr

Machine (M) Addr

Code

Code

Code

GUEST

Guest Page Tables V P

Host EPT P M

:-­‐)  

HOST

Nested Paging Hardware 8/21  

*  EPT:  Extended  Page  Tables        RVI:  Rapid  Virtualiza6on  Indexing  

When  to  Mediate   (1)  Efficient  detec/on  of  reads  into  executable  memory   Problem:  OS  na/ve  paging  cannot  mark  memory  as  execute-­‐only  

Physical (P) Addr

Virtual (V) Addr R_X

Code

HOST

9/21  

Code

Page Tables V P

When  to  Mediate   (1)  Efficient  detec/on  of  reads  into  executable  memory   Problem:  OS  na/ve  paging  cannot  mark  memory  as  execute-­‐only   Solu,on:  Virtualize  the  host  and  use  Intel  EPT  to  mark  execute-­‐only  

Guest Physical (P) Addr Addr Physical (P)

Guest Virtual (V) Addr Addr Virtual (V) R_X

Code

GUEST HOST

9/21  

Host Machine (M) Addr __X

Code

Guest Page Page Tables V P

Code

Host EPT P M

HOST

Reads  into     this  page  will     trap  into     hypervisor  

How  to  Mediate   (2)  Efficient  maintenance  of  separate  code/data  views   Goal:  Induce  different  program  behavior  at  the  same  virtual  address              depending  on  read  or  execute  opera/on   Solu,on:  Manipulate  EPT  to  redirect  memory  transla/on  at  run/me   Guest Physical (P) Addr

Guest Virtual (V) Addr R_X

Code

Host Machine (M) Addr __X

Code

Code RW_

GUEST

10/21  

Guest Page Tables V P

Host EPT Host EPT P M1 P M M2

M1

“Copy” Data M2

HOST

Change   transla/on   at  run/me  

Architecture  (Para-­‐virtualized)   Offline

Live Target System

Rewritten binary Relocated data .reloc

Loaded application Guest page tables

EPT

Guest mode component

Guest Kernel

Host mode component

Host

Heisenbyte

11/21  

Guest User

Configure  execute-­‐only  mem     When  and  how  to  mediate     Destroy  code  when  read  

Architecture  (Para-­‐virtualized)   Offline

Live Target System

Rewritten binary Relocated data .reloc

Loaded application Guest page tables

EPT

Guest mode component

Guest Kernel

Host mode component

Host

Heisenbyte

11/21  

Guest User

Iden/fy  executable  mem     Induce  COW  

Tracking  Run/me  Executable  Memory   How  to  iden/fy  executable  memory  we  want  to  protect?    

(1)  Sta/c  program  binaries   •  Windows  OS-­‐provided  run/me  callbacks  for   •  New/exi/ng  processes   •  Loaded  libraries   (2)  Dynamic  JIT  code   •  Inline  hooking  of  Windows  memory  management  APIs   •  Perform  hypercalls  to  hypervisor  when     •  Exec  buffer  à  Non-­‐exec   •  Non-­‐exec  buffer  à  Exec   •  Exec  buffer  à  Freed  

[More  in  paper  …]  Op6miza6ons  and  Windows-­‐specific  implementa6on  details   12/21  

Tracking  Run/me  Executable  Memory   Challenges    

  Challenge  1:  Shared  physical  memory  pages  across  processes    

Solu,on:  Induce  Copy-­‐On-­‐Write  (COW)  on  pages  with            1-­‐byte  iden/ty  write  opera/on  to  each  page       Challenge  2:  Demand  paging  –  pages  could  be  paged  out    

Solu,on:  Make  pages  resident  in  physical  memory  using                                      MmProbeAndLockPages()  kernel  API  

13/21  

Some  Caveats  to  HEISENBYTE   •  Cannot  handle  code  that  reads/writes  to  itself   •  Eg.  Self-­‐modifying  code  

  •  Cannot  mi/gate  a>acks  that  reveal  contents  of   memory  without  directly  reading  executable  memory   •  Eg.  Fault-­‐based  side-­‐channel  a>acks  (Blind-­‐ROP)  

•  Need  support  for  fine-­‐grained  ASLR  

•  Eg.  Instruc/on-­‐level  in-­‐place  code  randomiza/on  

•  One-­‐byte  code  “destruc/on”  regardless  of  operand  size   of  read  opera/on   14/21  

Outline   •  Destruc/ve  Code  Reads   •  System  Implementa/on   •  Evalua/on     •  Future  Work  

Evalua/on  –  Execu/on  Overhead   SPEC2006  Run/me  Overhead  (%)   70

Runtime Overhead (%)

60

Virtualization Destructive Code Reads

50 40 30 20 10

40 0. pe rlb en ch 40 1. bz ip 2 40 3. gc c 42 9. m cf 44 5. go bm k 45 6. hm m er 45 8. sj en g 46 4. h2 64 re 47 f 1. om ne tp p 47 3. as 48 ta 3. r xa la nc bm k

0

“Destruc/ve  code  reads”  overhead  depends  on  how  imperfect  the   separa/on  of  data  from  code  in  executable  sec/ons   15/21  

Evalua/on  –  Execu/on  Overhead   Run/me  Overhead  (%)   70

Runtime Overhead (%)

60

Virtualization Destructive Code Reads

50 40 30 20 10

40 0. pe rlb en ch 40 1. bz ip 2 40 3. gc c 42 9. m cf 44 5. go bm k 45 6. hm m er 45 8. sj en g 46 4. h2 64 re 47 f 1. om ne tp p 47 3. as 48 ta 3. r xa la nc bm k

0

                                 Virtualiza/on  avg  overhead:    ~1.8%   Destruc/ve  code  reads  avg  overhead:    ~16.5%   16/21  

Evalua/on  –  Memory  Overhead   Peak  Resident  Set  Size  (RSS)  Memory  Overhead  (%)  

40 Peak RSS Memory Overhead (%) 0. pe rlb en ch 40 1. bz ip 2 40 3. gc c 42 9. m cf 44 5. go bm k 45 6. hm m er 45 8. sj en g 46 4. h2 64 re 47 f 1. om ne tp p 47 3. as 48 ta 3. r xa la nc bm k

10

8 6 4 2 0

Peak  RSS  memory  avg  overhead:    ~0.8%  

17/21  

Evalua/on  -­‐  Security   HEISENBYTE  corrupts  code  with  debug  trap  code  0xCC   CraRed  dynamic  code  reuse  exploits  and  monitor  for    invoked  debug  trap    

 (1)  Dynamic  code    

•  Self-­‐injected  bug  in  toy  program  that  mimics  the  crea/on   of  a  JIT  code  buffer  

 (2)  Sta/c  code  

•  CVE-­‐2013-­‐2551:  Internet  Explorer  Bug  

Exploits  on  both  sta/c  programs  and  dynamic  JIT  code   triggered  debug  traps   18/21  

Evalua/on  –  Demo  on  Win8  /  IE10  

19/21  

Outline   •  Destruc/ve  Code  Reads   •  System  Implementa/on   •  Evalua/on     •  Future  Work  

Future  Work   •  Improve  code/data  separa/on  task  in  disassembly  for   Windows  COTS  binaries   •  Record  read  opera/ons  into  executable  memory  to  guide   disassembly  and  binary  rewri/ng  

•  Lower  overhead  of  destruc/ve  code  reads  

•  Use  new  virtualiza/on-­‐based  hardware  features  in  Haswell+   processors  (Eg.  New  #VE  excep/on)  

•  Explore  value  of  destruc/ve  data  reads  

20/21  

Conclusions   Key  Idea:  Make  exec.  mem.  indeterminate  aRer  it  has  been  read   •  New  security  concept:  “Destruc/ve  code  reads”     •  One  applica/on:  Mi/gate  memory  disclosure  a>acks   •  Heisenbyte  is  a  prac/cal  solu/on     •  Works  with  imperfect  disassembly  on  COTS  binaries   •  No  instrumenta/on  on  the  binaries   •  JIT  code  works  too  

Thank  you! 21/21  

Adrian  Tang        Ÿ        @0x0atang  

Suggest Documents