Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

segmentation fault when execute_command and the stack overflow caused by parameters #40

Closed
firmianay opened this issue Jul 5, 2022 · 5 comments
Labels
security security bugs

Comments

@firmianay
Copy link

hi, great project!

I think it's better to limit the size of res, otherwise it may cause the program to crash, such as performing "cat /dev/random | od -x", which maybe unlikely in reality.

char *execute_command(char *command) {
	FILE *fp;
	char *res = calloc(4096, sizeof(char));
	char buf[1024];

	fp = popen(command, "r");
	if (fp == NULL) {
		perror("Failed to run command");
		return NULL;
	}

	while (fgets(buf, sizeof(buf), fp) != NULL) {
		strcat(res, buf);
	}
	// printf("RESULT OF COMMAND: %s\n", res);

	pclose(fp);
	return res;
	}
@0xjet
Copy link
Collaborator

0xjet commented Jul 5, 2022

You're right. There is surely more instances like this one. Tagging this as a security bug to be fixed at some point. Thanks!

@0xjet 0xjet added the security security bugs label Jul 5, 2022
@firmianay
Copy link
Author

Well, there are other security issues. There is no limit to the length of program parameters, which may cause overflow.

src/client/client.c

void main(int argc, char* argv[]){
...
    int opt;
    char dest_address[32];
    char path_arg[512];

    while ((opt = getopt(argc, argv, ":S:c:e:u:a:p:s:h")) != -1) {
        switch (opt) {
        case 'S':
...
            strcpy(dest_address, optarg);

@firmianay firmianay changed the title segmentation fault when execute_command segmentation fault when execute_command and the stack overflow caused by parameters Jul 6, 2022
@Ifex370
Copy link

Ifex370 commented Jul 18, 2022

Is this the reason I get

Illegal instruction (core dumped) - when I run ./simple_timer. and a
segmentation fault (core dumped) - when I run ./simple_open?

I have not been able to carry out a PoC due to the above errors.

@h3xduck
Copy link
Owner

h3xduck commented Jul 18, 2022

@Ifex370 I am moving your issue to a different thread (#44) since it is not related to this security-related issue

@firmianay
Copy link
Author

firmianay commented Aug 4, 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
security security bugs
Projects
None yet
Development

No branches or pull requests

4 participants