Despite the failings of both the secret sale of U.S. arms to Iran and the clandestine effort to aid the Nicaraguan rebels, recent congressional testimony has revealed that the operations were enormously successful in one respect: They provided millions of dollars to the middlemen brokering the operations.

The Iran-contra affair, which erupted as a political scandal over misguided and potentially illegal efforts to buck up the rebels with profits from arms sales to Tehran, has taken on venal overtones. Republicans and Democrats alike have focused less on what the operators knew and when they knew it, and more on how much they made and how they spent it.

Even staunch congressional defenders of the White House seemed taken aback last week by the revelation that the middlemen funneled $8 million into Swiss bank accounts while steering only $4 million to support the contras. The middlemen, according to businessman Albert A. Hakim, were so deft at making a profit that they earned $860,000 for themselves on one weapons deal that actually lost nearly $1 million.

Furthermore, using money garnered in part by charging exorbitant prices to Iran for U.S. missiles -- money that Congress asserts belongs to the U.S. Treasury -- the brokers established their own venture capital fund to underwrite investment deals as disparate as a timber operation in the Northwest and selling submachine guns.

The veneer of "profit motive," Sen. Orrin G. Hatch (R-Utah) complained, "made a bad situation worse."

Hatch's comment reflects the predicament in which he and other Republicans find themselves at the end of nearly six weeks of testimony from 18 witnesses -- in defending the administration, they cannot appear to sanction profiteering or to condone even the hint of corruption.

"In some cases, the American flag that was being used to hide greed has been pierced," Sen. Sam Nunn (D-Ga.) told reporters immediately after the first phase of hearings ended yesterday afternoon.

When public hearings resume in two weeks, the issue of venality is certain to surface again, particularly with the eventual appearance at the witness table by Lt. Col. Oliver L. North.

The man lauded by President Reagan as "a national hero" will not only have to answer hundreds of questions about policy failures but also queries about his integrity, particularly whether he condoned efforts by Hakim to channel $200,000 to North's family.

Members of the select committees also have suggested that they will recall for further questioning Hakim's business partner, retired Air Force major general Richard V. Secord, whose four days of answers early last month were sharply contradicted by Hakim's testimony last week.

Secord, who swore last month that in mid-1985 he had renounced any profit from the contra arms sale and that he never intended to benefit from the Iran sales, reiterated that in an interview this week: "It is inaccurate to keep trying to paint me as a profiteer when I denied I benefited directly . . . . I've never seen so much preoccupation by so many important people with something I regard to be small potatoes."

Committee members disagree. "The documents are very clear," Rep. Michael DeWine (R-Ohio) told Hakim, "that you have made millions of dollars on this operation." Hakim acknowledged that he saw the Iran initiative as an opportunity to get in on the ground floor of new "business opportunities" that would be worth millions to him and Secord if relations between Washington and Tehran improved.

Committee investigators, who include several full-time government accountants, have sifted through reams of bank records and other documents to piece together a money trail.

According to a congressional staff analysis, the trail shows that $8.2 million in profits from arms sales to Iran was deposited in five Swiss accounts set up by Hakim for himself, Secord and others. Another $1.4 million in profits from earlier arms sales to the contras was also commingled with that.

Of the more than $9 million in the Swiss accounts, about $3.5 million was spent on fees and commissions to Hakim and business associate Thomas Clines, and to cover operational expenses. Secord received at least $136,000 of the $3.5 million for personal and business expenses, according to the congressional staff analysis of the records. Furthermore, Secord and Hakim's firm, Stanford Technology Trading Group International Inc., also received $500,000 in 1985 and 1986 from the Swiss Iran-contra accounts, according to the committees.

Another $250,000 was used as seed money for a series of private investments that Hakim, Secord and other partners were contemplating last year. A memo Hakim prepared on the investments proposed that Stanford Technology be converted into a holding company to oversee four subsidiaries that would sell products ranging from submachine guns to processed wheat to pharmaceutical products. Almost half of this money was spent on a plan to buy 10,000 acres of forest land in Washington state. Hakim testified that all of the schemes fell through.

Ownership of the remaining $6.7 million in the five Swiss "profit" accounts set up by Hakim is now in dispute, as is an additional $1.4 million left over from the operations that was not channeled into the "profit" accounts. Some members of the congressional committees have strongly asserted that the money should be "deeded" to the U.S. government.

Hakim countered that the money belongs to the "enterprise," the covert network of dummy corporations and foreign bank accounts set up to execute the Iran-contra operations. He also contends that there are substantial bills that remain unpaid, including, for example, $2 million in "obligations" to Iranians involved in hostage negotiations.

The large issue of who owns the money is tied to the related issue of whether Secord, contrary to his denials, benefited from Hakim's financial manipulation of the Iran-contra windfall. While acknowledging receipt of funds from Hakim during the covert operations, Secord said this week that except for money to cover operating expenses he was unaware that his partner had given him money from the Iran-contra accounts.

Secord said that when he and Hakim became partners in mid-1983, Hakim agreed to provide him with a series of loans in return for Secord's management and marketing expertise until their firm made a profit. Secord said that two payments he received -- one for $31,800 on March 25, 1985, and another for $22,000 on Jan. 30, 1985 -- were loans from Hakim. Secord said he used the $31,800 to buy a Porsche sports car, and about half of the $22,000 to cover legal fees for his attorney, Thomas C. Green.

Hakim, however, testified last week that the $31,800 was not a loan; he was not asked about the $22,000 payment.

Secord further said in interviews this week that Hakim told him a check for $52,500 on Oct. 1, 1985, was his fee for consulting work done in the Middle East that was unrelated to the Iran-contra affair. Secord said he bought a Piper Seneca airplane for about $30,000 of the $52,500 and deposited most of the balance in his personal bank account.

Secord also said Hakim arranged and financed a trip to an overseas clinic last year because of concern about Secord's high blood pressure at the time. Records show that the clinic cost $2,305.

Committee records also show Secord signing for a series of cash withdrawals -- totaling $28,000 between April 4 and Nov. 12, 1985 -- from the "profit" account that Hakim established. Secord said he and Hakim made numerous trips overseas during this period and used cash to cover expenses because the operation lacked credit cards. Secord said he also gave cash to Clines to cover expenses in arranging arms purchases in Portugal; the arms were later delivered to the contras. (Committee records also show that Clines, a former CIA official and longtime Secord friend, received $900,000 from a "profits" account that Hakim set up for him.)

Secord also said that if Hakim continued to make deposits in Secord's account -- code named Korel Assets -- it was done without Secord's knowledge or authorization. The retired general said he was hoping to return to government service and was concerned that any stigma of profiting from contra arms sales could hurt his chances.

Hakim, however, said he continued to set aside Secord's share because "there was no offer to Gen. Secord, at least as much as I knew, to go back to the government. And, I was not quite sure if that would occur or not, so I did not change my pattern."

More than $1.5 million remains in the special account Hakim set up for Secord, according to congressional investigators' analysis of Hakim's records. According to a committee aide, investigators have concluded that about $700,000 of those funds came from the Iran arms sales and were put in the account after Secord renounced any profits.

Secord said it is wrong to view the Korel Assets account as one set up to hold his profits because it was used to pay numerous bills for the operation.

For example, Secord said, $45,000 from the account that went to Green's law firm was a finder's fee owed by an arms dealer Green had introduced to Secord as part of the contra weapons sales.

Regardless of how the select committees eventually evaluate the middlemen, these brokers seem to have been particularly ingenious at making money under difficult circumstances. Hakim testified, for example, that last August he withdrew from the Swiss Iran-contra accounts an $860,000 commission on an arms deal, even though the operation was forced to sell the weapons at a loss.

According to Hakim's testimony and committee records, here is how the deal worked:

The weapons were purchased for $2.1 million. Before the arms were resold, Hakim immediately pulled $860,000 out of the Swiss accounts as a commission. He then divided all but a small portion of the commission into three equal shares of $258,000 and deposited the shares into the accounts he set up for himself, Secord and Clines.

When a hitch developed in the proposed sale of the weapons to the contras, the arms were sold to the Central Intelligence Agency for $1.2 million, creating a $900,000 loss.

The commissions, however, were unaffected by the loss and the Iran-contra accounts also absorbed the $900,000 loss.