Snort rule to block the HTTP request - snort

How do I write a rule to block the request if the request will cross set threshold limit?
Example: I want if someone will request 100 times my page in 1 min then snort will block the IP.
Regards
MR

Related

What is the best HTTP status code for pin code's "Max Attempt Reached"?

I'm implementing a pin code authorization in my web application and one of the requirements is to limit the attempt count of a user to n times in a day.
So, what is the best HTTP status code returned to the user when they reached the max attempt count?
Now, I'm thinking of
403
429 (but it's not about sending too many requests)
400 (but the request payload didn't invalid)
429 is exactly what you want.
from: https://datatracker.ietf.org/doc/html/rfc6585
429 Too Many Requests
The 429 status code indicates that the user has sent too many
requests in a given amount of time ("rate limiting").
The response representations SHOULD include details explaining the
condition, and MAY include a Retry-After header indicating how long
to wait before making a new request.
For example:
HTTP/1.1 429 Too Many Requests
Content-Type: text/html
Retry-After: 3600
<html>
<head>
<title>Too Many Requests</title>
</head>
<body>
<h1>Too Many Requests</h1>
<p>I only allow 50 requests per hour to this Web site per
logged in user. Try again soon.</p>
</body>
</html>
Note that this specification does not define how the origin server
identifies the user, nor how it counts requests. For example, an
origin server that is limiting request rates can do so based upon
counts of requests on a per-resource basis, across the entire server,
or even among a set of servers. Likewise, it might identify the user
by its authentication credentials, or a stateful cookie.
Responses with the 429 status code MUST NOT be stored by a cache.
Note how the spec invites the service / implementation to provide details. It does not say what type of requests is too much or anything specific, really. Therefore, you will want to say something like "stop spamming my service because x, y, z".

Vert.x httpClient - any idea how to limit the number of concurrent requests?

I need to send x HTTP client request. I want to send the requests in parallel, but no more than y at once.
I will explain:
The client can handle only y requests simultaneously. I need to send x request to the client, while x > y.
I don't want to wait until all the first y requests will end, and then send another bulk of y requests. This approach isn't efficient, because at each moment, my client can handle y requests. If I will wait until all the first y will end to send another y requests, the client won't be fully utilized.
Any Idea how can implement it with vert.x?
I'm considering sending x requests at once and then send another request each time the handler gets the callback. Is it make sense?
What is the meaning of maxPoolSize in HttpClientOptions? Is it have any connection to concurrent requests?
Many thanks!
I'm answering my question... After some tests, the described test does not scale well with any reactor pattern. The solution here is to use a thread poll of y for sending x tasks.
I would suggest to go with your solution based on callbacks, and not to rely on maxPoolSize.
From the documentation:
* If an HttpClient receives a request but is already handling maxPoolSize requests it will attempt to put the new
* request on it's wait queue. If the maxWaitQueueSize is set and the new request would cause the wait queue to exceed
* that size then the request will receive this exception.
https://github.com/eclipse-vertx/vert.x/blob/master/src/main/java/io/vertx/core/http/ConnectionPoolTooBusyException.java

How to enforce single threaded requests?

I've started rate limiting my API using HAProxy, but my biggest problem is not so much the rate of requests, but when multi-threaded requests overlap.
Even within my legal per-second limits, big problems are occurring when clients don't wait for a response before issuing another request.
Is it possible (say, per IP address) to queue requests and pass them one at at time to the back end for sequential processing?
Here is a possible solution to enforce one connection at a time per src IP.
You need to put the following HAProxy conf in the corresponding frontend:
frontend fe_main
mode http
stick-table type ip size 1m store conn_cur
tcp-request connection track-sc0 src
tcp-request connection reject if { src_conn_cur gt 1 }
This will create a stick table that stores concurrent connection counts per source IP. Then rejects new connections if there is already one established from the same src IP.
Browsers imitating multiple connections to your API or clients behind a NAT will not be able to efficiently use you API.

Check number of requests sent by all clients

I'm currently implementing my new conf for haproxy and I would like to create an ACL based on the number of requests sent.
When I read the documentation there is some check like that but it's dedicated to a specific IP, as:
src_conn_cur
src_conn_rate
sc0_http_err_rate()
sc0_http_req_rate()
Is there a solution to get all the request sent from every source addresses at the same time? If I reach a specific number of request I want to redirect the users to another backend.
You can use the fe_req_rate fetch.
You can use this to direct users to another backend like this if the global number of requests per second on the current frontend is above 100 / sec:
use_backend overflow if { fe_req_rate gt 100 }
use_backend default

What is the throttling time between requests for Box API?

Can't find it anywhere on Box View site. Just wondering how long I should wait between trying to convert documents.
When you make a request that exceeds a rate limit, you'll receive an a response with an HTTP status of 429 TOO MANY REQUESTSand the retry time will be included as a Retry-After header e.g.
HTTP/1.1 429 Too Many Requests
Retry-After: {retry time in seconds}
You can use the {retry time in seconds} to determine how long to wait.
Docs: http://developers.box.com/view/#rate-limiting