SlideShare a Scribd company logo
1 of 25
Download to read offline
CodeQL
Mostafa Sattari
2
Agenda
●
Introduction
●
Installation
●
Writing Queries
●
Example
3
Intro
void fire_thrusters(double
vectors[12]) {
for (int i = 0; i < 12 i++) {
... vectors[i] ...
}
}
double thruster[3] = ... ;
fire_thrusters(thruster);
●
In C, array types of parameters degrade to pointer types.
●
The size is ignored!
●
No protection from passing a mismatched array.
4
Intro
●
…to find all instances of the problem.
import cpp
from Function f, FunctionCall c, int i, int a, int b
where f = c.getTarget()
and a = c.getArgument(i).getType().(ArrayType).getArraySize()
and b = f.getParameter(i).getType().(ArrayType).getArraySize()
and a < b
select c.getArgument(i), "Array of size " + a
+ " passed to $@, which expects an array of size " + b +
".",
f, f.getName()
5
Intro
●
CodeQL Consists of:
– QL: the programming language for CodeQL
code analysis platform.
– CLI: run queries
– Libraries: QL libraries
– Databases: contains all the things needed to
run the queries
●
Used for Variant Analysis
6
Analysis overview
7
Intro - Tools
●
Standalone CodeQL CLI
●
Interactive Query Console (lgtm.com)
●
IDE extensions
– Eclipse
– VSCode
8
Intro - CLI
9
Intro – Interactive Query Console
10
Intro – VSCode Extension
11
●
What you need to run queries
– CodeQL CLI tool
– Query libraries
– A database
●
Installing VSCode and CodeQL extension
– Alternatively Eclipse + CodeQL extension
– Add CodeQL cli to your env
●
~/.config/Code/User/globalStorage/github.vscode-codeql/distribution1/codeql/codeql
●
It might vary on your machine
Installation
12
●
Install CodeQL CLI
or
●
Install VSCode and CodeQL extension
– Alternatively Eclipse + CodeQL extension
– Add CodeQL cli to your env
– ~/.config/Code/User/globalStorage/github.vscode-codeql/distribution1/codeql/codeql
●
It might vary on your machine
Installation
13
Installation
●
Running codeql database create
●
Importing a database from lgtm.com
$ codeql database create <database> --language=<language-
identifier>
--language: cpp/csharp/go/java/python/javascript
--source-root: the root folder for the primary source files
(default = current directory).
--command: for compiled languages only, the build commands
that invoke the compiler.
14
Writing QL Queries
●
QL
– logic programming language
– built up of logical formulas
– Object oriented
●
Basic syntax
from /* ... variable declarations ... */
where /* ... logical formulas ... */
select /* ... expressions ... */
// Example:
from int x, int y
where x = 6 and y = 7
select x * y
15
Writing QL Queries
●
Python
import python
from Function f
where count(f.getAnArg()) > 7
select f
●
Java
●
JavaScript
import java
from Parameter p
where not exists(p.getAnAccess())
select p
import javascript
from Comment c
where c.getText().regexpMatch("(?si).*bTODOb.*")
select c
16
Writing QL Queries
●
Formulas
<expression> <operator> <expression> // Comparison
<expression> instanceof <type> // Type check
<expression> in <range> // Range check
exists(<variable declarations> | <formula>)
forex(<variable declarations> | <formula 1> | <formula 2>)
forall(<vars> | <formula 1> | <formula 2>) and
exists(<vars> | <formula 1> | <formula 2>)
Two formulas in the body: It holds if <formula 2> holds for all values that <formula 1> holds for.
●
Aggregates
●
Common aggregates are count, max, min, avg (average) and sum.
from Person t
where t.getAge() = max(int i | exists(Person p | p.getAge() = i) | i)
select t
17
Writing QL Queries
●
Predicates
●
The name of a predicate always starts with a lowercase letter.
●
You can also define predicates with a result. In that case, the keyword predicate is
replaced with the type of the result. This is like introducing a new argument, the special
variable result. For example, int getAge() {result = ...} returns an int.
predicate southern(Person p) {
p.getLocation() = "south"
}
from Person p
where southern(p)
select p
18
Writing QL Queries
●
Classes
– instanceof
●
You might be tempted to think of the characteristic predicate as a constructor. However, this
is not the case - it is a logical property which does not create any objects.
class Southerner extends Person {
Southerner() { southern(this) }
}
from Southerner s
select s
class Child extends Person{
/* the characteristic predicate */
Child() { this.getAge() < 10 }
/* a member predicate */
override predicate isAllowedIn(string region){
region = this.getLocation()
}
}
19
Writing QL Queries
●
Annotations
– abstract, finaal, overrise, private, ...
●
Recursion
– Transitive closures +
– Reflexive transitive closure *
●
Name Resolution
– Qualified references (import examples.security.MyLibrary)
– Selections (<module_expression>::<name>)
20
Variant analysis
●
Control flow analysis (CFA) allows you to inspect how the different parts of the source
code are executed and in which order. Control flow analysis is useful for finding vulnerable
code paths that are only executed under unlikely circumstances.
●
Data flow analysis (DFA) is the process of tracking data from a source, where it enters an
application, to a sink, where the data is used in a potentially harmful way if it's not sanitized
along the way.
●
Taint tracking typically refers to untrusted – or tainted – data that is under partial or full
control of a user. Using data flow analysis, tainted data is tracked from the source through
method calls and variable assignments – including containers and class members – to a sink.
●
Range analysis (or bounds analysis) is used to investigate which possible values a variable
can hold, and which values it will never hold. This is useful information in various lines of
investigation.
●
Semantic code search allows you to quickly interrogate a codebase and identify areas of
interest for further investigation. This is valuable to identify methods having a particular
signature, or variables that may contain credentials.
21
Variant analysis - Modules
●
semmle.code.cpp.dataflow.DataFlow
– IsSource : defines where data may flow from
– IsSink : defines where data may flow to
– HasFlow : performs the analysis
●
semmle.code.cpp.dataflow.TaintTracking
– IsSanitizerGuard : optional, restricts the taint flow
22
Variant analysis
●
Analyzing data flow in C/C++
import cpp
import semmle.code.cpp.dataflow.TaintTracking
class MyTaintTrackingConfiguration extends TaintTracking::Configuration {
MyTaintTrackingConfiguration() { this = "MyTaintTrackingConfiguration" }
override predicate isSource(DataFlow::Node source) {
...
}
override predicate isSink(DataFlow::Node sink) {
...
}
}
23
Variant analysis - Example
import semmle.code.cpp.dataflow.DataFlow
class EnvironmentToFileConfiguration extends DataFlow::Configuration {
EnvironmentToFileConfiguration() { this =
"EnvironmentToFileConfiguration" }
override predicate isSource(DataFlow::Node source) {
exists (Function getenv |
source.asExpr().(FunctionCall).getTarget() = getenv and
getenv.hasQualifiedName("getenv")
)
}
override predicate isSink(DataFlow::Node sink) {
exists (FunctionCall fc |
sink.asExpr() = fc.getArgument(0) and
fc.getTarget().hasQualifiedName("fopen")
)
}
}
from Expr getenv, Expr fopen, EnvironmentToFileConfiguration config
where config.hasFlow(DataFlow::exprNode(getenv),
DataFlow::exprNode(fopen))
select fopen, "This 'fopen' uses data from $@.",
getenv, "call to 'getenv'"
24
●
Almost all materials are burrowed from Semmle.com
– https://help.semmle.com/QL/learn-ql/index.html
– https://help.semmle.com/QL/ql-training/cpp/intro-ql-cpp.html
– https://marketplace.visualstudio.com/items?itemName=github.vscode-codeql
●
Get help
– https://discuss.lgtm.com/latest
– https://stackoverflow.com/questions/tagged/semmle-ql
Recaps
25
Thank you

More Related Content

What's hot

Comparing Native Java REST API Frameworks - Seattle JUG 2022
Comparing Native Java REST API Frameworks - Seattle JUG 2022Comparing Native Java REST API Frameworks - Seattle JUG 2022
Comparing Native Java REST API Frameworks - Seattle JUG 2022Matt Raible
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introductionRasheed Waraich
 
Deep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UKDeep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UKJosé Paumard
 
Lightweight static code analysis with semgrep
Lightweight static code analysis with semgrepLightweight static code analysis with semgrep
Lightweight static code analysis with semgrepNull Bhubaneswar
 
TypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painTypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painSander Mak (@Sander_Mak)
 
Mock Server Using WireMock
Mock Server Using WireMockMock Server Using WireMock
Mock Server Using WireMockGlobant
 
SwiftUI and Combine All the Things
SwiftUI and Combine All the ThingsSwiftUI and Combine All the Things
SwiftUI and Combine All the ThingsScott Gardner
 
Security DevOps - Staying secure in agile projects // OWASP AppSecEU 2015 - A...
Security DevOps - Staying secure in agile projects // OWASP AppSecEU 2015 - A...Security DevOps - Staying secure in agile projects // OWASP AppSecEU 2015 - A...
Security DevOps - Staying secure in agile projects // OWASP AppSecEU 2015 - A...Christian Schneider
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot IntroductionJeevesh Pandey
 
Container Runtime Security with Falco
Container Runtime Security with FalcoContainer Runtime Security with Falco
Container Runtime Security with FalcoMichael Ducy
 
Defending against Java Deserialization Vulnerabilities
 Defending against Java Deserialization Vulnerabilities Defending against Java Deserialization Vulnerabilities
Defending against Java Deserialization VulnerabilitiesLuca Carettoni
 
An Introduction of Node Package Manager (NPM)
An Introduction of Node Package Manager (NPM)An Introduction of Node Package Manager (NPM)
An Introduction of Node Package Manager (NPM)iFour Technolab Pvt. Ltd.
 

What's hot (20)

Comparing Native Java REST API Frameworks - Seattle JUG 2022
Comparing Native Java REST API Frameworks - Seattle JUG 2022Comparing Native Java REST API Frameworks - Seattle JUG 2022
Comparing Native Java REST API Frameworks - Seattle JUG 2022
 
Spring boot introduction
Spring boot introductionSpring boot introduction
Spring boot introduction
 
Maven ppt
Maven pptMaven ppt
Maven ppt
 
Java basic
Java basicJava basic
Java basic
 
Deep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UKDeep Dive Java 17 Devoxx UK
Deep Dive Java 17 Devoxx UK
 
Lightweight static code analysis with semgrep
Lightweight static code analysis with semgrepLightweight static code analysis with semgrep
Lightweight static code analysis with semgrep
 
TypeScript Presentation
TypeScript PresentationTypeScript Presentation
TypeScript Presentation
 
TypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painTypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the pain
 
Mock Server Using WireMock
Mock Server Using WireMockMock Server Using WireMock
Mock Server Using WireMock
 
SwiftUI and Combine All the Things
SwiftUI and Combine All the ThingsSwiftUI and Combine All the Things
SwiftUI and Combine All the Things
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Security DevOps - Staying secure in agile projects // OWASP AppSecEU 2015 - A...
Security DevOps - Staying secure in agile projects // OWASP AppSecEU 2015 - A...Security DevOps - Staying secure in agile projects // OWASP AppSecEU 2015 - A...
Security DevOps - Staying secure in agile projects // OWASP AppSecEU 2015 - A...
 
Spring boot Introduction
Spring boot IntroductionSpring boot Introduction
Spring boot Introduction
 
Container Runtime Security with Falco
Container Runtime Security with FalcoContainer Runtime Security with Falco
Container Runtime Security with Falco
 
Defending against Java Deserialization Vulnerabilities
 Defending against Java Deserialization Vulnerabilities Defending against Java Deserialization Vulnerabilities
Defending against Java Deserialization Vulnerabilities
 
Spring Boot
Spring BootSpring Boot
Spring Boot
 
Java 17
Java 17Java 17
Java 17
 
Maven Introduction
Maven IntroductionMaven Introduction
Maven Introduction
 
An Introduction of Node Package Manager (NPM)
An Introduction of Node Package Manager (NPM)An Introduction of Node Package Manager (NPM)
An Introduction of Node Package Manager (NPM)
 
SSRF workshop
SSRF workshop SSRF workshop
SSRF workshop
 

Similar to Semmle Codeql

TransmogrifAI - Automate Machine Learning Workflow with the power of Scala an...
TransmogrifAI - Automate Machine Learning Workflow with the power of Scala an...TransmogrifAI - Automate Machine Learning Workflow with the power of Scala an...
TransmogrifAI - Automate Machine Learning Workflow with the power of Scala an...Chetan Khatri
 
Apache Flink Training Workshop @ HadoopCon2016 - #2 DataSet API Hands-On
Apache Flink Training Workshop @ HadoopCon2016 - #2 DataSet API Hands-OnApache Flink Training Workshop @ HadoopCon2016 - #2 DataSet API Hands-On
Apache Flink Training Workshop @ HadoopCon2016 - #2 DataSet API Hands-OnApache Flink Taiwan User Group
 
An Execution-Semantic and Content-and-Context-Based Code-Clone Detection and ...
An Execution-Semantic and Content-and-Context-Based Code-Clone Detection and ...An Execution-Semantic and Content-and-Context-Based Code-Clone Detection and ...
An Execution-Semantic and Content-and-Context-Based Code-Clone Detection and ...Kamiya Toshihiro
 
4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)
4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)
4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)PROIDEA
 
Whats New In C# 4 0 - NetPonto
Whats New In C# 4 0 - NetPontoWhats New In C# 4 0 - NetPonto
Whats New In C# 4 0 - NetPontoPaulo Morgado
 
Visula C# Programming Lecture 6
Visula C# Programming Lecture 6Visula C# Programming Lecture 6
Visula C# Programming Lecture 6Abou Bakr Ashraf
 
Core Java Programming Language (JSE) : Chapter X - I/O Fundamentals
Core Java Programming Language (JSE) : Chapter X - I/O Fundamentals Core Java Programming Language (JSE) : Chapter X - I/O Fundamentals
Core Java Programming Language (JSE) : Chapter X - I/O Fundamentals WebStackAcademy
 
Scikit-Learn: Machine Learning in Python
Scikit-Learn: Machine Learning in PythonScikit-Learn: Machine Learning in Python
Scikit-Learn: Machine Learning in PythonMicrosoft
 
Applying Compiler Techniques to Iterate At Blazing Speed
Applying Compiler Techniques to Iterate At Blazing SpeedApplying Compiler Techniques to Iterate At Blazing Speed
Applying Compiler Techniques to Iterate At Blazing SpeedPascal-Louis Perez
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and DestructorsKeyur Vadodariya
 
The operation principles of PVS-Studio static code analyzer
The operation principles of PVS-Studio static code analyzerThe operation principles of PVS-Studio static code analyzer
The operation principles of PVS-Studio static code analyzerAndrey Karpov
 
Internship - Final Presentation (26-08-2015)
Internship - Final Presentation (26-08-2015)Internship - Final Presentation (26-08-2015)
Internship - Final Presentation (26-08-2015)Sean Krail
 
Automate ml workflow_transmogrif_ai-_chetan_khatri_berlin-scala
Automate ml workflow_transmogrif_ai-_chetan_khatri_berlin-scalaAutomate ml workflow_transmogrif_ai-_chetan_khatri_berlin-scala
Automate ml workflow_transmogrif_ai-_chetan_khatri_berlin-scalaChetan Khatri
 
Robust C++ Task Systems Through Compile-time Checks
Robust C++ Task Systems Through Compile-time ChecksRobust C++ Task Systems Through Compile-time Checks
Robust C++ Task Systems Through Compile-time ChecksStoyan Nikolov
 
Sperasoft‬ talks j point 2015
Sperasoft‬ talks j point 2015Sperasoft‬ talks j point 2015
Sperasoft‬ talks j point 2015Sperasoft
 
C++11: Feel the New Language
C++11: Feel the New LanguageC++11: Feel the New Language
C++11: Feel the New Languagemspline
 
(7) c sharp introduction_advanvced_features_part_ii
(7) c sharp introduction_advanvced_features_part_ii(7) c sharp introduction_advanvced_features_part_ii
(7) c sharp introduction_advanvced_features_part_iiNico Ludwig
 

Similar to Semmle Codeql (20)

report
reportreport
report
 
TransmogrifAI - Automate Machine Learning Workflow with the power of Scala an...
TransmogrifAI - Automate Machine Learning Workflow with the power of Scala an...TransmogrifAI - Automate Machine Learning Workflow with the power of Scala an...
TransmogrifAI - Automate Machine Learning Workflow with the power of Scala an...
 
Apache Flink Training Workshop @ HadoopCon2016 - #2 DataSet API Hands-On
Apache Flink Training Workshop @ HadoopCon2016 - #2 DataSet API Hands-OnApache Flink Training Workshop @ HadoopCon2016 - #2 DataSet API Hands-On
Apache Flink Training Workshop @ HadoopCon2016 - #2 DataSet API Hands-On
 
An Execution-Semantic and Content-and-Context-Based Code-Clone Detection and ...
An Execution-Semantic and Content-and-Context-Based Code-Clone Detection and ...An Execution-Semantic and Content-and-Context-Based Code-Clone Detection and ...
An Execution-Semantic and Content-and-Context-Based Code-Clone Detection and ...
 
4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)
4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)
4Developers 2018: Ile (nie) wiesz o strukturach w .NET (Łukasz Pyrzyk)
 
Whats New In C# 4 0 - NetPonto
Whats New In C# 4 0 - NetPontoWhats New In C# 4 0 - NetPonto
Whats New In C# 4 0 - NetPonto
 
Visula C# Programming Lecture 6
Visula C# Programming Lecture 6Visula C# Programming Lecture 6
Visula C# Programming Lecture 6
 
Core Java Programming Language (JSE) : Chapter X - I/O Fundamentals
Core Java Programming Language (JSE) : Chapter X - I/O Fundamentals Core Java Programming Language (JSE) : Chapter X - I/O Fundamentals
Core Java Programming Language (JSE) : Chapter X - I/O Fundamentals
 
Scikit-Learn: Machine Learning in Python
Scikit-Learn: Machine Learning in PythonScikit-Learn: Machine Learning in Python
Scikit-Learn: Machine Learning in Python
 
Applying Compiler Techniques to Iterate At Blazing Speed
Applying Compiler Techniques to Iterate At Blazing SpeedApplying Compiler Techniques to Iterate At Blazing Speed
Applying Compiler Techniques to Iterate At Blazing Speed
 
Constructors and Destructors
Constructors and DestructorsConstructors and Destructors
Constructors and Destructors
 
The operation principles of PVS-Studio static code analyzer
The operation principles of PVS-Studio static code analyzerThe operation principles of PVS-Studio static code analyzer
The operation principles of PVS-Studio static code analyzer
 
Day 1
Day 1Day 1
Day 1
 
Internship - Final Presentation (26-08-2015)
Internship - Final Presentation (26-08-2015)Internship - Final Presentation (26-08-2015)
Internship - Final Presentation (26-08-2015)
 
Automate ml workflow_transmogrif_ai-_chetan_khatri_berlin-scala
Automate ml workflow_transmogrif_ai-_chetan_khatri_berlin-scalaAutomate ml workflow_transmogrif_ai-_chetan_khatri_berlin-scala
Automate ml workflow_transmogrif_ai-_chetan_khatri_berlin-scala
 
Robust C++ Task Systems Through Compile-time Checks
Robust C++ Task Systems Through Compile-time ChecksRobust C++ Task Systems Through Compile-time Checks
Robust C++ Task Systems Through Compile-time Checks
 
Day 2
Day 2Day 2
Day 2
 
Sperasoft‬ talks j point 2015
Sperasoft‬ talks j point 2015Sperasoft‬ talks j point 2015
Sperasoft‬ talks j point 2015
 
C++11: Feel the New Language
C++11: Feel the New LanguageC++11: Feel the New Language
C++11: Feel the New Language
 
(7) c sharp introduction_advanvced_features_part_ii
(7) c sharp introduction_advanvced_features_part_ii(7) c sharp introduction_advanvced_features_part_ii
(7) c sharp introduction_advanvced_features_part_ii
 

Recently uploaded

08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGSujit Pal
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 

Recently uploaded (20)

08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Google AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAGGoogle AI Hackathon: LLM based Evaluator for RAG
Google AI Hackathon: LLM based Evaluator for RAG
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 

Semmle Codeql

  • 3. 3 Intro void fire_thrusters(double vectors[12]) { for (int i = 0; i < 12 i++) { ... vectors[i] ... } } double thruster[3] = ... ; fire_thrusters(thruster); ● In C, array types of parameters degrade to pointer types. ● The size is ignored! ● No protection from passing a mismatched array.
  • 4. 4 Intro ● …to find all instances of the problem. import cpp from Function f, FunctionCall c, int i, int a, int b where f = c.getTarget() and a = c.getArgument(i).getType().(ArrayType).getArraySize() and b = f.getParameter(i).getType().(ArrayType).getArraySize() and a < b select c.getArgument(i), "Array of size " + a + " passed to $@, which expects an array of size " + b + ".", f, f.getName()
  • 5. 5 Intro ● CodeQL Consists of: – QL: the programming language for CodeQL code analysis platform. – CLI: run queries – Libraries: QL libraries – Databases: contains all the things needed to run the queries ● Used for Variant Analysis
  • 7. 7 Intro - Tools ● Standalone CodeQL CLI ● Interactive Query Console (lgtm.com) ● IDE extensions – Eclipse – VSCode
  • 9. 9 Intro – Interactive Query Console
  • 10. 10 Intro – VSCode Extension
  • 11. 11 ● What you need to run queries – CodeQL CLI tool – Query libraries – A database ● Installing VSCode and CodeQL extension – Alternatively Eclipse + CodeQL extension – Add CodeQL cli to your env ● ~/.config/Code/User/globalStorage/github.vscode-codeql/distribution1/codeql/codeql ● It might vary on your machine Installation
  • 12. 12 ● Install CodeQL CLI or ● Install VSCode and CodeQL extension – Alternatively Eclipse + CodeQL extension – Add CodeQL cli to your env – ~/.config/Code/User/globalStorage/github.vscode-codeql/distribution1/codeql/codeql ● It might vary on your machine Installation
  • 13. 13 Installation ● Running codeql database create ● Importing a database from lgtm.com $ codeql database create <database> --language=<language- identifier> --language: cpp/csharp/go/java/python/javascript --source-root: the root folder for the primary source files (default = current directory). --command: for compiled languages only, the build commands that invoke the compiler.
  • 14. 14 Writing QL Queries ● QL – logic programming language – built up of logical formulas – Object oriented ● Basic syntax from /* ... variable declarations ... */ where /* ... logical formulas ... */ select /* ... expressions ... */ // Example: from int x, int y where x = 6 and y = 7 select x * y
  • 15. 15 Writing QL Queries ● Python import python from Function f where count(f.getAnArg()) > 7 select f ● Java ● JavaScript import java from Parameter p where not exists(p.getAnAccess()) select p import javascript from Comment c where c.getText().regexpMatch("(?si).*bTODOb.*") select c
  • 16. 16 Writing QL Queries ● Formulas <expression> <operator> <expression> // Comparison <expression> instanceof <type> // Type check <expression> in <range> // Range check exists(<variable declarations> | <formula>) forex(<variable declarations> | <formula 1> | <formula 2>) forall(<vars> | <formula 1> | <formula 2>) and exists(<vars> | <formula 1> | <formula 2>) Two formulas in the body: It holds if <formula 2> holds for all values that <formula 1> holds for. ● Aggregates ● Common aggregates are count, max, min, avg (average) and sum. from Person t where t.getAge() = max(int i | exists(Person p | p.getAge() = i) | i) select t
  • 17. 17 Writing QL Queries ● Predicates ● The name of a predicate always starts with a lowercase letter. ● You can also define predicates with a result. In that case, the keyword predicate is replaced with the type of the result. This is like introducing a new argument, the special variable result. For example, int getAge() {result = ...} returns an int. predicate southern(Person p) { p.getLocation() = "south" } from Person p where southern(p) select p
  • 18. 18 Writing QL Queries ● Classes – instanceof ● You might be tempted to think of the characteristic predicate as a constructor. However, this is not the case - it is a logical property which does not create any objects. class Southerner extends Person { Southerner() { southern(this) } } from Southerner s select s class Child extends Person{ /* the characteristic predicate */ Child() { this.getAge() < 10 } /* a member predicate */ override predicate isAllowedIn(string region){ region = this.getLocation() } }
  • 19. 19 Writing QL Queries ● Annotations – abstract, finaal, overrise, private, ... ● Recursion – Transitive closures + – Reflexive transitive closure * ● Name Resolution – Qualified references (import examples.security.MyLibrary) – Selections (<module_expression>::<name>)
  • 20. 20 Variant analysis ● Control flow analysis (CFA) allows you to inspect how the different parts of the source code are executed and in which order. Control flow analysis is useful for finding vulnerable code paths that are only executed under unlikely circumstances. ● Data flow analysis (DFA) is the process of tracking data from a source, where it enters an application, to a sink, where the data is used in a potentially harmful way if it's not sanitized along the way. ● Taint tracking typically refers to untrusted – or tainted – data that is under partial or full control of a user. Using data flow analysis, tainted data is tracked from the source through method calls and variable assignments – including containers and class members – to a sink. ● Range analysis (or bounds analysis) is used to investigate which possible values a variable can hold, and which values it will never hold. This is useful information in various lines of investigation. ● Semantic code search allows you to quickly interrogate a codebase and identify areas of interest for further investigation. This is valuable to identify methods having a particular signature, or variables that may contain credentials.
  • 21. 21 Variant analysis - Modules ● semmle.code.cpp.dataflow.DataFlow – IsSource : defines where data may flow from – IsSink : defines where data may flow to – HasFlow : performs the analysis ● semmle.code.cpp.dataflow.TaintTracking – IsSanitizerGuard : optional, restricts the taint flow
  • 22. 22 Variant analysis ● Analyzing data flow in C/C++ import cpp import semmle.code.cpp.dataflow.TaintTracking class MyTaintTrackingConfiguration extends TaintTracking::Configuration { MyTaintTrackingConfiguration() { this = "MyTaintTrackingConfiguration" } override predicate isSource(DataFlow::Node source) { ... } override predicate isSink(DataFlow::Node sink) { ... } }
  • 23. 23 Variant analysis - Example import semmle.code.cpp.dataflow.DataFlow class EnvironmentToFileConfiguration extends DataFlow::Configuration { EnvironmentToFileConfiguration() { this = "EnvironmentToFileConfiguration" } override predicate isSource(DataFlow::Node source) { exists (Function getenv | source.asExpr().(FunctionCall).getTarget() = getenv and getenv.hasQualifiedName("getenv") ) } override predicate isSink(DataFlow::Node sink) { exists (FunctionCall fc | sink.asExpr() = fc.getArgument(0) and fc.getTarget().hasQualifiedName("fopen") ) } } from Expr getenv, Expr fopen, EnvironmentToFileConfiguration config where config.hasFlow(DataFlow::exprNode(getenv), DataFlow::exprNode(fopen)) select fopen, "This 'fopen' uses data from $@.", getenv, "call to 'getenv'"
  • 24. 24 ● Almost all materials are burrowed from Semmle.com – https://help.semmle.com/QL/learn-ql/index.html – https://help.semmle.com/QL/ql-training/cpp/intro-ql-cpp.html – https://marketplace.visualstudio.com/items?itemName=github.vscode-codeql ● Get help – https://discuss.lgtm.com/latest – https://stackoverflow.com/questions/tagged/semmle-ql Recaps