How to stop hack/DOS attack on web API

后端 未结 6 1119
时光取名叫无心
时光取名叫无心 2021-01-30 03:15

My website has been experiencing a denial of service/hack attack for the last week. The attack is hitting our web API with randomly generated invalid API keys in a loop.

<
6条回答
  •  醉梦人生
    2021-01-30 03:48

    For a targeted and highly distributed DOS attack the only practical solution (other than providing the capacity to soak it up) is to profile the attack, identify the 'tells' and route that traffic to a low resource handler.

    Your question has some tells - that the request is invalid, but presumably there is too much cost in determining that. That the requests originate from a specific group of networks and that presumably they occur in bursts.

    In your comments you've told us at least one other tell - the user agent is null.

    Without adding any additional components, you could start by tarpitting the connection - if a request matching the profile comes in, go ahead and validate the key, but then have your code sleep for a second or two. This will reduce the rate of requests from these clients at a small cost.

    Another solution would be to use log failures matching the tell and use fail2ban to reconfigure your firewall in real time to drop all packets from the source address for a while.

    No, its unlikely you will be able to identify the app without getting hold of an affected device.

提交回复
热议问题