找回SecureCRT密码

本文介绍了如何从SecureCRT中找回并转移服务器密码到Xshell。详细讲述了密码在Windows上的保存位置,并提供了一个Python脚本SecureCRTDecrypt.py用于解密密码,依赖包为pycrypto。

前言

因为S公司历史原因,几百台服务器的密码保存SecureCRT上,但是这个软件实在太难用了,所以提取其中的原始账号密码,转移到Xshell上

密码保存位置

Windows 在 “用户名\AppData\Roaming\VanDyke\Config\Sessions\”中,每个机器名对应一个ini文件
Tested with version 7.2.6 (build 606) for Windows,其他版本未加测试
(位置可能会有修改)

使用

先看后面的安装,Python脚本保存为SecureCRTDecrypt.py
用法
python SecureCRTDecrypt.py [filename...]
例子

[@bx_5_219 /tmp]# python SecureCRTDecrypt.py 10.10.123.123.ini   
10.10.123.123.ini
ssh root@10.10.70.30 # I'mpassword

依赖包

安装解密依赖包pycrypto
下载

https://pypi.python.org/pypi/pycrypto
wget https://pypi.python.org/packages/source/p/pycrypto/pycrypto-2.6.1.tar.gz

解压安装

tar -zxvf pycrypto-2.6.1.tar.gz
cd pycrtyto-2.6.1
python setup.py build
python setup.py install

密文解密程序

保存为SecureCRTDecrypt.py

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))

参考

[1] 如何找回SecureCRT密码
[2] GitHub上gitPoc32的项目

评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值