난 정말 최고야 멋있어
CTFLearn - Bite-code 본문
자바 바이트 코드를 풀어내는 문제
바이트코드는 어렵진 않으나... 맞는 답을 찾는 과정이 더 어려운 기이한 문제
public static boolean checkNum(int); descriptor: (I)Z flags: ACC_PUBLIC, ACC_STATIC Code: stack=2, locals=3, args_size=1 0: iload_0 1: iconst_3 2: ishl 3: istore_1 //v1 = param <<3 4: iload_0 5: ldc #2 // int 525024598 7: ixor 8: istore_2 //v2 = param ^ 525024598 9: iload_1 10: iload_2 11: ixor 12: ldc #3 // int -889275714 //v1^ v2== -889275714일때 정답출력 14: if_icmpne 21 17: iconst_1 18: goto 22 21: iconst_0 22: ireturn LineNumberTable: line 3: 0 line 4: 4 line 5: 9 StackMapTable: number_of_entries = 2 frame_type = 253 /* append */ offset_delta = 21 locals = [ int, int ] frame_type = 64 /* same_locals_1_stack_item */ stack = [ int ] |
파이썬으로 브루트포스 스크립트를 만들어서 풀었다
계산량이 꽤 많으므로 멀티프로세스를 이용했다
import multiprocessing
base_list = [0x00000000,0x10000000,0x20000000,0x30000000, 0x40000000,0x50000000,0x60000000,0x70000000, 0x80000000,0x90000000,0xa0000000,0xb0000000, 0xc0000000,0xd0000000,0xe0000000,0xf0000000] def solve(base): for i in range(base,base+0xfffffff): v1 = (i << 3)&0xffffffff v2 = i ^ 0x1f4b3d56 if (v1^v2) == 0xcafebabe : print(f'Answer is {i}') break
if __name__ == '__main__': pool = multiprocessing.Pool(processes=8) pool.map(solve,base_list) pool.close() pool.join() |
(base) D:\pythonprojects>python bitecode.py
Answer is 2942112424
이때 2942112424 는 signed int 로는 -1352854872가 된다