Lecture 01
Lecture 01
Lecture 01
Verification Laboratory
Software Security
Lucas Cordeiro
Department of Computer Science
lucas.cordeiro@manchester.ac.uk
Career Summary
1 4
BSc/MSc in
Engineering and
Lecturer
Career Summary
1 2
Set-top Box
Software Engineer
Career Summary
1,7 2 3 4
5 6
5 6 8
5 6 8 9
• Cyber-Security
Relationship to Other Courses
Software Security involves people and practices, to
build software systems, ensuring confidentiality,
integrity and availability
• Cyber-Security
• Cryptography
Relationship to Other Courses
Software Security involves people and practices, to
build software systems, ensuring confidentiality,
integrity and availability
• Cyber-Security
• Cryptography
• Automated Reasoning and Verification
Relationship to Other Courses
Software Security involves people and practices, to
build software systems, ensuring confidentiality,
integrity and availability
• Cyber-Security
• Cryptography
• Automated Reasoning and Verification
• Logic and Modelling
Relationship to Other Courses
Software Security involves people and practices, to
build software systems, ensuring confidentiality,
integrity and availability
• Cyber-Security
• Cryptography
• Automated Reasoning and Verification
• Logic and Modelling
• Agile and Test-Driven Development
Relationship to Other Courses
Software Security involves people and practices, to
build software systems, ensuring confidentiality,
integrity and availability
• Cyber-Security
• Cryptography
• Automated Reasoning and Verification
• Logic and Modelling
• Agile and Test-Driven Development
• Software Engineering Concepts In Practice
Relationship to Other Courses
Software Security involves people and practices, to
build software systems, ensuring confidentiality,
integrity and availability
• Cyber-Security
• Cryptography
• Automated Reasoning and Verification
• Logic and Modelling
• Agile and Test-Driven Development
• Software Engineering Concepts In Practice
• Systems Governance
Cyber-Security Pathway
Cyber-Security
• 70% Coursework
o Lab exercises = 40%
o Quizes = 10%
o Seminars = 20%
• 30% Exam
o Format: 2 hours, 3 questions, all the material.
Textbook
• McGraw, Gary: Software Security: Building Security
In, Addison-Wesley, 2006
Textbook
• McGraw, Gary: Software Security: Building Security
In, Addison-Wesley, 2006
• Hoglund, Greg: Exploiting Software: How to Break
Code, Addison-Wesley, 2004
Textbook
• McGraw, Gary: Software Security: Building Security
In, Addison-Wesley, 2006
• Hoglund, Greg: Exploiting Software: How to Break
Code, Addison-Wesley, 2004
• Ransome, James and Misra, Anmol: Core Software
Security: Security at the Source, CRC Press, 2014
Textbook
• Edmund M. Clark Jr., Orna Grumberg, Daniel Kroening,
Doron Peled, Helmut Veith: Model Checking, The MIT
Press, 2018
Textbook
• Edmund M. Clark Jr., Orna Grumberg, Daniel Kroening,
Doron Peled, Helmut Veith: Model Checking, The MIT
Press, 2018
• Mark Dowd , John McDonald, et al.: The Art of
Software Security Assessment: Identifying and
Preventing Software Vulnerabilities, Addison-Wesley,
2006
Textbook
• Edmund M. Clark Jr., Orna Grumberg, Daniel Kroening,
Doron Peled, Helmut Veith: Model Checking, The MIT
Press, 2018
• Mark Dowd , John McDonald, et al.: The Art of
Software Security Assessment: Identifying and
Preventing Software Vulnerabilities, Addison-Wesley,
2006
https://www.cybok.org/media/downloads/cybok_version_1.0.pdf
SEI CERT C Coding Standard: Rules for
Developing Safe, Reliable, and Secure
Systems
https://resources.sei.cmu.edu/downloads/secure-coding/
assets/sei-cert-c-coding-standard-2016-v01.pdf
The CERT Division
• CERT’s main goal is to improve the security and
resilience of computer systems and networks
https://www.sei.cmu.edu/about/divisions/cert/
End of Admin
Most importantly,
ENJOY!
Intended Learning
Outcomes
• Define standard notions of security and use
them to evaluate the system’s confidentiality,
integrity and availability
Intended Learning
Outcomes
• Define standard notions of security and use
them to evaluate the system’s confidentiality,
integrity and availability
• Explain standard software security problems
in real-world applications
Intended Learning
Outcomes
• Define standard notions of security and use
them to evaluate the system’s confidentiality,
integrity and availability
• Explain standard software security problems
in real-world applications
• Use testing and verification techniques to
reason about the system’s safety and security
Intended Learning
Outcomes
• Define standard notions of security and use
them to evaluate the system’s confidentiality,
integrity and availability
• Explain standard software security problems
in real-world applications
• Use testing and verification techniques to
reason about the system’s safety and security
Motivating Example
void main(){
int x=getPassword();
int getPassword() { if(x){
char buf[4]; printf(“Access Denied\n”);
gets(buf); exit(0);
return strcmp(buf, ”SMT”); }
} printf(“Access Granted\n”);
}
• A more extended input will run over into other parts of the computer
memory
• Security
– If an attacker supplies unexpected input, then the
system does not fail in specific ways
• Bad input ⇒ Bad output
• Protection of individuals, organizations,
and properties against external threats
• More features leads to a higher
chance of attacks
Overview
System
User Attacker
System
User Attacker
Network Attacker
User
Boneh, D. and Mitchell, J., “Computer and Network Security”, 2009.
Web Security
System
Web Attacker
Sets up a malicious
site visited by the
victim; there exists
no control of the
User network
OS Attacker
Controls malicious
files and
applications
User
Boneh, D. and Mitchell, J., “Computer and Network Security”, 2009.
CIA Principle
System
User Attacker
System
User Attacker
System
User Attacker
https://cve.mitre.org/
Critical Software Vulnerabilities
int main() {!
double *p = NULL;
int n = 8;!
for(int i = 0; i < n; ++i )
*(p+i) = i*2;!
return 0;!
}
Critical Software Vulnerabilities
Scope Impact
Availability Crash, exit and restart
Integrity Execute Unauthorized Code
Confidentiality or Commands
Availability
Critical Software Vulnerabilities
Scope Impact
Integrity Execute Unauthorized Code
Confidentiality or Commands
Availability
Critical Software Vulnerabilities
VDU
VDU
VDU VDU
Race conditions
P P P P
occur when
multiple
processes
perform Process
unsynchronized
accesses to the Database
database
Race Condition Vulnerabilities
https://www.imperva.com/blog/the-state-of-web-application-
vulnerabilities-in-2018/
Vulnerabilities by Categories
Structured output generation
vulnerabilities
• A SQL injection vulnerability is a structured output
generation vulnerability where the structured output
consists of SQL code
– These vulnerabilities are relevant for server-side web app
• interact with a back-end database by constructing queries
based on input provided through web forms
Structured output generation
vulnerabilities
• A SQL injection vulnerability is a structured output
generation vulnerability where the structured output
consists of SQL code
– These vulnerabilities are relevant for server-side web app
• interact with a back-end database by constructing queries
based on input provided through web forms
https://portswigger.net/web-security/sql-injection
Example of SQL Injection
§ No proofs!!! (Algorithmic
rather than Deductive)
Advantages of Model Checking
§ No proofs!!! (Algorithmic
rather than Deductive)
§ Fast (compared to other
rigorous methods such as
theorem proving)
Advantages of Model Checking
§ No proofs!!! (Algorithmic
rather than Deductive)
§ Fast (compared to other
rigorous methods such as
theorem proving)
§ Diagnostic
counterexamples
Advantages of Model Checking
§ No proofs!!! (Algorithmic
rather than Deductive)
§ Fast (compared to other
rigorous methods such as
theorem proving)
§ Diagnostic
counterexamples
§ No problem with partial
specifications
Advantages of Model Checking
§ No proofs!!! (Algorithmic
rather than Deductive)
§ Fast (compared to other
rigorous methods such as
theorem proving)
§ Diagnostic
counterexamples
§ No problem with partial
specifications
§ Logics can easily express
many concurrency
properties
LTL - Linear Time Logic (Pn 77)
Determines Patterns on Infinite Traces
Atomic Propositions a
Boolean Operations
Temporal operators
a “a is true now”
Xa “a is true in the neXt state”
Fa “a will be true in the Future”
Ga “a will be Globally true in the future”
aUb “a will hold true Until b becomes true”
LTL - Linear Time Logic (Pn 77)
Determines Patterns on Infinite Traces
Atomic Propositions a
Boolean Operations
Temporal operators
a “a is true now”
Xa “a is true in the neXt state”
Fa “a will be true in the Future”
Ga “a will be Globally true in the future”
aUb “a will hold true Until b becomes true”
LTL - Linear Time Logic (Pn 77)
Determines Patterns on Infinite Traces
Atomic Propositions a
Boolean Operations
Temporal operators
a “a is true now”
Xa “a is true in the neXt state”
Fa “a will be true in the Future”
Ga “a will be Globally true in the future”
aUb “a will hold true Until b becomes true”
LTL - Linear Time Logic (Pn 77)
Determines Patterns on Infinite Traces
Atomic Propositions a a a a a
Boolean Operations
Temporal operators
a “a is true now”
Xa “a is true in the neXt state”
Fa “a will be true in the Future”
Ga “a will be Globally true in the future”
aUb “a will hold true Until b becomes true”
LTL - Linear Time Logic (Pn 77)
Determines Patterns on Infinite Traces
Atomic Propositions a a a a b
Boolean Operations
Temporal operators
a “a is true now”
Xa “a is true in the neXt state”
Fa “a will be true in the Future”
Ga “a will be Globally true in the future”
aUb “a will hold true Until b becomes true”
Model Checking Problem
Start ~ Start
~ Start
~ Close Close
Close
~ Heat Heat
~ Heat
Error ~ Error
~ Error
• (~ heat_up) U door_closed
Bounded Model Checking (BMC)
Basic idea: check negation of given property up to given depth
property
¬ϕ0 ∨ ¬ϕ1 ∨ ¬ϕ2 ∨ ¬ϕk-1 ∨ ¬ϕk
...
transition
system M0 M1 M2 Mk-1 Mk
counterexample trace bound
Bounded Model Checking (BMC)
Basic idea: check negation of given property up to given depth
property
¬ϕ0 ∨ ¬ϕ1 ∨ ¬ϕ2 ∨ ¬ϕk-1 ∨ ¬ϕk
...
transition
system M0 M1 M2 Mk-1 Mk
counterexample trace bound
property
¬ϕ0 ∨ ¬ϕ1 ∨ ¬ϕ2 ∨ ¬ϕk-1 ∨ ¬ϕk
...
transition
system M0 M1 M2 Mk-1 Mk
counterexample trace bound
property
¬ϕ0 ∨ ¬ϕ1 ∨ ¬ϕ2 ∨ ¬ϕk-1 ∨ ¬ϕk
...
transition
system M0 M1 M2 Mk-1 Mk
counterexample trace bound
Theory Example
Equality x1=x2 ∧ ¬ (x1=x3) ⇒ ¬(x1=x3)
Bit-vectors (b >> i) & 1 = 1
Linear arithmetic (4y1 + 3y2 ≥ 4) ∨ (y2 – 3y3 ≤ 3)
Arrays (j = k ∧ a[k]=2) ⇒ a[j]=2
Combined theories (j ≤ k ∧ a[j]=2) ⇒ a[i] < 3
int getPassword() {
Software BMC char buf[4];
gets(buf);
return strcmp(buf, ”ML”);
}
• program modelled as transition system void main(){
– state: pc and program variables int x=getPassword();
if(x){
– derived from control-flow graph printf(“Access Denied\n”);
exit(0);
– added safety properties as extra nodes }
printf(“Access Granted\n”);
• program unfolded up to given bounds }
⎢∧ 1 + i0 ≥ 0 ∧ 1 + i0 < 2 ⎥
⎥
• satisfiability check of C ∧ ¬P
⎢ ⎥
⎣∧ select (a4 , i0 + 1) = 1 ⎦
Software BMC Applied to Security
void main(){ buffer overflow attack
int x=getPassword();
int getPassword() { if(x){
char buf[4]; printf(“Access Denied\n”);
gets(buf); exit(0);
return strcmp(buf, ”SMT”); }
} printf(“Access Granted\n”);
}
sp0,sp1,sp2:BITVECTOR(8);
ip:BITVECTOR(8);
m0,m1,m2,m3,m4,m5 : ARRAY BITVECTOR(8) OF BITVECTOR(8);
in : ARRAY INT OF BITVECTOR(8);
ASSERT sp1 = BVSUB(8,sp0,0bin100);
ASSERT m1 = m0 WITH [sp1] := in[1];
ASSERT m2 = m1 WITH [BVPLUS(8,sp1,0bin1)] := in[2];
ASSERT m3 = m2 WITH [BVPLUS(8,sp1,0bin10)] := in[3];
ASSERT m4 = m3 WITH [BVPLUS(8,sp1,0bin11)] := in[4];
ASSERT m5 = m4 WITH [BVPLUS(8,sp1,0bin100)] := in[5];
ASSERT sp2 = BVPLUS(8,sp1,0bin100);
ASSERT ip = m5[sp2];
ASSERT NOT ip = m0[sp0];
CHECKSAT;
Barrett et al., “Problem Solving for the 21st Century”, 2014.
Software BMC Applied to Security
void main(){ buffer overflow attack
int x=getPassword();
int getPassword() { if(x){
char buf[4]; printf(“Access Denied\n”);
gets(buf); exit(0);
return strcmp(buf, ”SMT”); }
} printf(“Access Granted\n”);
}
SSA & loop unrolling
sp0,sp1,sp2:BITVECTOR(8);
ip:BITVECTOR(8);
m0,m1,m2,m3,m4,m5 : ARRAY BITVECTOR(8) OF BITVECTOR(8);
in : ARRAY INT OF BITVECTOR(8);
ASSERT sp1 = BVSUB(8,sp0,0bin100); 4-character array buf
ASSERT m1 = m0 WITH [sp1] := in[1];
ASSERT m2 = m1 WITH [BVPLUS(8,sp1,0bin1)] := in[2];
ASSERT m3 = m2 WITH [BVPLUS(8,sp1,0bin10)] := in[3];
ASSERT m4 = m3 WITH [BVPLUS(8,sp1,0bin11)] := in[4];
ASSERT m5 = m4 WITH [BVPLUS(8,sp1,0bin100)] := in[5];
ASSERT sp2 = BVPLUS(8,sp1,0bin100);
ASSERT ip = m5[sp2];
ASSERT NOT ip = m0[sp0];
CHECKSAT;
Barrett et al., “Problem Solving for the 21st Century”, 2014.
Software BMC Applied to Security
void main(){ buffer overflow attack
int x=getPassword();
int getPassword() { if(x){
char buf[4]; printf(“Access Denied\n”);
gets(buf); exit(0);
return strcmp(buf, ”SMT”); }
} printf(“Access Granted\n”);
}
SSA & loop unrolling
sp0,sp1,sp2:BITVECTOR(8);
ip:BITVECTOR(8);
m0,m1,m2,m3,m4,m5 : ARRAY BITVECTOR(8) OF BITVECTOR(8);
in : ARRAY INT OF BITVECTOR(8);
ASSERT sp1 = BVSUB(8,sp0,0bin100); 4-character array buf
ASSERT m1 = m0 WITH [sp1] := in[1];
ASSERT m2 = m1 WITH [BVPLUS(8,sp1,0bin1)] := in[2];
ASSERT m3 = m2 WITH [BVPLUS(8,sp1,0bin10)] := in[3];
ASSERT m4 = m3 WITH [BVPLUS(8,sp1,0bin11)] := in[4];
ASSERT m5 = m4 WITH [BVPLUS(8,sp1,0bin100)] := in[5];
ASSERT sp2 = BVPLUS(8,sp1,0bin100); reclaim the memory occupied by buf
ASSERT ip = m5[sp2];
ASSERT NOT ip = m0[sp0];
CHECKSAT;
Barrett et al., “Problem Solving for the 21st Century”, 2014.
Software BMC Applied to Security
void main(){ buffer overflow attack
int x=getPassword();
int getPassword() { if(x){
char buf[4]; printf(“Access Denied\n”);
gets(buf); exit(0);
return strcmp(buf, ”SMT”); }
} printf(“Access Granted\n”);
}
SSA & loop unrolling
sp0,sp1,sp2:BITVECTOR(8);
ip:BITVECTOR(8);
m0,m1,m2,m3,m4,m5 : ARRAY BITVECTOR(8) OF BITVECTOR(8);
in : ARRAY INT OF BITVECTOR(8);
ASSERT sp1 = BVSUB(8,sp0,0bin100); 4-character array buf
ASSERT m1 = m0 WITH [sp1] := in[1];
ASSERT m2 = m1 WITH [BVPLUS(8,sp1,0bin1)] := in[2];
ASSERT m3 = m2 WITH [BVPLUS(8,sp1,0bin10)] := in[3];
ASSERT m4 = m3 WITH [BVPLUS(8,sp1,0bin11)] := in[4];
ASSERT m5 = m4 WITH [BVPLUS(8,sp1,0bin100)] := in[5];
ASSERT sp2 = BVPLUS(8,sp1,0bin100); reclaim the memory occupied by buf
ASSERT ip = m5[sp2]; ip is loaded with the location pointed to by sp
ASSERT NOT ip = m0[sp0];
CHECKSAT;
Barrett et al., “Problem Solving for the 21st Century”, 2014.
Software BMC Applied to Security
void main(){ buffer overflow attack
int x=getPassword();
int getPassword() { if(x){
char buf[4]; printf(“Access Denied\n”);
gets(buf); exit(0);
return strcmp(buf, ”SMT”); }
} printf(“Access Granted\n”);
}
SSA & loop unrolling
sp0,sp1,sp2:BITVECTOR(8);
ip:BITVECTOR(8); We wish to determine
m0,m1,m2,m3,m4,m5 : ARRAY BITVECTOR(8) OF BITVECTOR(8); whether it is possible to
in : ARRAY INT OF BITVECTOR(8);
ASSERT sp1 = BVSUB(8,sp0,0bin100); 4-character array buf set ip to a value that we
ASSERT m1 = m0 WITH [sp1] := in[1]; choose instead of the
ASSERT m2 = m1 WITH [BVPLUS(8,sp1,0bin1)] := in[2]; location of the if
ASSERT m3 = m2 WITH [BVPLUS(8,sp1,0bin10)] := in[3];
ASSERT m4 = m3 WITH [BVPLUS(8,sp1,0bin11)] := in[4];
statement
ASSERT m5 = m4 WITH [BVPLUS(8,sp1,0bin100)] := in[5];
ASSERT sp2 = BVPLUS(8,sp1,0bin100); reclaim the memory occupied by buf
ASSERT ip = m5[sp2]; ip is loaded with the location pointed to by sp
ASSERT NOT ip = m0[sp0];
CHECKSAT;
Barrett et al., “Problem Solving for the 21st Century”, 2014.
Context-Bounded Model Checking
... combines
• symbolic model checking: on each individual interleaving
• explicit state model checking: explore all interleavings
– bound the number of context switches allowed among
threads
Context-Bounded Model Checking
... combines
• symbolic model checking: on each individual interleaving
• explicit state model checking: explore all interleavings
– bound the number of context switches allowed among
threads
… implements
• symbolic state hashing (SHA1 hashes)
• monotonic partial order reduction that combines dynamic POR
with symbolic state space exploration
Lazy Exploration of the Reachability Tree
υ0 : tmain,0, active thread, context bound
initial state val1=0, val2=0,
m1=0, m2=0,… global and local variables
CS2
execution paths
Lazy Exploration of the Reachability Tree
υ0 : tmain,0, active thread, context bound
initial state val1=0, val2=0,
m1=0, m2=0,… global and local variables
υ2: ttwoStage,2,
val1=1, val2=0,
m1=1, m2=0,… interleaving completed, so
call single-threaded
CS2 BMC
execution paths
Lazy Exploration of the Reachability Tree
υ0 : tmain,0, active thread, context bound
initial state val1=0, val2=0,
m1=0, m2=0,… global and local variables
υ1: ttwoStage,1,
val1=0, val2=0, backtrack to last unexpanded node
m1=1, m2=0,…
and continue
CS1
execution paths
blocked execution paths (eliminated)
Lazy Exploration of the Reachability Tree
υ0 : tmain,0, active thread, context bound
initial state val1=0, val2=0,
m1=0, m2=0,… global and local variables
υ1: ttwoStage,1,
val1=0, val2=0, backtrack to last unexpanded node
m1=1, m2=0,…
and continue
CS1
execution paths
blocked execution paths (eliminated)
Lazy Exploration of the Reachability Tree
υ0 : tmain,0, active thread, context bound
initial state val1=0, val2=0,
m1=0, m2=0,… global and local variables
execution paths
blocked execution paths (eliminated)
Predicate Abstraction
• It abstracts data by only keeping track of certain
predicates to represent the data
Predicate Abstraction
• It abstracts data by only keeping track of certain
predicates to represent the data
Initial Abstraction Verification
C/C++ Concurrent
Program Boolean Model Property
with threads Program Checker holds
}
while(even(i))
i++; + p1 ⇔ i=0
p2 ⇔ even(i) = while(p2)
{
p1=p1?FALSE:nondet();
p2=!p2;
}
}
Embedded Software
Specification Microprocessor
model
Combine Simulation and
Verification
• Improve coverage and reduce verification time by
combining static and dynamic verification
Verification Techniques
Combine
Coverage Improve
Quiz about Software Security
Go to https://kahoot.it/
Summary