2017年11月23日 星期四

Detecting Security Incidents Using Windows Workstation Event Logs

Windows Event Logs對於調查系統是否被入侵是最關鍵的資源,且一般入侵的初始點大都在使用者電腦,因此,若是能夠收集Workstation上的Event Logs,並進行有效的集中管理及關聯分析,就能在資安事件的初始階段察覺,攔截入侵,並加以防範。

Mandiant (美國麥迪安網路安全公司) 定義APT攻擊的活動週期步驟如下---

  1. Initial compromise                   初期入侵
  2. Establishing a footholds           建立立足點
  3. Escalating privileges                提權
  4. Internal reconnaissance           偵查內部網路
  5. Moving laterally                      橫向移動
  6. Maintaining presence              保留後門
  7. Completing the mission          完成入侵目標
通常入侵攻擊的發生起點都在於Workstation,所以若要對抗APT的攻擊,將攔截點放在Workstation是個合理的策略,但是,收集WorkstationLogs會有些挑戰--
  1. Workstations會產生巨量的Event Logs,要如何有效率的收集
  2. Windows系統本身沒有發送Log給收集器的機制
  3. 安全人員如何分析這些巨量的Log來辨別有針對性的入侵活動
對於這個挑戰,Gartner指出兩種策略應對---
  1. Output-Driven Strategy
    針對已知威脅收集相對應的Event Logs,故可大量減少需收集的Logs,並提供高效的Alert輸出,在資安監控程序中,是比較便宜、高效率、及高附加價值的策略,但要注意的是,因為要先定義出須監控的威脅,那就表示資安人員需要相應的知識與大量的前期規劃。
  2. Input-Driven Strategy
    收集『所有』Logs,再去分析出已發生或潛在的威脅,也就是目前常見的 Security Information and Event Monitoring (SIEM) 系統的作法。此策略利用syslog協定來集中各種Logs,而在Windows系統上,便須安裝syslog agent來協助發送Logs。
Syslog agent的功能,第一必須要有Filter來過濾出需要的Logs再發送以滿足Output-Driven Strategy需求;第二必須要能在企業環境中輕易管理,Filter規則能夠由Server端派送套用以因應快速變更的需求;最後必須要能夠在WorkstationServer離線時,持續記錄,待恢復網路連線後接續上傳Log



Filtering the Event Logs
  1. Event Filtering - The First Cut
    對於Output-Driven Strategy的資安人員來說,已清楚知道要收集哪些Event Logs,所以會建立Whitelist來過濾出需要的Log進行發送,以下表Win7為例,列出Security Incident相關常用到的Event Log,建議以Regular Expressions 來進行過濾,也有以Event ID Number來過濾,但在某些case中,會顯的較沒效率。
    以下有兩個不錯的網站能夠提供各Event ID 的內容說明及參考--
        www.ultimatewindowssecurity.com
        www.eventid.net
    Windows 7 regular expressions
    SOURCE
    EventID
    Number
    ".*APPCRASH.*"
    Application
    1001
    ".*he protected system file.*"
    Application
    64004
    ".*EMET_DLL Module logged the following event:.*"
    Application
    2
    .*your virus/spyware.*
    Application
    Varies
    ".*A new process has been created\..*"
    Security
    4688
    ".*A service was installed in the system\..*"
    Security
    4697
    ".*A scheduled task was created\..*"
    Security
    4698
    ".*Logon Type:[\W]*(3|10).*"
    Security
    4624,4625
    ".*\\Software\\Microsoft\\Windows\\CurrentVersion\\Run.*"
    Security
    4657
    ".*service terminated unexpectedly\..*"
    System
    7034
    ".*service was successfully sent a.*"
    System
    7035
    ".*service entered the.*"
    System
    7036
    ".*service was changed from.*"
    System
    704
  2. Event Filtering - The Second Cut
    相應Whitelist是過濾出想要的Event Log,Blacklist則是用來過濾掉不需要的資訊。Blacklist是用來輔助將通過Whitelist的Event Log再次過濾,將不需要的資訊 (通常我們稱之為noise) 移除。例如“new process created” events,若是常見的正常程序,則將之列入Blacklist,以減少資料量,提高分析效率。但有些程序建議不加入Blacklist如svchost.exe及cmd.exe等。
  3. Output Driven Filtering Summary
    通常Workstations所產生的每1,000,000 筆events,約有300,000筆能通過Whitelist,然後約有90,000筆能通過Blacklist,所以約有90%的events會過濾掉。



Analysis of the Windows Event Logs
  1. Detecting the initial Compromise   (偵測初期入侵)
    偵測初期入侵的方式是偵測不尋常的執行程序(Unusual running process)。
    就像許多辨識Malware的方式是透過分析記憶體去找出--
        不尋常的程序名稱 (unusual process name)、
        不尋常的程式路徑 (unusual process paths)、
        不尋常的程序關聯 (unusual process relationships)等,
    也可用來作為分析 “new process created” events (Event ID 4688|592)時的偵測方式。


    常見的 unusual process name 是偽裝正常系統檔案名稱,例如scvhost.exe, iexplorer.exe,或是svcdost.exe...等,若你認為以上檔名都是正常的,恭喜!! 你中獎了!!!

    另一種常見的 unusual process name 是任何具有以小寫字母開頭的路徑的進程。小寫盤符表示該進程是從命令行或腳本或批處理文件啟動的。

    還有一種是檔名含有長空白字串的,例如“Employee Hanbook.pdf                .exe”。
    這是利用畫面截斷.pdf後的空白字串,讓你誤以為這是一個pdf檔案而開啟執行。

    另外,任何Windows process若是從非標準預設路徑執行,則可高度懷疑為惡意程式。
    幸運的是,unusual process paths能夠以簡單的邏輯辨別出來---
        ● Alert on [windows_process_name] unless the path is correct
        ● Alert on svchost.exe unless its path is C:\Windows\System32\svchost.exe
        ● Alert on explorer.exe unless its path is C:\Windows\explorer.exe

    Windows系統中,若程序啟動後,皆會產生一組Process ID Number (PID),而我們可以在“new process created” events 中以PID來識別出執行程序間的process relationship。例如:系統檔 lsass.exe 不應該透過 cmd.exe 來啟動。

    另一種監控“new process created” events的方式是進行程序使用頻率的排序,而使用頻率越少的程式則列為可疑的程序。另外,也可參考SANS提供的SANS Intrusion Discovery Cheat Sheet (SANS, n.d.) for Windows文件來作為辨識依據。

    再來,Application (如:Adobe Reader、Adobe Acrobat、Adobe Flash、Microsoft Office) 的crash或許與Spear Phishing attack(魚叉式網路釣魚攻擊)有關。
    何謂魚叉式網路釣魚攻擊?

    魚叉式網路釣魚是專門針對特定對象的網路釣魚Phishing),其對象通常是某個機構,其最終目標是取得機密資訊,其技巧則包括:假冒他人名義、使用迷人的誘餌、 避開安全機制 (如電子郵件過濾及防毒) 等等。預算和一般網路釣魚(Phishing)的都會誘騙目標對象開啟郵件中的附件檔案或點選郵件中的連結。

    最後,防毒軟體的Alert也可作為Intrusion detecting的參考。
  2. Detecting Persistence   (偵測後門)
    任何攻擊者在初期入侵成功後,首先要作的便是維持與被控主機的連線,取得立足點,即使該主機重啟後仍能取得控制,稱之為Persistence。
    有許多作法可達成此目標---

        ● Create and install a new service.                       (Event ID 4697)
        ● Create a new scheduled task.                            (Event ID 4698)
        ● Modify the registry keys so the service is started ad boot.   (Event ID 4657)

    要偵測registry key的變更需要先滿足兩個條件---
        1. 啟用Policy
        2. 對需要監控的registry key設定audit enable

    可參考
    SANS Intrusion Discovery Cheat Sheet (SANS, n.d.) for Windows文件所提供的常見Malware建立的registry key路徑進行監控---

        
    ● HKLM\Software\Microsoft\Windows\CurrentVersion\Run
        ● HKLM\Software\Microsoft\Windows\CurrentVersion\Runonce
        ● HKLM\Software\Microsoft\Windows\CurrentVersion\RunonceEx
        ● HKCU\Software\Microsoft\Windows\CurrentVersion\Run
        ● HKCU\Software\Microsoft\Windows\CurrentVersion\Runonce
        ● HKCU\Software\Microsoft\Windows\CurrentVersion\RunonceEx

    有些惡意程式會將防毒軟體關閉,以下提供參考---
        ● The [protection mechanism service] terminated unexpectedly.* (EventID 7034)
        ● The [protection mechanism service] was successfully sent a .* (EventID 7035)
        ● The [protection mechanism service] entered the stopped state.* (EventID 7036)
        ● The [protection mechanism service] service was change from.* (EventID 7040)

    [protection mechanism service] 通常是企業使用的防毒軟體、HIPS、Windows Defender或Windows syslog agent等。一般來說,企業版防毒軟體或因更新會有停止的訊息,但若Windows Defender也一起被停止了,那就很可能是被惡意程式停止的。

  3. Detecting Privilege Escalation   (偵測提權行為)
    提權通常是為了透過網路去存取資源。有一常見的提權技術叫做『Pash the Hash』。
    『Pash the Hash』分為兩個步驟--

        1. 在本機將locally cached credentials 的hash值dump出來
        2. 嘗試利用這個hash來登入網路上其他主機 (稱為pass)

    而要dump出本機的hash需要三個條件---
        ● Hash dumping tool kit  (例:mimikatz)
        ● Local administrator privileges
        ● debug user right (Local administrator 預設即有此權限)
    要防範hash被dump出來,可將debug user right移除,再根據需要開啟。
    而監控Event ID 4704來偵測privilege的變更。

  4. Detecting Internal Reconnaissance   (偵測內網偵查活動)
    通常在系統被入侵後,攻擊者會利用Windows Command Line Tools如 ipconfig, tasklist, 及net use等指令來取得系統或內部網路環境的相關資訊,以作為進一步入侵的準備。

  5. Detecting Lateral Movement   (偵測平行移動)
    在攻擊者取得立足點,透過dump出hash取得合法帳密,並收集足夠的內部網路資訊後,便可對內部網路其他主機進行入侵行動,存取資料,甚至安裝惡意程式在其他主機上,此活動稱之為Lateral Movement (平行移動)。
    而因為攻擊者使用的是合法的帳密,故此活動較難偵測。
    偵測此活動的其中一種方法是尋找不尋常的host to host網路登入行為。
    Windows 會以Network login Type 3 及 Network Login Type 10來記錄這些網路登入行為,記錄的Event ID Number 為 4624|4625。
    Type 3 => 建立網路連線的登入行為,例如連線分享資料夾。
    Type 10 => 遠端桌面連線的登入行為。
    Logon type        
    Logon title
    Description
    2
    Interactive
    A user logged on to this computer.
    3
    Network
    A user or computer logged on to this computer from the network.
    4
    Batch
    Batch logon type is used by batch servers, where processes may be executing on behalf of a user without their direct intervention.
    5
    Service
    A service was started by the Service Control Manager.
    7
    Unlock
    This workstation was unlocked.
    8
    NetworkCleartext
    A user logged on to this computer from the network. The user's password was passed to the authentication package in its unhashed form. The built-in authentication packages all hash credentials before sending them across the network. The credentials do not traverse the network in plaintext (also called cleartext).
    9
    NewCredentials
    A caller cloned its current token and specified new credentials for outbound connections. The new logon session has the same local identity, but uses different credentials for other network connections.
    10
    RemoteInteractive
    A user logged on to this computer remotely using Terminal Services or Remote Desktop.
    11
    CachedInteractive
    A user logged on to this computer with network credentials that were stored locally on the computer. The domain controller was not contacted to verify the credentials.

2017年11月6日 星期一

CentOS 7 新增/移除 應用程式到喜好

從 活動概覽 中新增 
  1. 進入 應用程式 \ 活動概覽
  2. 搜尋欲加入喜好的程式 (例:螢幕擷圖)
  3. 於程式點擊右鍵,選擇 加入喜好 即可
























以 gsettings 的方式設定喜好 (新增/刪除)
  1. 查看目前喜好設定
    user@localhost ~$ gsettings list-recursively | grep -i fav
    org.gnome.shell favorite-apps ['firefox.desktop', 'google-chrome.desktop', 'evolution.desktop', 'vinagre.desktop', 'org.gnome.Terminal.desktop', 'org.gnome.Nautilus.desktop']
  2. 設定喜好
    user@localhost ~$ gsettings set org.gnome.shell favorite-apps "['firefox.desktop', 'google-chrome.desktop', 'evolution.desktop', 'vinagre.desktop', 'org.gnome.Terminal.desktop', 'org.gnome.Nautilus.desktop']"