查找空格注入PHP文件 [英] Find whitespace-injecting PHP files

查看:161
本文介绍了查找空格注入PHP文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在空白的PHP文件有时是有问题的,所以我试图找到符合共同问题的标准文件。我试图找到递归所有文件其中有一个或两个条件:

1)不开始< 字符

和/或

2)无法在结束方式> 字符,除非它确实结束之后是新行的任何数量的右括号

我认为,第一个条件是: $ [^<#]

我认为,第二个条件是: [^> ^] | [} \\ n * ^]

不过,请注意,我天真的正则表达式 $ ^ 重新present的开始和结束该文件,文件中没有任何行。甚至与那些,假设他们是正确的,我将如何结合呢?像这样?

  [$ [^<#] | [[[^> ^] | [} \\ n * ^]]]

然后,他们将在grep的:

 的grep -r [$ [^<#] | [[[^> ^] | [} \\ n * ^]]] *

显然,这是行不通的(TM)。谁能教我如何纠正错误?谢谢你。

这是一个很好的文件:

 < PHP?>

所以是这样的:

 < PHP
功能someFunc(){
}

而这也很好:

 #!的/ usr / bin中/ PHP -q
< PHP
?>

HTML领导是好的:

 < HTML和GT;
< PHP
呼应'< / HTML>';
?>

追踪HTML是罚款太:

 < PHP
呼应'< HTML和GT;';
?>
< / HTML>

这是不好的(领导换行):

 
< PHP?>

这是太糟糕(前导空格):

 < PHP?>

这是不好的,以及(尾随的换行符):

 < PHP?> 


解决方案

扔了一个前pression真正的快,我认为你想要做什么。这是pretty晚在这里,由于某种原因,我的计算器。无论如何,我希望我得到了你的请求权。

试试这个普通的前pression / \\ A(?:\\ S + *> | [^<#*> \\ S * |< *方式> \\ S +)\\ Z / S 。这里解释: http://regex101.com/r/cT7eY5

我希望这帮助。如果我以任何方式误会你了,请你澄清,我会尽量调整前pression。

Whitespace in PHP files is sometimes problematic, so I'm trying to find files which meet common problematic criteria. I'm trying to find all files recursively which have one or both of these conditions:

1) Does not begin with a < or # character.

and/or

2) Does not end in a > character, unless it does end in a close brace which is followed by any amount of newlines.

I think that the first condition would be: $[^<#]

I think that the second condition would be: [ [^>^] | [}\n*^]]

However, note that in my naive regexes $ and ^ represent the start and end of the file, not of any line in the file. And even with those, assuming that they were correct, how would I combine them? Like so?

[$[^<#]] | [[ [^>^] | [}\n*^]]]

Then, putting them in grep:

grep -r [$[^<#]] | [[ [^>^] | [}\n*^]]] *

Obviously, this is Not Working (tm). Can someone teach me how to correct the mistakes? Thanks.

This is a good file:

<?php

?>

So is this:

<?php
function someFunc(){
}


‏

And this is good too:

#!/usr/bin/php -q
<?php
?>

Leading HTML is fine:

<html>
<?php
echo '</html>';
?>

Trailing HTML is fine too:

<?php
echo '<html>';
?>
</html>

This is bad (leading newline):

‏
<?php

?>

This is bad too (leading space):

‏ <?php

?>

This is bad as well (trailing newline):

<?php

?>
‏

解决方案

Tossed up an expression real quick that I think does what you want. It's pretty late here and for some reason I'm on stackoverflow. Regardless, I hope I got your request right.

Try this regular expression /\A(?:\s+.*>|[^<#].*>\s*|<.*>\s+)\Z/s. Explained here: http://regex101.com/r/cT7eY5

I hope this help. If I misunderstood you in any way, please clarify and I will try to adjust the expression.

这篇关于查找空格注入PHP文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆