Az - Service Bus Privesc
Reading time: 13 minutes
tip
AWS हैकिंग सीखें और अभ्यास करें:HackTricks Training AWS Red Team Expert (ARTE)
GCP हैकिंग सीखें और अभ्यास करें: HackTricks Training GCP Red Team Expert (GRTE)
Azure हैकिंग सीखें और अभ्यास करें:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks का समर्थन करें
- सदस्यता योजनाओं की जांच करें!
- हमारे 💬 Discord समूह या टेलीग्राम समूह में शामिल हों या हमें Twitter 🐦 @hacktricks_live** पर फॉलो करें।**
- हैकिंग ट्रिक्स साझा करें, PRs को HackTricks और HackTricks Cloud गिटहब रिपोजिटरी में सबमिट करके।
Service Bus
अधिक जानकारी के लिए देखें:
Microsoft.ServiceBus/namespaces/authorizationrules/listKeys/action या Microsoft.ServiceBus/namespaces/authorizationrules/regenerateKeys/action
ये अनुमतियाँ आपको एक Service Bus namespace के भीतर स्थानीय प्राधिकरण नियमों के लिए कुंजी प्राप्त करने या पुनः उत्पन्न करने की अनुमति देती हैं। इन कुंजियों का उपयोग करके Service Bus namespace के रूप में प्रमाणित होना संभव है, जिससे आप किसी भी कतार या विषय में संदेश भेज सकते हैं, किसी भी कतार या सदस्यता से संदेश प्राप्त कर सकते हैं, या संभावित रूप से सिस्टम के साथ ऐसे तरीकों से इंटरैक्ट कर सकते हैं जो संचालन को बाधित कर सकते हैं, वैध उपयोगकर्ताओं का अनुकरण कर सकते हैं, या संदेश प्रवाह में दुर्भावनापूर्ण डेटा इंजेक्ट कर सकते हैं।
ध्यान दें कि डिफ़ॉल्ट रूप से RootManageSharedAccessKey
नियम का Service Bus namespace पर पूर्ण नियंत्रण है और इसका उपयोग az
cli द्वारा किया जाता है, हालाँकि, अन्य कुंजी मानों के साथ अन्य नियम भी हो सकते हैं।
# List keys
az servicebus namespace authorization-rule keys list --resource-group <res-group> --namespace-name <namespace-name> --authorization-rule-name RootManageSharedAccessKey [--authorization-rule-name RootManageSharedAccessKey]
# Regenerate keys
az servicebus namespace authorization-rule keys renew --key [PrimaryKey|SecondaryKey] --resource-group <res-group> --namespace-name <namespace-name> [--authorization-rule-name RootManageSharedAccessKey]
Microsoft.ServiceBus/namespaces/AuthorizationRules/write
इस अनुमति के साथ, यह संभव है कि एक नया प्राधिकरण नियम सभी अनुमतियों और इसके अपने कुंजी के साथ बनाया जाए:
az servicebus namespace authorization-rule create --authorization-rule-name "myRule" --namespace-name mynamespacespdemo --resource-group Resource_Group_1 --rights Manage Listen Send
[!WARNING] यह कमांड कुंजियों के साथ प्रतिक्रिया नहीं करता है, इसलिए आपको विशेषाधिकार बढ़ाने के लिए उन्हें पिछले कमांड (और अनुमतियों) के साथ प्राप्त करना होगा।
इसके अलावा, उस कमांड (और Microsoft.ServiceBus/namespaces/authorizationRules/read
) के साथ, यदि आप Azure CLI के माध्यम से यह क्रिया करते हैं, तो एक मौजूदा प्राधिकरण नियम को अपडेट करना और उसे अधिक अनुमतियाँ देना संभव है (यदि इसमें कुछ की कमी थी) निम्नलिखित कमांड के साथ:
az servicebus namespace authorization-rule update \
--resource-group <MyResourceGroup> \
--namespace-name <MyNamespace> \
--name RootManageSharedAccessKey \
--rights Manage Listen Send
Microsoft.ServiceBus/namespaces/[queues|topics]/authorizationRules/ListKeys/action OR Microsoft.ServiceBus/namespaces/[queues|topics]/authorizationRules/regenerateKeys/action
एक Service Bus namespace के भीतर विशिष्ट विषयों और कतारों के अपने स्वयं के प्राधिकरण नियम हो सकते हैं, जिन्हें इकाई तक पहुंच को नियंत्रित करने के लिए उपयोग किया जा सकता है। इन अनुमतियों के साथ, आप इन स्थानीय प्राधिकरण नियमों के लिए कुंजी प्राप्त या पुन: उत्पन्न कर सकते हैं, जिससे आप इकाई के रूप में प्रमाणीकरण कर सकते हैं और संभावित रूप से संदेश भेजने या प्राप्त करने, सदस्यता प्रबंधित करने, या सिस्टम के साथ ऐसे तरीकों से बातचीत कर सकते हैं जो संचालन को बाधित कर सकते हैं, वैध उपयोगकर्ताओं का अनुकरण कर सकते हैं, या संदेश प्रवाह में दुर्भावनापूर्ण डेटा इंजेक्ट कर सकते हैं।
# List keys (topics)
az servicebus topic authorization-rule keys list --resource-group <res-group> --namespace-name <namespace-name> --topic-name <topic-name> --name <auth-rule-name>
# Regenerate keys (topics)
az servicebus topic authorization-rule keys renew --key [PrimaryKey|SecondaryKey] --resource-group <res-group> --namespace-name <namespace-name> --topic-name <topic-name> --name <auth-rule-name>
# List keys (queues)
az servicebus queue authorization-rule keys list --resource-group <res-group> --namespace-name <namespace-name> --queue-name <queue-name> --name <auth-rule-name>
# Regenerate keys (queues)
az servicebus queue authorization-rule keys renew --key [PrimaryKey|SecondaryKey] --resource-group <res-group> --namespace-name <namespace-name> --queue-name <queue-name> --name <auth-rule-name>
Microsoft.ServiceBus/namespaces/[queues|topics]/authorizationRules/write
इस अनुमति के साथ, यह संभव है कि एक नई प्राधिकरण नियम सभी अनुमतियों और अपनी कुंजियों के साथ बनाई जाए:
# In a topic
az servicebus topic authorization-rule create --resource-group <res-group> --namespace-name <namespace-name> --topic-name <topic-name> --name <auth-rule-name> --rights Manage Listen Send
# In a queue
az servicebus queue authorization-rule create --resource-group <res-group> --namespace-name <namespace-name> --queue-name <queue-name> --name <auth-rule-name> --rights Manage Listen Send
[!WARNING] यह कमांड कुंजियों के साथ प्रतिक्रिया नहीं करता है, इसलिए आपको विशेषाधिकार बढ़ाने के लिए उन्हें पिछले कमांड (और अनुमतियों) के साथ प्राप्त करना होगा।
इसके अलावा, उस कमांड (और Microsoft.ServiceBus/namespaces/[queues|topics]/authorizationRules/read
) के साथ, यदि आप Azure CLI के माध्यम से यह क्रिया करते हैं, तो एक मौजूदा प्राधिकरण नियम को अपडेट करना संभव है और इसे अधिक अनुमतियाँ देना (यदि यह कुछ की कमी थी) निम्नलिखित कमांड के साथ:
# In a topic
az servicebus topic authorization-rule update --resource-group <res-group> --namespace-name <namespace-name> --topic-name <topic-name> --name <auth-rule-name> --rights Manage Listen Send
# In a queue
az servicebus queue authorization-rule update --resource-group <res-group> --namespace-name <namespace-name> --queue-name <queue-name> --name <auth-rule-name> --rights Manage Listen Send
Microsoft.ServiceBus/namespaces/write (& Microsoft.ServiceBus/namespaces/read if az cli is used)
इन अनुमतियों के साथ एक हमलावर "स्थानीय प्रमाणीकरण" को फिर से सक्षम कर सकता है निम्नलिखित कमांड के साथ और इसलिए साझा नीतियों से सभी कुंजी काम करेंगी।
az servicebus namespace update --disable-local-auth false -n <namespace-name> --resource-group <res-group>
Send Messages with keys (Microsoft.ServiceBus/namespaces/[queues|topics]/authorizationRules/ListKeys/action OR Microsoft.ServiceBus/namespaces/[queues|topics]/authorizationRules/regenerateKeys/action)
आप PrimaryConnectionString
प्राप्त कर सकते हैं, जो Service Bus namespace के लिए एक क्रेडेंशियल के रूप में कार्य करता है। इस कनेक्शन स्ट्रिंग के साथ, आप Service Bus namespace के रूप में पूरी तरह से प्रमाणीकरण कर सकते हैं, जिससे आप किसी भी कतार या विषय पर संदेश भेजने में सक्षम होते हैं और संभावित रूप से सिस्टम के साथ ऐसे तरीकों से इंटरैक्ट कर सकते हैं जो संचालन को बाधित कर सकते हैं, वैध उपयोगकर्ताओं का अनुकरण कर सकते हैं, या संदेश प्रवाह में दुर्भावनापूर्ण डेटा इंजेक्ट कर सकते हैं। यह विधि काम करती है यदि --disable-local-auth
को false पर सेट किया गया है (तो स्थानीय प्रमाणीकरण सक्षम है)।
import asyncio
from azure.servicebus.aio import ServiceBusClient
from azure.servicebus import ServiceBusMessage
# pip install azure-servicebus
NAMESPACE_CONNECTION_STR = "<PrimaryConnectionString>"
TOPIC_OR_QUEUE_NAME = "<TOPIC_OR_QUEUE_NAME>"
async def send_message():
async with ServiceBusClient.from_connection_string(NAMESPACE_CONNECTION_STR) as client:
async with client.get_topic_sender(topic_name=TOPIC_OR_QUEUE_NAME) as sender:
await sender.send_messages(ServiceBusMessage("Hacktricks-Training: Single Item"))
print("Sent message")
asyncio.run(send_message())
इसके अलावा, आप az rest के साथ संदेश भेज सकते हैं, इस मामले में आपको उपयोग करने के लिए एक sas टोकन उत्पन्न करने की आवश्यकता है।
import time, urllib.parse, hmac, hashlib, base64
def generate_sas_token(uri, key_name, key, expiry_in_seconds=3600):
expiry = int(time.time() + expiry_in_seconds)
string_to_sign = urllib.parse.quote_plus(uri) + "\n" + str(expiry)
signed_hmac_sha256 = hmac.new(key.encode('utf-8'), string_to_sign.encode('utf-8'), hashlib.sha256).digest()
signature = urllib.parse.quote_plus(base64.b64encode(signed_hmac_sha256))
token = f"SharedAccessSignature sr={urllib.parse.quote_plus(uri)}&sig={signature}&se={expiry}&skn={key_name}"
return token
# Replace these with your actual values
resource_uri = "https://<namespace>.servicebus.windows.net/<queue_or_topic>"
key_name = "<SharedKeyName>"
primary_key = "<PrimaryKey>"
sas_token = generate_sas_token(resource_uri, key_name, primary_key)
print(sas_token)
az rest --method post \
--uri "https://<NAMESPACE>.servicebus.windows.net/<queue>/messages" \
--headers "Content-Type=application/atom+xml;type=entry;charset=utf-8" "Authorization=SharedAccessSignature sr=https%3A%2F%2F<NAMESPACE>.servicebus.windows.net%2F<TOPIC_OR_QUEUE_NAME>&sig=<SIGNATURE>&se=<EXPIRY>&skn=<KEYNAME>" \
--body "<MESSAGE_BODY>"
Receive with keys (Microsoft.ServiceBus/namespaces/[queues|topics]/authorizationRules/ListKeys/action OR Microsoft.ServiceBus/namespaces/[queues|topics]/authorizationRules/regenerateKeys/action)
आप PrimaryConnectionString प्राप्त कर सकते हैं, जो Service Bus namespace के लिए एक क्रेडेंशियल के रूप में कार्य करता है। इस कनेक्शन स्ट्रिंग का उपयोग करके, आप namespace के भीतर किसी भी queue या subscription से संदेश प्राप्त कर सकते हैं, जिससे संभावित संवेदनशील या महत्वपूर्ण डेटा तक पहुंच मिलती है, डेटा exfiltration की अनुमति मिलती है, या संदेश प्रसंस्करण और एप्लिकेशन वर्कफ़्लो में हस्तक्षेप होता है। यह विधि तब काम करती है जब --disable-local-auth
को false पर सेट किया गया हो।
import asyncio
from azure.servicebus.aio import ServiceBusClient
# pip install azure-servicebus
CONN_STR = "<PrimaryConnectionString>"
QUEUE = "<QUEUE_NAME>"
# For topics/subscriptions, you would use:
# TOPIC = "<TOPIC_NAME>"
# SUBSCRIPTION = "<TOPIC_SUBSCRIPTION_NAME>"
async def receive():
async with ServiceBusClient.from_connection_string(CONN_STR) as client:
# For a queue receiver:
async with client.get_queue_receiver(queue_name=QUEUE, max_wait_time=5) as receiver:
msgs = await receiver.receive_messages(max_wait_time=5, max_message_count=20)
for msg in msgs:
print("Received:", msg)
await receiver.complete_message(msg)
# For a topic/subscription receiver (commented out):
# async with client.get_subscription_receiver(topic_name=TOPIC, subscription_name=SUBSCRIPTION, max_wait_time=5) as receiver:
# msgs = await receiver.receive_messages(max_wait_time=5, max_message_count=20)
# for msg in msgs:
# print("Received:", msg)
# await receiver.complete_message(msg)
asyncio.run(receive())
print("Done receiving messages")
इसके अलावा, आप az rest के साथ संदेश भेज सकते हैं, इस मामले में आपको उपयोग करने के लिए एक sas टोकन उत्पन्न करने की आवश्यकता है।
import time, urllib.parse, hmac, hashlib, base64
def generate_sas_token(uri, key_name, key, expiry_in_seconds=3600):
expiry = int(time.time() + expiry_in_seconds)
string_to_sign = urllib.parse.quote_plus(uri) + "\n" + str(expiry)
signature = urllib.parse.quote_plus(base64.b64encode(
hmac.new(key.encode('utf-8'), string_to_sign.encode('utf-8'), hashlib.sha256).digest()
))
token = f"SharedAccessSignature sr={urllib.parse.quote_plus(uri)}&sig={signature}&se={expiry}&skn={key_name}"
return token
# Example usage:
resource_uri = "https://<namespace>.servicebus.windows.net/queue" # For queue
# resource_uri = "https://<namespace>.servicebus.windows.net/<topic>/subscriptions/<subscription>" # For topic subscription
sas_token = generate_sas_token(resource_uri, "<KEYNAME>", "<PRIMARY_KEY>")
print(sas_token)
क्यू के लिए आप संदेश प्राप्त कर सकते हैं या उसे देख सकते हैं (संदेश प्राप्त करने से वे हटा दिए जाएंगे, जबकि देखने से ऐसा नहीं होगा):
#Get a message
az rest --method post \
--uri "https://<NAMESPACE>.servicebus.windows.net/<QUEUE>/messages/head?timeout=60" \
--headers "Content-Type=application/atom+xml;type=entry;charset=utf-8" "Authorization=SharedAccessSignature sr=<URI_ENCODED_RESOURCE>&sig=<SIGNATURE>&se=<EXPIRY>&skn=<KEYNAME>"
#Peek a message
az rest --method get \
--uri "https://<NAMESPACE>.servicebus.windows.net/<QUEUE>/messages/head?peekonly=true&timeout=60" \
--headers "Authorization=SharedAccessSignature sr=<URI_ENCODED_RESOURCE>&sig=<SIGNATURE>&se=<EXPIRY>&skn=<KEYNAME>"
#You can select the meesage changing the field PreviousSequenceNumber
az rest --method get \
--uri "https://<NAMESPACE>.servicebus.windows.net/<ENTITY>/messages?timeout=60&PreviousSequenceNumber=<LAST_SEQUENCE_NUMBER>&api-version=2017-04" \
--headers "Authorization=SharedAccessSignature sr=<URI_ENCODED_RESOURCE>&sig=<SIGNATURE>&se=<EXPIRY>&skn=<KEYNAME>"
Please provide the text you would like me to translate.
#Get a message
az rest --method post \
--uri "https://<NAMESPACE>.servicebus.windows.net/<TOPIC>/subscriptions/<SUBSCRIPTION>/messages/head?timeout=60" \
--headers "Content-Type=application/atom+xml;type=entry;charset=utf-8" "Authorization=SharedAccessSignature sr=<URI_ENCODED_RESOURCE>&sig=<SIGNATURE>&se=<EXPIRY>&skn=<KEYNAME>"
#Peek a message
az rest --method get \
--uri "https://<NAMESPACE>.servicebus.windows.net/<TOPIC>/subscriptions/<SUBSCRIPTION>/messages/head?timeout=60&api-version=2017-04" \
--headers "Authorization=SharedAccessSignature sr=<URI_ENCODED_RESOURCE>&sig=<SIGNATURE>&se=<EXPIRY>&skn=<KEYNAME>"
#You can select the meesage changing the field PreviousSequenceNumber
az rest --method get \
--uri "https://<NAMESPACE>.servicebus.windows.net/<TOPIC>/subscriptions/<SUBSCRIPTION>/messages?timeout=60&PreviousSequenceNumber=<LAST_SEQUENCE_NUMBER>&api-version=2017-04" \
--headers "Authorization=SharedAccessSignature sr=<URI_ENCODED_RESOURCE>&sig=<SIGNATURE>&se=<EXPIRY>&skn=<KEYNAME>"
Send Messages. DataActions: Microsoft.ServiceBus/namespaces/messages/send/action
आप इस अनुमति का उपयोग संदेश भेजने के लिए कर सकते हैं, भले ही --disable-local-auth
को सत्य पर सेट किया गया हो।
import asyncio
from azure.identity.aio import DefaultAzureCredential
from azure.servicebus.aio import ServiceBusClient
from azure.servicebus import ServiceBusMessage
# pip install azure-servicebus
NS = "<namespace>.servicebus.windows.net" # Your namespace
QUEUE_OR_TOPIC = "<QUEUE_OR_TOPIC>" # Your queue name
async def run():
credential = DefaultAzureCredential()
async with ServiceBusClient(fully_qualified_namespace=NS, credential=credential) as client:
#async with client.get_topic_sender(topic_name=TOPIC) as sender: # Use this to send the message to a topic
async with client.get_queue_sender(queue_name=QUEUE) as sender:
await sender.send_messages(ServiceBusMessage("Single Message"))
print("Sent a single message")
await credential.close()
if __name__ == "__main__":
asyncio.run(run())
संदेश प्राप्त करें। DataActions: Microsoft.ServiceBus/namespaces/messages/receive/action
आप इन अनुमतियों का उपयोग संदेश प्राप्त करने के लिए कर सकते हैं, भले ही --disable-local-auth
को सत्य पर सेट किया गया हो।
import asyncio
from azure.identity.aio import DefaultAzureCredential
from azure.servicebus.aio import ServiceBusClient
# pip install azure-servicebus
NS = "<namespace>.servicebus.windows.net"
QUEUE = "<QUEUE>"
# For a topic subscription, uncomment and set these values:
# TOPIC = "<TOPIC>"
# SUBSCRIPTION = "<SUBSCRIPTION>"
async def run():
credential = DefaultAzureCredential()
async with ServiceBusClient(fully_qualified_namespace=NS, credential=credential) as client:
# Receiving from a queue:
async with client.get_queue_receiver(queue_name=QUEUE, max_wait_time=5) as receiver:
async for msg in receiver:
print("Received from Queue:", msg)
await receiver.complete_message(msg)
# To receive from a topic subscription, uncomment the code below and comment out the queue receiver above:
# async with client.get_subscription_receiver(topic_name=TOPIC, subscription_name=SUBSCRIPTION, max_wait_time=5) as receiver:
# async for msg in receiver:
# print("Received from Topic Subscription:", msg)
# await receiver.complete_message(msg)
await credential.close()
asyncio.run(run())
print("Done receiving messages")
संदर्भ
- https://learn.microsoft.com/en-us/azure/storage/queues/storage-powershell-how-to-use-queues
- https://learn.microsoft.com/en-us/rest/api/storageservices/queue-service-rest-api
- https://learn.microsoft.com/en-us/azure/storage/queues/queues-auth-abac-attributes
- https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-python-how-to-use-topics-subscriptions?tabs=passwordless
- https://learn.microsoft.com/en-us/azure/role-based-access-control/permissions/integration#microsoftservicebus
tip
AWS हैकिंग सीखें और अभ्यास करें:HackTricks Training AWS Red Team Expert (ARTE)
GCP हैकिंग सीखें और अभ्यास करें: HackTricks Training GCP Red Team Expert (GRTE)
Azure हैकिंग सीखें और अभ्यास करें:
HackTricks Training Azure Red Team Expert (AzRTE)
HackTricks का समर्थन करें
- सदस्यता योजनाओं की जांच करें!
- हमारे 💬 Discord समूह या टेलीग्राम समूह में शामिल हों या हमें Twitter 🐦 @hacktricks_live** पर फॉलो करें।**
- हैकिंग ट्रिक्स साझा करें, PRs को HackTricks और HackTricks Cloud गिटहब रिपोजिटरी में सबमिट करके।