Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[vuln] OpenRedirect leads to XSS attack in login.php #316

Open
wants to merge 7 commits into
base: testlink_1_9_20_fixed
Choose a base branch
from

Conversation

hi-unc1e
Copy link

@hi-unc1e hi-unc1e commented May 31, 2021

Hi, guys, sorry for having chosen the wrong branch in here

Here i come again,

While I using testlink I had noticed that an arbitrary open redirect is not validating properly which may lead to credentials stolen of the user (self-xss).

  • Risk: Medium
  • Tested version: 1.9.20
  • Environent: Windows10+ Chrome90.0.4430.212
  • Credit:unc1e

Personally I prefer to split them into 2 vulns, Here's what i found

0x01 the vulnerable regex -> Unvalidated Redirects and Forward

Related code lies in login.php#371 , which is shown as follows
image

the regex-expression /linkto.php/ stands for the combination of [linkto]{1} + [\w]{1} + [php]{1}, in which . can be replaced by any signle character, so as a consequence.
These input could pass the validation, and reflected in the HTTP response when a user succeed in logining.

destination=ANYSITE/linkto1php

image

So the mediation may be like /^linkto\.php$/ , according to what your need.

What happened next may elevate this risk to a High-Level vuln.

0x02 Improper XSS validation

While deeply analysing the function of redirect(), i noticed an odd implementation.

$safeUrl = addslashes($url);

image

ONLY addslashes is used, which is SURELY NOT ENOUGH and VULNERABLE to XSS attack.
Which means if I craft a XSS payload in the URL, it could execute any Javascript Code in victim's browser, certainly after he's logged in.
image

Putting together

So the senario is:

  1. Craft a URL, for example: http://testlink/login.php?viewer=123&destination=</script>linkto.php<script>alert(/xss/);//
  2. Send it to a victim, the victim open that link
  3. The victim logged with correct credentials
  4. XSS attack is triggered, an attacker could steal the victim's valid cookie or craft a phishing page to the victim depends on different purpose.
  5. Here is the PoC of this vuln ( You can see that Javascipt-script is executed on victim's browser. )
    image

Mediation

For 0x01, you should validate the $destination properly according to Unvalidated_Redirects_and_Forwards_Cheat_Sheet

For 0x02, you should escape the user-input data ( htmlspecialchars() for instance ) properly, according to Cross_Site_Scripting_Prevention_Cheat_Sheet.html

@fmancardi
Copy link
Contributor

fmancardi commented Jun 2, 2021 via email

@hi-unc1e
Copy link
Author

hi-unc1e commented Jun 3, 2021

See my testing in 83010fb#r51662554

Fix type juggling vulnerability.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants