IAST工具Semmle QL初探

Semmle公司获得2100美元的B轮融资,领投方为Accel Partners,这是后者第二次投资这家公司。其他投资者包括Work-BenchCapital OneCredit Suisse、谷歌、微软、NASANasdaq Trust。本轮融资后,Semmle的融资总额将达到3100万美元。那么被业界追捧的Semmle有什么产品呢?

 

Semmle公司声称以一种独特的方法寻找代码中的漏洞。技术核心是把代码当成数据,将分析问题变成对数据库的请求。Semmle QL是一个声明式的面向对象的查询语言。它是现代数据记录的变体,对于那些想有无限的能力去询问他们代码的问题的人是理想的,并通过询问QL将开发团队信息和他们想要的数据库方式联系起来。

 

Semmle QL的功能主要包括:

  1. 寻找安全漏洞的所有实例。
  2. 检查API是否使用正确。
  3. 搜索指定库的使用——它在哪里被谁使用。
  4. 报告标准,例如代码行或测试方法的数量等。
  5. 完成任何其他搜索或你能想象到的分析。

其公司提供了一个免费的检测平台,lgtm.com,提供广大的安全团队和开发人员使用。平台地址是https://lgtm.com/下面通过试用这个平台,初步认识一下这个工具。

打开网站注册后,要使用平台,需要与github进行关联,可以对github中的项目进行检测。如果我们想使用这个平台,首先是要把自己的代码上传到github,且不能设置为私有。直接分析master上的项目,子分支项目好像不能关联。

在“My Projects”中与github进行关联后,创建一个新项目,输入github上项目url后,即可进行检测,根据项目大小检测时间不等,时间感觉还是比较长。

等检测完成后,发现的缺陷统计如下图:

打开某个errors后,看到如下界面:

其中红色条表示对其上面语句的检测出的缺陷的描述。

上述检测是平台后台对程序代码进行了检测分析。

在上述检测完成后,也可以在“Query console”中可以,选择语言和项目后,可以通过交互式查询进行错误检测,按照介绍这种检测可以挖掘新的缺陷。

QL查询语言支持COBOLC/C++C#JavaJavascriptpython。项目只支持Github或者Bitbucket上的项目。可能是master,且公开的项目才能测试。

当然下面也有样例参考,里面有很多QL查询例子,下面是其中一个例子:

 

Read more 更多的详细描述:

https://lgtm.com/rules/2159000700/

Open in query console 对没有返回值的错误查询语句举例:

/**

 * @name Missing return statement

 * @description All functions that are not void should return a value on every exit path.

 * @kind problem

 * @problem.severity error

 * @precision high

 * @id cpp/missing-return

 * @tags reliability

 *       readability

 *       language-features

 *       external/jsf

 */

import cpp

 

/* This is slightly subtle: The extractor adds a dummy 'return;' statement for control paths

   that fall off the end of a function. So we can simply look for non-void functions containing

   a non-value carrying return. If the predecessor is a return statement it means that

   the return did not return a value. (If that return was not added by the extractor but by the

   programmer, we can flag it anyway, since this is arguably a bug.) */

 

predicate functionsMissingReturnStmt(Function f, ControlFlowNode blame) {

  f.fromSource() and

  exists(Type returnType |

    returnType = f.getType().getUnderlyingType().getUnspecifiedType() and

    not returnType instanceof VoidType and

    not returnType instanceof TemplateParameter

  ) and

  exists(ReturnStmt s |

    f.getAPredecessor() = s and

    blame = s.getAPredecessor()

  )

}

 

/* If a function has a value-carrying return statement, but the extractor hit a snag

   whilst parsing the value, then the control flow graph will not include the value.

   As such, to avoid embarrassing false positives, we exclude any function which

   wasn't perfectly extracted. */

predicate functionImperfectlyExtracted(Function f) {

  exists(CompilerError e | f.getBlock().getLocation().subsumes(e.getLocation()))

  or

  exists(ErrorExpr ee | ee.getEnclosingFunction() = f)

  or

  count(f.getType()) > 1

}

 

from Stmt stmt, string msg, Function f, ControlFlowNode blame

where

  functionsMissingReturnStmt(f, blame) and

  reachable(blame) and

  not functionImperfectlyExtracted(f) and

  (blame = stmt or blame.(Expr).getEnclosingStmt() = stmt) and

  msg = "Function " + f.getName() + " should return a value of type " + f.getType().getName() + " but does not return a value here"

select stmt, msg

 

Semmle 也支持程序引用组件依赖关系,见下图。该功能列出了当前项目所引用的其它组件。通过引用组件分析,可以查看引用组件的版本、代码行和以及其中包含的缺陷。

结束

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

manok

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值