#!/bin/sh
######################
# Derek Be Gone v1.1 #
# Author: qnapd #
######################
set_mutable() {
if [ ! -e "$1" ]; then
return 0
fi
if [ -e /etc/IS_64BITS ]; then
# 64bit set mutable
SET_M_64="$1"
echo " [*] Setting mutable 64bit on $SET_M_64"
python -c "import os,fcntl,sys,struct;fd = os.open('${SET_M_64}', os.O_RDONLY); rec = struct.pack('L', 0); x = fcntl.ioctl(fd, 0x80086601, rec); flags = struct.unpack('L',x)[0]; was_immutable = flags & 0x00000010; flags = flags & ~0x00000010; f = struct.pack('i', flags); fcntl.ioctl(fd, 0x40086602, f); os.close(fd)"
else
# 32bit set mutable
SET_M_32="$1"
echo " [*] Setting mutable 32bit on $SET_M_32"
python -c "import os,fcntl,sys,struct;fd = os.open('${SET_M_32}', os.O_RDONLY); rec = struct.pack('L', 0); x = fcntl.ioctl(fd, 0x80046601, rec); flags = struct.unpack('L',x)[0]; was_immutable = flags & 0x00000010; flags = flags & ~0x00000010; f = struct.pack('i', flags); fcntl.ioctl(fd, 0x40046602, f); os.close(fd)"
fi
}
remove_bad_thing() {
badpath="$1"
if [ -e "$badpath" ]; then
echo " [*] Removing $badpath"
rm -rf "$badpath"
if [ $? -eq 0 ]; then
echo " [+] Success!"
else
echo " [-] Failed"
fi
fi
}
# clear fake qpkg
bdir=
test -f "${confdir}/smb.conf" && for i in homes Public Download Multimedia Web Recordings; do bdir=`getcfg "$i" path -f "${confdir}/smb.conf"` && test ! -z "$bdir" && bdir=`dirname "$bdir"` && test -d "$bdir" && testwriteable=$(mktemp "${bdir}/.tmp.XXXXXX") && rm "${testwriteable}" && break; bdir=''; done
test -z "${bdir}" || test ! -d "${bdir}" && { command -v readlink >/dev/null 2>&1 || ln -sf /bin/busybox /usr/bin/readlink; for i in Public Download Multimedia Web Recordings homes; do bdir=`readlink "/share/${i}" 2>/dev/null` && test ! -z "$bdir" && bdir=`dirname "$bdir"` && bdir=/share/${bdir##*/} && test -d "$bdir" && break; done;
test -z "${bdir}" || test ! -d "${bdir}"; } && { bdir=`getcfg SHARE_DEF defVolMP -f "${confdir}/def_share.info"`
test -z "${bdir}" || test ! -d "${bdir}"; } && { bdir=`mount | sed -n "s/.*\(\/share\/[^ /]\+\) .*/\1/gp" | head -n 1`
test -z "${bdir}" || test ! -d "${bdir}"; } && { for i in CACHEDEV3_DATA CACHEDEV2_DATA CACHEDEV1_DATA MD0_DATA; do test -d "/share/${i}" && bdir="/share/${i}" && break; done;
test -z "${bdir}" || test ! -d "${bdir}" && bdir=/mnt/HDA_ROOT; }
echo "[o] System path: ${bdir}"
echo "[o] Removing fake qpkg"
remove_bad_thing "${bdir}/.qpkg/.liveupdate/"
remove_bad_thing "${bdir}/.qpkg/.config/"
echo "---"
# clear dom
mdir=/tmp/config
__BOOT_DEV=
__model=`getcfg System "Internal Model"`
CONFIG_DEV_NODE=`getcfg "CONFIG STORAGE" DEVICE_NODE -f /etc/platform.conf`
CONFIG_DEV_PART=`getcfg "CONFIG STORAGE" FS_ACTIVE_PARTITION -f /etc/platform.conf`
CONFIG_DEV_FS=`getcfg "CONFIG STORAGE" FS_TYPE -f /etc/platform.conf`
__BOOT_CONF=`test -f /etc/default_config/BOOT.conf && cat /etc/default_config/BOOT.conf 2>/dev/null || cat "${confdir}/BOOT.conf"` || { test "$arch_o" = arm && __BOOT_CONF=TS-NASARM; }
command -v hal_app > /dev/null 2>&1 && { __BOOT_DEV=$(hal_app --get_boot_pd port_id=0); }
test "${__BOOT_CONF}" = TS-NASARM || test "$arch_o" = arm && { test -f /etc/IS_TAS && __BOOT_DEV="${__BOOT_DEV:-/dev/mtdblock}7" || __BOOT_DEV="${__BOOT_DEV:-/dev/mtdblock}5"; } || __BOOT_DEV="${__BOOT_DEV:-/dev/sdx}6"
test "x${CONFIG_DEV_NODE}" != "x" && { ubiattach -m "${CONFIG_DEV_PART}" -d 2; mount -t ubifs ubi2:config "${mdir}" > /dev/null 2>&1 || { test -f /etc/IS_TAS && mount -t ext4 /dev/mmcblk0p7 "${mdir}"; } } || mount ${__BOOT_DEV} -t ext2 ${mdir} || { test "${__model}" = "TS-201" && mount -t ext2 /dev/mtdblock4 ${mdir}; } || { ubiattach -m "${CONFIG_DEV_PART}" -d 2; mount -t ubifs ubi2:config "${mdir}"; mount -t ext4 /dev/mmcblk0p7 "${mdir}"; } || { test "${__model}" = "TS-269L" && mount -t ext2 /dev/sdc6 ${mdir}; } || { test "${__model}" = "TS-869" && mount -t ext2 /dev/sdi6 ${mdir}; } || { test "$arch_o" = arm || ${__BOOT_CONF} = "TS-NASARM" && { for i in 5 7 4 6 3 8; do mount -t ext2 "/dev/mtdblock${i}" ${mdir} && break; done; }; } || { test "$arch_o" = x86 && for n in /dev/sdc /dev/sdx /dev/sdi $__BOOT_DEV; do for i in 6 $CONFIG_DEV_PART; do mount -t ext2 ${n}${i} ${mdir} && break 2; done; done; } || { mount -t ext2 $(/sbin/hal_app --get_boot_pd port_id=0)6 ${mdir}; }
echo "[o] Cleaning DOM"
remove_bad_thing "$mdir/autorun.sh"
for i in $mdir/K0*.sh; do
remove_bad_thing "$i"
done
umount "$mdir"
echo "---"
# reinstall MR
echo "[o] Remove old MR"
mrpath="${bdir}/.qpkg/MalwareRemover/"
set_mutable "$mrpath"
set_mutable "$mrpath/modules/10_derek_3.pyc"
set_mutable "$mrpath/modules/12_derek_3.pyc"
remove_bad_thing "$mrpath"
rmcfg MalwareRemover -f /etc/config/qpkg.conf
echo "---"
echo "[o] Install new MR"
mrpkg=MalwareRemover_3.4.0_20190121_173849.qpkg
wget -nv "https://download.qnap.com/Storage/tsd/utility/$mrpkg"
sh "$mrpkg" > /dev/null 2>&1
getcfg MalwareRemover Enable -f /etc/config/qpkg.conf > /dev/null
if [ $? -eq 0 ]; then
echo " [+] Success!"
else
echo " [-] Failed"
fi
rm -f "$mrpkg"
echo "---"
echo "Finished!"
rm -f "$0"