Are ALL system() calls a security risk in c++?

William FitzPatrick

A post in this (Are system() calls evil?) thread says:

Your program's privileges are inherited by its spawned programs. If your application ever runs as a privileged user, all someone has to do is put their own program with the name of the thing you shell out too, and then can execute arbitrary code (this implies you should never run a program that uses system as root or setuid root).

But system("PAUSE") and system("CLS") shell to the OS, so how could a hacker possibly intervene if it ONLY shells to a specific secure location on the hard-drive?

Does explicitly flush—by using fflush or _flushall—or closing any stream before calling system eliminate all risk?

Joshua

The original question references POSIX not windows. Here there is no COMSPEC (there is SHELL but system() deliberately does not use it); however /bin/sh is completely, utterly vulnerable.

Suppose /opt/vuln/program does system("/bin/ls"); Looks completely harmless, right? Nope!

$ PATH=. IFS='/ ' /opt/vuln/program

This runs the program called bin in the current directory. Oops. Defending against this kind of thing is so difficult it should be left to the extreme experts, like the guys who wrote sudo. Sanitizing environment is extremely hard.

So you might be thinking what is that system() api for. I don't actually know why it was created, but if you wanted to do a feature like ftp has where !command is executed locally in the shell you could do ... else if (terminalline[0] == '!') system(terminalline+1); else ... Since it's going to be completely insecure anyway there's no point in making it secure. Of course a truly modern use case wouldn't do it that way because system() doesn't look at $SHELL but oh well.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Does the client knowing all the endpoint names pose a security risk?

From Dev

strace all but specified system calls

From Dev

C system calls fails

From Dev

C system calls open()

From Java

PHP calls to system vs Bash scripts Security

From Dev

Security risk of PHP variables

From Dev

Are .eml attachments a security risk?

From Dev

Is this a security risk/concern?

From Dev

is this view a security risk?

From Dev

Setgid bit - is it a security risk?

From Java

System calls vs C/C++ system calls

From Dev

Storing System Calls in C Programming

From Dev

Linux System calls in C on OSX

From Dev

Endless session: any security risk?

From Java

One time password security risk

From Java

What is the security risk of object reflection?

From Dev

Is this SSH config misconfigured and a security risk?

From Dev

Does RedirectToAction pose a security risk?

From Dev

Multiple Submit Buttons Security Risk

From Dev

BitPay API notifications: security risk?

From Dev

How System.Security.Cryptography.OpenSsl calls OpenSSL functions?

From Dev

List all the Claim types stored in the System.Security.Claims.ClaimTypes in C#

From Dev

Why unsafe code context [related to pointer operation] is a security risk in C#?

From Dev

How to fix error- nodemon.ps1 cannot be loaded because running scripts is disabled on this system, (without security risk)?

From Java

Linux system calls vs C lib functions

From Dev

How to Mock Linux System Calls in C

From Dev

C: Suppress system calls from binary

From Dev

pipe stuck in read (C - system calls)

From Dev

Calling C system calls from JNI