From b0cf064f819357feedc77d6d5eb0de49e122554a Mon Sep 17 00:00:00 2001 From: marcinzelent Date: Sat, 16 Jun 2018 22:50:18 +0200 Subject: Added command injection example and secured examples --- examples-secure/command-injection/command-injection.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 examples-secure/command-injection/command-injection.c (limited to 'examples-secure/command-injection/command-injection.c') diff --git a/examples-secure/command-injection/command-injection.c b/examples-secure/command-injection/command-injection.c new file mode 100644 index 0000000..01eb15d --- /dev/null +++ b/examples-secure/command-injection/command-injection.c @@ -0,0 +1,17 @@ +#include +#include + +int main(int argc, char **argv) +{ + int argl = strlen(argv[1]); + char cmd[argl + 6]; + + for (int i = 0; i < argl; i++) + if (argv[1][i] == ';' || argv[1][i] == '|' || argv[1][i] == '&') + argv[1][i] = ' '; + strcpy(cmd, "echo "); + strcat(cmd, argv[1]); + system(cmd); + + return 0; +} -- cgit v1.2.3