Python入门:函数封装之python调用sqlmap

来源:互联网 发布:检测不到网络打印机 编辑:程序博客网 时间:2024/05/22 05:11

该案例是想通过python来简化sqlmap的使用,故会使用到查找sqlmap路径,以及在当前路径下找到sqlmap.py文件,这里肯定会有人要问了,为什么不使用list加下标的方式提取sqlmap.py文件呢?首先我们需要考虑的是,以下标的方式提取文件是可变的,如:在sqlmap文件夹中多了一个文件,这时候,你想取到目标文件的下标可能会变化,所以不能使用下标来提取目标文件,最简单的办法就是使用一个判断来找到目标文件,然后与目标path进行拼接,最终组合成想到的绝对文件路径

#test.pyimport ospath = '/Users/frankslg/tools/sqlmap/'os.chdir(path)find_sqlmap = os.listdir(path)num = len(find_sqlmap)for sql in find_sqlmap:    if sql == 'sqlmap.py':        sqlmap_path = path + sqlcomm = input('please enter the command parameters:')os.system(sqlmap_path + ' ' + comm)

上下代码分别是无封装的结构和使用了封装的结构,当然使用了封装有相当多的好处,如果调用简单、模块化、代码结构清晰等等。

#test1.pydef call_sqlmap(comm):    path = '/Users/frankslg/tools/sqlmap/'    os.chdir(path)    find_sqlmap = os.listdir(path)    for sql in find_sqlmap:        if sql == 'sqlmap.py':            sqlmap_path = path + sql    return os.system(sqlmap_path + ' ' + comm)comm = input('please enter the command parameters:')if __name__ == '__main__':    call_sqlmap(comm)

演示结果

please enter the command parameters:--help    sqlmap/0.9 - automatic SQL injection and database takeover tool    http://sqlmap.sourceforge.netUsage: python /Users/frankslg/tools/sqlmap/sqlmap.py [options]Options:  --version             show program's version number and exit  -h, --help            show this help message and exit  -v VERBOSE            Verbosity level: 0-6 (default 1)

补充案例

#burp.pypath1 = "/Users/frankslg/tools/burp/"file1 = os.listdir(path1)comm = ''for burp in file1:    if burp == "burpsuite1.6.jar":        comm = "burpsuite1.6.jar"os.chdir(path1)os.system('open' + ' ' + comm)
#burp.pydef burp_run(burp_path):    file1 = os.listdir(burp_path)    comm = ''    for burp in file1:        if burp == "burpsuite1.6.jar":            comm = "burpsuite1.6.jar"    os.chdir(burp_path)    return os.system('open' + ' ' + comm)burp_path = input('Plase enter burp_path:')if __name__ == '__main__':    burp_run(burp_path)

运行结果

在Plase enter burp_path:后输入/Users/frankslg/tools/burp/

Plase enter burp_path:/Users/frankslg/tools/burp/

burp工具就被打开了

0 0
原创粉丝点击