in reply to Perl as a command executor (with hash variable substitution)
You need Perl to perform variable interpolation on a previously existing string. You can accomplish this using a string eval, after formatting your input like a string to be interpolated. This means escaping potentially problematic characters first like backslashes and previously existing quotes.
my %TEST_HASH = (TEST_KEY => 'TEST_VALUE'); my $cmd = '/bin/touch $TEST_HASH{"TEST_KEY"}'; $cmd =~ s/\\/\\\\/g; $cmd =~ s/"/\\"/g; $cmd = eval qq{"$cmd"} or die $@; print $cmd
Please don't run your intended code on any machine you care about security on, because this is pretty much the definition of injection and privilege escalation.
#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Perl as a command executor (with hash variable substitution)
by RecursionBane (Beadle) on Mar 21, 2013 at 19:29 UTC | |
by McA (Priest) on Mar 21, 2013 at 19:40 UTC | |
by AnomalousMonk (Archbishop) on Mar 22, 2013 at 00:20 UTC | |
by RecursionBane (Beadle) on Apr 02, 2013 at 21:36 UTC |