Militants claiming allegiance to Islamic State, the Sunni Muslim militant organization based in Iraq and Syria, are scattered across parts of northern and eastern Afghanistan and have carried out increasingly brazen attacks in recent months.