Federal prosecutors in Boston could not figure out why marijuana smuggler Frank Lepere was always a step ahead of them.

When they wiretapped his girlfriend's phone, Lepere stopped using it for drug deals. When they installed a closed-circuit camera outside his trucking company, Lepere's crew spray-painted the lens. And when prosecutors finally brought charges against Lepere, he vanished days before the indictment was returned.

"Fingers were pointed at everyone in sight," said William F. Weld, U.S. attorney in Boston. "Everyone was mentioned as a possible suspect."

Weld believes the mystery was solved in October when David P. Twomey, a former prosecutor with the Justice Department's Organized Crime Strike Force, was charged with selling information to Lepere for $210,000 in bribes and a 30-foot speedboat. Twomey has denied the charges.

The indictment is the latest in a string of cases in which federal law-enforcement officials have been charged with betraying the government or with old-fashioned thievery.

In the last three years, one U.S. attorney, four assistant prosecutors, seven Federal Bureau of Investigation agents, five Drug Enforcement Administration agents and two Central Intelligence Agency agents have been indicted on charges ranging from bribery to car theft to cheating on expense accounts.

Such cases were once rare. But while the handful of ex-agents charged with espionage have attracted more public attention, the cases involving official corruption have sparked growing concern among senior law-enforcement officials.

"The first thing we have to realize is we have to investigate ourselves," said Rudolph W. Giuliani, the U.S. attorney in Manhattan, who recently had to deal with a corrupt assistant. "We have to aggressively investigate agents, police officers, assistant U.S. attorneys. We're in a dangerous business, and that's one of the prices you pay."

A decade ago, Giuliani said, "Maybe there was more of a tendency to brush these things under the rug. There was more institutional self-protection."

FBI Director William H. Webster said that every allegation about an agent, no matter how minor, is referred to a U.S. attorney. He said "there is no back door" through which renegade agents can be quietly dismissed.

"If we catch you, we're going to prosecute you," Webster said. He said he discusses ethics with each new class of FBI recruits, telling them, "You carry the reputation of us all around in your pocket."

William C. Hendricks III, deputy chief of the Justice Department's Public Integrity Section, said his office is determined to prosecute corrupt law-enforcement agents because "they are fairly high-profile symbols of what the federal government stands for." He said he is disturbed by the number of prosecutors and agents who have engaged in "casual betrayal, with no great agonizing."

Two themes run through the cases. One is that the vast amounts of cash in the narcotics world can tempt those who investigate drug trafficking. The other is that FBI agents sometimes get too close to the criminals on whom they rely for information.

FBI agent Dan A. Mitrione, for example, worked undercover with a drug-dealing informer in a 1982 narcotics probe in Florida. Mitrione eventually allowed the informer to distribute more than 90 pounds of cocaine, and took some of the profits in cash and property worth $850,000, according to the indictment against him. He pleaded guilty and was sentenced last month to 10 years in prison.

Frank Robin Jr., an assistant U.S. attorney in Houston, also drew a 10-year prison term after he was convicted of offering information to drug smugglers for $200,000.

Some officials tend to specialize in the kind of crimes they investigate. Arthur B. Hall, an FBI agent in Camden, N.J., got so close to a crooked car thief that they went into the stolen car business together. Hall and the informer chopped up cars and trucks in Hall's garage, removed the serial numbers and resold them.

When police arrested his cohort for unrelated burglaries, Hall got him released by vouching for his undercover status. Hall was later convicted and sentenced to five years in prison.

Anthony J. Civitano, a New York FBI agent, obtained counterfeit credit cards from a defendant he was aiding and used them to gamble at Atlantic City casinos. Civitano, who tried to have the defendant's sentencing postponed, was himself sentenced to three years in prison and fined $10,000.

"You see this time and again," Hendricks said. "Who's corrupting whom? Is the agent corrupting the informant, or is the informant corrupting the agent?"

Such cases are hardly limited to the FBI. President Reagan fired J. William Petro as the U.S. attorney in Cleveland last year following allegations that Petro told a friend, investor Howard B. Schulman, that associates of Schulman had been named in a sealed indictment for selling counterfeit merchandise. Petro was convicted of criminal contempt for violating grand jury secrecy and fined $7,500.

An Immigration and Naturalization Service officer at Dulles Airport was convicted of taking bribes to illegally admit Iranians into the country. A CIA officer assigned to debrief Soviet emigres pleaded guilty to making false statements on his expense account, including the purchase of vodka for emigres who, it turned out, did not drink.

The Public Integrity Section has also taken pains to prosecute several low-level clerical employes at the FBI and CIA on fraud and embezzlement charges. Earlier this year it planted an undercover agent in the department's Criminal Division to catch a clerk and secretary who were distributing cocaine.

The enticement of drug money has long concerned the DEA, the government's lead agency in the war on narcotics. DEA agent Harold (Slim) Lawrence pleaded guilty last year to accepting money to help smugglers fly marijuana into Tennessee. A Miami agent, Roger Schow, was indicted in June on charges of selling information to drug traffickers.

Perhaps no case better illustrates what Hendricks calls "the corrupting influence of drugs and money" than that of Twomey, who faces trial in Boston next month.

While a member of the elite Organized Crime Strike Force from 1978 to 1981, Twomey headed the probe into a large marijuana ring run by Lepere. Twomey, 40, became a Boston defense lawyer four years ago, but still managed to obtain details of the ongoing investigation, according to the indictment.

"He continued to socialize with agents and get information from them under the guise of friendship," said U.S. attorney Weld.

The indictment charges that Twomey, in exchange for regular payments, met secretly with Lepere and told him the identity of cooperating government witnesses and the locations of federal wiretaps. Twomey is also charged with warning Lepere about the indictment that was returned against him in South Carolina on Dec. 8, 1981. Sources say Lepere was so sure of the information that he had a leisurely Thanksgiving dinner with his family in Massachusetts before fleeing to a mountaintop retreat in upstate New York.

Lepere remained a fugitive until last fall when DEA agents, acting on a tip from an associate they arrested, captured Lepere at his hideaway. Lepere then named Twomey as the leak and offered to testify against him. Lepere was allowed to plead guilty to reduced charges and was sentenced to five years in prison. He also agreed to forfeit $3 million.

Twomey's attorney, Harry Manion, has argued that his client will prove his innocence by showing "that the government has made a sweetheart deal with perhaps the largest importer of marijuana. The majority of the government's case rests upon the uncorroborated testimony of Lepere. The government has hopped into bed with a notorious drug dealer."

An equally dark side of the drug problem came to light last May in Giuliani's New York office. Daniel N. Perlmutter, 29, an assistant U.S. attorney, was charged with stealing heroin and cocaine worth $450,000 from an office safe where the drugs were being held as evidence. Perlmutter, who also took $41,000 in cash, pleaded guilty in October and is awaiting sentencing.

Perlmutter once visited the office at 3 a.m., signed in with another prosecutor's name and left with 30 grams of cocaine in a manila envelope, according to a Justice Department report. After several such thefts prompted Giuliani to restrict access to the safe, Perlmutter found the new combination in another prosecutor's desk drawer, placed 175 grams of heroin in a rolled-up dollar bill and left the office after midnight, the report said.

Giuliani said Perlmutter, who had just split up with his wife, was a heavy drug user who apparently stole the drugs for himself and his girlfriend. He said the case has had a sobering impact on an office that runs on trust.

"It was like a death in the family," Giuliani said. "He is someone I trusted. He all of a sudden became a suspect and a defendant like everyone else you investigate."