COnverted astleyrm to HTML

This commit is contained in:
Claudio Maggioni 2018-10-24 13:53:55 +02:00
parent 48f648cae3
commit c04a7848b9
9 changed files with 380 additions and 166 deletions

View file

@ -0,0 +1,128 @@
---
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
---
<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>
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="My Spotify with a bunch of Rick Astley songs">
</p>
<p>
I like rickrolling people too, especially if they are trying to delete my entire
<code>/home</code> directory or, even worse, <code>/</code>. Since I learned
how to use the <code>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 will show will lock any <code>rm</code> command runned in
both recursive and force mode, so <code>rm -rf</code>, <code>rm -f -r</code>
and <code>rm -r --force</code> are all blocked, even if they are runned with
<code>sudo</code>. I am going to alias the rm command in
<code>/etc/profile</code>, <code>/etc/bash.bashrc</code> and in
<code>/etc/zsh/zshrc</code> (I am a zsh user) so that the rickroll will be
possible from all users, even root and the ones with a brand new
<code>.bashrc</code> or <code>.zshrc</code>. Here is the code I appended to
those files:
</p>
<p>
{% 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 %}
</p>
<p>
Since <code>alias</code> is not able to control the 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 are going to redirect each call of <code>rm</code> to
<code>/bin/rmAlias</code>, that would run the command if it is safe. I did
not use a function because it is a bit tricky to make that work with
<code>sudo</code>. So, let's see the code I put in <code>rmAlias</code>:
</p>
<p>
{% 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 %}
</p>
<p>
It may look messy to a <em>UNIX</em> guy more experienced than me, but it
works. The <code>getopts</code> built-in sees if both the <code>-r</code> and
the <code>-f</code> flags are used and, if so, it starts
<code>rickroll()</code>, which opens with <code>xdg-open</code> that amazing
clip from <em>RickAstleyVEVO</em>. From line 30 and below, the script checks
if the <code>--force</code> flag is used instead of <code>-f</code>.
</p>
<p>
Let's give execution permissions to the script we have just created:
</p>
<p>
{% highlight bash %}
# chmod +x /bin/rmAlias
{% endhighlight %}
</p>
<p>
Restart your shell, and enjoy. If you want to test safely, I suggest trying
to run <code>rm -rf</code> with no folders or a nonexistant one, since this
script stops even these commands.
</p>
<p>
If you want even more security, you can rename this script to
<code>/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>

View file

@ -1,78 +0,0 @@
---
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
---
<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>
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...

View file

@ -58,24 +58,18 @@ a {
blockquote {
color: $grey-color;
border-left: 4px solid $grey-color-light;
padding-left: $spacing-unit / 2;
font-size: 18px;
letter-spacing: -1px;
font-style: italic;
margin: 1rem 0;
padding: 1em;
> :last-child {
margin-bottom: 0;
}
}
/**
* Code formatting
*/
pre, code {
font-size: 15px;
background: rgb(66,66,66);
}
/* do not put padding around the table with line numbers and the code */
code table {
margin: -8px -12px;
}
@ -95,6 +89,26 @@ pre {
}
}
/* pull a nice monospace font from the internets, plus set font and
* background */
pre, code {
font-size: 0.95rem;
background: rgb(66,66,66);
font-family: "Source Code Pro", monospace;
}
/* Disable borders between line numbers and code when
* line numbers are shown */
code .rouge-table, code .rouge-table td {
border: 0;
border-radius: 0;
}
code .rouge-table {
border-spacing: 0;
border-collapse: collapse;
}
/**
* Basic layout rules
*/
@ -116,46 +130,33 @@ h6 { font-size: 0.8rem; }
* General style for the content inside main
*/
/* separate article metadata to the article itself with some space */
article .post-header {
margin-bottom: 3rem;
}
main article {
margin-bottom: 2em;
/* put some space at the end of each article and at the end of each section */
main article, main section {
margin-bottom: 2rem;
}
/* justify text */
p {
text-align: justify;
}
/* put a space between paragraphs and images */
p, figure {
margin-top: 1.2rem;
}
/* the first paragraph has no space at the top (since that is provided
* by either main or h? */
p:first-child {
margin-top: 0;
}
/**
* Syntax highlighting
*/
pre, code {
font-family: "Source Code Pro", monospace;
}
/* Disable borders between line numbers and code when
* line numbers are shown */
code .rouge-table, code .rouge-table td {
border: 0;
border-radius: 0;
}
code .rouge-table {
border-spacing: 0;
border-collapse: collapse;
}
/* make strongly emphasized elements REALLY STRONG */
strong {
background: #aa2222;
}

View file

@ -47,20 +47,15 @@ a {
blockquote {
color: #828282;
border-left: 4px solid #e8e8e8;
padding-left: 15px;
font-size: 18px;
letter-spacing: -1px;
font-style: italic; }
font-style: italic;
margin: 1rem 0;
padding: 1em; }
blockquote > :last-child {
margin-bottom: 0; }
/**
* Code formatting
*/
pre, code {
font-size: 15px;
background: #424242; }
/* do not put padding around the table with line numbers and the code */
code table {
margin: -8px -12px; }
@ -75,6 +70,23 @@ pre {
padding-right: 0;
padding-left: 0; }
/* pull a nice monospace font from the internets, plus set font and
* background */
pre, code {
font-size: 0.95rem;
background: #424242;
font-family: "Source Code Pro", monospace; }
/* Disable borders between line numbers and code when
* line numbers are shown */
code .rouge-table, code .rouge-table td {
border: 0;
border-radius: 0; }
code .rouge-table {
border-spacing: 0;
border-collapse: collapse; }
/**
* Basic layout rules
*/
@ -105,37 +117,28 @@ h6 {
/**
* General style for the content inside main
*/
/* separate article metadata to the article itself with some space */
article .post-header {
margin-bottom: 3rem; }
main article {
margin-bottom: 2em; }
/* put some space at the end of each article and at the end of each section */
main article, main section {
margin-bottom: 2rem; }
/* justify text */
p {
text-align: justify; }
/* put a space between paragraphs and images */
p, figure {
margin-top: 1.2rem; }
/* the first paragraph has no space at the top (since that is provided
* by either main or h? */
p:first-child {
margin-top: 0; }
/**
* Syntax highlighting
*/
pre, code {
font-family: "Source Code Pro", monospace; }
/* Disable borders between line numbers and code when
* line numbers are shown */
code .rouge-table, code .rouge-table td {
border: 0;
border-radius: 0; }
code .rouge-table {
border-spacing: 0;
border-collapse: collapse; }
/* make strongly emphasized elements REALLY STRONG */
strong {
background: #aa2222; }

View file

@ -6,29 +6,60 @@
</description>
<link>http://localhost:4000/</link>
<atom:link href="http://localhost:4000/feed.xml" rel="self" type="application/rss+xml"/>
<pubDate>Tue, 23 Oct 2018 17:24:59 +0200</pubDate>
<lastBuildDate>Tue, 23 Oct 2018 17:24:59 +0200</lastBuildDate>
<pubDate>Wed, 24 Oct 2018 13:52:54 +0200</pubDate>
<lastBuildDate>Wed, 24 Oct 2018 13:52:54 +0200</lastBuildDate>
<generator>Jekyll v3.8.4</generator>
<item>
<title>How to rickroll people that try to run &quot;rm -rf&quot; on your system</title>
<description>&lt;p&gt;&lt;strong&gt;
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!
&lt;/strong&gt;&lt;/p&gt;
<description>&lt;strong&gt;
WARNING: The method showed here could not prevent the actual execution of &quot;rm -rf&quot; if the &quot;UNIX vandal&quot; is clever enough. Proceed at your own risk, and make backups!
&lt;/strong&gt;
&lt;p&gt;I like Rick Astley late 80s songs, and you can see them here in my Spotify:&lt;/p&gt;
&lt;p&gt;
I like Rick Astley late 80's songs, and you can see them here in my Spotify:
&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://dl.dropboxusercontent.com/s/t9vywa4yjotxv0o/Screenshot_20160728_154506.png?dl=0&quot; alt=&quot;dQw4w9WgXcQ&quot; /&gt;&lt;/p&gt;
&lt;p&gt;
&lt;img
src=&quot;https://dl.dropboxusercontent.com/s/t9vywa4yjotxv0o/Screenshot_20160728_154506.png?dl=0&quot;
alt=&quot;My Spotify with a bunch of Rick Astley songs&quot;&gt;
&lt;/p&gt;
&lt;p&gt;I like rickrolling people myself too, especially if theyre trying to delete my entire &lt;code class=&quot;highlighter-rouge&quot;&gt;/home&lt;/code&gt; directory or, even worse, &lt;code class=&quot;highlighter-rouge&quot;&gt;/&lt;/code&gt;. Since I learned how to use the &lt;code class=&quot;highlighter-rouge&quot;&gt;alias&lt;/code&gt; 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.&lt;/p&gt;
&lt;p&gt;
I like rickrolling people too, especially if they are trying to delete my entire
&lt;code&gt;/home&lt;/code&gt; directory or, even worse, &lt;code&gt;/&lt;/code&gt;. Since I learned
how to use the &lt;code&gt;alias&lt;/code&gt; 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.
&lt;/p&gt;
&lt;p&gt;The method that Ill show will lock any &lt;code class=&quot;highlighter-rouge&quot;&gt;rm&lt;/code&gt; command runned in both recursive and force mode, so &lt;code class=&quot;highlighter-rouge&quot;&gt;rm -rf&lt;/code&gt;, &lt;code class=&quot;highlighter-rouge&quot;&gt;rm -f -r&lt;/code&gt; and &lt;code class=&quot;highlighter-rouge&quot;&gt;rm -r --force&lt;/code&gt; are all blocked, even if they are launched by &lt;code class=&quot;highlighter-rouge&quot;&gt;sudo&lt;/code&gt;. Im going to alias the rm command in &lt;code class=&quot;highlighter-rouge&quot;&gt;/etc/profile&lt;/code&gt; &lt;code class=&quot;highlighter-rouge&quot;&gt;/etc/bash.bashrc&lt;/code&gt; and in &lt;code class=&quot;highlighter-rouge&quot;&gt;/etc/zsh/zshrc&lt;/code&gt; (Im a zsh user) so that the rickroll will be possible from all users, even root and the ones with a brand new &lt;code class=&quot;highlighter-rouge&quot;&gt;bashrc&lt;/code&gt; or &lt;code class=&quot;highlighter-rouge&quot;&gt;zshrc&lt;/code&gt;. Here is the code I appended to those files:&lt;/p&gt;
&lt;p&gt;
The method that I will show will lock any &lt;code&gt;rm&lt;/code&gt; command runned in
both recursive and force mode, so &lt;code&gt;rm -rf&lt;/code&gt;, &lt;code&gt;rm -f -r&lt;/code&gt;
and &lt;code&gt;rm -r --force&lt;/code&gt; are all blocked, even if they are runned with
&lt;code&gt;sudo&lt;/code&gt;. I am going to alias the rm command in
&lt;code&gt;/etc/profile&lt;/code&gt;, &lt;code&gt;/etc/bash.bashrc&lt;/code&gt; and in
&lt;code&gt;/etc/zsh/zshrc&lt;/code&gt; (I am a zsh user) so that the rickroll will be
possible from all users, even root and the ones with a brand new
&lt;code&gt;.bashrc&lt;/code&gt; or &lt;code&gt;.zshrc&lt;/code&gt;. Here is the code I appended to
those files:
&lt;/p&gt;
&lt;p&gt;
&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;nb&quot;&gt;alias rm&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;/bin/rmAlias
&lt;span class=&quot;nb&quot;&gt;alias sudo&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;s1&quot;&gt;'sudo '&lt;/span&gt; &lt;span class=&quot;c&quot;&gt;# this enables aliases in sudo, see http://askubuntu.com/questions/22037/aliases-not-available-when-using-sudo&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p&gt;Since &lt;code class=&quot;highlighter-rouge&quot;&gt;alias&lt;/code&gt; is not able to control the flags of the aliases (see &lt;a href=&quot;http://apple.stackexchange.com/questions/50963/how-do-i-add-a-flag-to-an-alias&quot;&gt;here&lt;/a&gt;), were going to redirect each call of &lt;code class=&quot;highlighter-rouge&quot;&gt;rm&lt;/code&gt; to &lt;code class=&quot;highlighter-rouge&quot;&gt;/bin/rmAlias&lt;/code&gt;, that would run the command if its safe. I didnt use a function because its a bit tricky to make that work with &lt;code class=&quot;highlighter-rouge&quot;&gt;sudo&lt;/code&gt;. So, lets see the code I put in &lt;code class=&quot;highlighter-rouge&quot;&gt;rmAlias&lt;/code&gt;:&lt;/p&gt;
&lt;p&gt;
Since &lt;code&gt;alias&lt;/code&gt; is not able to control the flags of the aliases (see
&lt;a href=&quot;http://apple.stackexchange.com/questions/50963/how-do-i-add-a-flag-to-an-alias&quot;&gt;here&lt;/a&gt;, we are going to redirect each call of &lt;code&gt;rm&lt;/code&gt; to
&lt;code&gt;/bin/rmAlias&lt;/code&gt;, that would run the command if it is safe. I did
not use a function because it is a bit tricky to make that work with
&lt;code&gt;sudo&lt;/code&gt;. So, let's see the code I put in &lt;code&gt;rmAlias&lt;/code&gt;:
&lt;/p&gt;
&lt;p&gt;
&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;c&quot;&gt;#! /bin/bash&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# Rickroll whoever tries to desert this system, even root.&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# To achieve this, set the appropriate aliases even in /etc/profile and similars.&lt;/span&gt;
@ -68,16 +99,35 @@ done&lt;/span&gt;
&lt;span class=&quot;c&quot;&gt;# If it's safe, just run rm&lt;/span&gt;
/bin/rm &lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$@&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;&lt;/span&gt;
&lt;span class=&quot;nb&quot;&gt;exit&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$?&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p&gt;It may look messy to a UNIX guy more experienced than me, but it works. The &lt;code class=&quot;highlighter-rouge&quot;&gt;getopts&lt;/code&gt; built-in sees if both the &lt;code class=&quot;highlighter-rouge&quot;&gt;-r&lt;/code&gt; and the &lt;code class=&quot;highlighter-rouge&quot;&gt;-f&lt;/code&gt; flags are used and, if so, it starts &lt;code class=&quot;highlighter-rouge&quot;&gt;rickroll()&lt;/code&gt;, which opens with &lt;code class=&quot;highlighter-rouge&quot;&gt;xdg-open&lt;/code&gt; that amazing clip from RickAstleyVEVO. From line 30 and below, the script checks if the &lt;code class=&quot;highlighter-rouge&quot;&gt;--force&lt;/code&gt; flag is used instead of &lt;code class=&quot;highlighter-rouge&quot;&gt;-f&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;
It may look messy to a &lt;em&gt;UNIX&lt;/em&gt; guy more experienced than me, but it
works. The &lt;code&gt;getopts&lt;/code&gt; built-in sees if both the &lt;code&gt;-r&lt;/code&gt; and
the &lt;code&gt;-f&lt;/code&gt; flags are used and, if so, it starts
&lt;code&gt;rickroll()&lt;/code&gt;, which opens with &lt;code&gt;xdg-open&lt;/code&gt; that amazing
clip from &lt;em&gt;RickAstleyVEVO&lt;/em&gt;. From line 30 and below, the script checks
if the &lt;code&gt;--force&lt;/code&gt; flag is used instead of &lt;code&gt;-f&lt;/code&gt;.
&lt;/p&gt;
&lt;p&gt;Give execute permissions to the script weve just created:&lt;/p&gt;
&lt;p&gt;
Let's give execution permissions to the script we have just created:
&lt;/p&gt;
&lt;p&gt;
&lt;figure class=&quot;highlight&quot;&gt;&lt;pre&gt;&lt;code class=&quot;language-bash&quot; data-lang=&quot;bash&quot;&gt;&lt;span class=&quot;c&quot;&gt;# chmod +x /bin/rmAlias&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/figure&gt;
&lt;/p&gt;
&lt;p&gt;Restart your shell, and enjoy. If you want to test safely, I suggest trying to run &lt;code class=&quot;highlighter-rouge&quot;&gt;rm -rf&lt;/code&gt; with no folders or one nonexistant, since this script stop even these commands.&lt;/p&gt;
&lt;p&gt;
Restart your shell, and enjoy. If you want to test safely, I suggest trying
to run &lt;code&gt;rm -rf&lt;/code&gt; with no folders or a nonexistant one, since this
script stops even these commands.
&lt;/p&gt;
&lt;p&gt;If you want even more security, you can rename this script to &lt;code class=&quot;highlighter-rouge&quot;&gt;/bin/rm&lt;/code&gt; and move the original one in some other place, getting rid of all the aliases. I prefer the solution above because its tidier: you havent to move anything. In fact, this could be just an AUR package…&lt;/p&gt;
&lt;p&gt;
If you want even more security, you can rename this script to
&lt;code&gt;/bin/rm&lt;/code&gt; 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...
&lt;/p&gt;
</description>
<pubDate>Thu, 28 Jul 2016 16:00:00 +0200</pubDate>
<link>http://localhost:4000/linux/2016/07/28/how-to-rickroll-people-launching-rm-rf-on-your-system.html</link>

View file

@ -92,7 +92,37 @@
</header>
<main class="container">
<div class="home">
<h1>Welcome on Claudio Maggioni's website!</h1>
<section>
<h1>Welcome to Claudio Maggioni&#39;s website!</h1>
<p>Right now this page is almost empty because I have nothing to put in.
But remember:</p>
<blockquote>
<p>Eat <a target="_blank" href="https://en.wikipedia.org/wiki/Polenta">
<em>polenta</em></a> and do not counter-aim!</p>
</blockquote>
<p>The original, in italian:</p>
<blockquote>
<p>Mangiate la
<a target="_blank" href="https://it.wikipedia.org/wiki/Polenta">
<em>polenta</em>
</a>
e non contromirate!</p>
</blockquote>
</section>
<section>
<h2>Self-hosted stuff</h2>
<p>
Here are the <em>awesome</em> services provided by <code>maggioni.xyz</code>:
</p>
<ul>
<li><a href="https://git.maggioni.xyz">Gogs</a>, a private Git HTTP frontend;</li>
<li><a href="https://ci.maggioni.xyz">Drone CI</a>, a private CI/CD server;</li>
<li><a href="https://cloud.maggioni.xyz"><code>maggioni.xyz</code> cloud</a>,
a private <em>Nextcloud</em> instance;</li>
<li><a href="https://download.maggioni.xyz">Download area</a>, a generic download
area for the stuff that i want to put in.</li>
</ul>
</section>
</div>
</main>

View file

@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>How to rickroll people that try to run &quot;rm -rf&quot; on your system</title>
<meta name="description" content="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 ...">
<meta name="description" content="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 ...">
<link rel="stylesheet" href="/css/main.css">
<link href='https://fonts.googleapis.com/css?family=Hammersmith+One' rel='stylesheet' type='text/css'>
@ -98,23 +98,54 @@
</header>
<div class="post-content" itemprop="articleBody">
<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>
<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>I like Rick Astley late 80s songs, and you can see them here in my Spotify:</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>
<img
src="https://dl.dropboxusercontent.com/s/t9vywa4yjotxv0o/Screenshot_20160728_154506.png?dl=0"
alt="My Spotify with a bunch of Rick Astley songs">
</p>
<p>I like rickrolling people myself too, especially if theyre 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>
I like rickrolling people too, especially if they are trying to delete my entire
<code>/home</code> directory or, even worse, <code>/</code>. Since I learned
how to use the <code>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 Ill 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>. Im 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> (Im 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>
<p>
The method that I will show will lock any <code>rm</code> command runned in
both recursive and force mode, so <code>rm -rf</code>, <code>rm -f -r</code>
and <code>rm -r --force</code> are all blocked, even if they are runned with
<code>sudo</code>. I am going to alias the rm command in
<code>/etc/profile</code>, <code>/etc/bash.bashrc</code> and in
<code>/etc/zsh/zshrc</code> (I am a zsh user) so that the rickroll will be
possible from all users, even root and the ones with a brand new
<code>.bashrc</code> or <code>.zshrc</code>. Here is the code I appended to
those files:
</p>
<p>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="nb">alias rm</span><span class="o">=</span>/bin/rmAlias
<span class="nb">alias 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>
<p>Since <code class="highlighter-rouge">alias</code> is not able to control the flags of the aliases (see <a href="http://apple.stackexchange.com/questions/50963/how-do-i-add-a-flag-to-an-alias">here</a>), were 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 its safe. I didnt use a function because its a bit tricky to make that work with <code class="highlighter-rouge">sudo</code>. So, lets see the code I put in <code class="highlighter-rouge">rmAlias</code>:</p>
<p>
Since <code>alias</code> is not able to control the 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 are going to redirect each call of <code>rm</code> to
<code>/bin/rmAlias</code>, that would run the command if it is safe. I did
not use a function because it is a bit tricky to make that work with
<code>sudo</code>. So, let's see the code I put in <code>rmAlias</code>:
</p>
<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>
@ -154,16 +185,35 @@ 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>
<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>
It may look messy to a <em>UNIX</em> guy more experienced than me, but it
works. The <code>getopts</code> built-in sees if both the <code>-r</code> and
the <code>-f</code> flags are used and, if so, it starts
<code>rickroll()</code>, which opens with <code>xdg-open</code> that amazing
clip from <em>RickAstleyVEVO</em>. From line 30 and below, the script checks
if the <code>--force</code> flag is used instead of <code>-f</code>.
</p>
<p>Give execute permissions to the script weve just created:</p>
<p>
Let's give execution permissions to the script we have just created:
</p>
<p>
<figure class="highlight"><pre><code class="language-bash" data-lang="bash"><span class="c"># chmod +x /bin/rmAlias</span></code></pre></figure>
</p>
<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>
Restart your shell, and enjoy. If you want to test safely, I suggest trying
to run <code>rm -rf</code> with no folders or a nonexistant one, since this
script stops 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 its tidier: you havent to move anything. In fact, this could be just an AUR package…</p>
<p>
If you want even more security, you can rename this script to
<code>/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>
</div>

View file

@ -3,5 +3,35 @@ layout: main
---
<div class="home">
<h1>Welcome on Claudio Maggioni's website!</h1>
<section>
<h1>Welcome to Claudio Maggioni&#39;s website!</h1>
<p>Right now this page is almost empty because I have nothing to put in.
But remember:</p>
<blockquote>
<p>Eat <a target="_blank" href="https://en.wikipedia.org/wiki/Polenta">
<em>polenta</em></a> and do not counter-aim!</p>
</blockquote>
<p>The original, in italian:</p>
<blockquote>
<p>Mangiate la
<a target="_blank" href="https://it.wikipedia.org/wiki/Polenta">
<em>polenta</em>
</a>
e non contromirate!</p>
</blockquote>
</section>
<section>
<h2>Self-hosted stuff</h2>
<p>
Here are the <em>awesome</em> services provided by <code>maggioni.xyz</code>:
</p>
<ul>
<li><a href="https://git.maggioni.xyz">Gogs</a>, a private Git HTTP frontend;</li>
<li><a href="https://ci.maggioni.xyz">Drone CI</a>, a private CI/CD server;</li>
<li><a href="https://cloud.maggioni.xyz"><code>maggioni.xyz</code> cloud</a>,
a private <em>Nextcloud</em> instance;</li>
<li><a href="https://download.maggioni.xyz">Download area</a>, a generic download
area for the stuff that i want to put in.</li>
</ul>
</section>
</div>