16
Static Detection of Access Control Vulnerabilities in Web Applications Fangqi Sun Liang Xu Zhendong Su University of California, Davis {fqsun, leoxu, su}@ucdavis.edu Abstract Access control vulnerabilities, which cause privilege es- calations, are among the most dangerous vulnerabilities in web applications. Unfortunately, due to the difficulty in designing and implementing perfect access checks, web applications often fall victim to access control at- tacks. In contrast to traditional injection flaws, access control vulnerabilities are application-specific, rendering it challenging to obtain precise specifications for static and runtime enforcement. On one hand, writing specifi- cations manually is tedious and time-consuming, which leads to non-existent, incomplete or erroneous specifica- tions. On the other hand, automatic probabilistic-based specification inference is imprecise and computationally expensive in general. This paper describes the first static analysis that au- tomatically detects access control vulnerabilities in web applications. The core of the analysis is a technique that statically infers and enforces implicit access control as- sumptions. Our insight is that source code implicitly doc- uments intended accesses of each role and any successful forced browsing to a privileged page is likely a vulner- ability. Based on this observation, our static analysis constructs sitemaps for different roles in a web applica- tion, compares per-role sitemaps to find privileged pages, and checks whether forced browsing is successful for each privileged page. We implemented our analysis and evaluated our tool on several real-world web applications. The evaluation results show that our tool is scalable and detects both known and new access control vulnerabilities with few false positives. 1 Introduction Web applications often restrict privileged accesses to au- thorized users. While bringing the convenience of ac- cessing a large amount of information and operations from anywhere into people’s daily lives, web applications have opened a new door for attacks and the number of web-based attacks is on the rise. A Symantec Internet security threat report published in April 2011 points out that the volume of web-based attacks in 2010 increased by 93% over the volume observed in 2009 1 . Researchers of web security have focused their attention on injection vulnerability, which is the most common vulnerability in web applications. Although not as prevalent as injection vulnerability, access control vulnerability poses a more se- rious threat because of exposed privileges, and has started attracting the attention of researchers [7]. Compared with those in traditional software, access checks in web ap- plications are harder to get right because of the stateless nature of the HTTP protocol. In traditional software, once a user has passed an authentication check, the system remembers the identity of the user until she logs out or a timeout event happens. This is not the case for web applications, which must parse each new HTTP request to identify a previously logged-in user. A statistics re- port published in 2007 states that 14.15% of the surveyed web applications suffer from vulnerabilities of insufficient authorization 2 . Traditional injection vulnerabilities such as Cross-Site Scripting (XSS) and SQL injection are not application- specific and have a clear and general definition [25]: an in- jection vulnerability exists when an untrusted input flows into a sensitive sink without proper sanitization. To detect injection vulnerabilities, it is sufficient to analyze indi- vidual pages separately to examine where untrusted user inputs can flow. In contrast, access control vulnerabilities are application-specific, and it is necessary to examine connections between pages. Web application developers frequently make implicit assumptions of allowed accesses and protect privileged pages by hiding links to these pages from unauthorized users. However, security by obscurity is insufficient to prevent a determined and skilled attacker from accessing these pages, viewing sensitive data or performing dan- gerous operations. As an example, Business Wire used a 1 http://www.symantec.com/business/threatreport 2 http://projects.webappsec.org/f/wasc wass 2007.pdf

Static Detection of Access Control Vulnerabilities in Web ...web.cs.ucdavis.edu/~su/publications/security11.pdf · constructs sitemaps for different roles in a web applica-tion, compares

  • Upload
    others

  • View
    0

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Static Detection of Access Control Vulnerabilities in Web ...web.cs.ucdavis.edu/~su/publications/security11.pdf · constructs sitemaps for different roles in a web applica-tion, compares

Static Detection of Access Control Vulnerabilities in Web Applications

Fangqi Sun Liang Xu Zhendong SuUniversity of California, Davis{fqsun, leoxu, su}@ucdavis.edu

AbstractAccess control vulnerabilities, which cause privilege es-calations, are among the most dangerous vulnerabilitiesin web applications. Unfortunately, due to the difficultyin designing and implementing perfect access checks,web applications often fall victim to access control at-tacks. In contrast to traditional injection flaws, accesscontrol vulnerabilities are application-specific, renderingit challenging to obtain precise specifications for staticand runtime enforcement. On one hand, writing specifi-cations manually is tedious and time-consuming, whichleads to non-existent, incomplete or erroneous specifica-tions. On the other hand, automatic probabilistic-basedspecification inference is imprecise and computationallyexpensive in general.

This paper describes the first static analysis that au-tomatically detects access control vulnerabilities in webapplications. The core of the analysis is a technique thatstatically infers and enforces implicit access control as-sumptions. Our insight is that source code implicitly doc-uments intended accesses of each role and any successfulforced browsing to a privileged page is likely a vulner-ability. Based on this observation, our static analysisconstructs sitemaps for different roles in a web applica-tion, compares per-role sitemaps to find privileged pages,and checks whether forced browsing is successful foreach privileged page. We implemented our analysis andevaluated our tool on several real-world web applications.The evaluation results show that our tool is scalable anddetects both known and new access control vulnerabilitieswith few false positives.

1 IntroductionWeb applications often restrict privileged accesses to au-thorized users. While bringing the convenience of ac-cessing a large amount of information and operationsfrom anywhere into people’s daily lives, web applicationshave opened a new door for attacks and the number ofweb-based attacks is on the rise. A Symantec Internet

security threat report published in April 2011 points outthat the volume of web-based attacks in 2010 increasedby 93% over the volume observed in 20091. Researchersof web security have focused their attention on injectionvulnerability, which is the most common vulnerability inweb applications. Although not as prevalent as injectionvulnerability, access control vulnerability poses a more se-rious threat because of exposed privileges, and has startedattracting the attention of researchers [7]. Compared withthose in traditional software, access checks in web ap-plications are harder to get right because of the statelessnature of the HTTP protocol. In traditional software, oncea user has passed an authentication check, the systemremembers the identity of the user until she logs out ora timeout event happens. This is not the case for webapplications, which must parse each new HTTP requestto identify a previously logged-in user. A statistics re-port published in 2007 states that 14.15% of the surveyedweb applications suffer from vulnerabilities of insufficientauthorization2.

Traditional injection vulnerabilities such as Cross-SiteScripting (XSS) and SQL injection are not application-specific and have a clear and general definition [25]: an in-jection vulnerability exists when an untrusted input flowsinto a sensitive sink without proper sanitization. To detectinjection vulnerabilities, it is sufficient to analyze indi-vidual pages separately to examine where untrusted userinputs can flow. In contrast, access control vulnerabilitiesare application-specific, and it is necessary to examineconnections between pages.

Web application developers frequently make implicitassumptions of allowed accesses and protect privilegedpages by hiding links to these pages from unauthorizedusers. However, security by obscurity is insufficient toprevent a determined and skilled attacker from accessingthese pages, viewing sensitive data or performing dan-gerous operations. As an example, Business Wire used a

1http://www.symantec.com/business/threatreport2http://projects.webappsec.org/f/wasc wass 2007.pdf

Page 2: Static Detection of Access Control Vulnerabilities in Web ...web.cs.ucdavis.edu/~su/publications/security11.pdf · constructs sitemaps for different roles in a web applica-tion, compares

web server to store files of important trade information,which were supposed to be accessible to registered mem-bers only. Although the URLs to these files were hiddenin the presentation layer from unauthorized users, thedate-based URLs were highly predictable. By simply ac-cessing these privileged files, an investment bank LohmusHaavel & Viisemann profited over eight million dollarsbased on the disclosed trade information3. Similarly, inNovember 2010, Blooming News obtained and publishedvaluable financial earnings data of Disney and NetAppto its subscribers hours before official data releases bypredicting resource locations inside secure corporate net-works. As yet another example, accesses to the videosof USENIX conference presentations are restricted toUSENIX members for a short period after a conference.However, the authors of this paper were able to predictthe author-name-based URLs of the videos and downloada few videos as public users.

Researchers have proposed various static and dynamicanalysis techniques [1, 7, 10, 13] to detect violations ofapplication logic, including access control attacks. Unfor-tunately, these techniques have limited effectiveness ondetecting access control vulnerabilities. Dynamic analy-ses have difficulty finding hidden pages and determiningintended accesses for each role. Furthermore, sitemapscovered by dynamic executions tend to be shallow andincomplete as user inputs are usually limited. Despite thatstatic analyses typically have better coverage, they oftenrequire good specifications in order to generate usefulreports, whose false positives do not overwhelm users.In practice, deriving precise specifications is challenging,especially when diverse authentication and access controlmanagement schemes are in use. As manually writingspecifications is time-consuming and probabilistic-basedinference is error-prone, it is desirable to precisely in-fer implicit assumptions on intended accesses from thesource code of applications.

In this paper, we use role to represent a unique setof privileges that a group of users has. Most web ap-plications have at least three types of roles: the role foradministrators, the role for normal logged-in users andthe role for public or anonymous users. Access controlchecks must be performed before granting access to anyprivileged resource to prevent privilege escalation attacks.When implicit assumptions are not matched by explicitaccess checks, unauthorized accesses are possible.

We propose the first role-based static analysis to detectaccess control vulnerabilities with automatic inference onimplicit access control assumptions. Our key observationsare that each role represents a unique set of privileges, andintended accesses for each role are reflected in explicitlinks shown in the presentation layer of an application.Guided by these observations, our analysis automatically

3http://www.whitehatsec.com/home/assets/WP bizlogic092407.pdf

derives specifications on privileged accesses by compar-ing explicit links presented to different roles. It thendirectly accesses privileged pages for unprivileged roles,and examines whether these accesses are allowed to de-tect vulnerable pages which have missing or insufficientaccess checks. Our main contributions are:

• A formal definition of access control vulnerabilitiesin web applications.

• The first role-based static analysis which automat-ically detects access control vulnerabilities in webapplications with minimal manual efforts.

• An implementation of our analysis which constructsintended per-role sitemaps. Given role-based speci-fications, our prototype can systematically explorefeasible execution paths based on the satisfiability ofconstraints.

• An evaluation of our tool on real-world web appli-cations. Our tool works on unmodified code, andis able to detect both new and known vulnerabili-ties before the deployment of web applications. Theevaluation results show that our approach is scalableand effective, with few false positives.

The rest of the paper is organized as follows. We firstuse an example to illustrate the main steps of our ap-proach (Section 2) and then present our formalizationof access control vulnerability in web applications (Sec-tion 3). Section 4 describes our detailed algorithms. Sec-tion 5 presents the implementation details of our staticanalyzer, and Section 6 shows the effectiveness, coverageand performance of our analyzer on real-world web appli-cations. Finally, we survey related work (Section 7) andconclude (Section 8).

2 Illustrative ExampleFigure 1 shows a simple web application based on oneof the real-world web applications in our test suite. Forillustration, suppose that the application has two roles:role a for administrators and role b for normal users. Inour approach, we require developers to only specify ap-plication entry points and role-based application states,which serve as the basis for automatically inferring the setof privileged pages. Suppose that in the given specifica-tions, the entry sets for both roles are identical and containonly “index.php”, and the value of $ SESSION[“admin”]is specified as true for role a but false for role b. Aswe can see from the source code, only “functions.php”checks accesses. This file is included via PHP inclu-sion in both “index.php” and “user delete.php”, but not“user add.php.” Consequently, access checks are missingin “user add.php” but present in the other three pages.

Page 3: Static Detection of Access Control Vulnerabilities in Web ...web.cs.ucdavis.edu/~su/publications/security11.pdf · constructs sitemaps for different roles in a web applica-tion, compares

<?php

session_start();

if (!$_SESSION[“admin”]) {

die(“Access denied!”);

}

...

?>

functions.php

<?php

include(“functions.php”);

delete_user();

...

?>

user_delete.php <?php

include(“functions.php”);

$add = “user_add.php”;

$del = “user_delete.php”;

echo “<a href=” . $add . “>Add User</a>”;

echo “<a href=” . $del . “>Delete User</a>”;

...

?>

index.php

<?php

add_user();

...

?>

user_add.php

ba ,

aa

a

Figure 1: An Example of Access Control Vulnerability. Solid arrows represent explicit links, and dashed arrowsrepresent inclusion relationship between pages. Arrows correspond to edges in sitemaps and are labeled withroles. The intended sitemap for privileged role a has four edges while the intended sitemap for role b has onlyone edge.

The first step of our analysis constructs per-rolesitemaps with a worklist-based algorithm. Initially, work-lists for both roles are [“index.php”]. While a worklist isnot empty, our analysis pops a work node from the frontof the worklist each time. Let us look at the sitemapconstruction for role a first. The first analyzed nodeis “index.php”. From this node, users of role a can ex-plicitly reach both “user add.php” and “user delete.php”via anchor tags, and “functions.php” via a file inclusion.Thus, our analysis adds three new edges in the sitemapand appends the newly discovered nodes to the worklist,which is now [“user add.php”, “user delete.php”, “func-tions.php”]. The second analyzed node is “user add.php”.This node can not reach any nodes, and thus our anal-ysis pops “user delete.php” and the worklist becomes[“functions.php”]. Role a can reach “functions.php” from“user delete.php”, and thus our analysis adds a new edgein the sitemap. Because “functions.php” is already inthe worklist, it is not appended to the current worklist.Finally, our analysis pops “functions.php”. This node cannot reach any nodes and our analysis stops because theworklist is now empty. Now let us look at the sitemapconstruction for role b. The first popped node is still“index.php”. However, role b can only explicitly reach“functions.php” via a file inclusion from this node. Thelinks to “user delete.php” and “user add.php” are hiddenfrom users of role b in “index.php” via the access checkin “functions.php”. Therefore, our analysis adds only onenew edge and stops because the worklist is now empty.The edges of constructed per-role sitemaps are shown inFigure 1.

The second step of our analysis infers the set of

privileged pages and attempts to access these pages di-rectly to detect access control vulnerabilities. Com-paring the sets of explicitly reachable nodes for role aand role b, our analysis infers that “user add.php” and“user delete.php” are privileged pages intended for usersof role a only. Consequently, these two pages shouldhave access checks to ward off users of role b. Un-fortunately, only “user delete.php” is safeguarded and“user add.php” is left unprotected. Therefore, a direct ac-cess to “user delete.php” fails, whereas a direct access to“user add.php” succeeds, indicating that “user delete.php”is guarded and “user add.php” is vulnerable.

3 Approach FormulationThis section formulates our high-level approach. We de-fine the notions of role, explicit link, forced browsing,web application and access control vulnerability, andpresent two assumptions we make with regard to rolesand intended accesses.

Definition 1 (Role). A role r ∈ R captures the set ofallowed accesses for all users of role r where set R denotesroles that a web application has. Each role r represents adistinctive set of privileges.

Assumption 1 We assume that roles in R form a lat-tice 〈R,v〉, where v denotes the ordering relationshipbetween any two roles. Under this assumption, accessinga privileged resource as an unprivileged role is considereda privilege escalation attack. Roles at the same level ofthe lattice are not ordered by v as they may representdifferent sets of allowed accesses. The role for adminis-trators is >; the role for public users is ⊥; and the role for

Page 4: Static Detection of Access Control Vulnerabilities in Web ...web.cs.ucdavis.edu/~su/publications/security11.pdf · constructs sitemaps for different roles in a web applica-tion, compares

normal logged-in users lies in the middle of the lattice.

Definition 2 (Explicit Link). In a web application,there exists an explicit link from page ni to a differentpage n j when it is possible to jump to n j via an explicitURL in ni, incurring no exceptions or errors. URLs mightappear in file inclusions, header redirections, HTML tagsfor anchors, forms, meta refresh headers, frames, iframes,scripts, images or links.

Definition 3 (Forced Browsing). Forced browsing isthe act of directly accessing privileged pages rather thanfollowing explicit links in a web application. Attackers of-ten harness brute force techniques to access hidden pageswith predictable locations. We consider forced browsingsuccessful when HTML pages presented to two differ-ent roles are identical, and no redirections, exceptions orerrors occur during the page rendering process.

Definition 4 (Web Application). Let node representa web page. Suppose that a web application containsk nodes. Given a user role r ∈ R, we abstract the webapplication as Pr = (Sr,Qr,Er, Ir,Πr,Nr), where

• Entry set Sr contains the entry nodes to the webapplication. We include index pages in all directoriesin the entry set. Different roles may have differententry sets.

• State set Qr = {qi | 0 ≤ i < k} is a set of applica-tion states. For each node ni, an application state qicaptures critical information at that node. It mightinclude session values, cookie values, request pa-rameter values, database records, variable values orfunction return values.

• Explicit edge set Er = {〈ni,n j〉 | 0 ≤ i, j < k}. Anexplicit edge from node ni to n j exists iff ni in stateqi contains an explicit link to n j.

• Implicit edge set Ir = {〈ni,n j〉 | 0 ≤ i, j < k}. Animplicit edge from node ni to n j exists iff forcedbrowsing enables one to jump to n j from ni in stateqi. Accesses via implicit edges are allowed but oftenunintended.

• Navigation path set Πr = {(ni)0≤i<l | 0 < l < k∧n0 ∈ Sr ∧ 〈ni,ni+1〉 ∈ (Er ∪ Ir)}. It consists of allpossible navigation paths for role r, including ex-plicit edges as well as implicit edges.

• Explicitly reachable node set Nr consists of nodesthat are reachable from application entries in Sr viaexplicit edges in Er. It can be easily computed witha graph reachability analysis.

Assumption 2 For each node in a web application, ifmultiple roles can reach this node on navigation paths

composed of only explicit edges, we assume that theprivilege level required to access this node is determinedby the least privileged role.

Definition 5 (Access Control Vulnerability). Leta,b ∈ R denote two roles that can be ordered in a webapplication where role b is less privileged than role a, i.e.,b @ a. An access control vulnerability exists at node nwhen:

n ∈ Na∧n /∈ Nb∧∃ πb ∈Πb (n ∈ πb)

In this definition, destination node n is a privilegednode intended to be accessible to role a but not role b. Weuse n ∈ πb to denote that n is on navigation path πb. Thisnode is vulnerable to access control attacks when a userof role b is able to access n via an allowed, but probablyunintended, navigation path πb.

4 Analysis AlgorithmIn this section, we introduce the three major algorithmsof our approach. Section 4.1 describes how our analysisautomatically infers specifications of implicit access con-trol assumptions and detects access control vulnerabilitiesfrom a high-level view. Section 4.2 shows the algorithmthat we use to build per-role sitemaps. Finally, we presentthe detailed link extraction algorithm in Section 4.3.

4.1 Vulnerability DetectionFigure 2 presents the vulnerability detection algorithmwhich is the core of our approach. This algorithm infersprivileged nodes from the source code of a web applica-tion and identifies nodes that are not properly protected.

DETECTVULS(Speca,Specb,reg)1 Vuls← /02 nfa← REG2NFA(reg)3 dfa← NFA2DFA(nfa)4 Na← BUILDSITEMAP(Speca,dfa)5 Nb← BUILDSITEMAP(Specb,dfa)6 Privileged← Na \Nb7 for each n in Privileged8 do 〈cfga,Ra〉 ← GETCFG(n,Speca)9 〈cfgb,Rb〉 ← GETCFG(n,Specb)

10 if SIZEOF(cfga) = SIZEOF(cfgb) and Ra = Rb11 then Vuls← Vuls∪{n}12 return Vuls

Figure 2: Algorithm for Vulnerability Detection.

Let Speca and Specb denote specifications for role a androle b respectively. Initially, the set of vulnerable nodesVuls is empty. First, this algorithm parses the regularexpression reg, which captures HTML tags where a linkmight appear, into a non-deterministic finite automaton

Page 5: Static Detection of Access Control Vulnerabilities in Web ...web.cs.ucdavis.edu/~su/publications/security11.pdf · constructs sitemaps for different roles in a web applica-tion, compares

(NFA). Then, the algorithm transforms the NFA into adeterministic finite automaton (DFA). Either NFA or DFAcould be used for extracting links, and we chose DFA forits advantage on performance and the ease of FA statemanagement.

Throughout this paper, we assume role a is more priv-ileged than role b. Following Definition 4, we use Naand Nb to denote the sets of explicitly reachable nodesfor roles a and b respectively. Function BUILDSITEMAP,whose details are shown later in Section 4.2, computesthese two sets. Relying on Assumption 2, the algorithminfers privileged nodes that are present in Na but not in Nb(Line 6). For the example in Section 2, Na ={“index.php”,“user add.php”, “user delete.php”, “functions.php”} andNb ={“index.php”, “functions.php”}.

Access checks at privileged locations may be missingor insufficient. This algorithm analyzes each privilegednode n twice with function GETCFG, once for role a tocreate an oracle for the intended server response (Line 8),and once for role b to emulate forced browsing (Line 9).Given a role r and a privileged node n, GETCFG returnsa context-free grammar (CFG) cfgr and the set of pageredirections Rr.4 The obtained cfgr is an approximationof the dynamic HTML output of node n. We observe thatwhen an access check succeeds, users are often grantedaccesses to sensitive information or operations; otherwise,they are redirected to another page, or presented with errormessages or login forms. In the latter case, CFG sizes ofthe two roles are different because of the different HTMLoutputs that are presented. Consequently, if the sizes ofthe two CFGs or the two redirection sets differ, node n isconsidered guarded; otherwise, n may be vulnerable (Line11). For the privileged page “user delete.php” shown inFigure 1, SIZEOF(cfga) 6= SIZEOF(cfgb) and Ra = Rb =/0, indicating that the page is guarded; for the privilegedpage “user add.php”, SIZEOF(cfga)= SIZEOF(cfgb) andRa = Rb = /0, indicating that the page is vulnerable.

4.2 Building SitemapsFunction BUILDSITEMAP shown in Figure 3 builds a per-role sitemap with specifications Specr for role r and theDFA dfa. We use a worklist-based algorithm to traversenodes in a web application in a breath-first manner. Ini-tially, both the visited node set Visited and the edge set Erare empty, and the worklist WkLst is initialized with theentry set Sr specified in Specr (Line 3).

In each iteration of the loop, function GETWORKN-ODE pops a working node ni from the front of list WkLstand retrieves its associated state qi from Specr (Line 5)to find outgoing edges of this working node. Next, thisalgorithm constructs a CFG that represents the possibleHTML outputs of node ni (Line 6). Besides cfgi, function

4Throughout this paper, CFG stands for context-free grammar ratherthan control-flow graph.

BUILDSITEMAP(Specr,dfa)1 Er← /02 Visited← /03 WkLst← GETENTRIES(Specr)4 while WkLst5 do 〈ni,qi〉 ← GETWORKNODE(WkLst,Specr)6 〈cfgi,Ri,Fi〉 ← CONSTRUCTCFG(ni,qi)7 Li← EXTRACTLINKS(cfgi,dfa)8 N j← Li∪Ri∪Fi9 for each n j in N j

10 do Er← Er ∪{〈ni,n j〉}11 Visited← Visited∪{ni}12 N← ACTIVE(N j)\ (Visited∪WkLst)13 WkLst← APPEND(WkLst,N)14 return GETNODES(Er)

Figure 3: Algorithm for Building Sitemaps.

CONSTRUCTCFG also returns the page redirection set Riand the file inclusion set Fi as links in these two sets alsocontribute to outgoing edges in a sitemap. Then, functionEXTRACTLINKS extracts a set of matched links Li thatare present in cfgi based on dfa (Line 7). The details ofEXTRACTLINKS are presented later in Section 4.3. Theset of reachable nodes N j for ni is the union of Li, Ri andFi (Line 8). We conservatively include Fi in this union be-cause included files may present sensitive information oroperations. The algorithm adds an outgoing edge 〈ni,n j〉to the explicit edge set Er for each node n j ∈ N j (Line10) and then adds ni to the visited node set (Line 11). Todetermine which nodes to analyze, we partition nodes intoactive nodes and inactive nodes, and only analyze activeones. Active nodes may have outgoing edges in a sitemap,whereas inactive nodes are dead ends. For example, aPDF file is considered an inactive node, while a PHP pageis considered an active node. Finally, the algorithm addsthe newly discovered active nodes to the worklist, exclud-ing the ones that have been visited or are already in theworklist (Line 12, 13). The loop terminates when WkLstbecomes empty, indicating that the construction of a per-role sitemap is complete. At this point, function BUILD-SITEMAP returns the set of explicitly reachable nodes Nrbased on Er (Line 14). When work node ni =“index.php”shown in Figure 1 is analyzed for role a in a loop iter-ation, Li ={“user delete.php”, “user add.php”}, Ri = /0and Fi ={“functions.php”}. Therefore, three new outgo-ing edges from “index.php” are added to Ea. In contrast,when “index.php” is analyzed for role b, Li = Ri = /0 andFi ={“functions.php”}. In this case, only one new edgeis added to Eb.

Page 6: Static Detection of Access Control Vulnerabilities in Web ...web.cs.ucdavis.edu/~su/publications/security11.pdf · constructs sitemaps for different roles in a web applica-tion, compares

4.3 Link ExtractionWe use C to denote a CFG, and F to denote an FA. In oursetting, a CFG represents the dynamic HTML output of anode and an FA matches a single link-introducing HTMLtag of various forms. Let L (C) be the set of words in thelanguage for the CFG and L (F) be the set of words inthe language for the FA. Suppose that function SUBSTRreturns true only when w′ is a substring of w. The outputof EXTRACTLINKS on C and F is defined as follows:

EXTRACTLINKS(C,F) = { w′ | w ∈L (C) ∧w′ ∈L (F) ∧SUBSTR(w′,w) }

We could use a straight-forward three-step approachto extract links. In the first step, we could use the stan-dard CFG-reachability algorithm [20] to compute a CFGrepresenting the intersection of the two languages for Cand F ′, where F ′ matches HTML outputs that containat least one link-introducing tag. The subtle differencebetween F ′ and F is that F ′ matches link-introducing tagsas well as link-irrelevant HTML outputs, while F onlymatches link-introducing tags. In the second step, wecould generate all possible HTML outputs of the CFG. Inthe third step, we could use an HTML parser to extractlinks from the generated HTML outputs. Nevertheless,this approach is not ideal for two reasons. The first isthat the words of a CFG can be infinite and we can onlygenerate a finite set of possible HTML outputs. The sec-ond is that the generated HTML outputs are likely beinghighly similar, and thus we may repetitively parse similarHTML outputs. For better performance, we designed anew algorithm that does not generate intermediate HTMLoutputs, but directly extracts links from the CFG.

In a CFG 〈V,Σ,P,S0〉, V is a finite set of variables (i.e.non-terminals); Σ is a finite set of terminals which is thealphabet of the language; P = {v→ rhs | v ∈ V ∧ rhs ∈(V ∪Σ)∗} is a finite set of grammar productions; and S0 isthe start variable. In an FA 〈Q,Σ′,q0,δ ,Q f 〉, Q is a finite,non-empty set of states; Σ′ is the input alphabet; q0 ∈ Qis the start state; δ : Q× Σ→ Q is the state-transitionrelation; and Q f ⊆ Q is the set of final states.

Figure 4 shows our link extraction algorithm wherefunction EXTRACTLINKS is the entry point. We use setVQW to store 〈v,q,w〉 tuples where v represents a CFGvariable, q is an FA state and w is a partially matched linkstring. Completely matched links are stored in set Words.To begin with, this algorithm walks the CFG with the startCFG symbol S0, the start FA state q0, and the empty stringwhich represents the terminals that have been partiallymatched (Line 38).

Function WALKTERMINAL is the only function thatadvances an FA state q to a new state q′ based on the FAtransition function δ and an input character t (Line 1). If

WALKTERMINAL(t,q,w)1 q′← δ (q, t)2 if q′ = q03 then return 〈q0, “” 〉4 w′← APPEND(w, t)5 if q′ ∈ Q f6 then Words←Words∪{w′}7 w′ = “”8 return 〈q′,w′〉

WALKVAR(v,q,w)10 VQW← VQW ∪{〈v,q,w〉}11 RHS← PRODUCTIONS(v,P)12 if ISSIGMA(RHS) or RHS = /013 then return {〈q,w〉}14 QW← /015 for each rhs in RHS16 do if ISEPSILON(rhs)17 then QW← QW ∪{〈q,w〉}18 else QW← QW ∪WALKSYMBOLS(rhs,q,w)19 return QW

WALKSYMBOL(s,QW)21 Result← /022 for each 〈q,w〉 in QW23 do if ISTERMINAL(s)24 then QW ′←{WALKTERMINAL(s,q,w)}25 else if 〈s,q,w〉 ∈ VQW26 then QW ′←{〈q,w〉}27 else QW ′←WALKVAR(s,q,w)28 Result← Result∪QW ′

29 return Result

WALKSYMBOLS(rhs = [γ],q,w)31 QW←{〈q,w〉}32 for each si in [γ]33 do QW←WALKSYMBOL(si,QW)34 return QW

EXTRACTLINKS(cfg = 〈V,Σ,P,S0〉, fa = 〈Q,Σ′,q0,δ ,Q f 〉)36 VQW← /037 Words← /038 WALKVAR(S0,q0, “” )39 return VALID(Words)

Figure 4: Algorithm for Link Extraction.

Page 7: Static Detection of Access Control Vulnerabilities in Web ...web.cs.ucdavis.edu/~su/publications/security11.pdf · constructs sitemaps for different roles in a web applica-tion, compares

Context-Free

Grammar

Constructor

Link Extractor

Sitemap Builder

Reachable

Nodes

Comparator

Vulnerability

Detector

Vulnerable

Nodes

DFA

Constructor

aSpec

bSpec

reg

aN

bN

Privileged

Figure 5: System Architecture.

q′ is the FA start state q0, which indicates a mismatch,the algorithm clears the partially matched terminals andreturns (Line 3); otherwise, it appends t to w (Line 4) andexamines q′ again (Line 5). If q′ is a final FA state in Q f ,the algorithm adds the completely matched link to Words(Line 6) and resets w′ to the empty string. In this way, wefilter out noises that are irrelevant to links in the CFG andonly keep track of link-introducing HTML outputs.

Recursive function WALKVAR walks the grammar pro-ductions of variable v under an FA state q and a partiallymatched word w. Function PRODUCTIONS retrieves theset of productions which have v as the left-hand-side vari-able from the CFG production set P, and returns the set ofright-hand sides RHS (Line 11). The different elementsin RHS indicate how the dynamic HTML output mightdiverge for v. Function ISSIGMA checks whether a set isequivalent to the CFG alphabet Σ. A link of value Σ∗ canpoint to any file in the application and therefore shouldbe discarded. If RHS forms the alphabet or the emptyset, the function returns the pair of unchanged q and win a set (Line 13); otherwise, it walks the elements in setRHS one by one. In each loop iteration, if a right-handside rhs has no symbols, the HTML output remains thesame (Line 17); otherwise, the algorithm searches the setof new possible outcomes QW ′ with a call to functionWALKSYMBOLS (Line 18).

Recursive function WALKSYMBOLS walks the sym-bols in list [γ] in order. Consequently, links in the CFGare matched in the order of their appearances in a possibleHTML output. Here [γ] = (si)

∗∧ si ∈ (V ∪Σ), represent-ing a sequence of right-hand-side symbols. For eachsymbol si in the list, the algorithm transitions the set ofpossible outcomes to a new set (Line 33).

Recursive function WALKSYMBOL walks a right-hand-side symbol s under each possible outcome 〈q,w〉. In eachloop iteration, the algorithm first examines the symbols (Line 23). If s is a terminal, the FA state is determin-istically advanced via function WALKTERMINAL (Line24). Otherwise, if the symbol is a variable, this algorithmrecursively calls function WALKVAR for s (Line 27) whenv is associated with a new q or a new w. The use of setVQW ensures the termination of the algorithm. This al-gorithm stops when all reachable grammar productions

have been explored at least once. A concrete example ofhow this algorithm works is given in Section 5.2.2.

5 ImplementationAs PHP is one of the most popular programming lan-guages for web applications, we implemented our ap-proach by extending Wassermann and Minamide’s PHPstring analyzer [21, 30], which is written in OCaml. Theoriginal PHP string analyzer was developed to detect in-jection vulnerabilities in web applications, and it analyzesindividual pages in isolation and explores all executionpaths. To detect access control vulnerabilities, we mod-ified the string analyzer to build per-role sitemaps andexamined connections between different pages. In par-ticular, we introduced the concept of role into the staticanalyzer, added new specification rules for applicationstates and entry sets, and strategically explored pathsbased on branch feasibilities. To explore only feasibleexecution paths, we keep track of both arithmetic con-straints and string constraints. For arithmetic constraints,the analyzer consults a Satisfiability Modulo Theories(SMT) solver Z3 [8]; for string constraints, it consults acustom-built string constraint solver. Furthermore, we de-signed and implemented the algorithm shown in Figure 4to efficiently extract explicit links from CFGs, added sup-port for 176 built-in PHP functions, and modified both thespecification lexer and parser to support specifications forthe values of integers, floating-point numbers and strings.

Figure 5 shows our system architecture. A web appli-cation can have multiple roles, and our analysis comparesa pair of ordered roles each time. Initially, the DFA con-structor transforms the given regular expression reg intoa DFA. The detection of access control vulnerabilities iscarried out in two major steps. First, the sitemap builderexplores the given web application based on parsed speci-fications and the DFA. Second, the reachable nodes com-parator infers what privileged nodes are, and the vulnera-bility detector performs forced browsing to detect nodesthat are vulnerable to access control attacks.

5.1 Specification RulesIn our analysis, specifications are parsed with a lexer anda parser. For each role r, we only require developers tospecify the entry set Sr and the set of critical application

Page 8: Static Detection of Access Control Vulnerabilities in Web ...web.cs.ucdavis.edu/~su/publications/security11.pdf · constructs sitemaps for different roles in a web applica-tion, compares

states Qr. Multiple roles can share the same set of en-try points. Either index pages or active pages with noincoming edges can be entry nodes. Index pages oftenhave conventional names such as “index.php” and “in-dex.html”, and can be easily identified with a file scan;active pages with no incoming edges can be specified asentry nodes by developers. The types of application statesthat we support are listed in Definition 4. The state valuesthat can be specified include abstract types and concretevalues of built-in PHP types, and string values that canbe represented by a regular expression. For function in-vocations, we allow developers to pinpoint an invocationby specifying the filename and line number where the in-vocation occurs. This is especially useful when functioninvocations return different values at different call sites.

Optionally, developers can explicitly specify a set ofprivileged nodes. In contrast to implicit navigation pathswhich involve forced browsing, explicit navigation pathsare often tested more thoroughly. However, it is still pos-sible that an allowed access to a sensitive node via anexplicit navigation path of an unprivileged role is unau-thorized, violating Assumption 2. In this case, when anunprivileged user can explicitly navigate to a privilegednode, we would have false negatives. To solve this prob-lem, we allow developers to explicitly specify privilegednodes. Such a node may be vulnerable to access controlattacks even if it is explicitly accessible for both roles.

5.2 Sitemap BuilderThe sitemap builder has two components: the context-freegrammar constructor and the link extractor. With thesetwo components, our analysis constructs a CFG for eachexplicitly reachable node, and extracts links embedded inthe CFG to find outgoing edges of the node.

5.2.1 Context-Free Grammar Constructor

For each web page, our analyzer first parses the pageinto an Abstract Syntax Tree (AST), and then transformsthe AST into an Intermediate Representation (IR), dis-tinguishing every variable occurrence. Interested readerscan refer to Wassermann’s work [30] for more details.

To build a per-role CFG, our analyzer explores the IRonly when necessary by predicting branch feasibilitieswith an inter-procedural path-sensitive analysis. It ana-lyzes statements in the IR in a top-down manner, updatingpath conditions for both string constraints and arithmeticconstraints. For arithmetic constraints, our analyzer re-sorts to the integrated Z3 to check the satisfiability ofconstraints; for string constraints, it feeds possible valuesof string variables and their aliases to our string constraintsolver in exchange of answers. Our prototype string con-straint solver supports string constraints which may con-tain multiple variables, regular expressions, equality andinequality operators, and checks on string lengths. Wetried to solve string constraints with HAMPI [15], but

function checkUser ( ) {if ( !isset ($_SESSION ["validUser" ] )

| | $_SESSION ["validUser" ] != true ) {header ("Location: login.php" ) ;

}}checkUser ( ) ;sensitiveOperation ( ) ;

Figure 6: An Example of Path Exploration.

it does not support multiple string variables yet. Whenconstraints of a conditional is unsolvable, the analyzerexplores both branches, updating path conditions for boththe true branch and the false branch. For each functioncall, our analyzer first checks its calling context and thenexplores the function only when the context is new. Next,it propagates constraints on the arguments and relatedglobal variables of the function call. The IR explorationterminates when all possible branches have redirections orexits, indicating that none of the unexplored branches arefeasible. In our implementation, we do not consider differ-ent contexts of page accesses and assume the parametersof HTTP requests to be Σ∗ unless specified. In this way,we analyze each page only once, making our analyzerscalable at the expense of obtaining over-approximationsof outgoing edges.

Finding the targets of PHP includes is a non-trivial task.It requires value resolution of possible string variablesthat are used for filename construction. Furthermore, itis necessary to find the directories that a PHP include filemay reside in. When resolving PHP include paths, thefollowing steps are performed in order:

• The include path in the configuration of a PHPapplication is checked first;

• If no matching file is found under include path,the directory of the calling script is checked;

• If no matching file is found in the directory ofthe calling script, the current working directory ischecked;

• If no matching file is found in the current workingdirectory, the inclusion finally fails.

We illustrate our basic exploration strategy with a sim-ple example shown in Figure 6 based on one of the web ap-plications that we have analyzed. Function checkUserchecks whether an access should be allowed for a givenuser. Function SensitiveOperation will only beexecuted when the user has passed the access check. Sup-pose that $ SESSION[“validUser”] is a critical applica-tion state which determines the privileges of a role, and

Page 9: Static Detection of Access Control Vulnerabilities in Web ...web.cs.ucdavis.edu/~su/publications/security11.pdf · constructs sitemaps for different roles in a web applica-tion, compares

1

10 119 13

7

654

12

32

8

Σ\{<}

{<}

{A,a}

{I,i}

{F,f} {R,r}

{O,o}

{M,m}

{E,e}

{\t,\n,\r,˽}

Σ\{>}

{A,a}

{F,f} {R,r} {M,m}

{>}

{<}

{R,r}

Figure 7: A Deterministic Finite Automaton Example.

its value should be specified as true for role a and falsefor role b. Our analyzer explores the statements of theIR in order. Besides function definitions, the first state-ment it encounters is the function call checkUser().Therefore, it retrieves the corresponding function bodyand continues from the first statement in the function. Be-cause the first statement is an if statement, the analyzerattempts to solve the satisfiability of constraints to deter-mine branch feasibilities. If the given role is b, only thetrue branch is feasible. As the true branch has a headerredirection, the analyzer stops exploring the statementsafter this function call. Otherwise, when the role is a, onlythe false branch is feasible, and the analyzer continues ex-ploring the statements after this function call, and eventu-ally reaches function call SensitiveOperation().

Path sensitivity prevents us from exploring infeasiblepaths. For example, suppose we have predicate $x > 1 inthe current path condition when the exploration reachesan if statement, the branch target of which depends on aconditional $x < 0. To determine the feasibilities of thetwo possible branches, our analyzer sends two queriesto Z3. The first query appends the new constraint to theexisting path condition, while the second query appendsthe negation of the new constraint to the existing pathcondition. Z3 will conclude that ($x > 1 ∧ $x < 0) is un-satisfiable, but ($x > 1 ∧ ¬($x < 0)) is satisfiable. Thus,only the false branch is feasible and our analyzer will notexplore the infeasible true branch of the if statement.

5.2.2 Link Extractor

Our link extractor extracts links to different web pageswithin a given web application. Since we are interested inconstructing sitemaps, our link extractor filters links thatpoint to pages outside of the application. We did not reusethe implementation from the previous work [30], whichis based on the standard graph-reachability algorithm, butinstead implemented the new link extraction algorithmshown in Figure 4 to eliminate the need of computingintermediate HTML outputs. As an example, Figure 7

shows an FA which matches anchor, form, frame andiframe tags in HTML outputs based on a simple regularexpression:

/<([Aa]|[Ff][Oo][Rr][Mm]|[Ii]?[Ff][Rr][Aa][Mm][Ee]

)\s[ˆ>]*>/

We only show state-advancing edges in Figure 7 and omitstate-resetting edges. In this FA, the start state q0 = 1and the final state set Q f = {8}. For any FA state, astate-resetting edge directs the current FA state back tothe start FA state on input characters other than the onesshown on the state-advancing edges. We use the followingsimplified PHP code taken from one of our test subjectsto show how our link extractor works.

echo "<div><a href=". $lang. ".php>Anchor</a></div>" ;

The above PHP code dynamically generates a link de-pending on the value of variable $lang, which has threepossible candidates: “english”, “spanish” and “french”.For this code, a CFG with five variables and seven gram-mar productions will be generated:

S0→ S1S2

S1→ “<div><a href=”S2→ S3S4

S3→ “english” | “spanish” | “french”S4→ “.php>Anchor</a></div>”

In this CFG, V = {S0,S1,S2,S3,S4} and S0 is the startsymbol. Note that S3 has three associated grammar pro-ductions separated by bars. For the algorithm in Fig-ure 4, the link extraction starts with function call WALK-VAR(S0,1,“”) (Line 38). Since S0 maps to only one pro-duction, RHS = {[S1S2]} (Line 11) and our algorithmissues WALKSYMBOLS([S1S2],1,“”) (Line 18). Then, it

Page 10: Static Detection of Access Control Vulnerabilities in Web ...web.cs.ucdavis.edu/~su/publications/security11.pdf · constructs sitemaps for different roles in a web applica-tion, compares

examines the symbols in list [S1S2] (Line 32) in order toderive the set of possible outcomes QW , the initial valueof which is {〈1,“”〉} (Line 31). Our algorithm sees thatthe first symbol S1 is a variable and thus issues WALK-VAR(S1,1,“”) (Line 27). For S1, RHS ={“<div><ahref=”} (Line 11), and the algorithm issues WALKSYM-BOLS(“<div><a href=”,1,“”) (Line 18). Now our algo-rithm examines these terminals in order with functionWALKTERMINAL. The first character is ‘<’, thus thealgorithm transits the FA state from 1 to 2 along a state-advancing edge in Figure 7, and appends ‘<’ to w whichis now “<”. The second character is ‘d’, thus the algo-rithm resets the FA state to the start state 1, and clears thematched terminals in w. The third character is ‘i’, thusthe algorithm stays at the FA start state 1, and w is stillthe empty string. Our algorithm continues like this andby the time it gets to variable S3, the FA is in state 7 withw =“<a href=”. For S3, RHS ={“english”, “spanish”,“french”} (Line 11), and our algorithm walks these threeelements one by one (Line 15). There are three possibleoutcomes, and thus the return value QW of WALKSYM-BOLS(S3,7,“< a href=”) is {〈7, “<a href=english”〉,〈 7,“<a href=spanish”〉,〈7, “<a href=french”〉} (Line 19).Our algorithm continues until all the seven grammarrules have been explored. Upon termination, it returns{“english.php”, “spanish.php”, “french.php”} (Line 39).

5.3 Vulnerability DetectorWhen the construction of per-role sitemaps is complete,our analyzer compares the two reachable node sets to inferprivileged nodes. As HTML outputs presented to differ-ent roles are usually different, the set of privileged nodesis not empty in most cases. After obtaining the set ofprivileged nodes, our analyzer uses the same context-freegrammar constructor again to approximate the outcomesof forced browsing. Finally, it compares derived redi-rection sets and the sizes of CFGs to determine whetherforced browsing attemps are successful.

Even when forced browsing is successful, it is possiblethat the corresponding page does not contain any sensi-tive information or operations and is therefore consideredsafe. We observed that some pages used as file inclusionsonly contain function and class definitions. Such pagesnormally serve as inclusion files and are safe on their own.When the automatic vulnerability detection is over, weidentify such safe pages with manual analysis, report themas false positives, and then mark the remaining pages aspotentially vulnerable pages.

6 Empirical EvaluationTo evaluate the effectiveness and performance of our ap-proach, we tested our tool on seven real-world PHP appli-cations, two of which have patched versions. We pickedthese applications because they have reported vulnerabil-ities, which include injection vulnerabilities as well as

Subject Files LOC

PHP HTML

SCARF 25 1,318 0Events Lister 37 2,076 544PHP Calendars 67 1,350 0PHPoll 93 2,571 0PHP iCalendar 183 8,276 0AWCM 668 12,942 5,106YaPiG 134 4,801 1,271

Table 1: Statistics on Evaluation Subjects.

access control vulnerabilities. The test subjects includeboth traditional web applications and Web 2.0 applica-tions which use AJAX for client-server communications.The source code of all these PHP applications is publiclyavailable. For each of the test subjects, we provide a spec-ification file of at most ten lines. We ran all the tests on aPC with a quad-core CPU (2.40GHz) and 4 GB of RAM.

Our tool supports multiple roles and each role shouldhave a set of distinctive application states. Typically, theadministrator role has the most privileges; the normal userrole has necessary privileges for common user operations;and the public user role has the least privileges. Althoughour tool can detect access control violations for any tworoles, we chose to detect access control violations betweenadministrators and normal users for two reasons. First, theoperations and information that administrators can accessare of greater importance than those that normal users canaccess. Second, it is often difficult for attackers to legallyobtain administrator accounts, but easy to obtain normaluser accounts.

Table 1 shows the total number of files as well as thelines of code for each web application. For the two webapplications that have patched versions, we only list thestatistics for the patched versions in the table. The linesof code in each application are counted for both PHPand HTML, excluding comments and empty lines. Ouranalysis translates HTML code into equivalent PHP echostatements.

6.1 Analysis ResultsTable 2 shows the analysis results for the nine web appli-cations. Note that we include two versions of SCARF andAWCM for vulnerability analysis. Columns “Vulnerable”and “FP” denote the numbers of detected true vulnerabili-ties and manually confirmed false positives respectively.Column “Guarded” shows the number of privileged pagesthat are protected by access checks. The last four columnsshow numbers of explicitly reachable nodes and explicitedges in per-role sitemaps.

In summary, our tool found eight different access con-trol vulnerabilities, four of which are previously unknown.

Page 11: Static Detection of Access Control Vulnerabilities in Web ...web.cs.ucdavis.edu/~su/publications/security11.pdf · constructs sitemaps for different roles in a web applica-tion, compares

Project Privileged Vulnerable FP Guarded Admin Normal

Node Edge Node Edge

SCARF 4 1 0 3 19 149 15 69SCARF (patched) 4 0 0 4 19 149 15 69Events Lister 2.03 9 2 2 5 23 113 14 26PHP Calendars 3 1 0 2 19 35 19 30PHPoll v0.97 beta 3 3 0 0 21 63 19 58PHP iCalendar v1.1 1 0 0 1 51 292 50 292AWCM v2.1 47 1 0 46 176 2,634 129 2,438AWCM v2.2 final 47 0 0 47 180 2,851 133 2,612YaPiG 0.95 11 0 0 11 54 260 44 154

Table 2: Vulnerability Analysis Results.

It only has two false positives and correctly reports 119guarded pages as not vulnerable. We manually confirmedall vulnerabilities and false positives on deployed webapplications. In addition, the by-products of our analysis,the generated per-role sitemaps, provide high-level viewsof the test subjects and can be useful for understanding ormodifying the structures of these web applications.

6.1.1 SCARF

SCARF is the Standford Conference And Research Fo-rum. A critical access control checks whether the valueof $ SESSION[“privilege”] equals “admin” in functionsis admin and require admin.

Our tool detected a previously reported vulnerability(CVE-2006-5909). In this application, only users of role aare supposed to edit the configuration of the application inpage “generaloptions.php”. However, there is no accesscheck for this edit privilege. Although the link is hid-den from users of role b, they could still access and editthe configuration which affects the whole system. Ourtool correctly reported the other three privileged pages“addsession.php”, “editpaper.php” and “editsession.php”as guarded. Even if users of role b know the locationsof these pages, forced browsing would fail because ofthe presence of access checks in these pages. The lat-est version of SCARF fixed the vulnerability, and this isreflected in the vulnerability analysis result for SCARF(patched).

6.1.2 Events Lister

Events Lister is a PHP application that allows usersto manage their events. Function checkUser im-plements an access control by checking whether$ SESSION[“validUser”] equals true.

Our tool found a new vulnerability in this applicationas well as a previously known one (CVE-2009-3168). Wediscovered that page “admin/setup.php” has no accesschecks and allows users of role b to repeatedly insert testevents into the database of the application. It is even pos-

sible to create new tables in the database if none exists yet.The known vulnerability in page “admin/user add.php”permits users of role b to add new users into the system.This privilege should only belong to users of role a. Weconsider the other two reports on privileged pages “ad-min/recover.php” and “admin/form.php” false positives.Page “admin/recover.php” allows users of role b to re-set an administrator’s password by sending a new pass-word to the administrator’s email address. Since only theadministrator has access to her own email address, thepassword reset action does not pose any serious threats.Page “admin/form.php” contains an HTML form whichis included in other container pages. On its own, this pagedoes not expose any privileged operations or information,and is therefore considered safe. The notion of “safe” issometimes a subjective matter. In a manual case study ofanother web application, we found that public users canview the list of all registered users with forced browsing.Such a list is also available for normal users and one caneasily register for a normal user account. Consequently,it is unclear to us if the implicit access to the list of regis-tered users is intended. As such, we would rather reportsuch cases to developers for them to decide.

6.1.3 PHP Calendars

PHP Calendars is an online calendar management system.It protects privileged pages in the application by check-ing whether $ SESSION[“admin”] equals “yes” in page“admin/access.php”.

Our tool detected a known vulnerability (CVE-2010-0380) in page “install.php” of this application. TheREADME file in this application warns administrators todelete this page after installation, but does not check ifthe file has indeed been deleted. If “install.php” exists ina deployed application, any users of role b could modifythe configuration of the application by directly accessingthis page. Because there is an explicit link to this page,we manually added this page to the privileged node set inthe specification file. The other two privileged pages “ad-

Page 12: Static Detection of Access Control Vulnerabilities in Web ...web.cs.ucdavis.edu/~su/publications/security11.pdf · constructs sitemaps for different roles in a web applica-tion, compares

min/import.php” and “powerfeed.php” are not vulnerable.Note that Na is not necessarily a superset of Nb. In thisapplication, |Na|= |Nb|, but Na 6= Nb.

6.1.4 PHPoll

PHPoll is an online poll system where only usersof role a can pass access checks by providingcorrect values of $ COOKIE[$string cook login] and$ COOKIE[$string cook password]. Note that thecookie-based access controls are safe in this case becauseunauthorized users have no knowledge of valid cookievalues.

Our tool detected three new access control vulnera-bilities in this application and we manually confirmedthem on a deployed application of PHPoll. All threepages have no access checks. The first page “modi-fica configurazione.php” allows users of role b to modifylogin IDs and passwords, truncate the configuration table,and insert new entries into the configuration table of theapplication. The second page “modifica votanti.php” letsusers of role b delete votes or update polls stored in theMySQL database. The third page “modifica band.php”does not prevent users of role b from reading, updating,or deleting poll results from the database with POST re-quests. These access control vulnerabilities pose seriousthreats to the security of the application, yet they have notbeen reported to the best of our knowledge.

6.1.5 PHP iCalendar

PHP iCalendar is another calendar application whichdisplays calendar information to users. The onlyprivileged page is “admin.php”, and it is guardedby an access check which examines the value of$HTTP SESSION VARS[“phpical loggedin”].

This application does not have any access control vul-nerabilities. As Table 2 shows, users of role a can reach51 pages which include “admin.php”, while users of roleb can only reach 50 pages which exclude “admin.php”.

6.1.6 AWCM

AWCM (AR Web Content Manage system) differ-entiates role a from role b by determining whether$ SESSION[“awcm cp”] equals “yes” in a PHP includefile “control/common.php”.

Our tool detected a previously known vulnerabil-ity (CVE-2010-1066) in “control/db backup.php” whichdumps all the database information onto a web page. Thecause of this access control vulnerability is that “con-trol/db backup.php” includes “common.php” instead of“control/common.php”. Since access checks are onlypresent in “control/common.php” but not “common.php”,page “control/db backup.php” is not guarded and can beaccessed via forced browsing. Most pages in the “control”directory are intended for administrators only and our tooldetected 47 privileged nodes in total. Our tool correctly

recognized the access checks in the other 46 privilegedpages and only reported “control/db backup.php” to bevulnerable. The latest version of AWCM fixed the vulner-ability, and this is reflected in the analysis result shownin Table 2. Although this application is AJAX-heavy, ourtool covered nearly 80% of the active nodes, indicatingthat a majority of the links appear in PHP and HTMLcode which can be well handled with our tool.

6.1.7 YaPiG

YaPiG (Yet Another PHP Image Gallery) validates pass-words and determines the privilege level of users with anaccess check in function check admin login.

An interesting thing about YaPiG is that all the fiveunreachable pages result from an uncovered executionpath. In our implementation, we assume that an HTTPparameter $v could have any values. Therefore, our toolinfers that function call isset($v) returns true even ifv is undefined. When a conditional depends on such afunction call, the false branch is left unexplored. Our im-plementation does not yet support the specification of anoptional value, which can either be defined or undefined.

6.2 Performance EvaluationIn our evaluation, we collect links that point to files withinan application, excluding those that point to CSS fileswhich are of no interest to us. Currently, we treat PHP,HTML and XML files to be active nodes and analyze themto extract links. A page can contain links to both activenodes and inactive nodes. Although inactive nodes do notprovide sensitive operations, they may contain sensitiveinformation and therefore should also be checked.

Table 3 shows the coverage and performance of ourtool. Column “Entry” shows the number of specified en-try nodes for each application. Column “Active” lists thenumber of all active nodes. Column “Orphan” lists thenumber of specified orphan nodes which are non-entryactive nodes with no incoming edges. Column “Cover-age” lists the coverage of our tool on active nodes in anapplication, excluding orphan nodes. We list the aver-age numbers of variables and grammar productions ofall CFGs for each web application. Note that the num-bers are counted on CFGs that have been simplified withgrammar-reachability analysis. The last column showsthe total analysis time spent for each application in termsof seconds.

Active nodes may have outgoing edges and may nothave any incoming edges. An active node with no incom-ing edges can be optionally specified as either an entrynode or an orphan node. When it is specified as an entrynode, it is analyzed in the sitemap construction processto find outgoing edges; when it is specified as an orphannode, which indicates that this node should be outsideany sitemaps, it is excluded from the coverage calcula-tion; when it is unspecified, it may affect the coverage

Page 13: Static Detection of Access Control Vulnerabilities in Web ...web.cs.ucdavis.edu/~su/publications/security11.pdf · constructs sitemaps for different roles in a web applica-tion, compares

Project Nodes Context-Free Grammar Coverage Time (s)Entry Active Orphan Variables Productions

SCARF 1 19 0 158 719 100.00% 6.02SCARF (patched) 1 19 0 159 719 100.00% 6.01Events Lister v2.03 4 23 5 100 2,083 100.00% 3.84PHP Calendars 3 15 0 48 255 80.00% 5.09PHPoll v0.97 beta 5 21 6 115 224 100.00% 4.26PHP iCalendar v1.1 2 52 2 811 4,774 90.38% 760.62AWCM v2.1 17 208 22 410 422 79.33% 89.48AWCM v2.2 final 16 209 14 451 484 79.90% 108.51YaPiG 0.95 7 59 3 332 532 91.53% 208.38

Table 3: Coverage and Performance Results.

ProjectTime (s)

Admin Normal ForcedSitemap Sitemap Browsing

SCARF 3.15 1.70 1.15Events Lister 2.29 1.00 0.53PHP Calendars 1.81 1.67 1.61PHPoll 2.39 1.54 0.33PHP iCalendar 371.28 370.85 18.46AWCM 55.36 49.11 3.85YaPiG 85.59 44.91 77.86

Table 4: Analysis Time.

result. Let Active, Orphan and Reachable denote the setsof all active nodes, specified orphan nodes and explicitlyreachable nodes respectively. We calculate the coverageas:

Coverage =|Reachable|

|Active|− |Orphan|In our evaluation, we conservatively identify orphannodes with a simple manual analysis and the obtainedorphan sets may be incomplete, especially for large andcomplex applications. Therefore, the real coverages of ouranalysis might be better than the ones shown in the tablebecause uncovered nodes might indeed be unreachable.

Our static analyzer achieved good coverage of activenodes: 100% for four applications, about 90% for two,and about 80% for the remaining three. The total analy-sis time listed in Table 3 demonstrates that our approachis scalable. For the smaller test applications SCARF,Events Lister, PHP Calendars and PHPoll, our tool fin-ished within seven seconds; for the largest test applicationAWCM, our tool took less than two minutes to analyzethe active nodes in the whole application. The analysistime for iCalendar is the longest because of the inlining ofdynamic PHP files and the complexity of PHP code. Ascan be seen in Table 3, the number of grammar produc-

tions for PHP iCalendar is also the largest. We show thebreak down of analysis time in Table 4. Columns “AdminSitemap” and “Normal Sitemap” list the time spent onconstructing the sitemaps for roles a and b respectively.Column “Forced Browsing” shows the time spent on de-tecting access control vulnerabilities via forced brows-ing. It is obvious from the data in the table that buildingsitemaps consumes the majority of the analysis time.

6.3 DiscussionsAs we mentioned earlier, our prototype did not find allkinds of links in web applications. The major reason isthat our prototype did not identify all the links generatedby JavaScript code or HTML templates, or those con-structed with unresolvable string variables. Extractinglinks from JavaScript code is especially challenging be-cause of the dynamic features of the JavaScript language.Our prototype works better on traditional web applica-tions than AJAX-heavy ones. Incorporating JavaScriptanalysis could possibly improve the coverage. Further-more, our test applications may not be representative ofgeneral web applications.

What a node represents determines the granularity ofthe analysis. Our prototype treats a web page as a node,but the general approach still applies when the granularityis refined to functionalities within a page. Performingthe analysis at a refined granularity would be especiallyuseful for complex web pages which contain multiplefunctionalities within a single page. The techniques pro-posed by Halfond et al. [12] could be used to identifyimportant parameters in web applications to distinguishfunctionalities. Because a privilege is often granted witha set of atomic database operations, advancing the gran-ularity to the level of database operations might be toofine-grained.

Our prototype does not handle all object-oriented fea-tures in PHP. This prevents us from parsing some PHPpages in large PHP applications. We leave it as futurework to enhance our static analyzer for additional object-

Page 14: Static Detection of Access Control Vulnerabilities in Web ...web.cs.ucdavis.edu/~su/publications/security11.pdf · constructs sitemaps for different roles in a web applica-tion, compares

oriented features of the PHP language.The current implementation of the string constraint

solver is rudimentary. For either unsolvable constraintsor non-determinism in a conditional, we conservativelyexplore both branches. This might lead to false negativeswhen infeasible paths for a less privileged role are ex-plored. For access checks that involve non-determinism,such as password-based authentication and CSRF pro-tection that uses random tokens, we rely on role-basedspecifications to determine which execution paths to ex-plore. Non-determinism affects path explorations but notlink extractions. Furthermore, when Assumption 2 doesnot hold, we would also have false negatives introducedby explicit accesses to privileged nodes.

Our tool generated false positives. Even when accesschecks are missing in hidden pages, these pages may notcontain any sensitive information or operations and aretherefore safe to access for any role in the application. Wemanually examined the analysis results and marked suchsafe pages as false positives.

7 Related WorkIn this section, we discuss the most relevant work, includ-ing specification inference, workflow violation detection,privilege separation based on user roles, language-basedapproaches to secure web applications, and program anal-ysis for web security.

The capability of automated tools in detecting vulnera-bilities or bugs can only be as good as the specificationsgiven to them. Since manually writing specifications istedious, time-consuming and error-prone, a wide rangeof techniques have been proposed to automatically inferspecifications from the source code of programs. For in-trusion detection, Wagner and Dean [28] apply static anal-ysis to derive a model of normal application behavior as anoracle. Based on the observation that bugs are deviant be-havior [9], researchers have proposed probabilistic-basedapproaches [16, 26] to infer specifications from applica-tions. However, without taking into account of roles inweb applications, it is difficult to infer privileged pageswhich are only intended for a group of users.

Recently, workflow violations have attracted the in-terests of researchers. Nemesis [7] uses dynamic infor-mation flow tracking to detect authentication and accesscontrol vulnerabilities in web applications. It requiresdevelopers to specify access control lists for resources.Similarly, Halle et al. [13] proposed a runtime enforce-ment mechanism to only allow navigations that conformto a state machine model specified by developers. Re-searchers have proposed various techniques to automat-ically infer correct workflows. Swaddler [6] first learnsinternal states of web applications, and then detects ab-normal state violations at critical points. Targeting thedetection of Ajax intrusion attacks, Guha et al. [11] lever-age static analysis on client-side JavaScript code to infer

expected server-side behavior. To detect multi-modulevulnerabilities, MiMoSA [1] takes into account the in-teractions of different web pages. However, it is notalways easy to distinguish an intended path from an unin-tended one because of flexible navigation paths that webapplications allow. Its follow-up work Waler [10] usesa combination of dynamic analysis and symbolic modelchecking to first infer invariants from dynamic programexecutions, and then report violations of the invariants aslogic vulnerabilities. From a high-level view, the likelyinvariants that Waler generates with heuristics are subjectto errors. Furthermore, the inferred invariants may notalways hold due to the limited coverage of dynamic anal-ysis. Access control vulnerabilities can be considered aspecial case of workflow vulnerabilities where cross-roleworkflow assumptions are violated. Cross-role compar-isons allow us to precisely reason about privileged pagesin most cases.

To reduce least-privilege incompatibilities, researchersdistinguish different user roles and separate privilegesbased on different roles. Aiming at identifying dependen-cies on admin privileges in traditional software appli-cations, Chen et al. [4] run applications without adminprivileges and collect dynamic execution traces. We takea step further and use roles to represent sets of privilegesin web applications. In our setting, roles form a lattice andits height is not limited. To reduce developer’s burden onsecuring web applications, the CLAMP project [23] pre-vents leakage of sensitive information by restricting theflows of user data and isolating the authentication moduleof an application. While they also minimize developers’effort, they secure web applications by modifying appli-cation code at critical points. Web application vulnerabil-ity scanners can also automatically detect access controlvulnerabilities. However, they often build shallow andincomplete sitemaps, missing deep and invisible pagesthat are only accessible when valid form data are submit-ted. This undermines the capabilities of web scanners inboth discovering privileged nodes as well as successfullyperforming forced browsing with valid form data.

Previous work has proposed language-based ap-proaches to secure web applications in a principled way.SIF [5] accepts specifications either as program annota-tions at compile time, or as user requirements at run timeto guarantee confidentiality and integrity with informa-tion flow analysis. Recently, Krishnamurthy et al. [17]presented an object-capability language for fine-grainedprivilege separation for web applications. Unfortunately,theses language-based approaches do not apply to thelarge set of legacy code that is not written in the newlydesigned languages.

In the past few years, researchers have focused theirattention on detecting injection vulnerabilities in web ap-plications with both static analysis [18, 19, 25, 27, 29, 30,

Page 15: Static Detection of Access Control Vulnerabilities in Web ...web.cs.ucdavis.edu/~su/publications/security11.pdf · constructs sitemaps for different roles in a web applica-tion, compares

31, 32] and dynamic analysis [2, 3, 22, 24]. Similar to ourstatic analyzer, Pixy [14] is also a static analyzer built toanalyze PHP applications. It takes advantage of taint anal-ysis to detect injection vulnerabilities with specificationson taint sources and sinks. Its implementation hinders itfrom scaling to large applications as Pixy has no supportfor include resolution and object-oriented features.

8 ConclusionsDevelopers should enforce access controls throughoutweb applications for every privileged page. This paperproposes a novel approach to detect access control vul-nerabilities in web applications with minimal manual ef-fort. Based on the observation that sitemaps presentedto different roles are not identical, our analysis first au-tomatically infers the set of privileged pages from thesource code of a web application, and then detects accesscontrol vulnerabilities via forced browsing. We addedsupport for role-based specification rules, and integratedconstraint-solving capabilities with our static analyzer tosystematically explore program paths. Our tool is ableto achieve good coverage and scale to real-world applica-tions. The evaluation results demonstrate that it is capableof detecting both unknown and known access control vul-nerabilities in unmodified web applications with only afew lines of specifications. For future work, we plan tosupport additional language features of PHP, enhance thestring constraint solver, and scale the analysis to largerweb applications.

AcknowledgmentsWe thank the anonymous reviewers and Rob Johnson,the shepherd of this paper, for their useful and detailedcomments. We also thank Earl T. Barr, Mark Gabel,Taeho Kwon, Zhongxian Gu and other people who gavehelpful feedback on the overall approach and presentationof this work. We especially thank Gary Wassermannand Yasuhiko Minamide for developing the PHP stringanalyzer and answering our questions. This research wassupported in part by NSF CAREER Grant No. 0546844,NSF CyberTrust Grant No. 0627749, NSF CCF Grant No.0702622, NSF TC Grant No. 0917392, and the US AirForce under grant FA9550-07-1-0532. The informationpresented here does not necessarily reflect the position orthe policy of the Government and no official endorsementshould be inferred.

References[1] D. Balzarotti, M. Cova, V. V. Felmetsger, and G. Vi-

gna. Multi-Module Vulnerability Analysis of Web-based Applications. In Proceedings of ACM Con-ference on Computer and Communications Security,pages 25–35, 2007.

[2] D. Balzarotti, M. Cova, V. Felmetsger, N. Jovanovic,

E. Kirda, C. Kruegel, and G. Vigna. Saner: Compos-ing Static and Dynamic Analysis to Validate San-itization in Web Applications. In Proceedings ofIEEE Symposium on Security and Privacy, pages387–401, 2008.

[3] W. Chang, B. Streiff, and C. Lin. Efficient and Ex-tensible Security Enforcement Using Dynamic DataFlow Analysis. In Proceedings of ACM Conferenceon Computer and Communications Security, pages39–50, 2008.

[4] S. Chen, J. Dunagan, C. Verbowski, and Y.-M. Wang.A Black-Box Tracing Technique to Identify Causesof Least-Privilege Incompatibilities. In Proceed-ings of Network and Distributed System SecuritySymposium, 2005.

[5] S. Chong, K. Vikram, and A. C. Myers. SIF: Enforc-ing Confidentiality and Integrity in Web Applica-tions. In Proceedings of the Conference on USENIXSecurity Symposium, 2007.

[6] M. Cova, D. Balzarotti, V. Felmetsger, and G. Vigna.Swaddler: An Approach for the Anomaly-basedDetection of State Violations in Web Applications.In Proceedings of the International Symposium onRecent Advances in Intrusion Detection, pages 63–86, 2007.

[7] M. Dalton, C. Kozyrakis, and N. Zeldovich. Neme-sis: Preventing Authentication and Access ControlVulnerabilities in Web Applications. In Proceedingsof the USENIX Security Symposium, pages 267–282,2009.

[8] L. De Moura and N. Bjørner. Z3: An Efficient SMTSolver. In Proceedings of the International Confer-ence on Tools and Algorithms for the Constructionand Analysis of Systems, pages 337–340, 2008.

[9] D. Engler, D. Y. Chen, S. Hallem, A. Chou, andB. Chelf. Bugs as Deviant Behavior: A GeneralApproach to Inferring Errors in Systems Code. InProceedings of the ACM Symposium on OperatingSystems Principles, pages 57–72, 2001.

[10] V. Felmetsger, L. Cavedon, C. Kruegel, and G. Vi-gna. Toward Automated Detection of Logic Vul-nerabilities in Web Applications. In Proceedings ofthe USENIX Security Symposium, pages 143–160,2010.

[11] A. Guha, S. Krishnamurthi, and T. Jim. Using StaticAnalysis for Ajax Intrusion Detection. In Proceed-ings of the International Conference on World WideWeb, pages 561–570, 2009.

Page 16: Static Detection of Access Control Vulnerabilities in Web ...web.cs.ucdavis.edu/~su/publications/security11.pdf · constructs sitemaps for different roles in a web applica-tion, compares

[12] W. G. J. Halfond and A. Orso. Automated identifi-cation of parameter mismatches in web applications.In Proceedings of the Symposium on Foundations ofsoftware engineering, 2008.

[13] S. Halle, T. Ettema, C. Bunch, and T. Bultan. Elim-inating Navigation Errors in Web Applications viaModel Checking and Runtime Enforcement of Nav-igation State Machines. In Proceedings of the Inter-national Conference on Automated Software Engi-neering, pages 235–244, 2010.

[14] N. Jovanovic, C. Kruegel, and E. Kirda. Pixy: AStatic Analysis Tool for Detecting Web Applica-tion Vulnerabilities (short paper). In Proceedingsof IEEE Symposium on Security and Privacy, pages258–263, 2006.

[15] A. Kiezun, V. Ganesh, P. J. Guo, P. Hooimeijer, andM. D. Ernst. HAMPI: A Solver for String Con-straints. In Proceedings of the International Sympo-sium on Software Testing and Analysis, 2009.

[16] T. Kremenek, P. Twohey, G. Back, A. Ng, and D. En-gler. From Uncertainty to Belief: Inferring the Spec-ification Within. In Proceedings of the USENIXSymposium on Operating Systems Design and Im-plementation, pages 12–12, 2006.

[17] A. Krishnamurthy, A. Mettler, and D. Wagner. Fine-Grained Privilege Separation for Web Applications.In Proceedings of the International Conference onWorld Wide Web, pages 551–560, 2010.

[18] B. Livshits, A. V. Nori, S. K. Rajamani, andA. Banerjee. Merlin: Specification Inference for Ex-plicit Information Flow Problems. In Proceedingsof the ACM SIGPLAN Conference on ProgrammingLanguage Design and Implementation, pages 75–86,2009.

[19] V. B. Livshits and M. S. Lam. Finding Security Vul-nerabilities in Java Applications with Static Analy-sis. In Proceedings of the Conference on USENIXSecurity Symposium, pages 18–18, 2005.

[20] D. Melski and T. Reps. Interconvertbility of Set Con-straints and Context-Free Language Reachability. InProceedings of the Symposium on Partial Evalua-tion and Semantics-Based Program Manipulation,1997.

[21] Y. Minamide. Static Approximation of DynamicallyGenerated Web Pages. In Proceedings of the In-ternational Conference on World Wide Web, pages432–441, 2005.

[22] A. Nguyen-tuong, S. Guarnieri, D. Greene,J. Shirley, and D. Evans. Automatically Harden-ing Web Applications Using Precise Tainting. In

Proceedings of the IFIP International InformationSecurity Conference, pages 372–382, 2005.

[23] B. Parno, J. M. McCune, D. Wendlandt, D. G. An-dersen, and A. Perrig. CLAMP: Practical Preventionof Large-Scale Data Leaks. In Proceedings of theIEEE Symposium on Security and Privacy, pages154–169, 2009.

[24] R. Sekar. An Efficient Black-box Technique forDefeating Web Application Attacks. In Proceed-ings of the Network and Distributed System SecuritySymposium, 2009.

[25] Z. Su and G. Wassermann. The Essence of Com-mand Injection Attacks in Web Applications. InProceedings of the Annual Symposium on Principlesof Programming Languages, pages 372–382, 2006.

[26] L. Tan, X. Zhang, X. Ma, W. Xiong, and Y. Zhou.AutoISES: Automatically Inferring Security Specifi-cations and Detecting Violations. In Proceedings ofthe USENIX Security Symposium, pages 379–394,2008.

[27] O. Tripp, M. Pistoia, S. J. Fink, M. Sridharan, andO. Weisman. TAJ: Effective Taint Analysis of WebApplications. In Proceedings of the ACM SIGPLANConference on Programming Language Design andImplementation, pages 87–97, 2009.

[28] D. Wagner and D. Dean. Intrusion Detection viaStatic Analysis. In Proceedings of the IEEE Sym-posium on Security and Privacy, pages 156–168,2001.

[29] G. Wassermann and Z. Su. Sound and Precise Analy-sis of Web Applications for Injection Vulnerabilities.In Proceedings of the ACM SIGPLAN Conferenceon Programming Language Design and Implemen-tation, pages 32–41, 2007.

[30] G. Wassermann and Z. Su. Static Detection of Cross-Site Scripting Vulnerabilities. In Proceedings ofInternational Conference on Software Engineering,pages 171–180, 2008.

[31] Y. wen Huang, F. Yu, C. Hang, C. hung Tsai, D. T.Lee, and S. yen Kuo. Securing Web ApplicationCode by Static Analysis and Runtime Protection.In Proceedings of the International Conference onWorld Wide Web, pages 40–52, 2004.

[32] Y. Xie and A. Aiken. Static Detection of Securityvulnerabilities in Scripting Languages. In Proceed-ings of the Conference on USENIX Security Sympo-sium, 2006.