YellowFish
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights
    • Engagement control
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Versions and GitHub Sync Note Insights Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       owned this note    owned this note      
    Published Linked with GitHub
    Subscribed
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    Subscribe
    ###### tags: `lsa` `ncnu` # Week 02 (2024/02/29) - Book mode: https://hackmd.io/@ncnu-opensource/book [TOC] ## FHS 1. `/etc/password` & `/etc/shadow` 差別 - `/media` 媒體資料夾 - `/mnt` 掛載資料夾 - `/opt` 第三方應用程式資料夾 - `/lib` 系統和應用程式所需的函式庫 - `/run` 程式和服務的運行暫存資料夾 - `proc` 儲存當前核心運作狀態 - `/home` 使用者根目錄(```~/```) - `/var` 系統暫存檔(嗎 - `/tmp` 暫存(我都拿來放一次性的 Code :D) - `ls` 指令 - 不一定會有顏色,都是 bash 去檢查檔案類型加的 - 圖片檔是普通檔案?有的說不定會有顏色 - 執行檔,是檢查 executable bit - 要看環境變數 - `export` 看到你的 shell - `export | grep -i path` - 尤其是 PATH=xxxxx ,是你在 shell 裡去下指令時預設會去找的路徑 - 如果發現裡面有個路徑權限是 777 的話,可能是你被駭了 - 具體攻擊手法: 1. 駭客可能用暴力破解 SSH 密碼進來你的電腦 2. 在 `~/.profile` 或 `~/.bashrc` 的 PATH 變數加入自己有放惡意程式的路徑在最前面 3. 之後使用者去下任何指令就會第一個去駭客控制的這資料夾去找 4. 惡意程式假裝自己是 bash ,先看你在 bash 裡做了什麼事,再幫你把輸入給真正的 bash 5. 要是他剛好有用到 sudo 輸入密碼就記起來;去 `.bash_history` 裡面找你有沒有剛好用 `mysql -u <user> -p <password>` 來輸入你的密碼;去 exploit-db 去找這作業系統已知弱點,裡面 Local Type 的攻擊方法要有拿到帳號使用權才能用 - PS: exploit-db 上面有一些 PoC 程式碼會故意弄一些小錯誤讓 script kiddie 沒那麼容易拿去用 7. 下次駭客進來就能拿到 superuser 權限,可以真正在你系統重要路徑做壞事 - Q: 密碼很容易被暴力破解嗎? - 有大家常用使用者名稱/密碼,建表之後先去試就比較快 - 例如 admin:admin, fedora:!qaz2wsx - /bin 和 /sbin 差在哪 > 你有 sbin 也有 bin [name=BlueT] - 簡單來講: sbin 裡的東西用錯的話比較會用壞系統; bin 裡的東西比較不會用壞系統 - /sbin 例如 - ifconfig 要是設錯網路設定會害你無法再遠端連進去機器 - /bin 例如 - zip 只是解壓縮壓縮,很無害 - /usr - 其實以前是系統必要的檔案不會放在這的,等需要的時候再 mount 起來 - 某派系之爭(?)之後才變這樣 - `/etc/fstab` 或 `mount` 指令 - 有些 fs 有 (nodev) 標籤 - 你可以掛載時叫他 noatime ,不然每次 access 都去改他 access time timestamp 多很多次 io - ex. `/var/www` (web server 用的) 有人就會這樣做(因需大量存取,或是 ftp 的檔案之類的) - (ro) 標籤可以讓他 read only,如果你的 /usr 可以不被別人亂動的話會比較安全,因為前面講到環境變數裡的 PATH 第一個去找的就是這裡 - `/etc/skel` - 用 `ls -a` 才看得到隱藏檔 - 新增使用者時,使用者家目錄預設會新增的檔案 - 攻擊者也可以在裡面加壞東西 - /dev/shm - 權限是 777 - 除了 `/tmp` 之外會有 777 的地方 - 用 `mount` 看 type 是 tmpfs - 大小是你有的 RAM 一半 - 你複製進來的東西 os 會搬進記憶體裡 - 如果你在這放東西,又沒開 swap ,記憶體佔完,系統會變比較不穩定 - 也可以在裡面放惡意程式 - /proc - 有支援 proc filesystem 的系統會有這東西 - 可以從這裡找到某程式的 cmdline/COMMAND/CMD 是啥 - 像是 `./systemd` 一定有鬼 - 但有可能執行 process 後把原執行檔從 disk 刪掉 - /media - 有桌面環境的 distribution 比較會預設幫你掃描到插入的 USB 掛載起來 - /var/log/syslog - 系統的紀錄檔 - 很多程式都會預設把紀錄檔弄到這裡來,要 debug 問題也可以先來看看 ## 指令補充 - `alias` - 別名,好方便喔 - 推薦大家 `ls -alh` > 下 ls 指令不加 -a ,不如不要下 [name=BlueT] - 有看過有檔案取名叫 `.` 或 `...` - 我推薦 `rm -i` - `ls` - 檔案 - 權限 - r: read - w: write - x: execute - `touch` - 如果沒有對應的檔名,就會建立新檔案 - `mkdir` 建立新目錄 - `mv` 移動或重新命名檔案 - `mv <原始位置> <目標位置>` - `mv <原檔名> <新檔名>` - `mv <file1> <file2>... <目錄>` 將多個檔案搬至目標位置 - `rmdir`:刪除指定空目錄 - `rm`:刪除檔案或目錄 - `-r`: recursive - `-f`: 強制刪除 - `-i` - `echo`: 輸出使用者輸入的內容 - `echo <content> <filename>` - `echo <content> > <filename>` - 特殊符號 - `>`: 覆寫 - `>>`: append - `<`: - `<<`: - `cat`:輸出指定檔案的內容 - -b:印出行數 - -n - `grep`:找關鍵字 - -i:不分大小寫 - -n:顯示行號 - -E: ::: info pipe ( | ) 前面的輸出作為後面指令的輸入 ::: - `ln <source file> <link file>`:建立連結檔 - 一般預設是建立硬連結 - -s: 建立軟連結 - `whoami`:查看目前的使用者 - `groups`:查看使用者所在的群組 - `id`:查看自己的 UID 及所在群組的 GID - `who`:當前使用者的登入紀錄 - `sudo` 使用管理員權限 - 使用者 - `usermod` 修改使用者權限 - `adduser` 新增使用者 - `deluser` 刪除使用者 - `passwd` 修改當前使用者密碼 - 群組 - `groupadd` 添加群組 - `groupdel` 刪除群組 ## **chmod** ``` chmod [options] mode file... ``` **選項:** * `-R`:遞迴變更目錄和其子檔案的權限。 * `-a`:設定所有權限。 * `-o`:設定特定權限。 **模式:** * `r`:讀取權限。 * `w`:寫入權限。 * `x`:執行權限。 **檔案:** 指定要變更權限的檔案或目錄的名稱。 **範例:** ``` chmod 644 file.txt # 賦予 file.txt 可讀、可寫入和可執行權限。 chmod -R 755 directory # 賦予 directory 的所有子檔案和目錄可讀、可寫入和可執行權限。 chmod -a 0 file.log # 銷除 file.log 的所有權限。 ``` **注意事項:** * 權限值必須是 0-7 之間的數字。 * 如果指定了 `-R` 選項,則會變更目錄和其子檔案的權限。 * 如果沒有指定檔案或目錄,則會影響目前目錄中的所有檔案和目錄。 * 使用 `-o` 選項時,必須指定特定的權限。 --- ## chgrp ``` chgrp [options] group file... ``` **選項:** * `-R`:遞迴變更目錄和其子檔案的群組。 * `-o`:設定特定群組。 **檔案:** 指定要變更群組的檔案或目錄的名稱。 **範例:** ``` chgrp group file.txt # 將 file.txt 的群組變更為 group。 chgrp -R group directory # 將 directory 的所有子檔案和目錄的群組變更為 group。 ``` **注意事項:** * 群組值必須是系統中存在的群組名稱。 * 如果指定了 `-R` 選項,則會變更目錄和其子檔案的群組。 * 如果沒有指定檔案或目錄,則會影響目前目錄中的所有檔案和目錄。 --- ### 查詢相關ㄉ | 指令 | 功能 | | --- | --- | | find | 在目錄中尋找檔案 | | grep | 在檔案中搜尋文字 | | loc | 找到指定檔案的路徑 | | man | 顯示指定命令的手冊頁 | | pwd | 顯示目前目錄的路徑 | | stat | 取得檔案或目錄的狀態 | | chown | 變更檔案或目錄的所有權和群組 | | chmod | 變更檔案或目錄的權限 | | chattr | 設定檔案或目錄的屬性 | | cp | 複製檔案或目錄 | | mv | 移動或改名檔案或目錄 | | rm | 刪除檔案或目錄 | | touch | 創建新的檔案或目錄 | **find 指令** ``` find [路徑] -[條件] -exec command {} \; ``` `find` 指令用來在目錄中尋找檔案。 - **路徑**:要搜尋的目錄。 - **條件**:用來篩選搜尋結果的條件。 - **command**:找到檔案後要執行的命令。 **範例:** - 尋找目前目錄下所有以 `.txt` 結尾的檔案: ``` find . -name "*.txt" ``` - 尋找目前目錄下所有檔案大小超過 100 MB 的檔案: ``` find . -size +100M ``` - 尋找目前目錄下所有可執行檔案: ``` find . -type f -executable ``` **grep 指令** ``` grep [模式] [檔案] ``` `grep` 指令用來在檔案中搜尋文字。 - **模式**:要搜尋的文字模式。 - **檔案**:要搜尋的檔案。 **範例:** - 在 `/etc/passwd` 檔案中搜尋所有包含 "root" 的行: ``` grep root /etc/passwd ``` - 在所有 `.txt` 檔案中搜尋所有包含 "hello" 的行: ``` grep -R "hello" *.txt ``` **loc 指令** ``` loc [檔案] ``` `loc` 指令用來找到指定檔案的路徑。 - **檔案**:要查找的檔案。 **範例:** ``` loc ls ``` **man 指令** ``` man [命令] ``` `man` 指令用來顯示指定命令的手冊頁。 - **命令**:要查看手冊頁的命令。 **範例:** ``` man ls ``` **pwd 指令** ``` pwd ``` `pwd` 指令用來顯示目前目錄的路徑。 **範例:** ``` pwd ``` **stat 指令** ``` stat [檔案] ``` `stat` 指令用來取得檔案或目錄的狀態。 - **檔案**:要查看狀態的檔案或目錄。 **範例:** ``` stat /etc/passwd ``` **chown 指令** ``` chown [使用者]:[群組] [檔案] ``` `chown` 指令用來變更檔案或目錄的所有權和群組。 - **使用者**:新的檔案所有者。 - **群組**:新的檔案群組。 - **檔案**:要變更所有權和群組的檔案或目錄。 **範例:** ``` chown root:wheel /etc/passwd ``` **chattr 指令** ``` chattr [屬性] [值] [檔案] ``` `chattr` 指令用來設定檔案或目錄的屬性。 - **屬性**:要設定的檔案屬性。 - **值**:要設定的屬性值。 - **檔案**:要設定屬性的檔案或目錄。 **範例:** ``` chattr +i /etc/passwd ``` **cp 指令** ``` cp [來源] [目標] ``` `cp` 指令用來複製檔案或目錄。 - **來源**:要複製的檔案或目錄。 - **目標**:複製檔案或目錄 --- - `man` - `head` - `tail` - `file` - `whereis` 找檔案位置 - `which` 找指令存的位置 - `find` 根據設定的條件查詢檔案或目錄 - `env` environment, 顯示目前 shell 下的所有環境變數與說明 - `printenv` 輸出所有環境變數 - `type` 查看指令類型 - `-t` - file as 外部指令 - alias ### `apt` 套件管理器 | 指令 | 功能 | | --- | --- | | apt | 顯示 APT 的版本資訊 | | apt-cache | 查詢 APT 資料庫 | | apt-cdrom | 從 CD-ROM 安裝軟體 | | apt-get | 安裝、更新、移除軟體 | | apt-mark | 標記軟體包 | | apt-policy | 設定 APT 的策略 | | apt-preferences | 設定 APT 的偏好設定 | | apt-show | 顯示軟體包的資訊 | | apt-source | 安裝軟體包的原始碼 | **apt 指令** ``` apt ``` `apt` 指令用來顯示 APT 的版本資訊。 **範例:** ``` apt ``` **apt-cache 指令** ``` apt-cache [指令] ``` `apt-cache` 指令用來查詢 APT 資料庫。 - **指令**:要執行的查詢指令。 **範例:** - 搜尋所有可用的軟體包: ``` apt-cache search ``` - 顯示指定軟體包的資訊: ``` apt-cache showpkg <package-name> ``` **apt-cdrom 指令** ``` apt-cdrom [指令] ``` `apt-cdrom` 指令用來從 CD-ROM 安裝軟體。 - **指令**:要執行的安裝指令。 **範例:** ``` apt-cdrom install <package-name> ``` **apt-get 指令** ``` apt-get [指令] ``` `apt-get` 指令用來安裝、更新、移除軟體。 - **指令**:要執行的操作指令。 **範例:** - 安裝指定軟體包: ``` apt-get install <package-name> ``` - 更新所有已安裝的軟體包: ``` apt-get update apt-get upgrade ``` - 移除指定軟體包: ``` apt-get remove <package-name> ``` **apt-mark 指令** ``` apt-mark [指令] ``` `apt-mark` 指令用來標記軟體包。 - **指令**:要執行的標記指令。 **範例:** - 標記指定軟體包為自動安裝: ``` apt-mark auto <package-name> ``` - 標記指定軟體包為手動安裝: ``` apt-mark manual <package-name> ``` **apt-policy 指令** ``` apt-policy [指令] ``` `apt-policy` 指令用來設定 APT 的策略。 - **指令**:要執行的設定指令。 **範例:** - 設定 APT 的預設安裝位置: ``` apt-policy -d /usr/local ``` **apt-preferences 指令** ``` apt-preferences ``` `apt-preferences` 指令用來設定 APT 的偏好設定。 **範例:** - 設定 APT 的優先順序: ``` Package: * Pin: release a=stable Pin-Priority: 900 ``` **apt-show 指令** ``` apt-show [指令] ``` `apt-show` 指令用來顯示軟體包的資訊。 - **指令**:要執行的顯示指令。 **範例:** - 顯示指定軟體包的詳細資訊: ``` apt-show <package-name> ``` **apt-source 指令** ``` apt-source [指令] ``` `apt-source` 指令用來安裝軟體包的原始碼。 - **指令**:要執行的安裝指令。 **範例:** - 安裝指定軟體包的原始碼: ``` apt-source install <package-name> ``` ### Downloader - `wget` - `curl` ### 網路相關 - `ifconfig` 大家的網卡相關訊息好朋友 - 記得先裝 net-tools - `sudo apt install net-tools` - `route` - `ping` - `traceroute` - `nslookup` - `netstat` - `speedtest` - 需要安裝 - `sudo apt install speedtest-client`

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully