Showing posts with label password. Show all posts
Showing posts with label password. Show all posts

Wednesday, 5 May 2021

Storing and Using Encrypted Passwords with Powershell

There are lots of reasons why a username and password may be incorporated into a Powershell script - naturally, the quickest and easiest way to do this is to simply store the username and password in a script using a couple of variables such as;

$username = "user1"
$password = "password1"

Simple, and it works, but is definitely not secure.

There is a simple method you can use though to encrypt the password using powershell and store it as a text file on your computer. The password is encrypted using the currently logged in windows account that is running the powershell script (when you encrypt it) so keep this in mind if you are trying to decrypt the password with a different user account (because it won't work).

This is of course a 2 step process. The first step is to take your unsecured password (yourpassword) then encrypt it, and store the encrypted text value into a txt file (in C:\temp\user1-secpw.txt)

#Store Secure Credentials 
$unsecpw = "yourpassword"
$secpw = $unsecpw | convertto-securestring -asplaintext -force
$securestringtext = $secpw | convertfrom-securestring
set-content "C:\temp\user1-secpw.txt" $securestringtext

Once you've done this part and you have your password stored in the txt file, you should at the very least clear the value from the $unsecpw if you are saving this script - otherwise you're essentially defeating the purpose of encrypting it in the first place.

The second part is of course the process of importing the txt file into a new script so you can use the password. As previously mentioned, you will only be able to decrypt the password if you are executing the decryption commands under the same user security context (ie. windows user) as when you encrypted it.

$pwd = get-content "C:\temp\user1-secpw.txt" | convertto-securestring
$BSTR = [System.Runtime.InteropServices.Marshal]::SecureStringToBSTR($pwd)
$Unsecpw = [System.Runtime.InteropServices.Marshal]::PtrToStringAuto($BSTR)

Your password is now available to use via the $unsecpw variable

Friday, 7 October 2016

Optus - Sagemcom F@ST 3864 modem/router - admin username and password

The Sagemcom F@ST 3864 modem/router that is provided by Optus has an administrative interface that you can login to to access advanced features that aren't accessible via the the "standard" interface.

The standard interface is accessed via http://192.168.0.1/main.html?loginuser=1 and allows access to basic settings such as wifi options without needing to enter a username/password

However, if you change the "loginuser=" value from a "1" to a "0" you get prompted for a username/password. Once you've entered the correct username/password you can then access more advanced features within the modem setup/config.

There are a number of forum posts stating some of the default usernames/passwords for this modem, but none of them worked for me, even after a factory reset. What I did stumble across though was how to definitively (and easily) retrieve the admin password for this modem;


  1. Open a web browser and go to http://192.168.0.1/password.html
    You will be presented with a screen like the one pictured below;

  2. Right click in a blank area of the page, and select the option to "View source" or "View page source" (the wording might be slightly different depending on what browser you are using)

  3. This will load up all the html code used on this page. If you look towards the top of the page, you will see a line starting with "pwdAdmin = " - what is after this and contained within single quotes is the admin password that is set on the router



  4. You can then go to the URL http://192.168.0.1/main.html?loginuser=0 and enter the username "admin" and the password from Step 3 above and you will be able to access the hidden/advanced menu options within the router