The history of Japan describes the ninjas as the best combatants who used to be perfectly trained in martial art that involves strange but effective techniques. Few of the unconventional methods, which were used by the Ninjas were stealth, surveillance and disguise.
They had some special weapons and tricks up their sleeves that were simply inescapable. The actual origin of the Ninja is not clear. Yet it seemed they evolved as an opposing force to the samurai.
Where the samurai had the code of bushido (aka honour and loyalty), the ninja followed Ninjutsu. Bushido was noble. The samurai would state their challenge against a single opponent and announce his clan name. But this wasn’t effective. The ninjutsu code, on the other hand, prized the accomplishment of a mission by any means necessary above honour.
Ninja, therefore, were the olden day’s spies and assasins. It was the ninja who promoted the “Guerilla” technique of war, influenced by Sun Tzu and his Art of War manual.
The method of “Stealth” originated in Japan approximately at 522 AD. This was linked with the religion and the priests were the ones to practice this. There was no violence involved and the priests used to practice this in order to support the ruling power of that time. At around 645 A.D these priests mastered the art and realized the need to use it for their self-defense.
Later during the 1192 A.D. many of the wealthy and established clans emerged. They fought and killed for reasons that included survival and power. Gradually there was need of using techniques like stealth, surveillance and disguise. Who better to seek help from than those who had already mastered the art. This was how ninja slowly evolved.
According to the historical facts the ninja groups were developed in small villages or around the elite families. They were into protecting the residents of the villages and communities from external enemies. Women had the privilege to become the Ninjas, like men. While male ninja were called shinobi, female ninja were called kunoichi. It was said that female ninja were used to seduce enemies while accomplishing the task of spying on others.
There were various rules decided solely for the ninja and they were often kept as secrets. The facts that have been retrieved about the origin and purposes of the Ninjas are mostly the records kept by the outsiders who observed and scripted the history. But if you are looking for assured historical proofs for this, then they are not discovered to date.