forked from NewEraCracker/php-work
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathipv6_hack.php
More file actions
119 lines (111 loc) · 2.57 KB
/
Copy pathipv6_hack.php
File metadata and controls
119 lines (111 loc) · 2.57 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
<?php
/* IPv6 to IPv4, a dirty hack
*
* This will create fake IPv4 for IPv6 users based on the 64 first bits of their IP.
* As most currently existing IPv6 providers are assigning /64 classes to their customers,
* banning the generated IPv4 effectively bans the whole IPv6.
*
* Also this script generates a 32bits IPv4 from 64bits of IPv6 using XOR.
* While this means people using IPv6 might share the same generated IPv4 (quite unlikely),
* it is usually impossible for someone to obtain a different generated IPv4 without access
* to more than a /64 (I believe only system administrators have this kind of thing).
*
* Author: NewEraCracker
* License: Public Domain
*/
//@link: http://php.net/manual/en/function.inet-pton.php
if ( !function_exists('inet_pton'))
{
function inet_pton($ip)
{
if(strpos($ip, '.') !== FALSE)
{
// Pack ipv4
$ip = trim($ip,':f');
$ip = pack('N',ip2long($ip));
}
elseif(strpos($ip, ':') !== FALSE)
{
// Expand ipv6
$_count = count(explode(':', $ip));
while($_count<=8)
{
$ip = str_replace('::',':0::',$ip);
$_count++;
}
unset($_count);
$ip = str_replace('::',':',$ip);
// Pack ipv6
$ip = explode(':', $ip);
$res = str_pad('', (4*(8-count($ip))), '0000', STR_PAD_LEFT);
foreach ($ip as $seg)
{
$res .= str_pad($seg, 4, '0', STR_PAD_LEFT);
}
$ip = pack('H'.strlen($res), $res);
}
else
{
return false;
}
if(strlen($ip)==4 || strlen($ip)==16)
{
return $ip;
}
else
{
return false;
}
}
}
//@link: http://php.net/manual/en/function.inet-ntop.php
if ( !function_exists('inet_ntop'))
{
function inet_ntop($ip){
if(strlen($ip)==4)
{
// Unpack ipv4
list(,$ip)=unpack('N',$ip);
$ip=long2ip($ip);
}
elseif(strlen($ip)==16)
{
// Unpack ipv6
$ip=bin2hex($ip);
$ip=substr(chunk_split($ip,4,':'),0,-1);
$ip=explode(':',$ip);
$res='';
foreach($ip as $seg)
{
while($seg{0}=='0') $seg=substr($seg,1);
if($seg!='')
{
$res.=($res==''?'':':').$seg;
}
else
{
if (strpos($res,'::')===false) {
if (substr($res,-1)==':') continue;
$res.=':';
continue;
}
$res.=($res==''?'':':').'0';
}
}
$ip=$res;
}
else
{
return false;
}
return $ip;
}
}
//@link: http://blog.magicaltux.net/2010/02/18/invision-power-board-and-ipv6-a-dirty-hack/
$encoded_ip = inet_pton($_SERVER['REMOTE_ADDR']);
if (strlen($encoded_ip) == 16) {
$ipv4 = '';
for($i = 0; $i < 8; $i += 2) $ipv4 .= chr(ord($encoded_ip[$i]) ^ ord($encoded_ip[$i+1]));
$_SERVER['REMOTE_ADDR'] = inet_ntop($ipv4);
}
?>