The Treasure of the Sierra Madre is a 1927 novel by the mysterious German-English bilingual author B. Traven, in which two American down-and-outers in 1920s Mexico hook up with an old-timer to prospect for gold. The book was very successfully adapted into a 1948 film of the same name by John Huston.
Foreigners, like the three American prospectors who are the protagonists in the story, were at very real risk of being killed by the bandits if their paths crossed. The bandits, likewise, were given little more than a "last cigarette" by the army units after capture, even having to dig their own graves first. This is the context in which the three gringos band together in a small Mexican town and set out to strike it rich in the remote Sierra Madre mountains. They ride a train into the hinterlands, surviving a bandit attack en route.
Once out in the desert, Howard, the old-timer of the group, quickly proves to be by far the toughest and most knowledgeable; he is the one to discover the gold they are seeking. A mine is dug, and much gold is extracted, but greed soon sets in and Fred C. Dobbs begins to lose both his trust and his mind, lusting to possess the entire treasure.
The bandits then reappear, pretending, very crudely, to be Federales, which leads to the now-iconic line about not needing to show any "stinking badges". After a gunfight, a real troop of Federales appear and drive the bandits away. But when Howard is called away to assist some local villagers, Dobbs and third partner Curtin have a final confrontation, which Dobbs wins, leaving Curtin lying shot and bleeding. Dobbs continues on alone but is soon confronted and killed by three drifters. The drifters, thinking the gold is just worthless sand, scatter the paydirt. They are later captured and executed by the Federales. Curtin and Howard hear the story and can do nothing but laugh in the end.