SSHTunnelCommandArtifacts
Appsv1
Author: Aashiq Ahmed
description
Collect command history, scripts, and SSH client artifacts useful for identifying SSH tunneling and pivoting commands
paths
10 paths
› paths use Windows environment syntax
collection commands
# PowerShell Artifact Collection Script
# Target: SSHTunnelCommandArtifacts
# 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++ }
}
}
# 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
# PowerShell ConsoleHost history
$UserPath = "$($_.FullName)\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine"
Collect-Artifact -SourceDir $UserPath -FileMask "ConsoleHost_history.txt" -FolderName "PowerShell_ConsoleHost_history_$UserName"
# Bash history in user profiles
$UserPath = $_.FullName
Collect-Artifact -SourceDir $UserPath -FileMask ".bash_history" -FolderName "Bash_history_in_user_profiles_$UserName"
# Zsh history in user profiles
$UserPath = $_.FullName
Collect-Artifact -SourceDir $UserPath -FileMask ".zsh_history" -FolderName "Zsh_history_in_user_profiles_$UserName"
# User PowerShell scripts
$UserPath = $_.FullName
Collect-Artifact -SourceDir $UserPath -FileMask "*.ps1" -FolderName "User_PowerShell_scripts_$UserName"
# User batch scripts
$UserPath = $_.FullName
Collect-Artifact -SourceDir $UserPath -FileMask "*.bat" -FolderName "User_batch_scripts_$UserName"
# User command scripts
$UserPath = $_.FullName
Collect-Artifact -SourceDir $UserPath -FileMask "*.cmd" -FolderName "User_command_scripts_$UserName"
# User shell scripts
$UserPath = $_.FullName
Collect-Artifact -SourceDir $UserPath -FileMask "*.sh" -FolderName "User_shell_scripts_$UserName"
# SSH known_hosts
$UserPath = "$($_.FullName)\.ssh"
Collect-Artifact -SourceDir $UserPath -FileMask "known_hosts" -FolderName "SSH_known_hosts_$UserName"
# SSH config
$UserPath = "$($_.FullName)\.ssh"
Collect-Artifact -SourceDir $UserPath -FileMask "config" -FolderName "SSH_config_$UserName"
# SSH directory artifacts
$UserPath = "$($_.FullName)\.ssh"
Collect-Artifact -SourceDir $UserPath -FileMask "*" -FolderName "SSH_directory_artifacts_$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
› cyberchef recipes
Open in CyberChef to decode values extracted from this artifact.