真菌感染皮肤病用什么药最好| spf50是什么意思| 大姨妈来了喝红糖水有什么功效| 杜鹃花什么时候开| 直接胆红素高是什么病| 微尘是什么意思| 什么是早教| fl是什么意思| 艾滋病初期皮疹是什么样的| no医学上是什么意思| 穿堂风是什么意思| 青榄配什么煲汤止咳做法| 特点是什么| 崩盘是什么意思| 宫颈息肉有什么症状| 右耳朵痒是什么预兆| 铁路12306什么时候放票| 边缘化是什么意思| 去痛片又叫什么名| 开飞机是什么意思| 湿气是什么原因造成的| 鸡拉白色稀粪吃什么药| 什么是变态| 突然好想你你会在哪里是什么歌| 入定是什么意思| 头孢喝酒有什么反应| hpv11阳性是什么意思| 上升星座什么意思| 366红包代表什么意思| 媾是什么意思| 什么是植物| 胸痛一阵一阵的痛什么原因| 专科女生学什么专业好| 清款是什么意思| 物以类聚人以群分什么意思| 笑对人生是什么意思| pao2是什么意思| 骨裂吃什么药| 白醋洗脸有什么效果| 自言自语说话是什么病| 葡萄糖高是什么意思| 接驳是什么意思| fda是什么| 浓绿的什么| 茜草别名又叫什么| 吃蛋白粉有什么好处和坏处| 小孩牙疼吃什么药| 什么是音爆| 吃什么排黑色素最强| 女人梦见蛇缠身是什么预兆| 为什么三角形具有稳定性| 胆囊切除后可以吃什么水果| 五险一金的一金是什么| 苦荞茶适合什么人喝| 肤色是什么颜色| 花胶是什么| 早搏心律不齐吃什么药| 可乐鸡翅用什么可乐| 自怨自艾是什么意思| 胖子从12楼掉下来会变什么| 间作套种是什么意思| 俄罗斯是什么洲| 烫伤用什么| 前列腺液是什么东西| 肝功七项查的是什么| 为什么眼皮会跳| 墨菲定律是什么意思| 怀孕第一天有什么症状| flair是什么意思| 下雨天适合穿什么衣服| 青钱柳有什么功效与作用| 女人手心热吃什么调理| 最短的季节是什么| 右肺中叶小结节是什么意思严重吗| 落红是什么意思| 虾青素是什么| 超能力是什么意思| 打封闭针是什么意思| 八月一号是什么星座| 2019年什么生肖| 营养过剩是什么意思| 润滑油是什么| 探望产妇带什么礼物好| 主页是什么意思| 比细菌还小的东西是什么| 梦见自己流产了是什么征兆| 什么是脚气| 喝红糖水有什么好处和坏处| 必修是什么意思| 双鱼座跟什么星座最配| 眼泡是什么意思| 老子为什么叫老子| 1921年属什么生肖| 泥鳅吃什么东西| 麒麟是什么| 口腔上火是什么原因| 什么是副乳| 直肠窝积液是什么意思| 怀孕后乳房有什么变化| 淀粉在超市里叫什么| 喝苹果醋有什么好处和坏处| 前列腺多发钙化灶是什么意思| 吃中药为什么要忌口| 恢复伤口吃什么好得快| 二杠四星是什么军衔| 羊入虎口是什么生肖| 肾看什么科| 什么时候跑步最好| 1月1号是什么星座| 梦见纸钱是什么预兆| 巧囊是什么| 药学是干什么的| 生酮饮食是什么| 精忠报国是什么意思| 什么人不能吃玉米| 感冒喝什么汤| 神机妙算是什么生肖| 丝瓜只开花不结果是什么原因| 松鼠桂鱼是什么鱼| 姹紫嫣红是什么意思| 头皮很痒是什么原因| 莲雾什么味道| 什么叫伴手礼| 小白脸是什么意思| 木耳中毒什么症状| 黎明是什么时候| 老花眼是什么症状| 朱日和是什么意思| 2015属什么生肖| 烧心吃点什么药| 肌钙蛋白高说明什么| 蚰蜒是什么| 二十年是什么婚| 一什么野花| 感冒为什么会打喷嚏| 两会什么时候开| 酶是什么| 头胀是什么原因导致的| 两个a是什么牌子| 风热感冒用什么药好| 梦见打老婆是什么预兆| 血小板分布宽度是什么意思| 子宫肌瘤什么不能吃| 外阴苔藓用什么药膏| 遗精是什么意思啊| 磨破皮了涂什么药| 什么惚惚| 运筹帷幄是什么意思| 痔疮不能吃什么东西| 每天半夜两三点醒是什么原因| 火丹是什么原因造成的| 偏头疼是什么原因引起| 什么声什么气| 狗尾巴草的花语是什么| 隐形眼镜半年抛是什么意思| 什么含维生素d| 养肝护肝吃什么食物| 什么叫生酮| 说话声音小是什么原因| 属猪的跟什么属相最配| 福星高照是什么生肖| 火车为什么会晚点| 6月3日什么星座| 农历9月14日是什么星座| 胃间质瘤是什么性质的瘤| 脚气长什么样| 耳钉后面的塞子叫什么| 中国姓什么的人最多| 拖什么东西最轻松| 痛风有什么症状| 国资委什么级别| 身上发抖是什么原因| 本垒打是什么意思| 胀气吃什么药| 嫖娼是什么| 腿膝盖后面的窝窝疼是什么原因| 85年什么命| 梅花手表属于什么档次| 国师代表什么生肖| 米豆腐是什么做的| 猪心炖什么好吃又营养| 全脂牛奶是什么意思| 100聚酯纤维是什么面料| 钉钉是什么| 媱字五行属什么| 东山再起是什么生肖| 梦见打牌是什么意思| 吃什么补白细胞效果最好| td代表什么意思| 热病是什么病| 1905年属什么生肖| 11月12日什么星座| 水浒传主要讲了什么| 1990年什么生肖| 蒲公英和什么一起泡水喝最好| 什么鸟没有翅膀| 书店买不到的书是什么书| 觉悟高是什么意思| 手术后吃什么恢复快| 梦到小男孩是什么意思| 黄脸婆是什么意思| 大豆是什么| 年兽叫什么| 四月什么星座| 病符是什么意思| 嫁衣是什么意思| 梦见买手表是什么预兆| 料酒是什么| co2是什么意思| 为什么家里有蚂蚁| rsl是什么意思| image是什么意思| chloe是什么意思| 最聪明的狗是什么狗| 眩晕症有什么症状| 农历六月十七是什么星座| 反差是什么意思| tspot检查阳性能说明什么| 日本桑是什么意思| 沵是什么意思| 女儿红是什么酒| 心肌缺血是什么原因引起的| 乳腺结节3类什么意思| 半边脸肿是什么原因| 兰州大学什么专业最好| 出现的反义词是什么| 月经量多是什么原因导致的| 拉大便肛门口疼痛什么原因| 姐姐的婆婆叫什么| 明年是什么生肖| 红枣不能和什么一起吃| 什么的面目| 龙凤胎是什么意思| 喝什么茶可以降血脂| 药流后吃什么消炎药| 吃饭吧唧嘴有什么说法| 喝什么茶降血脂| 什么是肾阴虚和肾阳虚| 布偶猫长什么样| 我还能做什么| 婴儿头发竖起来是什么原因| 黑加仑是什么| 心代表什么数字| 鼻塞喉咙痛吃什么药| 风雨交加是什么生肖| 寒热错杂吃什么中成药| 心脏早搏是什么原因造成的| 肌层回声均匀是什么意思| 什么的绿叶| 毛周角化症用什么药膏| 高中什么时候分文理科| 领导喜欢什么样的员工| 肚脐左上方是什么部位| 头发油腻是什么原因| pedro是什么牌子| 癫痫病是什么症状| 孕妇吃海带有什么好处| 琼字代表什么生肖| 被蜱虫咬了有什么症状| 漆皮是什么皮| super star是什么意思| 血压高为什么| 周六左眼跳是什么预兆| 缺钾吃什么食物| 百度
Skip to content

歼20目前是矢量发动机吗?矢量发动机是什么意思?

Introduction

百度 旅游途中如遇纠纷可以拨打桂林市旅游投诉电话0773-2800315、工商投诉电话0773-12315。

This cheat sheet will help you prevent SQL injection flaws in your applications. It will define what SQL injection is, explain where those flaws occur, and provide four options for defending against SQL injection attacks. SQL Injection attacks are common because:

  1. SQL Injection vulnerabilities are very common, and
  2. The application's database is a frequent target for attackers because it typically contains interesting/critical data.

What Is a SQL Injection Attack?

Attackers can use SQL injection on an application if it has dynamic database queries that use string concatenation and user supplied input. To avoid SQL injection flaws, developers need to:

  1. Stop writing dynamic queries with string concatenation or
  2. Prevent malicious SQL input from being included in executed queries.

There are simple techniques for preventing SQL injection vulnerabilities and they can be used with practically any kind of programming language and any type of database. While XML databases can have similar problems (e.g., XPath and XQuery injection), these techniques can be used to protect them as well.

Anatomy of A Typical SQL Injection Vulnerability

A common SQL injection flaw in Java is below. Because its unvalidated "customerName" parameter is simply appended to the query, an attacker can enter SQL code into that query and the application would take the attacker's code and execute it on the database.

String?query?=?"SELECT?account_balance?FROM?user_data?WHERE?user_name?=?"
             +?request.getParameter("customerName");
try?{
    Statement?statement?=?connection.createStatement(?...?);
    ResultSet?results?=?statement.executeQuery(?query?);
}

...

Primary Defenses

  • Option 1: Use of Prepared Statements (with Parameterized Queries)
  • Option 2: Use of Properly Constructed Stored Procedures
  • Option 3: Allow-list Input Validation
  • Option 4: STRONGLY DISCOURAGED: Escaping All User Supplied Input

Defense Option 1: Prepared Statements (with Parameterized Queries)

When developers are taught how to write database queries, they should be told to use prepared statements with variable binding (aka parameterized queries). Prepared statements are simple to write and easier to understand than dynamic queries, and parameterized queries force the developer to define all SQL code first and pass in each parameter to the query later.

If database queries use this coding style, the database will always distinguish between code and data, regardless of what user input is supplied. Also, prepared statements ensure that an attacker cannot change the intent of a query, even if SQL commands are inserted by an attacker.

Safe Java Prepared Statement Example

In the safe Java example below, if an attacker were to enter the userID as tom' or '1'='1, the parameterized query would look for a username that literally matches the entire string tom' or '1'='1. Thus, the database would be protected against injections of malicious SQL code.

The following code example uses a PreparedStatement, Java's implementation of a parameterized query, to execute the same database query.

//?This?should?REALLY?be?validated?too
String?custname?=?request.getParameter("customerName");
//?Perform?input?validation?to?detect?attacks
String?query?=?"SELECT?account_balance?FROM?user_data?WHERE?user_name?=???";
PreparedStatement pstmt = connection.prepareStatement( query );
pstmt.setString(?1,?custname);
ResultSet?results?=?pstmt.executeQuery(?);

Safe C# .NET Prepared Statement Example

In .NET, the creation and execution of the query doesn't change. Just pass the parameters to the query using the Parameters.Add() call as shown below.

String?query?=?"SELECT?account_balance?FROM?user_data?WHERE?user_name?=??";
try?{
??OleDbCommand?command?=?new?OleDbCommand(query,?connection);
??command.Parameters.Add(new OleDbParameter("customerName", CustomerName Name.Text));
??OleDbDataReader?reader?=?command.ExecuteReader();
??//?…
}?catch?(OleDbException?se)?{
??//?error?handling
}

While we have shown examples in Java and .NET, practically all other languages (including Cold Fusion and Classic ASP) support parameterized query interfaces. Even SQL abstraction layers, like the Hibernate Query Language (HQL) with the same type of injection problems (called HQL Injection) support parameterized queries as well:

Hibernate Query Language (HQL) Prepared Statement (Named Parameters) Example

// This?is?an?unsafe?HQL?statement
Query?unsafeHQLQuery?=?session.createQuery("from?Inventory?where?productID='"+userSuppliedParameter+"'");
// Here?is?a?safe?version?of?the?same?query?using?named?parameters
Query?safeHQLQuery?=?session.createQuery("from?Inventory?where?productID=:productid");
safeHQLQuery.setParameter("productid",?userSuppliedParameter);

Other Examples of Safe Prepared Statements

If you need examples of prepared queries/parameterized languages, including Ruby, PHP, Cold Fusion, Perl, and Rust, see the Query Parameterization Cheat Sheet or this site.

Generally, developers like prepared statements because all the SQL code stays within the application, which makes applications relatively database independent.

Defense Option 2: Stored Procedures

Though stored procedures are not always safe from SQL injection, developers can use certain standard stored procedure programming constructs. This approach has the same effect as using parameterized queries, as long as the stored procedures are implemented safely (which is the norm for most stored procedure languages).

Safe Approach to Stored Procedures

If stored procedures are needed, the safest approach to using them requires the developer to build SQL statements with parameters that are automatically parameterized, unless the developer does something largely out of the norm. The difference between prepared statements and stored procedures is that the SQL code for a stored procedure is defined and stored in the database itself, then called from the application. Since prepared statements and safe stored procedures are equally effective in preventing SQL injection, your organization should choose the approach that makes the most sense for you.

When Stored Procedures Can Increase Risk

Occasionally, stored procedures can increase risk when a system is attacked. For example, on MS SQL Server, you have three main default roles: db_datareader, db_datawriter and db_owner. Before stored procedures came into use, DBAs would give db_datareader or db_datawriter rights to the webservice's user, depending on the requirements.

However, stored procedures require execute rights, a role not available by default. In some setups where user management has been centralized, but is limited to those 3 roles, web apps would have to run as db_owner so stored procedures could work. Naturally, that means that if a server is breached, the attacker has full rights to the database, where previously, they might only have had read-access.

Safe Java Stored Procedure Example

The following code example uses Java's implementation of the stored procedure interface (CallableStatement) to execute the same database query. The sp_getAccountBalance stored procedure has to be predefined in the database and use the same functionality as the query above.

//?This?should?REALLY?be?validated
String?custname?=?request.getParameter("customerName");
try?{
??CallableStatement cs = connection.prepareCall("{call sp_getAccountBalance(?)}");
??cs.setString(1, custname);
??ResultSet?results?=?cs.executeQuery();
??//?…?result?set?handling
}?catch?(SQLException?se)?{
??//?…?logging?and?error?handling
}

Safe VB .NET Stored Procedure Example

The following code example uses a SqlCommand, .NET's implementation of the stored procedure interface, to execute the same database query. The sp_getAccountBalance stored procedure must be predefined in the database and use the same functionality as the query defined above.

?Try
???Dim?command?As?SqlCommand?=?new?SqlCommand("sp_getAccountBalance",?connection)
???command.CommandType = CommandType.StoredProcedure
???command.Parameters.Add(new SqlParameter("@CustomerName", CustomerName.Text))
???Dim?reader?As?SqlDataReader?=?command.ExecuteReader()
???'...
?Catch?se?As?SqlException
???'error?handling
?End?Try

Defense Option 3: Allow-list Input Validation

If you are faced with parts of SQL queries that can't use bind variables, such as table names, column names, or sort order indicators (ASC or DESC), input validation or query redesign is the most appropriate defense. When table or column names are needed, ideally those values come from the code and not from user parameters.

Sample Of Safe Table Name Validation

WARNING: Using user parameter values to target table or column names is a symptom of poor design and a full rewrite should be considered if time allows. If that is not possible, developers should map the parameter values to the legal/expected table or column names to make sure unvalidated user input doesn't end up in the query.

In the example below, since tableName is identified as one of the legal and expected values for a table name in this query, it can be directly appended to the SQL query. Keep in mind that generic table validation functions can lead to data loss if table names are used in queries where they are not expected.

String?tableName;
switch(PARAM):
??case?"Value1":?tableName?=?"fooTable";
?????????????????break;
??case?"Value2":?tableName?=?"barTable";
?????????????????break;
??...
 ?default??????:?throw?new?InputValidationException("unexpected?value?provided"
                                                  + " for?table?name");

Safest Use Of Dynamic SQL Generation (DISCOURAGED)

When we say a stored procedure is "implemented safely," that means it does not include any unsafe dynamic SQL generation. Developers do not usually generate dynamic SQL inside stored procedures. However, it can be done, but should be avoided.

If it can't be avoided, the stored procedure must use input validation or proper escaping, as described in this article, to make sure that all user supplied input to the stored procedure can't be used to inject SQL code into the dynamically generated query. Auditors should always look for uses of sp_execute, execute or exec within SQL Server stored procedures. Similar audit guidelines are necessary for similar functions for other vendors.

Sample of Safer Dynamic Query Generation (DISCOURAGED)

For something simple like a sort order, it is best if the user supplied input is converted to a boolean, and then that boolean is used to select the safe value to append to the query. This is a very standard need in dynamic query creation.

For example:

public?String?someMethod(boolean?sortOrder)?{
?String?SQLquery?=?"some?SQL?...?order?by?Salary?"?+?(sortOrder???"ASC"?:?"DESC");`
?...

Any time user input can be converted to a non-String, like a date, numeric, boolean, enumerated type, etc. before it is appended to a query, or used to select a value to append to the query, this ensures it is safe to do so.

Input validation is also recommended as a secondary defense in ALL cases, even when using bind variables as discussed earlier in this article. More techniques on how to implement strong input validation is described in the Input Validation Cheat Sheet.

Defense Option 4: STRONGLY DISCOURAGED: Escaping All User-Supplied Input

In this approach, the developer will escape all user input before putting it in a query. It is very database specific in its implementation. This methodology is frail compared to other defenses, and we CANNOT guarantee that this option will prevent all SQL injections in all situations.

If an application is built from scratch or requires low risk tolerance, it should be built or re-written using parameterized queries, stored procedures, or some kind of Object Relational Mapper (ORM) that builds your queries for you.

Additional Defenses

Beyond adopting one of the four primary defenses, we also recommend adopting all of these additional defenses to provide defense in depth. These additional defenses are:

  • Least Privilege
  • Allow-list Input Validation

Least Privilege

To minimize the potential damage of a successful SQL injection attack, you should minimize the privileges assigned to every database account in your environment. Start from the ground up to determine what access rights your application accounts require, rather than trying to figure out what access rights you need to take away.

Make sure that accounts that only need read access are only granted read access to the tables they need access to. DO NOT ASSIGN DBA OR ADMIN TYPE ACCESS TO YOUR APPLICATION ACCOUNTS. We understand that this is easy, and everything just "works" when you do it this way, but it is very dangerous.

Minimizing Application and OS Privileges

SQL injection is not the only threat to your database data. Attackers can simply change the parameter values from one of the legal values they are presented with, to a value that is unauthorized for them, but the application itself might be authorized to access. As such, minimizing the privileges granted to your application will reduce the likelihood of such unauthorized access attempts, even when an attacker is not trying to use SQL injection as part of their exploit.

While you are at it, you should minimize the privileges of the operating system account that the DBMS runs under. Don't run your DBMS as root or system! Most DBMSs run out of the box with a very powerful system account. For example, MySQL runs as system on Windows by default! Change the DBMS's OS account to something more appropriate, with restricted privileges.

Details Of Least Privilege When Developing

If an account only needs access to portions of a table, consider creating a view that limits access to that portion of the data and assigning the account access to the view instead of the underlying table. Rarely, if ever, grant create or delete access to database accounts.

If you adopt a policy where you use stored procedures everywhere, and don't allow application accounts to directly execute their own queries, then restrict those accounts to only be able to execute the stored procedures they need. Don't grant them any rights directly to the tables in the database.

Least Admin Privileges For Multiple DBs

The designers of web applications should avoid using the same owner/admin account in the web applications to connect to the database. Different DB users should be used for different web applications.

In general, each separate web application that requires access to the database should have a designated database user account that the application will use to connect to the DB. That way, the designer of the application can have good granularity in the access control, thus reducing the privileges as much as possible. Each DB user will then have select access to only what it needs, and write-access as needed.

As an example, a login page requires read access to the username and password fields of a table, but no write access of any form (no insert, update, or delete). However, the sign-up page certainly requires insert privilege to that table; this restriction can only be enforced if these web apps use different DB users to connect to the database.

Enhancing Least Privilege with SQL Views

You can use SQL views to further increase the granularity of access by limiting the read access to specific fields of a table or joins of tables. It could have additional benefits.

For example, if the system is required (perhaps due to some specific legal requirements) to store the passwords of the users, instead of salted-hashed passwords, the designer could use views to compensate for this limitation. They could revoke all access to the table (from all DB users except the owner/admin) and create a view that outputs the hash of the password field and not the field itself.

Any SQL injection attack that succeeds in stealing DB information will be restricted to stealing the hash of the passwords (could even be a keyed hash), since no DB user for any of the web applications has access to the table itself.

Allow-list Input Validation

In addition to being a primary defense when nothing else is possible (e.g., when a bind variable isn't legal), input validation can also be a secondary defense used to detect unauthorized input before it is passed to the SQL query. For more information please see the Input Validation Cheat Sheet. Proceed with caution here. Validated data is not necessarily safe to insert into SQL queries via string building.

SQL Injection Attack Cheat Sheets:

The following articles describe how to exploit different kinds of SQL injection vulnerabilities on various platforms (that this article was created to help you avoid):

Description of SQL Injection Vulnerabilities:

How to Avoid SQL Injection Vulnerabilities:

How to Review Code for SQL Injection Vulnerabilities:

How to Test for SQL Injection Vulnerabilities:

iwc是什么牌子手表 牙齿酸痛什么原因 尿检ph值是什么意思 八月17号是什么星座的 2026年属什么生肖
八月三十日是什么星座 眼球有黑色斑点是什么 什么服务 阿司匹林肠溶片什么时候吃最好 乙酰磺胺酸钾是什么
神经性皮炎是什么 media是什么意思 韭黄炒什么好吃 不苟言笑的苟是什么意思 驼鸟吃什么食物
choice是什么意思 一心一意是什么生肖 为什么喝咖啡会拉肚子 低血压高吃什么药 菠菜什么时候传入中国
黄瓜有什么功效hcv8jop2ns9r.cn esd手术是什么意思luyiluode.com 小孩头晕是什么原因hcv8jop9ns6r.cn 淋巴结肿大吃什么药消肿效果好hcv8jop9ns0r.cn 今年是什么年啊hcv7jop5ns5r.cn
吃什么才能提高免疫力hcv8jop9ns6r.cn 眉毛下方有痣代表什么hcv9jop1ns1r.cn 每次睡觉都做梦为什么hcv9jop2ns2r.cn 营卫不和吃什么中成药hcv8jop1ns1r.cn 剖腹产后可以吃什么食物hcv8jop4ns2r.cn
锁阳是什么东西hcv8jop6ns2r.cn 经常感冒发烧是什么原因hcv7jop9ns4r.cn 50年是什么婚hcv8jop3ns4r.cn close是什么意思gangsutong.com 戊肝抗体igg阳性是什么意思hcv9jop2ns2r.cn
山楂片泡水喝有什么好处hcv8jop8ns1r.cn 人大常委会主任是什么级别helloaicloud.com emr是什么意思kuyehao.com 直博生是什么意思hcv8jop0ns7r.cn 痔疮吃什么水果xinmaowt.com
百度