Can't help with thread spec or length (the former probably common at M5 as most have stated, the latter will be relatively bike-specific I suspect). Only way to be sure is to pull it out and measure it!
I'd advise replacing with a stainless socket button cap - which will retain a similar low profile / aesthetic but with a nicer tool interface. I've replaced most of the standard fixings (for cable guide, guards, racks etc) on my bikes with these:
View attachment 761354
As
@grldtnr suggests A4 is the more corrosion-resistant commercially available grade. I'd be cautious of sticking a tap up the hole - instead an old M5 bolt with a slot or three cut along its threads (like the flutes in a tap) will chase the crap out of the threads with less risk of damaging the existing threads.
GWR fasteners are my go-to for common metric bolts.
I'd probably fit the new one with anti-seize grease..