On local services there is a penalty, depending on the area, usually 40 Euros. On Intercity and ICE services you are entitled to buy a ticket on board, albeit with at 7,50 Euro surcharge, used to be 5 Euros untill recently.
There will only be legal action if you do not pay at all or get caught...