SQL 服务器中 table 的数据异常

Weird table's data in SQL server

我的数据库中有一个名为 notifications 的 table,只要我的应用程序中的其他用户收到通知,数据就会插入到此 table 中。 table 的架构如下所示:

CREATE TABLE [dbo].[notifications](
    [id] [int] IDENTITY(1,1) NOT NULL,
    [sender] [char](17) NULL,
    [reciever] [char](17) NULL,
    [letter_code] [char](15) NULL,
    [txt] [nvarchar](max) NULL,
    [dateandtime] [datetime2](7) NULL,
    [letter_kind] [nvarchar](50) NULL,
    [seen] [bit] NULL,
 CONSTRAINT [PK_notifications] PRIMARY KEY CLUSTERED 
(
    [id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

插入的行必须是这样的:

id    || sender   ||    reciever || letter_code || txt     ||  dateandtime          || letter_kind ||   seen
============================================================================================================
1     ||   2      ||    2        ||    1734     || message ||   2015-10-12 09:59:01 ||   PS        || flase

今天我在检查数据库的 table 时,发现发生了一些奇怪的事情。一些奇怪的数据被插入notification table:

如您所见,txt 列包含一个非常奇怪的值:

1<div style="display:none">looking to cheat <a href="http://blog.perecruit.com/template/page/reason-women-cheat.aspx">go</a> how many men have affairs</div>

其他列包含 1 ! 有什么想法吗?

PS:我确定只有一处 table 的数据会被写入:

context.InsTotNotification(WebContext.Current.User.UserCode, CheckedUsersForSend.ElementAt(j), LetCods.ElementAt(i),
                                        string.Format("letter kind {0} letter code {1} datetime.",
                                        LetterKind, Convert.ToString(Convert.ToDouble(LetCods.ElementAt(i).Substring(4, 11)), CultureInfo.InvariantCulture)), DateTime.Now, LetterKind);

更新: 没有允许用户输入数据的表单,数据将使用后端而不是用户写入。

更新 2:我首先使用 EntityFramework 数据库,InsTotNotification 是我上下文中的一个存储过程:

    [Invoke]
    public string InsTotNotification(string sender, string reciever,string letter_code,string Txt,DateTime dateandtime,string Letter_kind)
    {
        var MQuery = ObjectContext.InsTo_Notification(sender, reciever, letter_code, Txt, dateandtime, Letter_kind).FirstOrDefault();
        return "Ok";
    }

这是 sp:

SET ANSI_NULLS OFF
GO
SET QUOTED_IDENTIFIER OFF
GO

ALTER PROCEDURE [dbo].[InsTo_Notification]
@Sender char(17), 
@Reciever char(17), 
@Letter_code char(15), 
@Txt nvarchar(MAX), 
@DateandTime datetime2, 
@Letter_kind nvarchar(50)
AS

BEGIN TRANSACTION InsertNotifications
Declare @T1 int
INSERT notifications (sender, reciever, letter_code, txt, dateandtime, letter_kind) 
       values (@Sender, @Reciever, @Letter_code, @Txt, @DateandTime,@Letter_kind)
SELECT @T1=@@ERROR
--------------------------
if (@T1=0)
BEGIN
COMMIT TRANSACTION InsertNotifications
SELECT @Letter_code as LetterNo
END
ELSE
BEGIN
  ROLLBACK TRANSACTION InsertNotifications
  SELECT 'NO' as 'It has Problem'
 END

更新 3:table:

中也有这些类型的行

请注意,所选行中的文本 نامه PS به شماره 11968 به شما ارجاع داده شدtxt 字段的实际值。

绝对SQL注射... 这是来自 Web 应用程序还是可以通过 Web 读取的内容,对吗? 您的存储过程在未经适当验证的情况下接受任何字符输入。 尝试检查参数是否包含“<”、“>”、保留 SQL 服务器 terms/statements 或其他不需要的字符。