<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Electricmonk.nl weblog &#187; security</title>
	<atom:link href="http://www.electricmonk.nl/log/category/security/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.electricmonk.nl/log</link>
	<description>Ferry Boender&#039;s ramblings</description>
	<lastBuildDate>Mon, 15 Apr 2013 18:48:50 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Re-use existing SSH agent (cygwin et al)</title>
		<link>http://www.electricmonk.nl/log/2012/04/24/re-use-existing-ssh-agent-cygwin-et-al/</link>
		<comments>http://www.electricmonk.nl/log/2012/04/24/re-use-existing-ssh-agent-cygwin-et-al/#comments</comments>
		<pubDate>Tue, 24 Apr 2012 19:07:59 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://www.electricmonk.nl/log/?p=4901</guid>
		<description><![CDATA[(Please note that this post is not specific to Windows nor Cygwin; it&#39;ll work on a remote unix machine just as well) On my netbook, I use Windows XP in combination with Cygwin (A unix environment for Windows) and Mintty for my Unixy needs. From there, I usually SSH to some unix-like machine somewhere, so [...]]]></description>
				<content:encoded><![CDATA[<p>
	(Please note that this post is not specific to Windows nor Cygwin; it&#39;ll work on a remote unix machine just as well)
</p>
<p>
	On my netbook, I use Windows XP in combination with Cygwin (A unix environment for Windows) and Mintty for my Unixy needs. From there, I usually SSH to some unix-like machine somewhere, so I can do systems administration or development.
</p>
<p>
	Unfortunately, the default use of an SSH agent under Cygwin is difficult, since there&#39;s no parent process that can run it and put the required information (<tt>SSH_AUTH_SOCK</tt>) in the environment. On most Linux distribution, the SSH agent is started after you log in to an X11 session, so that every child process (terminals you open, etc) inherits the <tt>SSH_AUTH_SOCK</tt> environment setting and SSH can contact the ssh-agent to get your keys. Result? You have to start a new SSH agent, load your key and enter your password for each Mintty terminal you open. Quite annoying.
</p>
<p>
	The upside is, it&#39;s not very hard to configure your system properly so that you need only one SSH agent running on your system, and thus only have to enter your password once.
</p>
<p>
	The key lies in how <tt>ssh-agent</tt> creates the environment. When we start <tt>ssh-agent</tt> in the traditional manner, we do:
</p>
<pre>
$ <b>eval `ssh-agent`</b>
Agent pid 1784
</pre>
<p>
	The command starts the SSH agent and sets a bunch of environment variables:
</p>
<pre>
$ <b>set | grep SSH_</b>
SSH_AGENT_PID=1784
SSH_AUTH_SOCK=/tmp/ssh-QzfPveH696/agent.696
</pre>
<p>
	The <tt>SSH_AUTH_SOCK</tt> is how the <tt>ssh</tt> command knows how to contact the agent. As you can see, the socket filename is generated randomly. That means you can&#39;t reuse the socket, since you can&#39;t guess the socket filename.
</p>
<p>
	Good thing ssh-agent allows us to specify the socket filename, so we can easily re-use it.
</p>
<p>
	Put the following in your <tt>~/.bashrc</tt>:
</p>
<pre>
# If no SSH agent is already running, start one now. Re-use sockets so we never
# have to start more than one session.

export SSH_AUTH_SOCK=/home/fboender/.ssh-socket

ssh-add -l &gt;/dev/null 2&gt;&amp;1
if [ $? = 2 ]; then
   # No ssh-agent running
   rm -rf $SSH_AUTH_SOCK
   <span style="font-family: 'courier new', monospace;"># &gt;| allows output redirection to over-write files if no clobber is set
</span><span style="font-family: 'courier new', monospace;">&nbsp; &nbsp;ssh-agent -a $SSH_AUTH_SOCK &gt;| /tmp/.ssh-script
</span>   source /tmp/.ssh-script
<font face="courier new, monospace">&nbsp; &nbsp;echo $SSH_AGENT_PID &gt;| ~/.ssh-agent-pid</font>
   rm /tmp/.ssh-script
fi</pre>
<p>
	What the script above does is, it sets the socket filename manually to <tt>/home/yourusername/.ssh-socket</tt>. It then runs <tt>ssh-add</tt>, which will attempt to connect to the ssh-agent through the socket. If it fails, it means no ssh-agent is running, so we do some cleanup and start one.
</p>
<p>
	Now, all you have to do is start a single terminal, and load your keys once:
</p>
<pre>
$ <b>ssh-add ~/.ssh/fboender\@electricmonk.rsa</b>
Enter passphrase for .ssh/fboender@electricmonk.rsa: <b>[PASSWORD]</b>
Identity added: .ssh/fboender@electricmonk.rsa (.ssh/fboender@electricmonk.rsa)
</pre>
<p>
	Now you can start as many new terminals as you&#39;d like, and they&#39;ll all use the same ssh-agent, never requiring you to enter your password for that key more than once per boot.
</p>
<p>
	<strong>Update:</strong>
</p>
<p>
	I&#39;ve updated the script with suggestions from&nbsp;Anthony Geoghegan. It now also works if noclobber is set.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.electricmonk.nl/log/2012/04/24/re-use-existing-ssh-agent-cygwin-et-al/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Stop Pingback/Trackback Spam on WordPress</title>
		<link>http://www.electricmonk.nl/log/2011/09/07/stop-pingbacktrackback-spam-on-wordpress/</link>
		<comments>http://www.electricmonk.nl/log/2011/09/07/stop-pingbacktrackback-spam-on-wordpress/#comments</comments>
		<pubDate>Wed, 07 Sep 2011 11:51:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[security]]></category>
		<category><![CDATA[sysadmin]]></category>
		<category><![CDATA[tech]]></category>

		<guid isPermaLink="false">http://www.electricmonk.nl/log/?p=4707</guid>
		<description><![CDATA[I guess the spammers finally found my blog, cause I&#039;ve been getting a lot of pignback/trackback spam. I tried some anti-spam plugins, but none really worked, so I disabled pingbacks altogether. Here&#039;s how: First, log into wordpress as an admin. Go to Settings &#8594; Discussion, and uncheck the Allow link notifications from other blogs (pingbacks [...]]]></description>
				<content:encoded><![CDATA[<p>I guess the spammers finally found my blog, cause I&#039;ve been getting a lot of pignback/trackback spam. I tried some anti-spam plugins, but none really worked, so I disabled pingbacks altogether. Here&#039;s how:</p>
<p>First, log into wordpress as an admin. Go to <tt>Settings &rarr; Discussion</tt>, and uncheck the <tt>Allow link notifications from other blogs (pingbacks and trackbacks.)</tt> box.</p>
<p>That&#039;s not all though, cause that just works for new articles. Old ones will still allow ping/trackbacks. As far as I could tell, WordPress doesn&#039;t have a feature to disable those for older posts, so we&#039;ll have to fiddle around in the database directly.</p>
<p>Connect to your MySQL server using the WordPress username and password. If you no longer remember those, you can find them in the <tt>wp-config.php</tt> file.</p>
<pre>$ <b>mysql -u USERNAME -p -h localhost</b>
Password: <b>PASSWORD</b>
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1684228
Server version: 5.0.51a-24+lenny5 (Debian)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql&gt;</pre>
<p>At the MySQL prompt, we must now switch to our WordPress database. Again, if you don&#039;t remember the name, you can find it in the <tt>wp-config.php</tt> file. In my case, it is <tt>em_wordpress</tt></p>
<pre>mysql&gt; <b>USE em_wordpress;</b>
Database changed</pre>
<p>Finally, we update all posts and disable ping backs on them:</p>
<pre>mysql&gt; <b>UPDATE wp_posts SET ping_status = 'closed';</b>
Query OK, 1084 rows affected (0.10 sec)
Rows matched: 1084  Changed: 1084  Warnings: 0
</pre>
<p>There we go. No more ping- and trackback spam on old posts.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.electricmonk.nl/log/2011/09/07/stop-pingbacktrackback-spam-on-wordpress/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SSH Tips and Tricks</title>
		<link>http://www.electricmonk.nl/log/2011/05/02/ssh-tips-and-tricks/</link>
		<comments>http://www.electricmonk.nl/log/2011/05/02/ssh-tips-and-tricks/#comments</comments>
		<pubDate>Mon, 02 May 2011 14:18:43 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[linux]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://www.electricmonk.nl/log/?p=4606</guid>
		<description><![CDATA[(The lastest version of this article is always available in stand-alone HTML format and in PDF format. The original AsciiDoc source is also available. Please link to the HTML version, not this Blog post!) SSH is capable of more than you&#039;d think! This article describes some of the lesser known features and configuration options. It [...]]]></description>
				<content:encoded><![CDATA[<p>(The lastest version of this article is always available in stand-alone <a href="http://www.electricmonk.nl/Writings/HomePage?action=download&#038;upname=ssh_tips_tricks.html">HTML format</a> and in <a href="http://www.electricmonk.nl/Writings/HomePage?action=download&#038;upname=ssh_tips_tricks.pdf">PDF format</a>. The original <a href="http://www.electricmonk.nl/Writings/HomePage?action=download&#038;upname=ssh_tips_tricks.txt">AsciiDoc source</a> is also available. Please link to the HTML version, not this Blog post!)</p>
<p>SSH is capable of more than you&#039;d think! This article describes some of the lesser known features and configuration options. It covers authentication, authorization, tunnels and proxies, file transfer and more. </p>
<p><span id="more-4606"></span></p>
<div id="content">
<h2 id="_authentication">Authentication</h2>
<div class="sectionbody">
<h3 id="_passwordless_key">Passwordless key</h3>
<div style="clear:left"></div>
<div class="paragraph">
<p>One very useful feature of SSH are passwordless keys. They are especially useful when you&#039;re writing scripts that need to run commands on a remote hosts. Since those will run unattended, you don&#039;t want them to prompt for a password.</p>
</div>
<div class="admonitionblock">
<table>
<tr>
<td class="icon">
<div class="title">Warning</div>
</td>
<td class="content">Be careful when using passwordless keys! If the security of the client machine is compromised, the remote server will be <strong>just as compromised</strong>! Check the Authorization section of this article for tips on how to limit the damage of a compromised client machine! You can also use an ssh agent, in which case you will only have to enter the password once after system boot after which scripts can run without requiring a password.</td>
</tr>
</table>
</div>
<div class="paragraph">
<p>You can generate passwordless keys using the <tt>ssh-keygen</tt> tool. Simply press <tt>enter</tt> when asked for the password:</p>
</div>
<div class="literalblock">
<div class="content">
<pre><tt>$ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_rsa): /home/user/passwordless_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/user/passwordless_rsa.
Your public key has been saved in /home/user/passwordless_rsa.pub.
The key fingerprint is:
70:50:84:e3:ea:de:62:43:4e:cf:76:a4:86:8e:c7:29 user@eek</tt></pre>
</div>
</div>
<div class="paragraph">
<p>This generates a normal public key and a private key without a password. We can add the public key to a remote machine&#039;s list of authorized keys using the <tt>ssh-copy-id</tt> tool:</p>
</div>
<div class="literalblock">
<div class="content">
<pre><tt>$ ssh-copy-id -i /home/user/passwordless_rsa.pub user@remote_host
Now try logging into the machine, with "ssh 'user@remote_host'", and check in:
  .ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.</tt></pre>
</div>
</div>
<div class="paragraph">
<p>We specify which public key to transport using the <tt>-i /home/user/passwordless_rsa.pub</tt> option.</p>
</div>
<div class="paragraph">
<p>Now we can ssh to the <tt>remote_host</tt> without using a password. If the private key has been placed in the current user&#039;s <tt>.ssh</tt> directory, ssh will automatically detect it when trying to connect. If you want to be sure it finds the private key to connect with, you can once again specify the <tt>-i path_to_private_key</tt> option:</p>
</div>
<div class="literalblock">
<div class="content">
<pre><tt>$ ssh -i /home/user/passwordless_rsa user@remote_host
user@remote_host$</tt></pre>
</div>
</div>
<div class="paragraph">
<p>When using passwordless keys, you may provide the <tt>-q</tt> and <tt>-o "BatchMode=yes"</tt> options to SSH in order to make it quiet. Otherwise, errors related to SSH might be interpreted as errors from remote commands.</p>
</div>
<h3 id="_ssh_agent">SSH Agent</h3>
<div style="clear:left"></div>
<div class="paragraph">
<p>The SSH Agent is a tool which can keep your private keys in memory. When connecting to a remote machine, any SSH session (including <tt>scp</tt> and <tt>sftp</tt>) will try to contact a running agent on the machine to see if the required private key is already loaded. If it is, it will be used to connect to the remote machine. This way you only have to enter your password for a private key once, instead of each time you want to connect.</p>
</div>
<div class="paragraph">
<p>You can test if an SSH Agent is already running with the following command:</p>
</div>
<div class="literalblock">
<div class="content">
<pre><tt>$ ssh-add -l
Could not open a connection to your authentication agent.</tt></pre>
</div>
</div>
<div class="paragraph">
<p>As you can see, no agent is currently running. We can start one with the following command:</p>
</div>
<div class="literalblock">
<div class="content">
<pre><tt>$ eval `ssh-agent`
Agent pid 6265</tt></pre>
</div>
</div>
<div class="paragraph">
<p>The above command runs the <tt>ssh-agent</tt> program, which will output some other commands, which are then run by the current shell. This is the actual output of the <tt>ssh-agent</tt> program:</p>
</div>
<div class="literalblock">
<div class="content">
<pre><tt>SSH_AUTH_SOCK=/tmp/ssh-tXJFfB6269/agent.6269; export SSH_AUTH_SOCK;
SSH_AGENT_PID=6270; export SSH_AGENT_PID;
echo Agent pid 6270;</tt></pre>
</div>
</div>
<div class="paragraph">
<p>As you can see, the <tt>ssh-agent</tt> is started. It then creates a socket in the <tt>/tmp</tt> directory and sets that location as an environment variable so that SSH clients (<tt>ssh</tt>, <tt>scp</tt>, <tt>sftp</tt>) know where to contact the agent.</p>
</div>
<div class="paragraph">
<p>We can add keys to the agent using the <tt>ssh-add</tt> tool:</p>
</div>
<div class="literalblock">
<div class="content">
<pre><tt>$ ssh-add user.rsa
Enter passphrase for user.rsa:
Identity added: user.rsa (user.rsa)</tt></pre>
</div>
</div>
<div class="paragraph">
<p>We can now connect to any remote machine that has the public key counterpart in its <tt>authorized_keys</tt> file without having to enter our password again.</p>
</div>
<div class="paragraph">
<p>The <tt>ssh_agent</tt> program generates a random name for the socket. One frequent problem with starting the SSH agent like we did just now is that only the current shell knows about the socket location. If we open another terminal, it won&#039;t know about the running SSH agent, since the environment variable isn&#039;t set in the new terminal. We can work around this by specifying our own path to a socket with the <tt>-a</tt> option.</p>
</div>
<div class="paragraph">
<p>Combining this knowledge, we can add a few lines to our <tt>.profile</tt> (or <tt>.bashrc</tt>) startup script to start an agent if none is running yet. We also check for a forwarded agent and don&#039;t do anything if a forwarded agent is found (more on forwarding agents later on).</p>
</div>
<div class="listingblock">
<div class="content">
<pre><tt># Do not start an SSH agent if the user has a forwarded agent.
if [ -z "$SSH_AUTH_SOCK" ]; then
    # Check if a local SSH agent is already running. If not, start one.
    export SSH_AUTH_SOCK="$HOME/.ssh/sshagent.socket"
    if [ ! -S "$SSH_AUTH_SOCK" ]; then
        eval `ssh-agent -a "$SSH_AUTH_SOCK"`
    fi
fi</tt></pre>
</div>
</div>
<div class="paragraph">
<p>With this script in your <tt>.profile</tt>, you will only have to start one agent ever for a given user as long as that machine doesn&#039;t reboot (or the agent is killed in some other way). If you log out, the agent is not killed, and will be re-used the next time you log in.</p>
</div>
<h3 id="_agent_forwarding">Agent forwarding</h3>
<div style="clear:left"></div>
<div class="paragraph">
<p>Perhaps the most useful feature of SSH is Agent Forwarding. We can tell <tt>ssh</tt> it should do Agent Forwarding by supplying the <tt>-A</tt> commandline option when we ssh to remote machine. For this to work, you have to have an SSH agent running locally, or agent forwarding had to be enabled when you SSHed into your current session. (Use <tt>ssh-add -l</tt> to see if an agent is avaiable).</p>
</div>
<div class="literalblock">
<div class="content">
<pre><tt>$ ssh -A user@remote_host</tt></pre>
</div>
</div>
<div class="paragraph">
<p>When enabling Agent Forwarding with the <tt>-A</tt> switch, ssh will automatically create a socket at the remote host and set some environment variables (<tt>SSH_AUTH_SOCK</tt>, most notably) when you connect to a remote machine. If an ssh session needs to perform authentication, it will first try to reach the SSH agent through the socket. All requests will be sent back to the original SSH agent. This works for as many nested sessions as you&#039;d like.</p>
</div>
<div class="paragraph">
<p>Using Agent forwarding, you can start a single agent on, say, your desktop machine. Every authentication request made by any SSH session will be sent back to the agent running on your desktop machine, without the need to start additional SSH agents on remote machines and loading keys there. As you can imagine, this is a much better method of keeping private keys secure than storing them on every machine you need to SSH from.</p>
</div>
<div class="paragraph">
<p>You can enable SSH agent forwarding for all the hosts you SSH to automatically (without the need to specify the <tt>-A</tt> switch) by putting the following in your <tt>~/.ssh/config</tt>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre><tt>Host *
        ForwardAgent yes</tt></pre>
</div>
</div>
</div>
<h2 id="_authorization">Authorization</h2>
<div class="sectionbody">
<h3 id="_restricting_commands">Restricting commands</h3>
<div style="clear:left"></div>
<div class="paragraph">
<p>You can restrict which command can be run by someone logging in with a public/private key in the <tt>authorized_keys</tt> file. For instance, to restrict a certain public/private key to running the <tt>df -h</tt> command (to view avaiable diskspace), you add a line to the <tt>authorized_keys</tt> file like this (Public key shortened for brevity):</p>
</div>
<div class="literalblock">
<div class="content">
<pre><tt>command="/bin/df -h" ssh-dss AAAAC8ghi9ldw== user@host</tt></pre>
</div>
</div>
<div class="paragraph">
<p>Now when we SSH to that machine (and we have that key loaded):</p>
</div>
<div class="literalblock">
<div class="content">
<pre><tt>$ ssh user@remote_host
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/dev-root   39G  2.2G   35G   6% /
Connection to host closed.</tt></pre>
</div>
</div>
<div class="paragraph">
<p>Its not possible for a single key to run multiple commands via any normal SSH configuration mechanism. However, SSH will set an environment variable <tt>$SSH_ORIGINAL_COMMAND</tt> with the command the user tried to run. We can take advantage of that by writing a shellscript. For example, we can create a script called <tt>commands.sh</tt> on the remote host:</p>
</div>
<div class="listingblock">
<div class="content">
<pre><tt>#!/bin/sh

case $SSH_ORIGINAL_COMMAND in
        "diskspace")
                df -h
                ;;
        "dirlist")
                ls -1
                ;;
        "apache_restart")
                /etc/init.d/apache restart
                ;;
        *)
                echo "Unknown command"
esac</tt></pre>
</div>
</div>
<div class="paragraph">
<p>Then we restrict the user to running that shellscript:</p>
</div>
<div class="literalblock">
<div class="content">
<pre><tt>command="/bin/sh /home/user/commands.sh" ssh-dss AAAAC8ghi9ldw== user@host</tt></pre>
</div>
</div>
<div class="paragraph">
<p>The user can now run multiple commands by specifying as an argument after the ssh command (The -q+ option makes ssh quiet, so it doesn&#039;t show any output other than that of the remote command):</p>
</div>
<div class="literalblock">
<div class="content">
<pre><tt>$ ssh -q user@remote_host diskspace
Filesystem            Size  Used Avail Use% Mounted on
/dev/mapper/dev-root   39G  2.2G   35G   6% /</tt></pre>
</div>
</div>
<div class="literalblock">
<div class="content">
<pre><tt>$ ssh -q remote_host dirlist
commands.sh
dump.sql</tt></pre>
</div>
</div>
<div class="admonitionblock">
<table>
<tr>
<td class="icon">
<div class="title">Warning</div>
</td>
<td class="content">Make sure you do not include any commands which lets the user run an interactive shell. Also, make sure users cannot overwrite the <tt>commands.sh</tt> and <tt>.ssh/authorized_keys</tt> files.</td>
</tr>
</table>
</div>
<h3 id="_restricting_addition_of_keys">Restricting addition of keys</h3>
<div style="clear:left"></div>
<div class="paragraph">
<p>By default, SSH puts the <tt>authorized_keys</tt> files in the user&#039;s home directory. This allows users to add other keys themselves; a situation you might want to avoid. You can change the location where the key files are kept in the <tt>/etc/ssh/sshd_config</tt> file, using the <tt>AuthorizedKeysFile</tt> option:</p>
</div>
<div class="listingblock">
<div class="content">
<pre><tt>#AuthorizedKeysFile     %h/.ssh/authorized_keys
AuthorizedKeysFile      /etc/ssh/authorized_keys/%u</tt></pre>
</div>
</div>
<div class="paragraph">
<p>The <tt>%u</tt> will expand to the username. The location of the <tt>authorized_keys</tt> file for a user named &#034;john&#034; will become <tt>/etc/ssh/authorized_keys/john</tt>. <tt>%h</tt> expands to the users homedirectory.</p>
</div>
<div class="paragraph">
<p>Make sure users can&#039;t write to the files in question.</p>
</div>
<h3 id="_restricting_which_users_can_ssh">Restricting which users can SSH</h3>
<div style="clear:left"></div>
<div class="paragraph">
<p>You can restrict which users are allowed to use SSH with the <tt>AllowUsers</tt> option in <tt>/etc/ssh/sshd_config</tt>:</p>
</div>
<div class="listingblock">
<div class="content">
<pre><tt>AllowUsers john pete</tt></pre>
</div>
</div>
<div class="admonitionblock">
<table>
<tr>
<td class="icon">
<div class="title">Note</div>
</td>
<td class="content">if the AllowUsers setting is completely missing from the sshd config file, all users are allowed (see man sshd_config). You may prefer to leave it that way&#8201;&#8212;&#8201;your choice. I prefer to make the usernames explicit because I&#039;m paranoid ;-)</td>
</tr>
</table>
</div>
</div>
<h2 id="_input_output">Input / Output</h2>
<div class="sectionbody">
<div class="paragraph">
<p>Like every other Unix tool, SSH can use input and output redirection. When running a command on a remote machine using SSH, it will redirect any input given to it locally to the remote command. Any output from the remote command is redirected back to your local machine. This allows for some very useful time-savers.</p>
</div>
<div class="paragraph">
<p>For instance, we can run the command <tt>du</tt> (diskusage) on the remote machine, and locally pipe it into <tt>xdu</tt> to get a graphical representation on our local X11 desktop of the remote disk usage:</p>
</div>
<div class="literalblock">
<div class="content">
<pre><tt>$ ssh remote_host du /var/www/ | xdu</tt></pre>
</div>
</div>
<div class="paragraph">
<p>Or suppose we want to transfer a remote directory&#039;s contents to the local machine without using scp (for whatever reason). We can remotely create a tar archive of the directory, and instruct <tt>tar</tt> to write it to the standard output (using the minus as the filename) instead of a file. SSH will transfer the remote standard output of tar to our local machine, where we can untar it in the same manner:</p>
</div>
<div class="literalblock">
<div class="content">
<pre><tt>$ ssh remote_host tar -cf - Documents/notes | tar -xf -
$ ls Documents/notes/
dev.c.txt                            sysadmin.networking.txt
dev.git.txt                          sysadmin.openssl.txt
dev.mysql.txt                        sysadmin.solaris.txt</tt></pre>
</div>
</div>
<div class="paragraph">
<p>Perhaps we need to create a local copy of a MySQL database on a remote machine. Unfortunatelly, MySQL access is not remotely allowed and the harddisk on the remote machine is full, so we can&#039;t create a dump there, transport it to our local machine and read it in. No worry, SSH to the rescue:</p>
</div>
<div class="literalblock">
<div class="content">
<pre><tt>$ ssh remote_host mysqldump -u USER -pPASSWORD -h localhost DATABASENAME &gt; dump.sql</tt></pre>
</div>
</div>
<div class="paragraph">
<p>Or we can just import it directly:</p>
</div>
<div class="literalblock">
<div class="content">
<pre><tt>$ ssh remote_host mysqldump -u USER -pPASSWORD -h localhost DATABASENAME | mysql -u USER -pPASSWORD -h localhost DATABASENAME</tt></pre>
</div>
</div>
<div class="paragraph">
<p>Likewise we can locally pipe data into ssh and use it at the remote host. Again, we use the minus-sign to indicate reading from standard in:</p>
</div>
<div class="literalblock">
<div class="content">
<pre><tt>$ echo "hello world" | ssh remote_host "cat &gt;foo.txt"</tt></pre>
</div>
</div>
<div class="paragraph">
<p>This will put &#034;hello world&#034; in a file called <tt>foo.txt</tt> on the remote host. We need to quote the parts that contain the redirection on the host (<tt>"cat &gt;foo.txt"</tt>) or it will be picked up by the local shell.</p>
</div>
</div>
<h2 id="_tunnels_and_proxies">Tunnels and proxies</h2>
<div class="sectionbody">
<h3 id="_local_port_tunnel">Local port tunnel</h3>
<div style="clear:left"></div>
<div class="paragraph">
<p>Sometimes you may need to use a certain service on a network, but the network has been firewalled against external connections on ports other than the SSH port. SSH allows us to create a <em>tunnel</em> into the remote network. Suppose we are on a network 192.168.1.x and we want to connect to port 80 on a machine with 192.168.56.3. But the 192.168.56.x network is firewalled, and we can only access it through a bastion host at 192.168.56.1. Here&#039;s what we do:</p>
</div>
<div class="literalblock">
<div class="content">
<pre><tt>$ ssh -L 80:192.168.56.3:80 user@192.168.56.1</tt></pre>
</div>
</div>
<div class="paragraph">
<p>SSH will now create a tunnel to 192.168.56.3 port 80 through 192.168.56.1. The <tt>-L</tt> option takes three arguments, separated with colons: <tt>local_port:remote_host:remote_port</tt>. The <tt>local_port</tt> is where SSH will listen for incoming connections on the machine where you issued this command. <tt>remote_host:remote_port</tt> is the machine/port to which you wish to create the tunnel. It is important to remember that this is as you&#039;d view it from the server you&#039;re ssh-ing too (192.168.56.1 in this case), not as you&#039;d view it from your local machine.</p>
</div>
<div class="paragraph">
<p>You can additionally specify the <tt>-N</tt> switch to prevent SSH from actually logging in to 192.168.56.1.</p>
</div>
<h3 id="_socks5_proxy">SOCKS5 proxy</h3>
<div style="clear:left"></div>
<div class="paragraph">
<p>We can use SSH as a SOCKS5 proxy. An SOCKS5 proxy works much like a normal tunnel, but works with multiple clients at the same time, and is not restricted to forwarding of a single port. We can start a SOCKS5 using the <tt>-D</tt> option:</p>
</div>
<div class="paragraph">
<p>Socks5 is pretty neat, as it allows you to proxy stuff without the server having to know anything about the way the client works. For instance, if we give the following command:</p>
</div>
<div class="literalblock">
<div class="content">
<pre><tt>$ ssh -D 8080 remote_host</tt></pre>
</div>
</div>
<div class="paragraph">
<p>Now we can configure local clients (such as Firefox, Pidgin Instant Messanger, Chrome, etc) to use the proxy. All network traffic (with the exception of DNS, possibly!) will go through the SOCKS5 proxy. For instance:</p>
</div>
<div class="literalblock">
<div class="content">
<pre><tt>$ chromium-browser --proxy-server="socks5://127.0.0.1:8080"</tt></pre>
</div>
</div>
<h3 id="_proxycommand">ProxyCommand</h3>
<div style="clear:left"></div>
<div class="paragraph">
<p>Many networks require you to SSH to a bastion (firewall/gateway) server before you&#039;re able to SSH to any machine on the network. This becomes tedious quickly, as you have to SSH twice each time. The <tt>ProxyCommand</tt> is a setting in your ssh configuration file which can do this for you automatically.</p>
</div>
<div class="paragraph">
<p>Assume we want to SSH to a host &#039;web1.example.com&#039;. Before we can SSH to this host we first have to SSH to &#039;example.com&#039;. We can SSH directly to &#039;web1.example.com&#039; by putting the following in our <tt>~.ssh/config</tt> file:</p>
</div>
<div class="listingblock">
<div class="content">
<pre><tt>Host web1
        ProxyCommand ssh example.com nc web1.example.com 22</tt></pre>
</div>
</div>
<div class="paragraph">
<p>This requires that the <tt>nc</tt> (<tt>netcat</tt>) tool is installed on web1.example.com. If we SSH to <tt>web1</tt> now, we are automatically sent to web1.example.com. It&#039;s even possible to use <tt>scp</tt> and other SSH tricks directly, thus saving us the trouble of having to transfer files to example.com first, then to our local machine (or vice versa).</p>
</div>
<div class="paragraph">
<p>ProxyCommand can also be used with other things. To SSH through a HTTP proxy at 192.0.2.0 port 8080:</p>
</div>
<div class="listingblock">
<div class="content">
<pre><tt>ProxyCommand /usr/bin/nc -X connect -x 192.0.2.0:8080 %h %p</tt></pre>
</div>
</div>
</div>
<h2 id="_configuration">Configuration</h2>
<div class="sectionbody">
<h3 id="_client_configuration">Client configuration</h3>
<div style="clear:left"></div>
<div class="paragraph">
<p>The SSH client configuration lives in the file <tt>/home/USER/.ssh/config</tt>. It has many useful directives. The basic way it works is we specify a host identifier, and add configuration settings to that host.</p>
</div>
<div class="paragraph">
<p>For instance, if your local username is <tt>john</tt>, but on the backup machine <tt>backup.example.com</tt> it&#039;s always <tt>backup</tt>, you can tell SSH to automatically use that username to log in:</p>
</div>
<div class="listingblock">
<div class="content">
<pre><tt>Host backup.example.com
        User backup</tt></pre>
</div>
</div>
<div class="paragraph">
<p>You can create aliases (much like the <tt>/etc/hosts</tt> file) to save some typing:</p>
</div>
<div class="listingblock">
<div class="content">
<pre><tt>Host backup
        Hostname backup.example.com
        User backup</tt></pre>
</div>
</div>
<div class="paragraph">
<p>If you want to apply a certain configuration option to <strong>every</strong> host, use the asterisk wildcard:</p>
</div>
<div class="listingblock">
<div class="content">
<pre><tt>Host *
        ForwardAgent yes
        ServerAliveInterval 5
        ServerAliveCountMax 720</tt></pre>
</div>
</div>
<div class="paragraph">
<p>Check <tt>man ssh_config</tt> for more useful options in this configuration file.</p>
</div>
</div>
<h2 id="_transferring_files">Transferring files</h2>
<div class="sectionbody">
<h3 id="_secure_copy_scp">Secure Copy (scp)</h3>
<div style="clear:left"></div>
<div class="paragraph">
<p>This should be obvious, but you can use the <tt>scp</tt> tool to transfer files between hosts using SSH. To copy a file <tt>localhost.txt</tt> to your home directory on the remote host:</p>
</div>
<div class="literalblock">
<div class="content">
<pre><tt>scp localfile.txt user@remote_host:</tt></pre>
</div>
</div>
<div class="paragraph">
<p>To put the file in a different path:</p>
</div>
<div class="literalblock">
<div class="content">
<pre><tt>scp localfile.txt user@remote_host:/path/absolute/to/root/</tt></pre>
</div>
</div>
<div class="paragraph">
<p>and</p>
</div>
<div class="literalblock">
<div class="content">
<pre><tt>scp localfile.txt user@remote_host:path/in/homedir/</tt></pre>
</div>
</div>
<div class="paragraph">
<p>Transferring an entire directory is possible using the <tt>-r</tt> switch:</p>
</div>
<div class="literalblock">
<div class="content">
<pre><tt>scp -r dir/ user@remote_host:</tt></pre>
</div>
</div>
<h3 id="_sftp">SFTP</h3>
<div style="clear:left"></div>
<div class="paragraph">
<p>OpenSSH (and most other SSH implementations) offer a secure FTP server. With it you can securely (encrypted) transfer files and authenticate using the default SSH authentication methods such as passwords or public keys. Contrary to ordinary FTP server (unless they run on TLS or some other form of encryption), passwords are not sent in plain-text over the network. SFTP also makes it easier for Windows user to transfer files between hosts, as there are many good free SFTP clients available. I personally recommend Filezilla.</p>
</div>
<div class="paragraph">
<p>The SFTP server needs to be enabled in the SSH server configuration. Edit <tt>/etc/ssh/sshd.config</tt> on the server and add the following line:</p>
</div>
<div class="literalblock">
<div class="content">
<pre><tt>Subsystem sftp /usr/lib/openssh/sftp-server</tt></pre>
</div>
</div>
<div class="paragraph">
<p>Restart SSH and you should be able to user the SFTP server:</p>
</div>
<div class="literalblock">
<div class="content">
<pre><tt>/etc/init.d/ssh restart</tt></pre>
</div>
</div>
<div class="paragraph">
<p>On the client, issue the <tt>sftp</tt> command:</p>
</div>
<div class="literalblock">
<div class="content">
<pre><tt>$ sftp user@remote_host
Connected to host.
sftp&gt; ls
bin          svn.tar.gz   xims
sftp&gt; get svn.tar.gz
Fetching /home/user/svn.tar.gz to svn.tar.gz
/home/user/svn.tar.gz           100%   11KB  11.0KB/s   00:00</tt></pre>
</div>
</div>
<div class="paragraph">
<p>You may get an error like this:</p>
</div>
<div class="literalblock">
<div class="content">
<pre><tt>subsystem request failed on channel 0
Couldn't read packet: Connection reset by peer</tt></pre>
</div>
</div>
<div class="paragraph">
<p>This means that either the sftp-server was not properly configurated, or your login shell on the remote server is outputting some text not expected by the SFTP server (perhaps a welcome message or something). Remove the output and try again.</p>
</div>
<div class="paragraph">
<p>A different way of enabling the SFTP server is in the <tt>authorized_keys</tt> file:</p>
</div>
<div class="literalblock">
<div class="content">
<pre><tt>command="/usr/lib/openssh/sftp-server" ssh-dss AAAAC8ghi9ldw== user@host</tt></pre>
</div>
</div>
<div class="paragraph">
<p>This will restrict any user that logs in using the public key <tt>AAAAC8ghi9ldw==</tt> to SFTP. The user cannot login using a normal SSH session. This does not require you to enable the SFTP server in <tt>/etc/ssh/sshd.conf</tt>.</p>
</div>
<div class="paragraph">
<p>You&#039;ll have to make sure that the user can&#039;t write to the .ssh directory nor upload any files such as .bashrc, .profile, etc, otherwise the user can overwrite those by uploading their own version, and they can still execute anything they like by just logging in with sftp. You can do this by creating these files and then changing their ownership and rights in such a way that the user can&#039;t write to them. Because it&#039;s hard to guess what files you should create so that the user can&#039;t cause any harm, it&#039;s best to simply create a seperate directory in which they can upload stuff, and lock off write access to their entire home directory.</p>
</div>
<div class="paragraph">
<p>Unlike the <tt>ssh</tt> and <tt>scp</tt> commands, <tt>sftp</tt> does not have a <tt>-i</tt> switch with which you can manually give the location of the private key to log in with. Fortunately, we can still provide one through the <tt>-o</tt> (options) switch:</p>
</div>
<div class="literalblock">
<div class="content">
<pre><tt>sftp -o IdentityFile=/home/user/.ssh/some_key_rsa username@hostname</tt></pre>
</div>
</div>
<div class="paragraph">
<p>This can be convenient in the case of automated tasks. The custom key does not have to have a password and can be placed anywhere. Speaking of automated tasks, here&#039;s an example of running <tt>sftp</tt> in a batch-mode:</p>
</div>
<div class="literalblock">
<div class="content">
<pre><tt>echo "PUT myfile" | sftp -o IdentityFile=/home/user/.ssh/some_key_rsa -b - username@hostname</tt></pre>
</div>
</div>
<div class="paragraph">
<p>Most normal FTP servers support jailing the user in a certain directory, preventing them from wandering around the file system. SFTP does not have this built-in ability, but we can use normal linux chroot/jails to jail a user to certain directory. For more information, see <a href="http://www.electricmonk.nl/log/2007/08/09/jailing-sftpscp/">http://www.electricmonk.nl/log/2007/08/09/jailing-sftpscp/</a></p>
</div>
<h3 id="_remote_mount_filesystem_sshfs">Remote mount filesystem (SSHfs)</h3>
<div style="clear:left"></div>
<div class="paragraph">
<p>Perhaps the most useful tool in existance: <tt>sshfs</tt>. SSHfs provides tools to locally mount a directory on a remote server over SSH, much like NFS. SSHfs requires remote support for SFTP. See the previous section on how to enable it. SSHfs is separate from the normal ssh tools, and is implemented as a FUSE (userland) filesystem. On Debian and Ubuntu machines you can easily install it using aptitude:</p>
</div>
<div class="literalblock">
<div class="content">
<pre><tt># aptitude install sshfs</tt></pre>
</div>
</div>
<div class="paragraph">
<p>Once installed, we can mount a remote directory using the <tt>sshfs</tt> tool:</p>
</div>
<div class="literalblock">
<div class="content">
<pre><tt>$ sshfs user@remote_host:path/to/dir ./local_mountpoint
$ cd local_mountpoint
$ ls
file1    file2    file3</tt></pre>
</div>
</div>
<div class="paragraph">
<p>Unmounting can be done with the <tt>fusermount</tt> tool:</p>
</div>
<div class="literalblock">
<div class="content">
<pre><tt>$ fusermount -u ./local_mountpoint</tt></pre>
</div>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.electricmonk.nl/log/2011/05/02/ssh-tips-and-tricks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Regular expression Denial of Service (ReDoS)</title>
		<link>http://www.electricmonk.nl/log/2011/04/22/regular-expression-denial-of-service-redos/</link>
		<comments>http://www.electricmonk.nl/log/2011/04/22/regular-expression-denial-of-service-redos/#comments</comments>
		<pubDate>Fri, 22 Apr 2011 08:05:14 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[link]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.electricmonk.nl/log/?p=4590</guid>
		<description><![CDATA[It&#039;s only logical, but I hadn&#039;t really thought about it much. Turns out Regular Expression can be vulnerable to external Denial of Service attacks.]]></description>
				<content:encoded><![CDATA[<p>It&#039;s only logical, but I hadn&#039;t really thought about it much. Turns out <a href="http://en.wikipedia.org/wiki/ReDoS">Regular Expression can be vulnerable to external Denial of Service</a> attacks.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.electricmonk.nl/log/2011/04/22/regular-expression-denial-of-service-redos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Security Questions considered harmful</title>
		<link>http://www.electricmonk.nl/log/2010/05/24/security-questions-considered-harmful/</link>
		<comments>http://www.electricmonk.nl/log/2010/05/24/security-questions-considered-harmful/#comments</comments>
		<pubDate>Mon, 24 May 2010 11:39:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[opinion]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false">http://www.electricmonk.nl/log/?p=4473</guid>
		<description><![CDATA[Many online services allow, or even worse, require, the so called &#034;Security Question&#034;. It is a question/answer you can enter in case you ever forget your password or can&#039;t access your account for some reason. In my opinion, security questions are an incredibly bad idea, from a security perspective. The usual security questions are things [...]]]></description>
				<content:encoded><![CDATA[<p>Many online services allow, or even worse, require, the so called &#034;Security Question&#034;. It is a question/answer you can enter in case you ever forget your password or can&#039;t access your account for some reason. In my opinion, security questions are an incredibly bad idea, from a security perspective. </p>
<p>The usual security questions are things like &#034;What was your mother&#039;s maiden name&#034;, &#034;What&#039;s your pet&#039;s name&#034;, etcetera. People won&#039;t understand that actually supplying a truthful answer to these kind of questions exposes them to an incredible weakness in their account&#039;s security. These are all questions to which the answer can be found relatively easy by googling a person or applying a little social engineering. &#034;Hey, I am John, and I think I might be related to you on your mother&#039;s side. What&#039;s her maiden name&#034;?</p>
<p>The worst part is that every site has basically the same questions from which you can choose. This means that people either have to pick the same question and answer every time, or pick a different one for each account. The first will make them vulnerable to repeated attacks on all their online profiles once an attacker has found the answer. The second will make it very hard for people to remember that they must never let anybody know about their favorite pet&#039;s name &#034;Buddy&#034;.  A lose/lose scenario at best.</p>
<p>As is often the case with security protocols, they must be followed to the letter to be safe. One flaw in the procedure, and the security collapses. Security questions could be a good idea, provided that:</p>
<ul>
<li>The user makes up his own question. No predefined questions should be supplied, and most importantly, different sites shouldn&#039;t all use the same questions.</li>
<li>The user should never be told what his security question was. If they need to reset their password, they should chose both the security <b>question</b> and the <b>answer</b>. This will make it much harder for a potential attacker to gain accees.</li>
</ul>
<p>Of course, taking the above in consideration, security questions are just as hard to remember as a password, which makes them kind of pointless. Pointless or insecure, make your pick. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.electricmonk.nl/log/2010/05/24/security-questions-considered-harmful/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>chkrootkit false positives filtering</title>
		<link>http://www.electricmonk.nl/log/2007/11/29/chkrootkit-false-positives-filtering/</link>
		<comments>http://www.electricmonk.nl/log/2007/11/29/chkrootkit-false-positives-filtering/#comments</comments>
		<pubDate>Thu, 29 Nov 2007 09:09:08 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[security]]></category>
		<category><![CDATA[shell scripting]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://www.electricmonk.nl/log/2007/11/29/chkrootkit-false-positives-filtering/</guid>
		<description><![CDATA[Chkrootkit is a tool that searches for rootkits, trojans and other signs of break-ins on your system. Like most security scanners, it sometimes generates false positives. Chkrootkit doesn&#039;t have a native way to filter those out. From the FAQ: [Q:] chkrootkit is reporting some files and dirs as suspicious: `.packlist&#039;, `.cvsignore&#039;, etc. These are clearly [...]]]></description>
				<content:encoded><![CDATA[<p><a href="http://www.chkrootkit.org/">Chkrootkit</a> is a tool that searches for rootkits, trojans and other signs of break-ins on your system. Like most security scanners, it sometimes generates false positives. Chkrootkit doesn&#039;t have a native way to filter those out. From the FAQ:</p>
<blockquote><p>
<b>[Q:] chkrootkit is reporting some files and dirs as suspicious: `.packlist&#039;, `.cvsignore&#039;, etc. These are clearly false positives. Can&#039;t you ignore these?</b></p>
<p>[A:] Ignoring some files and dirs could impair chkrootkit&#039;s accuracy. An attacker might use this, since he knows that chkrootkit will ignore certain files and dirs.
</p></blockquote>
<p>This is true, but getting an email every day is simply too annoying, and makes me skip chkrootkit generated emails on occasion because &#034;It&#039;s probably a false positive anyway&#034;. So here&#039;s a small guide for setting up a filtering of chkrootkit&#039;s output.</p>
<p>First, we create a file <tt>/etc/chkrootkit.ignore</tt> which will hold a bunch of regular expressions that will match everything we don&#039;t want to be warned about. For instance, I&#039;ve got a machine that needs to have a dhcp client installed. Chkrootkit keeps on generating emails with these lines:</p>
<pre>
eth0: PACKET SNIFFER(/sbin/dhclient[346])
eth1: PACKET SNIFFER(/usr/sbin/dhcpd3[1008])
</pre>
<p>So what we do is create the file <tt>/etc/chkrootkit.ignore</tt> and put the following in it:</p>
<p><tt>/etc/chkrootkit.ignore</tt></p>
<pre>
^eth0: PACKET SNIFFER\(/sbin/dhclient\[[0-9]*\])$
^eth1: PACKET SNIFFER\(/usr/sbin/dhcpd3\[[0-9]*\]\)$
</pre>
<p>In order to test if the rules we created are correct, we put the two lines with false positives in a separate file (<tt>/tmp/chkrk-fp.txt</tt>) and run the following:</p>
<p>test:</p>
<p>[root@sharky]/etc# cat /tmp/chkrk-fp.txt | grep -f /etc/chkrootkit.ignore<br />
eth0: PACKET SNIFFER(/sbin/dhclient[346])<br />
eth1: PACKET SNIFFER(/usr/sbin/dhcpd3[1008])</p>
<p>The lines that should be filtered out of the chkrootkit output should appear here. If nothing appears, or if not all of the lines that you want to filter appear, there&#039;s a problem. Refine your regular expressions in /etc/chkrootkit.filter until it works. </p>
<p>Now we need to modify the chkrootkit cronjob so that the false positives are filtered. To do this, we edit <tt>/etc/cron.daily/chkrootkit</tt>. Below is a patch that shows what should be changed. You can apply the patch with the &#039;<tt>patch</tt>&#039; command, or you can manually add the lines that start with a &#039;+&#039;, replacing the lines with a &#039;-&#039;.</p>
<pre>
--- /home/root/foo      2007-11-21 11:53:58.532769984 +0100
+++ /etc/cron.daily/chkrootkit  2007-11-21 11:54:00.689442120 +0100
@@ -1,27 +1,28 @@
 #!/bin/sh -e

 CHKROOTKIT=/usr/sbin/chkrootkit
 CF=/etc/chkrootkit.conf
+IGNOREF=/etc/chkrootkit.ignore
 LOG_DIR=/var/cache/chkrootkit

 if [ ! -x $CHKROOTKIT ]; then
   exit 0
 fi

 if [ -f $CF ]; then
     . $CF
 fi

 if [ "$RUN_DAILY" = "true" ]; then
     if [ "$DIFF_MODE" = "true" ]; then
-        $CHKROOTKIT $RUN_DAILY_OPTS > $LOG_DIR/log.new 2>&#038;1
+        $CHKROOTKIT $RUN_DAILY_OPTS | grep -v -f $IGNOREF > $LOG_DIR/log.new 2>&#038;1 || true
         if [ ! -f $LOG_DIR/log.old ] \
            || ! diff -q $LOG_DIR/log.old $LOG_DIR/log.new > /dev/null 2>&#038;1; then
             cat $LOG_DIR/log.new
         fi
         mv $LOG_DIR/log.new $LOG_DIR/log.old
     else
-        $CHKROOTKIT $RUN_DAILY_OPTS
+        $CHKROOTKIT $RUN_DAILY_OPTS | grep -v -f $IGNOREF || true
     fi
 fi
</pre>
<p>Next, we try running chkrootkit, to see if anything shows up:</p>
<pre>
[root@sharky]/etc/cron.daily# ./chkrootkit
[root@sharky]/etc/cron.daily#
</pre>
<p>There is no output, so our false positives are now being ignored.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.electricmonk.nl/log/2007/11/29/chkrootkit-false-positives-filtering/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SSH + SOCKS5 = Universal proxy</title>
		<link>http://www.electricmonk.nl/log/2007/11/14/ssh-socks5-universal-proxy/</link>
		<comments>http://www.electricmonk.nl/log/2007/11/14/ssh-socks5-universal-proxy/#comments</comments>
		<pubDate>Wed, 14 Nov 2007 08:57:37 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[freedom and privacy]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://www.electricmonk.nl/log/2007/11/14/ssh-socks5-universal-proxy/</guid>
		<description><![CDATA[I didn&#039;t know it, but (Open)SSH supports setting up a Socks5 proxy: -D [bind_address:]port Specifies a local ``dynamic'' application-level port forwarding. This works by allocating a socket to listen to port on the local side, optionally bound to the specified bind_address. Whenever a connection is made to this port, the connection is forwarded over the [...]]]></description>
				<content:encoded><![CDATA[<p>I didn&#039;t know it, but (Open)SSH supports setting up a <a href="http://en.wikipedia.org/wiki/Socks5">Socks5</a> proxy:</p>
<pre>
-D [bind_address:]port
  Specifies a local ``dynamic'' application-level port forwarding.
  This works by allocating a socket to listen to port on the local
  side, optionally bound to the specified bind_address.  Whenever a
  connection is made to this port, the connection is forwarded over
  the secure channel, and the application protocol is then used to
  determine where to connect to from the remote machine.  Currently
  the SOCKS4 and SOCKS5 protocols are supported, and ssh will act
  as a SOCKS server.  Only root can forward privileged ports.
  Dynamic port forwardings can also be specified in the configura-
  tion file.
</pre>
<p>Socks5 is pretty neat, as it allows you to proxy stuff without the server having to know anything about the way the client works. For instance, if we give the following command:</p>
<pre>$ ssh -N -D 127.0.0.1:8080 todsah@sharky.electricmonk.nl</pre>
<p>We can now tell all kinds of clients such as web browsers and instant messaging clients that there is a Socks5 proxy running on the localhost at port 8080. SSH will forward all connections made to port 8080 to the sharky.electricmonk.nl host (all encrypted of course). </p>
<p>So, say we tell <a href="http://www.pidgin.im/">Pidgin</a> that it should connect your MSN account through the Socks5 proxy at localhost:8080 by opening the Accounts (Ctrl-A) &rarr; Click MSN account &rarr; click <tt>Modify</tt> &rarr; <tt>Advanced</tt> tab &rarr; Proxy options &rarr; Proxy type = SOCKS5 and setting it to Host: localhost, Port: 8080. Now, when we reconnect to our MSN account, all MSN traffic will be routed over an encrypted SSH tunnel to the <tt>sharky.electricmonk.nl</tt> host, and will enter the public Internet from there. </p>
<p>This works great if you don&#039;t trust the network you&#039;re currently on, but don&#039;t have access to a VPN for instance. You also don&#039;t have to specify a single forward for each application/port like you have to do when you use <tt>ssh -L</tt>. You can use the same SOCKS5 proxied port with multiple applications, as long as they understand SOCKS5.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.electricmonk.nl/log/2007/11/14/ssh-socks5-universal-proxy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Virtualization Security</title>
		<link>http://www.electricmonk.nl/log/2007/10/25/virtualization-security/</link>
		<comments>http://www.electricmonk.nl/log/2007/10/25/virtualization-security/#comments</comments>
		<pubDate>Thu, 25 Oct 2007 20:35:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[security]]></category>
		<category><![CDATA[sysadmin]]></category>

		<guid isPermaLink="false">http://www.electricmonk.nl/log/2007/10/25/virtualization-security/</guid>
		<description><![CDATA[Theo de Raadt on virtualisation security: > Virtualization seems to have a lot of security benefits. You&#039;ve been smoking something really mind altering, and I think you should share it. x86 virtualization is about basically placing another nearly full kernel, full of new bugs, on top of a nasty x86 architecture which barely has correct [...]]]></description>
				<content:encoded><![CDATA[<p><a href="http://kerneltrap.org/OpenBSD/Virtualization_Security">Theo de Raadt on virtualisation security</a>:</p>
<blockquote><p>
> Virtualization seems to have a lot of security benefits.</p>
<p>You&#039;ve been smoking something really mind altering, and I think you<br />
should share it.</p>
<p>x86 virtualization is about basically placing another nearly full<br />
kernel, full of new bugs, on top of a nasty x86 architecture which<br />
barely has correct page protection.  Then running your operating<br />
system on the other side of this brand new pile of shit.</p>
<p>You are absolutely deluded, if not stupid, if you think that a<br />
worldwide collection of software engineers who can&#039;t write operating<br />
systems or applications without security holes, can then turn around<br />
and suddenly write virtualization layers without security holes.</p>
<p>> Anything we can do to increase security, *including* setting up VMs (of any<br />
> flavor) is an improvement [that also increased hardware utilization].</p>
<p>This last sentence is such a lie.  </p>
<p>The fact is that you, and most of the other fanboys, only care about<br />
the [that also increased hardware utilization].  The yammering about<br />
security is just one thing &#8212; job security.  You&#039;ve got to be able to<br />
sell increased harwdare utilization in a way that does not hang you up<br />
at the end of the day.
</p></blockquote>
<p>Of course, de Raadt is right&#8230; in his own tiny little world at least. Running services which would normally run on multiple machines on multiple hypervisored instances on a single host machine would indeed be less secure than running them from multiple physical machines.</p>
<p>But running multiple <em>applications</em> on virtualized machines which would normally run on a <em>single</em> machine <b>is</b> more secure, simply because it adds another layer of protection. </p>
<p>But, as usual, de Raadt&#039;s complete ineptitude when it comes to communications totally negates any point he&#039;s trying to make and only serves to rile up people against his cause.</p>
<p>It&#039;s the chrooted story all over again. Yes, chroot isn&#039;t completely secure. Yes, chroot isn&#039;t meant as a security construction. Yes, running multiple services on a single machine that would normally be run on several separate physical machines is less secure. That doesn&#039;t mean chroot (and virtualisation for that matter) can&#039;t add an extra layer of security <em>if used properly</em>!</p>
<p>Theo de Raadt&#039;s problem is that he views security the way cryptography experts view cyphers: as an absolute. But security isn&#039;t like math. It&#039;s not absolute. There are right and wrong ways of doing security. De Raadt is like that security consultant who says: &#034;You must have randomly generated passwords consisting of at least eighteen characters, lower and upper case, numbers and symbols, nothing repeated twice, completely unique and changed every week, or your being insecure!&#034;, all the while ignoring the fact that that kind of password policy will only force people to write down passwords on a yellow-note under their keyboards. In theory, they&#039;re right. In practice, they&#039;re wrong. These people become blinded by their own viewpoint. Just as these so-called security consultants are blinded by their belief that strong passwords equal security, so is Theo de Raadt blinded by his belief that virtualization doesn&#039;t improve security.</p>
<p>Perhaps it&#039;s time to stop listening to de Raadt, and start listening to people with a broader overview of the situation. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.electricmonk.nl/log/2007/10/25/virtualization-security/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MyDoom</title>
		<link>http://www.electricmonk.nl/log/2004/01/28/mydoom/</link>
		<comments>http://www.electricmonk.nl/log/2004/01/28/mydoom/#comments</comments>
		<pubDate>Tue, 27 Jan 2004 22:26:40 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[opinion]]></category>
		<category><![CDATA[security]]></category>

		<guid isPermaLink="false"></guid>
		<description><![CDATA[So, I&#039;ve read there&#039;s another virus on the loose. *g* When will this end? I&#039;ll tell you: never. At least, not until these virusses do some radical damage. They aren&#039;t destructive enough against the right targets. Right now, these virusses do create a lot of problems and damage to infrastructures and companies. The problem is, [...]]]></description>
				<content:encoded><![CDATA[<p>So, I&#039;ve read there&#039;s another virus on the loose. *g* When will this end? I&#039;ll tell you: never. At least, not until these virusses do some radical damage. They aren&#039;t destructive enough against the right targets. Right now, these virusses do create a lot of problems and damage to infrastructures and companies. The problem is, home users <b>don&#039;t give a shit</b>. There are lots of sites out there which educate the people on how to avoid such virusses, but do they read them? Do they learn from previous virusses? Hell no. Why should they care, all the virus does is replicate. It doesn&#039;t delete all their digital camera pictures, mp3&#039;s, downloaded movies or porn, so they don&#039;t give a rat&#039;s ass.</p>
<p>When the propagators of these virusses, the home users, start feeling the pain caused by these virusses, <b>then</b> they will take the time to think for a couple of seconds and do something about it. E.g. install and REGURALY UPGRADE their virusscanners, stop clicking of everything that say&#039;s click me, run the WSH files that will protect their inboxes from crap.</p>
<p><i>Disclaimer: I haven&#039;t actually looked at how MyDoom propegates at all, so I might be totally off on this. But since I&#039;m not seeying as much as a glimp of this virus, I suspect it spreads in the usual fashion</i></p>
]]></content:encoded>
			<wfw:commentRss>http://www.electricmonk.nl/log/2004/01/28/mydoom/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
