JERUSALEM -- Last month, a pair of cousins from a village in the West Bank were smuggled into Israel, took a taxi to Tel Aviv and, using a pair of homemade rifles, went on a shooting spree at a trendy food mall. They killed four Israeli civilians and wounded 15.

On Monday, Israel’s domestic security agency, Shin Bet, said the cousins were inspired by the Islamic State.

The pair, both 21, were captured at the scene.

The intelligence agency cautioned that although Muhammad Muhamra and Khaled Muhamra were Islamic State supporters, they were not Islamic State militiamen, nor did they formally pledge their allegiance.

They carried out the attack “without having been officially recruited to the organization and without having received any guidance or assistance,” it said.

They may turn out to be Islamic State wannabes, but they also extensively planned their attack, practiced firing their weapons, disguised themselves as young business executives and sought to kill as many Israeli civilians as possible.

According to the Shin Bet and an indictment unveiled Monday, along with Israeli media reports:

Muhammad Muhamra studied recently in Jordan, where he became an Islamic state supporter.

His cousin allegedly also bore a grudge. His family home was destroyed when he was a child. His uncle was a Hamas operative convicted of a deadly gun attack and sentenced to multiple life terms, the Israeli media reported.

The weapons and ammunition used in the attack were acquired by their friend, Ayash Musa Zayn, 22, who helped plot the assault and has been arrested and charged alongside the cousins.

The crude but deadly submachine guns were produced locally in the West Bank, weapons known as “Carl Gustav” or “Carlo” submachine guns, modeled on a Swedish rifle from the 1950s.

The trio practiced firing the guns before their terror assault. The assailants also bought suits, watches, leather bags, shoes and glasses because they wanted to look like businessmen.

They purchased knives, too, and rat poison, planning to douse the blades before wielding them, according to the indictment.

“On the day of the attack, the two attackers took a photograph with Zayn with the backdrop of the Islamic State flag,” according to the Israeli newspaper Haaretz. “The Mahamras had stopped Zayn from participating in the attack itself by arguing that debts he had accrued would nullify his martyrdom.”

The indictment said the trio began planning an attack in January "as revenge on Israel in the name of the Islamic State” -- specifically for a deadly July 2015 arson attack on a Palestinian family in the West Bank village of Duma. A toddler was burned alive and his parents died afterward from their burns. A brother was severely injured. Two Jewish extremists based at nearby settlements were indicted for murder and accused of being members of a terror group that seeks to spark a sectarian war between Jews and Muslims.

The Palestinians snuck into Israel through a breach in the separation barrier and holed up in a house used by illegal workers entering Israel.

The indictment states that the attackers initially planned to strike a passenger train, but the target was changed when they observed tight security at the station.

Their decision to strike the Sarona Market, an open-air mall with upscale cafes and gourmet shops, was spontaneous. They asked locals for directions to an area with popular restaurants.

Then they walked to the Max Brenner dessert restaurant and ordered, and then opened fire.