SlideShare a Scribd company logo
1 of 41
Download to read offline
Static Analysis for
beginners
How you can find dragons
whoamy
●
Just another Programmer
●
Security Engineer
●
Ten years experience
●
About me: Github.com/CoolerVoid
Twitter: @Cooler_freenode
Contact: coolerlair@gmail.com
Etymology
Etymology
●
theguardian.com/technology/2011/oct/13/dennis-ritchie
●
economist.com/obituary/2011/11/05/dennis-ritchie-and-john-
mccarthy
Linux/Git creation
●
Version control
●
Manual Codereview
●
New tools for static analysis in Kernel or drivers to
make auto patch etc...
The root of study
The root of study
●
The Dragon Book
●
Flex
●
Bison
●
AST
●
Trees
●
Tokenizer
Security focus
●
Find Pitfalls
●
Fix each point
●
Mitigate
●
Sometimes its hard…
●
Education ???
Security focus
●
Find Pitfalls
●
Fix each point
●
Mitigate
●
Sometimes its hard…
●
Education ???
Security focus
●
Find Pitfalls
●
Fix each point
●
Mitigate
●
Sometimes its hard…
●
Education ???
Security focus
●
Mitre
●
OWASP
●
Other resources…
●
Owasp.org
●
cve.mitre.org
File system Pitfalls
●
File system problems
●
Call Open() but not call close()
●
Load config file, but don’t have lock…
●
Don’t check permissions to open file
●
Don’t check existence of file
●
Race condition (TOCTOU)
●
Mistake in permissions
Pitfall example 1
●
File system problems
●
Call Open() but not call close()
●
Load config file, but don’t have lock…
●
Don’t check permissions to open file
●
Don’t check existence of file
●
Race condition (TOCTOU)
●
Mistake in permissions
Pitfall example 1
●
This code example is noncompliant because the file opened by the
call to fopen() is not closed before function func() returns:
Pitfall example 1
●
This code example is right way, because open and close file:
Detection
●
Do you remember the dragon book ?
●
You can use DFA(Deterministic Finite Automaton) to solve this with
rank points.
●
You can tokenize each word and save in nodes, you can load data
structure and walk to collect each rule, the data structure you can
use Tree, AST, graph(this is common but more complex).
●
You can use Flex+Bison to generate input extractor and parser…
●
You can use regex(regular expression), but don’t have a good
performance! Its not better path!
●
Relax here! have other paths to following…
Detection
●
Do you remember the dragon book ?
●
You can use DFA(Deterministic Finite Automaton) to solve
this with rank points.
●
You can tokenize each word ans save in nodes, you can load data
structure and walk to collect each rule, the data structure you can
use Tree, AST, graph(this is common but more complex).
●
You can use Flex+Bison to generate input extractor and parse
rules…
●
You can use regex(regular expression), but don’t have a good
performance! Its not better path!
●
Relax here! have other paths to following…
Detection Ex 1
●
Its OK my choice is use Re2c to solve the problem!
●
Re2c is a free and open-source lexer generator for C, C++ and Go. It
compiles regular expressions to determinisitic finite automata
and encodes the automata in the form of a program in the target
language.
●
The main advantages of re2c are speed of the generated code
and a flexible user interface that allows one to adapt the generated
lexer to a particular environment and input model.
●
Re2c supports fast and lightweight submatch extraction with either
POSIX or leftmost greedy semantics.
Detection Ex 1
●
github.com/CoolerVoid/heap_detective/tree/master/doc/PoC1
●
doc/PoC1/rule.c
●
Rule to generate
●
Need Re2c tool
●
Need GCC
Detection Ex 1
●
github.com/CoolerVoid/heap_detective/tree/master/doc/PoC1
●
doc/PoC1/gen_re2.c
●
Rule to generate
●
Need Re2c tool
●
Need GCC
Detection Ex 1
●
github.com/CoolerVoid/heap_detective/tree/master/doc/PoC1
Detection Ex 1
●
github.com/CoolerVoid/heap_detective/tree/master/doc/PoC1/extest.c
Detection Ex 1
●
github.com/CoolerVoid/heap_detective/tree/master/doc/PoC1/test.sh
●
Note need re2c and gcc! (apt-get install re2c gcc)
Detection Ex 1
The logic its simple !
Detection Ex 1
●
github.com/CoolerVoid/heap_detective/tree/master/doc/PoC1/test.sh
●
Note need re2c and gcc! (apt-get install re2c gcc)
Detection
●
Do you remember the dragon book ?
●
You can use DFA(Deterministic Finite Automaton) to solve this with
rank points.
●
You can tokenize each word ans save in nodes, you can load data
structure and walk to collect each rule, the data structure you can
use Tree, AST, graph(this is common but more complex).
●
You can use Flex+Bison to generate input extractor and parse
rules…
●
You can use regex(regular expression), but don’t have a good
performance! Its not better path!
●
Relax here! have other paths to following…
●
Do you remember the dragon book ?
●
You can use DFA(Deterministic Finite Automaton) to solve this with
rank points.
●
You can tokenize each word ans save in nodes, you can load
data structure and walk to collect each rule, the data
structure you can use Tree, AST, graph(this is common but
more complex).
●
You can use Flex+Bison to generate input extractor and parse rules…
●
You can use regex(regular expression), but don’t have a good
performance! Its not better path!
●
Relax here! have other paths to following…
Detection
Heap detective
●
All languages uses heap memory
●
In C its commom when you use functions like malloc(), calloc(),
realloc(), strdup() etc…
●
In C++ its common when you use “new”.
●
Heap use can have a lot pitfalls if you not follow good practices.
●
Memory leak, double free, use after free, wild pointer, heap overflow,
crash(DoS) other pitfalls…
●
Some languages like Java have garbage collector to clean the heap
memory to manage this, but if programmer don’t know good
practices the problem with memory leak or crash can be found.
Heap detective
●
How you can map heap memory use ?
Heap detective
●
How you can map heap memory usage in static analysis ?
●
Use my Tool heap detective
●
https://github.com/CoolerVoid/heap_detective
Heap detective
●
How you can map heap memory use ?
●
List the functions that use heap memory
●
List functions to liberate heap
Overview
Heap detective
●
Heap detective
●
Heap detective
Heap detective
Cool stuff
●
My Tree library in C
●
Ice n-ary tree based on glib tree functions
●
https://github.com/CoolerVoid/icenarytree
Other projects
●
Code walk, code search, regex with rule based…
●
github.com/CoolerVoid/codewarrior
●
github.com/CoolerVoid/codecat
●
https://semgrep.dev (very cool)
Questions ?
Thank you!
Credits: CoolerVoid
Contact: coolerlair@gmail.com

More Related Content

What's hot

RIPS - static code analyzer for vulnerabilities in PHP
RIPS - static code analyzer for vulnerabilities in PHPRIPS - static code analyzer for vulnerabilities in PHP
RIPS - static code analyzer for vulnerabilities in PHP
Sorina Chirilă
 
TakeDownCon Rocket City: WebShells by Adrian Crenshaw
TakeDownCon Rocket City: WebShells by Adrian CrenshawTakeDownCon Rocket City: WebShells by Adrian Crenshaw
TakeDownCon Rocket City: WebShells by Adrian Crenshaw
EC-Council
 
Automated JavaScript Deobfuscation - PacSec 2007
Automated JavaScript Deobfuscation - PacSec 2007Automated JavaScript Deobfuscation - PacSec 2007
Automated JavaScript Deobfuscation - PacSec 2007
Stephan Chenette
 

What's hot (20)

Механизмы предотвращения атак в ASP.NET Core
Механизмы предотвращения атак в ASP.NET CoreМеханизмы предотвращения атак в ASP.NET Core
Механизмы предотвращения атак в ASP.NET Core
 
RIPS - static code analyzer for vulnerabilities in PHP
RIPS - static code analyzer for vulnerabilities in PHPRIPS - static code analyzer for vulnerabilities in PHP
RIPS - static code analyzer for vulnerabilities in PHP
 
Anatomy of PHP Shells
Anatomy of PHP ShellsAnatomy of PHP Shells
Anatomy of PHP Shells
 
Firmware Extraction & Fuzzing - Jatan Raval
Firmware Extraction & Fuzzing - Jatan RavalFirmware Extraction & Fuzzing - Jatan Raval
Firmware Extraction & Fuzzing - Jatan Raval
 
Pentester++
Pentester++Pentester++
Pentester++
 
Low latency Logging (BrightonPHP - 18th Nov 2013)
Low latency Logging (BrightonPHP - 18th Nov 2013)Low latency Logging (BrightonPHP - 18th Nov 2013)
Low latency Logging (BrightonPHP - 18th Nov 2013)
 
Hacking - Breaking Into It
Hacking - Breaking Into ItHacking - Breaking Into It
Hacking - Breaking Into It
 
Frida Android run time hooking - Bhargav Gajera & Vitthal Shinde
Frida  Android run time hooking - Bhargav Gajera & Vitthal ShindeFrida  Android run time hooking - Bhargav Gajera & Vitthal Shinde
Frida Android run time hooking - Bhargav Gajera & Vitthal Shinde
 
JS Fest 2019. Ryan Dahl. Deno, a new way to JavaScript
JS Fest 2019. Ryan Dahl. Deno, a new way to JavaScriptJS Fest 2019. Ryan Dahl. Deno, a new way to JavaScript
JS Fest 2019. Ryan Dahl. Deno, a new way to JavaScript
 
TakeDownCon Rocket City: WebShells by Adrian Crenshaw
TakeDownCon Rocket City: WebShells by Adrian CrenshawTakeDownCon Rocket City: WebShells by Adrian Crenshaw
TakeDownCon Rocket City: WebShells by Adrian Crenshaw
 
Who’s afraid of WinDbg
Who’s afraid of WinDbgWho’s afraid of WinDbg
Who’s afraid of WinDbg
 
Higher Level Malware
Higher Level MalwareHigher Level Malware
Higher Level Malware
 
Introduction to Binary Exploitation
Introduction to Binary Exploitation	Introduction to Binary Exploitation
Introduction to Binary Exploitation
 
Debugging tricks you wish you knew - Tamir Dresher
Debugging tricks you wish you knew  - Tamir DresherDebugging tricks you wish you knew  - Tamir Dresher
Debugging tricks you wish you knew - Tamir Dresher
 
Porting your favourite cmdline tool to Android
Porting your favourite cmdline tool to AndroidPorting your favourite cmdline tool to Android
Porting your favourite cmdline tool to Android
 
The Art of AV Evasion - Or Lack Thereof
The Art of AV Evasion - Or Lack ThereofThe Art of AV Evasion - Or Lack Thereof
The Art of AV Evasion - Or Lack Thereof
 
Wonderful world of (distributed) SCM or VCS
Wonderful world of (distributed) SCM or VCSWonderful world of (distributed) SCM or VCS
Wonderful world of (distributed) SCM or VCS
 
Bringing Down the House - How One Python Script Ruled Over AntiVirus
Bringing Down the House - How One Python Script Ruled Over AntiVirusBringing Down the House - How One Python Script Ruled Over AntiVirus
Bringing Down the House - How One Python Script Ruled Over AntiVirus
 
Ripping web accessible .git files
Ripping web accessible .git filesRipping web accessible .git files
Ripping web accessible .git files
 
Automated JavaScript Deobfuscation - PacSec 2007
Automated JavaScript Deobfuscation - PacSec 2007Automated JavaScript Deobfuscation - PacSec 2007
Automated JavaScript Deobfuscation - PacSec 2007
 

Similar to Static analysis for beginners

OS X Drivers Reverse Engineering
OS X Drivers Reverse EngineeringOS X Drivers Reverse Engineering
OS X Drivers Reverse Engineering
Positive Hack Days
 

Similar to Static analysis for beginners (20)

Ruxmon.2013-08.-.CodeBro!
Ruxmon.2013-08.-.CodeBro!Ruxmon.2013-08.-.CodeBro!
Ruxmon.2013-08.-.CodeBro!
 
HelsinkiJS - Clojurescript for Javascript Developers
HelsinkiJS - Clojurescript for Javascript DevelopersHelsinkiJS - Clojurescript for Javascript Developers
HelsinkiJS - Clojurescript for Javascript Developers
 
Dart the Better JavaScript
Dart the Better JavaScriptDart the Better JavaScript
Dart the Better JavaScript
 
Number of Computer Languages = 3
Number of Computer Languages = 3Number of Computer Languages = 3
Number of Computer Languages = 3
 
The Good, the Bad and the Ugly things to do with android
The Good, the Bad and the Ugly things to do with androidThe Good, the Bad and the Ugly things to do with android
The Good, the Bad and the Ugly things to do with android
 
Stripe CTF3 wrap-up
Stripe CTF3 wrap-upStripe CTF3 wrap-up
Stripe CTF3 wrap-up
 
Tips and Tricks for Increased Development Efficiency
Tips and Tricks for Increased Development EfficiencyTips and Tricks for Increased Development Efficiency
Tips and Tricks for Increased Development Efficiency
 
Why go ?
Why go ?Why go ?
Why go ?
 
Cloud accounting software uk
Cloud accounting software ukCloud accounting software uk
Cloud accounting software uk
 
Not Your Fathers C - C Application Development In 2016
Not Your Fathers C - C Application Development In 2016Not Your Fathers C - C Application Development In 2016
Not Your Fathers C - C Application Development In 2016
 
Docker and Go: why did we decide to write Docker in Go?
Docker and Go: why did we decide to write Docker in Go?Docker and Go: why did we decide to write Docker in Go?
Docker and Go: why did we decide to write Docker in Go?
 
Bsdtw17: george neville neil: realities of dtrace on free-bsd
Bsdtw17: george neville neil: realities of dtrace on free-bsdBsdtw17: george neville neil: realities of dtrace on free-bsd
Bsdtw17: george neville neil: realities of dtrace on free-bsd
 
NANO266 - Lecture 9 - Tools of the Modeling Trade
NANO266 - Lecture 9 - Tools of the Modeling TradeNANO266 - Lecture 9 - Tools of the Modeling Trade
NANO266 - Lecture 9 - Tools of the Modeling Trade
 
Performance optimization techniques for Java code
Performance optimization techniques for Java codePerformance optimization techniques for Java code
Performance optimization techniques for Java code
 
Dart the better Javascript 2015
Dart the better Javascript 2015Dart the better Javascript 2015
Dart the better Javascript 2015
 
Ruby, the language of devops
Ruby, the language of devopsRuby, the language of devops
Ruby, the language of devops
 
Power Leveling your TypeScript
Power Leveling your TypeScriptPower Leveling your TypeScript
Power Leveling your TypeScript
 
Why Functional Programming and Clojure - LightningTalk
Why Functional Programming and Clojure - LightningTalkWhy Functional Programming and Clojure - LightningTalk
Why Functional Programming and Clojure - LightningTalk
 
OS X Drivers Reverse Engineering
OS X Drivers Reverse EngineeringOS X Drivers Reverse Engineering
OS X Drivers Reverse Engineering
 
Practical SystemTAP basics: Perl memory profiling
Practical SystemTAP basics: Perl memory profilingPractical SystemTAP basics: Perl memory profiling
Practical SystemTAP basics: Perl memory profiling
 

More from Antonio Costa aka Cooler_ (10)

Strange security mitigations
Strange security mitigationsStrange security mitigations
Strange security mitigations
 
Improving spam detection with automaton
Improving spam detection with automatonImproving spam detection with automaton
Improving spam detection with automaton
 
Burlando Waf 2.0
Burlando Waf  2.0Burlando Waf  2.0
Burlando Waf 2.0
 
burlando um WAF
burlando um WAFburlando um WAF
burlando um WAF
 
Development pitfalls
Development pitfallsDevelopment pitfalls
Development pitfalls
 
0d1n bsides2
0d1n bsides20d1n bsides2
0d1n bsides2
 
Vivendo de hacking
Vivendo de hackingVivendo de hacking
Vivendo de hacking
 
Bsides odin
Bsides odinBsides odin
Bsides odin
 
Bsides4cooler
Bsides4coolerBsides4cooler
Bsides4cooler
 
detector de ladrão com laser
detector de ladrão com laserdetector de ladrão com laser
detector de ladrão com laser
 

Recently uploaded

JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)
Max Lee
 
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
mbmh111980
 
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
Alluxio, Inc.
 

Recently uploaded (20)

JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)JustNaik Solution Deck (stage bus sector)
JustNaik Solution Deck (stage bus sector)
 
AI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning FrameworkAI/ML Infra Meetup | Perspective on Deep Learning Framework
AI/ML Infra Meetup | Perspective on Deep Learning Framework
 
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
COMPUTER AND ITS COMPONENTS PPT.by naitik sharma Class 9th A mittal internati...
 
10 Essential Software Testing Tools You Need to Know About.pdf
10 Essential Software Testing Tools You Need to Know About.pdf10 Essential Software Testing Tools You Need to Know About.pdf
10 Essential Software Testing Tools You Need to Know About.pdf
 
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
Tree in the Forest - Managing Details in BDD Scenarios (live2test 2024)
 
how-to-download-files-safely-from-the-internet.pdf
how-to-download-files-safely-from-the-internet.pdfhow-to-download-files-safely-from-the-internet.pdf
how-to-download-files-safely-from-the-internet.pdf
 
Naer Toolbar Redesign - Usability Research Synthesis
Naer Toolbar Redesign - Usability Research SynthesisNaer Toolbar Redesign - Usability Research Synthesis
Naer Toolbar Redesign - Usability Research Synthesis
 
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product UpdatesGraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
GraphSummit Stockholm - Neo4j - Knowledge Graphs and Product Updates
 
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdf
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdfImplementing KPIs and Right Metrics for Agile Delivery Teams.pdf
Implementing KPIs and Right Metrics for Agile Delivery Teams.pdf
 
Malaysia E-Invoice digital signature docpptx
Malaysia E-Invoice digital signature docpptxMalaysia E-Invoice digital signature docpptx
Malaysia E-Invoice digital signature docpptx
 
AI Hackathon.pptx
AI                        Hackathon.pptxAI                        Hackathon.pptx
AI Hackathon.pptx
 
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdfMastering Windows 7 A Comprehensive Guide for Power Users .pdf
Mastering Windows 7 A Comprehensive Guide for Power Users .pdf
 
SQL Injection Introduction and Prevention
SQL Injection Introduction and PreventionSQL Injection Introduction and Prevention
SQL Injection Introduction and Prevention
 
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
A Python-based approach to data loading in TM1 - Using Airflow as an ETL for TM1
 
A Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data MigrationA Guideline to Zendesk to Re:amaze Data Migration
A Guideline to Zendesk to Re:amaze Data Migration
 
Automate your OpenSIPS config tests - OpenSIPS Summit 2024
Automate your OpenSIPS config tests - OpenSIPS Summit 2024Automate your OpenSIPS config tests - OpenSIPS Summit 2024
Automate your OpenSIPS config tests - OpenSIPS Summit 2024
 
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
Facemoji Keyboard released its 2023 State of Emoji report, outlining the most...
 
Microsoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdfMicrosoft365_Dev_Security_2024_05_16.pdf
Microsoft365_Dev_Security_2024_05_16.pdf
 
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
AI/ML Infra Meetup | Improve Speed and GPU Utilization for Model Training & S...
 
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAGAI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
AI/ML Infra Meetup | Reducing Prefill for LLM Serving in RAG
 

Static analysis for beginners