Machine Learning for Automated Vulnerability Detection in Source Code
Bug name: Junfan Huang
Context
Context
Introduction
Dataset
Code Representation
Machine Learning methods
Results
Dataset
Code Representation
Machine Learning methods
Results
Dataset
Code Representation
Machine Learning methods
Results
Dataset
Code Representation
ILP
Results
Dataset
Code Representation
Neural Network
Results
Dataset
Code Representation
Machine Learning methods
Results
Dataset
Juliet dataset[1]
118 different bugs
C/C++
65,000 samples
Dataset
Juliet dataset
Buffer overflow
C/C++
20,000 samples
Dataset
Buffer overflow
Good example
Dataset
Buffer overflows
Good examples
ID:1
ID:2
…
ID:n
Codes
Codes
Code representation
Codes
Code representation
Codes
Code representation
Representation
the way that someone or something is shown or described
Codes
Code representation
the way that code is shown or described
Codes
Code representation
Codes
Code representation
Codes
Code representation
Codes
Code representation
Codes
Code representation
Code representation
Code representation
Abstract Syntax Tree
(AST)
Code representation
Abstract Syntax Tree
(AST)
2+(0-1*9)
Code representation
Abstract Syntax Tree
(AST)
2+(0-1*9)
+
Code representation
Abstract Syntax Tree
(AST)
2
+
2+(0-1*9)
Code representation
Abstract Syntax Tree
(AST)
0-1*9
-
0
Code representation
Abstract Syntax Tree
(AST)
1*9
*
1
9
Code representation
Abstract Syntax Tree
(AST)
0-1*9
-
0
Code representation
Abstract Syntax Tree
(AST)
0-1*9
-
0
*
9
9
*
1
9
Code representation
Abstract Syntax Tree
(AST)
2+(0-1*9)
2
+
Code representation
Abstract Syntax Tree
(AST)
2+(0-1*9)
2
+
-
0
*
9
9
*
1
9
Code representation
Abstract Syntax Tree
(AST)
Code representation
Abstract Syntax Tree
(AST)
Code representation
Abstract Syntax Tree(AST)
Code Property Graph(CPG)
Codes
AST
Codes
AST
About AST
Clang
Bad example
Good example
Two ways
?
Vectorisation
AST
Vector
….
128 dimensions
Graph2vec
Vectors
….
….
….
….
About AST
AST
Adjacency matrix
Bad example
Good example
Bad example
Good example
Bad example
Buffer overflow
To find vulnerability and explain it,
more information might be helpful
AST
Control Flow Graph
(CFG)
Program Dependence Graph
(PDG)
AST
CFG
PDG
AST
CFG
PDG
CFG
PDG
Code property graph
AST
CFG
PDG
Codes
Code property graph[2]
Idea
Find a subgraph that indicates the vulnerability
# AST
ast(node1, node2).
ast(node2, node3).
...
# CFG
cfg(node1, node4).
cfg(node4, node8).
...
# PDG
pdg(node3, node2).
...
AST
CFG
PDG
Joern
Implementation
# AST
ast(node1, node2).
ast(node2, node3).
...
# CFG
cfg(node1, node4).
cfg(node4, node8).
...
# REF
ref(node3, node2).
...
AST
CFG
REF
Implementation
# AST
ast(node1, node2).
ast(node2, node3).
...
# CFG
cfg(node1, node4).
cfg(node4, node8).
...
# REF
ref(node3, node2).
...
# Rule
bug(nodeA, nodeB):-
rule(node1, node4).
rule(node4, node8).
...
Implementation
# AST
ast(node1, node2).
ast(node2, node3).
...
# CFG
cfg(node1, node4).
cfg(node4, node8).
...
# REF
ref(node3, node2).
...
# Rule
bug(A,B) :- ancestor(A,C), ancestor(B,D), assignment(A), writeToPointer(B), alloc_doesnt_check_sizeOf(C), sizeOfInt(D).
Implementation
# Rule
bug(A,B) :- ancestor(A,C), ancestor(B,D), assignment(A), writeToPointer(B), alloc_doesnt_check_sizeOf(C), sizeOfInt(D).
Reference
Thank you