aboutsummaryrefslogtreecommitdiff
path: root/src/hook/hook.c
blob: b677a7917976eb7f56f22d22217e44afb654f078 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <stdio.h>
#include <sys/syscall.h>
#include <sys/mman.h>
#include <string.h>

#include "hook.h"
#include "inject.h"
#include "memory.h"
#include "module.h"

#include "payloads/libSysLoadLibrary_so.h"

// defined in tvn:proc.c
extern pid_t getPid(const char*);

static void writeToDisk(const char* path, const char* content, const size_t size)
{
    FILE* fd = fopen(path, "wb");
    fwrite(content, sizeof(*content), size, fd);
    fclose(fd);
}

int fix_SysLoadLibary()
{
    pid_t pid = getPid("loop_forever");
    printf("%i\n", pid);
    if (pid != -1)
    {
        char* path = "/tmp/SysLoadLibrary.so";

        fprintf(stderr, "[~] writing library to disk\n");
        writeToDisk(path, libSysLoadLibrary_so, libSysLoadLibrary_so_size);

        //inject_syscall(pid, 1, (void*)21, NULL, NULL, NULL, NULL, NULL); 

        fprintf(stderr, "[~] loading library into process\n");
        int ret = load_library(pid, path);  
        if (!ret)
            fprintf(stderr, "[*] Success\n");
        else if (ret == 1)
            fprintf(stderr, "[!] library already loaded\n");
        else
            fprintf(stderr, "[!] could not load libary\n");
    }
    return 0;
}