Reversing.kr - 2019 進度

Sun, Aug 18, 2019 2-minute read

題目:Easy Crack, Ransomware

Easy Crack

Challenge Info

只有 Easy_CrackMe.exe 一個檔案

Solution

使用 file Easy_CrackMe.exe 分析檔案

1
Easy_CrackMe.exe: PE32 executable (GUI) Intel 80386, for MS Windows

實際執行看到有一個視窗可以輸入內容:

隨便輸入,得到警告訊息: Incorrect Password

看來目標應該跟 Password 有關


用 IDA pro(32 位元)開啟 Easy_CrackMe.exe

WinMain(x,x,x,x) 開始 trace code,它在最後 call DialogFunc

因此前往 DialogueFunc,看到它最後 call sub_401080

sub_401080 應該就是比較 Password 的 function

它在一開始宣告四個變數 String, var_63, var_62, var_60 儲存基本上連續的位置,然後在下面依序有四次比較:

第一個是 61h 對應到 'a'

第二個是 a5y 對應到 "5y"

第三個是 aR3versing 對應到 "R3versing"

第四個是 45h 對應到 'E'

因此根據位置排序,Password 應該是 “E” + “a” + “5y” + “R3versing” = Ea5yR3versing


實際輸入結果如下,看來沒有錯,而它也是 flag。

Flag

Ea5yR3versing


Ransomware

Challenge Info

file, run.exe, readme.txt 三個檔案

Solution

readme.txt 內容如下:

1
2
3
4
Decrypt File (EXE)


By Pyutic

可能代表是要解密某個東西。

執行 run.exe 看看,前面有一段不知道在說什麼,後面要求輸入 key,輸入之後會再有一段亂碼。

file run.exe 分析檔案:

1
run.exe: PE32 executable (console) Intel 80386, for MS Windows, UPX compressed

看來被 UPX 壓縮過,用 upx -d run.exe 解碼即可丟到 IDA 分析。


是說前面有一大堆沒用的東西,讓 IDA 跑很久…

1
2
3
4
5
6
...
401009:       50      pushl   %eax
40100a:       58      popl    %eax
40100b:       53      pushl   %ebx
40100c:       5b      popl    %ebx
...(重複很多次)

跳過之後看到程式會先將 file 讀出來(rb),之後會寫到 byte_5415B8

然後 loop byte_5415B8 的每個 byte,做一連串計算之後將結果寫回 file 裡面(wb)。

上面提到的一連串計算是重點,它會將三個參數(藍色匡的部分)做 xor,它們分別是(假設 loop 到第 i 個 byte):

  • byte_5415B8[i]
  • key[i%len(key)]
  • 0xFF

剛才觀察到的整個流程大致如下:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
with open('./file', 'rb') as f:
	f_data = r.read()

enc = []
for i in range(len(f_data)):
	enc.append(f_data[i] ^ key[i%len(key)] ^ 0xFF)
enc = bytes(enc)

with open('./file', 'wb') as f:
	f.write(enc)

也就是說 run.exe 的作用是讀取 key 然後更改 file


這個時候 readme.txt 便派上用場,它似乎暗示 file 應該要是個 EXE 檔,如果是這樣,代表只要找到更改它的 key 就能反推回原本的 file

因為 file 要是 EXE 檔,其前 116 位為固定值( DOS HeaderDOS STUB ),只要 key 的長度不大於 116,便可以逆推,腳本如下:

1
2
3
4
5
6
7
8
with open('./file', 'rb') as f:
    f_file = f.read()
with open('./run.exe', 'rb') as f:
    f_header = f.read()

for i in range(116):
    print(chr(f_file[i] ^ f_header[i] ^ 0xff), end="")
print()

執行結果:

1
letsplaychessletsplaychessletsplaychessletsplaychessletsplaychessletsplaychessletsplaychessletsplaychessletsplayches

十分順利,key 每 13 位會重複,因此 key 為 "letsplaychess" 或其倍數( "letsplaychessletsplaychess" 之類的)

一開始測試時在 run.exe 隨便輸入了 key 導致 file 已經被改掉了,因此執行腳本前要重新解壓一份新的 file


執行 run.exe 輸入 "letsplaychess",得到 file.exe 並且執行,然後跑出小錯誤 QQ

修復之後得到 Key -> Colle System

Flag

Colle System