[android] WirelessPass 08-15-2017, 05:11 AM
#1
This program prints out all wireless passwords on Android devices. It requires root and the ini4j library for easier parsing.
Code:
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import org.ini4j.Ini;
public class WirelessPass {
public static String SUPPLICANT_PATH = "/data/misc/wifi/WPA_supplicant.conf";
public static void main(String[] args)
{
if( isRootAvailable() )
{
if( isSupplicantAvailable() ) {
doSupplicant();
}
}
}
public static boolean isRootAvailable()
{
String[] paths = { "/sbin/su", "/system/bin/su", "/system/xbin/su",
"/data/local/xbin/su", "/data/local/bin/su", "/system/sd/xbin/su",
"/system/bin/failsafe/su", "/data/local/su" };
for (String path : paths) {
if ( new File(path).exists() ) {
return true;
}
}
return false;
}
public static boolean isSupplicantAvailable()
{
if( new File(SUPPLICANT_PATH).exists() ) {
return true;
}
return false;
}
public static int doSupplicant()
{
int read;
try {
StringBuilder data = new StringBuilder();
FileInputStream in = new FileInputStream( SUPPLICANT_PATH );
while ((read = in.read()) != -1) {
data.append( (char) read );
}
String temp = data.toString();
if( !temp.isEmpty() )
{
int count = countOccurrences( temp, "network" );
if( count > 0 )
{
String clean = formatToINI( temp, count);
Ini ini = new Ini(new ByteArrayInputStream(clean.toString().getBytes("UTF-8") ) );
if( !ini.isEmpty() )
{
int i = 0;
while( i < count )
{
String header = "network" + Integer.toString( i );
System.out.println( header );
String ssid = ini.get( header, "ssid" );
String key_mgmt = ini.get( header, "key_mgmt" );
String psk = ini.get( header, "psk" );
String priority = ini.get( header, "priority" );
if( key_mgmt.equals("NONE") ) {
psk = "OPEN";
}
System.out.println( "\n - SSID: " + ssid
+ "\n - Security: " + key_mgmt
+ "\n - Wireless Key: " + psk + "\n\r\n");
i++;
}
}
} else {
return 3;
}
} else {
return 2;
}
} catch ( Exception e ) {
return 1;
}
return 0;
}
public static int countOccurrences(String haystack, String needle)
{
int count = 0, index = 0;
while (index != -1)
{
index = haystack.indexOf(needle, index);
if (index != -1) {
count++;
index += needle.length();
}
}
return count;
}
public static String formatToINI( String input, int Occurrences )
{
int i = 0;
StringBuilder format = new StringBuilder();
format.append( "[main]\n");
while( i < Occurrences) {
input = input.replaceFirst("network=\\{", "[network" + Integer.toString( i ) + "]" );
input = input.replaceFirst("\\}", "");
i++;
}
input = input.replaceAll("\t", "");
input = input.replaceAll("\"", "");
format.append( input );
return format.toString();
}
}
(This post was last modified: 08-15-2017, 05:11 AM by titbang.)