Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ''' #!/usr/bin/env python3'''
- import requests
- import urllib3
- from bs4 import BeautifulSoup as bs
- from getpass import getpass
- from base64 import b64encode, b64decode
- import sys
- import json
- hosts = []
- hosts.append("10.13.8.76")
- hosts.append("10.13.8.79")
- hosts.append("10.13.8.77")
- hosts.append("10.13.8.47")
- hosts.append("10.13.8.23")
- hosts.append("10.13.8.30")
- # hosts.append("10.13.4.19")
- # hosts.append("10.13.4.91")
- scripting_end_point = "/hac/console/scripting/execute"
- #cluster_end_point = "/hac/monitoring/cluster/ping"
- #scriptToExec = input("Groovy> ")
- scriptToExec = "'ifconfig'.execute().text"
- headers = {
- 'user-agent': 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36'
- }
- proxies = {
- 'http': 'http://127.0.0.1:8080',
- 'https': 'https://127.0.0.1:8080',
- }
- urllib3.disable_warnings()
- user_session = requests.Session()
- csrf_token = ""
- def extractCsrf(host):
- try:
- response = user_session.get("https://" + host + ":9002/hac/login.jsp", verify=False,proxies=proxies, headers=headers)
- html_page = bs(response.text, "html.parser")
- csrf_token = html_page.select_one("input[name='_csrf']")['value']
- return csrf_token
- except Exception as e:
- print("[-] Error occured : " + str(e))
- exit(0)
- def authenticate(host, username="eahmed", passowrd="F5&?PE!y?PjM9.vU"):
- if "X-CSRF-TOKEN" in headers:
- del(headers['X-CSRF-TOKEN'])
- # csrf_token = extractCsrf(host)
- try:
- response = user_session.post("https://"+host+":9002/hac/j_spring_security_check", data = {"j_username":username, "j_password":passowrd, "_csrf":csrf_token}, headers=headers, proxies=proxies, verify=False)
- if response.status_code == 200:
- print ("[+] ----------------------------------- "+ host +" ----------------------------------- ")
- else:
- raise Exception('Requests status code : ' + str(response.status_code))
- if "JSESSIONID" not in user_session.cookies.get_dict() :
- raise Exception("Can't extract cookies.")
- except Exception as e:
- print("[-] Error occured : " + str(e))
- exit(0)
- def runCmd(host, payload):
- # if "X-CSRF-TOKEN" in headers:
- # del(headers['X-CSRF-TOKEN'])
- headers['X-CSRF-TOKEN'] = extractCsrf(host)
- try:
- response = user_session.post("https://"+host+":9002"+scripting_end_point, data = {"script":payload, "scriptType":"groovy", "commit":"False"}, proxies=proxies, headers=headers, verify=False)
- if response.status_code == 200:
- print(response.json()["stacktraceText"])
- print(response.json()["outputText"])
- print(response.json()["executionResult"])
- else:
- raise Exception('Requests status code : ' + str(response.status_code))
- except Exception as e:
- print("[-] Error occured : " + str(e))
- exit(0)
- # def getClusterInfo(host):
- # headers['X-CSRF-TOKEN'] = extractCsrf(host)
- # try:
- # response = user_session.post("https://"+host+":9002"+cluster_end_point, proxies=proxies, headers=headers, verify=False)
- # if response.status_code == 200:
- # print(json.dumps(response.json(),indent=4))
- # else:
- # raise Exception('Requests status code : ' + str(response.status_code))
- # except Exception as e:
- # print("[-] Error occured : " + str(e))
- # exit(0)
- for host in hosts:
- csrf_token = extractCsrf(host)
- authenticate(host)
- #runCmd(host, scriptToExec)
- getClusterInfo(host)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement