Pampuna has automated the task of selecting which port to use for a reverse shell with a Python script that he calls a “ping pong test”
The listener sets up a number of TCP listeners on common ports and logs any connections, but only responds with the phrase “pong”
On the target machine, the client attempts to contact the listener on the same ports, and those that receive a response are considered open.
The post includes examples in HTML, JavaScript, PowerShell, Bash and a custom Windows Media Player script, as well as examples of automating a reverse shell through the existing socket in both Python and PowerShell.