iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 8
0
Security

點錯遊戲的我也只好硬著頭皮上了 系列 第 8

[基本技巧] diff - 比對檔案內容

「Still awake?」
「Of course I’m awake! What are you talking about? I’ve ben helping you since I woke up. When didI do anything for them?」
「I’m trying to break things gently to you. It may have been a mistake to bring it up at all, the mind is delicate.」
「I’d feel better if I knew what you were talking about, believe me.」
「Do you remember how you were taken?」
「I already told you, I don’t’!」
「Wait. There is something… A light.」
「I think I was… excited. intent. And then there was nothing.」
「You’re starting to remember.」


10. whats-the-difference

Can you spot the difference? kitters cattos. They are also available at /problems/whats-the-difference_0_00862749a2aeb45993f36cc9cf98a47a on the shell server
你能找出這兩張圖的不同處嗎? kitters cattos。檔案可在以下路徑找到:/problems/whats-the-difference_0_00862749a2aeb45993f36cc9cf98a47a on the shell server
https://ithelp.ithome.com.tw/upload/images/20200922/20103688TF6zsRPf98.png

HINT:

How do you find the difference between two files?
Dumping the data from a hex editor may make it easier to compare.

WRITEUP:

這裡的核心問題是如何比對非文字(圖片)類型的檔案,我們必須先要讀出檔案的內容,接著使用文字比對的指令,最後再來考慮如何加速標記相異處。

回到題目,打開shell 連入該目錄後,查看兩張圖(可下載回來本地端)會發現長的不太一樣,尤其是第二張圖的像素怪怪的,
https://ithelp.ithome.com.tw/upload/images/20200922/20103688n21ffRryvr.png
左為 kitters.jpg ,右為 cottons.jpg

第一步,找出如何讀出檔案內容,google “linux dump nontext file” 得知內建指令 hexdump可以做到

hexdump kitter.jpg
0000000 d8ff e0ff 1000 464a 4649 0100 0101 4800
0000010 4800 0000 dbff 8400 0100 0101 0101 0101
0000020 0101 0101 0101 0202 0203 0202 0202 0304
0000030 0203 0503 0504 0505 0404 0504 0706 0506
0000040 0705 0406 0604 0609 0807 0808 0808 0605
0000050 0d09 090a 0d08 070a 0808 0108 0101 0201
0000060 0202 0204 0402 0508 0504 0808 0808 0808
0000070 0808 0808 0808 0808 0808 0808 0808 0808
*
以下略

第二步,找出如何比對文字檔,google ”linux compare files command” 得知內建令 diff 能夠做到
於是乎透過將 hexdump 與 diff 接在一起使用:

diff  <(hexdump kitters.jpg) <(hexdump cattos.jpg) 
3079c3079
< 000c060 a66d 994b 989d 60c8 951b e841 3db9 ad1b
---
> 000c060 a66d 704b 6369 606f 951b e841 3db9 ad1b
5452,211852c5452,212281

執行完會發現...嗯,是能成功比對沒錯,可是肉眼實在太難(懶)找出大量不同處了。因此最後一步再google 看看是否能有幫助標色的軟體。google “diff by character” 。得知有 diff-highlight 可以標出不同處,但此套件需要另行安裝,所以以下的操作皆在自己的 linux 主機。
diff-highlight安裝方法如下:

pip install diff-highlight
sudo cp ~/.local/bin/diff-highlight /usr/local/bin/

安裝完畢後進行比對

diff -u <(hexdump kitters.jpg) <(hexdump cattos.jpg) | diff-highlight

https://ithelp.ithome.com.tw/upload/images/20200922/20103688CVUaIPjUA4.png

這裡的不同處為 70 6369 6f,丟到轉換器還真的能轉出文字 pcio。到這裡是不是看出 flag 了? 將以上的不同處全部找出來後再貼到轉換器即可得到完整的 flag

p.s. 文字順序似乎有點不同,63與69這一對排在一起的需要反過來解碼才會是正確的 pico,這是為什麼呢,有興趣的可以看淺談計算機編碼(整數篇)。如果在 windows 使用 notepad ++ 等編輯器,順序就會是 70 6963 6f(pi co)

ANSWER:

picoCTF{th3yr3_a5_d1ff3r3nt_4s_bu773r_4nd_j311y_aslkjfdsalkfslkflkjdsfdszmz10548}


上一篇
[基本技巧] net cat - 網路版 cat,連接網路兩端的讀寫工具
下一篇
[基本技巧] ls - 列出檔案目錄
系列文
點錯遊戲的我也只好硬著頭皮上了 30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言