OpenSSHServer

Author: Matt Dawson

description

OpenSSH Server Config and Logs

paths

9 paths
paths use Windows environment syntax

collection commands

# PowerShell Artifact Collection Script
# Target: OpenSSHServer
# Run as Administrator

#Requires -RunAsAdministrator

$ErrorActionPreference = "Continue"
$SourceRoot = "C:"
$DestBase   = "D:\Evidence"
$Summary = @{ Copied = 0; Missed = 0; Errors = 0 }

function Collect-Artifact {
    param(
        [Parameter(Mandatory)][string]$SourceDir,
        [Parameter(Mandatory)][string]$FolderName,
        [string]$FileMask = "*"
    )
    # Expand wildcards in any path segment (e.g. 'Program Files*',
    # 'ScreenConnect Client*'). robocopy itself does not glob the source.
    $sources = @(Get-Item -Path $SourceDir -ErrorAction SilentlyContinue |
        Where-Object { $_.PSIsContainer })
    if ($sources.Count -eq 0) {
        $Summary.Missed++
        return
    }
    $FullDest = Join-Path -Path $DestBase -ChildPath $FolderName
    $null = New-Item -ItemType Directory -Force -Path $FullDest -ErrorAction SilentlyContinue
    foreach ($src in $sources) {
        robocopy $src.FullName "$FullDest" "$FileMask" /E /COPY:DAT /R:0 /W:0 /NP /NFL /NDL /NJH /NJS 2>$null | Out-Null
        if ($LASTEXITCODE -le 7) { $Summary.Copied++ } else { $Summary.Errors++ }
    }
}

# 1. OpenSSH Server Config File
Collect-Artifact -SourceDir "C:\ProgramData\ssh" -FileMask "sshd_config" -FolderName "OpenSSH_Server_Config_File"

# 2. OpenSSH Server Logs
Collect-Artifact -SourceDir "C:\ProgramData\ssh\logs" -FileMask "*" -FolderName "OpenSSH_Server_Logs"

# 3. OpenSSH Host ECDSA Key
Collect-Artifact -SourceDir "C:\ProgramData\ssh" -FileMask "ssh_host_ecdsa_key" -FolderName "OpenSSH_Host_ECDSA_Key"

# 4. OpenSSH Host ED25519 Key
Collect-Artifact -SourceDir "C:\ProgramData\ssh" -FileMask "ssh_host_ed25519_key" -FolderName "OpenSSH_Host_ED25519_Key"

# 5. OpenSSH Host DSA Key
Collect-Artifact -SourceDir "C:\ProgramData\ssh" -FileMask "ssh_host_dsa_key" -FolderName "OpenSSH_Host_DSA_Key"

# 6. OpenSSH Host RSA Key
Collect-Artifact -SourceDir "C:\ProgramData\ssh" -FileMask "ssh_host_rsa_key" -FolderName "OpenSSH_Host_RSA_Key"

# 7. OpenSSH Authorized Administrator Keys
Collect-Artifact -SourceDir "C:\ProgramData\ssh" -FileMask "administrators_authorized_keys" -FolderName "OpenSSH_Authorized_Administrator_Keys"

# Iterate every user profile under the source drive
Get-ChildItem "$SourceRoot\Users" -Directory -ErrorAction SilentlyContinue |
    Where-Object { $_.Name -notin @('All Users', 'Default', 'Default User', 'Public') } |
    ForEach-Object {
        $UserName = $_.Name
        # OpenSSH User Authorized Keys
        $UserPath = "$($_.FullName)\.ssh"
        Collect-Artifact -SourceDir $UserPath -FileMask "authorized_keys" -FolderName "OpenSSH_User_Authorized_Keys_$UserName"
        # OpenSSH User Authorized Keys 2
        $UserPath = "$($_.FullName)\.ssh"
        Collect-Artifact -SourceDir $UserPath -FileMask "authorized_keys2" -FolderName "OpenSSH_User_Authorized_Keys_2_$UserName"
    }

Write-Host ("Collection complete. Copied: {0}  Missed: {1}  Errors: {2}" -f $Summary.Copied, $Summary.Missed, $Summary.Errors) -ForegroundColor Green

Save as .ps1 and run as Administrator. Use: powershell -ExecutionPolicy Bypass -File script.ps1

references

included in collections