Merge remote-tracking branch 'origin/main'
This commit is contained in:
+167
-119
@@ -1,55 +1,54 @@
|
|||||||
# BruteForce — Demo Project
|
# BruteForce — Demo Project
|
||||||
|
|
||||||
> Small educational demo showing a tiny login backend, simple frontend, and several local-only attack/defense experiments.
|
> Small educational demo showing a minimal login backend, basic frontend, and **five** brute-force attack scripts for safe, local testing and security education.
|
||||||
|
|
||||||
> **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.
|
> **This is for educational use only. Never attack systems without explicit permission.**
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Table of contents
|
## Table of contents
|
||||||
|
|
||||||
* [Overview](#overview)
|
- [Overview](#overview)
|
||||||
* [Prerequisites](#prerequisites)
|
- [Prerequisites](#prerequisites)
|
||||||
* [Install](#install)
|
- [Install](#install)
|
||||||
* [Project structure](#project-structure)
|
- [Project structure](#project-structure)
|
||||||
* [Expected `users.json` formats](#expected-usersjson-formats)
|
- [Expected `users.json` formats](#expected-usersjson-formats)
|
||||||
* [Run the demo server (naive login)](#run-the-demo-server-naive-login)
|
- [Run the demo server](#run-the-demo-server)
|
||||||
* [Create users (plaintext and bcrypt)](#create-users-plaintext-and-bcrypt)
|
- [Create users](#create-users)
|
||||||
* [Safe testing — local simulation (recommended)](#safe-testing--local-simulation-recommended)
|
- [Safe testing (recommended)](#safe-testing-recommended)
|
||||||
* [Attacks folder — ethical warning](#attacks-folder--ethical-warning)
|
- [Attack scripts](#attack-scripts)
|
||||||
* [Security & Ethics (must read)](#security--ethics-must-read)
|
- [Security & Ethics (must read)](#security--ethics-must-read)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Overview
|
## Overview
|
||||||
|
|
||||||
This repository demonstrates:
|
This project demonstrates:
|
||||||
|
|
||||||
* a minimal Express login server (naive password check)
|
- A minimal Express-based login backend
|
||||||
* a simple static frontend (`index.html`) that posts login credentials
|
- A static frontend with form-based login
|
||||||
* educational scripts showing brute-force concepts, dictionary mutations and a *local-only* simulation harness for safe demonstrations
|
- Five Node.js scripts simulating brute-force/dictionary/rainbow attacks
|
||||||
* suggestions and code examples for defensive measures (rate limiting, progressive delay, lockout, bcrypt)
|
- Local-only and safe multi-instance testing
|
||||||
|
- User/password storage in plaintext and bcrypt
|
||||||
This is intended for classroom use only.
|
- Clear separation between demo functionality and security attack simulation
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|
||||||
* Node.js (v14+ recommended) and `npm`
|
- Node.js (v14+)
|
||||||
* Terminal / command line
|
- `npm`
|
||||||
|
- Terminal (or PowerShell)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Install
|
## Install
|
||||||
|
|
||||||
Clone or copy the repository, then install dependencies:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm install
|
npm install
|
||||||
```
|
````
|
||||||
|
|
||||||
If additional packages are required by specific scripts (e.g. `node-fetch`, `bcryptjs`, `express-rate-limit`, `morgan`), install them as needed:
|
If missing packages cause errors, install them explicitly:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
npm install bcryptjs node-fetch express express-rate-limit morgan fs-extra
|
npm install bcryptjs node-fetch express express-rate-limit morgan fs-extra
|
||||||
@@ -61,157 +60,206 @@ npm install bcryptjs node-fetch express express-rate-limit morgan fs-extra
|
|||||||
|
|
||||||
```
|
```
|
||||||
BruteForce/
|
BruteForce/
|
||||||
├─ .idea/
|
|
||||||
├─ attacks/
|
├─ attacks/
|
||||||
│ ├─ crack.js
|
│ ├─ crack.js # Mono charset brute force
|
||||||
│ ├─ crack2.js
|
│ ├─ crack2.js # Dictionary + mutations
|
||||||
│ └─ dictionary.txt
|
│ ├─ crack3.js # Rainbow table
|
||||||
├─ docs/
|
│ ├─ crack4.js # Parallel brute force
|
||||||
│ └─ README.md <- (this file)
|
│ ├─ crack5.js # Hybrid attack framework
|
||||||
|
│ ├─ dictionary.txt
|
||||||
|
│ ├─ rainbow_table.json
|
||||||
|
│ └─ wordlist.txt
|
||||||
├─ public/
|
├─ public/
|
||||||
│ ├─ Backend.js <- naive Express server
|
│ ├─ Backend.js # Express server
|
||||||
│ └─ index.html <- simple login page
|
│ └─ index.html # Login form
|
||||||
├─ TEST_DATA/
|
├─ TEST_DATA/
|
||||||
│ └─ users.json
|
│ └─ users.json
|
||||||
├─ package.json
|
├─ docs/
|
||||||
└─ package-lock.json
|
│ └─ README.md # This file
|
||||||
|
└─ package.json
|
||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Expected `users.json` formats
|
## 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 structure:
|
||||||
|
|
||||||
**Preferred (object with `users` array):**
|
|
||||||
|
|
||||||
```json
|
```json
|
||||||
{
|
{
|
||||||
"users": [
|
"users": [
|
||||||
{ "username": "test", "password": "test" }
|
{ "username": "alice", "password": "plaintext" },
|
||||||
|
{ "username": "bob", "passwordHash": "$2a$10$..." }
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
**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)
|
## Run the demo server
|
||||||
|
|
||||||
> This demo server reads `TEST_DATA/users.json`. By default the example server is intentionally minimal.
|
|
||||||
|
|
||||||
Start the server:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
node public/Backend.js
|
node public/Backend.js
|
||||||
```
|
```
|
||||||
|
|
||||||
Open the demo frontend in your browser:
|
Visit: `http://localhost:3000/login`
|
||||||
|
|
||||||
```
|
|
||||||
http://localhost:3000/login
|
|
||||||
```
|
|
||||||
|
|
||||||
The page sends a JSON `POST`:
|
|
||||||
|
|
||||||
```json
|
|
||||||
{ "username": "test", "password": "test" }
|
|
||||||
```
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Create users
|
## Create users
|
||||||
|
|
||||||
### Plaintext users (demo only)
|
### Option 1: Plaintext (demo only)
|
||||||
|
|
||||||
Edit `TEST_DATA/users.json` and add user objects in the expected format.
|
Edit `users.json` manually.
|
||||||
|
|
||||||
**Warning:** Do **not** store plaintext passwords in production.
|
### Option 2: Hashed (recommended)
|
||||||
|
|
||||||
### Bcrypt (preferred for demos)
|
|
||||||
|
|
||||||
Generate a bcrypt hash and store it as `passwordHash`:
|
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
node -e "const bcrypt=require('bcryptjs');(async(p)=>console.log(await bcrypt.hash(p,10)))(process.argv[1]) S3cret!"
|
node -e "const bcrypt=require('bcryptjs');(async(p)=>console.log(await bcrypt.hash(p,10)))(process.argv[1])" "S3cret!"
|
||||||
```
|
```
|
||||||
|
|
||||||
Then in `users.json`:
|
Then insert the hash into `users.json` under `passwordHash`.
|
||||||
|
|
||||||
```json
|
|
||||||
{
|
|
||||||
"users": [
|
|
||||||
{ "username": "alice", "passwordHash": "$2a$10$..." }
|
|
||||||
]
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
If your server code performs `bcrypt.compare`, it will validate hashed passwords.
|
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Safe testing — local simulation (recommended)
|
## Safe testing (recommended)
|
||||||
|
|
||||||
To explore brute-force behavior **safely**, use a local simulation harness that calls the login logic in-process (no network requests). This demonstrates:
|
All attacks simulate authentication attempts **locally** and do not target remote systems.
|
||||||
|
|
||||||
* progressive delay (server-side slowing)
|
---
|
||||||
* account lockout after repeated failures
|
|
||||||
* performance metrics (attempts/s) against a local hash
|
|
||||||
|
|
||||||
Example usage:
|
## Attack Scripts
|
||||||
|
|
||||||
|
### 1. `crack.js` – Mono-Zeichensatz Brute Force
|
||||||
|
|
||||||
|
**Simulates:**
|
||||||
|
|
||||||
|
* Pure brute force using a restricted character set (`digits`, `lower`, `upper`)
|
||||||
|
* Exhaustive search up to configurable length
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
node crack.js <username> <charset> <maxlen>
|
node crack.js <username> <charset> <maxlen>
|
||||||
# e.g.
|
|
||||||
node crack.js test digits 4
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
node crack2.js <username> <maxlen>
|
node crack.js alice digits 4
|
||||||
# e.g.
|
|
||||||
node crack2.js test 4
|
|
||||||
```
|
```
|
||||||
|
|
||||||
```bash
|
|
||||||
node crack3.js <username> <mode>
|
|
||||||
# e.g.
|
|
||||||
node crack3.js test rainbow
|
|
||||||
```
|
|
||||||
|
|
||||||
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
|
### 2. `crack2.js` – Dictionary + Mutation Attack
|
||||||
|
|
||||||
The `attacks/` folder contains example scripts that illustrate:
|
**Simulates:**
|
||||||
|
|
||||||
* candidate generation (charset iteration)
|
* Dictionary-based password guessing
|
||||||
* dictionary mutation techniques
|
* Case variants, common suffixes, and leetspeak
|
||||||
* rainbow table hash generation
|
* Limited to local dictionary and mutation rules
|
||||||
|
|
||||||
**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.
|
```bash
|
||||||
|
node crack2.js <username> <maxlen>
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 3. `crack3.js` – Rainbow Table
|
||||||
|
|
||||||
|
**Simulates:**
|
||||||
|
|
||||||
|
* Use of precomputed hash-password maps
|
||||||
|
* Includes script for building a rainbow table from a dictionary
|
||||||
|
|
||||||
|
```bash
|
||||||
|
node crack3.js <username> rainbow
|
||||||
|
node crack3.js <username> create # To build rainbow table
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 4. `crack4.js` – Parallel Brute Force
|
||||||
|
|
||||||
|
**Simulates:**
|
||||||
|
|
||||||
|
* Brute-force attack split across multiple instances
|
||||||
|
* Each instance works on a portion of the keyspace
|
||||||
|
|
||||||
|
```bash
|
||||||
|
node crack4.js <username> bruteforce <instanceId> <totalInstances>
|
||||||
|
```
|
||||||
|
|
||||||
|
Example (Instance 2 of 4):
|
||||||
|
|
||||||
|
```bash
|
||||||
|
node crack4.js alice bruteforce 1 4
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### 5. `crack5.js` – Hybrid Framework (Full Simulation Suite)
|
||||||
|
|
||||||
|
**Simulates:**
|
||||||
|
|
||||||
|
* Dictionary + Rainbow + Brute-force
|
||||||
|
* Multi-instance parallelism
|
||||||
|
* Shared state file to halt on success
|
||||||
|
* Tracks stats, request speed, response time, success/failure logs
|
||||||
|
* Also supports username enumeration
|
||||||
|
|
||||||
|
```bash
|
||||||
|
node crack5.js <username> <mode> <instanceId> <totalInstances>
|
||||||
|
```
|
||||||
|
|
||||||
|
Modes:
|
||||||
|
|
||||||
|
* `dictionary`
|
||||||
|
* `bruteforce`
|
||||||
|
* `rainbow`
|
||||||
|
* `create-table`
|
||||||
|
* `enumerate`
|
||||||
|
* `hybrid` (dictionary → brute-force)
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
node crack5.js admin hybrid 0 4
|
||||||
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
## Security & Ethics (must read)
|
## Security & Ethics (must read)
|
||||||
|
|
||||||
* These materials are for **educational** purposes only.
|
> **DO NOT** use any attack scripts against systems you do not own.
|
||||||
* 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.
|
* These tools are **for learning and classroom use only**
|
||||||
* Prefer the local simulation or secure test-mode endpoint for demonstrations and grading.
|
* Use only against the demo server or authorized systems
|
||||||
* Remove any test credentials and disable test endpoints after you finish.
|
* Violating ethical guidelines or legal boundaries may lead to severe consequences
|
||||||
|
* When in doubt, ask for explicit permission before testing
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## PowerShell: Launch Parallel Instances (Example)
|
||||||
|
|
||||||
|
```powershell
|
||||||
|
$WorkingDir = "C:\Users\your_username\your_project_folder\BruteForce\attacks" #
|
||||||
|
|
||||||
|
for ($i = 0; $i -lt 10; $i++) {
|
||||||
|
$cmd = "Set-Location -Path `"$WorkingDir`"; node crack5.js test hybrid $i 10"
|
||||||
|
Start-Process powershell -ArgumentList "-NoExit", "-Command", $cmd
|
||||||
|
Start-Sleep -Milliseconds 100
|
||||||
|
}
|
||||||
|
```
|
||||||
|
Execute powershell script locally:
|
||||||
|
```
|
||||||
|
powershell -ExecutionPolicy Bypass -File "C:\Users\your_username\your_project_folder\BruteForce\attacks\open_10_terminals_windows.ps1"
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## ✅ Final Notes
|
||||||
|
|
||||||
|
* `crack5.js` is the most advanced and recommended for robust demos
|
||||||
|
* Use the naive server (`Backend.js`) for all testing
|
||||||
|
* Monitor server logs and browser output during attacks
|
||||||
|
|
||||||
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user