<?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 luiz boina on Medium]]></title>
        <description><![CDATA[Stories by luiz boina on Medium]]></description>
        <link>https://medium.com/@luizboina55?source=rss-28eeecc3c052------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/proxy/1*TGH72Nnw24QL3iV9IOm4VA.png</url>
            <title>Stories by luiz boina on Medium</title>
            <link>https://medium.com/@luizboina55?source=rss-28eeecc3c052------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 01 Dec 2026 11:31:00 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@luizboina55/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[Android Malware Analysis II: Russian RAT & Its Anti-Analysis Techniques]]></title>
            <link>https://medium.com/@luizboina55/android-malware-analysis-ii-russian-rat-its-anti-analysis-techniques-a700611bb017?source=rss-28eeecc3c052------2</link>
            <guid isPermaLink="false">https://medium.com/p/a700611bb017</guid>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[android-malware-analysis]]></category>
            <category><![CDATA[malware-analysis]]></category>
            <category><![CDATA[android-malware]]></category>
            <category><![CDATA[threat-intelligence]]></category>
            <dc:creator><![CDATA[luiz boina]]></dc:creator>
            <pubDate>Tue, 05 Nov 2024 17:26:36 GMT</pubDate>
            <atom:updated>2024-11-05T18:49:25.195Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*aQD3x4xyLRJb5mfS.jpg" /><figcaption>Owl Hunting by Wild Wonders of Europe</figcaption></figure><p>In this article, I present an analysis of an Android malware sample obtained last month. The malware uses anti-analysis techniques to prevent researchers from decompiling it with most commonly used tools, such as apktool and jadx. Although I could not fix the malware’s tampered fields, I discovered another tool that worked to resolve the problem.</p><p>The malware, Tap2Earn, was collected on Oct. 24 directly from its phishing page. It claims to be a legitimate app for earning money while playing games on the phone.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pxIhy9u6Huc_SUVEhDa-iA.png" /><figcaption>Phishing page used to spread the malware</figcaption></figure><p>Dynamic analysis showed that this APK is actually a downloader for the main malicious program. Once installed, this first APK prompts the user with an update screen and requests permissions to read and write to the storage, install and remove applications, and access accessibility features. Once these permissions were granted, it installed a second-stage malware and deleted itself, but retained the same name and icon. The malware used a black window created through accessibility services to conceal the action.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/895/1*6RgHD8kxk0qc_mIVZRoWtg.png" /><figcaption>1. Malware requests an “update” to install the second APK; 2. and 3. APK prompts the user to grant permission to install the APK</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/904/1*NNcKa34bj8gSDie__MwLLA.png" /><figcaption>The Package name changed from com.appd.instll.load to kansas.midwest.dialog but the name and icon remains the same</figcaption></figure><p>After execution, the second-stage malware displayed an infinity loading screen with its content obtained from a remote server, likely awaiting further instructions from a C2 server. The root path of the malicious domains points to a Telegram channel, which is likely used to spread other malware.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v8eLKaXTRV4UZrjxbB1pLA.png" /><figcaption>HTML Response, in Russian, displayed in second stage malware’s screen</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/303/1*xQHtbJ3ssoKGx7ObO_h3lw.png" /><figcaption>Infinity loading, indicating that the access will be “granted”</figcaption></figure><p>A persistence mechanism was found in this APK. When the user selects this app in the settings screen, it automatically closes the window and redirects the victim to the home screen.</p><p>Talking more about the static analysis and anti-analysis techniques implemented, I tried to use unzip, apktool, jadx-gui, and apkinspector but none of them worked. This was due to tampered zip headers in the APK files, such as the compression method, which these tools rely on to decompress and decode the APK properly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*P1NxplgPpdaBKo-rKw1gGg.png" /><figcaption>ApkInspector identifying tampered fields</figcaption></figure><p>I used unzip to examine the compressed files and noticed that the compression method field of <em>AndroidManifest.xml</em> was tampered with. Also, a very long directory structure with Unicode names and different compression methods was found, which mentioned tools could not decompress properly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*in2ZyC0w5dCiYBCTPelALA.png" /><figcaption>Decompilation error when using Apktool; Unexpected APK structure found</figcaption></figure><p>Studying this topic more, I discovered that Android 9 and above do not rely on the local directory information to install the APK on a device, using only the central directory. I spent considerable time trying to fix the tampered fields using <a href="https://www.sweetscape.com/010editor/">010 Editor</a> without success, so I switched to <a href="https://www.pnfsoftware.com/">JEB</a>, which worked perfectly in this case.</p><p>As observed, the first-stage malware only requests read/write to the storage, installation, and package removal permissions. Despite the anti-analysis techniques used, it lacks significant obfuscation. While the package names were obfuscated, most of the code was in plain text. The malware appears to target users from countries with English, Turkish, Portuguese, Russian, Arabic, and Chinese languages, as these translations are available.</p><p>The install method utilizes the PackageInstaller class to replace the first APK with the second one. The second APK file, named childapp.apk, was embedded within the first one, inside that long chain of directories with Unicode names in the assets folder.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NUXjGu3jG6GtMWFSxTLqGQ.png" /><figcaption>First APK replaces itself by installing the embedded APK</figcaption></figure><p>The real malicious behavior was found in the second-stage malware. It requests several additional permissions, allowing it to perform the same actions as the first APK and more, including:</p><ul><li>Write and read SMS, call log, and contacts</li><li>Set wallpaper, use full-screen intents, and prevent phone lock</li><li>Manage Wi-fi state and internet connection</li></ul><p>The analysis of the APK reveals it as a Remote Access Trojan (RAT) with evasion techniques, including emulator detection, heavy obfuscation, and extensive malicious capabilities. This malware uses a well-known technique to automate device navigation through accessibility services. As noted, it leverages accessibility to prevent the user from deleting the app, as shown in the code snippet below. Interestingly, it also compares strings on the current screen against a list of possible languages to broaden its range of potential victims based on system language.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/927/1*trwacO6xo2U9TuSKaZHczg.png" /><figcaption>Prevent deletion by checking strings and packages on the screen</figcaption></figure><p>This malware uses Telegram for C2 communication and has extensive capabilities, essentially granting it full access to a victim’s phone. It can read personal data and operate remotely, intercept OTP passwords, and even access bank accounts. While listing all its capabilities would be time-consuming, this summary provides a clear idea of how dangerous this malware is.</p><p><strong>IoCs:</strong></p><ul><li>hxxps[:]//tap2moon[.]luvnse[.]com</li><li>Downloader APK MD5: af5244a1cdab1bafd1329b7d4d8087a8</li><li>Dropped APK MD5: 1475983584ba42a415d9956f4a5f2733</li><li>Certificate:34bdf3dbb34dfc02d111cf72ad5826ba19a90c9c410b34ebfac2302bf9105090</li></ul><p><strong>References:<br></strong><a href="https://x.com/joe4security/status/1674042511969468418">https://x.com/joe4security/status/1674042511969468418</a><br><a href="https://www.zimperium.com/blog/over-3000-android-malware-samples-using-multiple-techniques-to-bypass-detection/">https://www.zimperium.com/blog/over-3000-android-malware-samples-using-multiple-techniques-to-bypass-detection/</a><br><a href="https://unit42.paloaltonetworks.com/apk-badpack-malware-tampered-headers/">https://unit42.paloaltonetworks.com/apk-badpack-malware-tampered-headers/</a><br><a href="https://hatching.io/blog/triage-insights-ep2/">https://hatching.io/blog/triage-insights-ep2/</a><br><a href="https://x.com/malwrhunterteam/status/1850130384370991466">https://x.com/malwrhunterteam/status/1850130384370991466</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a700611bb017" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Android Malware Analysis I: AndroidService Spyware]]></title>
            <link>https://medium.com/@luizboina55/android-malware-analysis-i-androidservice-spyware-d5a2451c1c12?source=rss-28eeecc3c052------2</link>
            <guid isPermaLink="false">https://medium.com/p/d5a2451c1c12</guid>
            <category><![CDATA[android-malware]]></category>
            <category><![CDATA[malware-analysis]]></category>
            <category><![CDATA[spyware]]></category>
            <category><![CDATA[malware]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[luiz boina]]></dc:creator>
            <pubDate>Sun, 27 Oct 2024 00:53:52 GMT</pubDate>
            <atom:updated>2024-10-27T00:53:52.343Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6dNHTPO0TBPrZhh3.jpg" /><figcaption>Owl Hunting by Javier Fernández Sánchez</figcaption></figure><p><strong>TL;DR:<br></strong>The Malware sample collected, AndroidService, is a Spyware that steals victims&#39; information, saves it to local storage, and then sends it to a remote server defined in a Google Docs file. It uses rudimentary persistence and detection evasion techniques. It was not possible to identify if this sample was related to other previous campaigns. The Google Docs file containing IPs of the C2 server was unavailable at the time of analysis, likely having been removed by Google or the Threat Actor themselves.</p><p><strong>IoCs:<br></strong>hxxps://punjabb[.]weebly[.]com/uploads/7/7/4/1/77411406/secureandroid.apk<br>hxxps://docs[.]google[.]com/uc?id=0B1s1xR30fG_QbkFXM0pLVThzSXM&amp;export=download<br>md5: b4ab82bdee5f8af58763dd1d3c884f0f<br>sha1: 2a6b6c1258f12690b5925a8b793d203d0b0e9263 <br>sha256: 894d9b6be5746e1e625022d805940b98aa0c0e3749bdbe7eb7776e9d69d6f826<br>packagename: com.backupphone.factory</p><p>On Oct 18th, I decided to search for new apks with no prior analysis to collect and test my skills with no clues. Thanks to <a href="https://x.com/malwrhunterteam">MalwareHunterTeam</a>, I found a sample called “secureandroid.apk” and began the static analysis using the well-known <a href="https://github.com/skylot/jadx">JADX-GUI</a> decompiler.<br>For those new to this field, I suggest watching my previous <a href="https://www.youtube.com/watch?v=4PqV8BBsA_Q">presentation</a> talking about tools and common procedures used when analyzing Android malware (in Portuguese).</p><p>While examining the decompiled apk, I realized that the malware wasn’t obfuscated, which facilitated the reverse engineering process and the understanding of how it works. The permissions defined in <em>AndroidManifest.xml </em>provide clues that the malware is a type of spyware. The requested permissions allow the malware to:<br> — Access Fine Geolocation<br> — Access the list of registered Services Accounts<br> — Monitor, redirect, and prevent outgoing calls<br> — Read Calendar, Call History, Contacts, External Storage, GMail, Web Browsing and Phone Information<br> — Send, receive and view SMS messages</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2sPJMLoS6hpakUmWEbjsMQ.png" /><figcaption>Malware Requested Permissions</figcaption></figure><p>Still in this file, one aspect that caught my attention was a Broadcast Receiver that listens to BOOT_COMPLETED and other related Intents. This class defines a method of system persistence that runs malware services as soon as the device boots. The malware executes by registering and listening to System Alarms. It creates alarms via AlarmManager to execute scheduled tasks responsible for stealing victims’ information over a defined short period.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/992/1*TZchzYkwtiI1AoiqCjJGWQ.png" /><figcaption>BroadcastReceiver that listens to BOOT_COMPLETED Intent and defines Alarms</figcaption></figure><p>In this file, I also noticed a function called “setWhatsAppRead”. Searching for the “WhatsApp” string, I found a class that implements functions to steal WhatsApp chat history and encryption keys. Since Android implements sandboxing, an application cannot access other data by default. Because of that, as seen in the snippet below, this application attempts to steal this data via root privilege (lines 381 and 400), so it will only be able to steal the data if the device is rooted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BCtRTh0Pi_3Y6kTTb4WPNg.png" /><figcaption>Dumping chat history to sdcard</figcaption></figure><p>The AndroidService and WebActivity classes are responsible for reading localDAO, where the victims’ information is stored locally, and sending it to the remote server. The IPs of the Command and Control server appear to be saved in a Google Docs file, but, as you will see, it is no longer available. The NotifyReceiver attempts to pull this file and store it locally in ip.txt.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/720/1*Be9OtK6S7Qj_nq-M48mxVQ.png" /><figcaption>NotifyReceiver runs principal Malware’s Services and pulls C2 data</figcaption></figure><p>The AppSetting class defines important strings such as Google Docs URL, and certificate paths.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/812/1*AKh5Rftz5qrBQ933rwzsIw.png" /><figcaption>AppSetting defines important strings</figcaption></figure><p>The Malware contains additional classes to listen for new incoming calls and messages to record, as well as mechanisms to maintain stealth, such as a Shutdown Broadcast Receiver to stop recording and shortcut deletion after the first run. It’s important to note that this last-mentioned functionality was disabled on Android Oreo (8.0) and later, and every application with an activity needs to have a shortcut.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/908/1*02uMeegChNpwbUuwxcM2RA.png" /><figcaption>MainActivity removes shortcut after first run</figcaption></figure><p>During the dynamic analysis, I used Android 5, LolliPop, to test it. As observed during the static analysis, just after running the app, its shortcut was deleted, and the SMS application popped up.</p><p>Then, I used adb to collect the ip.txt file. At the moment I was analyzing this sample, it was the Google Drive login page HTML. It shows that the content is no longer available.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-4twgJxzBALJmA5nS-0fXg.png" /><figcaption>ip.txt file containing Google Drive Login Page HTML</figcaption></figure><p>Moving to network analysis, I used BurpSuite to intercept the traffic from the device and its outbound connections. It constantly tries to pull the ip.txt file from Docs, but, likely, the threat actors or Google already [re]moved the file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-7nvIC6DRrnMJlHphtTPXg.png" /><figcaption>Request for file</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*luiVRljNizHxDW9RqCZuaA.png" /><figcaption>Reponse, getting 302 Moved Temporarily</figcaption></figure><p>Finally, examining the stored files, we first encounter the /.data1/log.txt file, which contains logs of the malware detailing every function call. Some files were not created because, for example, WhatsApp was not installed on the device.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/998/1*x0I0cwfXpjqYDE0DYlFG0Q.png" /><figcaption>Malware log</figcaption></figure><p>Examining the database created by localDAO, I found several tables related to the stolen data, including sms_logs, wifi_detail, gps_detail, and others.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8am1xhgwjNysZb63WVftHw.png" /><figcaption>Tables created by the malware</figcaption></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d5a2451c1c12" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hardware Hacking II: Router’s Firmware Modification]]></title>
            <link>https://medium.com/@luizboina55/hardware-hacking-modifying-an-old-router-firmware-to-play-a-snake-game-7e309484185a?source=rss-28eeecc3c052------2</link>
            <guid isPermaLink="false">https://medium.com/p/7e309484185a</guid>
            <category><![CDATA[hardware-hacking]]></category>
            <category><![CDATA[pentest]]></category>
            <category><![CDATA[hardware]]></category>
            <category><![CDATA[router]]></category>
            <dc:creator><![CDATA[luiz boina]]></dc:creator>
            <pubDate>Tue, 05 Sep 2023 21:56:14 GMT</pubDate>
            <atom:updated>2024-04-17T17:13:45.183Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Rb3VKH-H2ZeEApYTijeTzg.jpeg" /><figcaption><a href="https://www.pexels.com/pt-br/foto/fotografia-em-tons-de-cinza-de-hwak-416202/">By Pixabay on Pexels</a></figcaption></figure><h3>Introduction</h3><p>In <a href="https://medium.com/@luizboina55/hardware-hacking-playing-around-with-routers-e5f95c4b07f3">part 1</a> of this sequence of posts talking about pentesting routers, I found some interesting things like the correlation between the SSID, Serial Number, MAC Address, default password and ISP name.</p><p>I also showed How to identify the UART pins and how to use it to communicate with the router’s bootloader and gather information about the device like EEPROM chip name, linux version and so on.</p><p>In this post, I will extract the file system from the EEPROM to understand how it’s structured and which sensitive information I can gather or change from it. At the end of this post, you will see how I was able to modify the router portal to provide a path to play a snake game.</p><p>Of course, this study is only for educational purposes and there are a lot of bad things that a malicious actor can do with this scenario, like ARP or DNS poisoning, deploying a backdoor, sniffing, etc.</p><h3><strong>Firmware Extraction</strong></h3><p>If you read the first part, you already know that I bought two units of the same router and I accidentally broke one of them. Fortunately, the flash memory of this broken device wasn’t damaged and, since I don’t need the router working as a whole to read the memory, I used an EEPROM programmer, the CH341a, to read this memory.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*fSedwNU1Da6y-S8hv6tABg.png" /><figcaption>CH341a - The tool used to read/write to the flash memory</figcaption></figure><p>All we need to know about the EEPROM programmer is that it can read from 24xx and 25xx memory series and it will work since the router’s memory is a 25xx series (an MX25L12805D).</p><p>To correctly use the programmer to read the memory, I needed to plug the blue board on the correct pins of the programmer socket, as shown in the image, and to clip the alligator on the flash memory. For this step, I need to take care to clip the alligator pin with the red wire on the first pin of the flash memory, the one that has a dot notch on top (the datasheet can be consulted as well).</p><p>Actually, this scenario would be the best of the worlds but the place where the memory was soldered didn’t let me clip the connector correctly. So, I tried to remove it using a soldering iron but my soldering skills weren’t good enough. Therefore, I decided to remove the flash memory as simply as possible since the router was already broken: Cutting it from the PCB using a rotary tool.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XMXDCLaJVmv-RICZI9SX5w.jpeg" /><figcaption>Flash memory removed and ready to read using the programmer</figcaption></figure><p>After removing the flash memory from the board, I dumped the memory to a file using the “ flashrom” command, providing the chip name as argument to it knows which EEPROM it’s reading from:</p><p>sudo flashrom --programmer ch341a_spi -r &lt;extracted_bin&gt; -c MS25L12805D</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/902/1*CfoMCl5L8yyDUdZDbCmohg.png" /><figcaption>Flash memory read successfully</figcaption></figure><p>Got it! The content of the flash memory was extracted and now I can use Binwalk to search, extract and uncompress files that are in the file system stored on the memory. But before doing that, I checked the segments of the binary:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MN1i9t7zs9nwDftHb4dyUw.png" /><figcaption>Firmware segments</figcaption></figure><p>The output above shows that the firmware is compressed using the LZMA algorithm and there are two squashfs (filesystem). Generally, in embedded devices we have a duplicated file system for point-of-return purposes, so if some error occurs when upgrading the system we have a fallback.</p><p>After understanding what is present on the dumped file system, I used the -e flag of Binwalk to extract the content from the binary:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*t1gSerqeyxf8J_FagU3DCg.png" /><figcaption>Directory structure</figcaption></figure><p>Let’s dive into these directories and executables. The executable found were symbolic links pointing to the busybox file. BusyBox is a collection of UNIX softwares used on embedded systems for using commands like cat, login and ls and it also has dangerous commands such as telnet which can be used to deploy a simple and effective backdoor.<br>Looking for more relevant files I found the squashfs-root folder which contains scripts used for:</p><ul><li>Firmware upgrade;</li><li>IP and FQDN filters;</li><li>Led control.</li></ul><p>Some of these scripts are called when the router is booting and altering the file content makes it possible to do a lot of cool things, like playing a Morse code with the LEDs or configure the router to be used for another finality such as a local server or a NAS. The capability of changing these files and writing them back to the router also can open the way for threats, like DNS poisoning, deploying package sniffers and backdoors.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*TjQGKbMIbpLcqbcLWjPK_g.gif" /><figcaption>Edward Wong and Ein floating around</figcaption></figure><p>The objective here is to embed a snake game on the router portal so I didn’t spend too much time on other files. Searching for HTML and JavaScript files I found the portal folder and discovered that it was using the “Boa WebServer”: An open source and relatively old web server designed for embedded systems. Starting from that, everything I needed was to create a new path for the snake game and add the source code of the game itself.</p><p>Since I need to unpack the binary, modify it, and pack it again, I prefer to develop my own script to achieve it instead of using Binwalk. The script above does two things depending on what I want. The script unpacks the binary by splitting it into three parts: Everything that goes before the file system, the file system itself, and everything that goes after the file system. It also packs the three parts in one again:</p><pre>#!/usr/bin/env python3<br><br>import sys<br><br>class FirmwarePart:<br>    def __init__(self, name, offset, size):<br>        self.name = name<br>        self.offset = offset<br>        self.size = size<br><br>firmware_parts = [<br>    FirmwarePart(&quot;all_compressed_header&quot;, 0x0, 0x14FAC1),<br>    FirmwarePart(&quot;squashfs_1&quot;, 0x14FAC1, 0x800200),<br>    FirmwarePart(&quot;all_compressed_data_footer&quot;, 0x800200, 0x91FB97),<br>]<br><br>if sys.argv[1] == &quot;unpack&quot;:<br>    f = open(sys.argv[2], &quot;rb&quot;)<br>    for part in firmware_parts:<br>        outfile = open(part.name, &quot;wb&quot;)<br>        f.seek(part.offset, 0)<br>        data = f.read(part.size)<br>        outfile.write(data)<br>        outfile.close()<br>        print(f&quot;Wrote {part.name} - {hex(len(data))} bytes&quot;)<br>elif sys.argv[1] == &quot;pack&quot;:<br>    f = open(sys.argv[2], &quot;wb&quot;)<br>    for part in firmware_parts[0:]:<br>        i = open(part.name, &quot;rb&quot;)<br>        data = i.read()<br>        f.write(data)<br>        padding = (part.size - len(data))<br>        print(f&quot;Wrote {part.name} - {hex(len(data))} bytes&quot;)<br>        print(f&quot;Padding: {hex(padding)}&quot;)</pre><p>The correct size and offset was obtained via binwalk and then I ran dd in the last data segment (0x800200) to know the exact size of the last segment. To finish this step, I ran the developed script to unpack the firmware and uncompress the squashfs:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KAE_-ce3zHUzoGUQvNEi0A.png" /><figcaption>Decompressing squashfs</figcaption></figure><p>The same pattern obtained when I used Binwalk was obtained on the unpacked filesystem when I used the developed script, so it is time to change the content of Boa Server. Searching through the folders and understanding how the portal was implemented, I found that the boaroot folder contains the content of the portal. I found the two files responsible for the path text, and its translation in Portuguese and English, and the HTML file that contains the portal paths. I modified these two files to add the “Play/Jogar” text and the new path for the snake game.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/847/1*4vX76wsIFsWBaSFE_eAFrg.png" /><figcaption>menu text translation</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LIDnDjyb84KPC1y1xrD9Aw.png" /><figcaption>Adding option</figcaption></figure><p>So I added the snake.html file on the root folder of the project that contains all the code needed to execute the game.</p><p>With all modifications done, I just needed to compress the squashfs and join the three parts of the unpacked binary in one again to write it back to the flash memory. Before compressing the squashfs, I needed to exam the original compressed data to know the compression method used, and the block size:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q4VyAJ9EPZRzno4ImujPRQ.png" /><figcaption>Compressing modified file system</figcaption></figure><p>Running unsquashfs -s squashfs_1, I obtained that the compression method utilized was the LZMA, and the block size was 131072 bytes. Then I used the mksquashfs to generate the new modified squashfs. Finally I packed the binary in one, and I wrote it back to the router using the CH341a.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/594/1*Ygp9jh_x7rxKS5wSUb7qbA.png" /><figcaption>Packing the new binary</figcaption></figure><p>But, before writing the new firmware to the router, I got stuck on how to clip the alligator on the EEPROM since we had components blocking me from correctly connecting the alligator to the board. So, instead of thinking of solutions that involve soldering or bending the UART pins of the board, I simply used the rotary tool to carefully trim the edges and reduce the width of the alligator clip.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*j5J6uv_ZHEkSupbu-XVGRg.jpeg" /><figcaption>Writing the new modified firmware</figcaption></figure><p>Finally, it’s time to turn on the router, cross the fingers and pray to it boots correctly. Connecting to the router’s network and accessing the portal, I saw the new added path and I was able to play the embedded snake game. In the video below, you can see the final result (I add some censors to the video to conceal the ISP name):</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2Fj14Ftb9pDuU%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3Dj14Ftb9pDuU&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2Fj14Ftb9pDuU%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/f6230f61d3bf259ce2d4e4a929b1aeef/href">https://medium.com/media/f6230f61d3bf259ce2d4e4a929b1aeef/href</a></iframe><h3>Conclusion</h3><p>I assume I got myself stuck in a lot of parts, mainly on how to understand more about firmware segments and compression methods. Doing this kind of activity was actually pretty fun and I was really engaged in making a device doing something that it wasn’t supposed to do. I encourage every person who is interested in this area to get an old device and start looking at it with other eyes and try to understand more on how it works and what you can change.</p><h3>References</h3><ul><li><a href="https://www.youtube.com/watch?v=hV8W4o-Mu2o">Stacksmashing</a></li><li><a href="https://www.youtube.com/@MakeMeHack/videos">Make Me Hack</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7e309484185a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hardware Hacking I: Playing around with routers]]></title>
            <link>https://medium.com/@luizboina55/hardware-hacking-playing-around-with-routers-e5f95c4b07f3?source=rss-28eeecc3c052------2</link>
            <guid isPermaLink="false">https://medium.com/p/e5f95c4b07f3</guid>
            <category><![CDATA[pentest]]></category>
            <category><![CDATA[router]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[pentesting]]></category>
            <category><![CDATA[hardware-hacking]]></category>
            <dc:creator><![CDATA[luiz boina]]></dc:creator>
            <pubDate>Thu, 31 Aug 2023 03:25:13 GMT</pubDate>
            <atom:updated>2024-04-17T19:08:52.496Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MBASJrqIrM-RGXlq1E9MlQ.jpeg" /><figcaption><a href="https://www.pexels.com/pt-br/foto/close-up-disparou-sobre-uma-coruja-3940911/">By Vincent on Pexels</a></figcaption></figure><h3>Introduction</h3><p>This is the first part of a series of articles I will post to talk about hardware hacking and share what I learned during the analysis. In this one in particular, I will talk about what I found analyzing a relatively old router that I bought last month at a street market in my neighborhood.</p><p>I will bring some interesting content that I found when analyzing this equipment just by reading the router label, and how to find the correct UART pins to communicate with the router. I really suggest you read more about what the UART protocol is, but in summary this protocol uses two pins for data transfer, one to send and another to receive, and other two for ground and power supply. As we will see, we don’t need to use this last one since the equipment is already turned on by the power supply cable.</p><p>After some hours studying about this topic, I decided to buy old devices and start practicing what I have learned. At the market I bought three routers for R$30.00 ( roughly US$ 6.00), two of them are the exact same, a dsl-100hn-t1-nv, and they will be the focus of this article. The strategy of getting two of the same device is desired because if any problem happens (yes, it happened), I will have another one to continue the research.</p><h3>Let’s Go, Kitty!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pVqn4eI3pna30PKCkI9qXA.jpeg" /><figcaption>my cat helping me to hack this very dirty old router</figcaption></figure><p>I started analyzing the information printed under the router, in the router label, such as the MAC address, the SSID and, correlating it with the default password, I got some interesting information which I hadn’t ever paid much attention to before studying this topic. What I initially noticed was the following:</p><ul><li>The Serial Number, SN, is equal to MAC Address;</li><li>The SSID is the name of the ISP along with the last 2 bytes of the MAC, “E8B0”;</li><li>The default password of the router is the last 5 bytes of the MAC address, “33D717E8B0”.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QyuaIrme3grarqdJZ7NLLg.jpeg" /><figcaption>Some information was removed to conceal the identity of the ISP</figcaption></figure><p>Opening the router case, I quickly identified the UART pins since the male pins were already soldered on the board. The EEPROM (Electrically Erasable Programmable Read-Only Memory) was really close to the soldered pins and, because of that, I needed to warp this a little bit to be able to connect the ch341a, an EEPROM extractor, on the memory, but it’s material for another post.</p><p>I will discuss more about the memory in the next post, but I have some useful information I want to say here for those who want to enter this area. First, I wasn’t able to read the memory chip name because it was blanky but we have methods like chalking over to make the words more visible. Second, you may not want to spend so much time with it since you can get this information and more about the EEPROM via UART protocol, during the router boot, as we will see below.</p><p>To communicate with the router using the UART interface we need a serial to USB converter and I used the PL2303 for that. In a UART connection, one thing you need to pay attention to is to connect the sender pin, also known as TX, of the converter to the receiver, also known as RX, of the router and vice-versa, since one will read what the other is sending.</p><p>So, using a multimeter in continuity test mode, I was able to identify the ground pin testing each UART pin with the negative leg of the capacitor present on the circuit (it’s the leg below the gray line). After that, I needed to discover which pin is the output voltage, the Vcc. To do that, I turned on the router and tested every pin to find out which one had a more stable voltage, and to do that I put one probe on the ground and another on the pin that I wanted to test. Doing that, I found that the last pin, to the left to the right, was the Vcc. I didn’t need to use this pin since the circuit already will be charged by the 12V power supply.</p><p>At this point, if I make any mistake guessing which pin is the TX or the RX I will not blow the board. So, to identify which one is the TX, I booted the device and with one probe of the multimeter on the ground and another taking turns testing the two pins left, I paid attention to identify which one had more voltage variation and which one was less variation and/or voltage equal to zero. The pin with more variation during the boot probably is the TX and the one with less variation or zero voltage will be the RX. It happens because, when a device is booting, a lot of information is transmitted so we have more voltage variation on TX because of this data transfer.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*n_zcLcSnSQfOD2fm1sB4bg.jpeg" /><figcaption>router connected to the laptop via serial to usb converter</figcaption></figure><p>At some point of the research I accidentally dropped my phone on the board trying to take pictures of the connections. Since I bought two units of the same router, I was able to continue the research taking more care in this last shoot. The broken router board started to get really hot and the UART Vcc dropped from 3.3V to 0.28V. Probably a short circuit happened and, because of that, I started again with another router.</p><p>This accident didn’t make the broken router totally useless. In the second part of this series I will try to read the EEPROM of this broken router and fortunately, it will work. It’s possible because when we are interacting with the EEPROM using a tool like CH341a, we don’t need to turn on the equipment as a whole, just the memory, and the tool provides connections to do that. It’s done this way since we don’t want interference caused by a concurrency reading between the CH341a and the rest of the device.</p><p>Continuing, I used a handful command to prompt a shell and interact with the router called <em>screen</em>. To do so, I need to know the tty device of my converter and the baudrate. The first one was easy to find because I just have one connected to my laptop, so I ran the ls /dev/tty* command and found that was <em>/dev/ttyUSB</em>.</p><p>Now we need a few things before being able to see the router’s boot data and interact with it using the UART. First, we must identify where the serial to usb converter was mounted and to do so I just runned the `ls /dev/tty*` and found it on /dev/ttyUSB. Then, we need a tool to see the bootloader output and send commands to the router, and to do so we can use the `screen` command. The Screen command is a tool that enables us to open a shell session passing the port where the device was mounted, in this case /dev/ttyUSB, and the baud rate. Since in UART communication we don’t have any wire to share the baud rate (bits per second) we need to discover it by guessing. Exists tools to brute force and automate the process of guessing but just testing the more common baud rates, like 19200, 115200, 38400 and 57600, I was able to identify that the 115200 was the correct one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vsRyKGlJwtkMir3am-fp5w.png" /><figcaption>Wrong guess! can’t read any data here, right?</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MQ2AlyNo9miNiDLEwcOBdw.png" /><figcaption>available commands before boot completes</figcaption></figure><p>Nice! Now I was able to read the initial logs generated during the boot process and I stopped it to interact with the U-boot, the bootloader. The HELP command gave me the list of available commands. It has some useful commands like: ATSH, which prints more information about the device; ATEN, which switches the router to debug mode to unlock more commands. For example, one of the debug commands permits me to dump the memory via UART (which is very slow because of baud rate).<br>Running ATSH I was able to get more information about the manufacturer, checksums and other interesting information.</p><p>Proceeding to full boot of the system, I used the flag “-L” so the screen command will save the logs into a file to better analyze the output when the boot completes. The more relevant information gather was:</p><ul><li>Linux version: 2.6.36 (gcc 4.3.4);</li><li>Memory location of each partition, which will be used later to dump the filesystem and the firmware;</li><li>EEPROM name and type, a SPI Flash MX25L12805D;</li><li>Used softwares and its versions.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6lbRN7vaO5vy8Dmg9EFIpg.png" /></figure><p>At the end of the boot process, a /bin/login was prompted to authenticate and access the router CLI. In the next post I will talk more about interesting things found during the firmware analysis.</p><h3>Conclusion</h3><p>For me, the funny part of pentesting a hardware compared to a web server is that you make more things with your hands, will get stuck more often in problems that you can’t easily find the solution on the internet, and will need to find how to solve the problem on your own. I don’t have a big background in this area, so if something wasn’t clear or if you think that I made some wrong assumptions, please get in contact with me via email or LinkedIn, it will be very helpful!<br>I see you in the next post!</p><h3>Reference</h3><ul><li><a href="https://www.youtube.com/@MakeMeHack">https://www.youtube.com/@MakeMeHack</a></li><li><a href="https://learn.sparkfun.com/tutorials/serial-communication/all">https://learn.sparkfun.com/tutorials/serial-communication/all</a></li><li><a href="https://openwrt.org/toh/zyxel/nbg460n">https://openwrt.org/toh/zyxel/nbg460n</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e5f95c4b07f3" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>