You've landed in a very poor environment. Clearly, the devs there feel that they have the run of the place, and are willing to do the minimum necessary in order to hang on to their jobs.
You can't change their attitudes, and they will have by now also poisoned the CEO's view of what development is, and can accomplish.
There's really two ways to approach this situation, however the only one who can possibly get a feel for which way to roll with it will be you:
1. Keep Your Head Down
I think a lot of people will lean in this direction because they hate confrontation, and stirring the pot.
You're just a contractor. It's not your job to fix the company culture, the CEO's opinions, or point out the issues within their development department.
You're only there for a short amount of time. Just get your work done and start looking for a sane client!
2. Sit Down With The CEO
Seeing how you're not a full time employee and your contract will soon be ending anyway you may not have much to lose with this approach. Keep in mind, however, that you will be declaring war on the devs, and they will become hostile (more so than they are already)
Draft up a document outlining some of the many issues with the code, and a realistic timeline for improvements. Don't present this to the devs - they're the problem! Instead, ask for a one-on-one with the CEO.
Tell the man that you've worked with many companies, and completed many projects, but have never before run into a development team as unmotivated and dysfunctional as the this one. Hand him a copy of the document and clearly state that the project has great potential, however it is the day-to-day approach of the team which is sinking it.
Tell him that given the chance you could get it off the ground, however that you cannot keep working with these people as they are a burden more than anything else, and that he is welcomed to call in some other expert to offer his advice, however you are confident that they would reach the same conclusion.
At that point the ball is in the CEO's court. If he is a strong leader he may choose to keep you on, put the devs in their place, and hopefully hire new ones in their place. If he's not then he might understand what you're telling him but not have the confidence to carry out the plan, in which case you're better off moving on anyway.
What do you really have to lose?