The Malicious HTTP Traffic Defending Middleware, powered by OpenResty Defender, is a powerful solution designed to protect your web applications from various forms of malicious HTTP traffic. This middleware acts as a shield, allowing only legitimate traffic to pass through while effectively defending against potential threats.
Designed and developed a robust middleware capable of detecting and thwarting malicious activities originating from specific IP addresses, effectively safeguarding application backend servers.
Implemented an extendable rule engine using the strategy design pattern. This engine manages HTTP request detection rules, such as identifying high-frequency IP addresses and forbidden geographical locations. The modular approach allows for easy addition and modification of detection rules.
Developed a mechanism for rule hot reloading by periodically fetching rule specifications from Amazon S3. This dynamic rule management enables real-time adjustments to detection criteria without interrupting the middleware's operation.
Leveraged socket programming to establish a TCP servlet, enabling seamless communication between the middleware and an OpenResty Lua module. This communication channel facilitates the exchange of incoming requests and the retrieval of verdicts based on the applied detection rules.
Optimized the high-frequency IP detection algorithm by utilizing a Redis List data structure. This optimization results in improved performance and efficiency when identifying and mitigating high-frequency IP addresses engaged in suspicious activities.
Before you begin, ensure you have the following prerequisites in place:
-
OpenResty: Make sure you have OpenResty installed on your system.
-
Lua: Ensure you have Lua installed. It's a scripting language used for customizing the middleware's behavior.
-
AWS CLI: If you plan to use AWS services for storage or other operations, install the AWS CLI to manage your AWS credentials.
Start by cloning this repository to your local machine:
git clone https://github.com/YXShang97/OpenRestyDefender.git
If you wish to implement rule hot reloading by periodically fetching rule specifications from Amazon S3, follow these steps:
-
Set Up AWS S3 Bucket: Create an Amazon S3 bucket to store your rule specification files.
-
Configure AWS Credentials: Add your AWS access key and secret key to your
application.propertiesfile:
cd OpenRestyDefender/src/main/resources/Replace XXXXXXXXXXXXXXXXXXXX with your actual AWS access key and your AWS secret key:
cloud.aws.credentials.access-key=XXXXXXXXXXXXXXXXXXXX
cloud.aws.credentials.secret-key=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXNote: Make sure to keep your AWS credentials secure. Do not share them in public repositories or insecure locations.
Add the middleware to your application's OpenResty configuration. For example, in your Nginx server block:
server {
listen 999;
server_name yourdomain.com;
location / {
rewrite_by_lua_block {
.......
}
}
}