After more than four months in captivity, the Pakistani Taliban on Thursday released 17 teenage boys after they mistakenly crossed the Afghan border in September, according to a senior Pakistani government official.

More than 30 boys between the ages of 10 and 30 were kidnapped from Pakistan's Bajaur tribal region during a celebration marking the Eid holiday. The militant group released the boys with conditions, according to Islam Zeb, an administration official in Bajaur Agency, a stronghold of the country's Taliban, CNN reported. But at least eight are still being held.

Zeb said they were not harmed while being held.

In early October, two of the boys managed to escape custody. The Taliban reportedly said they kidnapped member of the Mamund tribe because it supported the Pakistani government. CNN reported a Taliban representative saying the abduction was a means of revenge for a pro-government militia's battle against the group.

The border between Pakistan and Afghanistan has long created challenged for the authorities. According to the Pakistani government, militants position themselves just across the border in Afghanistan's eastern province of Kunar, making it easier to carry out attacks in northwestern Pakistan, the BBC reported.