将有趣的信息返回到不同的注射中


Returning fun messages to different injections

我正在开发一个Web应用程序。有一个输入框来跟踪订单,并对任何人开放。如果有人试图注入易受攻击的脚本,我想返回有趣的消息。例如,如果有人尝试老派的把戏

' OR '1'='1

它可能会返回"看来你是一个初学者!请多学习,再试一次'。我必须用正则表达式检查输入吗?还是有其他更好的方法?有人开发过这样的脚本吗?

哈哈很有趣。好吧,我可以帮助您清理输入,但是如果您真的想这样做.试试这个:

public function verifyMessageSubject($ps)
{
    if (!preg_match('%^[A-Za-z0-9"<>/,]{3,100}$%', stripcslashes(trim($ps))))
            return false;
    return true;
}

如果你想清理输入,你可以试试这个

public function sanitize($data)// CALL THIS FUNCTION BEFORE CALLING ANY OTHER FUNCTION
{
    $data = trim($data);
    $data = strip_tags($data);
    $data = stripcslashes($data);
    return $data;
}
public function isCrudFree($data)
{
    $flags = array("SELECT", "ALTER", "INSERT", "CREATE", "DROP", "TRUNCATE", "DELETE", "=", "GRANT");
    foreach ($flags as $key => $value) 
    {
        $x = stripos($data, $value);
        if ($x !== FALSE)  // find array elements in the given string
            return false;
        return true;
    }
}
有很多

方法可以清理您的数据。如果您决定调用黑客,您将不得不在谷歌上搜索很多内容以确保您的输入安全。(不是一个好主意)

如果您使用的是Apache(可能但不保证),则也许可以利用.htaccess来重定向尝试在url,POST请求等中执行恶意命令的用户

RewriteCond %{THE_REQUEST} ^.*(''r|''n).* [NC,OR]
RewriteCond %{HTTP_REFERER} ^(.*)(<|>|%0A|%0D|%27|%3C|%3E|%00).* [NC,OR]
RewriteCond %{HTTP_COOKIE} ^.*(<|>|?|%0A|%0D|%27|%3C|%3E|%00).* [NC,OR]
RewriteCond %{REQUEST_URI} ^/(,|;|:|<|>|?>|?<|/|'''.'.'').{0,9999}.* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^.*({'s?:;};|'/bin'/bash|'/cgi-bin'/|'/dev'/tcp'/|'/dev'/udp'/).* [NC,OR]
RewriteCond %{QUERY_STRING} ^.*({'s?:;};|'/bin'/bash|'/cgi-bin'/|'/dev'/tcp'/|'/dev'/udp'/).* [NC,OR]
RewriteCond %{QUERY_STRING} ^.*(;|<|>|?|?|')|%22|%27|%3C|%3E|%00).*(/'*|union|select|insert|cast|set|declare|drop|update|md5|benchmark).* [NC,OR]
RewriteCond %{QUERY_STRING} ^.*(localhost|loopback|127'.0'.0'.1).* [NC,OR]
RewriteCond %{QUERY_STRING} ^.*(<|>|%27|%3C|%3E|%00).* [NC,OR]
RewriteCond %{QUERY_STRING} base64_encode.*'(.*') [NC,OR]
RewriteCond %{QUERY_STRING} base64_decode.*'(.*') [NC,OR]
RewriteCond %{QUERY_STRING} printf.*'(.*') [NC,OR]
# configure `funny` to intercept the `ref` parameter as an example!
RewriteRule ^(.*)$ http://%{SERVER_NAME}/funny/?ref=$1 [L,R=301]