def getXMLTree(cls, filename, verbose): """ Opens a config file for reading. Returns XML Elementree object representing XML Config file. Argument(s): No arguments are required. Return value(s): ElementTree Restrictions: File must be named sites.xml and must be in same directory as caller. This Method is tagged as a Class Method """ if SitesFile.fileExists(filename): try: with open(filename) as f: sitetree = ElementTree() sitetree.parse(f) return sitetree except: SiteDetailOutput.PrintStandardOutput( 'There was an error reading from the {xmlfile} input file.\n' 'Please check that the {xmlfile} file is present and correctly ' 'formatted.'.format(xmlfile=filename), verbose=verbose) else: SiteDetailOutput.PrintStandardOutput( 'No local {xmlfile} file present.'.format(xmlfile=filename), verbose=verbose) return None
def TargetList(self, filename, verbose): """ Opens a file for reading. Returns each string from each line of a single or multi-line file. Argument(s): filename -- string based name of the file that will be retrieved and parsed. verbose -- boolean value representing whether output will be printed to stdout Return value(s): Iterator of string(s) found in a single or multi-line file. Restriction(s): This Method is tagged as a Class Method """ try: target = '' with open(filename) as f: li = f.readlines() for i in li: target = str(i).strip() yield target except IOError: SiteDetailOutput.PrintStandardOutput( 'There was an error reading from the target input file.', verbose=verbose)
def main(): """ Serves as the instantiation point to start Automater. Argument(s): No arguments are required. Return value(s): Nothing is returned from this Method. Restriction(s): The Method has no restrictions. """ sites = [] parser = Parser('IP, URL, and Hash Passive Analysis tool', __VERSION__) # if no target run and print help if parser.hasNoTarget(): print('[!] No argument given.') parser.print_help() # need to fix this. Will later sys.exit() if parser.VersionCheck: Site.checkmoduleversion(__GITFILEPREFIX__, __GITLOCATION__, parser.Proxy, parser.Verbose) # user may only want to run against one source - allsources # is the seed used to check if the user did not enter an s tag sourcelist = ['allsources'] if parser.hasSource(): sourcelist = parser.Source.split(';') # a file input capability provides a possibility of # multiple lines of targets targetlist = [] if parser.hasInputFile(): for tgtstr in TargetFile.TargetList(parser.InputFile, parser.Verbose): tgtstrstripped = tgtstr.replace('[.]', '.').replace('{.}', '.').replace('(.)', '.') if IPWrapper.isIPorIPList(tgtstrstripped): for targ in IPWrapper.getTarget(tgtstrstripped): targetlist.append(targ) else: targetlist.append(tgtstrstripped) else: # one target or list of range of targets added on console target = parser.Target tgtstrstripped = target.replace('[.]', '.').replace('{.}', '.').replace('(.)', '.') if IPWrapper.isIPorIPList(tgtstrstripped): for targ in IPWrapper.getTarget(tgtstrstripped): targetlist.append(targ) else: targetlist.append(tgtstrstripped) sitefac = SiteFacade(parser.Verbose) sitefac.runSiteAutomation(parser.Delay, parser.Proxy, targetlist, sourcelist, parser.UserAgent, parser.hasBotOut, parser.RefreshRemoteXML, __GITLOCATION__) sites = sitefac.Sites if sites: SiteDetailOutput(sites).createOutputInfo(parser)
def main(): """ Serves as the instantiation point to start Automater. Argument(s): No arguments are required. Return value(s): Nothing is returned from this Method. Restriction(s): The Method has no restrictions. """ sites = [] parser = Parser('IP, URL, and Hash Passive Analysis tool') # if no target run and print help if parser.hasNoTarget(): print '[!] No argument given.' parser.print_help() # need to fix this. Will later sys.exit() # user may only want to run against one source - allsources # is the seed used to check if the user did not enter an s tag source = "allsources" if parser.hasSource(): source = parser.Source # a file input capability provides a possibility of # multiple lines of targets targetlist = [] if parser.hasInputFile(): for tgtstr in TargetFile.TargetList(parser.InputFile): if IPWrapper.isIPorIPList(tgtstr): for targ in IPWrapper.getTarget(tgtstr): targetlist.append(targ) else: targetlist.append(tgtstr) else: # one target or list of range of targets added on console target = parser.Target if IPWrapper.isIPorIPList(target): for targ in IPWrapper.getTarget(target): targetlist.append(targ) else: targetlist.append(target) sitefac = SiteFacade() sitefac.runSiteAutomation(parser.Delay, targetlist, source, parser.hasPost()) sites = sitefac.Sites if sites is not None: SiteDetailOutput(sites).createOutputInfo(parser)
def run_automater(cmd,targets): """ Runs Automator on list of target strings and returns results as json encoded string object. """ targetlist = targets source = cmd #"allsources" sitefac = SiteFacade() try: sitefac.runSiteAutomation(1,None, targetlist, source, False,"Automater/2.1",quiet=True) sites = sitefac.Sites if sites is not None: out = SiteDetailOutput(sites) return out.jsonOutput() return None # If you just want results as string just return output.getvalue() except Exception as e: print e.message return None
def run_automater(self): """ Runs Automator on list of target strings and returns results as json encoded string object. """ targetlist = self.target sitefac = SiteFacade() #print targetlist #print self.site try: sitefac.runSiteAutomation(1,None, [targetlist], self.site, False,"Automater/2.1", quiet=False) sites = sitefac.Sites if sites is not None: out = SiteDetailOutput(sites) return out.jsonOutput() else: return "{}" except Exception as e: print e.message return None
def updateTekDefenseXMLTree(cls, prox, verbose): if prox: proxy = {'https': prox, 'http': prox} else: proxy = None remotemd5 = None localmd5 = None localfileexists = False try: localmd5 = SitesFile.getMD5OfLocalFile(__TEKDEFENSEXML__) localfileexists = True except IOError: SiteDetailOutput.PrintStandardOutput( 'Local file {xmlfile} not located. Attempting download.'. format(xmlfile=__TEKDEFENSEXML__), verbose=verbose) try: if localfileexists: remotemd5 = SitesFile.getMD5OfRemoteFile( __REMOTE_TEKD_XML_LOCATION__, proxy=proxy) if remotemd5 and remotemd5 != localmd5: SiteDetailOutput.PrintStandardOutput( 'There is an updated remote {xmlfile} file at {url}. ' 'Attempting download.'.format( url=__REMOTE_TEKD_XML_LOCATION__, xmlfile=__TEKDEFENSEXML__), verbose=verbose) SitesFile.getRemoteFile(__REMOTE_TEKD_XML_LOCATION__, proxy) else: SitesFile.getRemoteFile(__REMOTE_TEKD_XML_LOCATION__, proxy) except ConnectionError as ce: try: SiteDetailOutput.PrintStandardOutput( 'Cannot connect to {url}. Server response is {resp} Server error ' 'code is {code}'.format(url=__REMOTE_TEKD_XML_LOCATION__, resp=ce.message[0], code=ce.message[1][0]), verbose=verbose) except: SiteDetailOutput.PrintStandardOutput( 'Cannot connect to {url} to retreive the {xmlfile} for use.' .format(url=__REMOTE_TEKD_XML_LOCATION__, xmlfile=__TEKDEFENSEXML__), verbose=verbose) except HTTPError as he: try: SiteDetailOutput.PrintStandardOutput( 'Cannot connect to {url}. Server response is {resp}.'. format(url=__REMOTE_TEKD_XML_LOCATION__, resp=he.message), verbose=verbose) except: SiteDetailOutput.PrintStandardOutput( 'Cannot connect to {url} to retreive the {xmlfile} for use.' .format(url=__REMOTE_TEKD_XML_LOCATION__, xmlfile=__TEKDEFENSEXML__), verbose=verbose)
def post(self, cible): """ Serves as the instantiation point to start Automater. Argument(s): No arguments are required. Return value(s): Nothing is returned from this Method. Restriction(s): The Method has no restrictions. """ urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) __VERSION__ = '0.21' __GITLOCATION__ = 'https://github.com/1aN0rmus/TekDefense-Automater' __GITFILEPREFIX__ = 'https://raw.githubusercontent.com/1aN0rmus/TekDefense-Automater/master/' sites = [] parser = Parser('IP, URL, and Hash Passive Analysis tool', __VERSION__, cible) # if no target run and print help if parser.hasNoTarget(): print('[!] No argument given.') parser.print_help() # need to fix this. Will later sys.exit() if parser.VersionCheck: Site.checkmoduleversion(__GITFILEPREFIX__, __GITLOCATION__, parser.Proxy, parser.Verbose) # user may only want to run against one source - allsources # is the seed used to check if the user did not enter an s tag sourcelist = ['allsources'] if parser.hasSource(): sourcelist = parser.Source.split(';') # a file input capability provides a possibility of # multiple lines of targets targetlist = [] if parser.hasInputFile(): for tgtstr in TargetFile.TargetList(parser.InputFile, parser.Verbose): tgtstrstripped = tgtstr.replace('[.]', '.').replace( '{.}', '.').replace('(.)', '.') if IPWrapper.isIPorIPList(tgtstrstripped): for targ in IPWrapper.getTarget(tgtstrstripped): targetlist.append(targ) else: targetlist.append(tgtstrstripped) else: # one target or list of range of targets added on console #target = parser.Target target = cible #print("---------------------------------------------------------------------------------------------") #print(target) tgtstrstripped = target.replace('[.]', '.').replace('{.}', '.').replace( '(.)', '.') if IPWrapper.isIPorIPList(tgtstrstripped): for targ in IPWrapper.getTarget(tgtstrstripped): targetlist.append(targ) else: targetlist.append(tgtstrstripped) #print(targetlist) sitefac = SiteFacade(parser.Verbose) sitefac.runSiteAutomation(parser.Delay, parser.Proxy, targetlist, sourcelist, parser.UserAgent, parser.hasBotOut, parser.RefreshRemoteXML, __GITLOCATION__) sites = sitefac.Sites if sites: resultTemp = SiteDetailOutput(sites).createOutputInfo(parser) #print("---------------------------------------------------------------------------------------------") #print(sites) #print("---------------------------------------------------------------------------------------------") #-------------------PARSE RESULT-------------------------------------- tabTemp = resultTemp.split("\n") result = {} for i in range(len(tabTemp)): tabTemp[i] = tabTemp[i].replace("[+]", "") tabTemp[i] = tabTemp[i].strip() if (":" in tabTemp[i]): tab = tabTemp[i].split(":", 1) if (i == 1): result["target"] = tab[1].replace( "____________________", " ").strip() elif (tab[0] in result): result[tab[0]] = result[tab[0]] + " " + tab[1] else: result[tab[0]] = tab[1] results.append(result) #print(results) return result, 201