Spy planes over Cuba and warships in the Gulf of Mexico are the military edge to the Carter administration's effort to impress both Havana and Moscow that the United States stands ready to combat any offensive threat in its back yard officials said yesterday.

The SR71 Blackbird has been flying over Cuba for the last several weeks trying to photograph the Soviet Mig 23s recently shipped there in hopes the resulting pictures will show whether the plane is designed for bombing or aerial combat.

However, even if the photographs show the Migs are the type usually used for aerial combat rather than bombing, sources said, there is no guarantee that the planes will not be wired later for dropping nuclear weapons.

Migs continued for bombing, rather than air-to-air combat, would be considered offensive rather than defensive weapons. Defense Secretary Harold Brown and other administration officials have raised the question whether such Migs would violate the U.S. Soviet agreement that ended the missile crisis of 1962.

The lack of intelligence agents in Cuba has forced the United States to resort to aerial detective work to determine what kind of Migs the Soviets sent Cuba recently.

Although low-level photography is usually the best way to obtain detailed pictures of specific objects like the Migs, source said yesterday that the cameras on the high-flying SR71 are so good that the risk of flying low over Cuba probably will not have to be taken.

Cuba shot down a U2 flying low during the missile crisis of 1962.

The SR71 flies at about 100,000 feet and carries a wide array of sensors along with cameras.

The U.S. raval presence off Cuba at the moment is the largest force assembled in the Gulf of Mexico since the Cuban missile crisis. A prime objective is to impress the Moscow with the U.S. ability to handle any Soviet naval threat to those waters.

Called Gulf EX79, the naval exercise involves 36 warships, two nuclear powered submarines and more than 300 Air Force and Navy aircraft of 15 different kinds.

The frequent visits of Soviet warships to Cuba, no the shipment of the Migs there, impelled planners to locate much of the exercise close to Cuba. The Soviet Union currently has two guided-missile frigates, a guided-missile destroyer, an oiler and a diesel submarine visiting Cuba.

"We wanted to show the Russians we could wax them in our own backyard," said one official yesterday.

British ships also are participating in the exercise, which began on Wednesday and is scheduled to continue until Dec. 4.

The official Navy release states that Gulf EX79 is a "21-day exercise to improve overall task force battle readiness through extensive training in the major mission areas of carrier air strikes, dissimilar aerial combat training, antiair warfare, antisubmarine warfare and surface warfare."