<?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>No pain no gain &#187; Security</title>
	<atom:link href="http://www.dikant.de/category/security/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.dikant.de</link>
	<description>Personal blog of Peter Dikant</description>
	<lastBuildDate>Sat, 28 Jan 2012 12:25:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Configuring a PPTP-VPN on iOS and Android</title>
		<link>http://www.dikant.de/2011/10/03/configuring-a-pptp-vpn-on-ios-and-android/</link>
		<comments>http://www.dikant.de/2011/10/03/configuring-a-pptp-vpn-on-ios-and-android/#comments</comments>
		<pubDate>Mon, 03 Oct 2011 15:28:30 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[amazon]]></category>
		<category><![CDATA[android]]></category>
		<category><![CDATA[iOS]]></category>
		<category><![CDATA[pptp]]></category>
		<category><![CDATA[vpn]]></category>
		<category><![CDATA[was]]></category>

		<guid isPermaLink="false">http://www.dikant.de/?p=225</guid>
		<description><![CDATA[About a year ago, I wrote a blog posting about how to setup a PPTP VPN service on a Amazon EC2 node. This is a follow up to that posting which describes how to setup the VPN on an iOS &#8230; <a href="http://www.dikant.de/2011/10/03/configuring-a-pptp-vpn-on-ios-and-android/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>About a year ago, I wrote a <a href="http://www.dikant.de/2010/10/08/setting-up-a-vpn-server-on-amazon-ec2/" title="Setting up a VPN-server on Amazon EC2">blog posting</a> about how to setup a PPTP VPN service on a Amazon EC2 node. This is a follow up to that posting which describes how to setup the VPN on an iOS or Android device.</p>
<p>Please note that some carriers might block PPTP traffic. I experienced problems with using the VPN connection via 3G, while connecting through Wifi works for me. On 3G I can connect to the server, but no data is being transferred. On the server I see a lot of messages of the type &#8220;Protocol-Reject&#8221;. So if your device seems to be connected to the VPN but you get no traffic, it might be blocked by your carrier. You then need to find a Wifi Hotspot to use the VPN.</p>
<p><span id="more-225"></span></p>
<h2>iOS Devices</h2>
<p>Setting up the VPN is pretty straight forward:</p>
<ol>
<li>Go to Settings and open the &#8220;General&#8221; settings</li>
<li>Select &#8220;Network&#8221;</li>
<li>Select &#8220;VPN&#8221;</li>
<li>Choose &#8220;Add VPN Configuration&#8230;&#8221;</li>
<li>On this screen make sure you activate &#8220;PPTP&#8221;. Now you can name your VPN connection and enter the address of the server, your login and your password. Ensure that &#8220;Send All Traffic&#8221; is &#8220;ON&#8221;. Now save your settings.</li>
<li>Now you can turn on the VPN connection. An active connection is indicated by a blue &#8220;VPN&#8221; icon in the status bar.</li>
</ol>
<p><a href="http://www.dikant.de/wp-content/uploads/2011/10/IMG_0020.png"><img src="http://www.dikant.de/wp-content/uploads/2011/10/IMG_0020-150x150.png" alt="" title="iOS step 1" width="150" height="150" class="alignnone size-thumbnail wp-image-233" /></a><a href="http://www.dikant.de/wp-content/uploads/2011/10/IMG_0021.png"><img src="http://www.dikant.de/wp-content/uploads/2011/10/IMG_0021-150x150.png" alt="" title="iOS step 2" width="150" height="150" class="alignnone size-thumbnail wp-image-234" /></a><a href="http://www.dikant.de/wp-content/uploads/2011/10/IMG_0022.png"><img src="http://www.dikant.de/wp-content/uploads/2011/10/IMG_0022-150x150.png" alt="" title="iOS step 3" width="150" height="150" class="size-thumbnail wp-image-235" /></a><a href="http://www.dikant.de/wp-content/uploads/2011/10/IMG_0023.png"><img src="http://www.dikant.de/wp-content/uploads/2011/10/IMG_0023-150x150.png" alt="" title="iOS step 4" width="150" height="150" class="alignnone size-thumbnail wp-image-236" /></a><a href="http://www.dikant.de/wp-content/uploads/2011/10/IMG_0024.png"><img src="http://www.dikant.de/wp-content/uploads/2011/10/IMG_0024-150x150.png" alt="" title="iOS step 5" width="150" height="150" class="alignnone size-thumbnail wp-image-237" /></a><a href="http://www.dikant.de/wp-content/uploads/2011/10/IMG_0025.png"><img src="http://www.dikant.de/wp-content/uploads/2011/10/IMG_0025-150x150.png" alt="" title="iOS step 6" width="150" height="150" class="alignnone size-thumbnail wp-image-238" /></a></p>
<h2>Android Devices</h2>
<p>On Android, the steps are quite similar:</p>
<ol>
<li>Go to &#8220;Settings&#8221; and open &#8220;Wireless &#038; networks&#8221;</li>
<li>Select &#8220;VPN settings&#8221;</li>
<li>Select &#8220;Add VPN&#8221;</li>
<li>Choose &#8220;Add PPTP VPN&#8221;</li>
<li>Enter the &#8220;VPN name&#8221; and the server address in &#8220;Set VPN server&#8221;. Encryption should be enabled and DNS search domains not set. Now pull up the menu and save your changes.</li>
<li>Click on connect and enter your login and password.</li>
<li>An active VPN connection is indicated by a key icon in the status bar.</li>
</ol>
<p><a href="http://www.dikant.de/wp-content/uploads/2011/10/device-2011-10-03-162230.png"><img src="http://www.dikant.de/wp-content/uploads/2011/10/device-2011-10-03-162230-150x150.png" alt="" title="Android step 1" width="150" height="150" class="alignnone size-thumbnail wp-image-226" /></a><a href="http://www.dikant.de/wp-content/uploads/2011/10/device-2011-10-03-162247.png"><img src="http://www.dikant.de/wp-content/uploads/2011/10/device-2011-10-03-162247-150x150.png" alt="" title="Android step 2" width="150" height="150" class="alignnone size-thumbnail wp-image-227" /></a><a href="http://www.dikant.de/wp-content/uploads/2011/10/device-2011-10-03-162257.png"><img src="http://www.dikant.de/wp-content/uploads/2011/10/device-2011-10-03-162257-150x150.png" alt="" title="Android step 3" width="150" height="150" class="alignnone size-thumbnail wp-image-228" /></a><a href="http://www.dikant.de/wp-content/uploads/2011/10/device-2011-10-03-162304.png"><img src="http://www.dikant.de/wp-content/uploads/2011/10/device-2011-10-03-162304-150x150.png" alt="" title="Android step 4" width="150" height="150" class="alignnone size-thumbnail wp-image-229" /></a><a href="http://www.dikant.de/wp-content/uploads/2011/10/device-2011-10-03-162538.png"><img src="http://www.dikant.de/wp-content/uploads/2011/10/device-2011-10-03-162538-150x150.png" alt="" title="Android step 5" width="150" height="150" class="alignnone size-thumbnail wp-image-230" /></a><a href="http://www.dikant.de/wp-content/uploads/2011/10/device-2011-10-03-162631.png"><img src="http://www.dikant.de/wp-content/uploads/2011/10/device-2011-10-03-162631-150x150.png" alt="" title="Android step 6" width="150" height="150" class="alignnone size-thumbnail wp-image-231" /></a><a href="http://www.dikant.de/wp-content/uploads/2011/10/device-2011-10-03-163133.png"><img src="http://www.dikant.de/wp-content/uploads/2011/10/device-2011-10-03-163133-150x150.png" alt="" title="Android step 7" width="150" height="150" class="alignnone size-thumbnail wp-image-232" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.dikant.de/2011/10/03/configuring-a-pptp-vpn-on-ios-and-android/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Setting up a VPN-server on Amazon EC2</title>
		<link>http://www.dikant.de/2010/10/08/setting-up-a-vpn-server-on-amazon-ec2/</link>
		<comments>http://www.dikant.de/2010/10/08/setting-up-a-vpn-server-on-amazon-ec2/#comments</comments>
		<pubDate>Fri, 08 Oct 2010 17:34:24 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[aws]]></category>
		<category><![CDATA[ec2]]></category>
		<category><![CDATA[pptpd]]></category>
		<category><![CDATA[ubuntu]]></category>

		<guid isPermaLink="false">http://www.dikant.de/?p=129</guid>
		<description><![CDATA[Amazon has recently announced the new Micro Instances in their Elastic Cloud service. A so called Micro Instance is a virtual machine with 620 MB main memory and CPU power in the area of an 1 GHz Opteron processor. The &#8230; <a href="http://www.dikant.de/2010/10/08/setting-up-a-vpn-server-on-amazon-ec2/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.dikant.de/wp-content/uploads/2010/10/imgres.jpg"><img src="http://www.dikant.de/wp-content/uploads/2010/10/imgres.jpg" alt="" title="imgres" width="116" height="47" class="alignleft size-full wp-image-130" /></a><a href="http://aws.amazon.com">Amazon</a> has recently announced the new Micro Instances in their Elastic Cloud service. A so called Micro Instance is a virtual machine with 620 MB main memory and CPU power in the area of an 1 GHz Opteron processor. The advantage of the Micro Instance is its low cost of only $0.02 per hour of operation (be advised, there are some additional costs for traffic and storage). </p>
<p>The EC2 Micro Instance is an ideal way to operate your own VPN-server, when you need it only a couple of hours per month. Let&#8217;s assume, that you want to use it for about 50 hours per month with around 10 GB of traffic, this means $1.00 for computation time + $1.50 for 15 GB of storage + $1.50 for 10 GB outgoing traffic. So for $4 this is quite a good offer. Granted, you can find commercial VPN providers for $5 per month, but it is more fun to do it yourself. In this article I will describe, how to setup an EC2 instance as a VPN-server.<br />
<span id="more-129"></span><br />
I choose to setup a PPTP server. PPTP is not the most secure type of VPN, but it has the big advantage, that it is the most compatible. Nearly every OS is able to open a PPTP connection without additional software and this includes mobile devices like iPhones/iPads. </p>
<p>First, you need to choose a base image to boot in the Micro Instance. I have selected an 32-bit Ubuntu 10.04 server image. The AMI-ID of this image is <code>ami-6c06f305</code>. Start this image in a Micro Instance and log in with your SSH-key. For more details on these steps, refer to the AWS documentation.</p>
<p>Once you are logged in, you can install the pptp-daemon:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> pptpd</pre></div></div>

<p>Configuring the pptp-daemon is a breeze. First you to define an IP address range which will be used for connected clients. This can be any IP range, but keep in mind, if you want to avoid routing problems, choose a private IP range. Uncomment and modify 2 lines at the end of <code>/etc/pptpd.conf</code>:</p>
<pre>
localip 192.168.240.1
remoteip 192.168.240.2-9
</pre>
<p>With the above settings, the pptpd server will get the address 192.168.240.1 and there are 8 possible client addresses 192.168.240.2 to 192.168.240.9.</p>
<p>It is also a good idea to specify the address of at least one DNS server. You can use the DNS server of amazon (<code>172.16.0.23</code>) or the Google Public DNS. I choose the latter. Open the file <code>/etc/ppp/pptpd-options</code> and make sure it contains the following settings:</p>
<pre>
ms-dns 8.8.8.8
ms-dns 8.8.4.4
</pre>
<p>The last step for configuring the pptpd-daemon is to add a user account for the service:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;USERNAME pptpd PASSWORD *&quot;</span> <span style="color: #000000; font-weight: bold;">&gt;&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>ppp<span style="color: #000000; font-weight: bold;">/</span>chap-secrets</pre></div></div>

<p>Replace <code>USERNAME</code> and <code>PASSWORD</code> with whatever credentials you like. It is possible to add as many users as you like.</p>
<p>Now restart the pptp-daemon:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>pptpd restart</pre></div></div>

<p>It is already possible to open a PPTP-connection to the server, although no traffic will be forwarded to the Internet. We still need to enable packet forwarding and network address translation on the server.</p>
<p>To enable packet forwarding, uncomment the following line in <code>/etc/sysctl.conf</code>:</p>
<pre>
net.ipv4.ip_forward=1
</pre>
<p>Now reload this config:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> sysctl <span style="color: #660033;">-p</span></pre></div></div>

<p>The last step is to enable network address translation:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> iptables <span style="color: #660033;">-t</span> nat <span style="color: #660033;">-A</span> POSTROUTING <span style="color: #660033;">-o</span> eth0 <span style="color: #660033;">-j</span> MASQUERADE</pre></div></div>

<p>This setting is reset on every reboot, so make sure that you add the following line above <code>exit 0</code> in the file <code>/etc/rc.local</code>:</p>
<pre>
iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
</pre>
<p>Now the VPN server is fully functional. The only small problem is, that the server will get a new IP address every time you reboot it. I would recommend using a dynamic dns-provider to assign this machine a unique domain name. I am using <a href="http://www.dyndns.com/">DynDNS</a>.</p>
<p>The <a href="http://sourceforge.net/apps/trac/ddclient">ddclient</a> is a great little tool to update the current IP address on a number of different dynamic DNS services. Installation is done as usual:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">sudo</span> <span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> ddclient</pre></div></div>

<p>Once installed, the configuration is done in the file <code>/etc/ddclient.conf</code>. It will already contain some usefull settings, because the installer will require you to enter some information about the DNS service you are using. In the end the configuration should look something like this:</p>
<pre>
protocol=dyndns2
use=web, web=checkip.dyndns.com/, web-skip='IP Address'
server=members.dyndns.org
login=LOGINNAME
password='PASSWORD'
DOMAINNAME.dyndns.org
</pre>
<p>Replace <code>LOGINNAME</code>, <code>PASSWORD</code> and <code>DOMAINNAME.dyndns.org</code> with your own settings. The most important line is the one starting with <code>use=</code>. This defines that the registered IP-address is detected by DynDNS itself. This is neccessary, because the virtual machine is running with a private IP address.</p>
<p>That&#8217;s it! Now you have your own VPN-server up and running. Just start the instance in the <a href="https://console.aws.amazon.com/ec2/home">AWS Management Console</a> whenever you need it.</p>
<p><em>Update:</em></p>
<p>Here is a screenshot of the security groups setup I am using:<br />
<a href="http://www.dikant.de/wp-content/uploads/2010/10/ec2_security_setup.gif"><img src="http://www.dikant.de/wp-content/uploads/2010/10/ec2_security_setup.gif" alt="" title="ec2_security_setup" width="775" height="287" class="alignleft size-full wp-image-163" /></a></p>
<p><em>Update 2:</em></p>
<p>Please take a look at my <a href="http://www.dikant.de/2011/10/03/configuring-a-pptp-vpn-on-ios-and-android/" title="Configuring a PPTP-VPN on iOS and Android">follow up posting</a> on how to connect to the VPN from an iOS or Android device.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dikant.de/2010/10/08/setting-up-a-vpn-server-on-amazon-ec2/feed/</wfw:commentRss>
		<slash:comments>59</slash:comments>
		</item>
		<item>
		<title>Securing SSH server with fail2ban</title>
		<link>http://www.dikant.de/2009/06/19/securing-ssh-server-with-fail2ban/</link>
		<comments>http://www.dikant.de/2009/06/19/securing-ssh-server-with-fail2ban/#comments</comments>
		<pubDate>Fri, 19 Jun 2009 17:06:02 +0000</pubDate>
		<dc:creator>Peter</dc:creator>
				<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://www.dikant.de/?p=76</guid>
		<description><![CDATA[When you are running your SSH server on the standard port 22, you likely see brute force login attempts multiple times a day. The SSH server does not limit unsuccessfull login attempts by itself. So there are multiple ways to &#8230; <a href="http://www.dikant.de/2009/06/19/securing-ssh-server-with-fail2ban/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>When you are running your SSH server on the standard port 22, you likely see brute force login attempts multiple times a day. The SSH server does not limit unsuccessfull login attempts by itself. So there are multiple ways to deal with this problem.</p>
<p>One option is to move the SSH daemon to a non-standard port. But this means that you might get problems connecting yourself to the server if you are working from a restricted network. So another solution would be to use certificates for login. But then you need to make sure that you carry the certificates with you when you want to login to your server.</p>
<p>Now a good solution is to limit access to the SSH server. One way would be to use the so called port-knocking approach. Here the access to the SSH port is blocked until you use some kind of secret knock-sequence. Then the port will be unblocked for your IP for a certain time. This is very effective but has the downside that you always need to use this knock mechanism before connecting to your server.</p>
<p><span id="more-76"></span></p>
<p>What I prefer is a mechanism which works the other way around. The access to the SSH port is open until there are a number of failed login attempts detected. If this is the case, the IP address these login attempts came from will be blocked for a couple of hours. This approach is less secure then the port knocking approach but is a lot more convenient for me. As long is I don&#8217;t mess up multiple times with the login, I do not even notice any security restrictions. Brute force attacks on the other hand are blocked right away.</p>
<p>The most common tool for this task is the excellent <a href="http://www.fail2ban.org">fail2ban</a>. On a Debian system it can be installed via <code>aptitude</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #c20cb9; font-weight: bold;">aptitude</span> <span style="color: #c20cb9; font-weight: bold;">install</span> fail2ban</pre></div></div>

<p>The default configuration is already useful. It will secure the SSH daemon with a blocking time of 10 minutes after 6 failed login attempts. The configuration files can be found in the directory <code>/etc/fail2ban</code>.</p>
<p>You can change the blocking time in the file <code>/etc/fail2ban/jail.conf</code>:</p>

<div class="wp_syntax"><div class="code"><pre class="config" style="font-family:monospace;">[DEFAULT]
bantime  = 7200
maxretry = 4</pre></div></div>

<p>This will change the default settings which apply if not specified otherwise in the application settings. The setting <code>bantime</code> is specified in seconds and defines how long the blocked IP will not be able to connect to the blocked service. <code>maxretry</code> is the number of failed login attempts.</p>
<p>Lets take a look at the ssh setting:</p>

<div class="wp_syntax"><div class="code"><pre class="config" style="font-family:monospace;">[ssh]
enabled = true
port    = ssh
filter  = sshd
logpath  = /var/log/auth.log
maxretry = 3</pre></div></div>

<p>You can enable or disable the monitoring of specific services (ports). The ssh monitoring uses the <code>auth.log</code> file to detect failed login attempts.</p>
<p>To activate changed configuration settings, just reload the service:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">/</span>etc<span style="color: #000000; font-weight: bold;">/</span>init.d<span style="color: #000000; font-weight: bold;">/</span>fail2ban force-reload</pre></div></div>

<p>So what happens when an IP is blocked? Once the login attempt limit has been reached, the IP address will be blocked via iptables. Here is the output of iptables on my system:</p>

<div class="wp_syntax"><div class="code"><pre class="config" style="font-family:monospace;">Chain INPUT (policy ACCEPT)
target     prot opt source               destination
fail2ban-ssh  tcp  --  0.0.0.0/0            0.0.0.0/0           multiport dports 22
&nbsp;
Chain FORWARD (policy ACCEPT)
target     prot opt source               destination
&nbsp;
Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination
&nbsp;
Chain fail2ban-ssh (1 references)
target     prot opt source               destination
DROP       all  --  123.456.789.012        0.0.0.0/0
RETURN     all  --  0.0.0.0/0            0.0.0.0/0</pre></div></div>

<p>I have replaced the blocked IP address with some default numbers, but you can see that all traffic from this IP address to the port 22 will be blocked. This iptables rule will be automatically removed after the specified blockout time.</p>
<p>fail2ban is an effective tool to lock out brute force login attempts. It is really easy to setup and can be used to monitor multiple services besides SSH.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.dikant.de/2009/06/19/securing-ssh-server-with-fail2ban/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

