Lessons from the war in Ukraine are reverberating in Pakistan, where security forces are improvising new defenses against Islamist insurgents.