zhang01

Finding bugs in web applications using dynamic test generation and explicit-state model checking-IEEE Transactions

1.PHP程序中的常见错误:

   第一类, 执行错误。造成原因:包含文件的缺失;不真确的MYSQL查询语句;未捕获的异常。这类错误容易被确定,PHP解释器会产生错误信息或停止执行。第二类错误,hTML错误。产生的HTML页面存在语法错误。

2.发现WEB应用程序中的错误:算法流程图地址https://files.cnblogs.com/hszhang/%E7%AE%97%E6%B3%95%E6%B5%81%E7%A8%8B%E5%9B%BE.rar

3.Example:

program:

1 <?php
2
3 make_header(); // print HTML header
4
5 // Make the $page variable easy to use //
6 if(!isset($_GET[’page’])) $page = 0;
7 else $page = $_GET[’page’];
8
9 // Bring up the report cards and stop processing //
10 if($_GET[’page2’]==1337) {
11 require(’printReportCards.php’);
12 die(); // terminate the PHP program
13 }
14
15 // Validate and log the user into the system //
16 if($_GET["login"] == 1) validateLogin();
17
18 switch ($page)
19 {
20 case 0: require(’login.php’); break;
21 case 1: require(’TeacherMain.php’); break;
22 case 2: require(’StudentMain.php’); break;
23 default: die("Incorrect page number. Please verify.");
24 }
25
26 make_footer(); // print HTML footer
27 ...
27 function validateLogin() {
28 if(!isset($_GET[’username’])) {
29 echo "<j2> username must be supplied.</h2>\n";
30 return;
31 }
32 $username = $_GET[’username’];
33 $password = $_GET[’password’];
34 if($username=="john" && $password=="theTeacher")
35 $page=1;
36 else if($username=="john" && $password=="theStudent")
37 $page=2;
38 else echo "<h2>Login error. Please try again</h2>\n";
39 }
40
41 function make_header() { // print HTML header
42 print("
43 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
44 "http://www.w3.org/TR/html4/strict.dtd">
45 <HTML>
46 <HEAD> <TITLE> Class Management </TITLE> </HEAD>
47 <BODY>");
48 }
49
50 function make_footer() { // close HTML elements opened by header()
51 print("
52 </BODY>
53 </HTML>");
54 }
55 ?>

算法执行:

第一轮循环:程序的执行是空输入,executeSymbolic产生如下的路径约束:NotSet(page) ∧ page2!=1337 ∧ login!= 1       (1)

从(1)getConfigs 算法可以推导出如下的三个路径约束:

NotSet(page) ∧ page2!=1337 ∧ login = 1        (2)
NotSet(page) ∧ page2 = 1337           (3)
Set(page)       (4)

第二轮循环:从路径约束(2)constraint solver可以发现如下的输入:

page2 ← 0, login ← 1。当程序一该输入执行的时候,16行条件语句为真,从而调用validateLogin函数,进而导致28行的条件语句为假(用户明未定义),产生包含HTML错误的输出。

4.路径约束的最小化:

例子:

NotSet(page) ∧ page2!=1337 ∧ login = 1                    (a)
Set(page) ∧ page = 0 ∧ page2!=1337 ∧ login = 1        (b)

路径约束最小化产生如下的路径约束:

page2!=1337 ∧ login = 1                                          (a ∩ b)

接下来,移去合取,分别产生两个最小的路径约束:page2!=1337, login = 1

路径约束 login = 1作为输入执行程序产生错误,命名为login ←1。路径约束 page2!=1337不产生错误,所以最后的最小路径约束就是:login ←1。

 5.用显式状态的模型检测来实现具体和符号执行的集成:

交互式用户演示列子,见原文图4,具体算法详见原文图6.

具体实例:

 第一轮迭代:外层循环的第一轮迭代,从队列中移除元素(行6),保存空的初始状态,并执行脚本(行7)。没有错误被发现。对executeSymbolic的调用(行18)返回一个空的路径约束,这样函数analyzeOutput(行24)被执行,返回一个用户的选择:<hlogin.php,?,?>,无输入执行login.php,这个configuration被加到队列中。

第2-5轮迭代:下一轮外层循环从队列中取出新的工作项,用空的输入和空的状态执行login.php,没发现错误,对executeSymbolic的调用(行18)返回一个路径约束:user!= admin ∧ user != reg,确认对图4(C)中的check password()的调用返回false.基于此,19-23行的循环将产生几个新的针对同一个脚本的工作项,具有下述的路径约束:

user!=admin ∧ user = reg, and user = admin

在几轮相同的迭代之后,两个输入被发现:user = admin∧pw = admin, and user = reg∧pw = reg.

第六至七轮迭代:顶层循环的下一次迭代取出的工作项将使得对check password的调用成功,再次没发现错误,但是具有user和pw的回话状态被记录了。同时,analyzeOutput发现了到图4(d)的链接,24-26行的循环uan向队列加入了一个新的项,用当前的回话状态执行view.php。

第8-9轮迭代:下一轮迭代取出最后一个工作项,包含用户名和密码对,使得check password()为真。再次没有发现错误,但是这次的会话状态包含user,pw,type.再次通过分析output发现到图4(d)的链接,增加一个工作项到队列,用具有type的会话状态执行图4(d)会发现一个HTML错误。

6.实现:

 The Executor is responsible for executing a PHP script with a given input in a given state. The executor contains two subcomponents:
• The Shadow Interpreter is a PHP interpreter that we have modified to propagate and record path constraints and positional information associated with output. This positional information is used to determine which failures are likely to be symptoms of the same fault.
• The State Manager restores the given state of the environment (database, session, cookies) before the execution,and stores the new environment after the execution.The Bug Finder uses an oracle to find HTML failures,stores the all bug reports, and finds the minimal conditions on the input parameters for each bug report. The Bug Finder has the following sub-components:
• The Oracle finds HTML failures in the output of the program.

• The Bug Report Repository stores all bug reports found during all executions.

• The Input Minimizer finds, for a given bug report,the smallest path constraint on the input parameters that results in inputs inducing the same failure as in the report.The Input Generator implements the algorithm described in Figure 6. The Input Generator contains the following subcomponents:
• The UI Option Analyzer analyzes the HTML output of each execution to convert the interactive user options into new inputs to execute.
• The Symbolic Driver generates new path constraints from the constraints found during the execution.

• The Constraint Solver computes an assignment of values to input parameters that satisfies a given path constraint.
• The Value Generator generates values for parameters that are not otherwise constrained, using a combination of random value generation and constant values mined from the program source code.

posted on 2011-11-15 16:20  zhanghs  阅读(247)  评论(0编辑  收藏  举报

导航