Add ability to upload file to ADS

temp
m0rv4i 2019-03-10 17:11:22 +00:00
parent 5a6afd605a
commit 707dc93fa2
1 changed files with 22 additions and 7 deletions

View File

@ -500,24 +500,39 @@ function Upload-File
[bool] $NotHidden = $false
)
try {
$Stream = ""
if ($NotHidden -eq $true) {
write-output "Uploaded file to: $Destination"
$FullPath = $Destination
if ($Destination -Match ':[^\\]'){
$Destination = $FullPath.Substring(0, $FullPath.LastIndexOf(":"))
$Stream = $FullPath.Substring($FullPath.LastIndexOf(":") + 1)
}
$fileBytes = [Convert]::FromBase64String($Base64)
[io.file]::WriteAllBytes($Destination, $fileBytes)
if ($Stream){
add-content -path $Destination -value $fileBytes -stream $Stream -encoding byte
} else {
[io.file]::WriteAllBytes($Destination, $fileBytes)
}
} else {
write-output "Uploaded file as HIDDEN & SYSTEM to: $Destination"
write-output "Run Get-ChildItem -Force to view the uploaded files"
$FullPath = $Destination
if ($Destination -Match ':[^\\]'){
$Destination = $FullPath.Substring(0, $FullPath.LastIndexOf(":"))
$Stream = $FullPath.Substring($FullPath.LastIndexOf(":") + 1)
}
$fileBytes = [Convert]::FromBase64String($Base64)
if ($Stream){
add-content -path $Destination -value $fileBytes -stream $Stream -encoding byte
} else {
[io.file]::WriteAllBytes($Destination, $fileBytes)
}
$file = Get-Item $Destination -Force
$attrib = $file.Attributes
$attrib = "Hidden,System"
$file.Attributes = $attrib
}
} catch {