简体   繁体   English

sendmail和代码注入

[英]sendmail & code injection

I am sending content through 'sendmail' that includes some user supplied data. 我通过'sendmail'发送包含一些用户提供的数据的内容。 I call it using perl, eg 我用perl调用它,例如

open(MAIL, "| /usr/sbin/sendmail -fsomeone\@somewhere.com -t ") 
print MAIL "the user content..."
close(MAIL)

Are there any risks here, eg a user formats his data in a way that injects code? 这里有任何风险,例如用户以注入代码的方式格式化他的数据吗?

The Perl script itself isn't at risk through this specifically (I'm assuming that "the user content" stands for, say, the contents of a variable). Perl脚本本身没有特别危险(我假设“用户内容”代表变量的内容)。 But whoever gets the mail is at the mercy of whatever "the user content..." might be. 但无论是谁收到邮件都受到“用户内容......”的影响。

To make sure nothing bad happens, we'd need to see much more of your script. 为了确保没有任何不好的事情发生,我们需要看到更多的脚本。 Read (and make sure you understand) Dawid Wheeler's "Secure programming for Linux and Unix HOWTO" , look also for secure Perl programming (perhaps the CERT standard is a good starting point). 阅读(并确保您理解)Dawid Wheeler的“针对Linux和Unix HOWTO的安全编程” ,还要考虑安全的Perl编程(也许CERT标准是一个很好的起点)。

That depends if the email adress in the command line argument is hardcoded, or user-supplied. 这取决于命令行参数中的电子邮件地址是硬编码还是用户提供的。

If the command is hardcoded, and you use a double-quoted string, the @somewhere array will be interpolated. 如果命令是硬编码的,并且您使用双引号字符串,则将插入@somewhere 数组 I assume this is a typo, and it would be backslashed. 我认为这是一个错字,它会被反击。

If that adress can be user-set ( open MAIL, "| ... -f$adress" ), then this is vulnerable to shell code injection: $adress = '; rm -rf * ;' 如果该地址可以是用户设置的( open MAIL, "| ... -f$adress" ),那么这很容易受到shell代码注入: $adress = '; rm -rf * ;' $adress = '; rm -rf * ;'

This can be avoided by input validation, and/or by using multiple arguments for open : 这可以通过输入验证和/或使用open多个参数来避免:

open my $MAIL, "|-", "/usr/bin/sendmail", @args or die ...;
  • Lexical Filehandles are better Lexical Filehandles更好
  • Explicit open mode as seperate argument is safer ( |- -| < > >> +< ) 作为单独参数的显式打开模式更安全( |- -| < > >> +<
  • Multiple arguments to avoid shell interpretation of command. 避免shell解释命令的多个参数。
  • Return value checking 返回值检查

The -t flag will (iirc) read header values from the user input. -t标志将(iirc)从用户输入读取标头值。 This will not affect the security of your script, but would allow the user to include bogus headers. 这不会影响脚本的安全性,但会允许用户包含伪标题。 Users may be able to abuse your script for their purposes, eg spamming! 用户可能会滥用您的脚本用于其目的,例如垃圾邮件! It might be better to construct the header yourself, and restrict the user to providing the body of the message only. 自己构造标题可能更好,并限制用户仅提供消息正文。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM