/
TelefonicaWannacryFileRestorer.ps1
143 lines (112 loc) · 3.89 KB
/
TelefonicaWannacryFileRestorer.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
function restore{
param(
[parameter(Mandatory=$true)]
[string] $path
)
echo $path
$ErrorActionPreference = "SilentlyContinue"
Get-Childitem $path -include *.WNCRYT -recurse -force |
Foreach-Object {
$nombre = $_.FullName
echo "$nombre"
$bytes = gc -en byte -TotalCount 600 $nombre | % { '{0:X2}' -f $_ }
$b = ""
for($i=0; $i -le 100; $i++)
{
$b += $bytes[$i]
}
for($i=0; $i -lt $known.Length; $i++)
{
$fichero_docx=$false
$fichero_xlsx=$false
$fichero_pptx=$false
if ($b.contains($known[$i].header)){
echo "Header Detection: "$known[$i].extension
$newFile = $nombre + "." + $known[$i].extension
mv $nombre $newFile
if ($known[$i].extension -eq "doc"){
$doc = $newFile + ".doc"
cp $newFile $doc
$xls = $newFile + ".xls"
cp $newfile $xls
$ppt = $newFile + ".ppt"
cp $newfile $ppt
break
}
if ($known[$i].extension -eq "Zip"){
cat $newFile | findstr "word/_rels/document.xml.rels" | Out-Null
if ($?) {$fichero_docx=$true}
cat $newFile | findstr "xl/worksheets" | Out-Null
if ($?) {$fichero_xlsx=$true}
cat $newFile | findstr "ppt/_rels/presentation.xml.rels" | Out-Null
if ($?) {$fichero_pptx=$true}
if ($fichero_docx){
$docx = $newFile + ".docx"
mv $newFile $docx
}
if ($fichero_xlsx){
$xlsx = $newFile + ".xlsx"
mv $newFile $xlsx
}
if ($fichero_pptx) {
$pptx = $newFile + ".pptx"
mv $newFile $pptx
}
break
}
}
}
}
}
$known = @'
"Extension","Header"
"7z","377ABCAF271C"
"djvu","41542654464F524Dnnnnnnnn444A56"
"doc","D0CF11E0A1B11AE1"
"dpx","53445058"
"jpg","4A464946"
"pdf","25504446"
"png","89504E470D0A1A0A"
"ps","25215053"
"psd","38425053"
"rar","526172211A0700"
"rar","526172211A070100"
"tif","49492A00"
"vsdx","504B0708"
"wav","52494646nnnnnnnn"
"wma","A6D900AA0062CE6C"
"zip","504B0304"
"epub","504B03040A000200"
"ppt","D0CF11E0A1B11AE1"
"rtf","7B5C72746631"
"xls","D0CF11E0A1B11AE1"
"bmp","424D"
"txt",""
'@ | ConvertFrom-Csv | sort {$_.header.length} -Descending
echo "Telefonica Wannacry File Restorer Alpha v.0.1"
echo "============================================="
for($i=0; $i -lt $known.Length; $i++)
{
($known[$i].header).replace(" ","") | Out-Null
}
$strComputer = "."
$colDisks = Get-WmiObject -Class Win32_LogicalDisk -ComputerName $strComputer
foreach ($objDisk in $colDisks)
{
if ($objDisk.DriveType -eq 3)
{
$rutadefinitiva = $objDisk.deviceID
#
if ($rutadefinitiva -eq "C:")
{
#$path = $env:LOCALAPPDATA+"\temp"
$path = "C:\users\*\appdata\local\temp"
}
else
{
$path = "$rutadefinitiva\$RECYCLE"
}
restore -path $path
}
}
exit