Practical Journal

Documentation of the experiment: theory, method, algorithm and expected observations.

1. Aim

To design and implement an intrusion detection system with a lightweight web application firewall that inspects incoming HTTP requests, detects common web attacks using signature-based rules and behavioural analysis, decides an action (allow, monitor, block or rate-limit), logs every decision and raises alerts for high-risk events.

2. Theory

  • IDS vs WAF — an IDS observes and reports; a WAF sits inline and can reject the request. SentinelShield does both: it logs everything and blocks when confidence is high.
  • Signature detection — regular expressions match known malicious patterns (e.g. ' OR 1=1, <script>, ../).
  • Normalisation — payloads are URL-decoded twice, lower-cased and whitespace-collapsed so encoded attacks cannot evade the rules.
  • Behavioural analysis — per-IP counters detect scanning, bursts and repeated failures even when no signature matches.
  • Rate limiting — a fixed window counter limits requests per IP and temporarily blocks abusive sources.

3. Architecture

Client / attacker
      |
      v
[ Request Inspection ]  normalise URL, query, body, headers
      |
      v
[ Rule Engine ]  regex signatures  ->  attack type + confidence
      |
      v
[ Behaviour Analysis ]  per-IP counters, scanning, bursts
      |
      v
[ Rate Limiter ]  window counter -> RATE_LIMIT / temp block
      |
      v
[ Decision Engine ]  ALLOW | MONITOR | BLOCK | RATE_LIMIT
      |                 |
      |                 +--> [ Logging ] security_events
      |                 +--> [ Alerts ]  high / critical
      v
[ Mock Test App ]  echoes the request, never executes it

4. Algorithm

  1. Receive the request and extract method, endpoint, query, body and user agent.
  2. Normalise every surface (double URL decode, lower-case, collapse whitespace).
  3. Load enabled rules from the signature database.
  4. Match each rule; keep the highest-confidence hit and its severity.
  5. Update per-IP counters and compute behaviour metrics for the current window.
  6. If the request count exceeds the limit, return RATE_LIMIT and block the IP temporarily.
  7. Otherwise map confidence to a decision: ≥ BLOCK_CONFIDENCE → BLOCK, ≥ MONITOR_CONFIDENCE → MONITOR, else ALLOW.
  8. Sanitise the payload and write the event to the log.
  9. Raise an alert when the decision is BLOCK or the severity is CRITICAL.
  10. Forward allowed requests to the mock application and return its response.

5. Test table

IDTest caseCategoryPayloadExpected decision
TC-01Normal requestNormal Requestlaptop bagsALLOW
TC-02SQL injection tautologySQL Injection' OR '1'='1BLOCK
TC-03UNION SELECT extractionSQL Injection1 UNION SELECT username, password FROM usersBLOCK
TC-04Reflected XSS script tagXSS<script>alert(1)</script>BLOCK
TC-05XSS event handlerXSS<img src=x onerror=alert(document.cookie)>BLOCK
TC-06Directory traversalDirectory Traversal../../../../var/log/app.logBLOCK
TC-07Encoded traversalDirectory Traversal%2e%2e%2f%2e%2e%2fconfigBLOCK
TC-08Local file inclusionLFI/etc/passwdBLOCK
TC-09File wrapper inclusionLFIfile:///etc/shadowBLOCK
TC-10Command injectionCommand Injectionping 127.0.0.1; whoamiBLOCK
TC-11Command substitutionCommand Injectionecho $(uname -a)BLOCK
TC-12Scanner user agentSuspiciousscanMONITOR
TC-13Rate limit burstRate LimitburstRATE_LIMIT

6. Observations

  • Clean requests pass with confidence 0 and are logged as ALLOW.
  • Classic SQLi and XSS payloads match with high confidence and are blocked immediately.
  • Double-encoded payloads are only caught because of the normalisation step.
  • Scanner user agents and burst traffic are caught by behaviour analysis, not signatures.
  • Every blocked or critical event produces an alert in the alert queue.

7. Conclusion

A layered approach — normalisation, signatures, behaviour analysis and rate limiting feeding a single decision engine — detects the common OWASP-style web attacks reliably while keeping false positives low on legitimate traffic. The measured accuracy, precision, recall and F1 score for the practical test suite are shown on the Reports page. Signature detection alone is not sufficient; behavioural signals are what catch reconnaissance and abuse.