Post Page Advertisement [Top]



Click here to send WhatsApp On Unsaved Mobile Numbers For Free

 

Ethical Hacking Authentication & Password Security — Login, Hashing, Sessions & Secure Testing | Day 21
Ethical Hacking

🛡️ Ethical Hacking — Day 21

Authentication & Password Security — Login, Hashing, Sessions & Secure Testing

⚠️ LEARNING PURPOSE ONLY: This tutorial is strictly for educational and defensive cybersecurity learning. Perform practical exercises only against your local OWASP Juice Shop lab, applications you own, or systems for which you have explicit authorization. Do not attempt credential attacks against real users, public websites, or production systems.

Welcome to Day 21.

We've covered:

  • Network reconnaissance

  • SQL Injection

  • XSS

  • Burp Suite

  • Web application testing

Today we start another major area of web security:

🔐 Authentication Security

Authentication answers:

"Who are you?"

Authorization answers:

"What are you allowed to do?"

These are different concepts.


🎯 Today's Learning Objectives

By the end of Day 21, you'll understand:

  • Authentication

  • Authorization

  • Login workflows

  • Password storage

  • Password hashing

  • Salting

  • Argon2id

  • bcrypt

  • PBKDF2

  • Why MD5/SHA-256 shouldn't be used for password storage

  • Login request analysis

  • Session cookies

  • Session IDs

  • Session fixation concept

  • Session expiration

  • Logout

  • MFA

  • Rate limiting

  • Account protection

  • Password reset security

  • Secure authentication architecture

  • Linux practical commands

  • Windows practical commands

  • macOS practical commands

  • Burp Suite authentication analysis

OWASP recommends storing passwords with modern adaptive password-hashing algorithms such as Argon2id, bcrypt, or PBKDF2 rather than plaintext or fast general-purpose hashes. (OWASP Cheat Sheet Series)


1. Authentication vs Authorization

Authentication

Username
   +
Password
   ↓
Authentication
   ↓
Who are you?

Authorization

Authenticated User
       ↓
What can you access?

For example:

User
 ├── View profile
 └── View orders

Admin
 ├── View users
 ├── Edit users
 └── Manage system

2. Login Architecture

A typical login system:

Browser
   │
   │ username + password
   ▼
Web Application
   │
   ▼
Authentication Service
   │
   ▼
User Database
   │
   │ password hash
   ▼
Verification
   │
   ▼
Session / Token
   │
   ▼
Browser

3. Passwords Should Never Be Stored as Plaintext

❌ Extremely bad

users
--------------------------------
email       password
--------------------------------
user@test    MyPassword123

If the database is compromised, passwords are immediately exposed.

OWASP explicitly says passwords should never be stored in plaintext. (OWASP Cheat Sheet Series)


4. Hashing vs Encryption

This distinction is very important.

Encryption

Plaintext
   ↓
Encryption
   ↓
Ciphertext
   ↓
Decryption
   ↓
Plaintext

Encryption is reversible with the appropriate key.

Password hashing

Password
   ↓
Password Hash

The application verifies a password by hashing/processing the supplied password using the password-hashing algorithm and comparing it safely with the stored verifier.

Passwords generally should not be stored using reversible encryption. (OWASP Cheat Sheet Series)


5. What Is a Salt?

A salt is a unique random value associated with a password hash.

Conceptually:

Password
    +
Random Salt
    ↓
Password Hash

Two users with the same password should still have different password hashes because their salts differ.

Example:

User A
Password: Hello123
Salt:     random-A
Hash:     hash-A

User B
Password: Hello123
Salt:     random-B
Hash:     hash-B

Modern password-hashing algorithms such as Argon2id and bcrypt handle salting as part of their normal design. (OWASP Cheat Sheet Series)


6. Why Fast Hashes Are Bad for Passwords

You may know:

MD5
SHA-1
SHA-256

These are useful cryptographic primitives for various purposes, but fast general-purpose hashes are not appropriate as password-storage algorithms.

Why?

Because an attacker can perform huge numbers of guesses quickly.

Password hashing should deliberately be computationally expensive.

OWASP recommends adaptive password-hashing algorithms such as Argon2id, with bcrypt or PBKDF2 as alternatives depending on requirements. (OWASP Cheat Sheet Series)


7. Recommended Password Hashing

A simplified hierarchy:

Preferred
   ↓
Argon2id

Alternative
   ↓
scrypt

Legacy/compatibility
   ↓
bcrypt

Specific compliance environments
   ↓
PBKDF2

Don't implement these algorithms yourself.

Use the implementation provided by a trusted framework/library.


8. Argon2id

Argon2id is designed specifically for password hashing.

It deliberately consumes computational resources such as:

Memory
CPU
Time

This makes large-scale password guessing more expensive.

OWASP currently recommends Argon2id as the preferred choice for new password-storage systems. (OWASP Cheat Sheet Series)


9. Password Verification

A login should conceptually work like:

User enters password
       ↓
Password hashing/verifier
       ↓
Compare with stored password verifier
       ↓
Match?
  /       \
YES       NO
 ↓         ↓
Login    Reject

Never do:

SELECT *
FROM users
WHERE password = 'user_password'

with plaintext passwords.


10. Secure Java Example

With Spring Security, don't manually implement password hashing.

For example:

@Bean
PasswordEncoder passwordEncoder() {
    return new Argon2PasswordEncoder(
        16,
        32,
        1,
        19456,
        2
    );
}

The exact parameters should be chosen and benchmarked according to your environment and current security requirements.

Then:

String hash =
    passwordEncoder.encode(password);

and verification:

passwordEncoder.matches(
    password,
    storedHash
);

11. Laravel Example

Laravel provides password hashing support.

Example:

use Illuminate\Support\Facades\Hash;

$hash = Hash::make($password);

Verify:

if (Hash::check($password, $user->password)) {
    // authenticated
}

Don't implement your own password hashing algorithm.


12. PostgreSQL Database

A user table might contain:

users
-------------------------------------
id
email
password
created_at
updated_at

The password field should contain a password hash/verifier, not the user's original password.

Example conceptually:

email:
rohit@example.test

password:
$argon2id$...

The exact stored format depends on the library.


13. Practical Code Review

Look for dangerous patterns.

🚨 Bad

user.setPassword(password);

If password is the raw user password and is stored directly, that's a serious problem.

Better

user.setPassword(
    passwordEncoder.encode(password)
);

14. Another Dangerous Pattern

❌ Don't

$password = md5($request->password);

for password storage.

Also avoid:

hash('sha256', $password);

as your password-storage mechanism.

The issue is not that SHA-256 is "broken."

The issue is that it is designed to be fast, while password hashing should deliberately make guessing expensive.


15. Authentication Request

Let's inspect authentication in our lab.

Start:

http://127.0.0.1:3000

Open:

Burp Suite
 ↓
Proxy
 ↓
Open Browser

Log in using your local Juice Shop test account.


16. Capture Login Request

Open:

Proxy
 ↓
HTTP history

Find the authentication request.

It may resemble:

POST /rest/user/login HTTP/1.1
Host: 127.0.0.1:3000
Content-Type: application/json

with a JSON body.

The exact endpoint can vary by application/version, so use the request actually generated by your local lab.


17. Analyze the Request

Record:

Method:
Endpoint:
Content-Type:
Parameters:
Response:
Set-Cookie:
Token:

Example:

Method:
POST

Content-Type:
application/json

Body:
{
  "email": "...",
  "password": "..."
}

18. Important: Never Share Real Passwords

When documenting your lab:

password:
<REDACTED>

Don't paste:

  • Your real password

  • Production credentials

  • API secrets

  • Session tokens

  • JWTs

  • Recovery codes

into screenshots, reports, or public posts.


19. Login Response

A successful login might return:

HTTP 200

and possibly:

Set-Cookie

or:

Access token

The application then uses that authentication state for subsequent requests.


20. Session Management

Authentication establishes identity.

Session management keeps track of that identity across multiple HTTP requests.

Conceptually:

Login
 ↓
Authentication
 ↓
Session created
 ↓
Session ID
 ↓
Subsequent requests

OWASP describes the session ID as the value binding an authenticated user's session to subsequent HTTP traffic and access controls. (OWASP Cheat Sheet Series)


21. Session Cookie

A server may respond:

Set-Cookie: session=...;

The browser stores it and sends it with later requests.

Conceptually:

Login
 ↓
Session ID
 ↓
Browser Cookie
 ↓
Request
 ↓
Server identifies session

22. Important Cookie Attributes

For sensitive session cookies, look for:

Secure
HttpOnly
SameSite

Secure

Helps ensure the cookie is transmitted only over HTTPS.

HttpOnly

Prevents normal JavaScript APIs from directly reading the cookie.

SameSite

Controls certain cross-site cookie behavior.


23. Session ID Security

A session ID should be:

Random
Unpredictable
Unique
Meaningless

Don't create:

session=12345

or:

session=user123

or:

session=admin

OWASP recommends unpredictable session identifiers and recommends using framework-provided session management where possible. (OWASP Cheat Sheet Series)


24. Don't Put Session IDs in URLs

Avoid:

https://example.com/dashboard?session=abc123

Why?

URLs can leak through:

Browser history
Logs
Referrer headers
Bookmarks
Screenshots
Analytics

OWASP recommends avoiding session IDs in URLs and using appropriate cookie-based mechanisms instead. (OWASP Cheat Sheet Series)


25. Session Fixation

A simplified concept:

Attacker
   ↓
Obtains/sets a session identifier
   ↓
Victim authenticates
   ↓
Same session remains associated

This can allow session abuse.

A key defense is:

Regenerate the session identifier after authentication.

OWASP specifically recommends session ID regeneration after authentication to prevent session fixation. (OWASP Cheat Sheet Series)


26. Session Lifecycle

A secure session has:

Creation
   ↓
Authentication
   ↓
Usage
   ↓
Timeout
   ↓
Logout
   ↓
Destruction

Don't only think about login.

Think about the entire lifecycle.


27. Logout

A secure logout should invalidate the authenticated session server-side.

Conceptually:

Authenticated
     ↓
Logout
     ↓
Session invalidated
     ↓
Old session no longer works

Simply hiding the UI isn't enough.


28. Session Timeout

Sessions shouldn't remain valid forever.

Consider:

Idle timeout
Absolute timeout
Risk-based reauthentication

For sensitive operations, applications may require the user to authenticate again.

OWASP recommends reauthentication after certain high-risk events. (OWASP Cheat Sheet Series)


29. Password Policies

A password policy should encourage strong passwords without creating unnecessary usability problems.

Consider:

Minimum length
Password breach screening
No common passwords
No forced arbitrary periodic changes unless justified
Password manager support
MFA

The exact policy should be based on the application's risk.


30. Rate Limiting

A login endpoint should not accept unlimited authentication attempts.

Conceptually:

Attempt 1 → allowed
Attempt 2 → allowed
Attempt 3 → allowed
...
Too many attempts
      ↓
Slow down / temporary restriction

Rate limiting helps reduce automated password guessing.


31. Important Distinction

Authentication rate limiting

Protects:

Login
Password reset
OTP verification
MFA verification

API rate limiting

Protects:

General API resources
Search
Reports
Expensive operations

They can use different policies.


32. Account Lockout

Permanent account lockout can cause denial-of-service problems.

A better design may combine:

Rate limiting
+
Progressive delays
+
Risk detection
+
Temporary restrictions

The exact mechanism depends on the application.


33. Brute Force — Concept

A brute-force attack attempts many candidate passwords.

Conceptually:

Candidate 1
Candidate 2
Candidate 3
Candidate 4
...

We will not perform password attacks against real accounts.

For learning, your goal is to understand:

How authentication systems detect and prevent excessive attempts.

34. Credential Stuffing

Credential stuffing is different from brute force.

It uses:

Previously leaked username/password combinations

against another service.

The defense includes:

MFA
Rate limiting
Breached-password detection
Bot/risk detection
Strong authentication

Never test leaked credentials against accounts you don't own.


35. MFA

MFA means:

Multi-Factor Authentication

Common factors:

Something you know
    ↓
Password

Something you have
    ↓
Security key / authenticator

Something you are
    ↓
Biometric

MFA significantly strengthens authentication because stealing a password alone may not be sufficient.

OWASP recommends MFA as a strong defense against password-based attacks. (OWASP Cheat Sheet Series)


36. Password Reset Security

Password reset is part of authentication security.

A secure reset token should be:

Random
Unpredictable
Single-use
Short-lived
Stored securely

OWASP recommends secure random reset tokens with appropriate expiration and single-use behavior. (OWASP Cheat Sheet Series)


37. Password Reset Flow

User
 ↓
Forgot Password
 ↓
Email / Side Channel
 ↓
Random Reset Token
 ↓
User opens reset link
 ↓
Token verified
 ↓
New password
 ↓
Old reset token invalidated

38. Don't Reveal Account Existence

A weak system might say:

Email exists!

for one account and:

Email not found!

for another.

This can allow account enumeration.

A better response might be:

If an account exists, instructions will be sent.

Use consistent behavior where appropriate.


39. Practical Lab — Login Request

In your local Juice Shop:

1. Open login page
2. Enter your test credentials
3. Capture request in Burp
4. Send to Repeater
5. Record normal response

Do not perform password spraying or automated credential attacks.


40. Burp Request Analysis

Record:

Method:
Endpoint:
Content-Type:
Authentication parameters:
Response status:
Set-Cookie:
Token:

Then inspect:

Proxy → HTTP history

for requests made after authentication.


41. Compare Before vs After Login

Before login:

GET /profile

might return:

401 Unauthorized

After login:

GET /profile

might return:

200 OK

This demonstrates the relationship:

Authentication State
        ↓
Authorization Decision

42. Session Cookie Exercise

In your browser:

Developer Tools
 ↓
Application / Storage
 ↓
Cookies

Look at your local Juice Shop session cookies.

Record only:

Cookie name:
Secure:
HttpOnly:
SameSite:

Do not copy the actual cookie value into your notes.


43. Linux Practical Session

Check Juice Shop:

docker ps

Check HTTP headers:

curl -I http://127.0.0.1:3000

Verbose HTTP:

curl -v http://127.0.0.1:3000/

Through Burp:

curl -x http://127.0.0.1:8080 \
http://127.0.0.1:3000/

These commands are for your local lab.


44. Windows Practical Session

Check:

docker ps

Headers:

curl.exe -I http://127.0.0.1:3000

Verbose:

curl.exe -v http://127.0.0.1:3000/

Through Burp:

curl.exe -x http://127.0.0.1:8080 `
http://127.0.0.1:3000/

45. macOS Practical Session

docker ps

Headers:

curl -I http://127.0.0.1:3000

Verbose:

curl -v http://127.0.0.1:3000/

Through Burp:

curl -x http://127.0.0.1:8080 \
http://127.0.0.1:3000/

46. Practical Exercise — Password Hashing

Create a simple local learning example.

PHP/Laravel

use Illuminate\Support\Facades\Hash;

$password = 'LabPassword-Only';

$hash = Hash::make($password);

echo $hash;

Verify:

Hash::check($password, $hash);

This demonstrates:

Password
   ↓
Password Hash
   ↓
Stored

Never use your real password for the exercise.


47. Java/Spring Example

Conceptually:

String password = "LabPassword-Only";

String hash =
    passwordEncoder.encode(password);

boolean valid =
    passwordEncoder.matches(
        password,
        hash
    );

You should use your framework's supported password encoder rather than implementing hashing yourself.


48. Password Hashing Experiment

Try:

LabPassword-Only

twice with a proper password-hashing library.

You should see different encoded password hashes/verifiers because modern password hashing uses unique salts.

Conceptually:

Same password
      ↓
Different random salts
      ↓
Different stored hashes

49. What Not to Do

❌ Plaintext

password = LabPassword-Only

stored directly.

❌ MD5

md5(password)

❌ SHA-256 alone

sha256(password)

❌ Homemade algorithm

mySuperSecureHash(password)

✅

Use a trusted password-hashing implementation such as Argon2id, scrypt, bcrypt, or PBKDF2 according to current requirements. (OWASP Cheat Sheet Series)


50. Authentication Security Checklist

Review your application:

☐ Passwords never stored plaintext
☐ Modern password hashing
☐ Unique salts
☐ Secure password verification
☐ Rate limiting
☐ MFA available
☐ Secure password reset
☐ Session IDs unpredictable
☐ Session regenerated after login
☐ Logout invalidates session
☐ Session timeout
☐ Secure cookie
☐ HttpOnly cookie
☐ SameSite cookie
☐ HTTPS
☐ No session IDs in URLs
☐ No sensitive data in tokens
☐ Account enumeration minimized

OWASP's authentication and session-management guidance covers these areas in detail. (OWASP Cheat Sheet Series)


51. Authentication vs Session vs Authorization

Keep these three separate:

AUTHENTICATION
"Who are you?"
        ↓
SESSION
"How does the application remember you?"
        ↓
AUTHORIZATION
"What are you allowed to do?"

Example:

Login
 ↓
Authenticated as Rohit
 ↓
Session created
 ↓
Request /admin
 ↓
Authorization check
 ↓
Allowed / Denied

52. Very Important Security Principle

Never assume:

"I have a valid session,
therefore I can access everything."

The server should perform authorization checks for protected resources.

For example:

GET /users/10

should verify whether the authenticated user is actually allowed to access user 10.


53. IDOR Connection

This leads to another important future topic:

Insecure Direct Object Reference / Broken Access Control

For example:

/users/100

changing to:

/users/101

should not automatically grant access to another user's data.

We'll study access-control vulnerabilities later.


🧪 Day 21 Main Lab Challenge

Use your local Juice Shop.

Part 1 — Authentication

Capture:

Login request
Login response

Record:

Method:
Endpoint:
Content-Type:
Status:
Cookie/token type:

Part 2 — Session

Inspect:

Cookie name:
Secure:
HttpOnly:
SameSite:

Do not record the cookie value.

Part 3 — Logout

Log out.

Repeat a previously authenticated request.

Observe:

Authenticated?
Yes / No

Part 4 — Password Storage

Using a local code example:

Generate password hash
Verify password
Generate same password hash again
Compare outputs

Part 5 — Report

Document:

Finding:
Evidence:
Risk:
Recommendation:

📊 Day 21 Lab Report

╔══════════════════════════════════════╗
║    DAY 21 AUTHENTICATION LAB         ║
╚══════════════════════════════════════╝

Target:
127.0.0.1:3000

Login Endpoint:
________________________

HTTP Method:
________________________

Authentication Type:
________________________

Response Status:
________________________

Session Cookie:
________________________

Secure:
Yes / No / Unknown

HttpOnly:
Yes / No / Unknown

SameSite:
________________________

Session Regenerated:
Yes / No / Unknown

Logout Invalidates Session:
Yes / No / Unknown

Password Hashing:
________________________

MFA:
Yes / No / Unknown

Rate Limiting:
Yes / No / Unknown

Password Reset:
________________________

Potential Finding:
________________________

Evidence:
________________________

Recommendation:
________________________

📝 Day 21 Assignment

Answer these questions:

  1. What is authentication?

  2. What is authorization?

  3. What's the difference between authentication and authorization?

  4. Why shouldn't passwords be stored in plaintext?

  5. What is password hashing?

  6. What is a salt?

  7. Why isn't SHA-256 alone suitable for password storage?

  8. What is Argon2id?

  9. What is bcrypt?

  10. What is PBKDF2?

  11. Why should you use a trusted password-hashing library?

  12. What is a session?

  13. What is a session ID?

  14. What makes a session ID secure?

  15. What does HttpOnly do?

  16. What does Secure do?

  17. What does SameSite do?

  18. What is session fixation?

  19. Why should the session be regenerated after authentication?

  20. Why should login attempts be rate-limited?

  21. What is MFA?

  22. What makes a password-reset token secure?

  23. Why shouldn't session IDs be placed in URLs?

  24. Why is account enumeration a security concern?

  25. Why should logout invalidate the server-side session?


🏆 Day 21 Challenge

Create this security architecture:

                 USER
                   │
                   ▼
             LOGIN FORM
                   │
                   ▼
          HTTPS POST REQUEST
                   │
                   ▼
          AUTHENTICATION SERVER
                   │
            ┌──────┴──────┐
            │             │
       Password        User Record
       Verifier        / Account
            │             │
            └──────┬──────┘
                   ▼
             VERIFY PASSWORD
                   │
             ┌─────┴─────┐
             │           │
           FAIL         SUCCESS
             │           │
             ▼           ▼
           Reject     New Session
                         │
                         ▼
                  Secure Cookie
                         │
                         ▼
                 Authorization
                         │
                   ┌─────┴─────┐
                   │           │
                 Allow        Deny

Then add:

MFA
Rate Limiting
Session Timeout
Password Reset
Audit Logging

🔐 Day 21 Golden Rules

Remember these:

Rule 1

Never store passwords in plaintext.

Rule 2

Use a modern password-hashing algorithm rather than a fast general-purpose hash.

Rule 3

Never build authentication from scratch when your framework provides a mature implementation.

Rule 4

Authentication does not equal authorization.

Rule 5

Protect the entire session lifecycle, not just the login form.

Rule 6

Never test password attacks against accounts or systems you don't own or have permission to assess.


📚 Day 21 Summary

Today you learned:

  • Authentication

  • Authorization

  • Password hashing

  • Salting

  • Argon2id

  • bcrypt

  • PBKDF2

  • Plaintext password risks

  • MD5/SHA-256 password-storage problems

  • Login request analysis

  • Session management

  • Session IDs

  • Session fixation

  • Session timeout

  • Logout

  • Secure cookies

  • HttpOnly

  • Secure

  • SameSite

  • Rate limiting

  • MFA

  • Password reset

  • Account enumeration

  • Linux practical commands

  • Windows practical commands

  • macOS practical commands

  • Burp Suite authentication analysis

  • Java/Spring password handling

  • Laravel password handling

🔑 Most Important Lesson

SECURE AUTHENTICATION
        │
        ├── Strong Password Hashing
        ├── Secure Session Management
        ├── Rate Limiting
        ├── MFA
        ├── Secure Recovery
        └── Proper Authorization

Authentication security isn't just about the login form.

It's the entire identity lifecycle.

OWASP's current authentication, password-storage, and session-management guidance provides the underlying best practices used in today's lesson. (OWASP Cheat Sheet Series)


🔜 Day 22 — Authentication Testing & Session Security Lab

Tomorrow we'll continue with:

  • Burp authentication workflow

  • Login/logout request analysis

  • Session-cookie inspection

  • Session lifecycle

  • Session fixation concepts

  • Authentication error handling

  • Rate-limit observation

  • Password-reset security

  • MFA concepts

  • Secure Java/Spring implementation

  • Laravel authentication security

  • Linux, Windows & macOS practical sessions

  • Writing an authentication-security report

⚠️ LEARNING PURPOSE ONLY: All practical testing remains restricted to your local/authorized lab. No real-user credential attacks or unauthorized authentication testing.

No comments:

Post a Comment

Bottom Ad [Post Page]

rrkksinha.