This is a basic log analyzer script designed to simulate the analysis of server log files for potential malicious activity. It focuses on identifying failed login attempts and allows you to research suspicious IPs further.
- Bash shell
log_analyzer.sh: The script that analyzes the log file.log.txt: A sample log file (replace with your actual log file).
- Save the script as
log_analyzer.sh.
- Make the script executable:
chmod +x log_analyzer.sh
- Run the script:
./log_analyzer.sh
- Analyzes the
log.txtfile for lines containing "401 Unauthorized" (indicating failed login attempts). - Identifies IPs with a high number of failed login attempts (configurable threshold).
- Presents a menu of options:
- Ban IP (simulation)
- Block IP temporarily (simulation)
- Research further
- Ignore
- If "Research further" is selected, displays all activity for the specified IP.
- After researching an IP, provides additional options:
- Ban IP (simulation)
- Block IP temporarily (simulation)
- Ignore
- This is a simulation and does not implement actual banning or blocking functionalities. You would need to add the necessary logic based on your system's configuration.
- The script uses a basic threshold for detecting suspicious activity. You may need to adjust this threshold based on your specific needs and security requirements.
Analyzing log file...
10.0.0.2: 13 failed login attempts
Detected potentially malicious IPs:
Do you want to take action against any of these IPs?
1. Ban IP
2. Block IP temporarily
3. Research further
4. Ignore
Enter your choice: 3
Enter IP to research:
10.0.0.2
All activity for IP 10.0.0.2:
2024-12-28 07:48:12 | 10.0.0.2 | 80 | HTTP | POST /login | 401 Unauthorized
2024-12-28 07:48:15 | 10.0.0.2 | 80 | HTTP | POST /login | 401 Unauthorized
2024-12-28 07:48:12 | 10.0.0.2 | 80 | HTTP | POST /login | 401 Unauthorized
2024-12-28 07:48:13 | 10.0.0.2 | 80 | HTTP | POST /login | 401 Unauthorized
2024-12-28 07:48:15 | 10.0.0.2 | 80 | HTTP | POST /login | 401 Unauthorized
2024-12-28 07:48:16 | 10.0.0.2 | 80 | HTTP | POST /login | 401 Unauthorized
2024-12-28 07:48:17 | 10.0.0.2 | 80 | HTTP | POST /login | 401 Unauthorized
2024-12-28 07:48:18 | 10.0.0.2 | 80 | HTTP | POST /login | 401 Unauthorized
2024-12-28 07:48:19 | 10.0.0.2 | 80 | HTTP | POST /login | 401 Unauthorized
2024-12-28 07:48:20 | 10.0.0.2 | 80 | HTTP | POST /login | 401 Unauthorized
2024-12-28 07:48:21 | 10.0.0.2 | 80 | HTTP | POST /login | 401 Unauthorized
2024-12-28 07:48:22 | 10.0.0.2 | 80 | HTTP | POST /login | 401 Unauthorized
2024-12-28 07:48:23 | 10.0.0.2 | 80 | HTTP | POST /login | 401 Unauthorized
What do you want to do next?
1. Ban IP
2. Block IP temporarily
3. Ignore
Enter your choice: 1
IP 10.0.0.2 banned. (This is a simulation.)
This section details the recent updates and improvements made to the log analyzer script.
- Configurable Threshold: The threshold for failed login attempts can now be specified using the
-tcommand-line argument. For example:./log_analyzer.sh -t 5sets the threshold to 5. The default threshold is 3. - Log File as Argument: The log file name can be specified using the
-lcommand-line argument. For example:./log_analyzer.sh -l my_server.log. The default log file islog.txt. - Clearer Output Formatting: Improved output formatting using
printffor better readability and consistent alignment. - Unique IP Count: Displays the total number of unique suspicious IPs detected.
- Basic Timestamp Filtering: Added basic timestamp filtering using
-sfor start time and-efor end time. The format should be YYYY-MM-DD HH:MM:SS. Example:./log_analyzer.sh -s "2024-01-01 00:00:00" -e "2024-01-02 00:00:00" -l my_server.log - Basic Error Handling: Implemented basic error handling for checking file existence and readability, and invalid user input.
- "Last Seen" Timestamp: When researching an IP, the timestamp of the last failed login attempt is now displayed.
- Progress indicator for large log files.
- Colorized output using ANSI escape codes.
- More robust timestamp filtering and handling of various log formats.
- Advanced analysis features (geolocation, threat intelligence integration).
- Detailed reporting.