Skip to content

Latest commit

 

History

History
executable file
·
45 lines (43 loc) · 1.94 KB

File metadata and controls

executable file
·
45 lines (43 loc) · 1.94 KB

#python docopt

在injectMan和CVE-2017-11610的项目中用到了docopt这个库,其在命令行交互中堪称神器,比其他库要好用很多

####介绍 __doc__作为写在模块第一个未赋值的字符串,函数和类对象都具有这个属性,如

>>> import time
>>> print time.__doc__
This module provides various functions to manipulate time values.

There are two standard representations of time.  One is the number
of seconds since the Epoch, in UTC (a.k.a. GMT).  It may be an integer
or a floating point number (to represent fractions of seconds).
The Epoch is system-defined; on Unix, it is generally January 1st, 1970.
The actual value can be retrieved by calling gmtime(0)...

而docopt模块就是读取这个字符串,并做解析的一套库,其的作用就是打造一个更好、更简洁的交互程序

import docopt
arguments = docopt.docopt(__doc__)

经过上面的代码后arguments变量将会被赋值为一个数组 ####docopt中的关键字 其实我也不确定在docopt中是否是这样定义的,简单来说就是在docopt处理注释时,遇见以下字符就会开始把内容解析为交互的格式

Usage:
	Demo.py -r <arg1>
Options
	-r Example
Example:
	Deom.py -r 'arg1'

这样在arguments字典中,arguments['-r']会被复制为True或者Flase,而arguments['<arg1>']会被赋值为arg1 docopt中的参数类型(是必须还是可选)未完待续... ####交互相关 在写CVE-2017-11610的POC时有一版是创宇pocsuite的,这里mark一下,这个POC框架的一些交互的参数

--extra-params "{'a':'b'}"

这样,pocsuite可以接受一些非常规的输入指令,像上面就可以理解为 -a b,在程序中用self.params['a']这样的代码来获得输入,在这套框架中还有一些比较常规的交互参数

-u/--url
self.url

未完待续