我已经将Java Applet编写为学校项目,我需要一个CGI文件来在cgi-bin目录中创建一个文件。问题是当我从浏览器运行代码时,代码执行但我的文件不是用变量名创建的。什么都没有创造。这是代码
#!/usr/bin/perl -wT
use CGI;
print "content-type: text/plain\n\n";
my $q = CGI->new();
my $name = $q->param('username');
my $pw = $q->param('param');
my $bool = $q->param('bool');
my $rel = $q->param('rel');
my $ext = ".txt";
my $strt = "../cgi-bin/";
my $app = $strt . $name . $ext;
print $app;
open (FILE,'>',$app) or print "Error";
print FILE $pw . "\n";
print FILE $bool . "\n";
print FILE $rel;
close(FILE);
当我运行cgi时,它打印$ app变量,它是我想要的正确地址但是没有创建文件。如果我改变了行
open (FILE,'>',$app) or print "Error";
到
open (FILE,'>','../cgi-bin/test.txt') or print "Error";
它创建我想要的文件。任何想法为什么会在使用变量$ app时发生这种情况?无论哪种方式,我都不会在浏览器上打印错误。
解: 谢谢大家的帮助。使用时:
use CGI::Carp qw(fatalsToBrowser);
我收到了这个错误:
Content-type: text/html
<H1>Software error:</H1>
<PRE>Insecure dependency in open while running with -T switch
</PRE>
<P>
For help, please send mail to the webmaster (<a href="mailto:or webmaster">or webmaster</a>), giving this error message
and the time and date of the error.
似乎不喜欢-T。一旦我删除它,它工作。再次感谢
答案 0 :(得分:3)
为什么你用../cgi-bin写入cgi-bin? 只需使用:
open (FILE, ">$name$ext") or die $!;
和use CGI::Carp qw(fatalsToBrowser);
使用文件创建在浏览器上进行鲤鱼致死(适用于此调试)
答案 1 :(得分:1)
-T
是Perl的“污染数据”标志。它阻止您使用不受信任的数据进行不安全的操作。是的,您的脚本在没有-T
标志的情况下工作,但现在您的脚本非常不安全。
如果有人传入username
../../../../../../../../home/badguy/secret
的值,那么您将在badguy的主目录中将用户名和密码写入secret.txt
。 -T
阻止你这样做。这就是-T
存在的原因。