In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
The editor will share with you what the injection error of mysql sentence refers to. I hope you will gain a lot after reading this article. Let's discuss it together.
The injection error of mysql statement is to insert user data into the actual SQL language by using the external interface of some databases, so as to achieve the purpose of invading the database and even the operating system. Attackers use it to read, modify or delete data in the database, obtain information such as user information and passwords in the database, and more seriously gain administrator privileges.
Sql injection error (SQL injection)
SQL Injection is to insert user data into the actual database operation language (SQL) by using the external interface of some databases, so as to achieve the purpose of invading the database and even the operating system. It is mainly due to the fact that the program does not strictly filter the data input by the user, which leads to the execution of illegal database query statements.
"profound and simple MySQL"
Harm
Attackers use it to read, modify or delete data in the database, obtain information such as user information and passwords in the database, and, more seriously, obtain administrator privileges.
Examples
/ / injection error public static void test3 (String name,String passward) {Connection connection = null; Statement st = null; ResultSet rs = null; try {/ / load JDBC driver Class.forName ("com.mysql.jdbc.Driver"); / / get JDBC connection String url = "jdbc:mysql://localhost:3306/tulun" Connection = DriverManager.getConnection (url, "root", "123456"); / / create a query statement st = connection.createStatement (); / / sql statement String sql = "select * from student where name ='" + name+ "'and passward ='" + passward+ "'"; rs = st.executeQuery (sql) If (rs.next ()) {System.out.println ("login succeeded.") ;} else {System.out.println ("login failed.") } catch (Exception e) {e.printStackTrace ();}} public static void main (String [] args) {test3 ("wjm3' or'1 = 1", "151515");}
Database information
As the above code shows, the user name is wjm3' or'1 = 1, the password is 151515, we can see from the database that we do not have such a user, should have shown login failure, but the result is a successful login, because or'1 = 1 is no longer the contents of the user name, it is now the contents of the SQL statement, in any case, the result is true, which means you do not have to enter a password to log in. There is a security problem here.
Solution method
1. PrepareStatement
/ / injection error public static void test3 (String name,String passward) {Connection connection = null; PreparedStatement st = null; ResultSet rs = null; try {/ / load JDBC driver Class.forName ("com.mysql.jdbc.Driver"); / / get JDBC connection String url = "jdbc:mysql://localhost:3306/tulun" Connection = DriverManager.getConnection (url, "root", "123456"); / / create a query statement String sql1 = "select * from student where name =? And passward =? "; st = connection.prepareStatement (sql1); st.setString (1MagneName); st.setString (2MagneName); / / sql statement / / String sql =" select * from student where name ='"+ name+" 'and passward =' "+ passward+"'"; rs = st.executeQuery () If (rs.next ()) {System.out.println ("login succeeded.") ;} else {System.out.println ("login failed.") ;} catch (Exception e) {e.printStackTrace ();} finally {try {connection.close (); st.close (); rs.close ();} catch (SQLException e) {e.printStackTrace () } public static void main (String [] args) {test3 ("wjm3' or'1 = 1", "151515");}
No matter what the name parameter is, the above code is only a name parameter and will not be executed as part of the sql statement. Generally speaking, this method is recommended and is relatively safe.
two。 Define your own functions for verification
Collate the data to make it effective to reject known illegal input and accept only known legitimate input
So if you want to get the best security state, the best solution is to simply classify the data submitted or may be changed by the user, and apply regular expressions to strictly detect and verify the input data provided by the user.
In fact, you only need to filter illegal symbol combinations to prevent known forms of attacks, and if you find updated attack symbol combinations, you can also add these symbol combinations to continue to prevent new attacks. In particular, space symbols and symbols that separate keywords that have the same effect, such as "/ * /", if successfully filtered, many injection attacks will not occur, and their hexadecimal representation "% XX" will also be filtered.
After reading this article, I believe you have a certain understanding of what the injection error of mysql sentence refers to. Want to know more about it. Welcome to follow the industry information channel. Thank you for your reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.