IE – Grey Panthers Savannah https://grey-panther.net Just another WordPress site Fri, 09 Jan 2009 10:24:00 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.2 206299117 Using a single file to serve up multiple web resources https://grey-panther.net/2009/01/using-a-single-file-to-serve-up-multiple-web-resources.html https://grey-panther.net/2009/01/using-a-single-file-to-serve-up-multiple-web-resources.html#comments Fri, 09 Jan 2009 10:24:00 +0000 https://grey-panther.net/?p=466 While trying to set up my GHDB mirror, my first thought was to use googlepages. I quickly found the bulk upload to googlepages how to by X de Xavier, which is a very cool tool (and also an interesting way to hack your “chrome”), but unfortunately I found that Google Pages has a limit of 500 files (and the mirror contained aroung 1400 files), so this was a no-go.

My second thought was: the Browser Security Handbook documents several “pseudo-protocol” which can contain other files in them that can be directly adressed from the browser. Although support for them is rather spotty, I thought that using JAR (supported by Firefox) and MHT (supported by IE) I could cover a large gamut of users.

The results are rather disappointing, but I document the failure sources which I isolated, maybe it can help someone out.

First of was JAR. JARs are in fact just zip files, so creating them is very straight forward. After creating and testing it locally, I uploaded the archive and tried to access it like this (if you have NoScript, you must add it to the whitelist for it to work):

jar:http://ghdb.mirror.googlepages.com/ghdb.jar!/_0toc.html

Just to get the following error message:

Unsafe File Type

The page you are trying to view cannot be shown because it is contained in a file type that may not be safe to open. Please contact the website owners to inform them of this problem.

After searching for the error message and not coming up with anything useful, I took a stab at looking at the source code, this is one of the reasons open source is great after all.

From the code:

// We only want to run scripts if the server really intended to
// send us a JAR file.  Check the server-supplied content type for
// a JAR type.
...
mIsUnsafe = !contentType.EqualsLiteral("application/java-archive") &&
            !contentType.EqualsLiteral("application/x-jar");
...
if (prefs) {
    prefs->GetBoolPref("network.jar.open-unsafe-types", &allowUnpack);
}

if (!allowUnpack) {
    status = NS_ERROR_UNSAFE_CONTENT_TYPE;
}

Ignoring the fact that the code uses negative assertions (ie. mIsUnsage) rather than positive assertions (ie. mIsSafe), the code tells us that they are looking for the correct Content-Type sent by the webserver or, alternatively, for the “network.jar.open-unsafe-types” setting. This is probable to prevent the GIFAR attack. So, it seems that the googlepages server doesn’t return the correct Content-Type. We can quickly confirm it with the command:

curl http://ghdb.mirror.googlepages.com/ghdb.jar --output /dev/null --dump-header /dev/stdout

And indeed the result is:

HTTP/1.1 200 OK
Last-Modified: Wed, 31 Dec 2008 11:25:06 GMT
Cache-control: public
Expires: Fri, 09 Jan 2009 10:54:28 GMT
Content-Length: 2700935
Content-Type: application/octet-stream
Date: Fri, 09 Jan 2009 10:54:28 GMT
Server: GFE/1.3
...

So the options would be to (a) tell people to lower their security or (b) not use Google’s server, none of which was particularly attractive.

Now lets take a look at the MHT format. As many other MS formats, it is very sparsely documented (all hail our closed-source overlord), although there were some standardization efforts. Anyway, here is the Perl script I’ve thrown together to generate an MHTML file from the mirror:

use strict;
use warnings;
use File::Basename;
use MIME::Lite;
use File::Temp qw/tempfile/;
use MIME::Types;


my $mimetypes = MIME::Types->new;
my $msg = MIME::Lite->new(
        From    =>'Saved by Microsoft Internet Explorer 5',
        Subject =>'Google Hacking Data Base',
        Type    =>'multipart/related'
    );

my $i = 0;
my @tempfiles;
opendir my $d, 'WEB';
while (my $f = readdir $d) {
  $f = "WEB/$f";
  next unless -f $f;
  ++$i;

  next unless $f =~ /.([^.]+)$/;
  my $ext = lc $1;
  my $mime_type = $mimetypes->mimeTypeOf($ext);
  my $path = $f;

  if ('text/html' eq $mime_type) {
    my ($fh, $filename) = tempfile( "tmimeXXXXXXXX" );
    
    open my $fhtml, '<', $f;
    my $html = join('', <$fhtml>);
    close $fhtml;
    $html =~ s/(href|src)s*=s*"(.*?)"/manipulate_href($1, $2)/ge;
    $html =~ s/(href|src)s*=s*'(.*?)'/manipulate_href($1, $2)/ge;
    $html =~ s/(href|src)s*=s*([^'"][^s>]+)/manipulate_href($1, $2)/ge;
    print $fh $html;
    close $fh;

    $path = $filename;
    push @tempfiles, $path;
  }

  my $part = $msg->attach(
      Type        => $mime_type,
      Path        => $path,
      Filename    => basename $f,
  );
  $part->attr('Content-Location' => 'http://example.com/' . basename $f);  
}
closedir $d;

$msg->print(*STDOUT);

unlink $_ for (@tempfiles);

sub manipulate_href {
  my ($attr, $target) = @_;

  return qq{$attr="$target"} if ($target =~ /^http:///i);
  return qq{$attr="http://example.com/$target"};
}

The two important things here are the fact that each element must contain the Content-Location header (ok, is somewhat of an oversimplifaction, because there are other ways to identify subcontent, but this is the easiest) and all URLs must be absolute! This is why there is all the regex replacement going on (again, this is quick hack, if you want to create production code, you should consider using a parser. An other possibility – which I haven’t tried – is to use the BASE tag – you may also want to check out the changes IE7 brings to it, although most probably they wouldn’t affect you).

Now, with the MHT file created, time to try it out (with IE obviously):

mhtml:http://ghdb.mirror.googlepages.com/ghdb.mht!http://example.com/_0toc.html

The result is an IE consuming 100% CPU (or less if you are on a multi-core system :-)) and seemingly doing nothing. Tried this on two different systems with IE6 and IE7. Now I assume that in the background it is downloading and parsing the file, but I just got bored with waiting. Update: I did manage to get it working after a fair amount of working, however it seemed to want to download the entire file at each click, making this solution unusable. It still might be an alternative for smaller files…

Conclusions, future work:

  • Both solutions want to download the entire file before displaying it, making the solutions very slow in case of large files.
  • It would be interesting to see if the MHT could incorporate some compressed resources. IE, something like: Content-Encoding: gzip, base64 (first gzipped, and after it base64 encoded). This could possibly reduce the size problem.
  • It would also be interesting to know in which context the content is interpreted. Hopefully in the context of the MHT file URL (ie, in this case http://ghdb.mirror.googlepages.com/), rather than the specified URL (ie. http://example.com), because, if not, it can result in some nasty XSS-type scenarios (ie. malicious individual crafts MHT pages with resources being referred to as http://powned.com/ and hosts it on its own server. Convinces a user to click on the link mhtml:http://evil.com/pown.mht!http://powned.com/foo.html and steals the cookies for example from powned.com, even if powned has no vulnerabilities per se!). I’m too lazy to try this out :-), but hupefully this can’t happen.
]]>
https://grey-panther.net/2009/01/using-a-single-file-to-serve-up-multiple-web-resources.html/feed 4 466
Internet Explorer + Frames = Headache https://grey-panther.net/2008/04/internet-explorer-frames-headache.html https://grey-panther.net/2008/04/internet-explorer-frames-headache.html#respond Sun, 13 Apr 2008 19:54:00 +0000 https://grey-panther.net/?p=776 So lets say you have the following HTML snippet:

<html>
    <frameset rows="20,*" border="0" frameborder="no">
        <frame name="menu" src="menu_frame.html" scrolling="no" noresize="1">
        <frame name="work_frame" src="">
    </frameset>
</html>

First of all you would say: but frames are so 1998! And you would be right. Frames are outmoded, deprecated and a usability nightmare (because you can’t bookmark the exact state of the frameset), you have to use them in certain situations. Like, for example when providing a "unified menu" in an intranet where you can’t (or don’t want to) touch all the sub-sites referenced. "The right tool for the right job".

Back to our problem: the page from the upper frame contained a bunch of links targeted at the lower frame in the form of:

<a href="http://www.example.com" target="work_frame">Example</a>

The problem was that while on all "sane" browsers the link opened in the lower frame, Internet Explorer (both version 6 and 7) insisted on opening a new window for the link. Finally I got the idea to create a blank page and set the lower pane to it:

<html>
    <frameset rows="20,*" border="0" frameborder="no">
        <frame name="menu" src="menu_frame.html" scrolling="no" noresize="1">
        <frame name="work_frame" src="blank.html">
    </frameset>
</html>

Magically everything worked. So there you go: IE + Frames = Headache (from banging your head against the desk), or at least Magic.

PS. I never tried using "about:blank" instead of an explicit blank page, which seems to be standard (I don’t know if official or unofficial) between the major browsers. Possibly it would also work (and has the advantage that you don’t have to explicitly code an "empty" html file).

]]>
https://grey-panther.net/2008/04/internet-explorer-frames-headache.html/feed 0 776
Lies, Damn Lies and Statistics https://grey-panther.net/2007/04/lies-damn-lies-and-statistics.html https://grey-panther.net/2007/04/lies-damn-lies-and-statistics.html#respond Thu, 05 Apr 2007 05:55:00 +0000 https://grey-panther.net/?p=867 I’m back with more critique for Deb Shinder (who for one reason or an other doesn’t allow commenting on her blog, so I can’t directly post there). Read part one (Biometrics is not the answer!) and part two (Three letter acronyms don’t provide good security!) for more opinionated posts.

The post I’m talking about is Is Firefox less secure than IE 7?. First a little disclaimer: I may be biased in this matter (but who isn’t) as someone who’s been using and loving FireFox since version 0.9. The sentence I have the most issue with is the following: Firefox alone in recent months has had more exploits than Windows XP and Vista combined (yes, I should complain to George Ou for this one, and be sure that I will). People please try to limit ourselves to useful and meaningful information instead of trying to construct bogus and meaningless statistics to prove our points. If we have biases, lets come out and share them (like I did earlier) and lets try to compare apples to apples and oranges to oranges. This quote was insulting to the intellect of your readers (who are smart enough to realize that within MS there are different teams working on different products and they are so separated that you could almost call them a company withing a company). It is as if I would say that: IE had more vulnerabilities than there were full moons in 2006, so it is bad.

To finish up with an other statistic (again biased, but at least it is clear from the context): during 2006 Internet Explorer was vulnerable for 286 without a patch being available (78%) and Firefox for 9 (2.5%)

]]>
https://grey-panther.net/2007/04/lies-damn-lies-and-statistics.html/feed 0 867
Decoding obfuscated Javascript https://grey-panther.net/2007/02/decoding-obfuscated-javascript.html https://grey-panther.net/2007/02/decoding-obfuscated-javascript.html#comments Fri, 23 Feb 2007 07:06:00 +0000 https://grey-panther.net/?p=895 SANS had recently a posting about methods to decode obfuscated Javascript, and I just wanted to mention 2+1 tools here:

  • In Firefox you can use the View Source Chart extension to view the source after the javascript has executed. There is also the versatile Firebug, but IMHO that’s an overkill for this.
  • For Internet Explorer there is the Internet Explorer Developer Toolbar which is free (as in beer) and as of writing this required no WGA silliness.
  • And the bonus tips: if you are using Firefox, it may be worth to install the User Agent Switcher plugin and to switch to IE, because exploit sites were known for trying to serve up different exploits for different browsers. If you encounter scripts of type JScript.encoded or VBScript.encoded, you should find this tool useful.

Warning! These methods actually execute the script on your machine! They should be used with extreme care, and preferably only in controlled virtual machines or computers not connected to network.

]]>
https://grey-panther.net/2007/02/decoding-obfuscated-javascript.html/feed 4 895
What is not AJAX? https://grey-panther.net/2006/11/what-is-not-ajax.html https://grey-panther.net/2006/11/what-is-not-ajax.html#comments Tue, 14 Nov 2006 13:04:00 +0000 https://grey-panther.net/?p=1017 Not everything involving browser scripting is AJAX. The following two things are not AJAX:

  1. Yellow fading effect on web pages
  2. Downloading and running an executable in Internet Explorer if you have your Internet Zone security level set to low.
]]>
https://grey-panther.net/2006/11/what-is-not-ajax.html/feed 1 1017
Pimping my blog #2 https://grey-panther.net/2006/10/pimping-my-blog-2.html https://grey-panther.net/2006/10/pimping-my-blog-2.html#respond Thu, 12 Oct 2006 05:33:00 +0000 https://grey-panther.net/?p=1043 After observing that most of my visitors (45% currently) use Internet Explorer, I’ve made a little modification so that they to can enjoy the <q> tag. A more detailed discussion and other solutions can be found at the List Apart site. I’ll only present in short my version.

My version consists of two parts: a style using the underscore hack to make the contents of the tag italic for the security conscious users (those who don’t have Javascript enabled) and then a script written in unobtrusive style which (a) adds a " before and after each tag and (b) disables the italic style. You can find the sources below.

GeSHi © 2004, Nigel McNie
  1. <style type=“text/css”><!–
  2.   Q { _font-style: italic; }
  3. –></style>
GeSHi © 2004, Nigel McNie
  1.   var quoteResolver = {
  2.     addEvent : function (obj, evType, fn) {
  3.       //taken from: http://www.scottandrew.com/weblog/articles/cbs-events
  4.       if (obj.addEventListener){
  5.         obj.addEventListener(evType, fn, false);
  6.         return true;
  7.       } else if (obj.attachEvent){
  8.         var r = obj.attachEvent(“on”+evType, fn);
  9.         return r;
  10.       } else {
  11.         return false;
  12.       }  
  13.     },
  14.    
  15.     doWork: function () {
  16.       //add a ” before and after each q
  17.       var qs = document.getElementsByTagName(‘q’);
  18.       for (var i = 0; i < qs.length; i++) {
  19.         var before = document.createTextNode(‘”‘);
  20.         var after = document.createTextNode(‘”‘);
  21.         qs[i].parentNode.insertBefore(before, qs[i]);
  22.         qs[i].parentNode.insertBefore(after, qs[i].nextSibling);
  23.       }
  24.      
  25.       //deactivate the font-style: italic rule     
  26.       for (var i = 0; i < document.styleSheets.length; i++) {
  27.         //the standard would be cssRules, but IE uses rules
  28.         //and we are targeting IE only
  29.         var ruleList = document.styleSheets[i].rules;
  30.         for (var j = 0; j < ruleList.length; j++)
  31.           if (‘Q’ == ruleList[j].selectorText && ‘italic’ == ruleList[j].style.fontStyle) {
  32.             //this is the style we wish to disable
  33.             ruleList[j].style.fontStyle = ;
  34.             break;      
  35.           }
  36.       }         
  37.     },
  38.    
  39.     init : function () {
  40.       //try to determine if this is an IE browser
  41.       var userAgent = /MSIE/; var nonUserAgent = /Opera/; var os = /Windows/;
  42.       if ( userAgent.exec(navigator.userAgent) && !nonUserAgent.exec(navigator.userAgent) && os.exec(navigator.userAgent) ) { 
  43.         //register a function to do the work after we finish loading
  44.         this.addEvent(window, ‘load’, this.doWork);
  45.       }
  46.     }
  47.   }.init();
]]>
https://grey-panther.net/2006/10/pimping-my-blog-2.html/feed 0 1043