I worked at such place that boasted security on the outside. From within, it was spit and duct tape. I couldn't believe it was a fortune 10. After couple of weeks working on one of the smaller projects, I created a new branch and called it rewrite.
When I had free time, I would rewrite the entire project from scratch. I really hated all the in line mysql connections in side_bar_bottom_new_v2.php. It took me a month to realize that I couldn't rewrite an application that was built over the course of 10 years, in my spare time. Only when I embraced it and took the time to understand how it was built, was I able to turn it into a secure app (messy, but still secure).
Now when I meet dysfunctional systems, I don't get mad. I challenge myself to figuring out what the heck it is doing.