Ip-blocking using MLSecOps

Ip-blocking using MLSecOps

In this article I'm going to explain how we can block a particular IP, using Rhel8, Python script, Jenkins.

Our Problem Statement: Create an automated system which will be useful for a server in terms of the following features:-

1. This system will keep a log of the information about the clients hit or request to the server for example we can get log file of a webserver at location /var/log/httpd/ .

2. This log data of clients will be used for finding the unusual pattern of a client request for example if a client is sending request repeatedly. for this purpose, we can use here clustering to make clusters of different patterns of client request and to identify which cluster of client requests can cause some security and performance issue in the server.

3. If any kind of unusual pattern we got then we can use Jenkins to perform a certain task for example it can run some command to block that IP which is causing this trouble.

Solution: We have to create an architecture in which we will collect all data of IPs which are searching the particular website. For this task , I have created a webpage called index.html. The location of index.html is /etc/www/html . Here all webpages are saved , but I have created only one for testing purpose.

After extracting data , I have saved that log data in a file called alllog.txt which is saved in /logfiles folder. After creating this folder and saving this file I have pushed this file to Github so we can download that data and use it as a dataset.

Because the log data is managed as a record and this looks by only RHEL8 , it has a format which is not easily understood by any programming language . That's why we need to convert into CSV . So python Script can easily take that as a dataset. But, we know this data is having also unwanted features and those features will really create a big problem if we don't remove them , because it can affect its accuracy. So, we have to remove them , It is also called as Feature Selection.

Now , after collecting the data and converting into csv and feature selection , we have to create a small python program by which we will extract only those IPs , which are continuously attacking that particular webpage.

When we get that IP which is continuously attacking that WEBPAGE OR WEBSITE ,we will pass this information into github. After uploading to github we can easily extract that , by cloning this in that RHEL8 OS .

Using Jenkins, we can simply write a following command which is used to block an IP address.

iptables -A INPUT -s IP_ADDRESS_YOU_WANT_TO_BLOCK -j DROP


Step by Step Implementaion,

Accessing all logs from access_log file which is present in /var/log/httpd. I'm saving this file using cat into alllog.txt file because we can't see the access_log file using any text editor like gedit directly.

No alt text provided for this image
No alt text provided for this image

Now, I will push this allog.txt to Github.

No alt text provided for this image

Now I will download the file using git clone command.

Python: In Jupyter notebook, I made a particular to convert log data onto csv, and then to delete the unwanted columns or fields.

1. Importing pandas and NumPy.

No alt text provided for this image

2. Creating a code, to convert log to CSV.

No alt text provided for this image
No alt text provided for this image


3. Removing unwanted space in the CSV.

No alt text provided for this image

4. Removing unwanted columns.

No alt text provided for this image

5. Renaming the columns

No alt text provided for this image

6. Dataset created

No alt text provided for this image

7. Counting Ips with their number of attacking.

No alt text provided for this image

8. Extracting out that IP which is having attacks more than 12.

No alt text provided for this image

9. Saving in the ipoutput.txt file.

No alt text provided for this image

Pushing this file into GitHub.

No alt text provided for this image

Before Jenkins job building

No alt text provided for this image


Jenkins: Created a job to block the IP

No alt text provided for this image
No alt text provided for this image

After Jenkins job building

No alt text provided for this image

Conclusion :

1. we can easily block a particular IP using this concept

2. This will help in securing website from hackers, or even other vulnerable users who just attack to slow down the server.

No alt text provided for this image

?

Saurabh Gupta

Back End Developer | MCA | AppITron Solutions

4 年

and we can also track anyone location throught that ip, but i got a question as we know ip is dynamic and anyone can change it anytime. How you gonna block it ?

Sparsh Pandey

TSE @ Couchbase | Ex - Nagarro

4 年

Great work Aastha Saxena

回复
Arshit Paliwal

Analyst @ Annalect | 5x Datorama Certified | DevOps | Cloud

4 年

Nice work Was really helpful ??

回复
Vishal Sharma

software developer working react native and nodejs

4 年

Meri ip block melt krdena????????

Sakshi Tripathi

Software Engineer - 2 @HashedIn By Deloitte || Frontend Web Developer! Javascript/React

4 年

nice work??

回复

要查看或添加评论,请登录

Aastha Saxena的更多文章

  • Jenkins and Groovy on Kubernetes

    Jenkins and Groovy on Kubernetes

    What is Groovy? It is language in which we can write the code and steps to run JOBs of Jenkins. This language is very…

    2 条评论
  • Dynamic Cluster -Jenkins, Docker and Kubernetes

    Dynamic Cluster -Jenkins, Docker and Kubernetes

    In this article, we are going to explain how to make a dynamic Jenkins cluster with Kubernetes. Cluster: The group of…

    4 条评论
  • How to write a great resume?

    How to write a great resume?

    In this article I will share you my experience in how to write a resume. First of all , what we should write in resume?…

    6 条评论
  • Automation webserver using Kubernetes

    Automation webserver using Kubernetes

    1. Create container image that’s has Jenkins installed using dockerfile Or You can use the Jenkins Server on RHEL 8/7 2.

    4 条评论
  • AWS Deep Composer

    AWS Deep Composer

    In this article, I will go through, how we can compose our music using AWS DEEP COMPOSER. Firstly, let us learn what is…

  • MLOps Journey

    MLOps Journey

    Congratulations to my fellow MLOps students in the completion of MLOps Training given by Vimal Daga Sir. Let me…

    4 条评论
  • Face Recognition using Vgg-16

    Face Recognition using Vgg-16

    In this article, I'm going to explain how we can make our own Face recognition and detection system using VGG-16 and…

    8 条评论
  • Machine Learning Integration with DevOps

    Machine Learning Integration with DevOps

    Task Overview:1. Create container image that’s has Python3 and Keras or numpy installed using dockerfile 2.

    2 条评论
  • Automation of webserver using Docker ,Jenkins, Git and Github

    Automation of webserver using Docker ,Jenkins, Git and Github

    Task Aim: 1. Create container image that’s has Jenkins installed using dockerfile 2.

    4 条评论
  • DEVOPS AUTOMATION

    DEVOPS AUTOMATION

    Introduction of applications used: Github : Github is a centralised system where we can upload or download the code .It…

    4 条评论

社区洞察