Hiển thị các bài đăng có nhãn Crypto. Hiển thị tất cả bài đăng
Hiển thị các bài đăng có nhãn Crypto. Hiển thị tất cả bài đăng

Thứ Bảy, 10 tháng 12, 2016

[writeup] SECCON quals 2016

Giải SECCON  đầu tiên. Đội làm được 4 bài thôi mà 3 bài có dấu răng mình :3. Mặc dù chơi pwn mà chả pwn được bài nào :(. Quá kém.

Bài đầu tiên nhiều người giải nhất : Vignere 















Vigenre ? Nhìn qua thấy được là k có 12 kí tự.   Mà nhờ có 8 kí tự SECCON{} nên sẽ tính được 8 kí tự đầu của key là VIGENERE. Còn 4 kí tự sau thì brute force rồi kiểm tra với md5 thôi

Code : http://pastebin.com/UDZwC1Uv
Key : VIGENERECODE
flag : SECCON{ABABABCDEDEFGHIJJKLMNOPQRSTTUVWXYYZ}

Memory Analysis



















file : http://files.quals.seccon.jp/memoryanalysis.zip

Bài này làm khá ngáo =)). Không đổi domain thành IP làm không ra (Tks Khánh =)) )

Kiểm tra file trước 









Thêm cái hint là xem file hosts với thêm 1 cái nữa là file svchost fake







dump 2 file đó ra 





Kiểm tra 2 file thấy được ip bị chuyển tới và url của nó 







Curl và flag đây rồi :





flag : SECCON{_h3110_w3_h4ve_fun_w4rg4m3_}


Anti-Debugging








file : http://files.quals.seccon.jp/bin
Kiểm tra là file bin: PE32 executable (console) Intel 80386, for MS Windows
Bật ida lên xem qua : main http://pastebin.com/w5T5sHnU
Chú ý có đoạn này 
  1. printf("Input password >");
  2.   v3 = (FILE *)sub_40223D();
  3.   fgets(&v23, 64, v3);
  4.   strcpy(v21, "I have a pen.");
  5.   v22 = strncmp(&v23, v21, 0xDu);
  6.   if ( !v22 )
  7.   {
  8.     puts("Your password is correct.");
....

ủa vậy là flag là "I have a pen." à ? Tất nhiên là k phải (đã thử submit =)) ). Cái này chỉ để kiểm tra rồi nó chạy xuống thôi. 

Nhìn hết hàm main mà chả có gì đáng chú ý ngoài mấy cái check debug. Chuyển sang graph xem. 
Chú ý có cái này (Tks Khánh again =)) )










loc_401652:
mov     [ebp+var_78], 0
cmp     [ebp+var_78], 1
jnz     loc_40174D

Dòng trên làm nó luôn nhảy vào loc_40174D (nhánh bên phải). Vậy check xem nhánh bên trái xem sao. 
Đại khái là có một chuỗi khác rồi nó làm này nhọ gì nhức óc lắm vì vậy nên mình patch lại file bin này. Chuyển byte 1 ở trên thành cmp với 0 => vậy nó sẽ nhảy về nhánh bên trái 
Chuyển sang hex view xem (Bôi đen dòng đó rồi chuyển sang hex view sẽ thấy )









Rồi bật hex editor lên chuyển thành 83 7d 88 00 thôi 
file path : https://drive.google.com/file/d/0B-QPcxnExPUcamRLWGx6amRQVHc/view?usp=sharing
Run (Nhớ tắt mấy trình debug)





Flag : SECCON{check_Ascii85}

Thứ Sáu, 2 tháng 9, 2016

[write-up][ADCTF2014] crypto day 8 ROTATE

file http://adctf2014.katsudon.org/dat/bvvpSQFmYqKQLhEp/rotate.zip
extract thì có 2 file. 1 file là encypt hình và một file là flag.jpg.enc

import sys
import math
import struct

p = lambda x: struct.pack('f', x)
u = lambda x: struct.unpack('b', x)[0]

if len(sys.argv) != 3:
    sys.exit(1)

filename = sys.argv[1]
key = math.radians(int(sys.argv[2]))

bs = open(filename, 'rb').read()
enc = open(filename + '.enc', 'wb')

for i in range(0, len(bs), 2):
    x, y = u(bs[i]), u(bs[i+1])
    enc.write(p(x * math.cos(key) - y * math.sin(key)) + p(x * math.sin(key) + y * math.cos(key)))



Program này hoạt động như sau :
 - Ta truyền vào 2 argv ban đầu là tên file cần encrypt, thứ 2 là key. Key ở đây là một số. Do có đoạn 
"key = math.radians(int(sys.argv[2]))"
nên key chỉ nằm ở khoảng 0 - 360 . Sau đó sẽ đọc từng char xong file hình là encrypt theo công thức.
Sau khi hiểu cách hoạt động của program, mình bắt đầu vào viết code. Vì là code decrypt nên sẽ tiếp cận theo cách bottom-up.
Sau khi thử encrypt một file bình thường thì mình thấy sau khi encrypt thì từ 1 char ban đầu sẽ tăng lên 4 char, thì thế mình sẽ tách một đoạn 8 kí tự ra làm 2 phần. Sau đó giải pt tìm x và y. Rồi tiếp tục pack char đó lại về thành bs[i] và bs[i+1]. Sau khi decrypt, ta cần phải kiểm tra xem phải file hình không. Ban đầu mình kiểm tra header là ffd8ffe000 tuy nhiên k có file nào hợp lệ. Vì vậy đã giảm xuống ffd8ff. Tuy vậy nhưng vẫn decrypt được file như bình thường. 
Đây là code decrypt :
import sys
import math
import struct

z = lambda x: struct.unpack('f', x)[0]
t = lambda x: struct.pack('b', int(round(x)))


def cp(x): #check if x can pack with func t()
    if int(round(x))>127:
        return 0 
    elif int(round(x))<-128:
        return 0
    else:
        return 1


def decode(filee,key):
    de=''
    key=math.radians(int(key))
    sx=math.sin(key)
    cx=math.cos(key)
    for i in range(0,len(filee),8):
        a=z(filee[i:i+4]) 
        b=z(filee[i+4:i+8])
        y=((b*cx-a*sx)) 
        x=(a+y*sx)/cx
        if cp(x)==0 or cp(y)==0 :
            return 0
        xx=t(x)
        yy=t(y)
        de+=xx+yy
    if de.encode('hex')[:6]=='ffd8ff':
        return de
    else:
        return 0
def solve(filename):
    filee=open(filename,'rb').read()
    dc=open(filename + '.jpg','wb')
    for i in range(360): 
        if i!=0 and i!=90 and i!=270:
            if decode(filee,i)!=0 :
                print i
                dc.write(decode(filee,i))
solve(sys.argv[1])

Thứ Bảy, 27 tháng 8, 2016

[write-up][CTF(x)] [Crypto50] λ (lambda)


I used this program to encrypt a flag. The output was:n1s4_t1An(f1ctdb@mpl_h3)m3lp3y__Eas


print (lambda j,m:(lambda f,t:t if len(t) <= 1 else j([f(f,x)for x in m(j,m(reversed,(lambda s:zip(*[iter(s)]*(len(s)/2)))(t+"\x01"*(len(t)%2))))]))(lambda f,t:t if len(t) <= 1 else j([f(f,x)for x in m(j,m(reversed,(lambda s: zip(*[iter(s)]*(len(s)/2)))(t+"\x01"*(len(t)%2))))]),raw_input("Plaintext:")))(''.join,map).replace("\x01","")

I realized it's a obfuscation code so it too hard to reverse code to readable. So i think a ez way to solve this challenge. I think this program will change pos of char so i will find the pos of each char before encypt.
First i check length of cipher:
len("n1s4_t1An(f1ctdb@mpl_h3)m3lp3y__Eas")=35

Then i encrypt this type of flag : 


ctf(ABCDEFGHIJKLMNOPQRSTUVWXYZ0123)

after i encrypted this type of flag. i would found the pos of each char in this type of flag in encrypted flag. Here is my decrypt code :

def
enc(plaintext): return (lambda j,m:(lambda f,t:t if len(t) <= 1 else j([f(f,x)for x in m(j,m(reversed,(lambda s:zip(*[iter(s)]*(len(s)/2)))(t+"\x01"*(len(t)%2))))]))(lambda f,t:t if len(t) <= 1 else j([f(f,x)for x in m(j,m(reversed,(lambda s: zip(*[iter(s)]*(len(s)/2)))(t+"\x01"*(len(t)%2))))]),plaintext))(''.join,map).replace("\x01","") def dcode(cipher): flag_type="ctf(ABCDEFGHIJKLMNOPQRSTUVWXYZ0123)" flag="" for x in flag_type: flag+=cipher[enc(flag_type).find(x)] return flag cip='n1s4_t1An(f1ctdb@mpl_h3)m3lp3y__Eas' print "\nFLAG : ", dcode(cip)


Input : n1s4_t1An(f1ctdb@mpl_h3)m3lp3y__Eas
FLAG : ctf(1@mbd4_1nsAn1ty_pl3asE_h3lp_m3)