1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291
| //hook常规的获取设备信息接口 //通过打印堆栈信息来看是什么sdk调用
function showjavastack(){ var javastack = Java.use("android.util.Log").getStackTraceString(Java.use("java.lang.Exception").$new()); //console.log(javastack); }
function hook(){ Java.perform(function() { var TelephonyManager = Java.use("android.telephony.TelephonyManager"); //IMEI hook TelephonyManager.getDeviceId.overload().implementation = function () { console.log("[*]Called - getDeviceId()"); var temp = this.getDeviceId(); console.log("real IMEI: "+temp); showjavastack(); console.log("------------------------------------------------------"); return temp; }; // muti IMEI TelephonyManager.getDeviceId.overload('int').implementation = function (p) { console.log("[*]Called - getDeviceId(int) param is"+p); var temp = this.getDeviceId(p); console.log("real IMEI "+p+": "+temp); showjavastack(); console.log("------------------------------------------------------"); return temp; }; //IMSI hook TelephonyManager.getSimSerialNumber.overload().implementation = function () { console.log("[*]Called - getSimSerialNumber(String)"); var temp = this.getSimSerialNumber(); console.log("real IMSI: "+temp); showjavastack(); console.log("------------------------------------------------------"); return temp; }; //取出 IMEI 需要 api26以上 TelephonyManager.getImei.overload().implementation = function(){ console.log("[*]Called - getImei"); var temp = this.getImei(); console.log("real IMEI:" + temp); showjavastack(); console.log("------------------------------------------------------"); return temp; } TelephonyManager.getImei.overload('int').implementation = function(a){ console.log("[*]Called - getImei(int)"); var temp = this.getImei(a); console.log("real IMEI(int):" + temp); showjavastack(); console.log("------------------------------------------------------"); return temp; } TelephonyManager.getSimOperatorName.overload().implementation = function(){ console.log("[*]Called - getSimOperatorName"); var temp = this.getSimOperatorName(); console.log("real 运营商:" + temp); showjavastack(); console.log("------------------------------------------------------"); return temp; } TelephonyManager.getSimOperatorName.overload('int').implementation = function(a){ console.log("[*]Called - getSimOperatorName(int)"); var temp = this.getSimOperatorName(a); console.log("real 运营商:" + temp); showjavastack(); console.log("------------------------------------------------------"); return temp; } TelephonyManager.getLine1Number.overload().implementation = function(){ console.log("[*]Called - getLine1Number"); var temp = this.getLine1Number(); console.log("real MSISDN:" + temp); showjavastack(); console.log("------------------------------------------------------"); return temp; } TelephonyManager.getLine1Number.overload('int').implementation = function(a){ console.log("[*]Called - getLine1Number"); var temp = this.getLine1Number(a); console.log("real MSISDN:" + temp); showjavastack(); console.log("------------------------------------------------------"); return temp; } //////////////////////////////////////
// hook MAC var wifi = Java.use("android.net.wifi.WifiInfo"); wifi.getMacAddress.implementation = function () { console.log("[*]Called - getMacAddress"); var tmp = this.getMacAddress(); console.log("[*]real MAC: "+tmp); showjavastack(); console.log("------------------------------------------------------"); return tmp; }
var NetworkInterface = Java.use("java.net.NetworkInterface"); NetworkInterface.getHardwareAddress.implementation = function () { console.log("[*]Called - getHardwareAddress"); var tmp = this.getHardwareAddress(); console.log("[*]real HardwareAddress: "+tmp); showjavastack(); console.log("------------------------------------------------------"); return tmp; } //ANDOID_ID hook var Secure = Java.use("android.provider.Settings$Secure"); Secure.getString.implementation = function (p1,p2) { if(p2.indexOf("android_id")<0) return this.getString(p1,p2); console.log("[*]Called - get android_ID, param is:"+p2); var temp = this.getString(p1,p2); console.log("real Android_ID: "+temp); showjavastack(); console.log("------------------------------------------------------"); return temp; } //android获取GPS var LocationManager = Java.use("android.location.LocationManager"); LocationManager.getLastKnownLocation.implementation = function(a){ console.log("[*]Called - getLastKnownLocation"); var tmp = this.getLastKnownLocation(a); console.log("调用getLastKnownLocation获取了GPS地址" + tmp); showjavastack(); console.log("------------------------------------------------------"); return tmp; } LocationManager.requestLocationUpdates.overload('android.location.LocationRequest', 'android.app.PendingIntent').implementation = function(a,b){ console.log("[*]Called - requestLocationUpdates.overload('android.location.LocationRequest', 'android.app.PendingIntent')"); var tmp = this.requestLocationUpdates(a,b); console.log("调用requestLocationUpdates获取了GPS地址" + tmp); showjavastack(); console.log("------------------------------------------------------"); return tmp; } LocationManager.requestLocationUpdates.overload('android.location.LocationRequest', 'android.location.LocationListener', 'android.os.Looper').implementation = function(a,b,c){ console.log("[*]Called - requestLocationUpdates.overload('android.location.LocationRequest', 'android.location.LocationListener', 'android.os.Looper')"); var tmp = this.requestLocationUpdates(a,b,c); console.log("调用requestLocationUpdates获取了GPS地址" + tmp); showjavastack(); console.log("------------------------------------------------------"); return tmp; } LocationManager.requestLocationUpdates.overload('android.location.LocationRequest', 'android.location.LocationListener', 'android.os.Looper', 'android.app.PendingIntent').implementation = function(a,b,c,d){ console.log("[*]Called - requestLocationUpdates.overload('android.location.LocationRequest', 'android.location.LocationListener', 'android.os.Looper', 'android.app.PendingIntent')"); var tmp = this.requestLocationUpdates(a,b,c,d); console.log("调用requestLocationUpdates获取了GPS地址" + tmp); showjavastack(); console.log("------------------------------------------------------"); return tmp; } LocationManager.requestLocationUpdates.overload('long', 'float', 'android.location.Criteria', 'android.app.PendingIntent').implementation = function(a,b,c,d){ console.log("[*]Called - requestLocationUpdates.overload('long', 'float', 'android.location.Criteria', 'android.app.PendingIntent')"); var tmp = this.requestLocationUpdates(a,b,c,d); console.log("调用requestLocationUpdates获取了GPS地址" + tmp); showjavastack(); console.log("------------------------------------------------------"); return tmp; } LocationManager.requestLocationUpdates.overload('java.lang.String', 'long', 'float', 'android.app.PendingIntent').implementation = function(a,b,c,d){ console.log("[*]Called - requestLocationUpdates.overload('java.lang.String', 'long', 'float', 'android.app.PendingIntent')"); var tmp = this.requestLocationUpdates(a,b,c,d); console.log("调用requestLocationUpdates获取了GPS地址" + tmp); showjavastack(); console.log("------------------------------------------------------"); return tmp; } LocationManager.requestLocationUpdates.overload('java.lang.String', 'long', 'float', 'android.location.LocationListener').implementation = function(a,b,c,d){ console.log("[*]Called - requestLocationUpdates.overload('java.lang.String', 'long', 'float', 'android.location.LocationListener')"); var tmp = this.requestLocationUpdates(a,b,c,d); console.log("调用requestLocationUpdates获取了GPS地址" + tmp); showjavastack(); console.log("------------------------------------------------------"); return tmp; } LocationManager.requestLocationUpdates.overload('long', 'float', 'android.location.Criteria', 'android.location.LocationListener', 'android.os.Looper').implementation = function(a,b,c,d,e){ console.log("[*]Called - requestLocationUpdates.overload('long', 'float', 'android.location.Criteria', 'android.location.LocationListener', 'android.os.Looper')"); var tmp = this.requestLocationUpdates(a,b,c,d,e); console.log("调用requestLocationUpdates获取了GPS地址" + tmp); showjavastack(); console.log("------------------------------------------------------"); return tmp; } LocationManager.requestLocationUpdates.overload('java.lang.String', 'long', 'float', 'android.location.LocationListener', 'android.os.Looper').implementation = function(a,b,c,d,e){ console.log("[*]Called - requestLocationUpdates.overload('java.lang.String', 'long', 'float', 'android.location.LocationListener', 'android.os.Looper')"); var tmp = this.requestLocationUpdates(a,b,c,d,e); console.log("调用requestLocationUpdates获取了GPS地址" + tmp); showjavastack(); console.log("------------------------------------------------------"); return tmp; }
//获取应用列表 var Runtime = Java.use("java.lang.Runtime"); Runtime.exec.overload('java.lang.String').implementation = function(a){ console.log("[*]Called - exec(command)"); var tmp = this.exec(a); console.log("执行exec的命令:" + a); if(a.indexOf("packages") != -1){ console.log("应用使用"+ a + "收集应用列表"); showjavastack(); } console.log("------------------------------------------------------"); return tmp; } var PackageManager = Java.use("android.content.pm.PackageManager"); PackageManager.getInstalledPackages.implementation = function(a){ console.log("[*]Called - getInstalledPackages"); var tmp = this.getInstalledPackages(a); console.log("调用getInstalledPackages获取了应用列表" + tmp); showjavastack(); console.log("------------------------------------------------------"); return tmp; } PackageManager.getInstalledApplications.implementation = function(a){ console.log("[*]Called - getInstalledApplications"); var tmp = this.getInstalledApplications(a); console.log("调用getInstalledApplications获取了应用列表" + tmp); showjavastack(); console.log("------------------------------------------------------"); return tmp; } PackageManager.queryIntentActivities.implementation = function(a,b){ console.log("[*]Called - queryIntentActivities"); var tmp = this.queryIntentActivities(a,b); console.log("调用queryIntentActivities获取了应用列表" + tmp); showjavastack(); console.log("------------------------------------------------------"); return tmp; } var ContextWrapper = Java.use("android.content.ContextWrapper"); ContextWrapper.getPackageManager.implementation = function(){ console.log("[*]Called - getPackageManager"); var tmp = this.getPackageManager(); console.log("调用getPackageManager获取了应用列表" + tmp); showjavastack(); console.log("------------------------------------------------------"); return tmp; }
//android的hidden API,需要通过反射调用 var SP = Java.use("android.os.SystemProperties"); SP.get.overload('java.lang.String').implementation = function (p1) { var tmp = this.get(p1); console.log("[*]"+p1+" : "+tmp); showjavastack(); console.log("------------------------------------------------------"); return tmp; } SP.get.overload('java.lang.String', 'java.lang.String').implementation = function (p1,p2) { var tmp = this.get(p1,p2) console.log("[*]"+p1+","+p2+" : "+tmp); showjavastack(); console.log("------------------------------------------------------"); return tmp; } }) }
function main(){ hook(); }
setImmediate(main); ``` //新建一个命令行
adb shell
cd 保存frida_server的路径
./frida_server
//新建另一个命令行
//转发frida_server默认端口 adb forward tcp:27042 tcp:27042
frida -Uf packagename -l hook_privacy.js的绝对路径
|