<?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 Douglas Goddard on Medium]]></title>
        <description><![CDATA[Stories by Douglas Goddard on Medium]]></description>
        <link>https://medium.com/@douglas.goddard?source=rss-1a47cce65b0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*eAeSple6h6ZoSipiRmhyvg.jpeg</url>
            <title>Stories by Douglas Goddard on Medium</title>
            <link>https://medium.com/@douglas.goddard?source=rss-1a47cce65b0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 04 Dec 2026 23:40:17 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@douglas.goddard/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[XorShift128+ Backward]]></title>
            <link>https://medium.com/independent-security-evaluators/xorshift128-backward-ff3365dc0c17?source=rss-1a47cce65b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff3365dc0c17</guid>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[python]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Douglas Goddard]]></dc:creator>
            <pubDate>Tue, 29 Nov 2016 14:42:15 GMT</pubDate>
            <atom:updated>2021-04-07T08:38:40.086Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Recovering Previous States from the Xor Shift 128 Plus Algorithm</em></p><p>This article is a follow up to our previous post, <a href="https://blog.securityevaluators.com/hacking-the-javascript-lottery-80cc437e3b7f">Hacking the JavaScript Lottery</a>. In that post we wrote a Python <a href="https://github.com/Z3Prover/z3">Z3</a> implementation which utilized symbolic execution in order to recover the state of the <a href="https://en.wikipedia.org/wiki/Xorshift">XorShift128Plus</a> pseudo-random number generator (PRNG) used by most major browsers. Shortly after publishing, Chrome (specifically V8, Chrome’s JavaScript engine), updated and the SAT solver was no longer able to find valid solutions.</p><p>A few users reported this issue but time did not allow for digging into the source code and tracking down what was wrong. Thankfully, Github user <a href="https://github.com/psrok1">psrok1</a> discovered the source of the problem in NodeJS’s source code. V8 generates many pseudo-random numbers and stores them in a buffer for fast retrieval by later calls Math.Random(). The issue was that this buffer was being read back to front, instead of in the order that the numbers were generated.</p><p>There is a statistical test for uniformly distributed random numbers called <a href="https://en.wikipedia.org/wiki/TestU01">Big Crush</a>. The reason all the browsers switched to the XorShift family of algorithms was that the old PRNGs used failed to pass statistical tests, like Big Crush. While there was some discussion about a predecessor algorithm, Xsadd, failing statistical tests when the values were bit reversed, no one was talking about the XorShift buffer being read backward.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/1*UfZxAhF5YckROuc2PLbcbg.png" /><figcaption>A visual representation of randomly generated numbers from <a href="https://jandemooij.nl/test/random-precision.htm">jandemooij.nl.</a></figcaption></figure><p>Given that information, it was time to fix the XorShift prediction code. The XorShift128Plus algorithm uses two state variables to generate pseudo-random values. We’ll refer to these as state0 and state1. Each round, state0 gets the value that state1 had, and state1 is updated through a series of mathematical operations. Let’s look at it in code.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d044544b925e7eee020d1bc2edd7d6fc/href">https://medium.com/media/d044544b925e7eee020d1bc2edd7d6fc/href</a></iframe><p>The issue we faced was that once we recovered the state variables using Z3, we could go forward, that is, predict future values of the algorithm. The update made it necessary for us to also go backward, finding previous states from the current state. My first thought was that I would need Z3 for this, since I assumed some of the data was lost in the shift operations. However, when looking for shortcuts to save the symbolic executor some work, I found that the algorithm was entirely reversible.</p><h4><a href="http://eepurl.com/bLc2bf">Sign up to get our latest blogs</a></h4><p>Recovering the previous state1 is easy as that variable is stored entirely in the current state0 variable (line 8).</p><pre>prev_state1 = state0</pre><p>Recovering the previous state0 will require a little more work. The four operations that need to be reversed are on lines 4 through 7. Lines 6 and 7 are easily reversed, as s0 is simply the previous state1 which is unmodified. So we can xor the current state1 with the current state0 shifted right 26 bits (line 7). Then we can xor that result with the current state0 again (line 6).</p><pre>prev_state0 = state1 ^ (state0 &gt;&gt; 26)<br>prev_state0 = prev_state0 ^ state0</pre><p>Next, on line 5, we can reverse that operation 17 bits at a time. Let’s keep in mind the properties of xor.</p><ul><li>It is commutative meaning that the order of inputs doesn’t matter A^B = B^A. A counter example to this is division, where the order does matter (5/2 is different from 2/5).</li><li>It is associative, meaning that changing the grouping does not change the outcome. Again, using division as a counter example, (10/5)/3 is different from 10/(5/3).</li><li>It is a self-inverse operation, meaning it is to itself what subtraction is to addition.</li><li>Its identity element is zero, meaning that any number xord with zero is unchanged.</li></ul><p>Using all this, we know that A^B^A = B, since A^A is zero, B^0 = B. Since the high 17 bits are unmodified due to the right shift we can use those high bits to recover the next 17 bits. Once those bits are recovered we can use them to recover the next 17, and so on.</p><p>Visually, if we have a 64 bit value whose original bits are the repeating 4 bits 1110, and we xor that original value with itself, right shifted 17 bits.</p><pre> 11101110111011101 11011101110111011101110111011101110111011101110<br>^                  11101110111011101110111011101110111011101110111<br>-----------------------------------------------------------------_<br> 11101110111011101 00110011001100110011001100110011001100110011001</pre><p>You can see the original bit pattern 1110 is preserved in the high 17 bits of the result, and the lower 47 bits (17–63) are changed due to the xor operation.</p><p>To reverse the operation we can then take those upper 17 bits and xor the next 17 bits against them, recovering part of the original number.</p><pre> 11101110111011101 00110011001100110 011001100110011001100110011001<br>^        └-------&gt; 11101110111011101 000000000000000000000000000000<br>-------------------------------------------------------------------<br> 11101110111011101 11011101110111011 011001100110011001100110011001</pre><p>We repeat this operation twice more, with consecutive sets of 17 bits (until the last one, which only needs 13 bits, because 64 - 17*3 = 13) until we have recovered the complete original number.</p><pre> 11101110111011101 11011101110111011 01100110011001100 1100110011001<br>^                          └-------&gt; 11011101110111011 0000000000000<br>-------------------------------------------------------------------<br> 11101110111011101 11011101110111011 10111011101110111 1100110011001</pre><pre>...</pre><pre> 11101110111011101 11011101110111011 10111011101110111 1100110011001<br>^                                    └-----------┘---&gt; 1011101110111<br>-------------------------------------------------------------------<br> 11101110111011101 11011101110111011 10111011101110111 0111011101110</pre><p>In Python we can write a quick function to recover this number. We start with the top 17 bits, then we recover the top 34, then the top 51, then the original number, just as we did above.</p><pre>def reverse17(val):<br>    top34 = (val ^ (val &gt;&gt; 17)) &amp; 0xFFFFFFFFC0000000<br>    top51 = (val ^ (top34 &gt;&gt; 17)) &amp; 0xFFFFFFFFFFFFE000<br>    original = (val ^ (top51 &gt;&gt; 17))<br>    return original</pre><p>That operation takes care of line 5 of our original algorithm s1 ^= (s1 &gt;&gt; 17). With this newly gained knowledge, we can quickly write a function to undo line 4 as well s1 ^= (s1 &lt;&lt; 23). Instead of working from the high bits downward, we start with the low 23 bits and work upward.</p><pre>def reverse23(val):<br>    bot46 = (val ^ (val &lt;&lt; 23)) &amp; 0x3fffffffffff<br>    original = (val ^ (bot46 &lt;&lt;  23)) &amp; 0xFFFFFFFFFFFFFFFF<br>    return original</pre><p>Putting all that together, we can now do the XorShift128Plus algorithm backward! We can rewrite the reverse17 and reverse23 functions a little more succinctly.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f213c4c43f30a5b85f8dfb03c2a5a7a/href">https://medium.com/media/2f213c4c43f30a5b85f8dfb03c2a5a7a/href</a></iframe><p>Now once we recover the two state variables from Z3, if our target browser is Chrome we can feed the state values into this algorithm to predict the backward values from Math.Random(). This allowed me to get the lottery predictor script working in Chrome again.</p><p>There is a theoretical limitation on matching the values generated in V8. Values in V8 are generated ‘forward’ into a buffer then read in reverse. If you were predicting values near the low end of the buffer, exhausted the values and required that a new buffer be generated, your values would no longer match up as this algorithm goes strictly backward. The frequency of this occurring depends on the size of their random number buffer.</p><p>The original issue in which this solution was developed can be found <a href="https://github.com/douggard/XorShift128Plus/issues/1">here</a>. The updated code is on <a href="https://github.com/douggard/XorShift128Plus/blob/master/xs128p.py">Github</a>. Thanks again to user <a href="https://github.com/psrok1">psrok1</a> for finding the root cause.</p><p>Authored by<a href="https://blog.securityevaluators.com/@douglas.goddard"> <em>Douglas Goddard</em></a><em>, an Analyst at </em><a href="http://www.securityevaluators.com/"><em>Independent Security Evaluators</em></a><em>.</em></p><p>Twitters<em>: </em><a href="https://twitter.com/ISEsecurity"><em>@ISESecurity</em></a></p><h4><a href="http://eepurl.com/bLc2bf">Sign up to get our latest blogs</a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff3365dc0c17" width="1" height="1" alt=""><hr><p><a href="https://medium.com/independent-security-evaluators/xorshift128-backward-ff3365dc0c17">XorShift128+ Backward</a> was originally published in <a href="https://medium.com/independent-security-evaluators">Independent Security Evaluators</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Technical Anonymity Guide]]></title>
            <link>https://medium.com/independent-security-evaluators/technical-anonymity-guide-658a53adff5b?source=rss-1a47cce65b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/658a53adff5b</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[surveillance]]></category>
            <category><![CDATA[technology]]></category>
            <category><![CDATA[privacy]]></category>
            <category><![CDATA[anonymity]]></category>
            <dc:creator><![CDATA[Douglas Goddard]]></dc:creator>
            <pubDate>Tue, 05 Jul 2016 16:19:44 GMT</pubDate>
            <atom:updated>2021-04-07T08:38:15.170Z</atom:updated>
            <content:encoded><![CDATA[<p><em>This post is adapted from a presentation given at BSides Charm.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QEd2LlpGAkVu26GakLeVIQ.jpeg" /></figure><h4>Abstract</h4><p>As more data is collected at different layers of our digital lives an understanding of anonymity becomes a vital skill. While operational security (OPSEC) is important in practice, the technical setup for anonymity is a prerequisite to any operation. Given the range of use cases for anonymity and the many different actors who attempt to dismantle it, this design considers an environment in which everyone is an adversary. This article should serve as a start to finish guide on setting up a laptop for anonymous usage. While it will cover OPSEC in different sections this is not meant to be an exhaustive guide on the topic.</p><h4>Introduction</h4><p>Many companies are turning toward data collection and remote storage. This removes control from the consumer and provides their data and activities to be accessed by third parties. Each layer of usage provides a potential point for data insecurity; computer manufacturers, operating systems, applications, network access points, internet service providers, webpages, retailers, governments, and any partners of the controlling organizations with whom data is shared. Given the many points of failure and the possibility that any of these collections of data can be breached by an attacker, it is wise to treat every group as an adversary regardless of whether they are directly targeting you.</p><p>OPSEC is critical at every stage of operation. To ensure anonymity, operations will require significant planning and care during execution. Security researcher <a href="https://medium.com/u/8c278323b47c">the grugq</a> sums it up well with the following -</p><blockquote>Strong OPSEC means low efficiency, while high efficiency necessitates weak OPSEC. The strength of the oppositional forces dictate the minimum security requirements of the covert organization.</blockquote><blockquote>- the grugq (<a href="http://grugq.github.io/blog/2013/12/01/yardbirds-effective-usenet-tradecraft/">source</a>)</blockquote><p>Simply put, you must be willing to jump through hoops in order to preserve your anonymity.</p><p>The design covered in this guide is based off of a laptop and a Raspberry Pi. It utilizes <a href="https://github.com/grugq/PORTALofPi"><em>the grugq’s </em>PORTALofPi router</a> which turns the Raspberry Pi into a Tor router. That is, all traffic routed through the Pi will be sent through Tor.</p><h4>Acquiring Materials</h4><p>The first stage in an operation is securely gathering the required equipment. System attributes will be leaked during normal operation. For example, your network adapter’s MAC address is available to the network access point your are connecting through. If the MAC address is associated with a specific laptop manufacturer, store, or region, that can help narrow down identification. While you can randomize a MAC address, not all system attributes are able to be changed. Due to this, it is necessary to dissociate any purchase from your concrete identity.</p><p>In order to do this you need a currency that is not associated with your identity. Most importantly, no credit and debit cards. Cash is an excellent option, as are prepaid gift cards (however, you will likely need to purchase these with cash). It is unlikely that there is a major scheme going on that correlates bill serial numbers to debit withdrawals. However, under the <em>everyone is an adversary</em> threat model, it is safer to acquire cash via cashback or other means (working, pan handling, etc).</p><p>Our bill of materials:</p><ul><li>Laptop</li><li>Raspberry Pi 2</li><li>Micro SD Card</li><li>WiFi Adapter</li><li>Ethernet Cable</li><li>Burner Phone</li><li>USB Ethernet Adapter (optional)</li><li>Second Ethernet Cable (optional)</li><li>Bitcoin / Cash Cards</li></ul><p>Altogether these items can be purchased for less than 500$. It is important to purchase them from a physical retailer so that they are not subject to interdiction by an adversary.</p><p>It is possible that sometime in the future the device you purchased will be recovered by an adversary. The serial numbers of the various parts of your device may be tracked to that specific retailer. It would then be possible to recover clues to your identity from the security footage. It can be beneficial to wear clothing that masks your face, for example, sunglasses and a baseball cap. There have been <a href="https://cvdazzle.com/">methods</a> researched to defeat automated facial recognition, however, these methods may draw more attention than desired.</p><p>Bitcoin is the cryptocurrency of choice right now. It is easy to obtain and accepted by many retailers. There are a few ways to acquire Bitcoin, none of which are fool-proof in protecting anonymity. For example, Bitcoin ATMs have cameras and require a phone number. Mining over Tor provides more security than <a href="http://cointext.com/bitcoin-and-ip-address-privacy/">Bitcoin does by default</a>, but <a href="https://blog.torproject.org/blog/did-fbi-pay-university-attack-tor-users">Tor users can be deanonymized with certain attacks</a> and it is likely that you would be mining from an IP address associated with you. Due to this it is crucial to use mixers. There is a possibility that a mixer is controlled by your adversary so using multiple mixers is advised.</p><p>The burner phone is another consideration. It should be purchased in a similar manner to the rest of the hardware; as anonymously as possible.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KoSoZcXspT_YZN6OE3EK2w.jpeg" /></figure><h4>Hardware and Software Setup</h4><p>The laptop will be the main device and should be properly secured. The webcam and microphone should be disconnected. The battery should be removed so it can be powered down easily. Any radios, such as Bluetooth and WiFi, should be removed or disabled.</p><p>The operating system choice is up to the user. The OS that the user is most knowledgeable of is what they will be able to operate most securely on. With that said, there are some good choices for the host system depending on preference:</p><ul><li><a href="https://www.qubes-os.org/">Qubes OS</a> isolates different areas of the system using virtualization, also sandboxes networking code and USB drivers.</li><li><a href="https://subgraph.com/sgos/index.en.html">Subgraph OS</a> implements application containment, hardened kernel, and optional Tor proxy layer.</li><li><a href="https://hardenedbsd.org/">Hardened BSD</a> is a great choice if you are partial toward BSD, it implements security features that are missing from FreeBSD.</li><li><a href="http://xubuntu.org/">Xubuntu</a> does not contain any hardening features, but it is often chosen because so many applications are built for Ubuntu. Xubuntu is preferred over Ubuntu as the lighter desktop environment may run better on a budget laptop. (Edit: Thanks to Reddit user bestbirdaround for pointing out that stock Ubuntu does offer full disk encryption on install.)</li></ul><p>For any operating system the disks should be encrypted. This prevents your adversary from recovering data from your disks when the system is not powered. It was mentioned previously to remove the battery from the laptop. This is so that if your laptop is stolen in a snatch and grab operation it will shut down when removed from the power source.</p><p>The Raspberry Pi will be used as a Tor router that fails closed. This design utilizes the <a href="https://github.com/grugq/PORTALofPi">PORTALofPi</a> build script from security researcher <a href="https://medium.com/u/8c278323b47c">the grugq</a>. There are pending pull requests that add additional security features to the system that should be considered. This script configures an Arch Linux Raspberry Pi installation to act as a router for any computer connected to the Ethernet port. It forwards all traffic through Tor and when it cannot establish a connection through Tor it fails closed. If the laptop is compromised, this router adds an additional layer of protection from the public IP address being leaked.</p><p>This setup is significantly more secure if the Raspberry Pi connects to the internet via an Ethernet connection. This is incredibly inconvenient since most publicly available internet is offered through WiFi. In order to establish a connection via WiFi, the laptop will need to have some access to the Raspberry Pi in order to select networks and enter passwords. This access is established via SSH which requires some modifications to the iptables rules on the Raspberry Pi. This SSH connection is what provides attackers the opportunity to leak the public IP address of the system. If an attacker were to compromise the laptop, with access to keylogging or SSH keys, they could then move to the Raspberry Pi. This would allow them to leak the public IP address, circumventing Tor and deanonymizing the user. Further research is needed to lock down and isolate the SSH account and have it able to select and configure WiFi connections. Consider alternate methods to access the Pi, such as a monitor and keyboard.</p><p>The complete setup is the laptop connected to the Raspberry Pi via Ethernet, and the Raspberry Pi connected to the internet either via a USB WiFi adapter or a USB Ethernet adapter.</p><p>Burner phones require activation and some block activation via payphone. However, it is possible to activate them online via Tor. A phone is generally required when operating anonymously as many sites require SMS verification. Bitcoin ATMs also require a mobile number.</p><p>A Bitcoin wallet should be created to capture the Bitcoins you purchase. The Bitcoin core client syncs the entire blockchain to your computer. Since the computer is operating over Tor this is incredibly slow. Two alternatives are the <a href="https://electrum.org/">Electrum</a> client (native) and <a href="https://blockchain.info/wallet/#/">Blockchain.info</a> (web).</p><h4>Operating Securely</h4><p>There are some basic OPSEC principles that should be established. A lot of these points are sourced from <a href="https://www.youtube.com/watch?v=9XaYdCdwiWU">the grugq’s talk Opsec</a>, <a href="https://www.youtube.com/watch?v=J1q4Ir2J8P8">Zoz’s talk Don’t Fuck It Up</a>, and <a href="https://www.youtube.com/watch?v=J1q4Ir2J8P8">Whonix’s DoNot list</a>.</p><ul><li><strong>Never operate from a location associated with you.</strong> There are attacks against Tor that can reveal your IP address. If your public IP address is revealed as your home or business then you are immediately identified. By operating from somewhere not associated with you, this will ideally only reveal your general location.</li><li><strong>Be conscious of being tracked in public. </strong>There are technologies that make it easy to track people in public. <a href="https://en.wikipedia.org/wiki/Automatic_number_plate_recognition">Automated license plate recognition (ALPR) systems</a> have been deployed on many police vehicles as well as by private companies. These systems use computer vision to extract the text of license plates. The license plate is associated with the location it is spotted at, effectively tracking any vehicle that is seen. There also exists a company <a href="http://www.pss-1.com/">Persistent Surveillance Systems</a> that monitors large areas using high powered cameras attached to airplanes. This allows their customers to rewind on the movement of an area, tracking vehicles and people back to their source. Given these technologies and their limitations, it is best to travel more than 15 miles from any place associated with you, in a vehicle that cannot be tied to anyone you know. Consider using public transportation, though there are likely cameras monitoring both the vehicles and the stations. Bicycles and mopeds that do not require registration are a great solution. So may be a hired car in which you can pay cash.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pcKh5pk_wuqpxReLGS7SoA.jpeg" /><figcaption>Aerial surveillance can be less effective in groups of tall buildings.</figcaption></figure><ul><li><strong>Do not wear your regular uniform. </strong>Many people have a limited wardrobe. If what you wear can help narrow you down, (e.g., the person in Sometown, USA who wears all black) it is critical to wear different clothing while operating. Also cover any recognizable markings on your body, including <a href="https://www.eff.org/deeplinks/2016/05/5-ways-law-enforcement-will-use-tattoo-recognition-technology">tattoos</a>.</li><li><strong>Leave your personal cellphone at home. </strong>Cellphones connect to many different companies during normal operation. Most significantly, the cell service provider for coverage and the operating system manufacturer for system analytics and built-in services. Any applications on the phone could also collect data. Each time the phone connects to a cell tower during normal operation, it should be assumed that the connection is logged and that your phone has then been associated with that location. There are also <a href="https://en.wikipedia.org/wiki/IMSI-catcher">IMSI catchers</a> that act as fake cell towers and collect a log of phones in that area. With all these technologies it is very easy for your phone to place you in a location at a specific time. It is best to simply leave the phone behind or disable it by removing the battery. Turning it off when you are operating can lead to a correlation between your phone being down and operations taking place. It should instead be kept in a plausible location that indicates normal use.</li><li><strong>Keep the battery removed from the burner phone when it is not in use.</strong> Malware <a href="http://thehackernews.com/2015/02/poweroffhijack-android-malware.html">has been known</a> to fake the phone off-state. In order to make sure that any phone is in the off state the battery should be removed.</li><li><strong>Only turn on the burner cellphone at locations that are not associated with you.</strong> Given the nature of the burner phone and its strong connections to your anonymous accounts, ensure that it is never turned on in a location associated with your real identity.</li><li><strong>Never call anyone associated with you from the burner cellphone.</strong> Given the metadata that is collected in regards to who is in contact with whom, <a href="http://www.wired.com/2007/06/st-cia/">calling someone you know can link that phone to a social graph associated with you.</a></li><li><strong>Store your devices securely when they are not in use.</strong> The Raspberry Pi is not configured to have an encrypted disk. This means that an adversary who gains physical access to the SD card can modify it arbitrarily. As well, physical implants could be installed on the laptop and the adapters (WiFi or Ethernet) could be replaced with dummy devices designed to call out to your adversary. Due to these physical attacks it is critical to store the devices in a reasonably secure and tamper evident manner when they are unattended.</li><li><strong>Never log into accounts that are associated with your anonymous identities without Tor. </strong>It should be assumed that every site is logging the IPs associated with each account. Even a single login can circumvent the protection that Tor provides, revealing general information about your location and operations.</li><li><strong>Never log into your personal accounts at the same time or from the same systems as your anonymous accounts. </strong>If logged in at the same time a correlation can develop between the two accounts. It should also be assumed that a system could be compromised. Logging into a personal account from a compromised system would give an adversary a direct revelation of who is operating on the system.</li><li><strong>Be conscious of advertisements and cookies that track users between sites.</strong> While this tracking does not directly reveal your identity, it can associate operations or remove separation between multiple identities that are being managed. You should take the necessary measures to avoid being tracked online while operating. This can include regularly clearing cookies, installing adblocking software, and disabling JavaScript where possible.</li><li><strong>Dissociate from yourself any cryptocurrency that is linked to your real identity. </strong>There are very few ways to acquire a cryptocurrency without revealing pieces of your identity to some entity. Purchasing in person will allow the person you are purchasing from to see your face. However unlikely, this person may be an agent of your adversary. Bitcoin ATMs will have a camera and require your burner’s SMS number (this also associates a picture of you with your burner number). Mining can reveal your IP address as it is a rather stationary activity. Connecting to a mining pool via Tor is a good option but Tor users’ IP addresses can be revealed by an attacker with sufficient resources. Given these constraints, you should always utilize mixers before spending your coins. Using multiple mixers is advisable in case the mixer you use is controlled by your adversary.</li><li><strong>Manage multiple plausible identities that would be investigated if your machine becomes compromised. </strong>Many people sabotage their own attempts at anonymity by using pieces of their real name as a username or a username that is associated with them in real life. In order to avoid this pitfall, it is suggested that while operating you work under an assumed identity.</li><li><strong>Change out your hardware. </strong>Given the possibility of compromise, and the contamination that can occur if any device you use becomes associated with you in real life, it is important to change devices. For example, using a burner cell phone to purchase Bitcoins from an ATM will associate that phone number with your picture. That phone should be considered compromised after such a usage and a new phone should be purchased.</li><li><strong>Don’t make friends.</strong> Getting friendly and sharing details about your life will destroy your anonymity. Do not attempt to make personal connections when operating.</li></ul><p>Once you are setup there are additional measures that can be taken to harden your security. Utilizing services that provide end-to-end encryption is good. Utilizing PGP achieves the same goal and does not rely on trusting a service provider. If not, using a host that compartmentalizes programs and data using virtual machines can add a layer of protection against system compromise.</p><p>You should also acquire a jumpbox, a server to be used that is purchased anonymously and not associated with you in any way. This server is where you will store any information on your operation such that if your hardware is compromised you do not become tied to an operation. This should be purchased with Bitcoin that has been mixed.</p><p>While a smart burner phone may increase the attack surface through which you could be deanonymized, if one is required for use of modern applications it is recommended to use a hardened operating system. One solution to this is <a href="https://copperhead.co/android/">CopperheadOS</a>, a hardened version of Android. Unfortunately for this solution, the supported devices are expensive and do not qualify as good burner phones for anyone without an extensive budget.</p><p>Additionally, using Tor, you will often run into services like Cloudflare that require verification before accessing a website. This becomes incredibly tedious. Utilizing a VPN that you connect to through Tor will give you a clean IP address. You must be careful to not use the same IP address or VPN provider across multiple identities as this can lead to a break down in their compartmentalization.</p><h4>Conclusion</h4><p>Operating securely does require a significant budget, in terms of both time and money. It is not an easy process, and for the average person it will likely be viewed as an unnecessary expense. Anonymity also requires technical knowledge. No solution is completely secure, but to have reasonable levels of confidence in a system one must have the technical understanding of why and how it works and what its weak points are.</p><p><em>Douglas Goddard is an Analyst at </em><a href="http://www.securityevaluators.com/"><em>Independent Security Evaluators</em></a><em>.</em></p><p><em>Twitters: </em><a href="https://twitter.com/ISEsecurity"><em>@ISESecurity</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=658a53adff5b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/independent-security-evaluators/technical-anonymity-guide-658a53adff5b">Technical Anonymity Guide</a> was originally published in <a href="https://medium.com/independent-security-evaluators">Independent Security Evaluators</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hacking the JavaScript Lottery]]></title>
            <link>https://medium.com/independent-security-evaluators/hacking-the-javascript-lottery-80cc437e3b7f?source=rss-1a47cce65b0------2</link>
            <guid isPermaLink="false">https://medium.com/p/80cc437e3b7f</guid>
            <category><![CDATA[reverse-engineering]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Douglas Goddard]]></dc:creator>
            <pubDate>Tue, 17 May 2016 13:26:04 GMT</pubDate>
            <atom:updated>2021-04-07T08:37:48.676Z</atom:updated>
            <content:encoded><![CDATA[<p>January 2016 boasted a Powerball jackpot of 1.5 billion dollars. This generated a lot of interest in the lottery and the <a href="http://graphics.latimes.com/powerball-simulator/">Los Angeles Times released a simulator</a> where you start with 100 dollars and play until that is gone. I had seen <a href="http://franklinta.com/2014/08/31/predicting-the-next-math-random-in-java/">previous work for predicting Java’s Math.random()</a> and thought it would be a fun project to replicate for the browser.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*UV2hnS5gTtvh_w3jmj9paQ.png" /></figure><p>The first step is to find the algorithm used in the browser’s pseudo random number generator. Since I use Chrome I began searching through the source code of Chrome’s Javascript engine, V8. During this search I came across a <a href="http://v8project.blogspot.com/2015/12/theres-mathrandom-and-then-theres.html">V8 blog post</a> stating that they would be switching to XorShift128+ as it offers a higher quality random distribution. The blog post also stated that Firefox and Safari were in the process of switching over to this algorithm as well. One target, how convenient!</p><h4><a href="http://eepurl.com/bLc2bf"><strong>Signup to get our latest blogs</strong></a></h4><h4>XorShift128+</h4><p>Knowing that I had to wait for a few months for those versions of the browsers to be released, I got to work on the algorithm. The algorithm has two state variables (<strong>stateZero</strong> and <strong>stateOne</strong>). Each iteration, <strong>stateOne</strong> is updated by a combination of XORs and shifts of the two state variables. <strong>StateZero</strong> gets the previous value of <strong>stateOne</strong>. Everything in the following Python code is ANDed with ((1&lt;&lt;64)-1) in order to simulate 64 bit integers.</p><pre>def xs128p(state0, state1, browser):<br>    # save states to temp variables for operating<br>    s1 = state0 &amp; ((1&lt;&lt;64)-1)<br>    s0 = state1 &amp; ((1&lt;&lt;64)-1)<br>    <br>    # generate next state1<br>    s1 ^= (s1 &lt;&lt; 23) &amp; ((1&lt;&lt;64)-1)<br>    s1 ^= (s1 &gt;&gt; 17) &amp; ((1&lt;&lt;64)-1)<br>    s1 ^= s0 &amp; ((1&lt;&lt;64)-1)<br>    s1 ^= (s0 &gt;&gt; 26) &amp; ((1&lt;&lt;64)-1)<br>    <br>    # update state0<br>    state0 = state1 &amp; ((1&lt;&lt;64)-1)<br>    # update state1<br>    state1 = s1 &amp; ((1&lt;&lt;64)-1)<br>    <br>    # return updated state and the pseudo random number<br>    generated = (state0 + state1) &amp; ((1&lt;&lt;64)-1))<br>    return state0, state1, generated</pre><h4>Symbolic Execution</h4><p>Now that I understood the algorithm, I could attack it. Being particularly fond of symbolic execution I turned to my good friend <a href="https://github.com/Z3Prover/z3">Z3</a>. Z3 is an <a href="https://en.wikipedia.org/wiki/Satisfiability_modulo_theories">SMT solver</a> developed by Microsoft Research. SMT solvers take in logical formula and will resolve whether the constraints you place on that formula are satisfiable. For example, the formula (A &amp; B) is satisfiable (will resolve True) if the variables A and B are both True. If we add the constraint (A &amp; B &amp; A == False) then the formula is no longer satisfiable.</p><p>What is even cooler is that you can also represent arithmetic and bitwise operations in Z3. This provides a lot of room for emulating code and solving for inputs that create certain outputs. I’ve used this a few times with success in c<a href="https://ctftime.org/ctf-wtf/">apture the flag style competitions</a>. With this I set out to create a symbolically executed XorShift128+ algorithm in Python. The goal being to recover the state of the browser’s random number generator given random numbers generated from the browser.</p><p>The code starts by declaring two 64 bit symbolic variables in Z3 to represent the two state variables. These initial variables are saved for later use in the <strong>ostate</strong> (original state) variables and then assigned to <strong>sym_state</strong> (symbolic state) variables. The <strong>sym_state</strong> variables will be updated throughout the symbolic execution. Also declared are a Z3 Solver and a list for storing conditions.</p><pre>ostate0, ostate1 = BitVecs(‘ostate0 ostate1’, 64)<br>sym_state0 = ostate0<br>sym_state1 = ostate1<br>slvr = Solver()<br>conditions = []</pre><p>JavaScript’s Math.random() generates pseudo-random decimal values between zero (inclusive) and one (exclusive). Given three of these numbers generated (consecutively) we can recover the state of the random number generator and predict future values.</p><p>The following is a quick JavaScript snippet to be run in the browser’s console that will print 5 random numbers.</p><pre>nums = []; <br>for(var i=0; i&lt;5; ++i) { <br>    nums.push(Math.random()) <br>}; <br>console.log(nums);</pre><p>Now our sharp readers are probably wondering, “the algorithm gives back 64 bit unsigned integers, where are these decimal values coming from?” That’s a great question and the answer is that it varies by browser. The 64 bit integers are converted to <a href="https://en.wikipedia.org/wiki/Double-precision_floating-point_format">doubles</a>. Glossing over some intricacies, doubles consist of a sign, mantissa, and exponent and evaluate to sign * mantissa * 2^exponent. The mantissa is stored in 52 bits of the number, the exponent gets 11 bits, and the sign gets 1 bit as usual. This adds up to a nice round 64 bits.</p><p>In Chrome’s JavaScript engine (V8) the 64 bit uint is treated as the mantissa by ANDing the value with hex 0xFFFFFFFFFFFFF ((1&lt;&lt;52)-1). That value is then ORed with 0x3FF0000000000000 to get a value between one and two. Then 1.0 is subtracted from that value to get a value between zero and one.</p><p>In Firefox the 64 bit uint is ANDed with 0x1FFFFFFFFFFFFF ((1&lt;&lt;53)-1) then divided by 0x20000000000000 (1&lt;&lt;53) to get a value between zero and one.</p><p>In Safari’s JavaScript engine (WebKit’s JavaScriptCore) the 64 bit uint is similarly ANDed with 0x1FFFFFFFFFFFFF ((1&lt;&lt;53)-1), however, it is then multiplied by (1.0 / (1 &lt;&lt; 53)) to produce a value between zero and one.</p><p>For each double we retrieve from the browser we can then recover part of the unsigned integer that was generated. Given the simplicity of the Firefox code, we will use that from here on out in the examples. Here we take the doubles (in the list dubs) and multiply them by (1 &lt;&lt; 53) in order to recover the the lower 53 bits of the randomly generated number.</p><pre>for idx in xrange(3):<br>    generated.append(dubs[idx] * (0x1 &lt;&lt; 53))</pre><p>Next we run three iterations of the symbolic XorShift128+ algorithm. The function returns the updated symbolic state variables and also the conditionals generated in that iteration.</p><pre>for ea in xrange(3):<br>    state = sym_xs128p(slvr, sym_state0, sym_state1, generated[ea], browser)<br>    sym_state0, sym_state1, ret_conditions = state<br>    conditions += ret_conditions</pre><p>The symbolic XorShift128+ algorithm is pretty similar to the non-symbolic one. It follows the same algorithm except it uses the symbolic variables created earlier.</p><p>As a note, Z3 has two right shifts. It has a arithmetic right shift and a logical right shift. It uses the arithmetic shift when shifting with the &gt;&gt; operator. So the code must use the logical shift LShR or you will spend hours being confused, yea...</p><p>Following the normal algorithm operation, the code creates a condition and associates an implication with this condition. The implication or constraint being that the symbolically generated random number ANDed with (1&lt;&lt;53) is equivalent to our recovered number.</p><pre># Symbolic execution of xs128p<br>def sym_xs128p(slvr, sym_state0, sym_state1, generated, browser):<br>    s1 = sym_state0 <br>    s0 = sym_state1 <br>    s1 ^= (s1 &lt;&lt; 23)<br>    s1 ^= LShR(s1, 17)<br>    s1 ^= s0<br>    s1 ^= LShR(s0, 26) <br>    sym_state0 = sym_state1<br>    sym_state1 = s1<br>    calc = (sym_state0 + sym_state1)<br> <br>    condition = Bool(‘c%d’ % int(generated * random.random()))<br>    # Firefox number<br>    impl = Implies(condition, (calc &amp; 0x1FFFFFFFFFFFFF) == int(generated))</pre><pre>    slvr.add(impl)<br>    return sym_state0, sym_state1, [condition]</pre><p>With the returned conditions we can then ask the solver whether the execution is satisfiable. If it is then we can recover the initial values of our XorShift128+ state and then use the non-symbolic algorithm to confirm and predict future values.</p><pre>if slvr.check(conditions) == sat:<br>    m = slvr.model()<br>    state0 = m[ostate0].as_long()<br>    state1 = m[ostate1].as_long()</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*gzLxitkumwARO3jKwgaTJQ.png" /></figure><h4>Winning the Lottery</h4><p>Fast forward a few months to when Firefox and Chrome have both been updated to include the new pseudo random number generator. Time to revisit <a href="http://graphics.latimes.com/powerball-simulator/">the lottery page</a>. On the page you can “Quick Pick”, letting the page choose your lotto numbers or you can enter your own numbers. We’ll go ahead and enter our own.</p><p>I started by getting five values from Math.random() using the console (three to generate, two to confirm). Entering those numbers into the Python script we can recover the state of the browser.</p><p>Now we need to look at how the LA Time’s application generates the winning numbers. I was very pleased to find clearly named functions and commented code, a luxury I often work without.</p><p>In short, it generates an array of possible values for the lottery numbers (1–69 inclusive). Using Math.random() it selects 5 of those values, removing each selected value from the array so it can not be chosen twice. It does the same for the mega number which can have a value between (1–26 inclusive).</p><pre>function getWinning(max) {<br>    // Create possible user numbers array <br>    var possUserNumbs = [];<br>     for (var i=1; i&lt;(max+1); i++) {<br>        possUserNumbs.push(i);<br>    }<br>    // Quick pick winning user numbers array <br>    var userWinningNumbs = [];<br>    for (var j = 0; j&lt;5; j++) {<br>        userWinningNumbs.push(getRandomWinningNumbers());<br>    }<br>    // Gets random numbers and removes them after use<br>    function getRandomWinningNumbers() {<br>        var randomIndex = Math.floor(Math.random()*possUserNumbs.length);<br>        return possUserNumbs.splice(randomIndex, 1)[0];<br>    }<br>    // Reorder from smallest to largest<br>    userWinningNumbs.sort(function(a,b) {return a-b; });<br>    return userWinningNumbs;<br>}<br> <br>function getMega(megaMax) {<br>    // Create possible user mega numbers array<br>    var possMegaUserNumbs = [];<br>    for (var i=1; i&lt;(megaMax+1); i++) {<br>        possMegaUserNumbs.push(i);<br>    }    <br>    <br>    var randomIndex = Math.floor(Math.random()*possMegaUserNumbs.length);<br>    return possMegaUserNumbs.splice(randomIndex, 1)[0];<br>}<br>// view-source:http://graphics.latimes.com/powerball-simulator/</pre><p>So with the recovered state the code generates the five random numbers that were generated in the console. Then it will generate six more following the same procedure to generate the winning numbers and the mega number.</p><p>Using that I went to the webpage and didn’t win the lottery… Huh? The code checked out in the console. What if other things were calling Math.random()? Digging into the other code running on the page I saw quite a few places where Math.random() was called. For reproducibility I installed uBlock to simplify the number of scripts running on the page.</p><p>This left an LA Times’ analytics script as the only thing calling Math.random(). In Chrome, Math.random() was called twice for each click on the page and in Firefox it was called once for each click.</p><p>With that information I got the result of five Math.random() calls from the console. I then pasted those into the Python script and ran it. Once that spit out the winning numbers I used one click to put focus on the number entry fields and then navigated between them using Tab to minimize calls to Math.random(). Then one more click to hit the Play button. So for Firefox the script needs to simulate seven calls to Math.random() before generating the winning lottery numbers and in Chrome the script needs to simulate nine. Knowing this I added a convenient arrow to point out the winning numbers in the script’s output.</p><pre>$ time python xs128p.py <br>BROWSER: chrome <br>[0.8817331322829662, 0.31765120036119443, 0.3301985901101909]<br>0.842479503507<br>     [9, 29, 55, 58, 66] 9<br>0.783537328316<br>     [9, 23, 29, 58, 65] 23<br>0.126154072006<br>     [22, 28, 58, 60, 65] 11<br>0.827757042877<br>     [22, 29, 30, 59, 65] 20<br>0.410168206899<br>---&gt; [23, 29, 52, 59, 65] 22</pre><pre>real 0m41.021s<br>user 0m40.920s<br>sys 0m0.084s</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IpUepS4z-9B7UCjTOQquIw.png" /><figcaption>Winner!</figcaption></figure><h4>Importance of Secure Random</h4><p>Most developers know the importance of using secure random number generators. While a lotto simulator is by no means a critical application, we might as well take this time to remind everyone. When generating cookies, CSRF tokens, account recovery codes, crypto keys, etc. it is important that the future values are not predictable and past values are not recoverable. Using a cryptographically secure pseudo random number generator (CSPRNG) is critical. This class of PRNG is resilient to attack even when the part of the state is known by the attacker.</p><h4>Conclusion</h4><p>Using Z3 the XorShift128+ generator’s state can be recovered using three doubles from JavaScript’s Math.random(). The <a href="https://github.com/douggard/XorShift128Plus">Python script</a> is working in Chrome and Firefox.</p><p>Unfortunately, the script is not yet working in Safari. It appears the algorithm <a href="https://github.com/WebKit/webkit/commit/b3664e2851de198a9eb647196ba7af4b4f9624e5">has been implemented in WebKit</a>. However, I could not find it deployed in the JavaScriptCore framework on a MacBook Pro I had available. At first I was worried that it was a mistake in my code or they had switched algorithms, but after running the <a href="http://jandemooij.nl/blog/2015/11/27/math-random-and-32-bit-precision/">test provided on jandemooij.nl</a> and seeing a bunch of lines I am confident that Safari has not been updated yet to include the new WebKit code (at least not on that MacBook). Through testing, the <strong>Math.random() * (1.0 / (1 &lt;&lt; 53))</strong> method does appear to be the correct way to recover the lower bits of the generator’s number on Safari. So the script should be ready to go there too once it is updated.</p><p>Thanks for reading!</p><p><em>Douglas Goddard is an Analyst at </em><a href="http://www.securityevaluators.com/"><em>Independent Security Evaluators</em></a><em>.</em></p><p><em>Twitters: </em><a href="https://twitter.com/ISEsecurity"><em>@ISESecurity</em></a></p><h4><a href="http://eepurl.com/bLc2bf"><strong>Signup to get our latest blogs</strong></a></h4><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=80cc437e3b7f" width="1" height="1" alt=""><hr><p><a href="https://medium.com/independent-security-evaluators/hacking-the-javascript-lottery-80cc437e3b7f">Hacking the JavaScript Lottery</a> was originally published in <a href="https://medium.com/independent-security-evaluators">Independent Security Evaluators</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>