資訊安全

NTU CSIE CSCAMP-2019

https://slides.com/james01/computer-security-4

關於我

資安是什麼?

CIA

Confidentiality 保密性

保密防諜,人人有責

  • 密碼
  • 私人訊息

Integrity 一致性

資料不可被任意更動

  • 電子郵件
  • 郵局存款

Availability 可用性

服務 / 資料 使用不可被任意妨礙

  • 股市
  • github server

CTF Games!

  • Pwn
  • Reverse
  • Web
  • Crypto
  • Stego
  • Forensics
  • ...

Pwn

尋找並利用執行檔中的漏洞

  • Buffer overflow
  • Format String Attack
  • Heap/Stack

Reverse

解讀執行檔,並提取有用的資訊

Web

各種網頁相關漏洞

  • cookie stealing
  • XSS
  • SQL injection
  • code injection
  • php, html, js, ...

Crypto

密碼學

  • RSA
  • AES
  • Hash

 

** 現代密碼學大多跟離散數

     學,線性代數有關

Stego

隱藏訊息的藝術

  • Text in image
  • File in image
  • Image in audio
  • ...

Forensics

Recovering digital trail

  • 檔案格式
  • 截取 / 解析網路封包
  • 硬碟還原

Web Security

簡介

網頁到底是什麼

Server

Client

一般所看到的網頁

  • HTML
  • CSS
  • javascript

支撐網頁的各種程式

  • database
  • authentication
  • php/ruby/python/nodejs   (basically no limits)

request

response

client如何跟server

索取網頁內容?

<scheme>://<netloc>/<path>?<query>

URL

https://M30W.tw/search?q=ctf

<scheme>://<netloc>/<path>?<query>

URL

https://M30W.tw/search?q=ctf

https : Hypertext Transfer Protocol Secure

  • 定義溝通所使用的協定

<scheme>://<netloc>/<path>?<query>

URL

https://M30W.tw/search?q=ctf

M30W.tw : domain name

  • server在網路中的位置

<scheme>://<netloc>/<path>?<query>

URL

https://M30W.tw/search?q=ctf

search : path of the document 

  • 目標檔案在server上的位置

<scheme>://<netloc>/<path>?<query>

URL

https://M30W.tw/search?q=ctf

q=ctf : purpose of request

  • 傳給目標檔案的參數(希望網頁做的事)

 

最常見的兩種請求方法

HTTP methods

GET :

  • 向網頁索取資訊
  • 參數會以 ?A=B 的形式出現在url中

POST :

  • 傳遞資訊給server
  • 參數不會出現在url中

Other stuff worth knowing

HTTP request header

GET /query?q=ctf HTTP/1.1
   Host: M30W.tw
   User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:56.0)
   Gecko/20100101 Firefox/56.0
   Accept: text/html,application/xhtml+xml,application/xml;
   Connection: keep-alive

HTTP response header

HTTP/1.1 200 OK
    Date: Sat, 23 March 2019 20:00:00 GMT
    Server: Apache/2.4.18 (Ubuntu)
    Last-Modified: Sat, 23 March 2019 21:00:00 GMT
    ETag: "69fe-56ce289380252"
    Accept-Ranges: bytes
    Content-Length: 27134
    Vary: Accept-Encoding
    Connection: close
    Content-Type: text/plain

status codes

Other stuff worth knowing

HTTP vs HTTPS

Other stuff worth knowing

Cookie

Logged in ...

or not?

  • 紀錄用戶資訊
  • 存在瀏覽器上
  • 時常用來檢驗用戶身份 / 是否登入

What is a cookie

  1. Right Click
  2. Inspect
  3. Application
  4. Cookies

Where to find cookie

HTTP request headers

Lab 1

Welcome to M30W

 

 

All problems can be found at 139.162.125.106:4000

Javascript

What if client wants to run something?

What is javascript

  • 這邊只著重在client端的javascript (略過nodejs)
  • 可以直接存取client端資訊,但無法觸及server端的東西
  • 使用者可以直接看到程式碼
  • browser通常會提供console讓使用者可以自己寫javascript

XSS

  • Cross Site Scripting
  • 執行惡意程式碼
  • 用以偷取client端資訊 (cookie...)

XSS prevention

  • 輸入資料清理
  • html 解析檢查
  • 禁止 跨來源資源共用(CORS)
  • 瀏覽器內建保護機制
  • 用戶警覺性

Lab 2

Ultra Spiritual Cats

PHP

What if server needs to run something?

先備知識 : 基礎 bash 指令

  • ls : 列出當前目錄所有檔案
  • cat $file : 顯示檔案內容

bash 是最常被使用的文字介面之一

Common Vulnerabilities

  • exec(), shell_exec(), system() 等函示會執行bash指令
  • 如果指令內容可以由用戶直接控制,會產生各種問題

執行來自用戶的指令

Common Vulnerabilities

  • 輸入資料清理
  • preg_match() 可以幫助過濾輸入
  • 白名單? 黑名單?

How to deal with it

Lab 3

meet my cat;

SQL

What if server needs to store something?

What is SQL

  • Structured Query Language
  • 用來管理資料庫
  • MySQL, PostgreSQL, etc.

SQL Commands

  • SELECT
  • DROP
  • UNION
  • OR
  • AND

 

ref : 

https://www.codecademy.com/articles/sql-commands

SQL Injections

  • 原始指令 :
    • SELECT * FROM user WHERE name=' + $name + '
  • $name = ' OR 1=1 OR '
  • 注入後指令 :
    • SELECT * FROM user WHERE name=' ' OR 1=1 OR ' '
  • 後果 :
    • 用戶可提取整個資料庫的內容 

How to deal with it

  • 輸入資料清理
  • Prepared statements

Lab 4

to M30W or not to M30W

Information Leak

What?

My password is leaked?

Rule of least privilege

  • 不應該讓使用者看到任何沒必要看到的東西

Information leakage

  • Extremely common in real life
  • well-known leaks :
    • robots.txt (not really a leak...)
    • .git / .svn
    • .DS_Store
    • .xxx.php.swp
    • xxx.php~

Robots.txt

  • 告訴google等搜尋引擎哪些檔案是允許收錄的
  • 包含關於文件系統的資訊
  • 洩漏資料夾 / 檔案名稱

git/svn

  • 版本控制工具
  • 服務啟動前忘記移除
  • 可以用來還原程式碼

.DS_Store

  • Mac finder格式文件
  • 包含關於文件系統的資訊

.swp / ~

  • 暫存檔
  • 啟動服務前忘記刪除

github

  • 版本控制平台
  • 各種東西都會背上傳到這裡 程式碼, 教學, 工具,               密碼, 帳號 ... 
  • Example :
    • 華為

Lab 5

R. Daneel Olivaw

CTF Challenge

Baby Computer Security

By james01

Baby Computer Security

NTU CSCamp 2019 toy course

  • 827