I wasn't sure if I should post this or not, since I know that DIC doesn't like 'security-based' questions, but I figured I would try my luck anyway, as I am completely stuck. For my security assignment, we were given a program with some flaws in it, and we are required to find 3 flaws that we can exploit to obtain root access to the system. I have managed to find two: a format string vulnerability and a buffer overflow. For the third one, I believe that I may have found something since the program crashes (when it shouldn't), but I am not incredibly familiar with some of the linux functions in this code snippet, so I wanted some help. The function where the segmentation fault happens is:
//Update entry in /etc/shadow
static
void update_spent(char * crypt) {
FILE * old, * new;
struct spwd * spw, spw_copy;
char * username;
link("/etc/shadow", "/etc/shadow~");
unlink("/etc/shadow");
lckpwdf();
old = fopen("/etc/shadow~", "r");
new = fopen("/etc/shadow", "w");
printf("opening shadow files\n");
username = get_username();
spw = fgetspent(old);
while (spw != NULL) {
if (strcmp(username, spw->sp_namp) == 0) {
memcpy(&spw_copy, spw, sizeof(struct spwd));
spw_copy.sp_pwdp = crypt;
putspent(&spw_copy, new);
memset(&spw_copy, 0, sizeof(struct spwd));
} else {
putspent(spw, new);
}
spw = fgetspent(old);
}
fclose(old);
fclose(new);
unlink("/etc/shadow~");
ulckpwdf();
}
The program receives a segmentation fault after printing "opening shadow files". The other two vulnerabilities were found by manipulation arguments passed to the program, but this one crashes just from calling it normally with no arguments (i.e leaving everything in it's default case). So I am 100% sure that the string crypt is a valid pointer in this case, and null-terminated.
So, I guess I should begin by asking: what is this shadow file and putspent/fgetspent functions? The link/unlink commands have me a bit concerned, although I don't see why this would cause a problem and make the program crash. Likewise, the lckpwdf function acts as a lock on the file I believe, so I think that this should be okay as well. Would anyone know why this function crashes? Sorry for the multiple questions... I usually program on windows, so I am not familiar with all of the linux concepts presented in this function. I should also mention that I am just looking for help in determining the reason why this crashes, and if this can be use as an exploit somehow... I'll write the code for the vulnerability myself.
Let me know if any clarifications are required, I would be glad to provide more detail or code if needed. Also, I apologize if this violates one of the rules for DIC (being security related and all), but I am not sure where else to post.
Thanks!
This post has been edited by LivingNightmare: 14 May 2012 - 09:49 AM

New Topic/Question
Reply



MultiQuote






|