首页 > 数据库 >fortinet sql注入 语义分析检测

fortinet sql注入 语义分析检测

时间:2023-06-01 12:33:17浏览次数:67  
标签:sql 语义 statement SQL employee fortinet injection where select

Syntax-based SQL Injection Detection

Using regular expression based signatures to detect SQL injection attacks is core to a WAF solution however it does not go without issues. Due to the nature of the SQL language being similar to the English grammar false positives can occur together with false negatives as evasion techniques evolve. For example, one regex rule can not completely cover all the variables of a SQL injection type, such as:

SELECT * FROM users WHERE id = 1 OR 1=1

SELECT * FROM users WHERE id = 1 OR abc=abc

SELECT * FROM users WHERE id = 1 OR 3<5

SELECT * FROM users WHERE id = 1 OR UTC_DATE()=UTC_DATE()

It is a continuous and tedious process to maintain and update the signatures to address new evasion techniques and to tune false positives.

FortiWeb's Syntax-based SQL Injection Detection detects a SQL injection attack by analyzing the lexeme and syntax of SQL language rather than using a pattern matching mechanism. It first turns the input statement into a sequence of tokens, and then turns the sequence of tokens into an abstract syntax tree (AST), which is a tree representation of the abstract syntactic structure of the input statement. The parser will check whether this is a valid SQL grammar, and compare the produced AST with AST of built-in standard SQL statements to check whether they have the same AST structure. If it is not then FortiWeb recognizes it as a SQL injection attempt and then triggers the violation action.

How Syntax-based SQL Injection Detection works

When clients access web applications they input values in fields rather than the entire SQL statement. The application inserts the values into a SQL statement and sends the query to the database.

For example, you may be asked to enter the employee ID on the web page when you want to check someone's profile. The employee ID is the condition value for the query, and it is sent to the web server by a request:

GET /employee_profile.asp?employee_id=20001 HTTP/1.1

Then the received value 2001 will be combined with a SQL template to generate a SQL statement for the query:

select * from employee where employee_no = 2001

However, if a client inputs the condition value with a snippet such as 1 or 1 = 1, it might be a SQL injection attempt.

When Syntax-based SQL Injection Detection is enabled, the snippets in requests will be processed by SQL template combination, grammar parsing and AST comparison to validate whether it is a SQL injection. For example, the snippet 1 or 1 = 1 will be extracted from request

GET /employee_profile.asp?employee_id=1 or 1 = 1 HTTP/1.1

and combined with a FortiWeb built-in template

select * from t where v = [injection point]

to generate the SQL statement

select * from t where v = 1 or 1 = 1

FortiWeb runs the process to build AST for the target SQL statement and compare it with the FortiWeb built-in standard AST to see if they have the same structure. Different but equivalent SQL statements yield the same AST structure, and nonequivalent SQL statements have different AST structures. For example, here are a built-in standard statement and two target statements:

  • Built-in standard statement: select * from t where v = 1
  • Target statement 1: select * from t where v = WAF products
  • Target statement 2: select * from t where v = 1 or 1 = 1

The first target statement is equivalent to the built-in standard statement, they have the same AST structure as following:

fortinet sql注入 语义分析检测_bc

The second target statement is nonequivalent to the built-in standard statement, they are different AST structures as following and so that a SQL injection is detected:

fortinet sql注入 语义分析检测_安全分析_02

Built-in SQL statement templates

To address all possible injection points FortiWeb needs to first understand the probable context of SQL statements. The common three options are:

select * from employee where employee_no = "2001"

select * from employee where employee_no = '2001'

select * from employee where employee_no = 2001

To cover all cases that an attacker might try, Syntax-based SQL Injection Detection employs the following three templates:

  • Double Quote Based SQL Injection: select * from t where v = "[injection point]"
  • Single Quote Based SQL Injection: select * from t where v = '[injection point]'
  • As-Is Based SQL Injection: select * from t where v = [injection point]

By default, FortiWeb enables all three templates. While you can disable each one, it is not recommended to do so unless you're absolutely certain that this query type is not supported by the database.

SQL injection types

Once a snippet is identified as a SQL injection, FortiWeb will recognize the SQL injection type further as one of followings:

fortinet sql注入 语义分析检测_SQL_03

SQL Injection types

Snippet examples

Stacked queries SQL injection

1; delete from users

Embedded queries

1 union select username, password from users1 /*! ; drop table admin */

Condition based boolean injection

1 /**/OR/**/1/**/=/**/11 OR ’abc’=’abc’case 1 when 2 then 2 end1 || user_id is not null

Arithmetic operation based boolean injection

a'+'bA' DIV 'BA' & 'B

Line comments

1”--1 #abc

SQL function based boolean injection

ascii(substring(length(version()),1,1))

 

Enable Syntax Based SQL Injection detection

1.  Go to Web Protection > Known Attacks > Signatures, select existing signature policy or create a new one.

2.  Click the status button for SQL Injection (Syntax Based Detection) to enable it, and double-click to set the ActionBlock PeriodSeverity and Trigger Action for the policy:

fortinet sql注入 语义分析检测_bc_04

标签:sql,语义,statement,SQL,employee,fortinet,injection,where,select
From: https://blog.51cto.com/u_11908275/6393218

相关文章

  • SQL语句获取当天,昨天,本周,上周,本月,上月的起始时间和结束时间
    目录今天昨天本周上周本月上月今天SELECTDATE_FORMAT(NOW(),'%Y-%m-%d00:00:00')AS'今天开始';SELECTDATE_FORMAT(NOW(),'%Y-%m-%d23:59:59')AS'今天结束';昨天SELECTDATE_FORMAT(DATE_SUB(CURDATE(),INTERVAL1DAY),'%Y-%m-%d00:00:0......
  • SQL 语法笔记
    ➪SQL  ➪基本类型char/varchar/int/smallint/numeric/real,doubleprecision/float  ➪数据定义createtabledepartment//定义SQL关系 (dept_namevarchar(20),//属性名域buildingvarchar(15),budgetnumeric(12,2),primarykey(dept_name));//......
  • SQL注入绕过——主要是magic_quotes_gpc, is_int(只能跑路,无注入点),以及关键字绕过,WAF绕
       SQL注入点是可以在get、post、cookie、request、http头里等 ......
  • 利用cookie进行SQL注入——看来还是人工注入要熟悉才行
    Less-20基于错误的cookie头部POST注入首先从已知的条件中我们知道这又是一道“头部注入”,那么我们先输入正确的用户名和密码看一下登录成功是什么样子的:回显有User-Agent、IP这样从当次Request直接获取的,也有Cookie这样刷新页面后仍存在的,还有......
  • Mysql的存储过程
    一.存储过程的定义:存储过程(StoredProcedure)是在大型数据库系统中,一组为了完成特定功能的SQL语句集,经编译后存储在数据库中,用户通过指定存储过程的名字并给出参数(如果该存储过程带有参数)来执行它。二. 存储过程的优点:简化应用开发人员的工作。当用不同语言编写多客户......
  • postgresql 的 idle_session_timeout 与连接池的 max-ide-time参数
    看下面的异常:下面的错误说:terminatingconnectionduetoidle-sessiontimeout下面的这个错误说:Causedby:reactor.pool.PoolShutdownException:Poolhasbeenshutdownreactor.core.Exceptions$ErrorCallbackNotImplemented:org.springframework.dao.DataAccessResou......
  • mysql重复记录处理
    这里记录一下用到的语句和语句模板:--查询出重复的数据SELECTCOUNT(*)asrepeats,address,signer_name,signer_mobileFROMuser_operation_useraddressGROUPBYaddress,signer_name,signer_mobileHAVINGrepeats>1;--查询出重复的数据中最小的idSELECTMIN(......
  • 高频面试题|如何解决MySQL主从复制延时问题
    作者:楼仔来源:https://mp.weixin.qq.com/s/Jfrp-pLH_nfzKzwU-6gY5w这篇文章是去年写的,但是阅读量很低,不想让好的文章被埋没,重新整理后,可读性更强,文末有上周六技术派直播视频。MySQL主从一直是面试常客,里面的知识点虽然基础,但是能回答全的同学不多。比如我之前面试小米,就被问......
  • MySQL数据库10秒内插入百万条数据
    publicclassBaseDao{//静态工具类,用于创建数据库连接对象和释放资源,方便调用//导入驱动jar包或添加Maven依赖(这里使用的是Maven,Maven依赖代码附在文末)static{try{Class.forName("com.mysql.cj.jdbc.Driver");}catch(Cla......
  • Cassandra——类似levelDB的基于p2p架构的分布式NOSQL数据库
     C:Consistency一致性•A:Availability可用性(指的是快速获取数据)•P:ToleranceofnetworkPartition分区容忍性(分布式)10年前,EricBrewer教授指出了著名的CAP理论,后来SethGilbert和Nancylynch两人证明了CAP理论的正确性。CAP理论告诉我们,一个分布式系统不可能满足......