I have been struggling with trying to run a secure sshd server since
Sept. 24, and am pretty certain of my procedure and deduction. But I
don't know how wide-spread this problem is. So please check your
server to see if the same deadly problem is happening to you.
I had been running RedHat 9 on my apache/sshd server with static IP
for 6 months. On Sept. 24 I found my server was rootkitted. This is
not surprising in hindsight because I was not keeping up with updates,
and this is not what I am going to talk about. What I am talking about
is that on Sept. 24, I reformatted my / (/dev/hda1), did a clean
installation of Fedora core 3, test 2 from CD (ISO downloaded from
http://fedora.redhat.com/download/mirrors.html) with Firewall on and
only port 22 getting though (SELinux disabled - doesn't make a
difference though), within 1 minute that a ssh client connects to my
server, a sniffer found this out and rootkitted my brand new FC3T2
server.
Note that I was extra careful not using any executable not under
/dev/hda1. In fact I have just one other partition, /dev/hda3, which
is mounted under /home. I never used any commands in /home.
I found I was rootkitted by checking the file sizes of /bin/grep,
/bin/ls, /usr/bin/ssh. I took down their values when the machine is
just installed, which are 75684, 81272, 222248 bytes, respectively.
After infection, the file sizes are 77264, 85200, 227816. I wrote a
script to check this automatically.
#!/bin/csh
#
# Check the file sizes of Fedora Core 3, Test 2
#
# fc3t2
#
set array = ( /bin/grep 75684 \
/bin/ls 81272 \
/usr/bin/ssh 222248 )
set i = 1
while ( $i < $#array )
set file = $array[$i]
@ j = $i + 1
set HealthySize = $array[$j]
if ( -Z $file == $HealthySize ) then
# echo $file is healthy. #
else
echo $file is hacked\! file size should be $HealthySize\!
ls -ltr $file
endif
@ i = $i + 2
end
Those who are running Fedora Core 3, Test 2 with sshd (openssh-3.9p1-3
built on openssl-0.9.7a-39) open to the entire universe, and have
established at least one ssh client connection to it, please check
your /bin/grep, /bin/ls, /usr/bin/ssh file sizes !!!!!
The infected files are attached behind. Please be extra careful in
handling them. This virus is not actively knocking on port 22, it is
only passively listening: only after at least one ssh connection is
made so the sniffer heard it, then does it pound on your server. I
found this out by 'iptables -L -v -n'. Only when the port 22 line has
non-zero packet count does my server gets infected.
Now here is the really interesting part. I ran Rootkit Hunter
(
http://www.rootkit.nl/projects/rootkit_hunter.html) and it tells me
my openssl-0.9.7a-39 from stock FC3T2 distribution may be vulnerable.
So I downloaded the newest
http://www.openssl.org/source/openssl-0.9.7d.tar.gz and
ftp://ftp.openbsd.org/pub/OpenBSD/Op...h-3.9p1.tar.gz
to compile a static sshd:
wget
http://www.openssl.org/source/openssl-0.9.7d.tar.gz -O \
/tmp/openssl-0.9.7d.tar.gz
cd /tmp
rm -rf openssl-0.9.7d
tar xvfz /tmp/openssl-0.9.7d.tar.gz
cd openssl-0.9.7d
./config
make
make test
make install
wget
ftp://ftp.openbsd.org/pub/OpenBSD/Op...h-3.9p1.tar.gz \
-O /tmp/openssh-3.9p1.tar.gz
cd /tmp
rm -rf openssh-3.9p1
tar xvfz /tmp/openssh-3.9p1.tar.gz
cd openssh-3.9p1
mv /etc/ssh/ /etc/ssh.orig
./configure --help
./configure \
--with-ldflags=-static \
--with-ssl-dir=/usr/local/ssl/ \
--sysconfdir=/etc/ssh/ \
--with-xauth=/usr/X11R6/bin/xauth
make
make install
cp /etc/rc.d/init.d/sshd /etc/rc.d/init.d/sshd.orig
emacs /etc/rc.d/init.d/sshd &
replace /usr by /usr/local
cp /etc/ssh/sshd_config /etc/ssh/sshd_config.orig
cat <<EOF>>/etc/ssh/sshd_config
Port 22
Protocol 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
PermitRootLogin no
UsePAM no
EOF
/etc/init.d/sshd restart
The above would satisfy all Rootkit Hunter 1.1.8 entries
(/usr/local/bin/rkhunter -c --createlogfile) except the
" - OpenSSL 0.9.7a [ Vulnerable ]" line, which is
moot because I installed the newer openssl-0.9.7d.tar.gz in
/usr/local/ssl/ and linked against that. I did the
above compilation with Firewall set rejecting port 22 connections, then
after sshd restarted, set Firewall to accept port 22 again.
And the machine still gets infected in one minute after client
connections !!! This means it's not just a problem of FC3T2, but the
newest and best openssl-0.9.7d.tar.gz and/or openssh-3.9p1.tar.gz. So
this could get really serious for anyone running Linux server.
I also did clean installations of Fedora Core 2, Test 1; Fedora Core
2, Final; the respective file size checking scripts are behind.
#!/bin/csh
#
# Check the file sizes of Fedora Core 2, Test 1
#
# fc2t1
#
set array = ( /bin/grep 75668 \
/bin/ls 76004 \
/usr/bin/ssh 223900 )
set i = 1
while ( $i < $#array )
set file = $array[$i]
@ j = $i + 1
set HealthySize = $array[$j]
if ( -Z $file == $HealthySize ) then
# echo $file is healthy. #
else
echo $file is hacked\! file size should be $HealthySize\!
ls -ltr $file
endif
@ i = $i + 2
end
#!/bin/csh
#
# Check the file sizes of Fedora Core 2, Final
#
# fc2
#
set array = ( /bin/grep 75716 \
/bin/ls 76932 \
/usr/bin/ssh 208872 \
/bin/su 101390 )
set i = 1
while ( $i < $#array )
set file = $array[$i]
@ j = $i + 1
set HealthySize = $array[$j]
if ( -Z $file == $HealthySize ) then
# echo $file is healthy. #
else
echo $file is hacked\! file size should be $HealthySize\!
ls -ltr $file
endif
@ i = $i + 2
end
All are infected in the same way. In my opinion there is an unknown
bug in openssl / openssh source tree and the hacker is exploiting it.
I'm running out time dealing with this because I have other jobs to
do. If I were younger I would read /bin/grep assembly code and figure
out who did it. For now I will just shut down sshd. This is a heads-up
for those in the serious security business.