Skip to content

Commit 38b124b

Browse files
dev: add a hook to curl to bypass certificate pinning
1 parent df0583d commit 38b124b

4 files changed

Lines changed: 37 additions & 0 deletions

File tree

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "subhook"]
2+
path = subhook
3+
url = https://github.com/savushkin-r-d/subhook

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,15 @@ find_library(ANDROIDAPPMUSIC_LIB androidappmusic PATHS ${CMAKE_SOURCE_DIR}/rootf
3535
find_library(STORESERVICESCORE_LIB storeservicescore PATHS ${CMAKE_SOURCE_DIR}/rootfs/system/lib64)
3636
find_library(MEDIAPLATFORM_LIB mediaplatform PATHS ${CMAKE_SOURCE_DIR}/rootfs/system/lib64)
3737
find_library(CXX_SHARED_LIB c++_shared PATHS ${CMAKE_SOURCE_DIR}/rootfs/system/lib64)
38+
find_library(CURL_SHARED_LIB curl PATHS ${CMAKE_SOURCE_DIR}/rootfs/system/lib64)
3839

3940
# Link libraries
4041
target_link_libraries(main
4142
${CXX_SHARED_LIB}
4243
${ANDROIDAPPMUSIC_LIB}
4344
${STORESERVICESCORE_LIB}
4445
${MEDIAPLATFORM_LIB}
46+
${CURL_SHARED_LIB}
4547
)
4648

4749
link_directories(${CMAKE_SOURCE_DIR}/rootfs/system/lib64)

import.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ static inline const char *std_string_data(union std_string *str) {
5757
return str->data;
5858
}
5959

60+
extern void curl_easy_setopt(void *, int32_t, long);
61+
6062
extern void _ZN20androidstoreservices30SVSubscriptionStatusMgrFactory6createEv(struct shared_ptr *);
6163
extern void
6264
_ZN20androidstoreservices27SVSubscriptionStatusMgrImpl33checkSubscriptionStatusFromSourceERKNSt6__ndk110shared_ptrIN17storeservicescore14RequestContextEEERKNS_23SVSubscriptionStatusMgr26SVSubscriptionStatusSourceE(

main.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,38 @@
1616
#include "cmdline.h"
1717
#ifndef MyRelease
1818
#include "subhook/subhook.c"
19+
#include "subhook/subhook.h"
1920
#endif
2021

2122
static struct shared_ptr apInf;
2223
static uint8_t leaseMgr[16];
2324
struct gengetopt_args_info args_info;
2425
char *amUsername, *amPassword;
2526

27+
#ifndef MyRelease
28+
int32_t CURLOPT_SSL_VERIFYPEER = 64;
29+
int32_t CURLOPT_SSL_VERIFYHOST = 81;
30+
int32_t CURLOPT_PINNEDPUBLICKEY = 10230;
31+
32+
int32_t CURLOPT_CUSTOMREQUEST = 10036;
33+
int32_t CURLOPT_URL = 10002;
34+
int32_t CURLOPT_POSTFIELDS = 10015;
35+
36+
subhook_t curl_hook;
37+
38+
void curl_easy_setopt_hook(void *curl, int32_t option, long param) {
39+
subhook_remove(curl_hook);
40+
41+
if (option == CURLOPT_SSL_VERIFYPEER || option == CURLOPT_SSL_VERIFYHOST || option == CURLOPT_PINNEDPUBLICKEY) {
42+
curl_easy_setopt(curl, option, 0);
43+
printf("[+] hooked curl_easy_setopt %d\n", option);
44+
} else {
45+
curl_easy_setopt(curl, option, param);
46+
}
47+
subhook_install(curl_hook);
48+
}
49+
#endif
50+
2651
int file_exists(char *filename) {
2752
struct stat buffer;
2853
return (stat (filename, &buffer) == 0);
@@ -623,6 +648,11 @@ void write_storefront_id(struct shared_ptr reqCtx) {
623648
int main(int argc, char *argv[]) {
624649
cmdline_parser(argc, argv, &args_info);
625650

651+
#ifndef MyRelease
652+
curl_hook = subhook_new(curl_easy_setopt, curl_easy_setopt_hook, SUBHOOK_64BIT_OFFSET);
653+
subhook_install(curl_hook);
654+
#endif
655+
626656
init();
627657
const struct shared_ptr ctx = init_ctx();
628658
if (args_info.login_given) {

0 commit comments

Comments
 (0)