<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Spencer Alessi</title>
    <description>The latest articles on DEV Community by Spencer Alessi (@techspence).</description>
    <link>https://dev.to/techspence</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F149601%2F80354818-354a-495e-a90b-36a33b88b109.png</url>
      <title>DEV Community: Spencer Alessi</title>
      <link>https://dev.to/techspence</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/techspence"/>
    <language>en</language>
    <item>
      <title>How to Check a Sketchy Link Without Clicking It</title>
      <dc:creator>Spencer Alessi</dc:creator>
      <pubDate>Fri, 21 Feb 2020 13:28:32 +0000</pubDate>
      <link>https://dev.to/techspence/how-to-check-a-sketchy-link-without-clicking-it-1okh</link>
      <guid>https://dev.to/techspence/how-to-check-a-sketchy-link-without-clicking-it-1okh</guid>
      <description>&lt;p&gt;Let's say you're working through your dozens of emails, responding to clients or customers or business partners and you come across this one email from your bank informing you that you need to reset your password. This email comes completely out of the blue and to top it off you don't recognize the senders email address. Do you click it?&lt;/p&gt;

&lt;p&gt;Maybe...maybe not.&lt;/p&gt;

&lt;p&gt;Did you know that you can investigate if that link is sketchy or not &lt;strong&gt;&lt;em&gt;without&lt;/em&gt;&lt;/strong&gt; clicking on it?&lt;/p&gt;

&lt;p&gt;&lt;em&gt;This article and all the articles I write show up on my blog first. Head over there for more Cybersecurity thoughts, tips and write-ups: &lt;a href="https://spenceralessi.com" rel="noopener noreferrer"&gt;https://spenceralessi.com&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  How to sniff out a sketchy link
&lt;/h2&gt;

&lt;p&gt;When it comes to hyperlinks, sometime's it's really obvious it's sketchy, but other times, in the case of look-a-like domains, it can actually be a bit tricky. &lt;/p&gt;

&lt;p&gt;Here are a few things that make a link sketchy, when visibly looking at it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Links that end in uncommon top level domains (TLD). Because the cost to purchase domains within these TLDs are pretty inexpensive, they are very frequently used for spamming and malicious activity. Aside from abc.xyz which is a web site owned by Google's parent Alphabet I don't know of any legit domains with these TLDs. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Commonly used for spamming/nefarious activity:

&lt;ul&gt;
&lt;li&gt;.xyz&lt;/li&gt;
&lt;li&gt;.buzz&lt;/li&gt;
&lt;li&gt;.live&lt;/li&gt;
&lt;li&gt;.fit&lt;/li&gt;
&lt;li&gt;.tk&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Links that are knock-offs (known as look-a-like domains) of major brands. These are popular because the domain closely resembles that of real brands domains. Depending on how the URL looks in your browser and if you're on a mobile device or on your computer, you may or may not be able to spot these very easily.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Examples:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;netflix-mail[.]com&lt;/li&gt;
&lt;li&gt;t-mogbile[.]com&lt;/li&gt;
&lt;li&gt;googlre[.]com&lt;/li&gt;
&lt;li&gt;secure-paypal.com.fraud.hmmmm[.]com&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Note, these domains may or may not be valid at the time of you reading this&lt;/em&gt;&lt;/p&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Links that contain random numbers and/or letters. These are pretty obvious. Not all are malicious, however, anytime I see a url like this I immediatly get suspicious. It's not a trustworthy link in my opinion and should be investigated further.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Examples:

&lt;ul&gt;
&lt;li&gt;eqbqcguiwcymao[.]info&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  Checking a link without clicking
&lt;/h2&gt;

&lt;p&gt;There is definitly no shortage of URL and website scanners out there. I've tried dozens of them. None of them seem as good to me as URLscan. It's fast, extremely detailed, provides a live screenshot and it allows you to link out to other scanns to check them as well. &lt;/p&gt;

&lt;h3&gt;
  
  
  URLScan - &lt;a href="https://urlscan.io" rel="noopener noreferrer"&gt;https://urlscan.io&lt;/a&gt;
&lt;/h3&gt;

&lt;p&gt;My go-to move with any sketchy links is to pop them into URLScan and see what comes up. To do that, just head on over to &lt;a href="https://urlscan.io" rel="noopener noreferrer"&gt;https://urlscan.io&lt;/a&gt;. Then just simply &lt;strong&gt;copy&lt;/strong&gt; and &lt;strong&gt;paste&lt;/strong&gt; the link you want to scan into the scan field. Once there you can also click &lt;strong&gt;Options&lt;/strong&gt; and make your scan Private, which sometimes is nice to do, since Public scans will show up on the front page and in searches. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fspenceralessi.com%2Fassets%2Fimg%2Furlscan.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fspenceralessi.com%2Fassets%2Fimg%2Furlscan.png" alt="urlscan.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now that you have your link pasted in, click Scan! Once URLScan is finished checking our your link, doing it's analysis and fingerprinting it will bring you to a results page that looks something like this. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note, this is an example results page of a known malicious site.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fspenceralessi.com%2Fassets%2Fimg%2Furlscan-resultsmalicious.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fspenceralessi.com%2Fassets%2Fimg%2Furlscan-resultsmalicious.png" alt="urlscan-resultsmalicious.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Live Screenshot&lt;/strong&gt;. This allows you to visibly see if there might be anything weird going on with the site. This is good for sniffing out things like misspelled words on login pages.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fspenceralessi.com%2Fassets%2Fimg%2Furlscan-livescreenshot.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fspenceralessi.com%2Fassets%2Fimg%2Furlscan-livescreenshot.png" alt="urlscan-livescreenshot.png"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Google Safe Browsing rating&lt;/strong&gt;. This is a nice quick view of if the website is safe or potentially nefarious.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fspenceralessi.com%2Fassets%2Fimg%2Furlscan-googlesb.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fspenceralessi.com%2Fassets%2Fimg%2Furlscan-googlesb.png" alt="urlscan-googlesb.png"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Lookup the URL with other scanners&lt;/strong&gt;. The &lt;em&gt;lookup&lt;/em&gt; tab allows you to pick any of a number of other website scanners. This can help you gleen additional information about the site you're scanning incase you're still not sure about it.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fspenceralessi.com%2Fassets%2Fimg%2Furlscan-lookup.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fspenceralessi.com%2Fassets%2Fimg%2Furlscan-lookup.png" alt="urlscan-lookup.png"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Caution when Clicking
&lt;/h2&gt;

&lt;p&gt;It's a bit cliche by now but, &lt;strong&gt;think before you click!&lt;/strong&gt; It only takes a few minutes to pause, copy and paste the link into URLScan and check it out first before clicking.&lt;/p&gt;

&lt;p&gt;If you're at work and have an IT Department or Security Team, send it over to them and ask them to investigate it for you. It's better to wait 10 minutes to get a link checked out than spend 10 weeks recovering from a security incident. &lt;/p&gt;

&lt;h2&gt;
  
  
  Additional Information
&lt;/h2&gt;

&lt;p&gt;I did some googling on this topic and found some good articles related to suspcious and or malicious domains. The articles below go into much more detail on TLDs and their use for malicious or spammy activity. If you're into the technical nitty gritty these would be great reads.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://unit42.paloaltonetworks.com/newly-registered-domains-malicious-abuse-by-bad-actors" rel="noopener noreferrer"&gt;Newly Registered Domains: Malicious Abuse by Bad Actors&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.tripwire.com/state-of-security/security-data-protection/cyber-security/most-suspicious-tlds-revealed-by-blue-coat-systems" rel="noopener noreferrer"&gt;Most Suspicious TLDs Revealed by Blue Coat Systems&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://www.symantec.com/connect/blogs/exploring-xyz-another-shady-tld-report" rel="noopener noreferrer"&gt;Exploring .XYZ (Another Shady TLD Report)&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://blog.f-secure.com/why-is-theres-so-much-spam-coming-from-xyz-and-other-new-top-level-domains" rel="noopener noreferrer"&gt;Why is there’s so much spam coming from .xyz and other new top-level domains?&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>infosec</category>
      <category>cybersecurity</category>
      <category>phishing</category>
      <category>urlscan</category>
    </item>
    <item>
      <title>Quick And Easy Ways to Protect Your Company From CEO Fraud</title>
      <dc:creator>Spencer Alessi</dc:creator>
      <pubDate>Mon, 08 Apr 2019 01:49:09 +0000</pubDate>
      <link>https://dev.to/techspence/quick-and-easy-ways-to-protect-your-company-from-ceo-fraud-2al8</link>
      <guid>https://dev.to/techspence/quick-and-easy-ways-to-protect-your-company-from-ceo-fraud-2al8</guid>
      <description>&lt;p&gt;In this blog post (that originally appeared on my website: &lt;a href="https://www.spenceralessi.com/Quick-And-Easy-Ways-To-Protect-Your-Company-From-CEO-Fraud" rel="noopener noreferrer"&gt;https://www.spenceralessi.com/Quick-And-Easy-Ways-To-Protect-Your-Company-From-CEO-Fraud&lt;/a&gt;) i'm going to share one quick and easy technique you can use to protect your company from 2 different types of CEO fraud. &lt;/p&gt;

&lt;p&gt;The technique I detail in this blog post is not the only way to detect these emails. It's just one of many ways. Also. please know that nothing in this blog post is new or ground breaking. I don't propose any new fancy techniques. There are times in security where detection and prevention just comes down to a few simple, yet tedious tasks. This is one of those situations. &lt;/p&gt;

&lt;p&gt;By using a little understanding of what attackers try to do with some regular expression knowledge you can mitigate a good chuck of CEO fraud emails. My hope is that you get some value from this or maybe it prompts you to think about your phishing detection a little bit differently.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is CEO Fraud? What are Look-alike/Misspelled Domain Names?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;CEO Fraud is a type of phishing email technique where an attacker targets your accounting or billing managers, CFO, HR or other executive. The attacker will use your CEO's name along with a look-alike or Misspelled email address that's similar to your companies in order to trick your billing manager into wiring money or convince your HR manager into sending W2's. The emails that use this strategy usually have some kind of financial or employee tax record motive to them. A look-alike or Misspelled domain name is pretty self explanatory. Attackers will try to use a domain that looks similar to your company's domain. Sometimes this can be very tricky!&lt;/p&gt;

&lt;p&gt;Now, the first thing to tackle before jumping into this is to make sure you have the proper spoofing protections in place. If an attacker can spoof your companies domain, that's going to make it extremely difficult for your users to detect. So do that first. Then move onto this technique.&lt;/p&gt;

&lt;h1&gt;
  
  
  CEO Fraud Technique 1: look-alike/Misspelled Domain Names
&lt;/h1&gt;

&lt;p&gt;The thing I want you to focus on here is the &lt;strong&gt;domain&lt;/strong&gt;, everything after the @ symbol. In this blog post, my made up CEO's name is Jack Carter and the company email is eureka[.]com. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;If you're a syfy fan you will know that Jack Carter was the quirky and trouble prone Sheriff of a town called Eureka in the show with the same name. I love that show. It's about a town of geniuses that are always causing trouble, blowing stuff up or wreaking some other kind of havoc on the town.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;What attackers are hoping is that your billing manager or HR rep doesn't pay attention to the sender's information, sees the name, which matches the CEO's name, glances over the look-alike/Misspelled domain name and continues onto the body of the email. Attackers are banking on your co-workers just being lazy. Encourage your users to stay vigilant and stay aware!&lt;/p&gt;

&lt;p&gt;Ok here's an example of what i'm talking about:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a) Jack Carter &amp;lt;jcarter@eureka.com&amp;gt;

b) Jack Carter &amp;lt;jcarter@euneka.com&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Can you spot the difference between the two? Which one is the real Jack Carter? &lt;/p&gt;

&lt;p&gt;The answer is &lt;strong&gt;a&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;look-alike/Misspelled Domain Name Detection&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;One way to detect these emails is to compare the sender address with that of your CEO's actual email address using regular expressions.&lt;/p&gt;

&lt;p&gt;Here's some regex that can be used to detect look-alike or Misspelled domain names that use letter and character substitutions.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Blue highlighted text = text matches regex&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Letter Substitution&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@e(?:[^u]reka|u[^r]eka|ur[^e]ka|ure[^k]a|urek[^a]|eurk[^a])\.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Detection&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.spenceralessi.com%2Fassets%2Fimg%2Flettersubfake.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.spenceralessi.com%2Fassets%2Fimg%2Flettersubfake.png" alt="Letter Substitution Fake Domain"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Play with this regex: &lt;a href="https://regex101.com/r/tPVqPG/1/" rel="noopener noreferrer"&gt;https://regex101.com/r/tPVqPG/1/&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Character Substitution&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@e(?!ureka\.com).?u.?r.?e.?k.?a\.com
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Detection&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.spenceralessi.com%2Fassets%2Fimg%2Fcharactersubfake.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.spenceralessi.com%2Fassets%2Fimg%2Fcharactersubfake.png" alt="Character Substitution Fake Domain"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Play with this regex: &lt;a href="https://regex101.com/r/nv7uIT/1" rel="noopener noreferrer"&gt;https://regex101.com/r/nv7uIT/1&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  CEO Fraud Technique 2: Using your CEO's Name with a Random Domain Name
&lt;/h1&gt;

&lt;p&gt;As the title of this section implies, there is another technique that I have seen attackers use. They will use your CEO's name or a variation of their name combined with a random domain name.&lt;/p&gt;

&lt;p&gt;The thing I want you to focus on here is the &lt;strong&gt;sender name&lt;/strong&gt;, everything before the @ symbol. Again, in this blog post, my made up CEO's name is Jack Carter and the company email is eureka[.]com.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;I will repeat myself here because it's so important..&lt;/strong&gt; Attackers are hoping is that your billing manager or HR rep doesn't pay attention to the sender's information, sees the name, which matches the CEO's name and continues onto the body of the email. Attackers are banking on your co-workers just being lazy. Encourage your users to stay vigilant and stay aware!&lt;/p&gt;

&lt;p&gt;Ok here's an example of what i'm talking about:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;a) Jack Carter &amp;lt;whizbank@bankerceo.com&amp;gt;

b) Jack Carter &amp;lt;jcarter@eureka.com&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Can you spot the difference between the two? Which one is the real Jack Carter? &lt;/p&gt;

&lt;p&gt;The answer is &lt;strong&gt;b&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CEO's Name with a Random Domain Name Detection&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Just like technique 1, one way to detect these emails is to, this time, compare the sender name with that of your CEO's actual name using regular expressions.&lt;/p&gt;

&lt;p&gt;Here's some regex that can be used to detect names that use character substitutions.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Green highlighted text = text that matches a group of regex&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;character substitution&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[jJ][aA][cC][kK]\s[cC][aA][rR][tT][eE][rR]
[jJ][aA][cC][kK]\s[aA-zZ]\s[cC][aA][rR][tT][eE][rR]
[jJ][aA][cC][kK]\s[aA-zZ][.]\s[cC][aA][rR][tT][eE][rR]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can also combine these into one regex with the | character, wrapped with ()&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;([jJ][aA][cC][kK]\s[cC][aA][rR][tT][eE][rR]|[jJ][aA][cC][kK]\s[aA-zZ]\s[cC][aA][rR][tT][eE][rR]|[jJ][aA][cC][kK]\s[aA-zZ][.]\s[cC][aA][rR][tT][eE][rR])
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Detection&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.spenceralessi.com%2Fassets%2Fimg%2Fcharactersubfake-ceoname.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fwww.spenceralessi.com%2Fassets%2Fimg%2Fcharactersubfake-ceoname.png" alt="Character Substitution Fake CEOs Name"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Play with this regex: &lt;a href="https://regex101.com/r/u1VvHb/1" rel="noopener noreferrer"&gt;https://regex101.com/r/u1VvHb/1&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Now create your email filtering rules&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once you have some regex figured out, now you can go to your email gateway or whatever you are using to filter email based on rules and create a rule that uses these regular expressions to detect and handle this emails. I would love to include examples of how to do this with different platforms, but at this point, I just don't have access to a variety of platforms.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;&lt;em&gt;That’s all I have for now on this topic. I truly hope that someone, maybe 1 or 2 people find value in this. If you did get value from this, please share it and if my thoughts sparked an idea of your own or if you want to continue this conversation, hit me up on Twitter &lt;a href="https://twitter.com/techspence" rel="noopener noreferrer"&gt;@techspence&lt;/a&gt;, I would love to connect!&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>cybersecurity</category>
      <category>emailsecurity</category>
      <category>phishing</category>
      <category>ceofraud</category>
    </item>
    <item>
      <title>Using Powershell and Microsoft EWS Managed API to download attachments in Exchange 2016</title>
      <dc:creator>Spencer Alessi</dc:creator>
      <pubDate>Tue, 26 Mar 2019 14:46:04 +0000</pubDate>
      <link>https://dev.to/techspence/using-powershell-and-microsoft-ews-managed-api-to-download-attachments-in-exchange-2016-2171</link>
      <guid>https://dev.to/techspence/using-powershell-and-microsoft-ews-managed-api-to-download-attachments-in-exchange-2016-2171</guid>
      <description>

&lt;p&gt;This blog post originally appeared on my website. You can check it out here(&lt;a href="https://www.spenceralessi.com/Using-Powershell-and-Microsoft-EWS-Managed-API-to-download-attachments-in-Exchange-2016"&gt;https://www.spenceralessi.com/Using-Powershell-and-Microsoft-EWS-Managed-API-to-download-attachments-in-Exchange-2016&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Have you ever used a piece of software that provides no way of saving attachments or reports directly to a file? Yeah, me too. It's frustrating. I'm very passionate about automating repetitive tasks and the frustration I've had over this particular issue has caused me to look into a solution. What I found was that I can use my beloved Powershell, in combination with Microsoft Exchange Web Services Managed API, to download attachments from my (or any other) outlook mailbox. So, to solve this little problem and add a bit of automation I have created a Powershell script, that runs from a scheduled task, that will do just that. This blog post describes the details of how this Powershell script works. I call it, not so cleverly, &lt;a href="https://github.com/techspence/EWSEmailAttachmentSaver"&gt;EWSEmailAttachmentSaver&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Although this blog post is more related to system administration than security in terms of who would be creating this type of script at a given organization, my opinion is that the same qualities and skills that make up a good sysadmin overlap with the qualities and skills that make up a good information security practitioner. Fortunately, I work for an organization that has a relatively small IT department and I am given the freedom and autonomy to work on projects like this. Also, i've worked my way up the ranks from Help Desk and I am used to creating these scripts and automated processes, because that's what I have been doing the last 8 years. So now onto explaining the script..&lt;/p&gt;

&lt;p&gt;But first one quick note.&lt;/p&gt;

&lt;p&gt;I think it's really import to make sure you provide good documentation with and/or within your scripts. As I grow and develop my own skills I am reminded regularly how important good documentation is. I will go into more details about this in another post. But know that, if you plan to use a script in a production environment, please do document well, use common language and built-in functions. It helps troubleshoot issues immensely in the future, especially if someone else takes over your scripts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Resources
&lt;/h2&gt;

&lt;p&gt;Upon deciding I wanted to create a script to automate some of my daily reports I found some very helpful blog posts. The two main blog posts this script was built from are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://gsexdev.blogspot.com/2012/01/ews-managed-api-and-powershell-how-to.html"&gt;EWS Managed API and Powershell How-To series Part 1&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;a href="https://gsexdev.blogspot.com/2010/01/writing-simple-scripted-process-to.html"&gt;Writing a simple scripted process to download attachments in Exchange 2007/ 2010 using the EWS Managed API&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Glen's examples and write ups were very helpful in understanding EWS and how to write some Powershell to work with the API. Thanks Glen! If you are interested in learning more about Exchange or Office365 and Powershell, be sure to check out his blog. &lt;a href="https://gsexdev.blogspot.com"&gt;Glen's Exchange and Office 365 Dev Blog&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  EWS Email Attachment Saver
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Requirements&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This script requires:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Exchange 2007 or newer&lt;/li&gt;
&lt;li&gt;Exchange Web Services (EWS) Managed API 2.2&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;User Defined Variables&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;At the top of the script, under the comment section you will see a handful of user defined variables. If you use this script, most of your changes will occur here. This is all pretty standard stuff.&lt;/p&gt;

&lt;p&gt;This script has several functions:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;Function LogWrite&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Using &lt;code&gt;!(Test-Path $logpath)&lt;/code&gt; I first check to see if the path to the log file exists, if not I create it. If it does exist, I use the &lt;code&gt;Add-content&lt;/code&gt; cmdlet to send information i've specified to the log file.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;Function FindTargetFolder&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This function loops through the processed folders path until target folder is found. In my script, i've conveniently make the processed folder directly underneath the root of my mailbox.&lt;/p&gt;

&lt;p&gt;Fun little side-note, the root of your mailbox is called the &lt;em&gt;Top Information Store&lt;/em&gt; and is sometimes displayed like this &lt;code&gt;\\email@company.com&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Note, that my script assumes that the &lt;em&gt;processed folder&lt;/em&gt; is a subfolder of the root of the users mailbox (e.g. &lt;code&gt;\\email@company.com\ProcessedFolder&lt;/code&gt;)&lt;/p&gt;

&lt;p&gt;Fun little fact I found out was that, if you change the &lt;em&gt;processed folder&lt;/em&gt; to be underneath any other folder, including the Inbox, the script requires slight modification.&lt;/p&gt;

&lt;p&gt;If your &lt;em&gt;processed folder&lt;/em&gt; is a subfolder under any other folder you must change &lt;code&gt;$processedfolderpath&lt;/code&gt; and &lt;code&gt;$tftargetidroot&lt;/code&gt; appropriately.&lt;/p&gt;

&lt;p&gt;To quickly view the outlook folder location, right click on a folder in outlook, then click properties.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Example: processed folder is a subfolder of the root mailbox:&lt;/em&gt; &lt;code&gt;Location: \\email@company.com\ProcessedFolder&lt;/code&gt;&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$processedfolderpath = "/ProcessedFolder"
$tftargetidroot = New-Object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::MsgFolderRoot,$mailbox)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Example, processed folder is a subfolder of Inbox:&lt;/em&gt; &lt;code&gt;Location: \\email@company.com\Inbox\ProcessedFolder&lt;/code&gt;&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$processedfolderpath = "/Inbox/ProcessedFolder"
$tftargetidroot = New-Object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$processedfolderpath)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;&lt;code&gt;Function FindTargetEmail&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This is the main driver function that controls most of the scripts actions. Essentially this function loops through the emails that have been found using our filters, which I will explain in a minute, then it:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Determines the download location based on the attachment name&lt;/li&gt;
&lt;li&gt;Saves the attachment to the download location, then closes it&lt;/li&gt;
&lt;li&gt;Marks the email(s) as read then moves them to the processed folder&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;As you can see there are some splitting of attachment names and some hackery to make sure I move the files to the correct monthly folder. This is just my own OCD, it's not really necessary. :)&lt;/p&gt;

&lt;h2&gt;
  
  
  Using the Exchange EWS API
&lt;/h2&gt;

&lt;p&gt;Now that i've explained what the functions do, we can move on to explaining the Exchange EWS API. To learn more about it, see &lt;a href="http://www.microsoft.com/en-us/download/details.aspx?id=42951"&gt;Download the Microsoft Exchange Web Services Managed API 2.2 from&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Download and Install the EWS Managed API&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Once you download and install the Exchange EWS API components you need to load the appropriate EWS dll for the API namespace you want to use. By loading the &lt;code&gt;Microsoft.Exchange.WebServices.Data&lt;/code&gt; namespace we have access to a majority of the EWS classes and methods. Here is how you load the EWS dll.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$dllpath = "C:\Program Files\Microsoft\Exchange\Web Services\2.2\Microsoft.Exchange.WebServices.dll"
[void][Reflection.Assembly]::LoadFile($dllpath)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Once you load the Webservices dll you can begin working with it. To read more about the EWS API see: &lt;a href="http://msdn.microsoft.com/en-us/library/jj220535(v=exchg.80).aspx"&gt;Microsoft EWS Managed API Reference&lt;/a&gt;. Also note, there are multiple namespaces, for example, for things such as Autodiscover and Authentication, I suggest reviewing them if you want to learn more or mess around with other functionality.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Create an EWS Service Object&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now you need to create an EWS Service Object for the target mailbox. There are many ways you can authentication to the EWS API. For my script I chose to just use my organizations Autodiscover URL, which allows me to authenticate using the user who is running the script.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$exchangeservice.UseDefaultCredentials = $true
$exchangeservice.AutodiscoverUrl($mailbox)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This also makes it convenient for me when I create a scheduled task out of this script. I can permission a service account accordingly without having to worry about hard coding credentials in my script. Hard coded creds should be avoided at all costs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Bind to the Inbox&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Now you need to simply Bind to the users Inbox. There are again a few ways to do this. I chose to use the &lt;code&gt;WellKnownFolderName&lt;/code&gt; enum. &lt;code&gt;WellKnownFolderName&lt;/code&gt; defines common folder names that are used in a users mailbox.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$inboxfolderid = New-Object Microsoft.Exchange.WebServices.Data.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Inbox,$mailbox)
$inboxfolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($exchangeservice,$inboxfolderid)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Configure Search Filter&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;One of the last things to do is to create some search filters for the emails we are targeting. This time we are going to use the &lt;code&gt;EmailMessageSchema&lt;/code&gt; class combined with the &lt;code&gt;IsRead&lt;/code&gt;, &lt;code&gt;Subject&lt;/code&gt; and &lt;code&gt;HasAttachments&lt;/code&gt; fields. The subject I am targeting can be seen in the user defined variables section. I am looking for emails that contain the subject "Path Report." The other filters should be pretty self explanatory.&lt;/p&gt;

&lt;p&gt;One cool thing to note is you can chain these filters together, throw an &lt;code&gt;And&lt;/code&gt; at the end and create some logic out of it.&lt;/p&gt;

&lt;p&gt;Once you create those variables you add them all up into a collection and use that to find all the emails you're targeting.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$sfunread = New-Object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.EmailMessageSchema]::IsRead, $false)
$sfsubject = New-Object Microsoft.Exchange.WebServices.Data.SearchFilter+ContainsSubstring ([Microsoft.Exchange.WebServices.Data.EmailMessageSchema]::Subject, $subjectfilter)
$sfattachment = New-Object Microsoft.Exchange.WebServices.Data.SearchFilter+IsEqualTo([Microsoft.Exchange.WebServices.Data.EmailMessageSchema]::HasAttachments, $true)
$sfcollection = New-Object Microsoft.Exchange.WebServices.Data.SearchFilter+SearchFilterCollection([Microsoft.Exchange.WebServices.Data.LogicalOperator]::And);
$sfcollection.add($sfunread)
$sfcollection.add($sfsubject)
$sfcollection.add($sfattachment)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;"View" the Results&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I create a view filter so as to limit the query overhead. I chose to make this script view 10 items at a time. This was a tip I found from &lt;a href="https://seanonit.wordpress.com/2014/10/29/using-powershell-and-ews-to-monitor-a-mailbox/"&gt;Using PowerShell and EWS to monitor a mailbox&lt;/a&gt;.&lt;/p&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$view = New-Object -TypeName Microsoft.Exchange.WebServices.Data.ItemView -ArgumentList 10
$foundemails = $inboxfolder.FindItems($sfcollection,$view)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Then I just call &lt;code&gt;FindTargetFolder($processedfolderpath)&lt;/code&gt; and &lt;code&gt;FindTargetEmail($subject)&lt;/code&gt; and you're done.&lt;/p&gt;

&lt;p&gt;Now hit that command line, navigate to the folder where your script resides, and run it using &lt;code&gt;.\EWSEmailAttachmentSaver.ps1&lt;/code&gt;. Make sure you always test your code in a development or test environment BEFORE moving to production. Test, test, test!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;If anyone gets value from this, I would love to know what specifically. And if you have any comments, questions or feedback about anything I wrote above, I would love to continue the dialog on Twitter. Hit me up &lt;a href="http://twitter.com/techspence"&gt;@techspence&lt;/a&gt;&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;


</description>
      <category>powershell</category>
      <category>microsoftexchange</category>
      <category>api</category>
    </item>
  </channel>
</rss>
