Casbay Knowledge Base

Search our articles or browse by category below

Server hack and exim spamming

Last modified: October 1, 2022
Estimated reading time: 2 min

Server hack and exim spamming

In this article, we will guide you in checking the issues of server hack and exim spamming. 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

Note :-Check Server hack and exim spamming, 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 the queue:

exim -bpc

To open a mail:

exim -Mvh

The number of emails in the queue:

exim -Mvh

How many Frozen mails on the queue:

/usr/sbin/exim -bpr | grep frozen | wc

Deleting Frozen Messages:

/usr/sbin/exim -bpr | grep frozen | awk {โ€˜print $3โ€ฒ} | xargs exim -Mrm

To know the number of frozen mails in the mail queue, you can use the following command

exim -bpr | grep frozen | wc -l

In order to remove all frozen emails from the Exim mail queue, use the following command

exim -bpr | grep frozen | awk {โ€˜print $3โ€ฒ} | xargs exim -Mrmrm

You can also use the command given below to delete all frozen mails

exiqgrep -z -i | xargs exim -Mrm

To flush the exim queue

exim -qff

Base64 injection scripts

We can use this script to find out the 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โ€™ {};

How to Find the spammer spamming from home directory

โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”

The spammer may use his home directory for spamming we can use a script to locate the top scripts on your server that send out the email. 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 | sortrt -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

Visit our Knowledge Base page to find out more articles on the topic- Security.

Was this article helpful?
Dislike 0
Previous: A Quick Guide to Password Security
Next: Check Server hack and exim spamming