To create a reverse shell with Python, we will create a socket, connect to our listener, duplicate the input, output, and error descriptors and call /bin/sh with subprocess.
The initial command injection will place a malicious file in a world-writable directory (/var/tmp) that calls upon Node.js child_process and exec() functions. The latter will contain the Netcat reverse shell payload.
We import the Socket module, set up our IP and port, and pass these into a socket call. We then initialize the TCP connection (connect()), open channels for STDIN, STDOUT, and STDERR, and call /bin/bash.