TCP network communication security risks

204 views Asked by At

I am developing an application that can establish a server-client connection using QTcp*

The client sends the server a number.

The received string is checked on its length and quality (is it really a number?)

If everything is OK, then the server replies back with a file path (which depends on the sent number).

The client checks if the file exists and if it is a valid image. If the file complies with the rules, it executes a command on the file.

What security concerns exist on this type of connection?

The program is designed for Linux systems and the external command on the image file is executed using QProcess. If the string sent contained something like (do not run the following command):

; rm -rf /

then it would be blocked on the file not found security check (because it isn't a file path). If there wasn't any check about the validity of the sent string then the following command would be executed:

command_to_run_on_image ; rm -rf /

which would cause panic! But this cannot happen.

So, is there anything I should take into consideration?

1

There are 1 answers

0
Pavel Strakhov On

If you open a console and type command ; rm -rf /*, something bad would likely happen. It's because commands are processed by the shell. It parses text output, e.g. splits commands by ; delimiter and splits arguments by space, then it executes parsed commands with parsed arguments using system API.

However, when you use process->start("command", QStringList() << "; rm -rf /*");, there is no such danger. QProcess will not execute shell. It will execute command directly using system API. The result will be similar to running command "; rm -rf /*" in the shell.

So, you can be sure that only your command will be executed and the parameter will be passed to it as it is. The only danger is the possibility for an attacker to call the command with any file path he could construct. Consequences depends on what the command does.