A breach of South Korea’s military database in which suspected North Korean hackers pilfered defense secrets originated in compromised third-party cybersecurity software and was made possible by an unintended connection to the internet, according to people familiar with the attack.