ThreatScript Definitions » History » Version 1
Luke Murphey, 04/10/2010 01:01 PM
1 | 1 | Luke Murphey | h1. ThreatScript Definitions |
---|---|---|---|
2 | 1 | Luke Murphey | |
3 | 1 | Luke Murphey | ThreatScript Definitions are written in ECMAScript (basically the same as JavaScript). The ThreatScript definitions return a Result object which indicates whether a match was observed. |
4 | 1 | Luke Murphey | |
5 | 1 | Luke Murphey | h2. Meta-Data |
6 | 1 | Luke Murphey | |
7 | 1 | Luke Murphey | ThreatScripts must provide a meta-data that indicates the following information: |
8 | 1 | Luke Murphey | |
9 | 1 | Luke Murphey | | *Name* | *Valid Input* | *Notes* | |
10 | 1 | Luke Murphey | | Name | <category>.<sub_category>.<definition_name> | | |
11 | 1 | Luke Murphey | | Version | integer | | |
12 | 1 | Luke Murphey | | ID | integer | | |
13 | 1 | Luke Murphey | | Message | message to be displayed when definition matches | | |
14 | 1 | Luke Murphey | | Severity| Either: Low, Medium or High | | |
15 | 1 | Luke Murphey | |
16 | 1 | Luke Murphey | h2. ThreatScript Example |
17 | 1 | Luke Murphey | |
18 | 1 | Luke Murphey | Below is an example of a ThreatScript that triggers if the web-page has a form element. |
19 | 1 | Luke Murphey | |
20 | 1 | Luke Murphey | <pre><code class="javascript"> |
21 | 1 | Luke Murphey | /* |
22 | 1 | Luke Murphey | * Name: Example.General.Has_Form_Tag |
23 | 1 | Luke Murphey | * Version: 1 |
24 | 1 | Luke Murphey | * ID: 1000000 |
25 | 1 | Luke Murphey | * Message: Indicates if the page has as a form tag |
26 | 1 | Luke Murphey | * Severity: Low |
27 | 1 | Luke Murphey | */ |
28 | 1 | Luke Murphey | |
29 | 1 | Luke Murphey | importPackage(Packages.ThreatScript); |
30 | 1 | Luke Murphey | importPackage(Packages.HTTP); |
31 | 1 | Luke Murphey | |
32 | 1 | Luke Murphey | function analyze( httpResponse, operation, variables, environment, defaultRule ){ |
33 | 1 | Luke Murphey | |
34 | 1 | Luke Murphey | var parser = httpResponse.getDocumentParser(); |
35 | 1 | Luke Murphey | var location = new URL( httpResponse.getLocation() ); |
36 | 1 | Luke Murphey | |
37 | 1 | Luke Murphey | //Get a list of all script tags |
38 | 1 | Luke Murphey | var tagNameFilter = new TagNameFilter("form"); |
39 | 1 | Luke Murphey | var nodesList = parser.extractAllNodesThatMatch(tagNameFilter); |
40 | 1 | Luke Murphey | if( nodesList.size() > 0 ){ |
41 | 1 | Luke Murphey | return new Result( true, "A form was detected" ); |
42 | 1 | Luke Murphey | } |
43 | 1 | Luke Murphey | |
44 | 1 | Luke Murphey | return new Result( false, "No forms detected" ); |
45 | 1 | Luke Murphey | } |
46 | 1 | Luke Murphey | </code> |
47 | 1 | Luke Murphey | </pre> |