Skip to content
This repository has been archived by the owner on Jul 25, 2024. It is now read-only.

Commit

Permalink
Update app.py
Browse files Browse the repository at this point in the history
  • Loading branch information
arbs09 committed Mar 19, 2024
1 parent 2514b08 commit e0b9a7b
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,12 @@ def check_path():
@app.before_request
def check_user_agent():
user_agent = request.headers.get("User-Agent")
if user_agent:
for malicious_agent in MALICIOUS_USER_AGENTS:
if malicious_agent in user_agent:
ip = request.client_ip
if ip not in reported_ips or datetime.now() - reported_ips[ip] > REPORT_INTERVAL:
save_to_file(ip)
report_ip(ip, '18,19,21,15', f'Automated report for using malicious user-agent: {user_agent}')
reported_ips[ip] = datetime.now()
break # Exit the loop once a match is found
if user_agent and any(malicious_agent in user_agent for malicious_agent in MALICIOUS_USER_AGENTS):
ip = request.client_ip
if ip not in reported_ips or datetime.now() - reported_ips[ip] > REPORT_INTERVAL:
save_to_file(ip)
report_ip(ip, '18,19,21,15', f'Automated report for using malicious user-agent: {user_agent}')
reported_ips[ip] = datetime.now()

@app.route('/<path:filename>')
def report_rules(filename):
Expand Down

0 comments on commit e0b9a7b

Please sign in to comment.