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 New
    • 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 Note Insights Versions and GitHub Sync 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
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- tags: 1101, lsa --- - Book mode https://hackmd.io/@ncnu-opensource/book # Week 15(2021/12/30) [TOC] ## 期中考解答 ### A. 檔案權限設定 1. `vim 1101LSA_學號` 2. `chmod 4751 1101LSA_學號` ```txt= 你的名字 : 你的學號 : ``` - 執行`./1101LSA_學號` ### B. Forward Agent 1. ==本機端== - `~/.ssh/config`中 ForwardAgent 預設 no => yes 2. ==遠端(題目的 firewall)== - ForwardAgent 預設 yes => yes - 不用改 4. `ssh-add <私鑰路徑>` ### C. iptables 20% - en5 外網 - en6 內網 - en7 dmz (https 連線) 1. internal zone 所有去外網路的封包都會經過 firewall - 第一條 : en6 轉送到 en5 - 第三條 : 把內網 ip 改成外網 ip ```shell= sudo iptables -A FORWARD -i en6 -o en5 -j ACCEPT sudo iptables -A FORWARD -m conntrak --ctstate "ESTABLISHED,RELATED" -j ACCEPT sudo iptables -t nat -A POSROUTING -o en5 -j XXXX? ``` 2. 在 firewall 開 port 80 (public network) 導向 DMZ 中的 web-server 的 80 port,並且 web-server 要能夠知道使用者的 IP ```shell= sudo iptables -t nat -A PREROUTING -i en5 -p tcp --dport 80 -j DNAT --to {web server ip}:80 sudo iptables -A FORWARD -i en5 -o en7 -j ACCEPT # 來自en5 到 en7 我同意 sudo iptables -A FORWARD -m conntrack --ctstate "ESTABLISHED,RELATED" -j ACCEPT ``` 3. DMZ 可以透過 firewall 向 lsa.kija.io 建立 http 連線 ```cmd= # 先找 lsa.kija.io 的 ip nslookup lsa.kija.io # 在cmd下,nslookup domain name ``` ![](https://i.imgur.com/1UZBMFf.png =70%x) ```shell= sudo iptables -A FORWARD -i en7 -o en5 -d 159.223.32.147 -p -tcp -- // 回來的封包同意他進來 sudo iptables -A FORWARD -m conntrack --ctstate "ESTABLISHED,RELATED" -j ACCEPT // 讓外網知道 sudo iptables -t nat -A POSTROUTING -o en5 -j MASQUERADE ``` 4. 准許外網 ssh 連線至 firewall ```shell= sudo iptables -A INPUT -i en5 -p tcp --dport 22 -j ACCEPT ``` 5. internal zone 中的 student 可以透過 private IP ssh 連線至 DMZ 中的 web-server,並且 web-server 要能夠知道使用者的 IP ```shell= sudo iptables -A FORWARD -i en6 -s {student ip} -d {web server ip} -o en7 -p tcp --dport 22 -j ACCEPT sudo iptables -A FORWARD -m conntrack --ctstate "ESTABLISHED,RELATED" -j ACCEPT ``` 6. 所有對外的 DNS request 皆會被 firewall 導向 1.1.1.1 ```shell= #出去封包之前 改寫 firewall導向1.1.1.1 #有兩種方式進行連線 (TCP、UDP) #UDP的Port是53 sudo iptables -t nat -A PREROUTING -p udp --dport 53 DNAT --to 1.1.1.1:53 sudo iptables -t nat -A PREROUTING -p tcp --dport 53 -j DNAT --to 1.1.1.1:53 ``` 7. (WARRING) INPUT, FORWARD chain 預設的 policy 為 DROP (2%) ```shell= //允許 sudo iptables -A INPUT -m conntrack --ctstate "ESTABLISHED,RELATED" -j ACCEPT sudo iptables -A INPUT -j DROP sudo iptables -A FORWARD -j DROP or sudo iptables -A INPUT -m conntrack --ctstate "ESTABLISHED,RELATED" -j ACCEPT sudo iptables -P INPUT DROP sudo iptables -P FORWARD DROP ``` ### D. Web Server - 先在 /etc/hosts 下把所有 domain name 加進去 - apache(8091) - 連線8091port,會顯示老師的各項資訊 - lighttpd - 連線8092port, - ==練**喆**明== 可以去 moodle 看老師和助教的名字~ - 在網址後加入 `/~<username>` 顯示課程資訊 - enable userdir - public/userdir?? - nginx ### E. 火車快飛 1. 安裝sl ```shell= sudo apt install sl ``` 2. 新增使用者 - 並打密碼(基礎帳號設定) ```shell= sudo adduser train ``` 3. 找出sl 指令的位置 ```shell= whereis sl ``` 4. 編輯/etc/passwd 更改使用者登入後使用的script(將後面/bin/bash改成/games/sl) ```shell= sudo vim /etc/passwd ``` > `/etc/passwd` 告訴你使用者、id、group、家目錄位置、這個使用者登入的時候會執行哪一個script(預設 bin/bash) ``` shell= train:x:1005:1005:,,,:/home/train:/usr/games/sl ``` 5. 就可以測試拉 ```shell= sudo su - train ``` ## 基本的監控 強烈建議安裝 `awffull`和`MRTG` ### awffull - 了解 webserver 過去的存取相關資訊 - 每天定時去掃描 webserver log 之後製成圖表 - 可以更加了解使用者的行為,作為下次做決策的參考指標之一 - 流量最高的時間、使用者國家分布 ... ![](https://i.imgur.com/9K4Hczx.png ) - 圖記錄過去到現在流量的成長 - 資料依日期降冪排序 (最新最上面) - 點進去詳細資料: ![](https://i.imgur.com/4eZZadq.png) - forbidden 太多的話 : 有一些網路上笨笨的機器人在連你的網站 - 以星期來講是有周期的 示意圖![](https://i.imgur.com/2NSrFjx.png) - 通常要做網站維修 3點 ~ 6點 (伺服器使用人數最少),game 的話可能是早上 8點~ 10點 維修 #### 安裝 awffull - 搜尋 awffull - `apt -cache search awffull` 機器看的 - `apt search awffull` 人看的 - `apt-cache show awffull` - `sudo aptitude`: 圖形化介面,跟`apt-catch show`一樣,可以看更詳細的資料 - 可以用 `| grep` 過濾 - 安裝 - `sudo apt install awffull` #### 看設定檔`awffull.conf` - 對於所有軟體,安裝完後第一件事就是先去看它有什麼功能及其設定檔,而不是直接執行 (避免門戶大開) - `vim /etc/awffull/awffull.conf` - Logfile 指定你要讀的檔案是什麼 - `access.log`: 即時的、不完整的。目前正在紀錄、增加內容的檔案 - `access.log.1`: 較完整(因為已經記錄完)。數字越小,檔案越新 - `Incremental yes`建議打開 - 系統某一個時間應該要去啟動他,自己有timer時間到了會自動啟動 - 壞處: 要一直吃記憶體,關掉之後就沒有人可以打開他(?) - 用cron定時去跑 ### cron - under `/etc` <br> ![](https://i.imgur.com/Dukzo5v.png =60%x) - 會放每時、天、週、月跑 - everyday: `/etc/cron.daily` - 通常會在早上6點多跑 - 只要將檔案放進裡面,就會每天記錄 - 如果系統都是每天同一個時間掛掉,有可能是 `cron.daily` 裡面有怪怪的東西 > 系統管理一定要實作 - `/etc/default` - fail2ban - 在一定時間以內,如果登入失敗過多,可以把對方擋住 - 在一定時間內登入失敗多次後,可以設定該使用者多久後,可以再次登入 ### MRTG 畫圖 > multi router traffic grapher :::info :point_right: [1082LSA week12、week13 的講義 - 管理](https://hackmd.io/@ncnu-opensource/By4H6JLNW/%2FcximprOjTcWeZ1r44SCKeA?type=book) ::: - 監控最基本的網路流量資訊 - 透過 SNMP - 依照時間、數值呈現資料 - RRDtool (輪替型資料庫工具) 繪製線圖 - 安裝 snmp、snmpd - `sudo apt install snmp snmpd` - 安裝 mrtg - `sudo apt install mrtg` - 改 snmpd 設定檔 - `sudo vim /etc/snmp/snmpd.conf` - 加一行字 ```txt= rocommunity public localhost ``` ![](https://i.imgur.com/Uxf09tj.png) - `sudo systemctl restart snmpd` - `sudo systemctl status snmpd` ![](https://i.imgur.com/kuNKJE2.png) > 正常 - 看 mrtg 設定檔 - `sudo cat /etc/mrtg.cfg` ![](https://i.imgur.com/5ep0BHl.png) - 創一個資料夾 - 儲存畫好的圖表 - `sudo mkdir /var/www/mrtg` - 畫圖 - `sudo cfgmaker --output=/etc/mrtg.cfg public@localhost` - output=<輸出位置> ![](https://i.imgur.com/258LUfy.png) - 看圖 `ls /var/www/mrtg/` > 要等一段時間... :timer_clock: 才可以看到圖 > ![](https://i.imgur.com/dUfQQDH.png) - `sudo indexmaker --output=/var/www/mrtg/index.html /etc/mrtg.cfg` - apache `sites-available/` 加設定檔 > 要加什麼設定檔? - `sudo a2ensite mrtg` - 在瀏覽器打 myapache1.com:<port 號> - 去設定的網址就可以看到網路流量啦 - Cpu & memory監控要自己去查 ### Rsync Server - 要提供檔案給世界上所有的人,但又不希望開帳號給人 - 系統資安相關檢查 > 只要有 web shell 就可以下指令,再透過提權就可以讓一般使用者變成root - 看`/etc/rsyncd.conf` - 看`/etc/default/rsync` - `rsync --list-only rsync://ftp.ubuntu-tw.org` 看總共有哪些資料夾可以抓,含系統管理者寫的敘述 - `rsync -avz rsync://ftp.ubuntu-tw.org:: <本地目錄>` > `http://ftp.ubuntu-tw.org` 遠端 ### proftpd server - 安裝 - `apt install proftpd` - 設定檔 - 先猜,設定跟軟體同名的檔名內有設定檔 - `vim /etc/proftpd/proftpd.conf` - 跟安全有關的 - 看`user`和`group`是誰 - 會影響權限 - 通常會給最小權限 - sudo 才能取得比1024 port小的 - `/etc/services` 記錄所有 port - 影響權限 `/etc/proftpd/proftpd.conf` ![](https://i.imgur.com/JExB3QE.png =70%x) - `/etc/default/proftpd` <br> ![](https://i.imgur.com/ogRNoIh.png =60%x) - `/etc/proftpd/proftpd.conf`可以把`<Anonymous> </Anonymous>`區塊內的內容註解掉 ![](https://i.imgur.com/FrNFCL4.png =70%x) - 匿名使用者就可以直接登入 - `ncftp <連線主機>` ![](https://i.imgur.com/4zLrAj5.png) > 範例連線主機: lsa.kija.io ### postfix - 安裝畫面 - `sudo apt install postfix` ![](https://i.imgur.com/kg7pxzD.png) > 設定mail name ![](https://i.imgur.com/pDqdeXo.png) > 若收件人是 root 或 mail master,可以將它轉送給其他人 > ![](https://i.imgur.com/LirggKr.png) > domain name > ![](https://i.imgur.com/rG8yxNB.png) > 處理哪個區域的 IP 來的請求 > ![](https://i.imgur.com/1rOMvmv.png) > 信箱空間上限 > ![](https://i.imgur.com/ZnJS8JJ.png) > Local address extension character: > 如果有一封信 寄出來 只會辨識 + 號之前的字串 <br> > ~~這樣你可以在 yahoo 建立超多個帳號~~ > ![](https://i.imgur.com/bXARZFL.png) > 選擇使用的 ip protocol > ![](https://i.imgur.com/39Uymvf.png) > `vim /etc/aliases` > ![](https://i.imgur.com/Ol0hJi3.png) > 範例: > ![](https://i.imgur.com/1LStBvt.png) > 所以全部都寄給郭子偉 > 載入剛剛的設定 > 輸入`sudo newaliases` > 安裝詳細內容 > ![](https://i.imgur.com/H3cVYD7.png) - 非常基本的 email server - 重要的協定都要再用 email 去確認,目前比較正式的手法(避免訊息收回) - 現在的 spam mail 太多了,所以也產生相對應的驗證方式 - 偽造寄件人很容易 - apt-cache search postfix - 至少在本機的使用者之間可以傳送訊息,可以設定成local only - 指令 `sudo dpkg-reconfigure postfix`:可以重新設定當初安裝時設定的東西(如果有設定錯的話),可以設定的東西會詳細 - apt 只是一個介面幫你下載安裝檔,然後交給 dpkg - 寄信給 `chofinn+987@gmail.com` 等同於寄給 `chofinn@gmail.com` - `+` 號後面寫的東西不會被辨識 - `vim/etc/aliases` - `newaliases` ### SMB - Server Message Block - 我的電腦 - 網路芳鄰 > 如果還被鎖在 windows 這個監牢裡,是時候可以探索外面的世界了[name=BT] ### 搜尋關鍵字 --- 工具說明 ```shell= apt search <tool> ex:awffull apt-cache search awffull apt search rsync ``` ## /etc/default/底下 ### fail2ban - 位置: `/etc/default/fail2ban` - 如果發現有錯誤超過3次(過多),直接把 ip 鎖掉 ### rsync - 位置: `/etc/default/rsync` ## FTP Server ## NFS server - NFS (Network FileSystem),最早是由 Sun 這家公司所發展出來的 ## file Server ### SMB ::: info 在 1991 年一個名叫 Andrew Tridgell 博士班研究生就有這樣的困擾,他手上有三部機器,分別是跑 DOS 的個人電腦、DEC 公司的 Digital Unix 系統以及 Sun 的 Unix 系統。在當時, DEC 公司有發展出一套稱為 PATHWORKS 的軟體,這套軟體可以用來分享 DEC 的 Unix 與個人電腦的 DOS 這兩個作業系統的檔案資料,可惜讓 Tridgell 覺得較困擾的是,Sun 的 Unix 無法藉由這個軟體來達到資料分享的目的。 這個時候 Tridgell 就想說:『咦!既然這兩部系統可以相互溝通,沒道理 Sun 就必需這麼苦命吧?可不可以將這兩部系統的運作原理找出來,然後讓 Sun 這部機器也能夠分享檔案資料呢?』, 為了解決這樣的的問題,他老兄就自行寫了個 program 去偵測當 DOS 與 DEC 的 Unix 系統在進行資料分享傳送時所使用到的通訊協定資訊,然後將這些重要的資訊擷取下來, 並且基於上述所找到的通訊協定而開發出 Server Message Block (SMB) 這個檔案系統,而就是這套 SMB 軟體就能夠讓 Unix 與 DOS 互相的分享資料囉! 既然寫成了軟體,想一想,總是需要註冊一下商標吧!因此 Tridgell 就去申請了 SMBServer (Server Message Block 的簡寫) 這個名字來做為他撰寫的這個軟體的商標,可惜的是,因為 SMB 是沒有意義的文字,因此沒有辦法達成註冊。既然如此的話,那麼能不能在字典裡面找到相關的字詞可以做為商標來註冊呢? 翻了老半天,呵呵!這個 SAMBA 剛好含有 SMB , 又是熱情有勁的拉丁舞蹈的名稱,不然就用這個名字來做為商標好了!這成為我們今天所使用的 SAMBA 的名稱由來啦! ^ _ ^ ::: ### 好處 - 可以跨系統使用 ### 實作 - 安裝 - `sudo apt install samba` - 改設定檔 - `sudo vim /etc/samba/smb.conf` - 安裝 samba client 端 - `sudo apt install smbclient` - `smb.conf` - `browseable = yes` 能不能給別人看 - 新增 ```file= [LSA] comment = LSA for example path = /LSA browseable = yes read only = no ``` ![](https://i.imgur.com/tNRkTeV.png) - 有點像是用掛接的方法來連到電腦 - `sudo mkdir LSA` - `sudo mkdir myLSA` - `sudo chmod 777 LSA` - `sudo adduser <帳號>` 創建帳號 - `sudo smbpasswd -a <帳號>`設密碼 - `sudo service smbd restart` - `sudo apt install cifs-utils` 類似 windows 的網路芳鄰 - `sudo mount -t cifs -o username="<帳號>" //127.0.0.1/LSA /myLSA` 掛接至 myLSA - 下玩指令 - `sudo touch /home/LSA/a.txt` 之後就可以去 myLSA 看,就可以看到 LSA 底下更改的東西 - `ls /myLSA` 出現 a.txt ![](https://i.imgur.com/gL7sWs8.png) :::warning 目前版本為 samba4,so 這個部分不要太相信鳥哥的資料(是舊版) ::: :::info adduser 有家目錄<br/> useradd 沒有家目錄,單純是一個伺服器? :::

    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