<?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 wh00hw on Medium]]></title>
        <description><![CDATA[Stories by wh00hw on Medium]]></description>
        <link>https://medium.com/@wh00hw?source=rss-119b5b848606------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*sC5lzx5bzfODnQLF9vQwQw.jpeg</url>
            <title>Stories by wh00hw on Medium</title>
            <link>https://medium.com/@wh00hw?source=rss-119b5b848606------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 01:39:51 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@wh00hw/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[I Made The First Ever Player Gender Transition In A Pokemon GameBoy Game]]></title>
            <link>https://medium.com/@wh00hw/i-made-the-first-ever-player-gender-transition-in-a-gameboy-pokemon-game-d7778c65a081?source=rss-119b5b848606------2</link>
            <guid isPermaLink="false">https://medium.com/p/d7778c65a081</guid>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[pokemon-rom-hacks]]></category>
            <category><![CDATA[pokemon]]></category>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[gameboy]]></category>
            <dc:creator><![CDATA[wh00hw]]></dc:creator>
            <pubDate>Wed, 08 May 2024 17:03:34 GMT</pubDate>
            <atom:updated>2024-05-10T10:54:50.210Z</atom:updated>
            <content:encoded><![CDATA[<h4>Yep, for real, but with some memory manipulations (I KNOW YOU LOVE IT)</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*FQPCy_jqr-koL4WN" /></figure><h3>DISCLAIMER</h3><blockquote>The article is not intended to be offensive or underestimate the sensitivity of others. It is proposed as a reverse engineering and nerd hobby research project.</blockquote><h3>Yellow Legacy is a thing</h3><p>As a nostalgic Pokemon GameBoy fan, I used to watch a lot of youtuber playing the newest hack-ROMs. I came across Pokemon Yellow Legacy, in my opinion a great ROM that made Yellow finally playable. There are a LOT, trust me, a A LOT of improvements including stats, trainers and even the Gen 1 lore.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*GhF8Vw7pVGITlEE3NEOyJw.png" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FjTH2fVqHPwc%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DjTH2fVqHPwc&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FjTH2fVqHPwc%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/297ff562f7f9c89eb1645a2194563fda/href">https://medium.com/media/297ff562f7f9c89eb1645a2194563fda/href</a></iframe><h3>BOYs and GIRLs</h3><p>Most of you know that gender selection was released only after Gen 2 Pokemon Crystal, but the guys did the work.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/319/1*lsSDWNEQdU-bDXRWVoZEtA.png" /></figure><h3><strong>I was in a rush, and I selected BOY then I realized how COOL was the GIRL sprite. DAMN!</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/618/1*s5zT6B7fVbjpMSFTqAZsmA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*ziAAQ7XvduuBdaSngvvP_g.png" /></figure><h3>GRRRL POWA</h3><p>Well, I was too lazy to start a new game, even if I’ve just only obtained the second gym badge, I already loved my Pokemon and mostly, I was not mentally prepared to do Viridian Forest and Mt. Moon again in such short time.<br><strong>But… I really want to play as a GIRL!</strong> <br>The Pokemon hack-ROM scene is great, there are plenty of tutorial useful to understand how the game works and how to add new custom features.</p><p>So there was only one thing left to do…</p><h3>Flip that bit !!!</h3><p>The idea was to understand how the guys added the gender feature and where the game stores the gender selection in the save file, then manipulate the memory accordingly.<br>Luckily, they provided some detailed docs about the mods.</p><p><a href="https://github.com/pret/pokered/wiki/Adding-Gender-Selection-(original-tutorial-done-by-Mateo)">https://github.com/pret/pokered/wiki/Adding-Gender-Selection-(original-tutorial-done-by-Mateo)</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/1*2a6w2ZsDiIpjDUjZb-Chug.png" /></figure><p>The <em>wram.asm </em>contains all the working RAM flag slots used to track the progress and the player info. They add a new flag <em>wPlayerGender </em>allocating 1 byte (ds 1, “define space of 1 byte”) to store the gender selection, so that 0x00 is BOY and 0x01 is GIRL. Once the player saves the game, a portion of the WRAM is stored in the SRAM creating your save data.</p><p>By reading the original Pokemon Yellow assembly code, I managed to find out, more or less, where they put the gender flag.<br><a href="https://github.com/pret/pokeyellow/blob/b135272f9510ed78e8c062efe552d6dbdcc1523f/ram/wram.asm#L2299">https://github.com/pret/pokeyellow/blob/b135272f9510ed78e8c062efe552d6dbdcc1523f/ram/wram.asm#L2299</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/540/1*QH1VPtXRvaFWmJEECiVZcA.png" /></figure><p>But at which exact memory address is that byte located in the save file? I struggled a <em>bit</em> trying to find the memory offset, when suddenly a Bulbapedia page gives me some hints.<br><a href="https://bulbapedia.bulbagarden.net/wiki/Save_data_structure_(Generation_I">https://bulbapedia.bulbagarden.net/wiki/Save_data_structure_(Generation_I</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/332/1*ivx_lU3vjpzOFeSUP4aBCQ.png" /></figure><p>The gender flag is somewhere between the Completed Scripts (<em>wGameProgressFlagsEnd</em>, address <strong>0x289C</strong>) and Owned Hidden Items ( <em>wObtainedHiddenItemsFlags, </em>address <strong>0x299C</strong>) memory locations.</p><p>To avoid further headaches, I created two brand new save files, in the first I started a new game as a BOY, in the second as a GIRL. Then I compared the diffs using an hex editor, <strong>expecting a byte flipping from 0x00 to 0x01</strong> in the memory slice [<strong>0x289C:0x299C</strong>].</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/597/1*7DMzIgEn9Q-YU4VjSsCRDw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/591/1*n4mC7qAw5-r-Yhtj1GcA6g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*gjp9VIk38LqgXrXX.gif" /></figure><p><strong>Is that our <em>boy</em>?</strong></p><p>I flipped that bit at the address 0x2965 from 0x00 to 0x01, saved the file, booted in the emulator and then…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/319/1*raLS_hT6e-knul4DhEc2QQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/316/1*K2U7vr29n0i1ZGGzl9uSmQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/0*EGdJV-noMWN2133I.gif" /></figure><h3>Not all math jokes are bad, just sum.</h3><p>Ok, I went back to the docs, I was sure I missed something. Sure!!</p><p><strong>The checksum.</strong></p><p>As Bulpapedia says:</p><blockquote>Used to validate the integrity of saved data.</blockquote><blockquote>The checksum in Generation I is only 8 bits and has a single copy of it. If this value is incorrect, the error message “The file data is destroyed!” will appear after the title screen, and the continue option will not appear in the menu.</blockquote><blockquote>The algorithm used to calculate the checksum is as follows:</blockquote><blockquote>Initialize the checksum to 0</blockquote><blockquote>For every byte from 0x2598 to 0x3522, inclusive, add its value to the checksum</blockquote><blockquote>Invert the bits of the result</blockquote><blockquote>An equivalent way to achieve the same result is:</blockquote><blockquote>Initialize the checksum to 255</blockquote><blockquote>For every byte from 0x2598 to 0x3522, inclusive, subtract its value from the checksum</blockquote><p>Got it, if we modify the save file we need to recalculate the checksum as the algorithm explain, which is stored at the address 0x3523. In fact our gender flag (0x2965) is inside the memory slice [0x2598:0x3522]</p><p>There’s still hope…</p><h3>GIST or die</h3><p>Finally, I’ve created a Python script that reads a save file, creates a backup, toggles the gender, recalculates the checksum, and saves the result in place.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/c6f7116dfa87c586a416a3b9f1d91ccb/href">https://medium.com/media/c6f7116dfa87c586a416a3b9f1d91ccb/href</a></iframe><h3>Conclusions</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*VZwvJqNR4WgwFlzev2bI2w.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/318/1*WmztFuotYSnmi0eXA-JZBA.png" /></figure><pre>$ python pkmn_yl_gender_switch.py Pokemon\ -\ Yellow\ Version\ \(UE\)\ \[C\]\[\!\]\ \(patched\).sav<br>Gender transition to GIRL and checksum fixed successfully.<br>Backup file created: Pokemon - Yellow Version (UE) [C][!] (patched).bak</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/314/1*hf1kA7GuM1JdynVDwNcXeQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/316/1*VZmfihIwvJso8ilLrfcJJQ.png" /></figure><h3>Thank you for your attention!</h3><p>If you like it, please consider giving it a clap! 👏</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d7778c65a081" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Reply Cyber Security Challenge 2023: CODING 100 Writeup]]></title>
            <link>https://medium.com/@wh00hw/reply-cyber-security-challenge-2023-coding-100-writeup-25ae41464aaa?source=rss-119b5b848606------2</link>
            <guid isPermaLink="false">https://medium.com/p/25ae41464aaa</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[ctf-writeup]]></category>
            <category><![CDATA[leetcode]]></category>
            <dc:creator><![CDATA[wh00hw]]></dc:creator>
            <pubDate>Tue, 17 Oct 2023 10:28:47 GMT</pubDate>
            <atom:updated>2023-10-17T10:28:47.231Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/677/1*8AGYxHWEkHOPszq9b0bi0Q.png" /></figure><p>The challenge consists of several levels, each of which provides a text file, lvl_&lt;level&gt;.txt and a zip file lvl_&lt;level&gt;.zip containing the next Sudoku puzzle to solve. Once we have the correct sudoku values, we can use them as the password to extract the contents of the corresponding zip file for that level. The last zip file should contains flag.txt</p><p>The README file shows the solving rules, there are some arithmetic constraints applied to each regions rappresented by non-square matrix.</p><pre>Solve the Sumdoku following the rules:<br>- you are given a grid NxN:<br> - fill in the grid with all numbers from 1 to N in each row and column;<br> - no repetitions are allowed on rows and columns;<br>- cells are grouped in regions, represented by a lowercase letter:<br> - for each region, in the input file is defined a result and an operation: you have to fill in the cells in each region so that the operation between all cells in region produces the given result;<br> - operations allowed:<br>  - &quot;+&quot;: sum all cells in the region to get the provided result;<br>  - &quot;*&quot;: multiply all cells in the region to get the provided result;<br>  - &quot;-&quot;: subtract the max number minus the min number to get the provided result (size is limited to 2 cells);<br>  - &quot;/&quot;: divide the max number to the min number to get the provided result (size is limited to 2 cells).<br><br>The solved grid, read by rows, gives you the password for the zip on next level.</pre><pre>## Challenge example<br><br>INPUT:<br><br>a b b c c<br>a d e e c<br>f d g h h<br>f g g g i<br>j j k k i<br><br>a 3 +<br>b 10 *<br>c 12 +<br>d 7 +<br>e 4 /<br>f 15 *<br>g 10 *<br>h 1 -<br>i 4 *<br>j 9 +<br>k 6 *<br><br><br><br>The solved grid is:<br><br>1 2 5 4 3<br>2 3 4 1 5<br>5 4 1 3 2<br>3 1 2 5 4<br>4 5 3 2 1<br><br><br>SOLUTION: 1254323415541323125445321ma</pre><h3>Solution</h3><p>So we have a matrix NxN (Variables), where each cell could assume values in the range [1, N] (Domains), and we have a set of Constraints.</p><h4><a href="https://github.com/wh00hw/ReplyCyberSecurityCTF2023-coding-100#constraint-satisfaction-problem-csp">Constraint Satisfaction Problem (CSP)</a></h4><p>A Constraint Satisfaction Problem is a formal framework for representing and solving problems where a set of variables must be assigned values while satisfying a set of constraints. In this CTF challenge, the CSP includes:</p><ol><li><strong>Variables</strong>: These are represented by n_&lt;r&gt;_&lt;c&gt;, where r and c represent the row and column indexes in the grid. The goal is to find values that satisfy the constraints.</li><li><strong>Domains</strong>: The domain for each variable is the integers from 1 to N, where N is the size of the grid. Variables are assigned values from this domain.</li><li><strong>Constraints</strong>: Constraints are rules that define the relationships between variables. In this challenge, there are three types of constraints:</li></ol><ul><li><strong>Uniqueness Constraints</strong>: No two cells in the same row or column can have the same value. This is implemented with lambda functions that ensure different values for variables in the same row or column.</li><li><strong>Region Constraints</strong>: These are specific to regions in the grid marked with letters. Depending on the operator (‘+’, ‘*’, ‘-’, ‘/’), constraints are added to ensure the values in the region satisfy the given operation.</li></ul><h4><a href="https://github.com/wh00hw/ReplyCyberSecurityCTF2023-coding-100#recursive-backtracking-algorithm">Recursive Backtracking Algorithm</a></h4><p>Recursive Backtracking is a systematic search algorithm used to solve CSPs by exploring the possible assignments of values to variables. It works as follows:</p><ol><li><strong>Variable Selection</strong>: Choose an unassigned variable. In this challenge, variables represent the grid cells, and they are typically chosen in a predefined order.</li><li><strong>Value Assignment</strong>: Assign a value from the variable’s domain to the chosen variable.</li><li><strong>Constraint Propagation</strong>: Check if the assignment violates any constraints. If it does, backtrack and try a different value for the variable. If the assignment is valid, proceed to the next unassigned variable.</li><li><strong>Recursive Exploration</strong>: Repeat steps 1 to 3 for all unassigned variables. If a solution is found, return it. If a variable has no valid assignments left, backtrack to the previous variable and explore a different assignment.</li></ol><h4><a href="https://github.com/wh00hw/ReplyCyberSecurityCTF2023-coding-100#applying-recursive-backtracking-to-the-challenge">Applying Recursive Backtracking to the Challenge</a></h4><p>In this context, Recursive Backtracking is used to search for valid assignments of values to the grid cells (variables) while respecting the CSP’s constraints. Here’s how it works:</p><ol><li><strong>Variable Selection</strong>: Variables are typically selected in the order they appear in the grid. This ensures that the solver explores the puzzle systematically.</li><li><strong>Value Assignment</strong>: Values from the domain (1 to N) are assigned to the chosen variable.</li><li><strong>Constraint Propagation</strong>: The constraints are enforced during each assignment. If a constraint is violated, the solver backtracks to the previous variable and explores a different value.</li><li><strong>Recursive Exploration</strong>: The solver iterates through the variables recursively, attempting to find a valid assignment for each variable. If a solution is found, it is used as the password to extract the corresponding zip file. If a variable has no valid assignments left, the solver backtracks and explores different values for the previous variables.</li></ol><p>By following this process, the solver systematically explores the search space of variable assignments until it finds a valid solution.</p><h4>The Python Solver</h4><p>The solution involves using a constraint satisfaction problem solver to find a valid assignment of values to the variables. The code provided uses the constraint library to formulate and solve the problem. The process can be broken down as follows:</p><ol><li>Read the sudoku constraints from the text file for the current level.</li><li>Create variables for each cell in the grid and set their domains to integers from 1 to N.</li><li>Add constraints to ensure that no two cells in the same row or column have the same value.</li><li>For each region, add constraints based on the region’s specified operation (‘+’, ‘*’, ‘-’, ‘/’).</li><li>Solve the constraint satisfaction problem to find a valid assignment of values.</li><li>Use the obtained values as a password to extract the contents of the corresponding zip file.</li><li>Repeat from 1. until a flag.txt file is extracted</li><li>Print the flag.</li></ol><p>You can find solver.py here</p><p><a href="https://github.com/wh00hw/ReplyCyberSecurityCTF2023-coding-100">GitHub - wh00hw/ReplyCyberSecurityCTF2023-coding-100</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/884/1*wXNawRnCl08UMWLnQi2xAg.png" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=25ae41464aaa" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Vendors Still Allow You to Hack Their Vending Machine]]></title>
            <link>https://medium.com/@wh00hw/vendors-still-allow-you-to-hack-the-vending-machine-34ddad81dbad?source=rss-119b5b848606------2</link>
            <guid isPermaLink="false">https://medium.com/p/34ddad81dbad</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[coffee]]></category>
            <category><![CDATA[electronics]]></category>
            <dc:creator><![CDATA[wh00hw]]></dc:creator>
            <pubDate>Sat, 01 Oct 2022 19:21:38 GMT</pubDate>
            <atom:updated>2023-02-21T14:29:54.483Z</atom:updated>
            <content:encoded><![CDATA[<p>So if your company doesn’t include coffee in your contract, well, I’ll show you how to get it for free using a 90’s trick.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*mNVOFFswNCV5NV_u.gif" /></figure><h4>Addiction</h4><p>Another day, another dozen coffees, another hacking journey.</p><p>I was chilling in the relax area of the company I work for, but that was not a common coffee break. My eyes stared at the coffee vending machine at some point in a different way. I used to buy coffee by scanning the QR code with the vendor app to pay with credit card but the vending machine allows also to insert coins and a proprietary pen on which you can charge money. I asked to myself: “<em>Why is that pen still adopted</em>?”. In fact I saw a lot of employee using it, probably the boomers are uncomfy with the app?</p><p>Anyway that pen didn’t feel so secure to me and here the journey started.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/460/0*cJatNMO2ojCnddYO.gif" /></figure><h4>The “Bible” and those legendary guys</h4><p>I was sure, someone else had to have already hacked that thing, In a few step, hopping forum by forum I came across a real cyberpunk stuff.</p><p>It’s the year 2001, the web is a bunch of gif and various unknown forums. Some crazy anonymous electronic students release a document on how they reverse engineered the coffee pen, they called it the “Bible”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*ETZfCxwtKiAGWkau.gif" /></figure><p>The article was written in a proto-Medium style, with a lot of funny comments between the sentences.</p><h4>The pen</h4><p>The first part of the article explains how the pen is built and how to open it. In fact, the PCB is within an hard resin block, and a solvent to melt it is needed. <br>So I asked my girlfriend for nail polish remover and told her I care about my hand care.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/373/0*0PStcTC7ZUg0yfwr.gif" /></figure><p>After a lot of manual work in order to avoid to destroy the circuit, the PCB was clean. It seemed to be just an EEPROM, with an LC circuit.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/814/1*BL-QE4PuEJl4hvUAHs3KtQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/295/1*mbSq0_Xj9sUujts99GoLtg.jpeg" /></figure><h4>Memories</h4><p>Great! I got the EEPROM pinout exposed, the article specify the model: <strong>Mircrochip 24c02 . </strong>The EEPROM has 256 bytes memory and with just 4 wires I can read and write via I2C.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/1*UHn25vw1nJpBTVngrVIZ7Q.jpeg" /></figure><p>But I needed a micro-controller programmer to communicate with it. I searched my old high school box full of electronic stuff I soldered and I found the <strong>Pickit2 </strong>that I used to program the PIC16F1827 when I was young.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*lnO22kMKx1xZeKoZ.gif" /></figure><h4>Connections</h4><p>The EEPROM has a simple pinout, 1,2,3,4, and 7 connected to ground (it enables write mode). The pin 6 is the clock, 8 VCC (from 3.3 V to 4.5 V), and 5 is the data. The Pickit2 needs one 10k ohms pull-up resistor between VCC and SDA. I didn’t have it, so I used a trimmer carefully calibrated.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KkJae0vd4VTgPKOcYD4oEw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/899/1*g76Q1aVzoLmsSR0YBR_L8w.jpeg" /></figure><p>I admit, it has been so much time since the last solder I did…</p><h4>Gimme those bytes</h4><p>Ok, everything was ready. I launched the Pickit2 software, selected the EEPROM device, pushed the read button praying God I didn’t burn anything aaaand…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/673/1*G8K-yj1n-6He9e3bIB2BKQ.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*Ud3VO-5rEc7MIW4X.gif" /></figure><blockquote>Here comes the dump, doo-doo-doo-doo.</blockquote><h4>Insert coin</h4><p>Well, I got the dump, but what was the meaning of those bytes? Fortunately those legendary guys did a great work. The second part of the article tells how they understand, inserting coins by coins, where the credit is stored by seeing which bytes changed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/332/1*qXDVlnqrINl0SmZNPnjZ7A.png" /></figure><p>The credit is 4 byte long starting from 0x44 and it’s 0.04 €</p><p>Why?</p><p>80C041C0</p><p>For each byte take the lowest hexadecimal nibbles</p><p>0 0 1 0</p><p>Convert them to binary with four zeros padding</p><p>n₃ = 0000 <br>n₂ = 0000<br>n₁ = 0001<br>n₀ = 0000</p><p>Split each nibble in 2 bit high e 2 bit low</p><p>h₃= 00, l₃= 00<br>h₂ = 00, l₂= 00<br>h₁ = 00, l₁ = 01<br>h₀ = 00, l₀ = 00</p><p>These are the <strong>base 4 </strong>coefficients of the base 2 exponents.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/202/1*GtmPnAmaehg_33IFixG1CQ.png" /></figure><p>0*2¹⁴ + 0*2¹² + 0*2¹⁰ + 0*2⁸ + 0*2⁶ + 0*2⁴ + <strong>1</strong>*2² + 0*2⁰ = 4 = 0.04 €</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/0*tNyLObSaZJfI_RfR.gif" /></figure><p>Feel confused? No worries, I was too, that’s why I wrote some lines of python code to better understand the algorithm.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3269b60c01bd0a2613068bf35bea9274/href">https://medium.com/media/3269b60c01bd0a2613068bf35bea9274/href</a></iframe><p>So the maximum credit value available must be:<br>3*2¹⁴ + 3*2¹² + 3*2¹⁰ + 3*2⁸ + 3*2⁶ + 3*2⁴ + 3*2²+ 3*2⁰ = 65535 = 655.35 €</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*tecfEGIii2LIxs0u.gif" /></figure><p>Going backwards to the bit notation</p><p>h₃= 11, l₃= 11<br>h₂ = 11, l₂= 11<br>h₁ = 11, l₁ = 11<br>h₀ = 11, l₀ = 11</p><p>That leads to our lowest nibbles in base16<br>F F F F</p><p>Cool! So can I replace those nibbles (8<strong>F</strong> C<strong>F</strong> 4<strong>F</strong> C<strong>F) </strong>in order to have 655.35 € instead of 0.04 €?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*OfK16V2xqPcb-kWd.gif" /></figure><p>Nope.</p><h4>The “Check”sum</h4><p>Another little step is required, in fact take a look at the credit bytes<br><strong>8</strong>0 <strong>C</strong>0 <strong>4</strong>1 <strong>C</strong>0<br>What about the highest nibbles we’ve not considered yet?<br>8 C 4 C<br>They seem to be a sort of checksum, and they discovered it only depends from the value of the credit.</p><p>The forumla is:</p><p>Ehm, I’m not able to describe it in math notation, sorry, here’s the code</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4ace92aac0303a086e69c6e642ee6ec3/href">https://medium.com/media/4ace92aac0303a086e69c6e642ee6ec3/href</a></iframe><h4>The Backup</h4><p>For some reason, the 4 bytes starting from 0x54 are the backup. Probably in case of fault the vending machine can restore the correct credit. Fortunatly it differs just in one nibble, in fact the backup is calculated by decrementing the second checksum nibble by 4.</p><p>So if the credit is<br>80 <strong>C</strong>0 41 C0<br>the backup is<br>80 <strong>8</strong>0 41 C0</p><p>C — 4 = 8</p><p>Easy.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/0*qynrVPXupvPs0ulG.gif" /></figure><h4>The Coffee Editor</h4><p>Yeah, I was bored so I built a graphical editor from the previous snippets. <br>By the way tkinter is cool.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/817/1*TBy7wbjx_R0FdTGMO3MD_Q.png" /></figure><p><a href="https://github.com/wh00hw/CoffeeEditor">GitHub - wh00hw/CoffeeEditor</a></p><h4>Write and test, what could go wrong?</h4><p>Here we go, I edited the dump by adding 10 € written successfully to the EEPROM with Pickit2 and I was in front of the vending machine.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*GaB6rlfELpi95yp9.gif" /></figure><p>I plugged the pen, but the red led above the port started blinking…<br>The pen was not recognized correctly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*YxiUSEBX3JqGglX4.gif" /></figure><p>During the following days I tried to figure out why, I read all the forum threads talking about that pen and I find out a way. Some bytes, probably starting from the 0x20 address, rappresent the vendor code. Each vending machine can only read it’s own pens, mine is not recognized because I got it from another company.</p><p>I also discovered an interesting feature. In fact, the first time a virgin pen is plugged in a vending machine, it’s initialized with its vendor code!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*oogSpcoeAoM_I8Ug.gif" /></figure><h4>Like a virgin</h4><p>So I needed a virgin pen. The first attempt was writing the FF byte in the whole EEPROM. <br>But it failed, same red led blinking.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/0*mK0z3JuxRGV6SsBB.jpg" /></figure><p>So what about to find a vergin dump? I had to buy a vergin pen somewhere, melt it, read it again, and eventually I would obtained what I was looking for.</p><p>But at some point, a saviour randomly met in a Telegram group dropped me the precious virgin dump.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*pZH9rvBD0qST3t6T.gif" /></figure><p>I wrote the virgin dump to the EEPROM, and plugged into the vending machine. This time the led bliked red just for 2 seconds, and then a fixed GREEN light!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*BdtuNtoqjk9U2mVy.gif" /></figure><p>It seemed the pen was correctly binded to the vending machine, so I inserted a 10 cents coin, and the pen was successfully charged!</p><p>I dumped the EEPROM again and I noticed that a lot of bytes changed confirming that the vending machine initialized the pen correctly with its vendor code and my 10 cents!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*Ve1lYic6rhDdB2Kn.gif" /></figure><h4>Through the decades and beyond</h4><p>Ok, nothing interesting so far, but I was ready to edit the credit thanks to the Coffee Editor.</p><p>So I turned my 10 cents into 10 €, wrote the dump to the EEPROM plugged the pen into the vending machine…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/899/1*hil2PQS4q570Kxx6Jzo3qw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*OgoS7YJ5kuJiEKHi.gif" /></figure><p>OH MY GOD, really? It’s (still) working!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/306/0*Tc_KND0z50wCacSA.gif" /></figure><p>Yeah, the credit was 9.47 € actually because I stole 53 cents of coffee just to test it, then I repaid manually the vending machine.</p><p>Let me tell you, I didn’t discover anything and that’s not a vulnerability instead it’s a bad project design that persists since the late 90’s.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/0*Oqvsxev0okDcyBJG.gif" /></figure><p>Why do they still allow that?</p><h4>My pet is a dolphin</h4><p>My dolphin needs care, attention and must be feed (really, it needs to hack things otherwise it becomes sad). That’s why I did a FAP</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*4B66eAS9NTh0q_R_.gif" /></figure><p><strong>(Flipper Application Package)</strong></p><p>If you’ve not heard yet about the Flipper Zero, I suggest you to read my previous article below where I hacked a restaurant thanks to it.</p><p><a href="https://medium.com/@nic_whr/how-to-hack-a-restaurant-5d394be105a9">How To Hack a Restaurant</a></p><p>The Flipper Zero is built on top of the famous micro-controller STM32 and you can control any I2C devices (like that EEPROM) through the GPIO.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*UmtAhJhOPxljr75y" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*wzC8ZMYp3XGGyNzq" /></figure><p>The idea was to write a FAP that, read the credit and set it to 10 €.</p><p>First, I connected the EEPROM to the Flipper:</p><p>SDA -&gt; Pin 15<br>SCL -&gt; Pin 16<br>VCC (3.3V) -&gt; Pin 9<br>GND -&gt; Pin 18</p><p>Then I provided two 4k7 ohms Pull-Up resistors from SDA to VCC and one from SCL to VCC (again, I used two trimmers…)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*WvPRZ-JcdhBQf_bkKoikcQ.jpeg" /></figure><p>I’m definitly not a C++ expert, but fortunatly the Flipper firmware has the I2C API built in.</p><pre>#include &quot;furi_hal_i2c.h&quot;</pre><p>I just needed a function that read the credit bytes</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a699cca0ea14836f67d02d84164157a3/href">https://medium.com/media/a699cca0ea14836f67d02d84164157a3/href</a></iframe><p>and a function that write the credit</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bc75b3271f3e8629aa7ce362d11e803c/href">https://medium.com/media/bc75b3271f3e8629aa7ce362d11e803c/href</a></iframe><p>Thanks to the repo I linked below I got the Hello World FAP example as a simple tutorial on how to draw things on the Flipper screen.</p><p><a href="https://github.com/mfulz/Flipper-Plugin-Tutorial">GitHub - mfulz/Flipper-Plugin-Tutorial: Get started with Flipper Zero by building a Custom &quot;Hello world&quot; plugin</a></p><p>And this is the result, press Left turns it to virgin, press Right to set 10 €, press Ok to dump the EEPROM on the terminal when you are connected via USB serial.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*HMmt3L6P0H72FqHo-ahUBA.png" /></figure><p><a href="https://github.com/wh00hw/Coffee-EEPROM-FAP">GitHub - wh00hw/Coffee-EEPROM-FAP</a></p><h4>Conclusions</h4><p>Well, it was really fun. Thank you for your attention!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/477/0*Da8FImDpLStLCfK_.gif" /></figure><h4>Disclaimer</h4><p><strong>All the information and the actions done in this article are described for educational purpose only. All of them can be easily found in other forums. I am not responsible for any illegal use of these informations. Edit the credit is like stealing.</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=34ddad81dbad" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How To Hack a Restaurant]]></title>
            <link>https://medium.com/@wh00hw/how-to-hack-a-restaurant-5d394be105a9?source=rss-119b5b848606------2</link>
            <guid isPermaLink="false">https://medium.com/p/5d394be105a9</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[restaurant-business]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[python-development]]></category>
            <dc:creator><![CDATA[wh00hw]]></dc:creator>
            <pubDate>Sun, 28 Aug 2022 17:09:09 GMT</pubDate>
            <atom:updated>2022-10-01T19:13:31.355Z</atom:updated>
            <content:encoded><![CDATA[<p>Well, it’s actually a DOS attack but that was a journey into some nerds stuff that bring me to discover how easily you can create problems to people who work honestly.</p><h3>It’s matter of hunger</h3><p>I like to eat and everything starts in a common lunch break. My 9–6 job office is in a big chaotic city where everyone has no time to say sorry when they bump into you… I don’t like delivery food so I prefer to take a walk and to go pick it up by myself. So as usual, my pick was a famous kind of sandwich at ** ******* restaurant.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*Frvq4se4OGdolfBv.gif" /></figure><h3>Those damn buzzers</h3><p>Also known as “Restaurant Pagers”, they were probably created to generate mental confusion among customers and employee. That’s why when your order is ready they start buzzing loudly until someone pushes the button hidden under the restaurant sticker. It’s not a secret, believe me, please push that button for our ears grace. By the way, I was wondering how they work, if there was some kind of communication encryption, if it could be sniffed, captured, emulated, and so on, just normal thoughts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*EINmIqfCvHh3Ym3M.png" /></figure><h3>The Flipper Zero</h3><p>Here comes the cool part. Probably some of you have already heard about this evil device, it looks like a cute Tamagotchi…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/532/1*e8T36wyaUgV1uytH-ieibQ.png" /></figure><p>but inside it hides some powerful antennas.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*a-vwWLjH0wvDNUh6.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KrKamn8B_SQ8XnfjXMCfQQ.png" /></figure><p>Thanks to the sub 1 Ghz module you can capture signals in the frequency range allowed by your region… but it’s completely opensource so thanks @<a href="https://github.com/Eng1n33r">Eng1n33r</a> for the <a href="https://github.com/Eng1n33r/flipperzero-firmware"><em>Unleashed Firmware</em></a><em>.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*WAk0PL7zG50kOqAJ.png" /></figure><h3>Do not try this at home</h3><p><strong>Even if that’s not WWE I’m not encouraging you to do what I’m describing below, it’s just a geek diary.</strong></p><p>As soon as I got my Flipper Zero I went to the usual restaurant to test my new cute little dolphin.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/530/1*uFVxsvc52b7GfzeNOGhqIA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*rV-BUCiajHsqSKWLLZX2fA.png" /></figure><p>Eureka! The listener started and a bunch of signals were captured, actually a lot. In fact, everytime a meal was ready the dolphin beeped displaying the communication details. There’s no encryption, the Flipper recognized the protocol automatically.</p><p>So, once captured, I instantly saved them then I tried to reply the signal and… <strong>it worked</strong>!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/312/0*jskVHKWVSRQCEN2Y.gif" /></figure><p>The buzzer started to vibrate beeping loudly as usual. During the first day, I sniffed dozens of them.</p><h3>Take the red pill</h3><p>Going deeper I analyzed all the buzzers codes captured.</p><pre>Filetype: Flipper SubGhz Key File</pre><pre>Version: 1</pre><pre>Frequency: 433920000</pre><pre>Preset: FuriHalSubGhzPresetOok650Async</pre><pre>Protocol: Princeton</pre><pre>Bit: 24</pre><pre><strong>Key: 00 00 00 00 00 17 93 20</strong></pre><pre>TE: 269</pre><p>The difference between all the captured signals is the 24 bit key. In the coming days I captured more of them and I thought…</p><p>What if replying by looping through the keys?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/0*SbcNtKlSfQHmNPPl.gif" /></figure><h3>The Pizza DOS</h3><p>When I was at high school, the IT Teacher used to explain to us the Denial of Service attack with the Pizzeria example. Suppose there is a city with only two Pizzeria competitors, one in front of each other, in the same street. Both only use the telephone to take orders but one has many more customers than the other. So at some point, the other decides to be evil. He starts to call cyclically the luckiest Pizzeria to keep the line busy. The customers can not order their favorite pizza, and they are indirectly forced to purchase from him.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/1*GeFdsrV6je7f67HXtuuSSQ.gif" /></figure><h3>No pain no gain</h3><p>So my goal was to perform a proof of concept DOS attack to the restaurant pagers by using the Flipper Zero, ok but… How? In fact the dolphin doesn’t have implemented in the firmware a function that loops and sends automatically all the signals I saved before. However, it implements a UART interactive command cli by connecting it through the USB.</p><h3>pyFlipper</h3><p>So I decided to exploit this thing by implementing a Python library to interact programmatically with the Flipper Zero. This library is intended to be a wrapper, it simply abstracts each already existing cli function as Python methods.</p><p><a href="https://github.com/wh00hw/pyFlipper">GitHub - wh00hw/pyFlipper: Unoffical Flipper Zero cli wrapper written in Python</a></p><h3>The Script</h3><p>Now thanks to pyFlipper things are easier, I programmatically extract all the buzzers saved key, put it on a list and send it forever in a while true loop.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*O9VNwiOJkusEDC8gIu2ASQ.png" /></figure><h3>Almost done… maybe</h3><p>The script works well but, can you imagine going to the restaurant with the laptop? I was looking for something more stealthier, maybe just plugging the Flipper via OTG USB on Android and running the script in Termux was enough, no?</p><p><strong>No.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/354/0*NSKxnzzikUxAcpoX.gif" /></figure><h3>Yet another OTG USB UART Bridge</h3><p>Unfortunately I can not just plug the Flipper via OTG USB and get the UART through /dev/ttyAMC0 as I do on Linux. I need root access (not tested yet) for that and my actual smartphone is stock (for my choice). The second smartphone I have is an old Redmi 4 Prime Android 10, rooted with Custom Rom but the OTG communication doesn’t work in any Custom ROM according to XDA forum.<br>I came across a bunch of documentations and articles and I discovered that the Android SDK allows you access the UART. So I decided, again, to write my own code. <br>The idea was to create a native Android app in Java. The app read from the UART and opens a websocket server. Any websocket client connected to it can read and write data through the serial.</p><p><strong>And it worked.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/614/0*3JLH9m_MCh0nMlo5.gif" /></figure><p>The app works even with Arduino, Raspberry, and every UART device and supports multiple connected devices at the same time.</p><p>First of all, I implemented the websocket client in the PyFlipper library, then I decided to release it into the PlayStore so you can take advantage of the Flipper functionality on Android without root.</p><p><a href="https://play.google.com/store/apps/details?id=com.wh00hw.serial2websocket">OTG USB Serial2Websocket - Apps on Google Play</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AKO41A3bMP9eV2EzvpGozw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zMY5TJ8aaJKZDvOOr5s9YQ.png" /></figure><h3>The POC</h3><p>Finally, I plugged the Flipper into the smartphone OTG USB port, then I opened the Serial2Websocket app. I started the websocket server on the loopback address and then launched the script in Termux as a websocket client.</p><p>Everything was ready and here comes the attack.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/480/0*zi3JEdiBOIcKknpY.gif" /></figure><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FglJNziIx6oI%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DglJNziIx6oI&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FglJNziIx6oI%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/c196a231d0d9a59ec47f2b275eacc7bc/href">https://medium.com/media/c196a231d0d9a59ec47f2b275eacc7bc/href</a></iframe><h3>Conclusion</h3><p>The attack could be improved by bruteforcing the 24 bit key range, instead of looping through the saved signals, to cover the maximum number of buzzers. However this is enough. This journey was unintended, but thanks to that I realeased an open-source library that really helps the Flipper Zero community.</p><p>Curiosity is the key, sometimes a rabbit hole.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5d394be105a9" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>