I work on an ASP.NET project (using serenity.is) and have now a problem with a database query :
[HttpGet]
[Route("SimonTest/{id=0}/{obj=0}")]
public ActionResult SimonTest(int id, int obj)
{
SqlConnection myConn = new SqlConnection(@"Server=(LocalDb)\MSSqlLocalDB;Integrated security=SSPI;database=Serene5_Default_v1");
// skipped code building the following command :
command = "INSERT INTO [Serene5_Default_v1].[tcpdump].[Errors] (TimeStp,IdSource,IdDestination,PortSource,PortDestination,ToTheRight,ToTheLeft) VALUES ('11:2','11','1','1','1',1,1);";
System.Diagnostics.Debug.WriteLine(command);
SqlCommand myCommand2 = new SqlCommand(listDb, myConn);
myCommand2.ExecuteNonQuery();
System.Diagnostics.Debug.WriteLine("Commande exécutée");
myCommand2.Dispose();
myConn.Close();
return View("~/Modules/Default/TcpDump/TcpDumpIndex.cshtml");
}
When I execute the query INSERT INTO ... with Microsoft SQL Server Management Studio, nothing goes wrong, but here the command seems to be skipped (no exception raised and nothing written in database)
listDb? Did you mean to usecommandwhen constructing theSqlCommandobject?command!=listDb. No idea what the contents of the latter is, but that's what you're executing.'; drop database x; select 1, 'this will then be concatenated into your SQL and bye bye database. Most likely won't this particular query execute but with some experimentation I should be able to either retrieve data you don't want me to or modify it. This bug is called SQL Injection - w3schools.com/sql/sql_injection.asp.