Las imágenes, el tamaño del archivo y los hashes son datos que podremos extraer de forma sencilla con PHP como veréis ahora en el código del software. Y los permisos, versión code, versión name y nombre del paquete son datos que extraeremos del archivo "AndroidManifest.xml".
Cómo habitualmente os comparto a continuación el código completo del programa. En este caso he optado por analizar un apk de whatsapp descargado de un sitio web desconocido de Internet:
<?php
//******** APK *******************************************************
$bin='whatsapp';
$ext='.apk';
//******** GLOBAL VARIABLES ******************************************
$rutaTemp="";$html_img="";$html_url="";$html_perm="";$html_manifest="";
$x=0;
//******** EXTRACT IMAGES ********************************************
function showImages($ruta)
{
$extensions=array("png","jpg","jpeg","bmp","tiff","gif");
global $rutaTemp,$x,$html_img;
if (is_dir($ruta))
{
if ($aux = opendir($ruta))
{
while (($archivo = readdir($aux)) !== false)
{
if ($archivo!="." && $archivo!="..")
{
$ruta_completa = $ruta . '/' . $archivo;
if (is_dir($ruta_completa))
{
$rutaTemp=$rutaTemp.$ruta_completa . "/";
showImages($ruta_completa . "/");
}
else
{
foreach($extensions as $extension)
{
if(strpos($archivo, $extension)!==false)
{
$html_img.='<img src="' . $rutaTemp."/".$archivo . '" style="width:50px;height:50px;"/>';
$x++;
}
}
}
}
}
$rutaTemp="";
closedir($aux);
}
}
}
//******** SHELL COMMANDS *******************************************
$com1='mkdir -p android';
$com2='d2j-dex2jar '.$bin.$ext.' --force ';
$com3='java -jar jd-core.jar '.$bin.'-dex2jar.jar android/apk ';
$com4='find android/apk -type f -print0 | xargs -0 grep -1 "https:"';
$com5='find android/apk -type f -print0 | xargs -0 grep -1 "http:"';
$com6='apktool d -f '.getcwd().'/'.$bin.$ext.' '.getcwd().'/android/manifest';
$commands=array($com1,$com2,$com3,$com4,$com5,$com6);
foreach($commands as $com)
{
$output=array();
exec($com, $output);
foreach($output as $valor)
{
//http/s extract
$pos = strpos($valor, '"http');
if ($pos !== false)
{
$valor = substr($valor, $pos+1);
$html_url.='<li>'.$valor.'</li>';
}
}
}
//******** EXTRACT IMAGES *******************************************
showImages("./");
//******** EXTRACT MANIFEST *****************************************
$a = getcwd().'/android/manifest/AndroidManifest.xml';
$fp = fopen($a,'r');
$html_manifest = fread($fp, filesize($a));
$xml=simplexml_load_string(str_replace(":", "", $html_manifest));
//******** EXTRACT PERMISSIONS **************************************
$c=0;
foreach ($xml->children() as $node)
if($node->attributes()->{'androidname'}!="")
{
$prm=$node->attributes()->{'androidname'};
$html_perm.='<li>'.$prm.'</li>';
$c++;
}
?>
<html>
<head>
</head>
<body>
<h1>INFO</h1>
<ul>
<?php
echo '<li>Package: '.$xml->attributes()->{'package'}.'</li>';
echo '<li>Version code: '.$xml->attributes()->{'androidversionCode'}.'</li>';
echo '<li>Version name: '.$xml->attributes()->{'androidversionName'}.'</li>';
echo '<li>Size:'.filesize($bin.$ext).' bytes</li>';
echo '<li>MD5:'.md5_file($bin.$ext).'</li>';
echo '<li>SHA1:'.sha1_file($bin.$ext).'</li>';
echo '<li>Permissions:'.$c.'</li>';
echo '<li>Images:'.$x.'</li>';
?>
</ul>
<h1>HTTP/S</h1>
<ul> <?php echo $html_url;?> </ul>
<h1>PERMISSIONS</h1>
<ul> <?php echo $html_perm; ?> </ul>
<h1>IMAGES</h1>
<?php echo $html_img; ?>
<h1>MANIFEST</h1>
<textarea cols="100" rows="25"> <?php echo $html_manifest; ?> </textarea>
</body>
</html>
0 comentarios:
Publicar un comentario