Yes, you can buy a car if you can afford it. But remember that you need to register it at licensing office (Kfz-Zulassungsstelle) before you can use it!
To do so you need an auto liability insurance (Kfz-Haftpflichtversicherung). You’ll have to bring a paper that states that you have this kind of insurance to the licensing office. Besides that you have to prove your identity by bringing an ID or a passport and a registration card (you can get it at residents’ registration office or Einwohnermeldeamt as it’s called in Germany).
I’m not sure if your Aufenthaltsgestattung or a foreign ID/passport is enough to register a car. Maybe you can go to licensing office first (before you buy the car) and ask them if your documents are sufficient.
And last but not least: of course you need a valid driver’s license to drive your car ;)
All the best,