While (barely) possible this seems unlikely, especially in a time frame that would be useful to you. You would need to find a university, hopefully a reputable one, willing to do it as well as a problem significant enough to have the faculty there agree that you had covered all the necessary bases.
It is also unlikely that very many people would be able to gain the necessary knowledge both about the field and about research to make this common enough that people would consider it. One of the problems is that you can learn on your own but focused learning usually (i.e. most people) requires guidance. That is what graduate, especially doctoral programs, are all about: both the what and the how of contributions to scholarship.
Some people have been awarded honorary degrees, which don't carry quite the same weight, for their work outside academia that contributes something important, or even a lifetime of contributions.
See the canonical question about doctoral admissions to see what is usually required before you are even allowed to begin doctoral study.
It is a lot more than being about being "smart" or "knowing a lot" of stuff.
But it is rare because so few could begin to do it, so it hasn't been considered enough to be an option in almost every case. And it is also unlikely that you could get a degree for some "exam", though exams are often required in doctoral study to guarantee broad knowledge of a field.
I suspect that if it were to become more common, it would require a process in which one first makes a plan and a proposal, then gets approval (or not), and then executes the plan and carries out the study. The approval process might be quite difficult.
The reputation of universities depends in part on doing things right which implies some vetting process. This would be especially true in some fields where human subjects are involved.