Hello @Atilla
First of all, welcome to our community and thank you for your question!
You are right, when your visa expires and you don't get another type of residence title your stay becomes illegal. Marrying a German or a EU citizen will grant you the right to get a residence permit allowing you to stay/work here.
But it's not the only solution to avoid an illegal stay:
For example, you can apply for asylum, even now that your visa has expired. You will receive documents that allow you to stay for the duration of your procedure and if your case ends with a positive result you will receive a residence permit. People from Iran might not have a super high rate of acceptance (~60% in 2016), but it might be worth a shot.
You should also consider this option in order to have more time to get married to your girlfriend. Otherwise you might have to leave the country (or you will get deported) soon because you are residing here illegally.
I know that being an asylum seeker will result in a couple of restrictions for you.
For example you'll have to live in a camp in the beginning and you are not allowed to work for a certain time. But as soon as you are married you can withdraw your asylum application because you don't need a refugee status anymore anyway.
Best regards,
Thorgen