killchain-compendium/Post Exploitation/Windows/Powershell Scripts/Invoke-IFileOperation.ps1

49 lines
11 KiB
PowerShell
Raw Normal View History

2022-11-11 01:15:07 +01:00
function Invoke-IFileOperation {
<#
.SYNOPSIS
Bootstrap function to expose an IFileOperation COM interface to powershell (script-scope).
.DESCRIPTION
Author: Ruben Boonen (@FuzzySec)
License: BSD 3-Clause
Required Dependencies: None
Optional Dependencies: None
.EXAMPLE
C:\PS> Invoke-IFileOperation
C:\PS> $IFileOperation.CopyItem("C:\Some\Dir\a.txt", "C:\Some\Other\Dir\", "b.txt")
C:\PS> $IFileOperation.PerformOperations()
#>
# Compressed Dll which wraps the IFileOperation COM
# Compression --> http://www.exploit-monday.com/2012/12/in-memory-dll-loading.html
$EncodedCompressedFile = @'
7Vt7fFx1lT/3kZnMJJk8GkoLAaZNS9PYhLzatFC0k8ykGTIvZiZ9YCXcmblJhk7mjvdO2oZSTBVRP4ACgqLAQl1YEFhhPwsfkccuAlbWFUHRBS0qiuKyvlBXF1Fkzzn3zp2ZJDzWP/y4n483ud/fOed3fud3fud3fr/7yE34nCtAAgAZz9dfB7gPzGMbvPUxj6fnlPs9cI/riVX3CaEnViWns4a3oGtTujLjTSv5vFb0plSvPpv3ZvNefzThndEyandDg3uNZSMWAAgJErT8/Ns7S3afh9XeOqEHAH/B Ycry EQQvnucx28S0aPoNUC7hJlNOhwTbPkiq9Fsu7YKPNrQbBdPutdLSg6zH4kch1H0bMbEP9K+2gq1FfrSC7y6qB4pYFrutcfWU/a4wcV63buhpsHxDH3mgfdV62/C3W1dzWtr0lSeGbG1apDe00M1YxCxHuUkNyDgxz3cACG9rkIuPV8WOZgC3dBkaOLGrTseiYLSg5AJTpC1DWmtFKFUeR5WidGg5lp0niwe5/JxZcpMNJ1UwHccjdap4IQn +dBxJOleLrR01mCidp4pSa4eDKIBlPRLstXwyXcIucA5l8SKcbrljBUqKTqw7NEbCg4ReWby4SVuHBsSDpLrheNGsMFltLdYcCiMlb1huVsjaSrTTcQKN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bSD+D5zE4in0+Jr6E52/xfA1Pl/CY2IznOjy78DwNzzOER8RhLMdgEvNW5Of6UJ0si0hLsMbtxTV2DviFU+BGhwDy/MK3tPR0XvkK+VYY5Tfa1bJPekxKxh+X +
'@
# Decompress & load assembly
$DeflatedStream = New-Object IO.Compression.DeflateStream([IO.MemoryStream][Convert]::FromBase64String($EncodedCompressedFile),[IO.Compression.CompressionMode]::Decompress)
$UncompressedFileBytes = New-Object Byte[](14336)
$DeflatedStream.Read($UncompressedFileBytes, 0, 14336) | Out-Null
[Reflection.Assembly]::Load($UncompressedFileBytes) | Out-Null
# PS C:\Users\b33f> $IFileOperation |Get-Member
#
# TypeName: FileOperation.FileOperation
#
# Name MemberType Definition
# ---- ---------- ----------
# CopyItem Method void CopyItem(string source, string destination, string newName)
# DeleteItem Method void DeleteItem(string source)
# Dispose Method void Dispose(), void IDisposable.Dispose()
# Equals Method bool Equals(System.Object obj)
# GetHashCode Method int GetHashCode()
# GetType Method type GetType()
# MoveItem Method void MoveItem(string source, string destination, string newName)
# NewItem Method void NewItem(string folderName, string name, System.IO.FileAttributes attrs)
# PerformOperations Method void PerformOperations()
# RenameItem Method void RenameItem(string source, string newName)
# ToString Method string ToString()
$script:IFileOperation = New-Object FileOperation.FileOperation
}