John Redyns
John Redyns

Reputation: 5913

Correcting shell script vulnerabilities

What are some simple fixes you would make for the obvious vulnerabilities in this script?

#!/bin/tcsh
# foreachfile command
# a shell script to apply command to each file in the current directory

set ListOfFiles = `ls`
set Count = 1
set ListLength = $#ListOfFiles
while ($Count <= $ListLength)
        $argv $ListOfFiles[$Count]
        @ Count = $Count + 1
end

Upvotes: 0

Views: 210

Answers (1)

Dennis Williamson
Dennis Williamson

Reputation: 360143

#!/bin/tcsh
# foreachfile command <<<< You gave away the ending!
# a shell script to apply command to each file in the current directory

foreach f (*)
        "$argv" "$f"
end

You might want to check $argv against a whitelist of permitted commands.

Upvotes: 1

Related Questions