Skip to content

Commit 4dbe776

Browse files
David MaloneyDavid Maloney
authored andcommitted
Merge branch 'master' into findpids
2 parents 71e57a6 + cc81024 commit 4dbe776

File tree

1,382 files changed

+7104
-58115
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,382 files changed

+7104
-58115
lines changed

data/meterpreter/elevator.dll

512 Bytes
Binary file not shown.

data/meterpreter/ext_server_espia.dll

512 Bytes
Binary file not shown.
512 Bytes
Binary file not shown.
0 Bytes
Binary file not shown.

data/meterpreter/ext_server_priv.dll

0 Bytes
Binary file not shown.
-6.5 KB
Binary file not shown.
29 Bytes
Binary file not shown.

data/meterpreter/metsrv.dll

-12.5 KB
Binary file not shown.

data/meterpreter/screenshot.dll

0 Bytes
Binary file not shown.

external/source/meterpreter/source/extensions/stdapi/server/net/config/netstat.c

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -644,26 +644,62 @@ DWORD linux_parse_proc_net_file(char * filename, struct connection_table ** tabl
644644
DWORD linux_proc_get_program_name(struct connection_entry * connection, unsigned char * pid)
645645
{
646646
FILE *fd;
647-
char buffer[30], buffer_file[50], name[30];
647+
char buffer[30], buffer_file[256], name[256];
648+
char * bname;
649+
int do_status = 0;
648650

649-
snprintf(buffer, sizeof(buffer), "/proc/%s/status", pid);
651+
do {
652+
// try /proc/PID/cmdline first
653+
snprintf(buffer, sizeof(buffer)-1, "/proc/%s/cmdline", pid);
654+
fd = fopen(buffer, "r");
650655

651-
fd = fopen(buffer, "r");
652-
if (fd == NULL)
653-
return -1;
656+
// will try /proc/PID/status
657+
if (fd == NULL) {
658+
do_status = 1;
659+
break;
660+
}
661+
if (fgets(buffer_file, sizeof(buffer_file), fd) == NULL) {
662+
do_status = 1;
663+
break;
664+
}
665+
// each entry in cmdline is seperated by '\0' so buffer_file contains first the path of the executable launched
666+
if ((bname = basename(buffer_file)) == NULL) {
667+
do_status = 1;
668+
break;
669+
}
670+
// copy basename into name to be consistent at the end
671+
strncpy(name, bname, sizeof(name)-1);
672+
name[sizeof(name)-1] = '\0';
654673

655-
if (fgets(buffer_file, sizeof(buffer_file), fd) == NULL) {
656-
fclose(fd);
657-
return -1;
658-
}
674+
} while (0);
659675

660-
if (sscanf(buffer_file, "Name: %s\n", name) != 1) {
661-
fclose(fd);
662-
return -1;
663-
}
676+
if (fd != NULL)
677+
fclose(fd);
664678

665-
snprintf(connection->program_name, sizeof(connection->program_name), "%s/%s",pid,name);
666-
fclose(fd);
679+
680+
// /proc/PID/cmdline failed, try /proc/PID/status
681+
if (do_status == 1) {
682+
snprintf(buffer, sizeof(buffer)-1, "/proc/%s/status", pid);
683+
fd = fopen(buffer, "r");
684+
685+
// will try /proc/PID/status
686+
if (fd == NULL)
687+
return -1;
688+
689+
if (fgets(buffer_file, sizeof(buffer_file), fd) == NULL) {
690+
fclose(fd);
691+
return -1;
692+
}
693+
694+
if (sscanf(buffer_file, "Name: %200s\n", name) != 1) {
695+
fclose(fd);
696+
return -1;
697+
}
698+
fclose(fd);
699+
700+
}
701+
702+
snprintf(connection->program_name, sizeof(connection->program_name), "%s/%s", pid, name);
667703
return 0;
668704
}
669705

0 commit comments

Comments
 (0)