Mobile Tech Support

  • Subscribe to our RSS feed.
  • Twitter
  • StumbleUpon
  • Reddit
  • Facebook
  • Digg

Monday, 25 November 2013

EMC Defenders CTF - Week 3 - Contest 14 - Reversing

Posted on 19:19 by Unknown
I played the EMC defenders CTF with a few of my friends a while back. We sadly couldn't complete all the challenges. All the same it was quite a lot of fun. One of the challenges in Week 3 was reverse engineering a 32 bit Windows executable.
While the challenge finished a while ago, I was poking at it a bit even after the challenge finished and finally managed to get a flag. In this post, I wanted to talk a little bit about the various obstacles that were in the way and how I circumvented them.

The first thing that I noticed was that directly running the executable caused it to terminate. So I started digging into it a bit more and found that there were a couple of checks that the exe performed.

- Check if it was being executed in a 64 bit environment
- Check if it was being run inside a debugger







A quick patch of the JZ to a JNZ bypassed both these protections and we were able to proceed without a problem.

After a while at 4010CF VirtualAlloc was called and a section of memory allocated to write "something into" - we don't know what at this time. The next problem was when a CALL was made at 40110B - which called into this section.





Going to that place in memory showed a lot of weird weird code which did not look right at all. Have a look at the screenshot.








Trying to run this code at this point caused an Access Violation straightaway. So I started single stepping the code, and immediately found that code a little lower down started changing. This meant that this was some kind of self modifying executable - a lot of packers use this trick.

I single stepped up to a point and ran again but it crashed again. Single step again - the next section made sense now. I repeated this for quite a while until the entire section started to make sense. What was happening, was that a small section of code would decrypt the next section. The next section would then run and decrypt the next bit. And so on ... until the entire bit unpacked itself.

Here is a screenshot of a packed section.






..And the same section after it's unpacked.







Single stepping the code until 3D0194 eventually decrypted every single bit of the code.












The unpacked code is at 3D0791 (red highlight in screen-shot above). This is how most packers behave - unpack the code to a different location and run it from there. Notice also all those junk ADD instructions after the CALL - more signs that the unpacking ends here. Lets hop over to 3D0791 now and see what's there.









Look at the last instruction and the red highlighted bit below. There is a CMP with 5A4D there and something happening after that. Hmm. 5A4D = MZ in Ascii. And MZ is the start of an EXE file. So it looks like it's searching for the start of an EXE file in memory. That too probably is what the unpacker has done - unpacked the real EXE file somewhere into memory. Where? We don't know as of now.

The red highlighted bits do have MZ and PE - things which lead us to think that the file's somewhere near.. but the other bits like "This program cannot be run in DOS mode.." .. are nowhere near. So maybe... it's not this bit which is the EXE but somewhere else. Where though?

Lets run the code after this and see what happens. We hit F9 and the code starts looping backward .. each time decrementing the place it searches by 1 (ECX register). Hmm. Meaning.. it's searching for the PE header backward. At some point it is going to find this header. Maybe :)

So I started searching for all occurrences of 4D 5A in memory. We got a hit at 3D0181 and with more text which looks like an EXE.







So I set a conditional break-point just after the CMP to break when ECX = 3D0181.








As expected it breaks. Now EDX is compared to 5A 4D. I'd expected that it would find a match and move on. Strangely the program never found a match and kept crashing. So I looked at what EDX was getting set to when the program broke.

Interestingly it got set to 5A CC and not 5A 4D. In other words the instruction CMP EDX,5A4D was failing.. coz EDX was getting set to 5A CC instead and hence never finding a match. Why?

Well CC in assembly is a software breakpoint .. or INT 3 as is often known. I'd set a conditional breakpoint..right? So the 4D at that point was temporarily overwritten by CC and thus the match failed and the app felt that there was no PE file there at all... when in reality there was. Here's a screenshot of what EDX actually contained.












But we know for sure... that there IS a PE file here. Right? So I edited EDX at run-time (and cheated a bit :)) and made it 5A 4D so that the match would succeed.














Suddenly all the code after all started to make sense...and all the right branches started getting selected, which meant I was on the right track. The biggest hint was that the next CMP which compared against 45 50 (start of PE header) succeeded and I exited the "search for PE header" loop. Which means that the header was found. Nice.

There was more memory allocated at 3D09E4 where the entire EXE was copied into 3D0000. Load Library was then called a couple of times at 3D0A9A and the addresses for a ton of functions in kernel32.dll and user32.dll were obtained.

Then I got bored and tried running it after this point to see if it'd give me a flag.. but nope.. program exited again. Aargh :(. More single stepping. I eventually came up to a call at 3D0D46. This call suddenly called to some code which was quite far from 3D0246... it called to 320A0B. Hmm. Interesting..

Eventually I managed to isolate which function was causing the code to exit. I followed the path 3D0915 - 3D097C - 3D0180 - 3D01130. And then I saw this...









So there's 3 CMP instructions ..comparing 3 different locations on the stack to 16,2 and 7E6 in hex and if they "fail" jumping to the end of the code which is 3D0171 (Screenshot shows 261171 because I wrote this blog over a couple of days and the addresses changed :D... just replace 261 with 3D0 and continue reading).

What is it looking at? Lets convert all those 3 to decimal - and it comes out to 22, 2 and 2022. Hmm. 22-2-2022. 22nd February 2022. And look at the call just before that - GetSystemTime. What'll happen if we change our system date to 22nd Feb 2022 and proceed? Let's try.

No.. that didn't work and the program still exited. So there's something else which is calculating those numbers so there is an exact match. We could sit and play around and possibly find the right match..but maybe..we do not need to and can just patch the 3 jumps. I just toggled the ZF thrice... and passed all the conditions so the program exited normally.

No more changes....and I eventually made my way over to 3D009A where there seemed to be some kind of comparison happening with all the sections of the executable..and the right path chosen when one landed on .bss.. one of the sections.






Then there seemed to be a bunch of junk copied over to 18F5CC. But I looked to be coming closer.




And then finally, there seemed to be an XOR with 5E and a MessageBox popping up with..a FLAG?






Maybe..maybe. Yessss.. Finally :)








Unfortunately I couldn't submit the flag since the contest was long long over. But still... it was nice to finish the challenge :)
Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in | No comments
Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • EMC Defenders CTF - Week 3 - Contest 14 - Reversing
    I played the EMC defenders CTF with a few of my friends a while back. We sadly couldn't complete all the challenges. All the same it was...
  • AuthenTec co-founder discusses how Touch ID fingerprint reader evolved from early prototypes!!!
    AuthenTec co-founder F. Scott Moody recently stopped by his alma mater to deliver a  speech  about the company he helped launch. His company...
  • Hackers breach vBulletin support forum using zero-day vulnerability!!!
    A group of European hackers by the name of Inj3ct0r Team have taken  responsibility  for hacking the support forums of vBulletin.com and the...
  • ASRock unveils a pair of motherboards designed specifically for Bitcoin mining!!!
    Those looking to generate some extra cash by mining for Bitcoin now have a couple of new hardware options courtesy of ASRock. The motherboar...
  • Amazon's trio of biospheres gets two thumbs up from Seattle Design Review Board!!!
    Earlier this year Amazon  submitted a building proposal  to construct a series of massive biospheres in downtown Seattle adjacent to three o...
  • 20 Life Hacks and Tools to Boost Productivity on Your Computer!!!
    With the flood of  new technologies , websites, apps, news, work files, pictures, articles and the like, staying organized and focused is be...
  • Why and how to set up your own wiki with Dokuwiki!!!
    DokuWiki is a simple but versatile wiki. Find out how to install, configure, and begin using DokuWiki.  A couple of weeks ago, I had to set ...
  • Chrome used more than Firefox, Opera and Internet Explorer combined!!!
    Google Chrome is absolutely dominating the web browser market, at least according to social analytics firm  Shareaholic , which yesterday re...
  • A peek at the inside of Sony's PlayStation 4!!!
    See  what's inside the PlayStation 4 with these exclusive photos  Inside Sony headquarters, at the heart of Tokyo’s Shinagawa district, ...
  • Crysis developer releases free-to-play FPS browser game Warface!!!
    Crytek is well known for its graphically impressive and visually stunning games on PC and console, but now the developer is taking its exper...

Categories

  • 100
  • 12.04
  • 2.2
  • 2013
  • 21
  • 4848
  • 8080
  • add
  • alternative
  • analysis
  • android
  • apk
  • app
  • applet
  • applets
  • appletviewer
  • application
  • appsec
  • asmx
  • assembly
  • attack
  • attacks
  • basic
  • basics
  • beginner
  • blazeds
  • blog
  • book
  • books
  • breakpoint
  • breakpoints
  • browser
  • burp
  • CALL
  • capture
  • certificate
  • chain
  • cheops
  • client side
  • code
  • conference
  • console
  • content-type
  • coverage
  • CRLF
  • cross
  • crossdomain
  • csrf
  • ctf
  • customer service
  • database
  • deblaze
  • debug
  • debugger
  • decision
  • defcon
  • delete
  • deleting
  • dll
  • dogbert
  • dom
  • dynamic
  • element
  • emulator
  • encryption
  • engineering
  • entity
  • environment
  • example
  • executable
  • external
  • firebug
  • flash
  • flex
  • FlourineFX
  • flow
  • flowchart
  • forensics
  • fs
  • fuzz
  • glassfish
  • graph
  • handbook
  • harden
  • hash
  • hints
  • hit
  • hittrace
  • howto
  • IDA
  • idapro
  • IDB
  • immunity
  • in use
  • incremental
  • inetsim
  • injection
  • install
  • introduction
  • java
  • java.policy
  • javaee
  • javascript
  • jks
  • jump
  • keyboard
  • lab
  • loaderdata
  • malware
  • management
  • mapper
  • market
  • MD Description
  • MD FAQ
  • MD Technical Support
  • MD Updates
  • MD User Guide
  • md5deep
  • mount
  • msdn
  • network
  • newbie
  • olly
  • ollydbg
  • options
  • packet
  • password
  • pbkdf
  • pcap
  • peb
  • peb_ldr_data
  • penetration
  • pentest
  • permissions
  • phone
  • pkcs12
  • policytool
  • port
  • practical
  • procedure
  • proxy
  • resign
  • resignation
  • response
  • restrict
  • reverse
  • reversing
  • review
  • salt
  • same origin
  • sample
  • scripting
  • sdk
  • secure
  • security
  • set
  • setup
  • sharif
  • shortcuts
  • SI
  • signed
  • site
  • snapshot
  • soapui
  • source
  • splitting
  • ssl
  • start
  • static
  • steps
  • stunnel
  • superblock
  • support
  • test
  • thoughts
  • thread
  • tips
  • tool
  • tools
  • tor
  • trace
  • truecrypt
  • tutorial
  • ubuntu
  • umask
  • understand
  • university
  • unsigned
  • video
  • view
  • virgin
  • virtual
  • virtual box
  • virtual machine
  • virtualbox
  • vm
  • watch
  • web
  • web application
  • web service
  • work
  • wsdl
  • xhr
  • xml
  • xss
  • xxe

Blog Archive

  • ▼  2013 (496)
    • ▼  November (143)
      • EMC Defenders CTF - Week 3 - Contest 14 - Reversing
      • Report details Intel Broadwell-K CPUs, Iris Pro gr...
      • What happens if you plug an Xbox One into... itsel...
      • Google completes upgrading its SSL certificates to...
      • Honda, Hyundai and Toyota showcase vehicles powere...
      • Valve readying invites for local game streaming be...
      • Liquid metal alloy could allow hobbyists to print ...
      • AMD is giving away 1,000 copies of Battlefield 4 o...
      • Acer's replacement CEO resigns before taking offic...
      • Jury awards Apple $290 million in patent infringem...
      • HBO Go now supports Chromecast on both iOS and And...
      • Half-Life mod Black Mesa approved for sale on Stea...
      • Xbox One teardown reveals standard PC hardware com...
      • University in Cyprus becomes world's first to acce...
      • Adobe opens $9.99 per month Photoshop + Lightroom ...
      • Building a coding machine becomes fun with the $99...
      • Motorola signs deal with 3D Systems to help build ...
      • Google sends out developer invites to Chromecast h...
      • Sprint finishes dead last in Consumer Reports' lat...
      • MediaFire's new desktop file-sharing client brings...
      • Infographic: A timeline of Sony's PlayStation fran...
      • FCC may allow passengers to make in-flight cellula...
      • Pogoplug launches $49 Safeplug to anonymize your h...
      • Silk Road mastermind allegedly ordered six murders...
      • Intel Atom SoC roadmap updated, new chips and 64-b...
      • Upcoming MMORPG by Ex-Blizzard devs, WildStar to b...
      • A Software Challenge: Why Users Uninstall Apps!!!
      • geeky support 2013 gift Guide/recommendations!!!
      • Yahoo to announce the hire of Katie Couric as 'Glo...
      • Microsoft matches Sony, sells over a million Xbox ...
      • What Black Friday deals are you eyeballing this ye...
      • Instagram said to be working on private messaging ...
      • Doom co-creator John Carmack resigns from id Softw...
      • Motorola signs deal with 3D Systems to help build ...
      • The state of self-driving cars, Intel details upco...
      • Xbox One Review!!!
      • Qualcomm reveals new Snapdragon 805 processor with...
      • MediaTek showcases world's first true octa-core mo...
      • Logitech releases PowerShell controller with integ...
      • Firefox’s streamlined “Australis” user interface l...
      • Flickr rolls out new printed photo book options st...
      • Greedy wireless carriers aren't interested in smar...
      • New details on Elder Scrolls Online campaign, stor...
      • Google launches free prepaid debit card, links to ...
      • End of an era: Winamp is shutting down after more ...
      • Are you sure you're clean?
      • John McAfee Responds To Wrongful Death Lawsuit!!!
      • Google Nexus 5: The geekysupport Review!!!
      • Tesla chief Elon Musk updates Model S warranty to ...
      • Command & Conquer not dead after all, revival immi...
      • MOGA unveils the Ace Power gamepad for iPhone, iPo...
      • Yahoo to encrypt all products in light of NSA spyi...
      • Call of Duty: Ghosts patch adds e-sports features,...
      • Sony's $399 PlayStation 4 costs roughly $381 to bu...
      • Snapchat turns down $3 billion acquisition offer f...
      • Samsung has now shipped 800,000 Galaxy Gears, new ...
      • Snapchat surpasses photo sharing activities of Fac...
      • Nokia Lumia 2520 available at Verizon this week, p...
      • Valve set to reveal its own Steam integrated virtu...
      • Google to pay $17 million for unauthorized trackin...
      • New Toshiba Kira Ultrabook lasts 22 hours on a sin...
      • Senate hosts hearing on Bitcoin and other virtual ...
      • Apple reportedly buying PrimeSense, the company be...
      • Decade-long study claims video games don't affect ...
      • FBI memo claims Anonymous has been hacking US gove...
      • ZTE Open smartphone with Firefox OS review!!!
      • Sony sells more than a million PlayStation 4s with...
      • Ouya unveils limited edition white console with do...
      • Qualcomm's $350 Toq smartwatch releases on Decembe...
      • A behind-the-scenes look at how YouTube handles an...
      • NFL and MLB ask the Supreme Court to hear a challe...
      • Trademark application points to impending Fallout ...
      • Raspberry Pi has now sold 2 million units, doubles...
      • Hackers breach vBulletin support forum using zero-...
      • Sony publishes guide to troubleshoot PlayStation 4...
      • 12 Ways Black Friday 2013 Will Be Different!!!
      • Apple iPad Air: The geekysupport Review!!!
      • VMware Tools now available for nested ESXi with th...
      • VMware Tools now available for nested ESXi with th...
      • VMware Tools now available for nested ESXi with th...
      • Prepare yourself for the looming deadline of Windo...
      • Final PS4 & Xbox One specs compared, why users uni...
      • What's the oldest gadget you still use regularly?!!!
      • Newly appointed FCC chairman calls for wireless ca...
      • ASRock unveils a pair of motherboards designed spe...
      • Europe allows airlines to install 3G and LTE netwo...
      • The PlayStation 4 is officially here, some systems...
      • Republic Wireless offers Moto X for $299 contract-...
      • FCC's Speed Test app for Android now available on ...
      • Jolla to launch inaugural smartphone with Sailfish...
      • Quantum computers looking more realistic with majo...
      • Samsung reportedly planning to launch smartphone w...
      • Minecraft: The Story of Mojang now available on Yo...
      • Jawbone's first wireless fitness tracker Up24 is a...
      • Yahoo to auction off more than 100 long-lost domai...
      • Computer History Museum publishes Apple II DOS sou...
      • CyanogenMod one-click installer for Android arrive...
      • PlayStation 4 Review: (In Progress), But Do You Ne...
      • MIT showcases impressive dynamic shape display tec...
      • snapchat turns down $3 billion acquisition offer f...
    • ►  October (297)
    • ►  September (51)
    • ►  August (2)
    • ►  March (1)
    • ►  January (2)
  • ►  2012 (16)
    • ►  October (3)
    • ►  September (1)
    • ►  August (4)
    • ►  June (1)
    • ►  May (4)
    • ►  April (2)
    • ►  February (1)
  • ►  2011 (22)
    • ►  October (1)
    • ►  September (2)
    • ►  August (1)
    • ►  July (9)
    • ►  June (1)
    • ►  May (2)
    • ►  April (6)
  • ►  2010 (8)
    • ►  August (3)
    • ►  April (2)
    • ►  January (3)
  • ►  2009 (6)
    • ►  December (6)
Powered by Blogger.

About Me

Unknown
View my complete profile