本文为看雪论坛优秀文章
看雪论坛作者ID:以和爲貴
一
java层的案例
final EditText editText = (EditText) findViewById(R.id.username);
final EditText editText2 = (EditText) findViewById(R.id.password);
public void onClick(View view) {
String obj = editText.getText().toString();
String obj2 = editText2.getText().toString();
else if (LoginActivity.a(obj, obj).equals(obj2)) {
LoginActivity.this.startActivity(new Intent(LoginActivity.this.mContext, FridaActivity1.class));
LoginActivity.this.finishActivity(0);
function hook_java(){
Java.perform(function(){
Java.use("com.example.androiddemo.Activity.LoginActivity").a.overload('java.lang.String', 'java.lang.String').implementation = function(arg1,arg2){
console.log("hook,start!")
var result = this.a(arg1,arg2);
console.log("arg1,arg2,result:",arg1,arg2,result);
}
})
}
function main(){
hook_java()//在main函数中调用hook_java函数
}
setImmediate(main);
R4jSLLLLLLLLLLOrLE7/5B+Z6fsl65yj6BgC6YWz66gO6g2t65Pk6a+P65NK44NNROl0wNOLLLL=
function hook_java(){
Java.perform(function(){
Java.use("com.example.androiddemo.Activity.FridaActivity1").a.implementation = function(arg1){
//这里有个函数重载,在刚刚的objection中也可以看出来
console.log("hook,start!")
var result = "R4jSLLLLLLLLLLOrLE7/5B+Z6fsl65yj6BgC6YWz66gO6g2t65Pk6a+P65NK44NNROl0wNOLLLL=";
console.log("arg1:",arg1);
return result;
}
})
}
function main(){
hook_java()//在main函数中调用hook_java函数
}
setImmediate(main);
private static void com.example.androiddemo.Activity.FridaActivity2.setStatic_bool_var()
private void com.example.androiddemo.Activity.FridaActivity2.setBool_var()
function hook_java(){
Java.perform(function(){
//这里需要注意一下,静态的成员变量可以直接修改
// private static boolean static_bool_var = false;
Java.use("com.example.androiddemo.Activity.FridaActivity2").static_bool_var.value = true;
//动态的成员变量需要使用主动调用的方法
//private boolean bool_var = false;
Java.choose("com.example.androiddemo.Activity.FridaActivity2",{
onMatch:function(instence){
console.log("found instence:",instence);
instence.bool_var.value = true;
},onComplete:function(){console.log("instence completed!")}
})
})
}
function main(){
hook_java()//在main函数中调用hook_java函数
}
setImmediate(main);
function hook_java(){
Java.perform(function(){
// private static void setStatic_bool_var()
//这个函数是静态的函数,所以可以直接hook调用
Java.use("com.example.androiddemo.Activity.FridaActivity2").setStatic_bool_var();
// private void setBool_var()
//这个函数不是static修饰的,所以要通过主动调用的方式
Java.choose("com.example.androiddemo.Activity.FridaActivity2",{
onMatch:function(instance){
console.log("found instence",instance);
instance.setBool_var()//调用函数,执行函数
},onComplete:function(){console.log("instence,completed!");}
})
})
}
function main(){
hook_java()//在main函数中调用hook_java函数
}
setImmediate(main);
function hook_java(){
Java.perform(function(){
//private static boolean static_bool_var = false;
//静态的成员变量可以直接修改
Java.use("com.example.androiddemo.Activity.FridaActivity3").static_bool_var.value = true;
// private boolean bool_var = false;
//private boolean same_name_bool_var = false;
//动态的成员变量需要主动调用
Java.choose("com.example.androiddemo.Activity.FridaActivity3",{
onMatch:function(instence){
console.log("found instence:",instence);
instence.bool_var.value = true;//修改成员变量的值
//这里需要注意一下,因为具有同名的成员变量和成员函数,所以修改成员变量的值的时候需要在前面加一个_
instence._same_name_bool_var.value = true;//修改成员变量的值
},onComplete:function(){console.log("instence completed!")}
})
})
}
function main(){
hook_java()//在main函数中调用hook_java函数
}
setImmediate(main);
function hook_java(){
Java.perform(function(){
Java.use("com.example.androiddemo.Activity.FridaActivity4$InnerClasses").check1.implementation = function(){return true};
Java.use("com.example.androiddemo.Activity.FridaActivity4$InnerClasses").check2.implementation = function(){return true};
Java.use("com.example.androiddemo.Activity.FridaActivity4$InnerClasses").check3.implementation = function(){return true};
Java.use("com.example.androiddemo.Activity.FridaActivity4$InnerClasses").check4.implementation = function(){return true};
Java.use("com.example.androiddemo.Activity.FridaActivity4$InnerClasses").check5.implementation = function(){return true};
Java.use("com.example.androiddemo.Activity.FridaActivity4$InnerClasses").check6.implementation = function(){return true};
})
}
function main(){
hook_java()//在main函数中调用hook_java函数
}
setImmediate(main);
function fifth(){
Java.perform(function(){
Java.choose("com.example.androiddemo.Activity.FridaActivity5",{
onMatch:function(instance){
//用classname来查看
console.log("found instence getDynamicDexCheck():",instance.getDynamicDexCheck().$className);
},onComplete:function(){console.log("search complete!");}
})
//用枚举法看看在那个类里面
Java.enumerateClassLoaders({
onMatch:function(loader){
try {
if(loader.findClass("com.example.androiddemo.Dynamic.DynamicCheck")){
console.log("Success found loader:",loader);
//将默认的classloader替换成loader
Java.classFactory.loader = loader;
}
} catch (error) {
console.log("found,error!"+error);
}
},onComplete:function(){console.log("enum complete!")}
})
Java.use("com.example.androiddemo.Dynamic.DynamicCheck").check.implementation = function(){return true;}
})
}
function func6() {
Java.perform(function () {
Java.enumerateLoadedClasses({
onMatch: function (name, handle) {
if (name.indexOf("com.example.androiddemo.Activity.Frida6") >= 0) {
console.log(name);
var frida6 = Java.use(name);
frida6.check.implementation = function () {
console.log("frida 6 check:", this);
return true;
};
}
}, onComplete: function () {
}
})
});
}
function main(){
Java.perform(function(){
var System = Java.use("java.lang.System");
console.log(System);
System.getProperty.overload('java.lang.String').implementation = function (key) {
var result = this.getProperty(key);
result = "Russia";
console.log("System.getProperty:", key, result);
return result;
};
})
}
setImmediate(main)
function main(){
Java.perform(function(){
var System = Java.use("java.lang.System");
console.log(System);
System.getProperty.overload('java.lang.String').implementation = function (key) {
var result = this.getProperty(key);
result = "Russia";
console.log("System.getProperty:", key, result);
return result;
};
System.getenv.overload('java.lang.String').implementation = function (key) {
var result = this.getenv(key);
result = "RkxBR3s1N0VSTDFOR180UkNIM1J9Cg==";
console.log("getenv :",key,result);
return result;
};
})
}
setImmediate(main)
if (this.n != null && this.o != null && !this.n.isEmpty() && !this.o.isEmpty()) {
if (!this.n.equals(getResources().getString(R.string.username))) {
} else if (!j()) {
private boolean j() {
byte[] digest = this.m.digest(this.o.getBytes());
//这里是用户输入的密码经过m函数(跟进分析之后发现m函数是md5函数)
String str = "";
for (byte b : digest) {
str = str + String.format("%x", Byte.valueOf(b));
}
//转换成hex字符串
return str.equals(getResources().getString(R.string.password));
//最后这个str要和资源文件中的password相等才可以
// <string name="password">84e343a0486ff05530df6c705c8bb4</string>
}
var a = Java.use("com.tlamb96.kgbmessenger.b.a");
a.$init.implementation = function(i,str,str2,z){
this.$init(i,str,str2,z);
console.log("a,$init",i,str,str2,z);
console.log(Java.use("android.util.Log").getStackTraceString(Java.use("java.lang.Throwable").$new()));
}
})
Java.choose("com.tlamb96.kgbmessenger.MessengerActivity",{
onMatch:function(instance){
console.log("found instance",instance);
instance.a = function(str){
result = "[email protected]]EAASB\u0012WZF\u0012e,a$7(&am2(3.\u0003";
return result;
}
},onComplete:function(){console.log("search,completed!")}
})
Java.use("com.tlamb96.kgbmessenger.MessengerActivity").a.implementation = function(x){
var result = this.a(x);
console.log("a:x,result:",x,result);
if(x=="kanxue"){
result= Java.use("java.lang.String").$new("[email protected]]EAASB\u0012WZF\u0012e,a$7(&am2(3.\u0003");
}
return result;
}
二
so层的案例
((MyApp) RegActivity.this.getApplication()).saveSN(sn);
intent.setComponent(new ComponentName(BuildConfig.APPLICATION_ID, "com.gdufs.xman.RegActivity"));
var fputs_str = null;
function Hook() {
Java.perform(function () {
const imports = Module.enumerateImportsSync("libmyjni.so");
const imports_len = imports.length;
var fputs_addr = null;
for (var i = 0; i < imports_len; i++) {
if (imports[i].name == "fputs") {
fputs_addr = imports[i].address;
break;
}
}
if (fputs_addr != null) {
Interceptor.attach(fputs_addr, {
onEnter: function (args) {
fputs_str = args[0].readCString();
},
onLeave: function (retval) {
}
})
}
})
}
function Invoke(temp) {
Java.perform(function () {
Java.choose("com.gdufs.xman.MyApp", {
onMatch: function (instance) {
instance.saveSN(temp);
},
onComplete: function () {
}
})
})
}
function attack() {
Hook();
Java.perform(function () {
const _array = new Array("EoP", "AoY", "[email protected]", "ElR");
const end = "D";
const secret = "[email protected]#$%^&*()?_"
const _array_len = _array.length;
const secret_len = secret.length
const myapp = Java.use("com.gdufs.xman.MyApp").$new();
var flag = "";
for (var i = 0; i < _array_len; i++) {
var flag = false;
for (var j = 0; j < secret_len; j++) {
if (flag == true) {
break;
}
for (var k = 0; k < secret_len; k++) {
if (flag == true) {
break;
}
for (var m = 0; m < secret_len; m++) {
const temp = secret[j] + secret[k] + secret[m];
console.log(`temp: ${temp}`);
myapp.saveSN(temp);
if (_array[i] == fputs_str) {
flag += temp;
console.log(`flag: ${temp}`);
flag = true;
break;
}
}
}
}
}
for (var i = 0; i < secret_len; i++) {
const temp = secret[i];
console.log(`temp: ${temp}`);
Invoke(temp);
if (end == fputs_str) {
flag += temp;
console.log(`flag: ${temp}`);
break;
}
}
console.log(`flag: xman{${flag}}`);
})
}
function hook_java(){
Java.perform(function(){
var MyApp = Java.use("com.gdufs.xman.MyApp");
MyApp.saveSN.implementation = function(str){
console.log("MyApp.saveSN.str:",str);
this.saveSN(str);//调用一下函数
}
//hook掉killProcess函数,不让他执行
var Process = Java.use("android.os.Process");
Process.killProcess.implementation = function(pid){
console.log("Process.killProcess not implement!",pid);
}
console.log("hook completed!");
})
}
function hook_native(){
//找到模块的地址
var base_myjni = Module.findBaseAddress("libmyjni.so");
//如果以spwan的模式启动,那么就要判断base_myjni的值是否为0,一开始会不加载这个so文件
if(base_myjni){
console.log("base_myjni",base_myjni);//base_myjni 0xbfd0e000
//找到要hook的函数 这个函数得是export函数
//参数: so所在路径,要hook的函数的名字
var n2 = Module.findExportByName("libmyjni.so","n2");
//thumb格式的函数,hook的时候在静态分析的地址上面加1
//ida地址:0x000011F8 实际地址:n2: 0xbfd0f1f9
//相差一个模块的地址
console.log("hook_native()__ n2:",n2);
//n2 - base_myjni = 偏移 + 1;
//11f9 = 偏移 + 1; 偏移 = 11f8 也就是ida中的地址
//开始hook函数
Interceptor.attach(n2,{
onEnter:function(args){
//args是一个数组
console.log("hook_native()__ n2 onEnter:",args[0],args[1],args[2]);
},onLeave:function(retval){
}
});
}
}
//hook这个函数GetStringUTFChars
//这个函数GetStringUTFChars在libart里面
function hook_libart(){
//枚举所有的文件来找到
//首先找到so
var module_libart = Process.findModuleByName("libart.so");
//看看有哪些符号
var symbols = module_libart.enumerateSymbols();
//找到函数的名字和地址
var add_GetStringUTFChars = null;
for(var i = 0;i < symbols.length;i++){
var name = symbols[i].name;
if(name.indexOf("art") >= 0 ){
if( (name.indexOf("JNI") >= 0) && (name.indexOf("CheckJNI") == -1) ){
if(name.indexOf("GetStringUTFChars") >= 0){
console.log("hook_libart()__ name:",name);
//找到函数的名字
add_GetStringUTFChars = symbols[i].address;
//找到函数的地址
}
}
}
}
//开始hook函数
if(add_GetStringUTFChars){
Interceptor.attach(add_GetStringUTFChars,{
onEnter:function(args){
console.log("onEnter find add_GetStringUTFChars************************************\r\n");
},onLeave:function(retval){
//从ida中看出返回值为const char *类型
console.log("onLeave GetStringUTFChars_native_retval************************************\r\n:",ptr(retval).readCString());
}
})
}
//通过hook strcmp函数来查看m的值,来查看程序是否被注册
function hook_libc() {
//hook libc的函数
var strcmp = Module.findExportByName("libc.so", "strcmp");
console.log("strcmp:", strcmp);
Interceptor.attach(strcmp, {
onEnter: function (args) {
var str_2 = ptr(args[1]).readCString();
if (str_2 == "[email protected]") {
console.log("strcmp:", ptr(args[0]).readCString(),
ptr(args[1]).readCString());
}
}, onLeave: function (retval) {
}
});
}
//用firda向文件中写内容
function write_reg_dat() {
//frida 的api来写文件
var file = new File("/sdcard/reg.dat", "w");
file.write("[email protected]");
file.flush();
file.close();
}
看雪ID:以和爲貴
https://bbs.pediy.com/user-home-939330.htm
招生![2023春季班]《安卓高级研修班(网课)》月薪三万计划https://www.kanxue.com/book-leaflet-84.htm
# 往期推荐
球分享
球点赞
球在看
点击“阅读原文”,了解更多!