{"id":12291,"date":"2015-08-22T15:12:21","date_gmt":"2015-08-22T15:12:21","guid":{"rendered":"https:\/\/www.bartbusschots.ie\/s\/?p=12291"},"modified":"2016-02-24T20:35:53","modified_gmt":"2016-02-24T20:35:53","slug":"using-the-hsxkpasswd-terminal-command-part-1-of-2","status":"publish","type":"post","link":"https:\/\/www.bartbusschots.ie\/s\/2015\/08\/22\/using-the-hsxkpasswd-terminal-command-part-1-of-2\/","title":{"rendered":"Using the <code>hsxkpasswd<\/code> Terminal Command (Part 1 of 2)"},"content":{"rendered":"<p>Since version 3.5, the <code>Crypt::HSXKPasswd<\/code> password generating perl module ships with a command line interface to the password generator called <code>hsxkpasswd<\/code>. This provides a way for non-Perl programers to access the vast majority of the module&#8217;s functionality.<\/p>\n<p>The easiest way to install the module, and it&#8217;s accompanying terminal command is via CPAN:<\/p>\n<pre class=\"crayon:false\">\r\nsudo cpan Crypt::HSXKPasswd\r\n<\/pre>\n<p>Once the module is installed, you&#8217;ll have access to the <code>hsxkpasswd<\/code> terminal command.<\/p>\n<p>Getting started is simple, run the command with no arguments at all and it will generate one password using the default settings:<\/p>\n<pre class=\"crayon:false\">\r\nbart-iMac2013:~ bart$ <strong>hsxkpasswd<\/strong>\r\n@@26.MEASURE.below.LIFT.95@@\r\nbart-iMac2013:~ bart$\r\n<\/pre>\n<p>If you want more passwords, pass a number as an argument, and you&#8217;ll get that many passwords:<\/p>\n<pre class=\"crayon:false\">\r\nbart-iMac2013:~ bart$ <strong>hsxkpasswd 10<\/strong>\r\n~~08!hole!VOWEL!then!45~~\r\n$$49^monday^YELLOW^remember^22$$\r\n\/\/69-express-MONDAY-edge-54\/\/\r\n--42~KITCHEN~save~COLD~40--\r\n==51%REPLY%even%AUGUST%28==\r\n%%63&list&INSIDE&train&58%%\r\n^^19!spain!CONGO!spain!01^^\r\n::30@SMILED@from@PERIOD@90::\r\n&&05%decimal%THREE%remember%80&&\r\n..47^ROAD^dress^BERLIN^11..\r\nbart-iMac2013:~ bart$\r\n<\/pre>\n<p><!--more--><\/p>\n<h2>Using Built-in Presets<\/h2>\n<p>The module, and hence the terminal command, ships with a number of pre-defined presets. To see a list of all available presets, use the <code>-l<\/code> (or <code>--list-presets<\/code>) flag:<\/p>\n<pre class=\"crayon:false\">\r\nbart-iMac2013:~ bart$ <strong>hsxkpasswd -l<\/strong>\r\nAPPLEID, DEFAULT, NTLM, SECURITYQ, WEB16, WEB32, WIFI, XKCD\r\nbart-iMac2013:~ bart$ \r\n<\/pre>\n<p>To use a preset, use the <code>-p<\/code> (or <code>--preset<\/code>) flag:<\/p>\n<pre class=\"crayon:false\">\r\nbart-iMac2013:~ bart$ <strong>hsxkpasswd -p SECURITYQ<\/strong>\r\nangry call fast soldier Monday Delaware?\r\nbart-iMac2013:~ bart$ \r\n<\/pre>\n<p>You can of course still generate as many passwords at once as you like:<\/p>\n<pre class=\"crayon:false\">\r\nbart-iMac2013:~ bart$ <strong>hsxkpasswd -p SECURITYQ 10<\/strong>\r\nsuddenly rich game desire Tuesday seeds.\r\npractice mile colour practice roll always.\r\npark resent offer signal even simple.\r\nlower dish room sent tomorrow mind?\r\nstory drawing strange spell Fiji burn.\r\nthink shall complete march afraid sight!\r\nsuffix finally surface again seem angle.\r\nkitchen later division dinner park killed?\r\nover period dollar hunger kept slowly?\r\nfellow Panama building what worn because.\r\nbart-iMac2013:~ bart$\r\n<\/pre>\n<p>It is also possible to tweak an existing preset by overriding the values in specific configuration keys. The first step to doing this is to peek under the hood and look at the settings specified by the preset you want to tweak, you can do that with the <code>--verbose<\/code> flag (I&#8217;ve marked the relevant section of the verbose output in bold):<\/p>\n<pre class=\"crayon:false\">\r\nbart-iMac2013:~ bart$ <strong>hsxkpasswd --verbose -p SECURITYQ<\/strong>\r\n*NOTE* no hsxkpasswdrc file loaded\r\n*NOTE* no custom entropy warning level set\r\n*NOTE* using standard preset 'SECURITYQ'\r\n*NOTE* using default word source\r\n*NOTE* using default rng\r\n\r\n*DICTIONARY*\r\nSource: Crypt::HSXKPasswd::Dictionary::EN\r\n# words: 1259\r\n# words of valid length: 1194 (95%)\r\nContains Accented Characters: NO\r\n\r\n<strong>*CONFIG*\r\nallow_accents: '0'\r\ncase_transform: 'NONE'\r\nnum_words: '6'\r\npadding_alphabet: ['!', '.', '?']\r\npadding_character: 'RANDOM'\r\npadding_characters_after: '1'\r\npadding_characters_before: '0'\r\npadding_digits_after: '0'\r\npadding_digits_before: '0'\r\npadding_type: 'FIXED'\r\nseparator_character: ' '\r\nword_length_max: '8'\r\nword_length_min: '4'<\/strong>\r\n\r\n*RANDOM NUMBER CACHE*\r\nRandom Number Generator: Crypt::HSXKPasswd::RNG::Math_Random_Secure\r\n# in cache: 0\r\n\r\n*PASSWORD STATISTICS*\r\nPassword length: between 30 & 54\r\nPermutations (brute-force): between 1.33x10^53 & 4.22x10^95 (average 2.37x10^74)\r\nPermutations (given dictionary & config): 8.69x10^18\r\nEntropy (Brute-Force): between 176bits and 317bits (average 247bits)\r\nEntropy (given dictionary & config): 62bits\r\n# Random Numbers needed per-password: 7\r\nPasswords Generated: 0\r\n\r\nspring might opposite poem London soil?\r\nbart-iMac2013:~ bart$\r\n<\/pre>\n<p>Let&#8217;s say we don&#8217;t like having question marks at the end of the generated security question answers, and lets say we want to alternate the case of each word, but leave the rest of the preset the same. We can do this with the <code>-o<\/code> (or <code>--overrides<\/code>) flag. This flag expects the value to be a JSON string representing configuration key name-value pairs (<a href=\"https:\/\/www.bartbusschots.ie\/s\/2015\/08\/08\/json-a-quick-intro\/\" target=\"_blank\">for help with JSON see this quick intro<\/a>). The command below makes our desired changes:<\/p>\n<pre class=\"crayon:false\">\r\nbart-iMac2013:~ bart$ <strong>hsxkpasswd -p SECURITYQ -o '{\"padding_alphabet\" : [\".\", \"!\"], \"case_transform\" : \"ALTERNATE\"}' 10<\/strong>\r\nSEEDS rain BRIGHT plan SOME receive.\r\nhappy HUNTING stop SHIP mine AFRAID!\r\nGOVERN sand SAIL into FRONT school.\r\ndish BETWEEN there SETTLE result AWAY!\r\nstory MEMBER british MISTER trust FIJI!\r\nSHOUT agree SINGLE halt INCLUDE spend.\r\nSTRENGTH english STREET than TEST laugh.\r\nlater BRITAIN turn EVEN nearly MEMBER!\r\nhowever NEVADA cuba RETURN happen WING.\r\nBRAZIL none TOWARD neptune BELL forever.\r\nbart-iMac2013:~ bart$ \r\n<\/pre>\n<h2>Creating Custom Presets<\/h2>\n<p>While tweaking existing presets might be a good approach much of the time, you may find yourself wanting to create a custom configuration that looks absolutely nothing like any of the presets. You can do this by creating a text file that represents your chosen settings in JSON format, and then passing the path to that file to <code>hsxkpasswd<\/code> using the <code>-c<\/code> (or <code>--config-file<\/code>) flag.<\/p>\n<blockquote>\n<h4>Suggestion<\/h4>\n<p>You can use the load\/save tab in the web interface at https:\/\/www.xkpasswd.net\/ to generate your config, then copy and paste it into a text file. The output from that web form is in JSON format. The only small caveat is that to avoid warnings, you should delete the line <code>\"random_increment\": \"AUTO\" <\/code> (and the trailing comma on the line above) from the file.<\/p>\n<\/blockquote>\n<p>As an example, I am going to save the following JSON markup to the file <code>~\/Documents\/Temp\/sampleconfig.json.txt<\/code>:<\/p>\n<pre class=\"crayon:false\">\r\n{\r\n \"num_words\": 4,\r\n \"word_length_min\": 4,\r\n \"word_length_max\": 8,\r\n \"case_transform\": \"ALTERNATE\",\r\n \"separator_character\": \"RANDOM\",\r\n \"separator_alphabet\": [\r\n  \"-\",\r\n  \":\",\r\n  \".\",\r\n  \",\"\r\n ],\r\n \"padding_digits_before\": 2,\r\n \"padding_digits_after\": 2,\r\n \"padding_type\": \"FIXED\",\r\n \"padding_character\": \"RANDOM\",\r\n \"symbol_alphabet\": [\r\n  \"!\",\r\n  \"?\",\r\n  \"@\",\r\n  \"&\"\r\n ],\r\n \"padding_characters_before\": 1,\r\n \"padding_characters_after\": 1\r\n}\r\n<\/pre>\n<p>Once that file is saved, I can use my custom created config:<\/p>\n<pre class=\"crayon:false\">\r\nbart-iMac2013:~ bart$ <strong>hsxkpasswd -c ~\/Documents\/Temp\/sampleconfig.json.txt 10<\/strong>\r\n?33-europe-CONTROL-wedge-PLANE-25?\r\n!31.power.DESIRE.know.MUST.81!\r\n@79:FOUR:lord:THOUSAND:light:21@\r\n?79,head,CHANCE,shake,COLUMN,28?\r\n?08:germany:SURPRISE:friends:FELT:08?\r\n&26:pull:TELL:steel:PARK:18&\r\n?56.GRAY.north.VERB.stood.13?\r\n@38-gone-VARIOUS-right-REASON-07@\r\n&85:BESIDE:probable:REALLY:inches:51&\r\n?46.DOUBT.daily.MADRID.bridge.28?\r\nbart-iMac2013:~ bart$\r\n<\/pre>\n<h2>Specifying Word Sources<\/h2>\n<p>There are two flags that can be used to specify the word list the terminal command should use, <code>-d<\/code> (or <code>--dict-file<\/code>), and <code>--dict-pkg<\/code> (perhaps accompanied by <code>--dict-pkg-args<\/code>).<\/p>\n<p>The first flag allows users to specify the path to a dictionary file (more on this later), and the second flag allows the user to specify the name of a Perl module which will serve as the word source. The module ships with a number of standard dictionary module, and programmers can create their own custom modules by extending the class <code>Crypt::HSXKPasswd::Dictionary<\/code>. Since this is a tutorial for terminal users rather than perl programmers, we won&#8217;t discuss the ins and outs of creating your own package. I&#8217;ll simply list the included dictionary modules of interest to terminal users:<\/p>\n<ul>\n<li><code>Crypt::HSXKPasswd::Dictionary::DE<\/code> (German words)<\/li>\n<li><code>Crypt::HSXKPasswd::Dictionary::EN<\/code> (English words &#8211; the default word source)<\/li>\n<li><code>Crypt::HSXKPasswd::Dictionary::ES<\/code> (Spanish words)<\/li>\n<li><code>Crypt::HSXKPasswd::Dictionary::FR<\/code> (French words)<\/li>\n<li><code>Crypt::HSXKPasswd::Dictionary::IT<\/code> (Italian words)<\/li>\n<li><code>Crypt::HSXKPasswd::Dictionary::NL<\/code> (Dutch\/Flemish words)<\/li>\n<li><code>Crypt::HSXKPasswd::Dictionary::PT<\/code> (Portuguese words)<\/li>\n<\/ul>\n<p>It should be noted that with the exception of the English dictionary, all the rest should be considered beta &#8211; they are currently VERY big, so they contain words that are not very common, and, they are slow to use because of their size. I&#8217;m looking for volunteers who speak these languages to help trim these dictionaries down to size by removing the uncommon words.<\/p>\n<p>With all that said, the Dutch\/Flemish dictionary can be used as follows:<\/p>\n<pre class=\"crayon:false\">\r\nbart-iMac2013:~ bart$ <strong>hsxkpasswd --dict-pkg=Crypt::HSXKPasswd::Dictionary::NL 10<\/strong>\r\n~~98;BAAS;wrangst;BANIER;03~~\r\n::39=knalgele=NAAMPJES=gemauwd=98::\r\n@@82=GEBROKEN=tarreert=KWIJLT=97@@\r\n..36*SCHOT*omwille*EERLOZE*51..\r\n__83*STAMELT*bomde*ZIELIGE*61__\r\n!!14!AFROMERS!stroopt!KINNETJE!71!!\r\n^^24?AFSLEURT?oorijzer?BAROK?57^^\r\n::75=KRUISERS=dunne=REVIERT=61::\r\n;;77~GEGRAAND~baxter~BELICHT~25;;\r\n__20\/RECEPT\/armelui\/VERSMOLT\/79__\r\nbart-iMac2013:~ bart$\r\n<\/pre>\n<p>Everyone has their own areas on interest, so you may want to create their own word lists containing words that you will find memorable. For example, Harry Potter fans might like to have words like <em>Expelliarmus<\/em> in their word list.<\/p>\n<p>By far the simplest way to create your own custom word list is to create a dictionary file. The format is very simple &#8211; dictionary files must be text files with one word per line. This is the same format as the standard Unix\/Linux words file.<\/p>\n<p>As an example, the following command uses the standard Unix words file:<\/p>\n<pre class=\"crayon:false\">\r\nbart-iMac2013:~ bart$ <strong>hsxkpasswd -d \/usr\/share\/dict\/words 10<\/strong>\r\n;;18_EXEUNT_unsocial_TOUCHPAN_04;;\r\n&&26&koppen&DINK&tinner&63&&\r\n~~61\/SCRAPPLE\/magadhi\/PENTIT\/45~~\r\n%%05$assurge$ICELAND$wrappage$11%%\r\n~~92-SOFTNESS-ethylene-MUSHER-74~~\r\n%%18~SLIM~killer~GERONTIC~92%%\r\n??07%TIRIBA%inertion%HAVENFUL%25??\r\n$$47%upflung%UNPUT%petioled%67$$\r\n**55\/fastness\/COGENCY\/bartlett\/81**\r\n&&64|CESTODE|spanghew|HOGGERY|23&&\r\nbart-iMac2013:~ bart$\r\n<\/pre>\n<h2>More Information<\/h2>\n<p>The terminal command can do much more than just what is described in this post. The command&#8217;s detailed documentation can be accessed in two different ways, via the <code>-h<\/code> (or <code>--help<\/code>) flag, or via the <code>man<\/code> command:<\/p>\n<pre class=\"crayon:false\">\r\nhsxkpasswd -h\r\nman hsxkpasswd\r\n<\/pre>\n<p>In the second part of this tutorial we will look at <code>.hsxkpasswdrc<\/code> files &#8211; these can be used to specify your own defaults for the terminal command, so you can avoid having to use flags all the time, and they can also be used to specify your own custom presets, again, saving you the need to specify overrides or point to JSON files each time you want to use custom settings.<\/p>\n<p><a href=\"https:\/\/www.bartbusschots.ie\/s\/2015\/09\/06\/using-the-hsxkpasswd-terminal-command-part-2-of-2\/\">Click here for Part 2<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Since version 3.5, the Crypt::HSXKPasswd password generating perl module ships with a command line interface to the password generator called hsxkpasswd. This provides a way for non-Perl programers to access the vast majority of the module&#8217;s functionality. The easiest way to install the module, and it&#8217;s accompanying terminal command is via CPAN: sudo cpan Crypt::HSXKPasswd [&hellip;]<\/p>\n","protected":false},"author":3,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[12,440,17,446],"tags":[406,410,458],"series":[],"class_list":["post-12291","post","type-post","status-publish","format-standard","hentry","category-computers-tech","category-tech-projects","category-security","category-sysadmin","tag-commandline","tag-hsxkpasswd","tag-tutorial"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/p7t9xK-3cf","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.bartbusschots.ie\/s\/wp-json\/wp\/v2\/posts\/12291","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.bartbusschots.ie\/s\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.bartbusschots.ie\/s\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.bartbusschots.ie\/s\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.bartbusschots.ie\/s\/wp-json\/wp\/v2\/comments?post=12291"}],"version-history":[{"count":7,"href":"https:\/\/www.bartbusschots.ie\/s\/wp-json\/wp\/v2\/posts\/12291\/revisions"}],"predecessor-version":[{"id":13733,"href":"https:\/\/www.bartbusschots.ie\/s\/wp-json\/wp\/v2\/posts\/12291\/revisions\/13733"}],"wp:attachment":[{"href":"https:\/\/www.bartbusschots.ie\/s\/wp-json\/wp\/v2\/media?parent=12291"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.bartbusschots.ie\/s\/wp-json\/wp\/v2\/categories?post=12291"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.bartbusschots.ie\/s\/wp-json\/wp\/v2\/tags?post=12291"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/www.bartbusschots.ie\/s\/wp-json\/wp\/v2\/series?post=12291"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}