コード例 #1
0
ファイル: set2.py プロジェクト: tcharding/lang
def chal_11():
    '''An ECB/CBC detection oracle'''
    chal = (2, 11)
    s = b'yellow submarineyellow submarineyellow submarineyellow submarine'
    for i in range(64):
        c = encryption_oracle(s)
    return ran(chal, True, True)
コード例 #2
0
ファイル: set2.py プロジェクト: tcharding/lang
def chal_9():
    """Implement PKCS#7 padding"""
    chal = (2, 9)
    b = b'YELLOW SUBMARINE'
    exp = b"YELLOW SUBMARINE\x04\x04\x04\x04"
    got = pad(b, 20)
    return ran(chal, exp, got)
コード例 #3
0
ファイル: set1.py プロジェクト: tcharding/lang
def chal_3():
    """Single-byte XOR cipher"""
    chal = (1, 3)
    s = b'1b37373331363f78151b7f2b783431333d78397828372d363c78373e783a393b3736'
    exp = b'Cooking MC\'s like a pound of bacon'

    brute_force = bruteforce_scx(hex_to_byte(s))
    rated = rate(brute_force)
    got = (top_rated(rated))
    return ran(chal, exp, got)
コード例 #4
0
ファイル: set1.py プロジェクト: tcharding/lang
def chal_2():
    """Fixed XOR"""
    chal = (1, 2)
    s = b'1c0111001f010100061a024b53535009181c'
    t = b'686974207468652062756c6c277320657965' 
    exp = b'746865206b696420646f6e277420706c6179'

    b = same_length_xor(hex_to_byte(s), hex_to_byte(t))
    got =  byte_to_hex(b)
    return ran(chal, exp, got)
コード例 #5
0
ファイル: set1.py プロジェクト: tcharding/lang
def chal_1():
    """Convert hex to base64"""
    chal = (1, 1)
    s = b'49276d206b696c6c696e6720796f757220627261696e206c'
    s += b'696b65206120706f69736f6e6f7573206d757368726f6f6d'
    exp = b'SSdtIGtpbGxpbmcgeW91ciBicmFpbiBsaWtlIGEgcG9pc29ub3VzIG11c2hyb29t'
    b = hex_to_byte(s)
    got = byte_to_base64(b)

    return ran(chal, exp, got)
コード例 #6
0
ファイル: set1.py プロジェクト: tcharding/lang
def chal_8():
    """Detect AES in ECB mode"""
    chal = (1, 8)
    got = (False, "")
    f = open('8.txt')
    for line in f:
        b = hex_to_byte(line.strip("\n").encode('ascii'))
        if has_repeating_blocks(b):
            got = (True, line)
    
    return ran(chal, True, got[0])
コード例 #7
0
ファイル: set2.py プロジェクト: tcharding/lang
def chal_12():
    '''Byte-at-a-time ECB decryption (Simple)'''
    chal = (2, 12)
    f = open('12.exp.txt')
    exp = f.read().encode('ascii')

    n = twelve.detect_blocksize()
    if has_repeating_blocks == False:
        raise RuntimeError("ciphertext does not appear to be using ECB mode")
    got = twelve.attack_ecb()
    return ran(chal, exp, got)
コード例 #8
0
ファイル: set1.py プロジェクト: tcharding/lang
def chal_5():
    """Implement repeating-key XOR"""
    chal = (1, 5)
    key = b'ICE'
    s = b'Burning \'em, if you ain\'t quick and nimble\n'
    s += b'I go crazy when I hear a cymbal'
    exp = b'0b3637272a2b2e63622c2e69692a23693a2a3c6324202d623d63343c2a'
    exp += b'26226324272765272a282b2f20430a652e2c652a3124333a653e2b202'
    exp += b'7630c692b20283165286326302e27282f'

    got = byte_to_hex(repeating_xor( bytearray(s), bytearray(key)))
    return ran(chal, exp, got)
コード例 #9
0
ファイル: set1.py プロジェクト: tcharding/lang
def chal_4():
    """Detect single-character XOR"""
    chal = (1, 4)
    filename = '4.txt'
    exp = b'Now that the party is jumping\n'

    rated = []
    for line in open( filename ):
        b = hex_to_byte( line.strip("\n" ))
        rated.extend( rate( bruteforce_scx( b )))
    got = top_rated( rated )
    return ran(chal, exp, got)
コード例 #10
0
ファイル: set1.py プロジェクト: tcharding/lang
def chal_7():
    """AES in ECB mode"""
    chal = (1, 7)
    key = b'YELLOW SUBMARINE'
    f = open('7.exp.txt')
    exp = f.read()
    exp = exp[0:len(exp)-1]
    exp = exp.encode('ascii')
    

    f = open('7.txt')
    c = f.read()
    got = decrypt_ecb(base64.b64decode(c), key)
    return ran(chal, exp, got)
コード例 #11
0
ファイル: set1.py プロジェクト: tcharding/lang
def chal_6():
    chal = (1, 6)
    f = open('6.exp.txt')
    exp = f.read().strip("\n")

    f = open('6.txt')
    b = base64_to_byte( f.read().encode('ascii') )
    # keysize = keysize_friedman_method(b)
    keysize = 29                # from above
    # key = crack_key(b, keysize)
    key = b'Terminator X: Bring the noise' # from above
    
    got =  repeating_xor(b, key).decode('ascii')
    return ran(chal, exp, got)
コード例 #12
0
ファイル: set2.py プロジェクト: tcharding/lang
def chal_10():
    '''Implement CBC mode'''
    chal = (2, 10)
    f = open('10.txt')
    ciphertext = base64.b64decode(f.read())
    key = b'YELLOW SUBMARINE'
    iv = chr(0x00) * 16
    iv = iv.encode('ascii')

    assert (len(iv) == 16)
    assert (len(key) == 16)

    got = decrypt_cbc(ciphertext, iv, key)

    f = open('10.exp.txt')
    exp = bytearray(f.read().encode('latin-1'))
    return ran(chal, exp, unpad(got))
コード例 #13
0
ファイル: set2.py プロジェクト: tcharding/lang
def chal_16():
    chal = (2, 16)
    return ran(chal, True, sixteen.attack_cbc())
コード例 #14
0
ファイル: set2.py プロジェクト: tcharding/lang
def chal_15():
    '''completed in block.py'''
    chal = (2, 15)
    return ran(chal, 1, 1)
コード例 #15
0
ファイル: set2.py プロジェクト: tcharding/lang
def chal_13():
    '''ECB cut-and-paste'''
    chal = (2, 13)
    exp = b'admin'
    role = thirteen.attack_ecb()
    return ran(chal, exp, role)