“Security used to be an inconvenience sometimes, but now it’s a necessity all the time.” — Martina Navratilova.
老樣子先wget下載檔案後,執行看看,如果Permission Denied的話用chmod +x賦予權限:
$ wget https://mercury.picoctf.net/static/cfea736820f329083dab9558c3932ada/warm
$ ./warm
-bash: ./warm: Permission denied
$ chmod +x ./warm
$ ./warm
根據輸出結果,我們加上 -h這個option:
# 並非每個執行檔都會提供 -h這個option!
$ ./warm -h
"oh, help? I actually do not do much, but I do have
this flag here: picoCTF{b1scu1ts_4nd_gr4vy_30e77291}"
$ wget https://artifacts.picoctf.net/c/23/convertme.py
$ python convertme.py
"If 100 is in decimal base, what is it in binary base?
Answer:"
可以看到這個程式會給定十進制的數,我們要回答該數轉換成二進制的結果。既然題目有給Source Code,那我們就打開看看吧!
import random
def str_xor(secret, key):
#extend key to secret length
new_key = key
i = 0
while len(new_key) < len(secret):
new_key = new_key + key[i]
i = (i + 1) % len(key)
return "".join([chr(ord(secret_c) ^ ord(new_key_c)) for (secret_c,new_key_c) in zip(secret,new_key)])
flag_enc = chr(0x15) + chr(0x07) + chr(0x08) + chr(0x06) + chr(0x27)
+ chr(0x21) + chr(0x23) + chr(0x15) + chr(0x5f) + chr(0x05) + chr(0x08)
+ chr(0x2a) + chr(0x1c) + chr(0x5e) + chr(0x1e) + chr(0x1b) + chr(0x3b)
+ chr(0x17) + chr(0x51) + chr(0x5b) + chr(0x58) + chr(0x5c) + chr(0x3b)
+ chr(0x4c) + chr(0x06) + chr(0x5d) + chr(0x09) + chr(0x5e) + chr(0x00)
+ chr(0x41) + chr(0x01) + chr(0x13)
num = random.choice(range(10,101))
print('If ' + str(num) + ' is in decimal base, what is it in binary base?')
ans = input('Answer: ')
try:
ans_num = int(ans, base=2)
if ans_num == num:
flag = str_xor(flag_enc, 'enkidu')
print('That is correct! Here\'s your flag: ' + flag)
else:
print(str(ans_num) + ' and ' + str(num) + ' are not equal.')
except ValueError:
print('That isn\'t a binary number. Binary numbers contain only 1\'s and 0\'s')
程式很簡單明瞭,我們可以看到當我們回答正確後,會去調用str_xor去解碼flag_enc,於是我們只要想辦法讓程式調用str_xor即可。
有兩種方法:
第一種:由於題目只有一題,我們可以用計算機、程式或者手算二進制出來,然後就可以得到答案。
第二種:由於是在我們本地自己執行,所以也可以把這個檔案做修改後再執行,跳過驗證的部分:
try:
ans_num = int(ans, base=2)
if True or ans_num == num: # 讓這個if判斷強制執行!
flag = str_xor(flag_enc, 'enkidu')
print('That is correct! Here\'s your flag: ' + flag)
else:
print(str(ans_num) + ' and ' + str(num) + ' are not equal.')
(延伸思考: 有沒有什麼方法獲得num的值?嘗試使用pdb看看!)
另外,嘗試去理解這題的加密方法,密碼學也是資訊安全的一塊喔!