SQL注入:如何击败ANSI SQL模式(用两个引号转义单引号)



我在一个练习网站上玩,试图击败一个在密码字段上使用ANSI SQL模式(用"(两个单引号)转义单引号)的网站。我的目标是登录。我已经知道用户名了。

我在密码字段中尝试了许多组合,例如以下。我想我必须使用反斜杠的一些变体,但我已经困惑了很长一段时间。我很感激你的帮助,谢谢!

'or'1'='1

如果它是可利用的,您必须找出应用程序层将忽略的适当转义符,但数据库不会。

有几个选项:

'  This is a single escaped quote, that presents as a literal instead of a transalation.
''  This is another way of escaping quotes, depending on the sql generator,
though since you have an engine that doubles quotes, this would end up being ''''
'' A literal quote escape quote is sometimes necessary to get through more than one layer of abstraction
\' May pass on a double quote with the escaped  generating an odd number of quotes

有时,验证解析器容易受到某些字符的攻击,因为它们使用正则表达式或文字查找器,但不考虑不同类型的字符,因此您可以选择解析器不会继续使用但不会破坏SQL 的内容

t n Playing around with spaces that might not be recognized might allow 
you to hide your attack string from the quote doubler.
-- /**/  These are sql comments that could disrupt the validator.

一些SQL解析器会将Unicode、html代码、十六进制或其他字符格式转换为ASCII以供执行,这些解析器在数量惊人且不幸的SQL服务器上工作。

U+02BC is a apostrophe modifier that can translate to a simple apostrophe
U+0027 is the Unicode for an apostrophe
' is the html code for an apostrophe.

有许多不同的unicode/html/hex值可能会被翻译成转义符或单引号字符,这是因为许多字符无法映射回ASCII,而且翻译器并不总是做得很好。

因此,最好的做法是尝试返回一条带有错误sql字符串的错误消息,然后从那里重新构建。您不需要直接从SQL攻击开始,错误会告诉您要处理的内容。如果你可以通过任何类型的错误来确定版本,即使它不是转义,你也可能会得到一个打印版本的SQL错误,你可以查找漏洞。有时超长的ASCII文本行也会导致此问题。

最新更新