-
Notifications
You must be signed in to change notification settings - Fork 9
/
decloakify.ps1
120 lines (88 loc) · 3.58 KB
/
decloakify.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
#
# Filename: decloakify.ps1
#
# Author: Joe Gervais (TryCatchHCF)
#
#
# Port to Powershell : John Aho
#
# Summary: Exfiltration toolset (see cloakify.ps1) that transforms data into lists
# of words / phrases / Unicode to ease exfiltration of data across monitored networks,
# essentially hiding the data in plain sight, and facilitate social engineering attacks
# against human analysts and their workflows. Bonus Feature: Defeats signature-based
# malware detection tools (cloak your other tools).
#
# Used by cloakifyFactory.ps1, can be used as a standalone script as well (example below).
#
# Description: Decodes the output of cloakify.ps1 into its underlying Base64 format,
# then does Base64 decoding to unpack the cloaked payload file. Requires the use of the
# same cipher that was used to cloak the file prior to exfitration, of course.
#
# Prepackaged ciphers include: lists of desserts in English, Arabic, Thai, Russian,
# Hindi, Chinese, Persian, and Muppet (Swedish Chef); Top 100 IP Addresses; GeoCoords of
# World Capitols; MD5 Password Hashes; An Emoji cipher; Star Trek characters; Geocaching
# Locations; Amphibians (Scientific Names); and evadeAV cipher, a simple cipher that
# minimizes the size of the resulting obfuscated data.
#
# Example:
#
# $ ./decloakify.ps1 cloakedPayload.txt ciphers/desserts.ciph
param (
[Parameter(Mandatory=$false)][string]$cloakedFile,
[Parameter(Mandatory=$false)][string]$cipher,
[Parameter(Mandatory=$false)][string]$outputFile
)
# Get directory path.
$invocation = (Get-Variable MyInvocation).Value
$directorypath = Split-Path $invocation.MyCommand.Path
Set-Location $directorypath
Write-Host $directorypath
[void] (Invoke-Expression("chcp 65001")) #sets output of console to UTF-8
$OFS = "`r`n"
$array64 = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789/+="
if($cloakedFile -ne $null -and ($cloakedFile.Length -gt 0)){
if(Test-Path $cloakedFile){
try{
$cipherArray = Get-Content ( $cipher ) -Encoding UTF8
}catch{
write-host("")
write-host("!!! Oh noes! Problem reading cipher '" + $cipher + "'")
write-host("!!! Verify the location of the cipher file" )
write-host("")
$ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName
Write-Host(" $ErrorMessage : $FailedItem ")
write-host("")
}
$listExfiltrated = get-content $cloakedFile -Encoding UTF8
$clear64SB = New-Object System.Text.StringBuilder
foreach($line in $listExfiltrated){
[void]$clear64SB.Append( $array64[ $cipherArray.IndexOf($line) ] )
}
$inclear64 = $clear64SB.ToString()
if ( $outputFile.Length -gt 0 ){
try{
if($outputFile.IndexOf("\") -lt 0){
$outputFile = $directorypath +"\"+$outputFile
}
[IO.File]::WriteAllBytes($outputFile, [Convert]::FromBase64String($inclear64))
}catch{
write-host("")
write-host("!!! Oh noes! Problem opening or writing to file "+ $outputFile)
write-host("")
$ErrorMessage = $_.Exception.Message
$FailedItem = $_.Exception.ItemName
Write-Host(" $ErrorMessage : $FailedItem ")
write-host("")
}
}else{
#Just write out text/result to console
$b = [System.Convert]::FromBase64String($gah)
write-host [System.Text.Encoding]::UTF8.GetString($b)
}
}else{
write-host("usage: decloakify.ps1 <cloakedFilename> <cipherFilename>")
}
}else{
write-host("usage: decloakify.ps1 <cloakedFilename> <cipherFilename>")
}