Aerosol Posted January 13, 2015 Report Posted January 13, 2015 A simple script to search on Shodan with the following options:Simple tool to search in Shodan[+] Search Results for IP[+] Search Results for quantity[+] Normal Search[+] List the saved query[+] Search the saved query that were already searched[+] Add popular tags[+] List all services shodan located[+] DNS Lookup[+] Reverse DNS Lookup[+] Return your IP[+] It gives you information about your APIThey must have an API Key yours to use API Shodan. DownloadGitHub Quote
mojito.mojito Posted January 13, 2015 Report Posted January 13, 2015 <?phpfunction curl_connect($url){ $headers[] = "Accept: text/html"; $headers[] = "Connection: Keep-Alive"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; rv:2.2) Gecko/20110201"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //che poi includo tutto nella var $exec curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); $exec = curl_exec($ch); if($exec) curl_close($ch); if(preg_match("/200 ok/i", $exec)) return true; else return false;}function login_shodan($user, $pass){ $headers[] = "Accept: text/html"; $headers[] = "Connection: Keep-Alive"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://account.shodan.io/login"); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_HEADER, true); //curl_setopt($ch, CURLOPT_REFERRER, ""); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; rv:2.2) Gecko/20110201"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //che poi includo tutto nella var $exec curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS,"username={$user}&password={$pass}&continue=https://www.shodan.io/"); curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt"); curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt"); $exec = curl_exec($ch); if($exec) curl_close($ch); if(preg_match("/200 ok/i", $exec)) return true; else return false;}function shodan_search($val, $pag){ $headers[] = "Accept: text/html"; $headers[] = "Connection: Keep-Alive"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://www.shodan.io/search?query=". urlencode("port:25") . "&page=" . intval($pag)); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; rv:2.2) Gecko/20110201"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); //che poi includo tutto nella var $exec curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt"); curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt"); $exec = curl_exec($ch); if($exec) curl_close($ch); //print $exec; //<div class="results-count">Showing results 1 - 10 of 18,046,644</div> //<div class="ip"><a href="/host/12.155.204.131">12.155.204.131</a> //<pre>220 MCG-EX01.McGeeGroup.local Microsoft ESMTP MAIL Service ready at Tue, 11 Nov 2014 02:42:44 -0500</pre> //<div class="search-result-summary"><span>204.15.253.98.icertified.net</span><br/><a href="/search?query=port%3A25+org%3A%22Certified+Hosting%22" class="os">Certified Hosting</a> //<div class="search-result-summary"><a href="/search?query=port%3A25+org%3A%22S.H.A.+Trans+SRL%22" class="os">S.H.A. Trans SRL</a> if(preg_match_all("/<div class=\"results-count\"\>Showing results (.*)<\/div\\>/i", $exec, $matches)) //print_r($matches); print "Risultati: " . $matches[1][0] . "\n"; if(preg_match_all("/<div class=\"ip\"><a href=\"(.*)\">(.*)<\/a>\n<\/div>\n<div class=\"search-result-summary\"><span>(.*)<\/span><br\/>/i", $exec, $matches)) { ///preg_match_all("/<div class=\"search-result-summary\"><span>(.*)<\/span><br\/>/i", $exec, $host); print_r($matches); $c = 0; preg_match_all("/<div class=\"ip\"><a href=\"(.*)\">(.*)<\/a>\n<\/div>\n<div class=\"search-result-summary\"><a href/i", $exec, $without); print_r($without); //print_r($matches); echo "Echo i 10 risultati della pagina {$pag}:\n"; echo "Scrivo su shodan-page-{$pag}\n"; //$fp = fopen("shodan-page-{$pag}", "a+"); //fwrite($fp, "Page {$pag}\n"); preg_match_all("/([^<]*)<\/pre>/i", $exec, $match_banners); foreach($without[2] as $ip) { $c++; print $ip . " - " . $match_banners[1] . "\n"; //fwrite($fp, $without[2][$i] . " - " . $match_banners[1][$i] . "\n"); } //fclose($fp); echo "Scritti {$c} Dati\n"; //print_r($match_banners); } unlink("cookie.txt");}if(curl_connect("https://www.shodan.io")){ echo "Connesso a https://www.shodan.io\n"; echo "Login in corso...\n"; if(login_shodan("USER", "PASS")) { echo "Loggato con user USER\n"; echo "Ora cerco " . $argv[1] . "\n"; shodan_search($argv[1], $argv[2]); } else{ echo "Errore Log In\n"; }} else { echo "Errore di connessione alla homepage di shodan.io";}?>Mie imi place mai mult sa stau din terminal decat aplicatii Desktop, am facut asta pentru mine ceva timp in urma ca eu stau aproape non stop pe shodan si scanhub. API ce pun ei la dispozitie nu imi place cum lucreaza si asa ca miam facut eu scriptul asta pentru cautare si organizare a rezultatelor, poate ajuta pe cineva. :DDD Quote