Taking the point of homogeneity, internal structure and our knowledge of so called M-type asteroids further.
Given how data has been collected for some of the larger M-type asteroids there is still some uncertainty regarding the homogeneity and internal structure of such asteroids.
One of the better indicators of the homogeneity and internal structure of a asteroid is it bulk density. The higher the density, around 8 g/cm3, the more likely its internal structure will resemble a block of metal. The density of iron is 7.87 g/cm3, steel 8 g/cm3 and copper is 8.93 g/cm3. Obtaining the bulk density of an asteroid is difficult because accurate measurements of its mass and volume are required.
A number of the large M-type asteroids have bulk densities between 3 and 4 g/cm3. This indicates such asteroids may be porous and thus more consistent with a rubble pile or they may contain silicate minerals and thus resemble stones (crystalline) - something analogous to basalt which has and average density of 2.9 g/cm3.
Returning to your question. Using a high powered nail gun on a block of metal might work if surface debris can be removed prior to using the nail gun. If used on a crystalline metal rich asteroid, a nail gun could shatter the asteroid or break it up into discrete chucks, particularly if the asteroid contain discontinuities and planes of weakness. I would not recommend considering using a nail gun on a rubble pile.
Alternatively, resin grouted rock bolts might be an option. A hole would be drilled into the asteroid, preferably under rotation, with no hammer to minimize the possibility damaging the asteroid. Clean the hole with a blast of air. Insert the anchoring bolt with a resin cartridge and rotate to break the cartridge and encase its contents around the bolt.
For the resin to set a setting agent is required. This can either be done by inserting a cartridge of resin and one of the setting agent. Alternatively single cartridges are available that contain both, each separated by a membrane. Rotating the bolt and the cartridge breaks up the cartridge and given the correct rotation time everything sets nicely. To assist with mixing the resin, the part of the anchor inside the hole would have flat "paddles" or flared out parts along its shaft.
If resin bolts aren't practical, then mechanical anchoring, where a deformable barb, or expansion shell grabs the sides of the drilled hole, securing the anchor.