Skip to content

Commit

Permalink
better test to see whether the so got injected
Browse files Browse the repository at this point in the history
  • Loading branch information
gaffe23 committed Jun 2, 2015
1 parent 6496496 commit 92593ed
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
12 changes: 9 additions & 3 deletions inject-arm.c
Expand Up @@ -323,9 +323,15 @@ int main(int argc, char** argv)
return 1;
}

// if __libc_dlopen_mode() returned a nonzero value, then our library
// was successfully injected.
printf("library \"%s\" successfully injected\n", libname);
// now check /proc/pid/maps to see whether injection was successful.
if(checkloaded(target, libname))
{
printf("\"%s\" successfully injected\n", libname);
}
else
{
fprintf(stderr, "could not inject \"%s\"\n", libname);
}

// as a courtesy, free the buffer that we allocated inside the target
// process. we don't really care whether this succeeds, so don't
Expand Down
42 changes: 42 additions & 0 deletions utils.c
Expand Up @@ -174,6 +174,48 @@ long getlibcaddr(pid_t pid)
return addr;
}

/*
* checkloaded()
*
* Given a process ID and the name of a shared library, check whether that
* process has loaded the shared library by reading entries in its
* /proc/[pid]/maps file.
*
* args:
* - pid_t pid: the pid of the process to check
* - char* libname: the library to search /proc/[pid]/maps for
*
* returns:
* - an int indicating whether or not the library has been loaded into the
* process (1 = yes, 0 = no)
*
*/

int checkloaded(pid_t pid, char* libname)
{
FILE *fp;
char filename[30];
char line[850];
long addr;
char perms[5];
char* modulePath;
sprintf(filename, "/proc/%d/maps", pid);
fp = fopen(filename, "r");
if(fp == NULL)
exit(1);
while(fgets(line, 850, fp) != NULL)
{
sscanf(line, "%lx-%*lx %*s %*s %*s %*d", &addr);
if(strstr(line, libname) != NULL)
{
fclose(fp);
return 1;
}
}
fclose(fp);
return 0;
}

/*
* getFunctionAddress()
*
Expand Down
1 change: 1 addition & 0 deletions utils.h
Expand Up @@ -4,6 +4,7 @@
pid_t findProcessByName(char* processName);
long freespaceaddr(pid_t pid);
long getlibcaddr(pid_t pid);
int checkloaded(pid_t pid, char* libname);
long getFunctionAddress(char* funcName);
unsigned char* findRet(void* endAddr);
void usage(char* name);

0 comments on commit 92593ed

Please sign in to comment.