# CTF
[](https://hackmd.io/R5cRa6t1R8SZCj0Vtf_Fng)
###### tags: `Information Security`
> 參考資料: https://ithelp.ithome.com.tw/m/articles/10265748
---
[TOC]
---
## 「億」些指令
| 命令 | 說明 | 用法 |
| ---- | ------------ | ------------ |
| cat | 查看檔案內容 | cat `檔案名` |
| wget | 下載檔案 | wget `網址` |
| \-\-help | 查看命令使用說明 | `命令` --help |
| grep | 在檔案中尋找符合條件的關鍵字或正規表示法 | grep `關鍵字` `檔案名` |
| unzip | 解壓縮 | unzip '檔案名' |
| nc(netcat) | 讓你直接連接一個遠方主機,它向你送訊息、你也向它送訊息,這樣一個溝通工具 | 超級無敵多用法 |
| man | 查詢指令用法 | man `指令` |
---
## picoCTF例題
### Obedient Cat
**Description**
This file has a flag in plain sight (aka "in-the-clear"). [Download flag](https://mercury.picoctf.net/static/a5683698ac318b47bd060cb786859f23/flag)).
#### 解法

---
### Python Wrangling
**Description**
Python scripts are invoked kind of like programs in the Terminal... Can you run [this Python script](https://mercury.picoctf.net/static/2ac2139344d2e734d5d638ac928f1a8d/ende.py) using [this password](https://mercury.picoctf.net/static/2ac2139344d2e734d5d638ac928f1a8d/pw.txt) to get [the flag](https://mercury.picoctf.net/static/2ac2139344d2e734d5d638ac928f1a8d/flag.txt.en)?
#### 解法
**step1.**

cat `flag.txt.en`和`pw.txt`。
**step2.**

執行`ende.py`,
`Usage: ende.py (-e/-d) [file]`表示需要輸入一個檔案,參數選項 -e, -d,基本上就是encode和decode。
接著按照提示輸入指令`python3 ende.py -d flag.txt.en`(記得一定要python3!只打python不給過:D),會跑出`Please enter the password:`,此時輸入剛剛cat pw.txt的內容,就會跑出flag了。
---
### Wave a flag
**Description**
Can you invoke help flags for a tool or binary? [This program](https://mercury.picoctf.net/static/fc1d77192c544314efece5dd309092e3/warm) has extraordinarily helpful information...
#### 解法
**step1.**
`wget`後,檔案為`warm`
**step2.**

無法執行(權限不足)
**step3.**

輸入`chmod +x ./warm`,幫`warm`加上執行權限
(此處注意是`./warm`而非`warm`,`./warm` 代表「目前目錄下的`warm`檔案」)
**step4.**

執行`warm`後,出現提示字!
按照提示,使用`-h`查詢`warm`的說明
**step5.**

輸入`./warm -h`,即出現flag!
---
### Nice netcat...
**Description**
There is a nice program that you can talk to by using this command in a shell: `$ nc mercury.picoctf.net 49039`, but it doesn't speak English...
#### 解法
**step1.**

按照題目輸入`$ nc mercury.picoctf.net 49039`後,出現一大串數字
step2.

將其丟到十進制轉ASCII,轉換結果為flag
---
### Static ain't always noise
**Description**
Can you look at the data in this binary: [static](https://mercury.picoctf.net/static/e9dd71b5d11023873b8abe99cdb45551/static)? This [BASH script](https://mercury.picoctf.net/static/e9dd71b5d11023873b8abe99cdb45551/ltdis.sh) might help!
#### 解法
**step1.**

執行兩個下載下來的檔案,其中輸入`./ltdis.sh`時,輸出寫到`disassembly`(反組譯),它會將執行檔的二進位檔案內容,轉換成對應組合語言。
> wiki: 反組譯器(disassembler)是一種將機器語言轉換為組合語言的電腦程式——這與組譯器的目的相反。反組譯器與反編譯器不同,反編譯器的目標是高階語言而非組合語言。反組譯器的反組譯輸出通常格式化為適合人類閱讀,而非用作組譯器的輸入源,因此它主要是一個逆向工程工具。
**step2.**

再來,看到執行`ltdis.sh`出現的`ltdis.sh <program-file>`,因此輸入`./ltdis.sh ./static`。
出現`Any strings found in ./static have been written to ./static.ltdis.strings.txt with file offset`,代表flag在`static.ltdis.strings.txt`裡。
**step3.**

接著,因為要找到在`static.ltdis.strings.txt`的flag,所以輸入`grep 'picoCTF' ./static.ltdis.strings.txt`(表示要在`static.ltdis.strings.txt`裡找到`picoCTF`關鍵字)。最終找到flag。
---
### Tab, Tab, Attack
**Description**
Using tabcomplete in the Terminal will add years to your life, esp. when dealing with long rambling directory structures and filenames: [Addadshashanammu.zip](https://mercury.picoctf.net/static/a350754a299cb58988d6d47aed5be3ba/Addadshashanammu.zip)
#### 解法
**step1.**

先解壓縮檔案。
解壓縮出來的檔案路徑檔名很長,目錄也很多層。
**step2.**

先進去`Addadshashanammu`資料夾之後,打`./`後爆按Tab,shell自動幫你補上所有路徑,最後到達`fang-of-haynekhtnamet`這個檔案,接著按Enter執行,即跑出flag。
---
### what's a net cat?
**Description**
Using netcat (nc) is going to be pretty important. Can you connect to jupiter.challenges.picoctf.org at port 25103 to get the flag?
#### 解法

輸入`netcat(or nc) jupiter.challenges.picoctf.org 25103`即可。
---
### strings it
**Description**
Can you find the flag in [file](https://jupiter.challenges.picoctf.org/static/94d00153b0057d37da225ee79a846c62/strings) without running it?
#### 解法
**step1.**


題目提示你要用`strings`指令,那就先查查看`strings`要怎麼用。
輸入`man strings`查看用法,按`q`離開。
**step2.**

輸入`strings strings`(`指令` `檔名`)後,跑出來一大串東西。
**step3.**

此時使用大絕招`strings strings | grep "pico"`**(grep)**,成功找到flag。
---
###