Wednesday, November 12, 2008

CSRF attack through Macros? Really?

Sitting with my co-worker and wondering what our next move would be at exploiting another XSS attack we both turned our minds toward Microsoft Excel. We had seen cases where we could get XSS attacks and even Excel attacks embedded in downloaded CSV files and were presented with an application allowing for similar functionality. My co-worker starting looking for ways to embed nastiness in a macro and sure enough we came across yet another attack vector for CSRF.

Like I said the application at hand allowed users to upload excel files and actually send these files to other users of the system. We found there is a "neat" little VBA object called InternetExplorer.Application which basically allows you to open an instance of IE from a macro. This "neat" little object provides most all functionality IE does BUT since the attacker is now ALLOWED access to the file system through the VBA code this could get interesting. Oh did I mention this object allows access to a users cookies.

Lets dig a little deeper. If I was able to write a quick little VBA macro that iterated through a users "Favorites" links and request cookies for every single site, what would happen. If the user is currently logged into any of these sites via normal IE the cookie of the authenticated session would now be in the hands of the attacker. This means CSRF is happening through a macro and in this case the attacker wants a bunch of authenticated sessions. This does work.

Now what if we wanted to take this a bit further and create a worm that not only stole session information but performed a CSRF against a favorite webmail provider wherein it grabbed the contact list, created an email, uploaded an infected xls file with our macro and sent it to every one of our contacts. That is scary and a zero day in my mind.

Now the really scary thing about this is we all know macros are bad and dangerous but honestly how many times have we gotten an xls file and clicked "Enable Macros" because we were told to. Come on be honest....We have all done it and we will continue to do it until something bad happens.

So how do we protect against this. It is almost impossible without getting MS to take this functionality away. With InternetExplorer.Application we have a fully functional browser where we could send multiple requests, parse the DOM returned and grab any CSRF token we need to present with each request.

This macro will obviously work in any MS application with macros enabled. And once the macro runs the user would never know what happened. As with any CSRF attack the user would need to be logged into a site the macro knew about.

No comments: