<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Python tool for converting plain text to Type9 passwords in Other Security</title>
    <link>https://community.cisco.com/t5/other-security/python-tool-for-converting-plain-text-to-type9-passwords/m-p/4316886#M348</link>
    <description>&lt;P&gt;I'm not familiar enough with the cryptographic features of the Type 9 passwords and their use of scrypt to recognize what is incorrect about your implementation. However, I was able to find some other work along these lines done in Java which you may be able to use to identify the issue.&amp;nbsp; Here is videgro's&amp;nbsp;&lt;A href="https://github.com/videgro/cisco-password-hashes/blob/master/src/main/java/net/videgro/poc/cisco_pw_hashes/CiscoPasswordHashType09.java" target="_self"&gt;Github repo for the Java implementation&lt;/A&gt;&amp;nbsp;and associated &lt;A href="http://blog.videgro.net/2017/06/cisco-type-8-and-9-password-hashes-calculated-using-java" target="_self"&gt;blog&lt;/A&gt; which may help.&lt;/P&gt;</description>
    <pubDate>Wed, 31 Mar 2021 15:53:05 GMT</pubDate>
    <dc:creator>Brian Sak</dc:creator>
    <dc:date>2021-03-31T15:53:05Z</dc:date>
    <item>
      <title>Python tool for converting plain text to Type9 passwords</title>
      <link>https://community.cisco.com/t5/other-security/python-tool-for-converting-plain-text-to-type9-passwords/m-p/4316528#M347</link>
      <description>&lt;P&gt;Hi all,&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;I've attempted to create a tool that takes a plain text password and converts it in to a Type9 (scrypt) encrypted password. The idea is to be able to build full CLI configurations for IOS/IOS-XE without having to ship configs with plain text passwords, and also not have to find a switch or router lying around to generate the Type9 password.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;My current code is:&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;PRE&gt;from passlib.hash import scrypt
import sys

# Illegal Cisco IOS characters
invalid_chars = r"\~?|[]&amp;lt;&amp;gt;{}:;+=/\"\'"
# Translate the Base64 table to custom Cisco table
base64chars  = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
cisco64chars = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
transtable = str.maketrans(base64chars, cisco64chars)

def main():
    while True:
        try:
            pwd = input('\n' + 'Enter a Plain Text Password to Encrypt: ')
        except KeyboardInterrupt:
            sys.exit(0)
        else:
            # Maximum characters
            if len(pwd) &amp;gt; 64:
                print ('Password must be between 1 and 64 characters. Try again.')
                main()
            else:
                for char in pwd:
                    if char in invalid_chars:
                        print ('Illegal characters. Try again.')
                        main()         
                else:
                    # Encrypt using - 2^14 iterations, random salt of 14 chars (80 bits/10 bytes)
                    hash = str(scrypt.using(rounds=14, salt_size=10).hash(pwd))[22:]
                    # Make the Base64 translation
                    hash = hash.translate(transtable)
                    print ('\n Your Type 9 hash is: $9$' + hash)
                    sys.exit(0)&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When specifying the password 'abc123' the resulting hash is - $9$MUmVJ6dlPaphXE$y6mDuGoy.6i7lLBL9bhCOoGu/RryL3VaVL7am0uz/ko&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I copy and paste this on to a cisco switch with&lt;/P&gt;&lt;PRE&gt;username admin secret 9&amp;nbsp;$9$MUmVJ6dlPaphXE$y6mDuGoy.6i7lLBL9bhCOoGu/RryL3VaVL7am0uz/ko&lt;/PRE&gt;&lt;P&gt;The password of 'abc123' is incorrect.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I suspect it's something to do with the way I am handling the salt (do I base64 encode/decode the salt, am I supposed to encrypt the salt using scrypt at all), but I'm really not sure!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;If anyone has an ideas, or wants to help me figure this out offline, I will be forever grateful! I am at my wits end, with this one.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;-Brett&lt;/P&gt;</description>
      <pubDate>Wed, 31 Mar 2021 04:22:14 GMT</pubDate>
      <guid>https://community.cisco.com/t5/other-security/python-tool-for-converting-plain-text-to-type9-passwords/m-p/4316528#M347</guid>
      <dc:creator>Brett Verney</dc:creator>
      <dc:date>2021-03-31T04:22:14Z</dc:date>
    </item>
    <item>
      <title>Re: Python tool for converting plain text to Type9 passwords</title>
      <link>https://community.cisco.com/t5/other-security/python-tool-for-converting-plain-text-to-type9-passwords/m-p/4316886#M348</link>
      <description>&lt;P&gt;I'm not familiar enough with the cryptographic features of the Type 9 passwords and their use of scrypt to recognize what is incorrect about your implementation. However, I was able to find some other work along these lines done in Java which you may be able to use to identify the issue.&amp;nbsp; Here is videgro's&amp;nbsp;&lt;A href="https://github.com/videgro/cisco-password-hashes/blob/master/src/main/java/net/videgro/poc/cisco_pw_hashes/CiscoPasswordHashType09.java" target="_self"&gt;Github repo for the Java implementation&lt;/A&gt;&amp;nbsp;and associated &lt;A href="http://blog.videgro.net/2017/06/cisco-type-8-and-9-password-hashes-calculated-using-java" target="_self"&gt;blog&lt;/A&gt; which may help.&lt;/P&gt;</description>
      <pubDate>Wed, 31 Mar 2021 15:53:05 GMT</pubDate>
      <guid>https://community.cisco.com/t5/other-security/python-tool-for-converting-plain-text-to-type9-passwords/m-p/4316886#M348</guid>
      <dc:creator>Brian Sak</dc:creator>
      <dc:date>2021-03-31T15:53:05Z</dc:date>
    </item>
    <item>
      <title>Re: Python tool for converting plain text to Type9 passwords</title>
      <link>https://community.cisco.com/t5/other-security/python-tool-for-converting-plain-text-to-type9-passwords/m-p/4428299#M355</link>
      <description>&lt;P&gt;Brian,&lt;/P&gt;&lt;P&gt;With that Java implementation and a Perl implementation (as well as help from someone in the community) I was able to successfully come up with some code to make this work.&lt;/P&gt;&lt;P&gt;I have posted the code on github -&amp;nbsp;&lt;A href="https://github.com/wifiwizardofoz/ciscoPWDhasher" target="_blank"&gt;GitHub - wifiwizardofoz/ciscoPWDhasher: A Python Cisco IOS, IOS-XE and NX-OS password hashing tool&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;Thanks for taking the time to reply!&lt;/P&gt;&lt;P&gt;-Brett&lt;/P&gt;</description>
      <pubDate>Tue, 06 Jul 2021 00:55:55 GMT</pubDate>
      <guid>https://community.cisco.com/t5/other-security/python-tool-for-converting-plain-text-to-type9-passwords/m-p/4428299#M355</guid>
      <dc:creator>Brett Verney</dc:creator>
      <dc:date>2021-07-06T00:55:55Z</dc:date>
    </item>
  </channel>
</rss>

