<?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 【☆ ゆう ☆ 】 on Medium]]></title>
        <description><![CDATA[Stories by 【☆ ゆう ☆ 】 on Medium]]></description>
        <link>https://medium.com/@netspooky?source=rss-e5bd5a0bb947------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*NQcnCAzLbra-9JOm.jpg</url>
            <title>Stories by 【☆ ゆう ☆ 】 on Medium</title>
            <link>https://medium.com/@netspooky?source=rss-e5bd5a0bb947------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 16:49:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@netspooky/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[What to do when an elder gets scammed]]></title>
            <link>https://netspooky.medium.com/what-to-do-when-an-elder-gets-scammed-93c052940fc3?source=rss-e5bd5a0bb947------2</link>
            <guid isPermaLink="false">https://medium.com/p/93c052940fc3</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[elder-care]]></category>
            <category><![CDATA[fraud]]></category>
            <category><![CDATA[scam]]></category>
            <dc:creator><![CDATA[【☆ ゆう ☆ 】]]></dc:creator>
            <pubDate>Wed, 02 Oct 2019 16:52:23 GMT</pubDate>
            <atom:updated>2019-10-02T20:08:42.314Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*gEtc_2e6kZzy1uHz0fac9A.jpeg" /></figure><p>Hi there! I used to work with elders and their families. In my time, I saw a lot of scams, fraud, and other devious means of pilfering money. I wanted to write a short guide for anyone who might have a bit of knowledge about this stuff, but don’t know where to begin with helping a loved one.</p><p>First and foremost, I want to thank you for being the one to bear the weight of helping with this. It’s not easy, it’s not fun, and can sometimes cause other problems down the road. You are not powerless, and there are things you can do to help.</p><h3>First Steps</h3><p>The very first step is to tell the person you are helping that you are here to help. Getting scammed, especially out of a lot of money, is a very frightening experience. It’s not something to chastise or guilt trip someone about, especially if they’re in a panic already. Calmly let them know that you are here to listen and lend a hand, and that they aren’t alone.</p><p>The next step is identifying what actually happened. Ask your loved one what happened in their own words. Pay attention to the ways they were communicated with, the way that goods &amp; services were transferred, what was exchanged, and when it happened. Write these things down while they are fresh in your memory, so that you can refer to them later.</p><p>After you establish a timeline, determine whether or not the person you are helping has the resources they need for daily life. It can be incredibly embarrassing for an elder or a loved one to admit that something like this happened to them, and it’s important to make sure that they have things like food and medicine, and won’t go without as a result of a scam.</p><h3>Locking Things Down</h3><p>The next steps are things that can be done in any situation, and are good to do while you dive into more specific actions.</p><h4>Change Passwords</h4><p>Changing passwords is always a good thing to do when an incident like this happens. Determine what accounts they use (especially if they were used when communicating with the scammers), and change those passwords. If you need help picking a good password that they can remember, check out <a href="https://www.howtogeek.com/195430/how-to-create-a-strong-password-and-remember-it/">this article</a>.</p><h4>Lock Down Devices</h4><p>Depending on what they used when the scam took place, you might have to take different steps. Here are some resources for <a href="https://gist.github.com/jaredhaight/e88b4323adce06395dace501841d3075">Windows</a>, <a href="https://www.pcworld.com/article/3332211/secure-android-phone.html">Android</a>, <a href="https://medium.com/@TheTechTutor/how-to-lock-down-your-iphone-f81c7bb4f8af">iOS</a>, and <a href="https://www.computerworld.com/article/3237187/lock-it-down-the-macos-security-guide-updated.html">Mac</a>.</p><h3>Next Steps</h3><p>The next steps you take depend on what specifically happened. I’m going to break it down into a few major categories, and have a short list for each.</p><h4>Financial</h4><p>If your loved one was involved in a financial scam, there are a few different things you can do. Make sure that you keep track of who you called, when, and what information was shared.</p><ul><li>If gift cards were involved, notify the store or website that the gift cards were purchased on. Provide them with dates, times, and amounts. Many retailers are aware of gift card related scams, and have procedures in place to address them. Giving them this information will help stop the flow of illicit funds, and can create a paper trail for later.</li><li>Call the bank that they use and explain the situation to them. If their bank account was specifically involved in the fraud, provide them with dates, times, and amounts involved so that the bank can monitor for future activity and possibly refund you. The same goes for credit cards with fraudulent purchases.</li><li>Lastly, file a police report with the above information. Give them everything you’ve gathered and explain the situation. Depending on the nature of the what happened, they may be able to do some follow up for you if you are trying to recover money from banks or retailers.</li></ul><h4>Health Insurance / Medicare</h4><p>Health Insurance scams are a huge issue. There are many bogus services that try and target elders. Aside from the calls you should make for financial scams (as listed above), there are some other key steps to take if you suspect fraudulent charges on insurance and medicare.</p><ul><li>Call the insurance provider and inform them of the charges.</li><li>You can also provide additional information by looking up the organization <a href="http://docnpi.com/">here</a>.</li><li>Many scams change their names and provider info from time to time, and there are internal divisions at insurance providers that keep tabs on all of these.</li><li>Give them as much information as you can about the service, what charges they incurred, and other details about working with them.</li></ul><h4>Tech Support Scams</h4><p>Tech Support scams are incredibly common. They rely on scare tactics to get their victims to install their products and use their services. The steps to take here can be a bit more nuanced than the others. Tech support scammers use a variety of methods depending on their goals.</p><p>After locking things down and making calls for financial matters (as listed above), there are some other things you can do.</p><ul><li>Check to see what software they installed on the computer.</li><li>Look for any text files on the desktop that may have been typed in by the scammer. Look for any receipts either in email inbox or on the Desktop and/or Downloads folder. These can be clues as to what they may have installed.</li><li>Run a malware scan on the computer. Tech Support scams largely target Windows users, so you can run whatever malware scanners you like to see if anything unsavory was installed.</li><li>Personally, I usually tend to use Windows Defender (pre-installed on Windows), <a href="https://www.malwarebytes.com/mwb-download/">Malwarebytes</a>, and <a href="https://www.ccleaner.com/ccleaner/download">CCleaner</a>, because they’re free and easy to install.</li><li>Make sure you keep track of any charges that were made and report them to the bank. They may continue to attempt to charge later on down the road.</li><li>If you can, determine what they used to remotely access their computer (if they did). Some companies (like LogMeIn), will actually shut down the scam call centers’ login information and effectively shut down the scam for a little bit if you can provide them with the access token they gave you. It’s definitely worth it to try and figure it out. Look at browser history.</li><li>Finally, tell your loved one that no legitimate tech company will ever call you to tell you that they detected a problem on their computer.</li></ul><h3>Conclusions</h3><p>That’s my short guide to what to do when an elder gets scammed. I will probably add more things if people have suggestions. Feel free to <a href="https://twitter.com/netspooky">tweet</a> at me, or leave a comment if you have anything else to share.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=93c052940fc3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To Do That]]></title>
            <link>https://netspooky.medium.com/how-to-do-that-fe8fcad0429c?source=rss-e5bd5a0bb947------2</link>
            <guid isPermaLink="false">https://medium.com/p/fe8fcad0429c</guid>
            <dc:creator><![CDATA[【☆ ゆう ☆ 】]]></dc:creator>
            <pubDate>Sun, 16 Jun 2019 02:34:49 GMT</pubDate>
            <atom:updated>2019-06-16T02:34:49.999Z</atom:updated>
            <content:encoded><![CDATA[<p>You do it :}</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fe8fcad0429c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Unauthenticated HP/Aruba Networks Switches]]></title>
            <link>https://netspooky.medium.com/unauthenticated-hp-aruba-networks-switches-219be815dab5?source=rss-e5bd5a0bb947------2</link>
            <guid isPermaLink="false">https://medium.com/p/219be815dab5</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[infosec]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[hp]]></category>
            <dc:creator><![CDATA[【☆ ゆう ☆ 】]]></dc:creator>
            <pubDate>Sun, 30 Dec 2018 04:18:20 GMT</pubDate>
            <atom:updated>2018-12-30T07:28:51.246Z</atom:updated>
            <content:encoded><![CDATA[<p>Hey there, here’s a quick bit of info about switches that are currently unauthenticated and serving traffic all over the place.</p><p>The Shodan dork for these is: <a href="https://www.shodan.io/search?query=eHTTP">https://www.shodan.io/search?query=eHTTP</a></p><p>Note that most do have authentication, and this write up focuses on ones that have no auth. I have identified 850+ switches that are currently unauthenticated on the web UI.</p><p>There are three versions of the web UI that are accessible from port 80. The web UI may be configured to use a different port, so it’s worth checking scan results.</p><p>/html/nhome.html is the classic version of the Web UI <br>/nextgen/ui/index.html is the newer version of the Web UI<br>/home.html is the older Java based version, under the Procurve label</p><p>Because they have no authentication, there are no intrusion / security events that show up in logs. These switches can be easily reconfigured from the Web UI, or via telnet.</p><p>From telnet, an attacker could do a number of things from this switch, from redirecting traffic / ports, to serving malware, to pivoting within the network that the switches live in.</p><h3>Solutions</h3><p>If you must have your switches connected to the internet in such a way, here are some steps you can take to secure them.</p><p><strong>Set a username and password!</strong> For both the telnet and web UI. You can do this over telnet via the system-view command password.</p><p><strong>Disable the web UI!</strong> If you don’t need the Web UI, then disable it. You can do this via the system-view command web-management.</p><p>You can also enable various logging mechanisms for your switch via the command line. If you find that you are unable to telnet into your switch, just reboot via the web UI and telnet in.</p><p>A full guide to setting up and securing your switch can be found <a href="https://h22208.www2.hpe.com/eginfolib/networking/docs/switches/common/15-18/5998-8158_bog/content/book.html">here</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=219be815dab5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Elf Binary Mangling Part 3 — Weaponization]]></title>
            <link>https://netspooky.medium.com/elf-binary-mangling-part-3-weaponization-6e11971108b3?source=rss-e5bd5a0bb947------2</link>
            <guid isPermaLink="false">https://medium.com/p/6e11971108b3</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[assembly]]></category>
            <category><![CDATA[thug]]></category>
            <category><![CDATA[elf]]></category>
            <category><![CDATA[x86]]></category>
            <dc:creator><![CDATA[【☆ ゆう ☆ 】]]></dc:creator>
            <pubDate>Mon, 17 Dec 2018 04:23:30 GMT</pubDate>
            <atom:updated>2021-01-04T21:24:45.287Z</atom:updated>
            <content:encoded><![CDATA[<h3>Elf Binary Mangling Part 3 — Weaponization</h3><p>Hey y’all, thanks for all the support ! I didn’t realize so many people would think this sort of coding was as cool as I do.</p><p>In the <a href="https://medium.com/@dmxinajeansuit/elf-binary-mangling-pt-2-golfin-7e5c82bb482c">previous write up</a>, the concept of binary golf was established, executing a binary in as few bytes as possible. There’s quite a lot of history in the realm of “size coding”, and extreme assembly optimization. The people who pioneered and later weaponized these approaches did some amazing work to really map out what the limitations of the processor actually are, and some wild ways of making things happen.</p><p>There are many resources regarding <a href="http://www.sizecoding.org/wiki/Main_Page">size coding</a>, <a href="http://shell-storm.org/shellcode/">shellcode development</a>, and other assembly tricks. In this write up, we are going to explore coding within the size boundary we established for ELF64, and actually make those 84 bytes actually do something.</p><h3>Establishing Boundaries</h3><p>Like everything in life, boundaries need to be established in order to understand processes and their effects. Within the boundaries of the ELF64 binary template, there are some key areas where code can safely exist. These are sections where the <a href="https://wiki.osdev.org/System_V_ABI">ABI</a> that processes your binary doesn’t seem to mind a bunch of junk data. Due to us already overlaying ELF and program headers, there is a significant challenge to identifying these locations, and reusable structures that we can leverage.</p><p>Our main areas of focus today are:</p><blockquote>0x04–0x0F : 12 bytes<br>0x3C-0x39 : 4 bytes <br>0x44–0x47: 4 bytes <br>0x4C-0x53: 8 bytes</blockquote><h3>bye.asm</h3><p>This is the code for the program that we want to execute:<br>badcfe2143 .. mov edx, 0x4321fedc <br>be69191228 .. mov esi, 0x28121969 <br>bfaddee1fe .. mov edi, 0xfee1dead <br>b0a9 ........ mov al, 0xa9<br>0f05 ........ syscall</p><p>In a nutshell, this program executes the <a href="http://man7.org/linux/man-pages/man2/reboot.2.html">reboot syscall</a> with the <em>LINUX_REBOOT_CMD_POWER_OFF</em> argument. This essentially executes the same syscall that your OS calls when you hold down the power off button, but without any of sync or other routines that will allow your system to shutdown gracefully. The syscall is executed by placing magic values and an argument for the specific type of reboot you want to do in the specified registers, and then calling the kernel.</p><h3>The Process</h3><p>So how do we load all of this into our 84 byte ELF binary? Let’s take a look at our code, and our binary, and see what we can do.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/99d8533b89eafbc0a1b72989d0e18213/href">https://medium.com/media/99d8533b89eafbc0a1b72989d0e18213/href</a></iframe><h4>0x04–0x0F</h4><p>The first two instructions move the constant values into two registers. These values are <em>LINUX_REBOOT_MAGIC2</em> (0x28121969) into ESI, and <em>LINUX_REBOOT_CMD_POWER_OFF</em> (0x4321fedc) into EDX. Here, we are using the 32 bit forms of the registers. Moving a 32 bit value into the lower 32 bits of a given 64 bit register will zero out the top 32 bits, meaning we don’t need to xor or do anything else to ensure that the top 32 bits are 0. This is not true for moving to lower bits though, such as say, mov al, 8. This would keep the top values in RAX, and only change the bottom 8 bits to 00001000.</p><p>These two instructions are 5 bytes each, meaning that in our 12 byte boundary, we have two bytes left to use up here. This is the perfect amount of space to fit a short jump to the rest of the code!</p><h4>0x4C-0x53</h4><p>Now we jump down to the label <strong>reeb</strong> within the <em>p_align</em> section of the program header, which has 8 bytes for us to use. Here, we are moving another constant, <em>LINUX_REBOOT_MAGIC1</em>, necessary for our syscall into EDI, and jumping to the last location to execute. The mov and jmp instructions together are only 7 bytes, so I included a nop at the very end to keep the binary at a svelte 84 bytes. Without this, the binary wouldn’t execute. It also shows how much space you have to work with in this location.</p><p>When I initially released this binary, I didn’t put the mov al, 0xa9 and syscall instructions up in the program header, leading to 1 extra byte. To solve this, we do something that requires a bit of care to do properly.</p><h4>0x3C-0x39 and 0x44–0x47</h4><p>The final step is our jump to the label <strong>cya</strong>, starting at 0x3C. There are a few structures in this area that need to be addressed.</p><p>The p_filesz and p_memsz structures appear to need to be the same value in order to execute properly on most kernels. The other tricky aspect is that these are file sizes that have a size limit within the program header that needs to be investigated more. Since this is little endian when we write in nasm, it stays in the lower 4 bytes of the addresses. If you touch the first byte, it might put you over the available memory on the system, which will render the binary unusable. In my experience, using only 4 bytes in these locations is playing it safe, but you should definitely play around with these!</p><p>Knowing these limitations, we have enough space to do our final moves, loading <strong>RAX</strong> with our syscall value 0xa9, and executing a REBOOT.</p><p>A very interesting thing to note about the bytes at 0x3C-0x39 is that they are processed a total of three times by the kernel when this executes. First as the <em>e_shnum</em> and <em>e_shstrndx</em> structures in the ELF header, second as the <em>p_filesz</em> structure in the Program Header, and lastly as the code that finishes the execution of the binary.</p><p>Here is a handy one liner that will do this.</p><p>base64 -d &lt;&lt;&lt; f0VMRrrc/iFDvmkZEijrPAIAPgABAAAABAAAAAEAAAAcAAAAAAAAAAAAAAAAAAAAAQAAAEAAOAABAAIAsKkPBQAAAACwqQ8FAAAAAL+t3uH+6+mQ &gt; bye;chmod +x bye;sudo ./bye</p><p>Please read the next section before running this on any system.</p><h3>Effects</h3><p>On a desktop system, this binary will shut down your computer abruptly. There are some potential side effects from a shutdown like this, but personally I haven’t experienced any issues with it.</p><p>However, on a VPS, this specific syscall proves to be a bit of a problem. Since the virtual machine doesn’t actually have any of it’s own physical hardware (it’s either virtualized or shared with the host), the power button on a VPS isn’t really a thing. By executing a syscall the effectively “shuts off the power” to the operating system, this puts the VM in an unknown state.</p><p>So far, whenever this is run on a VPS, it seemingly wipes out the entire instance. A thread about this one liner (the 85 byte version) is here:</p><h3>【☆ yuu ☆ 】 on Twitter</h3><p>So after some testing, I found that this one liner does the following to different VPS: @njal_la - Shuts down and makes unrecoverable @linode - Wipes and redeploys to same IP @awscloud - Wipes and stops instance (also re-IPs if out of the box deployed) More testing forthcoming. https://t.co/iDpxDgLEqR</p><p>This is a far more destructive piece of code than rm -rf --no-preserve-root / or a fork bomb, because even in those situations, a VM could be recovered via snapshots or mitigated with access / resource controls.</p><h3>.fini</h3><p>So there is still quite a lot to explore in this space, and not enough people doing it! I encourage you to play around with these concepts, and see what you can do with it! The next write up in this series will have to do with some assembly optimization concepts, and some space saving tricks like reusing constants of the header (hint: 0x00–0x04), and their practical usage.</p><p>In case you missed it, here are links to <a href="https://medium.com/@dmxinajeansuit/elf-binary-mangling-part-1-concepts-e00cb1352301">Part 1</a> and <a href="https://medium.com/@dmxinajeansuit/elf-binary-mangling-pt-2-golfin-7e5c82bb482c">Part 2</a> of this series.</p><p>greetz: hermit, blackout, jinn, dnz, phaith, readme, notpike, decoded and many others for encouraging me, nt for challenging me frequently (and publicly), and everyone who nuked their own VPS and VMs to test with me.</p><p>bye2: everyone who flashcards others with assembly, you really make chatting a joy and totally not toxic.</p><p>Check out my other work at <a href="https://n0.lol/">https://n0.lol</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/550/0*CG-yE0Q9jUwUyySd.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6e11971108b3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Elf Binary Mangling Pt. 2: Golfin’]]></title>
            <link>https://netspooky.medium.com/elf-binary-mangling-pt-2-golfin-7e5c82bb482c?source=rss-e5bd5a0bb947------2</link>
            <guid isPermaLink="false">https://medium.com/p/7e5c82bb482c</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[thugcrowd]]></category>
            <category><![CDATA[golf]]></category>
            <category><![CDATA[assembly]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[【☆ ゆう ☆ 】]]></dc:creator>
            <pubDate>Mon, 10 Dec 2018 03:41:50 GMT</pubDate>
            <atom:updated>2020-11-24T19:24:14.729Z</atom:updated>
            <content:encoded><![CDATA[<p>Greetings everyone, and welcome to part two of the Binary Mangling series. <a href="https://medium.com/@dmxinajeansuit/elf-binary-mangling-part-1-concepts-e00cb1352301">In our last installment</a>, we took a look at the basics of what an ELF binary is, how it’s laid out, and the bare minimum needed to execute some raw machine code. We also did a little bit of mangling, by hand optimizing our binary in a hex editor to put things where they aren’t supposed to go.</p><p>In this installment, we are going much, much deeper, to challenge the kernel with a clown car of barely valid bytes to test the limits of the ELF format itself.</p><p>The third part should be coming out at around the same time as this, with a practical example of binary golf, the art of executing a binary in as few moves as possible.</p><h3>That Shrinking Feeling</h3><p>Personally, I have wanted to figure out what the absolute smallest ELF64 binary I could manage to create was for a while now.</p><p>By normal means, using the GNU assembler and linker, you can create pretty small binaries that have the basic data structures needed to dictate how the executable is parsed by the OS.</p><p>In the previous write up, we showed the two necessary structures required to execute your code: The ELF header and the program header. For more info on these, please refer to <a href="https://medium.com/@dmxinajeansuit/elf-binary-mangling-part-1-concepts-e00cb1352301">part one</a>.</p><p>In my initial investigation, I created a 120 byte ELF64 that included the <a href="https://linux.die.net/man/2/exit">exit</a> syscall in part of the ELF header, meaning the binary was exactly the size of the ELF and Program Headers. After playing around a bit more, I discovered that you can actually end the ELF header early, at 0x3A instead of 0x40, meaning you could save a whole 6 bytes by moving the program header up into the ELF header.</p><p>I explored the possibility of overlaying the program and ELF headers, but due to the 8 byte addresses of ELF64, I couldn’t figure out a proper way to do it. I tried again months later and was almost there, but still no dice. After a bunch of messed up nasm files, and some botched hex editing sessions, <a href="https://twitter.com/_veekun">@_veekun</a> came through and found the proper alignment (big big shoutout).</p><p>Here is a breakdown of how we are going about this.</p><h3>Overlay</h3><p>So the basic principles of overlaying these two header structures relies on some very precise pieces to be in place.</p><p>It’s probably best explained with this nasm file.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce510c512d9d86defaa4ad52bbd9534a/href">https://medium.com/media/ce510c512d9d86defaa4ad52bbd9534a/href</a></iframe><p>Let’s go through this line by line</p><p><strong>Line 1</strong> says BITS64, which tells nasm that this is 64 bit. <br><strong>Line 3</strong> tells NASM where the binary should be loaded into memory. Usually this is at 0x40000, but this specific address will be useful later on.<br><strong>Line 8</strong> is the first 4 bytes of the ELF Header that are required to identify the file as an ELF binary.<br><strong>Line 9</strong> contains the <em>_start</em> label, which is the entry point of our program. It’s located at offset 0x4 within the binary. From here until line 12 is our actual program. Note the 5 nops at the end, these are just place holders to show the amount of code we can actually fit in this location. <br><strong>Line 21</strong> is where the ELF header continues until…<br><strong>Line 28</strong> where the program header begins in the middle of the <em>e_entry</em> data of the ELF header.</p><p>This is where things get interesting.</p><p>The <em>p_type</em> data structure denotes the type of segment, here a 1, which is a LOAD segment, meaning it will be loaded into memory for further usage (the ORG address on line 3 plays a key role in where we want to be loaded.)</p><p>This structure, containing a value of 1, actually completes the second half of the <em>e_entry</em> data structure, making the full value 04 00 00 00 01 00 00 00. This gives the proper entry address of 0x100000004, which is 4 bytes after the location that the binary is loaded into memory, or 0x4. This is precisely where our <em>_start</em> label is.</p><p>The next structures that overlap are <em>e_phoff</em> (which is where the program headers are located), and <em>p_flags</em>, which are the flags that determine the sections permissions. In this case the flags are 0x1C which is 00011100 in binary. The <a href="https://wiki.osdev.org/System_V_ABI">ABI</a> only pays attention to the lowest three bits, meaning this is marked “executable”, and it’s value can be shared with the ELF header to designate that 0x1C is the address where the program headers start (which is in the middle of the ELF header.)</p><p>The rest of the structure continues and overlaps each other with largely dummy values until the end.</p><p>Keeping these data sizes in mind and how they overlap will be useful in the next write up. For now, here’s a small annotated part of elf.h that shows how this is eventually laid out.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/33dfae9f647950595d25f71f7e857d44/href">https://medium.com/media/33dfae9f647950595d25f71f7e857d44/href</a></iframe><h3>Putt Putt</h3><p>So now we have our basic structure set up, let’s go through what happens when you run this.</p><p>First, let’s compile and run exit.asm like so:</p><blockquote>nasm -f bin -o exit exit.asm<br> chmod +x exit<br> ./exit<br> echo $?</blockquote><p>If all goes according to plan, you should see a 0 as the output from the last command.</p><p>When we run our ELF file, the kernel looks for the data structures we just went over in order to determine what to do with this particular binary. We want to load it into memory (at our specific address defined in <em>p_vaddr</em>) and execute at the entry point we defined at <em>e_entry</em>. Since the ELF and program headers overlap, the kernel jumps around our header and eventually loads our binary and figures out how to execute our code.</p><p>Our program is quite simple:</p><blockquote>mov al,0x3c<br> xor rdi,rdi<br> syscall</blockquote><p>All we are doing here is moving value of 0x3C into the lowest 8 bits of the <strong>RAX</strong> register, putting a value of zero in the<strong><em> </em>RDI</strong> register, and calling the kernel. 0x3C is the syscall number for exit, which just exits a process. Xoring <strong>RDI</strong><em> </em>with itself creates a 0, which is our <strong>EXIT STATUS</strong> code, 0 meaning <strong>SUCCESS</strong>.</p><p>So it’s running just fine, despite being completely mangled, but what happens when we try and analyze this code?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/673/1*iaaC4IYJFSEnKvOIWYLNvw.png" /><figcaption>oWo</figcaption></figure><p>It appears that objdump has no idea what to do with it, and readelf gives some very bizarre values as well. Other debuggers display some interesting results. You should play around !</p><h3>What’s next?</h3><p>So now we’ve successfully create an 84 byte ELF binary, the next step is seeing what else we can pack in this header, and do some more binary golfing. The <a href="https://medium.com/@dmxinajeansuit/elf-binary-mangling-part-3-weaponization-6e11971108b3">next write up</a> will describe applying these same techniques to create a VPS nuking one liner containing an 84 byte binary. It will also provide a more in depth look at specific data structures that can be reused to hold code, and how to jump around between them. Thanks for reading!</p><p>Greetz to: hermit, +Eevee, dnz, readme, rqu, decoded, notpike, skelsec, jinn, notdan, MG, phaith, nux, zuph, sshell, def_hand, cedric, protoxin, xero and the rest of the <a href="https://twitter.com/thugcrowd">Thugcrowd</a> crew. Check us out Tuesdays at 9:30 PM America/New_York! We do a live hacker podcast <a href="https://twitch.tv/hardchat">here</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e5c82bb482c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ELF Binary Mangling Part 1 — Concepts]]></title>
            <link>https://netspooky.medium.com/elf-binary-mangling-part-1-concepts-e00cb1352301?source=rss-e5bd5a0bb947------2</link>
            <guid isPermaLink="false">https://medium.com/p/e00cb1352301</guid>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[assembly]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[thugcrowd]]></category>
            <dc:creator><![CDATA[【☆ ゆう ☆ 】]]></dc:creator>
            <pubDate>Tue, 07 Aug 2018 19:17:55 GMT</pubDate>
            <atom:updated>2018-12-21T16:40:55.657Z</atom:updated>
            <content:encoded><![CDATA[<p>Okay, so you want to see how small you can make a 64 bit binary. In the age of giant bloated applications full of impossibly convoluted machine instructions, eating up your memory and disk space, it’s nice sometimes to get down to the lowest of low levels and create something so tiny, that you know what every single bit is doing and it’s purpose. To do so, we need to employ some standard tricks and a little creativity to get us down there.</p><h3>Building Your Binary</h3><p>Let’s start with a really simple program that prints a string in the terminal! I chose these smaller opcodes to save a bit more space, but we can get into assembly optimization in another post.</p><pre>.global _start<br>.text<br>_start:            <br>    mov   $1, %al     # RAX holds syscall 1 (write), I chose to use<br>                      # %al, which is the lower 8 bits of the %rax <br>                      # register. From a binary standpoint, there<br>                      # is less space used to represent this than<br>                      # mov $1, %rax<br>    mov   %rax, %rdi  # RDI holds File Handle 1, STDOUT. This means <br>                      # that we are writing to the screen. Again, <br>                      # moving RAX to RDI is shorter than <br>                      # using mov $1, %rdi<br>    mov   $msg, %rsi  # RSI holds the address of our string buffer. <br>    mov   $11, %dl    # RDX holds the size our of string buffer. <br>                      # Moving into %dl to save space.<br>    syscall           # Invoke a syscall with these arguments.<br>    mov   $60, %al    # Now we are invoking syscall 60. <br>    xor   %rdi, %rdi  # Zero out RDI, which holds the return value.<br>    syscall           # Call the system again to exit.<br>msg:<br>    .ascii &quot;[^0^] u!!\n&quot;</pre><p>This program uses the most primitive form of writing to STDOUT. It invokes a raw Unix system call to the kernel, with the registers containing the arguments. Save this into a file called asm_smile.s</p><pre>$ vim asm_smile.s<br>$ as asm_smile.s -o asm_smile.o</pre><p>Now we’ve created an object file that can be used to create an executable. We can link it with ld, then run.</p><pre>$ ld asm_smile.o -o asm_smile<br>$ ./asm_smile<br>[^0^] u!!</pre><p>Okay what have we done here? Let’s take a look at the raw data we generated. A good place to start is objdump.</p><pre>$ objdump -d asm_smile<br>   <br>   asm_smile:     file format elf64-x86-64<br>   <br>   Disassembly of section .text:<br>   <br>   0000000000400078 &lt;_start&gt;:<br>     400078:       b0 01                   mov    $0x1,%al<br>     40007a:       48 89 c7                mov    %rax,%rdi<br>     40007d:       48 c7 c6 8f 00 40 00    mov    $0x40008f,%rsi<br>     400084:       b2 0b                   mov    $0xb,%dl<br>     400086:       0f 05                   syscall<br>     400088:       b0 3c                   mov    $0x3c,%al<br>     40008a:       48 31 ff                xor    %rdi,%rdi<br>     40008d:       0f 05                   syscall<br>   <br>   000000000040008f &lt;msg&gt;:<br>     40008f:       5b                      pop    %rbx<br>     400090:       5e                      pop    %rsi<br>     400091:       30 5e 5d                xor    %bl,0x5d(%rsi)<br>     400094:       20 75 21                and    %dh,0x21(%rbp)<br>     400097:       21 0a                   and    %ecx,(%rdx)</pre><p>Our program + string is only 33 bytes, so why is our binary 752 bytes? Let’s take a look at a quick hex dump.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/611/1*IQGZdPh_NHQPJtO3xgsFVQ.png" /></figure><p>Hrm… There’s quite a bit of extra data in there! We can see our program begins at 0x78 and ends at 0x98. How can you make a binary smaller right off the bat? We can use strip!</p><pre>$ strip asm_smile</pre><p>Strip reads a binary file, and removes a lot of the extra debug and compiler info that isn’t needed. So what does our binary look like now?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/1*lTFwgVbFgB43iGBKQLHD7Q.png" /></figure><p>After using strip, we are down to 368 bytes! That’s a pretty small binary. But remember, our machine instructions were just 33 bytes, so what’s up with all this overhead?</p><p>To understand this, we need to break down the sections of an ELF binary real quick. If you’re not used to looking at hex dumps and hand modifying data, this is a great place to start. It’s not that scary!</p><h3>Under the Hood</h3><p>All ELF binaries need to have a few things in place in order for them to be interpreted by the Linux kernel properly. As with Windows EXEs, there’s a structure to the header that defines the overall layout of the binary.</p><p>This example is using x86_64 assembly, so the ELF binaries I am describing here are the 64 bit version. The 32 bit version is slightly different.</p><p>Let’s take a look at what other information is in this binary. We can use a program called readelf to help us follow along!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/595/1*hw6fi3LlklKSKxCC6d0RQQ.png" /><figcaption>Output from readelf</figcaption></figure><p>What does this all mean? We will start by first understanding the ELF header.</p><h3>ELF Header</h3><p>The ELF header section defines the file as an ELF binary. In the hex dump it looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/1*5VVgGa6gOPRebh_hGbQ1Gg.png" /></figure><p>Each one of these bytes has a specific purpose.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/467/1*UYtXVZJfa4SfGFQ61OBvaw.png" /></figure><p>This is the ELF Header with index values to show exactly where these values line up in our binary.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/1*bC4zi1NKeYLVSFm8m9idxQ.png" /></figure><p>These values are mainly metadata that tells the operating system what to do with this file. I won’t get too deep into what these things mean, but they are necessary to be aware of as we move along. You can find more info <a href="https://wiki.osdev.org/ELF">here!</a></p><h3>Program Header</h3><p>Next up is the program header. This area describes a segment / other info that the operating system needs to know how to run the program. This is how it appears in our hex dump</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/617/1*_0tG7NM-OqnjVnz-9fdxnQ.png" /></figure><p>Here is a quick listing of the components that make up the program header. Note: The offsets are relative to the start of the program header (at 0x40).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/891/1*9EaBCnV0_6SJYavrpSqRmQ.png" /></figure><p>Here’s a layout of our the program header in our binary, with indexes for reference.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/623/1*mtP4CJU4OkK9wylVleLOkw.png" /></figure><p>From the output of readelf, we can see that it matches up with the hex dump.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/1*h6GCu3Z2wpvFKzM4j9qwsg.png" /></figure><h3>.text Section</h3><p>Next up is the machine instructions themselves. We saw these earlier when we used objdump, but in their raw form they look like this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/616/1*uHyMA3oa3uOcZ828JG1SKA.png" /></figure><p>You can see that they contain the 33 bytes of our program.</p><h3>Section Headers</h3><p>These next chunks of information are known as the section headers. They are used to describe the layout of the sections in the binary.</p><p>You can see in the section header output of readelf that we have descriptions of the .text and .shstrtab sections. The .text section is what we just saw above, at offset 0x00000078, containing the machine instructions. The section after that is .shstrtab, which is the table of addresses where strings are located in the binary.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/623/1*MqiDSFj18um8smKUQ8IwZg.png" /></figure><p>In a binary this small, with no labels or anything else, .shstrtab only exists to say that it exists, by describing the location of the .shstrtab label.</p><p>In any case, these sections are totally unnecessary unless you are actively debugging the program. All we need are the machine instructions, so we can get rid of this big bulk of bytes taken up by the .shstrtab and the section headers by hand with your hex editor of choice.</p><p>Delete everything from 0x99 on!</p><p>Our binary now looks like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/623/1*QSDKsMXanBkTXJtXmUyNJw.png" /><figcaption>Our binary with the fresh cut</figcaption></figure><p>We keep the 0a byte at the end just so the terminal knows that the string is over and we need a new line.</p><h3>Mangling</h3><p>Well, we are now down to 0x99 (153) bytes. This is pretty small, but we can do more to get this thing even smaller.</p><p>We can see in the objdump from before that we MOV 0x40008f into %rsi, which is the virtual address pointing to our string 0x5b5e305e5d207521210a. or “[^0^] u!!\n”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/698/1*6aQ14SwHTw0Zq_1YXGR7oA.png" /></figure><p>If the program is pointing to the address of the string at 0x40008f, then that means that it maps out to 0x00008f in our binary. What if we save even more space (10 whole bytes!) by moving our string somewhere else?</p><p>But where else, and how? Well, we can try and find some unused space elsewhere to store our string. At first glance it looks like all the bytes in our binary are accounted for. Admittedly, x86_64’s structure is a bit more rigid than x86, because of the amount of space needed to hold addresses in such a large memory space. But, there are still some spots that we can hide some data.</p><p>The ELF Header from above contains a bit of padding at 0x08–0x015. It also contains some bytes that are pretty much always going to be a specific value at this point in ELF’s history.</p><p>Two of these values are the ELF version (which is 1 for version 1) at 0x06, and the OS Application Binary Interface at 0x07. These can be overwritten and still run on most Unix based systems, and are a perfect location to begin our code insertion.</p><p>We now have 10 bytes free that we can use to move our string up into the header like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/618/1*QtBQ0JgmADMbElAqRSaSlg.png" /></figure><p>Now before we run this, we have to make sure our machine code is pointing to where our new string is. Previously we were at 0x40008f, which is referenced in the binary at 0x00000080</p><pre>48 c7 c6 8f 00 40 00    mov    $0x40008f,%rsi</pre><p>Since our string is now at 0x00000006 in our binary, we change the address at 0x00000080 as such. Simply swap out 8f for 06. Note: Addresses are little endian, so 0x0040008f is represented as 0x8f004000.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/618/1*MDsmHs73UWtA5zfdXcamcA.png" /></figure><p>And there you have it. We have successfully rearranged this binary by hand to hide code in the header, and have removed debugging capabilities.</p><p>Our binary should do the same thing as it did when we first compiled it, but now at a lean 143 bytes.</p><p>Final Output:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/628/1*kKSEHe0J2ZZXWvSvvMtFnQ.png" /></figure><p>This is part 1 of binary mangling. Look out for <a href="https://medium.com/@dmxinajeansuit/elf-binary-mangling-pt-2-golfin-7e5c82bb482c">Part 2 —Golfin</a>, and <a href="https://medium.com/@dmxinajeansuit/elf-binary-mangling-part-3-weaponization-6e11971108b3">Part 3 — Weaponization</a>, soon!</p><p>Also check out the podcast I run with my friends! <a href="http://thugcrowd.com/">ThugCrowd</a> — on <a href="https://twitter.com/thugcrowd">Twitter</a>, <a href="https://twitch.tv/hardchat">Twitch</a>, <a href="https://www.youtube.com/channel/UCN5WEXJ3tNn7z6LSs94ehng">Youtube</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e00cb1352301" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>