Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Authentication support and POST request body parsing #6

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ And in the case of faliure you will get the reason why it failed (curl_error dir
}
```

### Checking Proxies with Authentication
To check a proxy that requires authentication you need to pass the login and password to the request.
This works on both SOCKS and HTTP proxies. Example:
```
checker.php?ip=137.116.76.252&port=3128&timeout=20&login=foo&password=bar
```

#### Checking SOCKS Proxies
If you are using version 1.2 you will also be able to check SOCKS4/5 proxies. In version 1.2 the proxy is checked for SOCKS by default after it has partially failed a check for HTTP (Connection reset error), however knowing for sure whether it is a SOCKS proxy you are about to check or no can minimise the time it will take to process.

Expand All @@ -68,6 +75,18 @@ To check a list of proxies contained in file `abc.txt` with a timeout of 20 seco
localhost/checker.php?file=abc.txt&timeout=20
```

#### Update: checking multiple proxies with a POST request
To check multiple proxies with a POST request, you need to pass the following request body:]
```json
{
"timeout" : 20,
"proxy_type" : "http(s)",
"authentication" : true,
"proxies" : ["ip:port:login:password", "ip:port:anotherproxy:password"]
}
```
This supports authentication and SOCKS proxies, based on the checkSingleProxy function.

This uses multi-threading and hence instead of taking 200 seconds for 10 proxies
(20 secs timeout * 10 proxies), it will take roughly 30 seconds to finish.

Expand Down
130 changes: 81 additions & 49 deletions checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,65 +22,91 @@
//To determine whether we are being supplied an ip-port or a filename, we'll take a look at the get params


//Step 1 - Check whether the user specified a timeout
if(!isset($_GET['timeout']))
{
die("You must specify a timeout in seconds in your request (checker.php?...&timeout=20)");
}

//Step 2 - Little extras go here
//Default is 'false' not to confuse the IF-logic later on
$socksOnly = false;
if(isset($_GET['proxy_type']))
{
if($_GET['proxy_type'] == "socks")
{
$socksOnly = true;
$proxy_type = "socks";
}
else
{
$proxy_type = "http(s)";
}
}
else
{
$proxy_type = "http(s)";
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {

//Step 3 - Go through a loop to determine what the user wants us to do
if(isset($_GET['file']))
{
//If we can't find the file, complain
if(!file_exists($_GET['file']))
//A new way to use the scipt : simply pass a proper object in the post body

$json = file_get_contents('php://input');
$data = json_decode($json);
$timeout = $data->timeout;
$proxy_type = $data->proxy_type;
$authentication = $data->authentication;
$proxies = $data->proxies;

//The structure of the function stays the same.
//@vasemkin
CheckMultiProxy($proxies, $timeout, $proxy_type, $authentication);

} else {

//Step 1 - Check whether the user specified a timeout
if(!isset($_GET['timeout']))
{
die("Could not find file '" . $_GET['file'] . "'");
die("You must specify a timeout in seconds in your request (checker.php?...&timeout=20)");
}

//Convert the file to a list of proxies
$array = file($_GET['file']);
CheckMultiProxy($array, $_GET['timeout'], $proxy_type);
}
else if(isset($_GET['ip']) && isset($_GET['port']))
{
CheckSingleProxy($_GET['ip'], $_GET['port'], $_GET['timeout'], true, $socksOnly, $proxy_type);
}
else
{
die("<h2>Could not find the required GET parameters.</h2><br /><b>To check a proxy use:</b><br /><i>checker.php?ip=...&port=...</i><br /><b>To go through a list of proxies (IP:PORT Format) use:</b><br /><i>checker.php?file=...</i>");
}
//Step 2 - Little extras go here
//Default is 'false' not to confuse the IF-logic later on
$socksOnly = false;
if(isset($_GET['proxy_type']))
{
if($_GET['proxy_type'] == "socks")
{
$socksOnly = true;
$proxy_type = "socks";
}
else
{
$proxy_type = "http(s)";
}
}
else
{
$proxy_type = "http(s)";
}

//Step 3 - Go through a loop to determine what the user wants us to do
if(isset($_GET['file']))
{
//If we can't find the file, complain
if(!file_exists($_GET['file']))
{
die("Could not find file '" . $_GET['file'] . "'");
}

//Convert the file to a list of proxies
$array = file($_GET['file']);
CheckMultiProxy($array, $_GET['timeout'], $proxy_type, $_GET['authentication']);
}
else if(isset($_GET['ip']) && isset($_GET['port']))
{
CheckSingleProxy($_GET['ip'], $_GET['port'], $_GET['timeout'], $_GET['login'], $_GET['password'], true, $socksOnly, $proxy_type);
}
else
{
die("<h2>Could not find the required GET parameters.</h2><br /><b>To check a proxy use:</b><br /><i>checker.php?ip=...&port=...</i><br /><b>To go through a list of proxies (IP:PORT Format) use:</b><br /><i>checker.php?file=...</i>");
}


}


function CheckMultiProxy($proxies, $timeout, $proxy_type)
function CheckMultiProxy($proxies, $timeout, $proxy_type, $authentication=false)
{
$data = array();
foreach($proxies as $proxy)
{
$parts = explode(':', trim($proxy));
$url = strtok(curPageURL(),'?');
$data[] = $url . '?ip=' . $parts[0] . "&port=" . $parts[1] . "&timeout=" . $timeout . "&proxy_type=" . $proxy_type;

//Authentication is optional, and an expantion to the main logic
if ($authentication) {
$data[] = $url . '?ip=' . $parts[0] . "&port=" . $parts[1] . "&login=" . $parts[2] . "&password=" . $parts[3] . "&timeout=" . $timeout . "&proxy_type=" . $proxy_type;
} else{
$data[] = $url . '?ip=' . $parts[0] . "&port=" . $parts[1] . "&timeout=" . $timeout . "&proxy_type=" . $proxy_type;
}
}

$results = multiRequest($data);
$holder = array();
foreach($results as $result)
Expand All @@ -94,11 +120,10 @@ function CheckMultiProxy($proxies, $timeout, $proxy_type)



function CheckSingleProxy($ip, $port, $timeout, $echoResults=true, $socksOnly=false, $proxy_type="http(s)")
function CheckSingleProxy($ip, $port, $timeout, $login=null, $password=null, $echoResults=true, $socksOnly=false, $proxy_type="http(s)")
{
$passByIPPort= $ip . ":" . $port;



// You can use virtually any website here, but in case you need to implement other proxy settings (show annonimity level)
// I'll leave you with whatismyipaddress.com, because it shows a lot of info.
$url = "http://whatismyipaddress.com/";
Expand All @@ -110,6 +135,13 @@ function CheckSingleProxy($ip, $port, $timeout, $echoResults=true, $socksOnly=fa
curl_setopt($theHeader, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($theHeader, CURLOPT_TIMEOUT, $timeout);
curl_setopt($theHeader, CURLOPT_PROXY, $passByIPPort);

//Basic proxy authentication support by @vasemkin
if($login && $password) {
$proxyAuth = $login . ":" . $password;
curl_setopt($theHeader, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
curl_setopt($theHeader, CURLOPT_PROXYUSERPWD, $proxyAuth);
}

//If only socks proxy checking is enabled, use this below.
if($socksOnly)
Expand All @@ -132,7 +164,7 @@ function CheckSingleProxy($ip, $port, $timeout, $echoResults=true, $socksOnly=fa
//Just as a safety net though, I'm still aborting if $socksOnly is true (i.e. we were initially checking for a socks-specific proxy)
if(curl_errno($theHeader) == 56 && !$socksOnly)
{
CheckSingleProxy($ip, $port, $timeout, $echoResults, true, "socks");
CheckSingleProxy($ip, $port, $timeout, $login, $password, $echoResults, true, "socks");
return;
}

Expand Down