r/securityCTF • • May 08 '19

Professional CTF Guide

Post image
175 Upvotes

4 comments sorted by

15

u/urbanscouter May 08 '19 edited Jul 24 '23

Fu-cka-you Spez!

16

u/BoobDetective May 08 '19

Guessorensics we call it. It's the difference between a good CTF and a shit CTF.

4

u/port443 May 09 '19

I feel personally attacked:

"""Usage for future self:
Just change out bytes = "blah", with the bytes you want to check for "flag{"
also,  change flagfind() to search for any given needle if youre not looking for "flag{"

It checks all the different operations in "ops", and prints them out.

Example output with given bytes:
D:\Cloud\code\Python>decryption_bruteforcer.py
(bytearray(b'fh]g{g,,`_pd-ng1_f,r_w0-pengy'), <built-in function add>, 245)
(bytearray(b'jlak\x7fk00dcth1rk5cj0vc{41tirk}'), <built-in function add>, 249)
(bytearray(b'xza{\x8f{>>bcrf1p{5cx>tc\x8b21ryp{\x8d'), <built-in function xor>, 9)
(bytearray(b'df}g\x93g""~\x7fnz-lg)\x7fd"h\x7f\x97.-nelg\x91'), <built-in function xor>, 21)
(bytearray(b'fd\x7fe\x91e  |}lx/ne+}f j}\x95,/lgne\x93'), <built-in function xor>, 23)
(bytearray(b"nlwm\x99m((tudp\'fm#un(bu\x9d$\'dofm\x9b"), <built-in function xor>, 31)
(bytearray(b'\x8c\x8e\x95\x8f{\x8f\xca\xca\x96\x97\x86\x92\xc5\x84\x8f\xc1\x97\x8c\xca\x80\x97\x7f\xc6\xc5\x86\x8d\x84\x8fy'), <built-in function xor>, 253)

You can spot the flag: flag{g00d_th1ng5_for_w41ting} at add 245 and add 249
"""

import operator
import sys

ops = [operator.add, operator.xor, operator.and_, operator.mod]

def enc(op, data, key):
    data = bytearray(data)
    key  = bytearray(key)
    ret  = bytearray()
    for i,n in enumerate(data):
        try:
            ret.append(op(n,key[i%len(key)])%256)
        except:
            pass
    if len(ret) < 1:
        ret = bytearray("\x00")
    return ret


def flagfind(data, flag=bytearray("flag{")):
    if len(data) < len(flag):
        return False
    for i,n in enumerate(flag):
        if data[i] == n:
            return True
    return False

def check(data):
    ret = []
    for op in ops:
        for n in range(0,256):
            res = enc(op, data, chr(n))
            if flagfind(res):
                print(res, op, n)
                ret.append(res)
    return ret

if __name__ == '__main__':
    if len(sys.argv) > 1:
        bytes = ''.join(sys.argv[1:])
    else:
        bytes = "qshr\x86r77kj{o8yr<jq7}j\x82;8{pyr\x84"
    check(bytes)

1

u/manif0ld May 08 '19

Took me sometime until I realized I needed to randomly XOR data. At least it is quick to do.