Advertisement
Guest User

Untitled

a guest
May 14th, 2018
314
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.88 KB | None | 0 0
  1. #!/usr/bin/python
  2. """
  3. Simple tool to extract local users and passwords from most Huawei routers/firewalls config files.
  4. Will extract plain-text passwords and  crypted credentials. Huawei config files use DES encryption with
  5. a known key. Using this information, the script will decrypt credentials found in the config file.
  6. Author: Etienne Stalmans (etienne@sensepost.com)
  7. Version: 1.0 (12/01/2014)
  8. """
  9.  
  10. from Crypto.Cipher import DES
  11. import sys
  12. import binascii
  13.  
  14. def decode_char(c):
  15.     if c == 'a':
  16.         r = '?'
  17.     else:
  18.         r = c
  19.     return ord(r) - ord('!')
  20.  
  21. def ascii_to_binary(s):
  22.     assert len(s) == 24
  23.  
  24.     out = [0]*18
  25.     i = 0
  26.     j = 0
  27.  
  28.     for i in range(0, len(s), 4):
  29.         y = decode_char(s[i + 0])
  30.         y = (y << 6) & 0xffffff
  31.  
  32.         k = decode_char(s[i + 1])
  33.         y = (y | k) & 0xffffff
  34.         y = (y << 6) & 0xffffff
  35.  
  36.         k = decode_char(s[i + 2])
  37.         y = (y | k) & 0xffffff
  38.         y = (y << 6) & 0xffffff
  39.  
  40.         k = decode_char(s[i + 3])
  41.         y = (y | k) & 0xffffff
  42.  
  43.         out[j+2] = chr(y & 0xff)
  44.         out[j+1] = chr((y>>8) & 0xff)
  45.         out[j+0] = chr((y>>16) & 0xff)
  46.  
  47.         j += 3
  48.  
  49.     return "".join(out)
  50.  
  51. def decrypt_password(p):
  52.     r = ascii_to_binary(p)
  53.     r = r[:16]
  54.  
  55.     d = DES.new("\x01\x02\x03\x04\x05\x06\x07\x08", DES.MODE_ECB)
  56.     r = d.decrypt(r)
  57.  
  58.     return r.rstrip("\x00")
  59.  
  60.  
  61. f_in = open(sys.argv[1],'r')
  62.  
  63. print "[*] Huawei Password Decryptor"
  64.  
  65. for line in f_in:
  66.    
  67.     if ('local-user' not in line) or ('password' not in line):
  68.         continue
  69.    
  70.     inp = line.split()
  71.     print "[*]-----------------------"
  72.     print "\t[+] User: %s"%inp[1]
  73.     print "\t[+] Password type: %s"%inp[3]
  74.     if inp[3] == "cipher":
  75.         print "\t[+] Cipher: %s"%inp[4]
  76.         print "\t[+] Password: %s"%decrypt_password(inp[4])
  77.     else:
  78.         print "\t[+] Password: %s"%(inp[4])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement