{"id":3141,"date":"2014-09-24T21:04:57","date_gmt":"2014-09-24T21:04:57","guid":{"rendered":"http:\/\/www.deuzebranaweb.com.br\/?p=3141"},"modified":"2014-09-24T21:04:57","modified_gmt":"2014-09-24T21:04:57","slug":"htaccess-regras-para-parar-ddos-post-flooding","status":"publish","type":"post","link":"https:\/\/blog.deuzebranaweb.com.br\/index.php\/2014\/09\/24\/htaccess-regras-para-parar-ddos-post-flooding\/","title":{"rendered":".htaccess regras para parar DDoS POST flooding"},"content":{"rendered":"<p>Como ja havia citado no posta abaixo:<\/p>\n<p>http:\/\/www.deuzebranaweb.com.br\/2014\/09\/24\/scripts-milagrosos-para-bloquear-ataques-ddos-utilizando-o-iptables\/<\/p>\n<p>&nbsp;<\/p>\n<pre><code>&lt;Limit POST&gt;\nDeny from all\n&lt;\/Limit&gt;<\/code><\/pre>\n<p>While monitoring hits to this blog, I recognize that the file which received most hits is <code>xmlrpc.php<\/code>. I was surprise because I don\u2019t use XML-RPC for remote access, posting at all. I guess the problem may comes from bots, spammers or even hackers. So I decided to <strong>disable XML-RPC<\/strong> completely and here is how I did that.<\/p>\n<h2>What is XML-RPC?<\/h2>\n<p>According to <a href=\"http:\/\/en.wikipedia.org\/wiki\/XML-RPC\">Wikipedia<\/a>, <strong>XML-RPC<\/strong> is a <strong>R<\/strong>emote <strong>P<\/strong>rocedure <strong>C<\/strong>all (RPC) protocol which uses <strong>XML<\/strong> to encode its calls and HTTP as a transport mechanism. XML-RPC also refers generically to the use of XML for remote procedure call, independently of the specific protocol.<\/p>\n<p>Briefly, you use XML-RPC when you want to do something remotely to your blog such as posting, viewing comments, etc.<\/p>\n<h2>How XML-RPC is used in WordPress?<\/h2>\n<p>By default, <a href=\"http:\/\/codex.wordpress.org\/XML-RPC_Support\"><strong>WordPress 3.5+ enables XML-RPC automatically<\/strong><\/a>! It was under user control in previous versions but that option was removed in version 3.5 as WordPress thinks it should be enable by default.<\/p>\n<p>WordPress creates <a href=\"http:\/\/codex.wordpress.org\/XML-RPC_WordPress_API\">its own API<\/a> for XML-RPC to let us interact (get, read, edit, post, etc.) posts, comments, taxonomies, media, users and even options which means everything!<\/p>\n<p>But <strong>where you can find application of XML-RPC in WordPress<\/strong>?<\/p>\n<p>The answer is many places:<br \/>\n\u2013 Pingback<br \/>\n\u2013 JSON API<br \/>\n\u2013 iPhone\/Android app<br \/>\n\u2013 Remote posting by Microsoft Word for example. <a href=\"http:\/\/wpmu.org\/how-to-use-microsoft-word-to-publish-directly-to-your-wordpress-site\/\">Here is guide<\/a><br \/>\n\u2013 Your own apps, perhaps!<\/p>\n<h2>How to disable XML-RPC in WordPress<\/h2>\n<p>As I said earlier, enabling XML-RPC without knowing about its functionality is no different to open a backdoor for spammers and hackers. It sometimes just wastes your server\/hosting resources. Disable it if you don\u2019t need.<\/p>\n<p>First of all, you need to turn off XML-RPC functionality in WordPress, using this code (you better put it in a <a href=\"http:\/\/wpcandy.com\/teaches\/how-to-create-a-functionality-plugin\/#.UgpGwJJT6rw\">functionality plugin<\/a>):<\/p>\n<ol class=\"linenums\">\n<li class=\"L0\"><code><span class=\"pln\">add_filter<\/span><span class=\"pun\">(<\/span> <span class=\"str\">'xmlrpc_enabled'<\/span><span class=\"pun\">,<\/span> <span class=\"str\">'__return_false'<\/span> <span class=\"pun\">);<\/span><\/code><\/li>\n<\/ol>\n<p>This simple line tells WordPress to stop all remote requests using XML-RPC. But if you use a tool to check HTTP headers, you still see the link to <code>xmlrpc.php<\/code>:<\/p>\n<p><img decoding=\"async\" title=\"Disable XML RPC in WordPress   Complete Guide\" src=\"http:\/\/www.deluxeblogtips.com\/wp-content\/uploads\/2013\/08\/disable-xmlrpc-wordpress.png\" alt=\"disable xmlrpc wordpress Disable XML RPC in WordPress   Complete Guide\" \/><\/p>\n<p>Here I use a <a href=\"http:\/\/redbot.org\">RedBot.org<\/a> to check HTTP headers. It\u2019s very simple but works better than any tool I\u2019ve used.<\/p>\n<p>The present of <code>xmlrpc.php<\/code> in HTTP headers is a sign that tells spammers, bots that I\u2019m still open a door for you. And you keep receiving hits to that door, even all hits are denied by WordPress. That wastes resources!<\/p>\n<p>So, to hide <code>xmlrpc.php<\/code> in HTTP response headers, you need the following code (in functionality plugin):<\/p>\n<ol class=\"linenums\">\n<li class=\"L0\"><code><span class=\"pln\">add_filter<\/span><span class=\"pun\">(<\/span> <span class=\"str\">'wp_headers'<\/span><span class=\"pun\">,<\/span> <span class=\"str\">'yourprefix_remove_x_pingback'<\/span> <span class=\"pun\">);<\/span><\/code><\/li>\n<li class=\"L1\"><code><span class=\"kwd\">function<\/span><span class=\"pln\"> yourprefix_remove_x_pingback<\/span><span class=\"pun\">(<\/span><span class=\"pln\"> $headers <\/span><span class=\"pun\">)<\/span><\/code><\/li>\n<li class=\"L2\"><code><span class=\"pun\">{<\/span><\/code><\/li>\n<li class=\"L3\"><code><span class=\"pln\"> unset<\/span><span class=\"pun\">(<\/span><span class=\"pln\"> $headers<\/span><span class=\"pun\">[<\/span><span class=\"str\">'X-Pingback'<\/span><span class=\"pun\">]<\/span> <span class=\"pun\">);<\/span><\/code><\/li>\n<li class=\"L4\"><code> <span class=\"kwd\">return<\/span><span class=\"pln\"> $headers<\/span><span class=\"pun\">;<\/span><\/code><\/li>\n<li class=\"L5\"><code><span class=\"pun\">}<\/span><\/code><\/li>\n<\/ol>\n<p>That\u2019s enough for WordPress. From now spammers and bots don\u2019t know URL to <code>xmlrpc.php<\/code> and if they <em>guess<\/em> correct URL, their requests are denied <strong>by WordPress<\/strong>.<\/p>\n<p>But there\u2019s still a room to improve the performance. Instead of making WordPress handles requests to <code>xmlrpc.php<\/code>, why don\u2019t we make web server like Apache or nginx handle them? Requests will be denied in a lower layer of application, thus improving performance in general.<\/p>\n<h2>Denied requests to <code>xmlrpc.php<\/code> by Apache or nginx<\/h2>\n<p>Jeff Starr at Perishable wrote a <a href=\"http:\/\/perishablepress.com\/wordpress-xmlrpc-pingback-vulnerability\/\">very detailed post<\/a> about how to deny request to <code>xmlrpc.php<\/code> using <code>.htaccess<\/code>. The code for <code>.htaccess<\/code> is very simple:<\/p>\n<ol class=\"linenums\">\n<li class=\"L0\"><code><span class=\"tag\">&lt;IfModule<\/span> <span class=\"atn\">mod_alias<\/span><span class=\"pln\">.<\/span><span class=\"atn\">c<\/span><span class=\"tag\">&gt;<\/span><\/code><\/li>\n<li class=\"L1\"><code><span class=\"pln\"> RedirectMatch 403 \/xmlrpc.php<\/span><\/code><\/li>\n<li class=\"L2\"><code><span class=\"tag\">&lt;\/IfModule&gt;<\/span><\/code><\/li>\n<\/ol>\n<p>or<\/p>\n<ol class=\"linenums\">\n<li class=\"L0\"><code><span class=\"tag\">&lt;Files<\/span> <span class=\"atn\">xmlrpc<\/span><span class=\"pln\">.<\/span><span class=\"atn\">php<\/span><span class=\"tag\">&gt;<\/span><\/code><\/li>\n<li class=\"L1\"><code><span class=\"pln\"> Order Deny,Allow<\/span><\/code><\/li>\n<li class=\"L2\"><code><span class=\"pln\"> Deny from all<\/span><\/code><\/li>\n<li class=\"L3\"><code><span class=\"tag\">&lt;\/Files&gt;<\/span><\/code><\/li>\n<\/ol>\n<p>If you want to redirect hits to <code>xmlrpc.php<\/code> to another website\/URL, use this code:<\/p>\n<ol class=\"linenums\">\n<li class=\"L0\"><code><span class=\"tag\">&lt;IfModule<\/span> <span class=\"atn\">mod_alias<\/span><span class=\"pln\">.<\/span><span class=\"atn\">c<\/span><span class=\"tag\">&gt;<\/span><\/code><\/li>\n<li class=\"L1\"><code><span class=\"pln\"> Redirect 301 \/xmlrpc.php http:\/\/example.com\/custom-page.php<\/span><\/code><\/li>\n<li class=\"L2\"><code><span class=\"tag\">&lt;\/IfModule&gt;<\/span><\/code><\/li>\n<\/ol>\n<p>If you\u2019re using nginx, this is the code you should add to <code>server<\/code> block:<\/p>\n<ol class=\"linenums\">\n<li class=\"L0\"><code><span class=\"pln\">server <\/span><span class=\"pun\">{<\/span><\/code><\/li>\n<li class=\"L1\"><code> <span class=\"com\"># stuff<\/span><\/code><\/li>\n<li class=\"L2\"><code><span class=\"pln\"> location <\/span><span class=\"pun\">=<\/span> <span class=\"pun\">\/<\/span><span class=\"pln\">xmlrpc<\/span><span class=\"pun\">.<\/span><span class=\"pln\">php <\/span><span class=\"pun\">{<\/span><\/code><\/li>\n<li class=\"L3\"><code><span class=\"pln\"> deny all<\/span><span class=\"pun\">;<\/span><\/code><\/li>\n<li class=\"L4\"><code> <span class=\"pun\">}<\/span><\/code><\/li>\n<li class=\"L5\"><code><span class=\"pun\">}<\/span><\/code><\/li>\n<\/ol>\n<p>That\u2019s all. Your blog is fully protected from unexpected remote requests using XML-RPC. And hopefully it saves server resources and improve website performance.<\/p>\n<pre><code>\n\n\nhttp:\/\/www.deluxeblogtips.com\/2013\/08\/disable-xml-rpc-wordpress.html\nhttp:\/\/www.linuxquestions.org\/questions\/linux-server-73\/iptables-rate-limit-to-block-ddos-931931\/ http:\/\/www.vivaolinux.com.br\/topico\/Squid-Iptables\/Bloqueando-ataque-DoS-no-Iptables No linux tem algo para o IPtables mas como entra pelo M$ s\u00f3 Deus Sabe. <\/code><\/pre>\n<div>###### Protege contra synflood<br \/>\n\/sbin\/iptables -A FORWARD -p tcp &#8211;syn -m limit &#8211;limit 1\/s -j ACCEPT<br \/>\necho 1 &gt; \/proc\/sys\/net\/ipv4\/tcp_syncookies###### Protecao contra ICMP Broadcasting<br \/>\n#echo 1 &gt; \/proc\/sys\/net\/ipv4\/icmp_echo_ignore_broadcasts<br \/>\n#echo 1 &gt; \/proc\/sys\/net\/ipv4\/icmp_echo_ignore_all<br \/>\n###### Prote.. Contra IP Spoofing<br \/>\necho 1 &gt; \/proc\/sys\/net\/ipv4\/conf\/all\/rp_filter###### Protecao diversas contra portscanners, ping of death, ataques DoS, pacotes danificados e etc.<br \/>\n\/sbin\/iptables -A FORWARD -p icmp &#8211;icmp-type echo-request -m limit &#8211;limit 1\/s -j ACCEPT<br \/>\n\/sbin\/iptables -A INPUT -p icmp &#8211;icmp-type echo-request -m limit &#8211;limit 1\/s -j ACCEPT<br \/>\n\/sbin\/iptables -A INPUT -i eth1 -p icmp &#8211;icmp-type echo-reply -m limit &#8211;limit 1\/s -j DROP<br \/>\n\/sbin\/iptables -A FORWARD -p tcp -m limit &#8211;limit 1\/s -j ACCEPT<br \/>\n\/sbin\/iptables -A FORWARD -m state &#8211;state ESTABLISHED,RELATED -j ACCEPT<br \/>\n\/sbin\/iptables -A FORWARD -p tcp &#8211;tcp-flags SYN,ACK,FIN,RST RST -m limit &#8211;limit 1\/s -j ACCEPT<br \/>\n\/sbin\/iptables -A FORWARD &#8211;protocol tcp &#8211;tcp-flags ALL SYN,ACK -j DROP<br \/>\n\/sbin\/iptables -A INPUT -m state &#8211;state INVALID -j DROP<br \/>\n\/sbin\/iptables -A FORWARD -m state &#8211;state ESTABLISHED,RELATED -j ACCEPT<br \/>\n\/sbin\/iptables -N VALID_CHECK<br \/>\n\/sbin\/iptables -A VALID_CHECK -p tcp &#8211;tcp-flags ALL FIN,URG,PSH -j DROP<br \/>\n\/sbin\/iptables -A VALID_CHECK -p tcp &#8211;tcp-flags ALL SYN,RST,ACK,FIN,URG -j DROP<br \/>\n\/sbin\/iptables -A VALID_CHECK -p tcp &#8211;tcp-flags ALL ALL -j DROP<br \/>\n\/sbin\/iptables -A VALID_CHECK -p tcp &#8211;tcp-flags ALL FIN -j DROP<br \/>\n\/sbin\/iptables -A VALID_CHECK -p tcp &#8211;tcp-flags SYN,RST SYN,RST -j DROP<br \/>\n\/sbin\/iptables -A VALID_CHECK -p tcp &#8211;tcp-flags SYN,FIN SYN,FIN -j DROP<br \/>\n\/sbin\/iptables -A VALID_CHECK -p tcp &#8211;tcp-flags ALL NONE -j DROP## Limitando conex..es na porta 80 #######<br \/>\n\/sbin\/iptables -I INPUT -p tcp &#8211;dport 80 -i eth1 -m state &#8211;state NEW -m recent &#8211;set<\/p>\n<p>\/sbin\/iptables -I INPUT -p tcp &#8211;dport 80 -i eth1 -m state &#8211;state NEW -m recent &#8211;update &#8211;seconds 1 &#8211;hitcount 10 -j DROP<\/p>\n<\/div>\n<pre><code>http:\/\/www.vivaolinux.com.br\/topico\/Squid-Iptables\/Bloqueando-ataque-DoS-no-Iptables<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Como ja havia citado no posta abaixo: http:\/\/www.deuzebranaweb.com.br\/2014\/09\/24\/scripts-milagrosos-para-bloquear-ataques-ddos-utilizando-o-iptables\/ &nbsp; &lt;Limit POST&gt; Deny from all &lt;\/Limit&gt; While monitoring hits to this blog, I recognize that the file which received most hits is xmlrpc.php. I was surprise because I don\u2019t use XML-RPC for remote access, posting at&#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_angie_page":false,"page_builder":"","footnotes":""},"categories":[5,12,7],"tags":[],"class_list":["post-3141","post","type-post","status-publish","format-standard","hentry","category-apache2","category-iptables","category-wordpress"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/blog.deuzebranaweb.com.br\/index.php\/wp-json\/wp\/v2\/posts\/3141","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.deuzebranaweb.com.br\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.deuzebranaweb.com.br\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.deuzebranaweb.com.br\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.deuzebranaweb.com.br\/index.php\/wp-json\/wp\/v2\/comments?post=3141"}],"version-history":[{"count":0,"href":"https:\/\/blog.deuzebranaweb.com.br\/index.php\/wp-json\/wp\/v2\/posts\/3141\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.deuzebranaweb.com.br\/index.php\/wp-json\/wp\/v2\/media?parent=3141"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.deuzebranaweb.com.br\/index.php\/wp-json\/wp\/v2\/categories?post=3141"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.deuzebranaweb.com.br\/index.php\/wp-json\/wp\/v2\/tags?post=3141"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}