Militants attacked a military base in north Iraq, kidnapped 20 soldiers and later shot them dead, police and a morgue employee said on Sunday.