my theory is that orochimaru knew from the begging that madara is still alive,and orochimaru knew that madara wish is to end the world and to control in a new form of existence(all people in genjutsu),so i think that orochimaru purpoe its to obtain enogh power to kill madara,orochimaru become a bad boy because he want to obtain enogh power to crush madara,even now he needs saske hor his powerfull body,in conclusion in my crazy theory i think that orochimaru in fact is a good boy,who want since he knew about madara,to stop him 