<?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/"
	
	xmlns:georss="http://www.georss.org/georss"
	xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#"
	>

<channel>
	<title>Security - Ryan Daniels</title>
	<atom:link href="https://ryandaniels.ca/blog/category/security/feed/" rel="self" type="application/rss+xml" />
	<link>https://ryandaniels.ca/blog/category/security/</link>
	<description></description>
	<lastBuildDate>Tue, 25 Jan 2022 04:20:53 +0000</lastBuildDate>
	<language>en-CA</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://ryandaniels.ca/wp-content/uploads/2019/07/img_5907-small-blur-square-100x100.jpg</url>
	<title>Security - Ryan Daniels</title>
	<link>https://ryandaniels.ca/blog/category/security/</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">22628916</site>	<item>
		<title>Firefox, I love you but you&#8217;re bringing me down</title>
		<link>https://ryandaniels.ca/blog/firefox-i-love-you-but-youre-bringing-me-down/</link>
		
		<dc:creator><![CDATA[Ryan Daniels]]></dc:creator>
		<pubDate>Tue, 25 Jan 2022 00:56:00 +0000</pubDate>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Firefox]]></category>
		<guid isPermaLink="false">https://ryandaniels.ca/?p=2604</guid>

					<description><![CDATA[<figure class="alignleft size-full is-resized"><img src="https://ryandaniels.ca/wp-content/uploads/2022/01/Firefox_Logo-2021-256.png" alt="" class="wp-image-2780" width="150" height="150"/></figure>
<p>I love Firefox. I'm a Firefox user, and hopefully always will be. Firefox is better than any other browser (plus it's free and open-source). However, there have been a few technical things that I don't like.</p>
<p>The post <a href="https://ryandaniels.ca/blog/firefox-i-love-you-but-youre-bringing-me-down/">Firefox, I love you but you&#8217;re bringing me down</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<div class="wp-block-image"><figure class="alignright size-full"><img fetchpriority="high" decoding="async" width="256" height="256" src="https://ryandaniels.ca/wp-content/uploads/2022/01/Firefox_Logo-2021-256.png" alt="Firefox, I love you but you're bringing me down" class="wp-image-2780"/></figure></div>



<p>I love Firefox. I&#8217;m a Firefox user, and hopefully always will be. Firefox is better than any other browser (plus it&#8217;s <a href="https://en.wikipedia.org/wiki/Firefox" target="_blank" rel="noreferrer noopener">free and open-source</a>). However, there have been a few technical things that I don&#8217;t like.</p>



<span id="more-2604"></span>



<ul class="wp-block-list"><li>Endless promotion of Mozilla VPN</li><li>Firefox DNS over HTTPS silently fails</li><li>Compact Toolbar Density not supported</li></ul>



<p>Queue track: <a href="https://www.youtube.com/watch?v=c5kM3iwYVi0" target="_blank" rel="noreferrer noopener">LCD Soundsystem &#8211; New York, I Love You but You&#8217;re Bringing Me Down</a></p>



<p>But, since Firefox can be customized, you can change these settings to what you like.</p>


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-55ed902e      "
					data-scroll= ""
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
													</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#mozilla-vpn-please-stop-bothering-me" class="uagb-toc-link__trigger">Mozilla VPN &#8211; Please stop bothering me</a><li class="uagb-toc__list"><a href="#firefox-dns-over-https-silently-fails-open" class="uagb-toc-link__trigger">Firefox DNS over HTTPS silently fails open</a><li class="uagb-toc__list"><a href="#compact-toolbar-density-option-missing" class="uagb-toc-link__trigger">Compact Toolbar Density option missing</a><li class="uagb-toc__list"><a href="#conclusion" class="uagb-toc-link__trigger">Conclusion</a></ol>					</div>
									</div>
				</div>
			


<h2 class="wp-block-heading" id="mozilla-vpn-please-stop-bothering-me">Mozilla VPN &#8211; Please stop bothering me</h2>



<p>Since Firefox 93, <a href="https://vpn.mozilla.org/" target="_blank" rel="noreferrer noopener">Mozilla VPN</a> promotions won&#8217;t go away. I understand Mozilla needs to make money. But I don&#8217;t want to constantly see this ad. I get it, you offer a VPN service. Unfortunately, there isn&#8217;t an easy way to hide the ads for their VPN. There isn&#8217;t even a documented way for the &#8220;user.js&#8221; settings, however I figured out a way to hide them when opening a new &#8220;Private&#8221; browsing window. This works in Firefox 94 to current (Firefox 96), and hopefully keeps working!</p>



<p>Update the <a href="https://ryandaniels.ca/blog/firefox-privacy-settings-made-easy/#how-to-automatically-change-firefox-settings">Firefox user.js</a> settings to fix this:</p>



<pre class="wp-block-code"><code>// FF94
user_pref("browser.privatebrowsing.vpnpromourl", "");</code></pre>



<p>Before and after:</p>



<figure class="wp-block-gallery has-nested-images columns-default wp-block-gallery-1 is-layout-flex wp-block-gallery-is-layout-flex">
<figure class="wp-block-image size-large"><a href="https://ryandaniels.ca/wp-content/uploads/2022/01/Firefox_private_window_vpn_ad.png" rel="lightbox[2604]"><img decoding="async" width="768" height="630" data-id="2752" src="https://ryandaniels.ca/wp-content/uploads/2022/01/Firefox_private_window_vpn_ad.png" alt="Firefox VPN ad" class="wp-image-2752" srcset="https://ryandaniels.ca/wp-content/uploads/2022/01/Firefox_private_window_vpn_ad.png 768w, https://ryandaniels.ca/wp-content/uploads/2022/01/Firefox_private_window_vpn_ad-731x600.png 731w, https://ryandaniels.ca/wp-content/uploads/2022/01/Firefox_private_window_vpn_ad-300x246.png 300w" sizes="(max-width: 768px) 100vw, 768px" /></a></figure>



<figure class="wp-block-image size-large"><a href="https://ryandaniels.ca/wp-content/uploads/2022/01/Firefox_private_window_vpn_ad-gone.png" rel="lightbox[2604]"><img decoding="async" width="768" height="385" data-id="2753" src="https://ryandaniels.ca/wp-content/uploads/2022/01/Firefox_private_window_vpn_ad-gone.png" alt="Firefox VPN ad removed" class="wp-image-2753" srcset="https://ryandaniels.ca/wp-content/uploads/2022/01/Firefox_private_window_vpn_ad-gone.png 768w, https://ryandaniels.ca/wp-content/uploads/2022/01/Firefox_private_window_vpn_ad-gone-300x150.png 300w" sizes="(max-width: 768px) 100vw, 768px" /></a></figure>
</figure>



<h2 class="wp-block-heading" id="firefox-dns-over-https-silently-fails-open">Firefox DNS over HTTPS silently fails open</h2>



<p>Firefox has a built-in option for <a href="https://en.wikipedia.org/wiki/DNS_over_HTTPS" target="_blank" rel="noreferrer noopener">DNS over HTTPS</a> (DOH). It&#8217;s great that you can set this up and add another layer of security from prying eyes. This actually isn&#8217;t a new thing, it has been around since Firefox 62.</p>



<p>However, I recently found out that it fails open by default with no warning.</p>



<p>What does this mean?<br>If the DNS over HTTPS server you pick stops working, Firefox silently fails to use DNS over HTTPS and uses your system&#8217;s default DNS settings instead. And there is no warning when this happens.</p>



<p>They say, a false sense of security is worse than no security at all. You thought you were more secure with DNS over HTTPS.</p>



<p>Read more about the option from: <br><a href="https://support.mozilla.org/en-US/kb/connection-settings-firefox" target="_blank" rel="noreferrer noopener">Connection settings in Firefox</a><br><a href="https://support.mozilla.org/en-US/kb/firefox-dns-over-https" target="_blank" rel="noreferrer noopener">Firefox about DNS-over-HTTPS</a></p>



<p id="block-4bd57f8a-e494-498d-bab3-6fe636aa0de2">And also read the <a href="https://wiki.mozilla.org/Trusted_Recursive_Resolver" target="_blank" rel="noreferrer noopener">Trusted Recursive Resolver</a> wiki page carefully about the different options.</p>



<p>You can fix this by changing the setting for &#8220;network.trr.mode&#8221; to 3, which will force Firefox to only use the resolver you specify for DOH and if it fails, then Firefox won&#8217;t use the system&#8217;s DNS.</p>



<p>In the <a href="https://ryandaniels.ca/blog/firefox-privacy-settings-made-easy/#how-to-automatically-change-firefox-settings">Firefox user.js</a> settings file add:</p>



<pre class="wp-block-code"><code>//trr.mode 5 is no DOH. 2 is enable DOH. 3 is no failback to system dns
user_pref("network.trr.mode", 3);
user_pref("network.trr.default_provider_uri", "https://dns.quad9.net/dns-query");
user_pref("network.trr.uri", "https://dns.quad9.net/dns-query");
user_pref("network.trr.custom_uri", "https://dns.quad9.net/dns-query");
user_pref("network.trr.bootstrapAddress", "9.9.9.9");</code></pre>



<p>The above also sets the DOH resolver to <a href="https://www.quad9.net/" target="_blank" rel="noreferrer noopener">Quad9</a>.</p>



<p id="block-4bd57f8a-e494-498d-bab3-6fe636aa0de2">Also note:<br>When you change the setting (URL or Disable/Enable) in the Firefox Settings, it will reset &#8220;network.trr.mode&#8221; to 2 so you need to change this again!</p>



<h2 class="wp-block-heading" id="compact-toolbar-density-option-missing">Compact Toolbar Density option missing</h2>



<p>I like the &#8220;Compact&#8221; Toolbar Density option because I don&#8217;t want a huge waste of space at the top of my Firefox window. I want to be able to optimize for these wide monitors we have, so vertical space is at a premium! Since Firefox 89 this <a href="https://support.mozilla.org/en-US/kb/compact-mode-workaround-firefox" target="_blank" rel="noreferrer noopener">has been hidden behind a configuration setting</a>.</p>



<p>With this setting in the <a href="https://ryandaniels.ca/blog/firefox-privacy-settings-made-easy/#how-to-automatically-change-firefox-settings">user.js</a> you now have the Compact option again in Firefox:</p>



<pre class="wp-block-code"><code>// FF89
// Compact mode workaround in Firefox
// https://support.mozilla.org/en-US/kb/compact-mode-workaround-firefox
user_pref("browser.compactmode.show", true); // &#91;DEFAULT: false]</code></pre>



<h2 class="wp-block-heading" id="conclusion">Conclusion</h2>



<p>Firefox is my browser of choice, and it is free and open-source. Its ability for customization means you can change it to your liking too. So these technical issues will (hopefully) always have a work-around.</p>
<p>The post <a href="https://ryandaniels.ca/blog/firefox-i-love-you-but-youre-bringing-me-down/">Firefox, I love you but you&#8217;re bringing me down</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2604</post-id>	</item>
		<item>
		<title>Secure Docker with iptables firewall and Ansible</title>
		<link>https://ryandaniels.ca/blog/secure-docker-with-iptables-firewall-and-ansible/</link>
		
		<dc:creator><![CDATA[Ryan Daniels]]></dc:creator>
		<pubDate>Sun, 24 May 2020 19:11:41 +0000</pubDate>
				<category><![CDATA[Ansible]]></category>
		<category><![CDATA[Docker]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[CentOS]]></category>
		<category><![CDATA[Guide]]></category>
		<category><![CDATA[IT Automation]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<guid isPermaLink="false">https://ryandaniels.ca/?p=2290</guid>

					<description><![CDATA[<figure class="alignleft wp-block-image size-thumbnail"><img src="https://ryandaniels.ca/wp-content/uploads/2020/05/punch_hole_eye-200x300.jpg" alt="" class="wp-image-2489"/></figure>
<p>Out of the box, security with Docker (and Docker Swarm) over the network is bad. Okay, that's not entirely true. Out of the box when you have no containers started, it's fine. But after you start a container, and if you publish a port, they are exposed to the outside world by default. And it's not easy to fix. You need to create a custom Docker firewall with iptables.<br />
&#160;</p>
<p>The post <a href="https://ryandaniels.ca/blog/secure-docker-with-iptables-firewall-and-ansible/">Secure Docker with iptables firewall and Ansible</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<p>Out of the box, security with Docker (and Docker Swarm) over the network is bad. Okay, that&#8217;s not entirely true. Out of the box when you have no containers started, it&#8217;s fine. But after you start a container, and if you publish a port, they are exposed to the outside world by default. And it&#8217;s not easy to fix. You need to create a custom Docker firewall with iptables.</p>



<p>Let&#8217;s discuss the background of firewall issues with Docker, and a working solution for my use case (either setup manually or using Ansible). By the end we will use a firewall on the server to lock down everything by default, only allowing my trusted IPs! With the option to open specified ports publicly (like SSH).</p>



<p>Note: This solution works with CentOS 7, RHEL 7, Ubuntu 18.04, and Ubuntu 20.04.</p>



<span id="more-2290"></span>


				<div class="wp-block-uagb-table-of-contents uagb-toc__align-left uagb-toc__columns-1  uagb-block-5708b17e-d0f5-4528-8221-706c39a8a865      "
					data-scroll= ""
					data-offset= "30"
					style=""
				>
				<div class="uagb-toc__wrap">
						<div class="uagb-toc__title">
							Table Of Contents						</div>
																						<div class="uagb-toc__list-wrap ">
						<ol class="uagb-toc__list"><li class="uagb-toc__list"><a href="#background" class="uagb-toc-link__trigger">Background</a><li class="uagb-toc__list"><a href="#roll-your-own-solution" class="uagb-toc-link__trigger">Roll your own solution</a><li class="uagb-toc__list"><a href="#problems-i-need-to-solve" class="uagb-toc-link__trigger">Problems I need to solve</a><li class="uagb-toc__list"><a href="#solution-docker-firewall-with-iptables-and-ipset" class="uagb-toc-link__trigger">Solution &#8211; Docker firewall with iptables and ipset</a><ul class="uagb-toc__list"><li class="uagb-toc__list"><a href="#high-level-summary" class="uagb-toc-link__trigger">High level summary</a></li></ul></li><li class="uagb-toc__list"><a href="#warnings" class="uagb-toc-link__trigger">Warnings</a><li class="uagb-toc__list"><a href="#the-manual-way" class="uagb-toc-link__trigger">The manual way</a><ul class="uagb-toc__list"><li class="uagb-toc__list"><a href="#prep" class="uagb-toc-link__trigger">Prep</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#configure-ipset" class="uagb-toc-link__trigger">Configure ipset</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#configure-iptables" class="uagb-toc-link__trigger">Configure iptables</a></li></ul></li></ul></li><li class="uagb-toc__list"><a href="#the-automatic-way-with-ansible" class="uagb-toc-link__trigger">The Automatic way with Ansible</a><li class="uagb-toc__list"><a href="#conclusion" class="uagb-toc-link__trigger">Conclusion</a><li class="uagb-toc__list"><a href="#references" class="uagb-toc-link__trigger">References</a><ul class="uagb-toc__list"><li class="uagb-toc__list"><a href="#background-for-dockers-undocumented-use-of-iptables-input-chain" class="uagb-toc-link__trigger">Background for Docker&#039;s undocumented use of iptables INPUT chain</a><li class="uagb-toc__list"><li class="uagb-toc__list"><a href="#references-and-links" class="uagb-toc-link__trigger">References and links</a></ul></ul></ul></ol>					</div>
									</div>
				</div>
			


<h2 class="wp-block-heading">Background</h2>



<div class="wp-block-image"><figure class="alignright size-medium"><img loading="lazy" decoding="async" width="400" height="600" src="https://ryandaniels.ca/wp-content/uploads/2020/05/punch_hole_eye-400x600.jpg" alt="Docker punches a hole through firewall" class="wp-image-2489" srcset="https://ryandaniels.ca/wp-content/uploads/2020/05/punch_hole_eye-400x600.jpg 400w, https://ryandaniels.ca/wp-content/uploads/2020/05/punch_hole_eye-480x720.jpg 480w, https://ryandaniels.ca/wp-content/uploads/2020/05/punch_hole_eye-200x300.jpg 200w, https://ryandaniels.ca/wp-content/uploads/2020/05/punch_hole_eye.jpg 533w" sizes="auto, (max-width: 400px) 100vw, 400px" /><figcaption><sup>Image credit: <a rel="noreferrer noopener" href="https://www.pexels.com/photo/brown-human-eye-2873058/" target="_blank">Jonathan Borba</a></sup></figcaption></figure></div>



<p>Firstly, even if you were using a firewall like iptables, Docker makes that useless. Docker punches a whole right through your firewall!</p>



<p>And if you <a href="https://ryandaniels.ca/blog/ansible-manage-firewalld/">try another firewall, like firewalld</a>? Docker Swarm (and even regular Docker) with firewalld is a complete mess. Restart the firewalld service, or change the firewalld config, and you lost all the config that Docker needed. Now you have to restart Docker! What happens if the firewalld service failed and restarted? That Docker Swarm node is out of service.</p>



<p>Keep in mind, when I mention Docker, it means the regular Docker Engine. Docker Swarm means SwarmKit, which is the newer way of using Swarm. (The old way is the standalone solution which is old and not referenced at all here).</p>



<p>There are many attempts to solve this problem by users of Docker. Unfortunately the Docker team has been pretty quiet about these issues. They recommend a manual user solution, and to disable Docker&#8217;s use of iptables. I&#8217;m speculating here, but it seems like any future change from Docker will likely be a breaking change since this is a complicated issue to fix.</p>



<p>The attempted solutions (from users) are not very straight forward for a normal Docker user. And that&#8217;s the real issue. On top of that, out of the box (after you start one service with a published port), there is no security at the network layer. Anyone can connect to an exposed container&#8217;s port. Most importantly, even if you think you have a firewall protecting you.. Wrong, you don&#8217;t! With normal Docker, you can bind your service to your localhost which helps. But what about Docker Swarm? Nope, that doesn&#8217;t work.</p>



<p>There&#8217;s a great article about &#8220;<a rel="noreferrer noopener" href="https://utcc.utoronto.ca/~cks/space/blog/tech/SecurityChoiceProblem" data-type="URL" data-id="https://utcc.utoronto.ca/~cks/space/blog/tech/SecurityChoiceProblem" target="_blank">The problem of forcing users to make choices (in security)</a>.&#8221; Definitely worth the read!</p>



<h2 class="wp-block-heading">Roll your own solution</h2>



<p>Until this is actually addressed in Docker, our only hope is to find the simplest solution possible. And turning off iptables integration in Docker is unacceptable (which is constantly recommended by the Docker developers). The other option is to move on from Docker and/or Docker Swarm. I hear this thing called Kubernetes is pretty great. Anyways, back to Docker. <br>Many people have spent hours trying to learn, and figure out iptables as a solution to this. You need to roll your own solution apparently! So iptables is probably the best approach, since that is what Docker needs to use to do it&#8217;s magic (and most other firewalls are just a wrapper for iptables anyway depending on your OS).</p>



<p>Something <s>fun</s> I found out while testing this, <a href="https://ryandaniels.ca/blog/docker-iptables-input-chain/">Docker Swarm uses iptables in an undocumented way</a>. Docker Swarm uses the iptables INPUT chain! It&#8217;s only for encrypted overlay networks. But it&#8217;s not very fun realizing that! All of a sudden rules are being appended to the INPUT chain.</p>



<p>Okay, enough backstory. On with my futile attempt to roll my own solution. This took way longer than I thought it would! But it does work! Currently it works at least.. (That&#8217;s why I use the word futile!)</p>



<h2 class="wp-block-heading">Problems I need to solve</h2>



<ol class="wp-block-list"><li>Only allow traffic from multiple &#8220;trusted&#8221; IP addresses to my servers. Not all of these IPs will be in the same &#8220;IP block/range&#8221; either. This will be to all services running directly on the server, and also all of the Docker containers.</li><li>Let only specific ports be publicly accessible, like SSH.</li><li>I&#8217;m not managing which containers are accessible through the firewall. Meaning, I&#8217;m not manually adding ports into my firewall solution. That kind of manual work is not happening. I need a dynamic, and flexible solution that blocks by default except to my trusted IPs.</li><li>The firewall solution must be simple. More complex means more room for error.</li><li>The firewall solution must not impact performance significantly.</li><li>Restarting the firewall won&#8217;t break Docker. </li><li>Restarting Docker won&#8217;t break the firewall.</li><li>No impact to running server processes or Docker services when making a change. Things need to keep working! <br>Firewall changes need to happen online and not impact Docker. Meaning I can&#8217;t be restarting Docker because I made a firewall change.<br>Docker &#8220;changes&#8221; need to happen online. Meaning I can&#8217;t be restarting the firewall because I made a Docker change. (A Docker &#8220;change&#8221; means starting/stopping a container).</li></ol>



<p>That sounds very simple! Unfortunately, it is not with Docker (and Docker Swarm).</p>



<h2 class="wp-block-heading">Solution &#8211; Docker firewall with iptables and ipset</h2>



<p>If you don&#8217;t know much about iptables, or ipset, that&#8217;s okay. You don&#8217;t really need to know. You should have some basic understandings though, so you don&#8217;t break your servers! The <a rel="noreferrer noopener" href="https://wiki.archlinux.org/index.php/Iptables#Chains" target="_blank">Arch Linux wiki</a> has great information about iptables. Including this helpful <a rel="noreferrer noopener" href="https://www.frozentux.net/iptables-tutorial/chunkyhtml/images/tables_traverse.jpg" target="_blank" rel="lightbox[2290]">visual</a> about the iptables flow.</p>



<p>Note: This solution works with CentOS 7, RHEL 7, Ubuntu 18.04, and Ubuntu 20.04.</p>



<h3 class="wp-block-heading">High level summary</h3>



<p>iptables with ipset will handle all of this for us. And keep our servers, and Docker locked down from the network level. </p>



<p>In this solution, we will use the iptables INPUT chain to jump to another chain (let&#8217;s call our custom chain FILTERS), but return if there&#8217;s some legitimate looking traffic, so the Swarm overlay can do whatever it wants in INPUT with IPSEC, or whatever it is appending to INPUT.<br>Inside our custom chain FILTERS, we drop everything that doesn&#8217;t match our trusted list of IPs. We also allow our SSH port and the basic default iptables stuff.. You can also add any OS port to be publicly accessible.<br>The DOCKER-USER chain only needs a few entries. Any internal Docker traffic is returned, and it will drop any other traffic that&#8217;s not in our allowed IP list. You can also add any container port to be publicly accessible.</p>



<p>One of the dangers with this approach is if Docker changes it&#8217;s behaviour our firewall could break, or our Docker services could stop working. Since Docker doesn&#8217;t offer any solution for their users, we need our own solution. So keep in mind that you need to test this when upgrading to a new version of Docker. That is the trade-off with a &#8220;roll your own&#8221; solution. But what choice do we have?</p>



<p>I&#8217;ve created an <a rel="noreferrer noopener" href="https://galaxy.ansible.com/ryandaniels/iptables_docker" target="_blank">Ansible Role: iptables for Docker</a>, on <a rel="noreferrer noopener" href="https://github.com/ryandaniels/ansible-role-iptables-docker" target="_blank">GitHub</a> and <a rel="noreferrer noopener" href="https://galaxy.ansible.com/ryandaniels/iptables_docker" target="_blank">Ansible Galaxy</a>.</p>



<h2 class="wp-block-heading">Warnings</h2>



<p><strong>Warning: Be sure you have everything needed in your configuration. Once the iptables firewall is started it blocks anything that wasn’t added! Don&#8217;t lock yourself out of your server. Be sure to have another way to connect, like a console.</strong></p>



<p><strong>Disclaimer: Keep in mind, you should test all of this in your lab or staging environments. I can’t guarantee this will be 100% safe and can’t be held responsible for anything going wrong!</strong></p>



<p><strong>SELinux Bug</strong>: If using SELinux, currently there&#8217;s a bug with SELinux which prevents saving the iptables rules to the iptables.save file.<br><strong>Impact</strong>: Saving the iptables rules a 2nd time will silently fail. Workaround has been added so SELinux allows chmod to interact with the iptables.save file. <a rel="noreferrer noopener" href="https://github.com/ryandaniels/ansible-role-iptables-docker/blob/master/README.md#selinux-manual-workaround-for-iptables-and-chmod" target="_blank">See notes on GitHub for SELinux workaround steps</a>. Alternatively you could disable SELinux, but that&#8217;s not recommended. Bug report: <a rel="noreferrer noopener" href="https://bugs.centos.org/view.php?id=12648" target="_blank">https://bugs.centos.org/view.php?id=12648</a></p>



<h2 class="wp-block-heading">The manual way</h2>



<p>Run the commands below. These commands are only for CentOS/RHEL 7. If you don&#8217;t want to do this manually, jump to the <a href="#the-automatic-way-with-ansible">Automatic section, using Ansible</a> (which also works with Ubuntu).</p>



<h3 class="wp-block-heading">Prep</h3>



<p>Make note of what you already have in iptables (if you are already using it). Be sure you have some background with iptables, since you could break things!</p>



<pre class="wp-block-code"><code># iptables -nvL --line-numbers</code></pre>



<p>Install the required packages for CentOS / RHEL:</p>



<pre class="wp-block-code"><code># yum install iptables iptables-services ipset ipset-service</code></pre>



<h3 class="wp-block-heading">Configure ipset</h3>



<p>ipset allows you to add a list of IPs that you can use with iptables. In our case, we will add a list of IPs we want to be able to connect to our servers.</p>



<p>Configure ipset with a setname of <code>ip_allow</code>.<br>Add IPs you want to allow. Change the IPs below to your actual trusted/allowed IP ranges. Be sure to include your Docker server IPs here, because if you don&#8217;t they can&#8217;t communicate with eachother:</p>



<pre class="wp-block-code"><code># mkdir -p /etc/sysconfig/ipset.d
# vi /etc/sysconfig/ipset.d/ip_allow.set

create -exist ip_allow hash:ip family inet hashsize 1024 maxelem 65536
add ip_allow 192.168.1.123
add ip_allow 192.168.100.0/24
add ip_allow 192.168.101.0/24
add ip_allow 192.168.102.0/24</code></pre>



<p>Start, and Enable the ipset service:</p>



<pre class="wp-block-code"><code># systemctl status ipset
# systemctl start ipset
# systemctl enable ipset</code></pre>



<p>See what ipset has in it&#8217;s loaded configuration:</p>



<pre class="wp-block-code"><code># ipset list | head</code></pre>



<p>Important: Make note of the size of &#8220;Number of entries&#8221;. If that number is close to the maxelem size (65536), then you need to delete the ipset and re-create it with a larger max size. If you only use a few IP ranges like above, you don&#8217;t need to worry and will be well below the limit.</p>



<h3 class="wp-block-heading">Configure iptables</h3>



<p>Next up, iptables. iptables is our solution for a firewall. We will create a file with our rules and then add those rules into iptables. The important part is to not flush the existing rules if you are already using Docker  (or Docker Swarm) on your server.</p>



<p>Create an iptables file to use with iptables-restore, to add the rules into iptables:</p>



<pre class="wp-block-code"><code># vi iptables-rules.txt</code></pre>



<p>Add below to the file. There is a lot going on here..</p>



<pre class="wp-block-code"><code>*filter
:DOCKER-USER - &#91;0:0]
:FILTERS - &#91;0:0]
#Can't flush INPUT. wipes out docker swarm encrypted overlay rules
#-F INPUT
#Use ansible or run manually once instead to add -I INPUT -j FILTERS
#-I INPUT -j FILTERS
-F DOCKER-USER
-A DOCKER-USER -m state --state RELATED,ESTABLISHED -j RETURN
-A DOCKER-USER -i docker_gwbridge -j RETURN
-A DOCKER-USER -s 172.18.0.0/16 -j RETURN
-A DOCKER-USER -i docker0 -j RETURN
-A DOCKER-USER -s 172.17.0.0/16 -j RETURN
#Below Docker ports open to everyone if uncommented
#-A DOCKER-USER -p tcp -m tcp -m multiport --dports 8000,8001 -j RETURN
#-A DOCKER-USER -p udp -m udp -m multiport --dports 9000,9001 -j RETURN
-A DOCKER-USER -m set ! --match-set ip_allow src -j DROP
-A DOCKER-USER -j RETURN
-F FILTERS
#Because Docker Swarm encrypted overlay network just appends rules to INPUT. Has to be at top unfortunately
-A FILTERS -p udp -m policy --dir in --pol ipsec -m udp -m set --match-set ip_allow src --dport 4789 -j RETURN
-A FILTERS -m state --state RELATED,ESTABLISHED -j ACCEPT
-A FILTERS -p icmp -j ACCEPT
-A FILTERS -i lo -j ACCEPT
#Below OS ports open to everyone if uncommented
-A FILTERS -p tcp -m state --state NEW -m tcp -m multiport --dports 22 -j ACCEPT
#-A FILTERS -p udp -m udp -m multiport --dports 53,123 -j ACCEPT
-A FILTERS -m set ! --match-set ip_allow src -j DROP
-A FILTERS -j RETURN
COMMIT</code></pre>



<p>Use iptables-restore to add the above rules into iptables. The very important flag is <code>-n</code>. That makes sure we don&#8217;t flush the iptables rules if we have rules already in Docker (or Docker Swarm).</p>



<pre class="wp-block-code"><code># iptables-restore -n &lt; iptables-rules.txt</code></pre>



<p>Next, add a rule to the INPUT chain, so we start using the new rules in FILTERS. It has to be at the top, and only needs to be added once:</p>



<pre class="wp-block-code"><code># iptables -I INPUT 1 -j FILTERS</code></pre>



<p>Save the iptables rules:</p>



<pre class="wp-block-code"><code># /usr/libexec/iptables/iptables.init save</code></pre>



<p>That will save any existing and our new iptables rules to the iptables configuration file so it will be persistent after a reboot.</p>



<p>In addition, it was needed to run the above iptables command manually since we want to ensure it&#8217;s only inserted once. And we can&#8217;t flush the INPUT chain to ensure that since Docker Swarm could have rules there already.</p>



<p>Start and Enable the iptables service:</p>



<pre class="wp-block-code"><code># systemctl status iptables
# systemctl start iptables
# systemctl enable iptables</code></pre>



<p>If you want to customize the iptables rules to allow more ports to be open to everyone, just add the port to the appropriate rule in the iptables file (tcp or udp), then re-run the same commands from above:</p>



<pre class="wp-block-code"><code># iptables-restore -n &lt; iptables-rules.txt
# /usr/libexec/iptables/iptables.init save</code></pre>



<p><strong>Don&#8217;t miss the <a href="#warnings">Warnings</a> from above! Especially about SELinux.</strong></p>



<p>If you don&#8217;t want to do all of that manually, and you use Ansible, then do this instead..</p>



<h2 class="wp-block-heading">The Automatic way with Ansible</h2>



<p>Manually run all of the above, on every Docker server is not ideal. Let&#8217;s use Ansible instead!</p>



<p>I&#8217;ve created an <a rel="noreferrer noopener" href="https://galaxy.ansible.com/ryandaniels/iptables_docker" target="_blank">Ansible Role: iptables for Docker</a>, on <a rel="noreferrer noopener" href="https://github.com/ryandaniels/ansible-role-iptables-docker" target="_blank">GitHub</a> and <a rel="noreferrer noopener" href="https://galaxy.ansible.com/ryandaniels/iptables_docker" target="_blank">Ansible Galaxy</a>. </p>



<p>This works on CentOS 7, RHEL 7, Ubuntu 18.04, and Ubuntu 20.04.</p>



<p>Install the Ansible Role using Ansible Galaxy:</p>



<pre class="wp-block-code"><code>$ ansible-galaxy install ryandaniels.iptables_docker</code></pre>



<p>Or, clone the GitHub project:</p>



<pre class="wp-block-code"><code>$ git clone https://github.com/ryandaniels/ansible-role-iptables-docker.git roles/ryandaniels.iptables_docker</code></pre>



<p>Create the Ansible Playbook, called iptables_docker.yml:</p>



<pre class="wp-block-code"><code>---
- hosts: '{{ inventory }}'
  become: yes
  vars:
    # Use this role
    iptables_docker_managed: true
  roles:
  - ryandaniels.iptables_docker</code></pre>



<p>Make configuration changes to add desired IP addresses and ports as needed.</p>



<p><strong>Don&#8217;t miss the <a href="#warnings">Warnings</a> from above!</strong></p>



<p>Then run the playbook:</p>



<pre class="wp-block-code"><code>$ ansible-playbook iptables_docker.yml --extra-vars "inventory=centos7" -i hosts-dev</code></pre>



<h2 class="wp-block-heading">Conclusion</h2>



<p>In conclusion, now we have secured our Docker (and Docker Swarm) environments using Ansible to perform the installation and configuration of iptables! None of our Docker published ports are exposed to the world, unless we want them to be! We have created a custom Docker firewall with iptables. Hopefully, some day this will be the default behaviour and shipped with Docker out of the box! Dare to dream. Security is hard.</p>



<h2 class="wp-block-heading">References</h2>



<h3 class="wp-block-heading">Background for Docker&#8217;s undocumented use of iptables INPUT chain</h3>



<p><a href="https://ryandaniels.ca/blog/docker-iptables-input-chain/">See my previous post about this</a>.</p>



<h3 class="wp-block-heading">References and links</h3>



<p>References, notes, and links about the Docker firewall discussion:</p>



<ul class="wp-block-list"><li><a rel="noreferrer noopener" href="https://docs.docker.com/network/overlay/#encrypt-traffic-on-an-overlay-network" target="_blank">Docker Documentation &#8211; Overlay Networks</a></li><li><a rel="noreferrer noopener" href="https://github.com/docker/for-linux/issues/690" target="_blank">Docker bypasses ufw firewall rules</a></li><li><a rel="noreferrer noopener" href="https://unrouted.io/2017/08/15/docker-firewall/" target="_blank">unrouted</a> &#8211; Solution using iptables. Not for Swarm. It clobbers the INPUT chain, which is used by encrypted overlay with Docker Swarm</li><li><a rel="noreferrer noopener" href="https://github.com/moby/moby/issues/22054" target="_blank">The big thread about Docker and a firewall</a></li><li><a rel="noreferrer noopener" href="https://wiki.archlinux.org/index.php/Iptables#Chains" target="_blank">Arch Linux wiki to the rescue to show iptables</a> flow which links to a <a rel="noreferrer noopener" href="https://www.frozentux.net/iptables-tutorial/chunkyhtml/images/tables_traverse.jpg" target="_blank" rel="lightbox[2290]">great visual</a><br><br></li></ul>
<p>The post <a href="https://ryandaniels.ca/blog/secure-docker-with-iptables-firewall-and-ansible/">Secure Docker with iptables firewall and Ansible</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">2290</post-id>	</item>
		<item>
		<title>Malicious code and abandoned websites</title>
		<link>https://ryandaniels.ca/blog/malicious-code-abandoned-websites/</link>
		
		<dc:creator><![CDATA[Ryan Daniels]]></dc:creator>
		<pubDate>Sat, 27 Oct 2018 21:57:44 +0000</pubDate>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Privacy]]></category>
		<guid isPermaLink="false">https://ryandaniels.ca/?p=1338</guid>

					<description><![CDATA[<p><a href="https://ryandaniels.ca/blog/malicious-code-abandoned-websites/"><img src="https://ryandaniels.ca/wp-content/uploads/2018/10/nsc_js-150x146.png" alt="" width="150" height="146" class="alignleft size-thumbnail wp-image-1359" /></a> Malicious code and abandoned websites are increasingly becoming more of a problem. It's a serious issue in terms of privacy and security.<br />
TL;DR: Website owners: Be careful when using third-party code that you don't control.<br />
Users: Hope for the best! Use a content blocker browser add-on like uBlock Origin. On your mobile device use Firefox with uBlock Origin.</p>
<p>The post <a href="https://ryandaniels.ca/blog/malicious-code-abandoned-websites/">Malicious code and abandoned websites</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>Malicious code and abandoned websites are increasingly becoming more of a problem. It&#8217;s a serious issue in terms of privacy and security.</p>
<p>TL;DR:<br />
<strong>Website owners</strong>: Be careful when using third-party code that you don&#8217;t control.<br />
<strong>Users</strong>: Hope for the best! Use a content blocker browser add-on like uBlock Origin. On your mobile device use Firefox with uBlock Origin.</p>
<p><span id="more-1338"></span></p>
<h2>What&#8217;s the problem?</h2>
<p>Abandoned or unmaintained websites can be re-registered by malicious people. Any website using third-party code could be a victim.</p>
<p>To highlight the issue, let&#8217;s look at a specific example. This example luckily wasn&#8217;t extremely malicious. It could have been much worse! But it still highlights the current state of the web.</p>
<p>Recently there was an issue where 800+ websites were using javascript from an abandoned free service called &#8220;New Share Counts&#8221; which counted the number of Twitter shares.</p>
<p>Image of malicious code:</p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-1359 size-full" src="https://ryandaniels.ca/wp-content/uploads/2018/10/nsc_js.png" alt="nsc.js malicious source code" width="897" height="146" srcset="https://ryandaniels.ca/wp-content/uploads/2018/10/nsc_js.png 897w, https://ryandaniels.ca/wp-content/uploads/2018/10/nsc_js-300x49.png 300w, https://ryandaniels.ca/wp-content/uploads/2018/10/nsc_js-768x125.png 768w" sizes="auto, (max-width: 897px) 100vw, 897px" /></p>
<p><a href="https://blog.sucuri.net/2018/10/malicious-redirects-from-newsharecounts-com-tweet-counter.html" target="_blank" rel="noopener noreferrer">Securi</a> and <a href="https://www.bleepingcomputer.com/news/security/abandoned-tweet-counter-hijacked-with-malicious-script/" target="_blank" rel="noopener noreferrer">BleepingComputer</a> have great write-ups on the details.</p>
<p>The problem is this third party website stopped offering their free service. They notified users via their website and eventually the resources they used for counting Tweets were abandoned. This included the Amazon S3 bucket they used. Unfortunately many website owners didn&#8217;t get the notice, or ignored it.</p>
<p>Image of a website including the malicious code in their source code:</p>
<p><img loading="lazy" decoding="async" class="alignnone wp-image-1360 size-full" src="https://ryandaniels.ca/wp-content/uploads/2018/10/website_source_code-nsc_js.png" alt="website including malicious code nsc.js" width="877" height="192" srcset="https://ryandaniels.ca/wp-content/uploads/2018/10/website_source_code-nsc_js.png 877w, https://ryandaniels.ca/wp-content/uploads/2018/10/website_source_code-nsc_js-300x66.png 300w, https://ryandaniels.ca/wp-content/uploads/2018/10/website_source_code-nsc_js-768x168.png 768w" sizes="auto, (max-width: 877px) 100vw, 877px" /></p>
<p>According the research from BleepingComputer, on October 3rd the AWS S3 bucket was cancelled and on October 4th a &#8220;bad actor&#8221; registered a new AWS S3 bucket under the same name. Up until October 23rd, all 800+ websites that didn&#8217;t remove this javascript file were serving all of their visitors with a malicious script which redirected mobile users to a scam website.</p>
<p><strong>As of October 23, 2018: </strong>the malicious javascript (newsharecounts.s3-us-west-2.amazonaws.com/nsc.js) has been blocked on the AWS S3 bucket. It is returning the error: Access Denied</p>
<p><strong>Update October 28, 2018</strong>: AWS will not confirm the S3 bucket was banned on their side. The malicious code could return at any time, and possibly be worse next time. According to AWS they need other people to alert them if the malicious content re-appears! From AWS: &#8220;<strong>Should you see the content return or similar appear, please report it immediately.</strong>&#8221;</p>
<p><strong>Update October 31, 2018</strong>: Malicious javascript is back online.</p>
<p><strong>Update November 9, 2018</strong>: From AWS: &#8220;Content in question is not currently accessible&#8221;.</p>
<p><strong>Update January 9, 2019</strong>: Malicious javascript is back online, again.</p>
<p><strong>Update January 14, 2019</strong>: From AWS: &#8220;We have again blocked the content.&#8221;</p>
<h2>Who can fix this?</h2>
<ul>
<li>Individual website(s) that include the third-party malicious code</li>
<li>Hosting provider where the malicious code resides</li>
<li>Web browser blocks malicious code</li>
<li>Web browser add-on blocks malicious code</li>
<li>You and me? Social media? News outlets?</li>
</ul>
<p>Unfortunately it&#8217;s hard to get all 800+ websites to fix this on their sites. So ultimately we need the company hosting the malicious content to step in.</p>
<p>It seems having this issue in the news and social media definitely helps put pressure on those who can take the malicious content down. In this case it was an Amazon S3 bucket hosting the malicious javascript.</p>
<p>But why is this so hard? Just take down the malicious code!</p>
<h3>What about the hosting provider?</h3>
<p>In this case, I submitted an abuse report to AWS the night of October 15th. It was only after Securi and BleepingComputer published news articles on October 16th/17th and some <a href="https://twitter.com/BleepinComputer/status/1052454195444555776" target="_blank" rel="noopener noreferrer">pressure on social media</a> did AWS acknowledge the issue (to me at least). Then it took AWS over a week to take the resource down*. And that was only after countless back and forth emails with them. Thankfully, at least for now, the malicious javascript has been removed.</p>
<p>At first they said this malicious script didn&#8217;t violate their terms of service! I had to read through their terms of service (TOS) and provided them with exact details of how this malicious script actually does violate their TOS.<br />
Such a painful process!</p>
<ul>
<li>At the time of publishing this post, AWS has <strong>not</strong> confirmed they took the malicious script down due to a violation of the terms of service. So hopefully this malicious script won&#8217;t come back online in the future at the same location!</li>
</ul>
<h3>A browser add-on can also help</h3>
<p>I had a feeling it was going to take the hosting provider a while to respond, since these things take time. As a work-around, a browser add-on to the rescue!<br />
uBlock Origin added this malicious javascript to their content filtering add-on <a href="https://github.com/uBlockOrigin/uAssets/issues/3730" target="_blank" rel="noopener noreferrer"><strong>25 minutes</strong> after I opened an issue with them</a>! Now that&#8217;s fast! So at least anyone using this popular browser add-on would be protected (well that is if they use Firefox on their mobile device, which actually isn&#8217;t the dominant browser).</p>
<h3>What about the browser itself?</h3>
<p>The most recent version of Firefox 63 now has <a href="https://developer.mozilla.org/en-US/docs/Mozilla/Firefox/Privacy/Storage_access_policy#Tracking_protection_explained">Tracking Protection</a>. But this can only block entire domains and not specific files. So that can&#8217;t help in this case.<br />
Directly in the Chrome browser? Not currently an option either.</p>
<h3>You and me? Social media? News outlets?</h3>
<p>Unfortunately that seems to be what it&#8217;s come to. More on that below.</p>
<p>Luckily this example wasn&#8217;t worse. The malicious code only redirected a mobile user to a scam website when they pressed their back button on one of the <a href="https://publicwww.com/websites/%22newsharecounts.s3-us-west-2.amazonaws.com%2Fnsc.js%22/" target="_blank" rel="noopener noreferrer">800 affected websites</a>. It could have been cryptocurrency mining malware, or code to exploit some bug in Android or iOS. Who knows, maybe the hosting provider would respond much faster if it was more serious? Or the website owners? Maybe.. Maybe not.</p>
<h2>Solution for users</h2>
<p>Unfortunately web users have little control over what a website is serving their browser. One thing that can help is using a content filter add-on for your browser like <a href="https://addons.mozilla.org/en-US/firefox/addon/ublock-origin/" target="_blank" rel="noopener noreferrer">uBlock Origin for Firefox</a> or for <a href="https://chrome.google.com/webstore/detail/ublock-origin/cjpalhdlnbpafiamejdnhcphjbkeiagm?hl=en" target="_blank" rel="noopener noreferrer">Chrome</a>. In the above case the malicious code was only affecting mobile users. Only Firefox supports add-ons for their mobile browser. This is another reason to use Firefox on your mobile devices! In a related post, check out how easy it is to <a href="https://ryandaniels.ca/blog/firefox-privacy-settings-made-easy/">upgrade your privacy using Firefox</a>.</p>
<h2>Long term solution for website owners</h2>
<p>Website owners need to be careful when adding third-party code to their websites. However, this is extremely difficult in today&#8217;s modern web. Often websites use many, many different third-party services.</p>
<p>One solution is to host all third party code locally on your web server. Unfortunately, this has it&#8217;s own issues since there would no longer updates to the code by the developer unless the website owner manually updates their site.</p>
<p>Another solution is to use <a href="https://en.wikipedia.org/wiki/Subresource_Integrity" target="_blank" rel="noopener noreferrer">Subresource Integrity (SRI)</a>. Unfortunately this can be tedious to implement for a website owner. And even worse, if you use a CMS like WordPress, you rely on the plugin developer to implement SRI into their plugin or theme. There is a WordPress plugin called <a href="https://wordpress.org/plugins/wp-sri/" target="_blank" rel="noopener noreferrer">(SRI) Manager</a> which can help add SRI to all plugins, but your mileage may vary with getting it to work.</p>
<h2>Conclusion &#8211; Who <span style="text-decoration: underline;">should</span> fix this?</h2>
<p>Who can fix this versus who should fix this is a good question. In my opinion, this should be the responsibility of the individual website. However, getting 800+ websites to fix this in a timely manner.. not going to happen (and it didn&#8217;t in this example!). As of the time of this post, most websites still include a link to the malicious code on their sites! Thankfully now it does nothing since it no longer exists.<br />
It really needs to be easier for website owners to have secure third-party code on their website, otherwise we continue down this path.</p>
<h3>Who needs to drive this change?</h3>
<p>Specifically in the above example of &#8220;New Share Counts,&#8221; was it only a concerned internet user (myself) that made this happen?<br />
Probably not, since it was in the news. That&#8217;s probably the only reason there was any traction. But regardless, I contacted an infected website (which I randomly found while surfing the net. Mind you, only one website of 800+), initiated an abuse case with the hosting provider (AWS) where the malicious code was, and lastly, initiated a support ticket for a work-around using a popular browser add-on.</p>
<p>Maybe other people also contacted the hosting provider. Maybe I should have contacted more content filtering browser add-ons? More pressure on social media? Or something else in addition?</p>
<p>Maybe more people need to take action against these issues after they happen.</p>
<p>The next question is, who should be driving this overall change to make it easier to secure third-party code on websites? That&#8217;s also a great question..</p>
<p>However, until that&#8217;s figured out we need individuals and news outlets to raise these issues when they happen.<br />
For instance, open abuse reports with the hosting provider, try to inform the websites impacted, find work-arounds when it&#8217;s taking too long. Raise awareness on social media platforms.</p>
<p>Currently, that&#8217;s all we can do. That is, if the issue is even <strong>detected</strong> in the first place.</p>
<p>&nbsp;</p>
<h2>Timeline</h2>
<p>For anyone interested, here&#8217;s a timeline of events for the &#8220;New Share Counts&#8221; issue from what  I observed. This isn&#8217;t meant to single out the hosting provider (AWS) in particular, they are probably flooded with abuse reports. But still, their generic responses are pretty funny. <strong>Bold</strong> used for emphasis.</p>
<p>2018/10/14 23:13 EST &#8211; Randomly found issue on one specific website (Latest Hacking News) while surfing the net on my couch (on my phone) and informed them about malicious javascript on their site.<br />
<a href="https://i.imgur.com/4E6uSx5.png" target="_blank" rel="noopener noreferrer" rel="lightbox[1338]">https://i.imgur.com/4E6uSx5.png</a></p>
<p>2018/10/15 17:19 EST &#8211; Emailed &#8220;Latest Hacking News&#8221; with more details. Including script where the malicious javascript is located.</p>
<p>2018/10/15 17:47 EST &#8211; Abuse report submitted to the hosting provider (AWS). ( where malicious javascript is hosted: newsharecounts.s3-us-west-2.amazonaws.com/nsc.js ). Gave details on what this malicious javascript is doing and how to reproduce malicious behaviour.</p>
<p>2018/10/15 17:55 EST &#8211; Response from hosting provider: Generic response asking for logs.</p>
<p>2018/10/15 18:04 EST &#8211; Replied to hosting provider: Gave info where they can find a site infected with the malicious javascript. Also, exact steps to reproduce malicious behaviour.</p>
<p>2018/10/16 06:56 EST &#8211; <a href="https://blog.sucuri.net/2018/10/malicious-redirects-from-newsharecounts-com-tweet-counter.html" target="_blank" rel="noopener noreferrer">Securi publishes article about malicious redirects from newsharecount</a>.</p>
<p>2018/10/16 11:06 EST &#8211; &#8220;Latest Hacking News&#8221; removed the malicious javascript from their website.</p>
<p>2018/10/17 03:00 EST &#8211; <a href="https://www.bleepingcomputer.com/news/security/abandoned-tweet-counter-hijacked-with-malicious-script/" target="_blank" rel="noopener noreferrer">BleepingComputer publishes article</a>.</p>
<p>2018/10/17 18:22 EST &#8211; Replied to hosting provider via email: No response from hosting provider (AWS) since 15th. Asked for abuse case to be expedited and if they can shutdown this AWS S3 bucket / javascript file. Also mentioned to AWS this was now in the news via Securi and BleepingComputer.</p>
<p>2018/10/17 18:33 EST &#8211; <a href="https://twitter.com/BleepinComputer/status/1052454195444555776" target="_blank" rel="noopener noreferrer">Reply to BleepingComputer&#8217;s tweet</a>, including AWS twitter handle to highlight lack of response from AWS.</p>
<p>2018/10/17 18:39 EST &#8211; Hosting provider responded via email: &#8220;This case has been investigated and being resolved by the appropriate team.&#8221;</p>
<p>2018/10/17 19:15 EST &#8211; Submitted issue with uBlock Origin (browser add-on to filter content) via their <a href="https://github.com/uBlockOrigin/uAssets/issues/3730" target="_blank" rel="noopener noreferrer">Github issue tracker</a>.</p>
<p>2018/10/17 19:40 EST &#8211; <a href="https://github.com/uBlockOrigin/uAssets/commit/c126e1e6a05072c53d5ab8836c160dc1a7b56fdb" target="_blank" rel="noopener noreferrer">uBlock Origin now blocks this malicious code</a>. Only took 25 minutes! Anyone using the uBlock Origin browser addon (on mobile device) will not be affected by the malicious javascript.</p>
<p>2018/10/18 03:48 EST &#8211; <a href="https://twitter.com/AWSSupport/status/1052828747618033664" target="_blank" rel="noopener noreferrer">Hosting provider responds via twitter</a> that they are investigating.</p>
<p>2018/10/18 04:46 EST &#8211; &#8220;Latest Hacking News&#8221; <a href="https://twitter.com/7H3Wh173R4bb17/status/1052843254121713665" target="_blank" rel="noopener noreferrer">responded</a> via twitter, with thanks for finding the malicious javascript on their website.</p>
<p>2018/10/19 09:41 EST &#8211; Hosting provider responded via email:<br />
&#8220;We understand your concern regarding the continued availability of the content you have reported. As noted previously, AWS customers are responsible for their activity on AWS. As a courtesy we notified our customer of your request to have the content removed or access disabled, however, as we do not consider this content to be in violation of our terms, we are not able to take additional action. We strongly encourage you to continue to work with our customer directly to address the concerns that you may have.&#8221;</p>
<p>2018/10/19 10:12 EST &#8211; Replied to hosting provider via email:<br />
&#8220;It&#8217;s unfortunate that this bad actor&#8217;s malicious script/bucket can&#8217;t be removed since it is clearly hijacking users mobile browsers to serve them ads/malware/malicious script. I suspect that notifying the current AWS customer which owns this bucket will have no result, since they are responsible for this malicious script in the first place.&#8221;</p>
<p>2018/10/19 10:29 EST &#8211; Hosting provider responded, via email, stating the same thing again and the case was closed:<br />
&#8220;As noted previously, AWS customers are responsible for their activity on AWS. <strong>As a courtesy we notified our customer of your request to have the content removed or access disabled, however, as we do not consider this content to be in violation of our terms, we are not able to take additional action. We strongly encourage you to continue to work with our customer directly to address the concerns that you may have. This case has been resolved by the appropriate team.</strong>&#8221;</p>
<p>2018/10/19 18:26 EST &#8211; Replied to hosting provider via email. I read through all of their Terms of Service and found where this malicious javascript violated their terms in two places. Provided details about how this malicious javascript was breaking their TOS in those two places.</p>
<p>2018/10/19 19:08 EST &#8211; Hosting provider responded via email:<br />
&#8220;Thank you for your reply. We are looking into this issue further and passed it on to our customer.&#8221;</p>
<p>2018/10/23 16:30 EST &#8211; &#8220;Abandoned Tweet Counter Hijacked With Malicious Script&#8221; Podcast from <a href="https://www.grc.com/securitynow.htm" target="_blank" rel="noopener noreferrer">Security Now!</a> about this issue. <a href="https://www.grc.com/sn/sn-686-notes.pdf" target="_blank" rel="noopener noreferrer">Episode #686</a> Audio &amp; <a href="https://twit.tv/shows/security-now/episodes/686?autostart=false" target="_blank" rel="noopener noreferrer">Video</a>.</p>
<p>2018/10/23 19:45 EST &#8211; Noticed http://newsharecounts.s3-us-west-2.amazonaws.com/nsc.js is down. Returning error: &#8220;Access Denied&#8221;.</p>
<p>2018/10/23 19:48 EST &#8211; <a href="https://twitter.com/ryan_daniels/status/1054882214889078785" target="_blank" rel="noopener noreferrer">Replied to hosting provider via twitter</a>: Asking hosting provider to confirm they took down the javascript due to violation of their terms.</p>
<p>2018/10/25 16:53 EST &#8211; Replied to hosting provider via email:<br />
&#8220;Can you confirm this S3 bucket is now suspended and can&#8217;t be used again?&#8221;</p>
<p>2018/10/27 &#8211; No response from the hosting provider at time of this post.</p>
<p>2018/10/28 09:19 EST &#8211; Hosting provider responded, via email:<br />
&#8220;<strong>At this time the content appears to be no longer active or available. If you have any evidence otherwise, please let us know.</strong>&#8221;</p>
<p>2018/10/28 09:27 EST &#8211; Replied to hosting provider via email, asking for confirmation the S3 bucket is suspended and if not, to do so.</p>
<p>2018/10/28 09:39 EST &#8211; Hosting provider responded, via email. Due to privacy policies they cannot discuss what actions have been taken, and:<br />
&#8220;<strong>Should you see the content return or similar appear, please report it immediately.</strong>&#8221;</p>
<p>2018/10/31 17:42 EST &#8211; Replied to hosting provider via email. Malicious content is back online.</p>
<p>2018/11/06 11:05 EST &#8211; Hosting provider responded via email.<br />
&#8220;We have begun our investigation into the source of the activity or content you reported.&#8221;</p>
<p>2018/11/09 04:28 EST &#8211; Hosting provider responded via email.<br />
&#8220;Content in question is not currently accessible.. If you believe this content is still live, please provide additional evidence and we will be sure to investigate further. At this time please consider this case as resolved.&#8221;</p>
<p>2019/01/09 05:42 EST &#8211; Emailed hosting provider. Malicious content is live, again.</p>
<p>2019/01/14 08:55 EST &#8211; Hosting provider responded via email.<br />
&#8220;Thank you for advising us that the content has been uploaded again. We have again blocked the content.&#8221;</p>
<p>The post <a href="https://ryandaniels.ca/blog/malicious-code-abandoned-websites/">Malicious code and abandoned websites</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1338</post-id>	</item>
		<item>
		<title>Upgrade SSH keys and use gpg-agent with Ed25519 keys</title>
		<link>https://ryandaniels.ca/blog/upgrade-ssh-keys-gpg-agent-ed25519/</link>
		
		<dc:creator><![CDATA[Ryan Daniels]]></dc:creator>
		<pubDate>Sun, 11 Feb 2018 16:30:46 +0000</pubDate>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Encryption]]></category>
		<category><![CDATA[Guide]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[SSH]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<guid isPermaLink="false">https://ryandaniels.ca/?p=1245</guid>

					<description><![CDATA[<p>SSH keys are convenient and more secure than using a password to authenticate. If you created your SSH key a while ago, it's probably time to generate new RSA 4096 and Ed25519 keys. SSH keys like DSA and RSA 1024 are very old and now insecure. You should even upgrade ssh keys that are RSA 2048.</p>
<p>The post <a href="https://ryandaniels.ca/blog/upgrade-ssh-keys-gpg-agent-ed25519/">Upgrade SSH keys and use gpg-agent with Ed25519 keys</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p>SSH keys are very convenient and more secure than using only a password to authenticate. If you created your SSH key a while ago, it&#8217;s probably time to generate new keys. SSH keys like DSA and RSA 1024 are very old and now insecure. You should even upgrade ssh keys that are RSA 2048. But really, it&#8217;s time to start using RSA 4096 for legacy servers, and Ed25519 for servers with modern ssh key support.</p>
<p><span id="more-1245"></span></p>
<p>The below commands are based on the post <a href="https://blog.g3rt.nl/upgrade-your-ssh-keys.html" target="_blank" rel="noopener noreferrer">Upgrade your SSH keys.</a> Check that out for more details.</p>
<h2>Identify and rename old ssh keys</h2>
<p>First, identify your old ssh keys:</p>
<pre>$ cd ~/.ssh
$ for sshkey in $(ls *.pub);do echo $sshkey;ssh-keygen -lf $sshkey;done
/home/ryan/.ssh/id_rsa.pub
2048 SHA256:gIDkzI98pEna3j9+2Ja5di0+k2dCaXtCtx6k71dskA1 ryan@home (RSA)</pre>
<p>From the output, this is showing it is an RSA 2048 key.</p>
<p>Next rename your old public and private ssh keys:</p>
<pre>$ mv id_rsa.pub id_rsa_legacy.pub
$ mv id_rsa id_rsa_legacy</pre>
<h2>Stop using insecure keys</h2>
<p>Use only keys that are greater than RSA 2048, or Ed25519.<br />
Specifically, remove:</p>
<ul>
<li>DSA</li>
<li>RSA 1024 and 2048</li>
<li>ECDSA</li>
</ul>
<p>Just be sure you aren&#8217;t using these ssh keys. Only remove them when you no longer need them and have the new keys setup and working.</p>
<h2>Create or Change your existing password</h2>
<p>If you old RSA ssh key didn&#8217;t use a password, now is the time to set a password. You can upgrade ssh keys that previously existed and didn&#8217;t use a password, without breaking anything. Also adding 100 rounds helps make your old key more secure when at rest if you need to continue using it.</p>
<pre>$ ssh-keygen -f ~/.ssh/id_rsa_legacy -p -o -a 100</pre>
<h2>Upgrade ssh keys &#8211; Generate RSA 4096 ssh keys</h2>
<p>RSA 4096 is good to use for legacy systems which do not yet support the new Ed25519 key.</p>
<p>Generate the RSA 4096 keys, and make sure to use a strong password:</p>
<pre>$ ssh-keygen -t rsa -b 4096 -o -a 100
Generating public/private rsa key pair.
Enter file in which to save the key (/home/ryan/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/ryan/.ssh/id_rsa.
Your public key has been saved in /home/ryan/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:732MQCPPaMS815Y7MFXl4n2WXuawR1Zsat+PEG1TnPA ryan@home
The key's randomart image is:
+---[RSA 4096]----+
|         +. o+.oo|
|        o * .+*..|
|         B oo=Eo.|
|          =o=..oo|
|        S .BoBo+=|
|         .  *.Ooo|
|          .  B =.|
|        .   B * .|
|          .... . |
+----[SHA256]-----+</pre>
<p>The &#8220;<code>-o -a 100</code>&#8221; means it is harder to crack the private key&#8217;s password using brute-force attacks. If your legacy system doesn&#8217;t support this, remove this option.</p>
<h2>Upgrade ssh keys &#8211; Generate Ed25519 ssh keys</h2>
<p><a href="https://en.wikipedia.org/wiki/EdDSA#Ed25519" target="_blank" rel="noopener noreferrer">Ed25519</a> ssh keys work on modern systems (OpenSSH 6.7+) and are much shorter than RSA keys. Note, the &#8220;<code>-o -a 100</code>&#8221; option is implied with Ed25519 key generation.<br />
Generate your new Ed25519 key and use a strong password:</p>
<pre>$ ssh-keygen -t ed25519
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/ryan/.ssh/id_ed25519.
Your public key has been saved in /home/ryan/.ssh/id_ed25519.pub.
The key fingerprint is:
SHA256:oU44/TftLl2/d4IKQla36Z1TMqrcdK1xBcerye78fxM ryan@home
The key's randomart image is:
+--[ED25519 256]--+
|        . .      |
|     . . . . .   |
|    . o .   o o .|
|   .   + . o o = |
|    . + S * + +  |
|     = . = B  .E |
|      + B.=.oo ..|
|       =.=o.o ..=|
|      ..oo=+o..+=|
+----[SHA256]-----+</pre>
<p>Now you have both RSA 4096 and Ed25519 ssh keys ready to go.</p>
<p>Next, add the keys to your ssh agent so it will remember the keys for you.</p>
<h2>Install and configure ssh agent</h2>
<p>Using an ssh agent allows you to type in a password once, and then the agent remembers the ssh keys.</p>
<p>On Ubuntu 16.04 there is one problem though. The built-in Gnome-keyring doesn&#8217;t support Ed25519. To work-around this, you could use the normal ssh-agent. But, I suggest instead to use gpg-agent and disable the gnome-keyring.</p>
<p>The below commands are based on the <a href="https://wiki.archlinux.org/index.php/GnuPG#SSH_agent" target="_blank" rel="noopener noreferrer">Arch wiki</a> and an answer from the <a href="https://askubuntu.com/questions/732581/gpg-agent-and-ssh-no-keys/930105#930105" target="_blank" rel="noopener noreferrer">Ask Ubuntu Forum</a>.</p>
<p>Disable Gnome ssh keyring daemon (<a href="https://wiki.archlinux.org/index.php/GNOME/Keyring#Disable_keyring_daemon_components" target="_blank" rel="noopener noreferrer">reference</a>):</p>
<pre>$ cp -rp /etc/xdg/autostart/gnome-keyring-ssh.desktop ~/.config/autostart
$ echo "Hidden=true" &gt;&gt; ~/.config/autostart/gnome-keyring-ssh.desktop</pre>
<p>Install gpg-agent:</p>
<pre>$ sudo apt-get install gpa gnupg-curl</pre>
<p>Enable ssh support in gpg-agent, and set a timeout to remember the key and password for 1 hour, since this adds some convenience:</p>
<pre>$ echo "enable-ssh-support" &gt;&gt; ~/.gnupg/gpg-agent.conf
$ echo "default-cache-ttl-ssh 3600" &gt;&gt; ~/.gnupg/gpg-agent.conf
$ echo "max-cache-ttl-ssh 3600" &gt;&gt; ~/.gnupg/gpg-agent.conf</pre>
<p>Edit your .bashrc to automatically load gpg-agent when you log in.</p>
<pre>$ vi ~/.bashrc
# Set SSH to use gpg-agent
unset SSH_AGENT_PID
if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]; then
export SSH_AUTH_SOCK="~/.gnupg/S.gpg-agent.ssh"
fi</pre>
<p>Reload gpg-agent:</p>
<pre>$ gpg-connect-agent reloadagent /bye</pre>
<p>Next, add your new ssh keys to the gpg-agent:</p>
<pre>$ ssh-add ~/.ssh/id_ed25519 ~/.ssh/id_rsa ~/.ssh/id_rsa_legacy</pre>
<p>You will be prompted to enter your ssh key password. And after you enter that, another prompt will pop-up, from the gpg-agent. It will be used to unlock the gpg-agent&#8217;s key storage. This should be a different password than the password for your ssh keys. You will be prompted to enter this password every time you log in, or after the 1 hour timeout.</p>
<p>Enter the password that you want to use to unlock the gpg-agent key storage. And if you use the same password here for all your ssh keys, you only have to unlock it once:</p>
<p><img loading="lazy" decoding="async" class="alignnone size-full wp-image-1270" src="https://ryandaniels.ca/wp-content/uploads/2018/02/gpg-agent_password_prompt.png" alt="gpg-agent password prompt upgrade ssh keys" width="477" height="277" srcset="https://ryandaniels.ca/wp-content/uploads/2018/02/gpg-agent_password_prompt.png 477w, https://ryandaniels.ca/wp-content/uploads/2018/02/gpg-agent_password_prompt-300x174.png 300w" sizes="auto, (max-width: 477px) 100vw, 477px" /></p>
<p>And now you can list your keys stored in the gpg-agent:</p>
<pre>$ ssh-add -l -E md5 # list fingerprint using md5 hash
$ ssh-add -l        # list fingerprint using sha256 hash
$ ssh-add -L        # list public key parameters</pre>
<h2>Re-deploy the new public keys</h2>
<p>Lastly, you need to add your new public keys to your servers. This command will ssh to your server and add your new public keys to the authorized_keys file.<br />
Change <code>1.2.3.4</code> to your server&#8217;s IP:</p>
<pre>$ ssh 1.2.3.4 "mkdir -p .ssh;echo $(cat ~/.ssh/id_ed25519.pub) &gt;&gt; .ssh/authorized_keys;echo $(cat ~/.ssh/id_rsa.pub) &gt;&gt; .ssh/authorized_keys;chmod 700 .ssh;chmod 640 .ssh/authorized_keys"</pre>
<p>Be sure to do this for ever server you connect to.</p>
<p><strong>Important</strong>: Be sure you <strong>don&#8217;t lock yourself out</strong> of your servers. Have another session open and test to make sure you can log in again after making this change.</p>
<p>Now you can remove your old ssh key from the ssh agent and only use the secure ssh keys:</p>
<pre>$ ssh-add -d 2&gt;/dev/null;ssh-add ~/.ssh/id_ed25519;ssh-add ~/.ssh/id_rsa</pre>
<p>Be sure to add the Ed25519 key first, like above. Since it seems to be a feature that prioritizes RSA keys first. So add the Ed25519 key first.</p>
<p>SSH to your servers to test the new key is working. You can also see in the logs the type of ssh key being used.</p>
<p>Confirm using the new Ed25519 ssh key, on Ubuntu 16.04:</p>
<pre>$ grep " sshd\[" /var/log/auth.log|grep "Accepted publickey"|tail
Feb 11 10:00:00 home sshd[1802]: Accepted publickey for ryan from 192.168.1.100 port 60708 ssh2: ED25519 SHA256:oU44/TftLl2/d4IKQla36Z1TMqrcdK1xBcerye78fxM</pre>
<h2>Conclusion</h2>
<p>Now you have more secure ssh keys since you are using Ed25519 and RSA 4096 keys. You have been able to upgrade ssh keys that are insecure! Next, you should look into updating your ssh server and client settings to use better encryption settings, using <a href="https://stribika.github.io/2015/01/04/secure-secure-shell.html" target="_blank" rel="noopener noreferrer">these</a> <a href="https://wiki.mozilla.org/Security/Guidelines/OpenSSH" target="_blank" rel="noopener noreferrer">references</a>.</p>
<p>And if you don&#8217;t want to manually deploy the new ssh keys to all of your servers, instead you can use <a href="https://ryandaniels.ca/blog/ansible-user-management/">Ansible for user management</a>.</p>
<p>The post <a href="https://ryandaniels.ca/blog/upgrade-ssh-keys-gpg-agent-ed25519/">Upgrade SSH keys and use gpg-agent with Ed25519 keys</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1245</post-id>	</item>
		<item>
		<title>How to setup OpenVPN with ad blocking on Raspberry Pi or a VPS</title>
		<link>https://ryandaniels.ca/blog/openvpn-ad-blocking/</link>
		
		<dc:creator><![CDATA[Ryan Daniels]]></dc:creator>
		<pubDate>Sun, 04 Feb 2018 14:18:33 +0000</pubDate>
				<category><![CDATA[Ansible]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Guide]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[OpenVPN]]></category>
		<category><![CDATA[Ubuntu]]></category>
		<guid isPermaLink="false">https://ryandaniels.ca/?p=1117</guid>

					<description><![CDATA[<p><a href="https://ryandaniels.ca/blog/openvpn-ad-blocking/"><img src="https://ryandaniels.ca/wp-content/uploads/2018/02/ad_overload-300x144.jpg" alt="Ad Overload happens.. Is Ad Blocking possible in NYC?" width="300" height="144" class="alignleft size-medium wp-image-1174" /></a> Using a VPN can help to protect your privacy. You can use a VPN to appear like you are in another country to reach a website that was previously blocked, to stop your ISP from restricting you to certain websites, and when travelling to protect your data while using insecure WiFi. There's another: ad blocking.</p>
<p>The post <a href="https://ryandaniels.ca/blog/openvpn-ad-blocking/">How to setup OpenVPN with ad blocking on Raspberry Pi or a VPS</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-1174" src="https://ryandaniels.ca/wp-content/uploads/2018/02/ad_overload.jpg" alt="Ad Overload happens.. Is Ad Blocking possible in NYC?" width="800" height="383" srcset="https://ryandaniels.ca/wp-content/uploads/2018/02/ad_overload.jpg 800w, https://ryandaniels.ca/wp-content/uploads/2018/02/ad_overload-300x144.jpg 300w, https://ryandaniels.ca/wp-content/uploads/2018/02/ad_overload-768x368.jpg 768w" sizes="auto, (max-width: 800px) 100vw, 800px" /></p>
<p>Using a VPN (Virtual Private Network) can help to protect your privacy. You can use a VPN to appear like you are in another country so you can reach a website that was previously blocked. You can also use a VPN to stop your ISP from restricting you to certain websites, and when travelling to protect your data while using insecure WiFi. There are many many more reason. However, there can be an extra benefit to using a VPN that people don&#8217;t usually think about: Automatic content blocking (also known as ad blocking).</p>
<p><span id="more-1117"></span></p>
<h2>Why?</h2>
<p>Ad <a href="https://en.wikipedia.org/wiki/Ad_blocking" target="_blank" rel="noopener noreferrer">blocking</a> is now a necessity because of dangerous ads. Some ad networks have had problems with ads containing malicious JavaScript which is actually malware. Even recently <a href="https://arstechnica.com/information-technology/2018/01/now-even-youtube-serves-ads-with-cpu-draining-cryptocurrency-miners/" target="_blank" rel="noopener noreferrer">YouTube was showing ads that contained a cryptocurrency miner</a>. An add-on like <a href="https://addons.mozilla.org/en-US/firefox/addon/ublock-origin/" target="_blank" rel="noopener noreferrer">uBlock Origin for Firefox</a> or <a href="https://chrome.google.com/webstore/detail/ublock-origin/cjpalhdlnbpafiamejdnhcphjbkeiagm?hl=en" target="_blank" rel="noopener noreferrer">Chrome</a> can help. And customizing your <a href="https://ryandaniels.ca/blog/firefox-privacy-settings-made-easy/">Firefox privacy settings</a> will also help. But what if apps on your phone are showing dangerous ads? Or, what if you have an old phone that&#8217;s no longer getting updates and you want better protection from the recent Meltdown vulnerability? A browser add-on alone will not help you.</p>
<p><img loading="lazy" decoding="async" class="aligncenter size-full wp-image-1179" src="https://ryandaniels.ca/wp-content/uploads/2018/02/openvpn.png" alt="OpenVPN with ad blocking" width="208" height="54" /></p>
<p>Now, combine the benefits of a VPN, and ad blocking into one solution. This is where OpenVPN with ad blocking using dnsmasq comes in. For this to work you need control of the OpenVPN server configuration. So using a VPN provider is not an option. But, this way is cheaper! Plus you get the satisfaction of setting up your own VPN!</p>
<h2>Setup a Raspberry Pi with OpenVPN</h2>
<p>You can create your own VPN with a <a href="https://www.raspberrypi.org/products/" target="_blank" rel="noopener noreferrer">Raspberry Pi</a>. If you live in Canada, a good way to get started is with the <a href="http://amzn.to/2FI0IuW" target="_blank" rel="nofollow noopener noreferrer">Raspberry Pi 3 CanaKit</a>. There are many <a href="https://github.com/pivpn/pivpn" target="_blank" rel="noopener noreferrer">guides</a> for setting up a Raspberry Pi with OpenVPN.</p>
<p>However, this method won&#8217;t help if a website restricts your country, or if your ISP blocks you from certain content, since you will have the Raspberry Pi at home. But, you can still use this method to protect you when using open WiFi while travelling, or when at home to get the benefit of ad blocking on your mobile devices.</p>
<h2>Setup a VPS with OpenVPN</h2>
<p>If using a Raspberry Pi isn&#8217;t your thing, you can buy an inexpensive VPS (Virtual Private Server) and host your VPN from there. This may seem like more work, but it&#8217;s pretty easy. And with a VPS you don&#8217;t need to worry about exposing your home network to the public internet. Also, when using a VPS that is only for OpenVPN, you can use common ports to have a better chance of being able to connect to your VPN.</p>
<p><a href="https://ryandaniels.ca/go/linode/" target="_blank" rel="nofollow noopener noreferrer">Linode</a> is a great VPS provider for $5 per month. Or, <a href="https://ryandaniels.ca/go/vultr/" target="_blank" rel="nofollow noopener noreferrer">Vultr</a> offers a VPS for $2.50 per month! (For IPv6 only, IPv4 is $3.50). Whichever VPS provider you choose, make sure to create your VPS in a country that&#8217;s right for you. For example, if you need to access a website usually only available to a certain country. Also make sure you obey their TOS.  I&#8217;m not responsible for anything you do from following this guide!</p>
<p>When using your own VPS, I suggest setting it up with OpenVPN using the <a href="https://github.com/StreisandEffect/streisand" target="_blank" rel="noopener noreferrer">Streisand</a> project. It has many options to bypass blocking if you live in an oppressive country. Note that the commands below will only install OpenVPN (with stunnel) if using Streisand. Plus, Streisand does a good job at protecting your VPS with security tweaks and automatically updating packages.</p>
<h2>Install OpenVPN</h2>
<p>You can install OpenVPN many different ways. Here are two ways I recommend:</p>
<p>To install OpenVPN via PiVPN, follow these <a href="https://github.com/pivpn/pivpn#installation" target="_blank" rel="noopener noreferrer">steps</a>.</p>
<p>To install (only) OpenVPN (also with stunnel) via Streisand, follow the <a href="https://github.com/StreisandEffect/streisand#prerequisites" target="_blank" rel="noopener noreferrer">prerequisites</a> steps, and then run:</p>
<pre><code>$ remote_server_IP=1.2.3.4  # Change IP to your VPS/remote server IP
$ git clone https://github.com/ryandaniels/ansible-role-dnsmasq-adblock.git ~/ansible/roles/dnsmasq-adblock
$ git clone https://github.com/StreisandEffect/streisand.git &amp;&amp; cd streisand
$ ~/streisand/deploy/streisand-existing-cloud-server.sh --ip-address $remote_server_IP --ssh-user username123 --site-config ~/ansible/roles/dnsmasq-adblock/files/streisand-local-site.yml</code></pre>
<p>Change &#8220;remote_server_IP&#8221; to your server&#8217;s IP.<br />
This will use the user &#8220;username123&#8221; with ssh keys for a <a href="https://www.tecmint.com/ssh-passwordless-login-using-ssh-keygen-in-5-easy-steps/" target="_blank" rel="noopener noreferrer">passwordless ssh connection</a>. Be sure to use a use that you&#8217;ve setup with ssh keys.</p>
<h2>Setup ad blocking for OpenVPN using dnsmasq</h2>
<p>Now that you have OpenVPN setup on a RaspberryPi or your own VPS you are ready for the last step, ad blocking. For this you can use a program called dnsmasq. It performs DNS lookups and you can modify the dnsmasq behaviour to block certain domains.</p>
<h3>Manually install and configure dnsmasq on Ubuntu</h3>
<p>These steps were modified from <a href="https://github.com/BobNisco/adblocking-vpn" target="_blank" rel="noopener noreferrer">this github project by Bob Nisco</a> and also uses <a href="https://github.com/StevenBlack/hosts" target="_blank" rel="noopener noreferrer">Steve Black&#8217;s host project</a>.</p>
<p>Install and configure dnsmasq using the DNS servers from OpenDNS:</p>
<pre><code>$ sudo apt-get -y install dnsmasq
$ sudo wget https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts -O /etc/hosts_blocked

$ sudo cat &gt; /etc/dnsmasq.conf &lt;&lt; 'EOF'
domain-needed
bogus-priv
no-resolv
server=208.67.222.222
server=208.67.220.220
listen-address=127.0.0.1
listen-address=10.8.0.1
addn-hosts=/etc/hosts_blocked
EOF</code></pre>
<p>Configure OpenVPN:</p>
<pre><code>$ sudo vi /etc/openvpn/server.conf</code></pre>
<p>Add below, and make sure no other lines have &#8220;dhcp-option DNS&#8221;:</p>
<pre><code>push "dhcp-option DNS 10.8.0.1"</code></pre>
<p>Create a script to update the domains being blocked. And have it run every week:</p>
<pre><code>$ sudo cat &gt; /etc/cron.weekly/adblock_dl_hosts &lt;&lt; 'EOF'
#!/bin/bash
wget https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts -O /etc/hosts_blocked &amp;&amp; systemctl restart dnsmasq.service
EOF

$ sudo chmod +x /etc/cron.weekly/adblock_dl_hosts</code></pre>
<p>Restart dnsmasq and OpenVPN:</p>
<pre><code>$ sudo systemctl restart dnsmasq.service 
$ sudo systemctl restart openvpn.service</code></pre>
<h3>Using Ansible to automatically install and configure dnsmasq on Ubuntu</h3>
<p>If you are familiar with Ansible, then you can add a new role to handle the installation and configuration of dnsmasq for ad blocking automatically. If you are not familiar with Ansible but want to know more, check out my post explaining <a href="https://ryandaniels.ca/blog/getting-started-ansible-ubuntu-centos/">what is Ansible</a>.</p>
<p>I&#8217;ve created this <a href="https://github.com/ryandaniels/ansible-role-dnsmasq-adblock" target="_blank" rel="noopener noreferrer">Ansible role</a> to configure dnsmasq on Ubuntu or Raspbian.</p>
<p>Create the Ansible Playbook:</p>
<pre><code>$ cat &gt; ~/ansible/install-dnsmasq-adblock.yml &lt;&lt; 'EOF'
---
- hosts: '{{inventory}}'
  become: yes
  roles:
  - dnsmasq-adblock
EOF</code></pre>
<p>If using PiVPN or a normal OpenVPN installation (and not Streisand), clone the git repository and run the Ansible Playbook:</p>
<pre><code>$ git clone https://github.com/ryandaniels/ansible-role-dnsmasq-adblock.git ~/ansible/roles/dnsmasq-adblock
$ ansible-playbook install-dnsmasq-adblock.yml --extra-vars "inventory=openvpn-server" -i hosts</code></pre>
<p>If you are using Streisand, then you already cloned the git repositories. Just run the Ansible Playbook:</p>
<pre><code>$ ansible-playbook install-dnsmasq-adblock.yml --extra-vars "inventory=streisand-host adblock_manage_openvpn=false" -i ~/streisand/inventories/inventory-existing</code></pre>
<h2>Conclusion</h2>
<p>In conclusion, now you are more secure by using OpenVPN with ad blocking on your own Raspberry Pi or VPS. And if you are using your own VPS you can use the Streisand project to secure your installation and also to expose common ports to have a higher chance of being able to connect to your VPN from anywhere.</p>
<p>The post <a href="https://ryandaniels.ca/blog/openvpn-ad-blocking/">How to setup OpenVPN with ad blocking on Raspberry Pi or a VPS</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1117</post-id>	</item>
		<item>
		<title>Firefox privacy and custom settings made easy</title>
		<link>https://ryandaniels.ca/blog/firefox-privacy-settings-made-easy/</link>
		
		<dc:creator><![CDATA[Ryan Daniels]]></dc:creator>
		<pubDate>Thu, 18 Jan 2018 13:22:25 +0000</pubDate>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Guide]]></category>
		<guid isPermaLink="false">https://ryandaniels.ca/?p=1088</guid>

					<description><![CDATA[<p><a href="https://ryandaniels.ca/blog/firefox-privacy-settings-made-easy/"><img class="alignleft size-thumbnail wp-image-1094" src="https://ryandaniels.ca/wp-content/uploads/2018/01/Firefox_Logo-2017-150x150.png" alt="Change Firefox privacy settings with user.js" width="150" height="150" /></a> Firefox is a fast and customizable web browser. And with the latest version called Firefox Quantum it is faster than ever! It is great to load websites fast, but there's another amazing feature. Changing the Firefox privacy settings to be more effective at making user tracking more difficult. And you can make all these changes in a single configuration file.</p>
<p>The post <a href="https://ryandaniels.ca/blog/firefox-privacy-settings-made-easy/">Firefox privacy and custom settings made easy</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><img loading="lazy" decoding="async" class="aligncenter wp-image-1094 size-medium" src="https://ryandaniels.ca/wp-content/uploads/2018/01/Firefox_Logo-2017-300x300.png" alt="Change Firefox privacy settings with user.js" width="300" height="300" srcset="https://ryandaniels.ca/wp-content/uploads/2018/01/Firefox_Logo-2017-300x300.png 300w, https://ryandaniels.ca/wp-content/uploads/2018/01/Firefox_Logo-2017-150x150.png 150w, https://ryandaniels.ca/wp-content/uploads/2018/01/Firefox_Logo-2017-100x100.png 100w, https://ryandaniels.ca/wp-content/uploads/2018/01/Firefox_Logo-2017.png 512w" sizes="auto, (max-width: 300px) 100vw, 300px" /></p>
<p>Firefox is a fast and customizable web browser. And with the latest version called <a href="https://blog.mozilla.org/blog/2017/11/14/introducing-firefox-quantum/" target="_blank" rel="noopener noreferrer">Firefox Quantum</a> (version 57), it is faster than ever! It is great to load websites fast, but there&#8217;s another amazing feature. Changing the Firefox privacy settings to be more effective at making user tracking more difficult.</p>
<p><span id="more-1088"></span></p>
<p>You are hopefully already using a content blocking add-on like <a href="https://addons.mozilla.org/en-US/firefox/addon/ublock-origin/" target="_blank" rel="noopener noreferrer">uBlock Origin</a>, to help eliminate things you don&#8217;t want to see (like maybe one or two ads), and also for your <a href="https://www.technologyreview.com/s/601057/are-ad-blockers-needed-to-stay-safe-online/" target="_blank" rel="noopener noreferrer">online</a> <a href="https://arstechnica.com/information-technology/2018/01/now-even-youtube-serves-ads-with-cpu-draining-cryptocurrency-miners/" target="_blank" rel="noopener noreferrer">safety</a>. Customizing Firefox privacy settings is the next step.</p>
<p>To do this, normally you open a new tab, and type in &#8220;about:config&#8221;. Then you get tons of different settings to modify.</p>
<p>You can end up changing <em>a lot</em> of settings, all manually. But it can be easier, if you know how to save all your settings into a configuration file. And this works cross-platform (on Windows, Mac, Linux) as well.</p>
<h2>The Problem</h2>
<p>Nobody wants to manually type all these changes into Firefox. Especially in multiple places, like in your Firefox browser on your home computer, and your Firefox browser on your work computer.</p>
<h2><a id="what-settings-to-change" href="#what-settings-to-change"></a>What settings to change?</h2>
<p>I keep mentioning changing settings, but what settings should you change? That&#8217;s a very good question. I&#8217;ll group the changes into two categories: Privacy and Usability. If you already know what you are doing, jump ahead to <a href="#how-to-automatically-change-firefox-settings">making the changes</a>. If not, read on.</p>
<h3><a id="firefox-privacy-changes" href="#firefox-privacy-changes"></a>Firefox Privacy related changes</h3>
<p>For some insights into what to change to be more secure, I recommend starting with <a href="https://www.privacytools.io/#about_config" target="_blank" rel="noopener noreferrer">privacytools.io</a>. They have a helpful section for Firefox privacy settings. The entire website is good actually.<br />
Another good resource is <a href="https://ffprofile.com/" target="_blank" rel="noopener noreferrer">Firefox Profilemaker</a>.<br />
Keep in mind you should test after making a change, since websites can stop working!<em><br />
</em></p>
<p>The list of changes that I use is available on <a href="https://gist.github.com/ryandaniels/33e443bb401dde665fce15dd2a3959b6" target="_blank" rel="noopener noreferrer">GitHub</a>.</p>
<p>However, some changes might not work on the websites you use. So again, be sure to test. And take some time to understand what you are changing.</p>
<h3><a id="firefox-usability-changes" href="#firefox-usability-changes"></a>Firefox Usability changes</h3>
<p>These changes are mainly to improve Firefox with my own personal preferences.</p>
<p>The biggest change for me was the tab sizes. I keep many tabs open (yes, probably way too many). And with Firefox 57, I find the tab width gets too small with many tabs open.</p>
<pre>/* Fix tab width too small */
user_pref("browser.tabs.tabMinWidth", 100);

/* Change homepage */
user_pref("browser.startup.homepage", "https://startpage.com/");

/* Increase disk write timer to prevent SSD from dying
 * Source: https://www.servethehome.com/firefox-is-eating-your-ssd-here-is-how-to-fix-it/
 */
user_pref("browser.sessionstore.interval", 120000);

/* Turn off Smooth Scroll */
user_pref("general.smoothScroll", false);

/* Turn off warning on about:config */
user_pref("general.warnOnAboutConfig", false);

/* disable onboarding junk */
user_pref("browser.onboarding.enabled", false);</pre>
<h2><a id="how-to-automatically-change-firefox-settings" href="#how-to-automatically-change-firefox-settings"></a>How to automatically change Firefox settings</h2>
<p>Here are the steps to make all the configuration changes in Firefox. And without having to use &#8220;about:config&#8221;. Put all desired changes into a configuration file and then Firefox reads from this file when it starts.</p>
<p>Here are the steps:</p>
<ol>
<li>Put all of your configuration changes into a file named: <strong>user.js</strong></li>
<li>Open your profile directory, which you can find in &#8220;about:support&#8221; or &#8220;about:profiles&#8221;</li>
<li>Save this file into your profile directory</li>
<li>Restart Firefox. This overrides the previous settings with the user.js file when Firefox starts</li>
<li>Optional: Rename user.js file to something like user-unused.js</li>
</ol>
<p>Renaming user.js  will make sure not to override the settings again, in case you do make the changes in &#8220;about:config&#8221;. However, it could be good to keep this file in place in case Mozilla gets any ideas about changing your default search engine without asking you (if you have that in user.js of course). Not that Mozilla would ever do <a href="https://blog.mozilla.org/blog/2017/11/14/firefox-features-google-as-default-search-provider-in-the-u-s-canada-hong-kong-and-taiwan/" target="_blank" rel="noopener noreferrer">something</a> like <a href="https://www.reddit.com/r/firefox/comments/7hwr4o/startpage_firefoxs_latest_update_5701/" target="_blank" rel="noopener noreferrer">that</a>..</p>
<h2>Conclusion</h2>
<p>To summarize, now you have put all your Firefox privacy and usability settings into your user.js file. You can now copy this file to your other Firefox profiles, on your other computers, and automatically have the same settings loaded into Firefox. As an added bonus, you have now made user tracking more difficult.</p>
<p>Have a question? <a href="https://ryandaniels.ca/contact/">Contact me</a>.</p>
<p>The post <a href="https://ryandaniels.ca/blog/firefox-privacy-settings-made-easy/">Firefox privacy and custom settings made easy</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></content:encoded>
					
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">1088</post-id>	</item>
		<item>
		<title>WordPress Security &#8211; How to Protect WordPress</title>
		<link>https://ryandaniels.ca/blog/wordpress-security-how-to-protect-wordpress/</link>
					<comments>https://ryandaniels.ca/blog/wordpress-security-how-to-protect-wordpress/#comments</comments>
		
		<dc:creator><![CDATA[Ryan Daniels]]></dc:creator>
		<pubDate>Sun, 22 Dec 2013 20:02:30 +0000</pubDate>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Guide]]></category>
		<category><![CDATA[WordPress Security]]></category>
		<guid isPermaLink="false">http://ryandaniels.ca/?p=584</guid>

					<description><![CDATA[<p>WordPress Security is very important. It is much easier spending a few minutes securing WordPress, then spending hours recovering from being hacked. Security is becoming even more important because of the increase in automated brute force WordPress attacks. Below are a several tips to help secure WordPress and Apache. If you have your own server or VPS, to help reduce brute force attacks a very good solution is to use CloudFlare custom "Page Rules". That will stop the requests before even getting to your server. WordPress security doesn't sound like an exciting topic, but it is important so read on!</p>
<p>The post <a href="https://ryandaniels.ca/blog/wordpress-security-how-to-protect-wordpress/">WordPress Security &#8211; How to Protect WordPress</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></description>
										<content:encoded><![CDATA[<p><img loading="lazy" decoding="async" class="size-full wp-image-683 alignnone" title="wordpress security lock" src="https://ryandaniels.ca/wp-content/uploads/2013/12/lock.jpg" alt="wordpress security lock" width="500" height="375" srcset="https://ryandaniels.ca/wp-content/uploads/2013/12/lock.jpg 500w, https://ryandaniels.ca/wp-content/uploads/2013/12/lock-300x225.jpg 300w" sizes="auto, (max-width: 500px) 100vw, 500px" /></p>
<p>WordPress Security is very important. It is much easier spending a few minutes securing WordPress, then spending hours recovering from being hacked. Security is becoming even more important because of the increase in automated brute force WordPress attacks. Below are a several tips to help secure WordPress and Apache. If you have your own server or VPS (like <a href="https://ryandaniels.ca/go/linode/" target="_blank" rel="nofollow noopener noreferrer">Linode</a> or <a href="https://ryandaniels.ca/go/vultr/" target="_blank" rel="nofollow noopener noreferrer">Vultr</a>), to help reduce brute force attacks a very good solution is to use CloudFlare custom &#8220;Page Rules&#8221;. That will stop the requests before even getting to your server. WordPress security doesn&#8217;t sound like an exciting topic, but it is important so read on!</p>
<p>To help reduce other vulnerabilities follow the rest of the tips to improve WordPress security. The best advice for this is to stay updated and delete ALL unused themes and plugins. An old theme or plugin that is no longer being developed is potentially very easy for an attacker to exploit through an old vulnerability. This is most likely how an attacker puts a backdoor into a site since WordPress on its own is secure.</p>
<p>Any comments, questions or suggestions are welcome in the comments section at the bottom or from the <a title="Contact" href="https://ryandaniels.ca/contact/">contact page</a>.</p>
<p>2013/12/31: Added information about minimizing number of plugins and OSSEC.<br />
2014/09/29: CloudFlare offers free HTTPS.<br />
2016/09/28: Update from 5G Blacklist to 6G Firewall, and add blocking for xmlrpc.php.</p>
<p>&nbsp;</p>
<h2>#1. Stay updated</h2>
<p>Keep WordPress, themes and plugins updated. Also if you run WordPress on your own server or VPS keep apache, php5 and other packages up to date. This is the most important for WordPress security and also general web server security.</p>
<p>&nbsp;</p>
<h2>#2. Delete unused themes and plugins</h2>
<p>Deactivating a theme or plugin that isn&#8217;t in use is not good enough. It needs to be completely deleted because the files can still be accessed (and exploited). This is probably the most common way an attacker will gain access to your server and a major benefit to improve WordPress security in general. Another good practice is to reduce the number of plugins running. If you don&#8217;t really need it, then delete it.</p>
<p>&nbsp;</p>
<h2>#3. Activate CloudFlare</h2>
<p>Use CloudFlare&#8217;s free service to utilize them as a CDN and more importantly use their built in security features. You can also try to use IPtables to block brute force attacks, but a much simpler solution is to use CloudFlare.<br />
The only negative about the free CloudFlare service is that it cannot use HTTPS. (That is a paid only feature).<br />
To use CloudFlare you must be able to edit the DNS settings of your domain (to change the NS records).<br />
When using CloudFlare make sure to setup custom &#8220;Page Rules&#8221;. <strong>This will greatly reduce the login requests that make it to your server</strong>. What better way to improve WordPress security than to not even get the malicious requests!</p>
<p>Setup &#8220;Page Rules&#8221; using URL Pattern: &#8220;/wp-login.php*&#8221; (without quotes)<br />
Change:<br />
Always Online: Off<br />
Security Level: I&#8217;m Under Attack<br />
Browser Integrity Check: On</p>
<p>This will use Cloudflare to verify every login attempt (even your own) before getting to your server. After this change there will be very little traffic to the WordPress login page, since CloudFlare will be blocking most (if not all) of it.</p>
<p><a href="https://ryandaniels.ca/wp-content/uploads/2013/12/cloudflare-page-rule.jpg" rel="lightbox[584]"><img loading="lazy" decoding="async" src="https://ryandaniels.ca/wp-content/uploads/2013/12/cloudflare-page-rule-272x300.jpg" alt="cloudflare page rule to help wordpress security" width="272" height="300" /></a></p>
<p>&nbsp;</p>
<h2>#4. Remove the default &#8220;admin&#8221; account</h2>
<p>Make sure the admin account is removed. This is one of the basic steps to improve WordPress security since automated attacks usually focus on this login, and if it isn&#8217;t there then it can&#8217;t be exploited.</p>
<p>Create another account with administrator privileges and then delete the admin account, or use a plugin that is mentioned below.</p>
<p>&nbsp;</p>
<h2>#5. Secure Passwords</h2>
<p>Be sure to use a very secure password of random characters consisting of upper case, lower case, numbers and punctuation. Even if someone figures out the login name it will still be relatively secure if a strong password is used.</p>
<p>&nbsp;</p>
<h2>#6. Restrict access to WordPress login using .htaccess</h2>
<p>It is a very good idea the restrict access to wp-login.php and the wp-admin directory to help with WordPress security and security in general. By restricting these pages based on an IP address it will cause anyone other than that IP to be blocked from logging in. CloudFlare is also a very good option (as previously mentioned) to help block access to logging in. If an attacker does get past the CloudFlare security, they will likely not get past this.</p>
<p>If you use CloudFlare use the first entry. Use either your exact IP or an IP range. You will probably need an IP range if your IP address changes often. Note that these requests still make it to your server. To further block access use CloudFlare page rules (as previously mentioned) if you can.</p>
<p><strong>Be careful editing .htaccess files since you could potentially lock yourself out of WordPress. It&#8217;s best to have SSH access to your server.</strong></p>
<h3>For wp-login.php edit the main .htaccess file</h3>
<p>If using CloudFlare (commented out line is for an IP range):</p>
<pre><code>&lt;files wp-login.php&gt;
#SetEnvIf X-FORWARDED-FOR "^1\.*\.*\.*" allow
SetEnvIf X-FORWARDED-FOR "1.1.1.1" allow
order deny,allow
deny from all
allow from env=allow
&lt;/files&gt;
</code></pre>
<p>If not using CloudFlare (commented out line is for an IP range):</p>
<pre><code>&lt;files wp-login.php&gt;
order deny,allow
deny from all
#allow from 1.0.0.0/8
allow from 1.1.1.1
&lt;/files&gt;
</code></pre>
<p>&nbsp;</p>
<p><span style="font-size: 20px; letter-spacing: -0.02em; line-height: normal;">For wp-admin restriction edit the .htaccess file inside wp-admin directory</span></p>
<p>If using CloudFlare (commented out line is for an IP range):</p>
<pre><code>SetEnvIf X-FORWARDED-FOR "1.1.1.1" allow
#SetEnvIf X-FORWARDED-FOR "^1\.*\.*\.*" allow
order deny,allow
deny from all
allow from env=allow

&lt;Files admin-ajax.php&gt;
    Order allow,deny
    Allow from all
    Satisfy any
&lt;/Files&gt;
</code></pre>
<p>If not using CloudFlare (commented out line is for an IP range):</p>
<pre><code>order deny,allow
deny from all
allow from 1.1.1.1
#allow from 1.0.0.0/8

&lt;Files admin-ajax.php&gt;
    Order allow,deny
    Allow from all
    Satisfy any
&lt;/Files&gt;</code></pre>
<p>&nbsp;</p>
<h2>#7. Reduce malicious URL requests</h2>
<p>Use the <a title="6G Firewall 2016" href="https://perishablepress.com/6g/" target="_blank" rel="noopener noreferrer">6G Firewall 2016</a> to reduce malicious URL requests. The list should be put at the beginning of the main .htaccess file. This helps in WordPress security since it stops an attack before it gets to the WordPress layer.</p>
<p>&nbsp;</p>
<h2>#8. Rename WordPress tables prefix</h2>
<p>When first installing WordPress make sure to change the table prefix from the default &#8220;wp_&#8221;. If WordPress is already installed a plugin (like Acunetix WP Security, more on that below) can be used to easily make the change to something random like &#8220;notforyou_&#8221;. This will help WordPress security since attackers are less likely perform SQL injection attacks.</p>
<p>&nbsp;</p>
<h2>#9. Use WordPress Security Keys</h2>
<p>Use the WordPress Security keys to make your stored passwords more secure and also by changing them it forces anyone that&#8217;s already logged in to re-authenticate. Overwrite the keys in the wp-config.php file after generating them <a title="WordPress Security Keys" href="http://codex.wordpress.org/Editing_wp-config.php#Security_Keys" target="_blank" rel="noopener noreferrer">here</a>.</p>
<p>&nbsp;</p>
<h2>#10. Other tweaks using .htaccess</h2>
<p>Remove access to readme.html and access to other unnecessary WordPress related files. This will improve WordPress security since it will be harder to determine the WordPress version. This also blocks other WordPress specific files. Blocking the xmlrpc.php file is a really good idea to prevent brute force login attempts unless you use the JetPack plugin, or another 3rd party tool to edit your posts.</p>
<p>Put at the bottom of main .htaccess file (After 6G Firewall 2016 and WordPress entries).</p>
<pre><code>&lt;files readme.html&gt;
Order allow,deny
Deny from all
&lt;/files&gt;
&lt;files license.txt&gt;
Order allow,deny
Deny from all
&lt;/files&gt;
&lt;files install.php&gt;
Order allow,deny
Deny from all
&lt;/files&gt;
&lt;files wp-config.php&gt;
Order allow,deny
Deny from all
&lt;/files&gt;
&lt;files xmlrpc.php&gt;
Order allow,deny
Deny from all
&lt;/files&gt;
</code></pre>
<p>&nbsp;</p>
<h2>#11. Remove WordPress version information</h2>
<p>If an attacker doesn&#8217;t know the version of WordPress it can be harder to exploit since they can&#8217;t target a known vulnerability of an older version. This will help to improve WordPress security but there are many ways a determined attacker can gather this information. This will help with the basic attacks.<br />
Edit the child theme&#8217;s functions.php file to include:</p>
<pre><code>function wpnohead_remove_version() {
return '';
}
add_filter('the_generator', 'wpnohead_remove_version');</code></pre>
<p>&nbsp;</p>
<h2>#12. Disable file editing in WordPress</h2>
<p>If an attacker gains access through WordPress they can&#8217;t do much damage if they are unable to edit files on the server which will improve WordPress security.</p>
<p>Edit wp-config.php to include:</p>
<pre><code>define( 'DISALLOW_FILE_EDIT', true );
define( 'DISALLOW_FILE_MODS', true );
</code></pre>
<p>&nbsp;</p>
<h2>#13. HTTPS for logins</h2>
<p>If possible use HTTPS for logins. <del>When using the free CloudFlare service this is not possible since only paid users can use HTTPS.</del> CloudFlare now offers free HTTPS for everyone, so this will work if you are using CloudFlare.<br />
If you can use HTTPS put this in wp-config.php (see <a title="Administration Over SSL" href="http://codex.wordpress.org/Administration_Over_SSL" target="_blank" rel="noopener noreferrer">info</a>):</p>
<pre><code>define('FORCE_SSL_LOGIN', true);</code></pre>
<p>&nbsp;</p>
<h2>#14. Take regular backups</h2>
<p>This doesn&#8217;t help WordPress security directly, but in general it is a very good idea. Use the plugin <a title="WP-DBManager" href="http://wordpress.org/plugins/wp-dbmanager/" target="_blank" rel="noopener noreferrer">WP-DBManager</a> to schedule automatic backups that can be emailed to you. If an attacker does get in this will help in the recovery.</p>
<p>&nbsp;</p>
<h2>#15. Security Plugins</h2>
<p>Here are some security plugins that can come in handy to help with WordPress security.</p>
<p><a title="Better WP Security" href="http://wordpress.org/plugins/better-wp-security/" target="_blank" rel="noopener noreferrer">Better WP Security</a> &#8211; Can move login pages, rename admin account and change database table prefix. Moving login pages can help, since the attacker can&#8217;t easily find where to login (security through obscurity), but this isn&#8217;t needed if other measures are followed (Restrict access using .htaccess and CloudFlare page rules).</p>
<p><a title="Acunetix WP Security" href="http://wordpress.org/plugins/wp-security-scan/" target="_blank" rel="noopener noreferrer">Acunetix WP Security</a> &#8211; Can change database table prefix and perform some useful security audits. Checking files for date changes isn&#8217;t very useful since attackers can change timestamps of the files if they are already in your system.</p>
<p><a title="Wordfence Security" href="http://wordpress.org/plugins/wordfence/" target="_blank" rel="noopener noreferrer">Wordfence Security</a> &#8211; Scans for known vulnerabilities. Another good feature is it scans core files, themes and plugins against WordPress.org repository versions to check their integrity. Verifying the security of your source. If/when you remove this plugin make sure to enable the option to remove all of the Wordfence options from your database, otherwise a large amount of data is sitting there. Option is at the bottom of the Wordfence &#8216;options&#8217; page titled: &#8220;Delete Wordfence tables and data on deactivation?&#8221;</p>
<p><a title="Limit Login Attempts" href="http://wordpress.org/plugins/limit-login-attempts/" target="_blank" rel="noopener noreferrer">Limit Login Attempts</a> &#8211; Useful if the same IP address keeps trying to login. But with the recent attacks there are many IP addresses trying to brute force the login and password. This plugin is no longer very useful.</p>
<p><a title="AskApache Password Protect" href="http://wordpress.org/plugins/askapache-password-protect/" target="_blank" rel="noopener noreferrer">AskApache Password Protect</a> &#8211; Password protect logins using Apache built in security.</p>
<p><a title="Google Authenticator" href="http://wordpress.org/plugins/google-authenticator/" target="_blank" rel="noopener noreferrer">Google Authenticator</a> &#8211; Two-factor authentication using the Google Authenticator app for Android/iPhone/Blackberry.</p>
<p><a title="Threat Scan Plugin" href="http://wordpress.org/plugins/threat-scan-plugin/" target="_blank" rel="noopener noreferrer">Threat Scan Plugin</a> &#8211; Scans PHP files for backdoors added by hackers.</p>
<p><a title="6Scan Security" href="http://wordpress.org/plugins/6scan-protection/" target="_blank" rel="noopener noreferrer">6Scan Security</a> &#8211; Another option to use. Haven&#8217;t tried it yet.</p>
<p><a title="All In One WP Security &amp; Firewall" href="http://wordpress.org/plugins/all-in-one-wp-security-and-firewall/" target="_blank" rel="noopener noreferrer">All In One WP Security &amp; Firewall</a> &#8211; Another option to use. Haven&#8217;t tried it yet.</p>
<p>&nbsp;</p>
<h2>#16. Apache tweaks</h2>
<p>If you have access to the main Apache configuration add the below lines. This isn&#8217;t specifically for WordPress security, it&#8217;s for the overall web server (Apache) security. Another obvious Apache security measure is to make sure Apache runs as a non-root user.</p>
<p>Prevent listing the index of folders.<br />
In apache&#8217;s virtual host configuration files make sure to have:</p>
<pre><code>Options -Indexes</code></pre>
<p>Remove server signature (from error pages, etc) and remove server version from header requests.<br />
In httpd.conf add these lines to the bottom:</p>
<pre><code>ServerSignature Off
ServerTokens Prod</code></pre>
<p>&nbsp;</p>
<h2>#17. Use SFTP</h2>
<p>Do not use regular FTP since it is insecure. FTP login and password information is sent unencrypted. This is a general security tip and not really specific to WordPress security.</p>
<p>&nbsp;</p>
<h2>#18. Monitor Apache logs</h2>
<p>Check the Apache logs for any errors or abnormal URL requests. This seems trivial but it is a very important step to ensure your site is working smoothly and there is no abnormal behaviour.</p>
<p>If using CloudFlare, make sure to <a title="Logging Real Visitor IP Addresses: mod_cloudflare for Apache httpd" href="https://www.cloudflare.com/resources-downloads" target="_blank" rel="noopener noreferrer">install the CloudFlare module for Apache</a> so the visitor IPs are in the logs and not the CloudFlare IPs.</p>
<p>&nbsp;</p>
<h2>#19. Host-based Intrusion Detection System (OSSEC)</h2>
<p>Install a program that runs on the server to monitor the system&#8217;s health and check for exploits. A program like <a title="OSSEC" href="http://www.ossec.net/" target="_blank" rel="noopener noreferrer">OSSEC</a> is a good choice.</p>
<p>&nbsp;</p>
<h2>Other Notes</h2>
<p>Port knocking with IPTables for WordPress logins is another option to provide further security through obscurity, but this is complicated and beyond the scope of this post about improving WordPress security.</p>
<p>Fail2Ban is another option to scan the Apache logs but this causes excessive load on the server and is not needed with all the changes above.</p>
<p>Another unnecessary but interesting option is hiding a custom field in the login form and using a browser extension to set that field only in your browser. But again this is now not needed.</p>
<p>&nbsp;</p>
<p>Any comments, questions or suggestions are welcome in the comments section below or from the <a title="Contact" href="https://ryandaniels.ca/contact/">contact page</a>.</p>
<p>&nbsp;</p>
<h2>References</h2>
<p><a title="Hardening WordPress" href="http://codex.wordpress.org/Hardening_WordPress" target="_blank" rel="noopener noreferrer">Hardening WordPress</a><br />
<a title="WordPress Consultant" href="https://rdwebconsulting.com/" target="_blank" rel="noopener noreferrer">WordPress Consultant</a><br />
<a title="Prevent badware: WordPress" href="https://www.stopbadware.org/prevent-badware-wordpress" target="_blank" rel="noopener noreferrer">Prevent badware: WordPress</a><br />
<a title="How to Protect WordPress Sites" href="http://webdesignerwall.com/general/how-to-protect-wordpress-sites" target="_blank" rel="noopener noreferrer">How to Protect WordPress Sites</a><br />
<a title="6G Firewall 2016" href="https://perishablepress.com/6g/" target="_blank" rel="noopener noreferrer">6G Firewall 2016</a><br />
<a title="How To Protect WordPress from Intrusion: Your Must-Read Checklist" href="http://www.makeuseof.com/tag/how-to-protect-wordpress-from-intrusion-si-x2/" target="_blank" rel="noopener noreferrer">How To Protect WordPress from Intrusion: Your Must-Read Checklist</a><br />
<a title="How to Improve the Security of your WordPress Blog" href="http://www.labnol.org/internet/improve-wordpress-security/" target="_blank" rel="noopener noreferrer">How to Improve the Security of your WordPress Blog</a><br />
<a title="The Definitive Guide to WP Security" href="http://moz.com/blog/the-definitive-guide-to-wordpress-security" target="_blank" rel="noopener noreferrer">The Definitive Guide to WP Security</a><br />
<a title="How to Password Protect Your WordPress Admin (wp-admin) Directory" href="http://www.wpbeginner.com/wp-tutorials/how-to-password-protect-your-wordpress-admin-wp-admin-directory/" target="_blank" rel="noopener noreferrer">How to Password Protect Your WordPress Admin (wp-admin) Directory</a><br />
<a title="Protect your wp-admin with this quick .htaccess trick" href="http://wordpress.damien.co/2013/04/wordpress-security-protect-your-wp-admin-with-this-quick-htaccess-trick/" target="_blank" rel="noopener noreferrer">Protect your wp-admin with this quick .htaccess trick</a><br />
<a title="Password Protect your WordPress Admin Folder" href="http://ctrlq.org/code/19247-password-protect-wordpress-admin" target="_blank" rel="noopener noreferrer">Password Protect your WordPress Admin Folder</a></p>
<p>&nbsp;</p>
<p>The post <a href="https://ryandaniels.ca/blog/wordpress-security-how-to-protect-wordpress/">WordPress Security &#8211; How to Protect WordPress</a> appeared first on <a href="https://ryandaniels.ca/">Ryan Daniels</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss></wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">584</post-id>	</item>
	</channel>
</rss>
