关于Mysql + asp.net注射能支持多语句的感慨
2010-09-08 09:10
176 查看
在一篇老外的文章里面看到一个图表,致使Mysql + Asp.Net 注入时支持多语句
真的?有点不信,测试了下:
protected void Page_Load(object sender, EventArgs e)
{
try
{
Response.Write("使用Mysql.Data.MySqlClient<br /><br />");
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 + "<br />");
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驱动<br /><br />");
// 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 + "<br />");
// 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能不能多语句执行,这和处理它的数据库驱动有很大关系。不知道是不是绝对联系,但是至少是一个重要的因素。
推而广之呢?
真的?有点不信,测试了下:
protected void Page_Load(object sender, EventArgs e)
{
try
{
Response.Write("使用Mysql.Data.MySqlClient<br /><br />");
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 + "<br />");
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驱动<br /><br />");
// 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 + "<br />");
// 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注射能支持多语句的感慨(2月)
- 关于X64位系统IIS7下支持32位asp.net程序
- Asp.Net关于错误“Sources”参数中指定了多次。“Sources”参数不支持重复项。
- (转)关于X64位系统IIS7下支持32位asp.net程序
- 关于asp.net中的错误提示“将截断字符串或二进制数据。 语句已终止。”
- Asp.Net关于错误“Sources”参数中指定了多次。“Sources”参数不支持重复项。
- 关于asp.net中js文件中文显示支持的问题。
- 关于X64位系统IIS7下支持32位asp.net程序
- 关于X64位系统IIS7下支持32位asp.net程序
- 关于SQL语句中的双引号、单引号和&-------asp.net
- 关于在asp.net中播放MP4格式的视频(好吧,只兼容支持html5的浏览器,ie8及以下的都歇菜了)
- 关于X64位系统IIS7下支持32位asp.net程序
- 推荐三篇文章,分别是关于微软企业库、ASP.NET MVC以及SEO优化
- ASP.NET 工作流:支持长时间运行操作的 Web 应用程序
- 关于ASP.NET验证中的一些事
- ASP.NET常用语句1--20条 非常实用
- 关于云服务器的ASP.Net MVC网站实现被外网访问
- ASP.NET Atlas 为您期待已久的 AJAX 样式的网站提供支持
- 【转】 在 ASP.NET 3.5 中使用同时支持 Ajax Json 和 .NET 客户端的 WCF 服务
- 关于asp.net 的一些好资料地址 , 防止丢失!