SlideShare ist ein Scribd-Unternehmen logo
1 von 24
Downloaden Sie, um offline zu lesen
MYSAFE
github.com/serkan-ozal/mysafe
SERKAN ÖZAL
AGENDA
● WHAT IS MYSAFE?
● MOTIVATION
● STATE OF ART
● HOW TO USE?
● FEATURES & DEMO
● ROADMAP
WHAT IS MYSAFE?
● Intercepts “sun.misc.Unsafe” calls
● Can track memory allocations and frees
● Can track memory accesses (reads/writes)
● Can align memory accesses (reads/writes)
● Can track custom memory allocations/frees
○ Ex. your custom memory manager implementation
● Can track memory allocation paths
○ Find the origins of leaked (non-free) memories
MOTIVATION
● Debugging memory allocations and frees
○ Checking native memory leaks over “Unsafe”
○ Detecting causes of native memory leaks
● Debugging memory accesses (reads/writes)
○ Finding the causes of illegal memory accesses
● Handle unaligned memory accesses (causes SIGBUS)
○ SPARC
○ ...
STATE OF ART
● Inspect application classes while loading
○ At “ClassFileTransformer” level
○ At “Classloader” level
● Redirect “Unsafe” calls to MySafe
● MySafe handles the call
● Proceeds to “Unsafe”
WHY NOT JUST INST. UNSAFE?
● Use “java.lang.Instrument#setNativeMethodPrefix”
● Add new wrapper methods for native methods
● Requires new method addition
● So class redefinition is not an option
● Hook into “Unsafe” classloading process
● “Unsafe” is already loaded before
○ Java agent
○ User classloader
● Use native JVMTI agent at startup (on the roadmap)
HOW TO USE?
● Java Agent Based Usage by VM Argument
○ -javaagent:<path_to_jillegal_agent><jillegal_agent_jar>=
"-p tr.com.serkanozal.mysafe.impl.processor.MySafeProcessor".
● Java Agent Based Usage Programmatically
○ MySafe.youAreMine();
● ClassLoader Based Usage by VM Argument
○ -Djava.system.class.loader=
tr.com.serkanozal.mysafe.impl.classloader.MySafeClassLoader
FEATURES & DEMO
● Memory Explorer API & Demo
● Memory Listener API & Demo
● Illegal Memory Access Listener API & Demo
● Custom Memory Management & Demo
● Tracing Allocation Path & Demo
Memory Explorer API
● Iterate on allocated memories
● Dump allocated memories
● MemoryExplorerDemo.java
Memory Listener API
● Be notified before/after allocate
● Be notified before/after reallocate
● Be notified before/after free
● MemoryListenerDemo.java
Illegal Mem. Acc. Listener API
● Be notified on illegal memory accesses (reads/writes)
● Be notified on un-allocated memory reallocations/frees
● Throws “IllegalArgumentException”
● IllegalMemoryAccessListenerDemo.java
Custom Memory Management
● Tracks custom memory mng. points instead of “Unsafe”
● Memory management points refers to methods which
○ allocate
○ reallocate
○ free
● Custom memory mng. points can be configured by:
○ @AllocationPoint
○ @FreePoint
○ @ReallocationPoint
● CustomMemoryManagementDemo.java
Tracing Allocation Path
● Alloc. path = stack trace of caller which allocates memory
● Dump active allocation paths
● Generate diagram of active allocation paths
● Alloc. paths are provided via “AllocPathManager” API
○ Instrumentation based (currently in use)
■ Pros: Very fast, low CPU and GC overhead
■ Cons: Not detailed, might be trashed
○ Java 9’s StackWalker API based (on the roadmap)
■ Pros: Detailed, no need to be trashed
■ Cons: Not fast as much as Inst. based one
● NativeMemoryLeakHuntingDemo.java
Inst. Based Alloc. Path Manager
● Identify each method which exist in the any alloc. path
● Inject code into methods to provide them as alloc. path
○ Push method identifier to thread-local call stack
○ Proceed actual call
○ Pop method identifier from thread-local call stack
● Generate alloc. path id from alloc. point (method) ids
○ Each alloc. point id is 2 bytes short number
○ Whole alloc. path is represented with 8 bytes long number
○ There can be at most 4 alloc. points, old ones are evicted
foo1 [1]
1
foo1 [1]
bar1 [2]
1 2
foo1 [1]
bar1 [2]
foo2 [3]
1 2 3
foo1 [1]
bar1 [2]
foo2 [3]
bar2 [4]
1 2 3 4
foo1 [1]
bar1 [2]
foo2 [3]
bar2 [4]
foo3 [5]
2 3 4 5
foo1 [1]
bar1 [2]
foo2 [3]
bar2 [4]
foo3 [5]
bar3 [6]
3 4 5 6
foo1 [1]
bar1 [2]
foo2 [3]
bar2 [4]
foo3 [5]
bar3 [6]
malloc
3 4 5 6
foo2 => bar2 => foo3 => bar3
ROADMAP
● Ability to track line numbers also
● More detailed and accurate allocation path detection
● Ability to inspect “Unsafe” directly
● Java 9 support
● Allocation path detection via Java 9’s StackWalker API
● Flame graph support
THANKS

Weitere ähnliche Inhalte

Ähnlich wie MySafe

Scalability, Fidelity and Stealth in the DRAKVUF Dynamic Malware Analysis System
Scalability, Fidelity and Stealth in the DRAKVUF Dynamic Malware Analysis SystemScalability, Fidelity and Stealth in the DRAKVUF Dynamic Malware Analysis System
Scalability, Fidelity and Stealth in the DRAKVUF Dynamic Malware Analysis System
Tamas K Lengyel
 
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CanSecWest
 

Ähnlich wie MySafe (20)

Adv java unit 1 M.Sc CS.pdf
Adv java unit 1 M.Sc CS.pdfAdv java unit 1 M.Sc CS.pdf
Adv java unit 1 M.Sc CS.pdf
 
Unsafe Java
Unsafe JavaUnsafe Java
Unsafe Java
 
Advanced Arm Exploitation
Advanced Arm ExploitationAdvanced Arm Exploitation
Advanced Arm Exploitation
 
Troubleshooting Java HotSpot VM
Troubleshooting Java HotSpot VMTroubleshooting Java HotSpot VM
Troubleshooting Java HotSpot VM
 
[Kiwicon 2011] Post Memory Corruption Memory Analysis
[Kiwicon 2011] Post Memory Corruption Memory Analysis[Kiwicon 2011] Post Memory Corruption Memory Analysis
[Kiwicon 2011] Post Memory Corruption Memory Analysis
 
WIndows Kernel-Land exploitation
WIndows Kernel-Land exploitationWIndows Kernel-Land exploitation
WIndows Kernel-Land exploitation
 
Veil-PowerView - NovaHackers
Veil-PowerView - NovaHackersVeil-PowerView - NovaHackers
Veil-PowerView - NovaHackers
 
Session - Debugging memory stomps and other atrocities - Stefan Reinalter - T...
Session - Debugging memory stomps and other atrocities - Stefan Reinalter - T...Session - Debugging memory stomps and other atrocities - Stefan Reinalter - T...
Session - Debugging memory stomps and other atrocities - Stefan Reinalter - T...
 
Emulating With JavaScript
Emulating With JavaScriptEmulating With JavaScript
Emulating With JavaScript
 
Scalability, Fidelity and Stealth in the DRAKVUF Dynamic Malware Analysis System
Scalability, Fidelity and Stealth in the DRAKVUF Dynamic Malware Analysis SystemScalability, Fidelity and Stealth in the DRAKVUF Dynamic Malware Analysis System
Scalability, Fidelity and Stealth in the DRAKVUF Dynamic Malware Analysis System
 
[HITB Malaysia 2011] Exploit Automation
[HITB Malaysia 2011] Exploit Automation[HITB Malaysia 2011] Exploit Automation
[HITB Malaysia 2011] Exploit Automation
 
Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...
Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...
Ansible for Configuration Management for Lohika DevOps training 2018 @ Lohika...
 
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
CSW2017 Henry li how to find the vulnerability to bypass the control flow gua...
 
Group meeting: UniSan - Proactive Kernel Memory Initialization to Eliminate D...
Group meeting: UniSan - Proactive Kernel Memory Initialization to Eliminate D...Group meeting: UniSan - Proactive Kernel Memory Initialization to Eliminate D...
Group meeting: UniSan - Proactive Kernel Memory Initialization to Eliminate D...
 
MSL2009. Valgrind
MSL2009. ValgrindMSL2009. Valgrind
MSL2009. Valgrind
 
Java SpringMVC SpringBOOT (Divergent).ppt
Java SpringMVC SpringBOOT (Divergent).pptJava SpringMVC SpringBOOT (Divergent).ppt
Java SpringMVC SpringBOOT (Divergent).ppt
 
Java 2
Java 2Java 2
Java 2
 
No locked doors, no windows barred: hacking OpenAM infrastructure
No locked doors, no windows barred: hacking OpenAM infrastructureNo locked doors, no windows barred: hacking OpenAM infrastructure
No locked doors, no windows barred: hacking OpenAM infrastructure
 
Metasploit For Beginners
Metasploit For BeginnersMetasploit For Beginners
Metasploit For Beginners
 
Distributed Coordination with Python
Distributed Coordination with PythonDistributed Coordination with Python
Distributed Coordination with Python
 

Mehr von Serkan Özal (7)

Flying Server-less on the Cloud with AWS Lambda
Flying Server-less on the Cloud with AWS LambdaFlying Server-less on the Cloud with AWS Lambda
Flying Server-less on the Cloud with AWS Lambda
 
Improving performance of decision support queries in columnar cloud database ...
Improving performance of decision support queries in columnar cloud database ...Improving performance of decision support queries in columnar cloud database ...
Improving performance of decision support queries in columnar cloud database ...
 
JVM Under the Hood
JVM Under the HoodJVM Under the Hood
JVM Under the Hood
 
Big data on aws
Big data on awsBig data on aws
Big data on aws
 
Ankara JUG Big Data Presentation
Ankara JUG Big Data PresentationAnkara JUG Big Data Presentation
Ankara JUG Big Data Presentation
 
AWS EMR - Amazon Elastic Map Reduce
AWS EMR - Amazon Elastic Map ReduceAWS EMR - Amazon Elastic Map Reduce
AWS EMR - Amazon Elastic Map Reduce
 
Big data concepts
Big data conceptsBig data concepts
Big data concepts
 

Kürzlich hochgeladen

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Kürzlich hochgeladen (20)

%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
Announcing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK SoftwareAnnouncing Codolex 2.0 from GDK Software
Announcing Codolex 2.0 from GDK Software
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital TransformationWSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
WSO2Con2024 - WSO2's IAM Vision: Identity-Led Digital Transformation
 
WSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go PlatformlessWSO2CON2024 - It's time to go Platformless
WSO2CON2024 - It's time to go Platformless
 
%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto%in Soweto+277-882-255-28 abortion pills for sale in soweto
%in Soweto+277-882-255-28 abortion pills for sale in soweto
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT  - Elevating Productivity in Today's Agile EnvironmentHarnessing ChatGPT  - Elevating Productivity in Today's Agile Environment
Harnessing ChatGPT - Elevating Productivity in Today's Agile Environment
 
%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand%in Midrand+277-882-255-28 abortion pills for sale in midrand
%in Midrand+277-882-255-28 abortion pills for sale in midrand
 
Architecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the pastArchitecture decision records - How not to get lost in the past
Architecture decision records - How not to get lost in the past
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park %in kempton park+277-882-255-28 abortion pills for sale in kempton park
%in kempton park+277-882-255-28 abortion pills for sale in kempton park
 

MySafe

  • 2. AGENDA ● WHAT IS MYSAFE? ● MOTIVATION ● STATE OF ART ● HOW TO USE? ● FEATURES & DEMO ● ROADMAP
  • 3. WHAT IS MYSAFE? ● Intercepts “sun.misc.Unsafe” calls ● Can track memory allocations and frees ● Can track memory accesses (reads/writes) ● Can align memory accesses (reads/writes) ● Can track custom memory allocations/frees ○ Ex. your custom memory manager implementation ● Can track memory allocation paths ○ Find the origins of leaked (non-free) memories
  • 4. MOTIVATION ● Debugging memory allocations and frees ○ Checking native memory leaks over “Unsafe” ○ Detecting causes of native memory leaks ● Debugging memory accesses (reads/writes) ○ Finding the causes of illegal memory accesses ● Handle unaligned memory accesses (causes SIGBUS) ○ SPARC ○ ...
  • 5. STATE OF ART ● Inspect application classes while loading ○ At “ClassFileTransformer” level ○ At “Classloader” level ● Redirect “Unsafe” calls to MySafe ● MySafe handles the call ● Proceeds to “Unsafe”
  • 6. WHY NOT JUST INST. UNSAFE? ● Use “java.lang.Instrument#setNativeMethodPrefix” ● Add new wrapper methods for native methods ● Requires new method addition ● So class redefinition is not an option ● Hook into “Unsafe” classloading process ● “Unsafe” is already loaded before ○ Java agent ○ User classloader ● Use native JVMTI agent at startup (on the roadmap)
  • 7. HOW TO USE? ● Java Agent Based Usage by VM Argument ○ -javaagent:<path_to_jillegal_agent><jillegal_agent_jar>= "-p tr.com.serkanozal.mysafe.impl.processor.MySafeProcessor". ● Java Agent Based Usage Programmatically ○ MySafe.youAreMine(); ● ClassLoader Based Usage by VM Argument ○ -Djava.system.class.loader= tr.com.serkanozal.mysafe.impl.classloader.MySafeClassLoader
  • 8. FEATURES & DEMO ● Memory Explorer API & Demo ● Memory Listener API & Demo ● Illegal Memory Access Listener API & Demo ● Custom Memory Management & Demo ● Tracing Allocation Path & Demo
  • 9. Memory Explorer API ● Iterate on allocated memories ● Dump allocated memories ● MemoryExplorerDemo.java
  • 10. Memory Listener API ● Be notified before/after allocate ● Be notified before/after reallocate ● Be notified before/after free ● MemoryListenerDemo.java
  • 11. Illegal Mem. Acc. Listener API ● Be notified on illegal memory accesses (reads/writes) ● Be notified on un-allocated memory reallocations/frees ● Throws “IllegalArgumentException” ● IllegalMemoryAccessListenerDemo.java
  • 12. Custom Memory Management ● Tracks custom memory mng. points instead of “Unsafe” ● Memory management points refers to methods which ○ allocate ○ reallocate ○ free ● Custom memory mng. points can be configured by: ○ @AllocationPoint ○ @FreePoint ○ @ReallocationPoint ● CustomMemoryManagementDemo.java
  • 13. Tracing Allocation Path ● Alloc. path = stack trace of caller which allocates memory ● Dump active allocation paths ● Generate diagram of active allocation paths ● Alloc. paths are provided via “AllocPathManager” API ○ Instrumentation based (currently in use) ■ Pros: Very fast, low CPU and GC overhead ■ Cons: Not detailed, might be trashed ○ Java 9’s StackWalker API based (on the roadmap) ■ Pros: Detailed, no need to be trashed ■ Cons: Not fast as much as Inst. based one ● NativeMemoryLeakHuntingDemo.java
  • 14.
  • 15. Inst. Based Alloc. Path Manager ● Identify each method which exist in the any alloc. path ● Inject code into methods to provide them as alloc. path ○ Push method identifier to thread-local call stack ○ Proceed actual call ○ Pop method identifier from thread-local call stack ● Generate alloc. path id from alloc. point (method) ids ○ Each alloc. point id is 2 bytes short number ○ Whole alloc. path is represented with 8 bytes long number ○ There can be at most 4 alloc. points, old ones are evicted
  • 19. foo1 [1] bar1 [2] foo2 [3] bar2 [4] 1 2 3 4
  • 20. foo1 [1] bar1 [2] foo2 [3] bar2 [4] foo3 [5] 2 3 4 5
  • 21. foo1 [1] bar1 [2] foo2 [3] bar2 [4] foo3 [5] bar3 [6] 3 4 5 6
  • 22. foo1 [1] bar1 [2] foo2 [3] bar2 [4] foo3 [5] bar3 [6] malloc 3 4 5 6 foo2 => bar2 => foo3 => bar3
  • 23. ROADMAP ● Ability to track line numbers also ● More detailed and accurate allocation path detection ● Ability to inspect “Unsafe” directly ● Java 9 support ● Allocation path detection via Java 9’s StackWalker API ● Flame graph support