~ubuntu-whitehat/ubuntu-whitehat-project/uwht.dev

1 by Emanuele Gentili
anteater alpha is in.
1
#!/usr/bin/env python
2
3
# anteater V 0.1 Alpha
4
# (C) 2008 Ubuntu Pentest, Emanuele Gentili
5 by Emanuele Gentili
bug.commit changes.
5
#
1 by Emanuele Gentili
anteater alpha is in.
6
# Authors
7
# Emanuele Gentili <emgent@emanuele-gentili.com>
5 by Emanuele Gentili
bug.commit changes.
8
#
9
# Contributors
1 by Emanuele Gentili
anteater alpha is in.
10
# Giorgio Carlo Gigli Tos <gionnyboss@gmail.com>
5 by Emanuele Gentili
bug.commit changes.
11
# Andrea Corbellini <andrea-bs@ubuntu.com>
12
# 
1 by Emanuele Gentili
anteater alpha is in.
13
# GPLv2, see /usr/share/common-licenses/GPL
14
15
import sys
16
import os
17
from stat import *
18
import re
2 by Andrea Corbellini
Added python-launchpad-bugs support.
19
import launchpadbugs.connector as Connector
1 by Emanuele Gentili
anteater alpha is in.
20
21
class Application():
22
	NAME = "anteater.py"
23
	VERSION = 0.1
5 by Emanuele Gentili
bug.commit changes.
24
	AUTHORS = "Emanuele Gentili (emgent)\n"
2 by Andrea Corbellini
Added python-launchpad-bugs support.
25
1 by Emanuele Gentili
anteater alpha is in.
26
	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" \
27
			+ "There is NO WARRANTY, to the extent permitted by law."
2 by Andrea Corbellini
Added python-launchpad-bugs support.
28
1 by Emanuele Gentili
anteater alpha is in.
29
	cocFilename = "whcoc.txt"
30
	editor = "nano"
31
32
33
	def __init__(self):
34
35
		self.__getOptions()
36
37
		# Displaying code of conduct
38
		os.system("more " + self.cocFilename)
2 by Andrea Corbellini
Added python-launchpad-bugs support.
39
1 by Emanuele Gentili
anteater alpha is in.
40
		while True:
41
			reply = self.__getLine("Do you accept Ubuntu Code of Conduct? [y,n] ")
42
			if re.match("^\s*y\s*$", reply, re.IGNORECASE):
43
				break
44
			elif re.match("^\s*n\s*$", reply, re.IGNORECASE):
45
				sys.exit("You did not accept Ubuntu Code of Conduct.\nExiting application...")
46
47
		self.start()
2 by Andrea Corbellini
Added python-launchpad-bugs support.
48
1 by Emanuele Gentili
anteater alpha is in.
49
	# Get command line options
50
	def __getOptions(self):
2 by Andrea Corbellini
Added python-launchpad-bugs support.
51
1 by Emanuele Gentili
anteater alpha is in.
52
		from optparse import OptionParser
2 by Andrea Corbellini
Added python-launchpad-bugs support.
53
1 by Emanuele Gentili
anteater alpha is in.
54
		usage = self.NAME + " [OPTION]..."
55
		version = self.NAME + " " + str(self.VERSION) + "\n" + self.LICENSE + "\n\nWritten by " + self.AUTHORS
56
		description = "Application description"
2 by Andrea Corbellini
Added python-launchpad-bugs support.
57
1 by Emanuele Gentili
anteater alpha is in.
58
		parser = OptionParser(usage=usage, version=version, description=description)
59
		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")
60
		(options, args) = parser.parse_args()
2 by Andrea Corbellini
Added python-launchpad-bugs support.
61
1 by Emanuele Gentili
anteater alpha is in.
62
		self.editor = options.editor
63
		# Checking if editor exists in path
64
		pathDirs = os.environ['PATH'].split(":")
65
66
		editorValid = False
67
		for dir in pathDirs:
68
			file = os.path.join(dir, self.editor)
69
			if os.path.isfile(file):
70
				mode = os.stat(file)[ST_MODE]
71
				# Checking if file is executable to Others
72
				# TODO - Think if there is a better way to do this.
73
				if (S_IMODE(mode) & S_IXOTH) == S_IXOTH:
74
					editorValid = True
75
					break
76
77
		if not editorValid:
78
			sys.exit(self.NAME + ": specified editor `" + self.editor + "' is not in your path")
79
80
	def __getLine(self, text):
2 by Andrea Corbellini
Added python-launchpad-bugs support.
81
1 by Emanuele Gentili
anteater alpha is in.
82
		try:
83
			line = raw_input(text)
84
		except (EOFError, KeyboardInterrupt):
85
			print ""
86
			self.quit("Aborted by user")
87
		return line
88
89
	def start(self):
90
		launchpadID = self.__getLine("Please insert your Launchpad ID: ")
91
		ip = self.__getLine("Please insert your current IP: ")
92
		platformName = self.__getLine("Please, enter the name of the platform where you make pt: ")
2 by Andrea Corbellini
Added python-launchpad-bugs support.
93
1 by Emanuele Gentili
anteater alpha is in.
94
		reportFilename = platformName + "-report.txt"
95
96
		# Opening coc file for reading and report file for writing
97
		cockFile = open(self.cocFilename, 'r')
98
		reportFile = open(reportFilename, 'w')
99
		# Writing coc file content to reportFile
100
		reportFile.write(cockFile.read())
101
		# Closing coc file
102
		cockFile.close()
103
		# Writing report intestation
7 by Emanuele Gentili
syntax fixed.
104
		reportFile.write("\n Ubuntu Pentest Evangelist Informations:\n" \
9 by Emanuele Gentili
another little edit.
105
				+ "USER: https://edge.launchpad.net/~" + launchpadID + "\n" \
106
				+ "IP: " + ip + "\n\n" \
7 by Emanuele Gentili
syntax fixed.
107
				+ "* Starting Report for " + platformName + ":\n\n")
1 by Emanuele Gentili
anteater alpha is in.
108
		# Closing report file
109
		reportFile.close()
110
111
		os.system(self.editor + " " + reportFilename)
112
113
		# gpg sign
114
		os.system("gpg --clearsign " + platformName + "-report.txt")
115
116
		# Deleting report file and renaming signed report file to report file name
117
		try:
118
			os.remove(reportFilename)
119
		except OSError:
120
			sys.exit(self.NAME + ": cannot remove `" + reportFilename + "'")
121
		try:
122
			os.rename(reportFilename + ".asc", reportFilename)
123
		except OSError:
124
			sys.exit(self.NAME + ": cannot rename file `" + reportFilename + ".asc' to `" + reportFilename + "'")
125
2 by Andrea Corbellini
Added python-launchpad-bugs support.
126
		# launchpad sending bug ...
8 by Emanuele Gentili
connector.connectbug method change
127
		Bug = Connector.ConnectBug(method="HTML")
4 by Andrea Corbellini
Converted spaces to tabs.
128
		bug = Bug.New(product={'name': 'ubuntu-whitehat-project'},
129
			summary='[%s] report from %s' % (platformName, launchpadID),
5 by Emanuele Gentili
bug.commit changes.
130
			description='Automatic Pentration Test report.',
4 by Andrea Corbellini
Converted spaces to tabs.
131
			security_related=True
132
		)
133
		attachment = Bug.NewAttachment(localfilename=reportFilename)
134
		attachment.description = "ptreport"
135
		bug.attachments.add(attachment)
8 by Emanuele Gentili
connector.connectbug method change
136
		bug.commit(force_changes=True, ignore_lp_errors=False)
6 by Emanuele Gentili
another fix in return.
137
		return
1 by Emanuele Gentili
anteater alpha is in.
138
139
	def quit(self, msg):
140
		sys.exit(msg)
141
142
# ------------------------------------------------------------------------------
143
# Application START
144
145
if __name__ == "__main__":
146
	application = Application()