-
Notifications
You must be signed in to change notification settings - Fork 6
/
he.php
356 lines (289 loc) · 11.2 KB
/
he.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
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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
<?php
require_once "getips.php";
require_once 'commands.php';
require_once 'setting.php';
$settings = loadSettings();
saveSettings($settings);
$settings = he($settings);
//$settings->username = "";
///$password = "";
//$directory = "/HECT/";
//$settings->repeat = 50;
//$settings->debug = true;
//$settings->timezone = new DateTimeZone('GB');
//he($settings->username,$password,$directory,$settings->repeat, $settings->debug,$settings->timezone);
/*
Main function
*/
function he($settings) {
date_default_timezone_set($settings->timezone);
if ($settings->debug)
print("Current Dir: " . $settings->directory . "\n");
//making dir is doesn't exist
if (!file_exists($settings->directory)) {
if (!mkdir($settings->directory, 0700, TRUE))
{
print "Failed to create place to store data";
exit(1);
}
}
if ($settings->debug) {
$time = new DateTime("now");
print "Start:" . $time->format(DATE_RFC822) . "\n";
}
getIPs($settings);
$address = getAddress($settings);
//
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://ipv6.he.net/certification/login.php');
curl_setopt($ch, CURLOPT_POSTFIELDS, 'f_user=' . urlencode($settings->username) . '&f_pass=' . urlencode(md5($settings->password))) . '&Login=Login';
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_COOKIEJAR, "");
curl_setopt($ch, CURLOPT_COOKIEFILE, $settings->directory . "my_cookies.txt");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
// $fh = fopen($settings->directory . "login.txt", 'w');
// fwrite($fh, curl_exec($ch));
// fclose($fh);
if (preg_match("/Either your username or your password is invalid./i", curl_exec($ch),$match))
{
print "Login failed\n";
exit(1);
}
$tests = $settings->tests;
foreach ($tests as $test) {
echo $test['name'] . "\n";
curl_setopt($ch, CURLOPT_URL, $test['url']);
curl_setopt($ch, CURLOPT_POST, 0);
$pageHtml = curl_exec($ch);
preg_match("{\<div id='vote_record'\>(.*)\</div\>}", $pageHtml, $match);
$nextq = FALSE;
if (count($match) > 0) {
if (preg_match("/Sorry, you've already submitted an IPv6/i", $match[1])) {
if ($settings->debug)
echo "Done\n";
} else {
if ($settings->debug) {
echo "Something else\n";
print_r($match);
}
}
} else {
if ($settings->debug)
echo "Not Done\n";
$nextq = performRepeat($test, $ch, $address, $settings) || $nextq;
}
}
// Check if any test has been done. If so go to next address
if ($nextq) {
nextnumber($settings);
}
if ($settings->debug) {
$time = new DateTime("now");
print "Done:" . $time->format(DATE_RFC822) . "\n";
}
}
function performTest($test, $settings, $ch, $address) {
$cmd = str_replace("{ip}", $address['ip'], $test['command']);
$cmd = str_replace("{host}", $address['host'], $cmd);
if ($settings->debug)
{
echo "Performing Test..\n";
echo $cmd."\n";
}
if ($settings->debug)
$cmd . "\n";
$command = shell_exec($cmd);
curl_setopt($ch, CURLOPT_URL, $test['url']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, true);
$data = array(
$test['textareaname'] => $command,
'submit' => 'Submit',
);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$pageHtml = curl_exec($ch);
$fh = fopen($settings->directory . $test['htmloutput'], 'w');
fwrite($fh, $pageHtml);
fclose($fh);
$fh = fopen($settings->directory . $test['rawoutput'], 'w');
fwrite($fh, $command);
fclose($fh);
return $pageHtml;
}
/*
Not used
Get the your scores of $settings->username and put it in to csv file called source.cvs
*/
function checkscore($settings) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://ipv6.he.net/certification/scoresheet.php?pass_name=' . $settings->username);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
$pageHtml = curl_exec($ch);
preg_match("{\<td align=right\>Current Score: \<font color=blue\>\<b\>(.*)\</b>}", $pageHtml, $match);
$total = str_replace(",", "", $match[1]);
preg_match("{\<b\>Daily Traceroute\</b\> ; Score: (.*)/ 100\</div\>}", $pageHtml, $match);
$traceroot = $match[1];
preg_match("{\<b\>Daily Dig \(AAAA\)\</b\> ; Score: (.*)/ 100\</div\>}", $pageHtml, $match);
$digaaaa = $match[1];
preg_match("{\<b\>Daily Ping6\</b\> ; Score: (.*)/ 100\</div\>}", $pageHtml, $match);
$ping = $match[1];
preg_match("{\<b\>Daily Whois\</b\> ; Score: (.*)/ 100\</div\>}", $pageHtml, $match);
$whois = $match[1];
preg_match("{\<b\>Daily Dig \(PTR\)\</b\> ; Score: (.*)/ 100\</div\>}", $pageHtml, $match);
$digptr = $match[1];
echo "Total Score: " . $total . "</td><td> Tracert: " . $traceroot . " Dig (AAAA): " . $digaaaa . " Dig (PTR): " . $digptr . " Daily Whois: " . $whois . " Ping6: " . $ping . "\n";
$sorcehandle = fopen($settings->directory . "score.csv", "a");
$date = date('c');
fwrite($sorcehandle, $date . ',' . $total . ',' . $traceroot . ',' . $ping . ',' . $whois . ',' . $digptr . ',' . $digaaaa . "\n");
fclose($sorcehandle);
}
/*
Get and address from ip
*/
function getAddress($settings) {
$iphandle = fopen($settings->directory . "ip.csv", "r");
for ($i = 0; $i <= $settings->number; $i++) {
$ipdata = fgetcsv($iphandle);
}
fclose($iphandle);
if (count($ipdata) < 2) {
print "Ran Out\n";
getIPs($settings);
zeronumber($settings);
$number = 0;
$iphandle = fopen($settings->directory . "ip.csv", "r");
$ipdata = fgetcsv($iphandle);
fclose($iphandle);
if (count($ipdata) != 2) {
print "No IP Addresses to use\n";
saveSetting($settings);
exit(1);
}
}
$host = escapeshellcmd(base64_decode($ipdata[0]));
$ip = escapeshellcmd(base64_decode($ipdata[1]));
$address = array('host' => escapeshellcmd(base64_decode($ipdata[0])), 'ip' => escapeshellcmd(base64_decode($ipdata[1])));
if ($settings->debug)
echo "IP:" . $address['ip'] . " Host:" . $address['host'] . "\n";
return $address;
}
//function getNumber($settings)
//{
// touch($settings->directory."number.txt");
// $numberhandle = fopen($settings->directory."number.txt","r");
// $number = fgets($numberhandle);
// if (!is_numeric($number))
// {
// $number = 0;
// }
// fclose($numberhandle);
// if($settings->debug) print "Number:".$number."\n";
// return $number;
//}
function zeronumber($settings) {
$settings->number = 0;
saveSettings($settings);
// return $settings; //Not needed as PHP is pass by ref.
// $fh = fopen($settings->directory."number.txt","w");
// fclose($fh);
}
function nextnumber($settings) {
//$number = getNumber($settings->directory,$settings->debug);
$settings->number = $settings->number + 1;
saveSettings($settings);
return $settings;
//$nextnum = fopen($settings->directory."number.txt","w");
//fwrite($nextnum,$number);
//fclose($nextnum);
//if($settings->debug) print "Next number:".$number." Written bytes:".$number."\n";
//getNumber($settings->directory,$settings->debug);
}
function performRepeat($test, $ch, $address, $settings) {
for ($i = 0; $i < $settings->repeat; $i++) {
print "Performing again : " . $i . "\n";
$pageHtml = performTest($test, $settings, $ch, $address);
if (preg_match("/Result\: Pass/i", $pageHtml, $match)) {
if ($settings->debug) print "Pass\n";
recordSuccess($test, "Pass", $address, $settings);
$time = new DateTime("now");
$date = $time->format("c");
$test['lastdone'] = $date;
saveSettings($settings);
return TRUE;
break;
} else {
// preg_match("{\<div id='vote_record'\>(.*)\</div\>}",$pageHtml,$match);
// echo $match[1];
$failinfo = proccessFails($pageHtml, $settings);
recordSuccess($test, "F-" . $failinfo, $address, $settings);
nextnumber($settings);
$address = getAddress($settings);
}
}
}
function recordSuccess($test, $success, $address, $settings) {
$time = new DateTime("now");
$date = $time->format("c");
$fh = fopen($settings->directory.$settings->passresults, 'a');
fwrite($fh, $date . ',' . $test['name'] . ',' . $success . ',' . $address['host'] . ',' . $address['ip'] . "\n");
fclose($fh);
}
function proccessFails($pageHtml, $settings) {
if (preg_match("/Sorry, you've already submitted a whois query that has the same netblock/i", $pageHtml, $match)) {
if ($settings->debug)
print "Fail - whois same netblock\n";
return "same netblock";
}
elseif (preg_match("/Sorry, this page is for dig forward submission only/i", $pageHtml, $match)) {
if ($settings->debug)
print "Fail - forward dig\n";
return "forward dig";
} elseif (preg_match("/Sorry, you've already submitted a traceroute/i", $pageHtml, $match)) {
if ($settings->debug)
print "Fail - same traceroute\n";
return "same address";
} elseif (preg_match("/Sorry, you've already submitted a ping output to the same destination/i", $pageHtml, $match)) {
if ($settings->debug)
print "Fail - same ping\n";
return "same address";
} elseif (preg_match("/Sorry, you've already submitted a dig query to the same destination/i", $pageHtml, $match)) {
if ($settings->debug)
print "Fail - same address dig\n";
return "same address";
}
elseif (preg_match("/like you submitted an invalid/i", $pageHtml, $match)) {
if ($settings->debug)
print "Fail - invalid submission\n";
return "invalid submission";
} elseif (preg_match("/Result\: Fail/i", $pageHtml, $match)) {
if ($settings->debug)
print "Fail - error in submission\n";
$fh = fopen($settings->directory . "fail.html", 'a');
fwrite($fh, $pageHtml);
fclose($fh);
return "error in submission";
} else {
if ($settings->debug)
print "Fail\n";
if ($settings->debug)
print "Fail - unknown reason\n";
$fh = fopen($settings->directory . "fail.html", 'w');
fwrite($fh, $pageHtml);
fclose($fh);
preg_match("{\<div id='vote_record'\>(.*)\</div\>}", $pageHtml, $match);
if (count($match) > 2) {
if ($settings->debug)
echo $match[1];
return "M-" . $match[1];
}
else {
return "unknown error";
}
}
}
?>