Changeset 5424

Show
Ignore:
Timestamp:
03/01/08 22:46:13 (7 months ago)
Author:
hdm
Message:

Lots of updates related to <secret project X>.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • framework3/trunk/data/sql/mysql.sql

    r4177 r5424  
    22create table hosts ( 
    33id SERIAL PRIMARY KEY, 
     4created TIMESTAMP, 
    45address VARCHAR(16) UNIQUE, 
    56comm VARCHAR(255), 
     
    1314id SERIAL PRIMARY KEY, 
    1415host_id INTEGER, 
     16created TIMESTAMP, 
    1517port INTEGER NOT NULL, 
    1618proto VARCHAR(16) NOT NULL, 
     
    2426id SERIAL PRIMARY KEY, 
    2527service_id INTEGER, 
     28created TIMESTAMP, 
    2629name VARCHAR(255), 
    2730data TEXT 
     
    3235id SERIAL PRIMARY KEY, 
    3336ref_id INTEGER, 
     37created TIMESTAMP, 
    3438name VARCHAR(512) 
    3539); 
     
    4044vuln_id INTEGER 
    4145); 
     46 
     47 
     48create table notes ( 
     49id SERIAL PRIMARY KEY, 
     50host_id INTEGER, 
     51created TIMESTAMP, 
     52ntype VARCHAR(512), 
     53data TEXT 
     54); 
  • framework3/trunk/data/sql/postgres.sql

    r3904 r5424  
    33create table hosts ( 
    44id SERIAL PRIMARY KEY, 
     5created TIMESTAMP, 
    56address VARCHAR(16) UNIQUE, 
    67comm VARCHAR(255), 
     
    1516id SERIAL PRIMARY KEY, 
    1617host_id INTEGER, 
     18created TIMESTAMP, 
    1719port INTEGER NOT NULL, 
    1820proto VARCHAR(16) NOT NULL, 
     
    2729id SERIAL PRIMARY KEY, 
    2830service_id INTEGER, 
     31created TIMESTAMP, 
    2932name VARCHAR(255), 
    3033data TEXT 
     
    3639id SERIAL PRIMARY KEY, 
    3740ref_id INTEGER, 
     41created TIMESTAMP, 
    3842name VARCHAR(512) 
    3943); 
     
    4549vuln_id INTEGER 
    4650); 
     51 
     52drop table notes 
     53 
     54create table notes ( 
     55id SERIAL PRIMARY KEY, 
     56host_id INTEGER, 
     57created TIMESTAMP, 
     58ntype VARCHAR(512), 
     59data TEXT 
     60); 
  • framework3/trunk/data/sql/sqlite.sql

    r5276 r5424  
    22create table hosts ( 
    33'id' INTEGER PRIMARY KEY NOT NULL, 
     4'created' TIMESTAMP, 
    45'address' VARCHAR(16) UNIQUE, 
    56'comm' VARCHAR(255), 
     
    1314'id' INTEGER PRIMARY KEY NOT NULL, 
    1415'host_id' INTEGER, 
     16'created' TIMESTAMP, 
    1517'port' INTEGER NOT NULL, 
    1618'proto' VARCHAR(16) NOT NULL, 
     
    2426'id' INTEGER PRIMARY KEY NOT NULL, 
    2527'service_id' INTEGER, 
     28'created' TIMESTAMP, 
    2629'name' VARCHAR(1024), 
    2730'data' TEXT 
     
    3235'id' INTEGER PRIMARY KEY NOT NULL, 
    3336'ref_id' INTEGER, 
     37'created' TIMESTAMP, 
    3438'name' VARCHAR(512) 
    3539); 
     
    4044'vuln_id' INTEGER 
    4145); 
     46 
     47drop table notes; 
     48create table notes ( 
     49'id' INTEGER PRIMARY KEY NOT NULL, 
     50'created' TIMESTAMP, 
     51'host_id' INTEGER, 
     52'ntype' VARCHAR(512), 
     53'data' TEXT 
     54); 
  • framework3/trunk/lib/msf/core/auxiliary/report.rb

    r3820 r5424  
    1212# Report host and service information 
    1313# 
     14                         
     15        # Shortcut method for detecting when the DB is active 
     16        def db 
     17                framework.db.active 
     18        end 
     19         
    1420        def report_host(opts) 
    1521                return if not db 
     
    4046                end 
    4147        end 
     48 
     49        def report_note(opts={}) 
     50                return if not db 
     51                addr  = opts[:host]  || return 
     52                ntype = opts[:type]  || return 
     53                data  = opts[:data]  || return 
     54 
     55                host  = framework.db.report_host_state(self, addr, Msf::HostState::Alive) 
     56                note  = framework.db.get_note(self, host, ntype, data) 
     57        end 
     58 
     59        def report_auth_info(opts={})            
     60                addr  = opts[:host]   || return 
     61                data  = opts[:proto]  || return 
    4262                 
    43         # Shortcut method for detecting when the DB is active 
    44         def db 
    45                 framework.db.active 
     63                opts[:type] = "auth_#{opts[:proto]}" 
     64                opts[:data] =  
     65                        "AUTH #{ opts[:targ_host] || 'unknown' }:#{ opts[:targ_port] || 'unknown' } " + 
     66                        "#{opts[:user] || "<NULL>"} #{opts[:pass] || "<NULL>" } #{opts[:extra]}" 
     67                report_note(opts)        
    4668        end 
     69 
    4770 
    4871end 
  • framework3/trunk/lib/msf/core/db.rb

    r4472 r5424  
    194194                Vuln.find(:all) 
    195195        end 
    196          
     196 
     197 
     198        # 
     199        # This method iterates the notes table calling the supplied block with the 
     200        # note instance of each entry. 
     201        # 
     202        def each_note(&block) 
     203                notes.each do |note| 
     204                        block.call(note) 
     205                end 
     206        end 
     207         
     208        # 
     209        # This methods returns a list of all notes in the database 
     210        # 
     211        def notes 
     212                Note.find(:all) 
     213        end 
     214                 
    197215        # 
    198216        # Find or create a host matching this address/comm 
     
    201219                host = Host.find(:first, :conditions => [ "address = ? and comm = ?", address, comm]) 
    202220                if (not host) 
    203                         host = Host.create(:address => address, :comm => comm, :state => HostState::Unknown
     221                        host = Host.create(:address => address, :comm => comm, :state => HostState::Unknown, :created => Time.now
    204222                        host.save 
    205223                        framework.events.on_db_host(context, host) 
     
    219237                                :proto      => proto, 
    220238                                :port       => port, 
    221                                 :state      => state 
     239                                :state      => state, 
     240                                :created    => Time.now 
    222241                        ) 
    223242                        rec.save 
     
    236255                                :service_id => service.id, 
    237256                                :name       => name, 
    238                                 :data       => data 
     257                                :data       => data, 
     258                                :created    => Time.now 
    239259                        ) 
    240260                        vuln.save 
     
    252272                if (not ref) 
    253273                        ref = Ref.create( 
    254                                 :name       => name 
     274                                :name       => name, 
     275                                :created    => Time.now 
    255276                        ) 
    256277                        ref.save 
     
    261282        end 
    262283 
     284        # 
     285        # Find or create a note matching this type/data 
     286        #        
     287        def get_note(context, host, ntype, data) 
     288                rec = Note.find(:first, :conditions => [ "host_id = ? and ntype = ? and data = ?", host.id, ntype, data]) 
     289                if (not rec) 
     290                        rec = Note.create( 
     291                                :host_id    => host.id, 
     292                                :ntype      => ntype, 
     293                                :data       => data, 
     294                                :created    => Time.now 
     295                        ) 
     296                        rec.save 
     297                        framework.events.on_db_note(context, rec) 
     298                end 
     299                return rec 
     300        end 
     301         
    263302        # 
    264303        # Find a reference matching this name 
  • framework3/trunk/lib/msf/core/db_objects.rb

    r3902 r5424  
    8585end 
    8686 
     87 
     88# Service object definition 
     89class Note < ActiveRecord::Base 
     90        include DBSave 
     91        belongs_to :host 
     92 
     93        def host 
     94                Host.find(:first, :conditions => [ "id = ?", host_id ]) 
     95        end      
     96end 
     97 
    8798end 
    8899end 
  • framework3/trunk/lib/msf/ui/console/command_dispatcher/db.rb

    r5247 r5424  
    3333                                "db_services" => "List all services in the database", 
    3434                                "db_vulns"    => "List all vulnerabilities in the database", 
     35                                "db_notes"    => "List all notes in the database", 
    3536                                "db_add_host" => "Add one or more hosts to the database", 
    3637                                "db_add_port" => "Add a port to host", 
     38                                "db_add_note" => "Add a note to host", 
    3739                                "db_autopwn"  => "Automatically exploit everything", 
    3840                                "db_import_nessus_nbe" => "Import a Nessus scan result file (NBE)", 
     
    4446                def cmd_db_hosts(*args) 
    4547                        framework.db.each_host do |host| 
    46                                 print_status("Host: #{host.address}") 
     48                                print_status("Time: #{host.created} Host: #{host.address}") 
    4749                        end 
    4850                end 
     
    5052                def cmd_db_services(*args) 
    5153                        framework.db.each_service do |service| 
    52                                 print_status("Service: host=#{service.host.address} port=#{service.port} proto=#{service.proto} state=#{service.state} name=#{service.name}")                  
     54                                print_status("Time: #{service.created}] Service: host=#{service.host.address} port=#{service.port} proto=#{service.proto} state=#{service.state} name=#{service.name}")                        
    5355                        end 
    5456                end              
     
    5759                        framework.db.each_vuln do |vuln| 
    5860                                reflist = vuln.refs.map { |r| r.name } 
    59                                 print_status("Vuln: host=#{vuln.host.address} port=#{vuln.service.port} proto=#{vuln.service.proto} name=#{vuln.name} refs=#{reflist.join(',')}") 
     61                                print_status("Time: #{vuln.created} Vuln: host=#{vuln.host.address} port=#{vuln.service.port} proto=#{vuln.service.proto} name=#{vuln.name} refs=#{reflist.join(',')}") 
    6062                        end 
    6163                end      
    62                  
     64 
     65                def cmd_db_notes(*args) 
     66                        framework.db.each_note do |note| 
     67                                print_status("Time: #{note.created} Note: host=#{note.host.address} type=#{note.ntype} data=#{note.data}")                       
     68                        end 
     69                end      
     70                                 
    6371                def cmd_db_add_host(*args) 
    6472                        print_status("Adding #{args.length.to_s} hosts...") 
    6573                        args.each do |address| 
    66                                 framework.db.get_host(nil, address) 
     74                                host = framework.db.get_host(nil, address) 
     75                                print_status("Time: #{host.created} Host: host=#{service.host.address}") 
    6776                        end 
    6877                end 
     
    8089                        return if not service 
    8190                         
    82                         print_status("Service: host=#{service.host.address} port=#{service.port} proto=#{service.proto} state=#{service.state}") 
    83                 end 
    84  
     91                        print_status("Time: #{service.created} Service: host=#{service.host.address} port=#{service.port} proto=#{service.proto} state=#{service.state}") 
     92                end 
     93 
     94                def cmd_db_add_note(*args) 
     95                        if (not args or args.length < 3) 
     96                                print_status("Usage: db_add_note [host] [type] [note]") 
     97                                return 
     98                        end 
     99 
     100                        naddr = args.shift  
     101                        ntype = args.shift 
     102                        ndata = args.join(" ") 
     103 
     104                        host = framework.db.get_host(nil, naddr) 
     105                        return if not host 
     106                         
     107                        note = framework.db.get_note(nil, host, ntype, ndata) 
     108                        return if not note 
     109                         
     110                        print_status("Time: #{note.created} Note: host=#{note.host.address} type=#{note.ntype} data=#{note.data}") 
     111                end 
     112                 
    85113                # 
    86114                # A shotgun approach to network-wide exploitation 
  • framework3/trunk/lib/rex/proto/smb/client.rb

    r5015 r5424  
    829829                self.smb_send(pkt.to_s) 
    830830                self.smb_recv_parse(CONST::SMB_COM_SESSION_SETUP_ANDX, false) 
     831        end      
     832 
     833 
     834        # Authenticate using extended security negotiation (NTLMv2), but stop half-way, using the temporary ID 
     835        def session_setup_ntlmv2_temp(domain = '', name = nil) 
     836         
     837                if (name == nil) 
     838                        name = Rex::Text.rand_text_alphanumeric(16) 
     839                end 
     840                 
     841                blob = UTILS.make_ntlmv2_secblob_init(domain, name) 
     842                 
     843                native_data = '' 
     844                native_data << self.native_os + "\x00" 
     845                native_data << self.native_lm + "\x00"           
     846 
     847                pkt = CONST::SMB_SETUP_NTLMV2_PKT.make_struct 
     848                self.smb_defaults(pkt['Payload']['SMB']) 
     849                                 
     850                pkt['Payload']['SMB'].v['Command'] = CONST::SMB_COM_SESSION_SETUP_ANDX 
     851                pkt['Payload']['SMB'].v['Flags1'] = 0x18 
     852                pkt['Payload']['SMB'].v['Flags2'] = 0x2801 
     853                pkt['Payload']['SMB'].v['WordCount'] = 12 
     854                pkt['Payload'].v['AndX'] = 255 
     855                pkt['Payload'].v['MaxBuff'] = 0xffdf 
     856                pkt['Payload'].v['MaxMPX'] = 2 
     857                pkt['Payload'].v['VCNum'] = 1            
     858                pkt['Payload'].v['SecurityBlobLen'] = blob.length 
     859                pkt['Payload'].v['Capabilities'] = 0x8000d05c 
     860                pkt['Payload'].v['SessionKey'] = self.session_id 
     861                pkt['Payload'].v['Payload'] = blob + native_data  
     862                 
     863                self.smb_send(pkt.to_s) 
     864                ack = self.smb_recv_parse(CONST::SMB_COM_SESSION_SETUP_ANDX, true) 
     865                 
     866                # The server doesn't know about NTLM_NEGOTIATE, try ntlmv1 
     867                if (ack['Payload']['SMB'].v['ErrorClass'] == 0x00020002) 
     868                        return session_setup_ntlmv1(user, pass, domain) 
     869                end 
     870                 
     871                # Make sure the error code tells us to continue processing 
     872                if (ack['Payload']['SMB'].v['ErrorClass'] != 0xc0000016) 
     873                        failure = XCEPT::ErrorCode.new 
     874                        failure.word_count = ack['Payload']['SMB'].v['WordCount'] 
     875                        failure.command = ack['Payload']['SMB'].v['Command'] 
     876                        failure.error_code = ack['Payload']['SMB'].v['ErrorClass'] 
     877                        raise failure 
     878                end 
     879 
     880                # Extract the SecurityBlob from the response 
     881                data = ack['Payload'].v['Payload'] 
     882                blob = data.slice!(0, ack['Payload'].v['SecurityBlobLen']) 
     883 
     884                # Extract the native lanman and os strings 
     885                info = data.split(/\x00/) 
     886                self.peer_native_os = info[0] 
     887                self.peer_native_lm = info[1] 
     888                 
     889                # Save the temporary UserID for use in the next request 
     890                self.auth_user_id = ack['Payload']['SMB'].v['UserID'] 
     891                 
     892                # Extract the NTLM challenge key the lazy way 
     893                cidx = blob.index("NTLMSSP\x00\x02\x00\x00\x00") 
     894                 
     895                if (cidx == -1) 
     896                        raise XCEPT::NTLM2MissingChallenge 
     897                end 
     898                 
     899                # Store the challenge key 
     900                self.challenge_key = blob[cidx + 24, 8] 
     901                 
     902                return ack 
    831903        end      
    832904 
     
    15921664         
    15931665# private methods 
    1594 protected 
    15951666        attr_writer             :dialect, :session_id, :challenge_key, :peer_native_lm, :peer_native_os 
    15961667        attr_writer             :default_domain, :default_name, :auth_user, :auth_user_id