Important Flashcards
CSRF Prevention
To prevent CSRF attacks, web applications need to build mechanisms to distinguish a legitimate request by a trusted user from a forged request crafted by an attacker but sent by the trusted user.
Token Based Mitigation:
- some frameworks like .NET have built-in protections that add a token to vulnerable CSRF resources.
- Synchronizer token pattern: csrf tokens should be generated server-side. They can be generated once per-user session for requests. The value is stored in the session and used for each request until the session expires. The server needs to verify the token in the request to the one found in the user session
- the token should be transmitted as part of the response and then transmitted back to the server as part of a hidden field on a form submission or as a AJAX header/part of JSON payload
- more secure to put it in a custom header (automatically same origin policy applies)
Double Submit Cookie:
- this is stateless unlike token-based mitigations
- server doesn’t need to generate the value, the client could
- the value will be sent as a cookie and as something else (request header)
- the attacker cannot access the cookie
- so the attacker cannot send the value as something else to verify itself (like in a request header) - this step needs to happen
Signed Double Submit Cookie:
- server has a secret key
- tokens are hashed/encrypted
- A simpler alternative to an encrypted CSRF cookie is to use HMAC (Hash-based Message Authentication Code) to hash the random value with a secret key known only by the server and place this value in a cookie.
- attacker cannot submit their own CSRF cookie
Custom request headers:
- no token
- In this pattern, the client appends a custom header to requests that require CSRF protection. The header can be any arbitrary key-value pair, as long as it does not conflict with existing headers.
- When handling the request, the API checks for the existence of this header. If the header does not exist, the backend rejects the request as potential forgery.
- this relies on SOP (that only JS can add the header and only from within its origin). By default, browsers do not allow JavaScript to make cross origin requests with custom headers. Only JavaScript that you serve from your origin can add these headers.
CSRF defense in depth protections
SameSite Cookie Attribute:
- helps browser decide whether to send cookies along with cross-site requests.
- lax, strict, none
Verify origin with standard headers
- check if source origin matches target origin
Client Side CSRF
the attacker tricks the client-side javascript code to send a forged HTTP request to the vulnerable target by manipulating the program’s input parameters
- Client-side CSRF originates when the JavaScript program uses attacker-controlled inputs, such as the URL, for the generation of asynchronous HTTP requests.
- it can bypass some CSRF mitigations like tokens
- circumvents same-site cookie
bypassing CSRF mitigations
Some applications correctly validate the token when it is present but skip the validation if the token is omitted.
Some applications do not validate that the token belongs to the same session as the user who is making the request. Instead, the application maintains a global pool of tokens that it has issued and accepts any token that appears in this pool.
In this situation, the attacker can log in to the application using their own account, obtain a valid token, and then feed that token to the victim user in their CSRF attack.
Bypassing same-site:
Open redirection -As far as browsers are concerned, these client-side redirects aren’t really redirects at all; the resulting request is just treated as an ordinary, standalone request. Most importantly, this is a same-site request and, as such, will include all cookies related to the site, regardless of any restrictions that are in place.
What happens when you enter a URL into the browser and hit enter?
- URL parsing - protocol, domain, path, query parameters
- DNS Lookup - check cache. Make a request to DNS server to find ip associated with the domain
- TCP Handshake
- TLS Handshake
- HTTP Request
- Server Processing
- HTTP Response
- Page rendering
How do you analyze a suspicious email attachment?
- Open on a virtual machine like virtual box with no network access.
- Take a snapshot of the virtual machine before and after
- see processes launched, ports, etc
The easiest way would be to foward the mail to an online scanning service. Or download (do not run) and upload to virus/malware scanner.
Look at the file type
Inspect the email. Sender. Typos. etc
How do you attack a VPN?
Weak ciphers that can be broken. Browser activity could be leaked if DNS requests are being handled by the ISP. These are unencrypted.
How do you find vulnerable software running on people’s work machines?
Endpoint management system running that will detect vulnerable software. See what processes are running. SentinelOne.
You visit a team website and get a 404, but everyone else on your team can access it. what is wrong?
Maybe you’re in the wrong role. Okta. Don’t have the right permissions.
Delete your cache.
A CEO of a well known company is sitting across from you at a coffee shop. how do you hack his email?
Is a public wifi being used. It’s safe as long as the websites you’re using are using HTTPS. Otherwise, someone else connected to the wifi can sniff your traffic content.
Look over his shoulder for passwords. Figure out what his email address is. Phish him. Send him to a site without HTTPS or to my own malicious site.
Wifi pineapple to mimic a network and have the CEO connect to the wifi pineapple.
Your manager wants you to bring you laptop to Defcon, how do you secure it from getting hacked?
Turn off wifi. Encrypt the machine. Make sure it’s updated/patched. Host based firewall. Turn off bluetooth.
If you were an attacker who compromised a CA and stole the private key, how would you use it?
Can issue fraudulent certificates.
How would you attack the OAuth workflow?
Implementation mistakes.
Take advantage of the redirect_uri for Open Redirects. the client application implements some whitelist of their genuine callback URLs when registering with the OAuth service to mitigate this attack. Could end up sending the access token to an attacker controlled url. CSRF like attack to trick the user into initiating the OAuth flow, but sending the token back to the malicious user.
Need to add the state parameter - needs to be an unguessable value. Otherwise vulnerable to CSRF. Because It potentially means that they can initiate an OAuth flow themselves before tricking a user’s browser into completing it, similar to a traditional CSRF attack.
Pre account takeover. Try to register an account with another user’s email. Then we they try to create an account using social network, then that will get linked to the pre existing account. Perhaps they can still login into the account using the pw they set.
OAuth authentication vulnerabilities arise partly because the OAuth specification is relatively vague and flexible by design. Lack of built-in security features
the first request of the flow will always be a request to the /authorization endpoint containing a number of query parameters that are used specifically for OAuth. In particular, keep an eye out for the client_id, redirect_uri, and response_type parameters
Explain the SSL handshake. How do certificates get provisioned?
They get provisioned by a CA. You send a request to a CA such as Verisign.
An applicant generates a key pair (public and private) and a CSR (certificate signing request). A CSR is an encoded file that includes the public key and other info such as domain name, org, email). This is usually generated on the server that the certificate will be installed.
The private key is never sent to the CA.
The applicant sends the CSR to the CA. CA independently validates the info. If validated, then signs the cert with an issuing private key and sends it to the applicant.
Third parties can validate the cert by confirming the CA’s signature with the CA’s public key.
You see a high volume of traffic to 169.254.169.254, what do you suspect?
This ip is used for instance metadata. Maybe they’re trying to see what kind of a server it is/where its hosted and try to gather more data about the server. Perhaps the server has been compromised.
API Security
Use HTTPS
JWT
Input Validation
Error handling
SSO - you don’t have to manage user pw storage yourself
API Gateway
XSS Prevention
- [ ] XSS Framework built in protections
- [ ] React
- [ ] Angular
- [ ] But still need to use these frameworks safely
- [ ] Cookie attributes - samesite, httponly
- [ ] CSP
- [ ] Web application firewalls
What is a JSONP?
JSONP stands for JSON with padding. It is a method for sending JSON data without having to worry about cross domain issues (because of SOP). This was before the adoption of CORS.
JSONP enables sharing of data bypassing same-origin policy, which disallows running JavaScript code to read media DOM elements or XMLHttpRequest data fetched from outside the page’s originating site. The originating site is indicated by a combination of URI scheme, hostname, and port number.
JSONP uses the
tag.
A server can send a function call (wrapped around JSON) returning JSON in a response. The client uses a script tag and the server url as the src to load this data by handling the function.
This “wrapped payload” is then interpreted by the browser. In this way, a function that is already defined in the JavaScript environment can manipulate the JSON data.
JSONP is vulnerable to the data source replacing the innocuous function call with malicious code, which is why it has been superseded by cross-origin resource sharing in modern applications.
You’re allowing a remote server to inject any content into your website. They could inject malicious javascript and because the script is bypassing SOP, it could lead to CSRF, fetching JS from another site, etc.
Give examples of secure libraries encoding, sanitization
DOMPurify - recommended by OWASP for HTML sanitization
Use safe HTML attributes unlike innerHTML use innerText
Don’t pipe values into eval()
What are some security network scanners?
NMAP
Wireshark
Burp
What is a race condition and how do you prevent them?
A race condition attack takes advantage of a system that needs to execute tasks in a specific sequence.
For example:
2 users try to use an Amazon gift card at the exact time. If multiple workers pick up this task, how do we know not to process the card twice?
We can use mutexes/locks on the db item. Resource is only accessible by one thread at a time.
What is seccomp?
Seccomp is a linux kernel security feature.
It restricts the system calls that can be made. The kernel will terminate/kill/log the process if any other system calls are attempted to be made.
Useful for containers/kubernetes. Can load a seccomp profile preconfigured with allowed/disallowed system calls.
seccomp-bpf is an extension to seccomp that allows filtering of system calls using a configurable policy implemented using Berkeley Packet Filter rules.
What are some security hardening flags?
- Stack protector/canary - Adds runtime checks to detect buffer overflows and stack smashing
- PIC/PIE - for ASLR
- Wformat - Adds compile time checks to detect issues relating to format string arguments in common library functions such as printf, scanf, strftime, etc.
- fortify_source - Adds compile and run time checks to detect buffer overflows in memory and string functions