Tuesday, August 17, 2010

PHP Parser to extract Filezilla FTP details

The following is a PHP program to extract FTP usernames and passwords from the filezilla xml file.
First export the filezilla FTP details using the export option in the filezilla
File - > Export

Save this file as 'FileZilla.xml'

Assign the xml file path to the variable and reun the program. It will list the ftp details . Add or change the xml_key variable to get the other details of FTP details.

Source Code
<?php
$xml_file = "FileZilla.xml";
$xml_host_key = "*FILEZILLA3*SERVERS*SERVER*HOST";
$xml_port_key = "*FILEZILLA3*SERVERS*SERVER*PORT";
$xml_user_key = "*FILEZILLA3*SERVERS*SERVER*USER";
$xml_pass_key = "*FILEZILLA3*SERVERS*SERVER*PASS";
$xml_name_key = "*FILEZILLA3*SERVERS*SERVER*NAME";
$story_array = array();
$counter = 0;
class xml_story{
var $host, $port,$user,$pass;
}
function startTag($parser, $data){
global $current_tag;
$current_tag .= "*$data";
}
function endTag($parser, $data){
global $current_tag;
$tag_key = strrpos($current_tag, '*');
$current_tag = substr($current_tag, 0, $tag_key);
}
function contents($parser, $data){
global $current_tag, $xml_host_key, $xml_port_key, $counter, $story_array,$xml_user_key,$xml_pass_key,$xml_name_key;
switch($current_tag){
case $xml_host_key:
$story_array[$counter] = new xml_story();
$story_array[$counter]->host = $data;
break;
case $xml_port_key:

$story_array[$counter]->port = $data;
//$counter++;
break;
case $xml_user_key:

$story_array[$counter]->user = $data;
// $counter++;
break;
case $xml_pass_key:

$story_array[$counter]->pass = $data;
// $counter++;
break;
case $xml_name_key:

$story_array[$counter]->name = $data;
$counter++;
break;

}
}
$xml_parser = xml_parser_create();
xml_set_element_handler($xml_parser, "startTag", "endTag");
xml_set_character_data_handler($xml_parser, "contents");
$fp = fopen($xml_file, "r") or die("Could not open file");
$data = fread($fp, filesize($xml_file)) or die("Could not read file");
if(!(xml_parse($xml_parser, $data, feof($fp)))){
die("Error on line " . xml_get_current_line_number($xml_parser));
}
xml_parser_free($xml_parser);
fclose($fp);
?>
<html>
<head>
<title>Filezilla Parser</title>
</head>
<body bgcolor="#FFFFFF">
<table width="1001" border="1">
<tr>
<td width="47"><strong>NO</strong></td>
<td width="185"><strong>Name</strong></td>
<td width="229"><strong>Host</strong></td>
<td width="221"><strong>User Name</strong></td>
<td width="125"><strong>Password</strong></td>
<td width="154"><strong>Port</strong></td>
</tr>
<?php
for($x=0;$x<count($story_array);$x++){
?>

<tr>
<td height="38"><?=$x++?></td>
<td><?=$story_array[$x]->name?></td>
<td><?=$story_array[$x]->host?></td>
<td><?=$story_array[$x]->user?></td>
<td><?=$story_array[$x]->pass?></td>
<td><?=$story_array[$x]->port?></td>
</tr>
<?php
}
?>
</table>
</body>
</html>

It will list the FTP host ,FTP username , FTP password and port etc.