mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-02-04 11:07:37 -08:00
Translated ['src/pentesting-cloud/aws-security/aws-privilege-escalation/
This commit is contained in:
@@ -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"""<a class="content_ref" href="/files/{href}"><span class="content_ref_label">{title}</span></a>"""
|
||||
|
||||
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
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
Dzięki tym uprawnieniom możesz **nadużyć roli IAM codestar**, aby wykonać **dowolne działania** za pomocą **szablonu cloudformation**.
|
||||
|
||||
Aby to wykorzystać, musisz utworzyć **wiadro S3, które jest dostępne** z zaatakowanego konta. Prześlij plik o nazwie `toolchain.json`. Plik ten powinien zawierać **eksploit szablonu cloudformation**. Można użyć następującego, aby ustawić zarządzaną politykę dla użytkownika pod twoją kontrolą i **przyznać mu uprawnienia administratora**:
|
||||
Aby to wykorzystać, musisz utworzyć **bucket S3, który jest dostępny** z zaatakowanego konta. Prześlij plik o nazwie `toolchain.json`. Plik ten powinien zawierać **eksploit szablonu cloudformation**. Można użyć następującego, aby ustawić zarządzaną politykę dla użytkownika pod twoją kontrolą i **przyznać mu uprawnienia administratora**:
|
||||
```json:toolchain.json
|
||||
{
|
||||
"Resources": {
|
||||
@@ -28,13 +28,15 @@ Aby to wykorzystać, musisz utworzyć **wiadro S3, które jest dostępne** z zaa
|
||||
}
|
||||
}
|
||||
```
|
||||
Również **prześlij** ten `empty zip` plik do **bucketu**:
|
||||
Również **prześlij** ten `pusty plik zip` do **wiadra**:
|
||||
|
||||
{% file src="../../../../images/empty.zip" %}
|
||||
{{#file}}
|
||||
empty.zip
|
||||
{{#endfile}}
|
||||
|
||||
Pamiętaj, że **bucket z oboma plikami musi być dostępny dla konta ofiary**.
|
||||
Pamiętaj, że **wiadro z oboma plikami musi być dostępne przez konto ofiary**.
|
||||
|
||||
Po przesłaniu obu rzeczy możesz teraz przejść do **eksploatacji**, tworząc projekt **codestar**:
|
||||
Po przesłaniu obu rzeczy możesz teraz przystąpić do **eksploatacji**, tworząc projekt **codestar**:
|
||||
```bash
|
||||
PROJECT_NAME="supercodestar"
|
||||
|
||||
@@ -79,6 +81,6 @@ aws codestar create-project \
|
||||
--source-code file://$SOURCE_CODE_PATH \
|
||||
--toolchain file://$TOOLCHAIN_PATH
|
||||
```
|
||||
Ten exploit opiera się na **eksploicie Pacu tych uprawnień**: [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) Można w nim znaleźć wariant do stworzenia zarządzanej polityki administratora dla roli zamiast dla użytkownika.
|
||||
To exploit this, you need to have the **Pacu exploit tych uprawnień**: [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) Na nim możesz znaleźć wariant do stworzenia polityki zarządzanej przez administratora dla roli zamiast dla użytkownika.
|
||||
|
||||
{{#include ../../../../banners/hacktricks-training.md}}
|
||||
|
||||
Reference in New Issue
Block a user