mirror of
https://github.com/androguard/androguard.git
synced 2024-11-22 20:50:03 +00:00
Fix crypto js and add the automatic tracing in the db
This commit is contained in:
parent
f8daa928e3
commit
fca5f2eff5
File diff suppressed because it is too large
Load Diff
@ -1,86 +1,142 @@
|
||||
// Ripped from https://github.com/Ch0pin/medusa/ and modified to fit Androguard packets
|
||||
|
||||
colorLog('[+] LOADING ENCRYPTION/CIPHER.JS', {c: Color.Red});
|
||||
colorLog("[+] LOADING ENCRYPTION/CIPHER.JS", { c: Color.Red });
|
||||
|
||||
var cipher = Java.use('javax.crypto.Cipher');
|
||||
var cipher = Java.use("javax.crypto.Cipher");
|
||||
|
||||
|
||||
|
||||
cipher.init.overload('int', 'java.security.Key').implementation = function(mode, key) {
|
||||
var operation = '';
|
||||
cipher.init.overload("int", "java.security.Key").implementation = function (
|
||||
mode,
|
||||
key,
|
||||
) {
|
||||
var operation = "";
|
||||
var algorithm = this.getAlgorithm();
|
||||
|
||||
if(mode == 1)
|
||||
operation = "Encrypting";
|
||||
else if(mode == 2)
|
||||
operation = "Decrypting";
|
||||
if (mode == 1) operation = "Encrypting";
|
||||
else if (mode == 2) operation = "Decrypting";
|
||||
|
||||
agPacket({algorithm: algorithm, operation: operation, mode: mode, key: byteArraytoHexString(key.getEncoded())}).send();
|
||||
agPacket({
|
||||
algorithm: algorithm,
|
||||
operation: operation,
|
||||
mode: mode,
|
||||
key: byteArraytoHexString(key.getEncoded()),
|
||||
}).send();
|
||||
|
||||
return this.init(mode, key);
|
||||
}
|
||||
};
|
||||
|
||||
cipher.init.overload('int', 'java.security.Key', 'java.security.spec.AlgorithmParameterSpec').implementation = function(mode, key, paramsec) {
|
||||
var operation = '';
|
||||
cipher.init.overload(
|
||||
"int",
|
||||
"java.security.Key",
|
||||
"java.security.spec.AlgorithmParameterSpec",
|
||||
).implementation = function (mode, key, paramsec) {
|
||||
var operation = "";
|
||||
var algorithm = this.getAlgorithm();
|
||||
var castedToIv = Java.cast(paramsec, Java.use('javax.crypto.spec.IvParameterSpec'));
|
||||
|
||||
if(mode == 1)
|
||||
operation = "Encrypting";
|
||||
else if(mode == 2)
|
||||
operation = "Decrypting";
|
||||
if (mode == 1) operation = "Encrypting";
|
||||
else if (mode == 2) operation = "Decrypting";
|
||||
|
||||
agPacket({algorithm: algorithm, mode: mode, operation: operation, key: byteArraytoHexString(key.getEncoded()), iv: byteArraytoHexString(castedToIv.getIV())}).send();
|
||||
return this.init(mode, key, paramsec);
|
||||
}
|
||||
agPacket({
|
||||
algorithm: algorithm,
|
||||
mode: mode,
|
||||
operation: operation,
|
||||
key: byteArraytoHexString(key.getEncoded()),
|
||||
iv: paramsec,
|
||||
}).send();
|
||||
|
||||
return this.init(mode, key, paramsec);
|
||||
};
|
||||
|
||||
|
||||
cipher.init.overload('int', 'java.security.Key', 'java.security.AlgorithmParameters', 'java.security.SecureRandom').implementation = function(mode, key, paramsec, secRnd){
|
||||
var operation = '';
|
||||
cipher.init.overload(
|
||||
"int",
|
||||
"java.security.Key",
|
||||
"java.security.AlgorithmParameters",
|
||||
"java.security.SecureRandom",
|
||||
).implementation = function (mode, key, paramsec, secRnd) {
|
||||
var operation = "";
|
||||
var algorithm = this.getAlgorithm();
|
||||
var castedToIv = Java.cast(paramsec, Java.use('javax.crypto.spec.IvParameterSpec'));
|
||||
|
||||
if(mode == 1)
|
||||
operation = "Encrypting";
|
||||
else if(mode == 2)
|
||||
operation = "Decrypting";
|
||||
|
||||
agPacket({algorithm: algorithm, mode: mode, operation: operation, key: byteArraytoHexString(key.getEncoded()), iv: byteArraytoHexString(castedToIv.getIV())}).send();
|
||||
return this.init(mode, key, paramsec, secRnd);
|
||||
}
|
||||
if (mode == 1) operation = "Encrypting";
|
||||
else if (mode == 2) operation = "Decrypting";
|
||||
|
||||
agPacket({
|
||||
algorithm: algorithm,
|
||||
mode: mode,
|
||||
operation: operation,
|
||||
key: byteArraytoHexString(key.getEncoded()),
|
||||
iv: paramsec,
|
||||
secRnd: secRnd,
|
||||
}).send();
|
||||
return this.init(mode, key, paramsec, secRnd);
|
||||
};
|
||||
|
||||
//DO FINAL--------------------------------
|
||||
|
||||
cipher.doFinal.overload('[B').implementation = function(byteArray) {
|
||||
cipher.doFinal.overload("[B").implementation = function (byteArray) {
|
||||
var ret = this.doFinal(byteArray);
|
||||
agPacket({in: byteArray, ret: ret}).send();
|
||||
agPacket({
|
||||
in: byteArraytoHexString(byteArray),
|
||||
ret: byteArraytoHexString(ret),
|
||||
}).send();
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
cipher.doFinal.overload('[B', 'int').implementation = function(byteArray, outputOffset) {
|
||||
cipher.doFinal.overload("[B", "int").implementation = function (
|
||||
byteArray,
|
||||
outputOffset,
|
||||
) {
|
||||
var ret = this.doFinal(byteArray, outputOffset);
|
||||
agPacket({in: byteArray, outputOffset: outputOffset, ret: ret}).send();
|
||||
agPacket({ in: byteArray, outputOffset: outputOffset, ret: ret }).send();
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
cipher.doFinal.overload('[B', 'int', 'int').implementation = function(byteArray, outputOffset, inputlen) {
|
||||
cipher.doFinal.overload("[B", "int", "int").implementation = function (
|
||||
byteArray,
|
||||
outputOffset,
|
||||
inputlen,
|
||||
) {
|
||||
var ret = this.doFinal(byteArray, outputOffset, inputlen);
|
||||
agPacket({in: byteArray, outputOffset: outputOffset, inputlen: inputlen, ret: ret}).send();
|
||||
agPacket({
|
||||
in: byteArray,
|
||||
outputOffset: outputOffset,
|
||||
inputlen: inputlen,
|
||||
ret: ret,
|
||||
}).send();
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
cipher.doFinal.overload('[B', 'int', 'int', '[B').implementation = function(byteArray, outputOffset, inputlen, output) {
|
||||
cipher.doFinal.overload("[B", "int", "int", "[B").implementation = function (
|
||||
byteArray,
|
||||
outputOffset,
|
||||
inputlen,
|
||||
output,
|
||||
) {
|
||||
var ret = this.doFinal(byteArray, outputOffset, inputlen, output);
|
||||
agPacket({in: byteArray, out: output, outputOffset: outputOffset, inputlen: inputlen, ret: ret}).send();
|
||||
agPacket({
|
||||
in: byteArray,
|
||||
out: output,
|
||||
outputOffset: outputOffset,
|
||||
inputlen: inputlen,
|
||||
ret: ret,
|
||||
}).send();
|
||||
return ret;
|
||||
}
|
||||
};
|
||||
|
||||
cipher.doFinal.overload('[B', 'int', 'int', '[B', 'int').implementation = function(byteArray, outputOffset, inputlen, output, outoffset) {
|
||||
var ret = this.doFinal(byteArray, outputOffset ,inputlen, output, outoffset);
|
||||
agPacket({in: byteArray, out: output, outputOffset: outputOffset, inputlen: inputlen, outoffset: outoffset, ret: ret}).send();
|
||||
return ret;
|
||||
}
|
||||
cipher.doFinal.overload("[B", "int", "int", "[B", "int").implementation =
|
||||
function (byteArray, outputOffset, inputlen, output, outoffset) {
|
||||
var ret = this.doFinal(
|
||||
byteArray,
|
||||
outputOffset,
|
||||
inputlen,
|
||||
output,
|
||||
outoffset,
|
||||
);
|
||||
agPacket({
|
||||
in: byteArray,
|
||||
out: output,
|
||||
outputOffset: outputOffset,
|
||||
inputlen: inputlen,
|
||||
outoffset: outoffset,
|
||||
ret: ret,
|
||||
}).send();
|
||||
return ret;
|
||||
};
|
||||
|
57
androguard/pentest/modules/encryption/keystore.js
Normal file
57
androguard/pentest/modules/encryption/keystore.js
Normal file
@ -0,0 +1,57 @@
|
||||
// Ripped from https://github.com/Ch0pin/medusa/ and modified to fit Androguard packets
|
||||
|
||||
colorLog("[+] LOADING ENCRYPTION/KEYSTORE.JS", { c: Color.Red });
|
||||
|
||||
var keystore = Java.use("java.security.KeyStore");
|
||||
|
||||
keystore.containsAlias.overload("java.lang.String").implementation = function (
|
||||
alias,
|
||||
) {
|
||||
var ret = this.containsAlias(alias);
|
||||
agPacket({
|
||||
alias: alias,
|
||||
ret: ret,
|
||||
}).send();
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
keystore.getKey.overload("java.lang.String", "[C").implementation = function (
|
||||
alias,
|
||||
password,
|
||||
) {
|
||||
var ret = this.getKey(alias, password);
|
||||
agPacket({
|
||||
alias: alias,
|
||||
password: password,
|
||||
algorithm: ret.getAlgorithm(),
|
||||
encoded: ret.getEncoded(),
|
||||
ret: ret,
|
||||
}).send();
|
||||
|
||||
return ret;
|
||||
};
|
||||
|
||||
keystore.load.overload("java.io.InputStream", "[C").implementation = function (
|
||||
stream,
|
||||
charArray,
|
||||
) {
|
||||
/* sometimes this happen, I have no idea why, tho... */
|
||||
if (stream == null) {
|
||||
/* just to avoid interfering with app's flow */
|
||||
this.load(stream, charArray);
|
||||
return;
|
||||
}
|
||||
|
||||
var hexString = readStreamToHex(stream);
|
||||
|
||||
agPacket({
|
||||
certType: this.getType(),
|
||||
password: charArray,
|
||||
cert: hexString,
|
||||
}).send();
|
||||
|
||||
/* call the original implementation of 'load' */
|
||||
this.load(stream, charArray);
|
||||
/* no need to return anything */
|
||||
};
|
14
androguard/pentest/modules/preferences/preferences.js
Normal file
14
androguard/pentest/modules/preferences/preferences.js
Normal file
@ -0,0 +1,14 @@
|
||||
// Ripped from https://github.com/Ch0pin/medusa/ and modified to fit Androguard packets
|
||||
|
||||
colorLog("[+] LOADING PREFERENCES/PREFERENCES.JS", { c: Color.Red });
|
||||
|
||||
var ContextWrapper = Java.use("android.content.ContextWrapper");
|
||||
|
||||
ContextWrapper.getSharedPreferences.overload(
|
||||
"java.lang.String",
|
||||
"int",
|
||||
).implementation = function (var0, var1) {
|
||||
var sharedPreferences = this.getSharedPreferences(var0, var1);
|
||||
agPacket({ name: var0, mode: var1, ret: sharedPreferences }).send();
|
||||
return sharedPreferences;
|
||||
};
|
Loading…
Reference in New Issue
Block a user