[ SEA-GHOST MINI SHELL]
#!/usr/bin/env python
import json
import requests
import sys
if len(sys.argv[1:]) == 2:
api_url = sys.argv[1]
server_name = sys.argv[2]
elif len(sys.argv[1:]) != 2:
print ("This script uses only two arguments.")
sys.exit(0)
def api_call(url):
try:
response = requests.get(url)
response.raise_for_status()
except requests.exceptions.HTTPError as httperror:
print("Http Error:", httperror)
sys.exit(0)
except requests.exceptions.ConnectionError as connerror:
print("Connection Error:", connerror)
sys.exit(0)
except requests.exceptions.Timeout as timeerror:
print("Timeout Error:", timeerror)
sys.exit(0)
except requests.exceptions.RequestException as othererror:
print("Something else:", othererror)
sys.exit(0)
try:
return response.json()
except ValueError:
print("Unknown API url:", url)
sys.exit(0)
def get_servers(api_url,server_name):
servers_url = api_url + "/api/1.0/server/?type=plesk&hostname=" + server_name
servers_response = api_call(servers_url)
try:
if ( servers_response['data'] ):
server_id = servers_response['data'][0]['server_id']
else:
print("Not found hostname from API:", server_name)
sys.exit(0)
return server_id
except KeyError:
print ("Not found key 'data' from API")
sys.exit(0)
def get_users_plesk(api_url, server_id):
active_users_url = api_url + "/api/1.0/account/?fields=account_id&suspended=0&server_id=" + server_id
active_users_response = api_call(active_users_url)
try:
return active_users_response['total_items']
except KeyError:
print ("Not found key 'total_items' from API")
sys.exit(0)
def main():
servers_list = get_servers(api_url,server_name)
active_user = get_users_plesk(api_url,servers_list)
print(active_user)
if __name__ == "__main__":
main()
SEA-GHOST - SHELL CODING BY SEA-GHOST