简体   繁体   English

在Web服务器日志中包含“A = 0或”0 = A的奇怪URL

[英]Strange URL containing 'A=0 or '0=A in web server logs

During the last weekend some of my sites logged errors implying wrong usage of our URLs: 在上周末,我的一些网站记录了错误,意味着错误使用了我们的网址:

...news.php?lang=EN&id=23'A=0

or 要么

...news.php?lang=EN&id=23'0=A

instead of 代替

...news.php?lang=EN&id=23

I found only one page originally which mentioned this ( https://forums.adobe.com/thread/1973913 ) where they speculated that the additional query string comes from GoogleBot or an encoding error. 我发现最初只提到了一页( https://forums.adobe.com/thread/1973913 ),他们推测附加的查询字符串来自GoogleBot或编码错误。

I recently changed my sites to use PDO instead of mysql_* . 我最近改变了我的网站使用PDO而不是mysql_* Maybe this change caused the errors? 也许这种变化导致错误? Any hints would be useful. 任何提示都会有用。


Additionally, all of the requests come from the same user-agent shown below. 此外,所有请求都来自下面显示的相同用户代理。

Mozilla/5.0 (Windows; U; Windows NT 5.1; pt-PT; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 (.NET CLR 3.5.30729)

This lead me to find the following threads: pt-BR and Strange parameter in URL - what are they trying? 这导致我找到以下线程: URL中的 pt-BRStrange参数 - 他们在尝试什么?

It is a bot testing for SQL injection vulnerabilities by closing a query with apostrophe, then setting a variable. 它是通过使用撇号关闭查询然后设置变量来测试SQL注入漏洞的机器人。 There are also similar injects that deal with shell commands and/or file path traversals. 还有类似的注入处理shell命令和/或文件路径遍历。 Whether it's a "good bot" or a bad bot is unknown, but if the inject works, you have bigger issues to deal with. 无论是“好机器人”还是坏机器人都是未知的,但如果注入有效,那么你需要处理更大的问题。 There's a 99% chance your site is not generating these style links and there is nothing you can do to stop them from crafting those urls unless you block the request(s) with a simple regex string or a more complex WAF such as ModSecurity. 您的网站有99%的可能无法生成这些样式链接,除非您使用简单的正则表达式字符串或更复杂的WAF(如ModSecurity)阻止请求,否则您无法阻止他们制作这些网址。

Blocking based on user agent is not an effective angle. 基于用户代理的阻止不是有效的角度。 You need to look for the request heuristics and block based on that instead. 您需要查找请求启发式和基于此的阻止。 Some examples of things to look for in the url/request/POST/referrer, as both utf-8 and hex characters: 在url / request / POST / referrer中查找的一些示例,包括utf-8和hex字符:

  • double apostrophes 双撇号
  • double periods, especially followed by a slash in various encodings 双倍期间,特别是随后的各种编码斜线
  • words like "script", "etc" or "passwd" 像“script”,“etc”或“passwd”这样的词
  • paths like dev/null used with piping/echoing shell output dev/null这样的路径用于管道/回显shell输出
  • %00 null byte style characters used for init a new command %00用于初始化新命令的空字节样式字符
  • http in the url more than once (unless your site uses it) 网址中的http不止一次(除非您的网站使用它)
  • anything regarding cgi (unless your site uses it) 关于cgi任何事情(除非你的网站使用它)
  • random "enterprise" paths for things like coldfusion, tomcat, etc 随机的“企业”路径,如coldfusion,tomcat等

If you aren't using a WAF, here is a regex concat that should capture many of those within a url. 如果你没有使用WAF,这里有一个正则表达式concat,它应该捕获url中的许多内容。 We use it in PHP apps, so you may/will need to tweak some escapes/looks depending on where you are using this. 我们在PHP应用程序中使用它,因此您可能需要调整一些转义/外观,具体取决于您使用它的位置。 Note that this has .cgi , wordpress , and wp-admin along with a bunch of other stuff in the regex, remove them if you need to. 请注意,这里有.cgiwordpresswp-admin以及正则表达式中的一堆其他内容,如果需要,请将其删除。

$invalid = "(\(\))"; // lets not look for quotes. [good]bots use them constantly. looking for () since technically parenthesis arent valid
$period = "(\\002e|%2e|%252e|%c0%2e|\.)";
$slash = "(\\2215|%2f|%252f|%5c|%255c|%c0%2f|%c0%af|\/|\\\)"; // http://security.stackexchange.com/questions/48879/why-does-directory-traversal-attack-c0af-work
$routes = "(etc|dev|irj)" . $slash . "(passwds?|group|null|portal)|allow_url_include|auto_prepend_file|route_*=http";
$filetypes = $period . "+(sql|db|sqlite|log|ini|cgi|bak|rc|apk|pkg|deb|rpm|exe|msi|bak|old|cache|lock|autoload|gitignore|ht(access|passwds?)|cpanel_config|history|zip|bz2|tar|(t)?gz)";
$cgis = "cgi(-|_){0,1}(bin(-sdb)?|mod|sys)?";
$phps = "(changelog|version|license|command|xmlrpc|admin-ajax|wsdl|tmp|shell|stats|echo|(my)?sql|sample|modx|load-config|cron|wp-(up|tmp|sitemaps|sitemap(s)?|signup|settings|" . $period . "?config(uration|-sample|bak)?))" . $period . "php";
$doors = "(" . $cgis . $slash . "(common" . $period . "(cgi|php))|manager" . $slash . "html|stssys" . $period . "htm|((mysql|phpmy|db|my)admin|pma|sqlitemanager|sqlite|websql)" . $slash . "|(jmx|web)-console|bitrix|invoker|muieblackcat|w00tw00t|websql|xampp|cfide|wordpress|wp-admin|hnap1|tmunblock|soapcaller|zabbix|elfinder)";
$sqls = "((un)?hex\(|name_const\(|char\(|a=0)";
$nulls = "(%00|%2500)";
$truth = "(.{1,4})=\1"; // catch OR always-true (1=1) clauses via sql inject - not used atm, its too broad and may capture search=chowder (ch=ch) for example
$regex = "/$invalid|$period{1,2}$slash|$routes|$filetypes|$phps|$doors|$sqls|$nulls/i";

Using it, at least with PHP, is pretty straight forward with preg_match_all() . 使用它,至少使用PHP,使用preg_match_all()非常简单。 Here is an example of how you can use it: https://gist.github.com/dhaupin/605b35ca64ca0d061f05c4cf423521ab 以下是如何使用它的示例: https//gist.github.com/dhaupin/605b35ca64ca0d061f05c4cf423521ab

WARNING: Be careful if you set this to autoban (ie, fail2ban filter). 警告:如果将其设置为autoban(即fail2ban过滤器),请务必小心。 MS/Bing DumbBots (and others) often muck up urls by entering things like strange triple dots from following truncated urls, or trying to hit a tel: link as a URi. MS / Bing DumbBots(以及其他人)经常通过输入以下截断的网址中的奇怪三重点或者尝试将tel: link作为URi来查找网址。 I don't know why. 我不知道为什么。 Here is what i mean: A link with text www.example.com/link-too-long...truncated.html may point to a correct url, but Bing may try to access it "as it looks" instead of following the href , resulting in a WAF hit due to double dots. 这就是我的意思:带有文本www.example.com/link-too-long...truncated.html的链接可能指向一个正确的URL,但Bing可能会尝试“看起来像”而不是href ,由于双点导致WAF命中。

since this is a very old version of FireFox, I blocked it in my htaccess file - 因为这是FireFox的一个非常旧的版本,我在我的htaccess文件中阻止了它 -

RewriteCond %{HTTP_USER_AGENT} Firefox/3\.5\.2 [NC]
RewriteRule .* err404.php  [R,L]

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

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