From 43c8a6b34e57303d8a45bf9a9cf57ad490815060 Mon Sep 17 00:00:00 2001 From: Fretux Date: Fri, 26 Sep 2025 15:59:58 +0200 Subject: [PATCH 1/6] Update README.md --- docs/README.md | 261 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 259 insertions(+), 2 deletions(-) diff --git a/docs/README.md b/docs/README.md index 6f7a58f..9a527a9 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,2 +1,259 @@ -# BruteForce -A Test Application to test Brute Force Attacks and Defenses +# BruteForce — Demo & Teaching Project + +> Small educational demo showing a tiny login backend, simple frontend, and several local-only attack/defense experiments. + +> **Important:** This repository is for learning **only**. Do **not** use the included attack scripts against systems you do not own or explicitly have written permission to test. See **Safety & Ethics** below. + +--- + +## Table of contents + +* [Overview](#overview) +* [Prerequisites](#prerequisites) +* [Install](#install) +* [Project structure](#project-structure) +* [Expected `users.json` formats](#expected-usersjson-formats) +* [Run the demo server (naive login)](#run-the-demo-server-naive-login) +* [Create users (plaintext and bcrypt)](#create-users-plaintext-and-bcrypt) +* [Safe testing — local simulation (recommended)](#safe-testing--local-simulation-recommended) +* [Attacks folder — ethical warning](#attacks-folder--ethical-warning) +* [Responsible testing of rate-limiting / lockouts](#responsible-testing-of-rate-limiting--lockouts) +* [Useful commands / examples](#useful-commands--examples) +* [Security & Ethics (must read)](#security--ethics-must-read) +* [License](#license) + +--- + +## Overview + +This repository demonstrates: + +* a minimal Express login server (naive password check) +* a simple static frontend (`index.html`) that posts login credentials +* educational scripts showing brute-force concepts, dictionary mutations and a *local-only* simulation harness for safe demonstrations +* suggestions and code examples for defensive measures (rate limiting, progressive delay, lockout, bcrypt) + +This is intended for classroom or lab use only. + +--- + +## Prerequisites + +* Node.js (v14+ recommended) and `npm` +* Terminal / command line + +--- + +## Install + +Clone or copy the repository, then install dependencies: + +```bash +npm install +``` + +If additional packages are required by specific scripts (e.g. `node-fetch`, `bcryptjs`, `express-rate-limit`, `morgan`), install them as needed: + +```bash +npm install bcryptjs node-fetch express express-rate-limit morgan fs-extra +``` + +--- + +## Project structure + +``` +BruteForce/ +├─ .idea/ +├─ attacks/ +│ ├─ crack.js +│ ├─ crack2.js +│ └─ dictionary.txt +├─ docs/ +│ └─ README.md <- (this file) +├─ public/ +│ ├─ Backend.js <- naive Express server +│ └─ index.html <- simple login page +├─ TEST_DATA/ +│ └─ users.json +├─ package.json +└─ package-lock.json +``` + +--- + +## Expected `users.json` formats + +The code in this repo expects one of the following formats. If scripts report `USER_NOT_FOUND`, check your JSON shape. + +**Preferred (object with `users` array):** + +```json +{ + "users": [ + { "username": "test", "password": "test" } + ] +} +``` + +**Alternate (array of users):** + +```json +[ + { "username": "test", "password": "test" }, + { "username": "alice", "passwordHash": "$2a$10$..." } +] +``` + +Fields used by scripts: + +* `username` — string +* `password` — plaintext (demo only) +* `passwordHash` — bcrypt hash (recommended for demo realism) + +--- + +## Run the demo server (naive login) + +> This demo server reads `TEST_DATA/users.json`. By default the example server is intentionally minimal. + +Start the server: + +```bash +node public/Backend.js +# or +node server.js +``` + +Open the demo frontend in your browser: + +``` +http://localhost:3000/login +``` + +The page sends a JSON `POST`: + +```json +{ "username": "test", "password": "test" } +``` + +--- + +## Create users + +### Plaintext users (demo only) + +Edit `TEST_DATA/users.json` and add user objects in the expected format. + +**Warning:** Do **not** store plaintext passwords in production. + +### Bcrypt (preferred for demos) + +Generate a bcrypt hash and store it as `passwordHash`: + +Example (Node one-liner): + +```bash +node -e "const bcrypt=require('bcryptjs');(async(p)=>console.log(await bcrypt.hash(p,10)))(process.argv[1]) S3cret!" +``` + +Then in `users.json`: + +```json +{ + "users": [ + { "username": "alice", "passwordHash": "$2a$10$..." } + ] +} +``` + +If your server code performs `bcrypt.compare`, it will validate hashed passwords. + +--- + +## Safe testing — local simulation (recommended) + +To explore brute-force behavior **safely**, use a local simulation harness that calls the login logic in-process (no network requests). This demonstrates: + +* progressive delay (server-side slowing) +* account lockout after repeated failures +* performance metrics (attempts/s) against a local hash + +A recommended script name: `crack_sim_local.js`. Example usage: + +```bash +node crack_sim_local.js [users.json] +# e.g. +node crack_sim_local.js test digits 4 TEST_DATA/users.json +``` + +This approach is safe for demonstrations and class assignments because it does not send guesses over the network to external targets. + +--- + +## `attacks/` folder — ethical warning + +The `attacks/` folder contains example scripts that illustrate: + +* candidate generation (charset iteration) +* dictionary mutation techniques + +**Important:** Those scripts are for educational analysis only. **Do not** run them against remote systems you do not own or have explicit permission to test. If you must test an HTTP endpoint on your own server, use one of the responsible test patterns described below. + +--- + +## Responsible testing of rate-limiting / lockouts + +If you need to validate how your server responds to repeated attempts: + +1. **Prefer local simulation** (no network). + +2. Or add a **secure test-mode endpoint** to your server: + + * Enabled only in non-production/test mode (`TEST_MODE` env var). + * Requires a secret header, e.g. `x-test-token: ` set via env var. + * Bound to `127.0.0.1` only. + * Has strict rate-limiting and logging. + * Remove or disable after testing. + +3. Log all test activity and audit after tests. + +I can help you implement a secure test-mode endpoint if needed. + +--- + +## Useful commands / examples + +Install deps: + +```bash +npm install +``` + +Start server: + +```bash +node public/Backend.js +``` + +Run local simulation (example): + +```bash +node crack_sim_local.js test digits 4 TEST_DATA/users.json +``` + +Generate bcrypt hash: + +```bash +node -e "const bcrypt=require('bcryptjs');(async(p)=>console.log(await bcrypt.hash(p,10)))(process.argv[1]) S3cret!" +``` + +--- + +## Security & Ethics (must read) + +* These materials are for **educational** purposes only. +* Creating or running automated tools that attempt to access systems without authorization is illegal in many jurisdictions and ethically wrong. +* Never use the attack scripts on systems you do not own or explicitly have permission to test. +* Prefer the local simulation or secure test-mode endpoint for demonstrations and grading. +* Remove any test credentials and disable test endpoints after you finish. From 11ff2f5f0a7ffe28346cb4b0a1bb1b10a2b4fbae Mon Sep 17 00:00:00 2001 From: Fretux Date: Fri, 26 Sep 2025 16:00:27 +0200 Subject: [PATCH 2/6] Update README.md --- docs/README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 9a527a9..4e5ee13 100644 --- a/docs/README.md +++ b/docs/README.md @@ -20,7 +20,6 @@ * [Responsible testing of rate-limiting / lockouts](#responsible-testing-of-rate-limiting--lockouts) * [Useful commands / examples](#useful-commands--examples) * [Security & Ethics (must read)](#security--ethics-must-read) -* [License](#license) --- From 951607824fb37d412e68e9364fc71245d253f2e9 Mon Sep 17 00:00:00 2001 From: Fretux Date: Fri, 26 Sep 2025 16:05:36 +0200 Subject: [PATCH 3/6] Update README.md --- docs/README.md | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/docs/README.md b/docs/README.md index 4e5ee13..40e570f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -120,8 +120,6 @@ Start the server: ```bash node public/Backend.js -# or -node server.js ``` Open the demo frontend in your browser: @@ -150,8 +148,6 @@ Edit `TEST_DATA/users.json` and add user objects in the expected format. Generate a bcrypt hash and store it as `passwordHash`: -Example (Node one-liner): - ```bash node -e "const bcrypt=require('bcryptjs');(async(p)=>console.log(await bcrypt.hash(p,10)))(process.argv[1]) S3cret!" ``` @@ -178,12 +174,18 @@ To explore brute-force behavior **safely**, use a local simulation harness that * account lockout after repeated failures * performance metrics (attempts/s) against a local hash -A recommended script name: `crack_sim_local.js`. Example usage: +Example usage: ```bash -node crack_sim_local.js [users.json] +node crack.js # e.g. -node crack_sim_local.js test digits 4 TEST_DATA/users.json +node crack.js test digits 4 +``` + +```bash +node crack2.js +# e.g. +node crack2.js test 4 ``` This approach is safe for demonstrations and class assignments because it does not send guesses over the network to external targets. From 76142d6be81e4ddfddaae7b32a1f61ff34e1bb5d Mon Sep 17 00:00:00 2001 From: Fretux Date: Fri, 26 Sep 2025 18:38:47 +0200 Subject: [PATCH 4/6] Update README.md --- docs/README.md | 33 ++------------------------------- 1 file changed, 2 insertions(+), 31 deletions(-) diff --git a/docs/README.md b/docs/README.md index 40e570f..ea579ce 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,4 +1,4 @@ -# BruteForce — Demo & Teaching Project +# BruteForce — Demo Project > Small educational demo showing a tiny login backend, simple frontend, and several local-only attack/defense experiments. @@ -18,7 +18,6 @@ * [Safe testing — local simulation (recommended)](#safe-testing--local-simulation-recommended) * [Attacks folder — ethical warning](#attacks-folder--ethical-warning) * [Responsible testing of rate-limiting / lockouts](#responsible-testing-of-rate-limiting--lockouts) -* [Useful commands / examples](#useful-commands--examples) * [Security & Ethics (must read)](#security--ethics-must-read) --- @@ -32,7 +31,7 @@ This repository demonstrates: * educational scripts showing brute-force concepts, dictionary mutations and a *local-only* simulation harness for safe demonstrations * suggestions and code examples for defensive measures (rate limiting, progressive delay, lockout, bcrypt) -This is intended for classroom or lab use only. +This is intended for classroom use only. --- @@ -223,34 +222,6 @@ I can help you implement a secure test-mode endpoint if needed. --- -## Useful commands / examples - -Install deps: - -```bash -npm install -``` - -Start server: - -```bash -node public/Backend.js -``` - -Run local simulation (example): - -```bash -node crack_sim_local.js test digits 4 TEST_DATA/users.json -``` - -Generate bcrypt hash: - -```bash -node -e "const bcrypt=require('bcryptjs');(async(p)=>console.log(await bcrypt.hash(p,10)))(process.argv[1]) S3cret!" -``` - ---- - ## Security & Ethics (must read) * These materials are for **educational** purposes only. From 414fbe8db8e04087b198d09e84b0cbd5e2f6241b Mon Sep 17 00:00:00 2001 From: Fretux Date: Fri, 26 Sep 2025 18:39:24 +0200 Subject: [PATCH 5/6] Update README.md --- docs/README.md | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/docs/README.md b/docs/README.md index ea579ce..6d9a0d7 100644 --- a/docs/README.md +++ b/docs/README.md @@ -17,7 +17,6 @@ * [Create users (plaintext and bcrypt)](#create-users-plaintext-and-bcrypt) * [Safe testing — local simulation (recommended)](#safe-testing--local-simulation-recommended) * [Attacks folder — ethical warning](#attacks-folder--ethical-warning) -* [Responsible testing of rate-limiting / lockouts](#responsible-testing-of-rate-limiting--lockouts) * [Security & Ethics (must read)](#security--ethics-must-read) --- @@ -202,26 +201,6 @@ The `attacks/` folder contains example scripts that illustrate: --- -## Responsible testing of rate-limiting / lockouts - -If you need to validate how your server responds to repeated attempts: - -1. **Prefer local simulation** (no network). - -2. Or add a **secure test-mode endpoint** to your server: - - * Enabled only in non-production/test mode (`TEST_MODE` env var). - * Requires a secret header, e.g. `x-test-token: ` set via env var. - * Bound to `127.0.0.1` only. - * Has strict rate-limiting and logging. - * Remove or disable after testing. - -3. Log all test activity and audit after tests. - -I can help you implement a secure test-mode endpoint if needed. - ---- - ## Security & Ethics (must read) * These materials are for **educational** purposes only. From ffe3cbd4487471b7127c7a3824a31e946c56dd6f Mon Sep 17 00:00:00 2001 From: Fretux Date: Fri, 26 Sep 2025 19:51:44 +0200 Subject: [PATCH 6/6] Update README.md --- docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/README.md b/docs/README.md index 6d9a0d7..a49ead7 100644 --- a/docs/README.md +++ b/docs/README.md @@ -197,7 +197,7 @@ The `attacks/` folder contains example scripts that illustrate: * candidate generation (charset iteration) * dictionary mutation techniques -**Important:** Those scripts are for educational analysis only. **Do not** run them against remote systems you do not own or have explicit permission to test. If you must test an HTTP endpoint on your own server, use one of the responsible test patterns described below. +**Important:** Those scripts are for educational analysis only. **Do not** run them against remote systems you do not own or have explicit permission to test. ---