I can't speak for the TEM in STEM, but for science it doesn't really matter that much where you do your undergrad. In fact, if you choose well, it's better to go to a less prestigious university if you will have an opportunity to do actual research (and take full advantage of that opportunity). It's a lot more important to have solid bench experience than a degree from Harvard. A degree is just a piece of paper. If you aren't happy with where you're at when you are finishing up your undergrad, you should also consider using a masters degree as a stepping stone to a better PhD program. It matters a lot more who you do your PhD and postdoc with (and to a lesser extent where).
On the issue of brains and talent, this is something I didn't appreciate for a long time. People get to the top through a lot of hard work and dedication. It's not like a Hollywood movie where there are people that are just born brilliant and are able to make things happen without effort. When you see someone college-age doing amazing things, it's usually because they've been working at it for a long time before college. If you focus beyond just passing tests, four years is a fair amount of time to catch up. When you see a brilliant 60 year old scientist, that outcome is the result of a career of hard work.
You will go far if you spend some time thinking about what you need to do to get yourself to the next level and start acting like it. If you want to be in academia, be the undergrad that thinks and works like a grad student. When you're a grad student, act like a postdoc; when you're a postdoc, act like a professor. And it shouldn't be just an act, you need to actually take on the responsibilities and do the work of someone at the next level. Let your work speak for itself rather pretending to be at the next level by talking down to your peers. When you think this way, it makes it very easy to take the next step. People making the hiring decisions won't have to think very hard to imagine you stepping up to the next level.