mirror of
https://github.com/tasket/Qubes-VM-hardening.git
synced 2025-08-18 03:10:33 -04:00
Fixes, add CLI service.
This commit is contained in:
parent
e288485024
commit
caa901593d
2 changed files with 36 additions and 19 deletions
|
@ -1,9 +1,10 @@
|
||||||
[Unit]
|
[Unit]
|
||||||
Description=Script protections to enhance vm-sudo
|
Description=Script protections to enhance VM security
|
||||||
After=qubes-sysinit.service
|
After=qubes-sysinit.service
|
||||||
Before=qubes-mount-dirs.service
|
Before=qubes-mount-dirs.service
|
||||||
ConditionPathExists=|/var/run/qubes-service/vm-sudo-protect
|
ConditionPathExists=|/var/run/qubes-service/vm-sudo-protect
|
||||||
ConditionPathExists=|/var/run/qubes-service/vm-sudo-protect-root
|
ConditionPathExists=|/var/run/qubes-service/vm-sudo-protect-root
|
||||||
|
ConditionPathExists=|/var/run/qubes-service/vm-sudo-protect-cli
|
||||||
DefaultDependencies=false
|
DefaultDependencies=false
|
||||||
OnFailure=shutdown.target
|
OnFailure=shutdown.target
|
||||||
OnFailureJobMode=replace-irreversibly
|
OnFailureJobMode=replace-irreversibly
|
||||||
|
|
|
@ -11,17 +11,19 @@
|
||||||
# to be protected
|
# to be protected
|
||||||
chfiles=".bashrc .bash_profile .bash_login .bash_logout .profile \
|
chfiles=".bashrc .bash_profile .bash_login .bash_logout .profile \
|
||||||
.xprofile .xinitrc .xserverrc .xsession"
|
.xprofile .xinitrc .xserverrc .xsession"
|
||||||
chdirs=".config/autostart .config/plasma-workspace/env .config/plasma-workspace/shutdown \
|
chdirs=".config/autostart .config/plasma-workspace/env \
|
||||||
.config/autostart-scripts"
|
.config/plasma-workspace/shutdown .config/autostart-scripts"
|
||||||
vmname=`qubesdb-read /name`
|
vmname=`qubesdb-read /name`
|
||||||
rw=/mnt/rwtmp
|
rw=/mnt/rwtmp
|
||||||
|
|
||||||
# Make user scripts immutable:
|
# Function: Make user scripts immutable.
|
||||||
make_immutable() {
|
make_immutable() {
|
||||||
|
#initialize_home $rw/home ifneeded
|
||||||
cd $rw/home/user
|
cd $rw/home/user
|
||||||
mkdir -p $chdirs
|
mkdir -p $chdirs
|
||||||
touch $chfiles
|
touch $chfiles
|
||||||
chattr -R -f +i $chfiles $chdirs
|
chattr -R -f +i $chfiles $chdirs
|
||||||
|
cd /root
|
||||||
touch $rw/home/user/FIXED #debug
|
touch $rw/home/user/FIXED #debug
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +37,11 @@ else
|
||||||
-e "bash -i"
|
-e "bash -i"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
if qsvc vm-sudo-protect-cli; then
|
||||||
|
xterm -hold -display :0 -title "VM PROTECTION: SERVICE PROMPT" \
|
||||||
|
-e "echo Private volume is mounted at $rw; bash -i"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Protection measures for /rw dirs:
|
# Protection measures for /rw dirs:
|
||||||
# Activated by presence of vm-sudo-protect-root Qubes service.
|
# Activated by presence of vm-sudo-protect-root Qubes service.
|
||||||
|
@ -64,46 +71,55 @@ if qsvc vm-sudo-protect-root && is_rwonly_persistent; then
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# Files mutable for del/copy operations
|
# Files mutable for del/copy operations
|
||||||
cd $rw/home/user
|
cd $rw/home/user
|
||||||
chattr -R -f -i $chfiles $chdirs $privdirs
|
chattr -R -f -i $chfiles $chdirs $privdirs
|
||||||
|
cd /root
|
||||||
|
|
||||||
# Deactivate private.img config dirs
|
# Deactivate private.img config dirs
|
||||||
for dir in $privdirs; do
|
for dir in $privdirs; do
|
||||||
rm -rf BAK-$dir
|
bakdir=`dirname $dir`/BAK-`basename $dir`
|
||||||
mv $dir BAK-$dir
|
rm -rf $bakdir
|
||||||
|
mv $dir $bakdir
|
||||||
done
|
done
|
||||||
mkdir -p $privdirs
|
mkdir -p $privdirs
|
||||||
|
|
||||||
for vmset in vms.all $vmname; do
|
for vmset in vms.all $vmname; do
|
||||||
|
|
||||||
# Process whitelists...
|
# Process whitelists...
|
||||||
while read wlfile; do
|
cat $defdir/$vmset.whitelist \
|
||||||
|
| while read wlfile; do
|
||||||
# Must begin with '/rw/'
|
# Must begin with '/rw/'
|
||||||
if echo $wlfile |grep -q "^\/rw\/"; then #Was [ $wlfile =~ ^\/rw\/ ];
|
if echo $wlfile |grep -q "^\/rw\/"; then #Was [ $wlfile =~ ^\/rw\/ ];
|
||||||
srcfile="`sed -r \"s|^/rw/(.+)$|$rw/BAK-\1|\" <<<\"$wlfile\"`"
|
srcfile="`echo $wlfile |sed -r \"s|^/rw/(.+)$|$rw/BAK-\1|\"`"
|
||||||
# For large dirs: instant mv whole dir when entry ends with '/'
|
dstfile="`echo $wlfile |sed -r \"s|^/rw/(.+)$|$rw/\1|\"`"
|
||||||
if echo $wlfile |grep -q "\/$"; then #Was [ $wlfile =~ .+\/$ ];
|
dstdir="`dirname \"$dstfile\"`"
|
||||||
mkdir -p "`dirname \"$wlfile\"`"
|
if [ ! -e "$srcfile" ]; then
|
||||||
mv "$srcfile" "`dirname \"$wlfile\"`"
|
echo "Whitelist entry not present in filesystem."
|
||||||
|
continue
|
||||||
|
# For very large dirs: mv whole dir when entry ends with '/'
|
||||||
|
elif echo $wlfile |grep -q "\/$"; then
|
||||||
|
echo "Whitelist mv $srcfile"
|
||||||
|
mkdir -p "$dstdir"
|
||||||
|
mv "$srcfile" "$dstdir"
|
||||||
else
|
else
|
||||||
cp -al --parents "$srcfile" /
|
echo "Whitelist cp $srcfile"
|
||||||
|
cp -a --link "$srcfile" "$dstdir"
|
||||||
fi
|
fi
|
||||||
else
|
elif [ -n "$wlfile" ]; then
|
||||||
echo "Whitelist path must begin with /rw/."
|
echo "Whitelist path must begin with /rw/."
|
||||||
fi
|
fi
|
||||||
done <$defdir/$vmset.whitelist
|
done
|
||||||
|
|
||||||
# Copy default files...
|
# Copy default files...
|
||||||
if [ -d $defdir/$vmset/rw ]; then
|
if [ -d $defdir/$vmset/rw ]; then
|
||||||
cp -af $defdir/$vmset/rw/* $rw
|
cp -af "$defdir/$vmset/rw/*" $rw
|
||||||
fi
|
fi
|
||||||
|
|
||||||
done
|
done
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
make_immutable
|
make_immutable
|
||||||
cd /
|
umount $rw
|
||||||
umount $rw && rmdir $rw
|
|
||||||
exit 0
|
exit 0
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue