# 成為駭客的前一哩路 ## Chapter 1 - Getting Start With The Basics ### Introductory Terms and Concepts * Binaries: 二進位執行檔 (就像在 Linux 中的 Windows 上的執行檔) ,通常是 Linux 的指令及工具。 * Case sensitivity: 在 Linux 系統中,檔案名稱和路徑的大小寫要區分好 (不然會找不到) * Directory: 資料夾 * Home: /home 資料夾,通常檔案創建儲存的地方 * Kali: 一個 for hacker 的 Linux 系統 * Root: 管理員帳號 * Script: 在終端上執行的指令、腳本 * Shell: 在 Linux 上執行指令的環境 (bash) * Terminal: 命令行介面 (Command Line Interface CLI) --- ### A Tour of Kali * /root: 管理員的主資料夾 * /etc: 包含 Linux 設定檔 (控制程序啟動) * /home: 使用者的主資料夾 * /mnt: 其他額外的檔案系統 * /media: CD 或 USB 連接或安裝到的資料夾 * /bin: 裝 *binaries* 的地方 * /lib: 裝 *libraries* 的地方 (類似 Windows 的 DLL 檔案) --- ### Basic Commands in Linux 1. 查詢當前路徑: **pwd** (print working directory) ![screenshot_20231102_183143.png](https://hackmd.io/_uploads/HyFiclWmT.png) 2. 查看當前登陸的使用者: **whoami** ![screenshot_20231102_183308.png](https://hackmd.io/_uploads/Skk_N-bQa.png) 3. 改變當前所在位置: **cd** (change directory) ![screenshot_20231102_183536.png](https://hackmd.io/_uploads/BkcP4--Xp.png) 如果想要回到上一層資料夾可以用 `cd ..` ![screenshot_20231102_191544.png](https://hackmd.io/_uploads/rJRyHWWXp.png) 想要回到上上層可以使用 `cd ../..` 以此類推 4. 查看當前資料夾內資料: **ls** (list) ![screenshot_20231102_194728.png](https://hackmd.io/_uploads/SJ0Un--mp.png) 也可以用 `ls PATH` 來去查看特定資料夾內的資料 ![screenshot_20231102_195542.png](https://hackmd.io/_uploads/r11UCbWXT.png) 也可以加上參數 `-l` 來查看更詳細有關權限 (l 代表 long) ![screenshot_20231102_195827.png](https://hackmd.io/_uploads/r17lkfW7a.png) 另外也可以加上 `-a` 來查看隱藏的資料夾或檔案 ![screenshot_20231102_200129.png](https://hackmd.io/_uploads/rkYo1GWmT.png) :::info `-l` 和 `-a` 都可以單獨使用或混合使用,順序也不影響 ::: 5. 查看幫助: **--help** * `--` 代表要使用單字的選擇 (`--help`) * `-` 代表要使用單字元的選擇 (`-h`) ![screenshot_20231102_200535.png](https://hackmd.io/_uploads/B1yilf-Xa.png) ![screenshot_20231102_200711.png](https://hackmd.io/_uploads/HkgJ-bfZQa.png) 6. 查看幫助手冊(更詳細): **man** (manual) ![screenshot_20231102_200907.png](https://hackmd.io/_uploads/S1-dZM-7a.png) 進入 man 的頁面後可以使用上下方向滾動菜單 ![screenshot_20231102_200925.png](https://hackmd.io/_uploads/rkQtWGb76.png) 如果要退出就按下 `q`,按下 `h` 可以進入指令幫助 --- ### Finding Stuff 1. 查看儲存庫中含有關鍵字的資料: **locate** ![screenshot_20231102_201804.png](https://hackmd.io/_uploads/SJpFQfWXT.png) 2. 找到工具的 *binaries* 和 *man* 位置: **whereis** ![screenshot_20231102_202207.png](https://hackmd.io/_uploads/S1ndVM-XT.png) 3. 找到工具的 *binaries* 路徑(比 `whereis` 更精確去找執行檔): **which** ![screenshot_20231102_202411.png](https://hackmd.io/_uploads/rkFgBfWm6.png) 4. 更強力的查找工具: **find** :::info 語法: `find directory option expression` ::: * 範例: - 顯示資料夾裡面的內容 ![image.png](https://hackmd.io/_uploads/HyPLkpN7p.png) - 退回 /home 開始找 crud.py ![image.png](https://hackmd.io/_uploads/BJR9J6NQ6.png) - 獲得找尋路徑 ![image.png](https://hackmd.io/_uploads/SJ_2yaNma.png) 5. 顯示運行中的進程: **ps aux** ![screenshot_20231102_212705.png](https://hackmd.io/_uploads/H1p3QX-XT.png) 6. 篩選出特殊關鍵字: **grep** 我們可以搭配 `ps aux` 去使用查找特定的進程 ![screenshot_20231102_213112.png](https://hackmd.io/_uploads/Syg2EQbmT.png) --- ### Modifying Files and Directories 1. 查看檔案內容或創建檔案: **cat** ![screenshot_20231102_213337.png](https://hackmd.io/_uploads/rk1BSmWmp.png) 2. 新增檔案內容或創建檔案: **cat >>** ![screenshot_20231102_213512.png](https://hackmd.io/_uploads/r1aqBmbXa.png) 3. 複寫檔案內容或創建檔案: **cat >** ![screenshot_20231102_213713.png](https://hackmd.io/_uploads/rywGUm-mp.png) 4. 創建檔案: **touch** ![screenshot_20231102_214054.png](https://hackmd.io/_uploads/SyAmP7-ma.png) 5. 創建資料夾: **mkdir** ![screenshot_20231102_214301.png](https://hackmd.io/_uploads/HyEOwQZ7p.png) 6. 複製檔案: **cp** ![screenshot_20231102_214623.png](https://hackmd.io/_uploads/ByCBOXZQT.png) 7. 重新命名檔案: **mv** ![screenshot_20231102_214743.png](https://hackmd.io/_uploads/ryycum-Xa.png) 8. 刪除檔案: **rm** ![screenshot_20231102_214952.png](https://hackmd.io/_uploads/Bk0ZYXbma.png) 9. 刪除資料夾: **rmdir** ![screenshot_20231102_215045.png](https://hackmd.io/_uploads/S1QHYmb7p.png) 如果資料夾內有資料是不能直接刪除的,要先進入資料夾刪除檔案後才能刪除資料夾 ![screenshot_20231102_215206.png](https://hackmd.io/_uploads/HkL9FXZmT.png) 使用 `rm -r` 即可刪除資料夾及其內容 --- ### Exercise 1. 在 root (/) 資料夾內使用 `ls` 探索 Linux 的檔案結構,利用 `cd` 改變位置和 `pwd` 查看是否真的進入該資料夾 2. 使用 `whoami` 查看登陸的使用者 3. 使用 `locate` 查找 **wordlists** (用來 Password Cracking) 4. 使用 `cat` 創建新檔案再新增內容到檔案 5. 創建新資料夾 **hackeddirectory**,在裡面創建新檔案 **hackedfile**,將其複製到 **/root** 資料夾並重命名為 **secretfile** --- <a href="https://hackmd.io/@MatchaCode/H1qPTyHma" role="button" style="display:block; text-align:right;"> 下一篇: Chapter 2</a>