Skip to content
This repository was archived by the owner on Jan 21, 2021. It is now read-only.

Commit 25934d4

Browse files
Added New-VolumeShadowCopy and Remove-VolumeShadowCopy Cmdlets
1 parent 2153a0a commit 25934d4

File tree

1 file changed

+168
-1
lines changed

1 file changed

+168
-1
lines changed

Exfiltration/VolumeShadowCopyTools.ps1

Lines changed: 168 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,174 @@
2020
Throw 'You must run Get-VolumeShadowCopy from an elevated command prompt.'
2121
}
2222

23-
Get-WmiObject Win32_ShadowCopy | ForEach-Object { $_.DeviceObject }
23+
Get-WmiObject -Namespace root\cimv2 -Class Win32_ShadowCopy | ForEach-Object { $_.DeviceObject }
24+
}
25+
26+
function New-VolumeShadowCopy
27+
{
28+
<#
29+
.SYNOPSIS
30+
31+
Creates a new volume shadow copy.
32+
33+
PowerSploit Function: New-VolumeShadowCopy
34+
Author: Jared Atkinson (@jaredcatkinson)
35+
License: BSD 3-Clause
36+
Required Dependencies: None
37+
Optional Dependencies: None
38+
Version: 2.0.0
39+
40+
.DESCRIPTION
41+
42+
New-VolumeShadowCopy creates a volume shadow copy for the specified volume.
43+
44+
.PARAMETER Volume
45+
46+
Volume used for the shadow copy. This volume is sometimes referred to as the original volume.
47+
The Volume parameter can be specified as a volume drive letter, mount point, or volume globally unique identifier (GUID) name.
48+
49+
.PARAMETER Context
50+
51+
Context that the provider uses when creating the shadow. The default is "ClientAccessible".
52+
53+
.EXAMPLE
54+
55+
New-VolumeShadowCopy -Volume C:\
56+
57+
Description
58+
-----------
59+
Creates a new VolumeShadowCopy of the C drive
60+
#>
61+
Param(
62+
[Parameter(Mandatory = $True)]
63+
[ValidatePattern('^\w:\\')]
64+
[String]
65+
$Volume,
66+
67+
[Parameter(Mandatory = $False)]
68+
[ValidateSet("ClientAccessible")]
69+
[String]
70+
$Context = "ClientAccessible"
71+
)
72+
73+
$UserIdentity = ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent())
74+
75+
if (-not $UserIdentity.IsInRole([Security.Principal.WindowsBuiltInRole]'Administrator'))
76+
{
77+
Throw 'You must run Get-VolumeShadowCopy from an elevated command prompt.'
78+
}
79+
80+
$class = [WMICLASS]"root\cimv2:win32_shadowcopy"
81+
82+
$return = $class.create("$Volume", "$Context")
83+
84+
switch($return.returnvalue)
85+
{
86+
1 {Write-Error "Access denied."; break}
87+
2 {Write-Error "Invalid argument."; break}
88+
3 {Write-Error "Specified volume not found."; break}
89+
4 {Write-Error "Specified volume not supported."; break}
90+
5 {Write-Error "Unsupported shadow copy context."; break}
91+
6 {Write-Error "Insufficient storage."; break}
92+
7 {Write-Error "Volume is in use."; break}
93+
8 {Write-Error "Maximum number of shadow copies reached."; break}
94+
9 {Write-Error "Another shadow copy operation is already in progress."; break}
95+
10 {Write-Error "Shadow copy provider vetoed the operation."; break}
96+
11 {Write-Error "Shadow copy provider not registered."; break}
97+
12 {Write-Error "Shadow copy provider failure."; break}
98+
13 {Write-Error "Unknown error."; break}
99+
default {break}
100+
}
101+
}
102+
103+
function Remove-VolumeShadowCopy
104+
{
105+
<#
106+
.SYNOPSIS
107+
108+
Deletes a volume shadow copy.
109+
110+
PowerSploit Function: Remove-VolumeShadowCopy
111+
Author: Jared Atkinson (@jaredcatkinson)
112+
License: BSD 3-Clause
113+
Required Dependencies: None
114+
Optional Dependencies: None
115+
Version: 2.0.0
116+
117+
.DESCRIPTION
118+
119+
Remove-VolumeShadowCopy deletes a volume shadow copy from the system.
120+
121+
.PARAMETER InputObject
122+
123+
Specifies the Win32_ShadowCopy object to remove
124+
125+
.PARAMETER DevicePath
126+
127+
Specifies the volume shadow copy 'DeviceObject' path. This path can be retrieved with the Get-VolumeShadowCopy PowerSploit function or with the Win32_ShadowCopy object.
128+
129+
.EXAMPLE
130+
131+
Get-VolumeShadowCopy | Remove-VolumeShadowCopy
132+
133+
Description
134+
-----------
135+
Removes all volume shadow copy
136+
137+
.EXAMPLE
138+
139+
Get-WmiObject Win32_ShadowCopy | Remove-VolumeShadowCopy
140+
141+
Description
142+
-----------
143+
Removes all volume shadow copy
144+
145+
.EXAMPLE
146+
147+
Remove-VolumeShadowCopy -DevicePath '\\?\GLOBALROOT\Device\HarddiskVolumeShadowCopy4'
148+
149+
Description
150+
-----------
151+
Removes the volume shadow copy at the 'DeviceObject' path \\?\GLOBALROOT\DeviceHarddiskVolumeShadowCopy4
152+
#>
153+
Param(
154+
[Parameter(Mandatory = $False, ValueFromPipeline = $True)]
155+
[ValidateNotNullOrEmpty()]
156+
[Object]
157+
$InputObject,
158+
159+
[Parameter(Mandatory = $False)]
160+
[ValidatePattern('^\\\\\?\\GLOBALROOT\\Device\\HarddiskVolumeShadowCopy[0-9]{1,3}$')]
161+
[String]
162+
$DevicePath
163+
)
164+
165+
PROCESS
166+
{
167+
if($PSBoundParameters.ContainsKey("InputObject"))
168+
{
169+
if($InputObject.GetType().Name -eq "String")
170+
{
171+
(Get-WmiObject -Namespace root\cimv2 -Class Win32_ShadowCopy | Where-Object {$_.DeviceObject -eq $InputObject}).Delete()
172+
}
173+
else
174+
{
175+
$InputObject.Delete()
176+
}
177+
}
178+
elseif($PSBoundParameters.ContainsKey("DevicePath"))
179+
{
180+
(Get-WmiObject -Namespace root\cimv2 -Class Win32_ShadowCopy | Where-Object {$_.DeviceObject -eq $DevicePath}).Delete()
181+
}
182+
else
183+
{
184+
$vsc = Get-WmiObject -Namespace root\cimv2 -Class Win32_ShadowCopy
185+
foreach($copy in $vsc)
186+
{
187+
$copy.Delete()
188+
}
189+
}
190+
}
24191
}
25192

26193
function Mount-VolumeShadowCopy

0 commit comments

Comments
 (0)