slimm609 / checksec

Checksec
https://slimm609.github.io/checksec
Other
2.04k stars 306 forks source link

fix missing sysctl in PATH for root #192

Closed spdfnet closed 2 years ago

spdfnet commented 2 years ago

After cleaning the ENV, # echo $PATH returns just this for root:

/usr/local/bin:/usr/bin

Whereas sysctl is in sbin # whereis sysctl:

sysctl: /usr/sbin/sysctl

This PR fixes the following:

+ for command in cat awk sed sysctl uname mktemp openssl grep stat file find sort head ps readlink basename id which xargs
+ command_exists sysctl
+ type sysctl
+ echo -e '\e[31mWARNING: '\''sysctl'\'' not found! It'\''s required for most checks.\e[0m'
WARNING: 'sysctl' not found! It's required for most checks.
+ commandsmissing=true
slimm609 commented 2 years ago

@spdfnet are you running this as root?

The default path for system binaries should be /sbin/ and /usr/sbin/. The linux filesystem hierarchy standard declares those 2 locations so those should be included if your user is root. https://refspecs.linuxfoundation.org/FHS_3.0/fhs/ch03s16.html

if /sbin and /usr/sbin are not included in your default root path, something may not be correct.

slimm609 commented 2 years ago

Can you run with the --debug flag and provide the output?

spdfnet commented 2 years ago

Some more context: Fedora 35 uses: checksec-2.4.0-3.fc35.noarch F36: checksec-2.5.0-2.fc36.noarch

Spotted the issue with user 'root': # checksec --debug

WARNING: 'sysctl' not found! It's required for most checks.

WARNING: Not all necessary commands found. Some tests might not work!

# echo $PATH

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin

# type sysctl

sysctl is /usr/sbin/sysctl

And by 'cleaning the env', I mean this line: [ "$(env | /bin/sed -r -e '/^(PWD|SHLVL|_)=/d')" ] && exec -c "$0" "$@" -> which messes with the $PATH with root. Not sure what really causes it, I also failed to understand the differences between versions :)

slimm609 commented 2 years ago

fixed in #193