root/trunk/umitGUI/OSFingerprintReport.py @ 2851

Revision 2851, 9.8 kB (checked in by ggpolo, 5 years ago)

Always use binary mode when playing with cPickle. This fixes issue #1879476 and possible others if there are more related to EOFError and pickle.

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