Attacks underscore difficulty in thwarting terrorist groups