| 1 | #!/usr/bin/env python |
|---|
| 2 | # -*- coding: utf-8 -*- |
|---|
| 3 | # |
|---|
| 4 | # Copyright (C) 2005-2006 Insecure.Com LLC. |
|---|
| 5 | # Copyright (C) 2007-2008 Adriano Monteiro Marques |
|---|
| 6 | # |
|---|
| 7 | # Author: Adriano Monteiro Marques <adriano@umitproject.org> |
|---|
| 8 | # |
|---|
| 9 | # This program is free software; you can redistribute it and/or modify |
|---|
| 10 | # it under the terms of the GNU General Public License as published by |
|---|
| 11 | # the Free Software Foundation; either version 2 of the License, or |
|---|
| 12 | # (at your option) any later version. |
|---|
| 13 | # |
|---|
| 14 | # This program is distributed in the hope that it will be useful, |
|---|
| 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 17 | # GNU General Public License for more details. |
|---|
| 18 | # |
|---|
| 19 | # You should have received a copy of the GNU General Public License |
|---|
| 20 | # along with this program; if not, write to the Free Software |
|---|
| 21 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|---|
| 22 | |
|---|
| 23 | import gtk |
|---|
| 24 | import cPickle |
|---|
| 25 | |
|---|
| 26 | from higwidgets.higdialogs import HIGAlertDialog |
|---|
| 27 | from higwidgets.higboxes import HIGHBox, HIGVBox |
|---|
| 28 | from higwidgets.higtables import HIGTable |
|---|
| 29 | from higwidgets.higlabels import HIGSectionLabel, HIGHintSectionLabel |
|---|
| 30 | |
|---|
| 31 | from umitCore.OSFingerprintRegister import OSFingerprintRegister |
|---|
| 32 | from umitCore.OSClassificationDump import os_classification_file |
|---|
| 33 | from umitCore.I18N import _ |
|---|
| 34 | |
|---|
| 35 | class OSFingerprintReport(gtk.Window, object): |
|---|
| 36 | def __init__(self, fingerprint, ip): |
|---|
| 37 | gtk.Window.__init__(self) |
|---|
| 38 | self.set_title(_('Operating System Fingerprint Report')) |
|---|
| 39 | self.set_position(gtk.WIN_POS_CENTER_ALWAYS) |
|---|
| 40 | |
|---|
| 41 | self.fingerprint = fingerprint |
|---|
| 42 | self.ip = ip |
|---|
| 43 | |
|---|
| 44 | self._create_widgets() |
|---|
| 45 | self._set_classification_list() |
|---|
| 46 | self._pack_widgets() |
|---|
| 47 | self._connect_widgets() |
|---|
| 48 | |
|---|
| 49 | def _set_classification_list(self): |
|---|
| 50 | class_file = open(os_classification_file, "rb") |
|---|
| 51 | class_list = cPickle.load(class_file) |
|---|
| 52 | class_file.close() |
|---|
| 53 | |
|---|
| 54 | for classification in class_list: |
|---|
| 55 | self.classification_list.append([classification[1], |
|---|
| 56 | classification[0]]) |
|---|
| 57 | |
|---|
| 58 | def _create_widgets(self): |
|---|
| 59 | self.vbox = HIGVBox() |
|---|
| 60 | self.button_box = gtk.HButtonBox() |
|---|
| 61 | |
|---|
| 62 | self.submitted_label = HIGHintSectionLabel(_("Submitted by (optional)"), |
|---|
| 63 | _("Enter your name and \ |
|---|
| 64 | e-mail address if we can contact you with any questions. (kept private, \ |
|---|
| 65 | used for nothing else)")) |
|---|
| 66 | self.submitted_entry = gtk.Entry() |
|---|
| 67 | |
|---|
| 68 | self.target_device_label = HIGHintSectionLabel(_("Target OS/device info"), |
|---|
| 69 | _("<b>The more details \ |
|---|
| 70 | the better!</b> For UNIX machines, '<i>uname -a</i>' often gives the proper \ |
|---|
| 71 | version number. On Linux, please also specify the distribution version (such as\ |
|---|
| 72 | Redhat 9.0) if you are using a vendor-provided kernel. For Windows, the \ |
|---|
| 73 | '<i>winver</i>' command (if available) should show you any service pack \ |
|---|
| 74 | information. If a Windows target has no service packs installed, \ |
|---|
| 75 | please say so explicitly. For appliances/embedded devices, please mention \ |
|---|
| 76 | the model number and what it is (printer, webcam, DSL router, VOIP phone, \ |
|---|
| 77 | etc). Try to provide the architecture (X86, SPARC, etc.) where appropriate.")) |
|---|
| 78 | self.target_device_entry = gtk.Entry() |
|---|
| 79 | |
|---|
| 80 | self.classification_label = HIGHintSectionLabel(_("Classification"), |
|---|
| 81 | _("Please select \ |
|---|
| 82 | the Device/OS info from this alphabetized choosebox")) |
|---|
| 83 | self.classification_list = gtk.ListStore(str, str) |
|---|
| 84 | self.classification_combo = gtk.ComboBoxEntry(self.classification_list, |
|---|
| 85 | 0) |
|---|
| 86 | |
|---|
| 87 | self.notes_label = HIGHintSectionLabel(_("Notes"), |
|---|
| 88 | _("Fill with further info on \ |
|---|
| 89 | the device, any special network conditions, etc.")) |
|---|
| 90 | self.notes_scrolled = gtk.ScrolledWindow() |
|---|
| 91 | self.notes_text = gtk.TextView() |
|---|
| 92 | |
|---|
| 93 | self.fingerprint_icon = gtk.Image() |
|---|
| 94 | self.fingerprint_text = gtk.Label(_("This form allows you to \ |
|---|
| 95 | contribute new operating system fingerprints to the Nmap database. Thanks for \ |
|---|
| 96 | helping! <b>Please do not fill this out unless you are sure that you know \ |
|---|
| 97 | what application is running on the machine you are submitting</b>. Incorrect \ |
|---|
| 98 | entries can pollute the database. By submitting fingerprints you are \ |
|---|
| 99 | transfering any copyright interest in the data to Fyodor so that he \ |
|---|
| 100 | can modify it, relicense it, incorporate it into programs such as Nmap, etc.")) |
|---|
| 101 | |
|---|
| 102 | self.btn_ok = gtk.Button(stock=gtk.STOCK_OK) |
|---|
| 103 | self.btn_cancel = gtk.Button(stock=gtk.STOCK_CANCEL) |
|---|
| 104 | |
|---|
| 105 | self.hbox = HIGHBox() |
|---|
| 106 | self.table = HIGTable() |
|---|
| 107 | |
|---|
| 108 | def _pack_widgets(self): |
|---|
| 109 | self.notes_scrolled.add(self.notes_text) |
|---|
| 110 | self.notes_scrolled.set_policy(gtk.POLICY_AUTOMATIC, |
|---|
| 111 | gtk.POLICY_AUTOMATIC) |
|---|
| 112 | self.notes_scrolled.set_size_request(400, 150) |
|---|
| 113 | self.notes_text.set_wrap_mode(gtk.WRAP_WORD) |
|---|
| 114 | |
|---|
| 115 | self.fingerprint_icon.set_from_stock(gtk.STOCK_DIALOG_INFO, |
|---|
| 116 | gtk.ICON_SIZE_DIALOG) |
|---|
| 117 | self.fingerprint_icon.set_padding(10, 0) |
|---|
| 118 | self.fingerprint_text.set_line_wrap(True) |
|---|
| 119 | self.fingerprint_text.set_use_markup(True) |
|---|
| 120 | |
|---|
| 121 | self.table.attach_label(self.submitted_label, 0, 1, 0, 1) |
|---|
| 122 | self.table.attach_entry(self.submitted_entry, 1, 2, 0, 1) |
|---|
| 123 | |
|---|
| 124 | self.table.attach_label(self.target_device_label, 0, 1, 1, 2) |
|---|
| 125 | self.table.attach_entry(self.target_device_entry, 1, 2, 1, 2) |
|---|
| 126 | |
|---|
| 127 | self.table.attach_label(self.classification_label, 0, 1, 2, 3) |
|---|
| 128 | self.table.attach_entry(self.classification_combo, 1, 2, 2, 3) |
|---|
| 129 | |
|---|
| 130 | self.table.attach_label(self.notes_label, 0, 2, 3, 4) |
|---|
| 131 | self.table.attach_entry(self.notes_scrolled, 0, 2, 4, 5) |
|---|
| 132 | |
|---|
| 133 | self.hbox.set_border_width(12) |
|---|
| 134 | self.hbox._pack_noexpand_nofill(self.fingerprint_icon) |
|---|
| 135 | self.hbox._pack_expand_fill(self.fingerprint_text) |
|---|
| 136 | |
|---|
| 137 | self.button_box.set_layout(gtk.BUTTONBOX_END) |
|---|
| 138 | self.button_box.pack_start(self.btn_ok) |
|---|
| 139 | self.button_box.pack_start(self.btn_cancel) |
|---|
| 140 | |
|---|
| 141 | self.vbox.set_border_width(6) |
|---|
| 142 | self.vbox._pack_noexpand_nofill(self.hbox) |
|---|
| 143 | self.vbox._pack_expand_fill(self.table) |
|---|
| 144 | self.vbox._pack_noexpand_nofill(self.button_box) |
|---|
| 145 | self.add(self.vbox) |
|---|
| 146 | |
|---|
| 147 | def _connect_widgets(self): |
|---|
| 148 | self.btn_ok.connect("clicked", self.send_report) |
|---|
| 149 | self.btn_cancel.connect("clicked", self.close) |
|---|
| 150 | self.connect("delete-event", self.close) |
|---|
| 151 | |
|---|
| 152 | def close(self, widget=None, event=None): |
|---|
| 153 | self.destroy() |
|---|
| 154 | |
|---|
| 155 | def send_report(self, widget): |
|---|
| 156 | if self.target_device == "": |
|---|
| 157 | cancel_dialog = HIGAlertDialog(type=gtk.MESSAGE_ERROR, |
|---|
| 158 | message_format=_("Operating System \ |
|---|
| 159 | Fingerprint report is incomplete!"), |
|---|
| 160 | secondary_text=_("The Operating \ |
|---|
| 161 | System Fingerprint report is incomplete. Please, try to provide as much \ |
|---|
| 162 | information as possible.")) |
|---|
| 163 | cancel_dialog.run() |
|---|
| 164 | cancel_dialog.destroy() |
|---|
| 165 | return None |
|---|
| 166 | |
|---|
| 167 | os_register = OSFingerprintRegister() |
|---|
| 168 | |
|---|
| 169 | os_register.email = self.submitted |
|---|
| 170 | os_register.os = self.target_device |
|---|
| 171 | os_register.classification = self.classification |
|---|
| 172 | os_register.ip = self.ip |
|---|
| 173 | os_register.fingerprint = self.fingerprint |
|---|
| 174 | os_register.notes = self.notes |
|---|
| 175 | |
|---|
| 176 | try: |
|---|
| 177 | os_register.report() |
|---|
| 178 | except: |
|---|
| 179 | cancel_dialog = HIGAlertDialog(type=gtk.MESSAGE_ERROR, |
|---|
| 180 | message_format=_("Operating System \ |
|---|
| 181 | Fingerprint not registered!"), |
|---|
| 182 | secondary_text=_("The Operating \ |
|---|
| 183 | System Fingerprint could not be registered. This problem may be caused by \ |
|---|
| 184 | the lack of Internet Access or indisponibility of the fingerprint server. \ |
|---|
| 185 | Please, verify your internet access, and then try to register the operating \ |
|---|
| 186 | system fingerprint once again.")) |
|---|
| 187 | cancel_dialog.run() |
|---|
| 188 | cancel_dialog.destroy() |
|---|
| 189 | else: |
|---|
| 190 | ok_dialog = HIGAlertDialog(type=gtk.MESSAGE_INFO, |
|---|
| 191 | message_format=_("Operating System \ |
|---|
| 192 | Fingerprint sucessfully registered!"), |
|---|
| 193 | secondary_text=_("The Operating System \ |
|---|
| 194 | Fingerprint was sucessfully registered. A web page with detailed description \ |
|---|
| 195 | about this registration is going to be openned in your default web browser.")) |
|---|
| 196 | ok_dialog.run() |
|---|
| 197 | ok_dialog.destroy() |
|---|
| 198 | |
|---|
| 199 | self.close() |
|---|
| 200 | |
|---|
| 201 | def run_unblocked(self): |
|---|
| 202 | if not self.modal: |
|---|
| 203 | self.set_modal(True) |
|---|
| 204 | self.show_all() |
|---|
| 205 | |
|---|
| 206 | def dialog_response_cb(self, dialog, response): |
|---|
| 207 | self.response_id = response |
|---|
| 208 | |
|---|
| 209 | def get_submitted(self): |
|---|
| 210 | return self.submitted_entry.get_text() |
|---|
| 211 | |
|---|
| 212 | def set_submitted(self, submitted): |
|---|
| 213 | self.submitted_entry.set_text(submitted) |
|---|
| 214 | |
|---|
| 215 | def get_target_device(self): |
|---|
| 216 | return self.target_device_entry.get_text() |
|---|
| 217 | |
|---|
| 218 | def set_target_device(self, target_device): |
|---|
| 219 | self.target_device_entry.set_text(target_device) |
|---|
| 220 | |
|---|
| 221 | def get_classification(self): |
|---|
| 222 | selected = self.classification_combo.child.get_text() |
|---|
| 223 | for i in self.classification_list: |
|---|
| 224 | if i[0] == selected: |
|---|
| 225 | return i[1] |
|---|
| 226 | return "" |
|---|
| 227 | |
|---|
| 228 | def set_classification(self, classification): |
|---|
| 229 | self.classification.child.set_text(classification) |
|---|
| 230 | |
|---|
| 231 | def get_notes(self): |
|---|
| 232 | buff = self.notes_text.get_buffer() |
|---|
| 233 | return buff.get_text(buff.get_start_iter(), buff.get_end_iter()) |
|---|
| 234 | |
|---|
| 235 | def set_notes(self, notes): |
|---|
| 236 | self.notes_text.get_buffer().set_text(notes) |
|---|
| 237 | |
|---|
| 238 | submitted = property(get_submitted, set_submitted) |
|---|
| 239 | target_device = property(get_target_device, set_target_device) |
|---|
| 240 | classification = property(get_classification, set_classification) |
|---|
| 241 | notes = property(get_notes, set_notes) |
|---|
| 242 | |
|---|
| 243 | if __name__ == "__main__": |
|---|
| 244 | w = OSFingerprintReport("Testing umit fingerprint submission", "IP Address") |
|---|
| 245 | w.connect("delete-event", lambda x, y: gtk.main_quit()) |
|---|
| 246 | w.show_all() |
|---|
| 247 | |
|---|
| 248 | gtk.main() |
|---|