Massive MIMO systems are vulnerable to pilot spoofing attacks (PSAs) since the estimated channel state information can be contaminated by the eavesdropping link, thus incurring severe information leakage in downlink transmission. To safeguard legitimate communications, this paper proposes a PSA detection method which relies on pilot manipulation. Specifically, users randomly partition pilot sequences into two parts, where the first part remains unchanged and the second one is multiplied with a diagonal matrix. Although a malicious node may follow the same way to send pilots, this makes it more likely to be detected. According to the principle of the likelihood-ratio test, the proposed detector is designed based on a decision metric that does not include the legitimate channel. This feature differentiates our scheme from existing ones and remarkably improves the detection accuracy. Besides, the possibility of performance enhancement by joint detection is discussed. Furthermore, based on pilot manipulation, a jamming-resistant receiver is designed. The key of this receiver is a new channel estimator that is robust to the PSA. Finally, extensive simulations are carried out to validate our proposed algorithms.