{"id":29,"date":"2018-10-31T19:33:26","date_gmt":"2018-11-01T00:33:26","guid":{"rendered":"https:\/\/quicksand.tech\/?p=29"},"modified":"2018-10-31T19:34:04","modified_gmt":"2018-11-01T00:34:04","slug":"search-unifiedauditlog-quick-tip","status":"publish","type":"post","link":"https:\/\/quicksand.tech\/index.php\/2018\/10\/31\/search-unifiedauditlog-quick-tip\/","title":{"rendered":"Search-UnifiedAuditLog Quick Tip"},"content":{"rendered":"<p>My poor neglected site. \ud83d\ude41<\/p>\n<p>I use the Search-UnifedAuditLog a lot. I should probably learn to use the API, but Search-UnifiedAudit log is how I start my day. When I have more time I&#8217;d like to do a write up of how I&#8217;ve scripted this, what I do with it, and how I parse out the output.<\/p>\n<p>Basically, I use Search-UnifiedAuditLog in two ways. Each morning I do a bit of &#8220;threat hunting,&#8221; in which I dump a bunch of logins and try to look for suspicious looking patterns. I can get more into that later.<\/p>\n<p>The second way, and arguably the more important way, is during incident response. During an active phishing campaign, I&#8217;m always finding new IOCs and needing to quickly get the results from the Audit Log (because some months ago Cloud App Security stopped showing &#8220;non-interactive&#8221; logins from legacy auth). So, again, I&#8217;d like to do a bigger write up on how I use this, but today, to show I&#8217;m alive on this blog, I&#8217;ll leave a quick tip.<\/p>\n<p>Usually, a compromised account that starts sending internal phishes will get reported. From there, I&#8217;ll check the account&#8217;s logins in the Audit Log in Security and Compliance to get login IP addresses as well as collect IP addresses from the messages sent through the Threat Explorer.<\/p>\n<p>The basic Search-UnifiedAuditLog command looks like this:<\/p>\n<div>\n<blockquote>\n<div>Search-UnifiedAuditLog -StartDate $start -EndDate $end -Operations UserLoggedIn -IPAddresses [IOCs here] -SessionCommand ReturnLargeSet -ResultSize 5000<\/div>\n<\/blockquote>\n<div><\/div>\n<\/div>\n<p>I&#8217;ll take all of those IP addresses and start filling in those IOCs. In the event I had tons of addresses (usually a deduplicated column from the csv export), I&#8217;d do a stupid $hold = get-content out.txt; $all = &#8220;&#8221;; foreach($i in $hold){$all = $all +&#8221;, &#8221; + $i}; $all.substring(2) | clip OR something messy like that, don&#8217;t quote me on it&#8230;then I&#8217;d paste the new comma delimited list into the [IOCs here] portion of the script.<\/p>\n<p>NO MORE.<\/p>\n<p>If you&#8217;ve got a text file, with a single IP per line, you can do -IPAddresses (get-content ip.txt)!!!<\/p>\n<p>Maybe this is obvious but it allowed me to build scripts to check against a set of bad \/23s so easily. Considering how stupid my previous pipe-to-clip method was, being that my IPs were already in an acceptable text file, this was awesome for me.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>My poor neglected site. \ud83d\ude41 I use the Search-UnifedAuditLog a lot. I should probably learn to use the API, but Search-UnifiedAudit log is how I start my day. When I have more time I&#8217;d like to do a write up of how I&#8217;ve scripted this, what I do with it, and how I parse out&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[5,4,6,7,3],"class_list":["post-29","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-auditlog","tag-exchange","tag-incident-response","tag-phishing","tag-powershell"],"_links":{"self":[{"href":"https:\/\/quicksand.tech\/index.php\/wp-json\/wp\/v2\/posts\/29","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/quicksand.tech\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/quicksand.tech\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/quicksand.tech\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/quicksand.tech\/index.php\/wp-json\/wp\/v2\/comments?post=29"}],"version-history":[{"count":2,"href":"https:\/\/quicksand.tech\/index.php\/wp-json\/wp\/v2\/posts\/29\/revisions"}],"predecessor-version":[{"id":31,"href":"https:\/\/quicksand.tech\/index.php\/wp-json\/wp\/v2\/posts\/29\/revisions\/31"}],"wp:attachment":[{"href":"https:\/\/quicksand.tech\/index.php\/wp-json\/wp\/v2\/media?parent=29"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/quicksand.tech\/index.php\/wp-json\/wp\/v2\/categories?post=29"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/quicksand.tech\/index.php\/wp-json\/wp\/v2\/tags?post=29"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}