User Registration & Login and User Management System v3.0 - Stored Cross-Site Scripting (XSS)

Exploit Author: Ashutosh Singh Umath Analysis Author: www.bubbleslearn.ir Category: WebApps Language: PHP Published Date: 2023-08-24
# Exploit Title: User Registration & Login and User Management System v3.0 - Stored Cross-Site Scripting (XSS)
# Google Dork: NA
# Date: 19/08/2023
# Exploit Author: Ashutosh Singh Umath
# Vendor Homepage: https://phpgurukul.com
# Software Link: https://phpgurukul.com/user-registration-login-and-user-management-system-with-admin-panel/
# Version: 3.0
# Tested on: Windows 11
# CVE : Requested


Description

User Registration & Login and User Management System With admin panel 3.0 application from PHPgurukul is vulnerable to
Persistent XSS via the fname, lname, email, and contact field name. When User logs in or the admin user logs in the payload gets executed.

POC

User side
1. Go to the user registration page http://localhost/loginsystem.
2. Enter <img src="x" onerror=alert(document.cookie)> in one of the
fields (first name, last name, email, or contact).
3. Click sign up.

Admin side
1. Login to admin panel http://localhost/loginsystem/admin.
2. After login successfully go to manage user page.
3. Payload


Thanks and Regards,

Ashutosh Singh Umath


Understanding Stored Cross-Site Scripting (XSS) in User Registration & Login Systems: A Case Study on PHPgurukul v3.0

Stored Cross-Site Scripting (XSS), also known as persistent XSS, is one of the most dangerous web vulnerabilities in modern application security. Unlike reflected XSS, where malicious scripts are executed only during a single request, stored XSS persists in the application's database or server-side storage, making it capable of affecting every user who accesses the vulnerable data.

Real-World Example: PHPgurukul User Registration & Login System v3.0

The User Registration & Login and User Management System v3.0 by PHPgurukul — a widely used open-source PHP framework for managing user accounts — has been identified as vulnerable to stored XSS. This vulnerability stems from inadequate input sanitization and improper output encoding when handling user data.

Exploiter Ashutosh Singh Umath reported that attackers can inject malicious JavaScript payloads into fields such as fname (first name), lname (last name), email, and contact during registration. Once submitted, these payloads are stored in the database and executed whenever the data is rendered in the frontend — particularly during login or admin user management pages.

Exploit Demonstration (Proof of Concept)

The following is a simplified representation of the attack vector:


<img src="x" onerror=alert(document.cookie)>

This payload is designed to trigger an alert() when the image fails to load (due to invalid src), which is a common technique to bypass simple filters. Since the application does not sanitize or encode this input before storing it, the script is preserved in the database.

Attack Flow: User Side

  • Step 1: Navigate to the registration page at http://localhost/loginsystem.
  • Step 2: Enter the malicious payload in any of the fields: first name, last name, email, or contact.
  • Step 3: Submit the form and complete registration.

Upon successful registration, the malicious script is stored in the backend database.

Attack Flow: Admin Side

  • Step 1: Log in to the admin panel at http://localhost/loginsystem/admin.
  • Step 2: Navigate to the "Manage Users" section.
  • Step 3: View user details — the stored XSS payload is rendered in the HTML output.

As the admin panel displays user data without proper sanitization, the script executes immediately in the browser context, potentially stealing session cookies or redirecting users to malicious sites.

Why This Vulnerability Is Critical

Stored XSS is particularly dangerous because:

  • Longevity: The payload remains active until manually removed or patched.
  • Mass Impact: Every user viewing the affected data (including admins) becomes a potential victim.
  • Stealth: Attackers can remain undetected for extended periods, especially in poorly monitored systems.
  • Session Hijacking: The alert(document.cookie) example demonstrates how attackers can extract sensitive session data.

Security Best Practices to Prevent Stored XSS

Developers must implement robust input validation and output encoding strategies to prevent such vulnerabilities. Here’s a recommended approach:

Input Sanitization

Before storing user data, sanitize all inputs using functions like htmlspecialchars() in PHP, or equivalent in other languages.


// Example: Sanitizing user input before database storage
$fname = htmlspecialchars($_POST['fname'], ENT_QUOTES, 'UTF-8');
$lname = htmlspecialchars($_POST['lname'], ENT_QUOTES, 'UTF-8');
$email = htmlspecialchars($_POST['email'], ENT_QUOTES, 'UTF-8');
$contact = htmlspecialchars($_POST['contact'], ENT_QUOTES, 'UTF-8');

// Store sanitized data in database

This ensures that any HTML or JavaScript characters are converted to their safe equivalents (e.g., < becomes &lt;).

Output Encoding

Even if data is stored safely, it must be encoded when rendered in the browser. Never directly output raw user data.


// When displaying user data in the admin panel
echo htmlspecialchars($user['fname'], ENT_QUOTES, 'UTF-8');
echo htmlspecialchars($user['lname'], ENT_QUOTES, 'UTF-8');
echo htmlspecialchars($user['email'], ENT_QUOTES, 'UTF-8');
echo htmlspecialchars($user['contact'], ENT_QUOTES, 'UTF-8');

This prevents any script execution during rendering.

Additional Mitigations

  • Use Content Security Policy (CSP): Implement a strict CSP header to block inline scripts and external sources.
  • Validate Input Types: Use regular expressions to restrict field inputs to expected formats (e.g., email validation).
  • Log and Monitor Suspicious Inputs: Track and alert on unusual patterns (e.g., onerror, alert, javascript:).
  • Role-Based Access Control: Limit admin access to sensitive data and enforce audit trails.

Conclusion: Lessons from PHPgurukul v3.0

The PHPgurukul v3.0 system serves as a cautionary tale for developers relying on open-source frameworks. While these tools offer convenience, they often lack built-in security safeguards. This vulnerability underscores the importance of:

  • Security by Design: Implementing defense mechanisms from the start, not as afterthoughts.
  • Code Review and Testing: Regularly auditing code for common vulnerabilities like XSS.
  • Vendor Accountability: Requesting CVEs and updates from vendors to ensure transparency.

As cyber threats evolve, developers must prioritize secure coding practices — especially when handling user data. A single unencoded input can compromise an entire system.

Recommended Action for Users of PHPgurukul v3.0

If you are using this system, immediately:

  • Update to the latest version (if available).
  • Apply input sanitization and output encoding across all user-facing fields.
  • Review and audit all database storage and frontend rendering logic.
  • Report the vulnerability to the vendor and request a CVE assignment.