<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mustafa on Medium]]></title>
        <description><![CDATA[Stories by Mustafa on Medium]]></description>
        <link>https://medium.com/@5yx?source=rss-caaeb48339c0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*PaZNDTrm6Bm2QZi3.png</url>
            <title>Stories by Mustafa on Medium</title>
            <link>https://medium.com/@5yx?source=rss-caaeb48339c0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 05 Dec 2026 01:06:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@5yx/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[x86-64 GetPC: SYSCALL]]></title>
            <link>https://medium.com/@5yx/x86-64-getpc-syscall-02f7a3100a27?source=rss-caaeb48339c0------2</link>
            <guid isPermaLink="false">https://medium.com/p/02f7a3100a27</guid>
            <category><![CDATA[x64]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[shellcode]]></category>
            <category><![CDATA[x86-64]]></category>
            <dc:creator><![CDATA[Mustafa]]></dc:creator>
            <pubDate>Thu, 17 Jul 2025 01:37:25 GMT</pubDate>
            <atom:updated>2025-07-21T22:41:40.718Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*D6qxOJLUmrgAPbms" /><figcaption>Photo by <a href="https://unsplash.com/@alicia2joy?utm_source=medium&amp;utm_medium=referral">Alicia Quan</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Usually, the first thing you do when running position-independent code (PIC) is find where your execution started. After messy exploitation and with ASLR in play, you need a reliable anchor point to locate the rest of your payload (like your data) so you can begin decoding, extracting, or comparing values.</p><h3>CALL/POP (6–10 bytes)</h3><p>The first and most well-known method is the classic CALL/POP technique. It uses a CALL instruction to push the return address (i.e., the current RIP) onto the stack, and then a POP retrieves it. This simple trick was the crown jewel of early shellcodes and remained a staple technique for a long time.</p><pre>  call get_rip<br>get_rip:<br>  pop rcx</pre><p>The moment execution reaches the POP RCX, it retrieves the return address -effectively pointing to the current location in memory. From there, you can calculate offsets to access other parts of your shellcode.</p><p>However, this method faced a major issue: the CALL instruction uses a relative 4-byte offset, which can introduce null bytes -something shellcode often can&#39;t tolerate.</p><p>To overcome this, you can use a JMP trampoline, like the following:</p><pre>  jmp label_forwards<br>label_backwards:<br>  jmp label_get_rip<br>label_forwards:<br>  call label_backwards<br>label_get_rip:<br>  pop rcx</pre><p>Now the JMP goes backwards, so the null bytes are avoided, the offset appears as negative, like 0xFFFFFFFF and decreasing.</p><h3>FPU/FNSTENV (7 bytes)</h3><p>Enter the Floating Point Unit (FPU) instructions , originally meant for floating-point calculations , but they also offered a way to retrieve EIP/RIP.</p><p>This technique involved executing one of about 100 FPU-related instructions, which would populate a 28-byte structure called the FPU data pointer. This structure includes various fields related to FPU execution, and one of them holds the address of the last executed FPU instruction.</p><p>The Shikata-ga-nai encoder used this method to ensure a more randomized stub. With many possible FPU instructions to choose from -and the ability to insert garbage instructions in between- it becomes harder for detection engines to recognize such shellcode.</p><p>Nick Hoffman, Jeremy Humble, and Toby Taylor wrote <a href="https://archive.ph/xYnwx">an excellent blog post</a> back in the day detailing the use of FPU instructions in Shikata-ga-nai, including methods for detection and suggestions for improvement.</p><p>In x64, fxsave64 is used to obtain such state.</p><h3>LEA (7–11 bytes)</h3><p>Accessing EIP/RIP directly isn’t allowed in the x86 instruction set, you can&#39;t MOV or perform arithmetic using EIP/RIP. If you could, we wouldn&#39;t even be talking about these workarounds. The only way to control RIP is through instructions like CALL and RET, which rely on known or relative addresses, something you typically don’t have access to <em>after</em> an instruction executes.</p><p>In x86–64, however, one instruction <em>does</em> have the privilege of working with RIP: the LEA instruction.</p><p>LEA works similarly to MOV, but instead of moving data, it calculates the address of the source operand and stores it in the destination, like this:</p><pre>; rbx = 0x05<br>  mov rax, [rbx + 0x01]  ; Load value in address 0x06 into rax<br>  lea rax, [rbx + 0x01]  ; Copy the address 0x06 itself into rax (no memory access)</pre><p>With MOV, RAX ends up containing the value stored at address 0x06, in other words, it dereferences the address. In contrast: LEA simply assigns the value 0x06 to RAX without dereferencing it.</p><p>This also works with RIP, where you can load its effective address into another register using an instruction like:</p><pre>lea rcx, [rip]</pre><p>This copies the value of RIP + 0x00 into RCX.</p><p>To avoid null bytes, you can also use LEA RCX, [RIP - 0x01] and then increment the value afterward as needed.</p><h3>Syscall</h3><p>Enter a new method: SYSCALL! the mechanism that transfers execution from user mode to kernel mode. The kernel exposes a set of system services, and a table (like KiServiceTable in Windows or sys_call_table in Linux) uses the index provided in EAX to locate the requested service.</p><p>When SYSCALL is executed, the CPU switches context from user mode to kernel mode, updates RFLAGS accordingly, and begins executing the target kernel service. Once the service completes, SYSRET is called, restoring the user-mode stack and the original caller&#39;s RIP, with the return value placed in RAX.</p><p>You can see the start of this process in action when ntdll prepares a call to NtTerminateProcess:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*K7w2_oTym_3ZCiOvj8KfQw.png" /><figcaption>ntdll preparing a call to NtTerminateProcess (0x002c in the current windows version)</figcaption></figure><p>Note that during the transition, RCX is stored into R10 because RCX changes.</p><p>What happens is the CPU uses RCX to store the caller’s RIP address (similar to how RIP is pushed onto the stack during a normal CALL). It also stores the user stack pointer in R8 and the RFLAGS register in R11, along with other operations.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/906/1*6UKErR8rQ8azXJuK1HBszg.png" /><figcaption><a href="https://www.felixcloutier.com/x86/syscall">https://www.felixcloutier.com/x86/syscall</a></figcaption></figure><p>Because of this, the registers RCX, R8-R11 get clobbered during the syscall transition. Once kernel takes control of execution, it also saves the new RCX into kernel stack, and restore it at the end.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2l3iTKA3pRopOn_Wa_u_kg.png" /><figcaption>reactos KiSystemServiceExit showing RCX being restored to return address</figcaption></figure><p>This behavior happens on both operating systems. In Linux, for example, a POP_REGS macro is called in <a href="https://github.com/torvalds/linux/blob/155a3c003e555a7300d156a5252c004c392ec6b0/arch/x86/entry/entry_64.S#L139">syscall_return_via_sysret</a> to undo the PUSH_AND_CLEAR_REGS operation performed upon syscall entry.</p><p>Knowing this allows us to use a syscall to obtain the current RIP. We can do this either by calling a non-destructive syscall or by invoking a non-existent syscall, hoping the system dispatcher doesn’t raise an exception but instead fails gracefully, returning an error code in RAX.</p><pre>mov eax, 0x20202020<br>syscall<br>; rcx will point to next instruction by now</pre><p>By executing the previous code, we get 0xC000001C as the return value in RAX, which corresponds to STATUS_INVALID_SYSTEM_SERVICE, indicating that there&#39;s no service with that number in the SSDT.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/1*_BHtsyewQK7yo6Yvfrspcw.png" /><figcaption>RCX is RIP, RAX is -38</figcaption></figure><p>The same concept applies in Linux, where the return value -38 corresponds to ENOSYS: Function not implemented.</p><h3>Conclusion</h3><p>The SYSCALL method gives us another way to get RIP, which can be useful in certain shellcode scenarios. With modern exploitation moving more toward data-only attacks, traditional shellcode tricks are used less often, but it’s still good to explore what’s possible.</p><p>This method could be flagged by invalid syscalls, or it might be made less suspicious by using harmless ones like getpid on Linux. Maybe it’s not even new and I could’ve just come across it late. Either way, it’s another option worth being aware of.</p><p>Thanks <a href="https://x.com/FJarid">@FJarid</a> for validation, @<a href="https://x.com/barakatsoror">barakatsoror</a> for valid input.</p><p><em>I found a mention of such a way a year ago on hn by </em><a href="https://news.ycombinator.com/item?id=41024259"><em>@LegionMammal978</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=02f7a3100a27" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Windows Event Log to the Dark Side]]></title>
            <link>https://medium.com/@5yx/windows-event-log-to-the-dark-side-storing-payloads-and-configurations-9c8ad92637f2?source=rss-caaeb48339c0------2</link>
            <guid isPermaLink="false">https://medium.com/p/9c8ad92637f2</guid>
            <category><![CDATA[microsoft]]></category>
            <category><![CDATA[dfir]]></category>
            <category><![CDATA[digital-forensics]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[windows]]></category>
            <dc:creator><![CDATA[Mustafa]]></dc:creator>
            <pubDate>Wed, 02 May 2018 11:20:15 GMT</pubDate>
            <atom:updated>2018-05-03T15:38:44.474Z</atom:updated>
            <content:encoded><![CDATA[<h3>Windows Event Log to the Dark Side — Storing Payloads and Configurations</h3><p>Event log is a component of Microsoft Windows which provides a central logging service for the operation system, logs helped fixing problems and provided many traces and evidences for forensics.</p><p>Event log has been a target for multiple attacks to terminate its Service, clear its entries or terminate its threads(<a href="https://github.com/hlldz/Invoke-Phant0m">Invoke-Phant0m</a>) to stop it from exposing attackers activities, at the same time other measures where taken to protect it, by forwarding logs to external machines where attackers have no access on, by protecting its service and datasets or keeping log for “clearance” actions done by users.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ukky39jzsMD8r3-Mm1rSZQ.png" /><figcaption>a log entry stating an RDP session to my desktop</figcaption></figure><h4>Windows Event Log Structure</h4><p>Event log consists of one main service called ‘EventLog’ which is ‘wevtsvc.dll’ running under ‘svchost.exe’ as a Local Service, providing logging service through Evt* windows API.</p><p>Log files are stored by default on “%SystemRoot%\System32\Winevt\Logs\” specially the legacy ones, and each LogFile has multiple Source as an identification for the application that triggered the source, registering new logfiles or sources requires admin rights on Windows Vista and later versions.</p><p>Each Source has different IDs for its different events, predefined IDs usually have predefined text or template that can be filled through string insertions from resources dll identified in EventMessageFile regkey, if you used undefined ID eventlog will display a message stating the “the description for the event is not found“ but it gonna be logged anyways.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/996/1*KwBjkdISYJBccagL2pV5ZA.png" /><figcaption>EventLog key with Logfiles as sub keys and sources as sub keys</figcaption></figure><p>Any application can use any registered source to write logs, some restrictions apply to Security logfile as it’s only accessible to Administrators only, beside that, other logs are easily writable for normal users, guest user will face problems accessing logs even if logfiles lacking “RestrictGuessAccess” key, as he has no permissions to “EventLog” root key.</p><h4>Reading and Writing to Eventlog</h4><p>Having proper permissions -not much required- user can write text and binary data to event logs and retrieve them easily with:</p><ul><li>Evt* EventLog APIs</li><li>Powershell</li><li>VBS &amp; WMI</li><li>eventcreate.exe &amp; wevtutil.exe</li></ul><p>methods varies by features, as some allows adding binary data, changing user SID, some can only post text and so.</p><pre>Write-EventLog -LogName &quot;Application&quot; -Source &quot;Microsoft-Windows-User-Loader&quot; -EventId 916 -EntryType Information -Message &quot;Hello World&quot; -Category 2 -RawData 65,66,67,68</pre><p>previous powershell command will write to Application logfile, using User-Loader source, with event 916, and will include 4 raw bytes that will be formated as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Y_fDTOFSE8qRxEecb5sz7w.png" /><figcaption>event with message formatted as its template</figcaption></figure><p>now to retrieve the message we call:</p><pre>Get-EventLog -Newest 1 -LogName &quot;Application&quot; -Source &quot;Microsoft-Windows-User-Loader&quot; -Message &quot;Provider Hello*&quot;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xEJs2tJkDZgd7QwN-cbdDw.png" /><figcaption>Last event information</figcaption></figure><p>that will get us the latest event having the specified file, source and formatted message, then raw bytes and original replacement strings can be accessed directly.</p><p>different IDs can result in different formatted messages to look for, this allows us to hide different parameters inside the message to be extracted later on.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/954/1*g2qj-x0DX7Cmt9Wxyh3tVw.png" /></figure><p>Now we were able to write and read we can use that to store a ‘fileless’ stage2 payload, and as logfiles are managed by system service, nothing suspicious in here, in fact, binary data can hold up to 32kb of data, that means we can even store sophisticated large payloads of empire, Meterpreter or any other payload and combine the chunks to rebuild the emipre.</p><p>for the purpose of demonstration, we can try to write some code, and read it back to read, using deflating to compress -despite the ration in here- and store it as raw bytes</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a3b856e445d7e243a1b15700e75470ad/href">https://medium.com/media/a3b856e445d7e243a1b15700e75470ad/href</a></iframe><p>now we can check and see how it looks in the eventlog viewer:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*yWMBZJe-Ouc05krniL8DEw.png" /></figure><p>all we need next is to read and deflate the same way and then call Invoke-Expression to execute the decoded payload.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c566f553bcec43b0963b697d9c088414/href">https://medium.com/media/c566f553bcec43b0963b697d9c088414/href</a></iframe><figure><img alt="" src="https://cdn-images-1.medium.com/max/752/1*7pbyNdWwF6l3QXj9uWXxWw.png" /><figcaption>Payload is decoded and running</figcaption></figure><h4>What’s Next?</h4><p>After writing, reading and executing using EventLog, we can work more on:</p><ul><li>blending the logs with existing logs and make use of parameters and text insertions.</li><li>multiplexing payloads using Categories, EventID and error Levels.</li><li>Hiding logs in unexpected logfiles and sources.</li><li>Increase LogFile size and retention policy, reissue the event to keep it persistent.</li><li>Reading events from raw log files directly if needed.</li><li>Sending logs to external computers as an update mechanism, as using remote computer “ doesn’t not rely on Windows PowerShell remoting. You can use the ComputerName parameter of the Get-EventLog cmdlet even if your computer is not configured to run remote commands.”</li></ul><p>I hope this finds a good use, and people keep an eye on their logs, for real.</p><blockquote>Empire has had this capability for some time. — Casey Smith</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c8ad92637f2" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[MSWord script injection using DDE]]></title>
            <link>https://medium.com/@5yx/dde-word-exec-3e57cc45b401?source=rss-caaeb48339c0------2</link>
            <guid isPermaLink="false">https://medium.com/p/3e57cc45b401</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[microsoft]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[Mustafa]]></dc:creator>
            <pubDate>Sun, 22 Oct 2017 14:58:45 GMT</pubDate>
            <atom:updated>2017-10-23T15:27:10.975Z</atom:updated>
            <cc:license>https://creativecommons.org/publicdomain/mark/1.0/</cc:license>
            <content:encoded><![CDATA[<p>for the past two weeks the infosec community didn’t stop talking about using DDE for macro-less command execution using office products, bypassing alerts and avoiding detection, and so I did, I’ve spent some time reading about DDE as I always refer to as “interprocess communications way” without trying it myself.</p><h3>Dynamic Data Exchange (DDE)</h3><p>it’s a client/server communication method implemented in Microsoft Windows operation system since early Windows 2.0 in 1987, based over Windows Messaging and using its functions to initiate a connection between two sides, the server listens to certain Topics and messages, acts upon them, responds to clients and terminate the connection at the end.</p><p>it was used to send parameters to applications like office products and browsers, send commands to shell -explorer- to create start menu groups and links and to integrate between different applications and services.</p><p>DDE consists of different messages to communicate like Poke, Request, Advise &amp; Execute. each with its own purpose and usage, the DDE flow looks like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/1*3NRR5GVhRsQhbYaKSroNBg.gif" /><figcaption>DDE conversation for IBM® Personal Communications. - ibm.com</figcaption></figure><h3>MSWord as DDE client</h3><p>what happened with published attacks is DDE used in Word, excel and others as a client, by telling it -using DDE formula- like the following:</p><pre>cmd!”/c notepad”!A0<br>{DDEAUTO c:\\windows\\system32\\cmd.exe &quot;/k calc.exe&quot;  }</pre><p>so the formula tells the process to connect to a non-existing DDE server called CMD with topic “/c notepad”, the operation fails and process proceeds to start it by starting cmd.exe and pass the topic as a parameter, CMD executes the topic hence the command execution.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cU7oX8_eQhgFELMvn67N6w.png" /><figcaption>Word is trying to Initiate a DDE session with aApp=cmd &amp; aTopic=”/k calc” and gets result=0</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/664/1*aPI5Pkt1FKO3AM6rFbD9JA.png" /><figcaption>Word failed to initiate, asks to start the target DDE server</figcaption></figure><p>After clicking “Yes”, MSWord tries again to Initiate DDE session with newly spawned cmd, fails and shows this warning message to indicate that -after RCE happened anyways-.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/445/1*7-_KBT44dtXTWsEbErumFw.png" /><figcaption>Word can’t Initiate DDE session with started CMD</figcaption></figure><p>if it happens that the target is a valid DDE server, communications will continue with the flow by sending DDE Advises and Requests to get the remote data as intended.</p><h3>MSWord as a DDE Server</h3><p>even though DDE is being replaced with other methods for RPCs, an ancient DDE server still exists within office products, providing integration with other systems and forms, each product has its own server with its Topics, and is waiting for messages the moment the product is started.</p><p>By trying to send some DDE messages, I noticed that WinWord -Word DDE server- responds to WM_DDE_EXECUTE messages in a strange way.</p><p>if you send WinWord server a message on System topic, it will post it directly in the active sheet, but -let the fun begins- if you enclosed the message with [] brackets, Word puts the message in a macro function TmpDDE() within a module called WordTmpDDEMod, and executes it.</p><p>that means if we could trigger a DDE Execute with MSWord, we can inject our own code and execute it under Word.exe process.</p><p>to do so, I used <a href="https://github.com/indranilsinharoy/pyzos/blob/master/pyzos/ddeclient.py">David Naylor’s DDE client in python</a> to send the execute code, then figured out there are other command line tools like <a href="http://www.robvanderwoude.com/ddecommandline.php">CMCDDE and others </a>that you can use for the same purpose.</p><p>now, if you tried to send a regular VB code, Word does the following:</p><ul><li>it suffixes function like CreateObject with <strong>__</strong>.</li><li>it prefixes known functions like MsgBox with <strong>WordBasic. </strong>which renders most functions useless.</li><li>it replaces some dots with commas, defines undefined variables too.</li></ul><p>so a valid command like:</p><blockquote>[CreateObject(“Wscript.Shell”).Run “notepad”]</blockquote><p>will be transformed into this:</p><blockquote>CreateObject___(“Wscript.Shell”), Run “notepad”</blockquote><p>which gives a Syntax error as it doesn’t recognize that function or as “,” isn’t well placed.</p><p>after some tries to find a running code, with the old “On error Resume Next” I figured out that WordBasic.Shell is a valid function, so by sending:</p><blockquote>[shell “notepad”]</blockquote><p>Word proceed to execute it as:</p><blockquote>WinWord.Shell(“notepad”)</blockquote><p>which pops notepad with Word process as a parent -with no log trace as no one records DDE messages-.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*amfgAWortdZ9QBcnS5zrPg.gif" /><figcaption>DDE Execute in action</figcaption></figure><p>in the current state, the method only works as a 2nd stage payload, as it requires Word to be running and a DDE client that we can control its Server, Topic and Data we send to Word.</p><p>I’ve also tried it with scenarios like :</p><ul><li>run DDE client as a guest account in the same admin session: <em>Successful</em>.</li><li>run DDE client as another account remotely using psexc: <em>Successful</em>.</li></ul><p>problem with above methods is Windows Messaging doesn’t work across sessions/desktops so you need an Admin|SYSTEM account to execute on other sessions -which is the least you will consider-.</p><p>I scanned my machine -Win10x64 with Office16- for any exe/dll that uses <strong>DdeClientTransaction </strong>and its related APIs and only found these:</p><ul><li><em>shell32.dll</em>: for running applications with /ddeexec, I guess.</li><li><em>twain_32.dll</em>: I have no idea what a DDE client is used for in here.</li><li><em>vbe7.dll &amp; msvbvm60.dll</em>: for DDE scripting in VBA.</li><li><em>ieframe.dll</em>: I may investigate more here and check its execution path.</li></ul><p>it was fun reading through DDE documents and articles, specially Word95 wrdbasic help file.. I hope this article will lead others somewhere. special thanks to <a href="https://sensepost.com/blog/2017/macro-less-code-exec-in-msword/">Etienne Stalmans and Saif El-Sherei</a> for their work.</p><p>have a nice day.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3e57cc45b401" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>