Militants have attacked a military base in north Iraq, kidnapped 20 soldiers and later shot them dead, officers and a morgue employee say.