Rendszer binárisokról ujjlenyomat

Foglalkoztatott a kérdés, hogy hogyan tudnám egyszerűen letárolni a rendszer binárisainak hash-ét és ellenőrizni, amellyel megállapítható hogy a binárisok érintetlenek. Több progit is megnéztem, köztük a tripwire-t, de inkább úgy döntöttem hogy írok rá egy egyszerű script-et ami végül is bármely rendszeren futtatható egyéb program telepítés nélkül.

Függőségek: find, mktemp, sha1sum (vagy tetszőlegesen akármelyikre átírható), gpg
-----------------------------------------------------

[code]
# ------------------------------------------
# --- CHECK SYSTEM BINARIES FINGERPRINTS ---
# ------------------------------------------

# For first time running the program creates an encrypted fingerprint
# datafile of the system binaries of particular folders.
#
# Second time it compares fingerprints of the binaries currently found
# on the system with the ones formerly stored.
#
# The encrypted fingerprint datafile should be stored somewhere else
# outside the current system because attackers can also create it
# by themselves!
#
# The program is advised to be run with root privileges.
# It uses gpg with symmetric encryption.
# Fingerprint datafile should be deleted and recreated after system update.

# Name of datafile that contains the fingerprints of system binaries
# (full path is allowed too)
OF="system_binaries_fingerprints.gpg"

# Name of temporary files
TF1=`mktemp -u`
TF2=`mktemp -u`

# Paths to the folders to look in
PT="/bin /sbin /usr/bin /usr/sbin /usr/local/bin /usr/local/sbin"

echo
if [ -a $OF ]
then

echo Searching for binaries...
find $PT -type f | sort | xargs sha1sum > $TF1
echo Decrypting datafile...
gpg -q -o $TF2 -d $OF
echo Comparing fingerprints...

if diff $TF1 $TF2; then
echo Results OK!
fi

rm -f $TF1 $TF2
echo Done.
echo

else

echo No datafile found under the name $OF !
echo Do you want to create it? [y/N]
read -n 1 -s ENC

if [ "$ENC" = "y" ]
then

echo Searching for binaries...
find $PT -type f | sort | xargs sha1sum > $TF1
echo Encrypting datafile...
if gpg -q -o $OF -c $TF1

then
echo File has been created with the name $OF !
echo Done.
echo

else
echo Failure.
echo

fi

rm -f $TF1

else

echo Nothing done.
echo

fi

fi
[/code]

Hozzászólások

Az előzőt Debian alatt teszteltem, itt a FreeBSD verzió (talán ez így kicsit kompatibilisebb):
-----------------------------------------------------------


# ------------------------------------------
# --- CHECK SYSTEM BINARIES FINGERPRINTS ---
# ------------------------------------------

# For first time running the program creates an encrypted fingerprint
# datafile of the system binaries of particular folders.
#
# Second time it compares fingerprints of the binaries currently found
# on the system with the ones formerly stored.
#
# The encrypted fingerprint datafile should be stored somewhere else
# outside the current system because attackers can also create it
# by themselves!
#
# The program is advised to be run with root privileges.
# It uses gpg with symmetric encryption.
# Fingerprint datafile should be deleted and recreated after system update.


# Name of datafile that contains the fingerprints of system binaries
# (full path is allowed too)
OF="system_binaries_fingerprints.gpg"

# Name of temporary files
TF1=`mktemp -u tmp.XXXXXX`
TF2=`mktemp -u tmp.XXXXXX`

# Paths to the folders to look in
PT="/bin /sbin /usr/bin /usr/sbin /usr/local/bin /usr/local/sbin"


echo
if [ -f $OF ]
then

   echo Searching for binaries...
   find $PT -type f | sort | xargs sha1 > $TF1
   echo Decrypting datafile...
   gpg -q -o $TF2 -d $OF
   echo Comparing fingerprints...

   if diff $TF1 $TF2; then
      echo Results OK!
   fi

   rm -f $TF1 $TF2
   echo Done.
   echo

else

   echo No datafile found under the name $OF !
   echo Do you want to create it? [y/N]
#   read -n 1 -s ENC
   read ENC

   if [ "$ENC" = "y" ]
   then

      echo Searching for binaries...
      find $PT -type f | sort | xargs sha1 > $TF1
      echo Encrypting datafile...
      if gpg -q -o $OF -c $TF1

      then
         echo File has been created with the name $OF !
         echo Done.
         echo

      else
         echo Failure.
         echo

      fi

      rm -f $TF1

   else

      echo Nothing done.
      echo

   fi

fi

ezzel 1 a gond: mivan ha az itt felhasznalt programok lettek hibasak? (sha1sum, gpg, stb)

--
A vegtelen ciklus is vegeter egyszer, csak kelloen eros hardver kell hozza!

irnal arrol hogy melyik programokat probaltad es miert nem tetszettek?

udv Zoli

Kicsit elkéstél vele. Telepítés után első dolgod kellett volna, hogy legyen.
Másrészt a tripwire nem véletlenül olyan, amilyen, szóval én ezt nem bíznám egy scriptre. Túl sok ponton támadható. Magyarul továbbra sem lehetsz biztos semmiben.

------------------------
Debian testing KDE amd64
MSI K8N-Neo-4, Athlon64 3800+, Leadtek 6600GT

Igen, lehet. Viszont talán az egyetlen biztos pont lehet a rendszerben.
Ha már ujjlenyomatot ellenőrzünk, legalább az integritás-ellenőrző csomag legyen megbízható. Félmunkát végezni csak időpocsékolás.

------------------------
Debian testing KDE amd64
MSI K8N-Neo-4, Athlon64 3800+, Leadtek 6600GT

Naná, hogy a neve ugyanaz marad :) Még a funkciója is majdnem. Csak egy-két apróságot esetleg nem mutat. Az rkhunter.dat fájlt, ami alapján az összehasonlítást végzi, módosíthatta-e valaki? Az rkhunter fájlról készített hash megegyezik-e azzal, amit telepítettél? És ha igen, az md5sum (sha1sum) igazat mond-e? És ha igen, az adatbázisfájl, amivel összehasonlítod a fájl ujjlenyomatát, érintetlen-e, vagy már hamis adat van benne?

------------------------
Debian testing KDE amd64
MSI K8N-Neo-4, Athlon64 3800+, Leadtek 6600GT

Persze, de te az rkhunter binárisáról beszéltél, ami nincs, mivel script. Akárcsak az, amit a topicnyitó írt. A tárolt hasheket persze módosíthatta akárki, de ez a fönti scriptre is igaz.
Nem azt mondtam, hogy ultimate megoldás, csak azt kérdeztem, hogy ez a script miért jobb.

--
Debian - The "What?!" starts not!
http://nyizsa.uni.cc

AIX-ben ilyen celra van kulon telepitesi opcio, a TCB (Trusted Computing Base), szoval ott csak a gyari DVD-ben kell megbizni ;-)