I wonder if it is possible to execute bash code or a local file from cURL, that is, using the following syntax:

curl "local file"

I was looking for possible solutions and found that to read the local files of the system can be done with "file://" as follows:

curl "file:///root/script.sh"

However this seems to be equivalent to a "cat" or a "more", that is, it opens the file but does not execute it, so is it possible to execute bash instructions or execute the file using the previous syntax from cURL?

  • 7
    Probably the answer is no, but what is it you are trying to do here in the first place? Context will help – Conor Mancone Nov 1 '18 at 15:16
  • curl doesn't execute any content -- not local or remote. – dave_thompson_085 Nov 2 '18 at 4:50

Not sure if this is against the spirit of what you are asking but you can pipe the output of a shell script to bash. e.g. curl "file:///root/script.sh" | bash

Also take a look at a list of known curl vulnerabilities... I'm not aware of a good one for your purpose but if I needed to execute code with only curl I would look at its known vulnerabilities.

  • Maybe, but I wanted to know if it is possible to do it without any pipe or cURL option, ie using the URL, at the beginning I was thinking something like curl "file:///root/script.sh | bash" – Julián Nov 1 '18 at 14:51
  • no curl options allowed? – DarkMatter Nov 1 '18 at 14:52
  • No, only the url :( – Julián Nov 1 '18 at 14:54
  • 2
    @Julián I got nothing sorry :/ – DarkMatter Nov 1 '18 at 14:59
  • 8
    I feel like this is an XY Problem. Can you explain why you need to do this? – Mike Ounsworth Nov 1 '18 at 15:00

Not without exploiting a vulnerability in either cURL, one of the libraries it uses, or the terminal emulator the output is printed to. While there certainly have been vulnerabilities in the utility that allowed for arbitrary code execution, there is no supported method to execute a file just by accessing it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.