From 853e602bc2cab1faa8e3e4fd8c17ed271c2495f9 Mon Sep 17 00:00:00 2001 From: Congon4tor Date: Fri, 3 Jan 2025 19:35:15 +0100 Subject: [PATCH] Support file downloads --- hacktricks-preprocessor.py | 38 +++++++++++++++++- src/files/empty.zip | Bin 0 -> 22 bytes .../iam-passrole-codestar-createproject.md | 7 ++-- 3 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 src/files/empty.zip diff --git a/hacktricks-preprocessor.py b/hacktricks-preprocessor.py index 7a4dd84a1..0077da80f 100644 --- a/hacktricks-preprocessor.py +++ b/hacktricks-preprocessor.py @@ -1,4 +1,5 @@ import json +import os import sys import re import logging @@ -26,7 +27,7 @@ def findtitle(search ,obj, key, path=(),): def ref(matchobj): - logger.debug(f'Match: {matchobj.groups(0)[0].strip()}') + logger.debug(f'Ref match: {matchobj.groups(0)[0].strip()}') href = matchobj.groups(0)[0].strip() title = href if href.startswith("http://") or href.startswith("https://"): @@ -69,8 +70,39 @@ def ref(matchobj): return result +def files(matchobj): + logger.debug(f'Files match: {matchobj.groups(0)[0].strip()}') + href = matchobj.groups(0)[0].strip() + title = "" + + try: + for root, dirs, files in os.walk(os.getcwd()+'/src/files'): + logger.debug(root) + logger.debug(files) + if href in files: + title = href + logger.debug(f'File search result: {os.path.join(root, href)}') + + except Exception as e: + logger.debug(e) + logger.debug(f'Error searching file: {href}') + print(f'Error searching file: {href}') + sys.exit(1) + + if title=="": + logger.debug(f'Error searching file: {href}') + print(f'Error searching file: {href}') + sys.exit(1) + + template = f"""{title}""" + + result = template + + return result + + def add_read_time(content): - regex = r'(# .*(?=\n))' + regex = r'(<\/style>\n# .*(?=\n))' new_content = re.sub(regex, lambda x: x.group(0) + "\n\nReading time: {{ #reading_time }}", content) return new_content @@ -104,6 +136,8 @@ if __name__ == '__main__': current_chapter = chapter regex = r'{{[\s]*#ref[\s]*}}(?:\n)?([^\\\n]*)(?:\n)?{{[\s]*#endref[\s]*}}' new_content = re.sub(regex, ref, chapter['content']) + regex = r'{{[\s]*#file[\s]*}}(?:\n)?([^\\\n]*)(?:\n)?{{[\s]*#endfile[\s]*}}' + new_content = re.sub(regex, files, chapter['content']) new_content = add_read_time(new_content) chapter['content'] = new_content diff --git a/src/files/empty.zip b/src/files/empty.zip new file mode 100644 index 0000000000000000000000000000000000000000..15cb0ecb3e219d1701294bfdf0fe3f5cb5d208e7 GIT binary patch literal 22 NcmWIWW@Tf*000g10H*)| literal 0 HcmV?d00001 diff --git a/src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-codestar-privesc/iam-passrole-codestar-createproject.md b/src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-codestar-privesc/iam-passrole-codestar-createproject.md index b310b6607..3c66eb292 100644 --- a/src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-codestar-privesc/iam-passrole-codestar-createproject.md +++ b/src/pentesting-cloud/aws-security/aws-privilege-escalation/aws-codestar-privesc/iam-passrole-codestar-createproject.md @@ -32,7 +32,9 @@ To exploit this you need to create a **S3 bucket that is accessible** from the a Also **upload** this `empty zip` file to the **bucket**: -{% file src="../../../../images/empty.zip" %} +{{#file}} +empty.zip +{{#endfile}} Remember that the **bucket with both files must be accessible by the victim account**. @@ -86,6 +88,3 @@ aws codestar create-project \ This exploit is based on the **Pacu exploit of these privileges**: [https://github.com/RhinoSecurityLabs/pacu/blob/2a0ce01f075541f7ccd9c44fcfc967cad994f9c9/pacu/modules/iam\_\_privesc_scan/main.py#L1997](https://github.com/RhinoSecurityLabs/pacu/blob/2a0ce01f075541f7ccd9c44fcfc967cad994f9c9/pacu/modules/iam__privesc_scan/main.py#L1997) On it you can find a variation to create an admin managed policy for a role instead of to a user. {{#include ../../../../banners/hacktricks-training.md}} - - -