def brute(self): if self._bruteTopDomain: for line in WordList(self._defaultTopDomainDict): domain = partDomain + "." + line ip = self._checkDomain(domain) if ip: yield Dict(domain=domain, ip=ip) for line in WordList(self._dictfile): domain = line.strip() + "." + self._domain ip = self._checkDomain(domain) if ip: yield Dict(domain=domain, ip=ip)
def nmapScan(cmd, scannerPath=None): ''' Nmap scan. @returns: a list of host, each host has attribute 'ip' 'port' ''' result = list() if "-oX" not in cmd: cmd = cmd + " -oX -" if scannerPath: cmd.replace("nmap", scannerPath) popen = Popen(cmd, shell=True, stdout=PIPE, stderr=STDOUT) scanResult = popen.stdout.read() if not scanResult: return None #parse the nmap scan result xmlDoc = etree.XML(scanResult) hosts = xmlDoc.findall(".//host") for host in hosts: try: if host[0].get('state') != "up": continue ip = host[1].get('addr') ports = host.findall(".//port") for port in ports: if port[0].get('state') != "open": continue result.append(Dict(ip=ip, port=port.get('portid'))) except IndexError: continue return result
def _parseHtml(self, document): tree = etree.HTML(document) for node in tree.xpath("//h3[@class='r']/a"): title = "".join([x for x in node.itertext()]) url = node.get("href") urlStart = url.find("http") urlEnd = url.find("&sa") urlStart = urlStart if urlStart != -1 else 0 urlEnd = urlEnd if urlEnd != -1 else len(url) yield Dict(title=title, url=url[urlStart:urlEnd])
def _parseHtml(self, document): tree = etree.HTML(document) for node in tree.xpath("//li[@class='b_algo']/h2/a"): title = "".join([x for x in node.itertext()]) url = node.get("href") yield Dict(title=title, url=url)