mysql支持asp.net_关于Mysql + asp.net注射能支持多语句的感慨(2月)
關于Mysql + asp.net注射能支持多語句的感慨
2010-09-07 03:32
在一篇老外的文章里面看到一個圖表,致使Mysql + Asp.Net 注入時支持多語句
真的?有點不信,測試了下:
protected void Page_Load(object sender, EventArgs e)
{
try
{
Response.Write(“使用Mysql.Data.MySqlClient
“);
string myConnectionString = “server=localhost;user id=root;password=123456;database=test”;
MySqlConnection myConnection = new MySqlConnection(myConnectionString);
string myQuery = “select * from admin where id=” + Request.QueryString["id"];
Response.Write(“SQL:” + myQuery + “
“);
MySqlCommand myCommand = new MySqlCommand(myQuery, myConnection);
myConnection.Open();
myCommand.ExecuteReader();
myCommand.Connection.Close();
}
catch (MySqlException err)
{
Response.Write(“Error:” + err.Message);
}
//try
//{
// Response.Write(“使用Mysql ODBC驅動
“);
// string myConnectionString = “DRIVER={MySQL ODBC 3.51 Driver};SERVER=localhost;DATABASE=test;UID=root;PASSWORD=123456;OPTION=3″;
// string myQuery = “select * from admin where id=” + Request.QueryString["id"];
// Response.Write(“SQL:” + myQuery + “
“);
// OdbcConnection myConnection = new OdbcConnection(myConnectionString);
// OdbcCommand myCommand = new OdbcCommand(myQuery, myConnection);
// myConnection.Open();
// myCommand.ExecuteReader();
// myCommand.Connection.Close();
//}
//catch(OleDbException err)
//{
// Response.Write(“Error:” + err.Message);
//}
}
這里面是連接mysql常用的兩個方式,一個是用Mysql.Data.MySqlClient這個類。二個try是使用更加傳統的odbc方式。
Step 1:注釋第一個代碼段,訪問http://localhost:2928/MysqlInj_test/MysqlInj_test.aspx?id=1;create table test(i int) 結果得到如下的錯誤信息:
“/MysqlInj_test”應用程序中的服務器錯誤。
——————————————————————————–
ERROR [42000] [MySQL][ODBC 3.51 Driver][mysqld-5.0.45-community-nt]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘;create table test(i int)’ at line 1
到test庫下面看,表test沒有被創建
Step 2:注釋第二個代碼段,刷新頁面。頁面返回
使用Mysql.Data.MySqlClient
SQL:select * from admin where id=1;create table test(i int)
繼續按F5刷新這個頁面,得到如下消息
使用Mysql.Data.MySqlClient
SQL:select * from admin where id=1;create table test(i int)
Error:Table ‘test’ already exists
跑到test庫看,果然有個叫test的表被創建了。乖乖,看來老外說的是真的,但是對了一半。
原來Mysql能不能多語句執行,這和處理它的數據庫驅動有很大關系。不知道是不是絕對聯系,但是至少是一個重要的因素。
推而廣之呢?
總結
以上是生活随笔為你收集整理的mysql支持asp.net_关于Mysql + asp.net注射能支持多语句的感慨(2月)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql 录入窗体设计_在Access
- 下一篇: python十进制转二进制循环_pyth