Jump to content

KPScript UDF (KeePass automation)


Recommended Posts

This UDF automates KeePass databases through the use of KPScript, a plugin for KeePass that is developed by the original author.

This is something I've wanted for a long time. I really like KeePass and I really like using AutoIt, but I feel uncomfortable typing clear text passwords into my scripts. I can only get away with using Send("^!a") to try to get KeePass to input my passwords for me for so long.

To download the UDF, head over to GitHub for now (this is easier for me to manage). When I get a release version, I'll update this post with more info and a link to download from the forums.

Be sure to read the Notes section, and let me know of any issues, features, or praise you might have! ;)

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager

Link to post
Share on other sites

Been a while (2016) since I've used KeePass.  my Co banned it and forced us to move to a web tool that InfoSec can control.

 

This is what i used with a standalone Keepass database stored on a network share that was setup for Windows Authentication so I didn't need credentials to log into KeePass as long as I was logged into the computer doing the automation.  Your version looks MUCH more detailed than the quick grab code I had.

;=========================================================================================================================
;   Access data from Keepass where the login credentials are set for Windows Authentication
;       sAppUserName = GetKpCredential(@UserName, "Portal", "UserName")
;       sAppPassword = GetKpCredential(@UserName, "Portal", "Password")
;=========================================================================================================================
Func _GetKpCredential($kpDatabase, $kpEntryName, $kpFieldName)

    $sKPLoc = "\\..\Path\"

    Local $iPID = Run('"' & $sKPLoc & 'KPScript.exe" -c:GetEntryString "' & $sKPLoc & $kpDatabase & '.kdbx" -useraccount -field:' & $kpFieldName & ' -ref-Title:"' & $kpEntryName & '"', "", @SW_HIDE, 2)

    ProcessWaitClose($iPID)                                             ;Need to wait for it to finish before we get the StdOutput values
    $sOutput = StdoutRead($iPID)                                        ;Retrieve whatever the KPScript.exe returned
    $sRetVal = StringLeft($sOutput, StringInStr($sOutput, @CRLF) - 1)   ;Split out the returned value to get the value or see if it failed
    If StringLeft($sRetVal, 3) = "OK:" Then
        Return SetError(1)
    Else
        Return $sRetVal
    EndIf

EndFunc ;_GetKpCredential

 

Link to post
Share on other sites

My company doesn't "recommend" it, but the IT security guys recommended it when I brought it up. :)

Yup, I'm working on getting all of the functionality of KPScript into it, then I'll probably create a wrapper function or two doing pretty much exactly that ^. I just need to write all of the base functions first or else I'll never get back to it :D

All my code provided is Public Domain... but it may not work. ;) Use it, change it, break it, whatever you want.

Spoiler

My Humble Contributions:
Personal Function Documentation - A personal HelpFile for your functions
Acro.au3 UDF - Automating Acrobat Pro
ToDo Finder - Find #ToDo: lines in your scripts
UI-SimpleWrappers UDF - Use UI Automation more Simply-er
KeePass UDF - Automate KeePass, a password manager

Link to post
Share on other sites

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...