Multi-User File Manager & Uploader with Progress Bar

September 19th, 2009 Script Posted in Java script, PHP script 1 Comment » 150 views

FileChucker is an AJAX-based web application that lets you accept file uploads on your own website. It’s simple to install (just one file), packed with features, fully configurable, nice looking, and very handy for when you want to share files with anyone. And during uploads FileChucker shows a progress bar & table, so the user knows how much time is left before the upload is complete.

FileChucker can also function as a full-fledged online file manager for your server: it can allow moving/renaming/deleting of uploaded files & folders right in the browser. Of course these features are configurable and password-protectable so you can customize FileChucker however you’d like.

To top it all off, FileChucker works in all major browsers (Moz/FF, IE, Opera, Safari), and runs on virtually any server, with no programming required! It’s a single Perl script, and most servers support Perl CGI scripts automatically; for the rare server that doesn’t, Perl can usually be easily added. If your site is more of a PHP site, don’t worry: FileChucker will run just fine alongside your PHP scripts, and you can even integrate it into your existing framework with a PHP virtual() call, if you want to!

Download now

AddThis Social Bookmark Button

PHP Firewall Script 2009

September 19th, 2009 Script Posted in PHP script No Comments » 147 views

Do you worry about your site’s security? Has your site ever been hacked? Worry no more! FireWall Script is a PHP-based configurable firewall. Once installed, you can configure what mischievous things you want to be on the lookout for and let FireWall Script do the rest. With the logging functionality included, you can also go back and see if anyone is attempting to sidestep your rules and stay ahead of the game. Install FireWall Script, stop worrying about your site’s security, and start worrying about your site. Our software now has premade rule packs for most popular pieces of software available.

firewall-script

  1. It supports every PHP/MySQL script in existence
    That means all forums, Blogs, Custom Scripts or anything else you can think of is covered.
  2. Only one edit required to install.
    You can install by performing just one file edit. Or if you prefer, use a .htaccess file to automatically load FWS on every page and forget file edits altogether!
  3. 100% protection guaranteed
    When properly configured, FWS can block any attacks on your site, guaranteed.

Download now

AddThis Social Bookmark Button

Php youtube grabber

September 19th, 2009 Script Posted in PHP script No Comments » 149 views

Create a file index.php and upload it on your server. Run it for testing :)).

<html>
<head>
<title>YouTube Ripper</title>
<style>
body, a, a:link, a:visited, a:hover, td {
font-family: verdana, sans-serif;
font-size: 8pt;
color: black;
}
a { font-weight: bold; }
input {
font-family: verdana, sans-serif;
font-size: 8pt;
border: black 2px solid;
padding: 2px;
}
#vid {
width: 500px;
}
</style>
</head>
<body>
<center>
<h1>Youtube ripper</h1>
<a href=’index.php’>Home</a>
<form action=”get.php” method=”get” target=”ifr”>
Video URL : <input id=”vid” type=”text” name=”vid” />
<select name=”mode”>
<option value=”1″>Just Give link</option>
<option value=”2″>Mirror and give link</option>
</select>
<input type=”submit” value=”Go!” />
</form>
<table width=”500″><tr><td>TOS: <br />Please do not use this to obtain illegal files hosted on youtube. <br />Mirrors are automatically cleared by the webmaster
frequently, so be sure to download before this happens. <br />The webmaster has the right to ban you from this server via I.P. address,
ISP, or anything else. <br />This is provided As-is, so if there are any bugs, or it doesn’t work for you, live with it, we will
try to fix any bugs so email us. <br />We are in no way affiliated with YouTube or any of their affiliates.<br />By using our
service you must agree to these terms.</td></tr></table>
<iframe width=”500″ frameborder=0 name=”ifr” id=”ifr”></iframe>
</center>
</body>
</html>

create a file get.php

<html>
<head>
<title>YouTube Ripper</title>
<style>
body, a, a:link, a:visited, a:hover {
font-family: verdana, sans-serif;
font-size: 8pt;
}
input {
font-family: verdana, sans-serif;
font-size: 8pt;
border: black 2px solid;
padding: 2px;
}
#vid {
width: 500px;
}
</style>
</head>
<body>
<?php

set_time_limit(’31337′);

// gettube youtube leecher

$regExpPattern = ‘/\”t\”\: \”([^\"\s]+)\”/i’;

$fData = file_get_contents($_GET['vid']);

preg_match($regExpPattern, $fData, $Params);

//print_r($Params);

$tID = $Params[1];

$vIDS = explode(’?v=’,$_GET['vid']);

$vID = $vIDS[1];

echo “<a href=’http://www.youtube.com/get_video?video_id=$vID&t=$tID’>Download Video</a> <br />This is a FLV file, so rename it to whatever.flv, and open with an FLV player.”;

if($_GET['mode']==2) {

$regExpPattern = ‘/content\=\”([^\"\']+)\”/i’;

preg_match($regExpPattern, $fData, $Params);

$flName = $Params[1];

$flName = preg_replace(”/[^a-zA-Z0-9s]/”, “_”, $flName);

srand((double)microtime()*1000000);
$flName = rand(0,100).$flName;

//die($flName);

$flData = file_get_contents(”http://www.youtube.com/get_video?video_id=$vID&t=$tID”);

$fp = fopen(”$flName.flv”,”w”);
fwrite($fp,$flData);
fclose($fp);

echo “<br /><a href=’$flName.flv’>Download (mirror)</a>”;

}

?>
</body>
</html>

AddThis Social Bookmark Button

Scraping websites with PHP cURL under proxy

September 18th, 2009 Script Posted in PHP script No Comments » 175 views

Scraping websites with PHP cURL is damn easy. Just do it the right way – use a proxy. Here is a simple function that does the job.

Simple PHP cURL scraper:

  1. &lt;?php function getPage($proxy, $url, $referer, $agent, $header, $timeout) {$ch = curl_init();
  2.  
  3. curl_setopt($ch, CURLOPT_URL, $url);
  4.  
  5. curl_setopt($ch, CURLOPT_HEADER, $header);
  6.  
  7. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  8.  
  9. curl_setopt($ch, CURLOPT_PROXY, $proxy);
  10.  
  11. curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
  12.  
  13. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  14.  
  15. curl_setopt($ch, CURLOPT_REFERER, $referer);
  16.  
  17. curl_setopt($ch, CURLOPT_USERAGENT, $agent);
  18.  
  19. $result[‘EXE’] = curl_exec($ch);
  20.  
  21. $result[‘INF’] = curl_getinfo($ch);
  22.  
  23. $result[‘ERR’] = curl_error($ch);
  24.  
  25.  
  26. return $result;
  27.  
  28. }
  29.  
  30. ?&gt;

PHP cURL functions used:

  • curl_init – initializes a cURL session.
  • curl_setopt – sets and option for a cURL transfer.
  • curl_exec – performs a cURL session.
  • curl_getinfo – gets information about the last transfer.
  • curl_error – returns a string containing the last error for the current session.
  • curl_close – close a cURL session.

curl_setopt options used:

  • CURLOPT_URL – the URL to scrap.
  • CURLOPT_HEADER – inlude/exclude the header?
  • CURLOPT_RETURNTRANSFER – return the transfer as a string or output it out directly? Use 1, i.e. return.
  • CURLOPT_PROXY – the HTTP proxy to tunnel request through.
  • CURLOPT_HTTPPROXYTUNNEL – tunnel through a given HTTP proxy? Use 1, i.e. tunnel.
  • CURLOPT_CONNECTTIMEOUT – it’s obvious.
  • CURLOPT_REFERER – header to be used in a HTTP request.
  • CURLOPT_USERAGENT – “User Agent:” to be used in a HTTP request.

Scraper usage:

  1. &lt; ?php
  2. $result = getPage(
  3. ‘[proxy IP]:[port]‘, // use valid proxy
  4. ‘http://www.google.com/search?q=twitter’,
  5. ‘http://www.google.com/’,
  6. ‘Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8′,1,5);if (empty($result[‘ERR’])) {
  7.  
  8. // Job’s done! Parse, save, etc.
  9.  
  10. // …
  11.  
  12. } else {
  13.  
  14. // WTF? Captcha or network problems?
  15.  
  16. // …
  17.  
  18. }
  19.  
  20. ?&gt;

Note: Activate cURL in php.ini if required.

AddThis Social Bookmark Button

Checking proxy script

September 18th, 2009 Script Posted in PHP script No Comments » 286 views

Finally, the last part of the post. Get ready for some “serious” programming.

  1. Include whatismyip.php. Don’t forget to specify URL.
  2. Copy getPage function to proxychecker.php or include it as a file.
  3. Specify a time limit.
  4. Write getProxies() function.
  5. Write deleteProxy($proxy) function.
  6. Specify badvars.php URL.
  7. Specify sleep intervals.
  8. Test and fix proxychecker.php. You don’t need to upload the script to a server. You can use your PC for testing.
  9. Deploy the script. Don’t use the same host for badvars.php and proxychecker.php.
  1. &lt;?php
  2. /*
  3. * TODO 1
  4. * Include whatismyip.php. Don’t forget to specify URL.
  5. *//*
  6. * TODO 2
  7. * Copy getPage (http://www.fromzerotoseo.com/scraping-websites-php-curl-proxy/)
  8. * here or include it as a file.
  9. */set_time_limit(/* TODO 3 specify a time limit */);function getProxies() {
  10. /*
  11. * TODO 4
  12. * Load proxies from a file or database.
  13. * Return array of [IP]:[port] proxies or NULL.
  14. */
  15. }function deleteProxy($proxy) {
  16. /*
  17. * TODO 5
  18. * Delete $proxy from file/database or
  19. * mark as ‘bad’.
  20. */
  21. }
  22.  
  23. $whatIsMyIp = new WhatIsMyIp();
  24. $myIpAddress = $whatIsMyIp-&gt;getServerIpAddress();
  25. if (empty($myIpAddress)) {
  26. echo("Can’t obtain IP address\n");
  27. exit();
  28. }
  29.  
  30. $proxies = getProxies();
  31. if (empty($proxies)) {
  32. echo("Can’t load proxies\n");
  33. exit();
  34. }
  35.  
  36. foreach ($proxies as $proxy) {
  37. $result = getPage(
  38. $proxy,
  39. /*
  40. * TODO 6
  41. * Specify badvars.php URL
  42. */,
  43. ‘http://www.google.com/’,
  44. ‘Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.8) Gecko/2009032609 Firefox/3.0.8′,
  45. 1,
  46. 5);
  47.  
  48. if (empty($result[‘ERR’])) {
  49. if (preg_match("/" . $myIpAddress . "/", $result[‘EXE’])) {
  50. deleteProxy($proxy);
  51. } else {
  52. /*
  53. * Good proxy!
  54. */
  55. }
  56. } else {
  57. echo($result[‘ERR’] . ‘\n’);
  58. deleteProxy($proxy);
  59. }
  60.  
  61. sleep(rand(/* TODO 7 [int] */, /* [int] */));
  62. }
  63. ?&gt;
AddThis Social Bookmark Button

IP address checker script

September 18th, 2009 Script Posted in PHP script No Comments » 258 views

You need to know your IP address before checking anonymity. If you have only one server it’s not a problem. Hardcode and forget. But what if you have several servers? As I said before, automation is the king.

Say thank you to people who cares about us. Grab URL(s) you like, extract IP and be happy. The WhatIsMyIp class (whatismyip.php) will help you in the beginning.

  1. &lt;?php
  2. class WhatIsMyIp {
  3. private function extractIpAddress($text) {
  4. $ip = NULL;if (preg_match(
  5. "/(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)/",
  6. $text, $matches)) {
  7. $ip = $matches[0];
  8. }
  9. return $ip;
  10. }
  11.  
  12. public function getServerIpAddress() {
  13. $file = file_get_contents(/*[URL YOU LIKE]*/);
  14. return $this-&gt;extractIpAddress($file);
  15. }
  16. }
  17. ?&gt;
AddThis Social Bookmark Button

PHP cURL proxy checker

September 18th, 2009 Script Posted in PHP script, Script reviews No Comments » 210 views

Most of the time I use server-side PHP scripts, because desktop proxy checkers don’t provide much flexibility. You don’t want to check, export and upload a list of proxies every time you need them, do you? That’s why PHP cURL is the best choice for me. Automation is the king!

So, how to check proxies with PHP? Let’s start with the proxy basics. What is an anonymous proxy? An anonymous proxy hides your IP address. Sometimes it informs a client that a proxy is being used. Sometimes it looks like a real host/user.

What should I look for when checking proxy anonymity? Make sure the real IP address is hidden. Check all variables that can expose your identity.

Warning! I’m not a security expert. Please let me know if any variable is missing from the list.

REMOTE_ADDR

REMOTE_HOST

HTTP_X_FORWARDED_FOR

HTTP_VIA

HTTP_CLIENT_IP

HTTP_PROXY_CONNECTION

FORWARDED_FOR

X_FORWARDED_FOR

X_HTTP_FORWARDED_FOR

HTTP_FORWARDED

HTTP_REFERER

Printing “bad” variables

Here is the first script (badvars.php) you need. It prints out required variables. Upload the file to a server and check if it’s working.

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=UTF-8″>
<title>I know you</title>
</head>
<body>
<p><?php echo(”REMOTE_ADDR ” . $_SERVER['REMOTE_ADDR'] . “\n”); ?></p>
<p><?php echo(”REMOTE_HOST ” . $_SERVER['REMOTE_HOST'] . “\n”); ?></p>
<p><?php echo(”HTTP_X_FORWARDED_FOR ” . $_SERVER['HTTP_X_FORWARDED_FOR'] . “\n”); ?></p>
<p><?php echo(”HTTP_VIA ” . $_SERVER['HTTP_VIA'] . “\n”); ?></p>
<p><?php echo(”HTTP_CLIENT_IP ” . $_SERVER['HTTP_CLIENT_IP'] . “\n”); ?></p>
<p><?php echo(”HTTP_PROXY_CONNECTION ” . $_SERVER['HTTP_PROXY_CONNECTION'] . “\n”); ?></p>
<p><?php echo(”FORWARDED_FOR ” . $_SERVER['FORWARDED_FOR'] . “\n”); ?></p>
<p><?php echo(”X_FORWARDED_FOR ” . $_SERVER['X_FORWARDED_FOR'] . “\n”); ?></p>
<p><?php echo(”X_HTTP_FORWARDED_FOR ” . $_SERVER['X_HTTP_FORWARDED_FOR'] . “\n”); ?></p>
<p><?php echo(”HTTP_FORWARDED ” . $_SERVER['HTTP_FORWARDED'] . “\n”); ?></p>
<br>
<p><?php echo(”HTTP_REFERER ” . $_SERVER['HTTP_REFERER'] . “\n”); ?></p>
<p><?php echo(”HTTP_USER_AGENT ” . $_SERVER['HTTP_USER_AGENT'] . “\n”); ?></p>
</body>
</html>

AddThis Social Bookmark Button

PHP anonymity checker script

September 18th, 2009 Script Posted in PHP script No Comments » 496 views

PHP class : socks 4, socks 5 and proxy lists validation (based on curl lib).

Anonymity is one of my favourites’ interests. This simple PHP 5 class validates Socks4 , Socks5 and Proxy lists.

Version: 0.2

  1. &lt;?php// PHP anonymity checker
  2. //
  3. //   (c) Involutive 2008 http://www.involutive.com
  4. //   author: Paolo Ardoino &lt; paolo@involutive.com &gt;
  5. //
  6. //      Usage:
  7. //              $anons = array(
  8. //                      array("ip" =&gt; "1.2.3.4", "port" =&gt; 8080, "type" =&gt; "socks4"),
  9. //                      array("ip" =&gt; "1.2.3.5", "port" =&gt; 8080, "type" =&gt; "socks5"),
  10. //                      array("ip" =&gt; "1.2.3.6", "port" =&gt; 8080, "type" =&gt; "proxy")
  11. //              );
  12. //
  13. //              $pa = new phpanon(array("anons" =&gt; $anons));
  14. //              $pa-&gt;check();
  15. //              $pa-&gt;done();
  16. //
  17. //              $anons is an array of triples ("ip" =&gt; ip, "port" =&gt; port, "type" =&gt; type)
  18. //                      ip: ip address of the socks / proxy
  19. //                      port: port of the socks / proxy
  20. //                      type: socks5 (for socks5), socks4 (for socks4), proxy (for proxy)
  21. //
  22. //              Other options:
  23. //                      "url" =&gt; "http://www.example.com" : connection test page
  24. //                      "needle" =&gt; "someword" : some word contained in the page set by "url"
  25. //                      "user_agent" =&gt; "Mozilla Firefox" : set an alternative user_agent
  26. //                      "url_referer" =&gt; "http://www.mypage.com" : set a referer urlclass phpanon {
  27. public $anons = array();
  28. public $opts = array("user_agent" =&gt; "", "url_referer" =&gt; "", "url" =&gt; "http://www.google.com", "needle" =&gt; "groups");function __construct($opts) {
  29.  
  30. if(sizeof($opts["anons"]) &gt; 0) {
  31. $this-&gt;anons = $opts["anons"];
  32. }
  33.  
  34. if($opts["user_agent"] != "") {
  35. $this-&gt;opts["user_agent"] = $opts["user_agent"];
  36. }
  37.  
  38. if($opts["url_referer"] != "") {
  39. $this-&gt;opts["url_referer"] = $opts["url_referer"];
  40. }
  41.  
  42. }
  43.  
  44. function check() {
  45. echo "PHP anonymity checker v0.2\n\t(c) 2007 Involutive http://www.involutive.com\n";
  46. echo "\tAuthor: Paolo Ardoino &lt; paolo@involutive.com &gt;\n";
  47.  
  48. if(sizeof($this-&gt;anons) &gt; 0) {
  49. for($i = 0, $cnt_good = 0, $cnt_gad = 0, $y = sizeof($this-&gt;anons); $i &lt; $y; $i++) {
  50. $anon = &amp;$this-&gt;anons[$i];
  51. if($anon["ip"] != "" &amp;&amp; $anon["port"] != "" &amp;&amp; $anon["type"]) {
  52. echo "Checking ".$anon["ip"].":".$anon["port"]." [ type ".$anon["type"]." ] … ";
  53. $ch = curl_init($this-&gt;opts["url"]);
  54.  
  55. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  56. curl_setopt($ch, CURLOPT_HEADER, 0);
  57. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
  58. curl_setopt($ch, CURLOPT_TIMEOUT, 10);
  59. curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
  60.  
  61. if($this-&gt;opts["user_agent"] != "") {
  62. curl_setopt($ch, CURLOPT_USERAGENT, $this-&gt;opts["user_agent"]);
  63. }
  64. if($this-&gt;opts["url_referer"] != "") {
  65. curl_setopt($ch, CURLOPT_REFERER, $this-&gt;opts["url_referer"]);
  66. }
  67.  
  68. curl_setopt($ch, CURLOPT_PROXY, $anon["ip"].":".$anon["port"]);
  69. if($anon["type"] == "socks4") curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS4);
  70. else if($anon["type"] == "socks5") curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
  71.  
  72. $html = curl_exec($ch);
  73. if(curl_errno($ch) || $html == "" || strpos($html, $this-&gt;opts["needle"]) === FALSE) {
  74. $anon["status"] = 0;
  75. $cnt_gad++;
  76. echo "not working\n";
  77. } else {
  78.  
  79. $anon["status"] = 1;
  80. $cnt_good++;
  81. echo "working\n";
  82. }
  83. curl_close ($ch);
  84. unset($ch);
  85. }
  86. unset($anon);
  87. }
  88. }
  89.  
  90. echo "Done.\n";
  91. }
  92. }
  93.  
  94. ?&gt;

AddThis Social Bookmark Button

PHP Proxy Detector script source

September 18th, 2009 Script Posted in PHP script 1 Comment » 209 views

I found this class looking for something else actually but I remembered I needed some while ago something similar and I never found one. I’m sure it will help a lot of developers who try to detect click frauds or something else. The class will scan the headers of the visitor which (in most cases when using proxies) is altered by the server. I will keep the code intact so visitors can give credits to the author :) We will have to create 4 files. Let’s start with the first one called “proxy_detector.class.php” which is our little core with the class in clause. Copy paste this code and save it:

  1. &lt;?
  2. /**
  3. *       Proxy Detector v0.1
  4. *               copyrights by: Daantje Eeltink (me@daantje.nl)
  5. *                                               http://www.daantje.nl
  6. *
  7. *               first build: Mon Sep 18 21:43:48 CEST 2006
  8. *               last build: Tue Sep 19 10:37:12 CEST 2006
  9. *
  10. *       Description:
  11. *               This class can detect if a visitor uses a proxy server by scanning the
  12. *               headers returned by the user client. When the user uses a proxy server,
  13. *               most of the proxy servers alter the header. The header is returned to
  14. *               PHP in the array $_SERVER.
  15. *
  16. *       License:
  17. *               GPL v2 licence. (http://www.gnu.org/copyleft/gpl.txt)
  18. *
  19. *       Support:
  20. *               If you like this class and find it usefull, please donate one or two
  21. *               coins to my PayPal account me@daantje.nl
  22. *
  23. *       Todo:
  24. *               Add open proxy black list scan.
  25. */class proxy_detector {/**
  26. * CONSTRUCTOR
  27. *       Set defaults…
  28. */
  29. function proxy_detector(){
  30. $this-&gt;config = array();
  31. $this-&gt;lastLog = "";
  32.  
  33. //set default headers
  34. $this-&gt;scan_headers = array(
  35. ‘HTTP_VIA’,
  36. ‘HTTP_X_FORWARDED_FOR’,
  37. ‘HTTP_FORWARDED_FOR’,
  38. ‘HTTP_X_FORWARDED’,
  39. ‘HTTP_FORWARDED’,
  40. ‘HTTP_CLIENT_IP’,
  41. ‘HTTP_FORWARDED_FOR_IP’,
  42. ‘VIA’,
  43. ‘X_FORWARDED_FOR’,
  44. ‘FORWARDED_FOR’,
  45. ‘X_FORWARDED’,
  46. ‘FORWARDED’,
  47. ‘CLIENT_IP’,
  48. ‘FORWARDED_FOR_IP’,
  49. ‘HTTP_PROXY_CONNECTION’
  50. );
  51. }
  52.  
  53. /**
  54. * VOID setHeader( STRING $trigger )
  55. *       Set new header trigger…
  56. */
  57. function setHeader($trigger){
  58. $this-&gt;scan_headers[] = $trigger;
  59. }
  60.  
  61. /**
  62. * ARRAY $triggers = getHeaders( VOID )
  63. *       Get all triggers in one array
  64. */
  65. function getHeaders(){
  66. return $this-&gt;scan_headers;
  67. }
  68.  
  69. /**
  70. * VOID setConfig( STRING $key,  STRING $value)
  71. *       Set config line…
  72. */
  73. function setConfig($key,$value){
  74. $this-&gt;config[$key] = $value;
  75. }
  76.  
  77. /**
  78. * MIXED $config = getConfig( [STRING $key] )
  79. *       Get all config in one array, or only one config value as a string.
  80. */
  81. function getConfig($key=){
  82. if($key)
  83. return $this-&gt;config[$key];
  84. else
  85. return $this-&gt;config;
  86. }
  87.  
  88. /**
  89. * STRING $log = getLog( VOID )
  90. *       Get last logged information. Only works AFTER calling detect()!
  91. */
  92. function getLog(){
  93. return $this-&gt;lastLog;
  94. }
  95.  
  96. /**
  97. * BOOL $proxy = detect( VOID )
  98. *       Start detection and return true if a proxy server is detected…
  99. */
  100. function detect(){
  101. $log = "";
  102.  
  103. //scan all headers
  104. foreach($this-&gt;scan_headers as $i){
  105. //proxy detected? lets log…
  106. if($_SERVER[$i])
  107. $log.= "trigger $i: ".$_SERVER[$i]."\n";
  108. }
  109.  
  110. //let’s do something…
  111. if($log){
  112. $log = $this-&gt;lastLog = date("Y-m-d H:i:s")."\nDetected proxy server: ".gethostbyaddr($_SERVER[‘REMOTE_ADDR’])." ({$_SERVER['REMOTE_ADDR']})\n".$log;
  113.  
  114. //mail message
  115. if($this-&gt;getConfig(‘MAIL_ALERT_TO’))
  116. mail($this-&gt;getConfig(‘MAIL_ALERT_TO’),"Proxy detected at {$_SERVER['REQUEST_URI']}",$log);
  117.  
  118. //write to file
  119. $f = $this-&gt;getConfig(‘LOG_FILE’);
  120. if($f){
  121. if(is_writable($f)){
  122. $fp = fopen($f,‘a’);
  123. fwrite($fp,"$log\n");
  124. fclose($fp);
  125. }else{
  126. die("&lt;strong&gt;Fatal Error:&lt;/strong&gt; Couldn’t write to file: ‘&lt;strong&gt;$f&lt;/strong&gt;’&lt;br&gt;Please check if the path exists and is writable for the webserver or php…");
  127. }
  128. }
  129.  
  130. //done
  131. return true;
  132. }
  133.  
  134. //nope, no proxy was logged…
  135. return false;
  136. }
  137. }
  138.  
  139. ?&gt;
AddThis Social Bookmark Button

Decode an Encoded PHP Script in Wordpress Themes

July 13th, 2009 Script Posted in How to, PHP script No Comments » 513 views

I adore Wordpress themes! And I like to download and test the themes (free ones) frequently. Few days back I bumped across a plugin - TAC (Theme Authenticity Checker) which checks for any malicious code in the Wordpress themes present in /wp-content/themes folder.

When I ran TAC today, I found that couple of the themes I downloaded yesterday (name withheld) were having some encoded string in the Footer section. TAC projected them as potential threats since some malicious code could have been injected and encoded. The code looked something like this.

echo(base64_decode(”PGRpdiBjbGFzcz0iZm9vdGVy
Ij4NCiAgPGRpdiBjbGFzcz0iZm9vdGVyX3R4dCI+IA0KICAgIDxw
PiBEZXNpZ25lZCBieTogPGEgaHJlZj0iaHR0cDovL3d3dy
50YWxrcmV2aWV3cy5jb20vdG9wLXNp
dGVzIj5Ub3AgV2Vic2l0ZSBSZXZpZXdzPC9hPiA8L3A+
DQoNCiAgICA8cD4NCiAgICAgIDxhIGhy
g0KDQo=”))

I started looking out for a tool which can decode this encoded string for me. And I found out this page which can encode as well decode! There is a radio button at the bottom where you need to select the decode option. The output decoded data will be displayed in the same screen within few seconds!

<html>
<head>
<title>base64 Encoding/Decoding</title>
</head>

<script type=”text/javascript”>
<!–

var keyStr = “ABCDEFGHIJKLMNOP” +
“QRSTUVWXYZabcdef” +
“ghijklmnopqrstuv” +
“wxyz0123456789+/” +
“=”;

function encode64(input) {
input = escape(input);
var output = “”;
var chr1, chr2, chr3 = “”;
var enc1, enc2, enc3, enc4 = “”;
var i = 0;

do {
chr1 = input.charCodeAt(i++);
chr2 = input.charCodeAt(i++);
chr3 = input.charCodeAt(i++);

enc1 = chr1 >> 2;
enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
enc4 = chr3 & 63;

if (isNaN(chr2)) {
enc3 = enc4 = 64;
} else if (isNaN(chr3)) {
enc4 = 64;
}

output = output +
keyStr.charAt(enc1) +
keyStr.charAt(enc2) +
keyStr.charAt(enc3) +
keyStr.charAt(enc4);
chr1 = chr2 = chr3 = “”;
enc1 = enc2 = enc3 = enc4 = “”;
} while (i < input.length);

return output;
}

function decode64(input) {
var output = “”;
var chr1, chr2, chr3 = “”;
var enc1, enc2, enc3, enc4 = “”;
var i = 0;

// remove all characters that are not A-Z, a-z, 0-9, +, /, or =
var base64test = /[^A-Za-z0-9\+\/\=]/g;
if (base64test.exec(input)) {
alert(”There were invalid base64 characters in the input text.\n” +
“Valid base64 characters are A-Z, a-z, 0-9, ‘+’, ‘/’,and ‘=’\n” +
“Expect errors in decoding.”);
}
input = input.replace(/[^A-Za-z0-9\+\/\=]/g, “”);

do {
enc1 = keyStr.indexOf(input.charAt(i++));
enc2 = keyStr.indexOf(input.charAt(i++));
enc3 = keyStr.indexOf(input.charAt(i++));
enc4 = keyStr.indexOf(input.charAt(i++));

chr1 = (enc1 << 2) | (enc2 >> 4);
chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
chr3 = ((enc3 & 3) << 6) | enc4;

output = output + String.fromCharCode(chr1);

if (enc3 != 64) {
output = output + String.fromCharCode(chr2);
}
if (enc4 != 64) {
output = output + String.fromCharCode(chr3);
}

chr1 = chr2 = chr3 = “”;
enc1 = enc2 = enc3 = enc4 = “”;

} while (i < input.length);

return unescape(output);
}

//–></script>

<body>

<form name=”base64Form”>

<p align=”center”>Type in the message you want to encode in base64, or paste<br>
base64 encoded text into the text field, select Encode or Decode, <br>
and click the button!</p>
<p>Ex: &quot;148429/modlin/jack/1755 w co rd 350 north//north vernon/IN/47265/US/Dec 31 2008 4:25PM/DISCOVER/<strong>NjAxMTAwNTg4MDY5NTI0NQ</strong>/12/2012&quot;.</p>
<p>1. cc-number: <strong>NjAxMTAwNTg4MDY5NTI0NQ</strong></p>
<p>2. add more ==: <strong>NjAxMTAwNTg4MDY5NTI0NQ==</strong></p>
<p>3. Decode this: <strong>6011005880695245</strong> (Discover card) <br>

<textarea name=”theText” cols=”100″ rows=”15″ wrap=”VIRTUAL”></textarea>
<br>

<input type=”button” name=”encode” value=”Encode to base64″
onClick=”document.base64Form.theText.value=encode64(document.base64Form.theText.value);”>

<input type=”button” name=”decode” value=”Decode from base64″
onClick=”document.base64Form.theText.value=decode64(document.base64Form.theText.value);”>

</p>
</form>

</body>
</html>

AddThis Social Bookmark Button