-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxyCheck.php
178 lines (148 loc) · 4.14 KB
/
proxyCheck.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
<?php
/**
* @version 1.0
* @package SNB proxy
* @copyright © 2008 security-net.biz
* @author Ivan Markovic <[email protected]>
*/
/**
* Proxy check functions.
* Collection of some functions that can help proxy detection
* Contains common methods needed as:
* headers check, open ports check, cookie trap.
*
* Sample usage:
* $myProxy = new proxyCheck();
* $myProxy->serverVar = $_SERVER;
* $headers = $myProxy->checkHeder();
* $ports = $myProxy->checkPort();
*/
class proxyCheck {
/**
* Server vars ($_SERVER)
* @access public
* @var array
*/
var $serverVar = array();
/**
* Timeout for fsockopen
* @access public
* @var int
*/
var $timeout = 5;
/**
* Common ports for testing
* @access public
* @var array
*/
var $ports = array(3128,8080,80);
/**
* Cookie name
* @access public
* @var string
*/
var $cookieName = "proxyCheck";
/**
* Finded headers
* @access private
* @var array
*/
private $proxyHeder = array();
/**
* Finded open ports
* @access private
* @var array
*/
private $portsData = array();
/**
* URL of proxy URL check
* @access public
* @var string
*/
var $proxyUrl = '';
/**
* proxyCheck constructor
* @access public
*/
function proxyCheck() {
// TODO
}
/**
* Check usual proxy headers
* @return array data
* @access public
*/
function checkHeder() {
if(isset($this->serverVar['HTTP_X_FORWARDED_FOR'])) {
$this->proxyHeder['HTTP_X_FORWARDED_FOR'] = $this->serverVar['HTTP_X_FORWARDED_FOR'];
}
if(isset($this->serverVar['HTTP_X_FORWARDED'])) {
$this->proxyHeder['HTTP_X_FORWARDED'] = $this->serverVar['HTTP_X_FORWARDED'];
}
if(isset($this->serverVar['HTTP_FORWARDED'])) {
$this->proxyHeder['HTTP_FORWARDED'] = $this->serverVar['HTTP_FORWARDED'];
}
if(isset($this->serverVar['HTTP_PROXY_AGENT'])) {
$this->proxyHeder['HTTP_PROXY_AGENT'] = $this->serverVar['HTTP_PROXY_AGENT'];
}
if(isset($this->serverVar['HTTP_VIA'])) {
$this->proxyHeder['HTTP_VIA'] = $this->serverVar['HTTP_VIA'];
}
if(isset($this->serverVar['HTTP_PROXY_CONNECTION'])) {
$this->proxyHeder['HTTP_PROXY_CONNECTION'] = $this->serverVar['HTTP_PROXY_CONNECTION'];
}
if(isset($this->serverVar['HTTP_CLIENT_IP'])) {
$this->proxyHeder['HTTP_CLIENT_IP'] = $this->serverVar['HTTP_CLIENT_IP'];
}
return $this->proxyHeder;
}
/**
* Check common ports
* @param string ip
* @return array data
* @access public
*/
function checkPort($ip = '') {
if(empty($ip)) $ip = $this->serverVar['REMOTE_ADDR'];
foreach($this->ports as $port) {
$fp = @fsockopen($ip,$port,$errno,$errstr,$this->timeout);
if(!empty($fp)) $this->portsData[$port] == $port;
@fclose($fp);
}
return $this->portsData;
}
/**
* Cookie trap
* @return true on finded proxy
* @access public
*/
function checkCookie() {
if(isset($_COOKIE[$this->cookieName])) {
if($this->serverVar['REMOTE_ADDR'] != $_COOKIE[$this->cookieName]) return true;
} else {
@setcookie($this->cookieName, $this->serverVar['REMOTE_ADDR']);
}
}
/**
* Connect back using CURL
* @return data from proxyUrl
* @access public
*/
function connectBack() {
if(!empty($this->proxyUrl)) {
$buffer = array();
foreach($this->ports as $key => $val) {
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, $this->proxyUrl);
curl_setopt($curl_handle, CURLOPT_PROXY, $this->serverVar['REMOTE_ADDR'].":".$val);
curl_setopt($curl_handle, CURLOPT_USERAGENT, $this->serverVar['HTTP_USER_AGENT']);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_HEADER, 0);
$buffer[$val] = curl_exec($curl_handle);
curl_close($curl_handle);
return $buffer;
}
} else return 'Empty proxyUrl.';
}
}
?>