Damon Cortesi's blog

Musings of an entrepreneur.

PowerShell Saves the Day

| Comments

I ran into a situation today where I only had remote desktop access to a Windows machine and that machine did not have any outbound network access, but I needed to somehow get a dll onto the system. As remote desktop drive access was disabled, but I could copy and paste data via the clipboard, it only took a few moments before I realized base64 was going to be the route to take. But how could I decode it on the other end? Fortunately, the remote system had PowerShell pre-installed (rare, but very fortunate)!

Thanks to a few useful references, I was able to whip up this one-liner to get my dll over to the remote box:

1
$fileName = "CustomLibrary.dll"; [System.Convert]::ToBase64String((Get-Content -Encoding Byte $fileName)) | Set-Content ($fileName + ".b64")

Open the .b64 file in notepad, copy the contents, then paste into a new file on the remote side and then use the following:

1
$fileName = "CustomLibrary.dll"; [System.Convert]::FromBase64String((Get-Content ($fileName + ".b64"))) | Set-Content -Encoding Byte $fileName

And there you have your new dll copied over to the remote system using nothing but PowerShell. And if Out-Clipboard was still built in, I wouldn’t have even had to deal with the intermediary file!

Comments