Inception工具测试报告


Inception测试

Inception作为一种SQL审核的工具出来之后就被多方面关注,而是不适合自己的公司状况,一切还是要看测试结果。这里就做一个工具测试,供大家参考。安装和参数使用在官方写的新详细大家可以自己过去看。

测试前准备

创建测试用户inc
 
mysql> grant all privileges on *.* to 'inc'@'192.168.127.%';
Query OK, 0 rows affected, 1 warning (0.00 sec)
创建测试库inception_test
 
mysql> create database inception_test;

Inception SQL审核测试

1、建表语句
建表语句检查项
  • 表属性的检查项
    • 这个表不存在
    • 对于create table like,会检查like的老表是不是存在。
    • 对于create table db.table,会检查db这个数据库是不是存在
    • 表名、列名、索引名的长度不大于64个字节
    • 如果建立的是临时表,则必须要以tmp为前缀
    • 必须要指定建立innodb的存储引擎(可配置)
    • 必须要指定utf8的字符集(字符串可配置,指定支持哪些字符集)
    • 表必须要有注释(可配置)
    • 表不能建立为分区表(可配置)
    • 只能有一个自增列
    • 索引名字不能是Primay
    • 不支持Foreign key(可配置)
    • 建表时,如果指定auto_increment的值不为1,报错(可配置)
    • 如果自增列的名字不为id,说明有可能是有意义的,MySQL这样使用比较危险,所以报警(可配置)
  • 列属性的检查项
    • 不能设置列的字符集(可配置)
    • 列的类型不能使用集合、枚举、位图类型。(可配置)
    • 列必须要有注释(可配置)
    • char长度大于20的时候需要改为varchar(长度可配置)
    • 列的类型不能是BLOB/TEXT。(可配置)
    • 每个列都使用not null(可配置)
    • 如果列为BLOB/TEXT类型的,则这个列不能设置为NOT NULL。
    • 如何是自增列,则使用无符号类型(可配置)
    • 如果自增列,则长度必须要大于等于4个字节(可配置)
    • 如果是timestamp类型的,则要必须指定默认值。
    • 对于MySQL5.5版本(包含)以下的数据库,不能同时有两个TIMESTAMP类型的列,如果是DATETIME类型,则不能定义成DATETIME DEFAULT CURRENT_TIMESTAMP及ON UPDATE CURRENT_TIMESTAMP等语句。
    • 每个列都需要定义默认值,除了自增列、主键列及大字段列之外(可配置)
    • 不能有重复的列名
  • 索引属性检查项
    • 索引必须要有名字
    • 不能有外键(可配置)
    • Unique索引必须要以uniq_为前缀(可配置)
    • 普通索引必须要以idx_为前缀(可配置)
    • 索引的列数不能超过5个(数目可以配置)
    • 表必须要有一个主键(可配置)
    • 最多有5个索引(数目可配置)
    • 建索引时,指定的列必须存在。
    • 索引中的列,不能重复
    • BLOB列不能建做KEY
    • 索引长度不能超过766
    • 不能有重复的索引,名字及内容
  • 默认值检查项
  • BLOB/TEXT类型的列,不能有非NULL的默认值
  • MySQL5.5以下(含)的版本,对于DATETIME类型的列,不能有函数NOW()的默认值。
  • 如果设置默认值为函数,则只能是NOW()。
  • 如果默认值为NULL,但列类型为NOT NULL,或者是主键列,或者定义为自增列,则报错。
  • 自增列不能设置默认值。
建表语句审核测试
Python脚本 testa.py
 
#/usr/bin/python
#-\*-coding: utf-8-\*-
import MySQLdb
sql='/*--user=inc;--password=;--host=192.168.127.128;--execute=1;--port=3306;*/\
inception_magic_start;\
use inception_test;\
create table `test1`(id int);\
inception_magic_commit;'
try:
    conn=MySQLdb.connect(host='192.168.127.129',user='test',passwd='123456',db='mysql',port=6669)
    cur=conn.cursor()
    ret=cur.execute(sql)
    result=cur.fetchall()
    num_fields = len(cur.description)
    field_names = [i[0] for i in cur.description]
    print field_names
    for row in result:
        print row[0], "|",row[1],"|",row[2],"|",row[3],"|",row[4],"|",
        row[5],"|",row[6],"|",row[7],"|",row[8],"|",row[9],"|",row[10]
    cur.close()
    conn.close()
except MySQLdb.Error,e:
     print "Mysql Error %d: %s" % (e.args[0], e.args[1])

审核未通过
 
$ python testa.py 
['ID', 'stage', 'errlevel', 'stagestatus', 'errormessage', 'SQL', 'Affected_rows', 'sequence', 'backup_dbname', 'execute_time', 'sqlsha1']
1 | CHECKED | 0 | Audit completed | None | 2 | CHECKED | 1 | Audit completed | Set engine to innodb for table 'test1'.
Set charset to one of 'utf8mb4' for table 'test1'.
Set comments for table 'test1'.
Column 'id' in table 'test1' have no comments.
Column 'id' in table 'test1' is not allowed to been nullable.
Set Default value for column 'id' in table 'test1'
Set a primary key for table 'test1'. |

审核通过
 
$ python testa.py 
['ID', 'stage', 'errlevel', 'stagestatus', 'errormessage', 'SQL', 'Affected_rows', 'sequence', 'backup_dbname', 'execute_time', 'sqlsha1']
1 | RERUN | 0 | Execute Successfully | None | 2 | EXECUTED | 2 | Execute Successfully
Backup failed | Backup: Access denied for user 'wzf1'@'localhost' (using password: YES)
Backup: Access denied for user 'wzf1'@'localhost' (using password: YES) |


2、插入语句
插入语句检查项
  • 表是否存在
  • 必须指定插入列表,也就是要对哪几个列指定插入值,如insert into t (id,id2) values(...),(可配置)
  • 必须指定值列表,与上面对应的列,插入的值是什么,必须要指定。
  • 插入列列表与值列表个数相同,上面二者的个数需要相同,如果没有指定列列表(因为可配置),则值列表长度要与表列数相同。
  • 不为null的列,如果插入的值是null,报错(可配置)
  • 插入指定的列名对应的列必须是存在的。
  • 插入指定的列列表中,同一个列不能出现多次。
  • 插入值列表中的简单表达式会做检查,但具体包括什么不一一指定

插入语句审核测试
Python脚本 testb.py
 
#/usr/bin/python
#-\*-coding: utf-8-\*-
import MySQLdb
sql='/*--user=inc;--password=;--host=192.168.127.128;--execute=1;--port=3306;*/\
inception_magic_start;\
use inception_test;\
insert into test2 values(1);\
inception_magic_commit;'
try:
    conn=MySQLdb.connect(host='192.168.127.129',user='test',passwd='123456',db='mysql',port=6669)
    cur=conn.cursor()
    ret=cur.execute(sql)
    result=cur.fetchall()
    num_fields = len(cur.description)
    field_names = [i[0] for i in cur.description]
    print field_names
    for row in result:
        print row[0], "|",row[1],"|",row[2],"|",row[3],"|",row[4],"|",
        row[5],"|",row[6],"|",row[7],"|",row[8],"|",row[9],"|",row[10]
    cur.close()
    conn.close()
except MySQLdb.Error,e:
     print "Mysql Error %d: %s" % (e.args[0], e.args[1])

审核未通过
 
$ python testb.py 
['ID', 'stage', 'errlevel', 'stagestatus', 'errormessage', 'SQL', 'Affected_rows', 'sequence', 'backup_dbname', 'execute_time', 'sqlsha1']
1 | CHECKED | 0 | Audit completed | None | 2 | CHECKED | 2 | Audit completed | Set the field list for insert statements.
Column count doesn't match value count at row 1. |

审核通过
 
['ID', 'stage', 'errlevel', 'stagestatus', 'errormessage', 'SQL', 'Affected_rows', 'sequence', 'backup_dbname', 'execute_time', 'sqlsha1']
1 | RERUN | 0 | Execute Successfully | None | 2 | EXECUTED | 2 | Execute Successfully
Backup failed | Backup: Access denied for user 'wzf1'@'localhost' (using password: YES)
Backup: Access denied for user 'wzf1'@'localhost' (using password: YES) |

3、更新、删除语句
更新、删除语句检查项
  • 表是否存在
  • 必须有where条件(可配置)
  • delete语句不能有limit条件(可配置)
  • 不能有order by语句(可配置)
  • 影响行数大于10000条,则报警(数目可配置)
  • 对WHERE条件这个表达式做简单检查,具体包括什么不一一指定
  • 对更新列的值列表表达式做简单检查,具体不一一指定
  • 对更新列对象做简单检查,主要检查列是不是存在等
  • 多表更新、删除时,每个表必须要存在

更新语句审核测试
Python脚本 testc.py
 
#/usr/bin/python
#-\*-coding: utf-8-\*-
import MySQLdb
sql='/*--user=inc;--password=;--host=192.168.127.128;--execute=1;--port=3306;*/\
inception_magic_start;\
use inception_test;\
update test2 set realname="chenlehan"  where username="b";\
inception_magic_commit;'
try:
    conn=MySQLdb.connect(host='192.168.127.129',user='test',passwd='123456',db='mysql',port=6669)
    cur=conn.cursor()
    ret=cur.execute(sql)
    result=cur.fetchall()
    num_fields = len(cur.description)
    field_names = [i[0] for i in cur.description]
    print field_names
    for row in result:
        print row[0], "|",row[1],"|",row[2],"|",row[3],"|",row[4],"|",
        row[5],"|",row[6],"|",row[7],"|",row[8],"|",row[9],"|",row[10]
    cur.close()
    conn.close()
except MySQLdb.Error,e:
     print "Mysql Error %d: %s" % (e.args[0], e.args[1])

审核通过
 
$ python testc.py 
['ID', 'stage', 'errlevel', 'stagestatus', 'errormessage', 'SQL', 'Affected_rows', 'sequence', 'backup_dbname', 'execute_time', 'sqlsha1']
1 | RERUN | 0 | Execute Successfully | None | 2 | EXECUTED | 2 | Execute Successfully
Backup failed | Backup: Access denied for user 'wzf1'@'localhost' (using password: YES)
Backup: Access denied for user 'wzf1'@'localhost' (using password: YES) |

删除语句审核测试
Python脚本 testd.py
 
#/usr/bin/python
#-\*-coding: utf-8-\*-
import MySQLdb
sql='/*--user=inc;--password=;--host=192.168.127.128;--execute=1;--port=3306;*/\
inception_magic_start;\
use inception_test;\
delete from test2 where username="b";\
inception_magic_commit;'
try:
    conn=MySQLdb.connect(host='192.168.127.129',user='test',passwd='123456',db='mysql',port=6669)
    cur=conn.cursor()
    ret=cur.execute(sql)
    result=cur.fetchall()
    num_fields = len(cur.description)
    field_names = [i[0] for i in cur.description]
    print field_names
    for row in result:
        print row[0], "|",row[1],"|",row[2],"|",row[3],"|",row[4],"|",
        row[5],"|",row[6],"|",row[7],"|",row[8],"|",row[9],"|",row[10]
    cur.close()
    conn.close()
except MySQLdb.Error,e:
     print "Mysql Error %d: %s" % (e.args[0], e.args[1])

审核通过
 
$ python testd.py 
['ID', 'stage', 'errlevel', 'stagestatus', 'errormessage', 'SQL', 'Affected_rows', 'sequence', 'backup_dbname', 'execute_time', 'sqlsha1']
1 | RERUN | 0 | Execute Successfully | None | 2 | EXECUTED | 2 | Execute Successfully
Backup failed | Backup: Access denied for user 'wzf1'@'localhost' (using password: YES)
Backup: Access denied for user 'wzf1'@'localhost' (using password: YES) |


4、查询语句
不支持大部分查询语句的优化,不能使用select *语句

查询语句审核测试
Python脚本 teste.py
 
#/usr/bin/python
#-\*-coding: utf-8-\*-
import MySQLdb
sql='/*--user=inc;--password=;--host=192.168.127.128;--execute=1;--port=3306;*/\
inception_magic_start;\
use inception_test;\
select * from test2 where username="b";\
inception_magic_commit;'
try:
    conn=MySQLdb.connect(host='192.168.127.129',user='test',passwd='123456',db='mysql',port=6669)
    cur=conn.cursor()
    ret=cur.execute(sql)
    result=cur.fetchall()
    num_fields = len(cur.description) 
    field_names = [i[0] for i in cur.description]
    print field_names
    for row in result:
        print row[0], "|",row[1],"|",row[2],"|",row[3],"|",row[4],"|",
        row[5],"|",row[6],"|",row[7],"|",row[8],"|",row[9],"|",row[10]
    cur.close()
    conn.close()
except MySQLdb.Error,e:
     print "Mysql Error %d: %s" % (e.args[0], e.args[1])

审核未通过
 
$ python teste.py 
['ID', 'stage', 'errlevel', 'stagestatus', 'errormessage', 'SQL', 'Affected_rows', 'sequence', 'backup_dbname', 'execute_time', 'sqlsha1']
1 | CHECKED | 0 | Audit completed | None | 2 | CHECKED | 1 | Audit completed | Select only star is not allowed. |



测试中遇到的问题
1、执行脚本时报错:
 
ImportError: libmysqlclient.so.20: cannot open shared object file: No such file or directory
解决方法:
找到libmysqlclient.so.20的绝对路径,链接到/usr/lib64目录下(如果是32位的链接到/usr/lib目录下)
2、
启动报错:
2017-07-11 01:19:59 16291 [ERROR] Can't start server : Bind on unix socket: No such file or directory
指定的配置文件中socket文件目录是否存在、是否有权限

注意
配置脚本时,注意如下部分,try中的port为inception客户端的端口号
 
try:
    conn=MySQLdb.connect(host='192.168.127.129',user='test',passwd='123456',db='mysql',port=6669)
    cur=conn.cursor()
    ret=cur.execute(sql)
    result=cur.fetchall()
    num_fields = len(cur.description)
    field_names = [i[0] for i in cur.description]
    print field_names
    for row in result:
        print row[0], "|",row[1],"|",row[2],"|",row[3],"|",row[4],"|",
        row[5],"|",row[6],"|",row[7],"|",row[8],"|",row[9],"|",row[10]
    cur.close()
    conn.close()
except MySQLdb.Error,e:
     print "Mysql Error %d: %s" % (e.args[0], e.args[1])












结论:我们能看出,Inception在ddl审核和dml审核方面是很给力的,但是在select语句的使用稍显不足,只支持检测使用*的情况,并没有针对是否有使用索引的情况的审核。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值