Skip to content
Nirmal Dahal

19 Jun 2019 · 3 min read

XSS on samy.pl

How a javascript: URL got past the source-viewing blocks on samy.pl, the site of security researcher Samy Kamkar, and the XSS issue behind it.

By Nirmal Dahal

Firefox on samy.pl with a script payload in the address bar and the page reading "Hacked???"

In this article, I am going to explain a security issue that I found on a web site which is famous within the information security researchers. Samy Kamkar is an American privacy and security researcher, computer hacker, entrepreneur and for me a very big influencer. Samy Kamkar is the person who created the first JavaScript-based worm known as Samy Worm which went viral within a few hours ultimately compelling myspace to shut down temporarily.

Viewing the hidden source

I was explaining the work of Samy Kamkar (opens in a new tab) to one of my friends. Samys site has so many easter-egg like challenges. We are not allowed to view the source code using normal methods like ‘right-click’ , ‘Inspect element’ , ‘Ctrl + shift + I’ etc. Then I tried the following snippet.

javascript:https://samy.pl/?%0aalert(document.body.innerText=document.body.innerHTML)

I was able to see the source code that was extracted from the DOM for the Samy’s website.

You guys can go to https://samy.pl (opens in a new tab) and try to right-click, view his source code using ctrl + u or even go to another tab and type:

view-source:https://samy.pl

Lastly, try to view the source using inspect element and I think you will be surprised. Do comment if you find any other way to view the source code.

Finding the vulnerable endpoint

Then I started going through everything that was on the website. I saw that he was using JS code to detect proxies like Burp, Charles & Fiddler. I dug deeper to see everything he was using to make the awesome website that he has. Sometime later I found a suspicious “jsonp endpoint” that was used to reflect the public IP address of whoever is requesting his website.

samy.pl source in an editor showing the JavaScript that detects Burp, Charles and Fiddler proxies

Verifying proxy tools.

The same samy.pl source, highlighting the testBurpPac routine that alerts "proxy detected"

This code was verifying if the user was logged in or not.

samy.pl source showing the pwn() function that injects a script pointing at the vulnerable /ipp.php?jsonp=st endpoint

Vulnerable EndPoint

The endpoint was something like https://samy.pl/ipp.php?jsonp=st (opens in a new tab) then it would reflect something like this

Browser at samy.pl/ipp.php?jsonp=st returning st('...') wrapping the requester's redacted IP address

From reflection to XSS

After finding the endpoint I started altering the endpoint. First I removed ‘st’ from the endpoint and I saw that it was also removed on the reflected output.

View-source of the endpoint with the jsonp value emptied, showing the callback name stripped from the reflected output

I then altered furthermore by adding ‘<>’ which was successfully reflected on the site.

View-source of the endpoint with jsonp set to <>, confirming the angle brackets are reflected unescaped

When I saw that the greater than and smaller than symbols were reflected I straight jumped into using my custom script to reflect a cross-site scripting vulnerability that was successfully executed and that was how I was able to perform XSS on Samy.pl.

Firefox showing samy.pl defaced to a full-page "Hacked???" with the injected script payload visible in the address bar

R-XSS DOM Overwrite

The "Hacked???" page on samy.pl, with the plain samy.pl address bar highlighted after the payload ran

A JavaScript alert box reading "samy.pl" on the real site, proving document.domain execution via the XSS

Timeline

  • June 6, 2019 — Report Sent

  • June 7, 2019 — Fixed & allowed to publish by Samy Kamkar

२ शब्द

I have found in my past experience that even some top security researchers from HackerOne have had their site hacked or other security researchers have discovered some type of vulnerability. No matter how much people claim to have their site/system it is 100% secure or no matter how much a person is experienced it is only a matter of time and the amount of knowledge to discover a new or even existing flaw.

Note: I did not think I would find an XSS issue in Samy Kamkar's site. The person who created the first-ever javascript-based worm. I have written this blog with the full permission of Samy Kamkar (opens in a new tab).

Email from Samy Kamkar thanking Nirmal for the report, confirming it is resolved and permitting publication

धन्यवाद!!!

Let's scope it together.

Tell me what you need to protect and by when. I'll reply with whether I can help and how I'd approach it.