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

Template Injection Emulator #337

Closed
wants to merge 20 commits into from

Conversation

rjt-gupta
Copy link
Collaborator

@rjt-gupta rjt-gupta commented Jun 25, 2019

Engines Supported:

  • Mako
  • Tornado

All of them are detected by using separate regex and have separate get_injection methods.

@rjt-gupta
Copy link
Collaborator Author

rjt-gupta commented Jun 25, 2019

We need to fix the travis build first.

tanner/emulators/template_injection.py Outdated Show resolved Hide resolved
tanner/emulators/template_injection.py Outdated Show resolved Hide resolved
@rnehra01
Copy link
Collaborator

Overall it looks pretty limited to me. I could get to work simple payloads like {{7*7}} which doesn't have serious impacts. Have you thought about complex payloads that can have high severity like reading local files, configs etc. https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Server%20Side%20Template%20Injection#jinja2

@rjt-gupta
Copy link
Collaborator Author

rjt-gupta commented Jun 26, 2019

So, payloads running commands or reading /etc/passwd can be done easily for mako, tornado template engines. For jinja2 I think a simple detection would work as its often detected using {{7*7}} type payloads.

Do you have something in mind for jinja2 engine?

tanner/tests/test_template_injection.py Outdated Show resolved Hide resolved
tanner/emulators/template_injection.py Outdated Show resolved Hide resolved
@rjt-gupta
Copy link
Collaborator Author

rjt-gupta commented Jul 1, 2019

So, the twig engine is working nicely along with from snare side as well.
To run the emulator install composer then install twig using composer - composer require "twig/twig:^2.0" from /tanner directory.

It will create a folder vendor/ with all the twig files. autoload.php etc

Input format - ?a={{7*"7"}}
Output should contain 49 which is twig engine specific.

@rjt-gupta
Copy link
Collaborator Author

rjt-gupta commented Jul 1, 2019

Also, maybe we can include this vendor/ files as a part of project then user won't have to worry about anything. Is this feasible?

@rnehra01
Copy link
Collaborator

rnehra01 commented Jul 3, 2019

@rjt-gupta What payloads are working for this emulator?

@rjt-gupta
Copy link
Collaborator Author

rjt-gupta commented Jul 6, 2019

Engines - Mako, Tornado are working using docker and a custom image(base image - alphine).

Working complex payloads -

Mako - <%\nimport os\nx=os.uname()\n%>\n${x}
Tornado - {%import os%}{{os.uname()}}

(run docker-compose build first)

* docs added

* possible travis fix

* travis fix

* CI fix
tanner/utils/patterns.py Show resolved Hide resolved
tanner/emulators/template_injection.py Outdated Show resolved Hide resolved
docker/docker-compose.yml Outdated Show resolved Hide resolved
docker/tanner/template injection/Dockerfile Outdated Show resolved Hide resolved
tanner/utils/docker_helper.py Outdated Show resolved Hide resolved
tanner/emulators/template_injection.py Outdated Show resolved Hide resolved
@coveralls
Copy link

coveralls commented Jul 10, 2019

Pull Request Test Coverage Report for Build 1067

  • 69 of 99 (69.7%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.4%) to 76.585%

Changes Missing Coverage Covered Lines Changed/Added Lines %
tanner/utils/docker_helper.py 24 54 44.44%
Totals Coverage Status
Change from base Build 1066: -0.4%
Covered Lines: 1377
Relevant Lines: 1798

💛 - Coveralls

@rjt-gupta
Copy link
Collaborator Author

Ready.

@rnehra01
Copy link
Collaborator

It gives me b'49' for {{7*7}}. Can you remove the b and quotes?

docker/tanner/template_injection/Dockerfile Outdated Show resolved Hide resolved
tanner/emulators/template_injection.py Outdated Show resolved Hide resolved
tanner/emulators/template_injection.py Outdated Show resolved Hide resolved
@rjt-gupta
Copy link
Collaborator Author

rjt-gupta commented Jul 11, 2019

It gives me b'49' for {{7*7}}. Can you remove the b and quotes?

I am decoding the output already and apparently "b'49'" as a whole is a string, dont know why it is getting encoded twice.

So, i'll just strip this to remove b''.

@rjt-gupta
Copy link
Collaborator Author

rjt-gupta commented Jul 12, 2019

Updated docker_helper to latest upgrade, updated lfi, cmd_exec, template_injection emulators also.

Added tests for this emulator.

* Added Comments

* updated changes

* removed comma
* Aiodocker helper

* Aiodocker tests

* deleting used containers

* close docker removed
@rjt-gupta rjt-gupta changed the base branch from master to develop July 26, 2019 07:36
@rjt-gupta rjt-gupta closed this Jul 30, 2019
@rjt-gupta rjt-gupta deleted the template-injection branch July 30, 2019 19:11
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

Successfully merging this pull request may close these issues.

3 participants