Recently, I encountered incident where several hosts been infected by < █████████ >. So, to investigate this incident, we received bunch of logs to be analyze; mostly Linux related logs.
I’ve been thinking.. What if the host has been successfully brute-forced? How can we identify it?
In Linux, there are several logs that we can refer that contains authentication logs for both successful or failed logins, and authentication processes. Location & names of the logs varies; depending on system type. For Debian/Ubuntu, the logs located at /var/log/auth.log. For Redhat/CentOS, the logs located at /var/log/secure.
There are 2 more logs that we can refer;
– /var/log/utmp: current login state by user.
– /var/log/wtmp: record of each user login/logout.
So, what if we write a script to quickly go thru those mentioned logs & identify the culprits? Probably we can find out if our host has been successfully brute-forced.
Introducing.. Break-In Analyzer – A script that analyze the log files /var/log/auth.log (for Debian based systems), /var/log/secure (for RHEL based systems), utmp/wtmp for possible SSH break-in attempts. – https://github.com/zam89/Break-In-Analyzer
Here are some screenshot of the script in action:
The output result will be written into text file; stored into folder named output. Inside the folder will contains file named:
So, you must been wondering; how can I validate these IPs? whether they are harmless or not? Well, to do that, we can use AbuseIPDB to quickly see each of IP reputation; either they’re clean or has been reported due to malicious activity.
In this example, I’m using AbuseIPDB Bulk Checker from – https://github.com/AdmiralSYN-ACKbar/bulkcheck. This tool can perform bulk checking of IPs towards AbuseIPDB website. *Just a side notes: it require API key from AbuseIPDb. You can get it for free by registering on the website. Its limited to 1000 request/IPs per day.
So, I’m checking 203 IPs that we got from Break-In Analyzer script output (after removing duplicated using Excels) on AbuseIPDB if there is any records for those IPs. After the check completed, the result shows something like this:
If you filter out by abuseConfidenceScore (removing score 0), you’ll see there are 3 IPs that having kinda high confidence score. The higher the score, the more chances the IP marked as malicious – meaning that the IP has been reported multiple times related to malicious activities.
Next, we cross check with our Break-In Analyzer outputs to see where did these IPs located on the logs. Or you can cross check directly with your logs. To do that, run command as below:
$ grep --perl-regexp "126.96.36.199" --color=always --only-matching --recursive * | sort | uniq --count | sort --numeric --reverse
This command is basically searching where the IP “188.8.131.52” located/contains inside the log. If you run the command, you’ll see output as below:
Now we know that the IP “184.108.40.206” is contains inside wtmp dump log:
and also inside tools output:
If we go search inside the wtmp dump log for that IP “220.127.116.11“, we found that the IP has been accessing the system since Feb 2016… hmm.. 🤦
cat node2/output/wtmpdump_output.txt | grep 18.104.22.168 --color=always
This may indicate that the attacker has been leveraging the host for very long time.
Next step is probably to search what the IP or the account “portaladmin-ts” is doing inside the host.