96 points · by LaurentGh · 10y ago · 66 comments
They tried blocking specific ip addresses, which didn't work, because the attack was somewhat distributed. They then just turned on some caching, which allowed the site to function, albeit with an unknown excess bandwidth charge pending.
And, the DDoS itself can't of been terribly impressive, as all it took to mitigate was a bit of caching. He mentions 10 requests / sec as the scale of the attack.
He first mentions having to change Apache to recognize X-Forwarded-For, because there is Amazon Elastic Load Balancing between his site and the internet.
This means, of course, that the "attacking ips" aren't making direct connections to his EC2 instance. They are proxied connections, all from the internal ELB service.
So later, when he mentions trying to use iptables to block traffic...that just doesn't make sense. There are no connections from those ips to the EC2 instance. You could use .htaccess rules, since Apache is aware of X-Forwarded-For.
Lastly...why would you put an elastic load balancer in front of a single web server?
This blog posts explains the whole thing: https://centos.tips/fail2ban-behind-a-proxyload-balancer/
I have no idea if using .htaccess rules would be better than this solution, I just know that this one works.
And, it's possible this is https, which would render the packet inspection useless.
Let's say you have a single web server you need to have up all of the time. You need high availability, but not necessarily instant fail-over, because you want to keep your costs low, and so you don't want two instances running all of the time. It may not serve much traffic at all, so there isn't much load to spread. What you can do is place an ELB in front of the web server, set a condition to start a new instance if the page becomes non-responsive (i.e., a failure), and set the auto-scaling to "min 1, max 1." This way, you'll always have a pool of one server, that will automatically rebuild if the instance fails.
I admit, it's not a common use case, but it's one of the more clever uses of the ELB I've heard. =)
Every service in our infrastructure runs the same way. Some have scaling policies, some don't.
DBs like Cassandra are also in ASGs since if one of them terminates and new one can come up and bootstrap without operator intervention.
Everything could have been planed way better (cached, written with a fancy language...), we could have had 10 mil requests/µsec... the main idea was just to get tell how we tried to manage the situation, with the website and skill we have.
I also think my testimony is nearer to what most of web dev can be confronted to, in contrary to one Cloudflare/Gihub BS press release written by 10 experts to increase valuation :p
I use async logic (previously OpenResty, more recently NodeJS and Go) and largely pregenerated sites, so 2500 requests/second is a minimum baseline -- on a much lower end instance than an m4.xlarge.
There's a reason I don't use PHP (or any primarily synchronous language like Ruby) any more.
Of course I've avoided WordPress and similar frameworks for years for a reason as well; I've seen front-end frameworks that require dozens if not hundreds of database queries to render a page, which is such bad design that it makes my brain hurt.
Say an API call spins up a Linux VM and makes it available some user. Or a bulk upload of data which needs to be indexed. Or whatever.
The idea that a site should be able to handle X requests/sec because the stack can handle X NOOPs per second is odd.
Node can render more NOOPs per second than that; I've heard of a well tuned Node server hitting 100k. But because of the async nature of the handling of responses, you don't need dozens or hundreds of threads to handle thousands of clients, and it's the threads that kill you.
Unless you've just got an awful architecture, in which case that will kill you first.
[1] https://nestify.io/wp-content/uploads/2015/10/loader.io_.png
That can typically be done from Node by simply adding the "use pooling" option in your database library (or sometimes by switching to the NPM for that database that enables pooling), and when you have additional slave databases, adding those to the database init call.
As far as Node is concerned, it really is that easy. Scaling PHP, though, pretty much requires that you add more threads, which means (after a point) you need a lot of RAM, or just adding more instances and load balancing between them.
Node won't prevent database scaling issues, but it will keep the part that it does handle a lot easier to maintain.
The language usually isn't the reason for issues like this...
For tasks that are primarily IO bound, async architectures can scale more than synchronous languages. Period.
It would take intentionally (or newb/cluelessly) bad design to end up with a Node server that DOSed at 12 connections per second.
In PHP, if you run 4 threads, it just takes a backend with a 333ms latency (on all queries performed serially) to limit you to 12 connections per second. If you only run one thread, you just need a backend with a cumulative 83ms latency to get DOSed at 12 connections per second. In a more realistic scenario, a typical crappy framework will result in dozens of queries for a single page, but it comes down to the same thing.
In Node, you can run one thread with a cumulative 333ms backend latency and still handle thousands of connections per second. They'll each just end up waiting a bit more than 333ms for their results, assuming the database itself isn't DOSed (which takes a surprisingly high load -- way above the levels we're talking). Actually, depending on how interconnected the backend queries are, Node may actually result in less than a total 333ms latency, because many of those queries may also be parallelized by the browser, and will then be handled in parallel by the server (and much of the latency may actually be in http negotiations and/or establishing a database connection, honestly).
[0]: http://lologhi.github.io/symfony2/2016/04/04/DDoS-attack-for...
[1]: https://webcache.googleusercontent.com/search?q=cache:J7lca_...
[2]: https://github.com/lologhi/lologhi.github.com/blob/master/_p...
The term actually seems to come from a 1920s boxing euphemism [2]: when a boxer is not actually knocked out but voluntarily lays down on the ground, it was called "a dive" for obvious reasons; euphemistically some people called this "going into the tank," since you'd dive into a pool.
How did this start referring to the vehicle? Again, back to [1], there was once a memo "recommending the proposed "caterpillar machine-gun destroyer" machines be entrusted to an organization "which, for secrecy, shall be called the 'Tank Supply Committee,' ..." and the rest is history.
[1] http://www.etymonline.com/index.php?term=tank
[2] http://www.slate.com/articles/news_and_politics/explainer/20...
It's not that impressive because we read everyday articles about crazy DDoS big companies are able to mitigate. But when it's the website your responsible for, whatever the number of requests/sec, you just need to find way to manage it, and CloudFlare can have some weird side effects.
my goodness.
For my own sites, I mostly use static html or server-parsed html.
There are many, very popular Wordpress plugins that take hundreds of SQL queries just to render a landing page. 10 hits/sec legitimately is "DDoS" territory for many businesses running such things.
At least for this kind of attack, a more serious DDoS won't be tamed by "just adding cache"
Site not installed The site ghirardotti.fr is not yet installed
[Edit: it's up now.]
Dig:
dig ghirardotti.fr
;; ->>HEADER<<- opcode: QUERY, rcode: NOERROR, id: 19860
;; flags: qr rd ra ; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;; ghirardotti.fr. IN A
;; ANSWER SECTION:
ghirardotti.fr. 3112 IN A 192.30.252.154
ghirardotti.fr. 3112 IN A 192.30.252.153
;; AUTHORITY SECTION:
;; ADDITIONAL SECTION:
Both ip's belong to Github, probably used as a failover/load balancing/round robin pair of some kind.reverse dns
dig -x 192.30.252.154
; <<>> DiG 9.8.3-P1 <<>> -x 192.30.252.154
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 46826
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;154.252.30.192.in-addr.arpa. IN PTR
;; ANSWER SECTION:
154.252.30.192.in-addr.arpa. 3593 IN PTR pages.github.com.
dig ipv6: dig AAAA ghirardotti.fr
; <<>> DiG 9.8.3-P1 <<>> AAAA ghirardotti.fr
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 0
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;ghirardotti.fr. IN AAAA
;; ANSWER SECTION:
ghirardotti.fr. 1613 IN AAAA 2001:41d0:1:1b00:213:186:33:19
;; Query time: 91 msec
Reverse dns on that: dig -x 2001:41d0:1:1b00:213:186:33:19
; <<>> DiG 9.8.3-P1 <<>> -x 2001:41d0:1:1b00:213:186:33:19
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 25262
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;9.1.0.0.3.3.0.0.6.8.1.0.3.1.2.0.0.0.b.1.1.0.0.0.0.d.1.4.1.0.0.2.ip6.arpa.
IN PTR
;; ANSWER SECTION:
9.1.0.0.3.3.0.0.6.8.1.0.3.1.2.0.0.0.b.1.1.0.0.0.0.d.1.4.1.0.0.2.ip6.arpa.
85728 IN PTR cluster010.ovh.net.villa-bali is not even close to this, my bet that you (or your ORM) are making too many requests to database. Try to record ALL requests to database during page rendering and I bet you have about hundred. Check out following test results:
8 test agents: http://loadme.socialtalents.com/Result/ViewById/57341f645b5f... - 5% of users have to wait more than 2 seconds 16 test agents: http://loadme.socialtalents.com/Result/ViewById/57341f1a5b5f... 5% of users need to wait for more than 4 seconds.
Definitely, any bot can nuke your website easily.
Stopped reading after that.