(CNN) Philippines President Rodrigo Duterte, giving a pep talk to his troops in the country's restive south, exhorted the soldiers to go all out in fighting Islamic militants and joked that under martial law they could even commit rape with impunity.

"The consequences of martial law and the ramifications of martial law, I and I alone would be responsible. Just do your jobs, I'll take care of the rest," he told his soldiers on Friday while visiting Iligan City in the country's Mindanao region.

He then warned against committing human rights violations, before joking: "If you rape three people, I will admit that I did it."

Duterte, who is known for making crass statements and his violent war on drugs, declared martial law earlier this week after ISIS declared a "wide-scale offensive on positions of Philippine troops in the city of Marawi."

However, he also said that he was open to dialogue with the terrorist group.

"If they want to talk, I will be most thankful to Allah that we talk about peace," Duterte said Friday. "If they insist on fighting, we can't do anything. Go for it and you have my full support."

Fighting flared this week

Fighting between government forces and the Maute group, an Islamist militant organization based in Mindanao, began Tuesday afternoon in Marawi, a city of about 200,000 people. The clashes between Filipino government troops and the Islamist militants have been deadly. A spokesman confirmed that the fighters had taken over several government buildings in the city, and had torched others, including a church, a school and the city jail.

The violence prompted Duterte to cut short a visit to Moscow, during which one of his top priorities was to acquire Russian-made precision armaments to use against the militants.

Duterte declared martial law, which covers both the city of Marawi and the wider island of Mindanao, of which Marawi is a part.

Mindanao is home to a sizable Muslim population, in contrast to the remainder of the country, which is overwhelmingly Catholic.

The media wing of ISIS, the Amaq News Agency, put out a statement announcing that "fighters of the Islamic State launch a wide-scale offensive on positions of Philippine troops in the city of Marawi."

A history of rape jokes

In his speech to the troops, Duterte said ISIS "is here already" and flying its flags. And he urged the soldiers to take tough measures, such as arresting anyone or searching any house.

He said he is tapping resources, "scraping the bottom of the barrel to look for money to see you through." He said governmental planes are at their disposal for the wounded to be transported and the best medical equipment is available.

Duterte's joked about rape while expressing his support for the soldiers. It was not the first time the president quipped about the subject.

While running for office in 2016, Duterte joked about the 1989 rape and murder of an Australian missionary that took place in Davao City, in the country's southeast, where he was mayor, CNN Philippines reported

"I was angry she was raped, yes that was one thing. But she was so beautiful, I think the mayor should have been first. What a waste," he said during a campaign rally, according to a CNN Philippines translation of the comments.

After drawing international condemnation from women, human rights organizations, political critics and celebrities in the Philippines, Duterte issued an apology

"I apologize to the Filipino people for my recent remarks in a rally. There was no intention of disrespecting our women and those who have been victims of this horrible crime," he said.

A sharp criticism

Phelim Kine, deputy Asia director of Human Rights Watch, deplored Duterte's latest remark, telling CNN it "referenced the crime of rape as an acceptable practice for men with guns and power, this time in comments dressed up as a sickening attempt at humor"

Kine said the comments underscore a message that soldiers "can commit the most serious crimes against Mindanao's civilian population without any fear of accountability." He said National Police undertaking Duterte's "murderous" war on drugs have gotten the same idea.

"Duterte's pro-rape comments only confirm some of the worst fears of human rights activists that the Duterte government will not just turn a blind eye to possible military abuses in Mindanao, but may actively encourage them," he said.

Martial law

Martial law will be in effect on the Muslim-majority southern Philippines island for 60 days "to suppress lawless violence and rebellion and for public safety," said Presidential spokesman Ernesto Abella, according to the Philippine News Agency.

Duterte said martial law in the southern Philippines could last a year. and remarked that the declaration was needed to combat the rise of ISIS.

"If I think that the ISIS has already taken foothold also in Luzon and terrorism is not really far behind, I might declare martial law throughout the country to protect the people," said the President, at a news conference in Manila, Wednesday.

Foreign fighters

Philippines Solicitor General Jose Calida told reporters on Friday that the declaration of martial law shouldn't cause alarm for law-abiding citizens. He said it is the President's duty to crush the rebellion.

But he warned that the Maute group is dangerous and that Mindanao is being invaded by foreign fighters. He said jihadists from Malaysia, Indonesia and Singapore are fighting in Marawi. He said they are claiming Mindanao as part of the caliphate.

"What's happening in Mindanao is no longer a rebellion of Filipino citizens. It has transmogrified into invasion by foreign terrorists who heeded the clarion call of the ISIS to go to the Philippines if they find difficulty in going to Iraq or Syria... They want to create Mindanao as part of the caliphate," he said.