commixproject / commix

Automated All-in-One OS Command Injection Exploitation Tool.
https://commixproject.com
Other
4.62k stars 818 forks source link

Commix Not Executed Properly When Run Programatically #923

Closed nik-ngp closed 4 months ago

nik-ngp commented 6 months ago

What's the problem (or question)?

Commix has issues when running under an emulated terminal.

For example, I tried running it within Python (which does execution differently, it creates an actual process) and it worked (edit it does not): import subprocess cmd = "commix -r req.txt --ignore-stdin --batch" returned_value = subprocess.call(cmd, shell=True) print(returned_value)

How can we reproduce the issue?

https://github.com/nik-ngp/commix-bug

When I run the program in the repo I receive this in the console: image

What are the running context details?

stasinopoulos commented 6 months ago

@nik-ngp honestly I don’t get the reason why to do that. Anyway, by knowing that in a Python environment works as it should, i am closing this down.

nik-ngp commented 6 months ago

@stasinopoulos

by knowing that in a Python environment works as it should, i am closing this down

The Python code actually doesn't work. My Python skills are a bit rusty and I have provided wrong code.

The code I provided does not return output of the executed command, the file descriptors were inherited from the running process which meant that the executed command was writing directly to standard out & err. Instead of to a variable.

Here is an updated script: import subprocess cmd = "commix -r req.txt --ignore-stdin --batch" # cmd = "echo 123" # <--- Works def do(command: str) -> str: try: return subprocess.check_output( command, shell = True ).decode('utf-8') except Exception as e: print(e) return 'Error' output = do(cmd) print(output)

This code reproduces the same behavior I am experiencing in the Golang example. If I set in my Golang code's stdout & stderr to os.Stdout & os.Stderr it would be equivalent to my initial Python example that worked.

honestly I don’t get the reason why to do that

I have a crawler that records requests with data and automatically targets them with Commix. Why would I have to crawl and run against endpoints when my script can? I am simply saving my own time.

stasinopoulos commented 5 months ago

@nik-ngp why not parsing targets (as a piped-in input) directly from your / other pentesting tools? (e.g https://x.com/commixproject/status/1525726750285733889)

nik-ngp commented 5 months ago

@stasinopoulos I did some attempts, however, it seems that it does not support piping in raw requests.

stasinopoulos commented 5 months ago

I updated your code and now works fine.

import subprocess

url = "http://php.testsparker.com/nslookup.php?param=1"
cmd = f"commix -u {url} --batch --os-cmd=whoami --answers=\"shell=n\""

def do(command: str) -> str:
  try:
    return subprocess.run(
      command,
      shell = True
    )
  except Exception as e:
    print(e)
    return 'Error'
output = do(cmd)
print(output)

image

nik-ngp commented 5 months ago

Hello @stasinopoulos. I have to admit, you got me a bit confused. I'm unsure of what the updated code is meant to represent since it deviates from the purpose of my script in two ways:

stasinopoulos commented 5 months ago

@nik-ngp just of curiosity, have you tried the same using other (similar) tools (e.g. sqlmap etc)? Anyway, I'll take a look into this issue and get back to you soon.

nik-ngp commented 5 months ago

@stasinopoulos Indeed I am using Sqlmap to tests against raw requests. It works nicely with my code.

stasinopoulos commented 5 months ago

Potential fix: https://github.com/commixproject/commix/commit/ebe84fac8a3f06db3590fd447434627d5ffef16e. Please check again.

github-actions[bot] commented 2 months ago

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

This action has been performed automatically by a bot.