Ewoks have long been contentious figures in Star Wars fandom, treasured by some as childhood memories, reviled by others who consider them a cynical cash grab meant only to sell toys. Both sides tend to admit that the idea of Ewoks besting hardened Imperial troops is more than a little absurd.
But they're wrong. Anyone contrasting the military abilities of the Stormtrooper against the Ewok is making the same mistake as the British did when they sneered at American militiamen, or when General Westmoreland believed he could simply kill the Viet Cong into submission. I do not make this comparison idly, since Lucas himself admits drawing inspiration from the Viet Cong. "This film was written during the Vietnam War," Lucas recalls on the audio commentary of Return of the Jedi, "where a small group of ill-equipped people overcame a mighty power." To him, the Ewoks represent revolutionary America, the Huns, any group that overcame a technologically and militarily superior empire through force of will. In other words, the Ewoks are not soldiers, but a tribal insurgency - and a remarkably successful one once they receive the backing of foreign special forces.
Insurgency and counterinsurgency have become major buzzwords in the past decade, but in reality these concepts date back to ancient times. To boil the concept down to its essentials, an insurgency is a socio-political movement that seeks to disrupt and destabilize a government so that the insurgency can replace it with their own administrative and political system. Insurgencies tend to be anti-foreign, either struggling against an occupation force or colonial power, or against a native government that is perceived to be subservient to foreign interests. Counterinsurgency, on the other hand, is an attempt to defend the current political system and ensure its continuity, while rendering the insurgency's competing system either illegitimate or inoperable. In other words, the struggle between insurgents and counterinsurgents is actually a political struggle to be seen as the legitimate representative of the population. The result is that insurgents and counterinsurgents end up with vastly different objectives: while counterinsurgents tend to focus on securing territory in order to build outposts, insurgencies enter territory with the objective of winning over the local population. The result is that whenever counterinsurgents build an outpost, they often find themselves surrounded by enemies that can strike with extreme force, then disappear into the local population. This necessitates a retaliatory response by the counterinsurgents, which inevitably disrupts and damages their relationship with the local population, causing them to further identify with the insurgency. Counterinsurgents can either try to reverse this process by building infrastructure to benefit the local population, or they can crack down as hard as possible in the hope that overwhelming force will dissuade any further insurgent action. The former is what the United States currently does in Afghanistan - the latter was the favored tactic of the Nazis, Saddam Hussein and Bashar al-Assad.
Among the various types of insurgencies, the tribal insurgency is one of the most grueling and dangerous. Because there is no central authority driving the guerrillas - only local concerns - the situation essentially grinds to a stalemate. Local villages and tribes cannot band together enough to overwhelm the occupying power, while counterinsurgents are left stamping out fires in a dozen locations at once, unable to bring a decisive end to the conflict. Such was the situation on Endor before the arrival of the Rebel Alliance.
The Empire did not come to Endor with the goal of colonization or conquest, but to create a base of operations for the construction and safeguarding of the Death Star II. While the subjugation of the local population was not an Imperial objective, after conflicts flared between Imperial survey teams and the Ewoks - which escalated over the years to include the theft of an Ewok artifact from Bright Tree Village - relations became hostile and Ewok bands began conducting insurgency operations.
The Imperial garrison consisted of Tempest Force, a legion-sized group of combat troops highly supplemented by Scout Trooper units and AT-STs to deal with the difficult terrain. Palpatine described them as his "best troops," though we should probably take that with a grain of salt - by this time the Emperor's elite front-line units like the 501st were severely depleted due to combat casualties, and Tempest Force's only notable action was during the subjugation of Kashyyyk twenty-three years before. In other words, they had a regimental history of suppressing nonhuman rebellions, but were at best extremely rusty and at worst largely consisted of garrison troops. In addition, the only ground transport was provided by a single AT-AT, which was not suited for the forested terrain. This lack of mobility crucially hampered the Imperial reaction speed once combat operations began.
Bright Tree, being the closest village to the installation, fortified itself against AT-STs with native traps designed to defend against the enormous, troll-like Gorax and began ambushing Stromtrooper patrols. Imperial authorities retaliated through their normal counterinsurgency strategy, by which I mean genocide. Troops raided local villages - Vader personally slew several Ewoks - and enslaved the inhabitants to assist in construction projects and forest-clearing operations. The result was essentially a draw. The Ewoks couldn't marshal enough force to dislodge the invaders from their outposts, and the Imperials ceased expanding their hold on the territory, content to guard their shield generator and shuttle pad rather than project their power onto the local population.
This is not to say that the situation improved during this stalemate. While this is entirely conjecture (as one sometimes must use when discussing a society with no written language) it is likely the Ewoks felt that the presence of the Imperial installation was in itself a desecration. Nature formed the basis of civil and religious life for Ewoks, and the foreigners' attempt to reshape the landscape violated the basic tenets of their indigenous beliefs. First, the Imperials brought a new moon into Endor's sky, something vast, artificial and broken that loomed above their villages. Next were the water resources, which the Imperial garrison would've diverted both to keep their troops hydrated and to help manufacture the ferroconcrete for bunkers. Worst, however, would've been the tree clearings. Trees played a special role in Ewok cosmology, not only because of their belief in a Great Tree that was the source of all life, but because each member of the tribe had a totem tree where their spirit would reside after death. Thus, not only were the Imperials destroying Bright Tree Village's natural habitat, they were bulldozing its ancestors as well. Faced with an existential threat both physically and spiritually, Bright Tree Village was ripe for further radicalization by outside provocateurs.
Insurgencies become especially dangerous when paired with conventional military forces or advised by seasoned commandos. During World War I, T.E. Lawrence provided British aid so the Arab Revolt could harry the Ottoman Turks, causing them to stretch their lines and become vulnerable to conventional troops. Before the U.S. invasion of Afghanistan, special operations units inserted into the country to build partnerships with the Northern Alliance, direct air strikes and in a surprise move, take Mazar-i-Sharif on horseback. Originally, the Rebel Strike Team led by General Solo had even less interest in the indigenous Ewoks than the Imperials did. However, as fate would have it, his team's capture by the Bright Tree Tribe would save them from what quickly became a botched operation. Even before blundering into an obvious hunting snare, Solo's team had already been detected clearing the fleet, broadcasted their presence to Vader, alerted a Scout Trooper patrol, engaged enemy forces in a loud firefight in the woods and lost one team member, who just happened to be a high-value political target. By any measure the mission was FUBAR before a single rebel trooper put his foot in the dirt, and that's discounting the fact that they were walking into an Imperial ambush. Thankfully, Skywalker prevented Solo from opening fire on their Ewok captors, which would've upgraded the mission from disaster to fiasco. Where Solo saw an enemy force, Skywalker sensed valuable allies.