Exemplo n.º 1
0
def descript(program, category="exploits", prof=False):
	if ".py" not in program:
		program += ".py"
	if category == "exploit":
		category = "exploits"
	inside = open(program).read()
	if not prof:
		prof = profiles[category][program.split("/")[-1].split(".py")[0]]
	if "description='" in inside:
		m = re.search('description=\'(.+?)\'', inside)
	elif "description=\"" in inside:
		m = re.search('description="(.+?)"', inside)
	elif "description = '" in inside:
		m = re.search('description = \'(.+?)\'', inside)
	elif "description = \"" in inside:
		m = re.search('description = "(.+?)"', inside)
	else:
		m = False
	if m:
		description = m.group(1)
	else:
		description = prof["name"]
	if prof:
		baseinfo = auto_info(prof["appname"], prof["rank"])
	screensize = console._get_screen_size()
	if screensize[0]/float(screensize[1]) >= 1.0:
		width = 80
	else:
		width = 49
	wrapper = textwrap.TextWrapper(initial_indent=baseinfo, width=width, subsequent_indent=" "*len(baseinfo))
	print wrapper.fill(description)
Exemplo n.º 2
0
def _show():
    from matplotlib._pylab_helpers import Gcf
    active_manager = Gcf.get_active()
    if active_manager:
        import console
        import tempfile
        screen_width, screen_height = console._get_screen_size()
        compact = screen_width < 768
        dpi = 160 if not compact else 66.2
        tmp = tempfile.mktemp(suffix='.png')
        active_manager.canvas.figure.savefig(tmp, dpi=dpi)
        console.show_image(tmp)
Exemplo n.º 3
0
def _show():
    from matplotlib._pylab_helpers import Gcf
    active_manager = Gcf.get_active()
    if active_manager:
        import console
        import tempfile
        screen_width, screen_height = console._get_screen_size()
        compact = screen_width < 768
        dpi = 160 if not compact else 66.2
        tmp = tempfile.mktemp(suffix='.png')
        active_manager.canvas.figure.savefig(tmp, dpi=dpi)
        console.show_image(tmp)
Exemplo n.º 4
0
def commandline(loc=""):
	loc = loc.replace("./","")
	while 1:
		console.write_link("msf","")
		if loc == "":
			sys.stdout.write(" ")
		else:
			loco = loc.split("/")
			sys.stdout.write(" %s(" %(loco[0]))
			if console._get_screen_size()[0] > 500 or len("/".join(loco[1:])) < 23:
				sys.stderr.write("%s"%("/".join(loco[1:]).replace(".py","")))
			else:
				sys.stderr.write("%s" %(loco[-1].replace(".py","")))
			sys.stdout.write(") ")
		try:
			cmd = raw_input("> ")
			cmd,post = cmd.split(" ")[0].lower(),cmd.split(" ")[1:]
		except:
			print
			cmd, post = "",[""]
		if cmd == "clear":
			console.clear()
			full_banner()
		elif cmd == "locate" and len(post) > 0:
			print " =>",fdir(post[0])
		elif cmd == "use" and len(post) == 1:
			try:
				commandline(fdir(post[0]))
			except Exception as e:
				sys.stderr.write(" => %s\n"%str(e))
				pass
		elif cmd == "back":
			break
		elif cmd == "exit": 
			exit()
		elif cmd == "banner":
			full_banner()
		elif cmd == "rename" and len(post) > 1:
			tgpg = fdir(post[0])
			if len(post[1]) > 3:
				if not post[1].endswith(".py"):
					post[1] += ".py"
				tf = "/".join(tgpg.split("/")[:-1])+ "/" + post[1]
				shutil.move(tgpg, tf)
				collectprograms()
				sys.stderr.write("[*] ")
				sys.stdout.write("Renamed %s -> %s\n"%(tgpg, tf))
		elif cmd == "search" and post[0] == "posts" and len(post) > 1:
			selected = []
			for ps in fdir("", get=True, end=".txt"):
				inf = open(ps).read()
				for srch in post[1:]:
					if srch in inf:
						selected.append(ps)
						break
			tmsg = "Search Results for (%s)"%" ".join(post[1:])
			print
			print tmsg
			print "="*len(tmsg)
			print
			print "  File\n  ----\n"
			for pst in selected:
				print " ",pst
			print
		elif cmd == "search" and len(post) > 0:
			tmsg = "Search Results for (%s)"%post[0]
			print
			print tmsg
			print "="*len(tmsg)
			print
			print "  Name           Rank        Description"
			print "  ----           ----        -----------"
			for prgrm in fdir(post[0], get=True):
				descript(prgrm, prgrm.split("/")[1])
			print
		elif cmd == "size" and len(post) == 0:
			console.set_font("Menlo", size)
		elif cmd == "size" and len(post[0]) > 1:
			try:
				console.set_font("Menlo", int(post[0]))
				globals()["size"] = int(post[0])
			except:
				pass
		elif cmd == "add_header" and len(post) > 1:
			if len(post[0]) > 3:
				tgf = fdir(post[0])
				if os.path.isfile(tgf) and len(post[1]) > 2:
					acode = open(tgf).read()
					acode = "# "+post[1]+"\n"+acode
					f = open(tgf,"w")
					f.write(acode)
					f.close()
					sys.stderr.write("[*] ")
					sys.stdout.write("Header added to %s\n"%tgf)
		elif cmd == "python" and len(post) > 0:
			if post[0].endswith(".py") and os.path.isfile(post[0]):
				try:
					t = threading.Thread(target=MetaThread, args=(post[0]," ".join(post[1:],)))
					t.name = "python_app"
					t.daemon = True
					t.start()
					while pause and "python_app" in threading._active:
						time.sleep(0.5)
					time.sleep(1.2)
					print
				except Exception as e:
					sys.stderr.write(" => %s\n"%str(e))
					print
			else:
				sys.stderr.write(" => Invalid file path\n")
		elif cmd == "remove" and len(post) > 0:
			try:
				if post[0] in sets and post[0] != "slowsearch":
					t = post[0]+" => "+sets.get(post[0])
					sets.pop(post[0])
					var.remove(t)
					print "Removed Values For \"%s\"" %data
			except Exception as e:
				pass
		elif cmd == "read" and len(post) > 0:
			if len(post[0]) > 0:
				post[0] = fdir(post[0])
				if os.path.isfile(post[0]):
					print open(post[0]).read()
					print
				else:
					sys.stderr.write(" => Invalid file path\n")
		elif cmd == "install" and len(post) > 0:
			if post[0] == "exploitdb":
				db = "https://github.com/offensive-security/exploit-database/archive/master.zip"
				resp = urllib.urlopen(db)
				try:
					file_size = int(resp.info().getheaders("Content-Length")[0])
				except AttributeError:
					file_size = int(resp.info().get("Content-Length"))
				downloaded_size = 0
				block_size = 4096
				sys.stderr.write("[*] ")
				sys.stdout.write("Downloading exploit-db\n")
				with open("./master.zip", "wb") as outfile:
					buff = resp.read(block_size)
					while buff:
						outfile.write(buff)
						downloaded_size += len(buff)
						downloaded_part = float(downloaded_size) / file_size
						progress_size = int(downloaded_part * 39)
						status = "[{0}{1}] {2:.2%}".format(
						"#" * progress_size,
						" " * (39 - progress_size), downloaded_part)
						sys.stdout.write("\r"+status+'\b' * (len(status) + 1))
						buff = resp.read(block_size)
					print
				sys.stderr.write("[*] ")
				sys.stdout.write("Unpackaging files (inturrupt process if it takes over 5 minutes)")
				try:
					zip_ref = zipfile.ZipFile("master.zip", "r")
					if raw_input(" => Run unzipping in background? [Y/n]\n    =>").lower() == "y":
						threading.Thread(target=zip_ref.extractall, args=("./",)).start()
					else:
						zip_ref.extractall("./")
						zip_ref.close()
				except:
					pass
				if os.path.isdir("./exploit-database-master"):
					if os.path.isdir("./exploits"):
						os.remove("./exploits")
					shutil.move("./exploit-database-master/exploits","./exploits")
					shutil.rmtree("./exploit-database-master/")
					if os.path.isfile("master.zip"):
						os.remove("master.zip")
					sys.stderr.write("[*] ")
					sys.stdout.write("Unpackaging process complete! Files have been added to your database!\n")
				else:
					sys.stderr.write("[!] ")
					sys.stdout.write("Unpackaging process interrupt too earily\n")
		elif cmd == "uninstall" and len(post) > 0:
			if len(post[0]) > 0:
				if post[0] == "notpy" or post[0] == "nonpy":
					end = "non python"
				else:
					end = ".%s"%post[0]
				sys.stderr.write("[!] ")
				sys.stdout.write("Are you sure you wish to uninstall all %s files? [Y/n]\n    => "%end)
				if raw_input().lower() == "y":
					if post[0] == "notpy":
						for prg in fdir("", get=True, end=""):
							ldir = ""
							if ".py" not in prg:
								ndir = "/".join(prg.split("/")[:-1])[2:]
								if ldir != ndir:
									sys.stdout.write(("\r[*] Cleaning: %s"+(" "*15))%ndir)
									ldir = ndir
								if sets["slowsearch"] == "true":
									time.sleep(0.005)
								if "exploit" in prg or "payload" in prg or "auxiliary" in prg:
									os.remove(prg)
					else:
						for prg in fdir("", get=True, end=end):
							ldir = ""
							if "."+post[0] in prg:
								ndir = "/".join(prg.split("/")[:-1])[2:]
								if ldir != ndir:
									sys.stdout.write(("\r[*] Cleaning: %s"+(" "*15))%ndir)
									ldir = ndir
								if sets["slowsearch"] == "true":
									time.sleep(0.005)
								os.remove(prg)
					clean_folders()
					print "\n"
		extended_cmd(cmd, post, loc)
Exemplo n.º 5
0
def programopt(program):
	name = program.split("/")[-1].split(".py")[0]
	category = program.split("/")[-2]
	print "\nModule Options (%s)\n"%program.strip("./").strip(".py")
	print "  Name     Current Setting  Required  Description"
	print "  ----     ---------------  --------  -----------"
	inside = open(program).read()
	arglines = []
	for line in inside.split("\n"):
		if ".add_argument" in line:
			arglines.append(line)
	for line in arglines:
		arg, default, nsa, nsahlp = None, None, None, None
		if ".add_argument('" in line:
			try: nsa = re.search(".add_argument\('(.+?)'", line).group(1)
			except: pass
			if 'help="' in line:
				try: nsahlp = re.search('help="(.+?)"', line).group(1).replace("(","[").replace(")","]")
				except: pass
			elif "help='" in line:
				try: nsahlp = re.search("help='(.+?)'", line).group(1)
				except: pass
		elif '.add_argument("' in line:
			try: nsa = re.search('.add_argument\("(.+?)"', line).group(1)
			except: pass
			if 'help="' in line:
				try: nsahlp = re.search('help="(.+?)"', line).group(1)
				except: pass
			elif "help='" in line:
				try: nsahlp = re.search("help='(.+?)'", line).group(1)
				except: pass
		if "--" in line:
			try: arg = re.search("--(.+?)'", line).group(1)
			except: pass
			if not arg:
				try: arg = re.search('--(.+?)"', line).group(1)
				except: pass
		if 'help="' in line:
			try: hlp = re.search('help="(.+?)"', line).group(1)
			except: pass
		elif "help='" in line:
			try: hlp = re.search("help='(.+?)'", line).group(1)
			except: pass
		if "default=" in line:
			try: default = re.search("default=(.+?)\)", line).group(1)
			except: pass
			if not default:
				try: default = re.search("default=(.+?),", line).group(1)
				except: pass
		if arg:
			arg = arg.replace('"',"").replace("'","")
			if not default:
				if "action=" in line:
					default = "FalseNSA"
					required = "no"
				else:
					default = ""
					required = "yes"
			else:
				if default == "True" and "action=" in line:
					default = "TrueNSA"
				required = "no"
			if not hlp:
				hlp = ""
			if arg in sets.keys():
				default = sets[arg]
			default = default.replace('"',"").replace("'","")
			baseinfo = auto_option(arg, default, required)
			screensize = console._get_screen_size()
			if screensize[0]/float(screensize[1]) >= 1.0:
				width = 80
			else:
				width = 49
			wrapper = textwrap.TextWrapper(initial_indent=baseinfo, width=width, subsequent_indent=" "*len(baseinfo))
			print wrapper.fill(hlp)
		if nsa and nsa.startswith("-") == False:
			nsa = nsa.replace('"',"").replace("'","")
			if nsa in sets.keys():
				default = sets[nsa]
			else:
				default = ""
			default = default.replace('"',"").replace("'","")
			baseinfo = auto_option(nsa, default, "yes")
			screensize = console._get_screen_size()
			if screensize[0]/float(screensize[1]) >= 1.0:
				width = 80
			else:
				width = 49
			wrapper = textwrap.TextWrapper(initial_indent=baseinfo, width=width, subsequent_indent=" "*len(baseinfo))
			if nsahlp:
				print wrapper.fill(nsahlp.strip("\n\t").replace("  ",""))
			else:
				print wrapper.fill(nsa.strip("\n\t").replace("  ",""))
	print