> For the complete documentation index, see [llms.txt](https://ericmao.gitbook.io/virtualization/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ericmao.gitbook.io/virtualization/master.md).

# Virtualization for Cybersecurity- Virtualbox

為了讓硬體效能有效的發揮，尤其當我們知道電腦大部分是在閒置的時候，如何壓榨出更多的運算與網路資源，是虛擬化技術發展很大的驅動力。

除了從有效利用硬體資源的角度，系統相容性議題往往是開發人員成本所在，資安人員建構攻防場域，更需要彈性且動態的平台技術，虛擬化技術也希望能讓動態架構系統的建制更有彈性。

本課程聚焦虛擬化技術以及容器化技術的基本概念以及建置演練，並結合網路安全主題，如：入侵偵測系統、資安日誌倉儲、惡意程式分析環境等。

課程進行方式以專題為核心，分為技術介紹與技術演練，技術介紹會從全球資安發展趨勢(5G、OT、Cloud)說明虛擬化技術扮演的重要性。接著，對於虛擬化技術進行深度探討。技術演練的部分，將以IDS與Elasticsearch整合技術作為課程上機演練的目標。

相關工具與資料：<https://drive.google.com/drive/u/0/folders/1GvYR--OwP522WkY6eRb2sLr85shs2Gbr>

### 虛擬化技術介紹 (8 hours)

* 從VMWare大廠的角度來看什麼是虛擬化？(包含影片) <https://www.vmware.com/tw/solutions/virtualization.html>
* VMWare可參考詳細記述文件：<https://www.vmware.com/content/dam/digitalmarketing/vmware/en/pdf/ebook/gated-vmw-ebook-virtualization-essentials.pdf>

> 問題討論 1： 大廠與開放源碼的虛擬化技術有什麼差別？可否分享過去的使用經驗。

* 虛擬化技術介紹，此份簡報是由國網中心線上公開簡報資源，作為本課程建構基礎知識之資料。 <https://slidesplayer.com/slide/14707489/>
* 此份資料著重虛擬化技術及應用，此份資料更聚焦於系統架構堆疊，很適合從系統角度了解虛擬化技術的層次。 <https://www.slideserve.com/hammer/3841515>

> 問題討論 2: 虛擬化技術對於資安防護與情資研析的用途？

* 由教育部補助中山大學所編纂的虛擬化技術，此份教材詳細從不同虛擬化平台說明，也探像是虛擬化處理器等技術核心，順帶一提，其中QEMU就被常用在IoT Honeypot用來模擬不同硬體。 <http://dns2.asia.edu.tw/~jdwang/TeachingCourses/Virtualization/Part1-_.pdf>
* 從虛擬化使用面向來探討，包含從伺服器、桌面虛擬化、環境管理虛擬化以及在虛擬化產品的實務經驗。 <http://ilms.csu.edu.tw/sys/read_attach.php?id=1424740>
* 虛擬機(VM)與容器(Container)之技術價值與比較分析，值得一讀有乾貨的文章，兩個容易被混淆的議題融合起來探討。 <https://medium.com/mr-efacani-teatime/%E6%B7%BA%E8%AB%87%E8%99%9B%E6%93%AC%E5%8C%96%E6%8A%80%E8%A1%93-%E8%99%9B%E6%93%AC%E6%A9%9F-vm-%E8%88%87%E5%AE%B9%E5%99%A8-container-%E4%B9%8B%E6%8A%80%E8%A1%93%E5%83%B9%E5%80%BC%E8%88%87%E6%AF%94%E8%BC%83%E5%88%86%E6%9E%90-5c10457aad62>

> 問題討論 3: 虛擬機與容器的共同性與差異性為何？

* CPU進階技術講解，這份資料針對CPU的技術有不錯的討論，當然我們聚焦在虛擬化最相關的技術來探討。

  <https://www.mobile01.com/topicdetail.php?f=233&t=1331238>

### VirtualBox實戰 （10 hours)

* Lab 1: 安裝與建置 安裝VirtualBox，安裝以Ubuntu 18.04的GuestOS，以及Kali Linux，並分別透過HostOS以SSH連線進入。
  * 瞭解NAT、Bridged與Host-only的差異
    * <https://kknews.cc/zh-tw/code/z2k548a.html>
    * <https://ocean2002n.pixnet.net/blog/post/94354066>
    * <https://www.itread01.com/content/1548942684.html>
  * 在Linux查網路設定？
    * 若碰到ifconfig not found，請執行`sudo apt install net-tools`

      參考來源：<https://blog.csdn.net/hanpenghu/article/details/84678503>
  * 設定固定網路IP位置（建議設定192.168.56.102)
  * 設定從從host os透過SSH連到Guest OS(Ubuntu Linux)
    * `sudo apt-get update`
    * `sudo apt-get install openssh-server`
    * 設定openssh-server，目標允許遠端用密碼登入及可以登入(0.0.0.0, specified IP)
      * sudo vim /etc/ssh/sshd\_config
        * `ListenAddress 0.0.0.0`
        * `PermitRootLogin yes`
    * 設定防火牆
      * `sudo ufw allow ssh`
    * 啟動openssh-server
      * `service ssh start`
  * 在Host OS，透過SSH Client(如： Putty)連入Guest OS。
* Lab 2: 建構一個可自我檢測分析的入侵偵測系統 依照Suricata安裝步驟。
  * 專案規劃：
    * 在Host-only的環境中建置攻防主機各一台
    * 網路配置
      * Gateway 192.168.56.1
      * 防禦主機(Suricata) 192.168.56.102
      * 攻擊主機(Kali) 192.168.56.101
  * 安裝Suricata
    * `sudo add-apt-repository ppa:oisf/suricata-stable`
    * `sudo apt-get update`
    * `sudo apt-get install suricata`
    * `sudo vim /etc/suricata/suricata.yaml`
      * 所有為eth0的地方替換為要偵測的網卡名稱(如：enp0s8) 可使用以下指令進行安裝測試
        * `sudo suricata -c  /etc/suricata/suricata.yaml -T`&#x20;
    * 啟動Suricata... `sudo systemctl start suricata.service`
    * 可到 `/var/log/suricata/suricata-start.log` 檢視啟動時有無問題 (例如：忘了把eth0改成enp0s8)
  * 安裝與設定Elasticsearch
    * `wget -qO -` [`https://artifacts.elastic.co/GPG-KEY-elasticsearch`](https://artifacts.elastic.co/GPG-KEY-elasticsearch) `| sudo apt-key add -`

    * `sudo apt-get install apt-transport-https`

    * `echo "deb` [`https://artifacts.elastic.co/packages/7.x/apt`](https://artifacts.elastic.co/packages/7.x/apt) `stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list`

    * `sudo apt-get update && sudo apt-get install elasticsearch`

    * `sudo apt-get install elasticsearch`

    * `sudo vim /etc/elasticsearch/elasticsearch.yml`

    * 在Elasticsearch.yml中，設定以下屬性：
      * *node.name: node-1*
      * *cluster.name: my-application*
      * *network.host: 192.168.56.103*
      * *cluster.initial\_master\_nodes: \["node-1"]*

    * 檢視與啟動Elasticsearch服務狀態
      * `sudo systemctl status elasticsearch.service`
      * `sudo systemctl start elasticsearch.service`

    * 確認是否正常運行（透過HTTP 9200確認Elasticsearch狀態畫面

      * `curl -XGET` [`http://192.168.56.103:9200`](http://192.168.56.103:9200)
      * 正常運作畫面

      <img src="/files/-MBRVu8vQttC_NcOU-jr" alt="" data-size="original">

    * **Elasticsearch有可能無法啟動，起因為 elasticsearch.service: Start operation timed out. Terminating.**，可參考 <https://discuss.elastic.co/t/debian-elasticsearch-service-start-operation-timed-out-terminating/223262>
  * 運送資料
    \*
  * 以Filebeats運送suricata的告警檔案eve.json至Elasticsearch
    * 安裝Filebeats
      * `sudo apt-get install filebeat`&#x20;
    * 設定Filebeats
      * `sudo vim /etc/filebeat/filebeat.yml`&#x20;
        * Filebeat inputs
          * *paths: /var/log/suricata/eve.json*
          * *enabled: true*
        * Kibana
          * *host: "localhost:5601"*
        * Outputs> Elasticsearch Output
          * *hosts:\["192.168.56.102:9200"]*
    * 運作Filebeats
      * `sudo systemctl start filebeat`
      * `sudo systemctl status filebeat`
    * 確認filebeat已將eve.json傳送至Elasticsearch
      * <img src="/files/-MBRhmEQxZCIO6bH_hBT" alt="" data-size="original">&#x20;
  * 掛載Kali Linux到Virtualbox
    * ID/PW: kali/password@@
    * 開啟NMAP，掃描192.168.56.103
    * 或是直接在host os安裝NMAP (<https://nmap.org/download.html>)
  * 加掛Logstash進行資料處理
    * 安裝Logstash
      * `sudo apt-get update`
      * `sudo apt install openjdk-11-jre-headless`
      * `sudo apt-get install -y logstash`
      * `sudo systemctl daemon-reload`
      * `sudo systemctl enable logstash.service`
    * 設定Logstash
      * Logstash的scripts預設目錄為 **/etc/logstash/conf.d/**
      * 參考10-input.conf (file) 與 30-outputs.conf (file)
      * 在10-input.conf中，請確認path是否已指向 /var/log/suricata/eve.json

        `input {`&#x20;

        &#x20;  `file {`&#x20;

        &#x20;     `path => ["/var/log/suricata/eve.json"]`&#x20;

        &#x20;     `sincedb_path => ["/var/lib/logstash/sincedb"]`&#x20;

        &#x20;     `codec => json type => "SuricataIDPS"`&#x20;

        &#x20;  `}`&#x20;

        `}`
      * 在30-outputs.conf中，請確認Elasticsearch位置以及index名稱

        `output {`&#x20;

        &#x20;   `elasticsearch {`&#x20;

        &#x20;       `hosts => ["`[`http://192.168.56.102:9200`](http://192.168.56.102:9200)`"]`&#x20;

        &#x20;       **`index`**`=> "logstash-%{+YYYY.MM.dd}"`&#x20;

        &#x20;   `}`&#x20;

        `}`
  * 使用Evebox套件檢視Suricata觸發事件
    * 安裝Evebox
      * sudo apt-get install wget gnupg&#x20;
      * wget -qO - <https://evebox.org/files/GPG-KEY-evebox> | sudo apt-key add -&#x20;
      * echo "deb <http://evebox.org/files/debian> stable main" | sudo tee /etc/apt/sources.list.d/evebox.list&#x20;
      * sudo apt-get update&#x20;
      * sudo apt-get install evebox
    * 啟動Evebox
      * <https://github.com/jasonish/evebox/wiki/Example-Filebeat-to-Logstash-Configuration>
      * <https://ssooking.github.io/gou-jian-ji-yu-suricata-splunk-de-ids-ru-qin-jian-ce-xi-tong/>
    * 啟動指令
      * `sudo cp evebox.yaml.example evebox.yaml`
      * `sudo vim /etc/evebox/evebox.yaml`
        * `LINE 42 elasticsearch:`
          * url: [http://192.168.56.102:9200](http://192.168.56.103:9200)&#x20;
          * index: logstash-\*&#x20;
          * disable-certificate-check: false
        * LINE 110 input:
          * enabled: true
          * filename: "/var/log/sricata/eve.json
      * `sudo evebox server -c /etc/evebox.yaml`
* Lab 3: 採用Script控制
  * Shell scripts&#x20;
    * <https://www.techrepublic.com/article/how-to-create-a-bash-script-for-starting-virtualbox-vms/>
    * <https://gist.github.com/jgcasta/03b643ecb6dc596d00bb>
    * <https://github.com/cirlabs/vm>
    * <https://www.virtualbox.org/manual/ch08.html>
    * <https://blog.sleeplessbeastie.eu/2013/07/23/virtualbox-how-to-control-virtual-machine-using-command-line/>
  * Docker Python scripts (problem)
    * <https://github.com/sethmlarson/virtualbox-python>&#x20;
* Lab 4: 雲端虛擬化資安技術探討 <https://opdhsblobprod01.blob.core.windows.net/contents/4a6d75bb3af747de838e6ccc97c5d978/e7e7f25fe015909d60a65f1588c7052c?sv=2018-03-28&sr=b&si=ReadPolicy&sig=JymlYeSRPlkaGj0Dynge5uy5G5ugVoPnlVX59p1dmgA%3D&st=2020-06-27T05%3A08%3A12Z&se=2020-06-28T05%3A18%3A12Z>

![](/files/-MBaeCgUiz7ek9K25paJ)

> 實作補充資料
>
> > * How To Set Up a Firewall with UFW on Ubuntu 18.04
> >
> >   <https://www.digitalocean.com/community/tutorials/how-to-set-up-a-firewall-with-ufw-on-ubuntu-18-04>
> > * Logstash Kibana and Suricata JSON output
> >
> >   <https://redmine.openinfosecfoundation.org/projects/suricata/wiki/_Logstash_Kibana_and_Suricata_JSON_output>
> > * 入侵偵測系統結合大數據分析: Suricata 與 ELK Stack 之實際應用
> >
> >   <http://tprc.tanet.edu.tw/tpnet2018/training/10708.pdf>
> > * Elasticsearch 筆記 <https://soarlin.github.io/2016/11/13/elasticsearch-note-operation/#%E6%AA%A2%E6%9F%A5-server-%E7%8B%80%E6%85%8B>
> > * Elasticsearch 教學 <https://learnku.com/docs/elasticsearch73/7.3/installing-elasticsearch/6466>&#x20;
> > * Elasticsearch 安裝與啟動 <https://yq.aliyun.com/articles/746610>
> > * Elasticsearch 狀態查看 <https://blog.csdn.net/kwame211/article/details/83786212>
> > * How To Install and Configure Elasticsearch on Ubuntu 16.04 <https://www.digitalocean.com/community/tutorials/how-to-install-and-configure-elasticsearch-on-ubuntu-16-04>
> > * How to setup up an Elastic version 7 cluster, <http://blogs.bmc.com/elasticsearch-v7-cluster/?print=pdf>
> > * Setup Elasticsearch Cluster over Oracle Virtualbox <https://discuss.elastic.co/t/setup-elasticsearch-cluster-over-oracle-virtualbox/13071/2>
> > * ELK 教學 - 從無到有安裝 ELK (CentOS/Red Hat) <https://blog.johnwu.cc/article/how-to-install-elasticsearch-logstash-and-kibana-elk-stack-on-centos-red-hat.html>
> > * ES7 學習筆記 <https://yq.aliyun.com/articles/746610>
> > * Get started with Filebeat <https://www.elastic.co/guide/en/beats/filebeat/current/filebeat-getting-started.html>

<https://medium.com/@ceall8650/%E7%AD%86%E8%A8%98-%E5%9C%A8window10-%E5%AE%B6%E7%94%A8%E7%89%88-%E7%84%A1-hyper-v-%E5%AE%89%E8%A3%9Ddocker-ee80a25c702d>

{% embed url="<https://software.intel.com/content/www/us/en/develop/documentation/intel-system-studio-docker-install/top/windows/windows-docker-toolbox-for-windows/windows-install-docker-toolbox.html>" %}
