Score:0

Script to filter nginx logs to automatically running nftables

jp flag

I have a domain served by nginx. nginx logs have this format:

178.128.120.151 - - [19/Jul/2023:20:27:25 +0200] "GET /favicon.ico HTTP/1.1" 301 162 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"
178.128.120.151 - - [19/Jul/2023:20:27:25 +0200] "GET /1.php HTTP/1.1" 301 162 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/108.0.0.0 Safari/537.36"
95.214.27.160 - - [19/Jul/2023:20:28:24 +0200] "POST /boaform/admin/formLogin HTTP/1.1" 301 162 "http://84.120.157.219:80/admin/login.asp" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:71.0) Gecko/20100101 Firefox/71.0"

I want to make an script (bash, python, whatever) to see the IPs which access to my server and filter this way:

  • if the requested path is /, /robots.txt or /favicon.ico, then nothing happens
  • but if the requested path is something else, the call nft add element inet my_table badips { <IP> }

Preferred to analyze in live the nginx logs, to detect the traffic meanwhile it happens.

jp flag
`fail2ban` can help you
somenxavier avatar
jp flag
@AlexD fail2ban is good program but it is not what I want because it sees unauthorized access to ssh, nginx, etc. It's a canion to kill flyes
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.