Skip to content

Commit

Permalink
Merge branch 'sensepost:master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
StingraySA authored Jun 7, 2024
2 parents b245d79 + d9c989d commit 0cbb307
Show file tree
Hide file tree
Showing 56 changed files with 1,196 additions and 2,805 deletions.
3,142 changes: 594 additions & 2,548 deletions agent/package-lock.json

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "0.0.0",
"description": "Runtime Mobile Exploration",
"private": true,
"type": "module",
"main": "src/index.ts",
"scripts": {
"prepare": "npm run build",
Expand Down Expand Up @@ -30,13 +31,13 @@
"dependencies": {
"frida-java-bridge": "^6",
"frida-objc-bridge": "^7",
"frida-screenshot": "^3",
"macho": "^1"
"frida-screenshot": "^5",
"macho-ts": "^0.1.0"
},
"devDependencies": {
"@types/frida-gum": "^18",
"@types/node": "^17",
"frida-compile": "^10",
"@types/node": "^18",
"frida-compile": "^16",
"tslint": "^6"
}
}
6 changes: 3 additions & 3 deletions agent/src/android/clipboard.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { colors as c } from "../lib/color";
import { colors as c } from "../lib/color.js";
import {
getApplicationContext,
wrapJavaPerform
} from "./lib/libjava";
import { ClipboardManager } from "./lib/types";
} from "./lib/libjava.js";
import { ClipboardManager } from "./lib/types.js";

export const monitor = (): Promise<void> => {
// -- Sample Java
Expand Down
8 changes: 4 additions & 4 deletions agent/src/android/filesystem.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import * as fs from "fs";
import { hexStringToBytes } from "../lib/helpers";
import { IAndroidFilesystem } from "./lib/interfaces";
import { hexStringToBytes } from "../lib/helpers.js";
import { IAndroidFilesystem } from "./lib/interfaces.js";
import {
getApplicationContext,
wrapJavaPerform
} from "./lib/libjava";
} from "./lib/libjava.js";
import {
File,
JavaClass
} from "./lib/types";
} from "./lib/types.js";

export const exists = (path: string): Promise<boolean> => {
// -- Sample Java
Expand Down
2 changes: 1 addition & 1 deletion agent/src/android/general.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { wrapJavaPerform } from "./lib/libjava";
import { wrapJavaPerform } from "./lib/libjava.js";

export const deoptimize = (): Promise<void> => {
return wrapJavaPerform(() => {
Expand Down
18 changes: 9 additions & 9 deletions agent/src/android/heap.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { colors as c } from "../lib/color";
import { colors as c } from "../lib/color.js";
import {
IHeapClassDictionary,
IHeapObject,
IJavaField,
IHeapNormalised
} from "./lib/interfaces";
import { wrapJavaPerform } from "./lib/libjava";
} from "./lib/interfaces.js";
import { wrapJavaPerform } from "./lib/libjava.js";

export let handles: IHeapClassDictionary = {};

Expand Down Expand Up @@ -72,20 +72,20 @@ export const getInstances = (clazz: string): Promise<any[]> => {

export const methods = (handle: number): Promise<string[]> => {
return wrapJavaPerform(() => {
const clazz: Java.Wrapper = getInstance(handle);
const clazz = getInstance(handle);
if (clazz == null) {
return [];
}

return clazz.class.getDeclaredMethods().map((method) => {
return clazz.class.getDeclaredMethods().map((method: any) => {
return method.toGenericString();
});
});
};

export const execute = (handle: number, method: string, returnString: boolean = false): Promise<string | null> => {
return wrapJavaPerform(() => {
const clazz: Java.Wrapper = getInstance(handle);
const clazz = getInstance(handle);

if (clazz == null) {
return;
Expand All @@ -104,13 +104,13 @@ export const execute = (handle: number, method: string, returnString: boolean =

export const fields = (handle: number): Promise<IJavaField[]> => {
return wrapJavaPerform(() => {
const clazz: Java.Wrapper = getInstance(handle);
const clazz = getInstance(handle);

if (clazz == null) {
return;
}

return clazz.class.getDeclaredFields().map((field): IJavaField => {
return clazz.class.getDeclaredFields().map((field: any): IJavaField => {
const fieldName: string = field.getName();
const fieldInstance: Java.Wrapper = clazz.class.getDeclaredField(fieldName);
fieldInstance.setAccessible(true);
Expand All @@ -132,7 +132,7 @@ export const fields = (handle: number): Promise<IJavaField[]> => {

export const evaluate = (handle: number, js: string): Promise<void> => {
return wrapJavaPerform(() => {
const clazz: Java.Wrapper = getInstance(handle);
const clazz = getInstance(handle);

if (clazz == null) {
return;
Expand Down
57 changes: 46 additions & 11 deletions agent/src/android/hooking.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { colors as c } from "../lib/color";
import { IJob } from "../lib/interfaces";
import * as jobs from "../lib/jobs";
import { ICurrentActivityFragment } from "./lib/interfaces";
import { colors as c } from "../lib/color.js";
import { IJob } from "../lib/interfaces.js";
import * as jobs from "../lib/jobs.js";
import { ICurrentActivityFragment } from "./lib/interfaces.js";
import {
getApplicationContext,
R,
wrapJavaPerform
} from "./lib/libjava";
} from "./lib/libjava.js";
import {
Activity,
ActivityClientRecord,
Expand All @@ -16,7 +16,7 @@ import {
PackageManager,
Throwable,
JavaMethodsOverloadsResult,
} from "./lib/types";
} from "./lib/types.js";

enum PatternType {
Regex = 'regex',
Expand Down Expand Up @@ -64,15 +64,36 @@ const getPatternType = (pattern: string): PatternType => {
return PatternType.Klass;
};

export const lazyWatchForPattern = (query: string): void => {
export const lazyWatchForPattern = (query: string, watch: boolean, dargs: boolean, dret: boolean, dbt: boolean): void => {
// TODO: Use param to control interval
let found = false;
const job: IJob = {
identifier: jobs.identifier(),
implementations: [],
type: `notify-class for: ${query}`,
};

// This method loops over all enumerate matches and then calls watch
// with the arguments specified in the parent function
const watchMatches = (matches: Java.EnumerateMethodsMatchGroup[]) => {
matches.forEach(match => {
match.classes.forEach(_class => {
_class.methods.forEach(_method => {
watchMethod(_class.name + "." + _method, job, dargs, dbt, dret);
})
})
})
}

// Check if the pattern is found before starting an interval
javaEnumerate(query).then(matches => {
if (matches.length > 0) {
found = true;
send(`${c.green(query)} is already loaded / available`);
if (watch) {
watchMatches(matches);
jobs.add(job);
}
}
});

Expand All @@ -87,6 +108,10 @@ export const lazyWatchForPattern = (query: string): void => {
if (!found && matches.length > 0) {
send(`${c.green(query)} is now available`);
found = true;
if (watch) {
watchMatches(matches);
jobs.add(job);
}
}

if (found) clearInterval(interval);
Expand Down Expand Up @@ -375,7 +400,12 @@ const watchMethod = (
};

// Push the implementation so that it can be nulled later
job.implementations.push(m);
if (job.implementations) {
job.implementations.push(m);
} else {
job.implementations = [ m ];
}

});
});
};
Expand Down Expand Up @@ -443,7 +473,7 @@ export const getServices = (): Promise<string[]> => {
// not using the helper as we need other variables too
const context = currentApplication.getApplicationContext();

let services = [];
var services: string[] = [];

currentApplication.mLoadedApk.value.mServices.value.values().toArray().map((potentialServices) => {
Java.cast(potentialServices, arrayMap).keySet().toArray().map((service) => {
Expand Down Expand Up @@ -477,7 +507,7 @@ export const getBroadcastReceivers = (): Promise<string[]> => {
GET_RECEIVERS
).receivers.value

let receivers = [];
var receivers: string[] = [];

currentApplication.mLoadedApk.value.mReceivers.value.values().toArray().map((potentialReceivers) => {
Java.cast(potentialReceivers, arrayMap).keySet().toArray().map((receiver) => {
Expand Down Expand Up @@ -540,7 +570,12 @@ export const setReturnValue = (fqClazz: string, filterOverload: string | null, n
};

// record override
job.implementations.push(m);
if (job.implementations) {
job.implementations.push(m);
} else {
job.implementations = [ m ];
}

});

jobs.add(job);
Expand Down
6 changes: 3 additions & 3 deletions agent/src/android/intent.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { colors as c } from "../lib/color";
import { colors as c } from "../lib/color.js";
import {
getApplicationContext,
wrapJavaPerform
} from "./lib/libjava";
import { Intent } from "./lib/types";
} from "./lib/libjava.js";
import { Intent } from "./lib/types.js";

// https://developer.android.com/reference/android/content/Intent.html#FLAG_ACTIVITY_NEW_TASK
const FLAG_ACTIVITY_NEW_TASK = 0x10000000;
Expand Down
14 changes: 7 additions & 7 deletions agent/src/android/keystore.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { colors as c } from "../lib/color";
import { colors as c } from "../lib/color.js";
import {
IKeyStoreDetail,
IKeyStoreEntry
} from "./lib/interfaces";
import { wrapJavaPerform } from "./lib/libjava";
} from "./lib/interfaces.js";
import { wrapJavaPerform } from "./lib/libjava.js";
import {
KeyFactory,
KeyInfo,
KeyStore,
SecretKeyFactory
} from "./lib/types";
import { IJob } from "../lib/interfaces";
import * as jobs from "../lib/jobs";
} from "./lib/types.js";
import { IJob } from "../lib/interfaces.js";
import * as jobs from "../lib/jobs.js";

// Dump entries in the Android Keystore, together with a flag
// indicating if its a key or a certificate.
Expand Down Expand Up @@ -220,9 +220,9 @@ const keystoreGetKey = (ident: string): any | undefined => {
export const watchKeystore = (): void => {
const job: IJob = {
identifier: jobs.identifier(),
implementations: [],
type: "android-keystore-watch",
};
job.implementations = [];

job.implementations.push(keystoreLoad(job.identifier));
job.implementations.push(keystoreGetKey(job.identifier));
Expand Down
2 changes: 1 addition & 1 deletion agent/src/android/monitor.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { wrapJavaPerform } from "./lib/libjava";
import { wrapJavaPerform } from "./lib/libjava.js";

export namespace monitor {
export const stringCanary = (can: string): Promise<void> => {
Expand Down
15 changes: 8 additions & 7 deletions agent/src/android/pinning.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { colors as c } from "../lib/color";
import { qsend } from "../lib/helpers";
import { IJob } from "../lib/interfaces";
import * as jobs from "../lib/jobs";
import { wrapJavaPerform } from "./lib/libjava";
import { colors as c } from "../lib/color.js";
import { qsend } from "../lib/helpers.js";
import { IJob } from "../lib/interfaces.js";
import * as jobs from "../lib/jobs.js";
import { wrapJavaPerform } from "./lib/libjava.js";
import {
ArrayList,
CertificatePinner,
Expand All @@ -11,7 +11,7 @@ import {
SSLContext,
TrustManagerImpl,
X509TrustManager,
} from "./lib/types";
} from "./lib/types.js";


// a simple flag to control if we should be quiet or not
Expand Down Expand Up @@ -367,10 +367,11 @@ export const disable = (q: boolean): void => {

const job: IJob = {
identifier: jobs.identifier(),
implementations: [],
type: "android-sslpinning-disable",
};

job.implementations = [];

job.implementations.push(sslContextEmptyTrustManager(job.identifier));
job.implementations.push(okHttp3CertificatePinnerCheck(job.identifier));
job.implementations.push(okHttp3CertificatePinnerCheckOkHttp(job.identifier));
Expand Down
4 changes: 2 additions & 2 deletions agent/src/android/proxy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { wrapJavaPerform } from "./lib/libjava";
import { colors as c } from "../lib/color";
import { wrapJavaPerform } from "./lib/libjava.js";
import { colors as c } from "../lib/color.js";

export const set = (host: string, port: string): Promise<void> => {
return wrapJavaPerform(() => {
Expand Down
14 changes: 8 additions & 6 deletions agent/src/android/root.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { colors as c } from "../lib/color";
import { IJob } from "../lib/interfaces";
import * as jobs from "../lib/jobs";
import { wrapJavaPerform } from "./lib/libjava";
import { colors as c } from "../lib/color.js";
import { IJob } from "../lib/interfaces.js";
import * as jobs from "../lib/jobs.js";
import { wrapJavaPerform } from "./lib/libjava.js";
import {
File,
IOException,
JavaString,
Runtime
} from "./lib/types";
} from "./lib/types.js";

const commonPaths = [
"/data/local/bin/su",
Expand Down Expand Up @@ -294,10 +294,11 @@ const jailMonkeyBypass = (success: boolean, ident: string): any => {
export const disable = (): void => {
const job: IJob = {
identifier: jobs.identifier(),
implementations: [],
type: "root-detection-disable",
};

job.implementations = [];

job.implementations.push(testKeysCheck(false, job.identifier));
job.implementations.push(execSuCheck(false, job.identifier));
job.implementations.push(fileExistsCheck(false, job.identifier));
Expand All @@ -322,6 +323,7 @@ export const enable = (): void => {
implementations: [],
type: "root-detection-enable",
};
job.implementations = [];

job.implementations.push(testKeysCheck(true, job.identifier));
job.implementations.push(execSuCheck(true, job.identifier));
Expand Down
Loading

0 comments on commit 0cbb307

Please sign in to comment.