<?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>SysAdminMan Blog &#187; Linux and Unix</title>
	<atom:link href="http://sysadminman.net/blog/category/linux/feed/" rel="self" type="application/rss+xml" />
	<link>http://sysadminman.net/blog</link>
	<description></description>
	<lastBuildDate>Mon, 14 May 2012 15:01:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Whitelist in fail2ban and denyhosts</title>
		<link>http://sysadminman.net/blog/2012/whitelist-in-fail2ban-and-denyhosts-3995</link>
		<comments>http://sysadminman.net/blog/2012/whitelist-in-fail2ban-and-denyhosts-3995#comments</comments>
		<pubDate>Fri, 04 May 2012 10:29:07 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Asterisk]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[asterisk]]></category>
		<category><![CDATA[denyhosts]]></category>
		<category><![CDATA[fail2ban]]></category>

		<guid isPermaLink="false">http://sysadminman.net/blog/?p=3995</guid>
		<description><![CDATA[All SysAdminMan servers come with fail2ban and denyhosts installed. These are two software packages that do similar things so can be confusing. Here are the differences - fail2ban monitors Asterisk logs for failed &#8216;Register&#8217; attempts and blocks the IP using IPTables. This means if you get yourself blocked it will appear as though the server [...]]]></description>
			<content:encoded><![CDATA[<p>All SysAdminMan servers come with fail2ban and denyhosts installed. These are two software packages that do similar things so can be confusing.<br />
Here are the differences -</p>
<p style="padding-left: 30px;"><strong>fail2ban</strong><br />
monitors Asterisk logs for failed &#8216;Register&#8217; attempts and blocks the IP using IPTables. This means if you get yourself blocked it will appear as though the server has gone down</p>
<p style="padding-left: 30px;"><strong>denyhosts</strong><br />
monitors /var/log/secure for failed SSH attempts and just blocks the IP for SSH access. You will get connection refused just for SSH if you get yourself blocked</p>
<p>It&#8217;s possible to whitelist your own IPs so that they don&#8217;t get accidentally blocked by following the instructions below.</p>
<p>You should replace 123.123.123.123 with your own IP -</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">export ignoreip=&quot;123.123.123.123&quot;<br />
<br />
sed -i &quot;s/ignoreip = /ignoreip = $ignoreip /&quot; /etc/fail2ban/jail.conf<br />
service fail2ban restart<br />
<br />
echo &quot;sshd: $ignoreip&quot; &gt;&gt; /etc/hosts.allow<br />
service denyhosts restart</div></div>
]]></content:encoded>
			<wfw:commentRss>http://sysadminman.net/blog/2012/whitelist-in-fail2ban-and-denyhosts-3995/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Asterisk virtualization &#8211; OpenVZ or VMWare?</title>
		<link>http://sysadminman.net/blog/2011/asterisk-virtualization-openvz-or-vmware-3004</link>
		<comments>http://sysadminman.net/blog/2011/asterisk-virtualization-openvz-or-vmware-3004#comments</comments>
		<pubDate>Mon, 10 Oct 2011 14:29:46 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Asterisk]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[asterisk]]></category>
		<category><![CDATA[kvm]]></category>
		<category><![CDATA[openvz]]></category>
		<category><![CDATA[vmware]]></category>
		<category><![CDATA[Xen]]></category>

		<guid isPermaLink="false">http://sysadminman.net/blog/?p=3004</guid>
		<description><![CDATA[I recently read a post/advert claiming that VMWare was a &#8216;much better&#8217; platform for hosting Asterisk than any other virtualization platform, such as OpenVZ, Xen, KVM &#8230; So I thought I&#8217;d write a little about the architecture running the SysAdminMan VPSs and why it was chosen. There are a few different names given to a [...]]]></description>
			<content:encoded><![CDATA[<p>I recently read a post/advert claiming that VMWare was a &#8216;much better&#8217; platform for hosting Asterisk than any other virtualization platform, such as OpenVZ, Xen, KVM &#8230; So I thought I&#8217;d write a little about the architecture running the SysAdminMan VPSs and why it was chosen.<a href="http://sysadminman.net/blog/wp-content/uploads/2011/10/openvz-logo.png"><img class="alignright size-full wp-image-3018" style="border-style: initial; border-color: initial; border-width: 0px; margin: 30px;" title="openvz-logo" src="http://sysadminman.net/blog/wp-content/uploads/2011/10/openvz-logo.png" alt="openvz-logo" width="135" height="135" /></a></p>
<p>There are a few different names given to a virtualized server &#8211; Virtual Private Server (VPS), Virtual Dedicated Server (VDS), VM (Virtual Machine) but they all refer to the same overall goal &#8211; take a dedicated server and partition it in to several virtual servers that share the underlying hardware.</p>
<p>Now, don&#8217;t get me wrong, I really like VMWare ESX. In fact I spent many years as a VMWare admin running mission critical ESX clusters that needed to be available 24/7. These hosted corporate web systems that processed many £100k&#8217;s of transactions per year. So does that make it the perfect platform for offering Asterisk hosting? Not necessarily.</p>
<p>VMWare and KVM both provide &#8216;full virtualization&#8217; which is a layer in between the hardware and VPS that emulates the hardware and provides the virtual machine access to it. This means the operating system on the VPS does not need to be aware that it is running inside a VPS. It runs as normal, with VMWare/KVM translating the requests to the underlying hardware. Xen can now also do this running in HVM mode.</p>
<p>While this provides good segregation between the Virtual Servers it does add a layer between the VPS and underlying hardware that <strong>can</strong> cause timing issues, which are so critical to VOIP/Asterisk. This is not always the case, but a possibility.</p>
<p>OpenVZ is different. This provides operating system-level virtualization where the underlying hardware runs a kernel that is shared by all of the virtual machines. On SysAdminMan VPSs this is CentOS. This provides more direct access to the underlying hardware which, in my experience, makes it an ideal platform for hosting Asterisk.</p>
<p>Where OpenVZ gets a bad name is that it&#8217;s very easy to provision many more VPSs on a physical server than that server can really handle. This means lots of virtual machines all trying to use the CPU, ram, network etc on the underlying server, resulting in bottlenecks. This might not be a problem on a webserver. If a web server takes half a second longer to display a web page because the server is overloaded then maybe nobody will notice. However, if your VOIP packets are delayed for half a second then you will definitely notice!<a href="http://sysadminman.net/blog/wp-content/uploads/2011/10/asterisk.jpg"><img class="alignright size-full wp-image-3022" style="border-style: initial; border-color: initial; border-width: 0px; margin: 40px;" title="asterisk" src="http://sysadminman.net/blog/wp-content/uploads/2011/10/asterisk.jpg" alt="" width="138" height="79" /></a></p>
<p>SysAdminMan only has around 10 virtual servers per physical server, often less depending on the resource allocations to the VPSs on that server. This results in a lot less contention for the underlying hardware than with some providers (especially general VPS providers) that might have 20, 30, 40 servers running on the same hardware.</p>
<p>Probably the most crucial fact about running Asterisk on a VPS though is <strong>who</strong> you are sharing the underlying hardware with, and how well the server is managed. Even if there are only a few other virtual servers on that server and they are allowed to abuse the resources available then you will likely get a bad VOIP experience. This can definitely be the case where Asterisk is installed on a general purpose VPS.</p>
<p>All SysAdminMan VPSs are specifically designed to be running Asterisk. The underlying hardware is closely monitored and you can be sure that you are not sharing the hardware with customers running highly demanding Java application servers or game servers etc. It can be very difficult for VPS customers to troubleshoot VOIP quality issues on their server as they have no visibility to the underlying hardware. You have to trust that your VPS provider is not allowing the underlying server to be overloaded.</p>
<p>The Asterisk hosting market is definitely getting more competitive but I&#8217;m confident that the service and products offered by SysAdminMan represent excellent value for money and a stable and well managed platform to host your VOIP server. SysAdminMan has been successfully hosting Asterisk servers since early 2009.</p>
]]></content:encoded>
			<wfw:commentRss>http://sysadminman.net/blog/2011/asterisk-virtualization-openvz-or-vmware-3004/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Check your DNS configuration &#8211; intoDNS</title>
		<link>http://sysadminman.net/blog/2011/check-you-dns-configuration-intodns-2456</link>
		<comments>http://sysadminman.net/blog/2011/check-you-dns-configuration-intodns-2456#comments</comments>
		<pubDate>Thu, 14 Jul 2011 20:15:20 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[intoDNS]]></category>

		<guid isPermaLink="false">http://sysadminman.net/blog/?p=2456</guid>
		<description><![CDATA[DNS can be a tricky thing! One of the main problems with troubleshooting your DNS set up is that DNS is a distributed system, there are thousands of DNS servers around the world, and changes to DNS records take time to propagate to all of these servers. A really useful tool for checking your DNS config is [...]]]></description>
			<content:encoded><![CDATA[<p>DNS can be a tricky thing! One of the main problems with troubleshooting your DNS set up is that DNS is a distributed system, there are thousands of DNS servers around the world, and changes to DNS records take time to propagate to all of these servers.<img class="alignright" style="border-width: 1px; border-color: black; border-style: solid; margin: 20px;" title="intoDNS" src="http://intodns.com/static/images/intodns_logo.gif" alt="intoDNS" width="250" height="43" /></p>
<p>A really useful tool for checking your DNS config is <a href="http://intodns.com/" rel="nofollow" title="intoDNS"  target="_blank">intoDNS</a>. You just type in your domain name and it will run some tests and highlight any potential issues it finds. It uses the authoritative DNS servers to try and rule out any confusion caused by DNS propagation times.</p>
<p>Check it out here &#8211; <a href="http://intodns.com/" rel="nofollow" title="intoDNS"  target="_blank">intoDNS</a></p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://sysadminman.net/blog/2011/check-you-dns-configuration-intodns-2456/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Restricting web interface access with iptables</title>
		<link>http://sysadminman.net/blog/2011/restricting-web-interface-access-with-iptables-2156</link>
		<comments>http://sysadminman.net/blog/2011/restricting-web-interface-access-with-iptables-2156#comments</comments>
		<pubDate>Mon, 18 Apr 2011 08:44:26 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://sysadminman.net/blog/?p=2156</guid>
		<description><![CDATA[By default all SysAdminMan VPSs come with port 443 open to allow https access to the web GUI. A really good security tip, where possible, is to restrict this to only IP addresses that need access. First, whenever making changes to iptables I always temporarily disable them from running at startup. This way if you [...]]]></description>
			<content:encoded><![CDATA[<p>By default all SysAdminMan VPSs come with port 443 open to allow https access to the web GUI. A really good security tip, where possible, is to restrict this to only IP addresses that need access.</p>
<p>First, whenever making changes to iptables I always temporarily disable them from running at startup. This way if you make an error and lock yourself out the server just needs a restart. You must remember to re-enable at the end!</p>
<p>Disable iptables at startup and copy the existing configuration -</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">chkconfig iptables off<br />
<br />
cp /etc/sysconfig/iptables /etc/sysconfig/iptables.orig</div></div>
<p><span id="more-2156"></span>Next list the current inbound rules with their line numbers -</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">iptables -L INPUT -n --line-numbers<br />
<br />
num  target     prot opt source               destination<br />
...<br />
7    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:4445<br />
8    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:22 state NEW<br />
9    ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:443 state NEW<br />
10   ACCEPT     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp dpt:5060<br />
...</div></div>
<p>So https access (port 443) is allowed in rule 9. Now we are going to delete this rule -</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">iptables -D INPUT 9</div></div>
<p>Now we add in the new rule to allow access to port 443 from a particular IP address. You will want to change the IP address below (123.123.123.123) to be your IP address. You may also want to change the Ethernet interface (venet0) if you are not using a SysAdminMan VPS -</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">iptables -I INPUT 1 -i venet0 -p tcp -m tcp -s 123.123.123.123 --dport 443 -j ACCEPT</div></div>
<p>Now check that the rule is working correctly. If it is we can save the current rules and enable them at startup again -</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">service iptables save<br />
chkconfig iptables on</div></div>
]]></content:encoded>
			<wfw:commentRss>http://sysadminman.net/blog/2011/restricting-web-interface-access-with-iptables-2156/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>KVM virtualization &#8211; text only CentOS guest install</title>
		<link>http://sysadminman.net/blog/2011/kvm-virtualization-text-centos-guest-install-2098</link>
		<comments>http://sysadminman.net/blog/2011/kvm-virtualization-text-centos-guest-install-2098#comments</comments>
		<pubDate>Tue, 05 Apr 2011 20:58:30 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[guest]]></category>
		<category><![CDATA[install]]></category>
		<category><![CDATA[kvm]]></category>
		<category><![CDATA[text]]></category>
		<category><![CDATA[virt-install]]></category>

		<guid isPermaLink="false">http://sysadminman.net/blog/?p=2098</guid>
		<description><![CDATA[It took me a little while today to figure out how to do a text only install of a CentOS guest on KVM. Previously I had started the install using virt-install and then connected to the VNC console over SSH. This is a bit of a hassle though when all you want is a quick, [...]]]></description>
			<content:encoded><![CDATA[<p>It took me a little while today to figure out how to do a text only install of a CentOS guest on KVM. Previously I had started the install using virt-install and then connected to the VNC console over SSH. This is a bit of a hassle though when all you want is a quick, text based install.</p>
<p>So here&#8217;s how.</p>
<p>Firstly all of my VMs live on LVM so create a virtual disk to hold the VM. I&#8217;m creating a 20G &#8216;partition&#8217; in a volume group called kvm-storage. The logical volume is called host.demo.com.</p>
<p><span id="more-2098"></span></p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">lvcreate -L20G -n host.demo.com kvm-storage</div></div>
<p>Now download the CentOS install ISO. Either CD1 or the netinstall ISO should be fine -</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">wget http://mirrors.manchester.icecolo.com/centos/5.5/isos/x86_64/CentOS-5.5-x86_64-bin-1of8.iso</div></div>
<p>Now we mount the ISO -</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">mkdir /mnt/centos55<br />
<br />
mount -o loop CentOS-5.5-x86_64-bin-1of8.iso /mnt/centos55/</div></div>
<p>Now we run the virt-install command. I suggest putting this command in a file and running it from there to make editing easier!</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">virt-install \<br />
-n host.demo.com \<br />
-r 512 \<br />
--vcpus=1 \<br />
--os-variant=rhel5.4 \<br />
--accelerate \<br />
--nographics  \<br />
-v \<br />
-l /mnt/centos55/ \<br />
-w bridge:br1 \<br />
--disk path=/dev/kvm-storage/host.demo.com \<br />
-x &quot;console=ttyS0&quot;</div></div>
<p>Here are the parts of the command above that allow for a text based install -</p>
<p>&#8211;nographics  &#8211; tells KVM not to allocate a graphics console to the VM</p>
<p>-v  &#8211; means we&#8217;re doing full virtualization</p>
<p>-l  &#8211; sets the boot location to be the ISO we mounted earlier</p>
<p>&#8211;disk  &#8211; sets the install destination disk to be the disk we created earlier</p>
<p>-x &#8220;console=ttyS0&#8243;  &#8211; sets a kernel boot parameter telling CentOS to use ttyS0 as the console</p>
<p>Once this is done you should see the text based installation screens. This worked pretty well in putty, you are able to tell what menu options you are selecting. You won&#8217;t be able to use the mounted ISO for the actual installation media so I did a HTTP install, selecting one of the CentOS mirrors to do the install from  (like &#8211; http://mirrors.manchester.icecolo.com/centos/5.5/os/x86_64/)</p>
<p>Once the install is complete and the VM rebooted you can access the console again by running -</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">virsh<br />
list --all<br />
console VM-ID</div></div>
]]></content:encoded>
			<wfw:commentRss>http://sysadminman.net/blog/2011/kvm-virtualization-text-centos-guest-install-2098/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Blocking Asterisk hacking/scanning attempts with fail2ban</title>
		<link>http://sysadminman.net/blog/2010/blocking-asterisk-hackingscanning-attempts-with-fail2ban-1392</link>
		<comments>http://sysadminman.net/blog/2010/blocking-asterisk-hackingscanning-attempts-with-fail2ban-1392#comments</comments>
		<pubDate>Thu, 07 Oct 2010 12:15:53 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Asterisk]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[asterisk]]></category>
		<category><![CDATA[elastix]]></category>
		<category><![CDATA[fail2ban]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[scanning]]></category>
		<category><![CDATA[trixbox]]></category>

		<guid isPermaLink="false">http://sysadminman.net/blog/?p=1392</guid>
		<description><![CDATA[Warning &#8211; if you follow these instructions fail2ban will, by default, be protecting you against other scans such as ssh attempts. This means though that if you get your IP blocked you will not be able to connect to your server from that IP. Ensure that you whitelist your IP by following the instructions at [...]]]></description>
			<content:encoded><![CDATA[<p><strong>Warning &#8211; if you follow these instructions fail2ban will, by default, be protecting you against other scans such as ssh attempts. This means though that if you get your IP blocked you will not be able to connect to your server from that IP. Ensure that you whitelist your IP by following the instructions at the end of the post.</strong></p>
<p>Over the past few weeks we have seen a big jump in the scanning of VOIP servers. All of these scans are brute force scanning attempts that first scan for valid extension numbers and then to brute force guess the extension password by repeatedly trying different passwords.</p>
<p>Unfortunately Asterisk doesn&#8217;t have anything built-in to prevent these types of scans but it is very good at logging these attempts in the Asterisk logs. This means we can use a free utility called <a href="http://www.fail2ban.org" rel="nofollow" title="fail2ban" >fail2ban</a> and the linux iptables firewall to block IP addresses that make repeated failed login attempts.</p>
<p>Fail2ban is already included in PBX-in-a-Flash but we can also use it with other Asterisk distributions.</p>
<p><span id="more-1392"></span><br />
Most of the information in this post was taken from <a href="http://www.voip-info.org/wiki/view/Fail2Ban+%28with+iptables%29+And+Asterisk" rel="nofollow" title="Asterisk fail2ban" >here</a>, so please visit for more information.</p>
<p>Here is a quick guide for getting fail2ban blocking Asterisk brute force scanning on a 32 bit CentOS server. You must have iptables installed already.</p>
<p>First we are going to install the rpmforge repository and use the fail2ban package from there -</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm<br />
sed -i 's/enabled = 0/enabled = 1/' /etc/yum.repos.d/rpmforge.repo</div></div>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">yum install -y fail2ban jwhois</div></div>
<p>Now disable the rpmforge repo do that it doesn&#8217;t interfere with any of the CentOS/Asterisk packages -</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">sed -i 's/enabled = 1/enabled = 0/' /etc/yum.repos.d/rpmforge.repo</div></div>
<p>Next we are going to create the fail2ban configuration file for Asterisk. This tells fail2ban what text to monitor the logs for -</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">cat &gt;&gt; /etc/fail2ban/filter.d/asterisk.conf &lt;&lt;-EOF<br />
# Fail2Ban configuration file<br />
#<br />
#<br />
# $Revision: 250 $<br />
#<br />
<br />
[INCLUDES]<br />
<br />
# Read common prefixes. If any customizations available -- read them from<br />
# common.local<br />
#before = common.conf<br />
<br />
[Definition]<br />
<br />
#_daemon = asterisk<br />
<br />
# Option: &nbsp;failregex<br />
# Notes.: &nbsp;regex to match the password failures messages in the logfile. The<br />
# &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;host must be matched by a group named &quot;host&quot;. The tag &quot;&lt;HOST&gt;&quot; can<br />
# &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;be used for standard IP/hostname matching and is only an alias for<br />
# &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;(?:::f{4,6}:)?(?P&lt;host&gt;\S+)<br />
# Values: &nbsp;TEXT<br />
# <br />
<br />
failregex = NOTICE.* .*: Registration from '.*' failed for '&lt;HOST&gt;' - Wrong password<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NOTICE.* .*: Registration from '.*' failed for '&lt;HOST&gt;' - No matching peer found<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NOTICE.* .*: Registration from '.*' failed for '&lt;HOST&gt;' - Username/auth name mismatch<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NOTICE.* .*: Registration from '.*' failed for '&lt;HOST&gt;' - Device does not match ACL<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NOTICE.* .*: Registration from '.*' failed for '&lt;HOST&gt;' - Peer is not supposed to register<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NOTICE.* &lt;HOST&gt; failed to authenticate as '.*'$<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NOTICE.* .*: No registration for peer '.*' \(from &lt;HOST&gt;\)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NOTICE.* .*: Host &lt;HOST&gt; failed MD5 authentication for '.*' (.*)<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NOTICE.* .*: Failed to authenticate user .*@&lt;HOST&gt;.*<br />
<br />
# Option: &nbsp;ignoreregex<br />
# Notes.: &nbsp;regex to ignore. If this regex matches, the line is ignored.<br />
# Values: &nbsp;TEXT<br />
#<br />
ignoreregex =<br />
EOF</div></div>
<p>Next we are going to add some lines to the jail.conf file that tells fail2ban what log files to monitor and what action to take when the required text is detected. This includes sending an alert e-mail so you may want to change &#8216;root&#8217; to your e-mail address. It also includes the length of time the IP address is blocked for in seconds. Here we have it set to 3 days, you may want to modify this -</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">cat &gt;&gt; /etc/fail2ban/jail.conf &lt;&lt;-EOF<br />
[asterisk-iptables]<br />
<br />
enabled &nbsp;= true<br />
filter &nbsp; = asterisk<br />
action &nbsp; = iptables-allports[name=ASTERISK, protocol=all]<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;sendmail-whois[name=ASTERISK, dest=root, sender=fail2ban@example.org]<br />
logpath &nbsp;= /var/log/asterisk/full<br />
maxretry = 5<br />
bantime = 259200<br />
EOF</div></div>
<p>Fail2ban needs the date in the Asterisk log files written in a specific format. To do this we can add a line to the &#8216;General&#8217; section of the Asterisk logger configuration file. If you already have a &#8216;General&#8217; section in there you will just want to add the line manually rather than running the command below -</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">cat &gt;&gt; /etc/asterisk/logger.conf &lt;&lt;-EOF<br />
[general]<br />
dateformat=%F %T<br />
EOF</div></div>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">asterisk -rx &quot;logger reload&quot;</div></div>
<p>Finally we want to fire up fail2ban and set it to start at boot time -</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">service fail2ban start<br />
chkconfig fail2ban on</div></div>
<p>One final thing you may want to do is &#8216;whitelist&#8217; your own IP address/s. You can do this by adding them to the ignoreip line in the jail.conf file. Here&#8217;s a couple of lines to do it automatically, just change the IP address here for your own IP address -</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">sed -i 's/ignoreip = /ignoreip = 123.123.123.123 /' /etc/fail2ban/jail.conf<br />
service fail2ban restart</div></div>
<div id="_mcePaste" style="position: absolute; left: -10000px; top: 176px; width: 1px; height: 1px; overflow: hidden;">
<pre class="code">rpm -Uhv http://apt.sw.be/redhat/el5/en/i386/rpmforge/RPMS/rpmforge-release-0.3.6-1.el5.rf.i386.rpm</pre>
</div>
]]></content:encoded>
			<wfw:commentRss>http://sysadminman.net/blog/2010/blocking-asterisk-hackingscanning-attempts-with-fail2ban-1392/feed/</wfw:commentRss>
		<slash:comments>12</slash:comments>
		</item>
		<item>
		<title>Limiting SIP/IAX connections to Asterisk with IPTables</title>
		<link>http://sysadminman.net/blog/2010/limiting-sipiax-connections-to-asterisk-with-iptables-1082</link>
		<comments>http://sysadminman.net/blog/2010/limiting-sipiax-connections-to-asterisk-with-iptables-1082#comments</comments>
		<pubDate>Sat, 27 Mar 2010 16:21:38 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Asterisk]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[asterisk]]></category>
		<category><![CDATA[iax]]></category>
		<category><![CDATA[iptables]]></category>
		<category><![CDATA[sip]]></category>

		<guid isPermaLink="false">http://sysadminman.net/blog/?p=1082</guid>
		<description><![CDATA[WARNING: be very careful when editing IPTables firewall rules. It is relatively easy to completely disable access to your machine. All Sysadminman VPSs come with IPTables enabled. However to allow for VOIP traffic both SIP and IAX ports are opened. If you know that your VOIP providers and all extensions are on fixed IP addresses [...]]]></description>
			<content:encoded><![CDATA[<p>WARNING: be very careful when editing IPTables firewall rules. It is relatively easy to completely disable access to your machine.</p>
<p>All Sysadminman VPSs come with IPTables enabled. However to allow for VOIP traffic both SIP and IAX ports are opened.</p>
<p>If you know that your VOIP providers and all extensions are on fixed IP addresses then it is possible to limit connections to just those addresses.</p>
<p><span id="more-1082"></span><br />
First let&#8217;s list all the VOIP traffic rules that are set up -</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">iptables -L --line-numbers<br />
<br />
Chain INPUT (policy DROP)<br />
num  target     prot opt source               destination<br />
<br />
10   ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:sip<br />
11   ACCEPT     udp  --  anywhere             anywhere            udp dpt:sip<br />
13   ACCEPT     tcp  --  anywhere             anywhere            tcp dpt:sip-tls<br />
14   ACCEPT     udp  --  anywhere             anywhere            udp dpt:sip-tls<br />
15   ACCEPT     udp  --  anywhere             anywhere            udp dpt:iax</div></div>
<p>The extract above just show&#8217;s the sip, sip-tls and iax2 rules.</p>
<p>Now let&#8217;s delete those rules. Warning! All SIP/IAX2 traffic will be blocked as soon as you run this! Note that your line numbers may be different. Make sure that you delete them in reverse number order or the numbers will change as you delete them.</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">iptables -D INPUT 15<br />
iptables -D INPUT 14<br />
iptables -D INPUT 13<br />
iptables -D INPUT 11<br />
iptables -D INPUT 10</div></div>
<p>Don&#8217;t delete this rule if you use SIP as it is what opens the high port numbers for the actual voice/media stream -</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">12 &nbsp; ACCEPT &nbsp; &nbsp; udp &nbsp;-- &nbsp;anywhere &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; anywhere &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;udp dpts:ndmp:dnp</div></div>
<p>Now, let&#8217;s assume that our SIP provider is at 1.1.1.1 and our extensions are at 2.2.2.2. Let&#8217;s allow access from those numbers for SIP.<br />
All lines are inserted at rule 10 and get shuffled up -</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">iptables -I INPUT 10 -p tcp --dport 5060 -s 1.1.1.1 -j ACCEPT<br />
iptables -I INPUT 10 -p udp --dport 5060 -s 1.1.1.1 -j ACCEPT<br />
iptables -I INPUT 10 -p tcp --dport 5060 -s 2.2.2.2 -j ACCEPT<br />
iptables -I INPUT 10 -p udp --dport 5060 -s 2.2.2.2 -j ACCEPT</div></div>
<p>Let&#8217;s check that those rules look OK (again, only listed here are the VOIP traffic rules) -</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">iptables -L --line-numbers<br />
<br />
Chain INPUT (policy DROP)<br />
num &nbsp;target &nbsp; &nbsp; prot opt source &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; destination<br />
10 &nbsp; ACCEPT &nbsp; &nbsp; tcp &nbsp;-- &nbsp;2.2.2.2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;anywhere &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tcp dpt:sip<br />
11 &nbsp; ACCEPT &nbsp; &nbsp; udp &nbsp;-- &nbsp;2.2.2.2 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;anywhere &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;udp dpt:sip<br />
12 &nbsp; ACCEPT &nbsp; &nbsp; udp &nbsp;-- &nbsp;1.1.1.1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;anywhere &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;udp dpt:sip<br />
13 &nbsp; ACCEPT &nbsp; &nbsp; tcp &nbsp;-- &nbsp;1.1.1.1 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;anywhere &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;tcp dpt:sip<br />
14 &nbsp; ACCEPT &nbsp; &nbsp; udp &nbsp;-- &nbsp;anywhere &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; anywhere &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;udp dpts:ndmp:dnp</div></div>
<p>Now test that everything is working as you expect. If it is you can save the rules so that they are loaded next time you reboot -</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">service iptables stop<br />
iptables-save &gt; /etc/sysconfig/iptables<br />
service iptables start</div></div>
<p>If you make a mistake while editing the rules then just restart iptables to restore your old rules. Note that you can only do this before you save your new rules!</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">service iptables restart<br />
Flushing firewall rules: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [ &nbsp;OK &nbsp;]<br />
Setting chains to policy ACCEPT: mangle filter nat &nbsp; &nbsp; &nbsp; &nbsp; [ &nbsp;OK &nbsp;]<br />
Unloading iptables modules: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[ &nbsp;OK &nbsp;]<br />
Applying iptables firewall rules: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;[ &nbsp;OK &nbsp;]</div></div>
]]></content:encoded>
			<wfw:commentRss>http://sysadminman.net/blog/2010/limiting-sipiax-connections-to-asterisk-with-iptables-1082/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Namecheap SSL certificate for Sysadminman VPS</title>
		<link>http://sysadminman.net/blog/2010/namecheap-ssl-certificate-for-sysadminman-vps-1062</link>
		<comments>http://sysadminman.net/blog/2010/namecheap-ssl-certificate-for-sysadminman-vps-1062#comments</comments>
		<pubDate>Sun, 21 Mar 2010 01:11:53 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[VPS]]></category>

		<guid isPermaLink="false">http://sysadminman.net/blog/?p=1062</guid>
		<description><![CDATA[A sysadminman template VPS comes already setup to use SSL (https) for web connections to a2billing and FreePBX. However, this is using a locally signed ssl certificate so you will receive a certificate warning when accessing your VPS. This is no less secure but can create a poor impression depending who will be accessing the [...]]]></description>
			<content:encoded><![CDATA[<p>A sysadminman template VPS comes already setup to use SSL (https) for web connections to a2billing and FreePBX. However, this is using a locally signed ssl certificate so you will receive a certificate warning when accessing your VPS. This is no less secure but can create a poor impression depending who will be accessing the site.</p>
<p>It&#8217;s relatively straight forward and inexpensive to get yourself a valid, externally signed, certificate.</p>
<p>The sysadminman template uses lighttpd as the web server so you need to follow these instructions -</p>
<p>Log in to your VPS as root:</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">[root@livedemo /]#</div></div>
<p><span id="more-1062"></span></p>
<p>Next create a folder to store the keys and then create the key. Make sure to replace the server name with the DNS name of your server. This must match the name that people will use to browse to your webserver/website. You will need to enter a password for the key at this point but we will remove it or it will need to be entered every time the webserver starts.</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">[root@livedemo /]# mkdir -p /etc/lighttpd/ssl<br />
[root@livedemo /]# cd /etc/lighttpd/ssl<br />
[root@livedemo ssl]#<br />
[root@livedemo ssl]# openssl genrsa -des3 -out livedemo.sysadminman.net.key 2048<br />
Generating RSA private key, 2048 bit long modulus<br />
..........++++++<br />
.......++++++<br />
e is 65537 (0x10001)<br />
Enter pass phrase for livedemo.sysadminman.net.key:<br />
Verifying - Enter pass phrase for livedemo.sysadminman.net.key:<br />
[root@livedemo ssl]#<br />
[root@livedemo ssl]# openssl rsa -in livedemo.sysadminman.net.key -out livedemo.sysadminman.net.nopass.key<br />
Enter pass phrase for livedemo.sysadminman.net.key:<br />
writing RSA key</div></div>
<p>Next generate the Certificate Signing Request (CSR). Be very careful when entering he hostname. This must match the name of your a2billing/FreePBX website. You can leave the password blank.</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">[root@livedemo ssl]# openssl req -new -key livedemo.sysadminman.net.nopass.key -out livedemo.sysadminman.net.csr<br />
You are about to be asked to enter information that will be incorporated<br />
in to your certificate request.<br />
What you are about to enter is what is called a Distinguished Name or a DN.<br />
There are quite a few fields but you can leave some blank<br />
For some fields there will be a default value,<br />
If you enter '.', the field will be left blank.<br />
-----<br />
Country Name (2 letter code) [GB]:<br />
State or Province Name (full name) [Berkshire]:Leics<br />
Locality Name (eg, city) [Newbury]:Leicester<br />
Organization Name (eg, company) [My Company Ltd]:sysadminman<br />
Organizational Unit Name (eg, section) []:<br />
Common Name (eg, your name or your server's hostname) []:livedemo.sysadminman.net<br />
Email Address []:<br />
<br />
Please enter the following 'extra' attributes<br />
to be sent with your certificate request<br />
A challenge password []:<br />
An optional company name []:</div></div>
<p>Now print the CSR and copy it</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">[root@livedemo ssl]# cat livedemo.sysadminman.net.csr<br />
-----BEGIN CERTIFICATE REQUEST-----<br />
MIIBqjCCARMCAQAwajELMAkGA1UEBhMCR0IxDjAMBgNVBAgTBUxlaWNzMRIwEAYD<br />
VQQHEwlMZWljZXN0ZXIxFDASBgNVBAoTC3N5c2FkbWlubWFuMSEwHwYDVQQDExhs<br />
aXZlZGVtby5zeXNhZG1pbm1hbi5uZXQwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJ<br />
AoGBANR0hOz7bXEwMB1jMW8j7GgnsaZGM+ySIdp1h9kZx5qh8Ma07CCmUJ3i8Anf<br />
FOWmiEx+04qxs2scaSaRgJpm499nflcm6lTzh6VwV/5hQuxwTHjN4DAPaxOB6Hrk<br />
ewjcz6KsDWv7+VnyFN3MYwqE4075Q5LtF0+4XsDmNmjvUktbAgMBAAGgADANBgkq<br />
hkiG9w0BAQUFAAOBgQDB3DbGcCSBqLDGVVRDEVOhICFKIlubKJ4S2Q2TLW2pa+j/<br />
Iqt7qcGdombxVJMk3EfVkC//5KuiA/PaZen8ViBLWwAaRlLZq2NOrWEweYMihKXb<br />
0a7CwVTMNWqji7QPjNtq4fyhKYKseZiAHpzyocVfw97zfGmk0hWjZbQfW5uwQA==<br />
-----END CERTIFICATE REQUEST-----</div></div>
<p>Now order your SSL certificate from -<a href="http://www.namecheap.com/learn/other-services/cheap-ssl-certificate-rapidssl.asp" rel="nofollow" title="Namecheap SSL certificate order"  target="_blank"> http://www.namecheap.com/learn/other-services/cheap-ssl-certificate-rapidssl.asp</a>. Select Apache + OpenSSL and paste the CSR text from earlier.</p>
<p><a href="http://sysadminman.net/blog/wp-content/uploads/2010/03/namecheap-ssl-order-form.png"><img class="alignnone size-full wp-image-1070" style="border: 1px solid black;" title="namecheap-ssl-order-form" src="http://sysadminman.net/blog/wp-content/uploads/2010/03/namecheap-ssl-order-form.png" alt="" width="781" height="533" /></a></p>
<p>Complete the order process. You will be required to accept an e-mail to a predefined address. This must be a valid address as you will receive an order confirmation e-mail which you must acknowledge.</p>
<p>You will ultimately receive a zip file containing your certificate. You want the text from the file with your server name ending in .crt.</p>
<p>Create a file on the server called yoursername.crt and paste in the contents of the crt file</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">[root@livedemo ssl]# vi livedemo.sysadminman.net.crt<br />
[root@livedemo ssl]# cat livedemo.sysadminman.net.crt<br />
-----BEGIN CERTIFICATE-----<br />
MIIEuTCCA6GgAwIBAgIQDvsV1EqjvyMdeQU5381EPDANBgkqhkiG9w0BAQUFADBx<br />
....<br />
-----END CERTIFICATE-----</div></div>
<p>Next combine the key and certificate to create a single .pem file.</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">[root@livedemo ssl]# cat livedemo.sysadminman.net.nopass.key livedemo.sysadminman.net.crt &amp;gt; livedemo.sysadminman.net.pem<br />
[root@livedemo ssl]# chmod 600 livedemo.sysadminman.net.pem</div></div>
<p>Now edit the lighttpd config file. Locate the reference to the existing .pem file and change it to your new .pem file</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">[root@livedemo ssl]# cp /etc/lighttpd/lighttpd.conf /etc/lighttpd/lighttpd.conf.backup<br />
[root@livedemo ssl]# vi /etc/lighttpd/lighttpd.conf<br />
<br />
#### SSL engine<br />
ssl.engine                 = &quot;enable&quot;<br />
ssl.pemfile                = &quot;/etc/lighttpd/ssl/livedemo.sysadminman.net.pem&quot;</div></div>
<p>Now restart lighttpd and ensure it starts backup correctly</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">[root@livedemo ssl]# service lighttpd restart<br />
Stopping lighttpd:                                         [  OK  ]<br />
Starting lighttpd:                                         [  OK  ]</div></div>
]]></content:encoded>
			<wfw:commentRss>http://sysadminman.net/blog/2010/namecheap-ssl-certificate-for-sysadminman-vps-1062/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>E-mail to voice call &#8211; with Asterisk, Postfix and Cepstral</title>
		<link>http://sysadminman.net/blog/2010/e-mail-to-voice-call-with-asterisk-postfix-and-cepstral-1010</link>
		<comments>http://sysadminman.net/blog/2010/e-mail-to-voice-call-with-asterisk-postfix-and-cepstral-1010#comments</comments>
		<pubDate>Sun, 14 Feb 2010 11:56:09 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Asterisk]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[ami]]></category>
		<category><![CDATA[asterisk]]></category>
		<category><![CDATA[asterisk manager interface]]></category>
		<category><![CDATA[cepstral]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[postfix]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[text to speech]]></category>

		<guid isPermaLink="false">http://sysadminman.net/blog/?p=1010</guid>
		<description><![CDATA[A few times recently I&#8217;ve wanted to be able to turn an e-mail into a voice call. This would be especially handy for emergency server monitoring and notification. Here is my first attempt. It&#8217;s also my first attempt at writing something in Python so you definitely use at your own risk! There is room for [...]]]></description>
			<content:encoded><![CDATA[<p>A few times recently I&#8217;ve wanted to be able to turn an e-mail into a voice call. This would be especially handy for emergency server monitoring and notification.</p>
<p>Here is my first attempt. It&#8217;s also my first attempt at writing something in Python so you definitely use at your own risk!</p>
<p>There is room for improvement as there is no validation on any of the fields extracted from the e-mail.</p>
<p>It also assumes that these components are already in place -</p>
<ul>
<li>Asterisk (with Astersk Manager Interface)</li>
<li>E-mail server (I&#8217;m using Postfix)</li>
<li>Ceptral text-to-speech (<a href="http://cepstral.com/" rel="nofollow" title="Cepstral text-to-speech"  target="_blank">www.cepstral.com</a>) &#8211; installed in /opt/swift/bin</li>
<li>Python (I&#8217;m using v2.4.3)</li>
<p><span id="more-1010"></span>
</ul>
<p>First we need to pipe the incoming e-mail to our Python script. For this I added a line to /etc/aliases -</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">emailspeak: &quot;|/usr/local/bin/emailspeak.py&quot;</div></div>
<p>and ran newaliases -</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">newaliases</div></div>
<p>Now for the script which is called &#8216;/usr/local/bin/emailspeak.py&#8217;</p>
<p>You will need to change at least the USER, SECRET and TRUNK settings at the top of the script to match you Asterisk setup.</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">#!/usr/bin/env python<br />
# emailspeak.py by sysadminman - http://sysadminman.net<br />
# v1.0 &nbsp;13/2/10<br />
<br />
# Import libs we need<br />
import sys, time, email, email.Message, email.Errors, email.Utils, smtplib, os, socket, random<br />
from datetime import date<br />
from email.Iterators import typed_subpart_iterator<br />
from time import sleep<br />
<br />
# Asterisk Manager connection details<br />
HOST = '127.0.0.1'<br />
PORT = 5038<br />
# Asterisk Manager username and password<br />
USER = 'manageruser'<br />
SECRET = 'managerpass'<br />
# Set the name of the SIP trunk to use for outbound calls<br />
TRUNK = 'trunkforcalls'<br />
<br />
# Generate a random number as a string. We'll use this for file names later on<br />
callnum = str(random.randint(1, 100000000))<br />
<br />
# Taken from here, with thanks - http://ginstrom.com/scribbles/2007/11/19/parsing-multilingual-email-with-python/<br />
def get_charset(message, default=&quot;ascii&quot;):<br />
&nbsp; &nbsp; &quot;&quot;&quot;Get the message charset&quot;&quot;&quot;<br />
<br />
&nbsp; &nbsp; if message.get_content_charset():<br />
&nbsp; &nbsp; &nbsp; &nbsp; return message.get_content_charset()<br />
<br />
&nbsp; &nbsp; if message.get_charset():<br />
&nbsp; &nbsp; &nbsp; &nbsp; return message.get_charset()<br />
<br />
&nbsp; &nbsp; return default<br />
<br />
# Taken from here, with thanks - http://ginstrom.com/scribbles/2007/11/19/parsing-multilingual-email-with-python/<br />
def get_body(message):<br />
&nbsp; &nbsp; &quot;&quot;&quot;Get the body of the email message&quot;&quot;&quot;<br />
<br />
&nbsp; &nbsp; if message.is_multipart():<br />
&nbsp; &nbsp; &nbsp; &nbsp; #get the plain text version only<br />
&nbsp; &nbsp; &nbsp; &nbsp; text_parts = [part<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for part in typed_subpart_iterator(message,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'text',<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;'plain')]<br />
&nbsp; &nbsp; &nbsp; &nbsp; body = []<br />
&nbsp; &nbsp; &nbsp; &nbsp; for part in text_parts:<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; charset = get_charset(part, get_charset(message))<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; body.append(unicode(part.get_payload(decode=True),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; charset,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &quot;replace&quot;))<br />
<br />
&nbsp; &nbsp; &nbsp; &nbsp; return u&quot;\n&quot;.join(body).strip()<br />
<br />
&nbsp; &nbsp; else: # if it is not multipart, the payload will be a string<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; # representing the message body<br />
&nbsp; &nbsp; &nbsp; &nbsp; body = unicode(message.get_payload(decode=True),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;get_charset(message),<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&quot;replace&quot;)<br />
&nbsp; &nbsp; &nbsp; &nbsp; return body.strip()<br />
<br />
# Read the e-mail message that has been piped to us by Postfix<br />
raw_msg = sys.stdin.read()<br />
emailmsg = email.message_from_string(raw_msg)<br />
<br />
# Extract database Fields from mail<br />
msgfrom = emailmsg['From']<br />
msgto = &nbsp;emailmsg['To']<br />
msgsubj = emailmsg['Subject']<br />
msgbody = get_body(emailmsg)<br />
<br />
# Write a log file in /tmp with a record of the e-mails<br />
currtime = date.today().strftime(&quot;%B %d, %Y&quot;)<br />
logfile = open('/tmp/email2voice.log', 'a')<br />
logfile.write(currtime + &quot;\n&quot;)<br />
logfile.write(&quot;Call Number: &quot; + callnum + &quot;\n&quot;)<br />
logfile.write(&quot;From: &quot; + msgfrom + &quot;\n&quot;)<br />
logfile.write(&quot;To: &quot; + msgto + &quot;\n&quot;)<br />
logfile.write(&quot;Subject: &quot; + msgsubj + &quot;\n&quot;)<br />
logfile.write(&quot;Body: &quot; + msgbody + &quot;\n\n&quot;)<br />
logfile.close()<br />
<br />
# Convert the body of the text to a wav file<br />
swiftcommand = &quot;/opt/swift/bin/swift -n Millie-8kHz -o /tmp/&quot; + callnum + &quot;.wav '&quot; + msgbody + &quot;'&quot;<br />
os.system(swiftcommand)<br />
<br />
# We need to allow Asterisk permission to read the wav file<br />
chmodcommand = &quot;chmod 777 /tmp/&quot; + callnum + &quot;.wav&quot;<br />
os.system(chmodcommand)<br />
<br />
# Set the number to be dailed as the subject of the e-mail<br />
OUTBOUND = msgsubj<br />
<br />
# Send the call details to the Asteirsk Manager Interface<br />
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)<br />
s.connect((HOST, PORT))<br />
sleep(3)<br />
s.send('Action: login\r\n')<br />
s.send('Username: ' + USER + '\r\n')<br />
s.send('Secret: ' + SECRET + '\r\n\r\n')<br />
sleep(3)<br />
s.send('Events: off\r\n\r\n')<br />
sleep(3)<br />
s.send('Action: originate\r\n')<br />
s.send('Channel: Sip/' + TRUNK + '/' + OUTBOUND + '\r\n')<br />
s.send('WaitTime: 30\r\n')<br />
s.send('CallerId: 1234\r\n')<br />
s.send('Application: playback\r\n')<br />
s.send('Data: /tmp/' + callnum + '\r\n')<br />
s.send('Context: from-internal\r\n')<br />
s.send('Async: true\r\n')<br />
s.send('Priority: 1\r\n\r\n')<br />
sleep(3)<br />
s.send('Action: Logoff\r\n\r\n')<br />
s.close()</div></div>
<p>And that should be it. To test just send an e-mail to emailspeak@yourserver.com with the telephone number you want to call as the subject line, and the text you want to be read in the body.</p>
<p>Don&#8217;t forget to write the telephone number in the format that your SIP provider is expecting it.</p>
]]></content:encoded>
			<wfw:commentRss>http://sysadminman.net/blog/2010/e-mail-to-voice-call-with-asterisk-postfix-and-cepstral-1010/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
		<item>
		<title>Hacking and securing your Asterisk server</title>
		<link>http://sysadminman.net/blog/2009/hacking-and-securing-your-asterisk-server-592</link>
		<comments>http://sysadminman.net/blog/2009/hacking-and-securing-your-asterisk-server-592#comments</comments>
		<pubDate>Sun, 12 Apr 2009 18:09:59 +0000</pubDate>
		<dc:creator>matt</dc:creator>
				<category><![CDATA[Asterisk]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[asterisk]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[sip]]></category>
		<category><![CDATA[sipvicious]]></category>

		<guid isPermaLink="false">http://sysadminman.net/blog/?p=592</guid>
		<description><![CDATA[I spent a little while playing with sipvicious today. This is a SIP scanner that can be used for scanning SIP servers &#8211; which obviousy includes Asterisk, Trixbox, Elastix, etc&#8230; It&#8217;s not surpising that scanning for vulnerable SIP servers is on the increase &#8211; these sort of tools are really easy to use, and with [...]]]></description>
			<content:encoded><![CDATA[<p>I spent a little while playing with <a href="http://sipvicious.org/blog/" rel="nofollow" title="sipvivious sip scanner"  target="_blank">sipvicious</a> today. This is a SIP scanner that can be used for scanning SIP servers &#8211; which obviousy includes Asterisk, Trixbox, Elastix, etc&#8230;</p>
<p>It&#8217;s not surpising that scanning for vulnerable SIP servers is on the increase &#8211; these sort of tools are really easy to use, and with the lure of making free phone calls at your expense it&#8217;s definitnely worth making sure that your PBX is secure.</p>
<p>Here&#8217;s what I did to scan one of my servers. The server is a Trixbox CE 2.6 server and I set up the following extensions for testing -</p>
<p><span id="more-592"></span></p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">Ext - 1001 : Display Name - 1001 : Secret - Empty<br />
Ext - 1002 : Display Name - 1002 :  Secret - 1002<br />
Ext - 1003 : Display Name - &quot;test&quot; : Secret - &quot;ekwrbq2k3b4lk32b&quot;</div></div>
<p>Next I downloaded Sipvicious -</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">cd /tmp<br />
wget http://sipvicious.googlecode.com/files/sipvicious-0.2.4.tar.gz<br />
tar xvfz sipvicious-0.2.4.tar.gz<br />
cd sipvicious-0.2.4</div></div>
<p>Now, first we need to find the Asterisk server we want to scan and for that we use svmap.py. I obviously know the name of my server but svmap.py will also scan blocks of IP addresses too.</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">./svmap.py asteriskdemo<br />
<br />
| SIP Device &nbsp; &nbsp; &nbsp; &nbsp;| User Agent &nbsp; | Fingerprint &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|<br />
-----------------------------------------------------------------------------<br />
| asteriskdemo:5060 | Asterisk PBX | Asterisk / SJphone/1.60.289a (SJ Labs) |</div></div>
<p>So all I had to do was give it the hostname/ip address of my Asterisk servers and svmap has successfully identified it.</p>
<p>Next we want to see what externsions are configured on the server so we use svwar.py</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">./svwar.py -e 1000-9999 asteriskdemo<br />
<br />
| Extension | Authentication |<br />
------------------------------<br />
| 1003      | reqauth        |<br />
| 1002      | reqauth        |<br />
| 1001      | noauth         |</div></div>
<p>The &#8220;-e 1000-9999&#8243; tells svwar to scan for all extensions between those numbers. As you can see it returns the test extensions I configured and also tells us that extension 1001 doesn&#8217;t need a password to connect to it. So potentially, as a hacker, I could already connect as this extension and start making calls.</p>
<p>Now let&#8217;s see if there&#8217;s any other vulnerable extenions with svcrack.py -</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">./svcrack.py -u1002 -r1-9999 asteriskdemo<br />
<br />
| Extension | Password |<br />
------------------------<br />
| 1002      | 1002     |</div></div>
<p>The &#8220;-u 1002&#8243; tells svcrack which extension to try and guess the password for and &#8220;-r1-9999&#8243; tells it to use that as a range for potential passwords. It took about 3 seconds to try all the numbers between 1 and 9999 and guess the password. It&#8217;s definitely not a good idea just to use numbers for your passwords!</p>
<p>It&#8217;s also possible to download dictionary files (just long lists of words) and tell sipvicious to use those as potential passwords. This obviously takes longer to run.</p>
<p>So, what can we do to protect ourselves?</p>
<p>There are a few really simple things that can make our Asterisk servers much more secure.</p>
<p>Always use long, difficult to guess passwords for your extensions!</p>
<p>Set &#8220;alwaysauthreject=yes&#8221; in your sip configuration file. What this does is prevent Asterisk from telling a sip scanner which are valid extension numbers. Here&#8217;s what happened when I changed the setting on my Trixbox -</p>
<p>I edited the file /etc/asterisk/sip_custom.conf and entered the line</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">alwaysauthreject=yes</div></div>
<p>Then reloaded SIP in Asterisk with -</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">asterisk -rv<br />
sip reload<br />
exit</div></div>
<p>Now if I run the same command as before to see what valid extension numbers there are I get the following error -</p>
<div class="codecolorer-container text twitlight notranslate" style="overflow:auto;white-space:nowrap;border:1px solid #9F9F9F;width:435px;"><div class="text codecolorer" style="padding:5px;font:normal 12px/1.4em Monaco, Lucida Console, monospace;white-space:nowrap">./svwar.py -e 1000-9999 asteriskdemo<br />
<br />
ERROR:TakeASip:SIP server replied with an authentication request for an unknown extension. Set --force to force a scan.<br />
WARNING:root:found nothing</div></div>
<p>There are other things you can do and there is a great article here &#8211; <a href="http://blogs.digium.com/2009/03/28/sip-security/" rel="nofollow" title="Asterisk security"  target="_blank">http://blogs.digium.com/2009/03/28/sip-security/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://sysadminman.net/blog/2009/hacking-and-securing-your-asterisk-server-592/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	<p class="updated" itemscope itemtype="http://schema.org/WebPage" itemid="http://sysadminman.net/blog/2009/hacking-and-securing-your-asterisk-server-592">Last updated by <span style="float:none" class="author vcard"><span class="fn"><a rel="author" href="http://sysadminman.net/blog/author/matt/" class="authorsure-author-link">matt</a></span></span>.</p></channel>
</rss>

