Verizon Fios Tech Support

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

Monday, 23 September 2013

CSAW CTF 2013 Qualifiers: Crypto 300 Writeup

Posted on 09:55 by Unknown
The CSAW Capture The Flag online qualifiers were held last weekend (9/19/2013 through 9/22/2013). The top 10 undergraduate teams will participate in the CSAW CTF finals in November; however the qualifiers were open to everyone and a small team from Digital Operatives participated. Below is a writeup of one of the Crypto challenges:

The Crypto 300 challenge was contained entirely in a tarball that contains a custom encryption Python script and nine encrypted files. The encryption algorithm reuses a single 256-byte key to XOR each subsequent block of the input file. Simple XOR encryption of uncompressed files often leads to the key sticking out of the ciphertext when the input file contains many zeroes. This is also the case with some rudimentary binary packers that XOR data inside themselves. In the case of Crypto 300, thousands of blocks were given to us in the ciphertext files, providing many opportunities to find (0 XOR key[i]) instances scattered throughout the files. For instance, if at byte offsets 0+blocksize * x (where x is a non-negative integer) in the ciphertexts frequently contains 0x40, it is likely that byte 0 of the key is 0x40.


We created a simple Python script to count the number of times each byte value occurs at each block offset.

#!/usr/bin/python
import os
import sys

blocksize=256
prefix="output/file"
suffix=".enc"

blocks=[]

for x in range(0,9):
        fxname = prefix + str(x) + suffix
        try:
                print "Opening " + fxname
                fx = open(fxname,'rb')
        except:
                print "Failed to open " + fxname
                continue
        moretoread = True
        while moretoread:
                block = fx.read(blocksize)
                if(len(block) < blocksize):
                        moretoread = False
                        print "Last block was " + str(len(block)) + " bytes."
                blocks.append(block)        

print "Extracted " + str(len(blocks)) + " blocks."

#Calculate the number of times each byte value occurs at each position in a block
histogram = [[0 for i in range(blocksize)] for j in range(blocksize)]
for block in blocks:
        for b in range(0, len(block)):
                val = ord(block[b])
                histogram[b][val] = histogram[b][val] + 1

#Get the most used byte value for each position in the block
maxvals=[0 for i in range(blocksize)]
for hidx in range(0, len(histogram)):
        bytearr = histogram[hidx]
        cur_max_pos = 0
        cur_max_count = 0
        for idx in range(0,len(bytearr)):
                count = bytearr[idx]
                if count > cur_max_count:
                        cur_max_count = count
                        cur_max_pos = idx
        maxvals[hidx] = cur_max_pos

f = open("newsecretkey.dat","wb")
f.write(bytearray(maxvals))
f.close()

print "Done"

With the key in our newsecretkey.dat we are then able to decrypt all of the files from the challenge output folder using our new secret key and some simple Python borrowed from onlythisprogram.py.

#!/usr/bin/python
import os
import sys
import argparse

blocksize=256

parser = argparse.ArgumentParser(description="Decryption")
parser.add_argument('--infile', metavar='i', nargs='?', type=argparse.FileType('r'), help='input file, defaults to standard in', default=sys.stdin)
parser.add_argument('--outfile', metavar='o', nargs='?', type=argparse.FileType('wb'), help='output file, defaults to standard out', default=sys.stdout)
parser.add_argument('--secretkey', metavar='s', nargs='?', type=argparse.FileType('a+'), help='output file, defaults to secretkey.dat', default='secretkey.dat')

args = parser.parse_args()

counter=0
args.secretkey.seek(0)
keydata = args.secretkey.read(blocksize)
print "Using secret key: "
print keydata

while 1:
        byte = args.infile.read(1)
        if not byte:
                break
        args.outfile.write(chr(ord(keydata[counter % len(keydata)]) ^ ord(byte)))
        counter+=1

sys.stderr.write('\nSecret keyfile: %s\nInput file: %s\nOutput file: %s\nTotal bytes: %d \n' % (args.secretkey.name, args.infile.name, args.outfile.name, counter))

Use the following commands with the above decrypt.py:

./decrypt.py --infile=output/file4.enc --outfile=file4.enc.gz --secretkey=newsecretkey.dat
gzip -d file4.enc.gz
vim file4.enc
:set nowrap

After decryption we have nine plaintext files.  The fifth file (file4.enc) is a gzip compressed ASCII file that contains a message and the key: BuildYourOwnCryptoSoOthersHaveJobSecurity

For Hackers nostalgia, play the MIDI file0! 


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