📦
2289 /agent/ssl_log.js.map
3133 /agent/ssl_log.js
2755 /agent/android/android_agent.js.map
3270 /agent/android/android_agent.js
937 /agent/android/android_java_tls_libs.js.map
1150 /agent/android/android_java_tls_libs.js
4361 /agent/android/bouncycastle.js.map
5111 /agent/android/bouncycastle.js
3715 /agent/android/conscrypt.js.map
6193 /agent/android/conscrypt.js
1654 /agent/android/cronet_android.js.map
2008 /agent/android/cronet_android.js
1347 /agent/android/gnutls_android.js.map
1401 /agent/android/gnutls_android.js
982 /agent/android/mbedTLS_android.js.map
1248 /agent/android/mbedTLS_android.js
1348 /agent/android/nss_android.js.map
1512 /agent/android/nss_android.js
1473 /agent/android/openssl_boringssl_android.js.map
1958 /agent/android/openssl_boringssl_android.js
3090 /agent/android/wolfssl_android.js.map
3892 /agent/android/wolfssl_android.js
1881 /agent/ios/ios_agent.js.map
2134 /agent/ios/ios_agent.js
2328 /agent/ios/openssl_boringssl_ios.js.map
3425 /agent/ios/openssl_boringssl_ios.js
1341 /agent/linux/gnutls_linux.js.map
1399 /agent/linux/gnutls_linux.js
2398 /agent/linux/linux_agent.js.map
2791 /agent/linux/linux_agent.js
982 /agent/linux/matrixssl_linux.js.map
1251 /agent/linux/matrixssl_linux.js
951 /agent/linux/mbedTLS_linux.js.map
1214 /agent/linux/mbedTLS_linux.js
3627 /agent/linux/nss_linux.js.map
4666 /agent/linux/nss_linux.js
1829 /agent/linux/openssl_boringssl_linux.js.map
1919 /agent/linux/openssl_boringssl_linux.js
3083 /agent/linux/wolfssl_linux.js.map
3886 /agent/linux/wolfssl_linux.js
1891 /agent/macos/macos_agent.js.map
2262 /agent/macos/macos_agent.js
1875 /agent/macos/openssl_boringssl_macos.js.map
2619 /agent/macos/openssl_boringssl_macos.js
2650 /agent/shared/pattern_based_hooking.js.map
3607 /agent/shared/pattern_based_hooking.js
10092 /agent/shared/shared_functions.js.map
12573 /agent/shared/shared_functions.js
397 /agent/shared/shared_structures.js.map
201 /agent/shared/shared_structures.js
2605 /agent/ssl_lib/cronet.js.map
3559 /agent/ssl_lib/cronet.js
6803 /agent/ssl_lib/gnutls.js.map
7899 /agent/ssl_lib/gnutls.js
2725 /agent/ssl_lib/java_ssl_libs.js.map
5235 /agent/ssl_lib/java_ssl_libs.js
5910 /agent/ssl_lib/matrixssl.js.map
7056 /agent/ssl_lib/matrixssl.js
6966 /agent/ssl_lib/mbedTLS.js.map
7038 /agent/ssl_lib/mbedTLS.js
31291 /agent/ssl_lib/nss.js.map
52013 /agent/ssl_lib/nss.js
13159 /agent/ssl_lib/openssl_boringssl.js.map
15856 /agent/ssl_lib/openssl_boringssl.js
4770 /agent/ssl_lib/wolfssl.js.map
5718 /agent/ssl_lib/wolfssl.js
14214 /agent/util/anti_root.js.map
18094 /agent/util/anti_root.js
550 /agent/util/log.js.map
290 /agent/util/log.js
1563 /agent/util/process_infos.js.map
1820 /agent/util/process_infos.js
974 /agent/windows/gnutls_windows.js.map
1035 /agent/windows/gnutls_windows.js
1019 /agent/windows/matrixssl_windows.js.map
1102 /agent/windows/matrixssl_windows.js
982 /agent/windows/mbedTLS_windows.js.map
1248 /agent/windows/mbedTLS_windows.js
1222 /agent/windows/nss_windows.js.map
1459 /agent/windows/nss_windows.js
1264 /agent/windows/openssl_boringssl_windows.js.map
1558 /agent/windows/openssl_boringssl_windows.js
13147 /agent/windows/sspi.js.map
16471 /agent/windows/sspi.js
2382 /agent/windows/windows_agent.js.map
2886 /agent/windows/windows_agent.js
1292 /agent/windows/wolfssl_windows.js.map
1426 /agent/windows/wolfssl_windows.js
✄
{"version":3,"file":"ssl_log.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/ssl_log.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,EAAE,sBAAsB,EAAE,MAAM,oBAAoB,CAAC;AAC5D,OAAO,EAAE,wBAAwB,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO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EAAE,KAAK,CAAC,EAAE;IACjD,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC;AAC9B,CAAC,CAAC,CAAC;AACH,mBAAmB,CAAC,IAAI,EAAE,CAAC,CAAA,KAAK;AAGhC;;;;;;;EAOE;AAGF,MAAM,UAAU,UAAU;IACtB,OAAO,OAAO,CAAC;AACnB,CAAC;AAED,uDAAuD;AACvD,MAAM,UAAU,iBAAiB;IAC7B,gHAAgH;IAChH,OAAO,QAAQ,CAAC,MAAM,GAAG,EAAE,CAAC;AAChC,CAAC;AAGD,SAAS,sBAAsB;IAC3B,IAAG,SAAS,EAAE,EAAC;QACX,GAAG,CAAC,2BAA2B,CAAC,CAAA;QAChC,0BAA0B,EAAE,CAAA;KAC/B;SAAK,IAAG,SAAS,EAAE,EAAC;QACjB,GAAG,CAAC,2BAA2B,CAAC,CAAA;QAChC,IAAG,SAAS,EAAC;YACT,GAAG,CAAC,2BAA2B,CAAC,CAAC;YACjC,iBAAiB,EAAE,CAAC;SACvB;QACD,0BAA0B,EAAE,CAAA;KAC/B;SAAK,IAAG,OAAO,EAAE,EAAC;QACf,GAAG,CAAC,yBAAyB,CAAC,CAAA;QAC9B,wBAAwB,EAAE,CAAA;KAC7B;SAAK,IAAG,KAAK,EAAE,EAAC;QACb,GAAG,CAAC,uBAAuB,CAAC,CAAA;QAC5B,sBAAsB,EAAE,CAAA;KAC3B;SAAK,IAAG,OAAO,EAAE,EAAC;QACf,GAAG,CAAC,yBAAyB,CAAC,CAAA;QAC9B,wBAAwB,EAAE,CAAA;KAC7B;SAAI;QACD,GAAG,CAAC,qCAAqC,CAAC,CAAA;QAC1C,GAAG,CAAC,0HAA0H,CAAC,CAAA;KAClI;AAEL,CAAC;AAED,sBAAsB,EAAE,CAAA"}
✄
import { load_android_hooking_agent } from "./android/android_agent.js";
import { load_ios_hooking_agent } from "./ios/ios_agent.js";
import { load_macos_hooking_agent } from "./macos/macos_agent.js";
import { load_linux_hooking_agent } from "./linux/linux_agent.js";
import { load_windows_hooking_agent } from "./windows/windows_agent.js";
import { isWindows, isLinux, isAndroid, isiOS, isMacOS } from "./util/process_infos.js";
import { anti_root_execute } from "./util/anti_root.js";
import { log } from "./util/log.js";
// global address which stores the addresses of the hooked modules which aren't loaded via the dynamic loader
global.init_addresses = {};
global.global_counter = 0;
//@ts-ignore
export let offsets = "{OFFSETS}";
//@ts-ignore
export let experimental = false;
//@ts-ignore
export let anti_root = false;
//@ts-ignore
export let enable_default_fd = false;
//@ts-ignore
export let patterns = "{PATTERNS}";
/*
This way we are providing boolean values from the commandline directly to our frida script
*/
send("defaultFD");
const enable_default_fd_state = recv('defaultFD', value => {
    //console.log("value.payload: "+value.payload)
    enable_default_fd = value.payload;
});
enable_default_fd_state.wait();
send("experimental");
const exp_recv_state = recv('experimental', value => {
    experimental = value.payload;
});
exp_recv_state.wait();
send("anti");
const antiroot_recv_state = recv('antiroot', value => {
    anti_root = value.payload;
});
antiroot_recv_state.wait(); /* */
/*

create the TLS library for your first prototpye as a lib in ./ssl_lib and than extend this class for the OS where this new lib was tested.

Further keep in mind, that properties of an class only visible inside the Interceptor-onEnter/onLeave scope when they are static.
As an alternative you could make a local variable inside the calling functions which holds an reference to the class property.

*/
export function getOffsets() {
    return offsets;
}
// Function to check if the patterns have been replaced
export function isPatternReplaced() {
    // The default placeholder is quite short, so if the length exceeds a certain threshold, we assume it's replaced
    return patterns.length > 10;
}
function load_os_specific_agent() {
    if (isWindows()) {
        log('Running Script on Windows');
        load_windows_hooking_agent();
    }
    else if (isAndroid()) {
        log('Running Script on Android');
        if (anti_root) {
            log('Applying anti root checks');
            anti_root_execute();
        }
        load_android_hooking_agent();
    }
    else if (isLinux()) {
        log('Running Script on Linux');
        load_linux_hooking_agent();
    }
    else if (isiOS()) {
        log('Running Script on iOS');
        load_ios_hooking_agent();
    }
    else if (isMacOS()) {
        log('Running Script on MacOS');
        load_macos_hooking_agent();
    }
    else {
        log('Running Script on unknown plattform');
        log("Error: not supported plattform!\nIf you want to have support for this plattform please make an issue at our github page.");
    }
}
load_os_specific_agent();
✄
{"version":3,"file":"android_agent.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/android/android_agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAqB,MAAM,gCAAgC,CAAC;AAC3F,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAC1G,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,YAAY,EAAC,MAAM,4BAA4B,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD,IAAI,cAAc,GAAG,OAAO,CAAC;AAC7B,IAAI,WAAW,GAAkB,cAAc,EAAE,CAAC;AACjD,MAAc,CAAC,SAAS,GAAG,EAAE,CAAC;AAE/B,MAAM,CAAC,MAAM,cAAc,GAAG,MAAM,CAAA;AAEpC,SAAS,kBAAkB;IACvB,YAAY,EAAE,CAAC;AACnB,CAAC;AAED,SAAS,2BAA2B,CAAC,sBAA0E,EAAE,YAAqB;IAClI,IAAI;QACJ,MAAM,WAAW,GAAG,eAAe,CAAA;QACnC,MAAM,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAA;QACrE,IAAI,KAAK,KAAK,SAAS,EAAC;YACpB,MAAM,mCAAmC,CAAA;SAC5C;QAED,IAAI,U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EAAE,sBAAsB,EAAC,WAAW,EAAC,SAAS,EAAC,YAAY,CAAC,CAAA;AAEjG,CAAC;AAGD,MAAM,UAAU,0BAA0B;IACtC,sBAAsB,CAAC,cAAc,CAAC,GAAG;QACrC,CAAC,gBAAgB,EAAE,qBAAqB,CAAC,cAAc,CAAC,CAAC;QACzD,CAAC,cAAc,EAAE,qBAAqB,CAAC,cAAc,CAAC,CAAC;QACvD,CAAC,gBAAgB,EAAE,qBAAqB,CAAC,cAAc,CAAC,CAAC;QACzD,CAAC,iBAAiB,EAAE,qBAAqB,CAAC,cAAc,CAAC,CAAC;QAC1D,CAAC,kBAAkB,EAAE,qBAAqB,CAAC,eAAe,CAAC,CAAC;QAC5D,CAAC,qBAAqB,EAAC,qBAAqB,CAAC,WAAW,CAAC,CAAC;QAC1D,CAAC,kBAAkB,EAAE,qBAAqB,CAAC,eAAe,CAAC,CAAC;KAAC,CAAC;IAElE,kBAAkB,EAAE,CAAC;IACrB,4BAA4B,CAAC,sBAAsB,EAAE,IAAI,CAAC,CAAC;IAC3D,2BAA2B,CAAC,sBAAsB,EAAE,KAAK,CAAC,CAAC;AAC/D,CAAC"}
✄
import { module_library_mapping } from "../shared/shared_structures.js";
import { getModuleNames, ssl_library_loader, invokeHookingFunction } from "../shared/shared_functions.js";
import { log, devlog } from "../util/log.js";
import { gnutls_execute } from "./gnutls_android.js";
import { wolfssl_execute } from "./wolfssl_android.js";
import { nss_execute } from "./nss_android.js";
import { mbedTLS_execute } from "./mbedTLS_android.js";
import { boring_execute } from "./openssl_boringssl_android.js";
import { java_execute } from "./android_java_tls_libs.js";
import { cronet_execute } from "./cronet_android.js";
var plattform_name = "linux";
var moduleNames = getModuleNames();
global.addresses = {};
export const socket_library = "libc";
function install_java_hooks() {
    java_execute();
}
function hook_Android_Dynamic_Loader(module_library_mapping, is_base_hook) {
    try {
        const regex_libdl = /.*libdl.*\.so/;
        const libdl = moduleNames.find(element => element.match(regex_libdl));
        if (libdl === undefined) {
            throw "Android Dynamic loader not found!";
        }
        let dl_exports = Process.getModuleByName(libdl).enumerateExports();
        var dlopen = "dlopen";
        for (var ex of dl_exports) {
            if (ex.name === "android_dlopen_ext") {
                dlopen = "android_dlopen_ext";
                break;
            }
        }
        Interceptor.attach(Module.getExportByName(libdl, dlopen), {
            onEnter: function (args) {
                this.moduleName = args[0].readCString();
            },
            onLeave: function (retval) {
                if (this.moduleName != undefined) {
                    for (let map of module_library_mapping[plattform_name]) {
                        let regex = map[0];
                        let func = map[1];
                        if (regex.test(this.moduleName)) {
                            log(`${this.moduleName} was loaded & will be hooked on Android!`);
                            func(this.moduleName, is_base_hook);
                        }
                    }
                }
            }
        });
        console.log(`[*] Android dynamic loader hooked.`);
    }
    catch (error) {
        devlog("Dynamic loader error: " + error);
        log("No dynamic loader present for hooking on Android.");
    }
}
function hook_native_Android_SSL_Libs(module_library_mapping, is_base_hook) {
    ssl_library_loader(plattform_name, module_library_mapping, moduleNames, "Android", is_base_hook);
}
export function load_android_hooking_agent() {
    module_library_mapping[plattform_name] = [
        [/.*libssl_sb.so/, invokeHookingFunction(boring_execute)],
        [/.*libssl\.so/, invokeHookingFunction(boring_execute)],
        [/.*cronet.*\.so/, invokeHookingFunction(cronet_execute)],
        [/.*libgnutls\.so/, invokeHookingFunction(gnutls_execute)],
        [/.*libwolfssl\.so/, invokeHookingFunction(wolfssl_execute)],
        [/.*libnspr[0-9]?\.so/, invokeHookingFunction(nss_execute)],
        [/libmbedtls\.so.*/, invokeHookingFunction(mbedTLS_execute)]
    ];
    install_java_hooks();
    hook_native_Android_SSL_Libs(module_library_mapping, true);
    hook_Android_Dynamic_Loader(module_library_mapping, false);
}
✄
{"version":3,"file":"android_java_tls_libs.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/android/android_java_tls_libs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AAGvD,MAAM,OAAO,gBAAiB,SAAQ,QAAQ;IAG1C,0BAA0B;QACtB,IAAI,IAAI,CAAC,SAAS,EAAE;YAChB,UAAU,CAAC;gBAEP,IAAI,CAAC,OAAO,CAAC;oBAET,4BAA4B;oBAC5B,IAAI;wBACA,oFAAoF;wBACpF,IAAI,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,oDAAoD,CAAC,CAAA;wBAC7E,GAAG,CAAC,qCAAqC,CAAC,CAAA;wBAC1C,cAAc,EAAE,CAAA;qBACnB;oBAAC,OAAO,KAAK,EAAE;wBACZ,2BAA2B;qBAC9B;gBACL,CAAC,CAAC,CAAC;YACP,CAAC,EAAE,CAAC,CAAC,CAAC;SACT;IACL,CAAC;IAGD,aAAa;QACT,IAAI,CAAC,0BAA0B,EAAE,CAAC;QAClC,IAAI,CAAC,kBAAkB,EAAE,CAAC;IAC9B,CAAC;CAEJ;AAGD,MAAM,UAAU,YAAY;IACxB,IAAI,QAAQ,GAAG,IAAI,gBAAgB,EAAE,CAAC;IACtC,QAAQ,CAAC,aAAa,EAAE,CAAC;AAC7B,CAAC"}
✄
import { log } from "../util/log.js";
import { execute as bouncy_execute } from "./bouncycastle.js";
import { SSL_Java } from "../ssl_lib/java_ssl_libs.js";
export class SSL_Java_Android extends SSL_Java {
    install_java_android_hooks() {
        if (Java.available) {
            setTimeout(function () {
                Java.perform(function () {
                    // Bouncycastle/Spongycastle
                    try {
                        //If we can load a class of spongycastle, we know its present and we have to hook it
                        var testLoad = Java.use("org.spongycastle.jsse.provider.ProvSSLSocketDirect");
                        log("Bouncycastle/Spongycastle detected.");
                        bouncy_execute();
                    }
                    catch (error) {
                        //On error, just do nothing
                    }
                });
            }, 0);
        }
    }
    execute_hooks() {
        this.install_java_android_hooks();
        this.install_java_hooks();
    }
}
export function java_execute() {
    var java_ssl = new SSL_Java_Android();
    java_ssl.execute_hooks();
}
✄
{"version":3,"file":"bouncycastle.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/android/bouncycastle.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,YAAY,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAChI,MAAM,UAAU,OAAO;IACnB,UAAU,CAAC;QACP,IAAI,CAAC,OAAO,CAAC;YAET,0FAA0F;YAC1F,gEAAgE;YAChE,IAAI,aAAa,GAAG,IAAI,CAAC,GAAG,CAAC,kEAAkE,CAAC,CAAA;YAChG,aAAa,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,cAAc,GAAG,UAAU,GAAQ,EAAE,MAAW,EAAE,GAAQ;gBACvG,IAAI,MAAM,GAAkB,EAAE,CAAC;gBAC/B,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,EAAE,CAAC,EAAE;oBAC1B,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,CAAC;iBAC9B;gBACD,IAAI,OAAO,GAA2B,EAAE,CAAA;gBACxC,OAAO,CAAC,aAAa,CAAC,GAAG,SAAS,CAAA;gBAClC,OAAO,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,YAAY,EAAE,CAAA;gBACtD,OAAO,CAAC,UAAU,CAAC,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,OAAO,EAAE,CAAA;gBACjD,IAAI,YAAY,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,eAAe,EAAE,CAAC,UAAU,EAAE,CAAA;gBACnE,IAAI,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,cAAc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,CAAA;gBACb,OAAO,IAAI,CAAC,uBAAuB,CAAC,CAAC,CAAC,CAAA;YAC1C,CAAC,CAAA;QAEL,CAAC,CAAC,CAAA;IACN,CAAC,EAAE,CAAC,CAAC,CAAC;AAEV,CAAC"}
✄
import { log } from "../util/log.js";
import { byteArrayToString, byteArrayToNumber, getAttribute, reflectionByteArrayToString } from "../shared/shared_functions.js";
export function execute() {
    setTimeout(function () {
        Java.perform(function () {
            //Hook the inner class "AppDataOutput/input" of ProvSSLSocketDirect, so we can access the 
            //socket information in its outer class by accessing this.this$0
            var appDataOutput = Java.use("org.spongycastle.jsse.provider.ProvSSLSocketDirect$AppDataOutput");
            appDataOutput.write.overload('[B', 'int', 'int').implementation = function (buf, offset, len) {
                var result = [];
                for (var i = 0; i < len; ++i) {
                    result.push(buf[i] & 0xff);
                }
                var message = {};
                message["contentType"] = "datalog";
                message["src_port"] = this.this$0.value.getLocalPort();
                message["dst_port"] = this.this$0.value.getPort();
                var localAddress = this.this$0.value.getLocalAddress().getAddress();
                var inetAddress = this.this$0.value.getInetAddress().getAddress();
                if (localAddress.length == 4) {
                    message["src_addr"] = byteArrayToNumber(localAddress);
                    message["dst_addr"] = byteArrayToNumber(inetAddress);
                    message["ss_family"] = "AF_INET";
                }
                else {
                    message["src_addr"] = byteArrayToString(localAddress);
                    message["dst_addr"] = byteArrayToString(inetAddress);
                    message["ss_family"] = "AF_INET6";
                }
                message["ssl_session_id"] = byteArrayToString(this.this$0.value.getConnection().getSession().getId());
                //log(message["ssl_session_id"])
                message["function"] = "writeApplicationData";
                send(message, result);
                return this.write(buf, offset, len);
            };
            var appDataInput = Java.use("org.spongycastle.jsse.provider.ProvSSLSocketDirect$AppDataInput");
            appDataInput.read.overload('[B', 'int', 'int').implementation = function (buf, offset, len) {
                var bytesRead = this.read(buf, offset, len);
                var result = [];
                for (var i = 0; i < bytesRead; ++i) {
                    result.push(buf[i] & 0xff);
                }
                var message = {};
                message["contentType"] = "datalog";
                message["ss_family"] = "AF_INET";
                message["src_port"] = this.this$0.value.getPort();
                message["dst_port"] = this.this$0.value.getLocalPort();
                var localAddress = this.this$0.value.getLocalAddress().getAddress();
                var inetAddress = this.this$0.value.getInetAddress().getAddress();
                if (localAddress.length == 4) {
                    message["src_addr"] = byteArrayToNumber(inetAddress);
                    message["dst_addr"] = byteArrayToNumber(localAddress);
                    message["ss_family"] = "AF_INET";
                }
                else {
                    message["src_addr"] = byteArrayToString(inetAddress);
                    message["dst_addr"] = byteArrayToString(localAddress);
                    message["ss_family"] = "AF_INET6";
                }
                message["ssl_session_id"] = byteArrayToString(this.this$0.value.getConnection().getSession().getId());
                log(message["ssl_session_id"]);
                message["function"] = "readApplicationData";
                send(message, result);
                return bytesRead;
            };
            //Hook the handshake to read the client random and the master key
            var ProvSSLSocketDirect = Java.use("org.spongycastle.jsse.provider.ProvSSLSocketDirect");
            ProvSSLSocketDirect.notifyHandshakeComplete.implementation = function (x) {
                var protocol = this.protocol.value;
                var securityParameters = protocol.securityParameters.value;
                var clientRandom = securityParameters.clientRandom.value;
                var masterSecretObj = getAttribute(securityParameters, "masterSecret");
                //The key is in the AbstractTlsSecret, so we need to access the superclass to get the field
                var clazz = Java.use("java.lang.Class");
                var masterSecretRawField = Java.cast(masterSecretObj.getClass(), clazz).getSuperclass().getDeclaredField("data");
                masterSecretRawField.setAccessible(true);
                var masterSecretReflectArray = masterSecretRawField.get(masterSecretObj);
                var message = {};
                message["contentType"] = "keylog";
                message["keylog"] = "CLIENT_RANDOM " + byteArrayToString(clientRandom) + " " + reflectionByteArrayToString(masterSecretReflectArray);
                send(message);
                return this.notifyHandshakeComplete(x);
            };
        });
    }, 0);
}
✄
{"version":3,"file":"conscrypt.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/android/conscrypt.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAA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,CAAC,6CAA6C,CAAC,CAAA;4BACrD,QAAQ,CAAC,mBAAmB,EAAE,CAAA;wBAClC,CAAC,CAAA;qBACJ;iBACA;aACJ;YAAA,OAAO,KAAK,EAAE;gBACX,MAAM,CAAC,6CAA6C,CAAC,CAAA;gBACrD,IAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,QAAQ,CAAC,kCAAkC,CAAC,EAAC;oBAC9D,MAAM,CAAC,qBAAqB,GAAC,KAAK,CAAC,CAAC;iBACvC;gBACD,qCAAqC;aACxC;SAEJ;IACL,CAAC,CAAC,CAAA;AAIN,CAAC"}
✄
import { devlog, log } from "../util/log.js";
import { getAndroidVersion } from "../util/process_infos.js";
function findProviderInstallerImplFromClassloaders(currentClassLoader, backupImplementation) {
    var providerInstallerImpl = null;
    var classLoaders = Java.enumerateClassLoadersSync();
    for (var cl of classLoaders) {
        try {
            var classFactory = Java.ClassFactory.get(cl);
            providerInstallerImpl = classFactory.use("com.google.android.gms.common.security.ProviderInstallerImpl");
            break;
        }
        catch (error) {
            devlog("Error in hooking ProviderInstallerImpl (findProviderInstallerImplFromClassloaders):");
            devlog("[-] Error message: " + error);
            providerInstallerImpl = null;
            // On error we return null
        }
    }
    var version = getAndroidVersion();
    if (version <= 12) {
        //Revert the implementation to avoid an infinitloop of "Loadclass"
        currentClassLoader.loadClass.overload("java.lang.String").implementation = backupImplementation;
    }
    return providerInstallerImpl;
}
function findProviderInstallerFromClassloaders(currentClassLoader, backupImplementation) {
    var providerInstaller = null;
    var classLoaders = Java.enumerateClassLoadersSync();
    for (var cl of classLoaders) {
        try {
            var classFactory = Java.ClassFactory.get(cl);
            providerInstaller = classFactory.use("com.google.android.gms.security.ProviderInstaller");
            break;
        }
        catch (error) {
            devlog("Error in hooking ProviderInstallerImpl (findProviderInstallerFromClassloaders):");
            if (!error.toString().includes("java.lang.ClassNotFoundException")) {
                devlog("[-] Error message: " + error);
            }
            providerInstaller = null;
            // On error we return null
        }
    }
    var version = getAndroidVersion();
    //log("is here the error")
    //log(typeof version)
    if (version <= 12) {
        //Revert the implementation to avoid an infinitloop of "Loadclass"
        currentClassLoader.loadClass.overload("java.lang.String").implementation = backupImplementation;
    }
    return providerInstaller;
}
export function execute() {
    //We have to hook multiple entrypoints: ProviderInstallerImpl and ProviderInstaller
    Java.perform(function () {
        //Part one: Hook ProviderInstallerImpl
        var javaClassLoader = Java.use("java.lang.ClassLoader");
        var backupImplementation = javaClassLoader.loadClass.overload("java.lang.String").implementation;
        //The classloader for ProviderInstallerImpl might not be present on startup, so we hook the loadClass method.  
        javaClassLoader.loadClass.overload("java.lang.String").implementation = function (className) {
            let retval = this.loadClass(className);
            if (className.endsWith("ProviderInstallerImpl")) {
                log("Process is loading ProviderInstallerImpl");
                var providerInstallerImpl = findProviderInstallerImplFromClassloaders(javaClassLoader, backupImplementation);
                if (providerInstallerImpl === null) {
                    log("ProviderInstallerImpl could not be found, although it has been loaded");
                }
                else {
                    providerInstallerImpl.insertProvider.implementation = function () {
                        log("ProviderinstallerImpl redirection/blocking");
                    };
                }
            }
            return retval;
        };
        //Part two: Hook Providerinstaller
        try {
            var providerInstaller = Java.use("com.google.android.gms.security.ProviderInstaller");
            providerInstaller.installIfNeeded.implementation = function (context) {
                devlog("Providerinstaller redirection/blocking");
            };
            providerInstaller.installIfNeededAsync.implementation = function (context, callback) {
                devlog("ProviderinstallerAsncy redirection/blocking");
                callback.onProviderInstalled();
            };
        }
        catch (error) {
            try {
                // probably class wasn't loaded by the app's main class loader therefore we load it
                var providerInstallerImpl = null;
                var providerInstallerFromClassloder = findProviderInstallerFromClassloaders(javaClassLoader, backupImplementation);
                if (providerInstallerFromClassloder === null) {
                    providerInstallerImpl = findProviderInstallerImplFromClassloaders(javaClassLoader, backupImplementation);
                }
                if (providerInstallerFromClassloder === null && providerInstallerImpl === null || providerInstallerFromClassloder === undefined) {
                    devlog("ProviderInstaller could not be found, although it has been loaded");
                }
                else {
                    if (providerInstallerImpl !== null) {
                        providerInstallerImpl.insertProvider.implementation = function () {
                            devlog("ProviderinstallerImpl redirection/blocking");
                        };
                    }
                    else {
                        providerInstallerFromClassloder.installIfNeeded.implementation = function (context) {
                            devlog("Providerinstaller redirection/blocking");
                        };
                        providerInstallerFromClassloder.installIfNeededAsync.implementation = function (context, callback) {
                            devlog("ProviderinstallerAsync redirection/blocking");
                            callback.onProviderInstalled();
                        };
                    }
                }
            }
            catch (error) {
                devlog("Some error in hooking the Providerinstaller");
                if (!error.toString().includes("java.lang.ClassNotFoundException")) {
                    devlog("[-] Error message: " + error);
                }
                // As it is not available, do nothing
            }
        }
    });
}
✄
{"version":3,"file":"cronet_android.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/android/cronet_android.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAC,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACxE,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAA;AAE3D,MAAM,OAAO,cAAe,SAAQ,MAAM;IAEtC,YAAmB,UAAiB,EAAS,cAAqB,EAAE,YAAqB;QACrF,KAAK,CAAC,UAAU,EAAC,cAAc,EAAC,YAAY,CAAC,CAAC;QAD/B,eAAU,GAAV,UAAU,CAAO;QAAS,mBAAc,GAAd,cAAc,CAAO;IAElE,CAAC;IAED,2BAA2B;QACvB,MAAM,YAAY,GAAG,OAAO,CAAC,gBAAgB,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;QAChE,MAAM,MAAM,GAAG,IAAI,mBAAmB,CAAC,YAAY,CAAC,CAAC;QAErD,IAAI,iBAAiB,EAAE,EAAC;YACpB,MAAM,CAAC,2BAA2B,CAAC,QAAQ,EAAC,CAAC,IAAW,EAAE,EAAE;gBACxD,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAE,4BAA4B;YAC3E,CAAC,CAAC,CAAC;SACN;aAAI;YACD,sFAAsF;YACtF,MAAM,CAAC,mBAAmB,CACtB;gBACI,OAAO,EAAE,6GAA6G;gBACtH,QAAQ,EAAE,yHAAyH,CAAE,mBAAmB;aAC3J,EACD,CAAC,IAAI,EAAE,EAAE;gBACL,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAE,+BAA+B;YAC9E,CAAC,CACJ,CAAC;SACL;IAOL,CAAC;IAED,aAAa;QACT,IAAI,CAAC,2BAA2B,EAAE,CAAC;IACvC,CAAC;CAEJ;AAGD,MAAM,UAAU,cAAc,CAAC,UAAiB,EAAE,YAAqB;IACnE,IAAI,MAAM,GAAG,IAAI,cAAc,CAAC,UAAU,EAAC,cAAc,EAAC,YAAY,CAAC,CAAC;IACxE,MAAM,CAAC,aAAa,EAAE,CAAC;IAEvB,IAAI,YAAY,EAAE;QACd,MAAM,cAAc,GAAG,MAAM,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QACpD,wDAAwD;QACxD,IAAI,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;YACvC,MAAc,CAAC,cAAc,CAAC,UAAU,CAAC,GAAG,cAAc,CAAC;SAC/D;KACJ;AAEL,CAAC"}
✄
import { Cronet } from "../ssl_lib/cronet.js";
import { socket_library } from "./android_agent.js";
import { PatternBasedHooking } from "../shared/pattern_based_hooking.js";
import { patterns, isPatternReplaced } from "../ssl_log.js";
export class Cronet_Android extends Cronet {
    constructor(moduleName, socket_library, is_base_hook) {
        super(moduleName, socket_library, is_base_hook);
        this.moduleName = moduleName;
        this.socket_library = socket_library;
    }
    install_key_extraction_hook() {
        const cronetModule = Process.findModuleByName(this.module_name);
        const hooker = new PatternBasedHooking(cronetModule);
        if (isPatternReplaced()) {
            hooker.hook_with_pattern_from_json(patterns, (args) => {
                this.dumpKeys(args[1], args[0], args[2]); // Unpack args into dumpKeys
            });
        }
        else {
            // This are the default patterns for hooking ssl_log_secret in BoringSSL inside Cronet
            hooker.hookModuleByPattern({
                primary: "3F 23 03 D5 FF C3 01 D1 FD 7B 04 A9 F6 57 05 A9 F4 4F 06 A9 FD 03 01 91 08 34 40 F9 08 11 41 F9 C8 07 00 B4",
                fallback: "3F 23 03 D5 FF 03 02 D1 FD 7B 04 A9 F7 2B 00 F9 F6 57 06 A9 F4 4F 07 A9 FD 03 01 91 08 34 40 F9 08 11 41 F9 E8 0F 00 B4" // Fallback pattern
            }, (args) => {
                this.dumpKeys(args[1], args[0], args[2]); // Hook args passed to dumpKeys
            });
        }
    }
    execute_hooks() {
        this.install_key_extraction_hook();
    }
}
export function cronet_execute(moduleName, is_base_hook) {
    var cronet = new Cronet_Android(moduleName, socket_library, is_base_hook);
    cronet.execute_hooks();
    if (is_base_hook) {
        const init_addresses = cronet.addresses[moduleName];
        // ensure that we only add it to global when we are not 
        if (Object.keys(init_addresses).length > 0) {
            global.init_addresses[moduleName] = init_addresses;
        }
    }
}
✄
{"version":3,"file":"gnutls_android.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/android/gnutls_android.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,MAAM,OAAO,YAAa,SAAQ,MAAM;IAEpC,YAAmB,UAAiB,EAAS,cAAqB,EAAE,YAAqB;QACrF,KAAK,CAAC,UAAU,EAAC,cAAc,CAAC,CAAC;QADlB,eAAU,GAAV,UAAU,CAAO;QAAS,mBAAc,GAAd,cAAc,CAAO;IAElE,CAAC;IAGD,aAAa;QACT,IAAI,CAAC,2BAA2B,EAAE,CAAC;QACnC,IAAI,CAAC,4BAA4B,EAAE,CAAC;QACpC,IAAI,CAAC,8BAA8B,EAAE,CAAC;IAC1C,CAAC;IAED,8BAA8B;QAC1B,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,aAAa,CAAC,EACtE;YACI,OAAO,EAAE,UAAU,IAAS;gBACxB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;YAC1B,CAAC;YACD,OAAO,EAAE,UAAU,MAAW;gBAC1B,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;gBACzB,MAAM,CAAC,kCAAkC,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,MAAM,CAAC,eAAe,CAAC,CAAA;YAEjG,CAAC;SACJ,CAAC,CAAA;IAEF,CAAC;CACJ;AAGD,MAAM,UAAU,cAAc,CAAC,UAAiB,EAAE,YAAqB;IACnE,IAAI,UAAU,GAAG,IAAI,YAAY,CAAC,UAAU,EAAC,cAAc,EAAE,YAAY,CAAC,CAAC;IAC3E,UAAU,CAAC,aAAa,EAAE,CAAC;IAE3B,IAAI,YAAY,EAAE;QACd,MAAM,cAAc,GAAG,UAAU,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QACxD,wDAAwD;QACxD,IAAI,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;YACvC,MAAc,CAAC,cAAc,CAAC,UAAU,CAAC,GAAG,cAAc,CAAC;SAC/D;KACJ;AAEL,CAAC"}
✄
import { GnuTLS } from "../ssl_lib/gnutls.js";
import { socket_library } from "./android_agent.js";
export class GnuTLS_Linux extends GnuTLS {
    constructor(moduleName, socket_library, is_base_hook) {
        super(moduleName, socket_library);
        this.moduleName = moduleName;
        this.socket_library = socket_library;
    }
    execute_hooks() {
        this.install_plaintext_read_hook();
        this.install_plaintext_write_hook();
        this.install_tls_keys_callback_hook();
    }
    install_tls_keys_callback_hook() {
        Interceptor.attach(this.addresses[this.module_name]["gnutls_init"], {
            onEnter: function (args) {
                this.session = args[0];
            },
            onLeave: function (retval) {
                console.log(this.session);
                GnuTLS.gnutls_session_set_keylog_function(this.session.readPointer(), GnuTLS.keylog_callback);
            }
        });
    }
}
export function gnutls_execute(moduleName, is_base_hook) {
    var gnutls_ssl = new GnuTLS_Linux(moduleName, socket_library, is_base_hook);
    gnutls_ssl.execute_hooks();
    if (is_base_hook) {
        const init_addresses = gnutls_ssl.addresses[moduleName];
        // ensure that we only add it to global when we are not 
        if (Object.keys(init_addresses).length > 0) {
            global.init_addresses[moduleName] = init_addresses;
        }
    }
}
✄
{"version":3,"file":"mbedTLS_android.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/android/mbedTLS_android.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,MAAM,OAAO,gBAAiB,SAAQ,QAAQ;IAE1C,YAAmB,UAAiB,EAAS,cAAqB,EAAE,YAAqB;QACrF,KAAK,CAAC,UAAU,EAAC,cAAc,CAAC,CAAC;QADlB,eAAU,GAAV,UAAU,CAAO;QAAS,mBAAc,GAAd,cAAc,CAAO;IAElE,CAAC;IAED;;;;;;MAME;IACF,8BAA8B;QAC1B,8BAA8B;IAClC,CAAC;IAED,aAAa;QACT,IAAI,CAAC,2BAA2B,EAAE,CAAC;QACnC,IAAI,CAAC,4BAA4B,EAAE,CAAC;IACxC,CAAC;CAEJ;AAGD,MAAM,UAAU,eAAe,CAAC,UAAiB,EAAE,YAAqB;IACpE,IAAI,WAAW,GAAG,IAAI,gBAAgB,CAAC,UAAU,EAAC,cAAc,EAAE,YAAY,CAAC,CAAC;IAChF,WAAW,CAAC,aAAa,EAAE,CAAC;IAE5B,IAAI,YAAY,EAAE;QACd,MAAM,cAAc,GAAG,WAAW,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QACzD,wDAAwD;QACxD,IAAI,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;YACvC,MAAc,CAAC,cAAc,CAAC,UAAU,CAAC,GAAG,cAAc,CAAC;SAC/D;KACJ;AAGL,CAAC"}
✄
import { mbed_TLS } from "../ssl_lib/mbedTLS.js";
import { socket_library } from "./android_agent.js";
export class mbed_TLS_Android extends mbed_TLS {
    constructor(moduleName, socket_library, is_base_hook) {
        super(moduleName, socket_library);
        this.moduleName = moduleName;
        this.socket_library = socket_library;
    }
    /*
    SSL_CTX_set_keylog_callback not exported by default on windows.

    We need to find a way to install the callback function for doing that

    Alternatives?:SSL_export_keying_material, SSL_SESSION_get_master_key
    */
    install_tls_keys_callback_hook() {
        // install hooking for windows
    }
    execute_hooks() {
        this.install_plaintext_read_hook();
        this.install_plaintext_write_hook();
    }
}
export function mbedTLS_execute(moduleName, is_base_hook) {
    var mbedTLS_ssl = new mbed_TLS_Android(moduleName, socket_library, is_base_hook);
    mbedTLS_ssl.execute_hooks();
    if (is_base_hook) {
        const init_addresses = mbedTLS_ssl.addresses[moduleName];
        // ensure that we only add it to global when we are not 
        if (Object.keys(init_addresses).length > 0) {
            global.init_addresses[moduleName] = init_addresses;
        }
    }
}
✄
{"version":3,"file":"nss_android.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/android/nss_android.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,GAAG,EAAE,MAAM,mBAAmB,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,MAAM,OAAO,WAAY,SAAQ,GAAG;IAEhC,YAAmB,UAAiB,EAAS,cAAqB,EAAE,YAAqB;QACrF,IAAI,sBAAsB,GAAqC,EAAE,CAAC;QAClE,sBAAsB,CAAC,IAAI,UAAU,GAAG,CAAC,GAAG,CAAC,UAAU,EAAE,SAAS,EAAE,0BAA0B,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,uBAAuB,EAAE,gBAAgB,CAAC,CAAA;QAC9K,sBAAsB,CAAC,UAAU,CAAC,GAAG,CAAC,sBAAsB,EAAE,iBAAiB,CAAC,CAAA;QAChF,sBAAsB,CAAC,aAAa,CAAC,GAAG,CAAC,cAAc,EAAE,kBAAkB,EAAE,uBAAuB,CAAC,CAAA;QACrG,sBAAsB,CAAC,IAAI,cAAc,GAAG,CAAC,GAAG,CAAC,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;QAEhG,KAAK,CAAC,UAAU,EAAC,cAAc,EAAC,sBAAsB,CAAC,CAAC;QAPzC,eAAU,GAAV,UAAU,CAAO;QAAS,mBAAc,GAAd,cAAc,CAAO;IAQlE,CAAC;IAGD,aAAa;QACT,IAAI,CAAC,2BAA2B,EAAE,CAAC;QACnC,IAAI,CAAC,4BAA4B,EAAE,CAAC;QACpC,sDAAsD;IAC1D,CAAC;CAEJ;AAGD,MAAM,UAAU,WAAW,CAAC,UAAiB,EAAE,YAAqB;IAChE,IAAI,OAAO,GAAG,IAAI,WAAW,CAAC,UAAU,EAAC,cAAc,EAAE,YAAY,CAAC,CAAC;IACvE,OAAO,CAAC,aAAa,EAAE,CAAC;IAExB,IAAI,YAAY,EAAE;QACd,MAAM,cAAc,GAAG,OAAO,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QACrD,wDAAwD;QACxD,IAAI,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;YACvC,MAAc,CAAC,cAAc,CAAC,UAAU,CAAC,GAAG,cAAc,CAAC;SAC/D;KACJ;AAEL,CAAC"}
✄
import { NSS } from "../ssl_lib/nss.js";
import { socket_library } from "./android_agent.js";
export class NSS_Android extends NSS {
    constructor(moduleName, socket_library, is_base_hook) {
        var library_method_mapping = {};
        library_method_mapping[`*${moduleName}*`] = ["PR_Write", "PR_Read", "PR_FileDesc2NativeHandle", "PR_GetPeerName", "PR_GetSockName", "PR_GetNameForIdentity", "PR_GetDescType"];
        library_method_mapping[`*libnss*`] = ["PK11_ExtractKeyValue", "PK11_GetKeyData"];
        library_method_mapping["*libssl*.so"] = ["SSL_ImportFD", "SSL_GetSessionID", "SSL_HandshakeCallback"];
        library_method_mapping[`*${socket_library}*`] = ["getpeername", "getsockname", "ntohs", "ntohl"];
        super(moduleName, socket_library, library_method_mapping);
        this.moduleName = moduleName;
        this.socket_library = socket_library;
    }
    execute_hooks() {
        this.install_plaintext_read_hook();
        this.install_plaintext_write_hook();
        //this.install_tls_keys_callback_hook() // might fail 
    }
}
export function nss_execute(moduleName, is_base_hook) {
    var nss_ssl = new NSS_Android(moduleName, socket_library, is_base_hook);
    nss_ssl.execute_hooks();
    if (is_base_hook) {
        const init_addresses = nss_ssl.addresses[moduleName];
        // ensure that we only add it to global when we are not 
        if (Object.keys(init_addresses).length > 0) {
            global.init_addresses[moduleName] = init_addresses;
        }
    }
}
✄
{"version":3,"file":"openssl_boringssl_android.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/android/openssl_boringssl_android.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,MAAM,OAAO,yBAA0B,SAAQ,iBAAiB;IAE5D,YAAmB,UAAiB,EAAS,cAAqB,EAAE,YAAqB;QACrF,KAAK,CAAC,UAAU,EAAC,cAAc,EAAC,YAAY,CAAC,CAAC;QAD/B,eAAU,GAAV,UAAU,CAAO;QAAS,mBAAc,GAAd,cAAc,CAAO;IAElE,CAAC;IAED,8BAA8B;QAE1B,IAAI,CAAC,2BAA2B,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,6BAA6B,CAAC,EAAE,MAAM,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC;QACvJ,IAAI,QAAQ,GAAG,IAAI,CAAC;QAGpB,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,SAAS,CAAC,EAC9D;YACI,OAAO,EAAE,UAAU,IAAS;gBACxB,QAAQ,CAAC,2BAA2B,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,iBAAiB,CAAC,eAAe,CAAC,CAAA;YACpF,CAAC;SAEJ,CAAC,CAAC;QAEH;;;;;;;;;;;UAWE;IACN,CAAC;IAED,aAAa;QACT,IAAI,CAAC,2BAA2B,EAAE,CAAC;QACnC,IAAI,CAAC,4BAA4B,EAAE,CAAC;QACpC,IAAI,CAAC,8BAA8B,EAAE,CAAC;QACtC,IAAI,CAAC,sBAAsB,EAAE,CAAC;IAClC,CAAC;CAEJ;AAGD,MAAM,UAAU,cAAc,CAAC,UAAiB,EAAE,YAAqB;IACnE,IAAI,UAAU,GAAG,IAAI,yBAAyB,CAAC,UAAU,EAAC,cAAc,EAAC,YAAY,CAAC,CAAC;IACvF,UAAU,CAAC,aAAa,EAAE,CAAC;IAE3B,IAAI,YAAY,EAAE;QACd,MAAM,cAAc,GAAG,UAAU,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QACxD,wDAAwD;QACxD,IAAI,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;YACvC,MAAc,CAAC,cAAc,CAAC,UAAU,CAAC,GAAG,cAAc,CAAC;SAC/D;KACJ;AAEL,CAAC"}
✄
import { OpenSSL_BoringSSL } from "../ssl_lib/openssl_boringssl.js";
import { socket_library } from "./android_agent.js";
export class OpenSSL_BoringSSL_Android extends OpenSSL_BoringSSL {
    constructor(moduleName, socket_library, is_base_hook) {
        super(moduleName, socket_library, is_base_hook);
        this.moduleName = moduleName;
        this.socket_library = socket_library;
    }
    install_tls_keys_callback_hook() {
        this.SSL_CTX_set_keylog_callback = new NativeFunction(this.addresses[this.module_name]["SSL_CTX_set_keylog_callback"], "void", ["pointer", "pointer"]);
        var instance = this;
        Interceptor.attach(this.addresses[this.module_name]["SSL_new"], {
            onEnter: function (args) {
                instance.SSL_CTX_set_keylog_callback(args[0], OpenSSL_BoringSSL.keylog_callback);
            }
        });
        /*
        // right now this won't work because we need the context
        // in SSL_do_handshake args[0] is actually a SSL object

        Interceptor.attach(this.addresses[this.module_name]["SSL_do_handshake"],
        {
            onEnter: function (args: any) {
             instance.SSL_CTX_set_keylog_callback(args[0], OpenSSL_BoringSSL.keylog_callback)
            }
    
        });
        */
    }
    execute_hooks() {
        this.install_plaintext_read_hook();
        this.install_plaintext_write_hook();
        this.install_tls_keys_callback_hook();
        this.install_extended_hooks();
    }
}
export function boring_execute(moduleName, is_base_hook) {
    var boring_ssl = new OpenSSL_BoringSSL_Android(moduleName, socket_library, is_base_hook);
    boring_ssl.execute_hooks();
    if (is_base_hook) {
        const init_addresses = boring_ssl.addresses[moduleName];
        // ensure that we only add it to global when we are not 
        if (Object.keys(init_addresses).length > 0) {
            global.init_addresses[moduleName] = init_addresses;
        }
    }
}
✄
{"version":3,"file":"wolfssl_android.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/android/wolfssl_android.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAE5D,MAAM,OAAO,eAAgB,SAAQ,OAAO;IAExC,YAAmB,UAAiB,EAAS,cAAqB,EAAE,YAAqB;QACrF,KAAK,CAAC,UAAU,EAAC,cAAc,CAAC,CAAC;QADlB,eAAU,GAAV,UAAU,CAAO;QAAS,mBAAc,GAAd,cAAc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3D,OAAO,CAAC,aAAa,CAAC,GAAG,QAAQ,CAAA;gBACjC,OAAO,CAAC,QAAQ,CAAC,GAAG,UAAU,CAAA;gBAC9B,IAAI,CAAC,OAAO,CAAC,CAAA;YAEjB,CAAC;SACJ,CAAC,CAAA;IACN,CAAC;CAGJ;AAGD,MAAM,UAAU,eAAe,CAAC,UAAiB,EAAE,YAAqB;IACpE,IAAI,QAAQ,GAAG,IAAI,eAAe,CAAC,UAAU,EAAC,cAAc,EAAE,YAAY,CAAC,CAAC;IAC5E,QAAQ,CAAC,aAAa,EAAE,CAAC;IAEzB,IAAI,YAAY,EAAE;QACd,MAAM,cAAc,GAAG,QAAQ,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QACtD,wDAAwD;QACxD,IAAI,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;YACvC,MAAc,CAAC,cAAc,CAAC,UAAU,CAAC,GAAG,cAAc,CAAC;SAC/D;KACJ;AAEL,CAAC"}
✄
import { WolfSSL } from "../ssl_lib/wolfssl.js";
import { socket_library } from "./android_agent.js";
import { toHexString } from "../shared/shared_functions.js";
export class WolfSSL_Android extends WolfSSL {
    constructor(moduleName, socket_library, is_base_hook) {
        super(moduleName, socket_library);
        this.moduleName = moduleName;
        this.socket_library = socket_library;
    }
    execute_hooks() {
        this.install_plaintext_read_hook();
        this.install_plaintext_write_hook();
        this.install_tls_keys_callback_hook();
    }
    install_tls_keys_callback_hook() {
        WolfSSL.wolfSSL_get_client_random = new NativeFunction(this.addresses[this.module_name]["wolfSSL_get_client_random"], "int", ["pointer", "pointer", "int"]);
        WolfSSL.wolfSSL_get_server_random = new NativeFunction(this.addresses[this.module_name]["wolfSSL_get_server_random"], "int", ["pointer", "pointer", "int"]);
        //https://www.wolfssl.com/doxygen/group__Setup.html#gaf18a029cfeb3150bc245ce66b0a44758
        WolfSSL.wolfSSL_SESSION_get_master_key = new NativeFunction(this.addresses[this.module_name]["wolfSSL_SESSION_get_master_key"], "int", ["pointer", "pointer", "int"]);
        Interceptor.attach(this.addresses[this.module_name]["wolfSSL_connect"], {
            onEnter: function (args) {
                this.ssl = args[0];
            },
            onLeave: function (retval) {
                this.session = WolfSSL.wolfSSL_get_session(this.ssl);
                var keysString = "";
                //https://www.wolfssl.com/doxygen/group__Setup.html#ga927e37dc840c228532efa0aa9bbec451
                var requiredClientRandomLength = WolfSSL.wolfSSL_get_client_random(this.session, NULL, 0);
                var clientBuffer = Memory.alloc(requiredClientRandomLength);
                WolfSSL.wolfSSL_get_client_random(this.ssl, clientBuffer, requiredClientRandomLength);
                var clientBytes = clientBuffer.readByteArray(requiredClientRandomLength);
                keysString = `${keysString}CLIENT_RANDOM: ${toHexString(clientBytes)}\n`;
                //https://www.wolfssl.com/doxygen/group__Setup.html#ga987035fc600ba9e3b02e2b2718a16a6c
                var requiredServerRandomLength = WolfSSL.wolfSSL_get_server_random(this.session, NULL, 0);
                var serverBuffer = Memory.alloc(requiredServerRandomLength);
                WolfSSL.wolfSSL_get_server_random(this.ssl, serverBuffer, requiredServerRandomLength);
                var serverBytes = serverBuffer.readByteArray(requiredServerRandomLength);
                keysString = `${keysString}SERVER_RANDOM: ${toHexString(serverBytes)}\n`;
                //https://www.wolfssl.com/doxygen/group__Setup.html#gaf18a029cfeb3150bc245ce66b0a44758
                var requiredMasterKeyLength = WolfSSL.wolfSSL_SESSION_get_master_key(this.session, NULL, 0);
                var masterBuffer = Memory.alloc(requiredMasterKeyLength);
                WolfSSL.wolfSSL_SESSION_get_master_key(this.session, masterBuffer, requiredMasterKeyLength);
                var masterBytes = masterBuffer.readByteArray(requiredMasterKeyLength);
                keysString = `${keysString}MASTER_KEY: ${toHexString(masterBytes)}\n`;
                var message = {};
                message["contentType"] = "keylog";
                message["keylog"] = keysString;
                send(message);
            }
        });
    }
}
export function wolfssl_execute(moduleName, is_base_hook) {
    var wolf_ssl = new WolfSSL_Android(moduleName, socket_library, is_base_hook);
    wolf_ssl.execute_hooks();
    if (is_base_hook) {
        const init_addresses = wolf_ssl.addresses[moduleName];
        // ensure that we only add it to global when we are not 
        if (Object.keys(init_addresses).length > 0) {
            global.init_addresses[moduleName] = init_addresses;
        }
    }
}
✄
{"version":3,"file":"ios_agent.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/ios/ios_agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAqB,MAAM,gCAAgC,CAAC;AAC3F,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAC1G,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAC;AAG5D,IAAI,cAAc,GAAG,QAAQ,CAAC;AAC9B,IAAI,WAAW,GAAkB,cAAc,EAAE,CAAA;AAEjD,MAAM,CAAC,MAAM,cAAc,GAAG,mBAAmB,CAAA;AAGjD,SAAS,uBAAuB,CAAC,sBAA0E,EAAE,YAAqB;IAC9H,IAAI;QACA,MAAM,WAAW,GAAG,mBAAmB,CAAA;QACvC,MAAM,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAA;QACrE,IAAI,KAAK,KAAK,SAAS,EAAE;YACrB,MAAM,kCAAkC,CAAA;SAC3C;QAED,IAAI,MAAM,GAAG,QAAQ,CAAA;QAErB,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,KAAK,EAAE,MAAM,CAAC,EAAE;YACtD,OAAO,EAAE,UAAU,IAAI;gBACnB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAA;YAC3C,CAAC;YACD,OAAO,EAAE,UAAU,MAAW;gBAC1B,IAAI,IAAI,CAAC,UAAU,IAAI,SAAS,EAAE;oBAC9B,KAAK,IAAI,GAAG,IAAI,sBAAsB,CAAC,cAAc,CAAC,EAAE;wBACpD,IAAI,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;wBAClB,IAAI,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;wBACjB,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE;4BAC7B,GAAG,CAAC,GAAG,IAAI,CAAC,UAAU,sCAAsC,CAAC,CAAA;4BAC7D,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,YAAY,CAAC,CAAA;yBACtC;qBAEJ;iBACJ;YACL,CAAC;SAGJ,CAAC,CAAA;QAEF,OAAO,CAAC,GAAG,CAAC,gCAAgC,CAAC,CAAA;KAChD;IAAC,OAAO,KAAK,EAAE;QACZ,MAAM,CAAC,gBAAgB,GAAG,KAAK,CAAC,CAAA;QAChC,GAAG,CAAC,+CAA+C,CAAC,CAAA;KACvD;AACL,CAAC;AAGD,SAAS,iBAAiB,CAAC,sBAA0E,EAAE,YAAqB;IACxH,kBAAkB,CAAC,cAAc,EAAE,sBAAsB,EAAC,WAAW,EAAC,KAAK,EAAC,YAAY,CAAC,CAAA;AAC7F,CAAC;AAID,MAAM,UAAU,sBAAsB;IAClC,sBAAsB,CAAC,cAAc,CAAC,GAAG;QACrC,CAAC,uBAAuB,EAAE,qBAAqB,CAAC,cAAc,CAAC,CAAC;KAAC,CAAA;IAErE,iBAAiB,CAAC,sBAAsB,EAAE,IAAI,CAAC,CAAC;IAChD,uBAAuB,CAAC,sBAAsB,EAAE,KAAK,CAAC,CAAC;AAC3D,CAAC"}
✄
import { module_library_mapping } from "../shared/shared_structures.js";
import { log, devlog } from "../util/log.js";
import { getModuleNames, ssl_library_loader, invokeHookingFunction } from "../shared/shared_functions.js";
import { boring_execute } from "./openssl_boringssl_ios.js";
var plattform_name = "darwin";
var moduleNames = getModuleNames();
export const socket_library = "libSystem.B.dylib";
function hook_iOS_Dynamic_Loader(module_library_mapping, is_base_hook) {
    try {
        const regex_libdl = /libSystem.B.dylib/;
        const libdl = moduleNames.find(element => element.match(regex_libdl));
        if (libdl === undefined) {
            throw "Darwin Dynamic loader not found!";
        }
        var dlopen = "dlopen";
        Interceptor.attach(Module.getExportByName(libdl, dlopen), {
            onEnter: function (args) {
                this.moduleName = args[0].readCString();
            },
            onLeave: function (retval) {
                if (this.moduleName != undefined) {
                    for (let map of module_library_mapping[plattform_name]) {
                        let regex = map[0];
                        let func = map[1];
                        if (regex.test(this.moduleName)) {
                            log(`${this.moduleName} was loaded & will be hooked on iOS!`);
                            func(this.moduleName, is_base_hook);
                        }
                    }
                }
            }
        });
        console.log(`[*] iOS dynamic loader hooked.`);
    }
    catch (error) {
        devlog("Loader error: " + error);
        log("No dynamic loader present for hooking on iOS.");
    }
}
function hook_iOS_SSL_Libs(module_library_mapping, is_base_hook) {
    ssl_library_loader(plattform_name, module_library_mapping, moduleNames, "iOS", is_base_hook);
}
export function load_ios_hooking_agent() {
    module_library_mapping[plattform_name] = [
        [/.*libboringssl\.dylib/, invokeHookingFunction(boring_execute)]
    ];
    hook_iOS_SSL_Libs(module_library_mapping, true);
    hook_iOS_Dynamic_Loader(module_library_mapping, false);
}
✄
{"version":3,"file":"openssl_boringssl_ios.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/ios/openssl_boringssl_ios.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAO,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAE7C,MAAM,OAAO,qBAAsB,SAAQ,iBAAiB;IAExD,8BAA8B;QAC1B,yGAAyG;QACzG,IAAI,IAAI,CAAC,SAAS,EAAE,EAAE,0EAA0E;YAC5F,IAAI,eAAe,GAAG,KAAK,CAAC;YAE5B,IAAI,gBAAg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QACzI,sBAAsB,CAAC,IAAI,UAAU,GAAG,CAAC,GAAG,CAAC,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,SAAS,EAAE,2BAA2B,CAAC,CAAA;QACpK,sBAAsB,CAAC,IAAI,cAAc,GAAG,CAAC,GAAG,CAAC,cAAc,EAAE,cAAc,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAA,CAAC,kFAAkF;QAEvL,KAAK,CAAC,UAAU,EAAC,cAAc,EAAC,YAAY,EAAC,sBAAsB,CAAC,CAAC;QARtD,eAAU,GAAV,UAAU,CAAO;QAAS,mBAAc,GAAd,cAAc,CAAO;IASlE,CAAC;IAED,aAAa;QAET;;;;UAIE;QAEF,IAAI,CAAC,8BAA8B,EAAE,CAAC;IAC1C,CAAC;CAIJ;AAGD,MAAM,UAAU,cAAc,CAAC,UAAiB,EAAE,YAAqB;IACnE,IAAI,UAAU,GAAG,IAAI,qBAAqB,CAAC,UAAU,EAAC,cAAc,EAAE,YAAY,CAAC,CAAC;IACpF,UAAU,CAAC,aAAa,EAAE,CAAC;IAE3B,IAAI,YAAY,EAAE;QACd,MAAM,cAAc,GAAG,UAAU,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QACxD,wDAAwD;QACxD,IAAI,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;YACvC,MAAc,CAAC,cAAc,CAAC,UAAU,CAAC,GAAG,cAAc,CAAC;SAC/D;KACJ;AACL,CAAC"}
✄
import { OpenSSL_BoringSSL } from "../ssl_lib/openssl_boringssl.js";
import { socket_library } from "./ios_agent.js";
import { devlog } from "../util/log.js";
export class OpenSSL_BoringSSL_iOS extends OpenSSL_BoringSSL {
    install_tls_keys_callback_hook() {
        //console.log(this.addresses) // currently only for debugging purposes will be removed in future releases
        if (ObjC.available) { // inspired from https://codeshare.frida.re/@andydavies/ios-tls-keylogger/
            var CALLBACK_OFFSET = 0x2A8;
            var foundationNumber = Module.findExportByName('CoreFoundation', 'kCFCoreFoundationVersionNumber')?.readDouble();
            if (foundationNumber == undefined) {
                devlog("Installing callback for iOS < 14");
                CALLBACK_OFFSET = 0x2A8;
            }
            else if (foundationNumber >= 1751.108 && foundationNumber < 1854) {
                devlog("Installing callback for iOS >= 14");
                CALLBACK_OFFSET = 0x2B8; // >= iOS 14.x 
            }
            else if (foundationNumber >= 1854 && foundationNumber < 1946.102) {
                devlog("Installing callback for iOS >= 15");
                CALLBACK_OFFSET = 0x2F8; // >= iOS 15.x 
            }
            else if (foundationNumber >= 1946.102 && foundationNumber <= 1979.1) {
                devlog("Installing callback for iOS >= 16");
                CALLBACK_OFFSET = 0x300; // >= iOS 16.x 
            }
            else if (foundationNumber > 1979.1) {
                devlog("Installing callback for iOS >= 17");
                CALLBACK_OFFSET = 0x308; // >= iOS 17.x 
            }
            Interceptor.attach(this.addresses[this.module_name]["SSL_CTX_set_info_callback"], {
                onEnter: function (args) {
                    ptr(args[0]).add(CALLBACK_OFFSET).writePointer(OpenSSL_BoringSSL.keylog_callback);
                }
            });
        }
    }
    constructor(moduleName, socket_library, is_base_hook) {
        var library_method_mapping = {};
        // the iOS implementation needs some further improvements - currently we are not able to get the sockfd from an SSL_read/write invocation
        library_method_mapping[`*${moduleName}*`] = ["SSL_read", "SSL_write", "BIO_get_fd", "SSL_get_session", "SSL_SESSION_get_id", "SSL_new", "SSL_CTX_set_info_callback"];
        library_method_mapping[`*${socket_library}*`] = ["getpeername*", "getsockname*", "ntohs*", "ntohl*"]; // currently those functions gets only identified if we at an asterisk at the end 
        super(moduleName, socket_library, is_base_hook, library_method_mapping);
        this.moduleName = moduleName;
        this.socket_library = socket_library;
    }
    execute_hooks() {
        /*
        currently these function hooks aren't implemented
        this.install_plaintext_read_hook();
        this.install_plaintext_write_hook();
        */
        this.install_tls_keys_callback_hook();
    }
}
export function boring_execute(moduleName, is_base_hook) {
    var boring_ssl = new OpenSSL_BoringSSL_iOS(moduleName, socket_library, is_base_hook);
    boring_ssl.execute_hooks();
    if (is_base_hook) {
        const init_addresses = boring_ssl.addresses[moduleName];
        // ensure that we only add it to global when we are not 
        if (Object.keys(init_addresses).length > 0) {
            global.init_addresses[moduleName] = init_addresses;
        }
    }
}
✄
{"version":3,"file":"gnutls_linux.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/linux/gnutls_linux.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,MAAM,OAAO,YAAa,SAAQ,MAAM;IAEpC,YAAmB,UAAiB,EAAS,cAAqB,EAAE,YAAqB;QACrF,KAAK,CAAC,UAAU,EAAC,cAAc,CAAC,CAAC;QADlB,eAAU,GAAV,UAAU,CAAO;QAAS,mBAAc,GAAd,cAAc,CAAO;IAElE,CAAC;IAGD,aAAa;QACT,IAAI,CAAC,2BAA2B,EAAE,CAAC;QACnC,IAAI,CAAC,4BAA4B,EAAE,CAAC;QACpC,IAAI,CAAC,8BAA8B,EAAE,CAAC;IAC1C,CAAC;IAED,8BAA8B;QAC1B,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,aAAa,CAAC,EACtE;YACI,OAAO,EAAE,UAAU,IAAS;gBACxB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAA;YAC1B,CAAC;YACD,OAAO,EAAE,UAAU,MAAW;gBAC1B,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;gBACzB,MAAM,CAAC,kCAAkC,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,MAAM,CAAC,eAAe,CAAC,CAAA;YAEjG,CAAC;SACJ,CAAC,CAAA;IAEF,CAAC;CAEJ;AAKD,MAAM,UAAU,cAAc,CAAC,UAAiB,EAAE,YAAqB;IACnE,IAAI,UAAU,GAAG,IAAI,YAAY,CAAC,UAAU,EAAC,cAAc,EAAE,YAAY,CAAC,CAAC;IAC3E,UAAU,CAAC,aAAa,EAAE,CAAC;IAE3B,IAAI,YAAY,EAAE;QACd,MAAM,cAAc,GAAG,UAAU,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QACxD,wDAAwD;QACxD,IAAI,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;YACvC,MAAc,CAAC,cAAc,CAAC,UAAU,CAAC,GAAG,cAAc,CAAC;SAC/D;KACJ;AAEL,CAAC"}
✄
import { GnuTLS } from "../ssl_lib/gnutls.js";
import { socket_library } from "./linux_agent.js";
export class GnuTLS_Linux extends GnuTLS {
    constructor(moduleName, socket_library, is_base_hook) {
        super(moduleName, socket_library);
        this.moduleName = moduleName;
        this.socket_library = socket_library;
    }
    execute_hooks() {
        this.install_plaintext_read_hook();
        this.install_plaintext_write_hook();
        this.install_tls_keys_callback_hook();
    }
    install_tls_keys_callback_hook() {
        Interceptor.attach(this.addresses[this.module_name]["gnutls_init"], {
            onEnter: function (args) {
                this.session = args[0];
            },
            onLeave: function (retval) {
                console.log(this.session);
                GnuTLS.gnutls_session_set_keylog_function(this.session.readPointer(), GnuTLS.keylog_callback);
            }
        });
    }
}
export function gnutls_execute(moduleName, is_base_hook) {
    var gnutls_ssl = new GnuTLS_Linux(moduleName, socket_library, is_base_hook);
    gnutls_ssl.execute_hooks();
    if (is_base_hook) {
        const init_addresses = gnutls_ssl.addresses[moduleName];
        // ensure that we only add it to global when we are not 
        if (Object.keys(init_addresses).length > 0) {
            global.init_addresses[moduleName] = init_addresses;
        }
    }
}
✄
{"version":3,"file":"linux_agent.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/linux/linux_agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAqB,MAAM,gCAAgC,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B,CAAC,sBAAsB,EAAE,IAAI,CAAC,CAAC;IAClD,yBAAyB,CAAC,sBAAsB,EAAE,KAAK,CAAC,CAAC;AAC7D,CAAC"}
✄
import { module_library_mapping } from "../shared/shared_structures.js";
import { log, devlog } from "../util/log.js";
import { getModuleNames, ssl_library_loader, invokeHookingFunction } from "../shared/shared_functions.js";
import { gnutls_execute } from "./gnutls_linux.js";
import { wolfssl_execute } from "./wolfssl_linux.js";
import { nss_execute } from "./nss_linux.js";
import { mbedTLS_execute } from "./mbedTLS_linux.js";
import { boring_execute } from "./openssl_boringssl_linux.js";
import { matrixSSL_execute } from "./matrixssl_linux.js";
var plattform_name = "linux";
var moduleNames = getModuleNames();
export const socket_library = "libc";
function hook_Linux_Dynamic_Loader(module_library_mapping, is_base_hook) {
    try {
        const regex_libdl = /.*libdl.*\.so/;
        const libdl = moduleNames.find(element => element.match(regex_libdl));
        if (libdl === undefined) {
            throw "Linux Dynamic loader not found!";
        }
        var dlopen = "dlopen";
        Interceptor.attach(Module.getExportByName(libdl, dlopen), {
            onEnter: function (args) {
                this.moduleName = args[0].readCString();
            },
            onLeave: function (retval) {
                if (this.moduleName != undefined) {
                    for (let map of module_library_mapping[plattform_name]) {
                        let regex = map[0];
                        let func = map[1];
                        if (regex.test(this.moduleName)) {
                            log(`${this.moduleName} was loaded & will be hooked on Linux!`);
                            func(this.moduleName, is_base_hook);
                        }
                    }
                }
            }
        });
        console.log(`[*] Linux dynamic loader hooked.`);
    }
    catch (error) {
        devlog("Loader error: " + error);
        log("No dynamic loader present for hooking.");
    }
}
function hook_Linux_SSL_Libs(module_library_mapping, is_base_hook) {
    ssl_library_loader(plattform_name, module_library_mapping, moduleNames, "Linux", is_base_hook);
}
export function load_linux_hooking_agent() {
    module_library_mapping[plattform_name] = [
        [/.*libssl_sb.so/, invokeHookingFunction(boring_execute)],
        [/.*libssl\.so/, invokeHookingFunction(boring_execute)],
        [/.*libgnutls\.so/, invokeHookingFunction(gnutls_execute)],
        [/.*libwolfssl\.so/, invokeHookingFunction(wolfssl_execute)],
        [/.*libnspr[0-9]?\.so/, invokeHookingFunction(nss_execute)],
        [/libmbedtls\.so.*/, invokeHookingFunction(mbedTLS_execute)],
        [/libssl_s.a/, invokeHookingFunction(matrixSSL_execute)]
    ];
    hook_Linux_SSL_Libs(module_library_mapping, true);
    hook_Linux_Dynamic_Loader(module_library_mapping, false);
}
✄
{"version":3,"file":"matrixssl_linux.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/linux/matrixssl_linux.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,MAAM,OAAO,gBAAiB,SAAQ,UAAU;IAE5C,YAAmB,UAAiB,EAAS,cAAqB,EAAE,YAAqB;QACrF,KAAK,CAAC,UAAU,EAAC,cAAc,CAAC,CAAC;QADlB,eAAU,GAAV,UAAU,CAAO;QAAS,mBAAc,GAAd,cAAc,CAAO;IAElE,CAAC;IAED;;;;;;MAME;IACF,8BAA8B;QAC1B,8BAA8B;IAClC,CAAC;IAED,aAAa;QACT,IAAI,CAAC,2BAA2B,EAAE,CAAC;QACnC,IAAI,CAAC,4BAA4B,EAAE,CAAC;IACxC,CAAC;CAEJ;AAGD,MAAM,UAAU,iBAAiB,CAAC,UAAiB,EAAE,YAAqB;IACtE,IAAI,UAAU,GAAG,IAAI,gBAAgB,CAAC,UAAU,EAAC,cAAc,EAAE,YAAY,CAAC,CAAC;IAC/E,UAAU,CAAC,aAAa,EAAE,CAAC;IAE3B,IAAI,YAAY,EAAE;QACd,MAAM,cAAc,GAAG,UAAU,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QACxD,wDAAwD;QACxD,IAAI,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;YACvC,MAAc,CAAC,cAAc,CAAC,UAAU,CAAC,GAAG,cAAc,CAAC;SAC/D;KACJ;AACL,CAAC"}
✄
import { matrix_SSL } from "../ssl_lib/matrixssl.js";
import { socket_library } from "./linux_agent.js";
export class matrix_SSL_Linux extends matrix_SSL {
    constructor(moduleName, socket_library, is_base_hook) {
        super(moduleName, socket_library);
        this.moduleName = moduleName;
        this.socket_library = socket_library;
    }
    /*
    SSL_CTX_set_keylog_callback not exported by default on windows.

    We need to find a way to install the callback function for doing that

    Alternatives?:SSL_export_keying_material, SSL_SESSION_get_master_key
    */
    install_tls_keys_callback_hook() {
        // install hooking for windows
    }
    execute_hooks() {
        this.install_plaintext_read_hook();
        this.install_plaintext_write_hook();
    }
}
export function matrixSSL_execute(moduleName, is_base_hook) {
    var matrix_ssl = new matrix_SSL_Linux(moduleName, socket_library, is_base_hook);
    matrix_ssl.execute_hooks();
    if (is_base_hook) {
        const init_addresses = matrix_ssl.addresses[moduleName];
        // ensure that we only add it to global when we are not 
        if (Object.keys(init_addresses).length > 0) {
            global.init_addresses[moduleName] = init_addresses;
        }
    }
}
✄
{"version":3,"file":"mbedTLS_linux.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/linux/mbedTLS_linux.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,MAAM,OAAO,cAAe,SAAQ,QAAQ;IAExC,YAAmB,UAAiB,EAAS,cAAqB;QAC9D,KAAK,CAAC,UAAU,EAAC,cAAc,CAAC,CAAC;QADlB,eAAU,GAAV,UAAU,CAAO;QAAS,mBAAc,GAAd,cAAc,CAAO;IAElE,CAAC;IAED;;;;;;MAME;IACF,8BAA8B;QAC1B,8BAA8B;IAClC,CAAC;IAED,aAAa;QACT,IAAI,CAAC,2BAA2B,EAAE,CAAC;QACnC,IAAI,CAAC,4BAA4B,EAAE,CAAC;IACxC,CAAC;CAEJ;AAGD,MAAM,UAAU,eAAe,CAAC,UAAiB,EAAE,YAAqB;IACpE,IAAI,WAAW,GAAG,IAAI,cAAc,CAAC,UAAU,EAAC,cAAc,CAAC,CAAC;IAChE,WAAW,CAAC,aAAa,EAAE,CAAC;IAE5B,IAAI,YAAY,EAAE;QACd,MAAM,cAAc,GAAG,WAAW,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QACzD,wDAAwD;QACxD,IAAI,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;YACvC,MAAc,CAAC,cAAc,CAAC,UAAU,CAAC,GAAG,cAAc,CAAC;SAC/D;KACJ;AACL,CAAC"}
✄
import { mbed_TLS } from "../ssl_lib/mbedTLS.js";
import { socket_library } from "./linux_agent.js";
export class mbed_TLS_Linux extends mbed_TLS {
    constructor(moduleName, socket_library) {
        super(moduleName, socket_library);
        this.moduleName = moduleName;
        this.socket_library = socket_library;
    }
    /*
    SSL_CTX_set_keylog_callback not exported by default on windows.

    We need to find a way to install the callback function for doing that

    Alternatives?:SSL_export_keying_material, SSL_SESSION_get_master_key
    */
    install_tls_keys_callback_hook() {
        // install hooking for windows
    }
    execute_hooks() {
        this.install_plaintext_read_hook();
        this.install_plaintext_write_hook();
    }
}
export function mbedTLS_execute(moduleName, is_base_hook) {
    var mbedTLS_ssl = new mbed_TLS_Linux(moduleName, socket_library);
    mbedTLS_ssl.execute_hooks();
    if (is_base_hook) {
        const init_addresses = mbedTLS_ssl.addresses[moduleName];
        // ensure that we only add it to global when we are not 
        if (Object.keys(init_addresses).length > 0) {
            global.init_addresses[moduleName] = init_addresses;
        }
    }
}
✄
{"version":3,"file":"nss_linux.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/linux/nss_linux.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,GAAG,EAAE,MAAM,mBAAmB,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAA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AAC,aAAa,EAAE,CAAC;IAExB,IAAI,YAAY,EAAE;QACd,MAAM,cAAc,GAAG,OAAO,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QACrD,wDAAwD;QACxD,IAAI,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;YACvC,MAAc,CAAC,cAAc,CAAC,UAAU,CAAC,GAAG,cAAc,CAAC;SAC/D;KACJ;AACL,CAAC"}
✄
import { NSS } from "../ssl_lib/nss.js";
import { socket_library } from "./linux_agent.js";
import { devlog } from "../util/log.js";
export class NSS_Linux extends NSS {
    constructor(moduleName, socket_library) {
        var library_method_mapping = {};
        library_method_mapping[`*${moduleName}*`] = ["PR_Write", "PR_Read", "PR_FileDesc2NativeHandle", "PR_GetPeerName", "PR_GetSockName", "PR_GetNameForIdentity", "PR_GetDescType"];
        library_method_mapping[`*libnss*`] = ["PK11_ExtractKeyValue", "PK11_GetKeyData"];
        library_method_mapping["*libssl*.so"] = ["SSL_ImportFD", "SSL_GetSessionID", "SSL_HandshakeCallback"];
        library_method_mapping[`*${socket_library}*`] = ["getpeername", "getsockname", "ntohs", "ntohl"];
        super(moduleName, socket_library, library_method_mapping);
        this.moduleName = moduleName;
        this.socket_library = socket_library;
    }
    execute_hooks() {
        this.install_plaintext_read_hook();
        this.install_plaintext_write_hook();
        this.install_tls_keys_callback_hook();
    }
    install_tls_keys_callback_hook() {
        NSS.getDescType = new NativeFunction(this.addresses[this.module_name]['PR_GetDescType'], "int", ["pointer"]);
        // SSL Handshake Functions:
        NSS.PR_GetNameForIdentity = new NativeFunction(this.addresses[this.module_name]['PR_GetNameForIdentity'], "pointer", ["pointer"]);
        /*
                SECStatus SSL_HandshakeCallback(PRFileDesc *fd, SSLHandshakeCallback cb, void *client_data);
                more at https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS/SSL_functions/sslfnc#1112702
        */
        NSS.get_SSL_Callback = new NativeFunction(this.addresses[this.module_name]["SSL_HandshakeCallback"], "int", ["pointer", "pointer", "pointer"]);
        // SSL Key helper Functions 
        NSS.PK11_ExtractKeyValue = new NativeFunction(this.addresses[this.module_name]["PK11_ExtractKeyValue"], "int", ["pointer"]);
        NSS.PK11_GetKeyData = new NativeFunction(this.addresses[this.module_name]["PK11_GetKeyData"], "pointer", ["pointer"]);
        Interceptor.attach(this.addresses[this.module_name]["SSL_ImportFD"], {
            onEnter(args) {
                this.fd = args[1];
            },
            onLeave(retval) {
                if (retval.isNull()) {
                    devlog("[-] SSL_ImportFD error: unknow null");
                    return;
                }
                var retValue = NSS.get_SSL_Callback(retval, NSS.keylog_callback, NULL);
                NSS.register_secret_callback(retval);
                // typedef enum { PR_FAILURE = -1, PR_SUCCESS = 0 } PRStatus;
                if (retValue < 0) {
                    devlog("Callback Error");
                    var getErrorText = new NativeFunction(Module.getExportByName('libnspr4.so', 'PR_GetErrorText'), "int", ["pointer"]);
                    var outbuffer = Memory.alloc(200); // max out size
                    console.log("typeof outbuffer: " + typeof outbuffer);
                    console.log("outbuffer: " + outbuffer); // should be a pointer
                    getErrorText(outbuffer.readPointer());
                    devlog("Error msg: " + outbuffer);
                }
                else {
                    devlog("[*] keylog callback successfull installed");
                }
            }
        });
        /*
            SECStatus SSL_HandshakeCallback(
                PRFileDesc *fd,
                SSLHandshakeCallback cb,
                void *client_data
            );
         */
        Interceptor.attach(this.addresses[this.module_name]["SSL_HandshakeCallback"], {
            onEnter(args) {
                this.originalCallback = args[1];
                Interceptor.attach(ptr(this.originalCallback), {
                    onEnter(args) {
                        var sslSocketFD = args[0];
                        devlog("[*] keylog callback successfull installed via applications callback function");
                        NSS.ssl_RecordKeyLog(sslSocketFD);
                    },
                    onLeave(retval) {
                    }
                });
            },
            onLeave(retval) {
            }
        });
    }
}
export function nss_execute(moduleName, is_base_hook) {
    var nss_ssl = new NSS_Linux(moduleName, socket_library);
    nss_ssl.execute_hooks();
    if (is_base_hook) {
        const init_addresses = nss_ssl.addresses[moduleName];
        // ensure that we only add it to global when we are not 
        if (Object.keys(init_addresses).length > 0) {
            global.init_addresses[moduleName] = init_addresses;
        }
    }
}
✄
{"version":3,"file":"openssl_boringssl_linux.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/linux/openssl_boringssl_linux.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD,MAAM,OAAO,uBAAwB,SAAQ,iBAAiB;IAE1D,YAAmB,UAAiB,EAAS,cAAqB,EAAE,YAAqB;QACrF,KAAK,CAAC,UAAU,EAAC,cAAc,EAAC,YAAY,CAAC,CAAC;QAD/B,eAAU,GAAV,UAAU,CAAO;QAAS,mBAAc,GAAd,cAAc,CAAO;IAElE,CAAC;IAED,8BAA8B;QAE1B,IAAI,CAAC,2BAA2B,GAAG,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,2BAA2B,CAAC,EAAE,MAAM,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,cAAc,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,6BAA6B,CAAC,EAAE,MAAM,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,CAAC;QAC5R,IAAI,QAAQ,GAAG,IAAI,CAAC;QAEpB,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,SAAS,CAAC,EAC9D;YACI,OAAO,EAAE,UAAU,IAAS;gBACxB,QAAQ,CAAC,2BAA2B,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,iBAAiB,CAAC,eAAe,CAAC,CAAA;YACpF,CAAC;SAEJ,CAAC,CAAC;QAGH,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC,kBAAkB,CAAC,EACvE;YACI,OAAO,EAAE,UAAU,IAAS;gBACxB,QAAQ,CAAC,2BAA2B,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,iBAAiB,CAAC,eAAe,CAAC,CAAA;YACpF,CAAC;SAEJ,CAAC,CAAC;IACP,CAAC;IAID,aAAa;QACT,IAAI,CAAC,2BAA2B,EAAE,CAAC;QACnC,IAAI,CAAC,4BAA4B,EAAE,CAAC;QACpC,IAAI,CAAC,8BAA8B,EAAE,CAAC;QACtC,IAAI,CAAC,sBAAsB,EAAE,CAAC;IAClC,CAAC;CAEJ;AAOD,MAAM,UAAU,cAAc,CAAC,UAAiB,EAAE,YAAqB;IACnE,IAAI,UAAU,GAAG,IAAI,uBAAuB,CAAC,UAAU,EAAC,cAAc,EAAE,YAAY,CAAC,CAAC;IACtF,UAAU,CAAC,aAAa,EAAE,CAAC;IAE3B,IAAI,YAAY,EAAE;QACd,MAAM,cAAc,GAAG,UAAU,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QACxD,wDAAwD;QACxD,IAAI,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;YACvC,MAAc,CAAC,cAAc,CAAC,UAAU,CAAC,GAAG,cAAc,CAAC;SAC/D;KACJ;AAEL,CAAC"}
✄
import { OpenSSL_BoringSSL } from "../ssl_lib/openssl_boringssl.js";
import { socket_library } from "./linux_agent.js";
export class OpenSSL_BoringSSL_Linux extends OpenSSL_BoringSSL {
    constructor(moduleName, socket_library, is_base_hook) {
        super(moduleName, socket_library, is_base_hook);
        this.moduleName = moduleName;
        this.socket_library = socket_library;
    }
    install_tls_keys_callback_hook() {
        this.SSL_CTX_set_keylog_callback = ObjC.available ? new NativeFunction(this.addresses[this.module_name]["SSL_CTX_set_info_callback"], "void", ["pointer", "pointer"]) : new NativeFunction(this.addresses[this.module_name]["SSL_CTX_set_keylog_callback"], "void", ["pointer", "pointer"]);
        var instance = this;
        Interceptor.attach(this.addresses[this.module_name]["SSL_new"], {
            onEnter: function (args) {
                instance.SSL_CTX_set_keylog_callback(args[0], OpenSSL_BoringSSL.keylog_callback);
            }
        });
        Interceptor.attach(this.addresses[this.module_name]["SSL_do_handshake"], {
            onEnter: function (args) {
                instance.SSL_CTX_set_keylog_callback(args[0], OpenSSL_BoringSSL.keylog_callback);
            }
        });
    }
    execute_hooks() {
        this.install_plaintext_read_hook();
        this.install_plaintext_write_hook();
        this.install_tls_keys_callback_hook();
        this.install_extended_hooks();
    }
}
export function boring_execute(moduleName, is_base_hook) {
    var boring_ssl = new OpenSSL_BoringSSL_Linux(moduleName, socket_library, is_base_hook);
    boring_ssl.execute_hooks();
    if (is_base_hook) {
        const init_addresses = boring_ssl.addresses[moduleName];
        // ensure that we only add it to global when we are not 
        if (Object.keys(init_addresses).length > 0) {
            global.init_addresses[moduleName] = init_addresses;
        }
    }
}
✄
{"version":3,"file":"wolfssl_linux.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/linux/wolfssl_linux.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAE5D,MAAM,OAAO,aAAc,SAAQ,OAAO;IAEtC,YAAmB,UAAiB,EAAS,cAAqB,EAAE,YAAqB;QACrF,KAAK,CAAC,UAAU,EAAC,cAAc,CAAC,CAAC;QADlB,eAAU,GAAV,UAAU,CAAO;QAAS,mBAAc,GAAd,cAAc,CAAO;IAElE,CAAC;IAGD,aAAa;QACT,IAAI,CAAC,2BAA2B,EAAE,CAAC;QACnC,IAAI,CAAC,4BAA4B,EAAE,CAAC;QACpC,IAAI,CAAC,8BAA8B,EAAE,CAAC;IA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;SACJ,CAAC,CAAA;IACN,CAAC;CAEJ;AAGD,MAAM,UAAU,eAAe,CAAC,UAAiB,EAAE,YAAqB;IACpE,IAAI,QAAQ,GAAG,IAAI,aAAa,CAAC,UAAU,EAAC,cAAc,EAAE,YAAY,CAAC,CAAC;IAC1E,QAAQ,CAAC,aAAa,EAAE,CAAC;IAEzB,IAAI,YAAY,EAAE;QACd,MAAM,cAAc,GAAG,QAAQ,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QACtD,wDAAwD;QACxD,IAAI,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;YACvC,MAAc,CAAC,cAAc,CAAC,UAAU,CAAC,GAAG,cAAc,CAAC;SAC/D;KACJ;AACL,CAAC"}
✄
import { WolfSSL } from "../ssl_lib/wolfssl.js";
import { socket_library } from "./linux_agent.js";
import { toHexString } from "../shared/shared_functions.js";
export class WolfSSL_Linux extends WolfSSL {
    constructor(moduleName, socket_library, is_base_hook) {
        super(moduleName, socket_library);
        this.moduleName = moduleName;
        this.socket_library = socket_library;
    }
    execute_hooks() {
        this.install_plaintext_read_hook();
        this.install_plaintext_write_hook();
        this.install_tls_keys_callback_hook();
    }
    install_tls_keys_callback_hook() {
        WolfSSL.wolfSSL_get_client_random = new NativeFunction(this.addresses[this.module_name]["wolfSSL_get_client_random"], "int", ["pointer", "pointer", "int"]);
        WolfSSL.wolfSSL_get_server_random = new NativeFunction(this.addresses[this.module_name]["wolfSSL_get_server_random"], "int", ["pointer", "pointer", "int"]);
        //https://www.wolfssl.com/doxygen/group__Setup.html#gaf18a029cfeb3150bc245ce66b0a44758
        WolfSSL.wolfSSL_SESSION_get_master_key = new NativeFunction(this.addresses[this.module_name]["wolfSSL_SESSION_get_master_key"], "int", ["pointer", "pointer", "int"]);
        Interceptor.attach(this.addresses[this.module_name]["wolfSSL_connect"], {
            onEnter: function (args) {
                this.ssl = args[0];
            },
            onLeave: function (retval) {
                this.session = WolfSSL.wolfSSL_get_session(this.ssl);
                var keysString = "";
                //https://www.wolfssl.com/doxygen/group__Setup.html#ga927e37dc840c228532efa0aa9bbec451
                var requiredClientRandomLength = WolfSSL.wolfSSL_get_client_random(this.session, NULL, 0);
                var clientBuffer = Memory.alloc(requiredClientRandomLength);
                WolfSSL.wolfSSL_get_client_random(this.ssl, clientBuffer, requiredClientRandomLength);
                var clientBytes = clientBuffer.readByteArray(requiredClientRandomLength);
                keysString = `${keysString}CLIENT_RANDOM: ${toHexString(clientBytes)}\n`;
                //https://www.wolfssl.com/doxygen/group__Setup.html#ga987035fc600ba9e3b02e2b2718a16a6c
                var requiredServerRandomLength = WolfSSL.wolfSSL_get_server_random(this.session, NULL, 0);
                var serverBuffer = Memory.alloc(requiredServerRandomLength);
                WolfSSL.wolfSSL_get_server_random(this.ssl, serverBuffer, requiredServerRandomLength);
                var serverBytes = serverBuffer.readByteArray(requiredServerRandomLength);
                keysString = `${keysString}SERVER_RANDOM: ${toHexString(serverBytes)}\n`;
                //https://www.wolfssl.com/doxygen/group__Setup.html#gaf18a029cfeb3150bc245ce66b0a44758
                var requiredMasterKeyLength = WolfSSL.wolfSSL_SESSION_get_master_key(this.session, NULL, 0);
                var masterBuffer = Memory.alloc(requiredMasterKeyLength);
                WolfSSL.wolfSSL_SESSION_get_master_key(this.session, masterBuffer, requiredMasterKeyLength);
                var masterBytes = masterBuffer.readByteArray(requiredMasterKeyLength);
                keysString = `${keysString}MASTER_KEY: ${toHexString(masterBytes)}\n`;
                var message = {};
                message["contentType"] = "keylog";
                message["keylog"] = keysString;
                send(message);
            }
        });
    }
}
export function wolfssl_execute(moduleName, is_base_hook) {
    var wolf_ssl = new WolfSSL_Linux(moduleName, socket_library, is_base_hook);
    wolf_ssl.execute_hooks();
    if (is_base_hook) {
        const init_addresses = wolf_ssl.addresses[moduleName];
        // ensure that we only add it to global when we are not 
        if (Object.keys(init_addresses).length > 0) {
            global.init_addresses[moduleName] = init_addresses;
        }
    }
}
✄
{"version":3,"file":"macos_agent.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/macos/macos_agent.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,sBAAsB,EAAqB,MAAM,gCAAgC,CAAC;AAC3F,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAC1G,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAG9D,IAAI,cAAc,GAAG,QAAQ,CAAC;AAC9B,IAAI,WAAW,GAAkB,cAAc,EAAE,CAAA;AAEjD,MAAM,CAAC,MAAM,cAAc,GAAG,mBAAmB,CAAA;AAGjD,SAAS,yBAAyB,CAAC,sBAA0E,EAAE,YAAqB;IAChI,IAAI;QACA,MAAM,WAAW,GAAG,mBAAmB,CAAA;QACvC,MAAM,KAAK,GAAG,WAAW,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC,CAAA;QACrE,IAAI,KAAK,KAAK,SAAS,EAAE;YACrB,MAAM,kCAAkC,CAAA;SAC3C;QAED,IAAI,MAAM,GAAG,QAAQ,CAAA;QAErB,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,eAAe,CAAC,mBAAmB,EAAE,MAAM,CAAC,EAAE;YACpE,OAAO,EAAE,UAAU,IAAI;gBACnB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,CAAA;YAC3C,CAAC;YACD,OAAO,EAAE,UAAU,MAAW;gBAC1B,IAAI,IAAI,CAAC,UAAU,IAAI,SAAS,EAAE;oBAC9B,KAAK,IAAI,GAAG,IAAI,sBAAsB,CAAC,cAAc,CAAC,EAAE;wBACpD,IAAI,KAAK,GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;wBAClB,IAAI,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC,CAAA;wBACjB,IAAI,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE;4BAC7B,GAAG,CAAC,GAAG,IAAI,CAAC,UAAU,wCAAwC,CAAC,CAAA;4BAC/D,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,YAAY,CAAC,CAAA;yBACtC;qBAEJ;iBACJ;YACL,CAAC;SAGJ,CAAC,CAAA;QAEF,GAAG,CAAC,8BAA8B,CAAC,CAAA;KACtC;IAAC,OAAO,KAAK,EAAE;QACZ,MAAM,CAAC,gBAAgB,GAAG,KAAK,CAAC,CAAA;QAChC,GAAG,CAAC,iDAAiD,CAAC,CAAA;KACzD;AACL,CAAC;AAGD,SAAS,mBAAmB,CAAC,sBAA0E,EAAE,YAAqB;IAC1H,kBAAkB,CAAC,cAAc,EAAE,sBAAsB,EAAC,WAAW,EAAC,OAAO,EAAE,YAAY,CAAC,CAAA;AAChG,CAAC;AAID,MAAM,UAAU,wBAAwB;IACpC,sBAAsB,CAAC,cAAc,CAAC,GAAG;QACrC,CAAC,uBAAuB,EAAE,qBAAqB,CAAC,cAAc,CAAC,CAAC;KAAC,CAAA;IAErE,mBAAmB,CAAC,sBAAsB,EAAE,IAAI,CAAC,CAAC,CAAC,yGAAyG;IAC5J,yBAAyB,CAAC,sBAAsB,EAAE,KAAK,CAAC,CAAC;AAC7D,CAAC"}
✄
import { module_library_mapping } from "../shared/shared_structures.js";
import { log, devlog } from "../util/log.js";
import { getModuleNames, ssl_library_loader, invokeHookingFunction } from "../shared/shared_functions.js";
import { boring_execute } from "./openssl_boringssl_macos.js";
var plattform_name = "darwin";
var moduleNames = getModuleNames();
export const socket_library = "libSystem.B.dylib";
function hook_macOS_Dynamic_Loader(module_library_mapping, is_base_hook) {
    try {
        const regex_libdl = /libSystem.B.dylib/;
        const libdl = moduleNames.find(element => element.match(regex_libdl));
        if (libdl === undefined) {
            throw "Darwin Dynamic loader not found!";
        }
        var dlopen = "dlopen";
        Interceptor.attach(Module.getExportByName("libSystem.B.dylib", dlopen), {
            onEnter: function (args) {
                this.moduleName = args[0].readCString();
            },
            onLeave: function (retval) {
                if (this.moduleName != undefined) {
                    for (let map of module_library_mapping[plattform_name]) {
                        let regex = map[0];
                        let func = map[1];
                        if (regex.test(this.moduleName)) {
                            log(`${this.moduleName} was loaded & will be hooked on MacOS!`);
                            func(this.moduleName, is_base_hook);
                        }
                    }
                }
            }
        });
        log("MacOS dynamic loader hooked.");
    }
    catch (error) {
        devlog("Loader error: " + error);
        log("No dynamic loader present for hooking on MacOS.");
    }
}
function hook_macOS_SSL_Libs(module_library_mapping, is_base_hook) {
    ssl_library_loader(plattform_name, module_library_mapping, moduleNames, "MacOS", is_base_hook);
}
export function load_macos_hooking_agent() {
    module_library_mapping[plattform_name] = [
        [/.*libboringssl\.dylib/, invokeHookingFunction(boring_execute)]
    ];
    hook_macOS_SSL_Libs(module_library_mapping, true); // actually we are using the same implementation as we did on iOS, therefore this needs addtional testing
    hook_macOS_Dynamic_Loader(module_library_mapping, false);
}
✄
{"version":3,"file":"openssl_boringssl_macos.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/macos/openssl_boringssl_macos.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAGlD,MAAM,OAAO,uBAAwB,SAAQ,iBAAiB;IAE1D,8BAA8B;QAC1B,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA,CAAC,2EAA2E;QACvG,IAAI,IAAI,CAAC,SAAS,EAAE,EAAE,0EAA0E;YAC5F,IAAI,eAAe,GAAG,KAAK,CAAC;YAE5B,IAAI,gBAAgB,GAAG,MAAM,CAAC,gBAAgB,CAAC,gBAAgB,EAAE,gCAAgC,CAAC,EAAE,UAAU,EAAE,CAAC;YAC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;IACtF,UAAU,CAAC,aAAa,EAAE,CAAC;IAE3B,IAAI,YAAY,EAAE;QACd,MAAM,cAAc,GAAG,UAAU,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QACxD,wDAAwD;QACxD,IAAI,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;YACvC,MAAc,CAAC,cAAc,CAAC,UAAU,CAAC,GAAG,cAAc,CAAC;SAC/D;KACJ;AACL,CAAC"}
✄
import { OpenSSL_BoringSSL } from "../ssl_lib/openssl_boringssl.js";
import { socket_library } from "./macos_agent.js";
export class OpenSSL_BoringSSL_MacOS extends OpenSSL_BoringSSL {
    install_tls_keys_callback_hook() {
        console.log(this.addresses); // currently only for debugging purposes will be removed in future releases
        if (ObjC.available) { // inspired from https://codeshare.frida.re/@andydavies/ios-tls-keylogger/
            var CALLBACK_OFFSET = 0x2A8;
            var foundationNumber = Module.findExportByName('CoreFoundation', 'kCFCoreFoundationVersionNumber')?.readDouble();
            if (foundationNumber == undefined) {
                CALLBACK_OFFSET = 0x2A8;
            }
            else if (foundationNumber >= 1751.108) {
                CALLBACK_OFFSET = 0x2B8; // >= iOS 14.x 
            }
            Interceptor.attach(this.addresses[this.module_name]["SSL_CTX_set_info_callback"], {
                onEnter: function (args) {
                    ptr(args[0]).add(CALLBACK_OFFSET).writePointer(this.keylog_callback);
                }
            });
        }
    }
    constructor(moduleName, socket_library, is_base_hook) {
        var library_method_mapping = {};
        // the iOS implementation needs some further improvements - currently we are not able to get the sockfd from an SSL_read/write invocation
        library_method_mapping[`*${moduleName}*`] = ["SSL_read", "SSL_write", "BIO_get_fd", "SSL_get_session", "SSL_SESSION_get_id", "SSL_new", "SSL_CTX_set_info_callback"];
        library_method_mapping[`*${socket_library}*`] = ["getpeername*", "getsockname*", "ntohs*", "ntohl*"]; // currently those functions gets only identified if we at an asterisk at the end 
        super(moduleName, socket_library, is_base_hook, library_method_mapping);
        this.moduleName = moduleName;
        this.socket_library = socket_library;
    }
    execute_hooks() {
        /*
        currently these function hooks aren't implemented
        this.install_plaintext_read_hook();
        this.install_plaintext_write_hook();
        */
        this.install_tls_keys_callback_hook();
    }
}
export function boring_execute(moduleName, is_base_hook) {
    var boring_ssl = new OpenSSL_BoringSSL_MacOS(moduleName, socket_library, is_base_hook);
    boring_ssl.execute_hooks();
    if (is_base_hook) {
        const init_addresses = boring_ssl.addresses[moduleName];
        // ensure that we only add it to global when we are not 
        if (Object.keys(init_addresses).length > 0) {
            global.init_addresses[moduleName] = init_addresses;
        }
    }
}
✄
{"version":3,"file":"pattern_based_hooking.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/shared/pattern_based_hooking.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAE7C,MAAM,OAAO,mBAAmB;IAK5B,YAAY,MAAc;QAFlB,aAAQ,GAAQ,EAAE,CAAC;QAGvB,IAAI,CAAC,oBAAoB,GAAG,KAAK,CAAC;QAClC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAED,kFAAkF;IAClF,aAAa,CACT,OAAe,EACf,YAAoB,EACpB,eAAsC,EACtC,kBAA4C;QAE5C,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;QACpC,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;QACpC,IAAI,CAAC,oBAAoB,GAAG,KAAK,CAAC;QAElC,MAAM,CAAC,IAAI,CAAC,UAAU,EAAE,UAAU,EAAE,OAAO,EAAE;YACzC,OAAO,EAAE,CAAC,OAAO,EAAE,EAAE;gBACjB,IAAI,CAAC,oBAAoB,GAAG,IAAI,CAAC;gBACjC,GAAG,CAAC,qBAAqB,YAAY,MAAM,OAAO,EAAE,CAAC,CAAC;gBAEtD,qDAAqD;gBACrD,WAAW,CAAC,MAAM,CAAC,OAAO,EAA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,CAAC,8CAA8C,GAAE,KAAK,CAAC,CAAC;SACjE;IACL,CAAC;IAED,oDAAoD;IACpD,2BAA2B,CAAE,WAAmB,EAAE,YAAmC;QACjF,mCAAmC;QACnC,IAAI,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAC;QAEvC,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC,CAAC,uBAAuB;QAC1D,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,mBAAmB;QAE9C,gFAAgF;QAChF,IAAI,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,IAAI,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,EAAE;YAC1D,MAAM,cAAc,GAAG,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC;YACrD,MAAM,cAAc,GAAG,cAAc,CAAC,OAAO,CAAC;YAC9C,MAAM,eAAe,GAAG,cAAc,CAAC,QAAQ,CAAC;YAEhD,MAAM,CAAC,sBAAsB,QAAQ,QAAQ,IAAI,EAAE,CAAC,CAAC;YAErD,qCAAqC;YACrC,IAAI,CAAC,mBAAmB,CAAC,EAAE,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,eAAe,EAAE,EAAE,YAAY,CAAC,CAAC;SAClG;aAAM;YACH,MAAM,CAAC,qEAAqE,CAAC,CAAC;SACjF;IACL,CAAC;CACJ"}
✄
import { devlog, log } from "../util/log.js";
export class PatternBasedHooking {
    constructor(module) {
        this.patterns = {};
        this.found_ssl_log_secret = false;
        this.module = module;
    }
    // Method to hook by pattern, with a custom function to handle onEnter and onLeave
    hookByPattern(pattern, pattern_name, onMatchCallback, onCompleteCallback) {
        const moduleBase = this.module.base;
        const moduleSize = this.module.size;
        this.found_ssl_log_secret = false;
        Memory.scan(moduleBase, moduleSize, pattern, {
            onMatch: (address) => {
                this.found_ssl_log_secret = true;
                log(`Pattern found at (${pattern_name}): ${address}`);
                // Attach the hook using the provided onMatchCallback
                Interceptor.attach(address, {
                    onEnter: function (args) {
                        onMatchCallback(args);
                    },
                    onLeave: function (retval) {
                        // Optionally handle return value or additional behavior
                    }
                });
            },
            onComplete: () => {
                onCompleteCallback(this.found_ssl_log_secret);
            }
        });
    }
    // Method to hook the module with patterns provided as arguments
    hookModuleByPattern(patterns, onMatchCallback) {
        const moduleBase = this.module.base;
        const moduleSize = this.module.size;
        devlog(`Module Base Address: ${moduleBase}`);
        devlog(`Module Size: ${moduleSize}`);
        // Start by hooking using the primary pattern
        this.hookByPattern(patterns.primary, "primary_pattern", onMatchCallback, (pattern_success) => {
            // If the primary pattern doesn't work, try the fallback pattern
            if (!pattern_success) {
                devlog("Primary pattern failed, trying fallback pattern...");
                this.hookByPattern(patterns.fallback, "fallback_pattern", onMatchCallback, (pattern_success_alt) => {
                    if (!pattern_success_alt) {
                        devlog("None of the patterns worked. You may need to adjust the patterns.");
                    }
                });
            }
        });
    }
    loadPatternsFromJSON(jsonContent) {
        try {
            this.patterns = JSON.parse(jsonContent);
            devlog("Patterns loaded successfully from JSON.");
        }
        catch (error) {
            devlog("[-] Error loading or parsing JSON pattern:  " + error);
        }
    }
    // Method to hook functions using patterns from JSON
    hook_with_pattern_from_json(jsonContent, hookCallback) {
        // Load patterns from the JSON file
        this.loadPatternsFromJSON(jsonContent);
        const platform = Process.platform; // e.g., linux, android
        const arch = Process.arch; // e.g., x64, arm64
        // Access the relevant pattern for the module based on platform and architecture
        if (this.patterns[platform] && this.patterns[platform][arch]) {
            const modulePatterns = this.patterns[platform][arch];
            const primaryPattern = modulePatterns.primary;
            const fallbackPattern = modulePatterns.fallback;
            devlog(`Using patterns for ${platform} and ${arch}`);
            // Hook the module using the patterns
            this.hookModuleByPattern({ primary: primaryPattern, fallback: fallbackPattern }, hookCallback);
        }
        else {
            devlog("[-] No patterns available for the current platform or architecture.");
        }
    }
}
✄
{"version":3,"file":"shared_functions.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 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;IAC3C,MAAM,OAAO,GAAG,QAAQ,CAAC,gBAAgB,CAAC,UAAU,GAAG,UAAU,GAAG,GAAG,GAAG,UAAU,CAAC,CAAC;IAEtF,OAAO,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC;AAC9B,CAAC;AAGD,qFAAqF;AACrF,MAAM,UAAU,qBAAqB,CAAC,IAAyD;IAC3F,OAAO,CAAC,UAAkB,EAAE,YAAqB,EAAE,EAAE;QACjD,IAAI,CAAC,UAAU,EAAE,YAAY,CAAC,CAAC;IACnC,CAAC,CAAC;AACN,CAAC;AAGD,MAAM,UAAU,8BAA8B,CAAC,OAAiC;IAC5E,OAAO,KAAK;SACP,IAAI,CAAC,IAAI,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC,qDAAqD;SACnF,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,4CAA4C;SAC1G,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,uCAAuC;AAC1D,CAAC"}
✄
import { log, devlog } from "../util/log.js";
import { AF_INET, AF_INET6 } from "./shared_structures.js";
function wait_for_library_loaded(module_name) {
    let timeout_library = 5;
    let module_adress = Module.findBaseAddress(module_name);
    if (module_adress === NULL || module_adress === null) {
        log("[*] Waiting " + timeout_library + " milliseconds for the loading of " + module_name);
        setTimeout(wait_for_library_loaded, timeout_library);
    }
}
/**
 * This file contains methods which are shared for reading
 * secrets/data from different libraries. These methods are
 * indipendent from the implementation of ssl/tls, but they depend
 * on libc.
 */
export function ssl_library_loader(plattform_name, module_library_mapping, moduleNames, plattform_os, is_base_hook) {
    for (let map of module_library_mapping[plattform_name]) {
        let regex = new RegExp(map[0]);
        let func = map[1];
        for (let module of moduleNames) {
            if (regex.test(module)) {
                try {
                    log(`${module} found & will be hooked on ${plattform_os}!`);
                    try {
                        Module.ensureInitialized(module);
                    }
                    catch (error) {
                        wait_for_library_loaded(module);
                    }
                    // on some Android Apps we encounterd the problem of multiple SSL libraries but only one is used for the SSL encryption/decryption
                    func(module, is_base_hook);
                }
                catch (error) {
                    devlog(`error: skipping module ${module}`);
                    // when we enable the logging of devlogs we can print the error message as well for further improving this part
                    devlog("Loader error: " + error);
                    //  {'description': 'Could not find *libssl*.so!SSL_ImportFD', 'type': 'error'}
                }
            }
        }
    }
}
//TODO: 
export function getSocketLibrary() {
    var moduleNames = getModuleNames();
    var socket_library_name = "";
    switch (Process.platform) {
        case "linux":
            return moduleNames.find(element => element.match(/libc.*\.so/));
        case "windows":
            return "WS2_32.dll";
        case "darwin":
            return "libSystem.B.dylib";
        default:
            log(`Platform "${Process.platform} currently not supported!`);
            return "";
    }
}
export function getModuleNames() {
    var moduleNames = [];
    Process.enumerateModules().forEach(item => moduleNames.push(item.name));
    return moduleNames;
}
export function readAddresses(moduleName, library_method_mapping) {
    const resolver = new ApiResolver("module");
    const addresses = {};
    // Initialize addresses[moduleName] as an empty object if not already initialized
    if (!addresses[moduleName]) {
        addresses[moduleName] = {};
    }
    for (const library_name in library_method_mapping) {
        library_method_mapping[library_name].forEach(function (method) {
            const matches = resolver.enumerateMatches("exports:" + library_name + "!" + method);
            let match_number = 0;
            let method_name = method.toString();
            if (method_name.endsWith("*")) { // this is for the temporary iOS bug using Frida's ApiResolver
                method_name = method_name.substring(0, method_name.length - 1);
            }
            if (matches.length == 0) {
                throw "Could not find " + library_name + "!" + method;
            }
            else if (matches.length == 1) {
                devlog("Found " + method + " " + matches[0].address);
            }
            else {
                // Sometimes Frida returns duplicates or it finds more than one result.
                for (let k = 0; k < matches.length; k++) {
                    if (matches[k].name.endsWith(method_name)) {
                        match_number = k;
                        devlog("Found " + method + " " + matches[match_number].address);
                        break;
                    }
                }
            }
            addresses[moduleName][method_name] = matches[match_number].address;
        });
    }
    return addresses;
}
/**
 * Read the addresses for the given methods from the given modules
 * @param {{[key: string]: Array<String> }} library_method_mapping A string indexed list of arrays, mapping modules to methods
 * @param is_base_hook a boolean value to indicate if this hooks are done on the start or during dynamic library loading
 * @return {{[key: string]: { [functionName: string]: NativePointer } }} A string indexed list of NativePointers, which point to the respective methods
 */
export function readAddresses2(moduleName, library_method_mapping) {
    var resolver = new ApiResolver("module");
    var addresses = {};
    // Initialize addresses[library_name] as an empty object if not already initialized
    if (!addresses[moduleName]) {
        addresses[moduleName] = {};
    }
    for (let library_name in library_method_mapping) {
        library_method_mapping[library_name].forEach(function (method) {
            var matches = resolver.enumerateMatches("exports:" + library_name + "!" + method);
            var match_number = 0;
            var method_name = method.toString();
            if (method_name.endsWith("*")) { // this is for the temporary iOS bug using Frida's ApiResolver
                method_name = method_name.substring(0, method_name.length - 1);
            }
            if (matches.length == 0) {
                throw "Could not find " + library_name + "!" + method;
            }
            else if (matches.length == 1) {
                devlog("Found " + method + " " + matches[0].address);
            }
            else {
                // Sometimes Frida returns duplicates or it finds more than one result.
                for (var k = 0; k < matches.length; k++) {
                    if (matches[k].name.endsWith(method_name)) {
                        match_number = k;
                        devlog("Found " + method + " " + matches[match_number].address);
                        break;
                    }
                }
            }
            addresses[moduleName][method_name] = matches[match_number].address;
        });
    }
    return addresses;
}
/**
 * Returns the base address of a given module
 * @param {string} moduleName Name of module to return base address from
 * @returns
 */
export function getBaseAddress(moduleName) {
    console.log("Module to find:", moduleName);
    const modules = Process.enumerateModules();
    for (const module of modules) {
        if (module.name == moduleName) {
            return module.base;
        }
    }
    return null;
}
/**
* Returns a dictionary of a sockfd's "src_addr", "src_port", "dst_addr", and
* "dst_port".
* @param {int} sockfd The file descriptor of the socket to inspect.
* @param {boolean} isRead If true, the context is an SSL_read call. If
*     false, the context is an SSL_write call.
* @param {{ [key: string]: NativePointer}} methodAddresses Dictionary containing (at least) addresses for getpeername, getsockname, ntohs and ntohl
* @return {{ [key: string]: string | number }} Dictionary of sockfd's "src_addr", "src_port", "dst_addr",
*     and "dst_port".
*/
export function getPortsAndAddresses(sockfd, isRead, methodAddresses, enable_default_fd) {
    var message = {};
    if (enable_default_fd && (sockfd < 0)) {
        message["src" + "_port"] = 1234;
        message["src" + "_addr"] = "127.0.0.1";
        message["dst" + "_port"] = 2345;
        message["dst" + "_addr"] = "127.0.0.1";
        message["ss_family"] = "AF_INET";
        return message;
    }
    var getpeername = new NativeFunction(methodAddresses["getpeername"], "int", ["int", "pointer", "pointer"]);
    var getsockname = new NativeFunction(methodAddresses["getsockname"], "int", ["int", "pointer", "pointer"]);
    var ntohs = new NativeFunction(methodAddresses["ntohs"], "uint16", ["uint16"]);
    var ntohl = new NativeFunction(methodAddresses["ntohl"], "uint32", ["uint32"]);
    var addrlen = Memory.alloc(4);
    var addr = Memory.alloc(128);
    var src_dst = ["src", "dst"];
    for (var i = 0; i < src_dst.length; i++) {
        addrlen.writeU32(128);
        if ((src_dst[i] == "src") !== isRead) {
            devlog("src");
            getsockname(sockfd, addr, addrlen);
        }
        else {
            devlog("dst");
            getpeername(sockfd, addr, addrlen);
        }
        if (addr.readU16() == AF_INET) {
            message[src_dst[i] + "_port"] = ntohs(addr.add(2).readU16());
            message[src_dst[i] + "_addr"] = ntohl(addr.add(4).readU32());
            message["ss_family"] = "AF_INET";
        }
        else if (addr.readU16() == AF_INET6) {
            message[src_dst[i] + "_port"] = ntohs(addr.add(2).readU16());
            message[src_dst[i] + "_addr"] = "";
            var ipv6_addr = addr.add(8);
            for (var offset = 0; offset < 16; offset += 1) {
                message[src_dst[i] + "_addr"] += ("0" + ipv6_addr.add(offset).readU8().toString(16).toUpperCase()).substr(-2);
            }
            if (message[src_dst[i] + "_addr"].toString().indexOf("00000000000000000000FFFF") === 0) {
                message[src_dst[i] + "_addr"] = ntohl(ipv6_addr.add(12).readU32());
                message["ss_family"] = "AF_INET";
            }
            else {
                message["ss_family"] = "AF_INET6";
            }
        }
        else {
            devlog("[-] getPortsAndAddresses resolving error:" + addr.readU16());
            throw "Only supporting IPv4/6";
        }
    }
    return message;
}
/**
 * Convert a Java byte array to string
 * @param byteArray The array to convert
 * @returns {string} The resulting string
 */
export function byteArrayToString(byteArray) {
    return Array.from(byteArray, function (byte) {
        return ('0' + (byte & 0xFF).toString(16)).slice(-2);
    }).join('');
}
export function toHexString(byteArray) {
    const byteToHex = [];
    for (let n = 0; n <= 0xff; ++n) {
        const hexOctet = n.toString(16).padStart(2, "0");
        byteToHex.push(hexOctet);
    }
    return Array.prototype.map.call(new Uint8Array(byteArray), n => byteToHex[n]).join("");
}
/**
 * Convert a Java Reflection array to string
 * @param byteArray The array to convert
 * @returns {string} The resulting string
 */
export function reflectionByteArrayToString(byteArray) {
    var result = "";
    var arrayReflect = Java.use("java.lang.reflect.Array");
    for (var i = 0; i < arrayReflect.getLength(byteArray); i++) {
        result += ('0' + (arrayReflect.get(byteArray, i) & 0xFF).toString(16)).slice(-2);
    }
    return result;
}
/**
 * Convert a Java byte arry to number (Big Endian)
 * @param byteArray The array to convert
 * @returns {number} The resulting number
 */
export function byteArrayToNumber(byteArray) {
    var value = 0;
    for (var i = 0; i < byteArray.length; i++) {
        value = (value * 256) + (byteArray[i] & 0xFF);
    }
    return value;
}
/**
 * Access an attribute of a Java Class
 * @param Instance The instace you want to access
 * @param fieldName The name of the attribute
 * @returns The value of the attribute of the requested field
 */
export function getAttribute(Instance, fieldName) {
    var clazz = Java.use("java.lang.Class");
    var field = Java.cast(Instance.getClass(), clazz).getDeclaredField(fieldName);
    field.setAccessible(true);
    return field.get(Instance);
}
/**
 *
 * @param moduleName String of the name of the module e.g. libssl.so
 * @param symbolName the symbol where we do our check e.g. SSL_write_ex
 * @returns
 */
export function isSymbolAvailable(moduleName, symbolName) {
    const resolver = new ApiResolver("module");
    const matches = resolver.enumerateMatches("exports:" + moduleName + "!" + symbolName);
    return matches.length > 0;
}
// Wrapper function to ensure all execute functions conform to the required signature
export function invokeHookingFunction(func) {
    return (moduleName, is_base_hook) => {
        func(moduleName, is_base_hook);
    };
}
export function get_hex_string_from_byte_array(keyData) {
    return Array
        .from(new Uint8Array(keyData)) // Convert byte array to Uint8Array and then to Array
        .map(byte => byte.toString(16).padStart(2, '0').toUpperCase()) // Convert each byte to a 2-digit hex string
        .join(''); // Join all the hex values with a space
}
✄
{"version":3,"file":"shared_structures.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/shared/shared_structures.ts"],"names":[],"mappings":"AAAA,2DAA2D;AAG3D,MAAM,CAAC,IAAI,sBAAsB,GAAuD,EAAE,CAAC;AAG3F,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,CAAA;AACxB,MAAM,CAAC,MAAM,QAAQ,GAAG,EAAE,CAAA;AAC1B,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC"}
✄
/* In this file we store global variables and structures */
export var module_library_mapping = {};
export const AF_INET = 2;
export const AF_INET6 = 10;
export const pointerSize = Process.pointerSize;
✄
{"version":3,"file":"cronet.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/ssl_lib/cronet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,MAAM,+BAA+B,CAAC;AAE/E,OAAO,EAAE,MAAM,EAAO,MAAM,gBAAgB,CAAC;AAK7C,MAAM,OAAO,MAAM;IAUf,YAAmB,UAAiB,EAAS,cAAqB,EAAC,YAAqB,EAAS,6BAAgE;QAA9I,eAAU,GAAV,UAAU,CAAO;QAAS,mBAAc,GAAd,cAAc,CAAO;QAA+B,kCAA6B,GAA7B,6BAA6B,CAAmC;QAPjK,mBAAmB;QACnB,2BAAsB,GAAqC,EAAE,CAAC;QAO1D,IAAI,CAAC,WAAW,GAAG,UAAU,CAAC;QAC9B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;IACrC,CAAC;IAED,iBAAiB,CAAC,MAAqB,EAAE,gBAAwB;QAC7D,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE;YAClB,MAAM,iBAAiB,GAAkB,MAAM,CAAC,GA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EAAE,EAAE;YACpB,QAAQ,GAAG,QAAQ,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC,CAAE,2BAA2B;YACrE,+BAA+B;SAClC;aAAM;YACH,MAAM,CAAC,qCAAqC,CAAC,CAAC;SACjD;QAED,+CAA+C;QAC/C,IAAI,CAAC,YAAY,CAAC,MAAM,EAAE,EAAE;YACxB,aAAa,GAAG,IAAI,CAAC,iCAAiC,CAAC,YAAY,CAAC,CAAA;SACvE;aAAK;YACF,MAAM,CAAC,yCAAyC,CAAC,CAAC;SACrD;QAED,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE;YAClB,YAAY;YACZ,MAAM,OAAO,GAAG,MAAM,CAAC,aAAa,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,uCAAuC;YAEjG,oDAAoD;YACpD,MAAM,MAAM,GAAG,8BAA8B,CAAC,OAAO,CAAC,CAAC;YAEvD,UAAU,GAAG,MAAM,CAAC;SACvB;aAAM;YACH,MAAM,CAAC,gCAAgC,CAAC,CAAC;SAC5C;QAED,MAAM,CAAC,wEAAwE,CAAC,CAAC;QACjF,IAAI,OAAO,GAA8C,EAAE,CAAA;QAC3D,OAAO,CAAC,aAAa,CAAC,GAAG,QAAQ,CAAA;QACjC,OAAO,CAAC,QAAQ,CAAC,GAAG,QAAQ,GAAC,GAAG,GAAC,aAAa,GAAC,GAAG,GAAC,UAAU,CAAC;QAC9D,IAAI,CAAC,OAAO,CAAC,CAAA;IACjB,CAAC;IAED,2BAA2B;QACvB,MAAM;IACV,CAAC;IAED,4BAA4B;QACxB,MAAM;IACV,CAAC;IAED,2BAA2B;QACvB,+CAA+C;IACnD,CAAC;CACJ"}
✄
import { get_hex_string_from_byte_array } from "../shared/shared_functions.js";
import { devlog } from "../util/log.js";
export class Cronet {
    constructor(moduleName, socket_library, is_base_hook, passed_library_method_mapping) {
        this.moduleName = moduleName;
        this.socket_library = socket_library;
        this.passed_library_method_mapping = passed_library_method_mapping;
        // global variables
        this.library_method_mapping = {};
        this.module_name = moduleName;
        this.is_base_hook = is_base_hook;
    }
    get_client_random(s3_ptr, SSL3_RANDOM_SIZE) {
        if (!s3_ptr.isNull()) {
            const client_random_ptr = s3_ptr.add(0x30); // Offset in s3 struct
            //@ts-ignore
            const client_random = Memory.readByteArray(client_random_ptr, SSL3_RANDOM_SIZE);
            // Convert the byte array to a hex string
            const hexClientRandom = get_hex_string_from_byte_array(new Uint8Array(client_random));
            return hexClientRandom;
        }
        else {
            devlog("[Error] s3 pointer is NULL");
            return "";
        }
    }
    get_client_random_from_ssl_struct(ssl_st_ptr) {
        const SSL3_RANDOM_SIZE = 32;
        let offset_s3;
        switch (Process.arch) {
            case 'x64':
                offset_s3 = 0x30;
                break;
            case 'arm64':
                offset_s3 = 0x30;
                break;
            case 'ia32':
                offset_s3 = 0x2C;
                break;
            case 'arm':
                offset_s3 = 0x2C;
                break;
            default:
                devlog("[Error] Unsupported architecture");
                return "";
        }
        const s3_ptr = ssl_st_ptr.add(offset_s3).readPointer();
        return this.get_client_random(s3_ptr, SSL3_RANDOM_SIZE);
    }
    dumpKeys(labelPtr, sslStructPtr, keyPtr) {
        const KEY_LENGTH = 32; // Assuming key length is 32 bytes
        let labelStr = '';
        let client_random = '';
        let secret_key = '';
        // Read the label (the label pointer might contain a C string)
        if (!labelPtr.isNull()) {
            labelStr = labelPtr.readCString() ?? ''; // Read label as a C string
            //devlog(`Label: ${labelStr}`);
        }
        else {
            devlog("[Error] Argument 'labelPtr' is NULL");
        }
        // Extract client_random from the SSL structure
        if (!sslStructPtr.isNull()) {
            client_random = this.get_client_random_from_ssl_struct(sslStructPtr);
        }
        else {
            devlog("[Error] Argument 'sslStructPtr' is NULL");
        }
        if (!keyPtr.isNull()) {
            //@ts-ignore
            const keyData = Memory.readByteArray(keyPtr, KEY_LENGTH); // Read the key data (KEY_LENGTH bytes)
            // Convert the byte array to a string of  hex values
            const hexKey = get_hex_string_from_byte_array(keyData);
            secret_key = hexKey;
        }
        else {
            devlog("[Error] Argument 'key' is NULL");
        }
        devlog("invoking ssl_log_secret() from BoringSSL statically linked into Cronet");
        var message = {};
        message["contentType"] = "keylog";
        message["keylog"] = labelStr + " " + client_random + " " + secret_key;
        send(message);
    }
    install_plaintext_read_hook() {
        // TBD
    }
    install_plaintext_write_hook() {
        // TBD
    }
    install_key_extraction_hook() {
        // needs to be setup for the specific plattform
    }
}
✄
{"version":3,"file":"gnutls.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/ssl_lib/gnutls.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAe,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACjH,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAE3D,MAAM,OAAO,MAAM;IAef,YAAmB,UAAiB,EAAS,cAAqB,EAAQ,6BAAgE;QAAvH,eAAU,GAAV,UAAU,CAAO;QAAS,mBAAc,GAAd,cAAc,CAAO;QAAQ,kCAA6B,GAA7B,6BAA6B,CAAmC;QAb1I,mBAAmB;QACnB,2BAAsB,GAAqC,EAAE,CAAC;QAa1D,IAAG,OAAO,6BAA6B,KAAK,WAAW,EAAC;YACpD,IAAI,CAAC,sBAAsB,GAAG,6BAA6B,CAAC;SAC/D;aAAI;YACD,IAAI,CAAC,sBAAsB,CAAC,IAAI,UAAU,GAAG,CAAC,GAAG,CAAC,oBAAoB,EAAE,oBAAoB,EAAE,oCAAoC,EAAE,0BAA0B,EAAE,uBAAuB,EAAE,aAAa,EAAE,kBAAkB,EAAE,oCAAoC,EAAE,2BAA2B,CAAC,CAAA;YAC9R,IAAI,CAAC,sBAAsB,CAAC,IAAI,cAAc,GAAG,CAAC,GAAG,CAAC,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;SACxG;QAED,IAAI,CAAC,SAAS,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M,CAAC,yBAAyB,CAAC,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,CAAC,CAAA;KAClF;SAAI;QACD,OAAO,CAAC,GAAG,CAAC,4CAA4C,CAAC,CAAC;KAC7D;IAED,IAAI,iBAAiB,GAAG,EAAE,CAAA;IAC1B,IAAI,iBAAiB,GAAG,EAAE,CAAA;IAC1B,CAAC,GAAG,iBAAiB,CAAC,WAAW,EAAE,CAAA;IACnC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,iBAAiB,EAAE,CAAC,EAAE,EAAE;QACpC,sEAAsE;QACtE,2BAA2B;QAE3B,iBAAiB;YACb,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;KACtE;IACD,OAAO,CAAC,QAAQ,CAAC,GAAG,KAAK,CAAC,WAAW,EAAE,GAAG,GAAG,GAAG,iBAAiB,GAAG,GAAG,GAAG,UAAU,CAAA;IACpF,IAAI,CAAC,OAAO,CAAC,CAAA;IACb,OAAO,CAAC,CAAA;AACZ,CAAC,EAAE,KAAK,EAAE,CAAC,SAAS,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,AAxCtB,CAwCsB"}
✄
import { readAddresses, getPortsAndAddresses, getBaseAddress } from "../shared/shared_functions.js";
import { log } from "../util/log.js";
import { offsets, enable_default_fd } from "../ssl_log.js";
export class GnuTLS {
    constructor(moduleName, socket_library, passed_library_method_mapping) {
        this.moduleName = moduleName;
        this.socket_library = socket_library;
        this.passed_library_method_mapping = passed_library_method_mapping;
        // global variables
        this.library_method_mapping = {};
        if (typeof passed_library_method_mapping !== 'undefined') {
            this.library_method_mapping = passed_library_method_mapping;
        }
        else {
            this.library_method_mapping[`*${moduleName}*`] = ["gnutls_record_recv", "gnutls_record_send", "gnutls_session_set_keylog_function", "gnutls_transport_get_int", "gnutls_session_get_id", "gnutls_init", "gnutls_handshake", "gnutls_session_get_keylog_function", "gnutls_session_get_random"];
            this.library_method_mapping[`*${socket_library}*`] = ["getpeername", "getsockname", "ntohs", "ntohl"];
        }
        this.addresses = readAddresses(moduleName, this.library_method_mapping);
        this.module_name = moduleName;
        // @ts-ignore
        if (offsets != "{OFFSETS}" && offsets.gnutls != null) {
            if (offsets.sockets != null) {
                const socketBaseAddress = getBaseAddress(socket_library);
                for (const method of Object.keys(offsets.sockets)) {
                    //@ts-ignore
                    this.addresses[this.moduleName][`${method}`] = offsets.sockets[`${method}`].absolute || socketBaseAddress == null ? ptr(offsets.sockets[`${method}`].address) : socketBaseAddress.add(ptr(offsets.sockets[`${method}`].address));
                }
            }
            const libraryBaseAddress = getBaseAddress(moduleName);
            if (libraryBaseAddress == null) {
                log("Unable to find library base address! Given address values will be interpreted as absolute ones!");
            }
            for (const method of Object.keys(offsets.gnutls)) {
                //@ts-ignore
                this.addresses[this.moduleName][`${method}`] = offsets.gnutls[`${method}`].absolute || libraryBaseAddress == null ? ptr(offsets.gnutls[`${method}`].address) : libraryBaseAddress.add(ptr(offsets.gnutls[`${method}`].address));
            }
        }
        GnuTLS.gnutls_transport_get_int = new NativeFunction(this.addresses[this.moduleName]["gnutls_transport_get_int"], "int", ["pointer"]);
        GnuTLS.gnutls_session_get_id = new NativeFunction(this.addresses[this.moduleName]["gnutls_session_get_id"], "int", ["pointer", "pointer", "pointer"]);
        GnuTLS.gnutls_session_set_keylog_function = new NativeFunction(this.addresses[this.moduleName]["gnutls_session_set_keylog_function"], "void", ["pointer", "pointer"]);
        GnuTLS.gnutls_session_get_random = new NativeFunction(this.addresses[this.moduleName]["gnutls_session_get_random"], "pointer", ["pointer", "pointer", "pointer"]);
    }
    /**
       * Get the session_id of SSL object and return it as a hex string.
       * @param {!NativePointer} ssl A pointer to an SSL object.
       * @return {dict} A string representing the session_id of the SSL object's
       *     SSL_SESSION. For example,
       *     "59FD71B7B90202F359D89E66AE4E61247954E28431F6C6AC46625D472FF76336".
       */
    static getSslSessionId(session) {
        var len_pointer = Memory.alloc(4);
        var err = GnuTLS.gnutls_session_get_id(session, NULL, len_pointer);
        if (err != 0) {
            if (enable_default_fd) {
                log("using dummy SessionID: 59FD71B7B90202F359D89E66AE4E61247954E28431F6C6AC46625D472FF76337");
                return "59FD71B7B90202F359D89E66AE4E61247954E28431F6C6AC46625D472FF76337";
            }
            return "";
        }
        var len = len_pointer.readU32();
        var p = Memory.alloc(len);
        err = GnuTLS.gnutls_session_get_id(session, p, len_pointer);
        if (err != 0) {
            if (enable_default_fd) {
                log("using dummy SessionID: 59FD71B7B90202F359D89E66AE4E61247954E28431F6C6AC46625D472FF76337");
                return "59FD71B7B90202F359D89E66AE4E61247954E28431F6C6AC46625D472FF76337";
            }
            return "";
        }
        var session_id = "";
        for (var i = 0; i < len; i++) {
            // Read a byte, convert it to a hex string (0xAB ==> "AB"), and append
            // it to session_id.
            session_id +=
                ("0" + p.add(i).readU8().toString(16).toUpperCase()).substr(-2);
        }
        return session_id;
    }
    install_plaintext_read_hook() {
        var current_module_name = this.module_name;
        var lib_addesses = this.addresses;
        Interceptor.attach(this.addresses[this.moduleName]["gnutls_record_recv"], {
            onEnter: function (args) {
                var message = getPortsAndAddresses(GnuTLS.gnutls_transport_get_int(args[0]), true, lib_addesses[current_module_name], enable_default_fd);
                message["ssl_session_id"] = GnuTLS.getSslSessionId(args[0]);
                message["function"] = "SSL_read";
                this.message = message;
                this.buf = args[1];
            },
            onLeave: function (retval) {
                retval |= 0; // Cast retval to 32-bit integer.
                if (retval <= 0) {
                    return;
                }
                this.message["contentType"] = "datalog";
                send(this.message, this.buf.readByteArray(retval));
            }
        });
    }
    install_plaintext_write_hook() {
        var current_module_name = this.module_name;
        var lib_addesses = this.addresses;
        Interceptor.attach(this.addresses[this.moduleName]["gnutls_record_send"], {
            onEnter: function (args) {
                var message = getPortsAndAddresses(GnuTLS.gnutls_transport_get_int(args[0]), false, lib_addesses[current_module_name], enable_default_fd);
                message["ssl_session_id"] = GnuTLS.getSslSessionId(args[0]);
                message["function"] = "SSL_write";
                message["contentType"] = "datalog";
                send(message, args[1].readByteArray(parseInt(args[2])));
            },
            onLeave: function (retval) {
            }
        });
    }
    install_tls_keys_callback_hook() {
    }
}
//NativeCallback
GnuTLS.keylog_callback = new NativeCallback(function (session, label, secret) {
    var message = {};
    message["contentType"] = "keylog";
    var secret_len = secret.add(Process.pointerSize).readUInt();
    var secret_str = "";
    var p = secret.readPointer();
    for (var i = 0; i < secret_len; i++) {
        // Read a byte, convert it to a hex string (0xAB ==> "AB"), and append
        // it to secret_str.
        secret_str +=
            ("0" + p.add(i).readU8().toString(16).toUpperCase()).substr(-2);
    }
    var server_random_ptr = Memory.alloc(Process.pointerSize + 4);
    var client_random_ptr = Memory.alloc(Process.pointerSize + 4);
    if (typeof this !== "undefined") {
        GnuTLS.gnutls_session_get_random(session, client_random_ptr, server_random_ptr);
    }
    else {
        console.log("[-] Error while installing keylog callback");
    }
    var client_random_str = "";
    var client_random_len = 32;
    p = client_random_ptr.readPointer();
    for (i = 0; i < client_random_len; i++) {
        // Read a byte, convert it to a hex string (0xAB ==> "AB"), and append
        // it to client_random_str.
        client_random_str +=
            ("0" + p.add(i).readU8().toString(16).toUpperCase()).substr(-2);
    }
    message["keylog"] = label.readCString() + " " + client_random_str + " " + secret_str;
    send(message);
    return 0;
}, "int", ["pointer", "pointer", "pointer"]);
✄
{"version":3,"file":"java_ssl_libs.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/ssl_lib/java_ssl_libs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACvE,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAGrD,MAAM,OAAO,QAAQ;IAEjB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F,IAAI,QAAQ,CAAC,OAAO,EAAE,KAAK,aAAa,EAAE;oCACtC,OAAO,IAAI,CAAC,gBAAgB,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAA;iCAC5C;gCAED,4NAA4N;gCAC5N,8CAA8C;gCAC9C,4CAA4C;gCAC5C,sEAAsE;6BACzE;4BAED,OAAO,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAA;yBACpC;oBACL,CAAC,CAAA;gBACL,CAAC,CAAC,CAAA;YACN,CAAC,EAAE,CAAC,CAAC,CAAC;SACT;IACL,CAAC;CACJ"}
✄
import { log, devlog } from "../util/log.js";
import { execute as conscrypt_execute } from "../android/conscrypt.js";
import { isAndroid } from "../util/process_infos.js";
export class SSL_Java {
    install_java_hooks() {
        if (Java.available) {
            setTimeout(function () {
                Java.perform(function () {
                    //Conscrypt needs early instrumentation as we block the provider installation
                    var Security = Java.use("java.security.Security");
                    if (Security.getProviders().toString().includes("GmsCore_OpenSSL")) {
                        log("WARNING: PID " + Process.id + " Detected GmsCore_OpenSSL Provider. This can be a bit unstable. If you having issues, rerun with -spawn for early instrumentation. Trying to remove it to fall back on default Provider");
                        Security.removeProvider("GmsCore_OpenSSL");
                        log("Removed GmsCore_OpenSSL");
                    }
                    //As the classloader responsible for loading ProviderInstaller sometimes is not present from the beginning on,
                    //we always have to watch the classloader activity
                    conscrypt_execute();
                    //Now do the same for Ssl_guard
                    if (Security.getProviders().toString().includes("Ssl_Guard")) {
                        log("Ssl_Guard deteced, removing it to fall back on default Provider");
                        Security.removeProvider("Ssl_Guard");
                        log("Removed Ssl_Guard");
                    }
                    //Same thing for Conscrypt provider which has been manually inserted (not by providerinstaller)
                    if (Security.getProviders().toString().includes("Conscrypt version")) {
                        log("Conscrypt detected");
                        Security.removeProvider("Conscrypt");
                        log("Removed Conscrypt");
                    }
                    //Same thing for WolfSSLProvider provider which has been manually inserted (not by providerinstaller)
                    if (Security.getProviders().toString().includes("WolfSSLProvider")) {
                        log("WolfSSLProvider detected");
                        Security.removeProvider("WolfSSLProvider");
                        log("Removed WolfSSLProvider");
                    }
                    // run with -do in order to see which other securiy providers we should remove
                    devlog("Remaining: " + Security.getProviders().toString());
                    // TBD: AndroidOpenSSL version 1.0 or BC version 1.61? 
                    //Hook insertProviderAt/addprovider for dynamic provider blocking
                    Security.insertProviderAt.implementation = function (provider, position) {
                        if (provider.getName().includes("Conscrypt") || provider.getName().includes("Ssl_Guard") || provider.getName().includes("GmsCore_OpenSSL") || provider.getName().includes("WolfSSLProvider")) {
                            log("Blocking provider registration (insertProviderAt) of  " + provider.getName());
                            return position;
                        }
                        else {
                            return this.insertProviderAt(provider, position);
                        }
                    };
                    //Same for addProvider
                    Security.insertProviderAt.implementation = function (provider) {
                        if (provider.getName().includes("Conscrypt") || provider.getName().includes("Ssl_Guard") || provider.getName().includes("GmsCore_OpenSSL") || provider.getName().includes("WolfSSLProvider")) {
                            log("Blocking provider registration (addProvider) of " + provider.getName());
                            return 1;
                        }
                        else {
                            if (isAndroid()) {
                                /*
                                When a NetworkProvider will be installed it is only allow at position 1
                                s. https://android.googlesource.com/platform/frameworks/base/+/master/core/java/android/security/net/config/NetworkSecurityConfigProvider.java
                                */
                                if (provider.getName() === "AndroidNSSP") {
                                    return this.insertProviderAt(provider, 1);
                                }
                                // when the "Failed to install provider as highest priority provider. Provider was installed at position"-error is prompted on logcat please uncomment the following line, recompile the typescript and reopen the following
                                // https://github.com/fkie-cad/friTap/issues/1
                                // var android_Version = Java.androidVersion
                                // devlog("highest priority provider error with: "+provider.getName())
                            }
                            return this.addProvider(provider);
                        }
                    };
                });
            }, 0);
        }
    }
}
✄
{"version":3,"file":"matrixssl.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/ssl_lib/matrixssl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,cAAc,EAAC,MAAM,+BAA+B,CAAC;AACnG,OAAO,EAAE,iBAAiB,E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,MAAM,IAAI,CAAC,CAAA,CAAC,iCAAiC;gBAC7C,IAAI,MAAM,IAAI,CAAC,EAAE;oBACb,OAAM;iBACT;gBAED,IAAI,CAAC,EAAE,GAAG,MAAM,CAAC;YACrB,CAAC;SACJ,CAAC,CAAA;IACN,CAAC;IAED,YAAY,CAAC,GAAQ;QACjB,MAAM,GAAG,GAAG,UAAU,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC;QAC5C,MAAM,eAAe,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,OAAO,EAAE,CAAC;QACnE,MAAM,SAAS,GAAG,GAAG,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC,WAAW,EAAE,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC;QAC1F,OAAO,SAAS,CAAC;IACrB,CAAC;CAGJ"}
✄
import { readAddresses, getPortsAndAddresses, getBaseAddress } from "../shared/shared_functions.js";
import { enable_default_fd, offsets } from "../ssl_log.js";
import { log } from "../util/log.js";
export class matrix_SSL {
    constructor(moduleName, socket_library, passed_library_method_mapping) {
        this.moduleName = moduleName;
        this.socket_library = socket_library;
        this.passed_library_method_mapping = passed_library_method_mapping;
        // global variables
        this.library_method_mapping = {};
        if (typeof passed_library_method_mapping !== 'undefined') {
            this.library_method_mapping = passed_library_method_mapping;
        }
        else {
            this.library_method_mapping[`*${moduleName}*`] = ["matrixSslReceivedData", "matrixSslGetWritebuf", "matrixSslGetSid", "matrixSslEncodeWritebuf"];
            this.library_method_mapping[`*${socket_library}*`] = ["getpeername", "getsockname", "ntohs", "ntohl", "socket"];
        }
        this.addresses = readAddresses(moduleName, this.library_method_mapping);
        this.module_name = moduleName;
        // @ts-ignore
        if (offsets != "{OFFSETS}" && offsets.matrixssl != null) {
            if (offsets.sockets != null) {
                const socketBaseAddress = getBaseAddress(socket_library);
                for (const method of Object.keys(offsets.sockets)) {
                    //@ts-ignore
                    this.addresses[this.moduleName][`${method}`] = offsets.sockets[`${method}`].absolute || socketBaseAddress == null ? ptr(offsets.sockets[`${method}`].address) : socketBaseAddress.add(ptr(offsets.sockets[`${method}`].address));
                }
            }
            const libraryBaseAddress = getBaseAddress(moduleName);
            if (libraryBaseAddress == null) {
                log("Unable to find library base address! Given address values will be interpreted as absolute ones!");
            }
            for (const method of Object.keys(offsets.matrixssl)) {
                //@ts-ignore
                this.addresses[this.moduleName][`${method}`] = offsets.matrixssl[`${method}`].absolute || libraryBaseAddress == null ? ptr(offsets.matrixssl[`${method}`].address) : libraryBaseAddress.add(ptr(offsets.matrixssl[`${method}`].address));
            }
        }
        //Creates a new client session. If this happens we will save the id of this new session
        matrix_SSL.matrixSslNewCLientSession = new NativeFunction(this.addresses[this.moduleName]["matrixSslNewClientSession"], "int", ["pointer", "pointer", "pointer", "pointer", "int", "pointer", "pointer", "pointer", "pointer", "pointer"]);
        //This function extracts the sessionID object out of the ssl object
        matrix_SSL.matrixSslGetSid = new NativeFunction(this.addresses[this.moduleName]["matrixSslGetSid"], "pointer", ["pointer"]);
    }
    install_plaintext_read_hook() {
        var current_module_name = this.module_name;
        var lib_addesses = this.addresses;
        Interceptor.attach(this.addresses[this.moduleName]["matrixSslReceivedData"], {
            onEnter: function (args) {
                this.buffer = args[2];
                this.len = args[3];
                var message = getPortsAndAddresses(this.fd, true, lib_addesses[current_module_name], enable_default_fd);
                message["ssl_session_id"] = this.addresses[this.moduleName]["matrixSslGetSid"] === undefined ? matrix_SSL.sessionId : this.getSessionId(args[0]);
                message["function"] = "matrixSslReceivedData";
                this.message = message;
            },
            onLeave: function (retval) {
                retval |= 0; // Cast retval to 32-bit integer.
                if (retval <= 0) {
                    return;
                }
                var data = this.buffer.readByteArray(this.len);
                this.message["contentType"] = "datalog";
                send(this.message, data);
            }
        });
    }
    install_plaintext_write_hook() {
        var current_module_name = this.module_name;
        var lib_addesses = this.addresses;
        //This function is needed to extract the buffer address in which the plaintext will be stored before registring this buffer as the "sent data" buffer.
        Interceptor.attach(this.addresses[this.moduleName]["matrixSslGetWritebuf"], {
            onEnter: function (args) {
                this.outBuffer = args[1];
            },
            onLeave: function (retval) {
                retval |= 0; // Cast retval to 32-bit integer.
                if (retval <= 0) {
                    return;
                }
                this.outBufferLength = retval;
            }
        });
        //This function actual encodes the plaintext. We need to hook this, because the user will fill the data out buffer between matrixSslGetWritebuf and matrixSslEncodeWritebuf call.
        //So at the time this function is called, the buffer with the plaintext will be final 
        Interceptor.attach(this.addresses[this.moduleName]["matrixSslEncodeWritebuf"], {
            onEnter: function (args) {
                var data = this.outBuffer.readByteArray(this.outBufferLength);
                var message = getPortsAndAddresses(this.fd, false, lib_addesses[current_module_name], enable_default_fd);
                message["ssl_session_id"] = this.addresses[this.moduleName]["matrixSslGetSid"] === undefined ? matrix_SSL.sessionId : this.getSessionId(args[0]);
                message["function"] = "matrixSslEncodeWritebuf";
                message["contentType"] = "datalog";
                send(message, data);
            }
        });
    }
    install_tls_keys_callback_hook() {
        // TBD
    }
    install_helper_hook() {
        Interceptor.attach(this.addresses[this.moduleName]["matrixSslNewSessionId"], {
            onEnter: function (args) {
                this.sslSessionPointer = args[0];
            },
            onLeave: function (retval) {
                retval |= 0; // Cast retval to 32-bit integer.
                if (retval <= 0) {
                    return;
                }
                var sessionIdLength = this.sslSessionPointer.add(2 * Process.pointerSize).readU32();
                matrix_SSL.sessionId = this.sslSessionPointer.add(Process.pointerSize).readPointer().readCString(sessionIdLength);
            }
        });
        Interceptor.attach(this.addresses[this.moduleName]["connect"], {
            onEnter: function (args) {
            },
            onLeave: function (retval) {
                retval |= 0; // Cast retval to 32-bit integer.
                if (retval <= 0) {
                    return;
                }
                this.fd = retval;
            }
        });
    }
    getSessionId(ssl) {
        const sid = matrix_SSL.matrixSslGetSid(ssl);
        const sessionIdLength = sid.add(2 * Process.pointerSize).readU32();
        const sessionId = sid.add(Process.pointerSize).readPointer().readCString(sessionIdLength);
        return sessionId;
    }
}
✄
{"version":3,"file":"mbedTLS.js","sourceRoot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ACnB,IAAI,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;gBACrB,IAAI,GAAG,GAAQ,IAAI,CAAC,CAAC,CAAC,CAAC;gBACvB,GAAG,IAAI,CAAC,CAAA,CAAC,iCAAiC;gBAC1C,IAAI,GAAG,IAAI,CAAC,EAAE;oBACV,OAAM;iBACT;gBACD,IAAI,IAAI,GAAG,MAAM,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;gBACrC,IAAI,OAAO,GAAG,oBAAoB,CAAC,QAAQ,CAAC,mBAAmB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAW,EAAE,KAAK,EAAE,YAAY,CAAC,mBAAmB,CAAC,EAAE,iBAAiB,CAAC,CAAA;gBAChJ,OAAO,CAAC,gBAAgB,CAAC,GAAG,QAAQ,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;gBAC1D,OAAO,CAAC,UAAU,CAAC,GAAG,mBAAmB,CAAA;gBACzC,OAAO,CAAC,aAAa,CAAC,GAAG,SAAS,CAAA;gBAClC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAA;YACvB,CAAC;SACJ,CAAC,CAAC;IAEP,CAAC;IAGD,8BAA8B;QAC1B,MAAM;IACV,CAAC;CAGJ"}
✄
import { readAddresses, getPortsAndAddresses, getBaseAddress } from "../shared/shared_functions.js";
import { offsets, enable_default_fd } from "../ssl_log.js";
import { log } from "../util/log.js";
export class mbed_TLS {
    constructor(moduleName, socket_library, passed_library_method_mapping) {
        this.moduleName = moduleName;
        this.socket_library = socket_library;
        this.passed_library_method_mapping = passed_library_method_mapping;
        // global variables
        this.library_method_mapping = {};
        if (typeof passed_library_method_mapping !== 'undefined') {
            this.library_method_mapping = passed_library_method_mapping;
        }
        else {
            this.library_method_mapping[`*${moduleName}*`] = ["mbedtls_ssl_read", "mbedtls_ssl_write"];
            this.library_method_mapping[`*${socket_library}*`] = ["getpeername", "getsockname", "ntohs", "ntohl"];
        }
        this.addresses = readAddresses(moduleName, this.library_method_mapping);
        this.module_name = moduleName;
        // @ts-ignore
        if (offsets != "{OFFSETS}" && offsets.mbedtls != null) {
            if (offsets.sockets != null) {
                const socketBaseAddress = getBaseAddress(socket_library);
                for (const method of Object.keys(offsets.sockets)) {
                    //@ts-ignore
                    this.addresses[this.moduleName][`${method}`] = offsets.sockets[`${method}`].absolute || socketBaseAddress == null ? ptr(offsets.sockets[`${method}`].address) : socketBaseAddress.add(ptr(offsets.sockets[`${method}`].address));
                }
            }
            const libraryBaseAddress = getBaseAddress(moduleName);
            if (libraryBaseAddress == null) {
                log("Unable to find library base address! Given address values will be interpreted as absolute ones!");
            }
            for (const method of Object.keys(offsets.mbedtls)) {
                //@ts-ignore
                this.addresses[this.moduleName][`${method}`] = offsets.mbedtls[`${method}`].absolute || libraryBaseAddress == null ? ptr(offsets.mbedtls[`${method}`].address) : libraryBaseAddress.add(ptr(offsets.mbedtls[`${method}`].address));
            }
        }
    }
    static parse_mbedtls_ssl_context_struct(sslcontext) {
        return {
            conf: sslcontext.readPointer(),
            state: sslcontext.add(Process.pointerSize).readS32(),
            renego_status: sslcontext.add(Process.pointerSize + 4).readS32(),
            renego_records_seen: sslcontext.add(Process.pointerSize + 4 + 4).readS32(),
            major_ver: sslcontext.add(Process.pointerSize + 4 + 4 + 4).readS32(),
            minor_ver: sslcontext.add(Process.pointerSize + 4 + 4 + 4 + 4).readS32(),
            badmac_seen: sslcontext.add(Process.pointerSize + 4 + 4 + 4 + 4 + 4).readU32(),
            f_send: sslcontext.add(Process.pointerSize + 4 + 4 + 4 + 4 + 4 + 4).readPointer(),
            f_recv: sslcontext.add(Process.pointerSize + 4 + 4 + 4 + 4 + 4 + 4 + Process.pointerSize).readPointer(),
            f_recv_timeout: sslcontext.add(Process.pointerSize + 4 + 4 + 4 + 4 + 4 + 4 + 2 * Process.pointerSize).readPointer(),
            p_bio: sslcontext.add(Process.platform == 'windows' ? 48 : 56).readPointer(),
            session_in: sslcontext.add(Process.pointerSize + 4 + 4 + 4 + 4 + 4 + 4 + 4 * Process.pointerSize).readPointer(),
            session_out: sslcontext.add(Process.pointerSize + 4 + 4 + 4 + 4 + 4 + 4 + 5 * Process.pointerSize).readPointer(),
            session: {
                start: sslcontext.add(24 + 7 * Process.pointerSize).readPointer().readPointer(),
                ciphersuite: sslcontext.add(24 + 7 * Process.pointerSize).readPointer().add(8).readS32(),
                compression: sslcontext.add(24 + 7 * Process.pointerSize).readPointer().add(8 + 4).readS32(),
                id_len: sslcontext.add(24 + 7 * Process.pointerSize).readPointer().add(8 + 4 + 4).readU32(),
                id: sslcontext.add(24 + 7 * Process.pointerSize).readPointer().add(8 + 4 + 4 + 4).readByteArray(sslcontext.add(24 + 7 * Process.pointerSize).readPointer().add(8 + 4 + 4).readU32())
            }
        };
    }
    static getSocketDescriptor(sslcontext) {
        var ssl_context = mbed_TLS.parse_mbedtls_ssl_context_struct(sslcontext);
        return ssl_context.p_bio.readS32();
    }
    static getSessionId(sslcontext) {
        var ssl_context = mbed_TLS.parse_mbedtls_ssl_context_struct(sslcontext);
        var session_id = '';
        for (var byteCounter = 0; byteCounter < ssl_context.session.id_len; byteCounter++) {
            session_id = `${session_id}${ssl_context.session.id?.unwrap().add(byteCounter).readU8().toString(16).toUpperCase()}`;
        }
        return session_id;
    }
    install_plaintext_read_hook() {
        var current_module_name = this.module_name;
        var lib_addesses = this.addresses;
        //https://tls.mbed.org/api/ssl_8h.html#aa2c29eeb1deaf5ad9f01a7515006ede5
        Interceptor.attach(this.addresses[this.moduleName]["mbedtls_ssl_read"], {
            onEnter: function (args) {
                this.buffer = args[1];
                this.len = args[2];
                this.sslContext = args[0];
                var message = getPortsAndAddresses(mbed_TLS.getSocketDescriptor(args[0]), true, lib_addesses[current_module_name], enable_default_fd);
                message["ssl_session_id"] = mbed_TLS.getSessionId(args[0]);
                message["function"] = "mbedtls_ssl_read";
                this.message = message;
            },
            onLeave: function (retval) {
                retval |= 0; // Cast retval to 32-bit integer.
                if (retval <= 0) {
                    return;
                }
                var data = this.buffer.readByteArray(retval);
                this.message["contentType"] = "datalog";
                send(this.message, data);
            }
        });
    }
    install_plaintext_write_hook() {
        var current_module_name = this.module_name;
        var lib_addesses = this.addresses;
        //https://tls.mbed.org/api/ssl_8h.html#a5bbda87d484de82df730758b475f32e5
        Interceptor.attach(this.addresses[this.moduleName]["mbedtls_ssl_write"], {
            onEnter: function (args) {
                var buffer = args[1];
                var len = args[2];
                len |= 0; // Cast retval to 32-bit integer.
                if (len <= 0) {
                    return;
                }
                var data = buffer.readByteArray(len);
                var message = getPortsAndAddresses(mbed_TLS.getSocketDescriptor(args[0]), false, lib_addesses[current_module_name], enable_default_fd);
                message["ssl_session_id"] = mbed_TLS.getSessionId(args[0]);
                message["function"] = "mbedtls_ssl_write";
                message["contentType"] = "datalog";
                send(message, data);
            }
        });
    }
    install_tls_keys_callback_hook() {
        // TBD
    }
}
✄
{"version":3,"file":"nss.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/ssl_lib/nss.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAC9E,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,gCAAgC,CAAC;AAChF,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAC,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAqI1D,MAAM,EACF,OAAO,EACP,OAAO,EACP,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,YAAY,EACf,GAAG,aAAa,CAAC,SAAS,CAAC;AAG5B,6FAA6F;AAC7F,MAAM,CAAN,IAAY,SAIX;AAJD,WAAY,SAAS;IACjB,4DAAoB,CAAA;IACpB,sDAAiB,CAAA;IACjB,qDAAgB,CAAA;AACpB,CAAC,EAJW,SAAS,KAAT,SAAS,QAIpB;AAAA,CAAC;AAE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,UAAU,WAAW,EAAE,WAAW;IAC1E,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE;QAC7B,GAAG,CAAC,gBAAgB,CAAC,WAAW,CAAC,CAAC;KACrC;SAAM;QACH,OAAO,CAAC,GAAG,CAAC,wDAAwD,CAAC,CAAC;KACzE;IACD,OAAO,CAAC,CAAC;AACb,CAAC,EAAE,MAAM,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,AAPZ,CAOa;AAInC;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACI,mBAAe,GAAG,IAAI,cAAc,CAAC,UAAU,WAA0B,EAAE,KAAa,EAAE,GAAW,EAAE,MAAqB,EAAE,OAAsB;IACvJ,IAAI,OAAO,IAAI,KAAK,WAAW,EAAE;QAC7B,GAAG,CAAC,4CAA4C,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;KACxE;SAAM;QACH,OAAO,CAAC,GAAG,CAAC,2EAA2E,CAAC,CAAC;KAC5F;IAED,OAAO;AACX,CAAC,EAAE,MAAM,EAAE,CAAC,SAAS,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,AAR3C,CAQ4C"}
✄
import { readAddresses, getBaseAddress } from "../shared/shared_functions.js";
import { pointerSize, AF_INET, AF_INET6 } from "../shared/shared_structures.js";
import { log, devlog } from "../util/log.js";
import { offsets, enable_default_fd } from "../ssl_log.js";
const { readU32, readU64, readPointer, writeU32, writeU64, writePointer } = NativePointer.prototype;
// https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSS/SSL_functions/ssltyp#1026722
export var SECStatus;
(function (SECStatus) {
    SECStatus[SECStatus["SECWouldBlock"] = -2] = "SECWouldBlock";
    SECStatus[SECStatus["SECFailure"] = -1] = "SECFailure";
    SECStatus[SECStatus["SECSuccess"] = 0] = "SECSuccess";
})(SECStatus || (SECStatus = {}));
;
export var PRDescType;
(function (PRDescType) {
    PRDescType[PRDescType["PR_DESC_FILE"] = 1] = "PR_DESC_FILE";
    PRDescType[PRDescType["PR_DESC_SOCKET_TCP"] = 2] = "PR_DESC_SOCKET_TCP";
    PRDescType[PRDescType["PR_DESC_SOCKET_UDP"] = 3] = "PR_DESC_SOCKET_UDP";
    PRDescType[PRDescType["PR_DESC_LAYERED"] = 4] = "PR_DESC_LAYERED";
    PRDescType[PRDescType["PR_DESC_PIPE"] = 5] = "PR_DESC_PIPE";
})(PRDescType || (PRDescType = {}));
PRDescType;
export class NSS {
    constructor(moduleName, socket_library, passed_library_method_mapping) {
        this.moduleName = moduleName;
        this.socket_library = socket_library;
        this.passed_library_method_mapping = passed_library_method_mapping;
        // global variables
        this.library_method_mapping = {};
        if (typeof passed_library_method_mapping !== 'undefined') {
            this.library_method_mapping = passed_library_method_mapping;
        }
        else {
            this.library_method_mapping[`*${moduleName}*`] = ["PR_Write", "PR_Read", "PR_FileDesc2NativeHandle", "PR_GetPeerName", "PR_GetSockName", "PR_GetNameForIdentity", "PR_GetDescType"];
            this.library_method_mapping[`*libnss*`] = ["PK11_ExtractKeyValue", "PK11_GetKeyData"];
            this.library_method_mapping["*libssl*.so"] = ["SSL_ImportFD", "SSL_GetSessionID", "SSL_HandshakeCallback"];
            this.library_method_mapping[`*${socket_library}*`] = ["getpeername", "getsockname", "ntohs", "ntohl"];
        }
        this.addresses = readAddresses(moduleName, this.library_method_mapping);
        this.module_name = moduleName;
        // @ts-ignore
        if (offsets != "{OFFSETS}" && offsets.nss != null) {
            if (offsets.sockets != null) {
                const socketBaseAddress = getBaseAddress(socket_library);
                for (const method of Object.keys(offsets.sockets)) {
                    //@ts-ignore
                    this.addresses[this.moduleName][`${method}`] = offsets.sockets[`${method}`].absolute || socketBaseAddress == null ? ptr(offsets.sockets[`${method}`].address) : socketBaseAddress.add(ptr(offsets.sockets[`${method}`].address));
                }
            }
            const libraryBaseAddress = getBaseAddress(moduleName);
            if (libraryBaseAddress == null) {
                log("Unable to find library base address! Given address values will be interpreted as absolute ones!");
            }
            for (const method of Object.keys(offsets.nss)) {
                //@ts-ignore
                this.addresses[this.moduleName][`${method}`] = offsets.nss[`${method}`].absolute || libraryBaseAddress == null ? ptr(offsets.nss[`${method}`].address) : libraryBaseAddress.add(ptr(offsets.nss[`${method}`].address));
            }
        }
        NSS.SSL_SESSION_get_id = new NativeFunction(this.addresses[this.moduleName]["SSL_GetSessionID"], "pointer", ["pointer"]);
        NSS.getsockname = new NativeFunction(this.addresses[this.moduleName]["PR_GetSockName"], "int", ["pointer", "pointer"]);
        NSS.getpeername = new NativeFunction(this.addresses[this.moduleName]["PR_GetPeerName"], "int", ["pointer", "pointer"]);
    }
    /* PARSING functions */
    static parse_struct_SECItem(secitem) {
        /*
         * struct SECItemStr {
         * SECItemType type;
         * unsigned char *data;
         * unsigned int len;
         * }; --> size = 20
        */
        return {
            "type": secitem.readU64(),
            "data": secitem.add(pointerSize).readPointer(),
            "len": secitem.add(pointerSize * 2).readU32()
        };
    }
    // https://github.com/nss-dev/nss/blob/master/lib/ssl/sslimpl.h#L971
    static parse_struct_sslSocketStr(sslSocketFD) {
        return {
            "fd": sslSocketFD.readPointer(),
            "version": sslSocketFD.add(160),
            "handshakeCallback": sslSocketFD.add(464),
            "secretCallback": sslSocketFD.add(568),
            "ssl3": sslSocketFD.add(1432)
        };
    }
    // https://github.com/nss-dev/nss/blob/master/lib/ssl/sslimpl.h#L771
    static parse_struct_ssl3Str(ssl3_struct) {
        /*
        struct ssl3StateStr {
    
        ssl3CipherSpec *crSpec; // current read spec.
        ssl3CipherSpec *prSpec; // pending read spec.
        ssl3CipherSpec *cwSpec; // current write spec.
        ssl3CipherSpec *pwSpec; // pending write spec.
        
        PRBool peerRequestedKeyUpdate;                     --> enum type
        
        PRBool keyUpdateDeferred;                          --> enum type
        tls13KeyUpdateRequest deferredKeyUpdateRequest;    --> enum type
       
        PRBool clientCertRequested;                        --> enum type
    
        CERTCertificate *clientCertificate;
        SECKEYPrivateKey *clientPrivateKey;
        CERTCertificateList *clientCertChain;
        PRBool sendEmptyCert;
    
        PRUint8 policy;
        PLArenaPool *peerCertArena;
        
        void *peerCertChain;
        
        CERTDistNames *ca_list;
        
        SSL3HandshakeState hs;
        ...
        }
        */
        return {
            "crSpec": ssl3_struct.readPointer(),
            "prSpec": ssl3_struct.add(pointerSize).readPointer(),
            "cwSpec": ssl3_struct.add(pointerSize * 2).readPointer(),
            "pwSpec": ssl3_struct.add(pointerSize * 3).readPointer(),
            "peerRequestedKeyUpdate": ssl3_struct.add(pointerSize * 4).readU32(),
            "keyUpdateDeferred": ssl3_struct.add(pointerSize * 4 + 4).readU32(),
            "deferredKeyUpdateRequest": ssl3_struct.add(pointerSize * 4 + 8).readU32(),
            "clientCertRequested": ssl3_struct.add(pointerSize * 4 + 12).readU32(),
            "clientCertificate": ssl3_struct.add(pointerSize * 4 + 16).readPointer(),
            "clientPrivateKey": ssl3_struct.add(pointerSize * 5 + 16).readPointer(),
            "clientCertChain": ssl3_struct.add(pointerSize * 6 + 16).readPointer(),
            "sendEmptyCert": ssl3_struct.add(pointerSize * 7 + 16).readU32(),
            "policy": ssl3_struct.add(pointerSize * 7 + 20).readU32(),
            "peerCertArena": ssl3_struct.add(pointerSize * 7 + 24).readPointer(),
            "peerCertChain": ssl3_struct.add(pointerSize * 8 + 24).readPointer(),
            "ca_list": ssl3_struct.add(pointerSize * 9 + 24).readPointer(),
            "hs": {
                "server_random": ssl3_struct.add(pointerSize * 10 + 24),
                "client_random": ssl3_struct.add(pointerSize * 10 + 56),
                "client_inner_random": ssl3_struct.add(pointerSize * 10 + 88),
                "ws": ssl3_struct.add(pointerSize * 10 + 120).readU32(),
                "hashType": ssl3_struct.add(pointerSize * 10 + 124).readU32(),
                "messages": {
                    "data": ssl3_struct.add(pointerSize * 10 + 128).readPointer(),
                    "len": ssl3_struct.add(pointerSize * 11 + 128).readU32(),
                    "space": ssl3_struct.add(pointerSize * 11 + 132).readU32(),
                    "fixed": ssl3_struct.add(pointerSize * 11 + 136).readU32(),
                },
                "echInnerMessages": {
                    "data": ssl3_struct.add(pointerSize * 11 + 140).readPointer(),
                    "len": ssl3_struct.add(pointerSize * 12 + 140).readU32(),
                    "space": ssl3_struct.add(pointerSize * 12 + 144).readU32(),
                    "fixed": ssl3_struct.add(pointerSize * 12 + 148).readU32(),
                },
                "md5": ssl3_struct.add(pointerSize * 12 + 152).readPointer(),
                "sha": ssl3_struct.add(pointerSize * 13 + 152).readPointer(),
                "shaEchInner": ssl3_struct.add(pointerSize * 14 + 152).readPointer(),
                "shaPostHandshake": ssl3_struct.add(pointerSize * 15 + 152).readPointer(),
                "signatureScheme": ssl3_struct.add(pointerSize * 16 + 152).readU32(),
                "kea_def": ssl3_struct.add(pointerSize * 16 + 156).readPointer(),
                "cipher_suite": ssl3_struct.add(pointerSize * 17 + 156).readU32(),
                "suite_def": ssl3_struct.add(pointerSize * 17 + 160).readPointer(),
                "msg_body": {
                    "data": ssl3_struct.add(pointerSize * 18 + 160).readPointer(),
                    "len": ssl3_struct.add(pointerSize * 19 + 160).readU32(),
                    "space": ssl3_struct.add(pointerSize * 19 + 164).readU32(),
                    "fixed": ssl3_struct.add(pointerSize * 19 + 168).readU32(),
                },
                "header_bytes": ssl3_struct.add(pointerSize * 19 + 172).readU32(),
                "msg_type": ssl3_struct.add(pointerSize * 19 + 176).readU32(),
                "msg_len": ssl3_struct.add(pointerSize * 19 + 180).readU32(),
                "isResuming": ssl3_struct.add(pointerSize * 19 + 184).readU32(),
                "sendingSCSV": ssl3_struct.add(pointerSize * 19 + 188).readU32(),
                "receivedNewSessionTicket": ssl3_struct.add(pointerSize * 19 + 192).readU32(),
                "newSessionTicket": ssl3_struct.add(pointerSize * 19 + 196),
                "finishedBytes": ssl3_struct.add(pointerSize * 19 + 240).readU32(),
                "finishedMsgs": ssl3_struct.add(pointerSize * 19 + 244),
                "authCertificatePending": ssl3_struct.add(pointerSize * 18 + 316).readU32(),
                "restartTarget": ssl3_struct.add(pointerSize * 19 + 320).readU32(),
                "canFalseStart": ssl3_struct.add(pointerSize * 19 + 324).readU32(),
                "preliminaryInfo": ssl3_struct.add(pointerSize * 19 + 328).readU32(),
                "remoteExtensions": {
                    "next": ssl3_struct.add(pointerSize * 19 + 332).readPointer(),
                    "prev": ssl3_struct.add(pointerSize * 20 + 332).readPointer(),
                },
                "echOuterExtensions": {
                    "next": ssl3_struct.add(pointerSize * 21 + 332).readPointer(),
                    "prev": ssl3_struct.add(pointerSize * 22 + 332).readPointer(),
                },
                "sendMessageSeq": ssl3_struct.add(pointerSize * 23 + 332).readU32(),
                "lastMessageFlight": {
                    "next": ssl3_struct.add(pointerSize * 23 + 336).readPointer(),
                    "prev": ssl3_struct.add(pointerSize * 24 + 336).readPointer(),
                },
                "maxMessageSent": ssl3_struct.add(pointerSize * 25 + 336).readU16(),
                "recvMessageSeq": ssl3_struct.add(pointerSize * 25 + 338).readU16(),
                "recvdFragments": {
                    "data": ssl3_struct.add(pointerSize * 25 + 340).readPointer(),
                    "len": ssl3_struct.add(pointerSize * 26 + 340).readU32(),
                    "space": ssl3_struct.add(pointerSize * 26 + 344).readU32(),
                    "fixed": ssl3_struct.add(pointerSize * 26 + 348).readU32(),
                },
                "recvdHighWater": ssl3_struct.add(pointerSize * 26 + 352).readU32(),
                "cookie": {
                    "type": ssl3_struct.add(pointerSize * 26 + 356).readU64(),
                    "data": ssl3_struct.add(pointerSize * 27 + 356).readPointer(),
                    "len": ssl3_struct.add(pointerSize * 28 + 356).readU32(),
                },
                "times_array": ssl3_struct.add(pointerSize * 28 + 360).readU32(),
                "rtTimer": ssl3_struct.add(pointerSize * 28 + 432).readPointer(),
                "ackTimer": ssl3_struct.add(pointerSize * 29 + 432).readPointer(),
                "hdTimer": ssl3_struct.add(pointerSize * 30 + 432).readPointer(),
                "rtRetries": ssl3_struct.add(pointerSize * 31 + 432).readU32(),
                "srvVirtName": {
                    "type": ssl3_struct.add(pointerSize * 31 + 436).readU64(),
                    "data": ssl3_struct.add(pointerSize * 32 + 436).readPointer(),
                    "len": ssl3_struct.add(pointerSize * 33 + 436).readU32(),
                },
                "currentSecret": ssl3_struct.add(pointerSize * 33 + 440).readPointer(),
                "resumptionMasterSecret": ssl3_struct.add(pointerSize * 34 + 440).readPointer(),
                "dheSecret": ssl3_struct.add(pointerSize * 35 + 440).readPointer(),
                "clientEarlyTrafficSecret": ssl3_struct.add(pointerSize * 36 + 440).readPointer(),
                "clientHsTrafficSecret": ssl3_struct.add(pointerSize * 37 + 440).readPointer(),
                "serverHsTrafficSecret": ssl3_struct.add(pointerSize * 38 + 440).readPointer(),
                "clientTrafficSecret": ssl3_struct.add(pointerSize * 39 + 440).readPointer(),
                "serverTrafficSecret": ssl3_struct.add(pointerSize * 40 + 440).readPointer(),
                "earlyExporterSecret": ssl3_struct.add(pointerSize * 41 + 440).readPointer(),
                "exporterSecret": ssl3_struct.add(pointerSize * 42 + 440).readPointer()
            } // end of hs struct
            /*
            typedef struct SSL3HandshakeStateStr {
        SSL3Random server_random;
        SSL3Random client_random;
        SSL3Random client_inner_random;
        SSL3WaitState ws;                       --> enum type
    
        
        SSL3HandshakeHashType hashType;         --> enum type
        sslBuffer messages;                     --> struct of 20 bytes (1 ptr + 12 bytes;see lib/ssl/sslencode.h)
        sslBuffer echInnerMessages;
        
        PK11Context *md5;
        PK11Context *sha;
        PK11Context *shaEchInner;
        PK11Context *shaPostHandshake;
        SSLSignatureScheme signatureScheme;     --> enum type( see lib/ssl/sslt.h)
        const ssl3KEADef *kea_def;
        ssl3CipherSuite cipher_suite;           --> typedef PRUint16 ssl3CipherSuite (see lib/ssl/ssl3prot.h)
        const ssl3CipherSuiteDef *suite_def;
        sslBuffer msg_body;
                            
        unsigned int header_bytes;
        
        SSLHandshakeType msg_type;
        unsigned long msg_len;
        PRBool isResuming;
        PRBool sendingSCSV;
    
        
        PRBool receivedNewSessionTicket;
        NewSessionTicket newSessionTicket;      --> (see lib/ssl/ssl3prot.h)
    
        PRUint16 finishedBytes;
        union {
            TLSFinished tFinished[2];           --> 12 bytes
            SSL3Finished sFinished[2];          --> 36 bytes
            PRUint8 data[72];
        } finishedMsgs;                         --> 72
    
        PRBool authCertificatePending;
        
        sslRestartTarget restartTarget;
    
        PRBool canFalseStart;
        
        PRUint32 preliminaryInfo;
    
        
        PRCList remoteExtensions;
        PRCList echOuterExtensions;
    
        
        PRUint16 sendMessageSeq;
        PRCList lastMessageFlight;
        PRUint16 maxMessageSent;
        PRUint16 recvMessageSeq;
        sslBuffer recvdFragments;
        PRInt32 recvdHighWater;
        SECItem cookie;
        dtlsTimer timers[3];       24 * 3
        dtlsTimer *rtTimer;
        dtlsTimer *ackTimer;
        dtlsTimer *hdTimer;
        PRUint32 rtRetries;
        SECItem srvVirtName;
                                        
    
        // This group of values is used for TLS 1.3 and above
        PK11SymKey *currentSecret;            // The secret down the "left hand side"   --> ssl3_struct.add(704)
                                                //of the TLS 1.3 key schedule.
        PK11SymKey *resumptionMasterSecret;   // The resumption_master_secret.          --> ssl3_struct.add(712)
        PK11SymKey *dheSecret;                // The (EC)DHE shared secret.             --> ssl3_struct.add(720)
        PK11SymKey *clientEarlyTrafficSecret; // The secret we use for 0-RTT.           --> ssl3_struct.add(728)
        PK11SymKey *clientHsTrafficSecret;    // The source keys for handshake          --> ssl3_struct.add(736)
        PK11SymKey *serverHsTrafficSecret;    // traffic keys.                          --> ssl3_struct.add(744)
        PK11SymKey *clientTrafficSecret;      // The source keys for application        --> ssl3_struct.add(752)
        PK11SymKey *serverTrafficSecret;      // traffic keys                           --> ssl3_struct.add(760)
        PK11SymKey *earlyExporterSecret;      // for 0-RTT exporters                    --> ssl3_struct.add(768)
        PK11SymKey *exporterSecret;           // for exporters                          --> ssl3_struct.add(776)
        ...
    
    
        typedef struct {
        const char *label; 8
        DTLSTimerCb cb; 8
        PRIntervalTime started; 4
        PRUint32 timeout; 4
    } dtlsTimer;
    
            */
        };
    }
    // https://github.com/nss-dev/nss/blob/master/lib/ssl/sslspec.h#L140 
    static parse_struct_sl3CipherSpecStr(cwSpec) {
        /*
        truct ssl3CipherSpecStr {
            PRCList link;
            PRUint8 refCt;
    
            SSLSecretDirection direction;
            SSL3ProtocolVersion version;
            SSL3ProtocolVersion recordVersion;
    
            const ssl3BulkCipherDef *cipherDef;
            const ssl3MACDef *macDef;
    
            SSLCipher cipher;
            void *cipherContext;
    
            PK11SymKey *masterSecret;
            ...
        */
        return {
            "link": cwSpec.add,
            "refCt": cwSpec.add(pointerSize * 2),
            "direction": cwSpec.add(pointerSize * 2 + 4),
            "version": cwSpec.add(pointerSize * 2 + 8),
            "recordVersion": cwSpec.add(pointerSize * 2 + 12),
            "cipherDef": cwSpec.add(pointerSize * 2 + 16).readPointer(),
            "macDef": cwSpec.add(pointerSize * 3 + 16).readPointer(),
            "cipher": cwSpec.add(pointerSize * 4 + 16),
            "cipherContext": cwSpec.add(pointerSize * 4 + 24).readPointer(),
            "master_secret": cwSpec.add(pointerSize * 5 + 24).readPointer()
        };
    }
    /********* NSS helper functions  ********/
    /**
* Returns a dictionary of a sockfd's "src_addr", "src_port", "dst_addr", and
* "dst_port".
* @param {pointer} sockfd The file descriptor of the socket to inspect as PRFileDesc.
* @param {boolean} isRead If true, the context is an SSL_read call. If
*     false, the context is an SSL_write call.
* @param {{ [key: string]: NativePointer}} methodAddresses Dictionary containing (at least) addresses for getpeername, getsockname, ntohs and ntohl
* @return {{ [key: string]: string | number }} Dictionary of sockfd's "src_addr", "src_port", "dst_addr",
*     and "dst_port".

  PRStatus PR_GetPeerName(
PRFileDesc *fd,
PRNetAddr *addr);

PRStatus PR_GetSockName(
PRFileDesc *fd,
PRNetAddr *addr);

PRStatus PR_NetAddrToString(
const PRNetAddr *addr,
char *string,
PRUint32 size);


union PRNetAddr {
struct {
   PRUint16 family;
   char data[14];
} raw;
struct {
   PRUint16 family;
   PRUint16 port;
   PRUint32 ip;
   char pad[8];
} inet;
#if defined(_PR_INET6)
struct {
   PRUint16 family;
   PRUint16 port;
   PRUint32 flowinfo;
   PRIPv6Addr ip;
} ipv6;
#endif // defined(_PR_INET6)
};

typedef union PRNetAddr PRNetAddr;

*/
    static getPortsAndAddressesFromNSS(sockfd, isRead, methodAddresses, enable_default_fd) {
        var message = {};
        if (enable_default_fd && sockfd === null) {
            message["src" + "_port"] = 1234;
            message["src" + "_addr"] = "127.0.0.1";
            message["dst" + "_port"] = 2345;
            message["dst" + "_addr"] = "127.0.0.1";
            message["ss_family"] = "AF_INET";
            return message;
        }
        var getpeername = new NativeFunction(methodAddresses["PR_GetPeerName"], "int", ["pointer", "pointer"]);
        var getsockname = new NativeFunction(methodAddresses["PR_GetSockName"], "int", ["pointer", "pointer"]);
        var ntohs = new NativeFunction(methodAddresses["ntohs"], "uint16", ["uint16"]);
        var ntohl = new NativeFunction(methodAddresses["ntohl"], "uint32", ["uint32"]);
        var addrType = Memory.alloc(2); // PRUint16 is a 2 byte (16 bit) value on all plattforms
        //var prNetAddr = Memory.alloc(Process.pointerSize)
        var addrlen = Memory.alloc(4);
        var addr = Memory.alloc(128);
        var src_dst = ["src", "dst"];
        for (var i = 0; i < src_dst.length; i++) {
            addrlen.writeU32(128);
            if ((src_dst[i] == "src") !== isRead) {
                getsockname(sockfd, addr);
            }
            else {
                getpeername(sockfd, addr);
            }
            if (addr.readU16() == AF_INET) {
                message[src_dst[i] + "_port"] = ntohs(addr.add(2).readU16());
                message[src_dst[i] + "_addr"] = ntohl(addr.add(4).readU32());
                message["ss_family"] = "AF_INET";
            }
            else if (addr.readU16() == AF_INET6) {
                message[src_dst[i] + "_port"] = ntohs(addr.add(2).readU16());
                message[src_dst[i] + "_addr"] = "";
                var ipv6_addr = addr.add(8);
                for (var offset = 0; offset < 16; offset += 1) {
                    message[src_dst[i] + "_addr"] += ("0" + ipv6_addr.add(offset).readU8().toString(16).toUpperCase()).substr(-2);
                }
                if (message[src_dst[i] + "_addr"].toString().indexOf("00000000000000000000FFFF") === 0) {
                    message[src_dst[i] + "_addr"] = ntohl(ipv6_addr.add(12).readU32());
                    message["ss_family"] = "AF_INET";
                }
                else {
                    message["ss_family"] = "AF_INET6";
                }
            }
            else {
                devlog("[-] PIPE descriptor error");
                //FIXME: Sometimes addr.readU16() will be 0 when a PIPE Read oder Write gets interpcepted, thus this error will be thrown.
                throw "Only supporting IPv4/6";
            }
        }
        return message;
    }
    /**
    * This functions tests if a given address is a readable pointer
    *
    * @param {*} ptr_addr is a pointer to the memory location where we want to check if there is already an address
    * @returns 1 to indicate that there is a ptr at
    */
    static is_ptr_at_mem_location(ptr_addr) {
        try {
            // an exception is thrown if there isn't a readable address
            ptr_addr.readPointer();
            return 1;
        }
        catch (error) {
            return -1;
        }
    }
    /**
    *
    * typedef struct PRFileDesc {
    *       const struct PRIOMethods *methods;
    *       PRFilePrivate *secret;
    *       PRFileDesc *lower;
    *       PRFileDesc *higher;
    *       void (*dtor) (PRFileDesc *);
    *       PRDescIdentity identity;
    *  } PRFileDesc;
    *
    * @param {*} pRFileDesc
    * @param {*} layer_name
    * @returns
    */
    static NSS_FindIdentityForName(pRFileDesc, layer_name) {
        var lower_ptr = pRFileDesc.add(pointerSize * 2).readPointer();
        var higher_ptr = pRFileDesc.add(pointerSize * 3).readPointer();
        var identity = pRFileDesc.add(pointerSize * 5).readPointer();
        if (!identity.isNull()) {
            var nameptr = NSS.PR_GetNameForIdentity(identity).readCString();
            if (nameptr == layer_name) {
                return pRFileDesc;
            }
        }
        if (!lower_ptr.isNull()) {
            return this.NSS_FindIdentityForName(lower_ptr, layer_name);
        }
        if (!higher_ptr.isNull()) {
            devlog('Have upper');
        }
        // when we reach this we have some sort of error 
        devlog("[-] error while getting SSL layer");
        return NULL;
    }
    static getSessionIdString(session_id_ptr, len) {
        var session_id = "";
        for (var i = 0; i < len; i++) {
            // Read a byte, convert it to a hex string (0xAB ==> "AB"), and append
            // it to session_id.
            session_id +=
                ("0" + session_id_ptr.add(i).readU8().toString(16).toUpperCase()).substr(-2);
        }
        return session_id;
    }
    static getSSL_Layer(pRFileDesc) {
        var ssl_layer_id = 3; // SSL has the Layer ID 3 normally.
        var getIdentitiesLayer = new NativeFunction(Module.getExportByName('libnspr4.so', 'PR_GetIdentitiesLayer'), "pointer", ["pointer", "int"]);
        var ssl_layer = getIdentitiesLayer(pRFileDesc, ssl_layer_id);
        if (ptr(ssl_layer.toString()).isNull()) {
            devlog("PR_BAD_DESCRIPTOR_ERROR: " + ssl_layer);
            return -1;
        }
        return ssl_layer;
    }
    /**
    *
    * @param {*} readAddr is the address where we start reading the bytes
    * @param {*} len is the length of bytes we want to convert to a hex string
    * @returns a hex string with the length of len
    */
    static getHexString(readAddr, len) {
        var secret_str = "";
        for (var i = 0; i < len; i++) {
            // Read a byte, convert it to a hex string (0xab ==> "ab"), and append
            // it to secret_str.
            secret_str +=
                ("0" + readAddr.add(i).readU8().toString(16).toLowerCase()).substr(-2);
        }
        return secret_str;
    }
    /**
 * Get the session_id of SSL object and return it as a hex string.
 * @param {!NativePointer} ssl A pointer to an SSL object.
 * @return {dict} A string representing the session_id of the SSL object's
 *     SSL_SESSION. For example,
 *     "59FD71B7B90202F359D89E66AE4E61247954E28431F6C6AC46625D472FF76336".
 *
 * On NSS the return type of SSL_GetSessionID is a SECItem:
      typedef enum {
 * siBuffer = 0,
 * siClearDataBuffer = 1,
 * siCipherDataBuffer = 2,
 * siDERCertBuffer = 3,
 * siEncodedCertBuffer = 4,
 * siDERNameBuffer = 5,
 * siEncodedNameBuffer = 6,
 * siAsciiNameString = 7,
 * siAsciiString = 8,
 * siDEROID = 9,
 * siUnsignedInteger = 10,
 * siUTCTime = 11,
 * siGeneralizedTime = 12,
 * siVisibleString = 13,
 * siUTF8String = 14,
 * siBMPString = 15
 * } SECItemType;
 *
 * typedef struct SECItemStr SECItem;
 *
 * struct SECItemStr {
 * SECItemType type;
 * unsigned char *data;
 * unsigned int len;
 * }; --> size = 20
 *
 *
 */
    static getSslSessionIdFromFD(pRFileDesc) {
        var dummySSL_SessionID = "3E8ABF58649A1A1C58824D704173BA9AAFA2DA33B45FFEA341D218B29BBACF8F";
        var fdType = NSS.getDescType(pRFileDesc);
        //log("pRFileDescType: "+ fdType)
        /*if(fdType == 4){ // LAYERED
            pRFileDesc = ptr(getSSL_Layer(pRFileDesc).toString())
            if(pRFileDesc.toString() == "-1"){
                log("error")
        
            }
        }*/
        var layer = NSS.NSS_FindIdentityForName(pRFileDesc, 'SSL');
        if (!layer) {
            return dummySSL_SessionID;
        }
        var sslSessionIdSECItem = ptr(NSS.SSL_SESSION_get_id(layer).toString());
        if (sslSessionIdSECItem == null || sslSessionIdSECItem.isNull()) {
            try {
                devlog("---- getSslSessionIdFromFD -----");
                devlog("ERROR");
                devlog("pRFileDescType: " + NSS.getDescType(pRFileDesc));
                if (fdType == 2) {
                    var c = Memory.dup(pRFileDesc, 32);
                    //log(hexdump(c))
                    var getLayersIdentity = new NativeFunction(Module.getExportByName('libnspr4.so', 'PR_GetLayersIdentity'), "uint32", ["pointer"]);
                    var getNameOfIdentityLayer = new NativeFunction(Module.getExportByName('libnspr4.so', 'PR_GetNameForIdentity'), "pointer", ["uint32"]);
                    var layerID = getLayersIdentity(pRFileDesc);
                    devlog("LayerID: " + layerID);
                    var nameIDentity = getNameOfIdentityLayer(layerID);
                    devlog("name address: " + nameIDentity);
                    devlog("name: " + ptr(nameIDentity.toString()).readCString());
                    var sslSessionIdSECItem2 = ptr(NSS.getSSL_Layer(pRFileDesc).toString());
                    devlog("sslSessionIdSECItem2 =" + sslSessionIdSECItem2);
                    if (sslSessionIdSECItem2.toString().startsWith("0x7f")) {
                        var aa = Memory.dup(sslSessionIdSECItem2, 32);
                        //log(hexdump(aa))
                        var sslSessionIdSECItem3 = ptr(NSS.SSL_SESSION_get_id(sslSessionIdSECItem2).toString());
                        devlog("sslSessionIdSECItem3 =" + sslSessionIdSECItem3);
                    }
                    var sslSessionIdSECItem4 = ptr(NSS.SSL_SESSION_get_id(pRFileDesc).toString());
                    devlog("sslSessionIdSECItem4 =" + sslSessionIdSECItem4);
                    devlog("Using Dummy Session ID");
                    devlog("");
                }
                else if (fdType == 4) {
                    pRFileDesc = ptr(NSS.getSSL_Layer(pRFileDesc).toString());
                    var sslSessionIdSECItem = ptr(NSS.SSL_SESSION_get_id(pRFileDesc).toString());
                    devlog("new sessionid_ITEM: " + sslSessionIdSECItem);
                }
                else {
                    devlog("---- SSL Session Analysis ------------");
                    var c = Memory.dup(sslSessionIdSECItem, 32);
                    devlog(hexdump(c));
                }
                devlog("---- getSslSessionIdFromFD finished -----");
                devlog("");
            }
            catch (error) {
                devlog("Error:" + error);
            }
            return dummySSL_SessionID;
        }
        var len = sslSessionIdSECItem.add(pointerSize * 2).readU32();
        var session_id_ptr = sslSessionIdSECItem.add(pointerSize).readPointer();
        var session_id = NSS.getSessionIdString(session_id_ptr, len);
        return session_id;
    }
    static get_SSL_FD(pRFileDesc) {
        var ssl_layer = NSS.NSS_FindIdentityForName(pRFileDesc, 'SSL');
        if (!ssl_layer) {
            devlog("error: couldn't get SSL Layer from pRFileDesc");
            return NULL;
        }
        var sslSocketFD = NSS.get_SSL_Socket(ssl_layer);
        if (!sslSocketFD) {
            devlog("error: couldn't get sslSocketFD");
            return NULL;
        }
        return sslSocketFD;
    }
    /**
    *
    *
    *
    *
    *
    *
    * /* This function tries to find the SSL layer in the stack.
    * It searches for the first SSL layer at or below the argument fd,
    * and failing that, it searches for the nearest SSL layer above the
    * argument fd.  It returns the private sslSocket from the found layer.
    *
    sslSocket *
    ssl_FindSocket(PRFileDesc *fd)
    {
    PRFileDesc *layer;
    sslSocket *ss;
    
    PORT_Assert(fd != NULL);
    PORT_Assert(ssl_layer_id != 0);
    
    layer = PR_GetIdentitiesLayer(fd, ssl_layer_id);
    if (layer == NULL) {
    PORT_SetError(PR_BAD_DESCRIPTOR_ERROR);
    return NULL;
    }
    
    ss = (sslSocket *)layer->secret;
    /* Set ss->fd lazily. We can't rely on the value of ss->fd set by
    * ssl_PushIOLayer because another PR_PushIOLayer call will switch the
    * contents of the PRFileDesc pointed by ss->fd and the new layer.
    * See bug 807250.
    *
    ss->fd = layer;
    return ss;
    }
    
    *
    *
    */
    static get_SSL_Socket(ssl_layer) {
        var sslSocket = ssl_layer.add(pointerSize * 1).readPointer();
        return sslSocket;
    }
    /******** NSS Encryption Keys *******/
    /**
     *
     * ss->ssl3.cwSpec->masterSecret
     *
     * @param {*} ssl3  the parsed ssl3 struct
     * @returns the client_random as hex string (lower case)
     */
    static getMasterSecret(ssl3) {
        var cwSpec = ssl3.cwSpec;
        var masterSecret_Ptr = NSS.parse_struct_sl3CipherSpecStr(cwSpec).master_secret;
        var master_secret = NSS.get_Secret_As_HexString(masterSecret_Ptr);
        return master_secret;
    }
    /**
     * ss->ssl3.hs.client_random
     *
     * @param {*} ssl3 is a ptr to current parsed ssl3 struct
     * @returns the client_random as hex string (lower case)
     */
    static getClientRandom(ssl3) {
        var client_random = NSS.getHexString(ssl3.hs.client_random, NSS.SSL3_RANDOM_LENGTH);
        return client_random;
    }
    /**
    
     
    typedef struct sslSocketStr sslSocket;
     *
    
        SSL Socket struct (https://github.com/nss-dev/nss/blob/master/lib/ssl/sslimpl.h#L971)
    struct sslSocketStr {
    PRFileDesc *fd;                                                                     +8
    
    /* Pointer to operations vector for this socket *
    const sslSocketOps *ops;                                                            +8
    
    /* SSL socket options *
    sslOptions opt;                                                                     sizeOf(sslOptions) --> 40
    /* Enabled version range *
    SSLVersionRange vrange;                                                             + 4
    
    /* A function that returns the current time. *
    SSLTimeFunc now;                                                                    +8
    void *nowArg;                                                                       +8
    
    /* State flags *
    unsigned long clientAuthRequested;                                                  +8
    unsigned long delayDisabled;     /* Nagle delay disabled *                          +8
    unsigned long firstHsDone;       /* first handshake is complete. *                  +8
    unsigned long enoughFirstHsDone; /* enough of the first handshake is                +8
                                      * done for callbacks to be able to
                                      * retrieve channel security
                                      * parameters from the SSL socket. *
    unsigned long handshakeBegun;                                                       +8
    unsigned long lastWriteBlocked;                                                     +8
    unsigned long recvdCloseNotify; /* received SSL EOF. *                              +8
    unsigned long TCPconnected;                                                         +8
    unsigned long appDataBuffered;                                                      +8
    unsigned long peerRequestedProtection; /* from old renegotiation *                  +8
    
    /* version of the protocol to use *
    SSL3ProtocolVersion version;                                                        +4
    SSL3ProtocolVersion clientHelloVersion; /* version sent in client hello. *          --> at offset 160
     */
    static get_SSL_Version(pRFileDesc) {
        var ssl_version_internal_Code = -1;
        var sslSocket = NSS.get_SSL_FD(pRFileDesc);
        if (sslSocket.isNull()) {
            return -1;
        }
        var sslVersion_pointerSize = 160;
        ssl_version_internal_Code = sslSocket.add((sslVersion_pointerSize)).readU16();
        return ssl_version_internal_Code;
    }
    static get_Secret_As_HexString(secret_key_Ptr) {
        var rv = NSS.PK11_ExtractKeyValue(secret_key_Ptr);
        if (rv != SECStatus.SECSuccess) {
            //log("[**] ERROR access the secret key");
            return "";
        }
        var keyData = NSS.PK11_GetKeyData(secret_key_Ptr); // return value is a SECItem
        var keyData_SECITem = NSS.parse_struct_SECItem(keyData);
        var secret_as_hexString = NSS.getHexString(keyData_SECITem.data, keyData_SECITem.len);
        return secret_as_hexString;
    }
    /**
     *
     * @param {*} ssl_version_internal_Code
     * @returns
     *
     *      https://github.com/nss-dev/nss/blob/c989bde00fe64c1b37df13c773adf3e91cc258c7/lib/ssl/sslproto.h#L16
     *      #define SSL_LIBRARY_VERSION_TLS_1_2             0x0303
     *      #define SSL_LIBRARY_VERSION_TLS_1_3             0x0304
     *
     *      0x0303 -->  771
     *      0x0304 -->  772
     *
     */
    static is_TLS_1_3(ssl_version_internal_Code) {
        if (ssl_version_internal_Code > 771) {
            return true;
        }
        else {
            return false;
        }
    }
    //see nss/lib/ssl/sslinfo.c for details */
    static get_Keylog_Dump(type, client_random, key) {
        return type + " " + client_random + " " + key;
    }
    /**
     *
     * @param {*} pRFileDesc
     * @param {*} dumping_handshake_secrets  a zero indicates an false and that the handshake just completed. A 1 indicates a true so that we are during the handshake itself
     * @returns
     */
    static getTLS_Keys(pRFileDesc, dumping_handshake_secrets) {
        var message = {};
        message["contentType"] = "keylog";
        devlog("[*] trying to log some keying materials ...");
        var sslSocketFD = NSS.get_SSL_FD(pRFileDesc);
        if (sslSocketFD.isNull()) {
            return;
        }
        var sslSocketStr = NSS.parse_struct_sslSocketStr(sslSocketFD);
        var ssl3_struct = sslSocketStr.ssl3;
        var ssl3 = NSS.parse_struct_ssl3Str(ssl3_struct);
        // the client_random is used to identify the diffrent SSL streams with their corresponding secrets
        var client_random = NSS.getClientRandom(ssl3);
        if (NSS.doTLS13_RTT0 == 1) {
            //var early_exporter_secret = get_Secret_As_HexString(ssl3_struct.add(768).readPointer()); //EARLY_EXPORTER_SECRET
            var early_exporter_secret = NSS.get_Secret_As_HexString(ssl3.hs.earlyExporterSecret); //EARLY_EXPORTER_SECRET
            devlog(NSS.get_Keylog_Dump("EARLY_EXPORTER_SECRET", client_random, early_exporter_secret));
            message["keylog"] = NSS.get_Keylog_Dump("EARLY_EXPORTER_SECRET", client_random, early_exporter_secret);
            send(message);
            NSS.doTLS13_RTT0 = -1;
        }
        if (dumping_handshake_secrets == 1) {
            devlog("[*] exporting TLS 1.3 handshake keying material");
            /*
             * Those keys are computed in the beginning of a handshake
             */
            //var client_handshake_traffic_secret = get_Secret_As_HexString(ssl3_struct.add(736).readPointer()); //CLIENT_HANDSHAKE_TRAFFIC_SECRET
            var client_handshake_traffic_secret = NSS.get_Secret_As_HexString(ssl3.hs.clientHsTrafficSecret); //CLIENT_HANDSHAKE_TRAFFIC_SECRET
            //parse_struct_ssl3Str(ssl3_struct)
            devlog(NSS.get_Keylog_Dump("CLIENT_HANDSHAKE_TRAFFIC_SECRET", client_random, client_handshake_traffic_secret));
            message["keylog"] = NSS.get_Keylog_Dump("CLIENT_HANDSHAKE_TRAFFIC_SECRET", client_random, client_handshake_traffic_secret);
            send(message);
            //var server_handshake_traffic_secret = get_Secret_As_HexString(ssl3_struct.add(744).readPointer()); //SERVER_HANDSHAKE_TRAFFIC_SECRET
            var server_handshake_traffic_secret = NSS.get_Secret_As_HexString(ssl3.hs.serverHsTrafficSecret); //SERVER_HANDSHAKE_TRAFFIC_SECRET
            devlog(NSS.get_Keylog_Dump("SERVER_HANDSHAKE_TRAFFIC_SECRET", client_random, server_handshake_traffic_secret));
            message["keylog"] = NSS.get_Keylog_Dump("SERVER_HANDSHAKE_TRAFFIC_SECRET", client_random, server_handshake_traffic_secret);
            send(message);
            return;
        }
        else if (dumping_handshake_secrets == 2) {
            devlog("[*] exporting TLS 1.3 RTT0 handshake keying material");
            var client_early_traffic_secret = NSS.get_Secret_As_HexString(ssl3.hs.clientEarlyTrafficSecret); //CLIENT_EARLY_TRAFFIC_SECRET
            devlog(NSS.get_Keylog_Dump("CLIENT_EARLY_TRAFFIC_SECRET", client_random, client_early_traffic_secret));
            message["keylog"] = NSS.get_Keylog_Dump("CLIENT_EARLY_TRAFFIC_SECRET", client_random, client_early_traffic_secret);
            send(message);
            NSS.doTLS13_RTT0 = 1; // there is no callback for the EARLY_EXPORTER_SECRET
            return;
        }
        var ssl_version_internal_Code = NSS.get_SSL_Version(pRFileDesc);
        if (NSS.is_TLS_1_3(ssl_version_internal_Code)) {
            devlog("[*] exporting TLS 1.3 keying material");
            var client_traffic_secret = NSS.get_Secret_As_HexString(ssl3.hs.clientTrafficSecret); //CLIENT_TRAFFIC_SECRET_0
            devlog(NSS.get_Keylog_Dump("CLIENT_TRAFFIC_SECRET_0", client_random, client_traffic_secret));
            message["keylog"] = NSS.get_Keylog_Dump("CLIENT_TRAFFIC_SECRET_0", client_random, client_traffic_secret);
            send(message);
            var server_traffic_secret = NSS.get_Secret_As_HexString(ssl3.hs.serverTrafficSecret); //SERVER_TRAFFIC_SECRET_0
            devlog(NSS.get_Keylog_Dump("SERVER_TRAFFIC_SECRET_0", client_random, server_traffic_secret));
            message["keylog"] = NSS.get_Keylog_Dump("SERVER_TRAFFIC_SECRET_0", client_random, server_traffic_secret);
            send(message);
            var exporter_secret = NSS.get_Secret_As_HexString(ssl3.hs.exporterSecret); //EXPORTER_SECRET 
            devlog(NSS.get_Keylog_Dump("EXPORTER_SECRET", client_random, exporter_secret));
            message["keylog"] = NSS.get_Keylog_Dump("EXPORTER_SECRET", client_random, exporter_secret);
            send(message);
        }
        else {
            devlog("[*] exporting TLS 1.2 keying material");
            var master_secret = NSS.getMasterSecret(ssl3);
            devlog(NSS.get_Keylog_Dump("CLIENT_RANDOM", client_random, master_secret));
            message["keylog"] = NSS.get_Keylog_Dump("CLIENT_RANDOM", client_random, master_secret);
            send(message);
        }
        NSS.doTLS13_RTT0 = -1;
        return;
    }
    static ssl_RecordKeyLog(sslSocketFD) {
        NSS.getTLS_Keys(sslSocketFD, 0);
    }
    /***** Installing the hooks *****/
    install_plaintext_read_hook() {
        var current_module_name = this.module_name;
        var lib_addesses = this.addresses;
        Interceptor.attach(this.addresses[this.moduleName]["PR_Read"], {
            onEnter: function (args) {
                // ab hier nicht mehr
                this.fd = ptr(args[0]);
                this.buf = ptr(args[1]);
            },
            onLeave: function (retval) {
                if (retval.toInt32() <= 0 || NSS.getDescType(this.fd) == PRDescType.PR_DESC_FILE) {
                    return;
                }
                log("The results of NSS and its PR_Read is likely not the information transmitted over the wire. Better do a full capture and just log the TLS keys");
                var addr = Memory.alloc(8);
                var res = NSS.getpeername(this.fd, addr);
                // peername return -1 this is due to the fact that a PIPE descriptor is used to read from the SSL socket
                if (addr.readU16() == 2 || addr.readU16() == 10 || addr.readU16() == 100) {
                    var message = NSS.getPortsAndAddressesFromNSS(this.fd, true, lib_addesses[current_module_name], enable_default_fd);
                    devlog("Session ID: " + NSS.getSslSessionIdFromFD(this.fd));
                    message["ssl_session_id"] = NSS.getSslSessionIdFromFD(this.fd);
                    message["function"] = "NSS_read";
                    this.message = message;
                    this.message["contentType"] = "datalog";
                    var data = this.buf.readByteArray((new Uint32Array([retval]))[0]);
                    send(message, data);
                }
                else {
                    var message = NSS.getPortsAndAddressesFromNSS(null, true, lib_addesses[current_module_name], enable_default_fd);
                    message["ssl_session_id"] = NSS.getSslSessionIdFromFD(this.fd);
                    message["function"] = "NSS_read";
                    this.message = message;
                    this.message["contentType"] = "datalog";
                    var temp = this.buf.readByteArray((new Uint32Array([retval]))[0]);
                    devlog(JSON.stringify(temp));
                    send(message, temp);
                }
            }
        });
    }
    install_plaintext_write_hook() {
        var current_module_name = this.module_name;
        var lib_addesses = this.addresses;
        Interceptor.attach(this.addresses[this.moduleName]["PR_Write"], {
            onEnter: function (args) {
                this.fd = ptr(args[0]);
                this.buf = args[1];
                this.len = args[2];
            },
            onLeave: function (retval) {
                if (retval.toInt32() <= 0) { //|| NSS.getDescType(this.fd) == PRDescType.PR_DESC_FILE) {
                    return;
                }
                var addr = Memory.alloc(8);
                NSS.getsockname(this.fd, addr);
                if (addr.readU16() == 2 || addr.readU16() == 10 || addr.readU16() == 100) {
                    var message = NSS.getPortsAndAddressesFromNSS(this.fd, false, lib_addesses[current_module_name], enable_default_fd);
                    message["ssl_session_id"] = NSS.getSslSessionIdFromFD(this.fd);
                    message["function"] = "NSS_write";
                    message["contentType"] = "datalog";
                    send(message, this.buf.readByteArray((parseInt(this.len))));
                }
                else {
                    log("The results of NSS and its PR_Write is likely not the information transmitted over the wire. Better do a full capture and just log the TLS keys");
                    var message = NSS.getPortsAndAddressesFromNSS(null, true, lib_addesses[current_module_name], enable_default_fd);
                    message["ssl_session_id"] = NSS.getSslSessionIdFromFD(this.fd);
                    message["function"] = "NSS_write";
                    this.message = message;
                    this.message["contentType"] = "datalog";
                    var temp = this.buf.readByteArray((new Uint32Array([retval]))[0]);
                    devlog(JSON.stringify(temp));
                    send(message, temp);
                }
            }
        });
    }
    /***** install callbacks for key logging ******/
    /**
 *
 * This callback gets only called in TLS 1.3 and newer versions
 *
 * @param {*} pRFileDesc
 * @param {*} secret_label
 * @param {*} secret
 * @returns
 *
function tls13_RecordKeyLog(pRFileDesc, secret_label, secret){

    var sslSocketFD = get_SSL_FD(pRFileDesc);
    if(sslSocketFD == -1){
        return;
    }

    var sslSocketStr = parse_struct_sslSocketStr(sslSocketFD);

    var ssl3_struct = sslSocketStr.ssl3;
    var ssl3 = parse_struct_ssl3Str(ssl3_struct);
    

    var secret_as_hexString = get_Secret_As_HexString(secret);
    

    log(get_Keylog_Dump(secret_label,getClientRandom(ssl3),secret_as_hexString));


    return 0;
}

// our old way to get the diffrent secrets from TLS 1.3 and above
*/
    static parse_epoch_value_from_SSL_SetSecretCallback(sslSocketFD, epoch) {
        if (epoch == 1) { // client_early_traffic_secret
            NSS.getTLS_Keys(sslSocketFD, 2);
        }
        else if (epoch == 2) { // client|server}_handshake_traffic_secret
            NSS.getTLS_Keys(sslSocketFD, 1);
            /* our old way to get the diffrent secrets from TLS 1.3 and above
    
            per default we assume we are intercepting a TLS client therefore
            dir == 1 --> SERVER_HANDSHAKE_TRAFFIC_SECRET
            dir == 2 --> CLIENT_HANDSHAKE_TRAFFIC_SECRET
            typedef enum {
                ssl_secret_read = 1,
                ssl_secret_write = 2,
            } SSLSecretDirection;
            
            if(dir == 1){
                tls13_RecordKeyLog(sslSocketFD,"SERVER_HANDSHAKE_TRAFFIC_SECRET",secret);
            }else{
                tls13_RecordKeyLog(sslSocketFD,"CLIENT_HANDSHAKE_TRAFFIC_SECRET",secret);
            }*/
        }
        else if (epoch >= 3) { // {client|server}_application_traffic_secret_{N}
            return;
            // we intercept this through the handshake_callback
        }
        else {
            devlog("[-] secret_callback invocation: UNKNOWN");
        }
    }
    static insert_hook_into_secretCallback(addr_of_installed_secretCallback) {
        Interceptor.attach(addr_of_installed_secretCallback, {
            onEnter(args) {
                this.sslSocketFD = args[0];
                this.epoch = args[1];
                NSS.parse_epoch_value_from_SSL_SetSecretCallback(this.sslSocketFD, this.epoch);
            },
            onLeave(retval) {
            }
        });
    }
    /**
         * Registers a secret_callback through inserting the address to our TLS 1.3 callback function at the apprioate offset of the  SSL Socket struct
         * This is neccassy because the computed handshake secrets are already freed after the handshake is completed.
         *
         *
         * @param {*} pRFileDesc a file descriptor (NSS PRFileDesc) to a SSL socket
         * @returns
         */
    static register_secret_callback(pRFileDesc) {
        var sslSocketFD = NSS.get_SSL_FD(pRFileDesc);
        if (sslSocketFD.isNull()) {
            devlog("[-] error while installing secret callback: unable get SSL socket descriptor");
            return;
        }
        var sslSocketStr = NSS.parse_struct_sslSocketStr(sslSocketFD);
        if (NSS.is_ptr_at_mem_location(sslSocketStr.secretCallback.readPointer()) == 1) {
            NSS.insert_hook_into_secretCallback(sslSocketStr.secretCallback.readPointer());
        }
        else {
            sslSocketStr.secretCallback.writePointer(NSS.secret_callback);
        }
        devlog("[**] secret callback (" + NSS.secret_callback + ") installed to address: " + sslSocketStr.secretCallback);
    }
    install_tls_keys_callback_hook() {
    }
}
// global definitions
NSS.doTLS13_RTT0 = -1;
NSS.SSL3_RANDOM_LENGTH = 32;
/********* NSS Callbacks ************/
/*
This callback gets called whenever a SSL Handshake completed

typedef void (*SSLHandshakeCallback)(
        PRFileDesc *fd,
        void *client_data);
*/
NSS.keylog_callback = new NativeCallback(function (sslSocketFD, client_data) {
    if (typeof this !== "undefined") {
        NSS.ssl_RecordKeyLog(sslSocketFD);
    }
    else {
        console.log("[-] Error while installing ssl_RecordKeyLog() callback");
    }
    return 0;
}, "void", ["pointer", "pointer"]);
/**
 * SSL_SetSecretCallback installs a callback that TLS calls when it installs new
 * traffic secrets.
 *
 *
 *
 * SSLSecretCallback is called with the current epoch and the corresponding
 * secret; this matches the epoch used in DTLS 1.3, even if the socket is
 * operating in stream mode:
 *
 * - client_early_traffic_secret corresponds to epoch 1
 * - {client|server}_handshake_traffic_secret is epoch 2
 * - {client|server}_application_traffic_secret_{N} is epoch 3+N
 *
 * The callback is invoked separately for read secrets (client secrets on the
 * server; server secrets on the client), and write secrets.
 *
 * This callback is only called if (D)TLS 1.3 is negotiated.
 *
 * typedef void(PR_CALLBACK *SSLSecretCallback)(
 *   PRFileDesc *fd, PRUint16 epoch, SSLSecretDirection dir, PK11SymKey *secret,
 *   void *arg);
 *
 *  More: https://github.com/nss-dev/nss/blob/master/lib/ssl/sslexp.h#L614
 *
 */
NSS.secret_callback = new NativeCallback(function (sslSocketFD, epoch, dir, secret, arg_ptr) {
    if (typeof this !== "undefined") {
        NSS.parse_epoch_value_from_SSL_SetSecretCallback(sslSocketFD, epoch);
    }
    else {
        console.log("[-] Error while installing parse_epoch_value_from_SSL_SetSecretCallback()");
    }
    return;
}, "void", ["pointer", "uint16", "uint16", "pointer", "pointer"]);
✄
{"version":3,"file":"openssl_boringssl.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/ssl_lib/openssl_boringssl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AACvH,OAAO,EAAc,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AAG7C,MAAM,cAAc;IAGhB;QAFO,qBAAgB,GAAuB,IAAI,CAAC;QAC5C,sBAAiB,GAAuB,IAAI,CAAC;QAEhD,IAAI,CAAC,gBAAgB,EAAE,CAAC;QACxB,IAAI,CAAC,iBAAiB,EAAE,CAAC;IAC7B,CAAC;IAEO,gBAAgB;QACpB,IAAI,CAAC,SAAS,EAAE,CAAC,MAAM,EAAC,EAAE;YACtB,YAAY;YACZ,IAAI,CAAC,gBAAgB,GAAG,MAAM,CAAC,OAAO,IAAI,IAAI,CAAC,CAAC,CAAE,IAAI,UAAU,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,UAAU,CAAC;gBACjH,OAAO,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;YACxB,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAA;YACnB,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAC5B,CAAC,CAAC,CAAC;IAEP,CAAC;IAEO,iBAAiB;QACrB,IAAI,CAAC,UAAU,EAAE,CAAC,MAAM,EAAC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AAI,WAAW,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;QACjC,IAAI,CAAC,GAAG,IAAI,CAAC,kBAAkB,CAAC,OAAO,EAAE,WAAW,CAAkB,CAAA;QACtE,IAAI,GAAG,GAAG,WAAW,CAAC,OAAO,EAAE,CAAA;QAC/B,IAAI,UAAU,GAAG,EAAE,CAAA;QACnB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE;YAC1B,sEAAsE;YACtE,oBAAoB;YAEpB,UAAU;gBACN,CAAC,GAAG,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;SACtE;QACD,OAAO,UAAU,CAAA;IACrB,CAAC;;AAlVM,iCAAe,GAAG,IAAI,cAAc,CAAC,UAAU,MAAM,EAAE,OAAsB;IAChF,MAAM,CAAC,iDAAiD,CAAC,CAAC;IAC1D,IAAI,OAAO,GAA8C,EAAE,CAAA;IAC3D,OAAO,CAAC,aAAa,CAAC,GAAG,QAAQ,CAAA;IACjC,OAAO,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,WAAW,EAAE,CAAA;IACzC,IAAI,CAAC,OAAO,CAAC,CAAA;AACjB,CAAC,EAAE,MAAM,EAAE,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,AANZ,CAMY"}
✄
import { readAddresses, getPortsAndAddresses, getBaseAddress, isSymbolAvailable } from "../shared/shared_functions.js";
import { offsets, enable_default_fd } from "../ssl_log.js";
import { devlog, log } from "../util/log.js";
class ModifyReceiver {
    constructor() {
        this.readModification = null;
        this.writeModification = null;
        this.listenForReadMod();
        this.listenForWriteMod();
    }
    listenForReadMod() {
        recv("readmod", (newBuf) => {
            //@ts-ignore
            this.readModification = newBuf.payload != null ? new Uint8Array(newBuf.payload.match(/[\da-f]{2}/gi).map(function (h) {
                return parseInt(h, 16);
            })).buffer : null;
            this.listenForReadMod();
        });
    }
    listenForWriteMod() {
        recv("writemod", (newBuf) => {
            //@ts-ignore
            this.writeModification = newBuf.payload != null ? new Uint8Array(newBuf.payload.match(/[\da-f]{2}/gi).map(function (h) {
                return parseInt(h, 16);
            })).buffer : null;
            this.listenForWriteMod();
        });
    }
    get readmod() {
        return this.readModification;
    }
    get writemod() {
        return this.writeModification;
    }
    set readmod(val) {
        this.readModification = val;
    }
    set writemod(val) {
        this.writeModification = val;
    }
}
/**
 *
 * ToDO
 *  We need to find a way to calculate the offsets in a automated manner.
 *  Darwin: SSL_read/write need improvments
 *  Windows: how to extract the key material?
 *  Android: We need to find a way, when on some Android Apps the fd is below 0
 */
export class OpenSSL_BoringSSL {
    constructor(moduleName, socket_library, is_base_hook, passed_library_method_mapping) {
        this.moduleName = moduleName;
        this.socket_library = socket_library;
        this.passed_library_method_mapping = passed_library_method_mapping;
        // global variables
        this.library_method_mapping = {};
        OpenSSL_BoringSSL.modReceiver = new ModifyReceiver();
        if (typeof passed_library_method_mapping !== 'undefined') {
            this.library_method_mapping = passed_library_method_mapping;
        }
        else {
            this.library_method_mapping[`*${moduleName}*`] = ["SSL_read", "SSL_write", "SSL_get_fd", "SSL_get_session", "SSL_SESSION_get_id", "SSL_new", "SSL_do_handshake", "SSL_CTX_set_keylog_callback"];
            this.library_method_mapping[`*${socket_library}*`] = ["getpeername", "getsockname", "ntohs", "ntohl"];
        }
        // Check and add SSL_read_ex if available
        if (isSymbolAvailable(moduleName, "SSL_read_ex")) {
            this.library_method_mapping[`*${moduleName}*`].push("SSL_read_ex");
            this.is_openssl = true;
        }
        else {
            this.is_openssl = false;
        }
        // Check and add SSL_write_ex if available
        if (isSymbolAvailable(moduleName, "SSL_write_ex")) {
            this.library_method_mapping[`*${moduleName}*`].push("SSL_write_ex");
        }
        this.is_base_hook = is_base_hook;
        this.addresses = readAddresses(moduleName, this.library_method_mapping);
        this.module_name = moduleName;
        // @ts-ignore
        if (offsets != "{OFFSETS}" && offsets.openssl != null) {
            if (offsets.sockets != null) {
                const socketBaseAddress = getBaseAddress(socket_library);
                for (const method of Object.keys(offsets.sockets)) {
                    //@ts-ignore
                    this.addresses[this.moduleName][`${method}`] = offsets.sockets[`${method}`].absolute || socketBaseAddress == null ? ptr(offsets.sockets[`${method}`].address) : socketBaseAddress.add(ptr(offsets.sockets[`${method}`].address));
                }
            }
            const libraryBaseAddress = getBaseAddress(moduleName);
            if (libraryBaseAddress == null)
                log("Unable to find library base address! Given address values will be interpreted as absolute ones!");
            for (const method of Object.keys(offsets.openssl)) {
                //@ts-ignore
                this.addresses[this.moduleName][`${method}`] = offsets.openssl[`${method}`].absolute || libraryBaseAddress == null ? ptr(offsets.openssl[`${method}`].address) : libraryBaseAddress.add(ptr(offsets.openssl[`${method}`].address));
            }
        }
        this.SSL_SESSION_get_id = new NativeFunction(this.addresses[this.moduleName]["SSL_SESSION_get_id"], "pointer", ["pointer", "pointer"]);
        this.SSL_get_fd = ObjC.available ? new NativeFunction(this.addresses[this.moduleName]["BIO_get_fd"], "int", ["pointer"]) : new NativeFunction(this.addresses[this.moduleName]["SSL_get_fd"], "int", ["pointer"]);
        this.SSL_get_session = new NativeFunction(this.addresses[this.moduleName]["SSL_get_session"], "pointer", ["pointer"]);
    }
    install_plaintext_read_hook() {
        function ab2str(buf) {
            //@ts-ignore
            return String.fromCharCode.apply(null, new Uint16Array(buf));
        }
        function str2ab(str) {
            var buf = new ArrayBuffer(str.length + 1); // 2 bytes for each char
            var bufView = new Uint8Array(buf);
            for (var i = 0, strLen = str.length; i < strLen; i++) {
                bufView[i] = str.charCodeAt(i);
            }
            bufView[str.length] = 0;
            return buf;
        }
        var lib_addesses = this.addresses;
        var instance = this;
        var current_module_name = this.module_name;
        Interceptor.attach(this.addresses[this.moduleName]["SSL_read"], {
            onEnter: function (args) {
                this.bufLen = args[2].toInt32();
                this.fd = instance.SSL_get_fd(args[0]);
                if (this.fd < 0 && enable_default_fd == false) {
                    return;
                }
                var message = getPortsAndAddresses(this.fd, true, lib_addesses[current_module_name], enable_default_fd);
                message["ssl_session_id"] = instance.getSslSessionId(args[0]);
                message["function"] = "SSL_read";
                this.message = message;
                this.buf = args[1];
            },
            onLeave: function (retval) {
                retval |= 0; // Cast retval to 32-bit integer.
                if (retval <= 0 || this.fd < 0) {
                    return;
                }
                if (OpenSSL_BoringSSL.modReceiver.readmod !== null) {
                    //NULL out buffer
                    //@ts-ignore
                    Memory.writeByteArray(this.buf, new Uint8Array(this.bufLen));
                    //@ts-ignore
                    Memory.writeByteArray(this.buf, OpenSSL_BoringSSL.modReceiver.readmod);
                    retval = OpenSSL_BoringSSL.modReceiver.readmod.byteLength;
                }
                this.message["contentType"] = "datalog";
                send(this.message, this.buf.readByteArray(retval));
            }
        });
    }
    install_plaintext_write_hook() {
        function str2ab(str) {
            var buf = new ArrayBuffer(str.length + 1); // 2 bytes for each char
            var bufView = new Uint8Array(buf);
            for (var i = 0, strLen = str.length; i < strLen; i++) {
                bufView[i] = str.charCodeAt(i);
            }
            bufView[str.length] = 0;
            return buf;
        }
        var current_module_name = this.module_name;
        var lib_addesses = this.addresses;
        var instance = this;
        Interceptor.attach(this.addresses[this.moduleName]["SSL_write"], {
            onEnter: function (args) {
                if (!ObjC.available) {
                    try {
                        this.fd = instance.SSL_get_fd(args[0]);
                    }
                    catch (error) {
                        if (!this.is_base_hook) {
                            const fallback_addresses = global.init_addresses;
                            //console.log("Current ModuleName: "+current_module_name);
                            let keys = Object.keys(fallback_addresses);
                            let firstKey = keys[0];
                            instance.SSL_SESSION_get_id = new NativeFunction(fallback_addresses[firstKey]["SSL_SESSION_get_id"], "pointer", ["pointer", "pointer"]);
                            instance.SSL_get_fd = ObjC.available ? new NativeFunction(fallback_addresses[firstKey]["BIO_get_fd"], "int", ["pointer"]) : new NativeFunction(fallback_addresses["SSL_get_fd"], "int", ["pointer"]);
                            instance.SSL_get_session = new NativeFunction(fallback_addresses[firstKey]["SSL_get_session"], "pointer", ["pointer"]);
                        }
                        else {
                            if (error instanceof Error) {
                                console.log("Error: " + error.message);
                                console.log("Stack: " + error.stack);
                            }
                            else {
                                console.log("Unexpected error:", error);
                            }
                        }
                    }
                    if (this.fd < 0 && enable_default_fd == false) {
                        return;
                    }
                    var message = getPortsAndAddresses(this.fd, false, lib_addesses[current_module_name], enable_default_fd);
                    message["ssl_session_id"] = instance.getSslSessionId(args[0]);
                    message["function"] = "SSL_write";
                    message["contentType"] = "datalog";
                    if (OpenSSL_BoringSSL.modReceiver.writemod !== null) {
                        const newPointer = Memory.alloc(OpenSSL_BoringSSL.modReceiver.writemod.byteLength);
                        //@ts-ignore
                        Memory.writeByteArray(newPointer, OpenSSL_BoringSSL.modReceiver.writemod);
                        args[1] = newPointer;
                        args[2] = new NativePointer(OpenSSL_BoringSSL.modReceiver.writemod.byteLength);
                    }
                    send(message, args[1].readByteArray(args[2].toInt32()));
                } // this is a temporary workaround for the fd problem on iOS
            },
            onLeave: function (retval) {
            }
        });
    }
    install_tls_keys_callback_hook() {
        log("Error: TLS key extraction not implemented yet.");
    }
    install_extended_hooks() {
        // these functions (and its symbols) only available on OpenSSL
        if (this.is_openssl) {
            var current_module_name = this.module_name;
            var lib_addesses = this.addresses;
            var instance = this;
            Interceptor.attach(this.addresses[this.moduleName]["SSL_read_ex"], {
                onEnter: function (args) {
                    this.bufLen = args[2].toInt32();
                    this.fd = instance.SSL_get_fd(args[0]);
                    if (this.fd < 0 && enable_default_fd == false) {
                        return;
                    }
                    var message = getPortsAndAddresses(this.fd, true, lib_addesses[current_module_name], enable_default_fd);
                    message["ssl_session_id"] = instance.getSslSessionId(args[0]);
                    message["function"] = "SSL_read_ex";
                    this.message = message;
                    this.buf = args[1];
                },
                onLeave: function (retval) {
                    retval |= 0; // Cast retval to 32-bit integer.
                    if (retval <= 0 || this.fd < 0) {
                        return;
                    }
                    this.message["contentType"] = "datalog";
                    send(this.message, this.buf.readByteArray(retval));
                }
            });
            Interceptor.attach(this.addresses[this.moduleName]["SSL_write_ex"], {
                onEnter: function (args) {
                    if (!ObjC.available) {
                        try {
                            this.fd = instance.SSL_get_fd(args[0]);
                        }
                        catch (error) {
                            if (!this.is_base_hook) {
                                const fallback_addresses = global.init_addresses;
                                let keys = Object.keys(fallback_addresses);
                                let firstKey = keys[0];
                                instance.SSL_SESSION_get_id = new NativeFunction(fallback_addresses[firstKey]["SSL_SESSION_get_id"], "pointer", ["pointer", "pointer"]);
                                instance.SSL_get_fd = ObjC.available ? new NativeFunction(fallback_addresses[firstKey]["BIO_get_fd"], "int", ["pointer"]) : new NativeFunction(fallback_addresses["SSL_get_fd"], "int", ["pointer"]);
                                instance.SSL_get_session = new NativeFunction(fallback_addresses[firstKey]["SSL_get_session"], "pointer", ["pointer"]);
                            }
                            else {
                                if (error instanceof Error) {
                                    console.log("Error: " + error.message);
                                    console.log("Stack: " + error.stack);
                                }
                                else {
                                    console.log("Unexpected error:", error);
                                }
                            }
                        }
                        if (this.fd < 0 && enable_default_fd == false) {
                            return;
                        }
                        var message = getPortsAndAddresses(this.fd, false, lib_addesses[current_module_name], enable_default_fd);
                        message["ssl_session_id"] = instance.getSslSessionId(args[0]);
                        message["function"] = "SSL_write_ex";
                        message["contentType"] = "datalog";
                        send(message, args[1].readByteArray(args[2].toInt32()));
                    } // this is a temporary workaround for the fd problem on iOS
                },
                onLeave: function (retval) {
                }
            });
        }
    }
    /**
      * Get the session_id of SSL object and return it as a hex string.
      * @param {!NativePointer} ssl A pointer to an SSL object.
      * @return {dict} A string representing the session_id of the SSL object's
      *     SSL_SESSION. For example,
      *     "59FD71B7B90202F359D89E66AE4E61247954E28431F6C6AC46625D472FF76336".
      */
    getSslSessionId(ssl) {
        var session = this.SSL_get_session(ssl);
        if (session.isNull()) {
            if (enable_default_fd) {
                log("using dummy SessionID: 59FD71B7B90202F359D89E66AE4E61247954E28431F6C6AC46625D472FF76336");
                return "59FD71B7B90202F359D89E66AE4E61247954E28431F6C6AC46625D472FF76336";
            }
            log("Session is null");
            return 0;
        }
        var len_pointer = Memory.alloc(4);
        var p = this.SSL_SESSION_get_id(session, len_pointer);
        var len = len_pointer.readU32();
        var session_id = "";
        for (var i = 0; i < len; i++) {
            // Read a byte, convert it to a hex string (0xAB ==> "AB"), and append
            // it to session_id.
            session_id +=
                ("0" + p.add(i).readU8().toString(16).toUpperCase()).substr(-2);
        }
        return session_id;
    }
}
OpenSSL_BoringSSL.keylog_callback = new NativeCallback(function (ctxPtr, linePtr) {
    devlog("invoking keylog_callback from OpenSSL_BoringSSL");
    var message = {};
    message["contentType"] = "keylog";
    message["keylog"] = linePtr.readCString();
    send(message);
}, "void", ["pointer", "pointer"]);
✄
{"version":3,"file":"wolfssl.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/ssl_lib/wolfssl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAe,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACjH,OAAO,EAAE,GAAG,EAAE,MAAM,gBAAgB,CAAC;AACrC,OAAO,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAE3D,MAAM,OAAO,OAAO;IAahB,YAAmB,UAAiB,EAAS,cAAqB,EAAQ,6BAAgE;QAAvH,eAAU,GAAV,UAAU,CAAO;QAAS,mBAAc,GAAd,cAAc,CAAO;QAAQ,kCAA6B,GAA7B,6BAA6B,CAAmC;QAX1I,mBAAmB;QACnB,2BAAsB,GAAqC,EAAE,CAAC;QAW1D,IAAG,OAAO,6BAA6B,KAAK,WAAW,EAAC;YACpD,IAAI,CAAC,sBAAsB,GAAG,6BAA6B,CAAC;SAC/D;aAAI;YACD,IAAI,CAAC,sBAAsB,CAAC,IAAI,UAAU,GAAG,CAAC,GAAG,CAAC,cAAc,EAAE,eAAe,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,iBAAiB,EAAE,oBAAoB,EAAE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,MAAM,IAAI,CAAC,EAAE;oBACb,OAAM;iBACT;gBACD,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,GAAG,SAAS,CAAA;gBACvC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC,CAAA;YACtD,CAAC;SACJ,CAAC,CAAA;IACN,CAAC;IAGD,4BAA4B;QACxB,IAAI,mBAAmB,GAAG,IAAI,CAAC,WAAW,CAAC;QAC3C,IAAI,YAAY,GAAG,IAAI,CAAC,SAAS,CAAC;QAClC,WAAW,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,eAAe,CAAC,EACnE;YACI,OAAO,EAAE,UAAU,IAAS;gBACxB,IAAI,OAAO,GAAG,oBAAoB,CAAC,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,CAAW,EAAE,KAAK,EAAE,YAAY,CAAC,mBAAmB,CAAC,EAAE,iBAAiB,CAAC,CAAA;gBAC1I,OAAO,CAAC,gBAAgB,CAAC,GAAG,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAA;gBAC5D,OAAO,CAAC,UAAU,CAAC,GAAG,eAAe,CAAA;gBACrC,OAAO,CAAC,aAAa,CAAC,GAAG,SAAS,CAAA;gBAClC,IAAI,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,aAAa,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAA;YAC3D,CAAC;YACD,OAAO,EAAE,UAAU,MAAW;YAC9B,CAAC;SACJ,CAAC,CAAA;IACN,CAAC;CAIJ"}
✄
import { readAddresses, getPortsAndAddresses, getBaseAddress } from "../shared/shared_functions.js";
import { log } from "../util/log.js";
import { offsets, enable_default_fd } from "../ssl_log.js";
export class WolfSSL {
    constructor(moduleName, socket_library, passed_library_method_mapping) {
        this.moduleName = moduleName;
        this.socket_library = socket_library;
        this.passed_library_method_mapping = passed_library_method_mapping;
        // global variables
        this.library_method_mapping = {};
        if (typeof passed_library_method_mapping !== 'undefined') {
            this.library_method_mapping = passed_library_method_mapping;
        }
        else {
            this.library_method_mapping[`*${moduleName}*`] = ["wolfSSL_read", "wolfSSL_write", "wolfSSL_get_fd", "wolfSSL_get_session", "wolfSSL_connect", "wolfSSL_KeepArrays", "wolfSSL_SESSION_get_master_key", "wolfSSL_get_client_random", "wolfSSL_get_server_random"];
            this.library_method_mapping[`*${socket_library}*`] = ["getpeername", "getsockname", "ntohs", "ntohl"];
        }
        this.addresses = readAddresses(moduleName, this.library_method_mapping);
        this.module_name = moduleName;
        // @ts-ignore
        if (offsets != "{OFFSETS}" && offsets.wolfssl != null) {
            if (offsets.sockets != null) {
                const socketBaseAddress = getBaseAddress(socket_library);
                for (const method of Object.keys(offsets.sockets)) {
                    //@ts-ignore
                    this.addresses[this.moduleName][`${method}`] = offsets.sockets[`${method}`].absolute || socketBaseAddress == null ? ptr(offsets.sockets[`${method}`].address) : socketBaseAddress.add(ptr(offsets.sockets[`${method}`].address));
                }
            }
            const libraryBaseAddress = getBaseAddress(moduleName);
            if (libraryBaseAddress == null) {
                log("Unable to find library base address! Given address values will be interpreted as absolute ones!");
            }
            for (const method of Object.keys(offsets.wolfssl)) {
                //@ts-ignore
                this.addresses[this.moduleName][`${method}`] = offsets.wolfssl[`${method}`].absolute || libraryBaseAddress == null ? ptr(offsets.wolfssl[`${method}`].address) : libraryBaseAddress.add(ptr(offsets.wolfssl[`${method}`].address));
            }
        }
        WolfSSL.wolfSSL_get_fd = new NativeFunction(this.addresses[this.moduleName]["wolfSSL_get_fd"], "int", ["pointer"]);
        WolfSSL.wolfSSL_get_session = new NativeFunction(this.addresses[this.moduleName]["wolfSSL_get_session"], "pointer", ["pointer"]);
    }
    install_tls_keys_callback_hook() {
        log("Error: TLS key extraction not implemented yet.");
    }
    /**
       * Get the session_id of SSL object and return it as a hex string.
       * @param {!NativePointer} ssl A pointer to an SSL object.
       * @return {dict} A string representing the session_id of the SSL object's
       *     SSL_SESSION. For example,
       *     "59FD71B7B90202F359D89E66AE4E61247954E28431F6C6AC46625D472FF76336".
       */
    static getSslSessionId(ssl) {
        var session = WolfSSL.wolfSSL_get_session(ssl);
        if (session.isNull()) {
            if (enable_default_fd) {
                log("using dummy SessionID: 59FD71B7B90202F359D89E66AE4E61247954E28431F6C6AC46625D472FF76338");
                return "59FD71B7B90202F359D89E66AE4E61247954E28431F6C6AC46625D472FF76338";
            }
            log("Session is null");
            return 0;
        }
        var p = session.add(8);
        var len = 32; // This comes from internals.h. It is untested!
        var session_id = "";
        for (var i = 0; i < len; i++) {
            // Read a byte, convert it to a hex string (0xAB ==> "AB"), and append
            // it to session_id.
            session_id +=
                ("0" + p.add(i).readU8().toString(16).toUpperCase()).substr(-2);
        }
        return session_id;
    }
    install_plaintext_read_hook() {
        var current_module_name = this.module_name;
        var lib_addesses = this.addresses;
        Interceptor.attach(this.addresses[this.moduleName]["wolfSSL_read"], {
            onEnter: function (args) {
                var message = getPortsAndAddresses(WolfSSL.wolfSSL_get_fd(args[0]), true, lib_addesses[current_module_name], enable_default_fd);
                message["function"] = "wolfSSL_read";
                message["ssl_session_id"] = WolfSSL.getSslSessionId(args[0]);
                this.message = message;
                this.buf = args[1];
            },
            onLeave: function (retval) {
                retval |= 0; // Cast retval to 32-bit integer.
                if (retval <= 0) {
                    return;
                }
                this.message["contentType"] = "datalog";
                send(this.message, this.buf.readByteArray(retval));
            }
        });
    }
    install_plaintext_write_hook() {
        var current_module_name = this.module_name;
        var lib_addesses = this.addresses;
        Interceptor.attach(this.addresses[this.moduleName]["wolfSSL_write"], {
            onEnter: function (args) {
                var message = getPortsAndAddresses(WolfSSL.wolfSSL_get_fd(args[0]), false, lib_addesses[current_module_name], enable_default_fd);
                message["ssl_session_id"] = WolfSSL.getSslSessionId(args[0]);
                message["function"] = "wolfSSL_write";
                message["contentType"] = "datalog";
                send(message, args[1].readByteArray(parseInt(args[2])));
            },
            onLeave: function (retval) {
            }
        });
    }
}
✄
{"version":3,"file":"anti_root.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/util/anti_root.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,aAAa,EAAkB,MAAM,+BAA+B,CAAC;AAE9E;;GAEG;AAGH,MAAM,OAAO,QAAQ;IA2BjB;QAzBA,iBAAY,GAAG,CAAC,yBAAyB,EAAE,+BAA+B,EAAE,sBAAsB;YAC9F,4BAA4B,EAAE,0BAA0B,EAAE,iBAAiB,EAAE,6BAA6B;YAC1G,qCAAqC,EAAE,6BAA6B,EAAE,wBAAwB;YAC9F,4BAA4B,EAAE,+BAA+B,EAAE,0BAA0B,EAAE,8BAA8B;YACzH,kCAAkC,EAAE,sBAAsB,EAAE,gCAAgC,EAAE,yBAAyB;YACvH,+BAA+B,EAAE,6BAA6B,EAAE,sBAAsB,EAAE,kBAAkB;YAC1G,0BAA0B,EAAE,mBAAmB,EAAE,sBAAsB;SAC1E,CAAC;QAEF,iBAAY,GAAG,CAAC,IAAI,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,eAAe,EAAE,aAAa,EAAE,QAAQ,CAAC,CAAC;QAEvG,mBAAc,GAAG;YACb,kBAAkB,EAAE,GAAG;YACvB,eAAe,EAAE,GAAG;YACpB,kBAAkB,EAAE,GAAG;YACvB,WAAW,EAAE,GAAG;SACnB,CAAC;QAEF,uBAAkB,GAAa,EAAE,CAAC;QAKlC,2BAAsB,GAAqC,EAAE,CAAC;QAG1D,IAAI,CAAC,sBAAsB,CAAC,SAAS,CAAC,GAAG,CAAC,QAAQ,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAA;QACtE,IAAI,CAAC,WAAW,GAAG,SAAS,CAAC;QAC7B,IAAI,CAAC,SAAS,GAAG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AG,GAAG,CAAC,CAAC;gBACzB,YAAY;gBACZ,IAAI,GAAG,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,IAAI,GAAG,IAAI,OAAO,IAAI,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,IAAI,GAAG,IAAI,IAAI,EAAE;oBACnG,GAAG,CAAC,wBAAwB,GAAG,GAAG,CAAC,CAAC;oBACnC,IAAI,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,MAAM,CAAC,CAAC;iBACnC;gBACD,IAAI,GAAG,IAAI,IAAI,EAAE;oBACd,GAAG,CAAC,wBAAwB,GAAG,GAAG,CAAC,CAAC;oBACnC,IAAI,CAAC,CAAC,CAAC,CAAC,eAAe,CAAC,cAAc,CAAC,CAAC;iBAC3C;YACL,CAAC;YACD,OAAO,EAAE,UAAS,MAAM;YAExB,CAAC;SACJ,CAAC,CAAC;QAEH;;;;;;;;;;;;;;;UAeE;IAGE,CAAC;IAED,aAAa;QACT,IAAI,CAAC,mBAAmB,EAAE,CAAC;QAC3B,IAAI,CAAC,qBAAqB,EAAE,CAAC;IACjC,CAAC;CAEJ;AAED,MAAM,UAAU,iBAAiB;IAC7B,IAAI,SAAS,GAAG,IAAI,QAAQ,EAAE,CAAC;IAC/B,SAAS,CAAC,aAAa,EAAE,CAAC;AAG9B,CAAC"}
✄
import { log, devlog } from "./log.js";
import { readAddresses } from "../shared/shared_functions.js";
/*
 * mostly taken from here: https://codeshare.frida.re/@dzonerzy/fridantiroot/
 */
export class AntiRoot {
    constructor() {
        this.RootPackages = ["com.noshufou.android.su", "com.noshufou.android.su.elite", "eu.chainfire.supersu",
            "com.koushikdutta.superuser", "com.thirdparty.superuser", "com.yellowes.su", "com.koushikdutta.rommanager",
            "com.koushikdutta.rommanager.license", "com.dimonvideo.luckypatcher", "com.chelpus.lackypatch",
            "com.ramdroid.appquarantine", "com.ramdroid.appquarantinepro", "com.devadvance.rootcloak", "com.devadvance.rootcloakplus",
            "de.robv.android.xposed.installer", "com.saurik.substrate", "com.zachspong.temprootremovejb", "com.amphoras.hidemyroot",
            "com.amphoras.hidemyrootadfree", "com.formyhm.hiderootPremium", "com.formyhm.hideroot", "me.phh.superuser",
            "eu.chainfire.supersu.pro", "com.kingouser.com", "com.topjohnwu.magisk"
        ];
        this.RootBinaries = ["su", "busybox", "supersu", "Superuser.apk", "KingoUser.apk", "SuperSu.apk", "magisk"];
        this.RootProperties = {
            "ro.build.selinux": "1",
            "ro.debuggable": "0",
            "service.adb.root": "0",
            "ro.secure": "1"
        };
        this.RootPropertiesKeys = [];
        this.library_method_mapping = {};
        this.library_method_mapping["libc.so"] = ["strstr", "fopen", "system"];
        this.module_name = "libc.so";
        this.addresses = readAddresses(this.module_name, this.library_method_mapping);
        for (var k in this.RootProperties)
            this.RootPropertiesKeys.push(k);
    }
    java_based_bypasses() {
        Java.perform(function () {
            var PackageManager = Java.use("android.app.ApplicationPackageManager");
            var Runtime = Java.use('java.lang.Runtime');
            var NativeFile = Java.use('java.io.File');
            var String = Java.use('java.lang.String');
            var SystemProperties = Java.use('android.os.SystemProperties');
            var BufferedReader = Java.use('java.io.BufferedReader');
            var ProcessBuilder = Java.use('java.lang.ProcessBuilder');
            var StringBuffer = Java.use('java.lang.StringBuffer');
            var useKeyInfo = false;
            var useProcessManager = false;
            //@ts-ignore
            var ProcessManager = NULL;
            var loaded_classes = Java.enumerateLoadedClassesSync();
            devlog("Loaded " + loaded_classes.length + " classes!");
            devlog("loaded: " + loaded_classes.indexOf('java.lang.ProcessManager'));
            if (loaded_classes.indexOf('java.lang.ProcessManager') != -1) {
                try {
                    useProcessManager = true;
                    ProcessManager = Java.use('java.lang.ProcessManager');
                }
                catch (err) {
                    devlog("ProcessManager Hook failed: " + err);
                }
            }
            else {
                //ProcessManager = null;
                devlog("ProcessManager hook not loaded");
            }
            var KeyInfo = NULL;
            if (loaded_classes.indexOf('android.security.keystore.KeyInfo') != -1) {
                try {
                    useKeyInfo = true;
                    KeyInfo = Java.use('android.security.keystore.KeyInfo');
                }
                catch (err) {
                    log("KeyInfo Hook failed: " + err);
                }
            }
            else {
                log("KeyInfo hook not loaded");
            }
            PackageManager.getPackageInfo.overload('java.lang.String', 'int').implementation = function (pname, flags) {
                var shouldFakePackage = (this.RootPackages.indexOf(pname) > -1);
                if (shouldFakePackage) {
                    log("Bypass root check for package: " + pname);
                    pname = "set.package.name.to.a.fake.one.so.we.can.bypass.it";
                }
                return this.getPackageInfo.overload('java.lang.String', 'int').call(this, pname, flags);
            };
            /*
            This check results into the following error:
            {'description': 'Error: expected an unsigned integer', 'type': 'error'}


            NativeFile.exists.implementation = function() {
                var name = NativeFile.getName.call(this);
                var shouldFakeReturn = (this.RootBinaries.indexOf(name) > -1);
                console.log(shouldFakeReturn);
                if (shouldFakeReturn) {
                   log("Bypass return value for binary: " + name);
                    return false;
                } else {
                    return this.exists.call(this);
                }
            };  */
            var exec = Runtime.exec.overload('[Ljava.lang.String;');
            var exec1 = Runtime.exec.overload('java.lang.String');
            var exec2 = Runtime.exec.overload('java.lang.String', '[Ljava.lang.String;');
            var exec3 = Runtime.exec.overload('[Ljava.lang.String;', '[Ljava.lang.String;');
            var exec4 = Runtime.exec.overload('[Ljava.lang.String;', '[Ljava.lang.String;', 'java.io.File');
            var exec5 = Runtime.exec.overload('java.lang.String', '[Ljava.lang.String;', 'java.io.File');
            exec5.implementation = function (cmd, env, dir) {
                if (cmd.indexOf("getprop") != -1 || cmd == "mount" || cmd.indexOf("build.prop") != -1 || cmd == "id" || cmd == "sh") {
                    var fakeCmd = "grep";
                    log("Bypass " + cmd + " command");
                    return exec1.call(this, fakeCmd);
                }
                if (cmd == "su") {
                    var fakeCmd = "awesome_tool";
                    log("Bypass " + cmd + " command");
                    return exec1.call(this, fakeCmd);
                }
                return exec5.call(this, cmd, env, dir);
            };
            exec4.implementation = function (cmdarr, env, file) {
                for (var i = 0; i < cmdarr.length; i = i + 1) {
                    var tmp_cmd = cmdarr[i];
                    if (tmp_cmd.indexOf("getprop") != -1 || tmp_cmd == "mount" || tmp_cmd.indexOf("build.prop") != -1 || tmp_cmd == "id" || tmp_cmd == "sh") {
                        var fakeCmd = "grep";
                        log("Bypass " + cmdarr + " command");
                        return exec1.call(this, fakeCmd);
                    }
                    if (tmp_cmd == "su") {
                        var fakeCmd = "awesome_tool";
                        log("Bypass " + cmdarr + " command");
                        return exec1.call(this, fakeCmd);
                    }
                }
                return exec4.call(this, cmdarr, env, file);
            };
            exec3.implementation = function (cmdarr, envp) {
                for (var i = 0; i < cmdarr.length; i = i + 1) {
                    var tmp_cmd = cmdarr[i];
                    if (tmp_cmd.indexOf("getprop") != -1 || tmp_cmd == "mount" || tmp_cmd.indexOf("build.prop") != -1 || tmp_cmd == "id" || tmp_cmd == "sh") {
                        var fakeCmd = "grep";
                        log("Bypass " + cmdarr + " command");
                        return exec1.call(this, fakeCmd);
                    }
                    if (tmp_cmd == "su") {
                        var fakeCmd = "awesome_tool";
                        log("Bypass " + cmdarr + " command");
                        return exec1.call(this, fakeCmd);
                    }
                }
                return exec3.call(this, cmdarr, envp);
            };
            exec2.implementation = function (cmd, env) {
                if (cmd.indexOf("getprop") != -1 || cmd == "mount" || cmd.indexOf("build.prop") != -1 || cmd == "id" || cmd == "sh") {
                    var fakeCmd = "grep";
                    log("Bypass " + cmd + " command");
                    return exec1.call(this, fakeCmd);
                }
                if (cmd == "su") {
                    var fakeCmd = "awesome_tool";
                    log("Bypass " + cmd + " command");
                    return exec1.call(this, fakeCmd);
                }
                return exec2.call(this, cmd, env);
            };
            exec.implementation = function (cmd) {
                for (var i = 0; i < cmd.length; i = i + 1) {
                    var tmp_cmd = cmd[i];
                    if (tmp_cmd.indexOf("getprop") != -1 || tmp_cmd == "mount" || tmp_cmd.indexOf("build.prop") != -1 || tmp_cmd == "id" || tmp_cmd == "sh") {
                        var fakeCmd = "grep";
                        log("Bypass " + cmd + " command");
                        return exec1.call(this, fakeCmd);
                    }
                    if (tmp_cmd == "su") {
                        var fakeCmd = "awesome_tool";
                        log("Bypass " + cmd + " command");
                        return exec1.call(this, fakeCmd);
                    }
                }
                return exec.call(this, cmd);
            };
            exec1.implementation = function (cmd) {
                if (cmd.indexOf("getprop") != -1 || cmd == "mount" || cmd.indexOf("build.prop") != -1 || cmd == "id" || cmd == "sh") {
                    var fakeCmd = "grep";
                    log("Bypass " + cmd + " command");
                    return exec1.call(this, fakeCmd);
                }
                if (cmd == "su") {
                    var fakeCmd = "awesome_tool";
                    log("Bypass " + cmd + " command");
                    return exec1.call(this, fakeCmd);
                }
                return exec1.call(this, cmd);
            };
            String.contains.implementation = function (name) {
                if (name == "test-keys") {
                    log("Bypass test-keys check");
                    return false;
                }
                return this.contains.call(this, name);
            };
            var get = SystemProperties.get.overload('java.lang.String');
            get.implementation = function (name) {
                if (this.RootPropertiesKeys.indexOf(name) != -1) {
                    log("Bypass " + name);
                    return this.RootProperties[name];
                }
                return this.get.call(this, name);
            };
            BufferedReader.readLine.overload('boolean').implementation = function () {
                var text = this.readLine.overload('boolean').call(this);
                if (text === null) {
                    // just pass , i know it's ugly as hell but test != null won't work :(
                }
                else {
                    var shouldFakeRead = (text.indexOf("ro.build.tags=test-keys") > -1);
                    if (shouldFakeRead) {
                        log("Bypass build.prop file read");
                        text = text.replace("ro.build.tags=test-keys", "ro.build.tags=release-keys");
                    }
                }
                return text;
            };
            var executeCommand = ProcessBuilder.command.overload('java.util.List');
            ProcessBuilder.start.implementation = function () {
                var cmd = this.command.call(this);
                var shouldModifyCommand = false;
                for (var i = 0; i < cmd.size(); i = i + 1) {
                    var tmp_cmd = cmd.get(i).toString();
                    if (tmp_cmd.indexOf("getprop") != -1 || tmp_cmd.indexOf("mount") != -1 || tmp_cmd.indexOf("build.prop") != -1 || tmp_cmd.indexOf("id") != -1) {
                        shouldModifyCommand = true;
                    }
                }
                if (shouldModifyCommand) {
                    log("Bypass ProcessBuilder " + cmd);
                    this.command.call(this, ["grep"]);
                    return this.start.call(this);
                }
                if (cmd.indexOf("su") != -1) {
                    log("Bypass ProcessBuilder " + cmd);
                    this.command.call(this, ["awesome_tool"]);
                    return this.start.call(this);
                }
                return this.start.call(this);
            };
            if (useProcessManager) {
                //@ts-ignore
                var ProcManExec = ProcessManager.exec.overload('[Ljava.lang.String;', '[Ljava.lang.String;', 'java.io.File', 'boolean');
                //@ts-ignore
                var ProcManExecVariant = ProcessManager.exec.overload('[Ljava.lang.String;', '[Ljava.lang.String;', 'java.lang.String', 'java.io.FileDescriptor', 'java.io.FileDescriptor', 'java.io.FileDescriptor', 'boolean');
                ProcManExec.implementation = function (cmd, env, workdir, redirectstderr) {
                    var fake_cmd = cmd;
                    for (var i = 0; i < cmd.length; i = i + 1) {
                        var tmp_cmd = cmd[i];
                        if (tmp_cmd.indexOf("getprop") != -1 || tmp_cmd == "mount" || tmp_cmd.indexOf("build.prop") != -1 || tmp_cmd == "id") {
                            var fake_cmd = ["grep"];
                            log("Bypass " + cmd + " command");
                        }
                        if (tmp_cmd == "su") {
                            var fake_cmd = ["awesome_tool"];
                            log("Bypass " + cmd + " command");
                        }
                    }
                    return ProcManExec.call(this, fake_cmd, env, workdir, redirectstderr);
                };
                ProcManExecVariant.implementation = function (cmd, env, directory, stdin, stdout, stderr, redirect) {
                    var fake_cmd = cmd;
                    for (var i = 0; i < cmd.length; i = i + 1) {
                        var tmp_cmd = cmd[i];
                        if (tmp_cmd.indexOf("getprop") != -1 || tmp_cmd == "mount" || tmp_cmd.indexOf("build.prop") != -1 || tmp_cmd == "id") {
                            var fake_cmd = ["grep"];
                            log("Bypass " + cmd + " command");
                        }
                        if (tmp_cmd == "su") {
                            var fake_cmd = ["awesome_tool"];
                            log("Bypass " + cmd + " command");
                        }
                    }
                    return ProcManExecVariant.call(this, fake_cmd, env, directory, stdin, stdout, stderr, redirect);
                };
            }
            if (useKeyInfo) {
                //@ts-ignore
                KeyInfo.isInsideSecureHardware.implementation = function () {
                    log("Bypass isInsideSecureHardware");
                    return true;
                };
            }
        });
    }
    native_based_bypasses() {
        // char *strstr(const char *str1, const char *str2);
        Interceptor.attach(this.addresses[this.module_name]["strstr"], {
            onEnter: function (args) {
                this.str_source = args[0];
                this.str_to_look_for = args[1];
                this.frida = Boolean(0);
                var haystack = this.str_source.readUtf8String();
                var needle = this.str_to_look_for.readUtf8String();
                if (haystack.indexOf("frida") != -1 || haystack.indexOf("xposed") != -1) {
                    this.frida = Boolean(1);
                }
            },
            onLeave: function (retval) {
                if (this.frida) {
                    //send("strstr(frida) was patched!! :) " + haystack);
                    retval.replace(ptr(0));
                }
                return retval;
            }
        });
        Interceptor.attach(this.addresses[this.module_name]["fopen"], {
            onEnter: function (args) {
                var path = args[0].readCString();
                //@ts-ignore
                var path_array = path.split("/");
                var executable = path_array[path_array.length - 1];
                var shouldFakeReturn = (this.RootBinaries.indexOf(executable) > -1);
                if (shouldFakeReturn) {
                    args[0].writeUtf8String("/notexists");
                    log("Bypass native fopen");
                }
            },
            onLeave: function (retval) {
            }
        });
        Interceptor.attach(this.addresses[this.module_name]["system"], {
            onEnter: function (args) {
                var cmd = args[0].readCString();
                log("SYSTEM CMD: " + cmd);
                //@ts-ignore
                if (cmd.indexOf("getprop") != -1 || cmd == "mount" || cmd.indexOf("build.prop") != -1 || cmd == "id") {
                    log("Bypass native system: " + cmd);
                    args[0].writeUtf8String("grep");
                }
                if (cmd == "su") {
                    log("Bypass native system: " + cmd);
                    args[0].writeUtf8String("awesome_tool");
                }
            },
            onLeave: function (retval) {
            }
        });
        /*
        
        TO IMPLEMENT:
        
        Exec Family
        
        int execl(const char *path, const char *arg0, ..., const char *argn, (char *)0);
        int execle(const char *path, const char *arg0, ..., const char *argn, (char *)0, char *const envp[]);
        int execlp(const char *file, const char *arg0, ..., const char *argn, (char *)0);
        int execlpe(const char *file, const char *arg0, ..., const char *argn, (char *)0, char *const envp[]);
        int execv(const char *path, char *const argv[]);
        int execve(const char *path, char *const argv[], char *const envp[]);
        int execvp(const char *file, char *const argv[]);
        int execvpe(const char *file, char *const argv[], char *const envp[]);
        
        */
    }
    execute_hooks() {
        this.java_based_bypasses();
        this.native_based_bypasses();
    }
}
export function anti_root_execute() {
    var anti_root = new AntiRoot();
    anti_root.execute_hooks();
}
✄
{"version":3,"file":"log.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/util/log.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,GAAG,CAAC,GAAW;IAC3B,IAAI,OAAO,GAA8B,EAAE,CAAA;IAC3C,OAAO,CAAC,aAAa,CAAC,GAAG,SAAS,CAAA;IAClC,OAAO,CAAC,SAAS,CAAC,GAAG,GAAG,CAAA;IACxB,IAAI,CAAC,OAAO,CAAC,CAAA;AACjB,CAAC;AAGD,MAAM,UAAU,MAAM,CAAC,GAAW;IAC9B,IAAI,OAAO,GAA8B,EAAE,CAAA;IAC3C,OAAO,CAAC,aAAa,CAAC,GAAG,aAAa,CAAA;IACtC,OAAO,CAAC,aAAa,CAAC,GAAG,GAAG,CAAA;IAC5B,IAAI,CAAC,OAAO,CAAC,CAAA;AACjB,CAAC"}
✄
export function log(str) {
    var message = {};
    message["contentType"] = "console";
    message["console"] = str;
    send(message);
}
export function devlog(str) {
    var message = {};
    message["contentType"] = "console_dev";
    message["console_dev"] = str;
    send(message);
}
✄
{"version":3,"file":"process_infos.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/util/process_infos.ts"],"names":[],"mappings":"AACA,MAAM,UAAU,wBAAwB;IAChC,OAAO,OAAO,CAAC,IAAI,CAAC;AAC5B,CAAC;AAGD,MAAM,UAAU,SAAS;IACrB,IAAG,IAAI,CAAC,SAAS,IAAI,OAAO,CAAC,QAAQ,IAAI,OAAO,EAAC;QAC7C,IAAG;YACC,IAAI,CAAC,cAAc,CAAA,CAAC,yDAAyD;YAC7E,OAAO,IAAI,CAAA;SACd;QAAA,OAAM,KAAK,EAAC;YACT,OAAO,KAAK,CAAA;SACf;KACJ;SAAI;QACD,OA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ACvC,OAAO,cAAc,CAAC;AAG9B,CAAC"}
✄
export function get_process_architecture() {
    return Process.arch;
}
export function isAndroid() {
    if (Java.available && Process.platform == "linux") {
        try {
            Java.androidVersion; // this will raise an error when we are not under Android
            return true;
        }
        catch (error) {
            return false;
        }
    }
    else {
        return false;
    }
}
export function isiOS() {
    if (get_process_architecture() === "arm64" && Process.platform == "darwin") {
        try {
            // check if iOS or MacOS (currently we handle MacOS with ARM Processor as an iOS device)
            return true;
        }
        catch (error) {
            return false;
        }
    }
    else {
        return false;
    }
}
export function isMacOS() {
    if (get_process_architecture() === "x64" && Process.platform == "darwin") {
        return true;
    }
    else {
        return false;
    }
}
export function isLinux() {
    if (Process.platform == "linux") {
        if (Java.available == false && Process.platform == "linux") {
            return true;
        }
        else {
            try {
                Java.androidVersion; // this will raise an error when we are not under Android
                return false;
            }
            catch (error) {
                return true;
            }
        }
    }
    else {
        return false;
    }
}
export function isWindows() {
    if (Process.platform == "windows") {
        return true;
    }
    else {
        return false;
    }
}
export function getAndroidVersion() {
    var version = "-1";
    Java.perform(function () {
        version = Java.androidVersion; // this will return a value like 12 for Android version 12
    });
    var casted_version = +version;
    return casted_version;
}
✄
{"version":3,"file":"gnutls_windows.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/windows/gnutls_windows.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,MAAM,OAAO,cAAe,SAAQ,MAAM;IAEtC,YAAmB,UAAiB,EAAS,cAAqB,EAAE,YAAqB;QACrF,KAAK,CAAC,UAAU,EAAC,cAAc,CAAC,CAAC;QADlB,eAAU,GAAV,UAAU,CAAO;QAAS,mBAAc,GAAd,cAAc,CAAO;IAElE,CAAC;IAGD,aAAa;QACT,IAAI,CAAC,2BAA2B,EAAE,CAAC;QACnC,IAAI,CAAC,4BAA4B,EAAE,CAAC;QAEpC,wCAAwC;IAC5C,CAAC;IAED,8BAA8B;QAC1B,qBAAqB;IACzB,CAAC;CAEJ;AAGD,MAAM,UAAU,cAAc,CAAC,UAAiB,EAAE,YAAqB;IACnE,IAAI,OAAO,GAAG,IAAI,cAAc,CAAC,UAAU,EAAC,cAAc,EAAE,YAAY,CAAC,CAAC;IAC1E,OAAO,CAAC,aAAa,EAAE,CAAC;IAExB,IAAI,YAAY,EAAE;QACd,MAAM,cAAc,GAAG,OAAO,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QACrD,wDAAwD;QACxD,IAAI,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;YACvC,MAAc,CAAC,cAAc,CAAC,UAAU,CAAC,GAAG,cAAc,CAAC;SAC/D;KACJ;AACL,CAAC"}
✄
import { GnuTLS } from "../ssl_lib/gnutls.js";
import { socket_library } from "./windows_agent.js";
export class GnuTLS_Windows extends GnuTLS {
    constructor(moduleName, socket_library, is_base_hook) {
        super(moduleName, socket_library);
        this.moduleName = moduleName;
        this.socket_library = socket_library;
    }
    execute_hooks() {
        this.install_plaintext_read_hook();
        this.install_plaintext_write_hook();
        //this.install_tls_keys_callback_hook();
    }
    install_tls_keys_callback_hook() {
        //Not implemented yet
    }
}
export function gnutls_execute(moduleName, is_base_hook) {
    var gnu_ssl = new GnuTLS_Windows(moduleName, socket_library, is_base_hook);
    gnu_ssl.execute_hooks();
    if (is_base_hook) {
        const init_addresses = gnu_ssl.addresses[moduleName];
        // ensure that we only add it to global when we are not 
        if (Object.keys(init_addresses).length > 0) {
            global.init_addresses[moduleName] = init_addresses;
        }
    }
}
✄
{"version":3,"file":"matrixssl_windows.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/windows/matrixssl_windows.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,MAAM,OAAO,kBAAmB,SAAQ,UAAU;IAE9C,YAAmB,UAAiB,EAAS,cAAqB,EAAE,YAAqB;QACrF,KAAK,CAAC,UAAU,EAAC,cAAc,CAAC,CAAC;QADlB,eAAU,GAAV,UAAU,CAAO;QAAS,mBAAc,GAAd,cAAc,CAAO;IAElE,CAAC;IAGD,aAAa;QACT,IAAI,CAAC,2BAA2B,EAAE,CAAC;QACnC,IAAI,CAAC,4BAA4B,EAAE,CAAC;QACpC,IAAI,CAAC,mBAAmB,EAAE,CAAC;QAE3B,wCAAwC;IAC5C,CAAC;IAED,8BAA8B;QAC1B,qBAAqB;IACzB,CAAC;CAEJ;AAGD,MAAM,UAAU,iBAAiB,CAAC,UAAiB,EAAE,YAAqB;IACtE,IAAI,UAAU,GAAG,IAAI,kBAAkB,CAAC,UAAU,EAAC,cAAc,EAAE,YAAY,CAAC,CAAC;IACjF,UAAU,CAAC,aAAa,EAAE,CAAC;IAE3B,IAAI,YAAY,EAAE;QACd,MAAM,cAAc,GAAG,UAAU,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QACxD,wDAAwD;QACxD,IAAI,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;YACvC,MAAc,CAAC,cAAc,CAAC,UAAU,CAAC,GAAG,cAAc,CAAC;SAC/D;KACJ;AACL,CAAC"}
✄
import { matrix_SSL } from "../ssl_lib/matrixssl.js";
import { socket_library } from "./windows_agent.js";
export class matrix_SSL_Windows extends matrix_SSL {
    constructor(moduleName, socket_library, is_base_hook) {
        super(moduleName, socket_library);
        this.moduleName = moduleName;
        this.socket_library = socket_library;
    }
    execute_hooks() {
        this.install_plaintext_read_hook();
        this.install_plaintext_write_hook();
        this.install_helper_hook();
        //this.install_tls_keys_callback_hook();
    }
    install_tls_keys_callback_hook() {
        //Not implemented yet
    }
}
export function matrixSSL_execute(moduleName, is_base_hook) {
    var matrix_ssl = new matrix_SSL_Windows(moduleName, socket_library, is_base_hook);
    matrix_ssl.execute_hooks();
    if (is_base_hook) {
        const init_addresses = matrix_ssl.addresses[moduleName];
        // ensure that we only add it to global when we are not 
        if (Object.keys(init_addresses).length > 0) {
            global.init_addresses[moduleName] = init_addresses;
        }
    }
}
✄
{"version":3,"file":"mbedTLS_windows.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/windows/mbedTLS_windows.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,MAAM,OAAO,gBAAiB,SAAQ,QAAQ;IAE1C,YAAmB,UAAiB,EAAS,cAAqB,EAAE,YAAqB;QACrF,KAAK,CAAC,UAAU,EAAC,cAAc,CAAC,CAAC;QADlB,eAAU,GAAV,UAAU,CAAO;QAAS,mBAAc,GAAd,cAAc,CAAO;IAElE,CAAC;IAED;;;;;;MAME;IACF,8BAA8B;QAC1B,8BAA8B;IAClC,CAAC;IAED,aAAa;QACT,IAAI,CAAC,2BAA2B,EAAE,CAAC;QACnC,IAAI,CAAC,4BAA4B,EAAE,CAAC;IACxC,CAAC;CAEJ;AAGD,MAAM,UAAU,eAAe,CAAC,UAAiB,EAAE,YAAqB;IACpE,IAAI,WAAW,GAAG,IAAI,gBAAgB,CAAC,UAAU,EAAC,cAAc,EAAE,YAAY,CAAC,CAAC;IAChF,WAAW,CAAC,aAAa,EAAE,CAAC;IAE5B,IAAI,YAAY,EAAE;QACd,MAAM,cAAc,GAAG,WAAW,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QACzD,wDAAwD;QACxD,IAAI,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;YACvC,MAAc,CAAC,cAAc,CAAC,UAAU,CAAC,GAAG,cAAc,CAAC;SAC/D;KACJ;AACL,CAAC"}
✄
import { mbed_TLS } from "../ssl_lib/mbedTLS.js";
import { socket_library } from "./windows_agent.js";
export class mbed_TLS_Windows extends mbed_TLS {
    constructor(moduleName, socket_library, is_base_hook) {
        super(moduleName, socket_library);
        this.moduleName = moduleName;
        this.socket_library = socket_library;
    }
    /*
    SSL_CTX_set_keylog_callback not exported by default on windows.

    We need to find a way to install the callback function for doing that

    Alternatives?:SSL_export_keying_material, SSL_SESSION_get_master_key
    */
    install_tls_keys_callback_hook() {
        // install hooking for windows
    }
    execute_hooks() {
        this.install_plaintext_read_hook();
        this.install_plaintext_write_hook();
    }
}
export function mbedTLS_execute(moduleName, is_base_hook) {
    var mbedTLS_ssl = new mbed_TLS_Windows(moduleName, socket_library, is_base_hook);
    mbedTLS_ssl.execute_hooks();
    if (is_base_hook) {
        const init_addresses = mbedTLS_ssl.addresses[moduleName];
        // ensure that we only add it to global when we are not 
        if (Object.keys(init_addresses).length > 0) {
            global.init_addresses[moduleName] = init_addresses;
        }
    }
}
✄
{"version":3,"file":"nss_windows.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/windows/nss_windows.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,GAAG,EAAE,MAAM,mBAAmB,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,MAAM,OAAO,WAAY,SAAQ,GAAG;IAEhC,YAAmB,UAAiB,EAAS,cAAqB,EAAE,YAAqB;QACrF,IAAI,sBAAsB,GAAqC,EAAE,CAAC;QAClE,sBAAsB,CAAC,IAAI,UAAU,GAAG,CAAC,GAAG,CAAC,UAAU,EAAE,SAAS,EAAE,0BAA0B,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,uBAAuB,CAAC,CAAA;QAC5J,mFAAmF;QACnF,sBAAsB,CAAC,WAAW,CAAC,GAAG,CAAC,cAAc,EAAE,kBAAkB,EAAE,uBAAuB,CAAC,CAAA;QAEnG,KAAK,CAAC,UAAU,EAAC,cAAc,EAAC,sBAAsB,CAAC,CAAC;QANzC,eAAU,GAAV,UAAU,CAAO;QAAS,mBAAc,GAAd,cAAc,CAAO;IAOlE,CAAC;IAED,8BAA8B;QAC1B,MAAM;IACV,CAAC;IAGD,aAAa;QACT,IAAI,CAAC,2BAA2B,EAAE,CAAC;QACnC,IAAI,CAAC,4BAA4B,EAAE,CAAC;QACpC,iEAAiE;IACrE,CAAC;CAEJ;AAGD,MAAM,UAAU,WAAW,CAAC,UAAiB,EAAE,YAAqB;IAChE,IAAI,OAAO,GAAG,IAAI,WAAW,CAAC,UAAU,EAAC,cAAc,EAAE,YAAY,CAAC,CAAC;IACvE,OAAO,CAAC,aAAa,EAAE,CAAC;IAExB,IAAI,YAAY,EAAE;QACd,MAAM,cAAc,GAAG,OAAO,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QACrD,wDAAwD;QACxD,IAAI,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;YACvC,MAAc,CAAC,cAAc,CAAC,UAAU,CAAC,GAAG,cAAc,CAAC;SAC/D;KACJ;AAEL,CAAC"}
✄
import { NSS } from "../ssl_lib/nss.js";
import { socket_library } from "./windows_agent.js";
export class NSS_Windows extends NSS {
    constructor(moduleName, socket_library, is_base_hook) {
        var library_method_mapping = {};
        library_method_mapping[`*${moduleName}*`] = ["PR_Write", "PR_Read", "PR_FileDesc2NativeHandle", "PR_GetPeerName", "PR_GetSockName", "PR_GetNameForIdentity"];
        // library_method_mapping[`*libnss*`] = ["PK11_ExtractKeyValue", "PK11_GetKeyData"]
        library_method_mapping["*ssl*.dll"] = ["SSL_ImportFD", "SSL_GetSessionID", "SSL_HandshakeCallback"];
        super(moduleName, socket_library, library_method_mapping);
        this.moduleName = moduleName;
        this.socket_library = socket_library;
    }
    install_tls_keys_callback_hook() {
        // TBD
    }
    execute_hooks() {
        this.install_plaintext_read_hook();
        this.install_plaintext_write_hook();
        // this.install_tls_keys_callback_hook(); needs to be implemented
    }
}
export function nss_execute(moduleName, is_base_hook) {
    var nss_ssl = new NSS_Windows(moduleName, socket_library, is_base_hook);
    nss_ssl.execute_hooks();
    if (is_base_hook) {
        const init_addresses = nss_ssl.addresses[moduleName];
        // ensure that we only add it to global when we are not 
        if (Object.keys(init_addresses).length > 0) {
            global.init_addresses[moduleName] = init_addresses;
        }
    }
}
✄
{"version":3,"file":"openssl_boringssl_windows.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/windows/openssl_boringssl_windows.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEpD,MAAM,OAAO,yBAA0B,SAAQ,iBAAiB;IAE5D,YAAmB,UAAiB,EAAS,cAAqB,EAAE,YAAqB;QACrF,IAAI,OAAO,GAAoC,EAAE,CAAC;QAClD,OAAO,CAAC,GAAG,UAAU,EAAE,CAAC,GAAG,CAAC,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,SAAS,CAAC,CAAA;QACtH,OAAO,CAAC,IAAI,cAAc,GAAG,CAAC,GAAG,CAAC,aAAa,EAAE,aAAa,EAAE,OAAO,EAAE,OAAO,CAAC,CAAA;QACjF,KAAK,CAAC,UAAU,EAAC,cAAc,EAAE,YAAY,EAAE,OAAO,CAAC,CAAC;QAJzC,eAAU,GAAV,UAAU,CAAO;QAAS,mBAAc,GAAd,cAAc,CAAO;IAKlE,CAAC;IAED;;;;;;MAME;IACF,8BAA8B;QAC1B,8BAA8B;IAClC,CAAC;IAED,aAAa;QACT,IAAI,CAAC,2BAA2B,EAAE,CAAC;QACnC,IAAI,CAAC,4BAA4B,EAAE,CAAC;IACxC,CAAC;CAEJ;AAGD,MAAM,UAAU,cAAc,CAAC,UAAiB,EAAE,YAAqB;IACnE,IAAI,UAAU,GAAG,IAAI,yBAAyB,CAAC,UAAU,EAAC,cAAc,EAAE,YAAY,CAAC,CAAC;IACxF,UAAU,CAAC,aAAa,EAAE,CAAC;IAE3B,IAAI,YAAY,EAAE;QACd,MAAM,cAAc,GAAG,UAAU,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QACxD,wDAAwD;QACxD,IAAI,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;YACvC,MAAc,CAAC,cAAc,CAAC,UAAU,CAAC,GAAG,cAAc,CAAC;SAC/D;KACJ;AACL,CAAC"}
✄
import { OpenSSL_BoringSSL } from "../ssl_lib/openssl_boringssl.js";
import { socket_library } from "./windows_agent.js";
export class OpenSSL_BoringSSL_Windows extends OpenSSL_BoringSSL {
    constructor(moduleName, socket_library, is_base_hook) {
        let mapping = {};
        mapping[`${moduleName}`] = ["SSL_read", "SSL_write", "SSL_get_fd", "SSL_get_session", "SSL_SESSION_get_id", "SSL_new"];
        mapping[`*${socket_library}*`] = ["getpeername", "getsockname", "ntohs", "ntohl"];
        super(moduleName, socket_library, is_base_hook, mapping);
        this.moduleName = moduleName;
        this.socket_library = socket_library;
    }
    /*
    SSL_CTX_set_keylog_callback not exported by default on windows.

    We need to find a way to install the callback function for doing that

    Alternatives?:SSL_export_keying_material, SSL_SESSION_get_master_key
    */
    install_tls_keys_callback_hook() {
        // install hooking for windows
    }
    execute_hooks() {
        this.install_plaintext_read_hook();
        this.install_plaintext_write_hook();
    }
}
export function boring_execute(moduleName, is_base_hook) {
    var boring_ssl = new OpenSSL_BoringSSL_Windows(moduleName, socket_library, is_base_hook);
    boring_ssl.execute_hooks();
    if (is_base_hook) {
        const init_addresses = boring_ssl.addresses[moduleName];
        // ensure that we only add it to global when we are not 
        if (Object.keys(init_addresses).length > 0) {
            global.init_addresses[moduleName] = init_addresses;
        }
    }
}
✄
{"version":3,"file":"sspi.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/windows/s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AAO,CAAC,GAAG,CAAC,+BAAuB,CAAC;gBAC/F,CAAC;aACJ,CAAC,CAAC;IAEX,CAAC;IAED,aAAa;QACT,IAAI,CAAC,2BAA2B,EAAE,CAAC;QACnC,IAAI,CAAC,4BAA4B,EAAE,CAAC;QACpC,IAAG,YAAY,EAAC;YACZ,IAAI,CAAC,qBAAqB,EAAE,CAAC;SAChC;IACL,CAAC;CAEJ;AAGD,MAAM,UAAU,YAAY,CAAC,UAAiB,EAAE,YAAqB;IACjE,IAAI,QAAQ,GAAG,IAAI,YAAY,CAAC,UAAU,EAAC,cAAc,EAAE,YAAY,CAAC,CAAC;IACzE,QAAQ,CAAC,aAAa,EAAE,CAAC;IAEzB,IAAI,YAAY,EAAE;QACd,MAAM,cAAc,GAAG,QAAQ,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QACtD,wDAAwD;QACxD,IAAI,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,CAAC,MAAM,GAAG,CAAC,EAAE;YACvC,MAAc,CAAC,cAAc,CAAC,UAAU,CAAC,GAAG,cAAc,CAAC;SAC/D;KACJ;AACL,CAAC"}
✄
import { readAddresses, getBaseAddress } from "../shared/shared_functions.js";
import { socket_library } from "./windows_agent.js";
import { devlog, log } from "../util/log.js";
import { experimental, offsets } from "../ssl_log.js";
/*
ToDo:
- Write Test Client for ground truth and test everything
- Obtain information from the running process to get the socket information instead of using default values
*/
var keylog = (key, tlsVersion) => {
    devlog(`Exporting TLS 1.${tlsVersion} handshake keying material`);
    var message = {};
    message["contentType"] = "keylog";
    message["keylog"] = key;
    send(message);
};
// This library is only existend under Windows therefore there is no Superclass
export class SSPI_Windows {
    constructor(moduleName, socket_library, is_base_hook) {
        this.moduleName = moduleName;
        this.socket_library = socket_library;
        // global variables
        this.library_method_mapping = {};
        this.library_method_mapping[`*${moduleName}*`] = ["DecryptMessage", "EncryptMessage"];
        if (experimental) {
            // ncrypt is used for the TLS keys
            log(`ncrypt.dll was loaded & will be hooked on Windows!`);
            this.library_method_mapping["*ncrypt*.dll"] = ["SslHashHandshake", "SslGenerateMasterKey", "SslImportMasterKey", "SslGenerateSessionKeys", "SslExpandExporterMasterKey", "SslExpandTrafficKeys"];
        }
        this.library_method_mapping[`*${socket_library}*`] = ["getpeername", "getsockname", "ntohs", "ntohl"];
        this.addresses = readAddresses(moduleName, this.library_method_mapping);
        this.module_name = moduleName;
        // @ts-ignore
        if (offsets != "{OFFSETS}" && offsets.sspi != null) {
            if (offsets.sockets != null) {
                const socketBaseAddress = getBaseAddress(socket_library);
                for (const method of Object.keys(offsets.sockets)) {
                    //@ts-ignore
                    this.addresses[this.module_name][`${method}`] = offsets.sockets[`${method}`].absolute || socketBaseAddress == null ? ptr(offsets.sockets[`${method}`].address) : socketBaseAddress.add(ptr(offsets.sockets[`${method}`].address));
                }
            }
            const libraryBaseAddress = getBaseAddress(moduleName);
            if (libraryBaseAddress == null) {
                log("Unable to find library base address! Given address values will be interpreted as absolute ones!");
            }
            for (const method of Object.keys(offsets.sspi)) {
                //@ts-ignore
                this.addresses[this.module_name][`${method}`] = offsets.sspi[`${method}`].absolute || libraryBaseAddress == null ? ptr(offsets.sspi[`${method}`].address) : libraryBaseAddress.add(ptr(offsets.sspi[`${method}`].address));
            }
        }
    }
    install_plaintext_read_hook() {
        Interceptor.attach(this.addresses[this.module_name]["DecryptMessage"], {
            onEnter: function (args) {
                this.pMessage = args[1];
            },
            onLeave: function () {
                this.cBuffers = this.pMessage.add(4).readULong(); //unsigned long cBuffers (Count of buffers)
                this.pBuffers = this.pMessage.add(8).readPointer(); //PSecBuffer  pBuffers (Pointer to array of secBuffers)
                //https://docs.microsoft.com/en-us/windows/win32/api/sspi/ns-sspi-secbuffer
                //One SecBuffer got 16 Bytes (unsigned long + unsigned long + pointer (64 Bit))
                //--> Bytes to read: cBuffers + 16 Bytes
                this.secBuffers = []; //Addresses of all secBuffers
                for (let i = 0; i < this.cBuffers; i++) {
                    var secBuffer = this.pBuffers.add(i * 16);
                    this.secBuffers.push(secBuffer);
                }
                for (let i = 0; i < this.secBuffers.length; i++) {
                    var size = this.secBuffers[i].add(0).readULong();
                    var type = this.secBuffers[i].add(4).readULong();
                    var bufferPointer = this.secBuffers[i].add(8).readPointer();
                    if (type == 1) {
                        //TODO: Obtain information from the running process to get the socket information
                        var bytes = bufferPointer.readByteArray(size);
                        var message = {};
                        message["ss_family"] = "AF_INET";
                        message["src_port"] = 444;
                        message["src_addr"] = 222;
                        message["dst_port"] = 443;
                        message["dst_addr"] = 222;
                        message["function"] = "DecryptMessage";
                        message["contentType"] = "datalog";
                        message["ssl_session_id"] = 10;
                        send(message, bytes);
                    }
                }
            }
        });
    }
    install_plaintext_write_hook() {
        Interceptor.attach(this.addresses[this.module_name]["EncryptMessage"], {
            onEnter: function (args) {
                this.pMessage = args[2]; //PSecBufferDesc pMessage (https://docs.microsoft.com/en-us/windows/win32/api/sspi/ns-sspi-secbufferdesc)
                this.cBuffers = this.pMessage.add(4).readULong(); //unsigned long cBuffers (Count of buffers)
                this.pBuffers = this.pMessage.add(8).readPointer(); //PSecBuffer  pBuffers (Pointer to array of secBuffers)
                //https://docs.microsoft.com/en-us/windows/win32/api/sspi/ns-sspi-secbuffer
                //One SecBuffer got 16 Bytes (unsigned long + unsigned long + pointer (64 Bit))
                //--> Bytes to read: cBuffers + 16 Bytes
                this.secBuffers = []; //Addresses of all secBuffers
                for (let i = 0; i < this.cBuffers; i++) {
                    var secBuffer = this.pBuffers.add(i * 16);
                    this.secBuffers.push(secBuffer);
                }
                for (let i = 0; i < this.secBuffers.length; i++) {
                    var size = this.secBuffers[i].add(0).readULong();
                    var type = this.secBuffers[i].add(4).readULong();
                    var bufferPointer = this.secBuffers[i].add(8).readPointer();
                    if (type == 1) {
                        //TODO: Obtain information from the running process
                        var bytes = bufferPointer.readByteArray(size);
                        var message = {};
                        message["ss_family"] = "AF_INET";
                        message["src_port"] = 443;
                        message["src_addr"] = 222;
                        message["dst_port"] = 444;
                        message["dst_addr"] = 222;
                        message["function"] = "EncryptMessage";
                        message["contentType"] = "datalog";
                        message["ssl_session_id"] = 10;
                        send(message, bytes);
                    }
                }
            }
        });
    }
    install_tls_keys_hook() {
        /* Most of the following code fragments were copied from
         * https://github.com/ngo/win-frida-scripts/tree/master/lsasslkeylog-easy
        */
        var client_randoms = {};
        var buf2hex = function (buffer) {
            return Array.prototype.map.call(new Uint8Array(buffer), function (x) { return ('00' + x.toString(16)).slice(-2); }).join('');
        };
        /* ----- TLS1.2-specific ----- */
        var parse_h_master_key = function (pMasterKey) {
            var NcryptSslKey_ptr = pMasterKey; // NcryptSslKey
            var ssl5_ptr = NcryptSslKey_ptr.add(0x10).readPointer();
            var master_key = ssl5_ptr.add(28).readByteArray(48);
            return buf2hex(master_key);
        };
        var parse_parameter_list = function (pParameterList, calling_func) {
            /*
                typedef struct _NCryptBufferDesc {
                    ULONG         ulVersion;
                    ULONG         cBuffers;
                    PNCryptBuffer pBuffers;
                } NCryptBufferDesc, *PNCryptBufferDesc;
                typedef struct _NCryptBuffer {
                    ULONG cbBuffer;
                    ULONG BufferType;
                    PVOID pvBuffer;
                } NCryptBuffer, *PNCryptBuffer;
             */
            var buffer_count = pParameterList.add(4).readU32();
            var buffers = pParameterList.add(8).readPointer();
            for (var i = 0; i < buffer_count; i++) {
                var buf = buffers.add(16 * i);
                var buf_size = buf.readU32();
                var buf_type = buf.add(4).readU32();
                var buf_buf = buf.add(8).readPointer().readByteArray(buf_size);
                // For buf_type values see NCRYPTBUFFER_SSL_* constans in ncrypt.h
                if (buf_type == 20) { // NCRYPTBUFFER_SSL_CLIENT_RANDOM
                    devlog("Got client random from " + calling_func + "'s pParameterList: " + buf2hex(buf_buf));
                    return buf2hex(buf_buf);
                }
                //console.log("buf_type " + buf_type);
            }
            return null;
        };
        if (this.addresses[this.module_name]["SslHashHandshake"] != null)
            Interceptor.attach(this.addresses[this.module_name]["SslHashHandshake"], {
                onEnter: function (args) {
                    // https://docs.microsoft.com/en-us/windows/win32/seccng/sslhashhandshake
                    var buf = ptr(args[2]);
                    var len = args[3].toInt32();
                    var mem = buf.readByteArray(len);
                    var msg_type = buf.readU8();
                    var version = buf.add(4).readU16();
                    if (msg_type == 1 && version == 0x0303) {
                        // If we have client random, save it tied to current thread
                        var crandom = buf2hex(buf.add(6).readByteArray(32));
                        devlog("Got client random from SslHashHandshake: " + crandom);
                        client_randoms[this.threadId] = crandom;
                    }
                },
                onLeave: function (retval) {
                }
            });
        if (this.addresses[this.module_name]["SslGenerateMasterKey"] != null)
            Interceptor.attach(this.addresses[this.module_name]["SslGenerateMasterKey"], {
                onEnter: function (args) {
                    // https://docs.microsoft.com/en-us/windows/win32/seccng/sslgeneratemasterkey
                    this.phMasterKey = ptr(args[3]);
                    this.hSslProvider = ptr(args[0]);
                    this.pParameterList = ptr(args[6]);
                    this.client_random = parse_parameter_list(this.pParameterList, 'SslGenerateMasterKey') || client_randoms[this.threadId] || "???";
                },
                onLeave: function (retval) {
                    var master_key = parse_h_master_key(this.phMasterKey.readPointer());
                    devlog("Got masterkey from SslGenerateMasterKey");
                    keylog("CLIENT_RANDOM " + this.client_random + " " + master_key, 2 /* TLSVersion.ONE_TWO */);
                }
            });
        if (this.addresses[this.module_name]["SslImportMasterKey"] != null)
            Interceptor.attach(this.addresses[this.module_name]["SslImportMasterKey"], {
                onEnter: function (args) {
                    // https://docs.microsoft.com/en-us/windows/win32/seccng/sslimportmasterkey
                    this.phMasterKey = ptr(args[2]);
                    this.pParameterList = ptr(args[5]);
                    // Get client random from the pParameterList, and if that fails - from the value saved by SslHashHandshake handler
                    this.client_random = parse_parameter_list(this.pParameterList, 'SslImportMasterKey') || client_randoms[this.threadId] || "???";
                },
                onLeave: function (retval) {
                    var master_key = parse_h_master_key(this.phMasterKey.readPointer());
                    devlog("[*] Got masterkey from SslImportMasterKey");
                    keylog("CLIENT_RANDOM " + this.client_random + " " + master_key, 2 /* TLSVersion.ONE_TWO */);
                }
            });
        if (this.addresses[this.module_name]["SslGenerateSessionKeys"] != null)
            Interceptor.attach(this.addresses[this.module_name]["SslGenerateSessionKeys"], {
                onEnter: function (args) {
                    // https://docs.microsoft.com/en-us/windows/win32/seccng/sslgeneratesessionkeys
                    this.hMasterKey = ptr(args[1]);
                    this.hSslProvider = ptr(args[0]);
                    this.pParameterList = ptr(args[4]);
                    this.client_random = parse_parameter_list(this.pParameterList, 'SslGenerateSessionKeys') || client_randoms[this.threadId] || "???";
                    var master_key = parse_h_master_key(this.hMasterKey);
                    devlog("Got masterkey from SslGenerateSessionKeys");
                    keylog("CLIENT_RANDOM " + this.client_random + " " + master_key, 2 /* TLSVersion.ONE_TWO */);
                },
                onLeave: function (retval) {
                }
            });
        /* ----- TLS1.3-specific ----- */
        var stages = {};
        var get_secret_from_BDDD = function (struct_BDDD) {
            var struct_3lss = struct_BDDD.add(0x10).readPointer();
            var struct_RUUU = struct_3lss.add(0x20).readPointer();
            var struct_YKSM = struct_RUUU.add(0x10).readPointer();
            var secret_ptr = struct_YKSM.add(0x18).readPointer();
            var size = struct_YKSM.add(0x10).readU32();
            return secret_ptr.readByteArray(size);
        };
        if (this.addresses[this.module_name]["SslExpandTrafficKeys"] != null)
            Interceptor.attach(this.addresses[this.module_name]["SslExpandTrafficKeys"], {
                onEnter: function (args) {
                    this.retkey1 = ptr(args[3]);
                    this.retkey2 = ptr(args[4]);
                    this.client_random = client_randoms[this.threadId] || "???";
                    if (stages[this.threadId]) {
                        stages[this.threadId] = null;
                        this.suffix = "TRAFFIC_SECRET_0";
                    }
                    else {
                        stages[this.threadId] = "handshake";
                        this.suffix = "HANDSHAKE_TRAFFIC_SECRET";
                    }
                },
                onLeave: function (retval) {
                    var key1 = get_secret_from_BDDD(this.retkey1.readPointer());
                    var key2 = get_secret_from_BDDD(this.retkey2.readPointer());
                    keylog("CLIENT_" + this.suffix + " " + this.client_random + " " + buf2hex(key1), 3 /* TLSVersion.ONE_THREE */);
                    keylog("SERVER_" + this.suffix + " " + this.client_random + " " + buf2hex(key2), 3 /* TLSVersion.ONE_THREE */);
                }
            });
        if (this.addresses[this.module_name]["SslExpandExporterMasterKey"] != null)
            Interceptor.attach(this.addresses[this.module_name]["SslExpandExporterMasterKey"], {
                onEnter: function (args) {
                    this.retkey = ptr(args[3]);
                    this.client_random = client_randoms[this.threadId] || "???";
                },
                onLeave: function (retval) {
                    var key = this.retkey.readPointer().add(0x10).readPointer().add(0x20).readPointer().add(0x10).readPointer().add(0x18).readPointer().readByteArray(48);
                    keylog("EXPORTER_SECRET " + this.client_random + " " + buf2hex(key), 3 /* TLSVersion.ONE_THREE */);
                }
            });
    }
    execute_hooks() {
        this.install_plaintext_read_hook();
        this.install_plaintext_write_hook();
        if (experimental) {
            this.install_tls_keys_hook();
        }
    }
}
export function sspi_execute(moduleName, is_base_hook) {
    var sspi_ssl = new SSPI_Windows(moduleName, socket_library, is_base_hook);
    sspi_ssl.execute_hooks();
    if (is_base_hook) {
        const init_addresses = sspi_ssl.addresses[moduleName];
        // ensure that we only add it to global when we are not 
        if (Object.keys(init_addresses).length > 0) {
            global.init_addresses[moduleName] = init_addresses;
        }
    }
}
✄
{"version":3,"file":"windows_agent.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 fritap issues/friTap/","sources":["agent/windows/windows_agent.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAqB,MAAM,gCAAgC,CAAC;AAC3F,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AAC1G,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,gCAAgC,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AA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oC,CAAC,CAAA;KACpD;IAAC,OAAO,KAAK,EAAE;QACZ,MAAM,CAAC,gBAAgB,GAAG,KAAK,CAAC,CAAA;QAChC,GAAG,CAAC,wCAAwC,CAAC,CAAA;KAChD;AACL,CAAC;AAED,SAAS,qBAAqB,CAAC,sBAA0E,EAAE,YAAqB;IAC5H,kBAAkB,CAAC,cAAc,EAAE,sBAAsB,EAAC,WAAW,EAAC,SAAS,EAAE,YAAY,CAAC,CAAA;AAClG,CAAC;AAED,MAAM,UAAU,0BAA0B;IACtC,sBAAsB,CAAC,cAAc,CAAC,GAAG;QACrC,CAAC,yCAAyC,EAAE,qBAAqB,CAAC,cAAc,CAAC,CAAC;QAClF,CAAC,8BAA8B,EAAE,qBAAqB,CAAC,eAAe,CAAC,CAAC;QACxE,CAAC,uCAAuC,EAAE,qBAAqB,CAAC,cAAc,CAAC,CAAC;QAChF,CAAC,yBAAyB,EAAE,qBAAqB,CAAC,WAAW,CAAC,CAAC;QAC/D,CAAC,iCAAiC,EAAE,qBAAqB,CAAC,YAAY,CAAC,CAAC;QACxE,CAAC,cAAc,EAAE,qBAAqB,CAAC,eAAe,CAAC,CAAC;QACxD,CAAC,iBAAiB,EAAE,qBAAqB,CAAC,iBAAiB,CAAC,CAAC;KAAC,CAAA;IAElE,qBAAqB,CAAC,sBAAsB,EAAE,IAAI,CAAC,CAAC;IACpD,2BAA2B,CAAC,sBAAsB,EAAE,KAAK,CAAC,CAAC;AAC/D,CAAC"}
✄
import { module_library_mapping } from "../shared/shared_structures.js";
import { log, devlog } from "../util/log.js";
import { getModuleNames, ssl_library_loader, invokeHookingFunction } from "../shared/shared_functions.js";
import { sspi_execute } from "./sspi.js";
import { boring_execute } from "./openssl_boringssl_windows.js";
import { gnutls_execute } from "./gnutls_windows.js";
import { mbedTLS_execute } from "./mbedTLS_windows.js";
import { nss_execute } from "./nss_windows.js";
import { wolfssl_execute } from "./wolfssl_windows.js";
import { matrixSSL_execute } from "./matrixssl_windows.js";
var plattform_name = "windows";
var moduleNames = getModuleNames();
export const socket_library = "WS2_32.dll";
function hook_Windows_Dynamic_Loader(module_library_mapping, is_base_hook) {
    try {
        const resolver = new ApiResolver('module');
        var loadLibraryExW = resolver.enumerateMatches("exports:KERNELBASE.dll!*LoadLibraryExW");
        if (loadLibraryExW.length == 0)
            return console.log("[-] Missing windows dynamic loader!");
        Interceptor.attach(loadLibraryExW[0].address, {
            onLeave(retval) {
                let map = new ModuleMap();
                let moduleName = map.findName(retval);
                if (moduleName === null)
                    return;
                for (let map of module_library_mapping[plattform_name]) {
                    let regex = new RegExp(map[0]);
                    let func = map[1];
                    if (regex.test(moduleName)) {
                        log(`${moduleName} was loaded & will be hooked on Windows!`);
                        func(moduleName, is_base_hook);
                    }
                }
            }
        });
        console.log("[*] Windows dynamic loader hooked.");
    }
    catch (error) {
        devlog("Loader error: " + error);
        log("No dynamic loader present for hooking.");
    }
}
function hook_Windows_SSL_Libs(module_library_mapping, is_base_hook) {
    ssl_library_loader(plattform_name, module_library_mapping, moduleNames, "Windows", is_base_hook);
}
export function load_windows_hooking_agent() {
    module_library_mapping[plattform_name] = [
        [/^(libssl|LIBSSL)-[0-9]+(_[0-9]+)?\.dll$/, invokeHookingFunction(boring_execute)],
        [/^.*(wolfssl|WOLFSSL).*\.dll$/, invokeHookingFunction(wolfssl_execute)],
        [/^.*(libgnutls|LIBGNUTLS)-[0-9]+\.dll$/, invokeHookingFunction(gnutls_execute)],
        [/^(nspr|NSPR)[0-9]*\.dll/, invokeHookingFunction(nss_execute)],
        [/(sspicli|SSPICLI|SspiCli)\.dll$/, invokeHookingFunction(sspi_execute)],
        [/mbedTLS\.dll/, invokeHookingFunction(mbedTLS_execute)],
        ["/matrixSSL\.dll", invokeHookingFunction(matrixSSL_execute)]
    ];
    hook_Windows_SSL_Libs(module_library_mapping, true);
    hook_Windows_Dynamic_Loader(module_library_mapping, false);
}
✄
{"version":3,"file":"wolfssl_windows.js","sourceRoot":"/Users/danielbaier/research/projects/github/issues/2024 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,CAAC,MAAM,GAAG,CAAC,EAAE;YACvC,MAAc,CAAC,cAAc,CAAC,UAAU,CAAC,GAAG,cAAc,CAAC;SAC/D;KACJ;AACL,CAAC"}
✄
import { WolfSSL } from "../ssl_lib/wolfssl.js";
import { socket_library } from "./windows_agent.js";
import { log } from "../util/log.js";
export class WolfSSL_Windows extends WolfSSL {
    constructor(moduleName, socket_library, is_base_hook) {
        let mapping = {};
        mapping[`${moduleName}`] = ["wolfSSL_read", "wolfSSL_write", "wolfSSL_get_fd", "wolfSSL_get_session", "wolfSSL_connect", "wolfSSL_KeepArrays"];
        mapping[`*${socket_library}*`] = ["getpeername", "getsockname", "ntohs", "ntohl"];
        super(moduleName, socket_library, mapping);
        this.moduleName = moduleName;
        this.socket_library = socket_library;
    }
    install_tls_keys_callback_hook() {
        log("Key extraction currently not implemented for windows!");
    }
    execute_hooks() {
        this.install_plaintext_read_hook();
        this.install_plaintext_write_hook();
        //this.install_tls_keys_callback_hook(); currently not implemented
    }
}
export function wolfssl_execute(moduleName, is_base_hook) {
    var wolf_ssl = new WolfSSL_Windows(moduleName, socket_library, is_base_hook);
    wolf_ssl.execute_hooks();
    if (is_base_hook) {
        const init_addresses = wolf_ssl.addresses[moduleName];
        // ensure that we only add it to global when we are not 
        if (Object.keys(init_addresses).length > 0) {
            global.init_addresses[moduleName] = init_addresses;
        }
    }
}