Deman, ninja were not farmers and peasants. Some of them were, yes, but they were in the clan, they weren't actually operatives. For a long time, they served the government, performing in roles such as snipers (when retreating, they posted snipers to take out the other army's leaders for an easy victory), spies, and assassins.
Eventually they were forced into the mountains 'cause the government set them up (they had gotten a bad reputation for doing the government's bidding, and the government decided to say the ninja were working on their lonesome), and then they were forced to work as peasants, farmers and similar.
At least that what I remember, there are many conflicting sources on this stuff. ;/