From 5af4557c03a6f7087975995bca43d6969fa9ddb4 Mon Sep 17 00:00:00 2001 From: randomuser Date: Wed, 17 Feb 2021 19:42:23 -0600 Subject: [PATCH] check uid before executing netcat --- shellgopher.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/shellgopher.sh b/shellgopher.sh index 1caca7a..d912e76 100644 --- a/shellgopher.sh +++ b/shellgopher.sh @@ -11,6 +11,15 @@ createsrv () { nc -l "$1" <"$2" >>"$3" & exec 3>"$2" } +die () { + # $1 - error message + printf "%s\n" $1 + exit 1 +} +checkuid () { + [ $(whoami) = "root" ] && \ + die "You must execute shellgopher as root." +} writefile () { # $1 - file foo cat "$1" >&3 @@ -34,6 +43,7 @@ tmplocation=$(mktmp) writelocation="${tmplocation}/write" readlocation="${tmplocation}/read" +checkuid createsrv 70 "${writelocation}" "${readlocation}" printf "server created\n" while true; do