<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:atom="https://www.w3.org/2005/Atom" xmlns:sy="https://purl.org/rss/1.0/modules/syndication/" xmlns:dc="https://purl.org/dc/elements/1.1/" xmlns:content="https://purl.org/rss/1.0/modules/content/" xmlns:wfw="https://wellformedweb.org/CommentAPI/" xmlns:slash="https://purl.org/rss/1.0/modules/slash/"
  version="2.0">
  <channel>
    <title>Securing Office 365</title>
    <atom:link
      href="https://docs.microsoft.com/archive/blogs/office365security/feed.xml"
      rel="self"
      type="application/rss+xml" />
    <link>https://docs.microsoft.com/archive/blogs/office365security/feed.xml</link>
    <description>Official blog of the Office 365 Security team</description>
    <lastBuildDate>Thu, 05 Jul 2018 20:00:03 GMT</lastBuildDate>
    <language>en-US</language>
    <sy:updatePeriod>hourly</sy:updatePeriod>
    <sy:updateFrequency>1</sy:updateFrequency>
    <item>
      <title>Defending Against Rules and Forms Injection</title>
      <link>https://docs.microsoft.com/archive/blogs/office365security/defending-against-rules-and-forms-injection</link>
      <pubDate>Wed, 21 Feb 2018 11:29:36 GMT</pubDate>
      <dc:creator><![CDATA[Brandon Koeller]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/office365security/?p=3675</guid>
      <description><![CDATA[Over the last year, Office 365 security has been tracking an emergent attacker persistence mechanism...]]></description>
      <content:encoded><![CDATA[Over the last year, Office 365 security has been tracking an emergent attacker persistence mechanism in the Exchange Online ecosystem. The release of a security research tool called <a href="https://github.com/sensepost/ruler">Ruler</a> enables an attacker to install a persistence mechanism once an account has been breached to maintain access even through a password roll. While we haven't seen widespread use of the tool in Office 365, we wanted to equip IT Security Administrators with a robust understanding of the threat, a model for how to prevent the exploit, and some lightweight tooling to detect, monitor, and remediate the threat. The good news here is that if you keep your clients patched to the latest version, you are not vulnerable to the threat as Outlook client defaults block both mechanisms. You should still perform the actions in the 'How to Detect It' section, however, in case an account was breached prior to the patch releases last year.
<h1>The Threat</h1>
There are two variants of the persistence mechanism: mailbox rules and custom mail forms. In both cases, the rule/form is synced from the cloud service down to the desktop client, so a full format and re-install of the client software doesn't eliminate the injection mechanism as resyncing the mailbox will re-download the rules/forms from the cloud. The rules/forms, once placed, are used to execute remote or custom code, usually to install <a href="https://www.powershellempire.com/">malware</a> on the local machine, which is in turn leveraged to re-steal credentials or perform other illicit activity. You can read an in-depth description of the exploits here:
<ul>
 	<li>SilentBreak Security Post about Rules Vector: <a href="https://silentbreaksecurity.com/malicious-outlook-rules/">https://silentbreaksecurity.com/malicious-outlook-rules/</a></li>
 	<li>Sensepost Blog about Mailrule Pwnage: <a href="https://sensepost.com/blog/2016/mapi-over-http-and-mailrule-pwnage/">https://sensepost.com/blog/2016/mapi-over-http-and-mailrule-pwnage/</a></li>
 	<li>Sensepost Blog about Forms Threat Vector: <a href="https://sensepost.com/blog/2017/outlook-forms-and-shells/">https://sensepost.com/blog/2017/outlook-forms-and-shells/</a></li>
 	<li>Ruler Codebase: <a href="https://github.com/sensepost/ruler">https://github.com/sensepost/ruler</a></li>
</ul>
The exploits exhibit the following characteristics:
<h2>The Rules Exploit</h2>
<ol>
 	<li>A user's credential is compromised and an attacker logs on to their Exchange account (Exchange Online, or On-Premise)</li>
 	<li>The attacker creates a forwarding rule in the target's mailbox...</li>
 	<li>That when triggered with an email that matches the rule criteria...</li>
 	<li>Will execute an application...</li>
 	<li>Usually hosted on a remote WebDav server...</li>
 	<li>That installs malware locally such as <a href="https://www.powershellempire.com/">Powershell Empire</a></li>
 	<li>Which allows attacker to dump creds from local machine and perform other malicious activities</li>
</ol>
This is what the exploit looks like:

<a href="https://msdnshared.blob.core.windows.net/media/2018/02/maliciousruleinjection.jpg"><img src="https://msdnshared.blob.core.windows.net/media/2018/02/maliciousruleinjection.jpg" alt="" width="2114" height="1185" class="alignnone size-full wp-image-3655" /></a>
<h2>The Forms Exploit</h2>
<ol>
 	<li>A user's credential is compromised and an attacker logs on to their Exchange account (Exchange Online, or On-Premise)</li>
 	<li>The attacker creates a custom mail form template and injects it into the target's mailbox...</li>
 	<li>That when triggered with an email that matches the custom form template type...</li>
 	<li>Will execute custom code in the template...</li>
 	<li>That usually installs malware locally such as <a href="https://www.powershellempire.com/">Powershell Empire</a></li>
 	<li>Which allows attacker to dump creds from local machine and perform other malicious activities</li>
</ol>
This is what the exploit looks like:

<a href="https://msdnshared.blob.core.windows.net/media/2018/02/maliciousformsinjection.jpg"><img src="https://msdnshared.blob.core.windows.net/media/2018/02/maliciousformsinjection.jpg" alt="" width="2201" height="954" class="alignnone size-full wp-image-3645" /></a>
<h1>How to Prevent It</h1>
The Ruler exploit described here is considered a post-exploit technique, which means the account has already been breached by the attacker when this exploit is executed. Taking aggressive steps to prevent the initial breach in the first place is advised. There are many account breach vectors, including phishing and password spraying, which are relatively easy to execute. Using protection mechanisms like multi-factor authentication on user accounts, whether conditional or always-on, is an effective mitigation. This should be your first line of defense. Some effective tactics you can leverage include:
<ol>
 	<li>Enable Multi-factor Authentication for all of your users, especially those with administrative privileges.</li>
 	<li>Monitor your accounts for illicit activity. You can do this manually, or with a security monitoring toolset. This may not prevent the initial breach, but will shorten the duration, and the impact of the breach.</li>
 	<li>Leverage a tool like the Office 365 Secure Score (<a href="https://securescore.office.com">https://securescore.office.com</a>) to manage account security configurations and behaviors.</li>
</ol>
The second key prevention mechanism is to use the fully-updated latest versions of Outlook (2013/2016) and ensuring that rule actions that can start applications/macros are disabled per the security patches. This will ensure that, even if an attacker breaches the account, the rule and form execution mechanisms will be blocked.

Patched versions are 15.0.4937.1000 or greater (Outlook 2013) and 16.0.4534.1001 or greater (Outlook 2016).  Details about the patches are here:
<ul>
 	<li>Outlook 2013 Security Patch - <a href="https://support.microsoft.com/en-us/help/3191938">https://support.microsoft.com/en-us/help/3191938</a></li>
 	<li>Outlook 2016 Security Patch - <a href="https://support.microsoft.com/en-us/help/3191883">https://support.microsoft.com/en-us/help/3191883</a></li>
</ul>
Customers with on-premises Exchange installations should consider blocking older versions of Outlook that do not have patches available. Details on this process can be found in the article “<a href="https://technet.microsoft.com/en-us/library/dd335207(v=exchg.150).aspx">Configure Outlook client blocking</a>”.

Please note that the rule mitigation is to disable the "Start Application" rule action by default. Even with the patch, it is possible for an attacker to change the local machine configuration to re-enable this. Make sure you monitor and enforce local machine policies on your clients. If you do happen to have an important business process that relies on this functionality, you can enable it for your users, but you will need to monitor your deployed user roles as per below with extra vigilance.

To determine if “Start application” is enabled via override in the registry, check for these subkeys:
<ul>
 	<li>Outlook 2016: HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Outlook\Security\</li>
 	<li>Outlook 2013: HKEY_CURRENT_USER\Software\Microsoft\Office\15.0\Outlook\Security\</li>
</ul>
If the key EnableUnsafeClientMailRules exists with a value of 1, the patch is overridden and allows the action above.  If the value is 0, the rule actions are disabled.  If a current (fixed) version of Outlook is installed and this registry key is NOT present or present and set to 0, then a system is not susceptible to the mail rule injection exploit.

The custom mail form injection exploit relies on custom code being injected into a very rarely used custom mail form feature and then executed outside the normal office macro sandbox. New versions of Outlook client prevent this code execution.
<h1>How to Detect It</h1>
There are several methods you can leverage to detect and monitor for this exploit in your organization.

<em>Using Powershell</em>

The simplest method is to leverage a Powershell script we have created which allows you to dump all of the mail forwarding rules and custom forms for all the users in your tenancy: <a href="https://github.com/OfficeDev/O365-InvestigationTooling/blob/master/Get-AllTenantRulesAndForms.ps1">https://github.com/OfficeDev/O365-InvestigationTooling/blob/master/Get-AllTenantRulesAndForms.ps1</a> . You will need to have a global admin role elevation to run the script (because it connects to every mailbox in the tenancy to read the rules and forms). It takes no parameters. The script is written for an Office 365 organization, so if you are using Exchange on-prem, you'll need to modify it. The script will produce two time-stamped CSV files: one for rules and one for forms. The rules one should be examined for action conditions that include applications or executables. Two columns in the MailboxRulesExport_DATE.csv file will help focus your search.
<ul>
 	<li>This assesses the rule to see if there is a custom action, if the action is to execute an application, or if the action is run a macro. Any of these conditions will flag the rule as being potentially malicious.</li>
 	<li>This field contains the actual execution string if the rule executes an action. If it calls a remote server, or a suspiciously named application, it is likely malicious.</li>
</ul>
<em>Using Security Researcher Toolkit</em>

Another method you can leverage is to use the defensive version of the Ruler toolkit called NotRuler, authored by the same researcher: <a href="https://github.com/sensepost/notruler">https://github.com/sensepost/notruler</a>. The author has helpfully included a list of IOCs for the Ruler toolkit: <a href="https://github.com/sensepost/notruler/blob/master/iocs.md">https://github.com/sensepost/notruler/blob/master/iocs.md</a>.

<em>Using Outlook or MFCMAPI</em>

If you are willing to do substantial spelunking one mailbox at a time, you can also leverage the Outlook client or access the mailbox database directly by using the <a href="https://github.com/stephenegriffin/mfcmapi">MFCMAPI</a> tool. While this is time consuming and can result in a breach of the machine you are using to investigate the suspected breached mailbox, it is the most straightforward and complete enumeration of the exploit in context. Use the rule management interface form outlook and examine each rule description:

<a href="https://msdnshared.blob.core.windows.net/media/2018/02/rulesdetectionviaoutlook.jpg"><img src="https://msdnshared.blob.core.windows.net/media/2018/02/rulesdetectionviaoutlook.jpg" alt="" width="957" height="813" class="alignnone size-full wp-image-3666" /></a>

Or, enable the developer tab in the Outlook client, click <em>design a form</em>, and look in the user's Inbox for custom forms. The Ruler tool will, by default, mark the custom form as hidden. Once you open the form, click "View Code" to see what the custom form actually runs:

<a href="https://msdnshared.blob.core.windows.net/media/2018/02/formsinvestigationviaoutlook.jpg"><img src="https://msdnshared.blob.core.windows.net/media/2018/02/formsinvestigationviaoutlook.jpg" alt="" width="1240" height="802" class="alignnone size-full wp-image-3615" /></a>

<a href="https://msdnshared.blob.core.windows.net/media/2018/02/formsinvestigationviaoutlookreviewcode.jpg"><img src="https://msdnshared.blob.core.windows.net/media/2018/02/formsinvestigationviaoutlookreviewcode.jpg" alt="" width="1225" height="648" class="alignnone size-full wp-image-3625" /></a>

You can also MFCMAPI to connect to the suspected breached mailbox, find the Inbox Folder, right click and open associated contents table, the look for Message Class IPM.Rule.Version2.Message (for malicious rules) and IPM.Microsoft.FolderDesign.FormsDescription (for malicious forms). Custom forms are rare enough that if you have <em>any </em>custom forms, it is worth a deeper look.

<a href="https://msdnshared.blob.core.windows.net/media/2018/02/investiationviamfcmapi.jpg"><img src="https://msdnshared.blob.core.windows.net/media/2018/02/investiationviamfcmapi.jpg" alt="" width="1532" height="914" class="alignnone size-full wp-image-3635" /></a>

Broadly speaking, you are looking for the following indicators of compromise:
<ul>
 	<li>Indicators of compromise for rules
<ul>
 	<li>Rule Action is to start an application</li>
 	<li>Rule References an EXE, ZIP, or URL</li>
 	<li>On the local machine, look for new process starts that originate from the Outlook PID</li>
</ul>
</li>
 	<li>Indicators of compromise for forms
<ul>
 	<li>Custom form present saved as their own message class</li>
 	<li>Message class contains executable code</li>
 	<li>Usually stored in Personal Forms Library or Inbox folders</li>
 	<li>Form is named IPM.Note.[custom name]</li>
</ul>
</li>
</ul>
<h1>How to Remediate It</h1>
If you discover that you have been compromised with this vector, remediation of the actual exploit is straightforward: delete the rule or form from the mailbox. You can do this with the Outlook client, MFCMapi, or using remote PowerShell to remove rules. A full remediation, however, is more in depth and looks like:
<ol>
 	<li>Remove the rule or form from the user's mailbox using Outlook, remote Powershell, or MFCMapi.</li>
 	<li>Do not allow the user to logon and use email until the full remediation process is complete.</li>
 	<li>Every machine that the user has used with Outlook will need to be cleaned of potential malware. The simplest way to accomplish this is to format and re-install everything on the machine, but if you can ensure that all malware has been removed with high confidence that might work.</li>
 	<li>Ensure that you install the most up-to-date versions of Outlook so that the vector is closed.</li>
 	<li>Once all offline copies of the mailbox have been removed, reset the user's password (ensuring it has a high-quality one set) and enable multi-factor authentication on the account to ensure the user's credentials are not exposed via other means (such as phishing or password re-use).</li>
</ol>
<em>Deleting with Outlook</em>

<a href="https://msdnshared.blob.core.windows.net/media/2018/02/rulesdetectionviaoutlook.jpg"><img src="https://msdnshared.blob.core.windows.net/media/2018/02/rulesdetectionviaoutlook.jpg" alt="" width="957" height="813" class="alignnone size-full wp-image-3666" /></a>

<em>Deleting with MFCMapi</em>

<a href="https://msdnshared.blob.core.windows.net/media/2018/02/mfcmapidelete.jpg"><img src="https://msdnshared.blob.core.windows.net/media/2018/02/mfcmapidelete.jpg" alt="" width="996" height="380" class="alignnone size-full wp-image-3665" /></a>

There are two remote powershell cmdlets you can use to remove or disable dangerous rules:
<ul>
 	<li>Remove-InboxRule: <a href="https://technet.microsoft.com/en-us/library/dd351272(v=exchg.160).aspx">https://technet.microsoft.com/en-us/library/dd351272(v=exchg.160).aspx</a></li>
 	<li>Disable-InboxRule: <a href="https://technet.microsoft.com/en-us/library/dd298120(v=exchg.160).aspx">https://technet.microsoft.com/en-us/library/dd298120(v=exchg.160).aspx</a> (use if you need to retain the rule contents for further investigation)</li>
</ul>
<h2>References</h2>
Ruler Codebase: <a href="https://github.com/sensepost/ruler">https://github.com/sensepost/ruler</a>

SilentBreak Security Post about Rules Vector: <a href="https://silentbreaksecurity.com/malicious-outlook-rules/">https://silentbreaksecurity.com/malicious-outlook-rules/</a>

Sensepost Blog about Mailrule Pwnage: <a href="https://sensepost.com/blog/2016/mapi-over-http-and-mailrule-pwnage/">https://sensepost.com/blog/2016/mapi-over-http-and-mailrule-pwnage/</a>

Sensepost Blog about Forms Threat Vector: <a href="https://sensepost.com/blog/2017/outlook-forms-and-shells/">https://sensepost.com/blog/2017/outlook-forms-and-shells/</a>

Get-AllTenantRulesAndForms.ps1: <a href="https://github.com/OfficeDev/O365-InvestigationTooling/blob/master/Get-AllTenantRulesAndForms.ps1">https://github.com/OfficeDev/O365-InvestigationTooling/blob/master/Get-AllTenantRulesAndForms.ps1</a>

MFCMAPI: <a href="https://github.com/stephenegriffin/mfcmapi">https://github.com/stephenegriffin/mfcmapi</a>

Outlook 2013 Security Patch - <a href="https://support.microsoft.com/en-us/help/3191938">https://support.microsoft.com/en-us/help/3191938</a>

Outlook 2016 Security Patch - <a href="https://support.microsoft.com/en-us/help/3191883">https://support.microsoft.com/en-us/help/3191883</a>]]></content:encoded>
    </item>
    <item>
      <title>Defending Against Illicit Consent Grants</title>
      <link>https://docs.microsoft.com/archive/blogs/office365security/defending-against-illicit-consent-grants</link>
      <pubDate>Wed, 24 Jan 2018 15:47:32 GMT</pubDate>
      <dc:creator><![CDATA[Brandon Koeller]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/office365security/?p=3495</guid>
      <description><![CDATA[Problem Overview
Office 365 Security has been tracking an emergent threat to customer data in the...]]></description>
      <content:encoded><![CDATA[<h1>Problem Overview</h1>
Office 365 Security has been tracking an emergent threat to customer data in the Office 365 cloud over the last year. This blog post is intended to help IT Administrators of Office 365 organizations detect, monitor, and remediate this threat. In its simplest form, the attack consists of an adversary creating an Azure registered application which requests access to customer data (contact information, email, documents, etc.), and then tricking an end user into granting that application consent to access their data through a phishing attack, or by injecting illicit code into a trusted website. Once the illicit application has been granted consent, it functionally has account-level access to data but without needing an actual account in the organization. Normal remediation steps like resetting passwords for breached accounts or requiring MFA on accounts is not effective since these third party applications are external to the organization and leverage an interaction model which presumes the caller is automation, and not a human.

We’ve been tracking the pattern over the last year:
<ul>
 	<li><a href="https://www.volexity.com/blog/2017/11/06/oceanlotus-blossoms-mass-digital-surveillance-and-exploitation-of-asean-nations-the-media-human-rights-and-civil-society/">https://www.volexity.com/blog/2017/11/06/oceanlotus-blossoms-mass-digital-surveillance-and-exploitation-of-asean-nations-the-media-human-rights-and-civil-society/</a></li>
 	<li><a href="https://twitter.com/ItsReallyNick/status/926086495450095617">https://twitter.com/ItsReallyNick/status/926086495450095617</a></li>
 	<li><a href="https://blog.trendmicro.com/trendlabs-security-intelligence/pawn-storm-abuses-open-authentication-advanced-social-engineering-attacks/">https://blog.trendmicro.com/trendlabs-security-intelligence/pawn-storm-abuses-open-authentication-advanced-social-engineering-attacks/</a></li>
</ul>
We have also became aware of public proof of concept exploits created by security researchers which also leverage the model: <a href="https://blog.knowbe4.com/heads-up-new-ransomware-strain-encrypts-cloud-email-real-time-video">https://blog.knowbe4.com/heads-up-new-ransomware-strain-encrypts-cloud-email-real-time-video</a>.

The good news is that this attack pattern is detectable and can be remediated in the Office 365 ecosystem.
<h1>Monitoring and Detection</h1>
Since the attack pattern used in the wild is non-deterministic, most detection activities will require some kind of human intervention for now. Organizational Administrators should first understand what their current exposure is by enumerating all of the applications that have access to their data. To accomplish this, there are two patterns that can be employed: using powershell, and using the Azure Active Directory Portal.
<h2>Enumerating applications with access in your organization with powershell</h2>
The simplest way is to run the below powershell script which will dump all the oauth consent grants and app permissions for all users in your tenancy:
<ul>
 	<li><a href="https://gist.github.com/psignoret/41793f8c6211d2df5051d77ca3728c09">https://gist.github.com/psignoret/41793f8c6211d2df5051d77ca3728c09</a></li>
</ul>
You will need to ensure you have the AzureAD powershell cmdlet library installed and that you have connected to your directory with the <a href="https://docs.microsoft.com/en-us/powershell/module/azuread/connect-azuread?view=azureadps-2.0">Connect-AzureAD </a>commandlet. We highly recommend you require multi-factor authentication on your administrative account and this script will support MFA auth. You can execute the scripts as follows:
<ul>
 	<li><span>.\Get-AzureADPSPermissions.ps1 | Export-Csv -Path "permissions.csv" -NoTypeInformation</span></li>
</ul>
Once you have successfully executed the script, it will produce one local CSV file. To look for illicit applications, you should review the contents as follows:
<ul>
 	<li>Review the consents that are of ConsentType of 'AllPrincipals'. These permissions allow the client application to access everyone's content in the tenancy. Several are native O365 applications and are needed to work correctly, but non-Microsoft applications should be reviewed carefully.</li>
 	<li>Review the discrete permissions that each delegated permission or application has to content. Permissions that grant Read and Write permission or *.All should be reviewed carefully for appropriateness.</li>
 	<li>Review the specific users that have consents granted. If high profile or high impact users have inappropriate consents granted, you should investigate further.</li>
 	<li>Review ClientDisplayName for apps that seem suspicious. Apps with mispelled names, super bland names, or hacker-sounding names should be reviewed carefully.</li>
</ul>
Depending on the size of your organization, we recommend at least a weekly review of the most recent consent grants. Another approach to finding consent grant events is to search in the Security and Compliance Center's Audit Log Search. Look for activity called 'Consent to application' and 'Add OAuth2PermissionGrant'. In particular, be on the lookout for IsAdminConsent: True in the Extended Properties as this indicates one of your Global Admins may have granted broad access to data.

<a href="https://msdnshared.blob.core.windows.net/media/2018/01/auditlogsearch.jpg"><img src="https://msdnshared.blob.core.windows.net/media/2018/01/auditlogsearch.jpg" alt="" width="1920" height="949" class="alignnone size-full wp-image-3505" /></a>
<h2>Enumerating applications with access in your organization with the Azure Active Directory Portal</h2>
The other pattern you can leverage to find illicit applications is to use the Azure Active Directory Portal: <a href="https://portal.azure.com">https://portal.azure.com</a>. If you navigate to the Azure Active Directory blade, select all users, select the user you wish to review the applications that have access to that user's data, then select Applications, you'll be able to see what has privileges. Unfortunately, the only view currently available via the portal is on a per-user basis.

<a href="https://msdnshared.blob.core.windows.net/media/2018/01/azureportallisting.jpg"><img src="https://msdnshared.blob.core.windows.net/media/2018/01/azureportallisting.jpg" alt="" width="1280" height="740" class="alignnone size-full wp-image-3515" /></a>

Look for Name, Publisher, Date Assigned and Permissions granted for suspicious indicators.

<a href="https://msdnshared.blob.core.windows.net/media/2018/01/azurepermsandconsent.jpg"><img src="https://msdnshared.blob.core.windows.net/media/2018/01/azurepermsandconsent.jpg" alt="" width="1136" height="799" class="alignnone size-full wp-image-3525" /></a>

The final method you can leverage is to have your users individually go to <a href="https://myapps.microsoft.com">https://myapps.microsoft.com</a> and review their own application access there. They should be able to see all the apps with access, view details about them, including the scope of access, and be able to revoke privileges to suspicious or illicit apps.

<a href="https://msdnshared.blob.core.windows.net/media/2018/01/myapps.jpg"><img src="https://msdnshared.blob.core.windows.net/media/2018/01/myapps.jpg" alt="" width="1188" height="488" class="alignnone size-full wp-image-3535" /></a>

<a href="https://msdnshared.blob.core.windows.net/media/2018/01/appremove.png"><img src="https://msdnshared.blob.core.windows.net/media/2018/01/appremove.png" alt="" width="318" height="210" class="alignnone size-full wp-image-3555" /></a>

<a href="https://msdnshared.blob.core.windows.net/media/2018/01/appdetails.png"><img src="https://msdnshared.blob.core.windows.net/media/2018/01/appdetails.png" alt="" width="561" height="264" class="alignnone size-full wp-image-3545" /></a>
<h2>Managing applications with access in your organization with Microsoft Cloud App Security (MCAS)</h2>
The most complete solution to managing this risk can be achieved if you are a <a href="https://www.microsoft.com/en-us/microsoft-365/enterprise/home">Microsoft 365 Enterprise E5</a> subscriber, or you have purchased <a href="https://docs.microsoft.com/en-us/cloud-app-security/">Microsoft Cloud App Security</a> (MCAS) as a standalone product. MCAS has detection, investigation, and remediation workflows built directly into the product. You can find more details about how this works here: <a href="https://docs.microsoft.com/en-us/cloud-app-security/manage-app-permissions">https://docs.microsoft.com/en-us/cloud-app-security/manage-app-permissions</a>

<a href="https://msdnshared.blob.core.windows.net/media/2018/01/casprotection.png"><img src="https://msdnshared.blob.core.windows.net/media/2018/01/casprotection.png" alt="" width="1258" height="608" class="alignnone size-full wp-image-3585" /></a>
<h1><strong>Remediation</strong></h1>
Once you have identified an application with illicit permissions, you have several ways to remove that access.

You can revoke the Oauth consent grant with powershell: <a href="https://docs.microsoft.com/en-us/powershell/module/azuread/Remove-AzureADOAuth2PermissionGrant?view=azureadps-2.0">https://docs.microsoft.com/en-us/powershell/module/azuread/Remove-AzureADOAuth2PermissionGrant?view=azureadps-2.0</a>

You can revoke the Service App Role Assignment with powershell: <a href="https://docs.microsoft.com/en-us/powershell/module/azuread/Remove-AzureADServiceAppRoleAssignment?view=azureadps-2.0">https://docs.microsoft.com/en-us/powershell/module/azuread/Remove-AzureADServiceAppRoleAssignment?view=azureadps-2.0</a>

You can revoke the application's permission in the Azure Active Directory Portal by navigating to the affected user in the Azure Active Directory User blade, selecting Applications, selecting the illicit application, then clicking 'Remove' in the drill down:

<a href="https://msdnshared.blob.core.windows.net/media/2018/01/azureportalremove.png"><img src="https://msdnshared.blob.core.windows.net/media/2018/01/azureportalremove.png" alt="" width="1880" height="1450" class="alignnone size-full wp-image-3565" /></a>

You can also disable logon to the affected account altogether, which will in turn disable app access to data in that account. This isn't ideal for the end user's productivity, of course, but if you are working to limit impact quickly, it can be a viable short term remediation.

Finally, there is one very coarse grained capability in Office 365 that will allow you to prevent your users from inadvertently granting access to a malicious application. You can turn integrated applications off in your tenancy. This isn't strongly recommended as it severely impairs your users' ability to be productive with third party applications, but you can disable the ability for end users to grant consent on a tenant-wide basis: <a href="https://support.office.com/en-us/article/Turning-Integrated-Apps-on-or-off-7e453a40-66df-44ab-92a1-96786cb7fb34">https://support.office.com/en-us/article/Turning-Integrated-Apps-on-or-off-7e453a40-66df-44ab-92a1-96786cb7fb34</a>

<a href="https://msdnshared.blob.core.windows.net/media/2018/01/disableintegratedapps.png"><img src="https://msdnshared.blob.core.windows.net/media/2018/01/disableintegratedapps.png" alt="" width="2385" height="1469" class="alignnone size-full wp-image-3575" /></a>

The final set of activities you will have to undertake is to perform an investigation against activity data to determine the full scope of the breach. You can use the Security &amp; Compliance Center’s audit log search to accomplish this task. Focus your search on the affected users, the time frames that the illicit application had access, and the permissions that the app had access to. Please make sure you have both mailbox auditing as well as global activity auditing enabled.

<a href="https://support.office.com/en-us/article/Search-the-audit-log-in-the-Office-365-Security-Compliance-Center-0d4d0f35-390b-4518-800e-0c7ec95e946c">https://support.office.com/en-us/article/Search-the-audit-log-in-the-Office-365-Security-Compliance-Center-0d4d0f35-390b-4518-800e-0c7ec95e946c</a>

<strong>Reference Documentation</strong>

This article walks admins through various actions they may want to take after realizing there are unexpected applications with access to data: <a href="https://docs.microsoft.com/en-us/azure/active-directory/application-access-unexpected-application">https://docs.microsoft.com/en-us/azure/active-directory/application-access-unexpected-application </a>

Here is a high level overview doc on consent and permissions: <a href="https://docs.microsoft.com/en-us/azure/active-directory/active-directory-apps-permissions-consent">https://docs.microsoft.com/en-us/azure/active-directory/active-directory-apps-permissions-consent </a>

There is another overview here, which is part of an article on our app model all up which includes various code samples and walkthroughs: <a href="https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-integrating-applications#overview-of-the-consent-framework">https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-integrating-applications#overview-of-the-consent-framework</a>

Here is a content map that links to various consent-related articles: <a href="https://docs.microsoft.com/en-us/azure/active-directory/active-directory-application-dev-development-content-map">https://docs.microsoft.com/en-us/azure/active-directory/active-directory-application-dev-development-content-map</a>

This article gives a good overview of the Application and Service principal objects that are core to our app model: <a href="https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-application-objects">https://docs.microsoft.com/en-us/azure/active-directory/develop/active-directory-application-objects</a>

Here is an overview of the capabilities admins have to manage user access to apps: <a href="https://docs.microsoft.com/en-us/azure/active-directory/active-directory-managing-access-to-apps">https://docs.microsoft.com/en-us/azure/active-directory/active-directory-managing-access-to-apps</a>]]></content:encoded>
    </item>
    <item>
      <title>Managing asset inventory in Office 365</title>
      <link>https://docs.microsoft.com/archive/blogs/office365security/managing-asset-inventory-in-office-365</link>
      <pubDate>Thu, 21 Dec 2017 21:56:47 GMT</pubDate>
      <dc:creator><![CDATA[Matt Swann - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/office365security/?p=3486</guid>
      <description><![CDATA[In Office 365, servers are continuously provisioned and destroyed as the service is upgraded and...]]></description>
      <content:encoded><![CDATA[In Office 365, servers are continuously provisioned and destroyed as the service is upgraded and scaled to meet customer demand. To assess the coverage of our security monitoring and patch management processes, we needed an asset inventory system that met the following criteria:
<ol>
 	<li>The system must ascertain the current state of the fleet accurate to within the last hour</li>
 	<li>The system must allow engineers to ask new questions of the fleet without a redeployment</li>
 	<li>The system must handle assets that have been torn down or renamed without returning stale or “ghost” results</li>
 	<li>The system must be able to identify assets which are online but for which state information could not be returned</li>
 	<li>The system must scale to many hundreds of thousands of machines and dozens of queries while maintaining performance and reliability</li>
</ol>
We met this challenge by deploying a lightweight agent to each node and an Azure web service which stores data in Cosmos DB and Redis.
<h3>Agent deployment and check-in</h3>
The inventory agent is installed on each physical and virtual machine during deployment.

When the agent starts up, it looks in the Windows registry for a unique ID that identifies the machine. If one does not exist, it generates one and stores it. This ID ensures that each machine is associated with only one inventory entry even if it is renamed or moved between Active Directory domains.

The agent checks in with the inventory service hourly. At startup, the agent sleeps for a random interval between 0 and 60 minutes before the first check-in to ensure that requests to the Azure web service are evenly distributed across the fleet.

During each check-in, the agent:
<ul>
 	<li>Requests a list of WMI and registry queries from the Azure web service</li>
 	<li>Performs those queries locally</li>
 	<li>Reports machine metadata and query results to the web service</li>
</ul>
<h3>Inventory queries</h3>
Engineers add WMI and registry queries to the system using PowerShell cmdlets. These queries are stored in <a href="https://azure.microsoft.com/en-us/services/storage/tables/">Azure Table storage</a> using the query type as the partition key and a query ID as the row key.

A WMI query is defined by the query statement, the WMI namespace under which to perform the query, and a list of property names to return values for:
<pre>
<table>
<tbody>
<tr>
<td width="102">Id</td>
<td width="474">antimalware_details</td>
</tr>
<tr>
<td width="102">Query</td>
<td width="474">SELECT * FROM AntiMalwareHealthStatus</td>
</tr>
<tr>
<td width="102">Namespace</td>
<td width="474">root\Microsoft\SecurityClient</td>
</tr>
<tr>
<td width="102">Properties</td>
<td width="474">AntivirusEnabled, AntivirusSignatureAge, AntivirusSignatureVersion, …</td>
</tr>
</tbody>
</table>
</pre>

Likewise, a registry query is defined by the registry hive, the registry path, and a list of value names to return values for:
<pre>
<table>
<tbody>
<tr>
<td width="102">Id</td>
<td width="400">lsass_ppl</td>
</tr>
<tr>
<td width="102">Hive</td>
<td width="400">HKLM</td>
</tr>
<tr>
<td width="102">Query</td>
<td width="400">SYSTEM\CurrentControlSet\Control\Lsa</td>
</tr>
<tr>
<td width="102">ValueNames</td>
<td width="400">RunAsPPL</td>
</tr>
</tbody>
</table>
</pre>

Registry paths may contain wildcards which are expanded on the agent to handle cases where a unique ID (such as a network interface ID or certificate thumbprint) is part of the path:
<pre>SYSTEM\CurrentControlSet\services\NetBT\Parameters\Interfaces\*</pre>
<h3>Inventory results</h3>
WMI and registry results are returned as a list of result instances where each instance is a dictionary of name/value pairs. For example, consider a WMI query that selects all IP addresses assigned to the machine:
<pre>SELECT IPAddress FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = 'true'</pre>
This returns one result instance per network adapter, each of which contains one key/value pair for the IPAddress property:
<pre>[
    {"IPAddress": ["192.168.1.14", "fe80::7cbe:6ae:becf:93ad"]},
    {"IPAddress": ["10.0.0.14", "fe80::e14e:dbd6:df43:cfbc"]}
]</pre>
In addition to reporting these query results to the web service, the inventory agent reports machine metadata as well:
<ul>
 	<li>The machine’s name, domain, and IP addresses</li>
 	<li>The machine’s uptime and OS image age in hours</li>
 	<li>The agent version</li>
 	<li>The time it took to perform the WMI and registry queries</li>
 	<li>Any exceptions that occurred when executing the queries</li>
</ul>
<h3>Result storage</h3>
Machine metadata is stored in <a href="https://azure.microsoft.com/en-us/services/cosmos-db/">Azure Cosmos DB</a>. The unique ID associated with the machine serves as both the ID and the partition key to ensure that updates from the same machine never generate multiple entries. Cosmos DB automatically indexes property values as documents are inserted or updated, allowing engineers to rapidly locate a machine given an IP address, machine name, or range of uptime.

However, we encountered scale limits when we used Cosmos DB to store query results. As the number of registry and WMI queries increased, our upsert operations were impacted by throttling because our workload put O(M*N) demands on the indexing system, where M is the number of machines checking in each minute and N is the number of result instances and properties that are returned by each machine.

Instead, we built our own inverted index in <a href="https://azure.microsoft.com/en-us/services/cache/">Azure Redis Cache</a>. We use a set to track the values observed for each WMI property or registry value name – one entry per distinct value. For each value, we create another set to record the machines that returned that value. If a machine does not return a result for a given query, we track that too. This allows us to identify machines that are missing security-critical processes.

We incorporate the hour (0-23) into each key so that we can update the current hour’s results while locating last hour’s results. When engineers need to identify machines with a specific value, we union the current hour’s results and last hour’s results to ensure that every machine is represented, even if it has not yet checked in this hour. We apply a 2-hour expiration to each Redis set to ensure that memory use stays bounded.

We take advantage of async support in the <a href="https://stackexchange.github.io/StackExchange.Redis/">StackExchange.Redis</a> library to <a href="https://stackexchange.github.io/StackExchange.Redis/PipelinesMultiplexers">pipeline</a> our requests, allowing a small number of Azure web roles to perform roughly 30k Redis operations per second.
<h3>Locating missing agents</h3>
When assessing the health of the fleet, we not only need to identify machines that are reporting an unhealthy result – we also need to identify machines that are online but not running the inventory agent.

We solved this by having the inventory agents listen for incoming connections on a TCP port, and having them periodically perform a limited port scan against their neighbors on the same /24 subnet.

Each neighbor may be in one of three states:
<ul>
 	<li><strong>Healthy</strong>: It accepts connections on the inventory agent port</li>
 	<li><strong>Zombie</strong>: It does not accept connections on the inventory agent port, but it does accept connections on well-known Windows posts like SMB or RDP</li>
 	<li><strong>Offline</strong>: It does not accept connections on the inventory agent port nor other Windows ports</li>
</ul>
Zombie IP addresses are tracked in Redis for remediation.

To limit network traffic, each inventory agent scans its neighbors once each day. The agent uses the last octet of the machine’s current IP address modulo 24 to identify the hour in which it will perform a scan:
<pre>int scanHour = ipAddress[3] % 24;
bool shouldScan = (DateTime.UtcNow.Hour == scanHour);</pre>
On a fully-saturated /24 subnet, 11 machines will scan the subnet every hour – a scan every 5 minutes. On a subnet where only one agent is online, one scan per day will be performed.
<h3>Remediating unhealthy machines</h3>
Once the inventory system was deployed across the fleet, we used it to build a system which automatically reimages and redeploys machines that do not meet our security requirements.

First, we added inventory queries that measure the security health of the fleet:
<ul>
 	<li>Are our security and telemetry agents running?</li>
 	<li>Is AV running? Are the signatures fresh? Is real-time monitoring enabled?</li>
 	<li>Is the firewall running?</li>
 	<li>Is the machine uptime &lt;30d?</li>
 	<li>Is device firmware fully patched?</li>
</ul>
Next, we wrote a recurring job that fetches machines from the inventory system that do not meet these criteria and enqueues them for remediation. Remediation is handled by a separate system that reimages virtual and physical machines while maintaining high availability and a minimum set of redundant resources in each capacity unit.

To measure the effectiveness of this system, we created an Azure Logic App which periodically snapshots these health results and stores them in an Azure SQL database. We use Power BI to query this database for servers which have been persistently unhealthy for multiple hours. When the recurring job and replacement systems are properly functioning, the number of persistently unhealthy servers trends toward single digit numbers even in a fleet of hundreds of thousands.
<h3>Summary</h3>
In Office 365, we use a distributed inventory system to assess the security health of the fleet. This gives our engineers the ability to rapidly ask questions of the entire environment, and it drives a system which automatically reimages machines which are in an unhealthy state or whose state cannot be determined. This helps us maintain the security health of our fleet even as it scales to multiple hundreds of thousands of servers.

We continue to improve the systems that manage and secure our fleet at cloud scale. If you have questions, suggestions, or comments, I'd love to hear from you! Feel free to reach me on Twitter at <a href="https://twitter.com/MSwannMSFT">@MSwannMSFT</a>.]]></content:encoded>
    </item>
    <item>
      <title>Using Frequency Analysis to Defend Office 365</title>
      <link>https://docs.microsoft.com/archive/blogs/office365security/using-frequency-analysis-to-defend-office-365</link>
      <pubDate>Sun, 17 Sep 2017 11:41:35 GMT</pubDate>
      <dc:creator><![CDATA[Evan Zheng [MSFT]]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/office365security/?p=3345</guid>
      <description><![CDATA[As security threats evolve, so must defense. In Office 365, we have engineering teams dedicated to...]]></description>
      <content:encoded><![CDATA[As security threats evolve, so must defense. In Office 365, we have engineering teams dedicated to building intrusion detection systems that protect customer data against new and existing threats. In this blog, we are talking about a security monitoring challenge of cloud services and our recent attempt to solve it.

Let us start with two scenarios. In the first scenario, an adversary sneakily adds or updates a registry key to run his malware automatically. In the second scenario, an adversary sneakily injects a malicious DLL into a long running legitimate process to maintain a persistent backdoor. The traditional signature-based detections work well for known threats. To detect unknown threats, scheduled frequency analysis across machines is a practical approach, since it is unlikely that a malicious registry key or loaded DLL will be present on most of systems in our fleet. However, this approach usually requires collecting more monitoring data. For example, if we are capturing a daily snapshot of loaded DLLs for all running processes, we could easily log 10,000 events per machine per day. What if there are more similar detections? The data volume will stress our logging, uploading and analytics infrastructures.

To meet this challenge, we developed a "prevalence system" that enables us to identify common registry keys and DLL paths across our fleet and reduce the volume of data that must be logged. In the first part of this post, we present an initial prototype. In the following three parts, we discuss our solutions to three critical weaknesses in the initial prototype. Finally, we share some results of our experiments.
<h3>Initial Prototype</h3>
Our security agent periodically snapshots registry key values and loaded DLLs. Since most entries are the same across our fleet, we would like our agent to only log those that are unique to that machine. We call this measurement "prevalence". The system must maintain a secure, reliable, up-to-date list of prevalent entries. We call this the “prevalence web service”.

As shown in Figure 1, the initial prototype is not complicated and is comprised of three parts: prevalence web service, security monitoring agent and map/reduce system. The security agent is responsible for periodically outputting a snapshot of loaded DLLs. It calls the prevalence web service and retrieves a list of prevalent DLL paths. Next, it removes these prevalent DLL paths from the snapshot and only logs the DLL paths that are not in the list. Then those logged events are uploaded to security event hub. Map/reduce jobs determine which paths are prevalent across the fleet and which paths are uncommon. These newly-identified prevalent paths are uploaded to prevalence web service.

<a href="https://msdnshared.blob.core.windows.net/media/2017/09/Prevalence-System1.png"><img src="https://msdnshared.blob.core.windows.net/media/2017/09/Prevalence-System1.png" alt="Initial Prototype of Prevalence System" width="90%" height="auto" class="wp-image-3445 size-full aligncenter" /></a>

The overall design is trivial. But there are several critical problems to solve to ensure the system is reliable. One critical and common scenario is what to do when prevalence web service is unavailable. Another challenge with the prototype is how to maintain a relatively small prevalence list. Moreover, how to reduce detection false-positive is also important.
<h3>Round-Robin Logging</h3>
There are many reasons why the prevalence web service may be unavailable. For example, a network connectivity issue may prevent the service from being reached. Moreover, the prevalence web service might be under upgrade and be unavailable for all clients.

When the prevalence web service is unavailable, the agent could choose to log every entry (treating all of them as anomalous) or log no entries (treating all of them as prevalent). If we simply skip logging all snapshot events, then we lose coverage for that detection. The goal is to find a balance between resources and detection coverage. We implemented a consistent round-robin approach for event logging when prevalence is unavailable.

Suppose we have 1600 different loaded DLLs for all running processes in machine A. We would like to split these events into 16 buckets where every bucket has 100 events. Bucket 0 will be logged in day 1; bucket 1 will be logged in day 2 …; bucket 15 will be logged in day 16. One cycle completes in 16 days. A given entry will be logged exactly once in a 16-day cycle.

<a href="https://msdnshared.blob.core.windows.net/media/2017/09/Round-Robin-Logging.png"><img src="https://msdnshared.blob.core.windows.net/media/2017/09/Round-Robin-Logging.png" alt="Round-robin logging when prevalence is unavailable" width="75%" height="auto" class="size-full wp-image-3455 aligncenter" /></a>

The event-bucket mapping algorithm needs to be consistent. First, it must map the events uniformly into different buckets. We could use the .NET GetHashCode() method to uniformly hash DLL paths. However, this hash code is not guaranteed to be unique across machines. We need an algorithm that maps the same DLL path to the same bucket on every machine. This ensures that the same DLL will be uploaded to map/reduce systems on the same day so that the frequency analysis is reliable. We chose to use a cryptographic hash since it will return the same value for a given path on every machine.
<h3>Trimming the Prevalence List</h3>
Another challenge is the size of the prevalence list. The DLL list will grow as new versions of services are deployed. Storing a growing prevalence list in prevalence server is not a problem. However, fetching an ever-growing prevalence list will lead to network and memory pressure in the security monitoring agent.

One approach is to record the current timestamp when each prevalence entry is added to the service, and design the web method to only retrieve recent entries. However, these prevalent DLL paths will not be logged once they have been uploaded to the prevalence service. They will not be identified as prevalent entries again by the map/reduce jobs in the security event hub (see Figure 1). So, their timestamps will not be updated in the prevalence web service and they will become stale finally.

One solution is to log a subset of DLLs even if they are on the prevalence list. As shown in Figure 3, we use the round-robin event logging technique mentioned in the previous section when the DLL matches a prevalence entry. Then 1/16<sup>th</sup> of prevalence entries will be logged and uploaded to event hubs every day consistently. The timestamp of these entries in prevalence service will be updated every 16 days. Finally, we could ensure those ever-prevalent DLL paths always stay in prevalence web service with recent timestamps.

<a href="https://msdnshared.blob.core.windows.net/media/2017/09/Prevalent-Entry.png"><img src="https://msdnshared.blob.core.windows.net/media/2017/09/Prevalent-Entry.png" alt="Round-robin logging of prevalent entries" width="55%" height="auto" class="size-full wp-image-3435 aligncenter" /></a>
<h3>Reducing False-Positive</h3>
False-positive results can severely limit an intrusion detection system’s effectiveness. Random GUIDs and version numbers present in registry and DLL paths present a challenge for systems based on frequency analysis. One solution is to normalize registry and DLL paths by removing these portions. Another approach would be to compare against historical data and only flag those which randomly appear in history.
<h3>Reducing Event Volume</h3>
The prevalence system significantly reduces the amount of data we log for loaded DLLs and registry values. In our fleet of over 100,000 systems, this approach reduced the logging volume by 75%.

With the help of the prevalence system, we can now build high-fidelity detections for generic DLL side loading, phantom DLL hijacking and registry hijacking. The prevalence system can be applied to other scenarios where a large volume of similar events need to be captured from a large fleet of similar machines.
<h3>Conclusion</h3>
To better defend Office 365, we are constantly improving the techniques we use to identify unauthorized activities in our datacenter. This prevalence approach allows us to increase the amount of data that we analyze without overwhelming our telemetry pipeline. We are still iterating on this approach - if you have feedbacks or suggestions, we would love to hear from you.]]></content:encoded>
    </item>
    <item>
      <title>Mitigating Client External Forwarding Rules with Secure Score</title>
      <link>https://docs.microsoft.com/archive/blogs/office365security/mitigating-client-external-forwarding-rules-with-secure-score</link>
      <pubDate>Tue, 25 Jul 2017 12:16:59 GMT</pubDate>
      <dc:creator><![CDATA[Stu-Clark]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/office365security/?p=3276</guid>
      <description><![CDATA[Client created rules, that Auto-Forward email from users mailboxes to an external email address, are...]]></description>
      <content:encoded><![CDATA[Client created rules, that Auto-Forward email from users mailboxes to an external email address, are becoming an increasingly common and fruitful data exfiltration method being used by bad actors today and something we see quite a lot of in the Office 365 Service.

There are a lot of legitimate reasons for using rules that externally Auto-Forward email, such as mergers an acquisitions etc. However they also represent a risk that needs careful and vigilant management by the admins of your tenant to ensure they are not being misused.

These rules can be created through several interfaces, a desktop client, Outlook Web Access even an admin can use PowerShell to implement via the 'New-InboxRule' cmdlet. Users themselves are often unaware of the rules they have in place (lets face it, who in their desktop client regularly reviews their own rules?) so it is very easy to miss them, either accidentally created rules that Auto-Forward externally or intentionally created rules created by a bad actor after compromising an end users account or breaching a high privileged account such as the tenant admin.

One of the most recent scenarios we have seen, involved a bad actor compromising a tenant admin account, the tenant had Auto-Forward disabled on the default (*) Remote Domain, which offered some protection from client rules externally forwarding email, however the bad actor then created a new Remote Domain, with the namespace of where they wished to exfiltrate data to, enabled the Remote Domain to allow Auto-Forward emails and voila, started to implement client rules that would then Auto-Forward to that namespace.
<h1><a></a>Mitigation</h1>
The Office 365 service, does offer you a myriad of built in ways to control the impact of Auto-Forwarded email to external addresses, like all good security measures, you will likely need a combination of all/some of these to adopt the security posture that your organization feels is appropriate for your needs, defense in depth is key as always:
<ol>
 	<li><strong>Remote Domains</strong> - If you as an Organization do not want to allow Auto-Forward emails at all, ensure the setting 'Allow automatic forwarding' is disabled on your Remote Domain settings, such as 'Set-RemoteDomain Default -AutoForwardEnabled $false' or via the Admin Center.  Also ensure you are reviewing this as part of your scheduled security reviews, you should be checking the Default Remote Domain and other Remote Domains you may have active have your desired settings in place. A compromised tenant admin account, could see these settings altered.</li>
 	<li><strong>Review Client Auto Forwarding Rules</strong> - Half the challenge in developing any security posture is understanding your Organizations risk and exposure. Using a script called 'DumpDelegatesandForwardingRules.ps1'from here  <a href="https://github.com/OfficeDev/O365-InvestigationTooling">https://github.com/OfficeDev/O365-InvestigationTooling</a> will allow you to perform an audit of just how many of your clients have rules that Auto-Forward externally. This script can take a while to complete, as it iterates through each mailbox to check the rules (rules are stored in a users mailbox as a hidden item).</li>
 	<li><strong>RBAC</strong> - You can use RBAC to limit the impact as well, by adding a new management role based of the MyBaseOptions and restricting the parameters DeliverToMailboxAndForward, ForwardingAddress, ForwardingSmtpAddress.</li>
 	<li><strong>Transport Rules</strong> -  We have another tool at our disposal here, by using a Transport Rule. Implementing a Transport Rule based around the following can stop emails that are set to be Auto-Forwarded to an external address. In summary you create a rule based on the following logic. IF The Sender is located ‘Inside the organization’ AND IF The Recipient is located ‘Outside the organization’ AND IF The message type is ‘Auto-Forward’ THEN Reject the message with the explanation ‘External Email Forwarding via Client Rules is not permitted’. This will stop delivery of the Auto-Forward message and issue an NDR as the cherry on top. There are numerous great blog articles out there on how to achieve this.</li>
</ol>
<h1><a></a>How Can Secure Score Help?</h1>
Using Secure Score <a href="https://securescore.office.com">https://securescore.office.com</a> helps increase your organization’s security by encouraging you to use the built-in security features in Office 365 (many of which you already purchased but might not be aware of).

We have implemented a new Security Control in Secure Score called '<span>Client Rules Forwarding Blocks'. It basically takes mitigation 4 from above and turns that into a one click experience, allowing you to quickly implement a Transport Rule to help mitigate client created rules that Auto-Forward to external addresses. By using this control it will allow you create the Transport Rule above, you can then subsequently tweak the rule directly, for example if you wished to change the NDR text. This feature is now live within Secure Score.</span>

You can find this Security Control in the Advanced Action section of your queue.

<a href="https://msdnshared.blob.core.windows.net/media/2017/07/rules.png"><img src="https://msdnshared.blob.core.windows.net/media/2017/07/rules.png" alt="" width="780" height="249" class="alignnone wp-image-3286" /></a>

So, there we go some steps you can take to help mitigate the risk of managing Client External Forwarding Rules within your Organization. Remember, a layered approach is key to helping adopt your Organizations security posture.]]></content:encoded>
    </item>
    <item>
      <title>Hidden Treasure: Intrusion Detection with ETW (Part 2)</title>
      <link>https://docs.microsoft.com/archive/blogs/office365security/hidden-treasure-intrusion-detection-with-etw-part-2</link>
      <pubDate>Tue, 09 May 2017 20:19:19 GMT</pubDate>
      <dc:creator><![CDATA[Zac Brown [MSFT]]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/office365security/?p=3245</guid>
      <description><![CDATA[In our last post, we discussed how Event Tracing for Windows (ETW) provides a wealth of knowledge in...]]></description>
      <content:encoded><![CDATA[In our <a target="_blank" href="https://blogs.technet.microsoft.com/office365security/hidden-treasure-intrusion-detection-with-etw-part-1/">last post</a>, we discussed how Event Tracing for Windows (ETW) provides a wealth of knowledge in addition to what’s available from the Windows Security Event Log. While we can gain increased insight into Windows activity, ETW was originally meant as a high-volume debug trace. Without some mechanism for filtering or reducing event volume, our SIEM won’t be able to keep up. In this post we will discuss the ways in which you can consume ETW and then talk about filtering and reducing event volume efficiently.

<strong>Consuming ETW</strong>

ETW can be consumed in two primary ways. You can generate an ETL file using tools like xperf.exe or logman.exe. After you’ve created the ETL file, you can load it into a program like Windows Performance Analyzer or PerfView and review the events. This is how Microsoft engineers review power management issues and measure performance of Windows subsystems.

Alternatively, you can write a program to consume ETW events in real-time with an ETW API like the <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/bb968803(v=vs.85).aspx">Win32 Event Tracing APIs</a>. This is how xperf.exe and logman.exe consume ETW events. All programs consuming ETW in real-time follow the same pattern:
<ul>
 	<li>create a trace session</li>
 	<li>enable an ETW provider (e.g. DNS events) on the trace session</li>
 	<li>setup a callback to handle the events</li>
 	<li>start the trace</li>
 	<li>process events for a period</li>
 	<li>stop the trace</li>
</ul>
We might consider generating ETL files with the activity we are interested in, then post-processing them off box. The post-processing could be as simple as reading the ETL file and forwarding each event on to our SIEM. Unfortunately, the volume of data generated by even a small number of ETW providers would likely overwhelm the SIEM, producing gigabytes of data per minute. There are ways to filter ETW providers when generating ETL files, but flexibility is limited. To handle such a huge amount of data, we need to aggressively filter and aggregate the data coming from our ETW trace in real time.

<strong>Consuming ETW in Real-Time</strong>

There are a few APIs available for consuming ETW in real-time:
<ol>
 	<li><a href="https://msdn.microsoft.com/en-us/library/windows/desktop/bb968803(v=vs.85).aspx">Win32 TDH Event Tracing</a> API (native C/C++)</li>
 	<li><a href="https://github.com/vancem/perfview/tree/master/src/TraceEvent">TraceEvent</a> (.NET)</li>
 	<li><a href="https://msdn.microsoft.com/en-us/library/system.diagnostics.tracing(v=vs.110).aspx">Diagnostics.Tracing</a> (.NET)</li>
 	<li><a href="https://github.com/microsoft/krabsetw">krabsetw</a> (.NET &amp; native C++)</li>
</ol>
The TDH APIs are what all ETW APIs ultimately call. While they offer a great deal of power, they’re still Win32-style APIs that are cumbersome to use. TraceEvent is a library used by the PerfView tool and has the benefits of being a well-designed .NET API. Unfortunately, it doesn’t perform well for scenarios where we want to keep memory usage to a minimum. System.Diagnostics.Tracing has the advantage of being part of the .NET BCL but we’ve observed intermittent exceptions and unexpected behavior in the past. Additionally, it suffers from the same memory consumption issue that TraceEvent does.

In response to these challenges, Office 365 Security chose to implement our own API with three primary goals:
<ul>
 	<li>Intuitive and flexible API</li>
 	<li>High performance – filtering events in the native layer</li>
 	<li>Available both in .NET and native C++</li>
</ul>
The result of this work is <a href="https://github.com/microsoft/krabsetw">krabsetw</a>, a library we’ve open-sourced under the MIT license. It contains both a native C++ API as well as a .NET API. This library is used in production today across Office 365 workloads on more than 100,000 machines. With filtering, we’re able to process more than more than 500 billion events per day, generating more than 7TB of data per day across the machines.

<strong>Real-time ETW with krabsetw</strong>

Let’s look at how we can use krabsetw to monitor DNS resolutions via the DNS ETW trace in real time. The simplest program using krabsetw consists of three steps:
<ul>
 	<li>Create the object that represents the ETW provider we want to listen to</li>
 	<li>Register a callback to handle events</li>
 	<li>Create a trace session and enable the provider object with it</li>
</ul>
While this is the simplest program, it’s missing filtering which we’ve already called out as an important detail for consuming ETW in real-time. Here’s an example:
<pre>using System;
using O365.Security.ETW;

namespace hiddentreasure_etw_demo
{
    class Program
    {
        static void Main(string[] args)
        {
            var filter = new EventFilter(Filter
                .EventIdIs(3018)
                .Or(Filter.EventIdIs(3020)));

            filter.OnEvent += (IEventRecord r) =&gt; {
                var query = r.GetUnicodeString("QueryName");
                var result = r.GetUnicodeString("QueryResults");
                Console.WriteLine($"DNS query ({r.Id}): {query} - {result}");
            };

            var provider = new Provider("Microsoft-Windows-DNS-Client");
            provider.AddFilter(filter);

            var trace = new UserTrace();
            trace.Enable(provider);
            trace.Start();
        }
    }
}</pre>
This example listens to the Microsoft-Windows-DNS-Client ETW provider for hot and cached DNS resolutions and prints out the domain name queried as well as the result returned from the DNS server. The flow of the program can be summarized as:
<ul>
 	<li>Create an event filter, accepting only events with EventId 3018 (cached resolution) and EventId 3020 (hot resolution)</li>
 	<li>Setup a callback on the event filter. The callback fetches the “QueryName” property and the “QueryResults” property and prints them out.</li>
 	<li>Create an object representing the Microsoft-Windows-DNS-Client ETW provider.</li>
 	<li>Enable the event filter created in (2) on the provider object created in (3).</li>
 	<li>Create our trace session object and enable the provider from (3) on it.</li>
 	<li>Start the trace</li>
</ul>
The most interesting feature of this example is in the event filter. While we created the event filter in managed code – that event filter is transformed into a native code path for filtering events. That means we’ll never create a managed object that needs to be garbage collected for an event that doesn’t have EventId 3018 or 3020. This will save memory overhead and CPU time due to GC.

You might notice that we don’t call “Stop” in this example anywhere. To keep the example simple, I’ve omitted the call but it is worth discussing how we’d have to do it. Due to the nature of how the TDH Event API is designed, when you call the <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa364117(v=vs.85).aspx">StartTrace</a> function, you donate the calling thread to the ETW subsystem. This means that you’ll need to call <a href="https://msdn.microsoft.com/en-us/library/windows/desktop/aa364119(v=vs.85).aspx">StopTrace</a> on a different thread than you called start on. For testing purposes, a simple solution would be to add this bit of code to the example above:
<pre>            Console.CancelKeyPress += (sender, eventArg) =&gt;
            {
                if (trace != null)
                {
                    trace.Stop();
                }
            };</pre>
This code sets up the event handler for Ctrl-C to call trace.Stop() for us. Note – you’ll want to add that line above trace.Start() since trace.Start() is a blocking call.

Hopefully this example gives you a taste of how you can consume ETW in your own programs. You can find this example on my<a href="https://github.com/zacbrown/hiddentreasure-etw-demo"> github page here</a>. If you’d like to see a more in depth example, I’ve written one that demonstrates filtering PowerShell method invocations that can also be found on my<a href="https://github.com/zacbrown/PowerShellMethodAuditor"> github page</a>.

Earlier we talked about the importance of filtering and aggregating data coming from ETW to manage the volume of data we’re sending to our SIEM. Let’s talk about strategies we can employ to make the dataset more manageable.

<strong>Aggregating</strong>

Aggregation is interesting in cases where the events generated by ETW are highly granular. For example, the network TCP/IP kernel trace can generate an event for every packet sent. This data, without aggregation, isn’t easily interpreted once it’s in the SIEM. If we aggregate the sent events per process per hour and generate a derived event, we now have a picture of outbound traffic on the machine. We’ll refer to this event as per-process netflow in later examples.

<strong>Filtering</strong>

Unfortunately, even with aggregation, processing every outgoing packet sent on the machine is still going to be a huge amount of data under normal conditions. Most machines in a cloud talk to known good network endpoints and often send substantial amounts of data – e.g. frontends calling middle tier API machines or file copy to a remote share. If we can filter intra-environment and known-good network endpoint traffic, we could substantially reduce the data processed during the aggregation step.

<strong>Alerting</strong>

In addition to filtering the ETW events, we can apply some basic SIEM rules on box rather than forwarding them on. Using the per-process netflow event discussed above, we can apply a basic rule to detect activity that may indicate exfiltration. Tracking the per-process netflow data over the course of a day on the machine, we would generate a SIEM alert if any one process transferred more than 100MB to a single endpoint. This reduces the amount of work that the SIEM must do which becomes increasingly important as our environment size grows.

These techniques allow us to deploy host-based ETW monitoring across hundreds of thousands of servers without impacting performance or reliability. Centralized data processing will always be our bottleneck so distributed work whereby each endpoint filters and aggregates as much as possible will produce the greatest performance improvements.

<strong>Revisiting the Forensic Wishlist</strong>

In the <a href="https://blogs.technet.microsoft.com/office365security/hidden-treasure-intrusion-detection-with-etw-part-1/">first blog post</a> in this series, we discussed our forensic wishlist. We wanted to answer these questions:
<ul>
 	<li><strong>What</strong> suspicious activity was performed?</li>
 	<li><strong>Who</strong> performed the suspicious activity?</li>
 	<li><strong>Where</strong> did the output from that suspicious activity go?</li>
</ul>
Let’s revisit the wishlist and consider how we answer some of those questions with existing ETW providers.
<table width="952">
<tbody>
<tr>
<td width="240"><strong>Wishlist Item</strong></td>
<td width="240"><strong>ETW Provider</strong></td>
<td width="240"><strong>Example Data</strong></td>
</tr>
<tr>
<td width="240">What DNS lookups did the process perform</td>
<td width="240">Microsoft-Windows-DNS-Client</td>
<td width="240">evil.com</td>
</tr>
<tr>
<td width="240">What IP Addresses did the process connect to?</td>
<td width="240">Kernel Network Provider</td>
<td width="240">12.34.56.78</td>
</tr>
<tr>
<td width="240">How much data was transmitted by the process?</td>
<td width="240">Kernel Network Provider</td>
<td width="240">173MB</td>
</tr>
<tr>
<td width="240">Is the process “beaconing” to a C2?</td>
<td width="240">Kernel Network Provider</td>
<td width="240">Yes, every 15 seconds</td>
</tr>
<tr>
<td width="240">What DLLs did the process load?</td>
<td width="240">Kernel Image Load Provider</td>
<td width="240">System.Management.Automation.dll</td>
</tr>
<tr>
<td width="240">Did the process create threads in other processes?</td>
<td width="240">Kernel Thread Provider</td>
<td width="240">Injected into winlogon.exe</td>
</tr>
<tr>
<td width="240">What WMI operations did the process perform?</td>
<td width="240">Microsoft-Windows-WMI</td>
<td width="240">Registered an event handler backdoor</td>
</tr>
<tr>
<td width="240">What PowerShell functions did the process call?</td>
<td width="240">Microsoft-Windows-PowerShell</td>
<td width="240">Invoke-Mimikatz</td>
</tr>
</tbody>
</table>
&nbsp;

<strong>Conclusion</strong>

While the table above doesn’t provide the recipe for building these detections, we now have the ingredients necessary to do so. As you build detections for your environment, you’ll find that different detections work better or worse based on the baseline activity in your environment. In our experience, even within Microsoft, it is difficult to build detections that work the same way in every environment.]]></content:encoded>
    </item>
    <item>
      <title>DNS Intrusion Detection using Dnsflow</title>
      <link>https://docs.microsoft.com/archive/blogs/office365security/dns-intrusion-detection-using-dnsflow</link>
      <pubDate>Tue, 25 Apr 2017 10:30:29 GMT</pubDate>
      <dc:creator><![CDATA[Amar Shroff]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/office365security/?p=3176</guid>
      <description><![CDATA[In the DNS Intrusion Detection in Office 365 post we introduced strategies implemented in Office 365...]]></description>
      <content:encoded><![CDATA[In the <a href="https://blogs.technet.microsoft.com/office365security/dns-intrusion-detection-in-office-365/">DNS Intrusion Detection in Office 365</a> post we introduced strategies implemented in Office 365 to detect anomalous DNS activity. Dnsflow is one of those strategies and involves aggregating DNS data processed by the DNS servers in Office 365. In this post, we discuss detailed benefits, challenges and implementation of Dnsflow. We also discuss how Dnsflow enables us to easily build detections that inform us about the potential abuse of DNS in our network.
<h2><strong>Benefits</strong></h2>
<ul>
 	<li><strong>Access to complete DNS data
</strong>Dnsflow runs on DNS servers, which are the choke point of DNS traffic in our network. As a result, Dnsflow has access to all DNS queries and responses.</li>
</ul>
<ul>
 	<li><strong>Access to Nameserver IP address</strong>
Nameserver IP address is critical forensic information for incident response. DNS servers make outgoing DNS queries to the nameserver and Dnsflow collects this information.</li>
</ul>
<ul>
 	<li><strong>High performance and low impact monitoring</strong>
Dnsflow uses <a href="https://technet.microsoft.com/en-us/library/dn800669(v=ws.11).aspx">Enhanced DNS Logging</a> feature of Windows Sever 2012 R2 via the <span>Microsoft-Windows-DNSServer ETW trace</span>, which provides very low impact monitoring.</li>
</ul>
<ul>
 	<li><strong>Ability to detect anomalies in near real time</strong>
Since Dnsflow is aggregated DNS data for detecting anomalies, very little off the box processing is needed and the data is ready to be consumed in the detections at the end of each aggregation interval.</li>
</ul>
<h2><strong>Challenges, Risks, and Limitations</strong></h2>
<ul>
 	<li>DNS servers process very high volume of DNS data. While, the data source<span> is low impact, the processing and aggregation done by Dnsflow </span>needs to be highly efficient as well.</li>
 	<li>There is no visibility into the process that initiated the DNS query on the remote client.</li>
 	<li>Nameserver IP address accuracy depends on network topology and configuration of DNS server.</li>
 	<li>Since DNS Servers are the central point for monitoring DNS data in the network, they also become central point of failure and downtimes may result in large loss of monitoring data.</li>
</ul>
<h2><strong>Implementation</strong></h2>
<h3>Accessing raw DNS data</h3>
We use the <a href="https://technet.microsoft.com/en-us/library/dn800669(v=ws.11).aspx#analytic">analytic events</a> of the Microsoft-Windows-DNSServer ETW trace as the raw data source for Dnsflow data. It includes full DNS query and response data. We subscribe to the following events –
<ul>
 	<li>256: Query received</li>
 	<li>257: Response success</li>
 	<li>261: Recurse response in</li>
</ul>
&nbsp;

<a href="https://msdnshared.blob.core.windows.net/media/2017/04/Dnsflow_1.png"><img src="https://msdnshared.blob.core.windows.net/media/2017/04/Dnsflow_1.png" alt="dnsflow_1" width="605" height="282" class="alignnone size-full wp-image-3225" /></a>

We use the <a href="https://github.com/microsoft/krabsetw">krabsetw</a> library in our monitoring to consume the ETW events. Our agent receives the events for each DNS lookup upon configuring the library for the above events.
<h3>Addressing the challenges, risks and limitations</h3>
<ul>
 	<li><strong>Efficient data handling with fast-filtering</strong>
Dnsflow filters out very high-volume domains belonging to trusted internet services very early in the monitoring pipeline. Most known DNS intrusion exploits require an attacker to maintain control of the domain's nameserver for an extended time. Hijacking and using these domains is not a viable approach for the attackers. So, fast-filtering introduces minimal risk and significantly improves data handling.</li>
</ul>
<ul>
 	<li><strong>Process attribution
</strong>Results from detections using the Dnsflow data are joined with the Process and Netflow monitoring data from our servers to attribute a DNS lookup to a process. See <em>How to Make Results Actionable</em> section of <a href="https://blogs.technet.microsoft.com/office365security/dns-intrusion-detection-in-office-365/">DNS Intrusion Detection in Office 365</a>.</li>
</ul>
<ul>
 	<li><strong>Identifying nameserver for a domain</strong>
Dnsflow associates the IP address of the last recursive query as the nameserver for the domain being resolved.</li>
</ul>
<ul>
 	<li><strong>Preventing and mitigating gaps in monitoring data</strong>
The other two detection approaches discussed in the post <a href="https://blogs.technet.microsoft.com/office365security/dns-intrusion-detection-in-office-365/">DNS Intrusion Detection in Office 365</a> have some overlap with Dnsflow. They help in covering the gaps in case of loss of Dnsflow data.</li>
</ul>
<h3>Dnsflow data sets</h3>
Transforming raw DNS queries and responses into aggregated data is at the heart of this monitoring strategy. The Dnsflow data sets enable us to create baselines of normal activity in the network and build high-fidelity detections that include detailed forensic information. The data is comprised of three distinct but related data sets. These data sets are logged hourly in our initial release. Here are the details of the data sets.
<ol>
 	<li style="margin-bottom: 10px"><strong>Dnsflow Summary
</strong>This is the base data set with some attributes about the other two data sets.</li>
 	<li style="margin-bottom: 10px"><strong>Dnsflow Clients
</strong>This is the data set of client endpoints (source nodes) that initiated the DNS query.</li>
 	<li style="margin-bottom: 10px"><strong>Dnsflow Subdomains
</strong>This is the data set of subdomains in the DNS queries.</li>
</ol>
<table style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;margin-bottom: 10pt;width: 595">
<tbody>
<tr>
<th style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 132"><strong>Data set</strong></th>
<th style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 162"><strong>Aggregation keys</strong></th>
<th style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 301"><strong>Aggregated data points</strong></th>
</tr>
<tr>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 132">Dnsflow Summary</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 162">
<ul style="padding-left: 15pt">
 	<li>Second level domain</li>
 	<li>DNS query type</li>
 	<li>Transport protocol</li>
</ul>
</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 301">
<ul style="padding-left: 15pt">
 	<li>Query count</li>
 	<li>Response count</li>
 	<li>Query bytes sum</li>
 	<li>Response bytes sum</li>
 	<li>First seen</li>
 	<li>Last seen</li>
 	<li>Longest subdomain</li>
 	<li>Whether Clients data set is truncated<sup>+</sup></li>
 	<li>Whether Subdomains data set is truncated<sup>+</sup></li>
</ul>
</td>
</tr>
<tr>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 132">Dnsflow Clients</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 162">
<ul style="padding-left: 15pt">
 	<li>Second level domain</li>
 	<li>DNS query type</li>
 	<li>Transport protocol</li>
 	<li>Source IP address</li>
</ul>
</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 301">
<ul style="padding-left: 15pt">
 	<li>Query count</li>
 	<li>Response count</li>
 	<li>Query bytes sum</li>
 	<li>Response bytes sum</li>
 	<li>First seen</li>
 	<li>Last seen</li>
</ul>
</td>
</tr>
<tr>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 132">Dnsflow Subdomains</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 162">
<ul style="padding-left: 15pt">
 	<li>Second level domain</li>
 	<li>DNS query type</li>
 	<li>Transport protocol</li>
 	<li>Subdomain string</li>
</ul>
</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 301">
<ul style="padding-left: 15pt">
 	<li>Query count</li>
 	<li>Response count</li>
 	<li>Query bytes sum</li>
 	<li>Response bytes sum</li>
 	<li>First seen</li>
 	<li>Last seen</li>
 	<li>Nameserver IP Address</li>
</ul>
</td>
</tr>
</tbody>
</table>
<p style="font-size: 90%"><sup>+</sup>Dnsflow truncates the Clients and Subdomains data set if the number of distinct values exceeds a threshold. We record truncation events in the logged data sets via these properties and monitor them. The thresholds such that truncation is rare, however, this is essential for meeting our performance goals. It is important to note that the Dnsflow Summary data set is never truncated, and this data set alone is sufficient for most detections.</p>

<h4><strong>Example</strong></h4>
<strong>Sample DNS queries and responses</strong>

The following table shows a sample of DNS queries and responses processed by the DNS server.
<table style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;margin-bottom: 10pt">
<tbody>
<tr>
<th style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 60"><strong>Q Type</strong></th>
<th style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 224"><strong>Domain</strong></th>
<th style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 52"><strong>Proto</strong></th>
<th style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 59"><strong>Source IP</strong></th>
<th style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 113"><strong>Nameserver IP</strong></th>
<th style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 38"><strong>…</strong></th>
</tr>
<tr>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 60">A</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 224">onedrive.com</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 52">UDP</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 59">1.1.1.1</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 113">11.11.11.11</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 38"></td>
</tr>
<tr>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 60">AAAA</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 224">onedrive.com</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 52">UDP</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 59">1.1.1.1</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 113">11.11.11.11</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 38"></td>
</tr>
<tr>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 60">A</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 224">photos.onedrive.com</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 52">UDP</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 59">1.1.1.1</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 113">11.11.11.11</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 38"></td>
</tr>
<tr>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 60">A</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 224">photos.onedrive.com</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 52">UDP</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 59">2.2.2.2</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 113">11.11.11.11</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 38"></td>
</tr>
<tr>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 60">A</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 224">bing.com</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 52">UDP</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 59">2.2.2.2</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 113">&lt;empty&gt;</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 38"></td>
</tr>
<tr>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 60">TXT</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 224">13d74b57c7b.72805.cs2.evilzzz.com</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 52">TCP</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 59">2.2.2.2</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 113">33.33.33.33</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 38"></td>
</tr>
<tr>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 60">TXT</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 224">6e574x83c5v.72805.cs2.evilzzz.com</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 52">TCP</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 59">2.2.2.2</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 113">33.33.33.33</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 38"></td>
</tr>
</tbody>
</table>
<strong>Sample Dnsflow data sets</strong>

The next three tables show the Dnsflow data sets built from the processing of the above sample data.

Dnsflow Summary data set –
<table style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;margin-bottom: 10pt">
<tbody>
<tr>
<th style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 89"><strong>SLD</strong></th>
<th style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 60"><strong>Q Type</strong></th>
<th style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 57"><strong>Proto</strong></th>
<th style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 73"><strong>Q Count</strong></th>
<th style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 42"><strong>…</strong></th>
</tr>
<tr>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 89">onedrive.com</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 60">A</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 57">UDP</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 73">3</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 42"></td>
</tr>
<tr>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 89">onedrive.com</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 60">AAAA</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 57">UDP</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 73">1</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 42"></td>
</tr>
<tr>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 89">bing.com</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 60">A</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 57">UDP</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 73">1</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 42"></td>
</tr>
<tr>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 89">evilzzz.com</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 60">TXT</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 57">TCP</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 73">2</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 42"></td>
</tr>
</tbody>
</table>
Dnsflow Clients data set<span> </span><span>–</span>
<table style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;margin-bottom: 10pt">
<tbody>
<tr>
<th style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 89"><strong>SLD</strong></th>
<th style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 60"><strong>Q Type</strong></th>
<th style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 57"><strong>Proto</strong></th>
<th style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 81"><strong>Source IP</strong></th>
<th style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 73"><strong>Q Count</strong></th>
<th style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 42"><strong>…</strong></th>
</tr>
<tr>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 89">onedrive.com</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 60">A</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 57">UDP</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 81">1.1.1.1</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 73">2</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 42"></td>
</tr>
<tr>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 89">onedrive.com</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 60">AAAA</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 57">UDP</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 81">1.1.1.1</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 73">1</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 42"></td>
</tr>
<tr>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 89">onedrive.com</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 60">A</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 57">UDP</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 81">2.2.2.2</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 73">1</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 42"></td>
</tr>
<tr>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 89">bing.com</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 60">A</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 57">UDP</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 81">2.2.2.2</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 73">1</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 42"></td>
</tr>
<tr>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 89">evilzzz.com</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 60">TXT</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 57">TCP</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 81">2.2.2.2</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 73">2</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 42"></td>
</tr>
</tbody>
</table>
Dnsflow Subdomains data set<span> </span><span>–</span>
<table style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;margin-bottom: 10pt;width: 591">
<tbody>
<tr>
<th style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 94"><strong>SLD</strong></th>
<th style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 66"><strong>Q Type</strong></th>
<th style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 49"><strong>Proto</strong></th>
<th style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 155"><strong>Subdomains</strong></th>
<th style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 73"><strong>Q Count</strong></th>
<th style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 113"><strong>Nameserver IP</strong></th>
<th style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 40"><strong>…</strong></th>
</tr>
<tr>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 94">onedrive.com</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 66">A</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 49">UDP</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 155">&lt;empty&gt;</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 73">1</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 113">11.11.11.11</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 40"></td>
</tr>
<tr>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 94">onedrive.com</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 66">AAAA</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 49">UDP</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 155">&lt;empty&gt;</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 73">1</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 113">11.11.11.11</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 40"></td>
</tr>
<tr>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 94">onedrive.com</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 66">A</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 49">UDP</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 155">photos</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 73">2</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 113">11.11.11.11</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 40"></td>
</tr>
<tr>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 94">bing.com</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 66">A</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 49">UDP</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 155">&lt;empty&gt;</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 73">1</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 113">&lt;empty&gt;<sup>++</sup></td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 40"></td>
</tr>
<tr>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 94">evilzzz.com</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 66">TXT</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 49">TCP</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 155">13d74b57c7b.72805.cs2</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 73">1</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 113">33.33.33.33</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 40"></td>
</tr>
<tr>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 94">evilzzz.com</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 66">TXT</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 49">TCP</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 155">6e574x83c5v.72805.cs2</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 73">1</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 113">33.33.33.33</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 40"></td>
</tr>
</tbody>
</table>
<p style="font-size: 90%"><sup>++</sup>External Nameserver IP address is empty for responses from DNS data cached on the DNS server.</p>

<h2><strong>Detections</strong></h2>
The next table contains some of the detections that we have implemented using the Dnsflow data.
<table style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;margin-bottom: 10pt">
<tbody>
<tr>
<th style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 26%"><strong>Detection</strong></th>
<th style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 20%"><strong>Detects</strong></th>
<th style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 54%"><strong>Implementation overview</strong></th>
</tr>
<tr>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 26%">1)  Anomalous query type</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 20%">
<ul style="padding-left: 15pt">
 	<li>Exfiltration</li>
 	<li>Infiltration</li>
 	<li>Scanning of IP range</li>
</ul>
</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 54%">Compare the Dnsflow data with baseline of second level domain and query type data <span>–</span>
<ul style="padding-left: 15pt">
 	<li>Anomalous query types like TXT, MX may be an indication of exfiltration or infiltration.</li>
 	<li>Anomalous PTR queries may be an indication of scanning of IP range.</li>
</ul>
</td>
</tr>
<tr>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 26%">2)  Anomalous subdomain count</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 20%">
<ul style="padding-left: 15pt">
 	<li>Exfiltration</li>
 	<li>C2 communication</li>
</ul>
</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 54%">Count the number and rate of distinct subdomains <span>–</span>
<ul style="padding-left: 15pt">
 	<li>Anomalous total number of subdomains or anomalous rate of subdomains may be an indication of exfiltration or C2 communication.</li>
</ul>
</td>
</tr>
<tr>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 26%">3)  Anomalous long labels in queries</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 20%">
<ul style="padding-left: 15pt">
 	<li>Exfiltration</li>
 	<li>C2 communication</li>
</ul>
</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 54%">Compare the length of labels in the Dnsflow Subdomains data with the baseline <span>–</span>
<ul style="padding-left: 15pt">
 	<li>Long labels may be an indication of C2 communication or exfiltration.</li>
</ul>
</td>
</tr>
<tr>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 26%">4)  Anomalous rate (bytes per client) of DNS response data</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 20%">
<ul style="padding-left: 15pt">
 	<li>Infiltration</li>
</ul>
</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 54%">Calculate rate of inbound bytes in an interval. (i.e. sum of response bytes / total number of clients) <span>–</span>
<ul style="padding-left: 15pt">
 	<li>Anomalous rate of inbound bytes may be an indication of infiltration.</li>
 	<li>Join with Clients and Subdomains data to provide additional forensic context.</li>
</ul>
</td>
</tr>
<tr>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 26%">5)  Esoteric domains (domains queried by very few machines)</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 20%">
<ul style="padding-left: 15pt">
 	<li>Flag potential malicious domains</li>
</ul>
</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 54%">Select domains with number of clients below a threshold and high query counts <span>–</span>
<ul style="padding-left: 15pt">
 	<li>These domains could be malicious domains.</li>
</ul>
</td>
</tr>
<tr>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 26%">6)  Queries for young DNS domains</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 20%">
<ul style="padding-left: 15pt">
 	<li>Flag potential malicious domains</li>
</ul>
</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 54%">Join the domains logged via Dnsflow with the whois data stream and flag domains that are created in the last x days <span>–</span>
<ul style="padding-left: 15pt">
 	<li>These domains may be malicious domains.</li>
</ul>
</td>
</tr>
</tbody>
</table>
We have successfully used Dnsflow to build a baseline of DNS activity in our network and have implemented several detections to detect DNS related anomalies. The Dnsflow data also enables us to include highly actionable information in the anomaly detection results. The results inform us about the potential abuse of DNS and help us protect our network from adversaries.
<h2><strong>References</strong></h2>
<ul>
 	<li><a href="https://www.icsi.berkeley.edu/pubs/networking/practicalcomprehensive13.pdf">Practical Comprehensive Bounds on Surreptitious Communication Over DNS</a></li>
 	<li><a href="https://astrolavos.gatech.edu/articles/Antonakakis.pdf">Building a Dynamic Reputation System for DNS</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>DNS Intrusion Detection in Office 365</title>
      <link>https://docs.microsoft.com/archive/blogs/office365security/dns-intrusion-detection-in-office-365</link>
      <pubDate>Tue, 18 Apr 2017 13:30:50 GMT</pubDate>
      <dc:creator><![CDATA[Amar Shroff]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/office365security/?p=3156</guid>
      <description><![CDATA[In Office 365, we are committed to protecting our customer's data. We implement and exercise...]]></description>
      <content:encoded><![CDATA[In Office 365, we are committed to protecting our customer's data. We implement and exercise industry leading security practices to ensure that customer's data is safe. Intrusion detection is one such security practice which ensures that we are notified about any anomalous activity or behavior on our servers or in our network. We monitor and investigate notifications from our intrusion detection system for signs of adversary activities against our service, with the goal to prevent the adversary from gaining unauthorized access to customer data.

The Domain Name System, or DNS, is used in computer networks to translate domain names to IP addresses which are used by computers to communicate with each other. DNS exists in almost every computer network; it communicates with external networks and is extremely difficult to lock down since it was designed to be an open protocol. An adversary may find that DNS is an attractive mechanism for performing malicious activities like network reconnaissance, malware downloads, or communication with their command and control servers, or data transfers out of a network. Consequently, it is critical that we monitor our network for these activities to protect our customer's data.

This post discusses adversary techniques that abuse the DNS protocol to gain unauthorized access in computer networks and monitoring strategies for detecting such techniques.
<h2><strong>What to Detect</strong></h2>
Adversary and penetration-test tools may abuse DNS using techniques in the table below to achieve the following goals.
<ul>
 	<li><strong>Network footprinting</strong>
An adversary may attempt to obtain information about a target network by misusing DNS. Specific techniques involving DNS (see table below) may be used to learn about domain names, computer names and IP addresses in a target network. This information can be used to build a footprint or graph of the network.</li>
</ul>
<ul>
 	<li><strong>Credential theft</strong>
An adversary may create a malicious domain name that resembles a legitimate domain name and use it in phishing campaigns to steal credentials.</li>
</ul>
<ul>
 	<li><strong>Malware installation</strong>
An adversary may attempt to install malware on computers in a target network by directing requests to malicious domains or IP addresses. This may be done by hijacking DNS queries and responding with malicious IP addresses. The goal of malware installation can also be achieved by directing requests to phishing domains.</li>
</ul>
<ul>
 	<li><strong>Command and Control (C2) communication</strong>
If an adversary manages to gain foothold inside a target network, he or she may abuse DNS to communicate with a C2 server. This typically involves making periodic DNS queries from a computer in the target network for a domain controlled by the adversary. The responses contain encoded messages that may be used to perform unauthorized actions in the target network.</li>
</ul>
<ul>
 	<li><strong>Data theft</strong>
Like C2 communication, an adversary may abuse DNS to transfer data from a computer in a target network to a C2 server. This may be performed by <a href="https://dnstunnel.de/">tunneling</a> other protocols like FTP, SSH through DNS queries and responses. This typically involves making multiple DNS queries from a compromised computer to a domain owned by the adversary. DNS tunneling can also be used for executing commands and transferring malware into the target network.</li>
</ul>
<ul>
 	<li><strong>Evading detection</strong>
An adversary may use advanced techniques to evade detection of the malicious DNS traffic and make it hard for defenders to learn about the malicious domain or nameserver.</li>
</ul>
See the references section for links to posts that discuss some of these above topics in greater detail.

This tables summarizes the goals, techniques and DNS activity generated from the techniques.
<table style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;margin-bottom: 10pt">
<tbody>
<tr>
<th style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 15%">Adversary Goals</th>
<th style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 35%">Adversary Techniques</th>
<th style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 50%">DNS Activity (Indicators)</th>
</tr>
<tr>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 15%"><span>Network foot printing</span></td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 35%">
<ul style="padding-left: 15pt">
 	<li>Reverse DNS lookups over IP range</li>
 	<li>Zone transfer attempts</li>
 	<li>Brute forcing subdomains</li>
</ul>
</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 50%">
<ul style="padding-left: 15pt">
 	<li>Large number of PTR queries</li>
 	<li>SOA and AXFR queries</li>
 	<li>Forward DNS lookups for non-existent subdomains in target network’s root domain</li>
</ul>
</td>
</tr>
<tr>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 15%"><span>Credential theft, Malware installation</span></td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 35%">
<ul style="padding-left: 15pt">
 	<li>DNS hijacking using deceptive domain names</li>
 	<li>Resolving legitimate domains to malicious IP addresses (cache poisoning)</li>
</ul>
</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 50%">
<ul style="padding-left: 15pt">
 	<li>Forward DNS lookups of typo squatting, similar sounding/looking domains</li>
 	<li>Hosts file modification</li>
 	<li>DNS cache poisoning</li>
</ul>
</td>
</tr>
<tr>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 15%"><span>Command and control (C2) communication</span></td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 35%">
<ul style="padding-left: 15pt">
 	<li>Periodic queries to adversary controlled domain</li>
</ul>
</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 50%">
<ul style="padding-left: 15pt">
 	<li>DNS beaconing queries to anomalous domain</li>
 	<li>Low TTL for resolved IP addresses</li>
 	<li>Orphaned DNS requests</li>
</ul>
</td>
</tr>
<tr>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 15%"><span>Malware installation, Data theft</span></td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 35%">
<ul style="padding-left: 15pt">
 	<li>Tunneling over DNS using large number of queries to adversary controlled domain</li>
</ul>
</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 50%">
<ul style="padding-left: 15pt">
 	<li>Large number of subdomain lookups of anomalous domain</li>
 	<li>Large response size of subdomain lookups of anomalous domain</li>
 	<li>Long subdomains with high entropy; containing random/non-dictionary words</li>
 	<li>Large number or uncommon query types (MX, TXT)</li>
 	<li>Orphaned DNS requests</li>
</ul>
</td>
</tr>
<tr>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 15%"><span>Evading detection</span></td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 35%">
<ul style="padding-left: 15pt">
 	<li>Use of Domain Generation Algorithms</li>
 	<li>Use of Fast-Flux</li>
 	<li>Use anomalous nameserver for malicious DNS traffic</li>
</ul>
</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 50%">
<ul style="padding-left: 15pt">
 	<li>Lots of failed DNS requests (NXDomain responses)</li>
 	<li>Low TTL and multiple IP address resolutions for a domain</li>
 	<li>DNS traffic bypassing default DNS servers</li>
</ul>
</td>
</tr>
</tbody>
</table>
The indicators listed in the above table helped us create the list of detections for the adversary techniques. Here is the summarized list of detections.
<ul>
 	<li>Detect anomalous DNS query types and volume</li>
 	<li>Detect DNS traffic from anomalous processes or to anomalous DNS servers</li>
 	<li>Detect anomalous volume of failed DNS queries</li>
 	<li>Detect anomalous distinct IP address resolved for a domain</li>
 	<li>Detect phishing domains, domains with high entropy and random words</li>
 	<li>Detect anomalous entries in DNS hosts file</li>
 	<li>Detect cache poisoning via DNS responses</li>
 	<li>Detect DNS beaconing to anomalous domains</li>
 	<li>Detect long and random labels in subdomains and large subdomain count</li>
 	<li>Detect esoteric domains i.e. domains that only some of our servers are resolving</li>
</ul>
<h2><strong>How to Detect</strong></h2>
We analyzed the flow of DNS traffic in our service and observed that there was no single spot in the service where we could monitor and achieve all our goals of detecting malicious activity, reporting actionable information and monitoring reliably and in a highly performant manner.

To overcome this, we designed a solution that incorporates three monitoring strategies. Each strategy captures essential and unique details about DNS traffic in our network. The strategies also have some overlap so that all the details can be pieced together to create an end to end picture of the activity.

We use host based monitoring via Windows ETW data for each of these strategies. The post <a href="https://blogs.technet.microsoft.com/office365security/hidden-treasure-intrusion-detection-with-etw-part-1/">Hidden Treasure: Intrusion Detection with ETW</a> discusses the details of using Windows ETW for security monitoring.
<h4>Monitoring Strategies</h4>
Let's dive into the monitoring strategies that we have implemented.
<ul>
 	<li><strong>Monitor DNS resolutions on every endpoint</strong>
In this strategy, we collect every DNS resolution performed by the standard DNS resolver on each endpoint (or DNS client). The data is obtained from the Microsoft-Windows-DNS-Client ETW trace.</li>
</ul>
<ul>
 	<li><strong>Monitor Netflow (IP) traffic to outbound DNS port 53</strong>
In this strategy, we collect Netflow data for outbound port 53 from every server. Our Netflow data is aggregated network metadata from packet headers (IP Address, domain, port, protocol, bytes and process). The data is obtained from the Microsoft-Windows-Kernel-Network ETW trace.</li>
</ul>
<ul>
 	<li><strong>Monitor DNS data on internal DNS servers (<a href="https://blogs.technet.microsoft.com/office365security/dns-intrusion-detection-using-dnsflow/">Dnsflow</a>)
</strong>In this strategy, we aggregate and collect data from DNS queries and responses flowing through the DNS servers in our network. We call this Dnsflow monitoring. Some of the information collected is aggregated query count, query types, query and response bytes, subdomains, client and nameserver IP addresses. The data is obtained from the Microsoft-Windows-DnsServer ETW trace.</li>
</ul>
Here is a summary of the pros and cons of each of the monitoring strategies.
<table style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;margin-bottom: 10pt">
<tbody>
<tr>
<th style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 20%">Monitoring Strategy</th>
<th style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 40%">Pros</th>
<th style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 40%">Cons</th>
</tr>
<tr>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 20%"><span>Monitor DNS resolutions on every endpoint</span></td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 40%">
<ul style="padding-left: 15pt">
 	<li>Distributed monitoring and lesser load compared to centralized monitoring</li>
 	<li>Simpler handling and processing</li>
 	<li>High level detail. E.g. each DNS query and response may be logged</li>
</ul>
</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 40%">
<ul style="padding-left: 15pt">
 	<li>No visibility into external nameserver IPs</li>
 	<li>No visibility into DNS queries that bypass the standard resolver (E.g. nslookup, chrome)</li>
</ul>
</td>
</tr>
<tr>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 20%"><span>Monitor Netflow (IP) traffic to outbound DNS port 53</span></td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 40%">
<ul style="padding-left: 15pt">
 	<li>Efficient since data is mostly from packet headers (metadata)</li>
 	<li>Process information is very valuable to detect bypassing of standard DNS resolver (E.g. nslookup, chrome)</li>
 	<li>Valuable for detecting bypassing of standard DNS servers</li>
</ul>
</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 40%">
<ul style="padding-left: 15pt">
 	<li>Forward DNS lookups of typo squatting, similar sounding/looking domains</li>
 	<li>Hosts file modification</li>
 	<li>DNS cache poisoning</li>
</ul>
</td>
</tr>
<tr>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 20%"><span>Monitor DNS resolutions on service's internal DNS servers (<a href="https://blogs.technet.microsoft.com/office365security/dns-intrusion-detection-using-dnsflow/">Dnsflow</a>)</span></td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 40%">
<ul style="padding-left: 15pt">
 	<li>Near complete coverage</li>
 	<li>Access to nameserver IP address</li>
 	<li>DNS server’s ETW trace exposes more data that DNS client’s trace</li>
</ul>
</td>
<td style="border: solid #A3A3A3 1.0pt;border-collapse: collapse;padding: 4.0pt;vertical-align: top;width: 40%">
<ul style="padding-left: 15pt">
 	<li>Very high volume of data</li>
 	<li>No visibility into the client process requesting DNS resolution</li>
 	<li>Requires complex handling and processing</li>
 	<li>Can cause over-use of CPU from inefficient handling which may cause service wide impact vs. impact on a single client in other two strategies</li>
</ul>
</td>
</tr>
</tbody>
</table>
<h4>Performance and Reliability</h4>
Since each strategy involves host based monitoring, it is critical that the data collection, handling and logging is highly performant. We achieve this by filtering, aggregating where data volume is high, and closely monitoring the resource usage on an ongoing basis. We also detect significant changes to the data volumes handled which can affect resource utilization of our monitoring pipeline.

The overlap across monitoring strategies ensures that there aren’t any blind spots in our monitoring. Also, the overlap across the strategies adds redundancy and increases the resiliency of the overall solution to monitoring failures on a few servers.
<h2><strong>How to Make Results Actionable</strong></h2>
We have implemented DNS detections so that the anomaly reports include actionable information like the user name, process name, computer name, anomalous domain name and nameserver IP address involved in the anomalous activity. This helps us make the most informed decision about the anomaly.

Here’s an overview of how we do this.

<a href="https://msdnshared.blob.core.windows.net/media/2017/04/Dns_Intrusion_Detection_1.png"><img src="https://msdnshared.blob.core.windows.net/media/2017/04/Dns_Intrusion_Detection_1.png" alt="dns_intrusion_detection_1" class="alignnone wp-image-3165 size-full" width="749" height="490" /></a>

The above picture shows the flow of DNS through our network and the monitoring data related to the activity. The monitoring data is collected on the endpoints and processed so that detections can consume the data from all the monitoring modules (Netflow, Dnsflow, etc.).

When we detect DNS anomalies, we work to get all the entities related to the activity – from the user to the nameserver IP address. The above picture shows how the monitoring data contains information about the entities. Here is the relevant information from each monitoring module.
<ul>
 	<li>Process monitoring (details of this not discussed in this post) – user, process</li>
 	<li>DNS resolution monitoring – DNS query and response, process</li>
 	<li>Netflow monitoring – process, remote IP address and port, count of bytes transferred</li>
 	<li>Dnsflow monitoring – DNS query and response, client and nameserver IP address</li>
</ul>
We join the intermediate results from each anomaly detection with the above data to create a more complete picture about DNS anomalies. Furthermore, our triage pipeline clusters the DNS detection results with results from other detections. The clustering approach is discussed in the post <a href="https://blogs.technet.microsoft.com/office365security/defending-office-365-with-graph-analytics/">Defending Office 365 with Graph Analytics</a>. This helps us reason about the DNS anomaly in context of other anomalies related to a machine or a domain.

The above methodology leaves us with very few results that need detailed investigation and helps us clearly identify red team activities. We are using the DNS monitoring data not only to detect DNS anomalies but also to add context to results of existing anomaly detections.
<h2><strong>References</strong></h2>
<ul>
 	<li><a href="https://technet.microsoft.com/en-us/library/cc755131(v=ws.11).aspx">Security Information for DNS</a></li>
 	<li><a href="https://www.sans.org/reading-room/whitepapers/dns/detecting-dns-tunneling-34152">Detecting DNS Tunneling</a></li>
 	<li><a href="https://www.cisco.com/c/en/us/about/security-center/dns-best-practices.html#3">Maliciously Abusing Implementation Flaws in DNS </a></li>
 	<li><a href="https://blog.cobaltstrike.com/2013/06/20/thatll-never-work-we-dont-allow-port-53-out/">That’ll never work–we don’t allow port 53 out</a></li>
 	<li><a href="https://www.honeynet.org/papers/ff/">Know Your Enemy: Fast-Flux Service Networks</a></li>
 	<li><a href="https://resources.infosecinstitute.com/dns-hacking/">DNS Hacking (Beginner to Advanced)</a></li>
</ul>]]></content:encoded>
    </item>
    <item>
      <title>Hidden Treasure: Intrusion Detection with ETW (Part 1)</title>
      <link>https://docs.microsoft.com/archive/blogs/office365security/hidden-treasure-intrusion-detection-with-etw-part-1</link>
      <pubDate>Tue, 11 Apr 2017 14:07:21 GMT</pubDate>
      <dc:creator><![CDATA[Zac Brown [MSFT]]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/office365security/?p=3095</guid>
      <description><![CDATA[Today’s defenders face an increasing obstacle with information asymmetry. With the advent of...]]></description>
      <content:encoded><![CDATA[Today’s defenders face an increasing obstacle with information asymmetry. With the advent of in-memory attacks and targeted malware, defenders cannot simply rely on the default event logs provided by Windows. Attackers may make use of process hollowing to hide their code within a seemingly benign process as well as routing their Command &amp; Control traffic over DNS to remain hidden.

We began investigating alternate data sources beyond the Windows Security Event Log after exercising our incident response capabilities with the Office 365 red team. We realized that although we saw a suspicious process started, we didn’t know which domains the process had queried or how much data it had sent to an endpoint. Additionally, we found that instances of PowerShell.exe were black holes where the adversary could execute any number of unknown commands. We needed more information than what was available through the Security Event Log.

<strong>The Challenge</strong>

Imagine the following scenario – in reviewing your event logs, you’ve found a Process Start event (4688) for an unknown executable, bad.exe:

<a href="https://msdnshared.blob.core.windows.net/media/2017/04/bad.exe_.png"><img src="https://msdnshared.blob.core.windows.net/media/2017/04/bad.exe_.png" alt="bad-exe" width="866" height="662" class="alignnone size-full wp-image-3096" /></a>

Unfortunately, when you went to investigate the machine with this suspect process start, bad.exe was no longer on disk or anywhere to be found. Using only what’s available in the Windows Security Event Log, you’re left with very little information besides what is shown above in the 4688 Process Start event.

Now imagine your forensic wish list. What sort of information about bad.exe would be most useful in detection and threat assessment? Principally, we’re interested in three questions:
<ul>
 	<li>Who did it? e.g. username</li>
 	<li>What did they do? e.g. process – this can be misleading if process hollowing/injection was used</li>
 	<li>Where did they send the data? e.g. network destinations and domain names</li>
</ul>
With these questions in mind, our forensic wish list might look something like this:
<ul>
 	<li>What DNS lookups did the process perform?</li>
 	<li>What IP Addresses did the process connect to?</li>
 	<li>How much data was transmitted by the process?</li>
 	<li>Is the process “beaconing”? i.e. Is the process communicating with Command &amp; Control infrastructure?</li>
 	<li>What DLLs did the process load?</li>
 	<li>Did the process create threads in other processes?</li>
 	<li>What WMI operations did the process perform?</li>
 	<li>What PowerShell functions did the process call?</li>
</ul>
To collect this type of data, you might assume that a kernel driver or some sort of hooking mechanism would be needed. Fortunately for us, Windows provides an existing source of data that can help us answer these questions called ETW or Event Tracing for Windows.

<strong>ETW to the Rescue</strong>

<a href="https://msdn.microsoft.com/en-us/library/windows/desktop/bb968803(v=vs.85).aspx">Event Tracing for Windows</a><span> (ETW)</span> is a tracing technology that’s been available in Windows since Windows 2000. It was originally designed to help Microsoft engineers debug the operating system  – for example, performance measurements, and power management tracing. In a previous life, I was an engineer on Windows and used ETW for performance testing and component tracing.

ETW is not notably different from other tracing technologies you may have encountered. A component (e.g. PowerShell) registers a provider, with which it emits one or more types of events. Each event has a schema describing the type of data contained in the event payload. An event might contain string, integer, float, boolean, or even binary data.

To consume events from an ETW provider, the consumer needs to first create a trace session. Each trace session can consume one or more providers. After registering a provider with the trace session, the consumer registers a callback which must handle any event from any provider. The consumer is now ready to enable the trace session. It’s important to note that by starting the trace session, the consumer donates the calling thread to the ETW subsystem for pumping events.

The flow of events is best illustrated by this diagram:

<a href="https://msdnshared.blob.core.windows.net/media/2017/04/etw-flow.png"><img src="https://msdnshared.blob.core.windows.net/media/2017/04/etw-flow.png" alt="etw-flow" width="875" height="407" class="alignnone wp-image-3105" /></a>

<strong>The Shape of ETW</strong>

To get a better sense of what an ETW event looks like, we’ll make use of a tool called <a href="https://blogs.technet.microsoft.com/messageanalyzer/">Microsoft Message Analyzer</a>. This tool allows you to subscribe to ETW traces available on the operating system and inspect the events as they come in.

Here’s the main window of Message Analyzer after having registered for the PowerShell provider:

<a href="https://msdnshared.blob.core.windows.net/media/2017/04/ma1.png"><img src="https://msdnshared.blob.core.windows.net/media/2017/04/ma1.png" alt="ma1" width="654" height="499" class="alignnone size-full wp-image-3106" /></a>

In the center, we see a series of events with a summary blurb:

<a href="https://msdnshared.blob.core.windows.net/media/2017/04/ma2.png"><img src="https://msdnshared.blob.core.windows.net/media/2017/04/ma2.png" alt="ma2" width="776" height="420" class="alignnone size-full wp-image-3115" /></a>

When we select one of those events, like the one highlighted above, we get a detailed view in the bottom half:

<a href="https://msdnshared.blob.core.windows.net/media/2017/04/ma3.png"><img src="https://msdnshared.blob.core.windows.net/media/2017/04/ma3.png" alt="ma3" width="868" height="230" class="alignnone size-full wp-image-3125" /></a>

The first three items labeled “ContextInfo”, “UserData”, and “Payload” are all properties on this event. We can see that the “Type” column describes all of them being strings. If we select one of these properties, we can see the contents of that property:

<a href="https://msdnshared.blob.core.windows.net/media/2017/04/ma4.png"><img src="https://msdnshared.blob.core.windows.net/media/2017/04/ma4.png" alt="ma4" width="434" height="529" class="alignnone size-full wp-image-3135" /></a>

This is a structured string blob containing the Host Application (“powershell.exe”), the Command Name (“invoke-mimikatz”), and the user that invoked it (“REDMOND\zbrown”).

Each ETW provider emits events with their own unique schemas. In addition to the unique schema, there are some standard properties to each event – EventId, ProcessId, ThreadId, TimeStamp, ProviderId, and more. These properties are common to all ETW events.

If you’d like to learn more about using Message Analyzer to inspect ETW events, please consult <a href="https://github.com/Microsoft/krabsetw/blob/master/docs/UsingMessageAnalyzerToFindETWSources.md">this guide</a>.

<strong>Visibility</strong><strong> with ETW</strong>

ETW provides visibility into most core Windows subsystems, including:
<ul>
 	<li>Network activity</li>
 	<li>Process creation/termination</li>
 	<li>Thread creation/termination</li>
 	<li>Memory allocation</li>
 	<li>DLL load/unload</li>
 	<li>PowerShell method invocation</li>
 	<li>DNS resolutions (cached and hot)</li>
 	<li>Firewall activity</li>
 	<li>WMI activity</li>
 	<li>WinINet request/response headers</li>
 	<li>and so much more…</li>
</ul>
In Windows 10, there's more than 1000 providers. If you’re curious which providers are available on your version of Windows, you can run the following command:
<pre>        logman query providers &gt; providers.txt</pre>
With all this data ripe for collection, you might assume we can simply turn these ETW providers on and immediately start benefiting from the increased information at our disposal. However, ETW is still a debug stream and, as such, outputs a truly huge amount of data. It would be like drinking from a fire hose:

<a href="https://msdnshared.blob.core.windows.net/media/2017/04/firehost.jpg"><img src="https://msdnshared.blob.core.windows.net/media/2017/04/firehost.jpg" alt="firehost" width="527" height="316" class="alignnone wp-image-3145" /></a>

Imagine trying to send this data to your SIEM:
<ul>
 	<li>every DLL load in every process</li>
 	<li>every thread creation in every process</li>
 	<li>every process start on every endpoint</li>
</ul>
It would likely be impossible to make effective use of the data if we sent it in raw form. To use of this new data source, we’ll need some way to filter and/or aggregate the data.

In the next blog post on ETW, we’ll discuss ways to consume ETW programmatically, filtering inputs, and how we can flesh out answers to the forensic wish list we outlined above.]]></content:encoded>
    </item>
    <item>
      <title>Defending Office 365 with Graph Analytics</title>
      <link>https://docs.microsoft.com/archive/blogs/office365security/defending-office-365-with-graph-analytics</link>
      <pubDate>Mon, 13 Mar 2017 10:58:10 GMT</pubDate>
      <dc:creator><![CDATA[Matt Swann - MSFT]]></dc:creator>
      <guid
        isPermaLink="false">https://blogs.technet.microsoft.com/office365security/?p=2985</guid>
      <description><![CDATA[In Office 365, we are continually improving the detection and response systems that safeguard your...]]></description>
      <content:encoded><![CDATA[In Office 365, we are continually improving the detection and response systems that safeguard your data. We gather many terabytes of telemetry from our service infrastructure each day and apply real-time and batch analytics to rapidly detect unauthorized access.

The same engineers who design and operate the Office 365 service also analyze and act on the output of our intrusion detection system. The context we have about the design of Office 365 allows us to build highly-sensitive detections while differentiating between legitimate service behavior and suspicious activity.

As we have scaled up our telemetry and analysis infrastructure, we have also innovated in how we interact with the results of our detection system. One recent development is the use of graphs for correlation and visualization.
<!--more-->
Prior to our graph approach, we represented detection results as a set of tickets in a queue for manual review. We found that it was difficult to group related activity together, and occasional bursts of benign activity would overwhelm the system with irrelevant results.

Representing detection results as graphs has enabled us to
<ul>
 	<li>evaluate intrusion detection results in context with related activity,</li>
 	<li>incorporate lower-fidelity indicators without overwhelming us with benign results, and</li>
 	<li>determine with greater fidelity when datacenter activity is likely to represent an intrusion.</li>
</ul>
<h3>Representing activity as graphs</h3>
Here are three detection results associated with a recent Red Team engagement:<a href="https://msdnshared.blob.core.windows.net/media/2017/03/alerts-freetext1.png"></a>

<a href="https://msdnshared.blob.core.windows.net/media/2017/03/alerts-freetext1.png"><img width="602" height="108" class="aligncenter wp-image-3035" alt="Three alerts represented as free text" src="https://msdnshared.blob.core.windows.net/media/2017/03/alerts-freetext1.png" /></a>

Our first insight was to represent detection results as structured data rather than as free text.

We modified our analysis pipeline to represent each result as a row in SQL with columns for the user, hostname, or network destination associated with the result:
<a href="https://msdnshared.blob.core.windows.net/media/2017/03/alerts-structured.png"><img width="601" height="209" class="aligncenter wp-image-3015" alt="Three alerts represented as structured text" src="https://msdnshared.blob.core.windows.net/media/2017/03/alerts-structured.png" /></a>

Next, we represented this multi-dimensional data as a <a href="https://en.wikipedia.org/wiki/Bipartite_graph">bipartite graph</a> of <em>detection types</em> and <em>entities.</em> We discovered that when we represented detection activity in this format, it naturally formed clusters of detection results that had entities in common:
<a href="https://msdnshared.blob.core.windows.net/media/2017/03/minigraph1.png"></a>

<a href="https://msdnshared.blob.core.windows.net/media/2017/03/minigraph1.png"><img width="599" height="304" class="aligncenter wp-image-3025" alt="Three alerts represented as a graph" src="https://msdnshared.blob.core.windows.net/media/2017/03/minigraph1.png" /></a>
This clustering behavior is similar to the analysis technique that we follow when investigating detection results. Given a detection result on one machine, we look for correlated activity associated with the same server, account, or network destination.
<h2>Operationalizing graph clusters</h2>
As we continued to refine this graph technique, we hypothesized that an intrusion would be represented in the graph as a cluster of many distinct detection types linked by common entities.

We engaged the Office 365 security team to test our hypothesis with a Red Team engagement. Our telemetry and analytics quickly detected their activity, and our graph approach linked this activity together into one large cluster (at top left in the diagram below):

&nbsp;

<a href="https://msdnshared.blob.core.windows.net/media/2017/03/alertgraph.png"><img src="https://msdnshared.blob.core.windows.net/media/2017/03/alertgraph.png" alt="Graph of clustered alerts from a red team engagement" width="700" height="456" class="aligncenter wp-image-3045" /></a>
Because related activity forms clusters in the graph, we realized that we would be more effective if we reviewed detection results cluster-by-cluster.

We built a web application using <a href="https://js.cytoscape.org/">Cytoscape.js</a> to try out this approach. It displays a list of graph clusters and allows us to review each one in detail. Here is an example showing a cluster of extended Red Team activity:<a href="https://msdnshared.blob.core.windows.net/media/2017/03/graphux.png"></a>

<a href="https://msdnshared.blob.core.windows.net/media/2017/03/graphux.png"><img src="https://msdnshared.blob.core.windows.net/media/2017/03/graphux.png" alt="Interactive alert graph showing a cluster of red team activity" width="800" height="394" class="aligncenter wp-image-3055" /></a>
We found that we made faster, more accurate decisions when we used the graph structure to evaluate detection results as clusters of related activity.
<h2>Incorporating lower-fidelity indicators</h2>
Graphs are also helping us incorporate less-specific intrusion detection analytics into our system without flooding our engineers with benign results.

For example, an analytic may give us results about anomalous logon patterns, but benign anomalies exist in a small quantity every day. Similarly, certain built-in commands may be used by both Office 365 engineers as well as adversaries. In a traditional intrusion detection approach, these analytics would present our engineers with a morass of benign results.

When we adopted a graph approach, we discovered that clustering could help us distinguish between benign results and meaningful anomalies.

We started by classifying our analytics into three categories:
<ul>
 	<li><strong>Alerts:</strong> these activities have a significant service impact and are rarely due to benign activity. For example, a new account being granted Domain Administrator privileges would be classified as an alert.</li>
 	<li><strong>Behavioral:</strong> these activities may occur due to benign service operations but may also indicate unauthorized activity. An example of a Behavioral indicator is a new process executing that has never been observed across the service.</li>
 	<li><strong>Contextual:</strong> these activities occur very frequently due to benign activity but have forensic value during an investigation. A net.exe process start is one type of Contextual indicator.</li>
</ul>
Next, we established a grading system for determining which graph clusters to investigate first:
<ul>
 	<li>Any cluster that contains an <strong>alert </strong>is given high priority and evaluated by an engineer.</li>
 	<li>Clusters that contain results from two or more types of <strong>behavioral</strong> analytic are prioritized as well.</li>
 	<li><strong>Contextual</strong> results are only presented to engineers if they are part of an alert or behavioral cluster that meets the criteria for evaluation. These results help us understand the “bigger picture” behind the atomic and behavioral activity in a given cluster.</li>
</ul>
This allows our intrusion detection pipeline to emit thousands of behavioral and contextual results each day while keeping our engineers focused on the clusters of activity that are most likely to represent an attack.
<h2>A continuing investment</h2>
Our research into graph approaches for intrusion detection is just getting started. If you have questions, suggestions, or comments, I'd love to hear from you! Feel free to reach me on Twitter at <a href="https://twitter.com/MSwannMSFT">@MSwannMSFT</a>.]]></content:encoded>
    </item>
  </channel>
</rss>