Android Root方法原理解析及Hook(四) GingerBreak

和zergRush的攻击原理是一样的,其实zergRush的code部分源于GingerBreak,都是先使vold进程崩溃,从logcat拿到调试信息,然后让vold进程以root权限执行恶意的shellcode(boomsh),

       利用了android的/system/vold/DirectVolume.cpp中handlePartitionAdded()函数的漏洞

[cpp] view plain copy
  1. void DirectVolume::handlePartitionAdded(const char *devpath, NetlinkEvent *evt) {  
  2.     int major = atoi(evt->findParam("MAJOR"));  
  3.     int minor = atoi(evt->findParam("MINOR"));  
  4.       
  5.     int part_num;  
  6.     const char *tmp = evt->findParam("PARTN");  
  7.   
  8.     if (tmp) {  
  9.         part_num = atoi(tmp);  
  10.     } else {  
  11.         SLOGW("Kernel block uevent missing 'PARTN'");  
  12.         part_num = 1;  
  13.     }  
  14. +  
  15.     if (part_num > mDiskNumParts) {  
  16.         mDiskNumParts = part_num;  
  17.     }  
  18.     ...  
  19.     if (part_num > MAX_PARTITIONS) {  //攻击点,如果part_num小于1  
  20.         SLOGE("Dv:partAdd: ignoring part_num = %d (max: %d)\n", part_num, MAX_PARTITIONS);  
  21.     } else {  
  22.         mPartMinors[part_num -1] = minor;  
  23.     }  
  24.     --mPendingPartsCount;  
  25. …  
  26. }  


Android fixed patch and my hook code:

 

[cpp] view plain copy
  1. #include <cutils/log.h>  
  2. #define LOG_TAG “gingerbreak hooker”  
  3. void DirectVolume::handlePartitionAdded(const char *devpath, NetlinkEvent *evt) {  
  4.     int major = atoi(evt->findParam("MAJOR"));  
  5.     int minor = atoi(evt->findParam("MINOR"));  
  6.       
  7.     int part_num;  
  8.     const char *tmp = evt->findParam("PARTN");  
  9.   
  10.     if (tmp) {  
  11.         part_num = atoi(tmp);  
  12.     } else {  
  13.         SLOGW("Kernel block uevent missing 'PARTN'");  
  14.         part_num = 1;  
  15.     }  
  16.       
  17. +   if (part_num > MAX_PARTITIONS || part_num < 1) {  
  18. +       SLOGE("Invalid 'PARTN' value");  
  19. +       return;  
  20. +   }  
  21.   
  22.       
  23.     if (part_num > mDiskNumParts) {  
  24.         mDiskNumParts = part_num;  
  25.     }  
  26.     ...  
  27.     if (part_num >= MAX_PARTITIONS) {   
  28.         SLOGE("Dv:partAdd: ignoring part_num = %d (max: %d)\n", part_num, MAX_PARTITIONS);  
  29.     } else {  
  30.         mPartMinors[part_num -1] = minor;  
  31.     }  
  32.     mPendingPartMap &= ~(1 << part_num);  
  33. …  

你可能感兴趣的:(Android Root方法原理解析及Hook(四) GingerBreak)