Security Flashcards

1
Q

What is a DDoS attack?

A

Distributed Denial of Service attack

A DoS attack where the traffic flooding the target system comes from many different sources making it much harder to defend against

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

What is a DoS attack?

A

Denial of Service attack

Attack where a malicious user tries to bring down or damage a system in order to render it unavailable to users, often by flooding the target system

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

What is XSS and how does it occur?

A

Cross-Site Scripting

A security vulnerability typically found in web apps

Occurs when an app takes untrusted data and sends it without proper validation/escaping

Allows attackers to execute scripts in the victim’s browser which can access any cookies, session tokens or redirect users to malicious sites

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

What are some ways to prevent XSS?

A
  • Sanitise and validate all input
  • Add CSP
  • Add middleware to enable HTTPOnly flag on cookies to ensure cookies can’t be accessed and can’t be stolen by attackers whose XSS does get through
  • Encode output for correct context - encode characters (ie. < or >) to prevent JS from running in that context when putting untrusted data in HTML tag
  • Encode both client and server side so app can mitigate DOM-based XSS as well
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the role of SSL certificates?

A

SSL certificates are what clients and web servers use to prove that a site is who they say they are and then setting up a secure communication channel

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

What is salt?

A

Unique data (ie. timestamp) added to a hash to prevent hash collisions

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

What are some of the top vulnerabilities in modern web?

A
  • XSS
  • SQL injection
  • Sensitive data exposure
  • Broken authentication and broken access controls
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a hashing collision? Provide example

A

Where different inputs generate the same hash

To combat this, we can add salt to the hashes

ie. when two users use the same password

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

What does encryption and decryption mean?

A

Encryption
Turning readable data into unreadable data

Decryption
Turning unreadable data into readable data

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

What is the difference between hashing and encryption?

A

Hashing is unable to be reversed into its unhashed form

Encryption keeps data secure but recoverable

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

What is CSP?

A

Content Security Policy

Browser-side mechanism to allow developers to whitelist client side resources (ie. JavaScript, CSS, images)

Applied via a special HTTP header that instructs the browser to only execute/render resources from the whitelist

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

How does injection occur and what types are there?

A

Injection occurs when untrusted data is sent to an interpreter as part of a command or query

Types:

  • SQL injection
  • JavaScript injection
  • Command injection
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What are some authentication handshake strategies?

A
  • Key-based authentication
  • OAuth
  • SSO
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How does key-based authentication work?

A

Uses a username and password but comes with the burden of having to keep these details secure

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

How does OAuth work?

A

Website requests authentication from a third-party service then the logged in user verifies that they would like to share details with the new site

Used by Facebook, Google, Twitter

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

What is the difference between cookie vs session?

A

Cookie
Data stored by the browser and sent to the server on every request

Session
Data stored on the server and associated with a given user

17
Q

What is the difference between session-based vs token-based authentication?

A

Session-based
After client authentication, the server passes a unique session ID (that is typically stored in a cookie) and attached to subsequent requests

Token-based
After client authentication, client receives a token to identify the client but can also store additional info

Tokens are applied to HTTP authorization header as a bearer token and sent on subsequent requests

Used for OAuth and SSO strategies

18
Q

What are the pros and cons of session-based authentication?

A

Pros

  • Small size
  • Easy to implement

Cons

  • Prone to XSS and CSRF attacks
  • Sessions are stored in server’s memory, making scaling difficult
19
Q

What are the pros and cons of token-based authentication?

A

Pros

  • Robust security (since JWT is stateless and only a secret key can validate it when received at a server-side application)
  • Stored on client side, making it scalable and efficient
  • Flexibility and performance

Cons

  • Compromised secret key
  • Data overhead (larger in size compared to session tokens)
  • Short lifespan (annoying for users to regularly reauthorise - refresh tokens can be added to combat this)
20
Q

Why is it better to hash passwords rather than encrypt them?

A

If someone steals the key used to encrypt the passwords, they will be able to decrypt them

Strong hashing algorithms mean that even if hashed passwords are leaked, it will take longer than the lifetime of the universe to reverse the hash

21
Q

What are the differences between symmetric vs asymmetric encryption?

A

Symmetric encryption
Data is encoded/decoded using the same key so all authorised users must have a copy of the key

If the key is compromised, all encrypted data can be decrypted

Asymmetric encryption
All authorised users have 2 keys - private/public keys

Encode using the public key and decode with the private key

To send an encrypted message, you encode using the recipient’s public key and the recipient decodes the message using their private key

22
Q

How does SQL/NoSQL injection work?

A

Allows the attacker to inject code into a db query that will be executed by the db

Caused by developers using dynamic db queries or queries taking user input

ie. search field where data is put inside the query without sanitisation

23
Q

How can we prevent SQL/NoSQL injection?

A
  • Sanitise user input
  • Use prepared statements to avoid vulnerabilities and string concatenation to form db queries
  • Use principle of least privilege
24
Q

How can we prevent JavaScript injection?

A
  • Sanitise user input
  • Not using eval(), setTimeout(), setInterval() functions to parse user input - instead use JSON.parse()
  • Enable “strict mode” in Javascript
25
Q

What are some functions vulnerable to JavaScript injection and why?

A

Vulnerable functions:

  • eval()
  • setTimeout()
  • setInterval()

Web apps using eval() are vulnerable when user input is not validated

Without sanitising the data, an attacker can inject any data they want often leading to a DoS attack

setTimeout() and setInterval() are indirectly vulnerable because their first argument passes user input to the eval() function