您的位置:首页 > Web前端 > JavaScript

Coverity面向脚本语言的静态分析(1)- Javascript前端/服务器端的XSS/DOM_XSS

2016-10-15 20:54 417 查看
书分千篇,金字百言,我要说人分三种,肯定有某些女生或者喜欢女生的男人砍我。。。
好了,还是说编程语言吧,粗略的分类来看,编程语言分三种:编译型语言,解释型语言和脚本语言。

编译型语言在执行前有一个单独的编译和链接过程,将代码翻译成机器能够识别的语言和指令,如C/C++。

解释型语言在运行的时候把代码翻译成机器能够识别指令,所以运行速度比编译型语言要慢一些,例如Java或者C#。
脚本语言:不知道怎么解释和定义(求告知),只能举几个例子:Javascript,Python,Ruby,PHP。

今天用Javascript来聊聊脚本语言的静态分析技术,工具仍为Coverity,静态分析的好处就不多说了,简单扼要的介绍就是能够直接定位到源代码中的质量与安全问题。
首先Coverity获取Javascript的过程和C/C++/Java/C#都不同。这次是直接获取Javascript代码(cov-build --fs-capture-search js目录),后台将重新对JS执行一次内部沟通工作,识别JS的语义和逻辑(具体详情不详述,很复杂也很坎坷,据说硅谷的工程师们挠破了头)。全部指令如下:

cov-build --dir jscapturedirectory --fs-capture-search jsfiledirectory --no-command

cov-analyze --dir idir --all --webapp-security --webapp-security-preview --webapp-config-checkers --distrust-all --webapp-security-aggressiveness-level=high

最终检测的结果如下:

3 CONSTANT_EXPRESSION_RESULT

5 COPY_PASTE_ERROR

15 DEADCODE

3 DOM_XSS

23 FORWARD_NULL

1 MISSING_BREAK

1 NESTING_INDENT_MISMATCH

50 NO_EFFECT

3 NULL_RETURNS

2 REVERSE_INULL

10 XSS

今天我们只关注XSS,所以介绍下两种XSS漏洞:

XSS(Cross-site Scripting (XSS))

Cross-Site Scripting (XSS) attacks are a type of injection, in which malicious scripts are injected into otherwise benign and trusted web sites. XSS attacks occur when an attacker uses a web application to send malicious code, generally in the form of a
browser side script, to a different end user. Flaws that allow these attacks to succeed are quite widespread and occur anywhere a web application uses input from a user within the output it generates without validating or encoding it.

An attacker can use XSS to send a malicious script to an unsuspecting user. The end user’s browser has no way to know that the script should not be trusted, and will execute the script. Because it thinks the script came from a trusted source, the malicious
script can access any cookies, session tokens, or other sensitive information retained by the browser and used with that site. These scripts can even rewrite the content of the HTML page.

看一下Javascript的案例:



DOM_XSS(DOM Based
XSS (or as it is called in some texts, “type-0 XSS”))

DOM_XSS is an XSS attack wherein the attack payload is executed as a result of modifying the DOM “environment” in the victim’s browser used by the original client side script, so that the client side code runs in an “unexpected” manner. That is, the page
itself (the HTTP response that is) does not change, but the client side code contained in the page executes differently due to the malicious modifications that have occurred in the DOM environment.

This is in contrast to other XSS attacks (stored or reflected), wherein the attack payload is placed in the response page (due to a server side flaw).

同样的,示例如下:



几点说明:

红色的步骤(1,2,3,4)以及说明是Coverity自动添加的,黄色部分是Coverity给出的修改建议。中文版本说明如下:(我本人不太喜欢中文版:))


/

另:JS是我比较不熟悉的语言之一,如果写的不好,欢迎大家指出,我来修改。

如果大家想试用Coverity,请直接与我联系,我的电话(微信):13311307163,邮箱:Bao.Han@synopsys.com。

关于Coverity

Coverity是技术源自于斯坦福大学的最新一代的源代码静态分析工具,能够快速检测并定位源代码中可能导致产品崩溃、未知行为、安全缺口或者灾难性故障的软件缺陷。具有缺陷分析种类多、分析精度高和误报率低的特点,是业界误报率最低的源代码分析工具(小于15%)。Coverity Development Platform目前包含以下功能:

代码质量缺陷与安全漏洞检测:

Coverity 的智能静态分析引擎能够帮助开发者在工作流程中找出质量缺陷和安全漏洞,提供精确、可行的修复指导,在开发过程中识别关键质量缺陷,降低风险并减少项目成本。通过深刻理解行为和问题危急程度, Coverity SAVE 可以智能测试,精确找出那些潜在的难以发现的能够引发崩溃的问题,包括C/C++, Java (JSP)和 C #(ASP) ,Objective-C, Android,Javascript, Python, PHP代码库。

能够检测出的质量缺陷类型示例:

• 空指针引用,资源泄漏,死锁,内存崩溃,安全缺陷/缓冲区溢出,API使用错误,未初始化变量,类层次结构不一致,性能效率低下,安全最佳实践违反,代码维护问题 ,程序挂起,错误处理问题,并行数据访问违规,竞态条件,错误表达,控制数据流问题,内存非法访问,不安全数据处理。

代码安全与Web 应用安全审计:

Coverity 的安全审计引擎能够通过识别JSP和ASP网站中可能导致安全漏洞的关键缺陷,降低风险和项目成本。Coverity Static Analysis Verification Engine 能够智能检测出C/C++应用和Java web应用中的缺陷,包括缓存区溢出、整数溢出、格式字符串错误、SQL注入、系统命令行注入、资源泄露、目录遍历和跨站脚本攻击 (XSS)等问题,全面覆盖OWASP Top10。

以往的安全工具在开发中失败的主要原因是高误报率或结果不正确。Coverity设计的新引擎,能够解决现代应用的复杂问题,并获得更为精准的结果。

适用于web应用安全的Coverity SAVE 分析创新包括:

•企业框架分析器: 深刻理解现代web 应用,增加源代码分析包括依赖性注入,进入点以及MVC范例

•白盒模糊测试 自动验证日常数据清理惯例,对不可信数据进行充分清理,确保使用环境正确

客户状况:Coverity是第一个能够快速、准确分析当今的大规模(百万行、千万行甚至上亿行)、高复杂度代码的工具,目前已经检测了超过50亿行专有代码和开源代码。全球有超过1100个像华为,中兴,联想,百度,三星,腾讯,Apple,Honeywell, NEC, BAE Systems, Juniper Networks, BMC Software, Samsung, France Telecom, Sega, 和 Schneider Electric这样的品牌和企业依靠Coverity确保其产品和服务的质量与安全。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: