ganymed-ssh2-远程连接验证

Your account has expired; please contact your system administrator.

在这里插入图片描述
需求是批量验证密码是否过期,密码是否错误,正常不做处理。分别在零点和前台点击触发定时任务(5分钟后)的形式进行效验。(需要检测的就是上面图片中的内容)
这次的需求只需要验证密码,不需要远程执行。结果测试发现密码验证居然拿不到linux返回的验证错误信息。返回的内容一直都是Password authentication failed.
仅凭这个报错是无法判断该主机用户的密码是否已经过期的。断点追踪源码的时候看到AuthenticationManager内部的banner保存了返回结果,高兴的手舞足蹈。但随即发现这个类在Connection中没有提供访问的入口,正常的访问根本无法触碰到am这个属性。
然后各种操作,发现Connection类不是final修饰的,尝试重写…越重写越多…
最后简单的利用几个核心类成功获取到密码失效后的返回结果~

@Test
public void bingo() throws IOException {
    SecureRandom generator = null;
    if (generator == null) {
        generator = new SecureRandom();
    }
    String hostname = "192.168.0.104";
    String username = "z";
    String password = "z";
    String softwareversion = String.format("Ganymed_%s", Version.getSpecification());
    ClientTransportManager tm = new ClientTransportManager();
    tm.setSoTimeout(0);
    tm.setTcpNoDelay(false);
    tm.setConnectionMonitors(new ArrayList<>());
    tm.connect(hostname, 22, softwareversion, new CryptoWishList(), null,
            new DHGexParameters(), 0, generator);
    AuthenticationManager am = new AuthenticationManager(tm);
    try {
        boolean b = am.authenticatePassword(username, password);
        log.info("{}", b);
    } catch (Exception e)
    {
        log.info(am.getBanner());
    } finally {
            if (tm != null)
            {
                Throwable t = new Throwable("shutdown failed.");
                tm.close(t, true);
            }
    }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值