Differences
This shows you the differences between two versions of the page.
guides:passwords_in_scripts [2023-01-07 23:07] – created geek | guides:passwords_in_scripts [2023-01-13 13:34] (current) – Populate from anonymous1184 geek | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Passwords in Scripts ====== | ====== Passwords in Scripts ====== | ||
- | This article | + | Let me start by saying... |
+ | |||
+ | **AutoHotkey is not a replacement for a password manager!!!** | ||
+ | |||
+ | At least not without investing time and effort into making a proper password manager out of AHK (and that is completely outside the scope of this post, plus there are already many **// | ||
+ | |||
+ | The next thing is to acknowledge pretty obvious points that everyone must be aware of: | ||
+ | |||
+ | * Everything can be broken. | ||
+ | * Nothing is ever 100% secure. | ||
+ | |||
+ | But, depending on what you do to protect your information, | ||
+ | |||
+ | Security and cryptography both are really vast and complex topics, if you're interested in them, there are countless communities better suited for that. Here I'm just gonging to demonstrate how to safely have available in AHK a **single[(It can be adapted to pretty much anything that needs to be secured, not just a single password.)] password[(Checkout [[user: | ||
+ | |||
+ | Last note before we dig in; if you start an argument with: **//" | ||
+ | |||
+ | ~~REFNOTES~~ | ||
+ | |||
+ | ===== AHK and your Master Password ===== | ||
+ | |||
+ | < | ||
+ | |||
+ | If you are already using a password manager and following the basic principle of having a strong/ | ||
+ | |||
+ | And AHK is about automation and typing for you, right? | ||
+ | |||
+ | I'll present here a secure flow similar to what has been my daily driver for a really long time. At least as secure as cryptography goes, you still have to account for human error and how vulnerable is your system/ | ||
+ | |||
+ | This is what **// | ||
+ | |||
+ | <code AutoHotkey> | ||
+ | ^!p:: ; ← NEVER | ||
+ | Send qwerty123 | ||
+ | return | ||
+ | </ | ||
+ | |||
+ | On top of having what is one of the [[https:// | ||
+ | |||
+ | AutoHotkey scripts are not protected in any way[(AHK_H allows for some simple protection with some extra work, but it's not very secure. [[user: | ||
+ | |||
+ | Here you have a better approach with the same result (is an oversimplification for demonstrative purposes): | ||
+ | |||
+ | <code AutoHotkey> | ||
+ | ^!p::Send % MasterPassword(A_MyDocuments " | ||
+ | |||
+ | MasterPassword(Path) { | ||
+ | static decrypted := "" | ||
+ | if (decrypted) | ||
+ | return decrypted | ||
+ | FileRead encrypted, % Path | ||
+ | loop 3 { | ||
+ | InputBox key, Encryption Key:,, Hide, 200, 100 | ||
+ | decrypted := Decrypt(encrypted, | ||
+ | return decrypted | ||
+ | } | ||
+ | MsgBox 0x40010, Error, Password couldn' | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | What the above does? | ||
+ | |||
+ | First, the password is not stored in the script but loaded from an encrypted file called '' | ||
+ | |||
+ | The result is as secure as the encryption method you used to encrypt your password. And yes, you can safely encrypt your master password with (drumroll)... [[https:// | ||
+ | |||
+ | ~~REFNOTES~~ | ||
+ | |||
+ | ===== Why is secure and how it works? ===== | ||
+ | |||
+ | Now, let's go over the worst-case scenario that will never happen: | ||
+ | |||
+ | * You use a laptop. | ||
+ | * Your laptop is stolen. | ||
+ | * Boot is not password protected. | ||
+ | * Storage is not encrypted. | ||
+ | * Windows account doesn' | ||
+ | * The robber is well-versed in AHK. | ||
+ | |||
+ | Now, the robber turns on the laptop and goes all the way to the desktop as there is nothing to stop him... then sees that AutoHotkey is installed and that a script is loaded on startup; proceeds to meticulously examine the script and sees that there' | ||
+ | |||
+ | You are in serious problems. But for that insecure system, and **//NOT//** because you have your master password accessible to the script. In any case, if you have the password encrypted, unless the robber knows the decryption key he won't be able to get the password. | ||
+ | |||
+ | Let's tackle the next possible argument: //What if the password is already unencrypted?// | ||
+ | |||
+ | But even accounting for that unrealistic scenario, you can adjust how much time and under which conditions the password is kept in memory with any combination of the following: | ||
+ | |||
+ | * Manual removal: whenever you feel like it. | ||
+ | * Computer sleep: when putting the computer to sleep (commute? | ||
+ | * Windows Lock Screen: built-in OS locking mechanism (coffee break?). | ||
+ | * Lid close: if either the computer locks or not (docking station). | ||
+ | * Inactivity period: not having physical contact with the PC. | ||
+ | |||
+ | So, there you have it; you can actually have your master password accessible to AHK without posing an unnecessary risk. | ||
+ | |||
+ | ---- | ||
+ | |||
+ | I'm not gonna add the code/ | ||
+ | |||
+ | I use the password itself as the decryption key to simplify the example, but the data to be encrypted, and the key can be different and of course, it doesn' | ||
+ | |||
+ | Skip the next section if you know what key derivation is, how it works and how it helps to making brute force attacks harder to success. | ||
+ | |||
+ | ===== Key derivation ===== | ||
+ | |||
+ | If you don't know what key derivation is and how it can help: is a technique used to slow down brute force and dictionary attacks | ||
+ | |||
+ | Example: | ||
+ | |||
+ | You have data protected with a 4-digit PIN (please don' | ||
+ | |||
+ | Say a key derivation process consisting of **500,000** iterations is used, and it adds a second per attempt. Meaning that instead of cracking the PIN in under one second, it will take up to **2 hours, 46 minutes and 38 seconds**: one second for each attempt (if the PIN is actually '' | ||
+ | |||
+ | That's why you're encouraged to use long passwords and a big alphabet (//ie//, lower/upper case with numbers and symbols). The result is that casually trying to decrypt data is not worth the time, effort, and cost (CPU processing is costly). Hence, this is perfectly suited and more than adequate for most people (nuclear launch codes protection not included). | ||
+ | |||
+ | ===== Full working example ===== | ||
+ | |||
+ | The files in [[https:// | ||
+ | |||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | For the key derivation, a dynamic salt of the same length of the password is generated. It is also estimated how many derivations can be made in a second, that calculation is then used. | ||
+ | |||
+ | ===== Some basic security tips ===== | ||
+ | |||
+ | This is not the place to look for security advice, but is relevant to the topic. Also, these tips can be expanded indefinitely and in so many cases are not enough (or too much)... please take them as intended: a reminder that boosting the security of your system doesn' | ||
+ | |||
+ | * BIOS password protection: this is the first line to keep privy eyes from your system (if your household has them). | ||
+ | * Encrypt your storage: Windows has options to do so (EFS/ | ||
+ | * Password-protect the Windows account: doesn' | ||
+ | * Physical and software Firewalls: VPNs are mostly snake oil, properly configured firewalls can be more effective than other networking security solutions. Virtually every modem/ | ||
+ | * Kensington locks: if your computer can be snatched, why not? Nice when you move around a lot, totally worth it given how cheap they are. | ||
+ | |||
+ | The most beneficial might be storage encryption. With how powerful and fast consumer hardware is nowadays, transparent/ | ||
+ | |||
+ | ===== Closing note ===== | ||
+ | |||
+ | Are you **// | ||
+ | |||
+ | If you use only upper/ | ||
+ | |||
+ | < | ||
+ | 106, | ||
+ | </ | ||
+ | |||
+ | Meaning a brute force attack needs to go over those, if key derivation is used, well... is just nuts. | ||
+ | |||
+ | But there' |