Abstract:Prompt injection attacks have become an increasingly serious security threat to large language models (LLMs) and are ranked first in the OWASP Top 10 for LLM applications. Such attacks induce LLMs to generate misleading outputs by embedding malicious content in prompts, thus posing serious security risks such as information leakage and system abuse. However, current evaluation metrics for attack strategies against such attacks only include the attack success rate, making it difficult to comprehensively assess attack effectiveness. In terms of defense strategies, existing methods can typically be used for either prevention or detection, but it is difficult to achieve both simultaneously. This study presents an in-depth analysis of the characteristics of prompt injection attacks and defenses, as well as their impact on LLM outputs, and proposes an integrated attack-defense framework termed Int-AD. The proposed framework includes a prompt injection attack method, control-output attack (CoA), which employs sentiment enhancement and output control, and a defense strategy, universal defense (UnD), which possesses both prevention and detection capabilities. In terms of attacks, two new evaluation metrics are defined: attack interference rate (AIR) and attack misdirection rate (AMR), which are used to conduct precise evaluations under different attack outcomes, thus improving the evaluation metrics. By designing prompts with sentiment enhancement and output control, AIR and AMR are combined with the existing METEOR evaluation metric to assess the attack efficiency of CoA. On the defense side, UnD possesses both prevention and detection capabilities, which improves the defense success rate and enables the detection of the impact of prompt injection attacks. Experiments are conducted on three mainstream large models, Qwen, Llama, and DeepSeek, using the squad and web_questions public datasets. The average METEOR score of the CoA attack method is 0.050, which is 42.5% lower than that of the current best method, Combine. The average AIR and AMR reach 0.97 and 0.45, respectively, representing improvements of 6.59% and 28.57% over Combine and indicating that CoA possesses stronger attack capability. The average defense success rate of UnD is 80.6%, which is 9.07% higher than that of the current best method, Sandwich. Its average knownanswer matching rate (KMR) is 0.921, which is 58.52% higher than that of the Knownanswer method, indicating that UnD possesses stronger defense capability.