-
Notifications
You must be signed in to change notification settings - Fork 32
/
android-okhttp-logger.js
96 lines (83 loc) · 3.12 KB
/
android-okhttp-logger.js
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
/*
Description: Android OKHTTP HTTP/HTTPS requests and responses logger
Usage: frida -U -f XXX -l android-okhttp-logger.js --no-pause
Credit: M4v3r1ck
This script will add HttpLoggingInterceptor at OkHttpClient, so the HttpLoggingInterceptor will print all requests and responses.
This strategy does not matter if you are doing TLS Pinning bypass
Link:
https://github.com/square/okhttp/tree/master/okhttp-logging-interceptor
*/
setTimeout(function()
{
Java.perform(() =>
{
console.log('');
console.log('======');
console.log('[#] Android OKHttp logging by M4v3r1ck [#]');
console.log('======');
//Create a new instance of HttpLoggingInterceptor class
function getInterceptor()
{
try
{
const HttpLoggingInterceptor = Java.use('okhttp3.logging.HttpLoggingInterceptor');
const Level = Java.use('okhttp3.logging.HttpLoggingInterceptor$Level');
const MyLogger = Java.registerClass(
{
name: 'MyLogger',
superClass: Java.use('java.lang.Object'),
implements: [Java.use('okhttp3.logging.HttpLoggingInterceptor$Logger')],
methods:
{
log: [
{
returnType: 'void',
argumentTypes: ['java.lang.String'],
implementation: function(message)
{
console.log(' [LOG] ' + message);
}
}]
},
});
var logInstance = HttpLoggingInterceptor.$new(MyLogger.$new());
//If you want to log at the logcat just change to the line bellow
//var logInstance = HttpLoggingInterceptor.$new();
logInstance.setLevel(Level.BODY.value);
return logInstance;
}
catch (err)
{
console.log("[-] Error creating interceptor")
console.log(err);
console.log(err.stack)
return null;
}
}
try
{
var Builder = Java.use('okhttp3.OkHttpClient$Builder')
var build = Builder.build.overload();
build.implementation = function()
{
console.log('[+] OkHttpClient$Builder ==> Adding log interceptor')
//Add the new interceptor before call the 'build' function
try
{
this.addInterceptor(getInterceptor());
}
catch (err)
{
console.log('[-] OkHttpClient$Builder.addInterceptor error');
//console.log(err);
}
return build.call(this);
}
}
catch (err)
{
console.log('[-] OkHttpClient$Builder error');
console.log(err);
}
});
}, 1000);