<?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 Kenza el marchouk on Medium]]></title>
        <description><![CDATA[Stories by Kenza el marchouk on Medium]]></description>
        <link>https://medium.com/@kenzamarchouk?source=rss-ea314262d963------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*mR1fwqfhbvfX1V6S37O0vg.jpeg</url>
            <title>Stories by Kenza el marchouk on Medium</title>
            <link>https://medium.com/@kenzamarchouk?source=rss-ea314262d963------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 25 Nov 2026 00:00:40 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@kenzamarchouk/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[Keycloak Authentication in Node.js Express: User Management and Access Control PART3]]></title>
            <link>https://medium.com/@kenzamarchouk/keycloak-authentication-in-node-js-express-user-management-and-access-control-part3-950b6aad1353?source=rss-ea314262d963------2</link>
            <guid isPermaLink="false">https://medium.com/p/950b6aad1353</guid>
            <category><![CDATA[identity-management]]></category>
            <category><![CDATA[keycloak]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Kenza el marchouk]]></dc:creator>
            <pubDate>Mon, 20 May 2024 11:15:50 GMT</pubDate>
            <atom:updated>2024-09-25T13:31:47.432Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/795/1*0ITcBYYLkU9-0KDkGtnY-g.png" /></figure><p>In this section, we will cover <strong>the implementation of identity federation using OpenLDAP.</strong></p><p>To successfully complete this part, I assume you already have OpenLDAP installed.</p><p>In my OpenLDAP configuration, I have two users with different group roles: either candidate or resident.</p><p>Here is the tree schema of my OpenLDAP configuration:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*gi40TJR_TEJ3QqXZTlzV4A.jpeg" /></figure><p>Here is the LDIF file for this tree configuration:</p><pre><br>dn: dc=example,dc=com<br>objectClass: top<br>objectClass: dcObject<br>objectClass: organization<br>o: example.com<br>dc: example<br><br># users<br>dn: ou=users,dc=example,dc=com<br>objectClass: organizationalUnit<br>ou: users<br>description: Organizational unit for user entries<br><br># groups<br>dn: ou=groups,dc=example,dc=com<br>objectClass: organizationalUnit<br>ou: groups<br>description: Organizational unit for groups<br><br># user2, users<br>dn: uid=user2,ou=users,dc=example,dc=com<br>objectClass: inetOrgPerson<br>objectClass: posixAccount<br>objectClass: shadowAccount<br>cn: User Two<br>sn: Two<br>uid: user2<br>uidNumber: 1001<br>gidNumber: 1000<br>homeDirectory: /home/user2<br>loginShell: /bin/bash<br>userPassword:: MTItz<br><br># user1, users<br>dn: uid=user1,ou=users,dc=example,dc=com<br>objectClass: inetOrgPerson<br>objectClass: posixAccount<br>objectClass: shadowAccount<br>cn: User One<br>sn: One<br>uid: user1<br>uidNumber: 1000<br>gidNumber: 1000<br>homeDirectory: /home/user1<br>loginShell: /bin/bash<br>userPassword:: MTIfz<br><br># candidate, groups, example.com<br>dn: cn=candidate,ou=groups,dc=example,dc=com<br>objectClass: groupOfNames<br>cn: candidate<br>description: Group for candidates<br>member: uid=user1,ou=users,dc=example,dc=com<br><br># resident, groups, example.com<br>dn: cn=resident,ou=groups,dc=example,dc=com<br>objectClass: groupOfNames<br>cn: resident<br>description: Group for residents<br>member: uid=user2,ou=users,dc=example,dc=com<br></pre><h3>Step1: Load the LDIF File into OpenLDAP</h3><p>Use the ldapadd command to add the entries defined in the LDIF file to your OpenLDAP server.</p><pre>ldapadd -x -D &quot;cn=admin,dc=example,dc=com&quot; -W -f your_ldif_file.ldif</pre><h3>Step2: Create realm roles</h3><p>The next step is to create the two roles from our OpenLDAP configuration, ‘candidate’ and ‘resident’, in the Keycloak realm we created in part 1.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_7CPUELBZOZ6HGqm6TP1DA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aOHvhnpe8A-kAFRnHPhB1w.png" /></figure><h3>Step3: Create OpenLDAP user federation</h3><p>To import users we have in OpenLDAP in keycloak we need to add an LDAP provider.</p><p>The configuration we need to set:</p><ul><li>General setting:</li></ul><blockquote>vendor: other</blockquote><ul><li>Connection:</li></ul><blockquote>Connection URL: This is the URL used to connect to the OpenLDAP server. Use ldap://localhost for a standard connection or ldaps://localhost if an SSL certificate is already configured.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n2qDFWaereJINf3J6mX4DQ.png" /></figure><ul><li>Authentication</li></ul><blockquote>Set the password you use to authenticate with your admin account on the OpenLDAP server.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*XxvOng0UT1AfI8xyWgAYiQ.png" /></figure><ul><li>Configure Users’ Distinguished Names (DNs)</li></ul><blockquote>Define the distinguished names (DNs) for users in OpenLDAP. This ensures that Keycloak knows where to locate users existing in the OpenLDAP server.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3B7NKRq_rMKr_hwgUpcnXA.png" /></figure><ul><li>Synchronization settings</li></ul><blockquote><strong>Enable Import Users</strong>: This option allows the import of users from the OpenLDAP server into Keycloak.</blockquote><blockquote><strong>Enable Sync Registrations</strong>: This feature synchronizes user registrations between Keycloak and the OpenLDAP server. Any changes made to user in Keycloak, such as account creations or profile modifications, are synchronized back to the OpenLDAP server, ensuring consistency between the two systems.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*jykn5ZqyLtL7WxmkEwt6pA.png" /></figure><h3>Step4: add role LDAP mapper</h3><blockquote>In the mapper section of the LDAP provider previously created, add a role LDAP mapper. Configure the LDAP roles’ distinguished names (DNs) to inform Keycloak where to locate the roles of users existing in OpenLDAP and attribute them to the appropriate Realm role.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/947/1*q4X0CVCOSrs1AnhC7iOl0w.png" /></figure><p>My two users from the OpenLDAP server have been successfully imported into Keycloak with their respective roles assigned.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kjfF9_E7tvMqiMfr_GNk6Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y-zrJCzIlzjWDlVWe53FKA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pLIFfVtvnJbFV9MSfQ9sgg.png" /></figure><h3>Demo</h3><p>In this demo, I attempt to authenticate as user2 as a candidate. However, user2 has the role of resident, so access to the candidate space is denied, resulting in an access denied message.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/913/1*axUvRQcbk6nFRvgNsTawHg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/206/1*gXOEo-MyAX6xuNt9TpGncA.png" /></figure><p>Conversely, when I use user2 to access the resident space, the authentication is successful, and access is granted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/proxy/1*RYKpporqXF1swHBPu3knDQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=950b6aad1353" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Keycloak Authentication in Node.js Express: User Management and Access Control PART2]]></title>
            <link>https://medium.com/@kenzamarchouk/keycloak-authentication-in-node-js-express-user-management-and-access-control-part2-e7d1dc6391f9?source=rss-ea314262d963------2</link>
            <guid isPermaLink="false">https://medium.com/p/e7d1dc6391f9</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[identityaccess-management]]></category>
            <category><![CDATA[keycloak]]></category>
            <category><![CDATA[identity-management]]></category>
            <dc:creator><![CDATA[Kenza el marchouk]]></dc:creator>
            <pubDate>Sun, 19 May 2024 22:19:39 GMT</pubDate>
            <atom:updated>2024-05-19T22:19:39.186Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/795/1*0ITcBYYLkU9-0KDkGtnY-g.png" /></figure><p>In this part, we will cover : <strong>Handling authentication and authorization of users for a node js web application</strong>.</p><h3>Application node js</h3><p>This Node.js application implements authentication and authorization using Keycloak.</p><ol><li><strong>Dependencies :</strong></li></ol><blockquote>Express.js : for web server</blockquote><pre>npm install express</pre><blockquote>Express session : for session management</blockquote><pre>npm install express-session</pre><blockquote>Keycloak Connect : for integrating with Keycloak.</blockquote><pre>npm install keycloak-connect</pre><p>Once you’ve installed these dependencies and configured Keycloak, you’re ready to use them</p><pre>#Code of index.js<br>const app = express();<br>const express = require(&#39;express&#39;);<br>const session = require(&#39;express-session&#39;);<br>const Keycloak = require(&#39;keycloak-connect&#39;);</pre><p><strong>2. Configuration :</strong></p><p>Load the configuration JSON file containing your client’s adapter configuration downloaded earlier</p><pre>const keycloakConfig = require(&#39;PATH_To_AdapterConfiguration.json&#39;);</pre><p><strong>3. Session Management :</strong></p><p>Set up session middleware using express-session and configure it to use a MemoryStore to store session data.</p><pre>const memoryStore = new session.MemoryStore();<br>const keycloak = new Keycloak({ store: memoryStore });<br>app.use(session({<br>    secret: &#39;mymKWhjV&lt;T=-*VW&lt;;cC5Y6U-{F.ppK+])&#39;,<br>    resave: false,<br>    saveUninitialized: true,<br>    store: memoryStore<br>}));<br>app.use(keycloak.middleware());</pre><p><strong>4. Custom Middleware (</strong><strong>checkRole) :</strong></p><p>This middleware function extracts the access token from the request and verifies if the user&#39;s roles include the specified role.</p><pre>// Custom middleware to check user role<br>function checkRole(role) {<br>    return function(req, res, next) {<br>const accessToken = req.kauth.grant.access_token.token;<br> const username = req.kauth.grant.access_token.content.preferred_username;<br>const userRoles = req.kauth.grant.access_token.content.realm_access.roles;<br><br><br>if (userRoles.includes(role)) {<br>            next(); // Role is correct, continue<br>        } else {<br>            res.status(403).send(&#39;Access denied&#39;); // Role doesn&#39;t match, send access denied<br>        }<br>    };<br>}</pre><p><strong>5. Routes :</strong></p><ul><li>Home page route (/): This route renders a simple HTML page with buttons for logging in as a candidate or resident.</li></ul><pre>// Home page with authentication buttons<br>app.get(&#39;/&#39;, (req, res) =&gt; { res.send(`<br>        &lt;button onclick=&quot;window.location.href=&#39;/login/candidate&#39;&quot;&gt;Candidate&lt;/button&gt;<br>        &lt;button onclick=&quot;window.location.href=&#39;/login/resident&#39;&quot;&gt;Resident&lt;/button&gt;<br>    `);});</pre><ul><li>Protected routes (/login/:role) : These routes are protected using keycloak.protect(), meaning only authenticated users can access them. The role of the user is checked using the custom middleware (checkRole). If the user has the required role, they are allowed to access the route; otherwise, a &quot;403 Access Denied&quot; error is sent.</li></ul><pre>// Protected routes for candidate and resident<br>app.get(&#39;/login/:role&#39;, keycloak.protect(),(req, res, next) =&gt; {<br>    const role = req.params.role;<br>    const roleCheckMiddleware = checkRole(role);<br>roleCheckMiddleware(req, res, async () =&gt; {<br>try{<br>    <br>    const username = req.kauth.grant.access_token.content.preferred_username;<br><br>res.send(`<br><br>        &lt;h1&gt;Space ${role}&lt;/h1&gt;<br>        &lt;p&gt;Welcome ${username}&lt;/p&gt;<br>        &lt;form action=&quot;/logout&quot; method=&quot;post&quot;&gt;<br>            &lt;button type=&quot;submit&quot;&gt;Logout&lt;/button&gt;<br>        &lt;/form&gt;<br> <br>    `);<br>} catch (error) {<br>            console.error(&#39;Error:&#39;, error);<br>            res.status(500).send(&#39;Internal server error.&#39;);<br>        }<br>});<br>});</pre><ul><li>Logout route (/logout): This route logs the user out by clearing their session and then redirects them to the home page.</li></ul><pre>// Logout route<br>app.post(&#39;/logout&#39;, keycloak.protect(), (req, res) =&gt; {<br>    req.logout(); // Clear the user&#39;s session<br>    res.redirect(&#39;/&#39;); // Redirect the user back to the home page<br>});</pre><p>6. <strong>Start the server</strong> :</p><p>Start the Express server and listen on the port 3000</p><pre>// Start the server<br>app.listen(port, () =&gt; {<br>    console.log(`Server is listening at http://localhost:3000`);<br>});</pre><h3><strong>Demo</strong></h3><p>This is how our application looks:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/523/1*JSQtm84Vke144DrlRCv3qQ.png" /></figure><p>When I click on the “Candidate” or “Resident” button, I am redirected to the Keycloak authentication page:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/1*jOtQutYrcgqYz859JHIVTg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e7d1dc6391f9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Keycloak Authentication in Node.js Express: User Management and Access Control PART1]]></title>
            <link>https://medium.com/@kenzamarchouk/keycloak-authentication-in-node-js-express-user-management-and-access-control-part1-0c3370c75838?source=rss-ea314262d963------2</link>
            <guid isPermaLink="false">https://medium.com/p/0c3370c75838</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[identity-management]]></category>
            <category><![CDATA[keycloak]]></category>
            <dc:creator><![CDATA[Kenza el marchouk]]></dc:creator>
            <pubDate>Sun, 19 May 2024 22:15:56 GMT</pubDate>
            <atom:updated>2024-05-19T22:15:56.272Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/795/1*0ITcBYYLkU9-0KDkGtnY-g.png" /></figure><h3>Keycloak overview:</h3><p>Keycloak is an open-source tool for identity and access management that offers a wide range of solutions to simplify user authentication and authorization processes. It provides features such as Single Sign-On (SSO), social login, and user federation...etc</p><p>This tutorial contains 3 parts, covering the following points:</p><ol><li>Installation of Keycloak on Ubuntu</li><li>Handling authentication and authorization of users for a node js web application</li><li>Implementing identity federation using OpenLDAP</li></ol><p>In this part we will focus on <strong>installation of Keycloak on Ubuntu</strong></p><h3>Step1: Installation of Keycloak</h3><p>There are several methods to install Keycloak, including using OpenJDK, Docker, and others. You can find detailed installation guides on the official Keycloak website:</p><p><a href="https://www.keycloak.org/">https://www.keycloak.org/</a></p><p>In this tutorial, we will use OpenJDK for the installation process.</p><h3>Stepe2: Install OpenJDK in your operation system</h3><p><a href="https://openjdk.org/">OpenJDK</a></p><h3>Step2: Start Keycloak</h3><p>Once you’ve downloaded and extracted the Keycloak ZIP file, navigate to the directory where you extracted it in your terminal. Then, execute the following command to initiate it:</p><pre>bin/kc.sh start-dev</pre><h3>Step3: Create an admin account</h3><ol><li>Open the admin console by navigating to http://localhost:8080/ in your web browser, or replace “localhost” with your domain name if applicable</li><li>Proceed to create your admin account</li></ol><h3>Step4: Create a realm</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oJYqngZgoI95b88oHUVbSw.png" /></figure><h3>Step5: Create a client</h3><p>Inside your realm, create your client.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pYytGw5Fre-tYZBzMTtRzw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*A0giErTYu6XxD8rUW1keiQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rQ3dEO22mB1U133pKI_wtA.png" /></figure><p>In the URLs, replace the links with those corresponding to your Node.js application</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3RAect_NLhKJxMR9Hah1Jg.png" /></figure><p>Download the JSON file containing the adapter configuration of your client. We will require it to manage the authentication and authorization of your Node.js application</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IebXcAGnUxi8AZT2-OrJRQ.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0c3370c75838" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[OpenLDAP: Overview and Installation Guide]]></title>
            <link>https://medium.com/@kenzamarchouk/openldap-6af9f78d8dda?source=rss-ea314262d963------2</link>
            <guid isPermaLink="false">https://medium.com/p/6af9f78d8dda</guid>
            <category><![CDATA[openldap]]></category>
            <dc:creator><![CDATA[Kenza el marchouk]]></dc:creator>
            <pubDate>Fri, 13 Oct 2023 21:37:03 GMT</pubDate>
            <atom:updated>2025-03-07T18:54:34.189Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/299/1*Dm63EHu5hS9jB_Wuwi_B-A.png" /></figure><p><strong>OpenLDAP (Open Lightweight Directory Access Protocol)</strong>: A protocol that allows access to a centralized directory.</p><p>It facilitates the search for information within this directory.</p><p>An LDAP directory is a hierarchical structure in the form of a tree called a DIT (Directory Information Tree), composed of sets of attributes with a unique identifier called a DN (Distinguished Name).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8k0bJ9w7VA2NXKCgfVUIbQ.jpeg" /></figure><h3>Implementation</h3><ol><li>Windows: Active Directory</li><li>Linux: OpenLDAP, RedHat Directory Studio</li></ol><h3>Installation</h3><ol><li>Update your package list</li></ol><pre>sudo apt update</pre><p>2. Install the OpenLDAP server</p><pre>sudo apt install slapd</pre><p>3.Install OpenLDAP client</p><pre>sudo apt install ldap-utils</pre><p>4. Start OpenLDAP server</p><pre>service slapd start</pre><p>5. Check its status</p><pre>sudo systemctl status slapd</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*iJrZMsxR6OUNBrSlqRXRMA.png" /></figure><p>In Kali Linux, the OpenLDAP configuration files are typically located in the /etc/ldap/directory.</p><h3>LDAP server configuration</h3><pre>sudo dpkg-reconfigure slapd  </pre><p>Select <strong>No</strong> to configure the server</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/971/1*FLn5IkAQesYohW-eB7R30Q.png" /></figure><p>Next, provide: DNS Name Organization Name Administrator Password</p><p>Example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/509/1*rmsQ2VVm-N3IPsZjhZPmlA.jpeg" /></figure><ol><li><strong>Create a Hierarchical Structure</strong></li></ol><p>Start by creating the basic hierarchical structure of the schema below to store information about people. Therefore, create the file struc.ldif to define the structure.</p><pre>nano struc.ldif</pre><p>Add this content:</p><pre>dn: ou=Person,dc=kenza,dc=com<br>objectclass: organizationalUnit<br>ou: Person<br>description: Employies<br><br>dn: ou=Machine,dc=kenza,dc=com<br>objectclass: organizationalUnit<br>ou: Machine<br>description: Computers of the company<br><br>dn: cn=Kenza Kenza,ou=Person,dc=kenza,dc=com<br>objectClass: inetOrgPerson<br>givenName: Kenza<br>sn: Kenza<br>cn: Kenza Kenza<br>uid: mdupond<br>userPassword: mdupond</pre><p><strong>2. Add Entries</strong></p><p>Use ldapadd to add this hierarchical structure to your LDAP server</p><pre>ldapadd -x -D cn=admin,dc=kenza,dc=com -W -f struc.ldif </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/532/1*p6dRPL6K2pf2VWkXwAwxqg.png" /></figure><p><strong>3.</strong> <strong>Search for Entries</strong></p><p>Use the ldapsearch command to search for the entries you have added. For example, to search for all users</p><pre>ldapsearch -x -D cn=admin,dc=kenza,dc=com -W -b ou=Person,dc=kenza,dc=com &quot;objectClass=inetOrgPerson&quot; </pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/855/1*79T6Cbelz_r6WfasaCMtWg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6af9f78d8dda" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Cyber security under Linux: strategies and best practices]]></title>
            <link>https://medium.com/@kenzamarchouk/cyber-security-under-linux-strategies-and-best-practices-6bf43c16e061?source=rss-ea314262d963------2</link>
            <guid isPermaLink="false">https://medium.com/p/6bf43c16e061</guid>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[pluggable-module]]></category>
            <dc:creator><![CDATA[Kenza el marchouk]]></dc:creator>
            <pubDate>Sun, 17 Sep 2023 20:50:41 GMT</pubDate>
            <atom:updated>2023-10-05T15:35:24.169Z</atom:updated>
            <content:encoded><![CDATA[<h3>Command access control</h3><p>The file <strong>/etc/sudoers</strong> controls access to commands. It defines for each user what commandes his allowed to execut and in what computer his autorised.</p><p>Example: Restricting the user “kenza” from using the chage command.</p><p>The /etc/sudoers file is read-only, so to edit it, you must use the visudo command.</p><pre>sudo visudo</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/548/1*Zyj9LIr5BXhY8ZyqyQtlpg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*K0B6Ye6iM0CNLVUTyo6OiQ.png" /></figure><h3>PAM (Pluggable Authentication Modules)</h3><p>PAM is a framework used to manage and customize authentication, authorization methods.</p><p>PAM provides a common API that allows various applications and services to interact with authentication modules consistently. So developers don’t need to build authentication logic into each application separately; instead, they can leverage PAM.</p><p>Each application or service supporting PAM will have its own configuration file in the “/etc/pam.d” directory</p><p>To set up an application for PAM we use a directive with the syntax :</p><pre>mechanism (auth, account, password or session) control (include, optional or required) path-module argument</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QBzgiFbXR9jg5cWFtzkJhg.jpeg" /></figure><p>Let’s walk through a practical example of configuring Pluggable Authentication Modules (PAM) to enforce password policies by configuring password complexity requirements for user accounts. This example will help ensure that users set strong and secure passwords.</p><p><strong>Scenario</strong>: You want to enforce the following password complexity requirements for user accounts on your Linux system:</p><ul><li>Passwords must be at least 8 characters long.</li><li>Passwords must include a combination of letters (both uppercase and lowercase), numbers, and special characters.</li></ul><ol><li>Edit the PAM Configuration File:</li></ol><p>Open the PAM configuration file for password management, typically located at /etc/security/pwquality.conf. If this file doesn&#39;t exist, you can create it:</p><pre>sudo nano /etc/security/pwquality.conf</pre><p>2. Define Password Complexity Rules:</p><p>Add the following lines to the pwquality.conf</p><pre>#sets the minimum password length to 8 characters<br>minlen = 8        <br>#specifies that at least 3 different character classes (letters, digits, special characters) must be used        <br>minclass = 3<br>#It must contain a number               <br>mindigit = 1<br>#It must contain a lower char<br>minlower = 1<br>#It must contain an upper char<br>minupper = 1<br>minspecial = 1<br>#prevents the use of the username as part of the password<br>reject_username = true</pre><p>3. Edit the PAM Configuration File for Password Management:</p><p>Next, edit the PAM configuration file for password management for the desired application</p><pre>sudo nano /etc/pam.d/common-password</pre><p>Then, Add the following line to the PAM configuration file to include the pam_pwquality module, which enforces the password complexity rules defined in pam_pwquality.conf</p><pre>password requisite pam_pwquality.so retry=3</pre><p>4. Test the Configuration:</p><p>To test the new password complexity rules, you can change a user’s password using the passwd command. Try setting a password that meets or violates the complexity requirements to verify that the PAM configuration is working as expected.</p><pre>sudo passwd username</pre><h3>SSH server security</h3><p>The configuration of ssh server is done by changing the file: /etc/ssh/sshd_config.</p><p>After each configuration you should restart the server by the following commande:</p><pre>service sshd restart</pre><ol><li>Fist recommendation is to change the default port from 22 to an other one konwn only by you:</li></ol><pre>#Port 22 change to:<br>Port XXX</pre><p>2. Second recommendation is to use keys private and oublic to access to SSH Server:</p><pre>PasswordAuthentication no<br>RSAAuthentication yes<br>PubkeyAuthentication yes</pre><p>3. Deny root server access:</p><pre>PermitRootLogin no</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6bf43c16e061" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Resetting the Root Password in Kali Linux: A Step-by-Step Guide]]></title>
            <link>https://medium.com/@kenzamarchouk/resetting-the-root-password-in-kali-linux-a-step-by-step-guide-f44061e7ef70?source=rss-ea314262d963------2</link>
            <guid isPermaLink="false">https://medium.com/p/f44061e7ef70</guid>
            <category><![CDATA[linux-tutorial]]></category>
            <category><![CDATA[administration]]></category>
            <dc:creator><![CDATA[Kenza el marchouk]]></dc:creator>
            <pubDate>Thu, 14 Sep 2023 14:24:29 GMT</pubDate>
            <atom:updated>2023-09-14T14:24:29.288Z</atom:updated>
            <content:encoded><![CDATA[<h3>Step 1: Editing GNU/Linux</h3><p>Press <strong>‘e’</strong> to edit GNU/Linux</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/622/1*n4VJBfolfEsJLdufJqJ5wQ.png" /></figure><h3>Step 2: Editing the Line Beginning with ‘linux’</h3><p>Modify the line that starts with ‘linux’ by changing ‘ro’ (read-only) to ‘<strong>rw</strong>’ (read-write), and at the end of the line, append at the end ‘<strong>init=/bin/bash</strong>’.</p><p>Then press clt+X to save your changes.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/1*gKve_pcFkEw1S_iNQw5U-g.png" /></figure><h3>Step 3: Creating a New Password for the Root User</h3><p>Enter the ‘<strong>passwd</strong>’ command to create a new password for the root user</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*mgSeHAHZTm-dPMzdRSk05g.png" /></figure><p>You can now connect to the root user using the new password.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f44061e7ef70" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Maîtrise de l’Administration Système sous Linux]]></title>
            <link>https://medium.com/@kenzamarchouk/ma%C3%AEtrise-de-ladministration-syst%C3%A8me-sous-linux-3aaaace25b49?source=rss-ea314262d963------2</link>
            <guid isPermaLink="false">https://medium.com/p/3aaaace25b49</guid>
            <dc:creator><![CDATA[Kenza el marchouk]]></dc:creator>
            <pubDate>Sat, 09 Sep 2023 11:51:13 GMT</pubDate>
            <atom:updated>2023-10-05T14:52:17.068Z</atom:updated>
            <content:encoded><![CDATA[<p>Compendium des Commandes Cruciales et Fichiers Essentiels dans Linux</p><h3>Commandes Essentielles : Les Bases de l’Administration Linux</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dMdOxoOOoCBHvG7cVO_6qg.jpeg" /></figure><h3>Gestion des Fichiers et Répertoires : Commandes</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zTlohEq5A07Mf_Azqaex4Q.jpeg" /></figure><h3>La gestion des groupes et des utilisateurs</h3><p><strong>/etc/group</strong> : Stocke des informations sur les groupes du système</p><pre>&quot;nom_du_groupe:mot de passe:GID:liste_des_utilisateurs&quot;</pre><p><strong>/etc/gshadow</strong> : stocke des informations sensibles sur les groupes du système</p><pre>&quot;nom_du_groupe:mot de passe:administrateurs_autorisés:autres_membres&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*w0l7vX3hcfV10jQ3D23m9Q.jpeg" /></figure><p><strong>Le fichier /etc/passwd</strong> : Stocke des informations sur les utilisateurs du système</p><pre>&#39;login:mot de passe:UID:GID:nom_complet:repertoire_connexion_shell&#39;</pre><p><strong>/etc/shadow</strong> : stocke des informations liées aux mots de passe des utilisateurs</p><pre>&#39;login:mot de passe chiffré:derniere_modification:nombre_de_jours_avant_changement:mots_de_passe_avant_changement:nombre_de_jours_apres_lequel_changer:mots_de_passe_inactifs:expiration_mots_de_passe&#39;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XrdYhlkmEZYgvahMHroKxA.jpeg" /></figure><p><strong>Le fichier /etc/sudoers</strong> : utilisé pour définir les autorisations d’accès aux commandes en tant que superutilisateur (root) ou à d’autres utilisateurs spécifiques.</p><p>Les journaux d’accès à sudo sont généralement enregistrés , qui dépend de la distribution su système Linux dans <strong>/var/log/auth.log</strong> ou <strong>/var/log/secure</strong></p><h3>Administration de réseaux</h3><p>Le fichier <strong>/etc/hosts</strong> est utilisé pour configurer la correspondance entre les noms d’hôtes et les adresses IP locales.</p><pre>IP nom d&#39;hôte [alias] [#commentaire]</pre><p>Le fichier <strong>/etc/resolv.conf</strong> contient les paramètres de configuration pour la résolution des noms de domaine via le service DNS.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qJAPzx6JSMfL_lfIct1dxA.jpeg" /></figure><p>Le Pare-feu IPTABLES</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/971/1*Xhj3W7ACwQrPB_pH_Ghlvw.jpeg" /></figure><p>Exemple:</p><p>Bloquer l’accès des employés aux sites Web en utilisant le protocole HTTP (non sécurisé) tout en permettant l’accès aux sites utilisant HTTPS (sécurisé)</p><pre># Autoriser le trafic HTTPS (port 443)<br>sudo iptables -A OUTPUT -p tcp --dport 443 -j ACCEPT<br><br># Bloquer le trafic HTTP (port 80)<br>sudo iptables -A OUTPUT -p tcp --dport 80 -j DROP</pre><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3aaaace25b49" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Challenge: Boss Of The SOC v1 — Analyse de logs]]></title>
            <link>https://medium.com/@kenzamarchouk/challenge-boss-of-the-soc-v1-analyse-de-logs-35cd85aef76c?source=rss-ea314262d963------2</link>
            <guid isPermaLink="false">https://medium.com/p/35cd85aef76c</guid>
            <category><![CDATA[cyberdefender]]></category>
            <dc:creator><![CDATA[Kenza el marchouk]]></dc:creator>
            <pubDate>Sun, 27 Aug 2023 22:01:44 GMT</pubDate>
            <atom:updated>2023-08-30T19:27:19.204Z</atom:updated>
            <content:encoded><![CDATA[<h3>Challenge: Boss Of The SOC v1 — Analyse de logs</h3><p><a href="https://cyberdefenders.org/blue-team-labs/plans/?show_alert=True#nav-overview">CyberDefenders: Blue Team Training Platform</a></p><h3><strong>Description du challenge et de son contexte:</strong></h3><p>Nous avons 2 scénarios:</p><ol><li><strong>Scénario 1 APT</strong></li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/996/1*UoQO3eb6fpnDbVPImCLpkw.png" /></figure><p>Wayne Enterprises a été ciblé par un groupe APT nommé “P01s0n1vy”. L’objectif est donc de mener une investigation pour comprendre comment cette attaque s’est produite.</p><p><strong>2. Scénario 2 Ransomware</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1016/1*VdCD7nd2JABPipk6-Bsy-A.png" /></figure><p>Une machine appartenant à un employé de l’entreprise Wayne Enterprises est infectée par le ransomware Cerber. L’objectif est donc d’enquêter sur ce type de ransomware.</p><p><strong>Q1 Il s’agit d’une question simple qui vous permettra de vous familiariser avec les réponses à soumettre. Quel est le nom de la société qui fabrique le logiciel que vous utilisez pour ce concours ? Un simple mot de six lettres sans ponctuation.</strong></p><blockquote>La réponse est <strong>Splunk</strong></blockquote><p><strong>Q2 Quelle est l’adresse IP probable d’un membre du groupe Po1s0n1vy analysant le site imreallynotbatman.com à la recherche de vulnérabilités dans les applications web ?</strong></p><p>Pour répondre à cette question, nous effectuons une requête spécifique afin de rechercher des événements liés à l’index “botsv1”, qui correspond au nom de la machine virtuelle infectée par cet APT, ainsi qu’au protocole HTTP en streaming associé au domaine “imreallynotbatman.com”:</p><pre>index=&quot;botsv1&quot; sourcetype=&quot;stream:http&quot; imreallynotbatman.com</pre><p>Cela permet de détecter des connexions ou des communications faites vers ce domaine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*NMX_TvzvMtbhba4rR8Ix0w.png" /></figure><p>Nous avons donc identifié plusieurs requêtes effectuées à partir de l’adresse IP 40.80.148.42. Cela constitue une preuve qu’il pourrait s’agir de l’adresse IP d’un attaquant, étayée par le type de requêtes malveillantes qu’il a effectuées. Par exemple, dans l’image ci-dessus, nous pouvons observer une tentative d’exploitation de vulnérabilités de navigation ascendante dans les chemins de fichiers afin d’accéder à des répertoires parent. De plus, il utilise le logiciel de scanner de vulnérabilité Acunetix.</p><blockquote>Donc IP probable de l’attaquant est <strong>40.80.148.42</strong></blockquote><p><strong>Q3 Quelle société a créé le scanner de vulnérabilité web utilisé par Po1s0n1vy ? Saisissez le nom de la société. (Par exemple, “Microsoft” ou “Oracle”)</strong></p><blockquote>On a trouvé dans la question 1 que l’attaquant utilise le scanner de vulnérabilité web <strong>acunetix</strong></blockquote><p><strong>Q4 Quel est le système de gestion de contenu utilisé par imreallynotbatman.com ? (Veuillez ne pas inclure les signes de ponctuation tels que . , ! ? dans votre réponse. Nous recherchons uniquement des caractères alpha).</strong></p><p>Un système de gestion de contenu (CMS) est une plateforme logicielle utilisée pour créer, gérer et organiser le contenu d’un site web. Certains CMS populaires incluent WordPress, Joomla, Drupal, Magento, etc</p><p>Pour trouver le gestionnaire du web qui héberge imreallynotbatman.com, on utilise les fonctionnalités de recherche de Splunk pour filtrer les événements liés aux URI de ce domaine</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/901/1*NxMo5n6WUif1U3aLIheH7w.png" /></figure><blockquote>Donc le CMS utilisé est <strong>joomla</strong></blockquote><p><strong>Q5 Quel est le nom du fichier qui a défiguré le site imreallynotbatman.com ? Veuillez soumettre uniquement le nom du fichier avec son extension (par exemple, “notepad.exe” ou “favicon.ico”).</strong></p><p>Pour répondre à cette question on enquête sur les logs des requêtes HTTP effectuées par l’attaquant vers la machine cible on se focalise donc sur le champ c_ip qui fait référence à l’adresse IP client qui représente l’adresse IP source d’une connexion réseau ou d’une demande effectuée par un client On constate qu’on a 2 IP source et 2 IP destinataire, ce qui peut veut dire que le serveur cible a téléchargé le fichier malveillant dans un autre serveur distant très probablement celui ayant l’adresse IP privée 192.168.250.70</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/915/1*Q1We2T1XkrfdG-hhwPgpUw.png" /></figure><p>On effectue donc cette requête qui vise à trouver toutes les URLs visitées par l’adresse IP “192.168.250.70” dans les journaux:</p><pre>index=botsv1 c_ip=&quot;192.168.250.70&quot; | stats count by url</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/925/1*jKnjA6G2Um7k1UyKGliIlA.png" /></figure><blockquote>Donc le fichier qui a défiguré le site imreallynotbatman.com est <strong>poisonivy-is-coming-for-you-batman.jpeg</strong></blockquote><p><strong>Q6 Cette attaque a utilisé le DNS dynamique pour résoudre l’IP malveillante. Quel est le nom de domaine pleinement qualifié (FQDN) associé à cette attaque ?</strong></p><p>D’après la question 5, on a trouvé cet url <a href="http://prankglassinebracket.jumpingcrab.com:1337:1337/poisonivy-is-coming-for-you">http://prankglassinebracket.jumpingcrab.com:1337:1337/poisonivy-is-coming-for-you</a> -batman.jpeg</p><blockquote>Donc le FQDN est <strong>prankglassinebracket.jumpingcrab.com</strong></blockquote><p><strong>Q7 Quelle est l’adresse IP que Po1s0n1vy a liée à des domaines préparés pour attaquer Wayne Enterprises ?</strong></p><blockquote>D’après la question 5, nous avons identifié deux adresses IP sources. L’une d’entre elles correspond à l’adresse IP de l’attaquant, et l’autre, <strong>23.22.63.114</strong>, est l’adresse IP que Po1s0n1vy a liée à des domaines préparés pour attaquer Wayne Enterprises</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/921/1*YfSKT5VkOUIC_Ae8xoCUVw.png" /></figure><p>Afin de confirmer cela, nous avons utilisé Virustotal, qui a également prouvé que 23.22.63.114 est associée à des domaines préparés pour attaquer Wayne Enterprises, puisque on trouve le domaine qu’on a identifié dans la question 6.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/809/1*faPtKS0ESDo1UTWsnmke1A.png" /></figure><p><strong>Q8 Sur la base des données recueillies lors de cette attaque et common open-source intelligence sources pour les noms de domaine, quelle est l’adresse électronique la plus vraisemblablement associée au groupe APT Po1s0n1vy ?</strong></p><p>D’après les questions précédentes, nous avons trouvé l’un des domaines associés au groupe APT Po1s0n1vy : waynecorinc.com Pour trouver l’adresse électronique associée au groupe Po1s0n1vy, on utilise ou l’outil <a href="https://www.whoxy.com/whois-history/demo.php">whois History lookup</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/361/1*EOgRW8hI6GV1L4YFsa8R0A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/678/1*AatDEfvJLmNXM0KJQ9GNlQ.png" /></figure><blockquote>Donc l’adresse électronique la plus vraisemblablement associée au groupe APT Po1s0n1vy est <strong>lillian.rose@po1s0n1vy.com</strong></blockquote><p><strong>Q9 Quelle adresse IP est susceptible de tenter une attaque par force brute contre imreallynotbatman.com ?</strong></p><p>Pour répondre à cette question, nous recherchons les logs des adresses IP ayant effectué une requête HTTP POST sur le formulaire du site:</p><pre>index=&quot;botsv1&quot; imreallynotbatman.com sourcetype=&quot;stream:http&quot; http_method=POST | stats count by src_ip, form_data</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/905/1*0JfXIBVw3Noh15VA8r9LrQ.png" /></figure><blockquote>Donc IP qui tente l’attaque brute force contre le site de l’entreprise est <strong>23.22.63.114</strong></blockquote><p><strong>Q10 Quel est le nom de l’exécutable téléchargé par Po1s0n1vy ? Veuillez inclure l’extension du fichier. (Par exemple, “notepad.exe” ou “favicon.ico”)</strong></p><p>Pour répondre à cette question, nous recherchons les logs des requêtes POST HTTP contenant des fichiers .exe</p><pre>index=&quot;botsv1&quot; sourcetype=&quot;stream:http&quot; imreallynotbatman.com dest_ip=&quot;192.168.250.70&quot; http_method=POST .exe</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/903/1*n_yakmgNRp-jM_zyd1gJBQ.png" /></figure><blockquote>Le seul fichier .exe qu’on a trouvé est <strong>3791.exe</strong></blockquote><p><strong>Q11 Quel est le hachage MD5 de l’exécutable téléchargé ?</strong></p><p>Pour déterminer le sourcetype qui nous permettrait de récupérer le hash MD5 du fichier 3791.exe, nous effectuons la requête suivante :</p><pre>index=&quot;botsv1&quot; 3791.exe md5</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/913/1*I4izCeFprQkkreoc-vcpsQ.png" /></figure><p>Nous avons identifié un seul sourcetype : XmlWinEventLog:Microsoft-Windows-Sysmon/Operational. Dans le champ CommandLine, nous constatons que le fichier 3791.exe a été exécuté en ligne de commande. Nous filtrons donc sur ce champ avec la requête suivante:</p><pre>index=&quot;botsv1&quot; sourcetype=&quot;XmlWinEventLog:Microsoft-Windows-Sysmon/Operational&quot; CommandLine=&quot;3791.exe&quot; | stats values(MD5) as MD5</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/925/1*2wyl4_yHN5PyfO4zJC2lvQ.png" /></figure><blockquote>On obtient donc MD5 du fichier 3791.exe: <strong>AAE3F5A29935E6ABCC2C2754D12A9AF0</strong></blockquote><p><strong>Q12 Le GCPD a indiqué que la TTP (Tactiques, Techniques, Procédures) courante du groupe APT Po1s0n1vy, en cas d’échec de la compromission initiale, consiste à envoyer un courriel de spear-phishing contenant un logiciel malveillant personnalisé en pièce jointe à la cible visée. Ce logiciel malveillant est généralement connecté à l’infrastructure d’attaque initiale de Po1s0n1vy. En utilisant des techniques de recherche, fournissez le hachage SHA256 de ce logiciel malveillant.</strong></p><p>On a identifié dans la question 7, IP 23.22.63.114 lié au groupe APT Po1s0n1vy, on cherche dans Virustotal sur cet IP, on trouve qu’il fait référence au fichier exécutable MirandaTateScreensaver.scr.exe qui est probablement le malware envoyé en pièce jointe à la cible.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/898/1*IlAX_C5U60ddCbXqJFnssQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/783/1*ikrrE71TUIgER8G_jmZn6w.png" /></figure><blockquote>Donc le hash 256 est ce malware est <strong>9709473ab351387aab9e816eff3910b9f28a7a70202e250ed46dba8f820f34a8</strong></blockquote><p><strong>Q13 Quel est le code hexadécimal spécial associé au logiciel malveillant personnalisé évoqué à la question 12 ? (Indice : il n’est pas dans Splunk)</strong></p><blockquote>Dans VirusTotal, plus précisément dans la section Community, nous pouvons trouver le code hexadécimal associé au malware identifié dans la question 12: <strong>53 74 65 76 65 20 42 72 61 6e 74 27 73 20 42 65 61 72 64 20 69 73 20 61 20 70 6f 77 65 72 66 75 6c 20 74 68 69 6e 67 2e 20 46 69 6e 64 20 74 68 69 73 20 6d 65 73 73 61 67 65 20 61 6e 64 20 61 73 6b 20 68 69 6d 20 74 6f 20 62 75 79 20 79 6f 75 20 61 20 62 65 65 72 21 21 21</strong></blockquote><p>Ce code est fréquemment utilisé par les logiciels antimalware pour détecter les logiciels malveillants. Cependant, les logiciels malveillants deviennent de plus en plus sophistiqués et utilisent des techniques d’évasion pour éviter la détection par les logiciels antimalware basés uniquement sur les signatures.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*WdnMkDeeiSqPKm9aU87LUQ.png" /></figure><p><strong>Q14 L’un des domaines mis en scène par Po1s0n1vy présente des informations whois “uniques” et incohérentes. Concaténer les deux codes ensemble et les soumettre comme une seul</strong></p><p>D’après la réponse que nous avons obtenue dans la question 8, nous constatons des données incohérentes dans les champs company_name et mailing_address</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/669/1*NevKeUahmqrgeP6eIt8o1A.png" /></figure><p><strong>Q15 Quel a été le premier mot de passe utilisé par force brute ?</strong></p><p>D’après la question 9, nous avons découvert que le site de l’entreprise est victime d’une attaque brute force de la part de l’attaquant. Pour identifier le premier mot de passe utilisé dans cette attaque, nous trions les données en fonction du temps (timestamp). Tout d’abord, nous récupérons les champs username et passwd, que nous renommons respectivement en user et pwd. Ensuite, nous les trions en fonction du temps. Voici la requête correspondante :</p><pre>index=&quot;botsv1&quot; imreallynotbatman.com sourcetype=&quot;stream:http&quot; http_method=POST form_data=*username*passwd* | rex field=form_data &quot;passwd=(?\w+)&quot; | rex field=form_data &quot;username=(?\w+)&quot; | table user, pwd, timestamp | sort by timestamp</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/847/1*FNbbH9vuzaDzYoJu28QlGQ.png" /></figure><blockquote>Donc le première mot de passe utilisé dans l’attaque brute force est <strong>12345678</strong></blockquote><p><strong>Q16 L’un des mots de passe de l’attaque par force brute est la chanson préférée de Coldplay de James Brodsky. Indice : nous recherchons un mot de six caractères. De quel mot s’agit-il ?</strong></p><p>Après avoir effectué une recherche sur les chansons de Coldplay par James Brodsky dans <a href="https://en.wikipedia.org/wiki/List_of_songs_recorded_by_Coldplay">wikipedia</a>. nous extrayons les titres des chansons qui ont une longueur de caractères de 6 avec cette requête</p><pre>curl -s &quot;https://en.wikipedia.org/wiki/List_of_songs_recorded_by_Coldplay&quot; | grep &quot;&quot; | sed &#39;s///&#39; | sed -E &#39;s/]*&gt;//g&#39; |awk &#39;length($0)==8&#39;</pre><p>(On a met 8 car les deux apostrophes “ “sont inclus dans le calcule de longueurs de chanson)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*tKtQwOsm_fk3DJ7ABfisbw.png" /></figure><p>Nous recherchons donc les mots de passe ayant une longueur de 6 caractères et correspondant à l’un des titres des chansons récupérées:</p><pre>index=&quot;botsv1&quot; sourcetype=&quot;stream:http&quot; http_method=&quot;POST&quot; form_data=*username*passwd* | rex field=form_data &quot;passwd=(?\w+)&quot; | eval Lenpwd=len(pwd) | search Lenpwd=6 (pwd=&quot;Aliens&quot; OR pwd=&quot;Broken&quot; OR pwd=&quot;Church&quot; OR pwd=&quot;Clocks&quot; OR pwd=&quot;Murder&quot; OR pwd= &quot;Oceans&quot; OR pwd=&quot;Shiver&quot; OR pwd=&quot;Sparks&quot; OR pwd=&quot;School&quot; OR pwd=&quot;Yellow&quot; OR pwd=&quot;U.F.O.&quot; OR pwd=&quot;So Sad&quot; OR pwd=&quot;A Wave&quot;) | stats count by pwd | table pwd</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*NHumtJoGpVoGKcQCk75bOQ.png" /></figure><blockquote>La réponse est <strong>yellow</strong></blockquote><p><strong>Q17 Quel était le mot de passe correct pour l’accès administrateur au système de gestion de contenu de “imreallynotbatman.com” ?</strong></p><p>Pour identifier le bon mot de passe d’accès au compte admin dans l’attaque brute force, nous utilisons la même requête que celle de la question 15, mais nous ajoutons la condition count&gt;1 pour identifier les mots de passe qui ont été fréquemment saisis et qui pourraient être le mot de passe correct pour l’accès administrateur au système de gestion de contenu de “imreallynotbatman.com”:</p><pre>index=&quot;botsv1&quot; imreallynotbatman.com sourcetype=&quot;stream:http&quot; http_method=POST form_data=*username*passwd* | rex field=form_data &quot;passwd=(?\w+)&quot; | rex field=form_data &quot;username=(?\w+)&quot; | stats count by pwd | where count&gt;1</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/1*0WPWUdU2-bGdvp7L2Mi-uQ.png" /></figure><blockquote>Donc le bon mot de passe est <strong>batman</strong></blockquote><p><strong>Q18 Quelle était la longueur moyenne du mot de passe utilisé lors de la tentative de brute forcel du mot de passe ? (Arrondir à l’entier le plus proche, par exemple “5” et non “5.23213”)</strong></p><p>Pour calculer la longueur moyenne du mot de passe lors d’une attaque brute force, nous utilisons la fonction len pour calculer la longueur du mot de passe, et la fonction avg pour calculer sa moyenne. Voici la requête correspondante:</p><pre>index=&quot;botsv1&quot; imreallynotbatman.com sourcetype=&quot;stream:http&quot; http_method=POST form_data=*username*passwd* | rex field=form_data &quot;passwd=(?\w+)&quot; | eval lpwd=len(pwd) | stats avg(lpwd) as average</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1009/1*yJvylZrHZ3ujvhMFcmH2ug.png" /></figure><blockquote>Donc en moyenne les tentation du mot de passe dans l’attaque brute force est <strong>6</strong></blockquote><p><strong>Q19 Combien de secondes se sont écoulées entre le moment où la recherche de mot de passe par force brute a identifié le mot de passe correct et le moment où la connexion a été compromise ? Arrondissez à la deuxième décimale.</strong></p><p>D’après la question 17, nous avons identifié le bon mot de passe qui est “batman”. Pour obtenir la durée exacte en secondes entre les deux événements: l’identification réussie du mot de passe lors de la recherche par force brute et le moment où la connexion a été compromise, nous utilisons la fonction “transaction” pour regrouper les événements liés à chaque tentative de recherche de mot de passe par force brute, et la fonction “duration” pour calculer la durée entre le début et la fin d’une transaction:</p><pre>index=&quot;botsv1&quot; imreallynotbatman.com sourcetype=&quot;stream:http&quot; http_method=POST form_data=*username*passwd* | rex field=form_data &quot;passwd=(?\w+)&quot; | search pwd=batman | transaction pwd | eval d = round(duration,2) |table d</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/807/1*ko1NccKMeMyEktv3pMSNNg.png" /></figure><blockquote>Donc la durée est <strong>92.17</strong> (92 seconds = ‘1min et 32 sec’)</blockquote><p><strong>Q20 Combien de mots de passe uniques ont été tentés lors de la tentative de force brute ?</strong></p><p>Afin de répondre à cette question on utilise la fonction dedup abréviation de “deduplicate” permet de trouver des résultats uniques en éliminant les doublons.</p><pre>index=&quot;botsv1&quot; imreallynotbatman.com sourcetype=&quot;stream:http&quot; http_method=POST form_data=*username*passwd* | rex field=form_data &quot;passwd=(?\w+)&quot; | dedup pwd | stats count</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/1*ox4Orc9yYVx3zVWReS2AcA.png" /></figure><blockquote>Donc nombre de mots de passe uniques ont été tentés lors de la tentative de force brute est <strong>412</strong></blockquote><p><strong>Q21 Quelle était l’adresse IP la plus probable de we8105desk en 24AUG2016 ?</strong></p><p>Nous filtrons le résultat de la requête ci-dessous, qui nous donne l’IP probable de la machine selon la période allant du 24/08/2016 jusqu’à maintenant:</p><pre>index=&quot;botsv1&quot; we8105desk | stats count by src_ip</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/961/1*9htKh-cJECDq1Tx8w1ONsg.png" /></figure><blockquote>Donc IP probable de la machine we8105desk est <strong>192.168.250.100</strong></blockquote><p><strong>Q22 Parmi les signatures Suricata qui ont détecté le programme malveillant Cerber, laquelle a donné l’alerte le moins de fois ?</strong></p><blockquote>Soumettez UNIQUEMENT la valeur de l’ID de la signature comme réponse. (Pas de ponctuation, seulement 7 nombres entiers). Suricata est un système IDS et IPS open source, basé sur des règles et des signatures pour détecter les schémas de comportement suspects. En effectuant une recherche dans le champ “alert.signatures_id” qui correspond à l’ID des signatures Suricata pour les alertes de ransomware Cerber, nous avons identifié l’ID de signature Suricata qui a généré le moins d’alertes par rapport aux autres, et cet ID est <strong>2816763</strong>.</blockquote><pre>index=&quot;botsv1&quot; sourcetype=&quot;suricata&quot; Cerber</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/991/1*jUsZxXgkcm2tL4x2lalydQ.png" /></figure><p><strong>Q23 Vers quel nom de domaine pleinement qualifié (FQDN) le ransomware Cerber tente-t-il de diriger l’utilisateur à la fin de sa phase de chiffrement ?</strong></p><p>D’après la question 21, nous avons identifié l’adresse IP 192.168.250.100 de la machine victime du ransomware Cerber.</p><p>Nous effectuons donc la requête ci-dessous pour obtenir le nombre de requêtes DNS uniques associées à l’adresse IP source de la machine victime, en excluant de la requête les domaines connus, tels que microsoft.com, windows.com, skype.com, bing.com, etc.</p><pre>index=&quot;botsv1&quot; src_ip=&quot;192.168.250.100&quot; sourcetype=&quot;stream:dns&quot; query=*.* | search NOT (query=*.arpa OR query=*.local OR query=*microsoft.com OR query=&quot;isatap&quot; OR query=&quot;*msftncsi.com&quot; OR query=&quot;*s4-baas.acronis.com&quot; OR query=*windows.com OR query=*bing.com OR query=*skype.com OR query=*virtualearth.net OR query=*microsoftonline.com OR query=*windowsupdate.com OR query=*king.com OR query=&quot;*acronis.com&quot; OR query=&quot;*msn.com&quot; OR query=&quot;*windowsupdate.com&quot; OR query=&quot;*akamaized.net&quot; OR query=&quot;*cdn.com&quot; OR query=&quot;*microsoftonline.com&quot; OR query=&quot;*live.com&quot; OR query=&quot;*hybrid.api.here.com&quot; OR query=&quot;*virtualearth.net&quot; OR query=&quot;*time.windows.com&quot; OR query=&quot;*twimg.com&quot; OR query=&quot;*messaging.office.com&quot; ) | stats count by query</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1003/1*UXppOM5uxR0I7QT0p6ZOUA.png" /></figure><blockquote>Donc le FQDN est <strong>cerberhhyed5frqa.xmfir0.win</strong></blockquote><p><strong>Q24 Quel a été le premier domaine suspect visité par we8105desk en 24AUG2016 ?</strong></p><p>Pour répondre à cette question, nous utilisons la même requête que celle de la question 23, mais cette fois nous trions les données par date, de la plus ancienne à la plus récente. Cela nous permettra d’identifier le premier domaine suspect visité par we8105desk le 24 août 2016.</p><pre>index=&quot;botsv1&quot; src_ip=&quot;192.168.250.100&quot; sourcetype=&quot;stream:dns&quot; query=*.* | search NOT (query=*.arpa OR query=*.local OR query=*microsoft.com OR query=&quot;isatap&quot; OR query=&quot;*msftncsi.com&quot; OR query=&quot;*s4-baas.acronis.com&quot; OR query=*windows.com OR query=*bing.com OR query=*skype.com OR query=*virtualearth.net OR query=*microsoftonline.com OR query=*windowsupdate.com OR query=*king.com OR query=&quot;*acronis.com&quot; OR query=&quot;*msn.com&quot; OR query=&quot;*windowsupdate.com&quot; OR query=&quot;*akamaized.net&quot; OR query=&quot;*cdn.com&quot; OR query=&quot;*microsoftonline.com&quot; OR query=&quot;*live.com&quot; OR query=&quot;*hybrid.api.here.com&quot; OR query=&quot;*virtualearth.net&quot; OR query=&quot;*time.windows.com&quot; OR query=&quot;*twimg.com&quot; OR query=&quot;*messaging.office.com&quot; ) | table _time, query | sort by _time</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1013/1*44WH9-L5KPYlM7oUO1nJ9A.png" /></figure><blockquote>Donc premier suspect domaine visité par la victime est <strong>solidaritedeproximite.org</strong></blockquote><p><strong>Q25 Lors de l’infection initiale par Cerber, un script VB est exécuté. Le script complet de cette exécution, précédé du nom du fichier .exe lancé, peut être trouvé dans un champ de Splunk. Quelle est la longueur en caractères de la valeur de ce champ ?</strong></p><p>Pour répondre à cette question, nous utilisons le sourcetype le plus fréquent concernant les logs des scripts VBS: XmlWinEventLog:Microsoft-Windows-Sysmon/Operational</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/689/1*SIcaYrf46KjWqutShNeiHA.png" /></figure><p>Finalement, pour récupérer la longueur du script VBS exécuté dans la machine cible lors de l’infection initiale, nous exécutons cette requête:</p><pre>index=&quot;botsv1&quot; we8105desk .vbs sourcetype=&quot;XmlWinEventLog:Microsoft-Windows-Sysmon/Operational&quot; dest=&quot;we8105desk.waynecorpinc.local&quot; | eval Lcmd=len(CommandLine) | table CommandLine, Lcmd</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/998/1*3U_iQcqerOVdXKS7tdiWQw.png" /></figure><blockquote>Donc la longueur est <strong>4490</strong></blockquote><p><strong>Q26 Quel est le nom de la clé USB insérée par Bob Smith ?</strong></p><p>Après avoir recherché dans <a href="https://learn.microsoft.com/en-us/windows-hardware/drivers/usbcon/usb-device-specific-registry-settings">la documentation microsoft</a>, nous pouvons trouver les entrées de registre des périphériques USB, telles que le nom de la clé USB identifiée par le champ FriendlyName, en utilisant l’éditeur de registre correspondant au sourcetype winregistry</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/787/1*V2MW9u2cS_TR7wVvOEj_Lw.png" /></figure><blockquote>Donc la valeur du registre est <strong>MIRANDA_PRI</strong></blockquote><pre>index=botsv1 sourcetype=winregistry friendlyname</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1022/1*PA4xWt5CQlZcnfatJjtVww.png" /></figure><p><strong>Q27 Le poste de travail de Bob Smith (we8105desk) était connecté à un serveur de fichiers lors de l’épidémie de ransomware. Quelle est l’adresse IP du serveur de fichiers ?</strong></p><p>La sourcetype qui nous permet d’obtenir les logs de connexion Bob Smith au serveur de fichier est stream:smb</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1004/1*Ld7fXsV0a9P5oyahdlmsSw.png" /></figure><p>On filtre donc notre requête de recherche selon ce type de source. Ensuite on se focalise sur le champs path afin d’identifier le chemin d’accès des fichiers partagés via le protocole SMB (Server Message Block) en excitant cette requête:</p><pre>index=botsv1 src_ip=192.168.250.100 sourcetype=&quot;stream:smb&quot; fileshare | stats count by path</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1011/1*4K21Vv4KGziD0rVr4Ownuw.png" /></figure><blockquote>Donc IP du serveur de fichiers auquel la machine victime de Bob Smith était connecté est <strong>192.168.250.20</strong></blockquote><p><strong>Q28 Combien de PDF distincts le ransomware a-t-il cryptés sur le serveur de fichiers distant ?</strong></p><p>Pour répondre à cette question, on utilise le sourcetype “wineventlog” car il contient les logs les plus fréquents relatifs aux fichiers PDF</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*4u817Ma3iwld_7YWtn4Vkw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/846/1*giHmno8xUFOsG1CBnu5SZg.png" /></figure><p>Pour compter le nombre de fichiers PDF, nous nous appuyons sur le champ “target name”. Nous savons que l’adresse IP de la machine victime de Bob Smith est 192.168.250.100. Nous nous concentrons sur le nom de l’ordinateur “we9041srv.waynecorpinc.local”, qui est le serveur de destination. Afin d’éviter le double comptage des fichiers PDF, nous utilisons la fonction “dc” (“distinct count”) qui permet de calculer le nombre de valeurs distinctes des fichiers PDF. Voici la requête correspondante:</p><pre>index=botsv1 *.pdf sourcetype=wineventlog dest=&quot;we9041srv.waynecorpinc.local&quot; Source_Address=&quot;192.168.250.100&quot; | stats dc(Relative_Target_Name)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/999/1*2gm9OuPUSrmxQWnX_ogtwA.png" /></figure><blockquote>Donc le nombre du PDF distincts crypté par ransomware est <strong>257</strong></blockquote><p><strong>Q29 le VBScript trouvé à la question 25 lance 121214.tmp. Quel est le ParentProcessId de ce lancement initial ?</strong></p><blockquote>Pour connaître le script wscript lancé par 121214.tmp on utilise cette requête: index=botsv1 121214.tmp wscript On trouve donc le champ parent-process-id qui identifie id le processus parent: <strong>3968</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/980/1*rOcM6nD63NnjSa3hIjJPHA.png" /></figure><p><strong>30 Le ransomware Cerber crypte les fichiers situés dans le profil Windows de Bob Smith. Combien de fichiers .txt est-il en train de crypter ?</strong></p><p>Pour répondre à cette question, nous filtrons les résultats en utilisant le sourcetype “XmlWinEventLog:Microsoft-Windows-Sysmon/Operational”, car il permet d’identifier un plus grand nombre de logs sur les fichiers .txt</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/953/1*WNAnxG40Lfi5pb8XFdtbnw.png" /></figure><p>Ensuite, on se focalise sur le champs TargetFilename pour identifier les fichier txt ciblé, on remarque que tous ces fichiers ont un path commun qui commence par: C:\Users\bob.smith.WAYNECORPINC\Desktop\…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*FMgeQqK7_Cq2d5VPyAeFsA.png" /></figure><p>Finalement, nous effectuons la requête ci-dessous pour obtenir le nombre distinct des fichiers .txt que le ransomware est en train de chiffrer :</p><pre>index=botsv1 host=we8105desk sourcetype=&quot;XmlWinEventLog:Microsoft-Windows-Sysmon/Operational&quot; TargetFilename=&quot;C:\\Users\\bob.smith.WAYNECORPINC\\*.txt&quot; | stats dc(TargetFilename)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*KYoog8yU5A3L8HgUQsa9QA.png" /></figure><blockquote>Donc le nombre de fichiers txt chiffrés est <strong>406</strong></blockquote><p><strong>Q31 Le logiciel malveillant télécharge un fichier contenant le code cryptographique du ransomware Cerber. Quel est le nom de ce fichier ?</strong></p><p>D’après la question 24, nous avons identifié le domaine suspect solidaritedeproximite.org que la machine victime a visité. Ainsi, en filtrant la requête sur ce domaine et en nous focalisant sur le champ http.url , nous pouvons trouver le nom du fichier. Voici la requête correspondante :</p><pre>index=botsv1 sourcetype=suricata src=192.168.250.100 solidaritedeproximite.org | stats count values(http.url) by dest</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_qEcbR3cv_MhDInkaDxBjQ.png" /></figure><blockquote>Donc le fichier malveillant contenant le code cryptographique du ransomware Cerber est <strong>mhtr.jpg</strong></blockquote><p><strong>Q32 Maintenant que vous connaissez le nom du fichier crypté du ransomware, quelle technique d’obscurcissement utilise-t-il probablement ?</strong></p><p>Le ransomware utilise probablement la technique de <strong>la stéganographie</strong> pour se cacher dans un fichier JPG et éviter d’être détecté par les logiciels anti-malwares. La stéganographie est une méthode d’obscurcissement où les données malveillantes sont dissimulées à l’intérieur d’un fichier apparemment innocent, comme une image ou un document. Dans ce cas, le ransomware utilise un fichier JPG comme support pour cacher son code cryptographique. Cette technique lui permet de passer inaperçu et de contourner les mécanismes de détection traditionnels, car en surface, le fichier semble être une simple image, alors qu’il contient en réalité des informations malveillantes.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=35cd85aef76c" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>