CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/auxiliary/example.py
Views: 11766
1
#!/usr/bin/env python3
2
# -*- coding: utf-8 -*-
3
4
# standard modules
5
import logging
6
7
# extra modules
8
dependencies_missing = False
9
try:
10
import requests
11
except ImportError:
12
dependencies_missing = True
13
14
from metasploit import module
15
16
17
metadata = {
18
'name': 'Python Module Example',
19
'description': '''
20
Python communication with msfconsole.
21
''',
22
'authors': [
23
'Jacob Robles'
24
],
25
'date': '2018-03-22',
26
'license': 'MSF_LICENSE',
27
'references': [
28
{'type': 'url', 'ref': 'https://www.rapid7.com/blog/post/2017/12/28/regifting-python-in-metasploit/'},
29
{'type': 'aka', 'ref': 'Coldstone'}
30
],
31
'type': 'single_scanner',
32
'options': {
33
'targeturi': {'type': 'string', 'description': 'The base path', 'required': True, 'default': '/'},
34
'rhost': {'type': 'address', 'description': 'Target address', 'required': True, 'default': None}
35
}
36
}
37
38
39
def run(args):
40
module.LogHandler.setup(msg_prefix='{} - '.format(args['rhost']))
41
if dependencies_missing:
42
logging.error('Module dependency (requests) is missing, cannot continue')
43
return
44
45
# Your code here
46
try:
47
r = requests.get('https://{}/{}'.format(args['rhost'], args['targeturi']), verify=False)
48
except requests.exceptions.RequestException as e:
49
logging.error('{}'.format(e))
50
return
51
52
logging.info('{}...'.format(r.text[0:50]))
53
54
55
if __name__ == '__main__':
56
module.run(metadata, run)
57
58