mirror of https://schlomp.space/tastytea/hashboot
parent
db4669df68
commit
5b02e0e994
111
hashboot
111
hashboot
|
@ -12,7 +12,7 @@
|
||||||
# meet some day, and you think this stuff is worth it, you can give us a hug. #
|
# meet some day, and you think this stuff is worth it, you can give us a hug. #
|
||||||
###################################################################################
|
###################################################################################
|
||||||
|
|
||||||
VERSION="0.9.1"
|
VERSION="0.9.2"
|
||||||
PATH="/bin:/usr/bin:/sbin:/usr/sbin:${PATH}"
|
PATH="/bin:/usr/bin:/sbin:/usr/sbin:${PATH}"
|
||||||
|
|
||||||
DIGEST_FILE="/var/lib/hashboot.digest"
|
DIGEST_FILE="/var/lib/hashboot.digest"
|
||||||
|
@ -53,23 +53,23 @@ write_hashes ()
|
||||||
echo "#hashboot ${VERSION} - Algorithm: $(basename ${HASHER})" > ${1}
|
echo "#hashboot ${VERSION} - Algorithm: $(basename ${HASHER})" > ${1}
|
||||||
|
|
||||||
if [ $((${CKMODES} & 001)) != 0 ]; then
|
if [ $((${CKMODES} & 001)) != 0 ]; then
|
||||||
#copy mbr to file
|
#copy mbr to file
|
||||||
dd if=${MBR_DEVICE} of=${MBR_TMP} bs=${MBR_SIZE}K count=1 status=${DD_STATUS} || die 8
|
dd if=${MBR_DEVICE} of=${MBR_TMP} bs=${MBR_SIZE}K count=1 status=${DD_STATUS} || die 8
|
||||||
#Write hash of MBR to ${1}
|
#Write hash of MBR to ${1}
|
||||||
${HASHER} ${MBR_TMP} >> ${1}
|
${HASHER} ${MBR_TMP} >> ${1}
|
||||||
fi
|
fi
|
||||||
if [ $((${CKMODES} & 010)) != 0 ]; then
|
if [ $((${CKMODES} & 010)) != 0 ]; then
|
||||||
#Write hashes of all regular files to ${1}
|
#Write hashes of all regular files to ${1}
|
||||||
find /boot -type f -exec ${HASHER} --binary {} >> ${1} +
|
find /boot -type f -exec ${HASHER} --binary {} >> ${1} +
|
||||||
fi
|
fi
|
||||||
if [ $((${CKMODES} & 100)) != 0 ]; then
|
if [ $((${CKMODES} & 100)) != 0 ]; then
|
||||||
#if we set an programmer chip in config
|
#if we set an programmer chip in config
|
||||||
if [ ! ${PROGRAMMER} == "no" ]; then
|
if [ ! ${PROGRAMMER} == "no" ]; then
|
||||||
#read bios to file
|
#read bios to file
|
||||||
flashrom --programmer ${PROGRAMMER} -r ${BIOS_TMP} > /dev/null 2>&1
|
flashrom --programmer ${PROGRAMMER} -r ${BIOS_TMP} > /dev/null 2>&1
|
||||||
#and write hashes of bios files to ${1}
|
#and write hashes of bios files to ${1}
|
||||||
${HASHER} ${BIOS_TMP} >> ${1}
|
${HASHER} ${BIOS_TMP} >> ${1}
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ fi
|
||||||
# Debian < 8 check
|
# Debian < 8 check
|
||||||
if which lsb_release > /dev/null 2>&1 && [ "$(lsb_release -si)" == "Debian" ] && [ $(lsb_release -sr | cut -d'.' -f1) -lt 8 ]
|
if which lsb_release > /dev/null 2>&1 && [ "$(lsb_release -si)" == "Debian" ] && [ $(lsb_release -sr | cut -d'.' -f1) -lt 8 ]
|
||||||
then
|
then
|
||||||
DD_STATUS="noxfer"
|
DD_STATUS="noxfer"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
#Look for config file and set ${MBR_DEVICE}.
|
#Look for config file and set ${MBR_DEVICE}.
|
||||||
|
@ -153,25 +153,25 @@ if [ "${2}" > "1" ]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ $((${CKMODES} & 001)) != 0 ]; then
|
if [ $((${CKMODES} & 001)) != 0 ]; then
|
||||||
# Find out where the first partition starts and set ${MBR_SIZE} in KiB
|
# Find out where the first partition starts and set ${MBR_SIZE} in KiB
|
||||||
sectorsize=$(LC_ALL=C fdisk -l ${MBR_DEVICE} | grep '^Units' | awk '{print $8}' )
|
sectorsize=$(LC_ALL=C fdisk -l ${MBR_DEVICE} | grep '^Units' | awk '{print $8}' )
|
||||||
if [ "${sectorsize}" == "=" ] # Older versions of util-linux
|
if [ "${sectorsize}" == "=" ] # Older versions of util-linux
|
||||||
then
|
then
|
||||||
sectorsize=$(LC_ALL=C fdisk -l ${MBR_DEVICE} | grep '^Units' | awk '{print $9}' )
|
sectorsize=$(LC_ALL=C fdisk -l ${MBR_DEVICE} | grep '^Units' | awk '{print $9}' )
|
||||||
fi
|
fi
|
||||||
startsector=$(LC_ALL=C fdisk -l ${MBR_DEVICE} | grep -A1 'Device' | tail -n1 | awk '{print $2}' )
|
startsector=$(LC_ALL=C fdisk -l ${MBR_DEVICE} | grep -A1 'Device' | tail -n1 | awk '{print $2}' )
|
||||||
if [ "${startsector}" == "*" ] # If partition is marked as boot, read next field
|
if [ "${startsector}" == "*" ] # If partition is marked as boot, read next field
|
||||||
then
|
then
|
||||||
startsector=$(LC_ALL=C fdisk -l ${MBR_DEVICE} | grep -A1 'Device' | tail -n1 | awk '{print $3}' )
|
startsector=$(LC_ALL=C fdisk -l ${MBR_DEVICE} | grep -A1 'Device' | tail -n1 | awk '{print $3}' )
|
||||||
fi
|
fi
|
||||||
|
|
||||||
MBR_SIZE=$(expr ${sectorsize} \* ${startsector} / 1024)
|
MBR_SIZE=$(expr ${sectorsize} \* ${startsector} / 1024)
|
||||||
|
|
||||||
if [ ${?} != 0 ]
|
if [ ${?} != 0 ]
|
||||||
then
|
then
|
||||||
echo "Something went wrong. Most likely your partition table is corrupt." >&2
|
echo "Something went wrong. Most likely your partition table is corrupt." >&2
|
||||||
die 1 "You have to recover the MBR manually by copying the mbr from ${BACKUP_FILE}"
|
die 1 "You have to recover the MBR manually by copying the mbr from ${BACKUP_FILE}"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "${1}" == "index" ]
|
if [ "${1}" == "index" ]
|
||||||
|
@ -222,32 +222,37 @@ then
|
||||||
[ -f ${DIGEST_FILE} ] || die 9 "No digestfile"
|
[ -f ${DIGEST_FILE} ] || die 9 "No digestfile"
|
||||||
HASHER=$(head -n1 ${DIGEST_FILE} | awk '{print $5}')
|
HASHER=$(head -n1 ${DIGEST_FILE} | awk '{print $5}')
|
||||||
if [ $((${CKMODES} & 001)) != 0 ]; then
|
if [ $((${CKMODES} & 001)) != 0 ]; then
|
||||||
dd if=${MBR_DEVICE} of=${MBR_TMP} bs=${MBR_SIZE}K count=1 status=${DD_STATUS} || die 8
|
dd if=${MBR_DEVICE} of=${MBR_TMP} bs=${MBR_SIZE}K count=1 status=${DD_STATUS} || die 8
|
||||||
if ! grep ${MBR_TMP} ${DIGEST_FILE} | ${HASHER} --check --warn --quiet --strict | tee ${LOG_FILE}
|
grep ${MBR_TMP} ${DIGEST_FILE} | ${HASHER} --check --warn --quiet --strict | tee ${LOG_FILE}
|
||||||
then
|
if [ ${PIPESTATUS[1]} -ne 0 ]
|
||||||
echo " !! TIME TO PANIK: MBR WAS MODIFIED !!"
|
then
|
||||||
COUNTER=$((COUNTER + 1))
|
echo " !! TIME TO PANIK: MBR WAS MODIFIED !!"
|
||||||
fi
|
COUNTER=$((COUNTER + 1))
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
if [ $((${CKMODES} & 010)) != 0 ]; then
|
if [ $((${CKMODES} & 010)) != 0 ]; then
|
||||||
if ! grep -v ${MBR_TMP} ${DIGEST_FILE} | grep -v ${BIOS_TMP} | ${HASHER} --check --warn --quiet --strict | tee -a ${LOG_FILE}
|
grep -v ${MBR_TMP} ${DIGEST_FILE} | grep -v ${BIOS_TMP} | ${HASHER} --check --warn --quiet --strict | tee -a ${LOG_FILE}
|
||||||
then
|
if [ ${PIPESTATUS[1]} -ne 0 ]
|
||||||
echo " !! TIME TO PANIK: AT LEAST 1 FILE WAS MODIFIED !!"
|
then
|
||||||
COUNTER=$((COUNTER + 2))
|
echo " !! TIME TO PANIK: AT LEAST 1 FILE WAS MODIFIED !!"
|
||||||
die $COUNTER
|
COUNTER=$((COUNTER + 2))
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
if [ $((${CKMODES} & 100)) != 0 ]; then
|
if [ $((${CKMODES} & 100)) != 0 ]; then
|
||||||
flashrom --programmer ${PROGRAMMER} -r ${BIOS_TMP} > /dev/null 2>&1
|
flashrom --programmer ${PROGRAMMER} -r ${BIOS_TMP} > /dev/null 2>&1
|
||||||
#if we set an programmer chip in config, find line with hash for bios and compare. if smthg wrong, panic
|
#if we set an programmer chip in config, find line with hash for bios and compare. if smthg wrong, panic
|
||||||
if [ ! ${PROGRAMMER} == "no" ]; then
|
if [ ! ${PROGRAMMER} == "no" ]; then
|
||||||
if ! grep ${BIOS_TMP} ${DIGEST_FILE} | ${HASHER} --check --warn --quiet --strict | tee -a ${LOG_FILE}
|
grep ${BIOS_TMP} ${DIGEST_FILE} | ${HASHER} --check --warn --quiet --strict | tee -a ${LOG_FILE}
|
||||||
then
|
if [ ${PIPESTATUS[1]} -ne 0 ]
|
||||||
echo " !! TIME TO PANIK: BIOS WAS MODIFIED !!"
|
then
|
||||||
COUNTER=$((COUNTER + 10))
|
echo " !! TIME TO PANIK: BIOS WAS MODIFIED !!"
|
||||||
die $COUNTER
|
COUNTER=$((COUNTER + 10))
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ ${COUNTER} -gt 0 ]; then
|
||||||
|
die ${COUNTER}
|
||||||
fi
|
fi
|
||||||
elif [ "${1}" == "recover" ]
|
elif [ "${1}" == "recover" ]
|
||||||
then
|
then
|
||||||
|
|
Loading…
Reference in New Issue