KHANKE, Iraq — The advertisement on the Telegram app is as chilling as it is incongruous: A girl for sale is “Virgin. Beautiful. 12 years old…. Her price has reached $12,500 and she will be sold soon.”

The posting in Arabic appeared on an encrypted conversation along with ads for kittens, weapons and tactical gear. It was shared with the Associated Press by an activist with the minority Yazidi community, whose women and children are being held as sex slaves by the extremists.

While the Islamic State group is losing territory in its self-styled caliphate, it is tightening its grip on the estimated 3,000 women and girls held as sex slaves. In a fusion of ancient barbaric practices and modern technology, IS sells the women like chattel on smartphone apps and shares databases that contain their photographs and the names of their “owners” to prevent their escape through IS checkpoints. The fighters are assassinating smugglers who rescue the captives, just as funds to buy the women out of slavery are drying up.

The thousands of Yazidi women and children were taken prisoner in August 2014, when IS fighters overran their villages in northern Iraq with the aim to eliminate the Kurdish-speaking minority because of its ancient faith. Since then, Arab and Kurdish smugglers managed to free an average of 134 people a month. But by May, an IS crackdown reduced those numbers to just 39 in the last six weeks, according to figures provided by the Kurdistan regional government.

Mirza Danai, founder of the German-Iraqi aid organization Luftbrucke Irak, said in the last two or three months, escape has become more difficult and dangerous.

“They register every slave, every person under their owner, and therefore if she escapes, every Daesh control or checkpoint, or security force — they know that this girl … has escaped from this owner,” he said, using the Arabic acronym for the group.

The AP has obtained a batch of 48 head shots of the captives, smuggled out of the IS-controlled region by an escapee, which people familiar with them say are similar to those in the extremists’ slave database and the smartphone apps.

Lamiya Aji Bashar tried to flee four times before finally escaping in March, racing to government-controlled territory with Islamic State group fighters in pursuit. A land mine exploded, killing her companions, 8-year-old Almas and Katherine, 20. She never learned their last names.

The explosion left Lamiya blind in her right eye, her face scarred by melted skin. Saved by the man who smuggled her out, she counts herself among the lucky.

“I managed in the end, thanks to God, I managed to get away from those infidels,” the 18-year-told the AP from a bed at her uncle’s home in the northern Iraqi town of Baadre. “Even if I had lost both eyes, it would have been worth it, because I have survived them.”

***

The Sunni extremists view the Yazidis as barely human. The Yazidi faith combines elements of Islam, Christianity and Zoroastrianism, an ancient Persian religion. Their pre-war population in Iraq was estimated around 500,000. Their number today is unknown.

Nadia Mourad, an escapee, has appeared before the US Congress and the European Parliament to appeal for international help.

“Daesh is proud of what it’s done to the Yazidis,” she said to Parliament. “They are being used as human shields. They are not allowed to escape or flee. Probably they will be assassinated. Where is the world in all this? Where is humanity?”

IS relies on encrypted apps to sell the women and girls, according to an activist who is documenting the transactions and asked not to be named for fear of his safety.

The activist showed AP the negotiations for the captives in encrypted conversations as they were occurring in real time.

The postings appear primarily on Telegram and on Facebook and WhatsApp to a lesser degree, he said.

Both Facebook-owned WhatsApp and Telegram use end-to-end encryption to protect users’ privacy. Both have said they consider protecting private conversations and data paramount, and that they themselves cannot access users’ content.

“Telegram is extremely popular in the Middle East, among other regions,” said Telegram spokesman Markus Ra. “This, unfortunately, includes the more marginal elements and the broadest law-abiding masses alike.” He added the company is committed to prevent abuse of the service and that it routinely removes public channels used by IS.

In addition to the posting for the 12-year-old in a group with hundreds of members, the AP viewed an ad on WhatsApp for a mother with a 3-year-old and a 7-month-old baby, with a price of $3,700. “She wants her owner to sell her,” read the posting, followed by a photo.

“We have zero tolerance for this type of behavior and disable accounts when provided with evidence of activity that violates our terms. We encourage people to use our reporting tools if they encounter this type of behavior,” said Matt Steinfeld, a spokesman for WhatsApp.

Like the Bible, some passages of the Quran implicitly condone slavery, which was widespread when the holy book emerged. It also allows men to have sex with both their wives and “those they possess with their right hands,” taken by interpreters to refer to female slaves.

In the 19th and early 20th centuries, most Muslim scholars backed the banning of slavery, citing Quranic verses that say freeing them is a blessing. Some hard-liners, however, continued to insist that under Shariah, sex slavery must be permitted, though the Islamic State group is the first in the modern era to bring it into organized practice.

In the images obtained by AP, many of the women and girls are dressed in finery, some in heavy makeup. All look directly at the camera, standing in front of overstuffed chairs or brocade curtains in what resembles a shabby hotel ballroom. Some are barely out of elementary school. Not one looks older than 30.

One of them is Nazdar Murat, who was about 16 when she was abducted two years ago — one of more than two dozen young women taken away by the extremists in a single day in August 2014. Her father and uncles were among about 40 people killed when IS took over the Sinjar area, the heart of the Yazidi homeland.

Inside an immaculately kept tent in a displaced persons camp outside the northern Iraqi town of Dahuk, Nazdar’s mother said her daughter managed to call once, six months ago.

“We spoke for a few seconds. She said she was in Mosul,” said Murat, referring to Iraq’s second-largest city. “Every time someone comes back, we ask them what happened to her and no one recognizes her. Some people told me she committed suicide.”

The family keeps the file of missing Yazidis on a mobile phone. They show it to those who have escaped the caliphate, to find out if anyone has seen her, and to other families looking for a thread of hope they’ll see their own missing relatives again.

The odds of rescue, however, grow slimmer by the day. The smuggling networks that have freed the captives are being targeted by IS leaders, who are fighting to keep the Yazidis at nearly any cost, said Andrew Slater of the nonprofit group Yazda, which helps document crimes against the community and organizes refuge for those who have fled.

Kurdistan’s regional government had been reimbursing impoverished Yazidi families who paid up to $15,000 in fees to smugglers to rescue their relatives, or the ransoms demanded by individual fighters to give up the captives. But the Kurdish regional government no longer has the funds. For the past year, Kurdistan has been mired in an economic crisis brought on by the collapse of oil prices, a dispute with Iraq’s central government over revenues, and the fallout from the war against the Islamic State.

Even when IS retreats from towns like Ramadi or Fallujah, the missing girls are nowhere to be found.

“Rescues are slowing. They’re going to stop. People are running out of money, I have dozens of families who are tens of thousands of dollars in debt,” Slater said. “There are still thousands of women and kids in captivity but it’s getting harder and harder to get them out.”

***

Lamiya was abducted from the village of Kocho, near the town of Sinjar, in the summer of 2014. Her parents are presumed dead. Somewhere, she said, her 9-year-old sister Mayada remains captive. One photo she managed to send to the family shows the little girl standing in front of an IS flag.

Five other sisters all managed to escape and later were relocated to Germany. A younger brother, kept for months in an IS training camp in Mosul, also slipped away and is now staying with other relatives in Dahuk, a city in the Iraqi Kurdish region.

Sitting very still and speaking in a monotone, Lamiya recounted her captivity, describing how she was passed from one IS follower to another, all of whom beat and violated her. She was determined to escape.

She said her first “owner” was an Iraqi IS commander who went by the name Abu Mansour in the city of Raqqa, the de-facto IS capital deep in Syria. He brutalized her, often keeping her handcuffed.

She tried to run away twice but was caught, beaten and raped repeatedly. After a month, she said, she was sold to another IS extremist in Mosul. After she spent two months with him, she was sold again, this time to an IS bomb-maker who Lamiya said forced her to help him make suicide vests and car bombs.

“I tried to escape from him,” she said. “And he captured me, too, and he beat me.”

When the bomb-maker grew bored with her, she was handed over to an IS doctor in Hawija, a small IS-controlled Iraqi town. She said the doctor, who was the IS head of the town hospital, also abused her.

From there, after more than a year, she managed to contact her relatives in secret.

Her uncle said the family paid local smugglers $800 to arrange Lamiya’s escape. She will be reunited with her siblings in Germany, but despite everything, her heart remains in Iraq.

“We had a nice house with a big farm … I was going to school,” she said. “It was beautiful.”