donglou8371 2011-11-01 09:10
浏览 33
已采纳

检测危险的unix命令行元字符

I'm working on a web application that has some api calls that send arguments for command line operations. For example, (using jquery), an api call like:

$.get('/api',{
function:function_1,
data:data
},funcion(){},'text')

might execute a command line like:

php a.php data

in that case, if the content of data was "whatever;rm -rf *;", two commands would be executed

  1. php a.php watever;
  2. rm -rf *;

And I don't want to take that risk.

My problem is not detecting when a character is part of the data string, my problem is knowing which chars should I look for?

I'm adding a list of shell command metacharacters. Please specify which characters are risky and which combination of characters (if any) are risky.


NOTE: Taken from: http://www.fmrib.ox.ac.uk/fslcourse/unix_intro/shell.html

The shell meta characters include:

\ / < > ! $ % ^ & * | { } [ ] " ' ` ~ ;

NOTE 2: There may be other characters, please, if you know another add it or comment and I'll add it.

NOTE 3: My problem is similar to what might happen with sql injection. when someone adds hidden querys inside search text-boxes, but in my case, the problem is with shell commands. To prevent sql injection you can look at this.

  • 写回答

2条回答 默认 最新

  • duanjiao1256 2011-11-01 09:14
    关注

    That's exactly what escapeshellarg is for.
    http://www.php.net/manual/en/function.escapeshellarg.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程