命令注入漏洞和缓解措施

命令注入基本上是通过web应用程序执行操作系统命令的注入。命令注入攻击的目的是在易受攻击的应用程序中注入并执行攻击者指定的命令。在这种情况下,执行不需要的系统命令的应用程序就像一个伪系统外壳,攻击者可以将其用作任何授权的系统用户。但是,命令的执行权限和环境与web应用程序相同。由于缺乏正确的输入数据验证,可能会发生命令注入攻击,攻击者可以对输入数据进行操作(表单、cookie、HTTP头等)。

null

有一种变体 代码注入攻击 .在代码注入中,攻击者将自己的代码添加到现有代码中。注入的代码以与应用程序相同的权限和环境执行。

当攻击者试图通过易受攻击的应用程序执行系统级命令时,就会发生OS命令注入攻击。如果应用程序在系统级命令中使用用户输入,则被认为容易受到OS命令注入攻击。

例子:

// C program to demonstrate Command Injection attack
// The purpose of the program to print contents of a
// file provided as command line argument.
#include <stdio.h>
#include <unistd.h>
int main( int argc, char **argv)
{
char cat[] = "cat " ;
char *command;
size_t commandLength;
commandLength = strlen (cat) + strlen (argv[1]) + 1;
command = ( char *) malloc (commandLength);
strncpy (command, cat, commandLength);
strncat (command, argv[1], (commandLength - strlen (cat)) );
system (command);
return (0);
}


通常情况下,输出只是请求文件的内容:

$ ./a.out exploit.txt
my name is akash

但是,如果我们在这一行的末尾添加一个分号和另一个命令,该命令将由catWrapper执行,没有任何问题:

$ ./a.out "exploit.txt; ls"
my name is akash
exploit.txt               doubFree.c              nullpointer.c
unstosig.c              www*                    a.out*
format.c                strlen.c                useFree*
catWrapper*             misnull.c               strlength.c             useFree.c
commandinjection.c      nodefault.c             trunc.c                 writeWhatWhere.c

以下PHP代码片段容易受到命令注入攻击(web app):

<?php
print ( "Please specify the name of the file to delete" );
print ( "<p>" );
$file = $_GET [ 'filename' ];
system( "rm $file" );
?>


以下请求和响应是成功攻击的一个示例:

Request
http://mywesite.com/delete.php?filename=bob.txt;id
Response
Please specify the name of the file to delete
uid=33(www-data) gid=33(www-data) groups=33(www-data) 

缓解

  • 理想情况下,开发人员应该为他们的语言使用现有的API。例如(Java):而不是使用运行时。exec()要发出“mail”命令,请使用位于javax的可用Java API。邮件*
  • 如果不存在这样的可用API,开发人员应该清除所有输入中的恶意字符。实施积极的安全模式将是最有效的。通常,定义合法字符比定义非法字符容易得多。

工具书类 https://en.wikipedia.org/wiki/Code_injection http://stackoverflow.com/questions/44799/preventing-command-line-injection-attacks

本文由 阿卡什·沙兰 .如果你喜欢GeekSforgek,并想贡献自己的力量,你也可以使用 贡献极客。组织 或者把你的文章寄到contribute@geeksforgeeks.org.看到你的文章出现在Geeksforgeks主页上,并帮助其他极客。

如果您发现任何不正确的地方,或者您想分享有关上述主题的更多信息,请写下评论。

© 版权声明
THE END
喜欢就支持一下吧
点赞6 分享