Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: Re: Trojan Horse? (taint mode)

by cfreak (Chaplain)
on Nov 26, 2001 at 20:42 UTC ( [id://127569]=note: print w/replies, xml ) Need Help??


in reply to Re: Trojan Horse? (taint mode)
in thread Trojan Horse? (taint mode)

I think its very clear... I decided to try it as the author stated above. I used echo because well - I like my system the way it is. And its a good thing I did too because the command executed. This is what I have:
#!/usr/bin/perl $a ="${system(\"echo 'hello from system'\")}\n"; print "$a";
And this is the output:
hello from system stupid.pl

I think this is what the author is talking about. Now when I use the q or qq it responds as you said so I guess that perl treats qq differently than an actual double quote. Something I didn't know. Interestingly enough it prints the name of the script out as well when this command executes... not sure why.

Replies are listed 'Best First'.
Re: Re: Re: Trojan Horse? (taint mode)
by blakem (Monsignor) on Nov 26, 2001 at 23:35 UTC
    I see no difference in the behavior of the following two lines:
    $a = qq|${system("echo 'hello from system'")}\n|; $a = "${system(\"echo 'hello from system'\")}\n";
    They both execute the 'echo' command which sends a message to your terminal and returns 0. My perl (5.00503 and 5.6.1 on unix) then complains that 0 is not a scalar ref and dies. Apparently your perl is casting the return value of 0 into a scalar ref to 0, and $a is assigned the value of $0, which happens to be the name of the script.

    The book seems to imply that this behavior emulates what would happen if $a had come from user input. Fortunately that is not the case. If $a had come from STDIN, none of the above caveats would apply. Try it:

    #!/usr/bin/perl -wT use strict; my $a = <STDIN>; chomp($a); print "$a";
    </code>

    -Blake

      Opps must have foobared my test. You are correct
      $a = qq|${system("echo 'hello from system'")}\n|; $a = "${system(\"echo 'hello from system'\")}\n";

      do the same thing. Some how I had your example simply printing the string... hmmm

      Anyway I read the author to mean to not do this:
      $a = <stdin>; print "Some string with ${$a}";

      But as you stated I'm finding that doesn't work, which is very strange to me. It seems as though it should, and there could be really cool uses for it.

      That said, to get somewhat back on the orginal topic using taint mode is still a good idea, especially in CGI scripts. The trick is to learn what should be untainted and what doesn't have to be.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://127569]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (4)
As of 2024-04-19 04:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found