<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Pepe Pérez Sifre on Medium]]></title>
        <description><![CDATA[Stories by Pepe Pérez Sifre on Medium]]></description>
        <link>https://medium.com/@pepesifre?source=rss-2f0d5c5e8baf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*zaicd0RyKKhkwB_-Smd9OQ.jpeg</url>
            <title>Stories by Pepe Pérez Sifre on Medium</title>
            <link>https://medium.com/@pepesifre?source=rss-2f0d5c5e8baf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 12:55:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pepesifre/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[How to hear the Bloodhound barking]]></title>
            <link>https://medium.com/mercadonait/how-to-hear-the-bloodhound-barking-5ac290427b17?source=rss-2f0d5c5e8baf------2</link>
            <guid isPermaLink="false">https://medium.com/p/5ac290427b17</guid>
            <category><![CDATA[detection]]></category>
            <category><![CDATA[bloodhound]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[active-directory]]></category>
            <dc:creator><![CDATA[Pepe Pérez Sifre]]></dc:creator>
            <pubDate>Thu, 13 Jan 2022 12:07:15 GMT</pubDate>
            <atom:updated>2022-01-13T12:35:52.107Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/506/1*Qi5RURQxXJVFXGe2ZAa71Q.png" /><figcaption>Photo by <a href="https://medium.com/u/2f0d5c5e8baf">Pepe Pérez Sifre</a>. Detection capabilities at Mercadona</figcaption></figure><h3>How we are going to achieve it</h3><p>Bloodhound is a data analysis tool, which is used either by cybercriminals or the Red Team to discover different paths that can be used in order to escalate privileges or move laterally, or alternatively it can be used by the Blue Team to detect these paths and patch them. In this post we will look at the different ways in which this tactic can be detected [<a href="https://attack.mitre.org/tactics/TA0007/">1</a>], as well as the particular techniques used [<a href="https://attack.mitre.org/techniques/T1087/">2</a>] [<a href="https://attack.mitre.org/techniques/T1069/">3</a>] [<a href="https://attack.mitre.org/techniques/T1018/">4</a>]</p><p>Firstly, we all need to understand how this tool works in order to be able to draw up proper detection rules. Bloodhound uses graph theory to represent “paths” to different “nodes” using the data that is stored in a database, in particular the Neo4j [<a href="https://neo4j.com/">5</a>], therefore meaning that it does not actually execute any attacks itself. Said data needs to be ingested in some way, and that is the point at where the attack occurs and the point where we can detect the bad guys. In this post we will try to explain how this data collection is performed and then how it can be detected.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xEmJdGshr9MQz595Wr4rOQ.png" /><figcaption>BloodHound interface example</figcaption></figure><h3>Information gathering</h3><p>Anyone who is familiar with Bloodhound will immediately think of one tool: <strong>SharpHound</strong>[<a href="https://bloodhound.readthedocs.io/en/latest/data-collection/sharphound.html">6</a>], or the python version, <strong>bloodhound.py</strong> [<a href="https://github.com/fox-it/BloodHound.py">7</a>] when talking about information gathering and collection.</p><p>Both of these tools collect the same information, and they do so in more or less the same way, so we are going to try to abstract the way they work under the hood, so that we can create a common detection system for both cases.</p><p>After undertaking executions in a laboratory environment and performing code analysis for both tools, we determined that we can divide the collection process into two parts to make it easier: data collection and session collection.</p><p>In the data collection phase, LDAP queries are carried out to the domain controllers, in order to collect all of the information that is available about the directory. This information will subsequently be used for drawing the graph using objects to depict the relationship between them. This will be performed over the LDAP or LDAPS protocol:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*VLit6G5bsRXTSdiU5IFA3A.png" /><figcaption>Data collection.</figcaption></figure><p>In the session collection phase, session information will be collected from all of the computers joined to the domain. This will be done via RPC over SMB:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*L6-B4x_Tb24WBM-1pY20Kw.png" /><figcaption>Session collection</figcaption></figure><p>Once all of the data has been collected it will be parsed and stored in the Neo4j database for it to be queried.</p><p>The next image includes a quick overview of how Sharphound works, and in this case the collection is also divided in two depending on the protocol that is being used, LDAP for the Active Directory data or SMB for sessions. It is important to mention that unless we specify a collection method, the default will be used, which executes both phases.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*Q9d4q0_dqIomZig2Uzxk_A.png" /><figcaption>Sharphound overview [<a href="https://bloodhound.readthedocs.io/en/latest/data-collection/sharphound-all-flags.html#table-to-demonstrate-the-differences">8</a>]</figcaption></figure><h3>First phase. Data collection</h3><p><strong>The information</strong> stored in the Active Directory database <strong>is retrieved using LDAP queries</strong>, Therefore our first objective will be to find out what these queries are by using both the source code and the generated network traffic.</p><p>If we wish to retrieve all of the domain information we could expect thousands of requests via LDAP, however, that will not be the case, as if we filter our network traffic capture file by LDAP requests performed, only a few queries appear. “For example, the query shown in the image below will obtain all computer accounts that are not Administratively Disabled:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*5Q3GnwbQUzKGsNgq7Ipo9g.png" /><figcaption>LDAP query from Wireshark</figcaption></figure><p>On the other hand, by analyzing the source code it is possible to find the query seen before</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*ezl333ptkyPOaC8aiPCL8w.png" /><figcaption>LDAP query from the SharpHound.exe source code</figcaption></figure><p>Then, if we collect all the LDAP requests and compare them with the source code, the conclusion is that all the requests can be summarized in the next one:</p><pre>(|(|(samaccounttype=268435456)(samaccounttype=268435457)(samaccounttype=536870912)(samaccounttype=536870913)(primarygroupid=*))(&amp;(sAMAccountType=805306369)(!(UserAccountControl:1.2.840.113556.1.4.803:=2)))(|(samAccountType=805306368)(samAccountType=805306369)(samAccountType=268435456)(samAccountType=268435457)(samAccountType=536870912)(samAccountType=536870913)(objectClass=domain)(&amp;(objectcategory=groupPolicyContainer)(flags=*))(objectcategory=organizationalUnit))(objectclass=domain)(|(samaccounttype=268435456)(samaccounttype=268435457)(samaccounttype=536870912)(samaccounttype=536870913)(samaccounttype=805306368)(samaccounttype=805306369)(objectclass=domain)(objectclass=organizationalUnit)(&amp;(objectcategory=groupPolicyContainer)(flags=*)))(|(&amp;(&amp;(objectcategory=groupPolicyContainer)(flags=*))(name=*)(gpcfilesyspath=*))(objectcategory=organizationalUnit)(objectClass=domain))(&amp;(samaccounttype=805306368)(serviceprincipalname=*)))</pre><p>The content that is collected by each of these queries is mapped in this table:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/717/1*sjIqYIkFaq5Z2AiocXYhbg.png" /><figcaption>LDAP queries and their collection capabilities</figcaption></figure><p>Next, and in order to detect this phase, two different detection approaches will be analyzed: tool level and AD decoys:</p><h4>Tool level</h4><p>This option is<strong> the easiest to implement, however </strong>it is also t<strong>he least effective</strong>. This approach will try to detect the use of the collection tools on the endpoints. At a higher level, it can be used to detect the tool itself and its arguments as Florian has shown in this Sigma Rule[<a href="https://twitter.com/cyb3rops/status/1208034002239729664">9</a>]. In this case, it detects the signature <em>CollectionMethod All</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3nlrPFYHN8REf2PJvxnwvQ.png" /><figcaption>BloodHound.py execution using Docker</figcaption></figure><p>At a lower level, instead of detecting the tool itself, it is possible to detect the queries that are executed. To do so, network detection systems could be used to detect the LDAP requests. The downside of this approach is the use of LDAPS where these signatures will not match. Otherwise, we could use any EDR solution where Advanced Hunting queries can be performed. For example, by performing the following query, it is possible to detect the LDAP request that searches all the accounts which have a SPN (<em>ex. Microsoft EDR</em>):</p><pre>let timeframe = 7d;<br>let ldap_filter = dynamic([&quot;(serviceprincipalname=*)&quot;]);<br>DeviceEvents<br>| where Timestamp &gt;= ago(timeframe)<br>| where ActionType == &#39;LdapSearch&#39;<br>| extend LDAP = parse_json(AdditionalFields)<br>| extend AttributeList = LDAP.AttributeList<br>| extend SearchFilter = LDAP.SearchFilter<br>| extend DistinguishName = LDAP.DistinguishedName<br>| where SearchFilter has_any (ldap_filter)<br>| project Timestamp, DeviceName, SearchFilter, DistinguishName, AttributeList</pre><p>Both of these rules are pretty easy to implement, however, the overall downside of these types of detections is that they are based on the tool, meaning that they are tightly tied to the machine where the execution is performed, and usually cybercriminals are aware of this. As such, they perform executions from an un-monitored machine, or even from memory like we did to evade the AV layer of detection, making these detections useless, and therefore a completely different approach will be analyzed in the next section.</p><h4>AD decoys</h4><p>AD decoys are <strong>based on the Deception principle</strong>, and the Deception concept is rather simple: to trick the attacker into interacting with resources that have been created solely with that objective, either for detection purposes or to disrupt the attack process. In this case, AD decoys are AD objects like users or computers or even groups that are created by the security team in order to notify whenever they have been enumerated because any kind of reconnaissance over the entire Active directory also includes these decoy accounts.</p><p>For these decoys to work, the Windows Security Logs will be used. Each Windows system has nine audit policy categories and 50 policy subcategories, which can be enabled or disabled. The policy that we will use is the Directory Service Access [<a href="https://www.ultimatewindowssecurity.com/securitylog/book/page.aspx?spid=chapter9">10</a>] which makes low-level auditing available for all types of objects in AD. This policy is similar to the Object Access policy, however, this one logs events that are related to objects <em>outside</em> the AD, such as files or registry keys, whereas the Directory Service Access logs events that are related to AD objects, such as users or computers.</p><p>The subcategory that we are interested in is “<strong>Directory Service Access</strong>”, and the event ID we will use is 4662 [<a href="https://www.ultimatewindowssecurity.com/securitylog/encyclopedia/event.aspx?eventid=4662">11</a>](<em>An operation was performed on an object</em>). Activating this audit requires a two-step procedure. Firstly, we must enable the Active Directory Service object access policy on the system, and secondly, we must select the specific objects and define the types of access that we wish to monitor. The steps that must be followed to achieve this are:</p><p>First, we can check if this policy is enabled in our environment:</p><pre>auditpol /get /category:&quot;DS Access&quot;</pre><p>If it is not enabled, we can enable it with:</p><pre>auditpol /set /subcategory:&quot;Directory Service Access&quot; /Success:Enable</pre><p>Next, the decoys objects must be configured as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rg-0V7L7Ke0t1mkLbaus0A.png" /><figcaption>AD decoys configuration</figcaption></figure><p>With this policy, that <em>everyone</em> always performs, for example, a read operation over <em>this object,</em> an event log with id 4662 will be generated. Finally, to check if everything is configured properly, we can execute a Ldapsearch query of the object as follows from the Docker image:</p><pre>ldapsearch -Y GSSAPI -b &quot;DC=<em>EXAMPLE</em>,DC=<em>COM</em>&quot; -H ldap://<em>DCSERVER</em>:389 &quot;(SamAccountName=<em>HONEYACCOUNT</em>)&quot;</pre><p>This event is generated on the DC side:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zjzKmm9DZeZSFmawL9sf6w.png" /><figcaption>Event ID 4662</figcaption></figure><p>For the detection rule, we will have to pay attention to the <strong>Object Name field</strong>. We will not see the readable name of the audited object, instead, we will see its GUID, so to create the detection rule, we have to look for event ID 4662 and Object Name=GUID AD decoy. Now every time Bloodhound.py or Sharphound are executed this event will occur and an alert can be triggered.</p><p><strong>This detection </strong>is quite good, but it<strong> depends on </strong>the size or <strong>complexity of the organization</strong> where it is used. In this case all the tests were performed in a non-productive environment, where the results were perfect. Every time BloodHound was executed an alert was triggered and only two false-positives were observed during a one month period, and these were well identified and exempted, however, once it was moved to the production environment the number of false-positives was uncontrollable, meaning that this detection can be very accurate if the company is not too big and all of the processes are more or less under control, however, the opposite is true if the Active Directory is very large. Therefore, the traces left over from the second phase of the reconnaissance will be used to complement this first detection</p><h3>Second phase. Session collection</h3><p>Once all the data has been recollected using LDAP, these tools utilize the list of computers obtained to recollect user sessions. In summary, what this phase does is that instead of doing pings to check if a computer is alive, it checks if port 445 is open, and if it is available it will <strong>collect sessions from the computer</strong> using for example, in the SharpHound agent, the win32api function <strong>NetSessionEnum </strong>for user sessions, the NetWkstaUserEnum for user sessions (<em>privileged mode</em>), and the NetLocalGroupGetMembers for local group members. All these are performed via <strong>RPC over SMB</strong>.</p><p>To identify possible detection methods, we will execute this API function manually (<em>NetSessionEnum</em>) so that we can understand what kind of information is obtained, and how it can be used by the cybercriminal.</p><p>As we can see in the Microsoft Documentation[<a href="https://docs.microsoft.com/en-us/windows/win32/api/lmshare/nf-lmshare-netsessionenum">12</a>], in order for the NetSessionEnum function to be executed it requires at least level 10 privileges, that is to say domain authenticated privileges (<em>we can check it out on the log event shown before, where access mask equals 0x10</em>). It will query a computer each time it is called, and it will return the IP for where the session originated from and a username.</p><p>If we execute the <em>net session </em>command on a server, if nobody has accessed it yet, the response will be empty, however, if we establish an SMB session from a computer joined domain, with, for example, the command <em>net view \\Server-Name\ </em>, if we then execute the <em>net session</em> command on the server again, that session will be shown as follows:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/828/1*tHti1JjavdRO1nMOYHNbzQ.png" /><figcaption>Net session execution on the server</figcaption></figure><p>For the moment everything makes sense, we can access a share of a server and inside the server it is possible to check all the sessions, however, the <em>information leak </em>occurs if we execute Get-NetSession from PowerView[<a href="https://github.com/PowerShellMafia/PowerSploit/blob/master/Recon/PowerView.ps1">13</a>], from a remote machine and we also obtain that information:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*dokIgIA4XvUyE3YM5vcKkA.png" /><figcaption>Get-NetSession execution from a PC</figcaption></figure><p>So if that information is accessible, what can a bad guy do with it? It helps to map <strong>where every user has a session on the domain</strong>, for example, the information shown above, lets us know that the user <em>mvazquez </em>requested a resource from <em>DC-Company</em> from the IP 192.168.1.20. This information confirms that <em>mvazquez </em>currently has an active session on 192.168.1.20. This information is important given that it indicates that the <em>mvazquez’s credentials should </em>be in Lsass memory on 192.168.1.20, and if that account has any type of privileges, we could attempt to extract their credentials in order to move laterally or vertically.</p><p>Now that we have seen what information has been gathered and how it can be used, it is time have a look at the detection capabilities. On the <strong>first level</strong>, we are going to have a look at all of the different <strong>tools </strong>that can be used to recollect that information and check how these can be detected. The tools include Sharphound and BloodHound.py, however, as mentioned previously we can also get all of that information from PowerView using Get-NetSession, or if we do a quick Google search other options like NetSess will come up, so if we only try to detect session collection using Sharphound and BloodHound.py, we will be leaving other recollection options behind. Also, as explained in phase one, tool detection is not the best option, so we will try to abstract the behaviors of all these tools.</p><p>If we keep diving deeper into the different layers of detection, we will obtain a table such as this one included below (<em>If you want to know each of these I highly recommend you to check out this presentation [</em><a href="https://www.youtube.com/watch?v=_GJDkbUTSLY"><em>14</em></a><em>] from the SpecterOps team.</em>)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*H4VXXI3LSRyvUHcQNthX_g.png" /><figcaption>User Session Enumeration detection.</figcaption></figure><p>The overall idea behind this table is that we need to use <strong>a row at a layer where all recollection methods could be detected</strong>, that is to say, we could build a detection for each of these tools individually, but ultimately it will be impossible to create a detection for every single tool that could ever exist, so our main goal is to supplement the tool detections for non-tools, with a kind of technique based detection, like for example, modules being loaded, or API functions being called or RPC requests over the wire.</p><p>For example, if we try to detect this session collection at a <strong>Windows API Functions level</strong>, we could detect Sharphound, Get-NetSession, and NetSess, however we will not be able to detect BloodHound.py because if we review the SharpHound and Get-NetSession code, which are both publicly available on Github, we can see that they rely on NetSessionEnum..</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/642/1*1um6iHVqGYlVVv7z_AOk3Q.png" /><figcaption>NetSessionEnum usage on SharpHound</figcaption></figure><p>However, if we try to look for this code on the BloodHound.py script we will not find it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/626/1*lzc9YNxLC0sJUgcaf101GA.png" /><figcaption>NetSessionEnum search results on BloodHound.py</figcaption></figure><p>And this is because BloodHound.py directly calls the RCP procedure NetrSessionEnum, and in doing so it bypasses all of the operating system’s API functions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/817/1*KLLjwOfTkykdNG_YNCW6cQ.png" /><figcaption>hNetrSessionEnum usage on BloodHound.py</figcaption></figure><p>Therefore, the detections that we should rely on are the <strong>RPC Interfaces layer</strong> or the Network Protocol layer. On the Network Protocol, we should ask ourselves questions such as, does this technique require network connectivity? which port and protocol are used?, and above all, what differentiates this activity from other possibly benign activity? Taking into account the fact that the <em>srvsvc</em> named PIPE is added by Microsoft by default, we cannot just presume that if there is any request it must be bad. To analyze how this request is performed, we will use Wireshark again and execute each of the tools we have seen so far.</p><p>For SharpHound, Get-NetSession and NetSess, we see the NetSessEnum request:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*GTcNyAZABSAEY1Rq_2Es-g.png" /><figcaption>NetSessEnum from Wireshark</figcaption></figure><p>So, we could expect the same results with bloodhound.py, however that is not the case as shown below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/839/1*l1k7GIQnuUJvSve9jJpSYw.png" /><figcaption>BloodHound.py session recollection from Wireshark</figcaption></figure><p>That’s because bloodhound.py under the hood uses Impacket, and Impacket uses SMB3 which encrypts SMB traffic so it’s impossible to check if it calls NetSessionEnum or NetrSessionEnum as it should, then if at a payload packet level, we can’t detect anything, we will have to try it a higher level.</p><p>At the <strong>application layer</strong>, (<em>for each session collection</em>) in Wireshark, we firstly see the DNS request because we have the hostname from the LDAP queries but not the IP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/639/1*HNRQi8XQYln-fIU_LK-ofw.png" /><figcaption>DNS Request from Wireshark</figcaption></figure><p>The 3-way handshake with the computer, the data exchange, and finally the end of the session. Until here, everything looks normal, but if we zoom out, something very interesting appears, hundreds of connections to port 445 from the same source Ip to different destination IPs in a short period of time.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/589/1*mToz1Vcfgmo6WK-e8I-NRw.png" /><figcaption>Session recollection from the SIEM point of view</figcaption></figure><p>Therefore, if we characterize the requests that are made on our network, we could implement a pretty good detection that looks for the <strong>peak of requests to port 445 from the same source IP to a lot of different destination IPs</strong>.</p><h3>Conclusions</h3><p>We have seen two different ways in which the execution of the recollection tools used to inject the data into BloodHound can be detected, however, quite a good detection can be performed if we<strong> put it all together</strong>, that is to say, if we detect that a user from a specific source IP has enumerated a certain decoy object that we have created and that it immediately starts to connect to port 445 of almost all the endpoints we have, this would be a strong indicator that we are undergoing a reconnaissance.</p><p>In conclusion, depending on the size of the company, the accuracy we desire, and the FPs we are disposed to tolerate, different coverages will be obtained. The next table summarizes the best option for each case.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/1*Yiz0BrsIM5xJfTKDQAQ7xg.png" /><figcaption>Relation between detection methods and company size</figcaption></figure><p>Finally, with both rules, can we be completely sure that a BloodHound reconnaissance will be detected every time it is executed? Of course, not. There are many bypasses for these or any other detection, such as collecting all of the data we need during different periods of time using the different modules provided by the tools themselves, making the rules unable to correlate. Therefore, <strong>detection also depends on how noisy the bad guys are</strong>.</p><h4>Contributors:</h4><ul><li>Francisco Mateu Sanchez<br>Incident Response Manager</li><li>Luis Miguel Agudo<br>Red Team Lead</li><li>Mario Andrés<br>Chief Information Security Officer</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ac290427b17" width="1" height="1" alt=""><hr><p><a href="https://medium.com/mercadonait/how-to-hear-the-bloodhound-barking-5ac290427b17">How to hear the Bloodhound barking</a> was originally published in <a href="https://medium.com/mercadonait">Mercadona IT</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Intrusion detection system using artificial neural networks]]></title>
            <link>https://medium.com/analytics-vidhya/intrusion-detection-system-using-artificial-neural-networks-14afc2112be?source=rss-2f0d5c5e8baf------2</link>
            <guid isPermaLink="false">https://medium.com/p/14afc2112be</guid>
            <category><![CDATA[keras]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[intrusion-detectionsystem]]></category>
            <dc:creator><![CDATA[Pepe Pérez Sifre]]></dc:creator>
            <pubDate>Wed, 20 May 2020 18:37:20 GMT</pubDate>
            <atom:updated>2020-05-22T18:11:07.206Z</atom:updated>
            <content:encoded><![CDATA[<p>In the ever-changing world of computer technology and rapidly evolving cyber threats, attackers and defenders are in a constant loop of cat-and-mouse. On the defender’s side, a defense-in-depth strategy must be added to their security layer to effectively detect advanced persistent cyber threats, where Intrusion Detection System (IDS) is a key element. In this post I will try to apply the growing field of artificial intelligence to it. All the code used for the development of this project is on Github. See link I have attached below. [<a href="https://github.com/sepi1996/IDS-using-Neural-Networks">Github repository</a>]</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/225/0*X7u9ad3tptQgoiFN" /><figcaption>Defense-in-depth strategy</figcaption></figure><h3>Introduction</h3><h4>Intrusion Detection System</h4><p>Broadly speaking, we could define an Intrusion Detection System as a device or software application that monitors a network or systems for malicious activity or policy violations. Any intrusion or breach activity is, usually, then reported to an administrator or collected centrally using an event management and security information system.</p><p>As we can see in the image below, there are different types of IDS depending on the function. We will focus on NIDS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XOmaFChbyICBDaC8GwIHsg.png" /><figcaption>Types of IDS</figcaption></figure><p>There are two types of NIDS that vary based on the detection method used. The first, and earliest used, the signature-based NIDS like <a href="https://www.snort.org/">Snort</a> and <a href="https://suricata-ids.org/">Suricata</a>, are by far, the most used. A signature-based NIDS looks for patterns in network traffic and compares it to pre-installed known attack patterns called rules, which makes SNIDS a really great solution for detecting known attacks, but they fail to detect new or previously unrecognized attacks. This problem can be also applied to antivirus software because they rely on continuous virus signature updates to remain effective. The second type of NIDS is the anomaly-based NIDS, which rely on various statistical machine learning models to automatically learn patterns and create rules that distinguish normal traffic from malicious attacks. In summary, signature-based NIDS looks for patterns while anomaly-based NIDS analyze behaviors.</p><p>On reaching this point, one may ask, if the anomaly-based IDS are able to recognize known and unknown attacks, then why are signature-based NIDS like Snort and Suricata are the most used ones? In answer, anomaly-based IDS also has an important downside because its accuracy depends on, and therefore is limited, by the data used when training the model.</p><p>Finally, regarding the NIDS I will be using artificial neural networks for learning, specifically dense neural networks, whose main characteristic is that the neurons between two adjacent layers are completely connected in pairs, but the neurons within a single layer do not share connections.</p><h4>Dataset</h4><p>In order for the neural network to be able to distinguish between the normal traffic and the malicious one, it will require a set of categorized input values. For so, there a some datasets already made, like the <a href="https://www.ll.mit.edu/r-d/datasets/1998-darpa-intrusion-detection-evaluation-dataset">DARPA1998</a>, or the <a href="http://kdd.ics.uci.edu/databases/kddcup99/kddcup99.html">KDD99</a>, but in this case I will be using the dataset provided by the <a href="https://www.unb.ca/cic/datasets/ids-2018.html">Communications Security Establishment (CSE) &amp; the Canadian Institute for Cybersecurity (CIC)</a> mainly because it is the most updated. The 2018 dataset contains different type of attacks over a netwok, like DoS, web attacks, etc, but for the sake of simplicity I will focus on the brute-force attacks over the SSH and FTP protocol.</p><h4>Work environment</h4><p>As a work environment Anaconda along with Jupyter as a development environment will be used. To implement the neural network code I will use the Python programming language along with its high-level API <a href="https://keras.io/">Keras </a>for neural networks. Finally, other libraries will be used for the data visualization and managment like Pandas, Numpy or Matplotlib.</p><h3>Building the artificial neural network</h3><h4>Data Analysis and Cleanup</h4><p>After downloading the corresponding dataset, we analyzed the data to learn about their characteristics and cleaned it up if required.</p><ul><li>Row cleanup: The dataset contains non-numerical values, which cannot be processed by the neural network like “Nan” and “Infinity” therefore these rows will be deleted. The next table shows the final number of rows that will be procesed.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/543/1*88MZAP0fVxo70zA-clkRKw.png" /><figcaption>Final dataset content</figcaption></figure><ul><li>Extraction of unnecessary columns: The <a href="http://netflowmeter.ca/">CICFlowMeter</a>( the tool used by the CSE &amp; CIC to analyze network traffic flows) has extracted all the information in 79 different columns. As some of these will not be useful to us, or cannot be understood by the neural network for learning, so they will be droped as well.</li><li>Mix data: The data in the csv file, is ordered as it was produced, that is, first we have a small block of benign traffic, then the block of brute force attack on FTP, then benign traffic, then the other block of brute force attack over SSH and finally another benign traffic block. This is a learning problem for the neural network, since, initially, when receiving a block of 193,354 rows of brute force attack on FTP, the network will specialize in detecting only this type of input. This results in longer time lapse when receiving all benign traffic and mistakes always being made predicting attacks over FTP<br>To avoid this problem I will shuffle randomly all the rows:</li><li>Normalization: Depending on the type of the characteristic, the values ​​it has vary with respect to the values ​​of the other, for example, the values ​​of the Flow IAT MAX characteristic will always be greater than the values ​​in Flow IAT MIN, so these two characteristics are in different ranges. To avoid this problem the min-max normalization will be used.</li><li>Codification: In this dataset , we have three types of traffic: “FTP Brute Force”, “SSH Brute Force” and “Benign”. That is, they are categorical data since they contain labels instead of numerical values, which cannot be interpreted by our neural network. To solve this problem, we will use One-Hot encoding, through which these categorical variables are converted into numerical values. In the next image we can see an expample of this encoding:</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/747/1*7vKcBN7bv05xfXcNkTFA4A.png" /><figcaption>One Hot encoding</figcaption></figure><blockquote>The code corresponding to the pre-processing of the data is in the file import.py</blockquote><h4>Obtaining the best model</h4><p>One of the most difficult points when implementing a neural network is the architecture that it must have, at the level of hidden layers and neurons for each of these layers, and at level of activation functions, cost functions, overfitting etc, since there is no rule or protocol that indicates the hyperparameters we should use to achieve an optimal result. As this is a well known problem, there are currently a wide variety of tools to streamline this process. In this case I am going to use the <a href="https://github.com/autonomio/talos">Talos</a> tool.</p><p>With Talos we define a dictionary with the possible parameters of the neural network, so that later on we can analyze the results obtained and see which neural network has obtained a higher hit rate. After it’s execution the best results obtained over the 384 different models are the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/977/1*Ix8E_VSDhsxHjrAgTTz9Vg.png" /><figcaption>Tales results</figcaption></figure><p>From which we can therefore come to the subsequent conclusions:</p><ol><li>The model works best with a single hidden layer.</li><li>No need to apply dropout.</li><li>The best number of neurons in the hidden layers is 256 neurons.</li><li>Both optimizers obtain similar results.</li><li>The number of neurons in the input layer seems indifferent.</li></ol><p>Then, from these results, we gather that the best neural network architecture will be this one:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/358/1*RKj-8MHRjUlqEFjzECMxbg.png" /><figcaption>Best neural network architecture</figcaption></figure><blockquote>The code corresponding to the Talos implementation is in the file KerasTuner.py</blockquote><h3>Results</h3><p>Finally to evaluate the algorithm we will divide the dataset into three parts:</p><p>Training set: The actual dataset that we use to train the model. The model sees and learns from these data. For this set we are going to use 81% of the total data.<br>Validation set: This is the dataset used to provide an impartial evaluation of a fitted model in the training dataset while adjusting the hyperparameters of the model. For this set we are going to use 10% of the total data.<br>Test set: It is the dataset used to provide an impartial evaluation of a final model fitted in the training dataset. For this set we are going to use 9% of the total data.</p><p>In the next images we can check the results:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/973/1*a3kx2xIZlFYzStJvkRxFng.png" /><figcaption>Results depending on the activation function</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/971/1*zk6RKPVPB7eACOYsGc-NVA.png" /><figcaption>Results depending on the optimizer</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*oOswQVb2T_vDNPMIz549Gg.png" /><figcaption>Succes rate using different number of epochs</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/819/1*ombTul9ljj-1Pc-M-3vV2A.png" /><figcaption>Confusion matrix results</figcaption></figure><blockquote>The code corresponding to the best IDS and the graphics is in the file bestIDS.py</blockquote><h3>Conclusions</h3><p>As we have seen in the results section the accuracy of the IDS that we have developed is excellent.</p><p>The best activation function for this model is the ReLu function, and the best optimizer is the Adam optimizer. The number of epochs needed to obtain the the maximum succes rate is more or less 10, because as shown in the 50 epochs image, after 10 epochs the hit rate no longer improves.</p><p>The confusion matrices show us that the model has a 100% accuracy over FTP. That is, whenever the model has received a sample of an FTP attack it has predicted that it would indeed correspond to an attack over FTP. Hence the true positive rate over FTP is one whereas whenever an FTP attack has been received, it has never predicted to be another type of traffic. Further, the few times it has been wrong, it has been distinguishing between benign traffic and an attack on SSH</p><p>Finally, in this intrusion detection system, we have tried to separate two types of attacks to see if they could also be distinguished. This has been achieved with a very high hit rate, but the goal of an IDS is to detect threats. This is to say, it is not as important as how well you separate the different types of attacks, but rather being able to recognize attacks, which our best model has done in a practically perfect way, because over 602,462 traffic flows it does not recognize the attack, on 2 occasions.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=14afc2112be" width="1" height="1" alt=""><hr><p><a href="https://medium.com/analytics-vidhya/intrusion-detection-system-using-artificial-neural-networks-14afc2112be">Intrusion detection system using artificial neural networks</a> was originally published in <a href="https://medium.com/analytics-vidhya">Analytics Vidhya</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Forensic analysis of an encrypted virtual machine]]></title>
            <link>https://medium.com/@pepesifre/forensic-analysis-of-an-encrypted-virtual-machine-b24240274367?source=rss-2f0d5c5e8baf------2</link>
            <guid isPermaLink="false">https://medium.com/p/b24240274367</guid>
            <category><![CDATA[encryption]]></category>
            <category><![CDATA[forensic-analysis]]></category>
            <category><![CDATA[kali-linux]]></category>
            <category><![CDATA[virtual-machine]]></category>
            <category><![CDATA[autopsy]]></category>
            <dc:creator><![CDATA[Pepe Pérez Sifre]]></dc:creator>
            <pubDate>Thu, 14 May 2020 11:33:16 GMT</pubDate>
            <atom:updated>2020-05-14T11:48:33.253Z</atom:updated>
            <content:encoded><![CDATA[<p>Setting up the environment for the analysis of a virtual machine can be trivial and not too difficult if we use the correct tools, but in this post we will see a variant of this type of analysis, how to properly analyze an encrypted virtual machine without modifying the digital evidence.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/299/1*3Y_Duke2OYJiYzpIF4-bRQ.jpeg" /></figure><p>Virtual machine has been the most one of virtualization technology used today for working and saving hardware resources, besides as a tool conduct research on malware, network installations etc, so the wide use of virtualization technology is becoming a new challenge for digital forensics. One of the keys when carrying out an analysis on this evidence is its non-modification, which we can verify and demonstrate by using Hash functions. This can be “simple” if we analyze the machine with a tool like <a href="https://www.autopsy.com/">Autopsy</a>, through which we can import the image without modifying the evidence at any time. But this can be more complicated if the VM has a full disk encryption, because Autosy will not be able to analyze an encrypted image. So in this post, I will focus on explaining how we can help Autopsy to analyze the encrypted image without booting and therefore modifying it.</p><h3>Adding the image</h3><p>To start, I will use the <a href="https://www.virtualbox.org/">Oracle VM VirtualBox</a> virtualization environment, along with a Kali Linux virtual machine. Through the storage option that VirtualBox offers us, we will add a second hard drive, which will be the evidence, as we can see in the image. (It is important to work on a copy of the evidence, never on the evidence itself that has been provided for the analysis)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/468/1*tSR-l_IwGEWumXwvLR0sHQ.png" /><figcaption>ubuntu.vdi will be the evidence to analyze</figcaption></figure><p>Now we start the Kali machine and through a terminal, with the commands</p><pre>ls -ls /dev/sd* <br>lsblk -f /dev/sdb</pre><p>we can check how the hard disk has been added correctly, and it is effectively encrypted.</p><h3>Decrypt the image</h3><p>Now that we have checked that the image has been added, we use <em>cryptsetup </em>to open the image. For this, we need to know the encryption password which we will have to enter. Otherwise, we can test with a brute force attack. I attach two links with more information on how to do them. <a href="https://hackernoon.com/cracking-linux-full-disc-encryption-luks-with-hashcat-832d5543101f">[1]</a> <a href="https://dfir.science/2014/08/how-to-brute-forcing-password-cracking.html">[2]</a></p><p>Now we can check that the disk has been decrypted, and the logical volumes have been automatically mapped as we can see in the next image.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/1*bfZwcAQyTEe0UgV9jE7J7A.png" /><figcaption>Using cryptsetup to open the encrypted image</figcaption></figure><blockquote>If LVM support is not installed on the Kali machine, it can be installed using apt-get install lvm2. In this way, it will automatically map the LVM partitions of the image.</blockquote><p>Using other commands like vgdisplay, will show us the group of volumes that contain the hard drive of the virtual image.</p><h3>Mounting the volume</h3><p>The next step in the analysis will be mounting the volume. For this we will use the mount command to which we will indicate where we want to mount volume and specify that it is read-only, to ensure its integrity.</p><pre>mount -r /dev/ubuntu — vg-root /media/vdi</pre><p>Now we will have the content of the virtual machine on the directory /media/vdi fully accessible to be analyzed using Autopsy.</p><p>Finally, we could as well, use a dump tool to create a new unencrypted image for further analysis without having to go through the same steps we have seen previously. For so we can use tools like dd or dcfldd as follows:</p><pre>dcfldd if=/dev/Ubuntu-vg/root of=/home/kali/vdi.img</pre><p>With this image, now we can use the option “Disk Image or VM File” of Autopsy, to start the analysis of the virtual machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/426/1*nc3pt1odb1fvl3iTKNVbCA.png" /><figcaption>Adding data source from Autopsy</figcaption></figure><h3>Checking the integrity</h3><p>Finally, once we have analyzed the evidence, we are going to unmount the volume, using umount command and deactivate the volume group using:</p><pre>vgchange -a n ubuntu-vg </pre><p>where ubuntu-vg corresponds to the volume group that the vgdisplay command has previously shown us. Now, the last step once we have deactivated the volumes, would be to close them with:</p><pre>cryptsetup close /dev/dm-0 </pre><p>Now we can turn off the Kali machine and using any hash calculation tool we will check that the disk that we have attached, remains exactly the same as the original one, and therefore, we have not modified the evidence, as we can see in the next image:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/741/1*VRKV7e1agXhxe5wAArQQ8w.png" /><figcaption>Both hashes remain the same</figcaption></figure><h3>Conclusion</h3><p>As we have been able to verify, it is possible to perform the analysis of an encrypted virtual machine without modifying the evidence at any time, which is very important when we are conducting a forensic analysis. Of course, the encryption key will be required, or it will have little complexity to be attacked by brute force.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b24240274367" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>