Source Code Analysis Flashcards

1
Q

What can we do to be sure that code is trustworthy ?

A

Evaluate binary

  • Review source code, compile yourself
  • Evaluate compiler
  • Review compiler source code? +compiler’s compiler?
  • Review compiler machine code?
  • Evaluate operating system
  • Evaluate hardware, firmware

Evaluate persons, processes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

what are risks to outsourcing and offshore development ?

A

Untrustworthy staff
- Contract workers, contractors, sub-contracting
- Insider threat, traceability of code origin/modification
Untrustworthy suppliers
- Products: Libraries, components
- Services: Deployment, operation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What trust models exist for ICT supply chain ?

A

“Blind trust”, “Trust by directive”, “Liability”
-> Sufficient to evaluate 1st supplier

“Reputation”, “Strong interest”
-> Evaluate 1st supplier + 3rd party components

“Proven in use”
->All relevant components known and evaluated?

Higher risk

  • “Weak interest”
  • > Supplier without active interest
  • “Idealism”
  • > Supplier might be harmed by others
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are factors that need to be considerd for software inspections ?

A

Effectiveness: how much reduction?

Efficiency: at what cost?

  • Manual reviews: Skilled labor is scarce
  • Automation (but manual follow-up)

Risk-based analysis/testing
- Reduce scope

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what is the goal for software inspections ?

A

Reduce vulnerabilities in code

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what are advantages of software inspections ?

A

Ensure that more than one person
has seen every piece of code

Prospect of someone else reviewing
your code raises quality

Force developers to document decisions

Train junior developers to get familiar with code base

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What are methods used to find vulnerabilities ?

A

Black box
- Same situation as attackers

White box
- Insider knowledge, e.g., review of source code

Grey box

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

How could an example process of a code review look ?

A
  1. Define scope
  2. Collect information
  3. Review: design, code; test
  4. Document findings
  5. Analyse findings: severity, remediation effort
  6. (Support remediation)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Which parameters define the scope of a code review ?

A

Goal of review
– Ease of detection, severity, code coverage, depth
– Business context
– Compliance with regulations

Type of access
– Source
– Binary, binary+debug info
– Black box access to interfaces

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What tools can aid in the definiton of the scope ?

A

Coverage
- Execute test cases, measure coverage, i.e. which parts of
code affected
- Inspect affected code (assumption: what is not tested is less
relevant code)

Call graphs

  • Identify modules used by many
  • E.g. CScout

Hot spots
- Issue trackers: modules mentioned often (past experience)
- Version control logs
- Code modified often
- Code modified often because of bug fixes
- Defect prediction (type of change, dev. experience,
affected LOC, affected #files)
- Code metrics: complexity, #dependencies
- Code visualisation
- E.g. CodeCity, Gource

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Where can we collect infos while doing a code review ?

A

System documentation

Developer documentation
– Might not exist or might not be current
– Version control log is also documentation
Interviews: be polite

Documentation of standards that are used

Source code: get overview, get feeling

Deployed system: get overview, run scans

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What are the steps while doing the actual review ?

A

Plan: Decide what to look for and how
- High level (design) vs low level (implementation)
- Assets, entry points, trust boundaries, relationships
Review: Perform the review
- Vary: people, perspective
- Take notes, annotate source code
- Stay focused, do not get lost in details
Reflect: What worked well, what did not?
- Relate to review goals

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are common review strategies ?

A

Code comprehension
– Analyse source code, gain understanding
– Trace input, analyse module/algorithm/class

Candidate points
– List potential issues, then examine source code
– Tools often used to create list

Design generalisation
– Recover design from source code
– Identify missing trust boundaries

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What tools are used during the review stage ?

A

Code browsers
– Navigation in code, often integrated in IDE
– Cross-referencing variable/function definition/use
– Formatting/pretty-printing, make code easier to read,
e.g. Artistic Style (http://astyle.sourceforge.net)
– Call graphs, functional dependencies

Version control logs

Issue trackers (linked to version control)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What should be documented after a code review ?

A

Method used

Code coverage

Findings
– Threat, description, impact, location
– Proposed remediation (steps, effort)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What comes after a code review ?

A

Support remediation:
- Not part of review, but consequence of review
- Knowledge gained in discovery useful for fixing
- To fix or not to fix
-Estimate effort
- Business context
- Alternatives: change configuration,
reduce functionality, change environment
- Review fix

17
Q

What can Type Systems do in terms of Security ?

A

Support security by
– imposing discipline/restrictions on developer
– enforcing abstractions on developer

18
Q

What is Memory safety ?

A

Programming language ensures that only allocated (and

initialised) memory can be referenced

19
Q

What is Type safety ?

A

– Types annotate program elements to assert invariant
properties (e.g. integer, array, string)
– Type checking verifies the assertions

20
Q

What is Static code analysis and what are advantages ?

A

Detection of errors in a program without executing it
- No overhead in execution
- Often automated
- Focus on implementation vulnerabilities
- Beneficial for software quality in general
- Avoiding vulnerabilities is one aspect
- Often detects more (and different) errors
than manual review
- Examine unusual execution paths

21
Q

What are disadvantages of static analysis ?

A
False positives
– Static analysis tool reports non-error
– Low rate of false positives important,
critical for acceptance
– Big issue with existing code

False negatives
– Tool does not report error
– Static analysis does not cover all classes of vulnerabilities,
even if you buy all the combined tools on the market

22
Q

What are issues that can be cought with an analysis at compile- time ?

A

Analysis at compile-time
- Syntactic checks (often caught by compiler)
- Type checking (often done by compiler)
- Program semantics
- Unused variables, unreachable code, missing
initialisation
- Dataflow analysis, control flow analysis, abstract
interpretation, program verification, model checking

23
Q

What are classes of programm error ?

A
Data
– Are all variables initialized before use?
– Have all constants been named?
– Array lower bounds: 0, 1, k?
– Array upper bounds: size? size-1?

Control flow
– Correct conditions for conditional statements?
– Termination of loops?
– Correct bracketing?
– All cases accounted for in switch statements?

24
Q

What are analitcal approaches used in static code analysis ?

A

Syntactical analysis (find strings in source code)

Lexical analysis
– Match sequence of tokens against pattern

Data-flow analysis
– Determine possible values for variables

Abstract interpretation
– Model execution on (simpler)
abstract machine
– Define abstract security requirements
in advance, e.g., access to resources