NCNU-OpenSource
      • 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
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners 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
    • 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 Help
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
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners 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: `1111` `lsa` `ncnu` # Week 13 (2022/12/08) [TOC] - Book mode: https://hackmd.io/@ncnu-opensource/book --- ## 期中考題檢討 ### 手寫 1. Ubuntu 在台灣推廣的負責人是誰? **(2%)** > BT 2. 如果 ssh 到一台經常連線的 server 中間發生 MITM (Man-in-the-middle attack) 會出現什麼狀況?** > 警告 public key 不匹配,請你確認 3. (3%)** 請問 ssh 是利用什麼機制去偵測 MITM?**(3%)** > server public key == client public key 3. 系統中哪個檔案存放真正的使用者密碼(須回答完整路徑)? **(2%)** > `/etc/shadow` 4. 系統中哪一個特殊的使用者的家目錄預設不是在 `/home/` 底下?**(2%)** > root、超級使用者 5. 請解釋何為 swap 空間?**(2%)** 如果沒規劃 swap 空間會發生什麼事情? **(2%)** > 延伸記憶體、交換空間 > process 打亂、系統崩潰 6. 請說明 CSMA/CD (Carrier Sense Multiple Access / Collision Detection) 和 CSMA/CA (Carrier Sense Multiple Access / Collision Avoidance) 不同之處? **(3%)** 舉例分別運用於哪種網路環境 **(3%)** 7. 使用 `adduser` 指令新增兩個使用者 `使用者1` `使用者2`,不加任何額外的參數,且沒有更動過任何權限,請回答以下問題,並解釋 1. `使用者1` 可以跑去 `使用者2` 家目錄下新增檔案嗎?**(1%)** 為甚麼? **(2%)** >不行 因為`使用者1`沒有`使用者2`的權限 2. 接下來如果把 `使用者1` 的 uid 改成 `使用者2` 的 uid,這樣 `使用者1` 可以在 `使用者2` 的家目錄下新增檔案嗎? **(1%)** 為甚麼? **(2%)** 可以 因為在Linux系統中,使用者是靠id去區分的,會以為`使用者1`是`使用者2`,所以可以新增檔案 3. 再接下來 `使用者1` 可以回到自己的家目錄下新增檔案嗎?**(1%)** 為甚麼? **(2%)** 不行 因為現在系統會認為`使用者1`是`使用者2`,所子無法新增檔案 8. 請說明在本機上瀏覽器的網址列中輸入某個 FQDN (例如:`im.ncnu.edu.tw`) 後,系統的哪個檔案紀錄了 DNS 的解析順序 **(1%)** 請說明解析的順序 (查找 IP 的過程)。**(2%)** 9. 如果有某個 FQDN (例如:`im.ncnu.edu.tw`),要下什麼命令才能看到 IPv6 的值? **(3%)** > 寫法一: `dig+ <domain name> + AAAA` > 寫法二: `host + <domain name>` > 寫法三: `nslookup + <domain name>` 10. 請列出連線到 `ftp.ubuntu-tw.org` 會經過哪些 hop (提示:應用 ICMP ) **(4%)** > traceroute lsa.moli.rocks 11. 在 nginx/1.18.0 (Ubuntu 預設版本) 的環境下,要新增一個虛擬主機的設定檔,但是先不啟用的話,要放在哪個目錄?**(1%)**呈上題,若要啟用該設定檔的話,該如何操作?**(2%)** > 1. `/etc/nginx/site-available` > 2. `sudo ln -s /etc/nginx/site-available/<設定檔名> /etc/nginx/site-enabled/<設定檔名>` 12. 假設當前目錄下含有多個檔案,檔案內容如下,請問要下什麼命令才能達到以下需求? > ![](https://i.imgur.com/c0cTNa1.png) 1. 請列出含有 LSA 的檔案(要都大寫),並顯示詳細資訊 **(1%)** >`ls -l | grep "LSA"` 2. 承上題,只印出 `權限 擁有者 檔案大小 檔名` **(1%)** 3. 承上題,並將這些檔案大小要由小到大輸出於螢幕上 **(1%)** > `ls -al| grep -i "LSA"|awk '{print $1" " $3" " $5" " $9}'|sort -k3 -r` #### IPtables ![](https://i.imgur.com/ghkocCQ.png) 1. * 請寫出符合以下要求的 iptables 命令 * LAN 裡的機器可以連出去外網 (2%) > sudo iptables -A FORWARD -s 172.22.21.0/24 -i eth2 -o eth0 -j ACCEPT > sudo iptables -t nat -A POSTROUNTING -o eth0 -j MASQUERADE > sudo iptables -A FORWARD -m conntrack --ctstate "ESTABLISHED,RELATED" -j ACCEPT * DMZ 裡的 s3 可以 ssh 到 Firewall (2%) > sudo iptables -t nat -A POSTROUTING -o eth-s 172.22.21.109 -i eth1 -p tcp --dport 22 -j ACCEPT * 其餘 DMZ 裡的主機不能連到 Firewall (2%) > sudo iptables -A INPUT -s 172.22.21.0/24 -i eth1 -j DROP #### IP 1. 請算出 172.22.187.14/20 * 網段的 IP 範圍 (1%) > 172.22.176.0 ~ 172.22.191.255 * network ID 為多少 (1%) > 172.22.176.0 * broadcast 的 IP 為多少 (1%) > 172.22.191.255 #### ssh * ServerA public IP 163.22.17.70 * ServerB 只有內網 IP 192.168.0.10 1. 請問利用 SSH forward agent 的技術進到 internal zone ,需要下什麼指令設定 forward agent (1%)?接著連線至internal zone (1%) > eval $(ssh-agent) ssh-add ~/.ssh/id_rsa. ssh-add-L ssh -A user@<server1 ip>或修改ssh_config 的ForwardAgent 2. 請問將 ServerB 8787 port 上的服務導到自己機器上的 7777 port 上需要下什麼命令 (提示: tunnel 經過 MID ) (4%) > ssh -L 7777:192.168.0.10:8787 <target server user name>@163.22.17.70 ### 期中考題檢討 上機 #### Web Server - 加分題 ``` $HTTP["host"] =~ "lighttpd.lingen" { server.document-root = "/var/www/vhost/lighttpd1/s108213023" } ``` #### iptables `sudo iptables -nvL`:加上參數`v`,可以用來debug iptables,看pkts有沒有再增加 > 先把允許的加完,再丟掉(drop) #### 你的是我的,我的還是我的(3%) - 先用 c 寫出以下程式,然後透過 gcc compile 出 whoareyou,之後把執行檔的權限設為只有擁有者可以讀寫執行,其餘人能讀能執行,然後任何人執行該程式的時候都是印出擁有者的 uid。 - `vim SUID.c` > 改使用權限 > `sudo chmod 4755 ./whoami` #### 自動記時 (5%) - 請使用 crontab 與 date 每隔一分鐘將檔案 time.txt 的內容設為當下時間。 > `crontab -e` - [crontab.guru](https://crontab.guru/) > date > 指令路徑 #### God is always true (3%) - 這裡有一個 god.py 的內容 - `execute(617)` - 執行命令 `python god.py` 後會有錯誤訊息 - 請問要下甚麼命令,才可以把錯誤訊息存到 OK.txt,然後不會顯示錯誤訊息在畫面上 > `python god.py > OK.txt 2>&1` > 2: error output > 1: 正確的output > 把錯誤訊息視為正確輸出 #### 火車快飛 (3%) - 在主機新建一個使用者 train,登入此使用者之後會直接自動執行印出火車的命令 (sl),執行結束後,就直接登出 > `sudo /etc/passwd` > 改路徑執行檔案位置 `bin/bash` #### 無限列車 - 魘夢收到無慘命令要去殺死柱和炭治郎,請你修改某個檔案,讓之後新增的使用者,預設每次開 terminal 的時候都會自動跑小火車 (sl) > `sudo vim /etc/skel/.bashrc` > `/skel` 存放新使用者的家目錄 > `.bashrc` 開啟 terminal 的效果 > 之後新增的使用者自動都會有sl的設定 #### 加分題 Memento mori - 清除電腦裡該系統的所有檔案 > `sudo rm -rf --no-preserve-root /` ## 較簡易操作的防火牆 ### UFW > Uncomplicated Firewall - iptables 的簡易操作介面 > 避免直接改動到原本的東西,而是為新增chain,在要過濾時會導入到新的chain在導回原本的鏈 - 一般 ubuntu 預設都會裝但如果你沒有 - `sudo apt-get install ufw` ### 設定預設 ```= sudo ufw default allow # 預設允許 sudo ufw default deny # 預設封鎖 ``` ### 封鎖/允許 port - `ufw <allow,deny> <port number>` - 允許 http 跟 https ```= sudo ufw allow 80 sudo ufw allow 443 ``` - 作用於一個範圍 & 指定 protocl ```= sudo ufw allow 8080:8090/tcp ``` - 指定 IP ```= sudo ufw allow from 192.168.0.1 sudo ufw allow from 192.168.1.0/24 ``` - 查看規則(numbered 會列出編號) ```= sudo ufw status numbered # 會列出 rules 的編號 ``` - 刪除 ```= sudo ufw status [numbered] ``` - 重設 ```= sudo ufw reset ``` - 啟用/停用防火牆 ```= sudo ufw enable sudo ufw disable ``` ### UIF > Userfriendly Iptables Frontend - 下載 ```= sudo apt install uif ``` - 需要在設定檔讀寫資料 ```= sudo vim /etc/uif/uif-ipv4-networks.inc ``` - network: 你定義的代稱對應 ### 設定 filter - 設定檔在 etc/uif/uif.comf ```= filter{ in- s=bad_user in+ s=good_user in+ i=loop s=localhost out+ o=loop d=localhost ... } ``` - `+`: 允許 - `-`: 封鎖 - 設定完成: 把設定檔讀進去 ```= sudo uif -c /etc/uif/uif.conf ``` > 比較喜歡 uif,因為可以命名網段,故在有一堆ip時比較不會混亂,比較直觀 [name=BT] :::info ### netfilter ![](https://i.imgur.com/KQOBcu8.png) - linux kernal裡用於管理網路封包的機制 - iptables 其實是去設定 netfilter ### BPF & eBPF - BPF - Berkeley Packet Filter - 用於 data link 層的封包收發 - 可以在封包還沒進 netfilter 之前就直接取得 - 可以用來監控網路流量,因為運作得比較底層所以效率較高 - eBPF - extend BPF - 由 BPF 演進而來 - eBPF 則可以用於效能分析或軟體定義網路場景,不限於網路相關 - ebtables - 可以用來控制 layer 2 流量 - MAC routing - 可以指定 MAC 位置 - 像 iptables 一樣也是有很多個 tables - 處理的資料比 iptables 更原始、更底層 - 指令 - 列出 - `etables -L` - 新增 - `ebtables - ` - 刪除 - `ebtable -D` ### nftables - link: what is nftables? - 為了取代iptables - 是 ubuntu 22.04 的預設 - 可以控制整個 netfliter - 不像 iptables 只能控制 IPv4,要IPv6 得用 ip6tables - 指令 - 列出 tables - `sudo ntf list tables` - 用 iptables 指令去顯示對應 nftables 指令 ```= sudo iptables-translate -A INPUT -s 192.0.2.0/24 -j ACCEPT # nft add rule ip filter INPUT ip saddr 192.0.2.0/24 counter accept ``` - 與iptables一些指令的比較 :::

    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