%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /proc/4187198/root/usr/bin/
Upload File :
Create Path :
Current File : //proc/4187198/root/usr/bin/memcached-client

#!/usr/bin/python

import socket
import sys
import os

def send_command(sock_path, command):
    # Check if the socket path and command are provided
    if not sock_path:
        print("Error: Socket path is required.")
        return
    if not command:
        print("Error: Command is required.")
        return

    try:
        # Create a Unix socket
        sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)

        # Attempt to connect to the provided socket path
        try:
            sock.connect(sock_path)
        except FileNotFoundError:
            print("Error: Socket path '{}' does not exist.".format(sock_path))
            return
        except PermissionError:
            print("Error: Permission denied for accessing '{}'. Try running as root or check permissions.".format(sock_path))
            return
        except socket.error as e:
            print("Error: Unable to connect to the socket at '{}'. Reason: {}".format(sock_path, e))
            return

        # Send the specified command
        try:
            sock.sendall(command.encode() + b'\n')
        except BrokenPipeError:
            print("Error: Broken pipe. The socket connection was interrupted.")
            return
        except socket.error as e:
            print("Error: Failed to send data to the socket. Reason: {}".format(e))
            return

        # Receive and print the response
        try:
            response = sock.recv(4096)  # Adjust buffer size if needed
            if response:
                print(response.decode())
            else:
                print("Warning: Received an empty response from the server.")
        except socket.error as e:
            print("Error: Failed to receive data from the socket. Reason: {}".format(e))

    except Exception as e:
        print("An unexpected error occurred: {}".format(e))

    finally:
        # Close the socket connection gracefully
        try:
            sock.close()
        except Exception as e:
            print("Error: Failed to close the socket. Reason: {}".format(e))

if __name__ == "__main__":
    if os.geteuid() == 0:
        print("Error: This script should not be run as root for security reasons.")
        sys.exit(1)

    # Check if the required arguments are provided
    if len(sys.argv) < 3:
        print("Usage: /usr/bin/memcached-client <socket_path> <command>")
        sys.exit(1)

    # Get the socket path and command from the command-line arguments
    sock_path = sys.argv[1]
    command = " ".join(sys.argv[2:])  # Join all arguments after the socket path as the command

    # Run the function
    send_command(sock_path, command)


Zerion Mini Shell 1.0