E5BE GitHub - Vptsh/php-router: Zero Trust secure PHP router, Signed URL router with token replay protection, adaptive bot detection, stealth banning, rate limiting, and detailed access behavior logging. ยท GitHub
[go: up one dir, main page]

Skip to content

Vptsh/php-router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

7 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ›ก Secure Signed PHP Router

Zero-Trust File Access โ€ข Anti-Replay โ€ข Anti-Bot โ€ข Stealth Ban โ€ข Adaptive Security


๐Ÿ“Œ Project Overview

This project is a high-security PHP request router designed to prevent:

  • Direct file access
  • URL tampering
  • Token replay attacks
  • Bot scraping
  • Mass link sharing abuse
  • Path traversal attacks
  • Configuration leaks
  • Automated brute traffic

Instead of allowing users to open files directly, every request must pass cryptographic signature verification + behavioural security checks before content is served.

This router follows a Zero Trust Request Model โ€” every request is treated as potentially hostile until verified.


๐Ÿง  Why This Router Exists

Traditional routing:

user โ†’ /dashboard.php โ†’ file served

Secure signed routing:

user โ†’ signed URL โ†’ router โ†’ security validation โ†’ file served

Attack surface becomes extremely small.


๐Ÿ— Core Security Architecture

Multi-Layer Security Stack

Request
 โ†“
Forbidden Path Filter
 โ†“
Signature Validation
 โ†“
Token Replay Protection
 โ†“
Token Leak Detection
 โ†“
Rate Limiting
 โ†“
Bot Behaviour Scoring
 โ†“
Stealth Ban Check
 โ†“
Secure File Serve

Each layer independently blocks attacks.


๐Ÿ“‚ Project Folder Structure

project-root/

v.php                     โ†’ Main router entry point
error.html                โ†’ Generic error page

.set/
  router_config.php       โ†’ Main configuration

.runtime/
  m.json                  โ†’ Route mapping database
  u.json                  โ†’ Token replay database
  b.json                  โ†’ Bot score database
  r.json                  โ†’ Rate limit database
  k.json                  โ†’ Token leak tracker
  x.json                  โ†’ Stealth banned IP list

  a.log                   โ†’ Access logs
  s.log                   โ†’ Security logs

โš™ Configuration (router_config.php)

This file controls behaviour of entire system.

Example

define('ROUTER_NAME','v.php');
define('SIGN_SECRET','CHANGE_THIS_TO_LONG_RANDOM_SECRET');
define('SIGNED_TTL',300);
define('LOG_DEDUPE_WINDOW',5);

๐Ÿ” SIGN_SECRET

Used for:

  • URL signature generation
  • Tamper detection

If changed:

  • All existing signed URLs instantly become invalid

Use:

  • 64+ random characters
  • Never commit real secret to public repo

โณ SIGNED_TTL

Controls signed URL lifetime.

Value Behaviour
60 sec Ultra secure
300 sec Balanced (recommended)
600+ sec High performance / CDN

๐Ÿงพ LOG_DEDUPE_WINDOW

Prevents repeated identical log spam.


๐Ÿ”’ Security Constants (Router File)


Rate Limiting

RATE_LIMIT_MAX = 40
RATE_LIMIT_WINDOW = 60 seconds

Meaning: Maximum 40 suspicious events per minute per IP.


Token Replay Window

TOKEN_REPLAY_WINDOW = 7200 seconds

Token valid for 2 hours maximum.


Bot Detection Base Score

BOT_SCORE_BASE = 60

Adaptive threshold adjusts dynamically based on traffic behaviour.


Stealth Ban Time

STEALTH_BAN_TIME = 900 seconds

IP silently blocked for 15 minutes.

Returns fake 404 to avoid attacker detection.


๐Ÿ—„ Runtime Database System

Router uses JSON files instead of SQL for speed and portability.


u.json โ†’ Token Replay Database

Tracks:

  • Token signature
  • IP used
  • Session used
  • Refresh count
  • Expiry time

Prevents:

  • Link sharing abuse
  • Mass replay attacks

b.json โ†’ Bot Score Database

Stores per-IP behaviour score.

Score increases when:

  • Invalid signature
  • Replay attempt
  • Token leak detected

r.json โ†’ Rate Limit Database

Stores timestamp list of suspicious actions per IP.


k.json โ†’ Token Leak Tracker

Tracks how many unique IPs use same token.

If > 5 โ†’ suspicious.


x.json โ†’ Stealth Ban List

Stores banned IP + expiry time.


๐Ÿงน Automatic Database Cleaning

Old entries automatically deleted:

File Lifetime
u.json 24 hours
k.json 7 days
b.json 14 days
r.json 1 hour

Prevents storage growth.


๐Ÿ‘ค Visitor Identity System

Each session receives unique visitor ID:

VIS-XXXXXX

Used for:

  • Behaviour tracking
  • Log correlation
  • Session pattern analysis

๐ŸŒ Network Intelligence System

Router collects:

  • Country
  • City
  • ISP
  • VPN detection
  • Hosting detection
  • Mobile network detection

Cached for 24 hours per session for performance.


๐Ÿ”‘ Signed URL Security Model

Signed URL contains:

id   โ†’ route ID
exp  โ†’ expiry timestamp
router โ†’ router filename
sig  โ†’ HMAC signature

Signature Generation Logic

1. Sort parameters
2. Build query string
3. Generate HMAC SHA256 using SIGN_SECRET

If any parameter is modified โ†’ signature mismatch.


๐Ÿ”„ Token Replay Protection

Each token:

โœ” Bound to IP
โœ” Bound to session
โœ” Allows limited refresh
โœ” Expires automatically

If used from different IP โ†’ blocked.


๐Ÿงฌ Token Leak Detection

If same signed token used by multiple IPs:

Score increases โ†’ eventually blocked.

Prevents:

  • Telegram link sharing
  • Public forum link posting
  • Scraper distribution

๐Ÿค– Bot Scoring Engine

Each suspicious behaviour adds points.

Example:

Action Score
Invalid signature +10
Replay attempt +15
Token leak +20

Adaptive threshold increases if bot traffic increases.


๐Ÿ‘ป Stealth Ban System

Instead of blocking normally:

Returns:

404 Not Found

Attacker thinks resource missing, not blocked.


๐Ÿงญ Route Mapping System

Stored in:

.runtime/m.json

Example:

{
 "0": "index.html",
 "a92bd1": "dashboard.php"
}

Auto Mapping

If user accesses:

/dashboard.php

Router automatically:

  1. Generates route ID
  2. Stores mapping
  3. Redirects to signed URL

๐Ÿ“Š Logging System


Access Log (a.log)

Tracks:

  • Visitor ID
  • Route ID
  • Access Type
  • Original URL
  • Final Signed URL
  • Device
  • Network type

Security Log (s.log)

Tracks:

  • Attack type
  • Exact URL
  • IP
  • Device
  • ISP
  • Country
  • Reason for block

๐Ÿง  Access Behaviour Classification

Router classifies traffic:

Type Meaning
USER_ACTION Normal navigation
AUTO_BROWSER Reload or resource load
BACKGROUND_FETCH AJAX or silent request
REDIRECT_CHAIN Multi redirect flow
SESSION_EXPIRE Session timeout redirect

Useful for analytics + bot detection.


๐Ÿ›ก Attack Protection Coverage


Replay Attack

Protected using token usage tracking.


URL Tampering

Blocked using HMAC signature verification.


Brute Force Requests

Rate limiting + bot scoring.


Path Traversal

Blocked using realpath directory enforcement.


Config File Exposure

Blocked using forbidden path filters.


Bot Crawling

Adaptive scoring system blocks suspicious behaviour.


๐Ÿš€ Performance Optimizations

  • Session caching for IP intelligence
  • JSON lazy cleaning
  • Log deduplication
  • Smart 2-second router dedupe
  • No database overhead

โš™ Behaviour Tuning Profiles


๐Ÿ”’ High Security Mode

SIGNED_TTL = 120
RATE_LIMIT_MAX = 20
BOT_SCORE_BASE = 40

โš– Balanced Mode (Recommended)

SIGNED_TTL = 300
RATE_LIMIT_MAX = 40
BOT_SCORE_BASE = 60

โšก High Performance Mode

SIGNED_TTL = 600
RATE_LIMIT_MAX = 80
BOT_SCORE_BASE = 80

๐Ÿ”ง Installation


Step 1

Clone repository.


Step 2

Create runtime folder:

mkdir .runtime
chmod 777 .runtime

Step 3

Create config file:

.set/router_config.php

Step 4

Set strong SIGN_SECRET.


Step 5

Point web root to router location.


โ˜ Production Deployment Recommendations


With Cloudflare

Enable:

  • Bot Fight Mode
  • Rate Limiting Rules
  • WAF protection

With Nginx

Disable direct PHP execution except router.


With Apache

Use:

Options -Indexes

๐Ÿ”ฎ Future Upgrade Ideas

  • Redis memory token store
  • JWT token replacement
  • Machine learning bot detection
  • Device fingerprint scoring
  • Behaviour anomaly detection
  • Real time threat dashboard

๐Ÿ“œ License

MIT License


๐Ÿ‘จโ€๐Ÿ’ป Author Philosophy

This router is built on:

  • Security first design
  • Minimal trust surface
  • Behaviour driven blocking
  • Low infrastructure dependency
  • High portability

โญ Contributing

Pull requests are welcome. For major changes, open an issue first to discuss what you would like to change.


โค๏ธ Acknowledgement

Built with focus on real-world attack patterns and practical defence strategies.

About

Zero Trust secure PHP router, Signed URL router with token replay protection, adaptive bot detection, stealth banning, rate limiting, and detailed access behavior logging.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

0