@@ -12,10 +12,10 @@ class Metasploit3 < Msf::Auxiliary
12
12
13
13
def initialize ( info = { } )
14
14
super ( update_info ( info ,
15
- 'Name' => 'F5 Bigip Backend IP/PORT Cookie Disclosure. ' ,
15
+ 'Name' => 'F5 BigIP Backend Cookie Disclosure' ,
16
16
'Description' => %q{
17
- This module identify F5 BigIP SLB and decode sticky cookies which leak
18
- backend IP and port .
17
+ This module identify F5 BigIP Load Balancers and leaks backends
18
+ information through cookies .
19
19
} ,
20
20
'Author' => [ 'Thanat0s <thanspam[at]trollprod.org>' ] ,
21
21
'References' =>
@@ -29,66 +29,97 @@ def initialize(info = {})
29
29
register_options (
30
30
[
31
31
OptString . new ( 'TARGETURI' , [ true , 'The URI path to test' , '/' ] ) ,
32
- OptInt . new ( 'RETRY ' , [ true , 'Number of requests to try to find backends ' , 10 ] )
32
+ OptInt . new ( 'REQUESTS ' , [ true , 'Number of requests to send to disclose back ' , 10 ] )
33
33
] , self . class )
34
34
end
35
35
36
+ def change_endianness ( value , size = 4 )
37
+ conversion = value
38
+
39
+ if size == 4
40
+ conversion = [ value ] . pack ( "V" ) . unpack ( "N" ) . first
41
+ elsif size == 2
42
+ conversion = [ value ] . pack ( "v" ) . unpack ( "n" ) . first
43
+ end
44
+
45
+ conversion
46
+ end
47
+
36
48
def cookie_decode ( cookie_value )
37
- m = cookie_value . match ( /(\d +)\. (\d +)\. / )
38
- host = ( m . nil? ) ? nil : m [ 1 ]
39
- port = ( m . nil? ) ? nil : m [ 2 ]
40
- unless host . nil? && port . nil?
41
- port = ( ( "%04X" % port ) . slice ( 2 , 4 ) << ( "%04X" % port ) . slice ( 0 , 2 ) ) . hex . to_s
42
- byte1 = ( "%08X" % host ) . slice ( 6 ..7 ) . hex . to_s
43
- byte2 = ( "%08X" % host ) . slice ( 4 ..5 ) . hex . to_s
44
- byte3 = ( "%08X" % host ) . slice ( 2 ..3 ) . hex . to_s
45
- byte4 = ( "%08X" % host ) . slice ( 0 ..1 ) . hex . to_s
46
- host = byte1 << "." << byte2 << "." << byte3 << "." << byte4
49
+ back_end = ""
50
+
51
+ if cookie_value =~ /(\d {8})\. (\d {5})\. /
52
+ host = $1. to_i
53
+ port = $2. to_i
54
+
55
+ host = change_endianness ( host )
56
+ host = Rex ::Socket . addr_itoa ( host )
57
+
58
+ port = change_endianness ( port , 2 )
59
+
60
+ back_end = "#{ host } :#{ port } "
47
61
end
48
- return host , port
62
+
63
+ back_end
49
64
end
50
65
51
66
def get_cookie # request a page and extract a F5 looking cookie.
67
+ cookie = { }
52
68
res = send_request_raw ( {
53
69
'method' => 'GET' ,
54
70
'uri' => @uri
55
71
} )
56
- id , value = nil
57
- # Get the SLB session ID, like "TestCookie=2263487148.3013.0000"
58
- m = res . get_cookies . match ( /([\- \w \d ]+)=((?:\d +\. ){2}\d +)(?:$|,|;|\s )/ )
59
- unless m . nil?
60
- id = ( m . nil? ) ? nil : m [ 1 ]
61
- value = ( m . nil? ) ? nil : m [ 2 ]
62
- return id , value
72
+
73
+ unless res . nil?
74
+ # Get the SLB session ID, like "TestCookie=2263487148.3013.0000"
75
+ m = res . get_cookies . match ( /([\- \w \d ]+)=((?:\d +\. ){2}\d +)(?:$|,|;|\s )/ )
76
+ unless m . nil?
77
+ cookie [ :id ] = ( m . nil? ) ? nil : m [ 1 ]
78
+ cookie [ :value ] = ( m . nil? ) ? nil : m [ 2 ]
79
+ end
63
80
end
81
+
82
+ cookie
64
83
end
65
84
66
85
def run
67
- host_port = [ ]
68
- @uri = normalize_uri ( target_uri . path )
69
- print_status ( "Starting request #{ @uri } " )
70
- for i in 0 ...datastore [ 'RETRY' ]
71
- id , value = get_cookie ( ) # Get the cookie
86
+ unless datastore [ 'REQUESTS' ] > 0
87
+ print_error ( "Please, configure more than 0 REQUESTS" )
88
+ return
89
+ end
90
+
91
+ back_ends = [ ]
92
+ @uri = normalize_uri ( target_uri . path . to_s )
93
+ print_status ( "#{ peer } - Starting request #{ @uri } " )
94
+
95
+ for i in 0 ...datastore [ 'REQUESTS' ]
96
+ cookie = get_cookie ( ) # Get the cookie
72
97
# If the cookie is not found, stop process
73
- unless id
74
- print_error ( "F5 SLB cookie not found" )
75
- return
98
+ if cookie . empty? || cookie [ :id ] . nil?
99
+ print_error ( "#{ peer } - F5 Server Load Balancing cookie not found" )
100
+ break
76
101
end
102
+
77
103
# Print the cookie name on the first request
78
104
if i == 0
79
- print_status ( "F5 cookie \" #{ id } \" found" )
105
+ print_status ( "#{ peer } - F5 Server Load Balancing \" #{ cookie [ :id ] } \" found" )
80
106
end
81
- host , port = cookie_decode ( value )
82
- unless host_port . include? ( host +":" +port )
83
- host_port . push ( host +":" +port )
84
- print_status ( "Backend #{ host } :#{ port } " )
107
+
108
+ back_end = cookie_decode ( cookie [ :value ] )
109
+ unless back_ends . include? ( back_end )
110
+ print_status ( "#{ peer } - Backend #{ back_end } found" )
111
+ back_ends . push ( back_end )
85
112
end
86
113
end
114
+
87
115
# Reporting found backends in database
88
- report_note (
89
- :host => rhost ,
90
- :type => "F5_Cookie_Backends" ,
91
- :data => host_port
92
- )
116
+ unless back_ends . empty?
117
+ report_note (
118
+ :host => rhost ,
119
+ :type => "f5_load_balancer_backends" ,
120
+ :data => back_ends
121
+ )
122
+ end
123
+
93
124
end
94
125
end
0 commit comments