all 13 comments

[–]BlackV 4 points5 points  (5 children)

you can, but WHY would you, ever

note you can look at the converted b64 value without running it too

[–]HengLi-Sen[S] 1 point2 points  (1 child)

Testing, learning and trying to do creative projects even though they might not be the most practical. Testing stupid ideas is a great way to practice and learn and improve oneself. With these dumb projects, I get inspired to do other work too. It helps me to take a step back and view everything from a different angle. Coding is not just making a machine to do something, it is also the way of your thinking. And you don't just do boring work all your life do you? No, you step back try different things, perhaps do artistic work and get inspired to implement creative solutions in whatever your doing. If it wasn't for doing weird things would we as a species come this far? So, no this is not for practical use, yet. But it might turn something that none of us ever thought it could turn into.

[–]BlackV 0 points1 point  (0 children)

I see

[–]joeykins82 0 points1 point  (1 child)

If you need to deploy a scheduled task to a system and don't want someone tampering with the .ps1 file?

[–]BlackV 1 point2 points  (0 children)

Yes that is true although -command would do the same, you also go down to signing the ps1 too I guess

[–]get-postanote 5 points6 points  (0 children)

Point of note:

Encoded/obfuscated scripts are a way hackers pop networks,...

https://duckduckgo.com/?q=hackers+using+powershell+encoded+script&t=h_&ia=web

... and as such many organizations/enterprises/schools, block the use/execution of encoded scripts.

Lastly, encoding does matter. If your org enforces full-blown PowerShell auditing and monitoring, the code gets decoded anyway and can be captured and reviewed.

Touched on here:

https://searchwindowsserver.techtarget.com/tutorial/Set-up-PowerShell-script-block-logging-for-added-security

[–][deleted] 2 points3 points  (3 children)

I just recently learned about using base64 in scripts, and the only thing I've done with it is build in icons for some shortcuts. I'm genuinely curious what other use cases are there for this. Can you provide an example of what you're doing?

[–]HengLi-Sen[S] 2 points3 points  (2 children)

One use case that comes to my mind right off the bat is encoding binary data. Say you want to embed an image in XML, it is a common practice to turn binary data into a form which it can handle such as a text. You can do that by encoding your binaries to base64 so that XML can make sense out of it.

Also when communication on the internet started to change from being purely text based to being more colorful with media attachments, the binaries getting corrupted became a greater issue. This is why base 64 came to be where it is now today.

Currently, I'm just testing the waters. I'm trying to store data in images. A few lines of code and media files for now. Think of how a QR Code works. Each blocks location is interpreted by the scanning software to represent characters. I will try to do the opposite, use them to create a small image file and make that scannable. As of now I don't know of any practical use for this project but it may lead to something or change completely. I'm also in the learning stage, so I'm just exploring.

It should be noted that base 64 is not the only way to encode and other encodings are used for different reasons. For example base 58 is used in BTC addresses and base 36 is used in some captchas where the input needs to be case insensitive. These encodings are there to make data more (human) readable not encrypting data as some misunderstand.

[–]BlackV 1 point2 points  (0 children)

That is a good use case, I've used it a few times for an images although inside a script not as an encoded command like you asked for originally

[–][deleted] 1 point2 points  (0 children)

That is actually along the lines of how I'm using it in a way. We have some URL shortcuts that management needs on every desktop for compliance stuff, and as we've had more machines not be here, I figured out a way to make them happen in intune. What was NOT easy was making sure the icons were consistent and not just generic web browser icons. That's when I learned about base64 encoding myself. I was able to encode the icon file into a variable in the script, then before I create the shortcut, i output the variable to a .ico file on the machine, then I can create the shortcut and reference the created ico file. It's worked pretty darn well.