Yes that is my understanding of their history. Peasants who were being hassled by the Samurai and so developed these skills for defense. Later they moved on to doing jobs for hire.
Myth, unfortunately (for it does make a good story). There were many different clans in a certain mountainous region of Japan that we retroactively classify as "ninja". Many of them were, in fact, samurai. Other individuals from that region didn't have claim to familial titles that would make them samurai, but offered their services in combat and were often rewarded with land grants in return, making them samurai.
You see, "samurai" was just a word for the gentrified upper class at the time. It wasn't until later, after unification that a caste system came into existence and "samurai" became associated with special clothing, top knots, and the right to wear (but not use) swords.
[Source: I was a Japanese language & history major at one time, and studied a number of years in the Bujinkan.]
EDIT: Okay, partial myth. Peasants who armed themselves fought for hire does describe the humble origins of some schools. It was the "peasants hustled by the samurai" part I was responding to as a myth.