<?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>Forem: OULD AMARA Amine</title>
    <description>The latest articles on Forem by OULD AMARA Amine (@oaamine).</description>
    <link>https://forem.com/oaamine</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%2F740648%2F0897e06a-aecb-49ba-a3f3-bb4b53f3dc17.jpeg</url>
      <title>Forem: OULD AMARA Amine</title>
      <link>https://forem.com/oaamine</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/oaamine"/>
    <language>en</language>
    <item>
      <title>How to turn your linux machine into a Router.</title>
      <dc:creator>OULD AMARA Amine</dc:creator>
      <pubDate>Thu, 17 Feb 2022 23:16:16 +0000</pubDate>
      <link>https://forem.com/oaamine/how-to-turn-your-linux-machine-into-a-router-1ag4</link>
      <guid>https://forem.com/oaamine/how-to-turn-your-linux-machine-into-a-router-1ag4</guid>
      <description>&lt;h1&gt;
  
  
  Routing
&lt;/h1&gt;

&lt;h1&gt;
  
  
  Setting up a home lab
&lt;/h1&gt;

&lt;p&gt;First things first, before setting up a network, always use a diagram, it helps you get your plan in order and not get lost along the way. So this is our diagram.&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5om28qs3gffbojkespq9.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F5om28qs3gffbojkespq9.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Explaining the diagram
&lt;/h2&gt;

&lt;p&gt;So the first thing we're going to do is download and install oracle virtualbox which is what we're going to use to run our virtual machines on, after that's installed we're going to download a debian 9 iso. Next after we have everything downloaded we're going to create our first virtual machine that hosts our router machine. We're going to give this virtual machine three network adapters : One is going to be used to connect to the outside internet and the other two are going to be used to connect to the other two machines that are part of virtualbox' internal network.&lt;br&gt;
After our virtual machine is created, we're going to install debian 9 on it and then we're going to assign IP addressing for the internal network, the external network will automatically get IP addressing from your home router so we don't have to worry about it. After we have IP addressing setup, we're going to install the other two "client" machines and connect them to the router, this way the two machines will be able to ping one another.&lt;/p&gt;

&lt;h2&gt;
  
  
  Downloading and installing required software and OS
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Oracle virtual box
&lt;/h3&gt;

&lt;p&gt;Note that the performance of your computer might be affected depending on what hardware do you have and how much you allocate to your virtual machines.&lt;/p&gt;

&lt;h4&gt;
  
  
  On windows
&lt;/h4&gt;

&lt;p&gt;Head out to virtual box's &lt;a href="https://www.virtualbox.org/wiki/Downloads" rel="noopener noreferrer"&gt;download page&lt;/a&gt; and follow the installation instruction.&lt;/p&gt;

&lt;h4&gt;
  
  
  On linux
&lt;/h4&gt;

&lt;p&gt;Just follow &lt;a href="https://blogs.oracle.com/virtualization/post/installing-virtualbox-on-oracle-enterprise-linux" rel="noopener noreferrer"&gt;this guide&lt;/a&gt; by Oracle. If you have dependencies issues, check out &lt;a href="https://www.virtualbox.org/wiki/Linux%20build%20instructions" rel="noopener noreferrer"&gt;this page&lt;/a&gt; by the virtualbox team.&lt;/p&gt;

&lt;h4&gt;
  
  
  On MacOS
&lt;/h4&gt;

&lt;p&gt;Much like windows, you only need to visit virtual box's &lt;a href="https://www.virtualbox.org/wiki/Downloads" rel="noopener noreferrer"&gt;download page&lt;/a&gt; and select the OS X hosts option, then follow the installation instruction and you're done.&lt;/p&gt;

&lt;h3&gt;
  
  
  debian 9
&lt;/h3&gt;

&lt;p&gt;We will download debian 9 in and iso format, &lt;a href="https://cdimage.debian.org/cdimage/archive/9.13.0/amd64/iso-dvd/debian-9.13.0-amd64-DVD-1.iso" rel="noopener noreferrer"&gt;Click this link to get it&lt;/a&gt;. Remember where you downloaded the ISO file, because you'll need to know that later. &lt;/p&gt;

&lt;h2&gt;
  
  
  Creating the virtual machines
&lt;/h2&gt;

&lt;p&gt;So the next thing we're going to do is we're going to create our virtual machines. Open up virtualbox, I'm using Linux Ubuntu 20.04 so your interface might look slightly different if you're running it on Windows or MacOS. &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe8519yy309xsahzdjg3v.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe8519yy309xsahzdjg3v.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
We'll go to "new" and we're going to create the router debian 9 machine first, pick linux as the type and debian 64 as the version, also you should name it accordingly to remember which machine is which. just leave all the settings by default and simply click next, the settings should be so that you can use at least run three virtual machines at the same time depending on you computer's hardware, or you can tweak them as you please.Next, click on your newly created VM, go to Settings, Network, remember if we look at the diagram, we're creating our router right now so we want to have three NICs (Network Interface Controllers) we want one that's dedicated for the internet that's going to be running NAT and then we'll have two that are dedicated for the internal vmware network. So our third adapter is going to connect to our our house internet and be given an IP address automatically by your router's DHCP, so we want to add one two more adapters. But before that go, we will create two NAT networks (A NAT network is a type of internal network that allows outbound connections), go to "File", "Preferences", "Network" and add two nat networks by clicking the add button.&lt;br&gt;
Back to configuring the router VM, left click it and go to Settings, Network, Adapter 1 and enable it, then simply select "NAT Network" and select the first one, do the same for adapter 2 with the other NAT Network.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing Debian 9 in our VM
&lt;/h2&gt;

&lt;p&gt;the VM is configured but it's still empty, so next we are going to install Debian 9 on it. In order for the machine to detect the installation file, we will insert it in it's IDE storage controller, left click the machine, go to "Settings" and then "Storage", click on the "Empty" under "Controller : IDE" then on the blue disk next to the list for "Optical Drive" to choose a virtual optical drive, navigate to the debian 9 iso file you downloaded and select it and hit OK.&lt;br&gt;
Now fire up the vm by double clicking it and you'll be faced with a classic debian installation. Read the official debian documentation if you're stuck at one of installation steps.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cloning the VM twice to get the clients machines
&lt;/h2&gt;

&lt;p&gt;To create the other two clients' machines, it's much faster to just clone the router machine, after the installation process has finished, go ahead and close the VM, in virtualbox right click and choose "Clone", Rename it something like "debian 9 right" and do the same for the left one. We will configure the networks for each one of them later.&lt;/p&gt;

&lt;h2&gt;
  
  
  Configure the network interfaces inside debian
&lt;/h2&gt;

&lt;p&gt;Once inside the debian 9 Router VM, we will have to setup the two internal network interfaces. open a terminal and write "ip a", you'll see the loopback interface and below it the three adapters we attached to the machine,notice that the first two, enp0s3 and enp0s8 don't show much information, that because they are the NAT network ones and are not configured, let's fix that. Write this command to open up a text editor with the interfaces configuration file opened in it &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

sudo gedit /etc/network/interface


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;If you are unfamiliar with networking concepts such as IP addressing, i strongly advise you to read up on it, as i won't cover them in this guide, you should also learn more about debian network configuration and naming. Go ahead and copy the text below into that text editor.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

auto enp0s3
iface enp0s3 inet static
    address 192.168.10.254
    netmask 255.255.255.0

auto enp0s8
iface enp0s8 inet static
    address 192.168.20.254
    netmask 255.255.255.0


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Close the editor and restart the networking service by typing the following command :&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

sudo systemctl restart networking


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Type "ip a" again and see that now they are configured. What we basically did here is that we configured the two network interfaces to connect two the other two clients machines, now we will configure each one of them to connect to the router using the gateway address.&lt;/p&gt;

&lt;h1&gt;
  
  
  Configuring the right debian 9 Client
&lt;/h1&gt;

&lt;p&gt;Before starting the right machine, we have to change some settings since it's a cloned machine, it will have the same MAC address as our router's, and il will also have three network adapter and we only need one. right click the right machine and go to "Settings", "Network", disable adapters 2 and 3 and make adapter 1 attached to "NAT network" and as name the first one, now start the machine. you can run the "ip a" command to take a look&lt;br&gt;
Just like we did for the router, open the interfaces file and write these lines : &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

auto enp0s3
iface enp0s3 inet static
    address 192.168.20.10
    netmask 255.255.255.0
    gateway 192.168.20.254


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Don't forget to restart the networking service. now you can try to ping the router by typing "ping 192.168.20.254" in the terminal, and you do the same from the router and ping the right client with it's address 192.168.20.10&lt;/p&gt;

&lt;h1&gt;
  
  
  Configuring the left debian 9 Client
&lt;/h1&gt;

&lt;p&gt;Same steps as the right client, only changes are in selecting "natnetwork1" instead of the first one, and add these lines to the interfaces file :&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

auto enp0s3
iface enp0s3 inet static
    address 192.168.10.10
    netmask 255.255.255.0
    gateway 192.168.10.254


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Don't forget to restart the networking service. now you can try to ping the router by typing "ping 192.168.10.254" in the terminal, and you do the same from the router and ping the left client with it's address 192.168.10.10&lt;/p&gt;

&lt;p&gt;Now from one client try to ping the other, from the left machine ping 192.168.10.254 and from the right machine ping the left machine with ping 192.168.20.254, not working? Go to the next step&lt;/p&gt;

&lt;h1&gt;
  
  
  Enabling and disabling routing in the router machine
&lt;/h1&gt;

&lt;p&gt;Don't interrupt the two machines trying to ping each other, now go to the router machine and type the command&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

sudo more /proc/sys/net/ipv4/ip_forward


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;You'll get a 0, meaning forwarding packets on this machine is disabled. To enable it, execute this command : &lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;

sudo echo 1 &amp;gt; /proc/sys/net/ipv4/ip_forward


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Go back to the two client machines and you'll see that it's working, just like a light switch.&lt;/p&gt;

&lt;p&gt;You now know how to configure interfaces on your debian machines and setup a router.&lt;/p&gt;

</description>
      <category>networking</category>
      <category>tutorial</category>
      <category>linux</category>
    </item>
    <item>
      <title>Security Information and Event Management (SIEM) using Microsoft Sentinel.</title>
      <dc:creator>OULD AMARA Amine</dc:creator>
      <pubDate>Thu, 17 Feb 2022 23:00:10 +0000</pubDate>
      <link>https://forem.com/oaamine/security-information-and-event-management-siem-using-microsoft-sentinel-12j9</link>
      <guid>https://forem.com/oaamine/security-information-and-event-management-siem-using-microsoft-sentinel-12j9</guid>
      <description>&lt;h1&gt;
  
  
  What's a SIEM
&lt;/h1&gt;

&lt;p&gt;SIEM stands for security information and event management and provides organizations with next-generation detection, analytics and response. SIEM software combines security information management (SIM) and security event management (SEM) to provide real-time analysis of security alerts generated by applications and network hardware. SIEM software matches events against rules and analytics engines and indexes them for sub-second search to detect and analyze advanced threats using globally gathered intelligence. This gives security teams both insight into and a track record of the activities within their IT environment by providing data analysis, event correlation, aggregation, reporting and log management.&lt;br&gt;
SIEM software can have a number of features and benefits, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Consolidation of multiple data points&lt;/li&gt;
&lt;li&gt;Custom dashboards and alert workflow management &lt;/li&gt;
&lt;li&gt;Integration with other products&lt;/li&gt;
&lt;/ul&gt;
&lt;h1&gt;
  
  
  How does a SIEM work ?
&lt;/h1&gt;

&lt;p&gt;SIEM software works by collecting log and event data generated by an organizations applications, security devices and host systems and bringing it together into a single centralized platform. SIEM gathers data from antivirus events, firewall logs and other locations; it sorts this data into categories, for example: malware activity and failed and successful logins. When SIEM identifies a threat through network security monitoring, it generates an alert and defines a threat level based on predetermined rules. For example, someone trying to log into an account 10 times in 10 minutes is ok, while 100 times in 10 minutes might be flagged as an attempted attack. In this way it detects threats and creates security alerts. SIEM's custom dashboards and event management system improves investigative efficiency and reduces time wasted on false-positives.&lt;/p&gt;
&lt;h1&gt;
  
  
  Preview of technical steps
&lt;/h1&gt;

&lt;p&gt;We're going to create a windows 10 virtual machine inside Azure and set it up as a honeypot (A honeypot is a network-attached system set up as a decoy to lure cyberattackers and to detect, deflect or study hacking attempts in order to gain unauthorized access to information systems. The same goes vice versa, in which a hacker tries to distract a, e.G. , Company with a mock-up hack, to proceed to the main hack, of which the, e.G. , company doesn’t know about.)&lt;br&gt;
In order to do that, we will turn the external firewall off for the VM and we're going to turn the windows firewall off as well so our machine will be exposed to the internet and anyone can ping it from any country. Next we're going to create a log repository in azure called a "log analytics workspace" which will be used to ingest our logs from the virtual machine and then we're going to set up azure sentinel (Microsoft's cloud native SIEM) within azure which we're going to use to create a map that maps all the different attacker data so we can see from which country are the attacks coming.&lt;br&gt;
We're also going to use PowerShell in this lab in order to get the country's latitude and longitude, we'll extract the IP addresses from the VM's windows event security log and send it to a third-party API which will derive the latitude and longitude send back the state and province of the incoming attacks to our virtual machine which we'll then use to create a custom log with geographic data in it to display it in a map inside azure.&lt;br&gt;
One of the main features of a SIEM is to be able to create triggers and alerts when incidents occur, but this post will not cover that, I'll let you figure that out by yourself. &lt;br&gt;
What we will do is extract failed logon data and ingest it into sentinel and  map it on a world map so we can visualize where the attacks are coming from.&lt;/p&gt;
&lt;h1&gt;
  
  
  Create an A virtual machine in Azure
&lt;/h1&gt;


&lt;h4&gt;
  
  
  Before you start the lab, DO NOT FORGET or SKIP the VERY IMPORTANT NOTE at the end of the lab
&lt;/h4&gt;

&lt;p&gt;To create the windows 10 VM in Azure, you'll have to sign up for an Azure subscription, it's free and you get 200 dollars worth of free credits, but you'll have to provide some credit card info.&lt;br&gt;
After that, when you're on your account's homepage, search for "virtual machine" and click it, on the left you'll see a plus sign with "Create" written next to it, click it.&lt;/p&gt;

&lt;p&gt;Under "Resource group" click "New", a resource group is basically a logical grouping of resources in azure that share the same lifespan, you can name it "honeypot" or something memorable like that, for the name of the vm, do the same, and set the image as Windows 10 pro. Other settings are fine, just enter a username and password and make sure to remember them, check the licensing checkbox and move to the networking tab.&lt;/p&gt;
&lt;h1&gt;
  
  
  Allow all in firewall
&lt;/h1&gt;

&lt;p&gt;Under "NIC security group" which you can think of it as the equivalent of a firewall, choose Advanced and create a new one, under inbound rules you'll find a default rule, remove it and click "Add an inbound rule" which we will configure to allow all incoming connections into the VM. For "Destination port ranges" put a star(*), "Protocol" as Any, "Action" allow, "Priority" 100 and set the name whatever you want. &lt;br&gt;
And like this, our VM is discoverable by any mean; SYN scans, TCP pings, ICMP pings and other techniques can now find the machine. Hit OK and then "Review + Create", it'll take some time so open another tab with azure in it.   &lt;/p&gt;
&lt;h1&gt;
  
  
  Create analytics workspace
&lt;/h1&gt;

&lt;p&gt;Next search for "Log Analytics Workspaces", here we will setup ingesting logs from the vm, ingest windows event logs and create our own custom log that contain geographic data.&lt;br&gt;
Click "Create log analytics workspace", for the ressource group, select the one we just created, name it, and click "Review + Create" then "Create" &lt;/p&gt;
&lt;h1&gt;
  
  
  Enable gathering VM logs in Security center
&lt;/h1&gt;

&lt;p&gt;Next, search for "Security center", this is where we enable the ability to gather logs from the virtual machine into the logs analytics workspace. On the left side panel, click "pricing and security" and then the log analytics workspace we just made, turn on "Servers" and turn of "SQL servers on machines" because we won't need them in this lab, hit save.&lt;br&gt;
Next in the left panel click "Data Collection" and select "all events" and save.&lt;/p&gt;
&lt;h1&gt;
  
  
  Connect log analytics to VM
&lt;/h1&gt;

&lt;p&gt;Go back to log analytics, select the workspace from the left side panel, under "workspace data sources" click "virtual machines" and simply click "connect".&lt;/p&gt;
&lt;h1&gt;
  
  
  Setup Azure Sentinel
&lt;/h1&gt;

&lt;p&gt;Search for "Azure Sentinel" and hit create, here you can pick the analytics workspace you want to connect to, right click the one we just created and hit add.&lt;/p&gt;
&lt;h1&gt;
  
  
  Log into VM with remote access
&lt;/h1&gt;

&lt;p&gt;In order to log in to your virtual machine, search for virtual machines, and click it. In the essentials section you can find the machine's IP address, copy it so that we can connect toit using remote desktop. Depending on the OS you're using, you should find a native software that allows you to connect remotely to a machine. If you're on windows 10, open the start menu and search for Remote Desktop, if not, i'll let you figure out a way to do it for practice. Enter the IP address you just copied and connect using the machine's credentials  &lt;/p&gt;
&lt;h1&gt;
  
  
  Observing event viewer logs in analytics
&lt;/h1&gt;

&lt;p&gt;Once on the VM, open up the event viewer by searching it in the start menu, on the left side panel select "Windows logs" and then "Security" and you'll be faced with all the security event on the VM. What we're interested in here is event ID 4625, which is the audit failure security event. If you go back to your computer and try to log in again into the VM only this time using incorrect credentials, it'll show up in the security logs and you can see the details of the failed logon, among them the IP address from which the person tried to connect to the VM, in this case your IP. We will use it later to determine the country this happened from.&lt;/p&gt;
&lt;h1&gt;
  
  
  Turn off windows firewall in VM
&lt;/h1&gt;

&lt;p&gt;In order for our machine to be discoverable in the internet, let's turn off the firewall. For that, in the windows 10 virtual machine go to start and type "wf.msc", this will open windows defender firewall settings, click on "windows defender firewall properties" then turn everything off in "domain profile", "private profile" and "public profile".&lt;br&gt;
You can try to ping the VM from your computer and it'll work.&lt;/p&gt;
&lt;h1&gt;
  
  
  Powershell script
&lt;/h1&gt;

&lt;p&gt;This is a script that will export logs to a text file which will be used to map the incoming attacks, go ahead and copy it in Powershell ISE by going to the start menu and searching for it, hit save and name the .ps1 file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="c"&gt;# Get API key from here: https://ipgeolocation.io/&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nv"&gt;$API_KEY&lt;/span&gt;&lt;span class="w"&gt;      &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"d4600b4efdef42b39828f5155041a457"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nv"&gt;$LOGFILE_NAME&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"failed_rdp.log"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nv"&gt;$LOGFILE_PATH&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"C:\ProgramData\&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$LOGFILE_NAME&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="c"&gt;# This filter will be used to filter failed RDP events from Windows Event Viewer&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nv"&gt;$XMLFilter&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="sh"&gt;@'
&amp;lt;QueryList&amp;gt; 
   &amp;lt;Query Id="0" Path="Security"&amp;gt;
         &amp;lt;Select Path="Security"&amp;gt;
              *[System[(EventID='4625')]]
          &amp;lt;/Select&amp;gt;
    &amp;lt;/Query&amp;gt;
&amp;lt;/QueryList&amp;gt; 
'@&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="cm"&gt;&amp;lt;#
    This function creates a bunch of sample log files that will be used to train the
    Extract feature in Log Analytics workspace. If you don't have enough log files to
    "train" it, it will fail to extract certain fields for some reason -_-.
    We can avoid including these fake records on our map by filtering out all logs with
    a destination host of "samplehost"
#&amp;gt;&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="kr"&gt;Function&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nf"&gt;write-Sample-Log&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s2"&gt;"latitude:47.91542,longitude:-120.60306,destinationhost:samplehost,username:fakeuser,sourcehost:24.16.97.222,state:Washington,country:United States,label:United States - 24.16.97.222,timestamp:2021-10-26 03:28:29"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Out-File&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$LOGFILE_PATH&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Append&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Encoding&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;utf8&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s2"&gt;"latitude:-22.90906,longitude:-47.06455,destinationhost:samplehost,username:lnwbaq,sourcehost:20.195.228.49,state:Sao Paulo,country:Brazil,label:Brazil - 20.195.228.49,timestamp:2021-10-26 05:46:20"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Out-File&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$LOGFILE_PATH&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Append&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Encoding&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;utf8&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s2"&gt;"latitude:52.37022,longitude:4.89517,destinationhost:samplehost,username:CSNYDER,sourcehost:89.248.165.74,state:North Holland,country:Netherlands,label:Netherlands - 89.248.165.74,timestamp:2021-10-26 06:12:56"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Out-File&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$LOGFILE_PATH&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Append&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Encoding&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;utf8&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s2"&gt;"latitude:40.71455,longitude:-74.00714,destinationhost:samplehost,username:ADMINISTRATOR,sourcehost:72.45.247.218,state:New York,country:United States,label:United States - 72.45.247.218,timestamp:2021-10-26 10:44:07"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Out-File&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$LOGFILE_PATH&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Append&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Encoding&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;utf8&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s2"&gt;"latitude:33.99762,longitude:-6.84737,destinationhost:samplehost,username:AZUREUSER,sourcehost:102.50.242.216,state:Rabat-Salé-Kénitra,country:Morocco,label:Morocco - 102.50.242.216,timestamp:2021-10-26 11:03:13"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Out-File&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$LOGFILE_PATH&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Append&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Encoding&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;utf8&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s2"&gt;"latitude:-5.32558,longitude:100.28595,destinationhost:samplehost,username:Test,sourcehost:42.1.62.34,state:Penang,country:Malaysia,label:Malaysia - 42.1.62.34,timestamp:2021-10-26 11:04:45"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Out-File&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$LOGFILE_PATH&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Append&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Encoding&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;utf8&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s2"&gt;"latitude:41.05722,longitude:28.84926,destinationhost:samplehost,username:AZUREUSER,sourcehost:176.235.196.111,state:Istanbul,country:Turkey,label:Turkey - 176.235.196.111,timestamp:2021-10-26 11:50:47"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Out-File&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$LOGFILE_PATH&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Append&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Encoding&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;utf8&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s2"&gt;"latitude:55.87925,longitude:37.54691,destinationhost:samplehost,username:Test,sourcehost:87.251.67.98,state:null,country:Russia,label:Russia - 87.251.67.98,timestamp:2021-10-26 12:13:45"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Out-File&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$LOGFILE_PATH&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Append&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Encoding&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;utf8&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s2"&gt;"latitude:52.37018,longitude:4.87324,destinationhost:samplehost,username:AZUREUSER,sourcehost:20.86.161.127,state:North Holland,country:Netherlands,label:Netherlands - 20.86.161.127,timestamp:2021-10-26 12:33:46"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Out-File&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$LOGFILE_PATH&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Append&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Encoding&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;utf8&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s2"&gt;"latitude:17.49163,longitude:-88.18704,destinationhost:samplehost,username:Test,sourcehost:45.227.254.8,state:null,country:Belize,label:Belize - 45.227.254.8,timestamp:2021-10-26 13:13:25"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Out-File&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$LOGFILE_PATH&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Append&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Encoding&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;utf8&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s2"&gt;"latitude:-55.88802,longitude:37.65136,destinationhost:samplehost,username:Test,sourcehost:94.232.47.130,state:Central Federal District,country:Russia,label:Russia - 94.232.47.130,timestamp:2021-10-26 14:25:33"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Out-File&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$LOGFILE_PATH&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Append&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Encoding&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;utf8&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="c"&gt;# This block of code will create the log file if it doesn't already exist&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="kr"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="n"&gt;Test-Path&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$LOGFILE_PATH&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-eq&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="bp"&gt;$false&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="n"&gt;New-Item&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-ItemType&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;File&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Path&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$LOGFILE_PATH&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="n"&gt;write-Sample-Log&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="c"&gt;# Infinite Loop that keeps checking the Event Viewer logs.&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="kr"&gt;while&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;$true&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;

    &lt;/span&gt;&lt;span class="n"&gt;Start-Sleep&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Seconds&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;1&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="c"&gt;# This retrieves events from Windows EVent Viewer based on the filter&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nv"&gt;$events&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Get-WinEvent&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-FilterXml&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$XMLFilter&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-ErrorAction&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;SilentlyContinue&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="kr"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="bp"&gt;$Error&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="c"&gt;#Write-Host "No Failed Logons found. Re-run script when a login has failed."&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;

    &lt;/span&gt;&lt;span class="c"&gt;# Step through each event collected, get geolocation&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="c"&gt;#    for the IP Address, and add new events to the custom log&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="kr"&gt;foreach&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kr"&gt;in&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$events&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;


        &lt;/span&gt;&lt;span class="c"&gt;# $event.properties[19] is the source IP address of the failed logon&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="c"&gt;# This if-statement will proceed if the IP address exists (&amp;gt;= 5 is arbitrary, just saying if it's not empty)&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="kr"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;properties&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;19&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Value&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Length&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-ge&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;

            &lt;/span&gt;&lt;span class="c"&gt;# Pick out fields from the event. These will be inserted into our new custom log&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nv"&gt;$timestamp&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;TimeCreated&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nv"&gt;$year&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;TimeCreated&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Year&lt;/span&gt;&lt;span class="w"&gt;

            &lt;/span&gt;&lt;span class="nv"&gt;$month&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;TimeCreated&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Month&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="kr"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;TimeCreated&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Month&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Length&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-eq&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nv"&gt;$month&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"0&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;TimeCreated&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Month&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;

            &lt;/span&gt;&lt;span class="nv"&gt;$day&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;TimeCreated&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Day&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="kr"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;TimeCreated&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Day&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Length&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-eq&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nv"&gt;$day&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"0&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;TimeCreated&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Day&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;

            &lt;/span&gt;&lt;span class="nv"&gt;$hour&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;TimeCreated&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Hour&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="kr"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;TimeCreated&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Hour&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Length&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-eq&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nv"&gt;$hour&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"0&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;TimeCreated&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Hour&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;

            &lt;/span&gt;&lt;span class="nv"&gt;$minute&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;TimeCreated&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Minute&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="kr"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;TimeCreated&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Minute&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Length&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-eq&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nv"&gt;$minute&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"0&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;TimeCreated&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Minute&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;


            &lt;/span&gt;&lt;span class="nv"&gt;$second&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;TimeCreated&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Second&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="kr"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;TimeCreated&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Second&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Length&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-eq&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nv"&gt;$second&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"0&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;TimeCreated&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Second&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;

            &lt;/span&gt;&lt;span class="nv"&gt;$timestamp&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$year&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;-&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$month&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;-&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$day&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$hour&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;:&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$minute&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;:&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$second&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nv"&gt;$eventId&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Id&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nv"&gt;$destinationHost&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;MachineName&lt;/span&gt;&lt;span class="c"&gt;# Workstation Name (Destination)&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nv"&gt;$username&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;properties&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;5&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Value&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c"&gt;# Account Name (Attempted Logon)&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nv"&gt;$sourceHost&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;properties&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;11&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Value&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c"&gt;# Workstation Name (Source)&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nv"&gt;$sourceIp&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$event&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;properties&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;19&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Value&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="c"&gt;# IP Address&lt;/span&gt;&lt;span class="w"&gt;


            &lt;/span&gt;&lt;span class="c"&gt;# Get the current contents of the Log file!&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nv"&gt;$log_contents&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Get-Content&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Path&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$LOGFILE_PATH&lt;/span&gt;&lt;span class="w"&gt;

            &lt;/span&gt;&lt;span class="c"&gt;# Do not write to the log file if the log already exists.&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="kr"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;-Not&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$log_contents&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-match&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$timestamp&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-or&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$log_contents&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Length&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-eq&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;

                &lt;/span&gt;&lt;span class="c"&gt;# Announce the gathering of geolocation data and pause for a second as to not rate-limit the API&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="c"&gt;#Write-Host "Getting Latitude and Longitude from IP Address and writing to log" -ForegroundColor Yellow -BackgroundColor Black&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="n"&gt;Start-Sleep&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Seconds&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;1&lt;/span&gt;&lt;span class="w"&gt;

                &lt;/span&gt;&lt;span class="c"&gt;# Make web request to the geolocation API&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="c"&gt;# For more info: https://ipgeolocation.io/documentation/ip-geolocation-api.html&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nv"&gt;$API_ENDPOINT&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://api.ipgeolocation.io/ipgeo?apiKey=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$API_KEY&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;&amp;amp;ip=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$sourceIp&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nv"&gt;$response&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Invoke-WebRequest&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-UseBasicParsing&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Uri&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$API_ENDPOINT&lt;/span&gt;&lt;span class="w"&gt;

                &lt;/span&gt;&lt;span class="c"&gt;# Pull Data from the API response, and store them in variables&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nv"&gt;$responseData&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$response&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Content&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;ConvertFrom-Json&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nv"&gt;$latitude&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$responseData&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;latitude&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nv"&gt;$longitude&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$responseData&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;longitude&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nv"&gt;$state_prov&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$responseData&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;state_prov&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="kr"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$state_prov&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-eq&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$state_prov&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"null"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="nv"&gt;$country&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$responseData&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;country_name&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="kr"&gt;if&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$country&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-eq&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;$country&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;-eq&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"null"&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;

                &lt;/span&gt;&lt;span class="c"&gt;# Write all gathered data to the custom log file. It will look something like this:&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="c"&gt;#&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"latitude:&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$latitude&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;,longitude:&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$longitude&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;,destinationhost:&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$destinationHost&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;,username:&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$username&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;,sourcehost:&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$sourceIp&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;,state:&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$state_prov&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;, country:&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$country&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;,label:&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$country&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt; - &lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$sourceIp&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;,timestamp:&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$timestamp&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Out-File&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$LOGFILE_PATH&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Append&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Encoding&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;utf8&lt;/span&gt;&lt;span class="w"&gt;

                &lt;/span&gt;&lt;span class="n"&gt;Write-Host&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-BackgroundColor&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Black&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-ForegroundColor&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;Magenta&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"latitude:&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$latitude&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;,longitude:&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$longitude&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;,destinationhost:&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$destinationHost&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;,username:&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$username&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;,sourcehost:&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$sourceIp&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;,state:&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$state_prov&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;,label:&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$country&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt; - &lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$sourceIp&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;,timestamp:&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$timestamp&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="kr"&gt;else&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="c"&gt;# Entry already exists in custom log file. Do nothing, optionally, remove the # from the line below for output&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="c"&gt;# Write-Host "Event already exists in the custom log. Skipping." -ForegroundColor Gray -BackgroundColor Black&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I won't explain the script in detail but you should definitely learn more about scripting languages such as powershell or bash because you'll often use them to automate tasks. What this script does is it basically runs in a loop and looks through the event log we visited earlier, grabs all the failed login events and specifically gets their IP and store it in the directory specified in the $LOGFILE_PATH variable. One thing you need to do in order for the script to work is go to &lt;a href="https://ipgeolocation.io/"&gt;ipgeolocation.io&lt;/a&gt; and get your own API key, you'll need to sign up to get one. Go back to the script and paste your own key $API_KEY value&lt;/p&gt;

&lt;h1&gt;
  
  
  Run script to get geo data from attackers
&lt;/h1&gt;

&lt;p&gt;You can start the script, and notice down in the command line some text has popped up if you actually retried to connect with incorrect credentials, you can even go and take a look at the log file to see what's inside, you'll find some sample data followed by your failed login data&lt;/p&gt;

&lt;h1&gt;
  
  
  Create custom log in LAW to bring in our custom log
&lt;/h1&gt;

&lt;p&gt;Next thing we're going to do is we're going to create a custom log inside of our log analytics workspace to bring our custom log with the geo data in it into our workspace.&lt;br&gt;
Back to your machine, in azure look for "log analytics" click your workspace and then "custom logs" and the "add custom log", you'll see it's asking for a log file, but ours is in the virtual machine, there's a lot of ways you can send it to our machine but for now we will just copy it from the file directly. Go back to your VM and navigate to the folder where the log is, in the script it's in "C:\ProgramData\", you might have to toggle on "show hidden folders" in the windows file viewer because that directory is hidden. After copying it paste it in a notepad on your host machine and save it. Now you can add the file in azure, click next. On collection path write the path of the file "C:\ProgramData\failed_rdp.log" as we named it in the script and hit next, in details you can name the log and give it a description if you want, next and create.&lt;br&gt;
To see if it's working, go back to your Log analytics workspace in azure and click "Logs", on the right you can write whatever you named the log and see if it gives you results under the request, if you get nothing, you might want to leave some time in order for the two machines to sync, but you can try and request other logs for example "SecurityEvent" and see the results coming in from the VM. After sometime, the failedrdp logs should should up when you ask to see them, you'll see the sample ones followed by your own failed login attempts, we will have to take the raw data column and extract the latitude and longitude and make them in their own columns. &lt;/p&gt;
&lt;h1&gt;
  
  
  Create custom fields/extract fields from raw custom
&lt;/h1&gt;

&lt;p&gt;To do that, expand one of the logs, click the three dots above and click "Extract fields from 'what_you_named_the_log'". In raw data highlight the latitude value, you'll be prompted with a small panel where you can name it latitude and show numeric as field type, hit extract and you'll see some search results on the right, make sure the search is accurate and only the latitude values are highlighted. Hit save extraction and do the same for longitude, if you find that in the search results there something else highlighted other than the longitude, click on the pencil looking icon in the not accurate search result and hit "Modify this highlight" and highlight the longitude. Repeat this process because the extract algorithm is not always as accurate and needs help to identify the right values we want to extract. By now you know how to extract data from a raw data string, do the same for the destination host with the field type : text. Finish all the others until you find yourself with processed data instead of raw data, meaning all the fields are known to us and are well categorized and can be used in our analytics.&lt;/p&gt;
&lt;h1&gt;
  
  
  Testing extracts
&lt;/h1&gt;

&lt;p&gt;Going back to the custom logs panel you can click the "custom fields" tab to see what we extracted. you can run the failed_rdp query again in the logs panel and see your data all neatly organized in columns. If not, go ahead and try another failed log, this tile it should work  &lt;/p&gt;
&lt;h1&gt;
  
  
  Setup map in Sentinel with latitude longitude (or...
&lt;/h1&gt;

&lt;p&gt;Go to azure sentinel, click on the one we setup earlier, if you go to overview, you can see some data about the incidents that occurred on our VM, feel free to analyze it. Go to "Workbooks" under "Threat manager" in the left panel of sentinel and hit "Add workbook". Click edit and remove the default widgets you'll find in this workbook by clicking the three dots beside each one, we'll need the space to setup our map. Next add a query, and type this one in :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;FAILED_RDP_WITH_GEO_CL | summarize event_count=count() by sourcehost_CF, latitude_CF, longitude_CF, country_CF, label_CF, destinationhost_CF | where destinationhost_CF != "samplehost" | where sourcehost_CF != ""
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Providing that you named the columns the same way when we formatted that raw data earlier, if not, make it just like yours. What this query does it it asks for the failed login attempts from the custom log we created excluding the sample ones we used to train the extract algorithm because they don't make sense to us. Now in "Visualization" choose "Map".&lt;br&gt;
On the right side you'll find the settings for the map, for the location info we'll be using Latitude/Longitude, under it select the fields that correspond to both of them and size by the event_count.&lt;br&gt;
Click apply and you should see your location popup on the map, we can further tweaks the settings to make the map more readable. Under metric settings, put "Metric label" as label_CF and "Metric value" as event_count. You can change the plot data to whatever suits you as this is just a suggestion. When you're done hit save and close and save your workbook and click "Done editing".&lt;/p&gt;

&lt;h1&gt;
  
  
  Witnessing the attacks
&lt;/h1&gt;

&lt;p&gt;Note that you must leave the script in the VM under execution, since it's an infinite while loop it won't stop until you do it manually and if you do, the log file won't be updated and azure won't get new data.&lt;br&gt;
You can leave your computer and the virutual machine for an hour or two and come back later to discover who's been trying to log into the vm from around the world. Analyze the data, see the different techniques the hackers used.&lt;/p&gt;

&lt;h1&gt;
  
  
  VERY IMPORTANT NOTE :
&lt;/h1&gt;

&lt;p&gt;After finishing the lab, you should shutdown COMPLETELY the virtual machine in azure, do that by going to the machine's page in azure and click "Stop", verify the machine is deallocated by checking the "status : Stopped (deallocated)" under the Essentials menu. If you miss this, your 200 dollars will be depleted and you can't use them for future labs concerning azure.&lt;/p&gt;

&lt;h1&gt;
  
  
  Final thoughts
&lt;/h1&gt;

&lt;p&gt;As soon as a machine is vulnerable on the internet, it's bound to get attacked. Hackers don't care if you're worth hacking or not, if you're a business or just an individual with unexploitable data in your machine like personal data in the form of bank account credentials, family photos or work documents they can encrypt and request money for, what tried to login to your vm are probably bots scouring the internet for vulnerable machine. If they can do it, they will. So if your login credentials are admin admin or similarly guessable words, consider improving your password policy. Read up on how to secure your systems and on layered security.&lt;br&gt;
There are much better ways to do what we did here, but this basically is the gist of what a SIEM does; it aggregates log data, security alerts, and events into a centralized platform to provide real-time analysis for security monitoring. We didn't cover the alerts part, but you should definitely read up on it and try to implement it. Also, it's even better to understand what's happening behind the scene when it comes to which protocols were used to achieve this. &lt;br&gt;
There are still a lot more features to Azure Sentinel, we only scratched the surface here, so head on to the official &lt;br&gt;
documentation and experiment with this tool. &lt;/p&gt;




&lt;p&gt;Credit where credit's due,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This post was inspired by Josh &lt;a href="https://www.youtube.com/watch?v=RoZeVbbZ0o0&amp;amp;t=1297s&amp;amp;ab_channel=JoshMadakor"&gt;Madakor's youtube video&lt;/a&gt;, check out his youtube channel for cyber security related content.&lt;/li&gt;
&lt;li&gt;Some lines from &lt;a href="https://www.fireeye.com/products/helix/what-is-siem-and-how-does-it-work.html"&gt;this article&lt;/a&gt; about the definition of a SIEM and how it works.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>hacking</category>
      <category>siem</category>
      <category>microsoft</category>
      <category>soc</category>
    </item>
    <item>
      <title>Vulnerability management using Nessus</title>
      <dc:creator>OULD AMARA Amine</dc:creator>
      <pubDate>Mon, 14 Feb 2022 20:46:34 +0000</pubDate>
      <link>https://forem.com/oaamine/vulnerability-management-using-nessus-3nfh</link>
      <guid>https://forem.com/oaamine/vulnerability-management-using-nessus-3nfh</guid>
      <description>&lt;h1&gt;
  
  
  What is vulnerability management ?
&lt;/h1&gt;

&lt;p&gt;It is the process of identifying, evaluating, treating, and reporting on security vulnerabilities in systems and the software that runs on them. This, implemented alongside with other security tactics, is vital for organizations to prioritize possible threats and minimizing their "attack surface."&lt;/p&gt;

&lt;p&gt;Security vulnerabilities, in turn, refer to technological weaknesses that allow attackers to compromise a product and the information it holds. This process needs to be performed continuously in order to keep up with new systems being added to networks, changes that are made to systems, and the discovery of new vulnerabilities over time.&lt;/p&gt;

&lt;h1&gt;
  
  
  How does Nessus work ?
&lt;/h1&gt;

&lt;p&gt;To learn how Nessus and other port-scanning security tools work, it is necessary to understand different services (such as a web server, SMTP server, FTP server, etc) are accessed on a remote server.  Most high-level network traffic, such as email, web pages, etc reach a server via a high-level protocol that is transmitted reliably by a TCP stream.  To keep different streams from interfering with each other, a computer divides its physical connection to the network into thousands of logical paths, called ports.  So if you want to talk to a web server on a given machine, you would connect to port #80 (the standard HTTP port), but if you wanted to connect to an SMTP server on that same machine you would instead connect to port #25.   &lt;/p&gt;

&lt;p&gt;Each computer has thousands of ports, all of which may or may not have services (ie: a server for a specific high-level protocol) listening on them.  Nessus works by testing each port on a computer, determining what service it is running, and then testing this service to make sure there are no vulnerabilities in it that could be used by a hacker to carry out a malicious attack.  Nessus is called a "remote scanner" because it does not need to be installed on a computer for it to test that computer.  Instead, you can install it on only one computer and test as many computers as you would like.&lt;/p&gt;

&lt;h1&gt;
  
  
  Downloading and installing required software and OS
&lt;/h1&gt;

&lt;h2&gt;
  
  
  Download and install Nessus essentials
&lt;/h2&gt;

&lt;p&gt;In order to download Nessus essentials, follow &lt;a href="https://www.tenable.com/products/nessus/nessus-essentials"&gt;this link&lt;/a&gt; to the download page, you'll have to create an account using your name and email, the you'll be redirected to another page where you can click Download to download the software. look for the most recent version that's compatible with your OS, in my case it this one: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdv1zmo0nv4qfqf04fyde.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdv1zmo0nv4qfqf04fyde.png" alt="Image description" width="800" height="385"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After the download has finished, install it, then a web browser window will open with this URL "&lt;a href="https://localhost:8834/"&gt;https://localhost:8834/&lt;/a&gt;", you may have to do some extra steps to allow it through the firewall if you're using linux.&lt;br&gt;
Go ahead and click "Connect via SSL". Your browser will warn you that the connection is not private, just click on "Advanced" and "Proceed to ...", you'll have to wait a few minute for the configuration to finish.&lt;br&gt;
After that, choose Nessus essentials, this is the free version of the product, click continue. Since you already received the activation code upon your first registration,you can click skip and enter the code directly without giving your name and email again. Next click continue, setup a username and a password, make sure you don't forget them and click submit. while it's installing, let's download and install our windows 10 client machine in virtualbox. &lt;/p&gt;

&lt;h2&gt;
  
  
  Oracle virtual box
&lt;/h2&gt;

&lt;p&gt;Note that the performance of your computer might be affected depending on what hardware do you have and how much you allocate to your virtual machines.&lt;/p&gt;

&lt;h3&gt;
  
  
  On windows
&lt;/h3&gt;

&lt;p&gt;Head out to virtual box's &lt;a href="https://www.virtualbox.org/wiki/Downloads"&gt;download page&lt;/a&gt; and follow the installation instruction.&lt;/p&gt;

&lt;h3&gt;
  
  
  On linux
&lt;/h3&gt;

&lt;p&gt;Just follow &lt;a href="https://blogs.oracle.com/virtualization/post/installing-virtualbox-on-oracle-enterprise-linux"&gt;this guide&lt;/a&gt; by Oracle. If you have dependencies issues, check out &lt;a href="https://www.virtualbox.org/wiki/Linux%20build%20instructions"&gt;this page&lt;/a&gt; by the virtualbox team.&lt;/p&gt;

&lt;h3&gt;
  
  
  On MacOS
&lt;/h3&gt;

&lt;p&gt;Much like windows, you only need to visit virtual box's &lt;a href="https://www.virtualbox.org/wiki/Downloads"&gt;download page&lt;/a&gt; and select the OS X hosts option, then follow the installation instruction and you're done.&lt;/p&gt;

&lt;h3&gt;
  
  
  Windows 10
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.microsoft.com/en-us/software-download/windows10ISO"&gt;Head to this page to get it&lt;/a&gt;. When you go there, click "Get started," and follow the instructions and prompts until you finally get to the download page. Choose your language and whether you want to download the 32-bit or 64-bit version. I downloaded the 64-bit version, because I installed it on a 64-bit machine. Remember where you downloaded the ISO file, because you'll need to know that later. &lt;/p&gt;

&lt;h2&gt;
  
  
  Creating the virtual machines
&lt;/h2&gt;

&lt;p&gt;So the next thing we're going to do is we're going to create our virtual machine. Open up virtualbox, I'm using Linux Ubuntu 20.04 so your interface might look slightly different if you're running it on Windows or MacOS. &lt;br&gt;
&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe8519yy309xsahzdjg3v.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe8519yy309xsahzdjg3v.png" alt="Image description" width="800" height="449"&gt;&lt;/a&gt;&lt;br&gt;
We'll go to "new" and we're going to create the Windows 10 computer first, pick windows 64-bit, you should name it accordingly to remember which machine is which. just leave all the settings by default and simply click next, the settings should be so that you can use at least run three virtual machines at the same time depending on you computer's hardware, or you can tweak them as you please.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing Windows 10 in our VM
&lt;/h2&gt;

&lt;p&gt;Before launching the VM, left click it and go to "settings", "Network" and set "Attached to :" as "Bridged Adapter".&lt;br&gt;
Double click the VM to start it, it's going to open up a window, this is where we're going to select the Windows 10 iso that we downloaded earlier, we'll click "choose a virtual optical disk file" (it's the little yellow folder next the the list), click Add and you'll browse to where you put the Windows 10 iso file and add it, choose it in your newly updated lists of optical drives and click OK. Start the virtual machine and it will prompt you to a classic Windows 10 installation, click next, choose custom install and click next.&lt;/p&gt;

&lt;h1&gt;
  
  
  Ensure connectivity with VM
&lt;/h1&gt;

&lt;p&gt;In order for us to scan the virtual machine for vulnerabilities, we have to be connected. Open a command prompt on the windows 10 guest machine and type "ipconfig", there you can find the machine's IP address under IPv4 address. Go to back to your computer, open a command prompt and try to ping that address, it's will not work because the two computers are not connected.&lt;br&gt;
In a real-life situation the two machines will be on the same network, we can recreate that either by installing another machine in which we install Nessus, then configure both machines in virtualbox to be in the same internal network, Or we can add a second network adapter to our windows 10 guest as host only and configure it.&lt;br&gt;
For simplicity's sake, we will deactivate the windows 10 guest machine's firewall, but note that this is not done in real-life because it's a vulnerability in itself.&lt;br&gt;
For that, in the windows 10 machine go to start and type "wf.msc", this will open windows defender firewall settings, click on "windows defender firewall properties" then turn every off in "domain profile", "private profile" and "public profile".&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F84vey73o64vmwd5e01ru.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F84vey73o64vmwd5e01ru.png" alt="Image description" width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can now retry to ping the guest machine and you'll see that it works, because we have allowed all incoming connections into our guest computer.&lt;/p&gt;

&lt;h1&gt;
  
  
  Create a new scan in Nessus
&lt;/h1&gt;

&lt;p&gt;Nessus essentials should be ready by now, it's a web application so it's normal that you're using it in a web browser, go ahead and create a new scan by clicking "Create a new scan" and then choose "Basic network scan", name it and enter the windows 10 vm IP address in the "Targets" field then hit save.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu2neflva1i6l0t1y47ul.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fu2neflva1i6l0t1y47ul.png" alt="Image description" width="800" height="384"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There's a lot of other options you can choose from for performing scans, for example you can schedule scans to be performed each X amount of time or you can perform a scan using credentials which are the username and password of the targeted machine which will be a more in depth scan for registry and other things that require admin rights to read.&lt;/p&gt;

&lt;h1&gt;
  
  
  Inspecting the first scan (no credentials)
&lt;/h1&gt;

&lt;p&gt;In the "My scans" panel, you'll find the scan you just created, click launch and wait for it to finish. After it's done, click it and you'll face a bunch of data, you can find scan details on the right and tabs on the top : Hosts shows you the targeted machine that have been scanned, Vulnerabilities tab contains the vulnerabilities your machine has each color coded according to the severity of the Vulnerability. Info means that it's not necessarily a vulnerability but it's something worth knowing, you'll also find a description and a solution for remediating each one.&lt;br&gt;
You can go through each one and try to understand what it is about, you'll find some that say that Nessus wasn't able to fully scan for them because we didn't provide credentials, we'll do that in the next step.&lt;/p&gt;

&lt;h1&gt;
  
  
  Configuring VM for credentialed scans
&lt;/h1&gt;

&lt;p&gt;In order to perform a scan with credentials, the targeted machine has to be in the same domain as the machine performing the scan, since it's not in our case, we are will have to make some tweaks on the windows 10 VM to allow our computer to perform a credentialed scan. As said before, in a real-life situation the two machines in the same  organization will be the same network and in the same domain, so these tweaks won't be necessary.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frqj52u017w55msdyx4mn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frqj52u017w55msdyx4mn.png" alt="Image description" width="800" height="385"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We already configured the VM's network adapter as bridged, if not go ahead and do it, you'll have to shut down the vm first.&lt;/li&gt;
&lt;li&gt;Open the start menu and look for "services.msc", find "Remote registry", double click and choose "Start type" as automatic and click Start. &lt;/li&gt;
&lt;li&gt;From the start menu look for "Advanced sharing options" and turn on network discovery and file sharing. Next from the start menu look for "User account control settings" and turn it down to "never notify".&lt;/li&gt;
&lt;li&gt;From the start menu look for "Registry Editor", on the left side panel navigate to "Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" or simply paste it the directory input field. Right click on an empty space under all the other settings in this directory and choose NEW -&amp;gt; DWORD (32-bit) value and name it "LocalAccountTokenFilterPolicy", double click and set the value to 1. Restart the machine in order for the changes to apply.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  First scan with credentials
&lt;/h1&gt;

&lt;p&gt;Go back to Nessus, my scans, you can create a new scan or modify the previous one, check the previously created scan, go to "More" and "Configure". This time go to the "Credentials" tab and choose windows on the left side panel, set the authentication method as "Password", fill the username input field with the windows 10 VM account username, if you can't remember or find it simply go back to the VM, open a command line prompt and type "whoami". Fill the password, leave the other settings as default, hit save and launch the scan.&lt;/p&gt;

&lt;h1&gt;
  
  
  Inspecting the first scan (with credentials)
&lt;/h1&gt;

&lt;p&gt;Right away you can see that a lot more critical vulnerabilities have been found comparing to the previous scan, you can compare the two by going to the "History" tab. The reason for that is when performing a scan without credentials we didn't scan any of filesystems, registry or running services. Dive into the results and other tabs, try to remediate some of these issues for a better understanding.&lt;/p&gt;

&lt;h1&gt;
  
  
  Remediating vulnerabilities
&lt;/h1&gt;

&lt;p&gt;One of the easiest things you can do is, update your windows and deprecated software, go ahead and look for "Updates"  in the start menu and install the latest updates. Next open up Microsoft Edge and go to Settings and more &amp;gt; Help and feedback &amp;gt; About Microsoft Edge (edge://settings/help). If the About page shows Microsoft Edge is up to date., you don't need to do anything. If the About page shows An update is available. Select Download and install to proceed.&lt;br&gt;
Not all vulnerabilities are remediated with updates and patches, so you can try and remediate the other vulnerabilities by yourself for practice&lt;/p&gt;

&lt;h1&gt;
  
  
  Inspect scan results after remediating vulnerabilities
&lt;/h1&gt;

&lt;p&gt;Running another scan on our machine, we can see that we have less high risk vulnerabilities, but still some of them need remediating manually.&lt;/p&gt;

&lt;h1&gt;
  
  
  Final thoughts
&lt;/h1&gt;

&lt;p&gt;In this lab you've learned : &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How to install a Windows 10 Virtual Machine on Oracle's Virtual Box.&lt;/li&gt;
&lt;li&gt;How to install Nessus Essentials and run scans (with and without credentials)&lt;/li&gt;
&lt;li&gt;Analyze the data and remediate some of the vulnerabilities found.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These are the basics of how vulnerability management works, but there's still a lot more for you to learn, read up on the subject and learn more about how it's done in detail, visit Teenable's documentation on Nessus and try to implement the other features that are available in Nessus Essentials.&lt;br&gt;
You can also keep experimenting and install versions of software or OS like windows 7 or XP. Learn more about how vulnerability management is done in big organizations where you have to perform scans from a computer targeting computers and devices all withing the same domain, gain access to the other employees computers using their credentials and other advanced techniques for vulnerability management.&lt;br&gt;
Also, make sure to automate updating software and OS in your organization so that you can only focus on the real issues that are harder to fix than simply launching an update. Machines are generally deployed with zero or the least amount of vulnerabilities, this is called a "secure build standard" making sure the device is secure before it goes into production.&lt;br&gt;
Lastly, you'll also have to deal with humans and not only machines, getting everyone to coordinate and cooperate to face threats and how to respond when an incident occurs and how to prevent it from re-occurring can also be a part of the job.&lt;/p&gt;




&lt;p&gt;Credit where credit's due,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This post was inspired by &lt;a href="https://www.youtube.com/watch?v=WJODYmk4ys8&amp;amp;t=156s&amp;amp;ab_channel=JoshMadakor"&gt;Josh Madakor's youtube video&lt;/a&gt;, check out his youtube channel for cyber security related content&lt;/li&gt;
&lt;li&gt;Some lines from &lt;a href="https://www.rapid7.com/fundamentals/vulnerability-management-and-scanning/"&gt;this article&lt;/a&gt; about the definition of vulnerability management.&lt;/li&gt;
&lt;li&gt;Some lines from &lt;a href="https://www.cs.cmu.edu/~dwendlan/personal/nessus.html"&gt;this article&lt;/a&gt; about how does Nessus work.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>nessus</category>
      <category>infosec</category>
      <category>windows10</category>
      <category>hacking</category>
    </item>
    <item>
      <title>DNS, Active Directory and setting up a quick homelab using Oracle's VirtualBox.</title>
      <dc:creator>OULD AMARA Amine</dc:creator>
      <pubDate>Sat, 12 Feb 2022 18:54:45 +0000</pubDate>
      <link>https://forem.com/oaamine/dns-active-directory-and-setting-up-a-quick-homelab-using-oracles-virtualbox-de-2pb</link>
      <guid>https://forem.com/oaamine/dns-active-directory-and-setting-up-a-quick-homelab-using-oracles-virtualbox-de-2pb</guid>
      <description>&lt;h1&gt;
  
  
  What is DNS
&lt;/h1&gt;

&lt;p&gt;DNS is the backbone of your internet navigation ! Each website you gain access to via your favorite browser has an IP address, which is the address of the web sever hosting that website. Now, what if you had to memorize every website's IP address in order to access it ? That's where DNS comes in. DNS which stands for "Domain Name System", it is the hierarchical and decentralized naming system used to identify computers, services, and other resources reachable through the Internet or other Internet Protocol networks. In our previous example, what DNS does is provide a way to map names (a website you're seeking) to numbers (the address of the website), but how does that work exactly ?&lt;/p&gt;

&lt;h2&gt;
  
  
  How does DNS work ?
&lt;/h2&gt;

&lt;p&gt;The information mapping a server's IP and it's corresponding domain name is stored in something we call a nameserver, which is a file that stores DNS records that says “this domain” maps to “this IP address”. Nameservers are distributed all around the world and instead of storing every domain name ever, they only store the locations of the top level domains (TLDs).&lt;/p&gt;

&lt;h2&gt;
  
  
  DNS Hierarchy
&lt;/h2&gt;

&lt;p&gt;DNS uses a hierarchy to manage its distributed database system. The DNS hierarchy, also called the domain name space, is an inverted tree structure.&lt;br&gt;
The DNS tree has a single domain at the top of the structure called the root domain. A period or dot (.) is the designation for the root domain. Below the root domain are the top-level domains that divide the DNS hierarchy into segments.&lt;br&gt;
Listed below are the top-level DNS domains and the types of organizations that use them. Below the top-level domains, the domain name space is further divided into subdomains representing individual organizations. &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi55hb3viprzk2uctahc1.gif" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fi55hb3viprzk2uctahc1.gif" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Domains and Subdomains
&lt;/h2&gt;

&lt;p&gt;A domain is a label of the DNS tree. Each node on the DNS tree represents a domain. Domains under the top-level domains represent individual organizations or entities. These domains can be further divided into subdomains to ease administration of an organization's host computers.&lt;br&gt;
For example, "Company A" creates a domain called "companya.com" under the .com top-level domain. Company A has separate LANs for its locations in Chicago, Washington, and Providence. Therefore, the network administrator for Company A decides to create a separate subdomain for each division, as shown in Domains and Subdomains .&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzxbjovhy5rmajvm2wuqj.gif" 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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzxbjovhy5rmajvm2wuqj.gif" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Any domain in a subtree is considered part of all domains above it. Therefore, chicago.companya.com is part of the companya.com domain, and both are part of the .com domain. &lt;/p&gt;

&lt;h2&gt;
  
  
  Domain Names
&lt;/h2&gt;

&lt;p&gt;The domain name represents an entity's position within the structure of the DNS hierarchy. A domain name is simply a list of all domains in the path from the local domain to the root. Each label in the domain name is delimited by a period. For example, the domain name for the Providence domain within Company A is providence.companya.com, as shown in Domains and Subdomains and the list above.&lt;br&gt;
Note that the domain names in the figure end in a period, representing the root domain. Domain names that end in a period for root are called fully qualified domain names (FQDNs).&lt;br&gt;
Each computer that uses DNS is given a DNS hostname that represents the computer's position within the DNS hierarchy. Therefore, the hostname for host1 in Figure 2 is host1.washington.companya.com.&lt;br&gt;
TLDs are the two or three character extensions like ".com" at the end of a domain name. Each TLD has its own set of nameservers that store the information for who is authoritative for storing the DNS records for that domain. The authoritative nameserver is typically the DNS provider or the DNS registrar (like GoDaddy that offers both DNS registration and hosting). And here, we can find the DNS record that maps example.com to the IP 127.66.122.88.&lt;/p&gt;

&lt;h2&gt;
  
  
  DNS queries
&lt;/h2&gt;

&lt;p&gt;Let's suppose you have a computer and a printer connected to your domain which is called yourDomain.com, and your computer’s and your printer's addresses are yourComputer.yourDomain.com and yourPrinter.yourDomain.com respectively.&lt;br&gt;
When you want to print something from your computer, which has something installed in it by default called a DNS client, you send what we call a DNS query to your server yourDomain.com. which has a DNS service with a nameserver that will resolve incoming DNS queries, it will then look for the printer in it's children hosts meaning the end devices that end with yourDomain.com, in this case it's yourPrinter.yourDomain.com, the printer will be found among them and the server will respond to your computer with the printer's IP, your computer then sends the documents directly to your printer using it's IP and the printer will receive the order and will print what's needed,pretty straightforward right ?&lt;/p&gt;

&lt;h3&gt;
  
  
  Recursive and Iterative queries
&lt;/h3&gt;

&lt;p&gt;Now let's suppose you want to visit &lt;a href="http://www.wikipedia.org" rel="noopener noreferrer"&gt;www.wikipedia.org&lt;/a&gt;, your DNS server won't have a clue what address is that because it has never seen it before and it is not in it's address book.&lt;br&gt;
In that case, the DNS server will respond saying that it doesn't have that, but maybe, my parent has an answer to that query, the parent being the .com domain, it will in turn ask the root domain which will in turn ask the .org domain which will surely have &lt;a href="http://www.wikipedia.org" rel="noopener noreferrer"&gt;www.wikipedia.org&lt;/a&gt; among it's children. This is called a recursive query.&lt;br&gt;
The other type, you guessed it, iterative query basically is the DNS server firing queries to other DNS servers in order to find the IP address of a specific domain name it's looking for, this process is called DNS resolution. Once your local domain resolves the IP of &lt;a href="http://www.wikipedia.org" rel="noopener noreferrer"&gt;www.wikipedia.org&lt;/a&gt;, it will cache it, storing it for future use so that the whole search cycle won't be required again.&lt;br&gt;
Even your machine is capable of caching IP addresses and their corresponding domain name so that it doesn't even have to ask the DNS server but access the IP directly.&lt;/p&gt;

&lt;h1&gt;
  
  
  Active Directory
&lt;/h1&gt;

&lt;p&gt;In computing, a directory is a file system cataloging structure which contains references to other computer files, and possibly other directories in an alphabetical or thematic sequence. On many computers, directories are known as folders, or drawers, analogous to a workbench or the traditional office filing cabinet. (Wikipedia)&lt;br&gt;
So in a similar way active directory let's companies organize all their resources very easily at one place, resources being employees, servers, files, printers and many other things, basically everything will be organized, accessed and managed very easily and in a secure way.&lt;/p&gt;

&lt;h2&gt;
  
  
  Active directory logical architecture
&lt;/h2&gt;

&lt;p&gt;Suppose your company has a domain called companyDomain.com, now this domain is based on three locations in the world, Europe, United states and Asia. Suppose an employee joins the sales team of the US region of your company, the employee will be tagged as an "object", which is the most basic entity of an active directory and it will have it's own set of attributes (employee ID, name, email address,...).&lt;br&gt;
Now suppose there are 100 employees under said sales department, we will create and OU (Organizational Unit) which is a general purpose container that helps administrators manage objects. For example, if an admin wants to assign file directory access to all the 100 members of the sales team, they can simply give the access at the OU level at it will be propagated down the 100 employees.&lt;br&gt;
If you understood the DNS part, you will know that the objects, OUs and the three domains located around the world will all fall under one particular domain which is yourcompany.com.&lt;br&gt;
Domain name server and active directory go hand in hand and their functioning is quite interrelated, while AD holds information about resources in the network, it uses DNS to find and resolve distinguished names into IP addresses.&lt;br&gt;&lt;br&gt;
Below are some basic definitions of each element of the AD structure.&lt;/p&gt;

&lt;h3&gt;
  
  
  Objet
&lt;/h3&gt;

&lt;p&gt;Object is the basic element of Active Directory in Microsoft Windows Server family that represents something on the network, such as a user, a group, a computer, an application, a printer, or a shared folder.&lt;/p&gt;

&lt;h3&gt;
  
  
  Domain
&lt;/h3&gt;

&lt;p&gt;An Active Directory domain is a logical group of objects (users, computers, OUs and so on) that is managed by the same administrative team and is usually located on the same physical network.&lt;/p&gt;

&lt;h3&gt;
  
  
  OU
&lt;/h3&gt;

&lt;p&gt;Organizational Unit (OU) is a container in the Active Directory domain that can contain different objects from the same AD domain: other containers, groups, user and computer accounts. An Active Directory OU is a simple administrative unit within a domain on which an administrator can link Group Policy objects and assign permissions to other users/groups.&lt;br&gt;
There are two main tasks when using OU, besides storing Active Directory objects:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Delegation of management and administrative tasks within the domain to other administrators and users without granting them the domain administrator privileges;&lt;/li&gt;
&lt;li&gt;Linking Group Policies (GPO) to all objects (users and computers) in this OU.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Tree
&lt;/h3&gt;

&lt;p&gt;A domain is a logical grouping of network objects such as user, computers and network devices. A tree or domain tree is a collection of domains. Moreover, a tree follows a parent domain, child domain tree structure. When a domain is under a specific domain, that domain is called the child domain while the main domain is called the parent domain.&lt;br&gt;
Objects in different domains within a domain tree can communicate with each other through trusts. The trusts can be two-way or one-way trusts. For example, assume two domains. If both domains can communicate with each other, it is a two-way trust. If only one domain can communicate with the other domain, it is called one-way trust.  Furthermore, all domains in the domain tree share a contiguous namespace.&lt;/p&gt;

&lt;h3&gt;
  
  
  Forest
&lt;/h3&gt;

&lt;p&gt;A forest is a collection of trees or domain trees which provides the highest level of security boundary. It is also a complete active directory instance. Moreover, objects within the same forest can communicate with each other. If an object in one forest needs to exchange information with an object in another forest, the two forests should have forest level trust.&lt;/p&gt;

&lt;h1&gt;
  
  
  Setting up a home lab
&lt;/h1&gt;

&lt;p&gt;First things first, before setting up a network, always use a diagram, it helps you get your plan in order and not get lost along the way. So this is our diagram.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3wciqug82c09vo9crux2.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F3wciqug82c09vo9crux2.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Explaining the diagram
&lt;/h2&gt;

&lt;p&gt;So the first thing we're going to do is download and install oracle virtualbox which is what we're going to use to run our virtual machines on, after that's installed we're going to download a windows 10 iso and a server 2019 iso that we're going to use to install the two operating systems on two separate virtual machines.&lt;br&gt;
Next after we have everything downloaded and installed we're going to create our first virtual machine that hosts our domain controller inside active directory. We're going to give this virtual machine two network adapters : One is going to be used to connect to the outside internet and the other one that's going to be used to connect to the virtual box private network that the clients are going to connect to.&lt;br&gt;
After our virtual machine is created, we're going to install windows server 2019 on it and then we're going to assign IP addressing for the internal network, the external network will automatically get IP addressing from your home router so we don't have to worry about it. After we have IP addressing setup we're going to name the server and then we're going to install active directory and create our domain then we're going to configure NAT and routing so the clients on the private network can reach the internet through the domain controller. &lt;br&gt;
Next we're going to set up a DHCP on the domain controller so when we create our windows 10 machine it can automatically get an IP address&lt;br&gt;
Last thing we do on the domain controller before we create our client virtual machine is we're going to run a powershell script that will automatically create a thousand users in active directory, this is optional but you can surely learn a thing or two doing it.&lt;br&gt;
After creating the users we're going to create another virtual machine and install windows 10 on it and that virtual machine will be connected to the private virtual box network, we're going to name that machine client1 and join it to the domain and then we're going to log into it with one of our domain accounts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Downloading and installing required software and OS
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Oracle virtual box
&lt;/h3&gt;

&lt;p&gt;Note that the performance of your computer might be affected depending on what hardware do you have and how much you allocate to your virtual machines.&lt;/p&gt;

&lt;h4&gt;
  
  
  On windows
&lt;/h4&gt;

&lt;p&gt;Head out to virtual box's &lt;a href="https://www.virtualbox.org/wiki/Downloads" rel="noopener noreferrer"&gt;download page&lt;/a&gt; and follow the installation instruction.&lt;/p&gt;

&lt;h4&gt;
  
  
  On linux
&lt;/h4&gt;

&lt;p&gt;Just follow &lt;a href="https://blogs.oracle.com/virtualization/post/installing-virtualbox-on-oracle-enterprise-linux" rel="noopener noreferrer"&gt;this guide&lt;/a&gt; by Oracle. If you have dependencies issues, check out &lt;a href="https://www.virtualbox.org/wiki/Linux%20build%20instructions" rel="noopener noreferrer"&gt;this page&lt;/a&gt; by the virtualbox team.&lt;/p&gt;

&lt;h4&gt;
  
  
  On MacOS
&lt;/h4&gt;

&lt;p&gt;Much like windows, you only need to visit virtual box's &lt;a href="https://www.virtualbox.org/wiki/Downloads" rel="noopener noreferrer"&gt;download page&lt;/a&gt; and select the OS X hosts option, then follow the installation instruction and you're done.&lt;/p&gt;

&lt;h3&gt;
  
  
  Windows 10
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://www.microsoft.com/en-us/software-download/windows10ISO" rel="noopener noreferrer"&gt;Head to this page to get it&lt;/a&gt;. When you go there, click "Get started," and follow the instructions and prompts until you finally get to the download page. Choose your language and whether you want to download the 32-bit or 64-bit version. I downloaded the 64-bit version, because I installed it on a 64-bit machine. Remember where you downloaded the ISO file, because you'll need to know that later. &lt;/p&gt;

&lt;h3&gt;
  
  
  Windows server 2019
&lt;/h3&gt;

&lt;p&gt;Same as with Windows 10,&lt;a href="https://www.microsoft.com/en-us/evalcenter/evaluate-windows-server-2019" rel="noopener noreferrer"&gt;Head to this page&lt;/a&gt; and choose ISO file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Creating the virtual machines
&lt;/h2&gt;

&lt;p&gt;So the next thing we're going to do is we're going to create our virtual machines. Open up virtualbox, I'm using Linux Ubuntu 20.04 so your interface might look slightly different if you're running it on Windows or MacOS. &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe8519yy309xsahzdjg3v.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fe8519yy309xsahzdjg3v.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
We'll go to "new" and we're going to create the server 2019 computer first, pick other windows 64-bit, also you should name it accordingly to remember which machine is which. just leave all the settings by default and simply click next, the settings should be so that you can use at least run three virtual machines at the same time depending on you computer's hardware, or you can tweak them as you please.Next, click on your newly created VM, go to Settings, Network, remember if we look at the diagram, we're creating our domain controller right now so we wanna have two NICs (Network Interface Controllers) we want one that's dedicated for the internet that's going to be running NAT and then we'll have one that's dedicated for the internal vmware network. So our first adapter is going to connect to our our house internet and be given an IP address automatically by your router's DHCP, so we want to add one more adapter, go to Settings, Network, Adapter 2 and enable it, then simply select " Internal Network " under the Attached to menu, you can name it something like "intnet", click okay and now our VM is pretty much configured &lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcwajbjws348lvoh8sqmt.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcwajbjws348lvoh8sqmt.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing Windows 2019 OS in our VM
&lt;/h2&gt;

&lt;p&gt;the VM is configured but it's still empty, so next we are going to install Windows server 2019 on it. Double click it to start it, it's going to open up a window, this is where we're going to select the server 2019 iso that we downloaded earlier, we'll click "choose a virtual optical disk file" (it's the little yellow folder next the the list), click Add and you'll browse to where you put the server 2019 iso file and add it, choose it in your newly updated lists of optical drives and click OK. Start the virtual machine and it will prompt you to a classic Windows 10 window, go next and we'll say install and then we're going to select the one with desktop experience in order to have a GUI with our operating system, accept the license agreements, say custom install and click next. So server 2019 is installed, you will be prompt with the default administrator account so just give it a password and make sure to remember it. In order to log in you have to press [CONTROL] + [ALT] + [DELETE] keys to unlock, if you're having trouble logging in just go to input in the VM menus bar and choose keyboard -&amp;gt; Insert ctrl+alt+delete, log in with your password. &lt;/p&gt;

&lt;h2&gt;
  
  
  Setup server network adapters
&lt;/h2&gt;

&lt;p&gt;Next let's set up our IP addressing, so remember if we look at our diagram, we have two NICs : one that's dedicated for our internet connection and then we have an internal one that's going to be used for our internal network, for the internal one we have to set it up manually.&lt;br&gt;
Left click on the network looking icon down on windows taskbar then click network, change adapter options, you'll find two network interfaces, let's check out the first one. We'll go to status -&amp;gt; details and if you find the IP similar to 10.XX.XX.XX that should be the first NIC that we use to connect to the internet (default Virualbox IP addressing), so naturally the second will be our internal one, we will give it an IP address. &lt;br&gt;
Right click on it, select properties and double click on Internet Protocol version 4 and select "use the following IP address". If you want to learn more about IP addressing, check out &lt;a href="https://www.cisco.com/c/en/us/support/docs/ip/routing-information-protocol-rip/13788-3.html" rel="noopener noreferrer"&gt;this link&lt;/a&gt; that basically explains it, for now we will proceed assuming you have the knowledge. Enter this IP 172.16.0.1 and then the mask 255.255.255.0, under "Preferred DNS server" enter 172.16.0.1 and click OK, we're not going to use a default gateway because the domain controller itself is going to serve as the default gateway since it has two NICs, one for the internet and one on the inside so this particular NIC is not going to use the default gateway, and then for the DNS server, when we install active directory it automatically installs DNS so this server is going to actually use itself as the DNS server that's why we entered the same IP address as the first one, alternatively, you can enter the loopback address 127.0.0.1 which will have point to the machine itself.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install Active Directory Domain Services
&lt;/h2&gt;

&lt;p&gt;Next thing we're going to do is we're going to install active directory domain services, go ahead and open Server Manger, click on Add roles and features, click Next, select Role-based and continue, this is where you pick the server where you want to install the thing that you're going to install which is active directory domain services, we only have one server so we're just going to select the server we're going to use and then we're going to choose "active directory domain services" in the list, click next to all the setup, and then install. &lt;/p&gt;

&lt;h2&gt;
  
  
  Promote Domain Controller
&lt;/h2&gt;

&lt;p&gt;Now that it has been installed you'll notice there's this a little flag in the upper right menu of your server manager, go ahead and click that, we have to do our post deployment configuration, we installed the software for active directory domain services but we didn't actually create the domain yet so we'll click Promote this server to a domain controller. In the deployment operation we will select "Add a new forest" and you can name your domain something like "mydomain.com", next enter your password and confirm it, click next, there's no need to create a DNS delegation so just click next again and again until install, you'll be logged out so just log in again.&lt;/p&gt;

&lt;h2&gt;
  
  
  Create domain admin account
&lt;/h2&gt;

&lt;p&gt;Now we're going to create our own dedicated domain admin account instead of using the built-in administrator account, so we can do that by going to "start" and then "administrative tools" and then "active directory users and computers". See mydomain.com on the right side panel, this is our newly created domain, let's create an organizational unit to put our admin account in. We'll name it something like _ADMIN and uncheck "Protect this container from accidental deletion". This will be annoying when you try to delete it later. Now that you have create a domain admin account, right click on it on the right panel and select New -&amp;gt; User and name it like whatever your name is and enter create a password. Uncheck "user must change password next login" and check "password never expires", this is a basic password policy but you should definitely use your own organization's policy for more security. you'll notice your account has appeared, but it's not an admin yet, so right click it and go to "properties" -&amp;gt; "Member of" -&amp;gt; "Add" and  under "Enter the object names to select" write "Domain Admins" apply and exit. Go ahead and log out of the domain controller and instead of logging into the administrator , go to "Other User" and use your domain admin account you created, and now you you know how to create an admin account in Active directory.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install and configure RAS/NAT (Remote Access Server/Network Address Translation)
&lt;/h2&gt;

&lt;p&gt;The purpose of this is to allow our windows 10 client to be on our private virtual network but still be able to access the internet through the domain controller so we're going to install.&lt;br&gt;
Remember how we installed Active Directory Domain Services ? Do the same only this time select "Remote Access" in the list of Roles, next select "Routing" (DirectAccess and VPN is automatically selected), click next to the other setup steps and install.&lt;/p&gt;

&lt;h3&gt;
  
  
  Selecting the interface to connect to the internet
&lt;/h3&gt;

&lt;p&gt;After the installation is finished, go to "tools" in the server manager menus and then go to "routing and remote access", right click on your machine's name on the left panel and select "configure and enable routing and remote access", click next, select the second option which is NAT to allow internal clients to connect to the internet using one address .Next an you're supposed to be able to see your internal and external interface under "use this public interface to connect to the internet", go ahead and select the one we're using to connect to the internet, if you can't remember which one is which just go back to your network adapters settings and simply rename them accordingly, click next and then finish. Now your clients will have access to the internet.&lt;/p&gt;

&lt;h2&gt;
  
  
  Install and configure DHCP
&lt;/h2&gt;

&lt;p&gt;Setting up a DHCP server on our domain controller is essential in order for your windows 10 clients to get an IP address that will let them get on the internet they're on this kind of private internal network just like in your office or school.&lt;br&gt;
By now you know how to add roles and features on your domain controller, go ahead and select DHCP this time from the roles list and simply install it following the default settings.&lt;/p&gt;

&lt;h3&gt;
  
  
  Setting up the scope
&lt;/h3&gt;

&lt;p&gt;From the tools menu, select DHCP so we can set up our scope, DHCP' purpose is to allow devices on the network like client computers to automatically get their IP addresses so looking back at our diagram we defined a scope that will give the IP addresses in this range 172.16.0.100 with this subnet mask 255.255.255.0&lt;br&gt;
In the DHCP configuration tool, you'll find on the left side panel under your_machine_name.mydomain.com something called IPv4, right click it and select "new scope", click next and name the scope, for the range put 172.16.0.100 through 200 (put 172.16.0.200 in the second one) because that's the range we're going to use. Again,if you're unfamiliar with notions such as IP addressing and IPv4 i strongly advice that you learn more about them in order to gain a better understanding of what we are doing here. Under "configuration settings that propagate to DHCP clients" set the length as 24. Next if you want to add exlusion, meaning IP addresses that you don't want given to hosts, this is where you do it, otherwise click next. For the lease duration, it depends on your use cases, it basically means how long does your host keep his IP address and it won't change each time he connects until the lease has expired. Next, you'll be asked if you want to configure DHCP options, that means we want to tell the clients which server to use for DNS, which server to use for the gateway and we do want to configure those things because we want them to be able to get on the internet so we're going to say yes, you'll have to add an ip address for a router used by clients, following our diagram we see that we configured NAT on the domain controller and the domain controller has routing configured as well so one of its jobs is to forward traffic from the clients to the internet so because of this the clients are going to use the internal NIC of the domain controller as their default gateway/router so going back to our DHCP configuration we're just going to enter the domain controller's IP address here (172.16.0.1) and click add.&lt;br&gt;
Next you'll be asked what do you want to use for your DNS server, again when you install active directory on the domain controller it automatically installs DNS and so because of that we're going to use the domain controller as our DNS server, so just click next. For WINS Servers, we don't really need that in our setup so just click next and say yes to activating the scope and finish. Last step, right click the DHCP server up and say authorize then right click one more time and say refresh and you'll notice that IPv4 has turned green and just like that DHCP is set up.&lt;/p&gt;

&lt;h2&gt;
  
  
  Adding users using a PowerShell script (Optional)
&lt;/h2&gt;

&lt;p&gt;You can easily skip this step and only create one user in order to test our windows 10 client, but the purpose of using a script is to show you that you can add users programmatically faster and without using an interface, if you remember while installing our windows server 2019 VM we had the choice to install the server without an interface, the commands you'll see in this script are a small example of what you'll be working with if your AD server machine doesn't have an interface.&lt;br&gt;&lt;br&gt;
In order to create our clients and join them to the domain we're going to use a powershell script to create a whole bunch of users in active directory so we can have sample users and we don't have to manually create them.&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight powershell"&gt;&lt;code&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="c"&gt;# ----- Edit these Variables for your own Use Case ----- #&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nv"&gt;$PASSWORD_FOR_USERS&lt;/span&gt;&lt;span class="w"&gt;   &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Password1"&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nv"&gt;$USER_FIRST_LAST_LIST&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Get-Content&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;\names.txt&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="c"&gt;# ------------------------------------------------------ #&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="nv"&gt;$password&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;ConvertTo-SecureString&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$PASSWORD_FOR_USERS&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-AsPlainText&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Force&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;New-ADOrganizationalUnit&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-Name&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;_USERS&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-ProtectedFromAccidentalDeletion&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="bp"&gt;$false&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="kr"&gt;foreach&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$n&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kr"&gt;in&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$USER_FIRST_LAST_LIST&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nv"&gt;$first&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$n&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;" "&lt;/span&gt;&lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ToLower&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nv"&gt;$last&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$n&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Split&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;" "&lt;/span&gt;&lt;span class="p"&gt;)[&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ToLower&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nv"&gt;$username&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$first&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Substring&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="nx"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;)&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$last&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;ToLower&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="n"&gt;Write-Host&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Creating user: &lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nv"&gt;$username&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="w"&gt;

    &lt;/span&gt;&lt;span class="n"&gt;New-AdUser&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nt"&gt;-AccountPassword&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$password&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="se"&gt;`
&lt;/span&gt;&lt;span class="w"&gt;               &lt;/span&gt;&lt;span class="nt"&gt;-GivenName&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$first&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="se"&gt;`
&lt;/span&gt;&lt;span class="w"&gt;               &lt;/span&gt;&lt;span class="nt"&gt;-Surname&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$last&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="se"&gt;`
&lt;/span&gt;&lt;span class="w"&gt;               &lt;/span&gt;&lt;span class="nt"&gt;-DisplayName&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$username&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="se"&gt;`
&lt;/span&gt;&lt;span class="w"&gt;               &lt;/span&gt;&lt;span class="nt"&gt;-Name&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$username&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="se"&gt;`
&lt;/span&gt;&lt;span class="w"&gt;               &lt;/span&gt;&lt;span class="nt"&gt;-EmployeeID&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nv"&gt;$username&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="se"&gt;`
&lt;/span&gt;&lt;span class="w"&gt;               &lt;/span&gt;&lt;span class="nt"&gt;-PasswordNeverExpires&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="bp"&gt;$true&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="se"&gt;`
&lt;/span&gt;&lt;span class="w"&gt;               &lt;/span&gt;&lt;span class="nt"&gt;-Path&lt;/span&gt;&lt;span class="w"&gt; 
&lt;/span&gt;&lt;span class="s2"&gt;"ou=_USERS,&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="n"&gt;ADSI&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="err"&gt;`&lt;/span&gt;&lt;span class="s2"&gt;""&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;.distinguishedName)"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="se"&gt;`&lt;/span&gt;&lt;span class="w"&gt;
               &lt;/span&gt;&lt;span class="nt"&gt;-Enabled&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="bp"&gt;$true&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt;``&lt;/span&gt;&lt;span class="se"&gt;`&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="c"&gt;###Breaking up the script &lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="n"&gt;Obviously&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;every&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;has&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;his&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;own&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;unique&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;password&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;but&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;in&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;this&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;case&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;and&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;for&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;simplicity&lt;/span&gt;&lt;span class="s1"&gt;'s sake, we'&lt;/span&gt;&lt;span class="nx"&gt;re&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;gonna&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;create&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;the&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;users&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;in&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;the&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;list&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;of&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;names&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;with&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;one&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;password&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;so&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;we&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;create&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;variable&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;with&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;it&lt;/span&gt;&lt;span class="s1"&gt;'s value the shared password.

```powershell
$PASSWORD_FOR_USERS   = "Password1"
```

In order to get the names from our .txt file, we use the "Get-Content" command with as an argument the filepath of the .txt file containing the names, the commands gets the content of the file and store each line in an array, we'&lt;/span&gt;&lt;span class="nx"&gt;ll&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;store&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;the&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;array&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;in&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;variable.&lt;/span&gt;&lt;span class="w"&gt; 

&lt;/span&gt;&lt;span class="err"&gt;```&lt;/span&gt;&lt;span class="n"&gt;powershell&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nv"&gt;$USER_FIRST_LAST_LIST&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="n"&gt;Get-Content&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;\names.txt&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt;``&lt;/span&gt;&lt;span class="se"&gt;`&lt;/span&gt;&lt;span class="w"&gt;

&lt;/span&gt;&lt;span class="n"&gt;The&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"ConvertTo-SecureString"&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;cmdlet&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;converts&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;plain&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;text&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;to&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;secure&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;strings&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;we&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;do&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;this&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;in&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;order&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;to&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;use&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;it&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;for&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;the&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;function&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;that&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;sets&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;the&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;new&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;user&lt;/span&gt;&lt;span class="s1"&gt;'s password upon creation, the function in question requires a parameter of type "SecureString"



```powershell
$password = ConvertTo-SecureString $PASSWORD_FOR_USERS -AsPlainText -Force
```

This one is self explanatory, we are simply creating a new OU called _USERS and setting the protection from accidental deletion to false. 

```powershell
New-ADOrganizationalUnit -Name _USERS 
-ProtectedFromAccidentalDeletion $false
```



```powershell
foreach ($n in $USER_FIRST_LAST_LIST) {
    $first = $n.Split(" ")[0].ToLower()
    $last = $n.Split(" ")[1].ToLower()
    $username = "$($first.Substring(0,1))$($last)".ToLower()
    Write-Host "Creating user: $($username)"
```
Remember the parameters we set when we created a new user ? This is the exact same thing done with powershell commands. If you'&lt;/span&gt;&lt;span class="nx"&gt;re&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;having&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;trouble&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;understanding&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;line&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;simply&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;search&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;it&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="nx"&gt;on&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;microsoft&lt;/span&gt;&lt;span class="s1"&gt;'s powershell documentation](docs.microsoft.com/en-us/powershell) for more details.

```powershell
New-AdUser -AccountPassword $password `
               -GivenName $first `
               -Surname $last `
               -DisplayName $username `
               -Name $username `
               -EmployeeID $username `
               -PasswordNeverExpires $true `
               -Path "ou=_USERS,$(([ADSI]`"").distinguishedName)" `
               -Enabled $true


&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;h2&gt;
  
  
  Installing Windows 10 Client on a VM machine
&lt;/h2&gt;

&lt;p&gt;By now, you should be able to install a new machine on a oracle's virtualbox machine, if you can't remember the exact steps, go back to the Windows server 2019 installation instructions and follow those steps again only this time, you won't need two NICs, just one configured as internal network in order to connect to our domain controller. You might be asked more simple user oriented questions during the installation concerning privacy and ads, you can configure them as you wish as it doesn't affect our lab. Also, when you're prompted with "Let's connect you to a network" during the installation, it's preferred that you choose "I don't have internet", we will add a network manually for a more real-life situation where you're not always adding users as a newly installed Windows 10 OS. &lt;br&gt;
After the installation process is finished, open up a command line prompt by going to "Start" and look for "cmd", there's no need to open it as an admin. run the following command &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

ipconfig /all


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;look for the lines that specify the DHCP server, DNS, Default gateway and the machine's IPv4 IP address, notice that they all match our configuration for the domain controller,&lt;br&gt;
you can even try to access the internet or simply ping 8.8.8.8 in the command line to see if packets are being forwarded. Additionally, try to ping mydomain.com which will work naturally because you are on the same network. If it works, this means that all is in order, if you have different results, make sure you didn't forget any of the steps in our AD domain controller configuration.&lt;br&gt;
Now for adding the computer to the newly created domain, right click the start menu button on the bottom left of your windows 10 and choose "System", then look for "Rename this PC (advanced)" button, then you'll see "to rename this computer or change it's domain or workgroup, click change" go ahead and click change, you can change the computer's name into Client1to match our diagram if you want, but it's not necessary. Under "member of" click domain and type on the field "mydomain.com" and click OK. Here you can add a user previously created in the domain controller, remember you added your own name to the list of names we added using the powershell script? Simply enter your name and as password "password1" if you left it unchanged in the provided script. Click OK and congratulations you are a member of the active directory. If you want to checkout the changes that happened in the domain controller following adding a machine to the domain, you go to the server manager, Tools, DHCP, on the left side panel expand the scope list and double click on "Address leases", we can see in here that we have one lease from our client computer, so when we created our client computer and joined it to the network reached out to the DHCP server automatically and requested an address and then the DHCP server gave it an address and now we have this lease in here, when a client gets an IP, it'll show up in here.&lt;br&gt;
Another thing to check out, go to "Windows Administration", "Active directory users and computers", on the left side panel click on "Computers", there you'll find the computer's name we just added to the domain, you can manage that user from this menu, for example, if you delete it, he won't be able to log in with his credentials.&lt;br&gt;
Going back the Windows 10 client, in the log in interface, you'll find "Other user" has appeared in the bottom left corner of you screen, click it and you'll notice that it says "Sign in to : MYDOMAIN.COM", enter your credentials and you can log in. Actually, you can use any other user from the list of names we added but you can configure your domain controller to make sure a certain user only logs in from a certain computer, i'll let look for that.&lt;br&gt;
When logged in, open a command line and write "whoami", you'll see "mydomain\username", this again means that you are a member of the domain.&lt;/p&gt;

&lt;h1&gt;
  
  
  Final thoughts
&lt;/h1&gt;

&lt;p&gt;You have now learned : &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How does DNS work.&lt;/li&gt;
&lt;li&gt;HOW to created virtual machines and configure them in Oracle's Virtualbox.&lt;/li&gt;
&lt;li&gt;How to setup Active Directory, create a domain controller, configure DNS and DHCP, create users and admins.&lt;/li&gt;
&lt;li&gt;How to join a client computer to the Active Directory.
You have mastered the basics of DNS and Active Directory, but there's much more to learn ! Active Directory is a powerful tool and we only scratch to surface, i very much advise you to learn more about it's many features and the protocols it uses.
If you ran into any problem while doing this lab, you can troubleshoot either by looking at the documentation or looking in forums.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;Credit where credit's due,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This post was inspired by Josh &lt;a href="https://www.youtube.com/watch?v=MHsI8hJmggI&amp;amp;list=PLqBeiU46hx1H--SNfTrohTOWeqkK-M2Y0&amp;amp;ab_channel=JoshMadakor" rel="noopener noreferrer"&gt;Madakor's youtube video&lt;/a&gt;, check out his youtube channel for cyber security related content.&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>dns</category>
      <category>activedirectory</category>
      <category>windowsservers</category>
      <category>virtualbox</category>
    </item>
    <item>
      <title>Hashing Algorithms and creating a simple file integrity monitor (FIM)</title>
      <dc:creator>OULD AMARA Amine</dc:creator>
      <pubDate>Thu, 13 Jan 2022 23:19:19 +0000</pubDate>
      <link>https://forem.com/oaamine/hashing-algorithms-and-creating-a-simple-file-integrity-monitor-fim-5ei9</link>
      <guid>https://forem.com/oaamine/hashing-algorithms-and-creating-a-simple-file-integrity-monitor-fim-5ei9</guid>
      <description>&lt;h2&gt;
  
  
  The CIA triad
&lt;/h2&gt;

&lt;p&gt;which stands for : Confidentiality, Integrity and Availability. These are the three pillars of every security infrastructure and represent goals for security experts to ensure in their company. Here’s what each one means in simple terms :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Confidentiality is keeping the data confidential and not shown to people who are not supposed to see it. a simple example would be the data exchanged between a client and a server in an online store (passwords, credit card information, preferences ...)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Integrity is maintaining the consistency and trustworthiness of data, making sure it doesn’t change if it’s not supposed to and if it does, the user knows about it. This is what we will cover in this tutorial. We will build a simple FIM (File Integrity Monitor) using hashing algorithms to monitor data and keep tabs on changes made on it (writing) and implement a warning that is triggered when said changes happen so that the user may take the necessary precautions.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Availability is ensuring that systems remain online and available for those who need them.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Hashing Algorithms
&lt;/h2&gt;

&lt;p&gt;Or a cryptographic hash function is an algorithm that takes an arbitrary amount of data input and produces a fixed-size output of enciphered text called a hash value, or just “hash.” That enciphered text can then be stored instead of the password itself, and later used to verify the user in the most basic cases.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Hashes are non-reversible. it is very hard to find the original password from the output or hash.&lt;/li&gt;
&lt;li&gt;Diffusion, the slightest of changes to the input will produce an entirely different output, thus making it harder.&lt;/li&gt;
&lt;li&gt;Determinism, a given input must always produce the same hash value&lt;/li&gt;
&lt;li&gt;Collision resistance. It should be hard to find two different passwords that hash to the same enciphered text.&lt;/li&gt;
&lt;li&gt;Non-predictable. The hash value should not be predictable from the input.
There are many hashing algorithm, in this post, we will be using the sha256 hash function, which is still approved as a secure algorithm&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  FIM (File Integrity Monitor)
&lt;/h2&gt;

&lt;p&gt;File Integrity Monitoring (FIM) is a security practice which consists of verifying the integrity of operating systems and application software files to determine if tampering or fraud has occurred by comparing them to a trusted "baseline." this is mainly done by using hashing algorithms.&lt;/p&gt;

&lt;h2&gt;
  
  
  Coding our basic FIM
&lt;/h2&gt;

&lt;p&gt;In our application, the input will be the digital thumbprint of each file in the directory that we would like to monitor for changes, the outputted hashes will be stored in a file to be then later compared to a newly calculated hash; If they're equal, that means no changes have been made to the file, else there has been changes. We will also cover the cases where a file is deleted or a new file is created.&lt;br&gt;
Here's a chart to help you understand the functioning of the scripts we are about to see &lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhaeggi2joahb6jt29t6t.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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fhaeggi2joahb6jt29t6t.png" alt="Image description"&gt;&lt;/a&gt;&lt;br&gt;
Now for the code, this step-by-step guide will be in bash (the Bourne Again SHell) which is a widely used shell scripting language for automating tasks, but you can also find the python or Powershell version on the &lt;a href="https://github.com/OAAmine/File-Integrity-Monitor" rel="noopener noreferrer"&gt;github page&lt;/a&gt;&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="c"&gt;#User input &lt;/span&gt;
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nt"&gt;-ne&lt;/span&gt; &lt;span class="s2"&gt;"would you like to&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;   1) Collect a new .baseline&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;Or&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;    2) Proceed with the previously recorded one&lt;/span&gt;&lt;span class="se"&gt;\n&lt;/span&gt;&lt;span class="s2"&gt;   [ 1 | 2 ] ? "&lt;/span&gt;
&lt;span class="nb"&gt;read &lt;/span&gt;ans


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;get the user's input, easy enough, right?&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="k"&gt;function &lt;/span&gt;calculate_file_hash&lt;span class="o"&gt;(){&lt;/span&gt;
    &lt;span class="nv"&gt;filehash&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;sha256sum&lt;/span&gt; &lt;span class="nv"&gt;$1&lt;/span&gt; | &lt;span class="nb"&gt;cut&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s1"&gt;' '&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; 1&lt;span class="si"&gt;)&lt;/span&gt;
    &lt;span class="nv"&gt;filepath&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$1&lt;/span&gt;
    &lt;span class="nv"&gt;path_and_hash&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nv"&gt;$filepath&lt;/span&gt;&lt;span class="s2"&gt;"|"&lt;/span&gt;&lt;span class="nv"&gt;$filehash&lt;/span&gt;
    &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$path_and_hash&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;here we created a function that calculates the file hash for the specified file directory in function call argument &lt;/p&gt;

&lt;p&gt;First case scenario, Collecting the baseline&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$ans&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"1"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;&lt;span class="k"&gt;then
    if&lt;/span&gt; &lt;span class="o"&gt;[[&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="s2"&gt;".baseline.txt"&lt;/span&gt; &lt;span class="o"&gt;]]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then 
        &lt;/span&gt;&lt;span class="nb"&gt;rm&lt;/span&gt; .baseline.txt
        &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;.baseline.txt 
        &lt;span class="c"&gt;#hidden file starts with a . (in linux based systems) &lt;/span&gt;
    &lt;span class="k"&gt;else&lt;/span&gt;
        &lt;span class="o"&gt;&amp;gt;&lt;/span&gt;.baseline.txt 
    &lt;span class="k"&gt;fi&lt;/span&gt;


&lt;span class="c"&gt;#filling in the .baseline.txt file with filepath|filehash pairs&lt;/span&gt;
    &lt;span class="k"&gt;for &lt;/span&gt;entry &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$monitoring_dir&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;/&lt;span class="k"&gt;*&lt;/span&gt;
    &lt;span class="k"&gt;do
        &lt;/span&gt;&lt;span class="nv"&gt;res&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;calculate_file_hash &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$entry&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
        &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nv"&gt;$res&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; .baseline.txt
    &lt;span class="k"&gt;done&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;in this part, the user decided to collect a new baseline, the old one will be deleted if it exists and we will store the file_path|file_hash pairs in the newly created baseline.txt file using the calculate_file_hash function&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="k"&gt;else
    &lt;/span&gt;&lt;span class="nb"&gt;declare&lt;/span&gt; &lt;span class="nt"&gt;-A&lt;/span&gt; path_hash_dict
    &lt;span class="c"&gt;#creating a dictionary with filepath as key and filehash as value&lt;/span&gt;
    &lt;span class="nv"&gt;lines&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;cat&lt;/span&gt; .baseline.txt&lt;span class="si"&gt;)&lt;/span&gt;
    &lt;span class="k"&gt;for &lt;/span&gt;line &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="nv"&gt;$lines&lt;/span&gt; 
    &lt;span class="k"&gt;do
        &lt;/span&gt;&lt;span class="nv"&gt;path&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$line&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; | &lt;span class="nb"&gt;cut&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s1"&gt;'|'&lt;/span&gt; &lt;span class="nt"&gt;-f1&lt;/span&gt; &lt;span class="si"&gt;)&lt;/span&gt;
        &lt;span class="nb"&gt;hash&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt; &lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$line&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; | &lt;span class="nb"&gt;cut&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s1"&gt;'|'&lt;/span&gt; &lt;span class="nt"&gt;-f2-&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;
        path_hash_dict[&lt;span class="nv"&gt;$path&lt;/span&gt;&lt;span class="o"&gt;]=&lt;/span&gt;&lt;span class="nv"&gt;$hash&lt;/span&gt;
    &lt;span class="k"&gt;done&lt;/span&gt; 


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Second case scenario, user wants to start monitoring the files, first we create a dictionary where each key is the file path and the value for this key is the file's hash, this is done for easy access to the data stored in the baseline.txt file&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;

&lt;span class="k"&gt;while &lt;/span&gt;&lt;span class="nb"&gt;true
    &lt;/span&gt;&lt;span class="k"&gt;do
        &lt;/span&gt;&lt;span class="nb"&gt;sleep &lt;/span&gt;1
        &lt;span class="c"&gt;#checking if a file has been deleted &lt;/span&gt;
        &lt;span class="k"&gt;for &lt;/span&gt;key &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="p"&gt;!path_hash_dict[@]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do
            if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$key&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
                &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"A file has been REMOVED ! FILE NAME :&lt;/span&gt;&lt;span class="nv"&gt;$key&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; 
            &lt;span class="k"&gt;fi
        done


        for &lt;/span&gt;file &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$monitoring_dir&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;/&lt;span class="k"&gt;*&lt;/span&gt;
        &lt;span class="k"&gt;do
            &lt;/span&gt;&lt;span class="nb"&gt;hash&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;sha256sum&lt;/span&gt; &lt;span class="nv"&gt;$file&lt;/span&gt; | &lt;span class="nb"&gt;cut&lt;/span&gt; &lt;span class="nt"&gt;-d&lt;/span&gt; &lt;span class="s1"&gt;' '&lt;/span&gt; &lt;span class="nt"&gt;-f&lt;/span&gt; 1&lt;span class="si"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="o"&gt;!&lt;/span&gt; &lt;span class="nt"&gt;-v&lt;/span&gt; path_hash_dict[&lt;span class="nv"&gt;$file&lt;/span&gt;&lt;span class="o"&gt;]&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
                &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"A file has been CREATED ! FILE NAME : &lt;/span&gt;&lt;span class="nv"&gt;$key&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
            &lt;span class="k"&gt;else
                if&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$hash&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;path_hash_dict&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;$file&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
                   continue
                elif&lt;/span&gt; &lt;span class="o"&gt;[&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$hash&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;!=&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="k"&gt;${&lt;/span&gt;&lt;span class="nv"&gt;path_hash_dict&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;$file&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="k"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="o"&gt;]&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;then
                    &lt;/span&gt;&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="nt"&gt;-e&lt;/span&gt; &lt;span class="s2"&gt;"A file has been CHANGED ! FILE NAME : &lt;/span&gt;&lt;span class="nv"&gt;$key&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
                    &lt;span class="nb"&gt;ls&lt;/span&gt; &lt;span class="nt"&gt;-la&lt;/span&gt; &lt;span class="nv"&gt;$key&lt;/span&gt;

                &lt;span class="k"&gt;fi
            fi
        done

    done

fi&lt;/span&gt;



&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Let the monitoring start ! In this infinite while loop, if a key in our dictionary doesn't correspond to a file's name in the monitored directory, it means it has been deleted&lt;br&gt;
If a file's name is not among the keys in our dictionary, it means a new file has been created in the monitored directory&lt;br&gt;
Lastly, we calculate the hash of each file and compare it to the hash stored in the dictionary, if they're different, this means the file has been modified.&lt;/p&gt;




&lt;p&gt;Find the a more complete version of this script on &lt;a href="https://github.com/OAAmine/File-Integrity-Monitor" rel="noopener noreferrer"&gt;Github&lt;/a&gt;. You can also find the python and Powershell versions there.&lt;/p&gt;

&lt;p&gt;Credit where credit's due,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This post was inspired by Josh &lt;a href="https://www.youtube.com/watch?v=WJODYmk4ys8&amp;amp;t=156s&amp;amp;ab_channel=JoshMadakor" rel="noopener noreferrer"&gt;Madakor's youtube video&lt;/a&gt;, check out his youtube channel for cyber security related content&lt;/li&gt;
&lt;li&gt;Some lines from &lt;a href="https://www.synopsys.com/blogs/software-security/cryptographic-hash-functions/" rel="noopener noreferrer"&gt;this article&lt;/a&gt; about cryptographic hash functions&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>cybersecurity</category>
      <category>hashing</category>
      <category>bash</category>
      <category>fim</category>
    </item>
  </channel>
</rss>
