I am hereby providing some commands to have a basic checking on a server hack issue.
This will probably help you to find out the IP which tried the malpractices in a server to get compromised.
First, we can try to find the IP which I need to monitor
1. This netstat script will list out the number of connections made by an IP
2. Now you got the IP then you check it out in
a. /var/log/messages
b. /var/log/secure
Note :- In {print$5} value may change it can become 7, 8, 11, 12 etc …. eg:- {print$7}
EXIM COMMANDS
To view the mail queue:
number of mail-in queues:
To open a mail:
We can use this script to find out PHP script
How to Find the spammer spamming from home directory
———————————————————————
A spammer may use his home directory for spamming we can use a script to locate the top scripts on your server that send out emails. Then you can search the Exim mail log for those scripts to determine if it looks like spam, and even check your Apache access logs in order to find how a spammer might be using your scripts to send out spam.
To find suspicious IP activities
—————————————–
This will list the entries for the IP Address in question ( replace ip.add.re.ss with the suspicious ip address )
———————————————————————————————————–
——————————————————————————
This script will Sort files and display the number of times that file was accessed
This will probably help you to find out the IP which tried the malpractices in a server to get compromised.
First, we can try to find the IP which I need to monitor
1. This netstat script will list out the number of connections made by an IP
netstat -ntu | awk ‘{print $5}’ | cut -d: -f1 | sort | uniq -c | sort -n
2. Now you got the IP then you check it out in
a. /var/log/messages
b. /var/log/secure
cat /var/log/messages | grep ip | awk ‘{print$5}’ | cut -d: -f1 | uniq -c |sort -n
grep “unauthorised attempt” /var/log/messages | awk ‘{print$5}’ |cut -d: -f1 | uniq -c | sort -n
grep “unauthorised attempt” /var/log/secure | awk ‘{print$5}’ |cut -d: -f1 | uniq -c | sort -n
grep “unauthorised attempt” /var/log/messages | awk ‘{print$5}’ |cut -d: -f1 | uniq -c | sort -n
grep “unauthorised attempt” /var/log/secure | awk ‘{print$5}’ |cut -d: -f1 | uniq -c | sort -n
Note :- In {print$5} value may change it can become 7, 8, 11, 12 etc …. eg:- {print$7}
EXIM COMMANDS
To view the mail queue:
exim -bp
number of mail-in queues:
exim -bpc
To open a mail:
exim -Mvh <message id>
A number of emails in the queue:
/usr/sbin/exim -bpr | grep “<” | wc -l
How many Frozen mails are on the queue:/usr/sbin/exim -bpr | grep frozen | wc -l
Deleteing Frozen Messages:/usr/sbin/exim -bpr | grep frozen | awk {‘print $3′} | xargs exim -Mrm
To know the number of frozen emails in the mail queue, you can use the following commandexim -bpr | grep frozen | wc -l
In order to remove all frozen emails from the Exim mail queue, use the following commandexim -bpr | grep frozen | awk {‘print $3′} | xargs exim -Mrm
You can also use the command given below to delete all frozen mailsexiqgrep -z -i | xargs exim -Mrm
To flush the Exim queueexim -qff
Base64 injection scriptsWe can use this script to find out PHP script
grep “authentication failure” /var/log/secure | awk ‘{ print $3}’ | cut -b7- | sort | uniq -c
find /var/www/vhosts/ -name “*.php” | xargs -I{} sed -i ‘/<?php eval(gzinflate(base64_decode(/d’ {};
find /var/www/vhosts/ -name “*.php” | xargs -I{} sed -i ‘/<?php eval(gzinflate(base64_decode(/d’ {};
How to Find the spammer spamming from home directory
———————————————————————
A spammer may use his home directory for spamming we can use a script to locate the top scripts on your server that send out emails. Then you can search the Exim mail log for those scripts to determine if it looks like spam, and even check your Apache access logs in order to find how a spammer might be using your scripts to send out spam.
grep cwd /var/log/exim_mainlog | grep -v /var/spool | awk -F”cwd=” ‘{print $2}’ | awk ‘{print $1}’ | sort | uniq -c | sort -n
To find suspicious IP activities
—————————————–
This will list the entries for the IP Address in question ( replace ip.add.re.ss with the suspicious ip address )
find /var/log/ -exec grep “ip.add.re.ss” ‘{}’ \; -print
This script will provide you top 10 IP addresses that hit your apache access log———————————————————————————————————–
cat /var/log/httpd/access_log |awk ‘{print $1}’|cut -d? -f1|sort -n|uniq -c|sort -n|tail -10
This script will list the ten most accessed files on your site——————————————————————————
This script will Sort files and display the number of times that file was accessed
cat /var/log/httpd/access_log |awk ‘{print $7}’|cut -d? -f1|sort -n|uniq -c|sort -n| tail -10