diff --git a/_posts/2016-07-28-how-to-rickroll-people-launching-rm-rf-on-your-system.md b/_posts/2016-07-28-how-to-rickroll-people-launching-rm-rf-on-your-system.md new file mode 100644 index 0000000..5c3cf0d --- /dev/null +++ b/_posts/2016-07-28-how-to-rickroll-people-launching-rm-rf-on-your-system.md @@ -0,0 +1,77 @@ +--- +layout: post +title: "How to rickroll people that try to run \"rm -rf\" on your system" +date: 2016-07-28 16:00:00 +0200 +categories: linux +--- + +**WARNING: The method showed here could not prevent the actual execution of "rm -rf" if the "UNIX vandal" is clever enough. Proceed at your own risk, and make backups!** + +I like Rick Astley late 80's songs, and you can see them here in my Spotify: + +![dQw4w9WgXcQ](https://dl.dropboxusercontent.com/s/t9vywa4yjotxv0o/Screenshot_20160728_154506.png?dl=0) + +I like rickrolling people myself too, especially if they're trying to delete my entire `/home` directory or, even worse, `/`. Since I learned how to use the `alias` built-in, I wanted a way to prevent that random people tinkering with my laptop (that I may forgot to lock) could delete potentially important stuff, just for fun or boredom. + +The method that I'll show will lock any `rm` command runned in both recursive and force mode, so `rm -rf`, `rm -f -r` and `rm -r --force` are all blocked, even if they are launched by `sudo`. I'm going to alias the rm command in `/etc/profile` `/etc/bash.bashrc` and in `/etc/zsh/zshrc` (I'm a zsh user) so that the rickroll will be possible from all users, even root and the ones with a brand new `bashrc` or `zshrc`. Here is the code I appended to those files: + +{% highlight bash %} +alias rm=/bin/rmAlias +alias sudo='sudo ' # this enables aliases in sudo, see http://askubuntu.com/questions/22037/aliases-not-available-when-using-sudo +{% endhighlight %} + +Since `alias` is not able to control the flags of the aliases (see [here](http://apple.stackexchange.com/questions/50963/how-do-i-add-a-flag-to-an-alias)), we're going to redirect each call of `rm` to `/bin/rmAlias`, that would run the command if it's safe. I didn't use a function because it's a bit tricky to make that work with `sudo`. So, let's see the code I put in `rmAlias`: + +{% highlight bash %} +#! /bin/bash +# Rickroll whoever tries to desert this system, even root. +# To achieve this, set the appropriate aliases even in /etc/profile and similars. + +# Video played when rickrolling +ROLLVIDEO=/opt/anti-rm/serious-video.mkv # it's just Never Gonna Give You Up on my system, but be free to customize this! + +rickroll(){ + echo "Never gonna desert this system..." + xdg-open $ROLLVIDEO 2>&1 & + exit 0 +} + +while getopts ":rf-" opt; do + # Prevent '--force' to be detected as -r and -f + if [ "$opt" = "-" ]; then + OPTIND=$OPTIND+1 + continue + fi + if [ "$opt" = "r" ] || [ "$opt" = "f" ]; then + if [ "$tmp" = "" ]; then + tmp=$opt + continue + elif [ "$tmp" != "$opt" ]; then + rickroll + fi + fi +done + +for var in "$@" +do + if [[ "$var" = "--force" && "$tmp" = "r" ]]; then + rickroll + fi +done + +# If it's safe, just run rm +/bin/rm "$@" +exit $? +{% endhighlight %} + +It may look messy to a UNIX guy more experienced than me, but it works. The `getopts` built-in sees if both the `-r` and the `-f` flags are used and, if so, it starts `rickroll()`, which opens with `xdg-open` that amazing clip from RickAstleyVEVO. From line 30 and below, the script checks if the `--force` flag is used instead of `-f`. + +Give execute permissions to the script we've just created: + +{% highlight bash %} +# chmod +x /bin/rmAlias +{% endhighlight %} + +Restart your shell, and enjoy. If you want to test safely, I suggest trying to run `rm -rf` with no folders or one nonexistant, since this script stop even these commands. + +If you want even more security, you can rename this script to `/bin/rm` and move the original one in some other place, getting rid of all the aliases. I prefer the solution above because it's tidier: you haven't to move anything. In fact, this could be just an AUR package... diff --git a/_site/2016/07/28/2016-07-28-how-to-rickroll-people-launching-rm-rf-on-your-system.html b/_site/2016/07/28/2016-07-28-how-to-rickroll-people-launching-rm-rf-on-your-system.html new file mode 100644 index 0000000..4a87b80 --- /dev/null +++ b/_site/2016/07/28/2016-07-28-how-to-rickroll-people-launching-rm-rf-on-your-system.html @@ -0,0 +1 @@ +

WARNING: this

diff --git a/_site/2016/07/28/how-to-rickroll-people-launching-rm-rf-on-your-system.html b/_site/2016/07/28/how-to-rickroll-people-launching-rm-rf-on-your-system.html new file mode 100644 index 0000000..72fb118 --- /dev/null +++ b/_site/2016/07/28/how-to-rickroll-people-launching-rm-rf-on-your-system.html @@ -0,0 +1,8 @@ +
+

layout: post +title: “How to rickroll people that run “rm -rf” on your system” +date: 2016-07-28 18:00:00 +0200 +categories: linux +—-

+ +

WARNING: this

diff --git a/_site/feed.xml b/_site/feed.xml index 76f7248..590c04e 100644 --- a/_site/feed.xml +++ b/_site/feed.xml @@ -6,10 +6,86 @@ http://praticamentetilde.github.io/ - Tue, 12 Jul 2016 20:21:14 +0200 - Tue, 12 Jul 2016 20:21:14 +0200 + Thu, 28 Jul 2016 15:51:30 +0200 + Thu, 28 Jul 2016 15:51:30 +0200 Jekyll v3.1.6 + + How to rickroll people that try to run "rm -rf" on your system + <p><strong>WARNING: The method showed here could not prevent the actual execution of “rm -rf” if the “UNIX vandal” is clever enough. Proceed at your own risk, and make backups!</strong></p> + +<p>I like Rick Astley late 80’s songs, and you can see them here in my Spotify:</p> + +<p><img src="https://dl.dropboxusercontent.com/s/t9vywa4yjotxv0o/Screenshot_20160728_154506.png?dl=0" alt="dQw4w9WgXcQ" /></p> + +<p>I like rickrolling people myself too, especially if they’re trying to delete my entire <code class="highlighter-rouge">/home</code> directory or, even worse, <code class="highlighter-rouge">/</code>. Since I learned how to use the <code class="highlighter-rouge">alias</code> built-in, I wanted a way to prevent that random people tinkering with my laptop (that I may forgot to lock) could delete potentially important stuff, just for fun or boredom.</p> + +<p>The method that I’ll show will lock any <code class="highlighter-rouge">rm</code> command runned in both recursive and force mode, so <code class="highlighter-rouge">rm -rf</code>, <code class="highlighter-rouge">rm -f -r</code> and <code class="highlighter-rouge">rm -r --force</code> are all blocked, even if they are launched by <code class="highlighter-rouge">sudo</code>. I’m going to alias the rm command in <code class="highlighter-rouge">/etc/profile</code> <code class="highlighter-rouge">/etc/bash.bashrc</code> and in <code class="highlighter-rouge">/etc/zsh/zshrc</code> (I’m a zsh user) so that the rickroll will be possible from all users, even root and the ones with a brand new <code class="highlighter-rouge">bashrc</code> or <code class="highlighter-rouge">zshrc</code>. Here is the code I appended to those files:</p> + +<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nb">alias </span><span class="nv">rm</span><span class="o">=</span>/bin/rmAlias +<span class="nb">alias </span><span class="nv">sudo</span><span class="o">=</span><span class="s1">'sudo '</span> <span class="c"># this enables aliases in sudo, see http://askubuntu.com/questions/22037/aliases-not-available-when-using-sudo</span></code></pre></figure> + +<p>Since <code class="highlighter-rouge">alias</code> is not able to control flags of the aliases (see <a href="http://apple.stackexchange.com/questions/50963/how-do-i-add-a-flag-to-an-alias">here</a>), we’re going to redirect each call of <code class="highlighter-rouge">rm</code> to <code class="highlighter-rouge">/bin/rmAlias</code>, that would run the command if it’s safe. I didn’t use a function because it’s a bit tricky to make that work with <code class="highlighter-rouge">sudo</code>. So, let’s see the code I put in <code class="highlighter-rouge">rmAlias</code>:</p> + +<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="c">#! /bin/bash</span> +<span class="c"># Rickroll whoever tries to desert this system, even root.</span> +<span class="c"># To achieve this, set the appropriate aliases even in /etc/profile and similars.</span> + +<span class="c"># Video played when rickrolling</span> +<span class="nv">ROLLVIDEO</span><span class="o">=</span>/opt/anti-rm/serious-video.mkv <span class="c"># it's just Never Gonna Give You Up on my system, but be free to customize this!</span> + +rickroll<span class="o">(){</span> + <span class="nb">echo</span> <span class="s2">"Never gonna desert this system..."</span> + xdg-open <span class="nv">$ROLLVIDEO</span> 2&gt;&amp;1 &amp; + <span class="nb">exit </span>0 +<span class="o">}</span> + +<span class="k">while </span><span class="nb">getopts</span> <span class="s2">":rf-"</span> opt; <span class="k">do</span> + <span class="c"># Prevent '--force' to be detected as -r and -f</span> + <span class="k">if</span> <span class="o">[</span> <span class="s2">"</span><span class="nv">$opt</span><span class="s2">"</span> <span class="o">=</span> <span class="s2">"-"</span> <span class="o">]</span>; <span class="k">then + </span><span class="nv">OPTIND</span><span class="o">=</span><span class="nv">$OPTIND</span>+1 + <span class="k">continue + fi + if</span> <span class="o">[</span> <span class="s2">"</span><span class="nv">$opt</span><span class="s2">"</span> <span class="o">=</span> <span class="s2">"r"</span> <span class="o">]</span> <span class="o">||</span> <span class="o">[</span> <span class="s2">"</span><span class="nv">$opt</span><span class="s2">"</span> <span class="o">=</span> <span class="s2">"f"</span> <span class="o">]</span>; <span class="k">then + if</span> <span class="o">[</span> <span class="s2">"</span><span class="nv">$tmp</span><span class="s2">"</span> <span class="o">=</span> <span class="s2">""</span> <span class="o">]</span>; <span class="k">then + </span><span class="nv">tmp</span><span class="o">=</span><span class="nv">$opt</span> + <span class="k">continue + elif</span> <span class="o">[</span> <span class="s2">"</span><span class="nv">$tmp</span><span class="s2">"</span> !<span class="o">=</span> <span class="s2">"</span><span class="nv">$opt</span><span class="s2">"</span> <span class="o">]</span>; <span class="k">then + </span>rickroll + <span class="k">fi + fi +done + +for </span>var <span class="k">in</span> <span class="s2">"</span><span class="nv">$@</span><span class="s2">"</span> +<span class="k">do + if</span> <span class="o">[[</span> <span class="s2">"</span><span class="nv">$var</span><span class="s2">"</span> <span class="o">=</span> <span class="s2">"--force"</span> <span class="o">&amp;&amp;</span> <span class="s2">"</span><span class="nv">$tmp</span><span class="s2">"</span> <span class="o">=</span> <span class="s2">"r"</span> <span class="o">]]</span>; <span class="k">then + </span>rickroll + <span class="k">fi +done</span> + +<span class="c"># If it's safe, just run rm</span> +/bin/rm <span class="s2">"</span><span class="nv">$@</span><span class="s2">"</span> +<span class="nb">exit</span> <span class="nv">$?</span></code></pre></figure> + +<p>It may look messy to a UNIX guy more experienced than me, but it works. The <code class="highlighter-rouge">getopts</code> built-in sees if both the <code class="highlighter-rouge">-r</code> and the <code class="highlighter-rouge">-f</code> flags are used and, if so, it starts <code class="highlighter-rouge">rickroll()</code>, which opens with <code class="highlighter-rouge">xdg-open</code> that amazing clip from RickAstleyVEVO. From line 30 and below, the script checks if the <code class="highlighter-rouge">--force</code> flag is used instead of <code class="highlighter-rouge">-f</code>.</p> + +<p>Give execute permissions to the script we’ve just created:</p> + +<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="c"># chmod +x /bin/rmAlias</span></code></pre></figure> + +<p>Restart your shell, and enjoy. If you want to test safely, I suggest trying to run <code class="highlighter-rouge">rm -rf</code> with no folders or one nonexistant, since this script stop even these commands.</p> + +<p>If you want even more security, you can rename this script to <code class="highlighter-rouge">/bin/rm</code> and move the original one in some other place, getting rid of all the aliases. I prefer the solution above because it’s tidier: you haven’t to move anything. In fact, this could be just an AUR package…</p> + + Thu, 28 Jul 2016 16:00:00 +0200 + http://praticamentetilde.github.io/linux/2016/07/28/how-to-rickroll-people-launching-rm-rf-on-your-system.html + http://praticamentetilde.github.io/linux/2016/07/28/how-to-rickroll-people-launching-rm-rf-on-your-system.html + + + linux + + + Installing Gentoo on a Lenovo ThinkPad X60s <p>My only laptop is a <a href="http://www.thinkwiki.org/wiki/Category:X60s">IBM/Lenovo ThinkPad X60s</a>, a top line “ultrabook” from 2006 that features:</p> diff --git a/_site/index.html b/_site/index.html index bc3f5da..51bfa01 100644 --- a/_site/index.html +++ b/_site/index.html @@ -124,6 +124,14 @@
    +
  • + + +

    + How to rickroll people that try to run "rm -rf" on your system +

    +
  • +
  • diff --git a/_site/linux/2016/07/12/how-to-rickroll-people-launching-rm-rf-on-your-system.html b/_site/linux/2016/07/12/how-to-rickroll-people-launching-rm-rf-on-your-system.html new file mode 100644 index 0000000..a138ad7 --- /dev/null +++ b/_site/linux/2016/07/12/how-to-rickroll-people-launching-rm-rf-on-your-system.html @@ -0,0 +1,213 @@ + + + + + + + + How to rickroll people that try to run "rm -rf" on your system + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    +
    + +
    +

    How to rickroll people that try to run "rm -rf" on your system

    + +
    + +
    +

    WARNING: The method showed here could not prevent the actual execution of “rm -rf” if the “UNIX vandal” is clever enough. Proceed at your own risk, and make backups!

    + +

    I like Rick Astley late 80’s songs, and you can see them here in my Spotify:

    + +

    dQw4w9WgXcQ

    + +

    I like rickrolling people myself too, especially if they’re trying to delete my entire /home directory or, even worse, /. Since I learned how to use the alias built-in, I wanted a way to prevent that random people tinkering with my laptop (that I may forgot to lock) could delete potentially important stuff, just for fun or boredom.

    + +

    The method that I’ll show will lock any rm command runned in both recursive and force mode, so rm -rf, rm -f -r and rm -r --force are all blocked, even if they are launched by sudo. I’m going to alias the rm command in /etc/profile /etc/bash.bashrc and in /etc/zsh/zshrc (I’m a zsh user) so that the rickroll will be possible from all users, even root and the ones with a brand new bashrc or zshrc. Here is the code I appended to those files:

    + +
    alias rm=/bin/rmAlias
    +alias sudo='sudo ' # this enables aliases in sudo, see http://askubuntu.com/questions/22037/aliases-not-available-when-using-sudo
    + +

    Since alias is not able to control flags of the aliases (see here), we’re going to redirect each call of rm to /bin/rmAlias, that would run the command if it’s safe. I didn’t use a function because it’s a bit tricky to make that work with sudo. So, let’s see the code I put in rmAlias:

    + +
    #! /bin/bash
    +# Rickroll whoever tries to desert this system, even root.
    +# To achieve this, set the appropriate aliases even in /etc/profile and similars.
    +
    +# Video played when rickrolling
    +ROLLVIDEO=/opt/anti-rm/serious-video.mkv # it's just Never Gonna Give You Up on my system, but be free to customize this!
    +
    +rickroll(){
    +  echo "Never gonna desert this system..."
    +  xdg-open $ROLLVIDEO 2>&1 &
    +  exit 0
    +}
    +
    +while getopts ":rf-" opt; do
    +  # Prevent '--force' to be detected as -r and -f
    +  if [ "$opt" = "-" ]; then
    +    OPTIND=$OPTIND+1
    +    continue
    +  fi
    +  if [ "$opt" = "r" ] || [ "$opt" = "f" ]; then
    +    if [ "$tmp" = "" ]; then
    +      tmp=$opt
    +      continue
    +    elif [ "$tmp" != "$opt" ]; then
    +      rickroll
    +    fi
    +  fi
    +done
    +
    +for var in "$@"
    +do
    +  if [[ "$var" = "--force" && "$tmp" = "r" ]]; then
    +    rickroll
    +  fi
    +done
    +
    +# If it's safe, just run rm
    +/bin/rm "$@"
    +exit $?
    + +

    It may look messy to a UNIX guy more experienced than me, but it works. The getopts built-in sees if both the -r and the -f flags are used and, if so, it starts rickroll(), which opens with xdg-open that amazing clip from RickAstleyVEVO. From line 30 and below, the script checks if the --force flag is used instead of -f.

    + +

    Give execute permissions to the script we’ve just created:

    + +
    # chmod +x /bin/rmAlias
    + +

    Restart your shell, and enjoy. If you want to test safely, I suggest trying to run rm -rf with no folders or one nonexistant, since this script stop even these commands.

    + +

    If you want even more security, you can rename this script to /bin/rm and move the original one in some other place, getting rid of all the aliases. I prefer the solution above because it’s tidier: you haven’t to move anything. In fact, this could be just an AUR package…

    + +
    + +
    +
    + + + + +
    +
    +
    + +
    + + + + +
    + +
    + + + diff --git a/_site/linux/2016/07/28/how-to-rickroll-people-launching-rm-rf-on-your-system.html b/_site/linux/2016/07/28/how-to-rickroll-people-launching-rm-rf-on-your-system.html new file mode 100644 index 0000000..23fd2eb --- /dev/null +++ b/_site/linux/2016/07/28/how-to-rickroll-people-launching-rm-rf-on-your-system.html @@ -0,0 +1,213 @@ + + + + + + + + How to rickroll people that try to run "rm -rf" on your system + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    +
    +
    + +
    +

    How to rickroll people that try to run "rm -rf" on your system

    + +
    + +
    +

    WARNING: The method showed here could not prevent the actual execution of “rm -rf” if the “UNIX vandal” is clever enough. Proceed at your own risk, and make backups!

    + +

    I like Rick Astley late 80’s songs, and you can see them here in my Spotify:

    + +

    dQw4w9WgXcQ

    + +

    I like rickrolling people myself too, especially if they’re trying to delete my entire /home directory or, even worse, /. Since I learned how to use the alias built-in, I wanted a way to prevent that random people tinkering with my laptop (that I may forgot to lock) could delete potentially important stuff, just for fun or boredom.

    + +

    The method that I’ll show will lock any rm command runned in both recursive and force mode, so rm -rf, rm -f -r and rm -r --force are all blocked, even if they are launched by sudo. I’m going to alias the rm command in /etc/profile /etc/bash.bashrc and in /etc/zsh/zshrc (I’m a zsh user) so that the rickroll will be possible from all users, even root and the ones with a brand new bashrc or zshrc. Here is the code I appended to those files:

    + +
    alias rm=/bin/rmAlias
    +alias sudo='sudo ' # this enables aliases in sudo, see http://askubuntu.com/questions/22037/aliases-not-available-when-using-sudo
    + +

    Since alias is not able to control flags of the aliases (see here), we’re going to redirect each call of rm to /bin/rmAlias, that would run the command if it’s safe. I didn’t use a function because it’s a bit tricky to make that work with sudo. So, let’s see the code I put in rmAlias:

    + +
    #! /bin/bash
    +# Rickroll whoever tries to desert this system, even root.
    +# To achieve this, set the appropriate aliases even in /etc/profile and similars.
    +
    +# Video played when rickrolling
    +ROLLVIDEO=/opt/anti-rm/serious-video.mkv # it's just Never Gonna Give You Up on my system, but be free to customize this!
    +
    +rickroll(){
    +  echo "Never gonna desert this system..."
    +  xdg-open $ROLLVIDEO 2>&1 &
    +  exit 0
    +}
    +
    +while getopts ":rf-" opt; do
    +  # Prevent '--force' to be detected as -r and -f
    +  if [ "$opt" = "-" ]; then
    +    OPTIND=$OPTIND+1
    +    continue
    +  fi
    +  if [ "$opt" = "r" ] || [ "$opt" = "f" ]; then
    +    if [ "$tmp" = "" ]; then
    +      tmp=$opt
    +      continue
    +    elif [ "$tmp" != "$opt" ]; then
    +      rickroll
    +    fi
    +  fi
    +done
    +
    +for var in "$@"
    +do
    +  if [[ "$var" = "--force" && "$tmp" = "r" ]]; then
    +    rickroll
    +  fi
    +done
    +
    +# If it's safe, just run rm
    +/bin/rm "$@"
    +exit $?
    + +

    It may look messy to a UNIX guy more experienced than me, but it works. The getopts built-in sees if both the -r and the -f flags are used and, if so, it starts rickroll(), which opens with xdg-open that amazing clip from RickAstleyVEVO. From line 30 and below, the script checks if the --force flag is used instead of -f.

    + +

    Give execute permissions to the script we’ve just created:

    + +
    # chmod +x /bin/rmAlias
    + +

    Restart your shell, and enjoy. If you want to test safely, I suggest trying to run rm -rf with no folders or one nonexistant, since this script stop even these commands.

    + +

    If you want even more security, you can rename this script to /bin/rm and move the original one in some other place, getting rid of all the aliases. I prefer the solution above because it’s tidier: you haven’t to move anything. In fact, this could be just an AUR package…

    + +
    + +
    +
    + + + + +
    +
    + + + +