使用python解密SecureCRT上保存的密码

简介: 使用python解密SecureCRT上保存的密码

一、系统环境

系统:CentOS Linux release 7.5.1804 (Core) 

系统本身自带:python-2.7.5-69.el7_5.x86_64

另外安装:python2-crypto-2.6.1-15.el7.x86_64

yum install pycrypto


二、用法:

python Decrypt.py [filename...] 


1、使用vi编辑器创建Decrypt.py文件,写入源代码。

2、其中[filename...] 指的是ini文件,位于%APPDATA%\VanDyke\Config\Sessions\sessionname.ini

3、执行命令,即可查看到主机IP、账户、密码信息。


源代码:


from Crypto.Cipher import Blowfish
import argparse
import re

def decrypt(password) :
    c1 = Blowfish.new('5F B0 45 A2 94 17 D9 16 C6 C6 A2 FF 06 41 82 B7'.replace(' ','').decode('hex'), Blowfish.MODE_CBC, '\x00'*8)
    c2 = Blowfish.new('24 A6 3D DE 5B D3 B3 82 9C 7E 06 F4 08 16 AA 07'.replace(' ','').decode('hex'), Blowfish.MODE_CBC, '\x00'*8)
    padded = c1.decrypt(c2.decrypt(password.decode('hex'))[4:-4])
    p = ''
    while padded[:2] != '\x00\x00' :
        p += padded[:2]
        padded = padded[2:]
    return p.decode('UTF-16')

REGEX_HOSTNAME = re.compile(ur'S:"Hostname"=([^\r\n]*)')
REGEX_PASWORD = re.compile(ur'S:"Password"=u([0-9a-f]+)')
REGEX_PORT = re.compile(ur'D:"\[SSH2\] Port"=([0-9a-f]{8})')
REGEX_USERNAME = re.compile(ur'S:"Username"=([^\r\n]*)')

def hostname(x) :
    m = REGEX_HOSTNAME.search(x)
    if m :
        return m.group(1)
    return '???'

def password(x) :
    m = REGEX_PASWORD.search(x)
    if m :
        return decrypt(m.group(1))
    return '???'

def port(x) :
    m = REGEX_PORT.search(x)
    if m :
        return '-p %d '%(int(m.group(1), 16))
    return ''

def username(x) :
    m = REGEX_USERNAME.search(x)
    if m :
        return m.group(1) + '@'
    return ''

parser = argparse.ArgumentParser(description='Tool to decrypt SSHv2 passwords in VanDyke Secure CRT session files')
parser.add_argument('files', type=argparse.FileType('r'), nargs='+',
    help='session file(s)')

args = parser.parse_args()

for f in args.files :
    c = f.read().replace('\x00', '')
    print f.name
    print "ssh %s%s%s # %s"%(port(c), username(c), hostname(c), password(c))


代码来源: GitHub上gitPoc32的项目

目录
相关文章
|
17天前
|
数据安全/隐私保护 Python
1178: 密码翻译(python)
1178: 密码翻译(python)
|
3月前
|
存储 算法 安全
Python 密码破解指南:20~24
Python 密码破解指南:20~24
108 0
|
3月前
|
存储 Shell 数据安全/隐私保护
Python 密码破解指南:15~19
Python 密码破解指南:15~19
160 0
|
3月前
|
存储 Shell 数据安全/隐私保护
Python 密码破解指南:10~14
Python 密码破解指南:10~14
148 0
|
3月前
|
存储 Shell 数据安全/隐私保护
Python 密码破解指南:5~9
Python 密码破解指南:5~9
101 0
|
3月前
|
存储 Shell 数据安全/隐私保护
Python 密码破解指南:0~4
Python 密码破解指南:0~4
134 0
Python 密码破解指南:0~4
|
17天前
|
安全 数据安全/隐私保护 Python
292: 程序设计C 实验五 题目三 设计密码(python)
292: 程序设计C 实验五 题目三 设计密码(python)
|
1月前
|
存储 安全 算法
Python如何在打印日志时隐藏明文密码?
Python如何在打印日志时隐藏明文密码?
34 0
|
3月前
|
算法 Java Unix
python暴力破解压缩包密码(python暴力破解zip压缩包)
python暴力破解压缩包密码(python暴力破解zip压缩包)
66 0

热门文章

最新文章