Brake levers are relatively exposed on the bike. Many crash situations can end up with bent or broken levers. If the lever is aluminum, and has bent out of shape, leave it that way if at all possible. The extra stress of bending it back may snap it off.
Assuming however that you have ripped the lever right off the bike, but that the lever body is still functional, you may still be able to use the brake.
Rim brakes – if there’s a section of cable without housing round it, for instance the rear brake routing along the top tube- you can pull on this to pull the brake on. Loop a zip tie round the bare cable to more easily locate it and to use as a pull.
Hydraulic brakes – less leverage is required to hold the brake on, so you may be able to lash a stick or tool (screwdriver, Allen wrench) to the remaining part of the lever with zip ties. The lever typically pushes against a small piston inside the lever body. If there isn’t sufficient lever left, you may be able to use the stub as a leverage point for a new lever, which in turn pushes against the piston.
What not to do
There’s an old BMX trick that involves slowing the bike down by pushing the sole of your shoe against the rear tire. Not only is this incredibly dangerous with knobby mountain bike tires, it also requires more agility than you’d expect. Don’t try it.