Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- import binascii
- import collections
- import functools
- import hashlib
- import logging
- import os
- import metasploit.module as module
- _printer = collections.namedtuple('_Printer', ('print_error', 'print_good', 'print_status', 'print_warning'))
- printer = _printer(
- print_error=functools.partial(module.log, level='error'),
- print_good=functools.partial(module.log, level='good'),
- print_status=functools.partial(module.log, level='status'),
- print_warning=functools.partial(module.log, level='warning'),
- )
- targets = {
- 'Windows x86': {
- 'arch': 'x86',
- 'platform': 'win',
- },
- 'Windows x64': {
- 'arch': 'x64',
- 'platform': 'win',
- },
- }
- metadata = {
- 'name': 'PR Demo',
- 'description': '''
- This module demonstrates the functionality added by a pull request to
- the metasploit framework created by Spencer McIntyre in January 2019.
- ''',
- 'authors': ['Spencer McIntyre'],
- 'license': 'MSF_LICENSE',
- 'type': 'evasion',
- 'options': {
- 'LOG_LEVEL': {
- 'advanced': True,
- 'type': 'enum',
- 'description': 'The log level',
- 'required': True,
- 'default': 'WARNING',
- 'values': ['DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL']
- },
- 'LOG_NAME': {
- 'advanced': True,
- 'type': 'string',
- 'description': 'The name of the root logger',
- 'required': False,
- 'default': ''
- },
- },
- 'describe_payload_options': {
- 'PAYLOAD': 'windows/meterpreter/reverse_https'
- },
- 'targets': [dict(name=name, **value) for name, value in targets.items()],
- 'references': [
- {'type': 'URL', 'ref': 'https://github.com/rapid7/metasploit-framework'}
- ]
- }
- def run(msf_options):
- module.LogHandler.setup(level=msf_options['LOG_LEVEL'], name=msf_options['LOG_NAME'])
- printer.print_status('Demo module version 3')
- try:
- target = targets[msf_options['target']]
- printer.print_status('The target architecture is: ' + target['arch'])
- payload = binascii.a2b_base64(msf_options['payload_encoded'])
- payload_hash = hashlib.new('sha256', payload)
- printer.print_status('Payload hash (SHA-256): ' + payload_hash.hexdigest())
- # this is where we'd convert it to an EXE doing something fancy
- except Exception:
- logging.error('The module encountered and exception', exc_info=True)
- if __name__ == '__main__':
- module.run(metadata, run)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement