Skip to content

Commit

Permalink
Merge pull request #134 from dwhite9/mod-x-log
Browse files Browse the repository at this point in the history
Update Syslog and Default logging scripts to detect IP address of host
  • Loading branch information
clr2of8 authored Jun 10, 2023
2 parents 540ba99 + 213b567 commit c401108
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
14 changes: 13 additions & 1 deletion Public/Default-ExecutionLogger.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,18 @@ function Write-ExecutionLog($startTime, $stopTime, $technique, $testNum, $testNa
if (!(Test-Path $logPath)) {
New-Item $logPath -Force -ItemType File | Out-Null
}

if ($isWindows){
$ipAddress = (Get-NetIPAddress | Where-Object { $_.PrefixOrigin -ne "WellKnown"}).IPAddress
}
elseif ($IsMacOS) {
$ipAddress = ifconfig -l | xargs -n1 ipconfig getifaddr
}
elseif ($IsLinux) {
$ipAddress = ip -4 -br addr show |sed -n -e 's/^.*UP\s* //p'
}
else {
$ipAddress = ''
}
$timeUTC = (Get-Date($startTime).toUniversalTime() -uformat "%Y-%m-%dT%H:%M:%SZ").ToString()
$timeLocal = (Get-Date($startTime) -uformat "%Y-%m-%dT%H:%M:%SZ").ToString()
$msg = [PSCustomObject][ordered]@{
Expand All @@ -16,6 +27,7 @@ function Write-ExecutionLog($startTime, $stopTime, $technique, $testNum, $testNa
"Test Number" = $testNum
"Test Name" = $testName
"Hostname" = $targetHostname
"IP Address" = $ipAddress
"Username" = $targetUser
"GUID" = $testGuid
"ProcessId" = $res.ProcessId
Expand Down
14 changes: 14 additions & 0 deletions Public/Syslog-ExecutionLogger.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,27 @@ function Start-ExecutionLog($startTime, $logPath, $targetHostname, $targetUser,
function Write-ExecutionLog($startTime, $stopTime, $technique, $testNum, $testName, $testGuid, $testExecutor, $testDescription, $command, $logPath, $targetHostname, $targetUser, $res, $isWindows) {
$timeUTC = (Get-Date($startTime).toUniversalTime() -uformat "%Y-%m-%dT%H:%M:%SZ").ToString()
$timeLocal = (Get-Date($startTime) -uformat "%Y-%m-%dT%H:%M:%SZ").ToString()
if ($isWindows){
$ipAddress = (Get-NetIPAddress | Where-Object { $_.PrefixOrigin -ne "WellKnown"}).IPAddress
}
elseif ($IsMacOS) {
$ipAddress = ifconfig -l | xargs -n1 ipconfig getifaddr
}
elseif ($IsLinux) {
$ipAddress = ip -4 -br addr show |sed -n -e 's/^.*UP\s* //p'
}
else {
$ipAddress = ''
}

$msg = [PSCustomObject][ordered]@{
"Execution Time (UTC)" = $timeUTC
"Execution Time (Local)" = $timeLocal
"Technique" = $technique
"Test Number" = $testNum
"Test Name" = $testName
"Hostname" = $targetHostname
"IP Address" = $ipAddress
"Username" = $targetUser
"GUID" = $testGuid
"Tag" = "atomicrunner"
Expand Down

0 comments on commit c401108

Please sign in to comment.