Highlighted Topics Flashcards

1
Q

SQL Injections

A

Injection might happen when queries are built using (e.g. concatenating) the parameters provided by the users

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

SQL Injection Example

A

$query = “SELECT ssn FROM employees WHERE name = ‘“ + username +”’ ”

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

SQL Injection Solutions

A

Prepare statement allows for the clear separation of what is to be considered data and what is to be considered code
1) query is parsed and location of the parameters are identified
2) the parameters are bound to their actual value

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

SQL Injection Solution Example

A

1) perpare(“… name = ? AND username = ?”);
2) bind_param(“ss”, $name, $password);

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

Cross-Site Scripting (XSS)

A

Used to bypass JavaScript’s same-origin policy – malicious JavaScript code that is injected, stored on the server, and then executed.

Since it is stored on the server, the browser interprets the code as the same origin as the server

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

XSS Prevention

A

1) Input Sanitation
2) Output Encoding
3) User Frameworks with Built-it XSS Prevention

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

XXS Prevention: Input Sanitization

A

Implement robust input sanitization to strip out or encode potentially harmful characters from user inputs

Cannot be trivial since characters can be encoded (e.g. < is read as < and > is read as >)

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

XSS Prevention: Output Encoding

A

Ensure any data output to a page is treated as data, not executable code

Encode special characters (<, >, &, “, ‘) to their HTML or URL encoded equivalents

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

XSS Prevention: Frameworks

A

Leverage modern development frameworks and libraries that automatically handle input sanitization and output encoding to reduce XSS vulnerabilities

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

Cross-Site Request Forgery (CSRF)

A

An attacker induces users to perform action that they do not intend to perform on a web application in which they are currently authenticated (normally using website redirection)

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

CSRF Countermeasure

A

Anit-CSRF Tokens which are unique to each user session and embed this token in forms and requests to verify that the submission is intentional and originates from the legitimate user interface

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

Anit-CSRF Tokens: SameSite = Strict

A

Browser does not include cookies in any cross-site request

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

Anit-CSRF Tokens: SameSite = Lax

A

Allows cookies to be added to request triggered by cross-site top-level navigation

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

What is setuid?

A

If stored in setuid file, the permissions of the corresponding process will be equalivalent to the presmission of the owner of the file program

real user ID = user who started the process
effective user ID = owner

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

Spatial Memory Safety Errors

A

Out-of-bound Write/Read which can lead to software crashes if non-writable/readable/allocated memory is accessed

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

Out-of-Bound Read/Write

A

The software reads/writes data past the end/before the beginning of the intended buffer

Read: can lead to memory disclosure (leak)
Write: can lead to memory corruption

17
Q

Temporal Memory Safety Errors

A

Memory is accessed at the ‘wrong’ time
1) Use After Free
2) Accessing uninitialized variables
3) Double free

18
Q

Use After Free

A

Software reuses memory after it has been freed. Two pointers incorrectly point to the same region.

Can lead to Memory Disclosure or Memory Corruption

19
Q

Memory Safety Errors Exploitation

A

Spatial/temporal memory safety errors can be used to “leak” secrets from program (e.g. heartbleed)

Can be used to achieve arbitrary code execution

20
Q

Memory Safety Causing
Code Execution

A

1) Use an out-of-bound write or corrupt a code pointer
2) Make corrupted pointer point to some attacker-controlled data which will then be executed

21
Q

push

A

Write a value on the top of the stack

Rewriting push rax:
sub rsp, 8
mob qword ptr [rsp], rax

OR

sub rsp, 8
*rsp = rax

22
Q

pop

A

Read a value from the top of the stack

Rewriting pop rax:
mov rax, qword ptr [rsp]
add rsp, 8

OR

rax = *rsp
add rsp, 8

23
Q

call

A

Jump to a location, write the return address on the stack

Rewrite call 0x112230
push <address of following instruction>
jmp 0x112230

OR

sub rsp, 8
*rsp = <following>
jmp 0x112230</following>

24
Q

ret

A

Return from a call

Rewrite ret
pop rip

OR

jmp qword ptr [rsp]
add rsp, 8

25
Q

Address Space Layout Randomization (ASLR)

A

Addresses the assumption that “We know where the address of the attacker-controlled memory is”

Implemented by operating system and randomizes the position of: heap, stack, dynamically-linked libraries, and program’s main code

26
Q

ASLR Exploitation

A

Can disabled by “leaking” memory content (e.g. out-of-bound read) especially since common ASLR implementations only shift the entire memory layout by an offset

27
Q

Non-Executable Memory (NX)

A

Address the assumption that “The attacker-controlled memory is executable”

No memory page is both writable and executable. The CPU enforces that if the program attempts to execute data in an non-executable memory page an exception is raised

28
Q

NX Exploitation

A

If there exists a “win” function already in the code then we can use Code Reuse/Return Oriented Programming (ROP)

29
Q

Return Oriented Programming (ROP)

A

Re-use gadgets (such as pop rdi; ret)

We can set the stack so that the execution “jumps” from one gadget to the next one

30
Q

Control Flow Integrity (CFI)

A

Enforce that the flow of execution of the program only takes a legitimate path (e.g. ret can only return to its caller)

Hard to
1) cover all possible corner cases and uncommon behaviors legitimate programs may have
2) be efficient since it requires CPU supports

31
Q

Why is C memory unsafe?

A

1) Low-level memory access: arbitrarily create pointers at arbitrary locations

2) NO runtime check on the validity of the access memory

3) Manual memory management: need to manually allocate/de-allocate memory buffer (e.g. malloc() and free())

32
Q

Why is Java memory safe?

A

1) Automated memory management: if memory is needed, the garbage collector will run and frees memory of memory buffers that cannot be accessed anymore

2) Does not allow arbitrary memory access: accessing null throws a NullPoitnerException (especially since all variable need to be initialized_

3) Runtime array bounds checking: cannot access array out of bounds without throwing ArrayIndexOfBoundsException

33
Q

Drawbacks of Java

A

1) Performance impact from added checks
2) Require virtual machine and a large “runtime” library
3) No direct control over memory allocation/free
4) Does not allow fine-tuned memory management

34
Q

Reasons to use C

A

1) allows specifying how memory should be accessed and managed
2) allows low-level interaction with peripherals
3) allows writing highly-optimized code
4) is compatible with older systems

35
Q

Google’s Rule of 2

A

Can only have at most two of these things be true:
1) code which processes untrustworthy input
2) code written in an unsafe language
3) code which runs with no sandbox (e.g. browser process)

36
Q

Security Principles: Updates & Andriod

A

Apps are automatically updated in background
Many system components can be updated without a “full” system update

37
Q

Security Principles: Defense in Depth

A

Multiple layers of security controls are placed throughout a system

Prevents single vulnerabilities from leading to compromise of the entire OS or other apps

38
Q

Android Permissions

A

Prior to 6, it was all or nothing. Now there are three types of permissions:

1) install-time permissions: cannot be revoked

2) runtime-permissions: need to be approved at runtime

3) special permissions: enabled in ad-hoc ways (accessibility, device administrator)