Jump to content

Recommended Posts

Posted

Hello,
I have several scripts that has password in it. Like:
 

Run(@ComSpec & " /c " & '"C:\Program Files\PuTTY\plink.exe" -ssh -pw Pa$$w0rd administrator@192.168.1.1','', @SW_HIDE)
$sUsername = 'administrator'
$sPassword = 'Pa$$w0rd'

How do you handle password? because it is in clear in a "text" file.
or
Do you have some idea for more security ?

Thanks in advance.

C.

Posted (edited)
Quote

the easiest but not the safest
Just to hide it from prying eyes

Not bad

Edited by cramaboule
Posted (edited)

Hi @cramaboule 👋 ,

there are several criteria with different answers "it depends" 😁 .

  1. Is your code public or private (in a repository)?
  2. Runs your code/program only locally or on different machines?

If it's public, never use passwords, salts or other secrets in code directly.
Use the secret management of GitHub/GitLab (or other platforms).
Or use environment variables to store the secrets (but again, make sure the secrets are encrypted separately there).

If your code only runs on your machine locally, also use env vars or registry entries.
The way @ioa747 suggested, masking the secret (something like obfuscation) is "okayish" for local, private usage (in my opinion).
But for all other scenarios avoid secrets in code.

Best regards
Sven

Edited by SOLVE-SMART

==> AutoIt related: 🔗 GitHub, 🔗 Discord Server, 🔗 Cheat Sheet

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Posted
5 minutes ago, SOLVE-SMART said:

Hi @cramaboule 👋 ,

there are several criteria with different answers "it depends" 😁 .

  1. Is your code public or private (in a repository)?
  2. Runs your code/program only locally or on different machines?

If it's public, never use passwords, salts or other secrets in code directly.
Use the secret management of GitHub/GitLab (or other platforms).
Or use environment variables to store the secrets (but again, make sure the secrets are encrypted separately there).

If you code only runs on your machine locally, also use env vars or registry entries.
The way @ioa747 suggested, masking the secret (something like obfuscation) is "okayish" for local, private usage (in my opinion).
But for all other scenarios avoid secrets in code.

Best regards
Sven

Hi @SOLVE-SMART,

Well, some code are only for me, some other are on my network or on servers running here and there...
Obviously, I won't make any sensitif info on Github public...
--> Use the secret management of GitHub
--> secrets are encrypted separately
more info on those?

Posted (edited)

..I use an ini file with the crypt* functions. The decrypt part takes creativity. I use some string as "salt" plus the date-time of creation of said ini file in UTC but, shhhh, that's my secret :)

Again, my secret is creativity. Then again, just like you, these scripts are not for the public.

Edited by argumentum

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

  • Developers
Posted

Just to be clear: Whatever you do, the shell command requires the clear text password, so by definition no solution will be safe! 🙂
 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted
3 minutes ago, Jos said:

Just to be clear: Whatever you do, the shell command requires the clear text password, so by definition no solution will be safe! 🙂
 

Obviously... but I do not want the clear pw in my code.

Posted
7 minutes ago, argumentum said:

..I use an ini file with the crypt* functions. The decrypt part takes creativity. I use some string as "salt" plus the date-time of creation of said ini file in UTC but, shhhh, that's my secret :)

Again, my secret is creativity. Then again, just like you, these scripts are not for the public.

Hummmmm good idea ! will look at it !

C.

Posted
Exit CmdLineDetails()
Func CmdLineDetails($sName = "plink.exe") ; run as admin
    Local $sRun = @ComSpec & " /c powershell ""Get-CimInstance Win32_Process -Filter \""name = '" & $sName & "'\"" | Select-Object Name,ProcessId,CommandLine,CreationDate | ConvertTo-Json"" "
    ConsoleWrite($sRun & @CRLF)

    Local $hTimer = TimerInit(), $iPid = Run($sRun, @SystemDir, Default, $STDOUT_CHILD)
    ConsoleWrite($hTimer & @CRLF)
    ProcessWaitClose($iPid)
    Local $sJSON = StdoutRead($iPid)
    ConsoleWrite($sJSON & @CRLF)
EndFunc

Like Jos said, the way that is running is not that safe anyway. But yes, keep passwords safe.

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted (edited)

..the "salt" could be a hash of a password you enter before loading whatever. Then while that's running ( the script you entered the password to ), your other scripts can ask via IPC what's the salt. ( an idea that just pop into my head now )

Edited by argumentum

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Posted

one way would be to use it as intended: do not store the password in your script, instead have your script ask you for the password (via inputBox() for example). this is feasible when you don't need to do it too often. if you do, you can streamline the process by using an external password manager (KeePass for example), which can automatically insert the password when prompted.

but that's not how i would go about this.

i'd consider storing the username and password in the built-in Windows Credential Manager. you can query it to retrieve the credentials, and have your code insert them where required.

now, of course if a malicious actor gains access to your environment, any and all methods suggested are compromised. so i'm assuming the purpose is to prevent someone from discovering your password if all they have is the contents of your script.

P.S. if you compile your script to executable, that's the first barrier you can put against prying eyes. if those eyes belong to your over-the-average-curious end user, that should throw them off.

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

WinPose - simultaneous fluent move and resize

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

Magic Math - a math puzzle

Demos:

Title Bar Menu - click the window title to pop-up a menu

 

Posted
20 minutes ago, orbs said:

one way would be to use it as intended: do not store the password in your script, instead have your script ask you for the password (via inputBox() for example). this is feasible when you don't need to do it too often. if you do, you can streamline the process by using an external password manager (KeePass for example), which can automatically insert the password when prompted.

but that's not how i would go about this.

i'd consider storing the username and password in the built-in Windows Credential Manager. you can query it to retrieve the credentials, and have your code insert them where required.

now, of course if a malicious actor gains access to your environment, any and all methods suggested are compromised. so i'm assuming the purpose is to prevent someone from discovering your password if all they have is the contents of your script.

P.S. if you compile your script to executable, that's the first barrier you can put against prying eyes. if those eyes belong to your over-the-average-curious end user, that should throw them off.

Of course when possible, I'd ask password in inputbox,... but for servers who runs script unattended,... it is a bit more complicated !
Of course, exe, is the first barrier, but I always save my au3 files obviously.

Will see the Windows Credential Manager

Posted

For a task to backup the config of some 70+ switches I wrote an autoit script, that doesn't hold the password, but it's SHA256 hash.

When the script is triggered, it's asking for the password and comparing the calculated SHA256 of the given password against the value stored inside the script.

As SHA256 cannot be decoded, you can proof, that the right password was entered, without storing the password in the code itself.

 

#include <AutoItConstants.au3>
; *** End added by AutoIt3Wrapper ***
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_Description=Alle Cisco Switches die Config sichern auf H:
#AutoIt3Wrapper_Res_Fileversion=2.3.0.15
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=p
#AutoIt3Wrapper_Res_LegalCopyright=2016 - 2024 (c) by Rudolf Stang, IT-Beratung Rudolf Stang
#AutoIt3Wrapper_Res_SaveSource=y
#AutoIt3Wrapper_Res_Language=1031
#AutoIt3Wrapper_Add_Constants=n
#AutoIt3Wrapper_Run_Au3Stripper=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <date.au3>
#include <Debug.au3>
#include <array.au3>
#include "Crypt-mit-SHA256.au3" ; originale CRYPT.AU3, lediglich oben das Auskommentieren für SHA_256 entfernt. Muss * NEBEN * diesem Scirpt liegen("")

; [snip]

$PW_hash= "0x1D3965422171<snip>" ; SHA_256

Do
    $PWD = InputBox("Running-Config's sichern", "Switch Kennwort für Root?", "", "*")
Until $PWD <> ""
_Crypt_Startup()
$Hash_Input = _Crypt_HashData($PWD, $CALG_SHA_256)
If $Hash_Input <> $PW_hash Then
    ClipPut($Hash_Input)
    MsgBox(64, "Falsches Kennwort", "Sie haben sich vermutlich beim Kennwort vertippt, der SHA256 Hash passt nicht!", 10)
    Exit
EndIf
_Crypt_Shutdown()
#EndRegion Kennwort

pls use deepl yourself to translate the German phrases to you preferred language.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Posted
42 minutes ago, rudi said:

For a task to backup the config of some 70+ switches I wrote an autoit script, that doesn't hold the password, but it's SHA256 hash.

When the script is triggered, it's asking for the password and comparing the calculated SHA256 of the given password against the value stored inside the script.

As SHA256 cannot be decoded, you can proof, that the right password was entered, without storing the password in the code itself.

 

#include <AutoItConstants.au3>
; *** End added by AutoIt3Wrapper ***
#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Res_Description=Alle Cisco Switches die Config sichern auf H:
#AutoIt3Wrapper_Res_Fileversion=2.3.0.15
#AutoIt3Wrapper_Res_Fileversion_AutoIncrement=p
#AutoIt3Wrapper_Res_LegalCopyright=2016 - 2024 (c) by Rudolf Stang, IT-Beratung Rudolf Stang
#AutoIt3Wrapper_Res_SaveSource=y
#AutoIt3Wrapper_Res_Language=1031
#AutoIt3Wrapper_Add_Constants=n
#AutoIt3Wrapper_Run_Au3Stripper=y
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****
#include <date.au3>
#include <Debug.au3>
#include <array.au3>
#include "Crypt-mit-SHA256.au3" ; originale CRYPT.AU3, lediglich oben das Auskommentieren für SHA_256 entfernt. Muss * NEBEN * diesem Scirpt liegen("")

; [snip]

$PW_hash= "0x1D3965422171<snip>" ; SHA_256

Do
    $PWD = InputBox("Running-Config's sichern", "Switch Kennwort für Root?", "", "*")
Until $PWD <> ""
_Crypt_Startup()
$Hash_Input = _Crypt_HashData($PWD, $CALG_SHA_256)
If $Hash_Input <> $PW_hash Then
    ClipPut($Hash_Input)
    MsgBox(64, "Falsches Kennwort", "Sie haben sich vermutlich beim Kennwort vertippt, der SHA256 Hash passt nicht!", 10)
    Exit
EndIf
_Crypt_Shutdown()
#EndRegion Kennwort

pls use deepl yourself to translate the German phrases to you preferred language.

thanks... it is good if you prompt with inputbox... but in my case it is silent running script... thus making somehow clear and encrypted

 

Posted

You can use the windows credential manager as a tool to hide (not to protect) your password.

https://sites.utexas.edu/glenmark/2019/10/21/using-passwordvault-with-powershell/

basically either your password is valuable: Then it has to be entered each and every time, it is used, and there is no way around the fact, that it must not be in your code.

Or your password is not that important. Then you can put it into your code, but you have to be aware, that it's not safe any more.

Earth is flat, pigs can fly, and Nuclear Power is SAFE!

Posted (edited)
6 hours ago, cramaboule said:

for servers who runs script unattended

Then why not use a hardware serial like baseboard serial so the program can only be run on that machine.

Edited by Werty

Some guy's script + some other guy's script = my script!

Posted (edited)

I have to use passwords in a lot of my scripts.

I have an SQL server where each script has it's own database where I store passwords as an encrypted string along with any other config/test/log data.  I also only allow specific users access to that database via AD.  The decryption keys are also unique to each script.

This lets me keep passwords secure and lets me control who can access my apps as if the database connection fails then the app closes with a message to contact me for access.

Edited by BigDaddyO

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...