Tuesday, April 19, 2016

Sctf 2016 Q Unbrewed (85 pts)


File : unbrewed.jar
Hint  : Unlike pour-over, this coffee can be unbrewed.

lets decompile  unbrewed.jar





interesting Array :

IntArray(new int[] { -102, 30, -46, -83, 123, 110, 105, 99, -116, 34, -59, -66, 112, 95, 111, 102, -74, 13, -55, -66, 114, 95, 111, 118, -116, 15, -37 })))

Decimal2ascii

-102
30
-46
-83
123 {
110 n
105 i
99  c
-116
34
-59
-66
112 p
95  _
111 o
102 f
-74
13
-55
-66
114 r
95 _
111 o
118 v
-116
15
-37

XXXX{nicXXXXp_ofXXXXr_ovXXX

the flag start  with sctf and last is }

hint : pour-over

sctf{nicXXXXp_ofXXXXr_ovXX}

sctf{nicXXXXp_ofXpour_over}

sctf{nicXXXXp_of_pour_over}

guess :

sctf{nice_XXp_of_pour_over}

flag is  sctf{nice_cup_of_pour_over}




SCTF 2016 Q - Verticode (Crypto)


SCTF  2016 Q

Welcome to Verticode, the new method of translating text into vertical codes.
Each verticode has two parts: the color shift and the code.
The code takes the inputted character and translates it into an ASCII code, and then into binary, then puts that into an image in which each black pixel represents a 1 and each white pixel represents a 0.
For example, A is 65 which is 1000001 in binary, B is 66 which is 1000010, and C is 67 which is 1000011, so the corresponding verticode would look like this.
Except, it isn't that simple.
A color shift is also integrated, which means that the color before each verticode shifts the ASCII code, by adding the number that the color corresponds to, before translating it into binary. In that case, the previous verticode could also look like this.
The table for the color codes is:
Value Color
0 Red
1 Purple
2 Blue
3 Green
4 Yellow
5 Orange
This means that a red color shift for the letter A, which is 65 + 0 = 65, would translate into 1000001 in binary; however, a green color shift for the letter A, which is 65 + 3 = 68, would translate into 1000100 in binary.
Given this verticode, read the verticode into text and find the flag.
Note that the flag will not be in the typical sctf{flag} format, but will be painfully obvious text. Once you find this text, you will submit it in the sctf{text} format. So, if the text you find is adunnaisawesome, you will submit it as sctf{adunnaisawesome}.



Python script to decode the image :

import Image
def open_image(path):
    im = Image.open(path)
    im = im.convert('RGB')
    return im
im = open_image("code1.png")
def decode_line(j):
    row1 = [im.getpixel((i,j)) for i in range(im.size[0]/2)]
    row2 = [im.getpixel((i,j)) for i in range(im.size[0]/2,im.size[0])]
    row1 = row1 [::12]
    row2 = row2 [::12]
    for i in range(len(row2)):
        if row2[i] == (0,0,0):
            row2[i]= 1
        if row2[i] == (255,255,255):
            row2[i]= 0

    bincode   = ''.join([str(item) for item in row2])
    table_color = [(255,0,0),(128,0,128),(0,0,255),(0,128,0),(255,255,0),(255,165,0)]
    position = table_color.index(row1[0])
    decoded = chr(int(bincode, 2) - position )
    return decoded

flag=''

for j in range(0,im.size[1],12):
    flag += str(decode_line(j))
print flag 

JoeLopowasamanofmildtemperamentshortstatureandhadthegoaltobecometheworldsfastesttelephonee
aterThoughLoponeverknewevenbasicphysicshecreatedatelescopecapableofsightingthesmallesthair
onanalienwholivedquiteafewlightyearsawayJoeLopoquicklydestroyedalargeboulderandusedtheshat
teredremainstoformeightsmallstatuesthatstronglyresembledtinycreaturesbeingorrelatedtothewa
terfleaHeplacedtheminacircularpatterntoformasortofshrineandplacedthetelescopeinthemiddleof
itHethenchanneledthepowerofthestonewaterfleasintothetelescopetoviewthepoweroftheheavensHew
asinatrancewiththebeautyofthemysteriousdimensionanddidntevennoticetheverylargetornadoheadi
ngtowardhimTheshrinewasquicklydemolishedandtheimmediatewithdrawlofpowersentJoeLobointoalai
rofpitchblacknessfoundtobeaparalleldimensionthatcausABCiamtheflagalllowercasenojokeDEFanyo
newhosefirstnamebeganwithJalongwithMLandQtobecomeratheruncomfortableJoewasalsosuddenlyintr
oducedtoundroclamaticolomphasisciousytheeccentrictapewormwithastrongmorrocanaccentImundroc
lamaticolomphasisciousytheeccentrictapewormIlikepizzasohowareyadoinIhavenoideasaidJoe

flag is :  sctf{iamtheflagalllowercasenojoke}


Monday, April 18, 2016

AngstromCTF2016 - Smartest Encryption (re, 70)









We have  a PNG encrypted image :  https://angstromctf.com/static/problems/re/image_encryptor/flag.encrypted .
Softawre used to crypt the image : https://angstromctf.com/static/problems/re/image_encryptor/encryptor.apk

Hint : PNG image

first step decompile encryptor.apk :

The application ask for a password , create the hash of this password and than XOR the PNG image using key=md5(password) .
Routine to encrypt is  :
private byte[] encryptData(byte[] paramArrayOfByte1, byte[] paramArrayOfByte2)
  {
    int i = (byte)paramArrayOfByte2.length;
    byte[] arrayOfByte = new byte[paramArrayOfByte1.length];
    for (int j = 0; j < paramArrayOfByte1.length; j++) {
      arrayOfByte[j] = ((byte)(paramArrayOfByte1[j] ^ paramArrayOfByte2[(j % i)]));
    }
    return arrayOfByte;
  }










 Extract 32 Byte from flag.ecrypted :




 crypted=553430f1536d0beb5537521568637d36


png_header= 89504e470d0a1a0a0000000d49484452


key = crypted XOR png_header

def xor_strings(xs, ys):
    return "".join(chr(ord(x) ^ ord(y)) for x, y in zip(xs, ys))
crypted='553430f1536d0beb5537521568637d36'
png_header='89504e470d0a1a0a0000000d49484452'
binary_a = crypted.decode("hex")
binary_b = png_header.decode("hex")
key= xor_strings(binary_a, binary_b).encode("hex")
print key

dc647eb65e6711e155375218212b3964

Online md5 :















Now xor the   flag.encrypted using key = dc647eb65e6711e155375218212b3964  using xortool https://github.com/hellman/xortool




The flag is flag{all_encryption_is_equal_but_some_are_More_equal_than_others}