optparser模块 与 ZIP爆破(Python)
optparser模块:
为脚本传递命令参数。
初始化:
- 带 Usage 选项(-h 的显示内容 Usage:):
>>> from optparse import OptionParser
>>> usage = "usage %prog -f <zipfile> -d <dictionary>" # %prog为Py文件名
>>> parser=OptionParser(usage) #这里为类添加了参数usage
>>> parser.print_help()
Usage: usage -f <zipfile> -d <dictionary> Options:
-h, --help show this help message and exit
- 不带 Usage 选项:
>>> parser = OptionParser()
添加选项:
add_option:()
- action: 验证输入数据类型是否和type 匹配,并将符合要求的这个参数存储到dest变量中。有以下几个属性:
store 默认值。
store_false 标记 配合下边的那个store_true来进行代码的“标记”,辅助流程控制。
store_true 标记。
- type : 参数数据类型,如-f,-d等的接下来的那个参数的数据类型,有string,int,float等等。
- dest : 保存临时变量,其值可以作为 options 的属性进行访问。存储的内容就是如-f,-d 等紧挨着的那个参数内容。
- default : 给dest的默认值。
- help: 提供用户友好的帮助信息,解释add_option方法的功能。
>>>parser.add_option('-f', '--file', dest='zname', type='string', help='zip file name')
>>>parser.add_option('-d', '--dictionary', dest='dname', type='string', help=' password dictionary')
ZIP爆破脚本:
# -*- coding: utf-8 -*-
import zipfile
import optparse
from threading import Thread def extractFile(zFile, password): #extractFile()函数 寻找与ZIP文件匹配的密码
try:
zFile.extractall(pwd = password)
print '[+] Found password ' + password + '\n'
except:
pass def main():
parser = optparse.OptionParser("usage %prog "+ "-f <zipfile> -d <dictionary>")
parser.add_option('-f', '--file', dest='zname', type='string', help='The zip file which you want to crack')
parser.add_option('-d', '--dictionary', dest='dname', type='string', help='The password dictionary')
(options, args) = parser.parse_args() #调用 parse_args() 来解析程序的命令行
if (options.zname == None) | (options.dname == None):
print parser.usage
exit(0)
else:
zname = options.zname
dname = options.dname zFile = zipfile.ZipFile(zname)
passFile = open(dname) for line in passFile.readlines(): #读取字典文件
password = line.strip('\n')
t = Thread(target = extractFile, args =(zFile, password)) #使用线程
t.start() if __name__ == '__main__':
main()
optparser模块 与 ZIP爆破(Python)的更多相关文章
- .zip爆破
.zip爆破 Python的优化问题 Python在计算密集型任务方面没有明显的多线程优化,多线程更加适合用于处理I/O密集型任务(如网络请求).爆破任务使用顺序执行即可. 编写Python脚本 一个 ...
- Kemaswill 机器学习 数据挖掘 推荐系统 Python optparser模块简介
Python optparser模块简介
- optparser 模块 提取IP,端口,用户名,密码参数模板
import optparse #class FtpClient(object): #自定义类可以自己修改 '''ftp客户端''' #def __init__(self): parser = opt ...
- python 全栈开发,Day29(昨日作业讲解,模块搜索路径,编译python文件,包以及包的import和from,软件开发规范)
一.昨日作业讲解 先来回顾一下昨日的内容 1.os模块 和操作系统交互 工作目录 文件夹 文件 操作系统命令 路径相关的 2.模块 最本质的区别 import会创建一个专属于模块的名字, 所有导入模块 ...
- python optparser模块
python的内置模块中对于命令行的解析模块共两个getopt 和 optparse .不过getopt过于简单,往往不能满足需求.此时可以使用optparse模块.这个模块相对于getopt更新,功 ...
- python函数,模块及eclipse配置python开发环境
一.eclipse的使用 1.作用 (1)最好用的IDE (2)可调式debug (3)查看可执行过程 (4)可查看源代码 2.安装eclipse及配置 目录安装Pythonpython for ec ...
- zip函数-Python 3
zip函数接受任意多个(包括0个和1个)序列作为参数,返回一个tuple列表. zip函数在获取数据后,生成字典(dict)时比较好用. for examples: # Code based on P ...
- ssh爆破(python脚本)
最近在乌云看到一份端口详解:为了锻炼自己,按照端口详解写脚本 #!/usr/local/bin/ python # -*- coding: UTF-8 -*- __author__ = 'yangxi ...
- python-模块入门二(模块循环导入,区分python文件的两种用途,模块搜索路径,软件开发的目录规范)
一.模块的循环导入问题 run.py # import m1 # 第一次导入 m1.py # 错误示范 ''' print('正在导入m1') from m2 import y #第一次导入m2 x= ...
随机推荐
- Hibernate 自动更新表出错 More than one table found in namespace
报错:Caused by: org.hibernate.tool.schema.extract.spi.SchemaExtractionException: More than one table f ...
- 阶段5 3.微服务项目【学成在线】_day18 用户授权_19-微服务之间认证-Feign 拦截器
4.2 Feign 拦截器 4.2.1 定义Feign拦截器 微服务之间使用feign进行远程调用,采用feign拦截器实现远程调用携带JWT. 在common工程添加依赖: <dependen ...
- 阶段5 3.微服务项目【学成在线】_day17 用户认证 Zuul_16-网关-过虑器
4.5 过虑器 Zuul的核心就是过虑器,通过过虑器实现请求过虑,身份校验等. 4.5.1 ZuulFilter 自定义过虑器需要继承 ZuulFilter,ZuulFilter是一个抽象类,需要覆盖 ...
- IDEA中提示Error:java: Compilation failed: internal java compiler error
解决办法:File-->Setting...-->Build,Execution,Deployment-->Compiler-->Java Compiler 设置相应Modul ...
- Spring Cloud(8):日志及分布式跟踪(Sleuth&Zipkin)
简介 在微服务架构中,项目中前端发起一个请求,后端可能跨几个服务调用才能完成这个请求.如果系统越来越庞大,服务之间的调用与被调用关系就会变得很复杂,那么这时候我们需要分析具体哪一个服务出问题了就会显得 ...
- jenkins的pipeline拉取指定分支的代码
脚本示例 pipeline { agent any options { durabilityHint 'PERFORMANCE_OPTIMIZED' timeout(time:5, unit: 'MI ...
- python:解析requests返回的response(json格式)
import requests, json r = requests.get('http://192.168.207.160:9000/api/qualitygates/project_status? ...
- WEB前端动态背景集
本资源是我在源代码网站上发现的,内附几十种背景动态特效,我单独提取出来精品背景特效在此分享,文件里有20多种精品动态效果,本人觉得可用作于个人博客主页背景,登陆页面背景等,有20多个背景特效,非常漂亮 ...
- 移动架构-UML
UML(Unified Modeling Language),UML规范用来描述建模的概念有,类(对象的).对象.关联.职责.行为.接口.用例.包.顺序.协作,以及状态.这里对UML做一个简单介绍 前 ...
- WebStorm+Chrome调试Vue步骤
在调试时请 注意 : 在WebStorm中启动调试时,WebStorm会根据你设置的url,自动打开新的Chrome浏览器进程访问这个设置的url,而且这个浏览器页面和你平常看到的浏览器差异会比较大, ...