Highlighted Topics Flashcards
(38 cards)
SQL Injections
Injection might happen when queries are built using (e.g. concatenating) the parameters provided by the users
SQL Injection Example
$query = “SELECT ssn FROM employees WHERE name = ‘“ + username +”’ ”
SQL Injection Solutions
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
SQL Injection Solution Example
1) perpare(“… name = ? AND username = ?”);
2) bind_param(“ss”, $name, $password);
Cross-Site Scripting (XSS)
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
XSS Prevention
1) Input Sanitation
2) Output Encoding
3) User Frameworks with Built-it XSS Prevention
XXS Prevention: Input Sanitization
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 >)
XSS Prevention: Output Encoding
Ensure any data output to a page is treated as data, not executable code
Encode special characters (<, >, &, “, ‘) to their HTML or URL encoded equivalents
XSS Prevention: Frameworks
Leverage modern development frameworks and libraries that automatically handle input sanitization and output encoding to reduce XSS vulnerabilities
Cross-Site Request Forgery (CSRF)
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)
CSRF Countermeasure
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
Anit-CSRF Tokens: SameSite = Strict
Browser does not include cookies in any cross-site request
Anit-CSRF Tokens: SameSite = Lax
Allows cookies to be added to request triggered by cross-site top-level navigation
What is setuid?
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
Spatial Memory Safety Errors
Out-of-bound Write/Read which can lead to software crashes if non-writable/readable/allocated memory is accessed
Out-of-Bound Read/Write
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
Temporal Memory Safety Errors
Memory is accessed at the ‘wrong’ time
1) Use After Free
2) Accessing uninitialized variables
3) Double free
Use After Free
Software reuses memory after it has been freed. Two pointers incorrectly point to the same region.
Can lead to Memory Disclosure or Memory Corruption
Memory Safety Errors Exploitation
Spatial/temporal memory safety errors can be used to “leak” secrets from program (e.g. heartbleed)
Can be used to achieve arbitrary code execution
Memory Safety Causing
Code Execution
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
push
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
pop
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
call
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>
ret
Return from a call
Rewrite ret
pop rip
OR
jmp qword ptr [rsp]
add rsp, 8