Skip to content

Commit ec5b92b

Browse files
committed
Add Failed MySQL authentication
Added Failed MySQL authentication from error log.
1 parent 7a75f78 commit ec5b92b

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

csf_custom_regex.sh

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ date=$(date +"%d%m%y-%H%M%S")
4747
cd "$CURRDIR" || exit
4848
su -s "$(which bash)" -c "./$SCRIPT_FILENAME $1"
4949
cd - > /dev/null || exit
50-
exit 0;
50+
exit 0;
5151
fi
5252

5353
csf_installer_url=https://github.com/tmiland/csf/raw/master/csf_installer.sh
@@ -99,8 +99,8 @@ if [[ ! -f /usr/sbin/virtualmin ]]; then
9999
install_virtualmin
100100
break
101101
;;
102-
[Nn]* )
103-
break
102+
[Nn]* )
103+
break
104104
;;
105105
esac
106106
done
@@ -116,8 +116,8 @@ elif [[ ! -f /usr/sbin/csf ]]; then
116116
install_csf
117117
break
118118
;;
119-
[Nn]* )
120-
break
119+
[Nn]* )
120+
break
121121
;;
122122
esac
123123
done
@@ -132,12 +132,13 @@ install() {
132132
echo
133133
/usr/sbin/csf --profile backup backup-b4-customregex.$date
134134
cp -a /usr/local/csf/bin/regex.custom.pm /usr/local/csf/bin/regex.custom.pm.bak.$date
135-
egrep 'CUSTOM1_LOG|CUSTOM2_LOG|CUSTOM3_LOG|CUSTOM4_LOG' /etc/csf/csf.conf
135+
egrep 'CUSTOM1_LOG|CUSTOM2_LOG|CUSTOM3_LOG|CUSTOM4_LOG|CUSTOM5_LOG' /etc/csf/csf.conf
136136
sed -i "s|CUSTOM1_LOG = .*|CUSTOM1_LOG = \"/var/log/virtualmin/\*_access_log\"|" /etc/csf/csf.conf
137137
sed -i "s|CUSTOM2_LOG = .*|CUSTOM2_LOG = \"/var/log/virtualmin/\*_error_log\"|" /etc/csf/csf.conf
138138
sed -i "s|CUSTOM3_LOG = .*|CUSTOM3_LOG = \"/var/log/nginx/access.log\"|" /etc/csf/csf.conf
139139
sed -i "s|CUSTOM4_LOG = .*|CUSTOM4_LOG = \"/var/log/nginx/error.log\"|" /etc/csf/csf.conf
140-
egrep 'CUSTOM1_LOG|CUSTOM2_LOG|CUSTOM3_LOG|CUSTOM4_LOG' /etc/csf/csf.conf
140+
sed -i "s|CUSTOM5_LOG = .*|CUSTOM5_LOG = \"/var/log/mysql/error.log\"|" /etc/csf/csf.conf
141+
egrep 'CUSTOM1_LOG|CUSTOM2_LOG|CUSTOM3_LOG|CUSTOM4_LOG|CUSTOM5_LOG' /etc/csf/csf.conf
141142

142143
egrep 'HTACCESS_LOG|MODSEC_LOG|SSHD_LOG|FTPD_LOG|SMTPAUTH_LOG|IPTABLES_LOG|BIND_LOG|SYSLOG_LOG|WEBMIN_LOG' /etc/csf/csf.conf
143144
sed -i "s|HTACCESS_LOG = .*|HTACCESS_LOG = \"/var/log/virtualmin/\*_error_log\"|" /etc/csf/csf.conf

regex.custom.pm

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,22 @@ if (($config{LF_SMTPAUTH}) and ($globlogs{SMTPAUTH_LOG}{$lgfile}) and ($line =~
275275
}
276276

277277
#dovecot
278-
if (($config{LF_POP3D}) and ($globlogs{POP3D_LOG}{$lgfile}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) \S+ dovecot: pop3-login: Disconnected (\s*\(no auth attempts( in \d+ secs)?\))?: (user=(<\S*>)?, )rip=(\S+),/)) {
279-
$ip = $6;
280-
$acc = $4;
281-
$ip =~ s/^::ffff://;
282-
$acc =~ s/^<|>$//g;
283-
if (checkip(\$ip)) {return ("Failed POP3 login from","$ip|$acc","pop3d")} else {return}
284-
}
278+
if (($config{LF_POP3D}) and ($globlogs{POP3D_LOG}{$lgfile}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+) \S+ dovecot: pop3-login: Disconnected (\s*\(no auth attempts( in \d+ secs)?\))?: (user=(<\S*>)?, )rip=(\S+),/)) {
279+
$ip = $6;
280+
$acc = $4;
281+
$ip =~ s/^::ffff://;
282+
$acc =~ s/^<|>$//g;
283+
if (checkip(\$ip)) {return ("Failed POP3 login from","$ip|$acc","pop3d")} else {return}
284+
}
285+
286+
# Failed MySQL authentication
287+
# From /var/log/mysql/error.log:
288+
# 2022-04-01 1:39:27 xxxx [Warning] Aborted connection xxxx to db: 'unconnected' user: 'unauthenticated' host: 'xxx.xxx.xxx.xxx' (This connection closed normally without authentication)
289+
if (($globlogs{CUSTOM5_LOG}{$lgfile}) and ($line =~ /^(\S+|\S+\s+\d+\s+\S+)\s+(\S+|\S+\s+\d+\s+\S+) \d+ \[Warning\] Aborted connection \d+ to db: 'unconnected' user: 'unauthenticated' host: '(\S+)' \(This connection closed normally without authentication\)/)) {
290+
$ip = $3; $acc = "";
291+
$ip =~ s/^::ffff://;
292+
if (checkip(\$ip)) {return ("Failed MySQL authentication","$ip|$acc","mysql")} else {return}
293+
}
285294

286295
# If the matches in this file are not syntactically correct for perl then lfd
287296
# will fail with an error. You are responsible for the security of any regex

0 commit comments

Comments
 (0)