The source, who requested anonymity, told AFP that 18 soldiers and 15 police lost their lives in the assault in the town of Buni Yadi, in Yobe state, at about 8:00 pm (1900 GMT) on Monday.
"The militants arrived in vans wearing military uniform and went to the army barracks overlooking the police station," the source added.
"They were mistaken for soldiers and the soldiers opened the gates. They then began the attack."
Multiple witnesses told AFP yesterday that the insurgents fired first on soldiers manning a checkpoint before razing the local police station.
More From This Section
Details were slow to emerge because of poor mobile phone reception in the area, where the militants, who are seeking to establish an Islamic state in northern Nigeria, have destroyed much of the telecommunication infrastructure.
Boko Haram gunmen on April 14 seized more than 200 schoolgirls from the northeastern town of Chibok, provoking international outrage.
A boarding school in Buni Yadi was also attacked in February this year. Suspected Boko Haram militants stormed the Federal Government College and killed more than 40 students as they slept.
The source said the authorities had received reports of an impending attack on the state capital Damaturu and security had been increased but it was not clear whether the city or Buni Yadi was the real taget.