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
| <?php isset($argv[1]) ? $file = trim($argv[1]) : exit(); $str = @file_get_contents($file);
$sql = find_pass($str); if (!empty($sql)) { echo '---------------------------------------------' . PHP_EOL; echo $file . PHP_EOL . PHP_EOL; foreach ($sql as $s) { echo trim($s) . PHP_EOL; } echo '---------------------------------------------' . PHP_EOL . PHP_EOL; }
function find_pass($str) { if (preg_match_all('#\$\w*(?:host(?:name)?|server|user(?:name)?|pass(?:word)?)\w*\s*=\s*(?:\'|\")[[:alnum:][:punct:]]+(?:\'|\")#ism', $str, $sqlstr)) { if (count($sqlstr[0]) > 1) { return array_unique($sqlstr[0]); } }
if (preg_match_all('#mysqli?(?:_p?connect)?\((?:\'|\")([[:alnum:][:punct:]]*)(?:\'|\")\s*,\s*(?:\'|\")([[:alnum:][:punct:]]*)(?:\'|\")\s*,\s*(?:\'|\")([[:alnum:][:punct:]]*)(?:\'|\")#im', $str, $sqlstr)) { return array_unique($sqlstr[0]); } if (preg_match_all('#\$[\w]+->db(?:Host|Name|User|Pass)\s+?=\s*\'(.*?)\';#im', $str, $sqlstr)) { return array_unique($sqlstr[0]); } if (preg_match_all('#^((?!\*).)*(mysqli?:\/\/(?!username:password)[[:alnum:][:punct:]]+@[[:alnum:][:punct:]]*\/[[:alnum:][:punct:]]*)(?:\'|\")#im', $str, $sqlstr)) { return array_unique($sqlstr[0]); } if (preg_match_all('#^((?!\#|\/\/|\*).)*define\s*\((?:\'|\")(?:\w*SERVER\w*|\w*USER\w*|\w*PASS(?:WORD)?\w*|\w*HOST\w*)(?:\'|\"),\s*(?:\'|\")(.*)(?:\'|\")\)#im', $str, $sqlstr)) { return array_unique($sqlstr[0]); } if (preg_match_all('#\[database\]\s*driver\s*?=\s*?.*\s*host\s*?=\s*?(?:\'|\")(.*)(?:\'|\")\s*?username\s*?=\s*?(.*)\s*?password\s*?=\s*?(.*)#im', $str, $sqlstr)) { return array_unique($sqlstr[0]); }
if (preg_match_all('#^((?!\*).)*(?:\'|\")[[:alnum:][:punct:]]*(?:server|user|login|pass|host)[[:alnum:][:punct:]]*(?:\'|\")\s=>\s*[[:alnum:][:punct:]]+(?:\'|\")#im', $str, $sqlstr)) {
if (count($sqlstr[0]) > 1) { return array_unique($sqlstr[0]); } } if (preg_match_all('#\$[\w\[\]\'\"\s]*(?:host|server|user|name|pass|password|dbpw|hn|un|pw)\w*[\w\[\]\'\"\s]*=\s*(?:\'|\")[[:alnum:][:punct:]]+(?:\'|\")#im', $str, $sqlstr)) {
if (count($sqlstr[0]) > 1) { return array_unique($sqlstr[0]); } }
if (preg_match_all('#new\sPDO\((?:\'|\")([\w[:punct:]]+)(?:\'|\")\s*,\s*(?:\'|\")([\w[:punct:]]+)\s*,\s*(?:\'|\")([\w[:punct:]]+)(?:\'|\")\)#im', $str, $sqlstr)) { return $sqlstr[0]; }
if (preg_match_all('#connect\(\'([[:alnum:][:punct:]]+)\'\s*,\s*\'([[:alnum:][:punct:]]+)\'\s*,\s*\'([[:alnum:][:punct:]]+)\'\s*,\s*\'[[:alnum:][:punct:]]+\'\)#im', $str, $sqlstr)) { return $sqlstr[0]; }
if (preg_match_all('#db_(?:host|login|password|user|username):\s*[[:alnum:][:punct:]]+#im', $str, $sqlstr)) { return $sqlstr[0]; } } ?>
|