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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
|
<?php
// Deluje pravilno le za eno formo
// Mogoce bi tudi razsiril tako da bi podal form name
// Zaenkrat le radio in checkbox.
class ParseForm {
var $content; // vsebina strani
var $url;
// cookies
var $cookies;
// direktno dumpano
// [offset][0] -- name , [offset][1] -- value
var $inputs;
var $selects;
var $hidden;
var $checkboxes;
var $radio;
var $textbox;
// Kam kaze forma
var $method;
var $action;
// urejeno
var $arr_checkbox;
var $arr_radio;
var $arr_hidden;
function ParseForm ($url) {
$this->url = $url;
$fv = file_get_contents (str_replace('&', '&', $url));
if (strpos ($fv, "<body") !== false) {
$fv = substr ($fv, strpos ($fv, "<body"), strpos ($fv, "</body>"));
}
$this->content = $fv;
}
function GetCookies () {
ob_start();
$ch = curl_init($this->url);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_NOBODY, 1);
$ok = curl_exec($ch);
curl_close($ch);
$head = ob_get_contents();
ob_end_clean();
preg_match_all ("/Set-Cookie\:(.*?)\;/i", $head, $kukiji);
for ($x = 0; $x <= sizeof ($kukiji[1]); $x++) {
preg_match ("/\ (.*?)\=/i", $kukiji[1][$x], $ime);
$this->cookies[sizeof($this->cookies)][0] = str_replace (" ", "", str_replace ("=", "", $ime[0]));
$this->cookies[sizeof($this->cookies)-1][1] = str_replace ($ime[0], "", $kukiji[1][$x]);
}
}
function GetTarget () {
preg_match ("/\<form\ (.*?)>/i", $this->content, $forma);
preg_match ("/method\=\"(.*?)\"/i", $forma[1], $method);
$method = str_replace ('method="', '', $method[0]);
$this->method = str_replace ('"', '', $method);
preg_match ("/action\=\"(.*?)\"/i", $forma[1], $action);
$action = str_replace ('action="', '', $action[0]);
$this->action = str_replace ('"', '', $action);
echo 'METHOD: '.$this->method.'<br>';
echo 'ACTION: '.$this->action.'<br>';
}
function GetFields () {
preg_match_all ("/\<input\ (.*?)>/i", $this->content, $this->inputs);
echo "<hr>KLican sem na getfields<hr>";
// najprej parsajmo inpute
for ($x = 0; $x <= sizeof ($this->inputs[1]); $x++) {
unset ($value);
unset ($type);
unset ($name);
preg_match ("/name\=\"(.*?)\"/i", $this->inputs[1][$x], $name);
$name = str_replace ('name="', '', $name[0]);
$name = str_replace ('"', '', $name);
preg_match ("/value\=\"(.*?)\"/i", $this->inputs[1][$x], $value);
$value = str_replace ('value="', '', $value[0]);
$value = str_replace ('"', '', $value);
preg_match ("/type\=\"(.*?)\"/i", $this->inputs[1][$x], $type);
$type = str_replace ('type="', '', $type[0]);
$type = str_replace ('"', '', $type);
if (strtolower ($type) == "checkbox") {
$this->checkboxes[sizeof($this->checkboxes)][0] = $name;
$this->checkboxes[sizeof($this->checkboxes)-1][1] = $value;
}
if (strtolower ($type) == "radio") {
$this->radio[sizeof($this->radio)][0] = $name;
$this->radio[sizeof($this->radio)-1][1] = $value;
}
if (strtolower ($type) == "hidden") {
$this->hidden[sizeof($this->hidden)][0] = $name;
$this->hidden[sizeof($this->hidden)-1][1] = $value;
}
if (strtolower ($type) == "text") {
$this->textbox[sizeof($this->textbox)][0] = $name;
$this->textbox[sizeof($this->textbox)-1][1] = $value;
}
}
}
// Izpise na zaslon vsa polja
function DumpFields () {
for ($a=0; $a<=sizeof($this->checkboxes); $a++) {
echo "Checkbox" .$this->checkboxes[$a][0] .", val: " .$this->checkboxes[$a][1] ."<br>";
}
for ($a=0; $a<=sizeof($this->radio); $a++) {
echo "Radio name=" .$this->radio[$a][0] .", val: " .$this->radio[$a][1] ."<br>";
}
for ($a=0; $a<=sizeof($this->hidden); $a++) {
echo "Radio name=" .$this->hidden[$a][0] .", val: " .$this->hidden[$a][1] ."<br>";
}
}
// Spravi elemente forme v array (arr[offset][0]--name, arr[offset][1..n]-- val)
function FieldsToArrays () {
$pre_name = "";
for ($a=0; $a<=sizeof($this->radio); $a++) {
if ($this->radio[$a][0] != $pre_name) {
$this->arr_radio[sizeof($this->arr_radio)][0] = $this->radio[$a][0];
$pre_name = $this->radio[$a][0];
}
$this->arr_radio[sizeof($this->arr_radio)-1][sizeof($this->arr_radio[sizeof($this->arr_radio)-1])] = $this->radio[$a][1];
}
for ($a=0; $a<=sizeof($this->hidden); $a++) {
if ($this->hidden[$a][0] != $pre_name) {
$this->arr_hidden[sizeof($this->arr_hidden)][0] = $this->hidden[$a][0];
$pre_name = $this->hidden[$a][0];
}
$this->arr_hidden[sizeof($this->arr_hidden)-1][sizeof($this->arr_hidden[sizeof($this->arr_hidden)-1])] = $this->hidden[$a][1];
}
for ($a=0; $a<=sizeof($this->checkboxes); $a++) {
if ($this->checkboxes[$a][0] != $pre_name) {
$this->arr_checkbox[sizeof($this->arr_checkbox)][0] = $this->checkboxes[$a][0];
$pre_name = $this->checkboxes[$a][0];
}
$this->arr_checkbox[sizeof($this->arr_checkbox)-1][sizeof($this->arr_checkbox[sizeof($this->arr_checkbox)-1])] = $this->checkboxes[$a][1];
}
}
// nakljucno izpolni in submita formo.
function RandomFill () {
$radios = "";
$checks = "";
$data = "";
// Najprej random radio
for ($a = 0; $a < sizeof($this->arr_radio); $a++) {
$radios .= "&" .$this->arr_radio[$a][0] ."=" .$this->arr_radio[$a][rand(1, sizeof($this->arr_radio[$a])-1)];
$data[$this->arr_radio[$a][0]] = $this->arr_radio[$a][rand(1, sizeof($this->arr_radio[$a])-1)];
echo "Na ossfet " .$this->arr_radio[$a][0] ." nastavljam vrednost " .$this->arr_radio[$a][rand(1, sizeof($this->arr_radio[$a])-1)];
}
// hidden ni random
for ($a = 0; $a < sizeof($this->arr_hidden); $a++) {
$hidden .= "&" .$this->arr_hidden[$a][0] ."=" .$this->arr_hidden[$a][sizeof($this->arr_hidden[$a])-1];
$data[$this->arr_hidden[$a][0]] = $this->arr_hidden[$a][sizeof($this->arr_hidden[$a])-1];
}
// random checkbox
for ($a = 0; $a < sizeof($this->arr_checkbox); $a++) {
// Obkljukamo nakljucno kljukic
$kljukic = rand (1, sizeof($this->arr_checkbox[$a]));
for ($b = 0; $b < $kljukic; $b++) {
$checks .= "&" .$this->arr_checkbox[$a][0] ."=" .$this->arr_checkbox[$a][rand(1, sizeof($this->arr_checkbox[$a])-1)];
$data[$this->arr_checkbox[$a][0]] = $this->arr_checkbox[$a][rand(1, sizeof($this->arr_checkbox[$a])-1)];
}
}
echo "data[vrednost_2901] je " .$data['vrednost_2901'];
echo "<br><br>PRVIC JE DATA ";
echo var_dump($data);
echo "<br><br>";
$content = str_replace ("&=", "", str_replace ("&=", "", substr ($radios . $checks .$hidden, 1)));
echo "Izpolnil: $content";
if (strpos ($this->action, "http://")===false) {
if (strpos ($this->action, "/")===false) {
$url = substr ($this->url, 0, strrpos($this->url, "/")) ."/" .$this->action;
}
elseif (strpos ($this->action, "/") > 1) {
$url = substr ($this->url, 0, strrpos($this->url, "/")) .$this->action;
}
else {
$url = substr ($this->url, 0, strpos($this->url, "/")) .$this->action;
}
}
echo "<br>DRUGIC JE DATA: ";
echo var_dump($data);
echo "<hr>";
$url = 'dest.php';
if (strtolower ($this->method) == "post") {
$this->do_post_request ($url, $data);
}
else {
// ponavljaj skripto.
}
}
function do_post_request ($url, $data) {
echo '<hr><hr>';
echo "VSEBINA STRANI KI JO POSILJAM JE " .$this->content ."<br>";
echo "POSTATI HOCEM PODATAKE ";
echo var_dump($data);
echo "<br>";
echo "POSTATI HOCEM NA $url";
foreach($data as $key => $param) {
if (empty($param)) {
unset($data[$key]);
}
}
// Create data
$data = http_build_query($data);
// Headers
$headers = "Content-type: application/x-www-form-urlencoded\r\n";
$headers .= "Content-Length: " . strlen($data) . "\r\n";
for ($x = 0; $x < sizeof ($this->cookies); $x++) {
if ($this->cookies[$x][0]!="") {
$kukis .= "; " .$this->cookies[$x][0] ."=" .$this->cookies[$x][1];
}
}
if (strlen ($kukis) > 1) $headers .= "Cookie: " .substr ($kukis, 2, strlen($kukis)) ."\r\n";
echo "<br>header: $headers<hr>";
// Create stream
$options = array(
'http' => array(
'method' => 'POST',
'header' => $headers,
'content' => $data
)
);
echo "tu poslal naprej ---_" ;
echo var_dump($data);
echo '_-----';
$context = stream_context_create($options);
// Get the result
$result = file_get_contents($url, false, $context);
echo "<br><br><br>KAR DOBIM NAZAJ: $result";
/* // Lahko bi malo izpopolnil!!!
if (strpos ($result, '<form') !== false) {
echo "Grem na naslednjo stran...";
$this->ParseNextPage ($result);
}
*/ }
function ParseNextPage ($content) {
if (strpos ($content, "<body") !== false) {
$content = substr ($content, strpos ($content, "<body"), strpos ($content, "</body>"));
}
$this->inputs = "";
$this->selects= "";
$this->hidden= "";
$this->checkboxes= "";
$this->radio= "";
$this->textbox= "";
// Kam kaze forma
$this->method= "";
$this->action= "";
// urejeno
$this->arr_checkbox= "";
$this->arr_radio= "";
$this->arr_hidden= "";
$this->content = $content;
echo "Sem na parsenextpage, grem klicat getfields";
// kukijev na naslednjih straneh ne preverjam vec.
$this->GetTarget();
$this->GetFields();
$this->FieldsToArrays();
$this->RandomFill();
}
}
?>
|