Update README.md

This commit is contained in:
2025-09-26 15:59:58 +02:00
committed by GitHub
parent 0ed8c701ac
commit 43c8a6b34e
+259 -2
View File
@@ -1,2 +1,259 @@
# BruteForce # BruteForce — Demo & Teaching Project
A Test Application to test Brute Force Attacks and Defenses
> 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 <username> <charset> <maxlen> [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: <secret>` 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.