This repository was archived by the owner on Jan 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathutil.js
More file actions
215 lines (186 loc) · 7.01 KB
/
Copy pathutil.js
File metadata and controls
215 lines (186 loc) · 7.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*
Copyright 2007 Security Compass
This file is part of SQL Inject Me.
SQL Inject Me 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.
SQL Inject Me 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.
You should have received a copy of the GNU General Public License
along with SQL Inject Me. If not, see <http://www.gnu.org/licenses/>.
If you have any questions regarding SQL Inject Me please contact
tools@securitycompass.com
*/
/**
* util.js
* Utility Functions.
*/
const EXTENSION_NAME = 'xssme@security.compass';
/**
* This takes a string of a piece of encoded XML and decodes it.
* Specifically, this checks checks for encoded nested ]]> code.
* Note: No XML parsing or checking is done.
* @param xmlString
* @returns a decoded string of a piece of XML (same piece)
*/
function decodeXML(xmlString) {
var regex = ']]]]><![CDATA[';
var replaced = ']]>';
return xmlString.replace(regex, replaced, 'gm');
}
/**
* This takes a string of a piece of XML and decodes it.
* Specifically, this checks checks for nested ']]>' code.
* Note: No XML parsing or checking is done.
* @param xmlString
* @returns an encoded string of a piece of XML (same piece)
*/
function encodeXML(xmlString) {
var regex = ']]>';
var replaced = ']]]]><![CDATA[';
return xmlString.replace(regex, replaced, 'gm');
}
/**
* Takes a string and returns the string with each character encoded in html
* entities (e.g. A for A).
*/
function encodeString(str){
var rv = "";
for each(var letter in str){
rv += '&#' + letter.charCodeAt() + ';';
}
return rv;
}
/**
* This imports attacks from an XML file
*/
function importAttackFromXMLString(fileContents, container) {
var domParser = new DOMParser();
dump('PreferencesController::importAttacks imported data (post decoding): \n---\n' + fileContents + '\n---\n');
var dom = domParser.parseFromString(fileContents, "text/xml");
if(dom.documentElement.nodeName == "parsererror"){
alert("error while parsing document, ensure that the document is complete and uncorrupted.");
return false;
}
var attacksTags = dom.getElementsByTagName("attacks");
if (attacksTags.length != 1){
alert("couldn't find attacks tag. Error while processing document.");
return false;
}
var attacksTag = attacksTags[0];
var attackTags = new Array();
var attackStringContainer = (container === undefined) ? getAttackStringContainer() : container;
for (var i = 0; i < attacksTag.childNodes.length; i++){
// alert("'" + (attackTag.firstChild.firstChild.nodeName == '#text')+"'");
dump("::importAttacks()... (" + attacksTag + "== attacksTag) attacksTag[" + i + "] == " + attacksTag.childNodes[i] + "\n");
if ("attack" === attacksTag.childNodes[i].nodeName){
attackTags.push(attacksTag.childNodes[i]);
}
}
if (attackTags.length){
for each(var attackTag in attackTags){
var stringTag = null;
var sigTag = null;
for each(var tag in attackTag.childNodes){
dump("::importAttacks()... (looking for attackString and sig) " + tag.nodeName + "\n");
if (tag.nodeName === "attackString"){
dump("got attackString\n");
stringTag = tag;
}
else if (tag.nodeName === "signature"){
dump("got sigString\n");
sigTag = tag;
}
}
if (stringTag === null || sigTag === null){
alert("Couldn't import attack. Couldn't find stringAttack or signature tags. Error while processing the document. ");
this.makeUI(attackStringContainer.getStrings(), window); // just in case.
return false;
}
else{
if (stringTag.childNodes.length !== 0)
{
attackStringContainer.addString(
decodeXML(stringTag.textContent),
sigTag.textContent);
}
else {
alert("Couldn't import attack. attackString is empty. Error while processing the document. ");
this.makeUI(attackStringContainer.getStrings(), window); // just in case.
return false;
}
}
}
}
else {
alert("Couldn't find any attacks. No Attacks imported.");
return false;
}
}
function importAttacksFromXMLFile(importFile, container) {
var fileContents = FileIO.read(importFile);
return importAttackFromXMLString(fileContents, container);
}
function getMonthName(monthNumber) {
var months = new Array();
months[0] = "January";
months[1] = "February";
months[2] = "March";
months[3] = "April";
months[4] = "May";
months[5] = "June";
months[6] = "July";
months[7] = "August";
months[8] = "September";
months[9] = "October";
months[10] = "November";
months[11] = "December";
return months[monthNumber];
}
/**
* This function checks the success whether the work tab's content document
* match the original tab's content document (in ways that we care about).
* @returns true if same otherwise false.
*/
function compareContentDocuments(origTabContentDocument, workTabContentDocument) {
var rv = true;
if (workTabContentDocument.forms) {
if (origTabContentDocument.forms.length ===
workTabContentDocument.forms.length)
{
for (var i = 0; i < origTabContentDocument.forms.length && rv; i++) {
if (workTabContentDocument.forms[i]){
if (workTabContentDocument.forms[i].elements){
for (var n = 0; n < origTabContentDocument.forms[i].elements.length && rv; n++){
if (workTabContentDocument.forms[i].elements[i]) {
if (origTabContentDocument.forms[i].elements[i].type !=
workTabContentDocument.forms[i].elements[i].type) {
rv = false;
}
}
}
}
else {
rv = false;
}
}
else {
rv = false;
}
}
}
else {
rv = false;
}
}
else {
rv = false;
}
return rv
}
function getHTMLFormElementNameOrLabel(element) {
return element.name?element.name:element.id;
}