-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathDemo2.ps1
132 lines (101 loc) · 3.62 KB
/
Demo2.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# Break if accidentally executed fully
break
# Setup ISE
$psISE.Options.Zoom = 160
# Transcription by Profile
'$null = Start-Transcript -Path C:\Transcription\Profile.log -Append' |
Out-File -FilePath (Join-Path $PSHOME 'Microsoft.PowerShell_profile.ps1') -Force
# Show how to work around this
Stop-Transcript
# View Transcription log
Invoke-Item -Path 'C:\Transcription\Profile.log'
# Remove PowerShell Profile logging
Remove-Item -Path (Join-Path $PSHOME 'Microsoft.PowerShell_profile.ps1') -Force
# Module Transcription
# MMC -> Local Computer Policy
# Computer Configuration\Administrative Templates\Windows Components\Windows PowerShell
# Open PowerShell
Clear-EventLog -LogName 'Windows PowerShell'
Get-WinEvent -LogName 'Windows PowerShell' |
Select-Object -ExpandProperty Message |
Where-Object {$_ -match '"Get-WinEvent"'} |
Select-Object -First 1
# Count the number of lines in output
(Get-WinEvent -LogName 'Windows PowerShell' |
Select-Object -ExpandProperty Message |
Where-Object {$_ -match '"Get-WinEvent"'} |
Select-Object -First 1) -split "`r`n" |
Measure-Object
Import-Module CustomizeWindows10 -Verbose
Add-PowerShellWinX
Get-WinEvent -LogName 'Windows PowerShell' |
Select-Object -ExpandProperty Message |
Where-Object {$_ -match 'CommandLine=Add-PowerShellWinX'}
# Check LogPipelineExecutionDetails (3.0 feature)
(Get-Module CustomizeWindows10).LogPipelineExecutionDetails
# Disable LogPipelineExecutionDetails
(Get-Module CustomizeWindows10).LogPipelineExecutionDetails = $false
# Clear EventLog and rerun cmdlet
Clear-EventLog -LogName 'Windows PowerShell'
Add-PowerShellWinX
Get-WinEvent -LogName 'Windows PowerShell' |
Select-Object -ExpandProperty Message |
Where-Object {$_ -match 'CommandLine=Add-PowerShellWinX'}
# MMC -> Local Computer Policy
# Computer Configuration\Administrative Templates\Windows Components\Windows PowerShell
# Disable Module logging and Enable Transcription to C:\Transcription
# Restart ISE
# Open the log
Get-ChildItem C:\Transcription\20151119 -File | Invoke-Item
# Import Module
Import-Module -Name PS-MotD
Get-MOTD
# Open the log
Get-ChildItem C:\Transcription\20150919 -File | Invoke-Item
# PInvoke C# code and execute it
$Source = @"
using System;
namespace CS
{
public class Program
{
public static void Payload()
{
Console.WriteLine("Awesome!");
}
}
}
"@
Add-Type -TypeDefinition $Source -Language CSharp
[CS.Program]::Payload()
# Open the log
Get-ChildItem C:\Transcription\20150919 -File |
Sort-Object -Property LastWriteTime | Select-Object -Last 1 |
Invoke-Item
# Another example
$Code = Get-Content -Path C:\Users\JaapBrasser\Desktop\Demo2\Malicious.txt -Raw
Add-Type -TypeDefinition $Code -Language CSharp
[CS.Malicious]::Payload()
# MMC -> Local Computer Policy
# Computer Configuration\Administrative Templates\Windows Components\Windows PowerShell
# Enable Deep Script block logging
# Another example
$Code = Get-Content -Path C:\Users\JaapBrasser\Desktop\Demo2\Malicious.txt -Raw
Add-Type -TypeDefinition $Code -Language CSharp
[CS.Malicious]::Payload()
# Open the log
Get-ChildItem C:\Transcription\20151119 -File |
Sort-Object -Property LastWriteTime | Select-Object -Last 1 |
Invoke-Item
# Inspect the deep script logging results
Get-WinEvent -FilterHashtable @{
ProviderName="Microsoft-Windows-PowerShell"
Id = 4104
} | Select-Object -First 3 -ExpandProperty Message
# Encoded string
iex (-join (echo 91 109 97 116 104 93 58 58 80 73 | % {[char]$_}))
# Inspect the deep script logging results
Get-WinEvent -FilterHashtable @{
ProviderName="Microsoft-Windows-PowerShell"
Id = 4104
} | Select-Object -First 3 -ExpandProperty Message