More than 400 passengers were on board a train in south-west Pakistan when armed militants attacked.