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

Twig template injection #401

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open

Twig template injection #401

wants to merge 5 commits into from

Conversation

mzfr
Copy link
Collaborator

@mzfr mzfr commented Aug 22, 2020

Add twig template
Fix for #381

@coveralls
Copy link

coveralls commented Aug 22, 2020

Pull Request Test Coverage Report for Build 1411

  • 19 of 26 (73.08%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.05%) to 77.197%

Changes Missing Coverage Covered Lines Changed/Added Lines %
tanner/emulators/twig_template_injection.py 19 26 73.08%
Totals Coverage Status
Change from base Build 1400: -0.05%
Covered Lines: 1581
Relevant Lines: 2048

💛 - Coveralls

from tanner.utils import patterns


class PHPObjectInjection:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be updated

tanner/emulators/twig_template_injection.py Show resolved Hide resolved
tanner/emulators/twig_template_injection.py Show resolved Hide resolved
self.emulator_enabled['template_injection'] else None
self.emulator_enabled['template_injection'] else None,
'twig_template_injection': twig_template_injection.TwigTemplateInjection(loop) if
self.emulator_enabled['twig_template_injection'] else None
}

self.get_emulators = ['sqli', 'rfi', 'lfi', 'xss', 'php_code_injection', 'php_object_injection',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to add emulator here in order to enable it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

POST too.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possible_get_detection = await self.get_emulation_result(session, get_data, self.get_emulators)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh okay

@afeena
Copy link
Collaborator

afeena commented Aug 26, 2020

@mzfr And what is the pattern to catch this type of attack?

@mzfr
Copy link
Collaborator Author

mzfr commented Aug 26, 2020

@afeena This kind of injection can be detected by the same regex used for tornado template injection.

That is why I didn't added any new pattern.

@rjt-gupta
Copy link
Collaborator

@mzfr Are you able to see the results now?

@mzfr
Copy link
Collaborator Author

mzfr commented Aug 28, 2020

@rjt-gupta no, still having the same problem i.e no error, no result.


detection = None
if patterns.TEMPLATE_INJECTION_TORNADO.match(value):
detection = dict(name="twig_template_injection", order=3)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested with super simple string /foobar?b={{3*%272%27}} There are 2 possible detections:

{'name': 'template_injection', 'order': 4}
{'name': 'twig_template_injection', 'order': 3}

Since template_injection is order 4, tanner chooses it and execute.

Any ideas how to distinguish? @mzfr @rjt-gupta

Copy link
Collaborator

@rjt-gupta rjt-gupta Sep 1, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For twig this case should give 6 and for tornado 222. (right?)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we need something that distinguishes these two..

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah the regex is almost similar so it' hard to distinguish.

Also afeena can you please tell me how did you tested it? I mean the setup I want to know what I am doing wrong.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mzfr scan works perfectly fine, if you print possible detection you can see it. the only problem in the signature of the handle function.

detection = dict(name="twig_template_injection", order=3)
return detection

async def handle(self, attack_params):
Copy link
Collaborator

@afeena afeena Aug 31, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

session=None

the signature of the function is wrong. base emulator calls every handle with session
emulation_result = await self.emulators[detection['name']].handle(attack_params[detection['name']], session)

that is why function was not called properly, works for me now

return dict(value=result["stdout"], page=False)
async def handle(self, attack_params, session=None):
attack_params[0]['value'] = unquote(attack_params[0]['value'])
result = await self.get_injection_result(attack_params[0]['value'])
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tornado is getting its results from the custom docker image, and here its phpox. the returned format is different..

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rjt-gupta do you have an example of the format?

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.

None yet

4 participants