栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

将python扩展到msf中

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

将python扩展到msf中

前景需要:

msf框架提供了python的接口,并且网上有好多以Python写的渗透测试代码,尤其是exploit-da等漏洞库中,可不可以把网上的python代码稍稍改动一下放到msf中使用呢(假如根据同一套的逻辑重写一个的话,不仅要对ruby有一些理解,而且要费事的重写)?

一、想直接将python-poc加入msf框架中的话需要用特定的格式写python(from metasploit import module和metadata中要给出这个modul的type,因为支持的模板可能就那么几种,模板在/usr/share/metasploit-framework/lib/msf/core/modules/external/templates中),想打印出东西的话得用logging模块,这里不支持print语句;
二、写好python-poc(test.py)之后将其放在/root/.msf4/modules/下面,你的python是哪种类型的module(例’type’: ‘single_scanner’,在/usr/share/metasploit-framework/lib/msf/core/modules/external/templates找到相应的模板查看,例如single_scannerr的模板中有include Msf::Auxiliary::Scanner)那么你需要在/root/.msf4/modules/下面再创建一个auxiliary/scanner目录,并将python-poc放到里面;
三、启动msfconsole
四、加载所有的模块(运行reload_all命令)
五、如果将exploit-db里面的rb加载到msf中是相同流程;
六、github上的帮助文档链接:
扩展python)https://github.com/rapid7/metasploit-framework/wiki/Writing-External-Python-Modules
其他)https://github.com/rapid7/metasploit-framework/wiki/
七:例子:

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

# standard modules
import logging

# extra modules
dependencies_missing = False
try:
    import requests
except ImportError:
    dependencies_missing = True

from metasploit import module

metadata = {
    'name': 'Python Module Example',
    'description': '''
        Python communication with msfconsole.
    ''',
    'authors': [
        'Jacob Robles'
    ],
    'date': '2018-03-22',
    'license': 'MSF_LICENSE',
    'references': [
        {'type': 'url', 'ref': 'https://blog.rapid7.com/2017/12/28/regifting-python-in-metasploit/'},
        {'type': 'aka', 'ref': 'Coldstone'}
    ],
    'type': 'single_scanner',
    'options': {
        'targeturi': {'type': 'string', 'description': 'The base path', 'required': True, 'default': '/'},
        'rhost': {'type': 'address', 'description': 'Target address', 'required': True, 'default': None}
    }
}


def run(args):
    module.LogHandler.setup(msg_prefix='{} - '.format(args['rhost']))
    if dependencies_missing:
        logging.error('Module dependency (requests) is missing, cannot continue')
        return

 # Your code here
    try:
        r = requests.get('https://{}/{}'.format(args['rhost'], args['targeturi']), verify=False)
    except requests.exceptions.RequestException as e:
        logging.error('{}'.format(e))
        return

  logging.info('{}...'.format(r.text[0:50]))


if __name__ == '__main__':
    module.run(metadata, run)
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/948798.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号