@@ -17,38 +17,43 @@ class MetasploitModule < Msf::Auxiliary
17
17
18
18
def initialize
19
19
super (
20
- 'Name' => 'pSnuffle Packet Sniffer' ,
21
- 'Description' => 'This module sniffs passwords like dsniff did in the past' ,
22
- 'Author' => 'Max Moser <mmo[at]remote-exploit.org>' ,
23
- 'License' => MSF_LICENSE ,
24
- 'Actions' =>
25
- [
26
- [ 'Sniffer' , 'Description' => 'Run sniffer' ] ,
27
- [ 'List' , 'Description' => 'List protocols' ]
28
- ] ,
20
+ 'Name' => 'pSnuffle Packet Sniffer' ,
21
+ 'Description' => 'This module sniffs passwords like dsniff did in the past.' ,
22
+ 'Author' => 'Max Moser <mmo[at]remote-exploit.org>' ,
23
+ 'License' => MSF_LICENSE ,
24
+ 'Actions' => [
25
+ [ 'Sniffer' , { 'Description' => 'Run sniffer' } ] ,
26
+ [ 'List' , { 'Description' => 'List protocols' } ]
27
+ ] ,
29
28
'PassiveActions' => [ 'Sniffer' ] ,
30
- 'DefaultAction' => 'Sniffer'
29
+ 'DefaultAction' => 'Sniffer' ,
30
+ 'Notes' => {
31
+ 'Stability' => [ CRASH_SAFE ] ,
32
+ 'SideEffects' => [ ] ,
33
+ 'Reliability' => [ ]
34
+ }
31
35
)
36
+
32
37
register_options [
33
38
OptString . new ( 'PROTOCOLS' , [ true , 'A comma-delimited list of protocols to sniff or "all".' , 'all' ] ) ,
34
39
]
35
40
36
41
register_advanced_options [
37
- OptPath . new ( 'ProtocolBase' , [ true , 'The base directory containing the protocol decoders' ,
42
+ OptPath . new ( 'ProtocolBase' , [
43
+ true , 'The base directory containing the protocol decoders' ,
38
44
File . join ( Msf ::Config . data_directory , 'exploits' , 'psnuffle' )
39
45
] ) ,
40
46
]
41
47
deregister_options ( 'RHOSTS' )
42
48
end
43
49
44
-
45
50
def load_protocols
46
51
base = datastore [ 'ProtocolBase' ]
47
52
unless File . directory? base
48
- raise RuntimeError , 'The ProtocolBase parameter is set to an invalid directory'
53
+ raise 'The ProtocolBase parameter is set to an invalid directory'
49
54
end
50
55
51
- allowed = datastore [ 'PROTOCOLS' ] . split ( ',' ) . map { |x | x . strip . downcase }
56
+ allowed = datastore [ 'PROTOCOLS' ] . split ( ',' ) . map { |x | x . strip . downcase }
52
57
@protos = { }
53
58
decoders = Dir . new ( base ) . entries . grep ( /\. rb$/ ) . sort
54
59
decoders . each do |n |
@@ -57,15 +62,15 @@ def load_protocols
57
62
begin
58
63
m . module_eval ( File . read ( f , File . size ( f ) ) )
59
64
m . constants . grep ( /^Sniffer(.*)/ ) do
60
- proto = $1
65
+ proto = :: Regexp . last_match ( 1 )
61
66
next unless allowed . include? ( proto . downcase ) || datastore [ 'PROTOCOLS' ] == 'all'
62
67
63
68
klass = m . const_get ( "Sniffer#{ proto } " )
64
69
@protos [ proto . downcase ] = klass . new ( framework , self )
65
70
66
71
print_status ( "Loaded protocol #{ proto } from #{ f } ..." )
67
72
end
68
- rescue => e
73
+ rescue StandardError => e
69
74
print_error ( "Decoder #{ n } failed to load: #{ e . class } #{ e } #{ e . backtrace } " )
70
75
end
71
76
end
@@ -88,6 +93,7 @@ def run
88
93
p = PacketFu ::Packet . parse ( pkt )
89
94
next unless p . is_tcp?
90
95
next if p . payload . empty?
96
+
91
97
@protos . each_key do |k |
92
98
@protos [ k ] . parse ( p )
93
99
end
@@ -107,13 +113,13 @@ class BaseProtocolParser
107
113
108
114
def initialize ( framework , mod )
109
115
self . framework = framework
110
- self . module = mod
111
- self . sessions = { }
112
- self . dport = 0
116
+ self . module = mod
117
+ self . sessions = { }
118
+ self . dport = 0
113
119
register_sigs
114
120
end
115
121
116
- def parse ( pkt )
122
+ def parse ( _pkt )
117
123
nil
118
124
end
119
125
@@ -166,12 +172,12 @@ def report_cred(opts)
166
172
self . module . create_credential_login ( login_data )
167
173
end
168
174
169
- def report_note ( *s )
170
- self . module . report_note ( *s )
175
+ def report_note ( *opts )
176
+ self . module . report_note ( *opts )
171
177
end
172
178
173
- def report_service ( *s )
174
- self . module . report_service ( *s )
179
+ def report_service ( *opts )
180
+ self . module . report_service ( *opts )
175
181
end
176
182
177
183
def find_session ( sessionid )
@@ -184,39 +190,39 @@ def find_session(sessionid)
184
190
purge_keys << ses
185
191
end
186
192
end
187
- purge_keys . each { |ses | sessions . delete ( ses ) }
193
+ purge_keys . each { |ses | sessions . delete ( ses ) }
188
194
189
195
# Does this session already exist?
190
- if ( sessions [ sessionid ] )
196
+ if sessions [ sessionid ]
191
197
# Refresh the timestamp
192
198
sessions [ sessionid ] [ :mtime ] = Time . now
193
- else
199
+ elsif ( sessionid =~ /^([^:]+):([^-]+)-([^:]+):( \d +)$/s )
194
200
# Create a new session entry along with the host/port from the id
195
- if ( sessionid =~ /^([^:]+):([^-]+)-([^:]+):(\d +)$/s )
196
- sessions [ sessionid ] = {
197
- :client_host => $1,
198
- :client_port => $2,
199
- :host => $3,
200
- :port => $4,
201
- :session => sessionid ,
202
- :ctime => Time . now ,
203
- :mtime => Time . now
204
- }
205
- end
201
+ sessions [ sessionid ] = {
202
+ client_host : ::Regexp . last_match ( 1 ) ,
203
+ client_port : ::Regexp . last_match ( 2 ) ,
204
+ host : ::Regexp . last_match ( 3 ) ,
205
+ port : ::Regexp . last_match ( 4 ) ,
206
+ session : sessionid ,
207
+ ctime : Time . now ,
208
+ mtime : Time . now
209
+ }
206
210
end
207
211
208
212
sessions [ sessionid ]
209
213
end
210
214
211
215
def get_session_src ( pkt )
212
- return "%s:%d-%s:%d" % [ pkt . ip_daddr , pkt . tcp_dport , pkt . ip_saddr , pkt . tcp_sport ] if pkt . is_tcp?
213
- return "%s:%d-%s:%d" % [ pkt . ip_daddr , pkt . udp_dport , pkt . ip_saddr , pkt . udp_sport ] if pkt . is_udp?
214
- return "%s:%d-%s:%d" % [ pkt . ip_daddr , 0 , pkt . ip_saddr , 0 ]
216
+ return "#{ pkt . ip_daddr } :#{ pkt . tcp_dport } -#{ pkt . ip_saddr } -#{ pkt . tcp_sport } " if pkt . is_tcp?
217
+ return "#{ pkt . ip_daddr } :#{ pkt . udp_dport } -#{ pkt . ip_saddr } -#{ pkt . udp_sport } " if pkt . is_udp?
218
+
219
+ "#{ pkt . ip_daddr } :0-#{ pkt . ip_saddr } :0"
215
220
end
216
221
217
222
def get_session_dst ( pkt )
218
- return "%s:%d-%s:%d" % [ pkt . ip_saddr , pkt . tcp_sport , pkt . ip_daddr , pkt . tcp_dport ] if pkt . is_tcp?
219
- return "%s:%d-%s:%d" % [ pkt . ip_saddr , pkt . udp_sport , pkt . ip_daddr , pkt . udp_dport ] if pkt . is_udp?
220
- return "%s:%d-%s:%d" % [ pkt . ip_saddr , 0 , pkt . ip_daddr , 0 ]
223
+ return "#{ pkt . ip_saddr } :#{ pkt . tcp_sport } -#{ pkt . ip_daddr } :#{ pkt . tcp_dport } " if pkt . is_tcp?
224
+ return "#{ pkt . ip_saddr } :#{ pkt . udp_sport } -#{ pkt . ip_daddr } :#{ pkt . udp_dport } " if pkt . is_udp?
225
+
226
+ "#{ pkt . ip_saddr } :0-#{ pkt . ip_daddr } :0"
221
227
end
222
228
end
0 commit comments