rendered paste body#!/usr/bin/env python# anteater V 0.1 Alpha# (C) 2008 Ubuntu Pentest, Emanuele Gentili## Authors# Emanuele Gentili <emgent@emanuele-gentili.com>## Contributors# Giorgio Carlo Gigli Tos <gionnyboss@gmail.com># Andrea Corbellini <andrea-bs@ubuntu.com># # GPLv2, see /usr/share/common-licenses/GPLimport sysimport osfrom stat import *import reimport datetimeimport launchpadbugs.connector as Connectorimport globimport userclass Application(): NAME = "anteater.py" FULLNAME = "anteater" VERSION = 0.1 AUTHORS = "Emanuele Gentili (emgent)\n" LICENSE = "This is free software. You may redistribute copies of it under the terms of the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.\n" \ + "There is NO WARRANTY, to the extent permitted by law." USER_DIR = os.path.join(user.home, "." + FULLNAME) cocFilename = "whcoc.txt" editor = "nano" def __init__(self): # Creating user directory if it does not exist if not os.path.isdir(USER_DIR): try: os.mkdir(USER_DIR) except (OSError, IOError): sys.exit("Cannot create directory `" + USER_DIR + \ + "'\nPlease check file permissions and/or available disk space and launch application again.") self.__getOptions() # Displaying code of conduct os.system("more " + self.cocFilename) while True: reply = self.__getLine("Do you accept Ubuntu Code of Conduct? [y,n] ") if re.match("^\s*y\s*$", reply, re.IGNORECASE): break elif re.match("^\s*n\s*$", reply, re.IGNORECASE): sys.exit("You did not accept Ubuntu Code of Conduct.\nExiting application...") self.start() # Get command line options def __getOptions(self): from optparse import OptionParser usage = self.NAME + " [OPTION]..." version = self.NAME + " " + str(self.VERSION) + "\n" + self.LICENSE + "\n\nWritten by " + self.AUTHORS description = "Application description" parser = OptionParser(usage=usage, version=version, description=description) parser.add_option("-e", "--editor", action="store", type="string", default="nano", help="command of the editor to use to edit your bug report [default: %default]", metavar="EDITOR") (options, args) = parser.parse_args() self.editor = options.editor # Checking if editor exists in path pathDirs = os.environ['PATH'].split(":") editorValid = False for dir in pathDirs: file = os.path.join(dir, self.editor) if os.path.isfile(file): mode = os.stat(file)[ST_MODE] # Checking if file is executable to Others # TODO - Think if there is a better way to do this. if (S_IMODE(mode) & S_IXOTH) == S_IXOTH: editorValid = True break if not editorValid: sys.exit(self.NAME + ": specified editor `" + self.editor + "' is not in your path") def __getLine(self, text): try: line = raw_input(text) except (EOFError, KeyboardInterrupt): print "" self.quit("Aborted by user") return line def start(self): launchpadID = self.__getLine("Please insert your Launchpad ID: ") ip = self.__getLine("Please insert your current IP: ") platformName = self.__getLine("Please, enter the name of the platform where you make pt: ") # defining report filename including platform name and timestamp timestampTuple = datetime.datetime.now().timetuple() timestamp = "%i-%i-%i %i:%i:%i" % (timestampTuple[0], timestampTuple[1], timestampTuple[2], timestampTuple[3], timestampTuple[4], timestampTuple[5]) reportFilename = os.path.join(USER_DIR, platformName + "-" + timestamp + ".txt") # Opening coc file for reading and report file for writing cocFile = open(self.cocFilename, 'r') reportFile = open(reportFilename, 'w') # Writing coc file content to reportFile reportFile.write(cocFile.read()) # Closing coc file cocFile.close() # Writing report intestation reportFile.write("\nUbuntu Pentest Evangelist Informations:\n" \ + "USER: https://edge.launchpad.net/~" + launchpadID + "\n" \ + "IP: " + ip + "\n\n" \ + "* Starting Report for " + platformName + ":\n\n") # Closing report file reportFile.close() os.system(self.editor + " " + reportFilename) # gpg sign os.system("gpg --clearsign " + platformName + "-report.txt") # Deleting report file and renaming signed report file to report file name try: os.remove(reportFilename) except OSError: sys.exit(self.NAME + ": cannot remove `" + reportFilename + "'") try: os.rename(reportFilename + ".asc", reportFilename) except OSError: sys.exit(self.NAME + ": cannot rename file `" + reportFilename + ".asc' to `" + reportFilename + "'") # launchpad sending bug ... bug = Connector.ConnectBug(method="HTML") bug.authentication = glob.glob(os.path.expanduser("~/.mozilla/firefox/*/cookies.sqlite")).pop() # opening report file for reading reportFile = open(reportFilename, 'r') # creating bug bug = bug.New(product={'name': 'ubuntu-whitehat-project'}, summary='[%s] report from %s' % (platformName, launchpadID), description=reportFile.read(), security_related=True ) # closing report file reportFile.close()# attachment = bug.NewAttachment(localfilename=reportFilename)# attachment.description = "ptreport"# bug.attachments.add(attachment) bug.commit(force_changes=True, ignore_lp_errors=False) return def quit(self, msg): sys.exit(msg)# ------------------------------------------------------------------------------# Application STARTif __name__ == "__main__": application = Application()