Verizon Fios Tech Support

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

Wednesday, 25 September 2013

CSAW CTF 2013 Qualification Round: Reversing

Posted on 09:30 by Unknown

Each year, the Information Systems and Security Laboratory (ISIS Lab) of the Polytechnic Institute of New York University hosts a Cyber Security Awareness Week, bringing together students and researchers to discuss the latest in cybersecurity.  Cybersecurity has always been the core focus at Digital Operatives and we are looking forward to this year's events in November.  The 2013 CSAW Capture the Flag Qualification Round was held this past weekend with over 1300 participating teams.  Like most Jeopardy-style CTFs, CSAW had several categories of problems, with Reverse Engineering as one of them.  A small team from Digital Operatives participated in this competition; below are write-ups for the Reversing problems.  Congratulations to the winning teams and great job to the organizers of the competition!

Contents

  • Reversing 100: DotNetReversing.exe
  • Reversing 100: csaw2013reversing1.exe
  • Reversing 150: bikinibonanza.exe
  • Reversing 200: csaw2013reversing2.exe
  • Reversing 300: crackme
  • Reversing 400: keygenme32.elf
  • Reversing 500: Noobs First Firmware Mod
  • Reversing 500: Impossible

Reversing 100: DotNetReversing.exe

We are prompted for a passcode and, upon attempting "a", the program crashes with a System.FormatException by attempting to parse the input as a number.

Upon opening the program in IDA Pro, it is quite clear where the branch between success and failure is, and because we know the program is looking for a numerical input, the constants just above this branch stand out.

We see that the program takes 0xC5EC4D790 and 0xF423ABDB7 and XORs them.

The result is 0x31cfe6a27, or 13371337255 in base ten, so we try this as input and get the flag!

Flag: I'll create a GUI interface using visual basic...see if I can track an IP address.



Reversing 100: csaw2013reversing1.exe

When the program is run, it displays a jumbled mess as the flag. Something clearly went wrong.

IDA Pro shows that the program only goes into its decryption routine if a debugger is attached.

We simply run the program with IDA as a debugger and allow it to display the decrypted flag.

Flag: this1isprettyeasy:)



Reversing 150: bikinibonanza.exe

This program gives various failure messages when we enter a string, including misleading messages about adding or subtracting 3 to our string input.

Because the program is in .NET IL, we open it with Red Gate's .NET Reflector and find the relevant procedures.  The code takes the string "NeEd_MoRe_Bawlz" and the current hour (plus one), feeds them into another procedure, and compares the result with our input.  If they match, the program will display the flag.

The procedure that operates on the hour and fixed string calls another procedure that substitutes the values, then finally calculates an MD5 sum over the string.

We convert this code into Python so that we can run it over all 24 hours and get the valid inputs.

#!/usr/bin/python

import md5

key_string = "NeEd_MoRe_Bawlz"

def substitute(num2, num1):
s = [ 2, 3, 5, 7, 11, 13, 0x11, 0x13, 0x17, 0x1d, 0x1f, 0x25, 0x29, 0x2b,
0x2f, 0x35, 0x3b, 0x3d, 0x43, 0x47, 0x49, 0x4f, 0x53, 0x59, 0x61, 0x65,
0x67, 0x6b, 0x6d, 0x71 ]
return s[num1] ^ num2

def get_key(text1, num1):
t = ''
for num2 in xrange(len(text1)):
ch = text1[num2]
for num in xrange(num1):
ch = chr(substitute(ord(ch), num+1))
num += 1
t += ch;
return md5.new(t).hexdigest()

for i in xrange(24):
print get_key(key_string, i)

reversing-150.py

Finally, we feed the correct input for the computer's hour into the program and get the flag.

Flag: 0920303251BABE89911ECEAD17FEBF30



Reversing 200: csaw2013reversing2.exe

We initially run the program and nothing happens, so we'll open it in IDA Pro.  We simply start the binary in IDA's local debugger and guide the program to branch to the correct code, then examine memory just before the program terminates.

Alternatively, we could increment esi before allowing the call to MessageBoxA for the flag.

Flag: number2isalittlebitharder:p



Reversing 300: crackme

IDA Pro reveals that the file is an ELF that prompts for a key, hashes it, and succeeds if the hash equals 0xef2e3558.

The hash algorithm is a modified Bernstein hash with 1337 used as the start value instead of 5381.

unsigned int hash(char* s) {
unsigned int h = 1337;
while(*s) {
h = 33*h + *(s++);
}
return h;
}

We code up the algorithm and run it through Digital Operatives' constraint solver to generate matching strings.


~}?Jyjx
t~6pKpl
gt7_En;
*,2>bds
2k{].?=
GJJ4GSv
Piqqtoa
...

We send it off to the server and get the flag!

Flag: day 145: they still do not realize this software sucks



Reversing 400: keygenme32.elf

This file is an ELF; running it with no arguments gives:

usage: ./keygenme32.elf <username> <token 1> <token 2>

Analysis in IDA Pro shows this program creates a virtual CPU, executes an instruction stream with our provided username, then compares the two tokens to two of the registers within the virtual CPU via a check() function.

Rather than reversing the entire CPU instruction set, we write a GDB script to pull the values from the virtual CPU's registers and then derive the correct tokens.

break *0x804a2a2
run
file ./keygenme32.elf
x/xw $ebp+8
x/xw $ebp+12
kill
quit

script.gdb

#!/usr/bin/python

import socket
import re
import subprocess

server = '128.238.66.219'
port = 14549

prompt_pattern = re.compile('give me the password for (.*)')
gdb_pattern = re.compile('0x........:\t(0x........)')
gdb_command = ['gdb', '--batch', '-x', './script.gdb', '--args',
'./keygenme32.elf', 'WILL_BE_REPLACED', '0', '0']

# connect
s = socket.socket()
s.connect((server,port))

while True:
# get the prompt
prompt = ''
while prompt.find('give me the password for') == -1 and \
prompt.find('key') == -1:
prompt += s.recv(65536)
if prompt.find('key') != -1:
print prompt
s.close()
exit(0)
prompt = prompt.split('\n')
prompt = filter(None, prompt)
print repr(prompt)
prompt = prompt[-1]
name = prompt_pattern.match(prompt).group(1)

# place the name in the command
gdb_command[6] = name

# run it
p = subprocess.Popen(gdb_command, stdout=subprocess.PIPE)
output = p.communicate()[0]
print 'got output: '+output

# get values
output = output.split('\n')
output = filter(None, output)
token1 = gdb_pattern.match(output[-3]).group(1)
token2 = gdb_pattern.match(output[-2]).group(1)

# transform
token1 = int(token1, 16)
token1 ^= 0x31333337

token2_1 = token2[2:4]
token2_2 = token2[4:6]
token2_3 = token2[6:8]
token2_4 = token2[8:]
token2 = int('0x' + token2_3 + token2_1 + token2_2 + token2_4, 16)

# send the reply
reply = '%d %d\n' % (token1, token2)
print 'sending: '+reply
s.send(reply)

reversing-400.py

We run the Python script and get the flag!

Flag: r3vers1ng_emul4t3d_cpuz_a1n7_h4rd!



Reversing 500: Noobs First Firmware Mod

We are given a modified U-Boot firmware.  After setting up QEMU within an Ubuntu server virtual machine, we can use IDA Pro's Remote GDB Debugger to step through the code and analyze.  One of the first things U-Boot does is relocate itself from 0x00010000 to 0x07fd7000.  We can compensate for this in IDA by rebasing the program:

RebaseProgram(0x07fc7000, MSF_FIXONCE);

After digging around, we find a new command has been created, csaw, corresponding to the internal do_csaw function shown below.

The function, as hinted, has a bug in it: it attempts to copy from an empty/invalid memory address, 0x80002013. There is one other reference to this address, in the smc_init function, which tries to copy the string "SUPERSEXYHOTANDSPICY" there.  (The full string in the binary is actually "key!=SUPERSEXYHOTANDSPICY".)

Thus, we replace the two invalid addresses in do_csaw with the appropriate ones.  The remainder of do_csaw is supposed to extract characters from this string to construct the key, but again there is a bug — one of the pointers for the memcpy in its extraction loop is not incremented.  We code up some debugger hooks in IDC to do the work for us.

#include <idc.idc>

static fix_r5_and_r11()
{
SetRegValue(0x7feac27, "R5");
SetRegValue(0x7feac4f, "R11");
return 0;
}

static increment_r10()
{
SetRegValue(GetRegValue("R10") + 1, "R10");
return 0;
}

static main()
{
AddBpt(0x7fd8df0);
AddBpt(0x7fd8e10);
AddBpt(0x7fd8e34);
SetBptCnd(0x7fd8df0, "fix_r5_and_r11()");
SetBptCnd(0x7fd8e10, "increment_r10()");
}

reversing-500.idc

Flag: SPREYOADPC



Reversing 500: Impossible

We get a file, impossible.nds.  Analyzing strings in it reveals it is a Nintendo DS game file.  We load it up in no$gba and notice there are lots of debug strings printed, including "RENDER SHIP" and "RENDER WTF".  By placing read-access breakpoints on those strings, we can get context of the game state while tracing through each frame render.  An analysis of the registers leads us to an area of memory containing game time, score, and enemy HP, shown below.

Killing the enemy by modifying its HP causes the game to render a screen with the key, at which point we search the emulator memory for "key" and find the whole string.

Flag: ou6UbzM8fgEjZQcRrcXKVN

Email ThisBlogThis!Share to XShare to FacebookShare to Pinterest
Posted in | No comments
Newer Post Older Post Home

0 comments:

Post a Comment

Subscribe to: Post Comments (Atom)

Popular Posts

  • How to compile busybox with Android NDK for both ARM and x86 architectures
    I was looking for a way to run busybox on a Motorola RAZRi with an x86 Intel Atom processor but I couldn't find any Android app from th...
  • Security and Trust when Everything has a Computer In It
    Security and Trust when Everything has a Computer In It Recently, Panic Software announced that they had opened up an HDMI display adapter ...
  • Sony Cyber-shot DSC-HX200V 18.2 MP 30 x High Zoom GPS Digital Camera - BLACK
    Sony Cyber-shot DSC-HX200V 18.2 MP 30 x High Zoom GPS Digital Camera - BLACK Blogger Opportunity Giveaway from June 17 to  July 12 Come and ...
  • Free Blogger Opp – Timjan Design Malachite 5/1
    Here comes another Visionary Bri blogger opportunity. Sign up now for the Timjan Bloomers Giveaway. Our sponsor, Timjan Design , has offered...
  • Hackers that solve problems...
    The nation and the world at large are struggling to come to grips with the fact that we are now more than ever vulnerable in our daily lives...
  • How to build Python-4-Android for the ARM Neon
    Currently the Py4A project does not compile for the ARM Neon architecture. If you try to run ndk-build on the project by setting the APP_A...
  • How to Cross-Compile libiconv for Android
    If your legacy C/C++ code includes <iconv.h> to convert the encoding of characters from one coded character set to another, and you ne...
  • How to compile libogg for Android
    To compile libogg for Android, you just need to create an appropriate jni/Android.mk makefile with the minimum set of files and options need...
  • Problems with new version of rpmbuild
    The Problem With the new version of rpmbuild installed on CentOS 6.x, if you try to use an old RPM spec file, you will get an error like the...
  • Sony Cyber-shot DSC-HX200V Giveaway
    Hosted by: NYSavingSpecials and Your Fashion Resource ,  Co-hosted by Melissa Say What? ,  Barbara's Beat ,  LibbysLibrary ,  Confessio...

Categories

  • amazon
  • amazon.com
  • Android
  • Apple
  • Arduino
  • ARM
  • baby
  • baby reviews
  • back to school
  • beef jerky
  • bicycle. wagon
  • bike
  • Blanket Buddies
  • blogging
  • Blogging with The Tate's
  • books
  • busybox
  • camera
  • camera giveaway
  • candle giveaway
  • candles
  • CaseApp
  • CentOS
  • coffee
  • david haskell
  • dermorganic
  • DHCP
  • digital camera
  • events
  • Florida
  • Fortran
  • free blogger giveaway
  • free blogger sign-ups
  • full of flavor
  • giveaways
  • GNU
  • GPON
  • hair care
  • happy husband
  • Hot tea
  • Husband and Wife perspective
  • iMac
  • ipad
  • iphone
  • iphone case
  • iphone case review
  • Javascript
  • Keurig Coffee Review
  • Keurig Review
  • Kindle
  • ksh
  • LifeProof iPhone Case Review
  • Linux
  • MacOSX
  • Malachite Bloomers
  • man and women perspective
  • meat
  • Mips
  • Network
  • Pretzel Crisps
  • Pretzels
  • product reviews
  • products
  • Python
  • Router
  • scentsy
  • scentsy candles
  • school
  • scooter
  • security system
  • skin care
  • snacks
  • sony
  • sony cyber-shot
  • Stuff Animal
  • suface pro
  • Summer
  • summer fun
  • surface pro giveaway
  • techno thriller
  • Timjan Design
  • too much information
  • UNIX
  • vegan
  • vegan products
  • verizon
  • verizon fios
  • VitaminsBaby
  • waterproof case
  • Windows
  • x86
  • yummy

Blog Archive

  • ▼  2013 (41)
    • ►  November (2)
    • ►  October (2)
    • ▼  September (3)
      • Pretzel Crisps Review
      • CSAW CTF 2013 Qualification Round: Reversing
      • CSAW CTF 2013 Qualifiers: Crypto 300 Writeup
    • ►  August (3)
    • ►  July (2)
    • ►  June (2)
    • ►  May (6)
    • ►  April (8)
    • ►  March (2)
    • ►  February (5)
    • ►  January (6)
  • ►  2012 (17)
    • ►  December (3)
    • ►  November (4)
    • ►  October (8)
    • ►  July (1)
    • ►  June (1)
Powered by Blogger.

About Me

Unknown
View my complete profile