peri hokiperihokiclarustologisticsrimashaop.compola taktis menang gates of olympus x1000 perihokipemain perihoki bongkar trik jepep starlight princess x1000perihoki beri panduan lengkap bermain mahjong ways 2 pgsofttips cara penghasil uang pgsoft mahjong ways 2 perihokimahjong wins 3 perihoki memberikan penggali terbesarfenomena gates of olympus buka peluang besar bagi duta76cara dapat pola emas rahasia di duta7 wild west goldtrik menang pgsoft mahjong ways 2 modal receh maxwin duta76duta76 main pgsoft mahjong ways 2 di sela istirahatscatter hitam mahjong wins 3 spin pasti jepe duta76perihoki spin mahjong ways 2 pgsoft scatter hitam maxwinsimbol mahjong wins 3 yang sering muncul di awal perihokitrik gampang menang mahjong winscuan mahjong wins 3 tanpa hentipola spin taruhan kecil mahjong winsstrategi kunci scatter hitam beruntungacor total mahjong wayskemenangan maksimal mahjong wayskemenangan pria pekanbaru mahjong waysmahjong wins3 fenomena baru sumatera baratmenangkan mahjong dengan lincahmenembus batas keberuntungan mahjong waysmenjajal keberuntungan di mahjong wayspola gratis mahjong ways1scatter hitam senjata rahasia mahjong winsteknik spinning menguntungkan untuk scatter hitamanalisis rtp tertinggi mahjong winsfenomena scatter hitam mahjong winsibu rumah tangga dan keberuntungan mahjongkeseruan main mahjong wins3menang mahjong pengguna baru di sosial mediamenghargai setiap momen di mahjong waysserunya main mahjong di warung internetspin slow motion mancing scatterstrategi jitu maxwin mahjong waysstrategi jitu menang mahjong modal kecil jackpot besaranak kampung papua menggemparkan mahjongkeajaiban scatter hitam mahjong wayskeberhasilan joni mahjong winskejaiban mahjong ways di ujung jalanketua mahjong wins3 kehadiran kemenangan dimulai dari balimahjong kehadiran yang menguntungkanmahjong menggila adat88panduan kilat raih 108 jutatips memenangkan mahjongbarista kopi menang 110 juta spin mahjongdakota76 scatter hitam mahjong wins 3gagal cpns menang mahjong wins 3 rp120 jutakisah karyawan minimarket dapat thr lebih awal mahjong winskisah pelajar sma kuasai mahjong wins 3 inspirasi sekolahkisah penjaga parkir tanah abang motor baru mahjong winskisah sukses ibu rumah tangga bandung mahjong winsmahasiswa kkn beli iphone15 mahjong wins3 dakotamantan anak band influencer mahjong scatter hitampola rtp senin gates of olympus guru matematikatukang cuci motor menemukan keberuntungan di mahjong

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 282

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: session_set_cookie_params(): Cannot change session cookie parameters when headers already sent

Filename: Session/Session.php

Line Number: 294

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 304

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 314

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 315

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 316

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 317

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: Session/Session.php

Line Number: 375

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: ini_set(): Headers already sent. You cannot change the session module's ini settings at this time

Filename: drivers/Session_files_driver.php

Line Number: 108

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: session_set_save_handler(): Cannot change save handler when headers already sent

Filename: Session/Session.php

Line Number: 110

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

A PHP Error was encountered

Severity: Warning

Message: session_start(): Cannot start session when headers already sent

Filename: Session/Session.php

Line Number: 143

Backtrace:

File: /home/blogchuabenh/domains/freetuts.net/public_html/site/controllers/Main_controller.php
Line: 10
Function: __construct

File: /home/blogchuabenh/domains/freetuts.net/public_html/sources/index.php
Line: 299
Function: require_once

File: /home/blogchuabenh/domains/freetuts.net/public_html/index.php
Line: 26
Function: require_once

SQL Injection trong SQLite - Freetuts
CĂN BẢN
NÂNG CAO
CÁC CHỦ ĐỀ
BÀI MỚI NHẤT
MỚI CẬP NHẬT

SQL Injection trong SQLite

Trong bài học hôm nay chúng ta sẽ cùng tìm hiểu một khái niệm khá quan trọng trong SQLite đó là injection. Vậy injection trong SQLite là gì? Chúng ta sẽ cùng tìm hiểu trong nội dung tiếp theo.

test php

banquyen png
Bài viết này được đăng tại freetuts.net, không được copy dưới mọi hình thức.

1. Injection trong SQLite là gì?

Nếu bạn nhận user input thông qua một Webpage và chèn nó vào trong một cơ sở dữ liệu trong SQLite, thì vô tình bạn đã mở rộng cửa cho vấn đề bảo mật ra bên ngoài, được gọi là SQL Injection. Trong bài này sẽ hướng dẫn bạn cách ngăn cản tình huống này xảy ra và giúp bạn bảo vệ script của bạn và các lệnh SQLite của bạn.

Injection xảy ra khi bạn yêu cầu người dùng nhập liệu, ví dụ như tên của họ và thay vì họ nhập tên , họ sẽ cung cấp cho bạn một câu lệnh SQLite mà bạn sẽ vô tình chạy trên cơ sở dữ liệu của bạn.

Đừng bao giờ tin tưởng dữ liệu do người dùng cung cấp, chúng ta chỉ xử lý dữ liệu này sau khi đã xác thực dữ liệu đó an toàn, và như một qui tắc, điều này được thực hiện bởi Pattern Matching (so khớp mẫu).

Bài viết này được đăng tại [free tuts .net]

Trong ví dụ sau, tên người dùng được giới hạn ở các ký tự chữ và số cộng với dấu gạch dưới và độ dài từ 8 đến 20 ký tự.

if (preg_match("/^\w{8,20}$/", $_GET['username'], $matches)){
   $db = new SQLiteDatabase('filename');
   $result = @$db->query("SELECT * FROM users WHERE username = $matches[0]");
} else {
   echo "username not accepted";
}

Để chứng minh vấn đề nói trên, chúng ta cùng xem xét đoạn script sau:

$name = "Qadir'; DELETE FROM users;";
@$db->query("SELECT * FROM users WHERE username = '{$name}'");

Hàm trên dùng để lấy một bản ghi từ bảng users trong đó cột username khớp với $name do người dùng chỉ định. Trong các trường hợp thông thường, $name sẽ chỉ chứa các ký tự chữ và số và có thể có khoảng trắng, chẳng hạn như chuỗi ilia. Tuy nhiên, trong trường hợp này, bằng cách nối thêm một truy vấn hoàn toàn mới vào $name, lời gọi đến cơ sở dữ liệu sẽ biến thành một thảm họa. Truy vấn DELETE được chèn sẽ xóa tất cả các bản ghi khỏi bảng users.

Có một số cơ sở dữ liệu không cho phép query stacking hoặc thực hiện nhiều truy vấn trong một lệnh gọi hàm đơn. Nếu bạn cố gắng stack queries, lời gọi thất bại nhưng SQLitePostgreSQL lại cho thực hiện stacked queries, thực hiện tất cả các truy vấn được cung cấp trong một chuỗi và tạo ra sự cố bảo mật nghiêm trọng.

2. Ngăn chặn Injection trong SQLite

Bạn có thể xử lý tất cả escape characters một cách thông minh bằng các ngôn ngữ script như PERLPHP. Ngôn ngữ lập trình PHP cung cấp hàm sqlite_escape_opes() để escape input characters đặc biệt đối với SQLite.

if (get_magic_quotes_gpc()) {
   $name = sqlite_escape_string($name);
}
$result = @$db->query("SELECT * FROM users WHERE username = '{$name}'");

Mặc dù mã hóa giúp chèn dữ liệu an toàn, nhưng nó sẽ hiển thị các so sánh văn bản đơn giản và các mệnh đề LIKE trong các truy vấn của bạn không sử dụng được cho các cột chứa dữ liệu nhị phân.

Lưu ý - addcslashes() không nên được sử dụng để trích dẫn các chuỗi của bạn cho các truy vấn SQLite. Nó sẽ dẫn đến kết quả lạ khi lấy dữ liệu của bạn.

Cùng chuyên mục:

Các hàm hữu ích trong SQLite

Các hàm hữu ích trong SQLite

SQLite có nhiều hàm dựng sẵn để thực hiện xử lý trên dữ liệu chuỗi…

Date & Time trong SQLite

Date & Time trong SQLite

SQLite hỗ trợ năm hàm ngày và giờ như date(timestring, modifiers...), time(timestring, modifiers...), datetime(timestring, modifiers...),…

VACUUM trong SQLite

VACUUM trong SQLite

Lệnh VACUUM trong SQLite làm sạch cơ sở dữ liệu chính bằng cách sao chép…

EXPLAIN trong SQLite

EXPLAIN trong SQLite

Câu lệnh SQLite có thể được bắt đầu bằng từ khóa "EXPLAIN" hoặc bằng cụm…

Tăng tự động AUTOINCREMENT trong SQLite

Tăng tự động AUTOINCREMENT trong SQLite

AUTOINCREMENT trong SQLite là một từ khóa được sử dụng để tự động tăng giá…

Subquery trong SQLite

Subquery trong SQLite

Subquery hoặc Inner query hoặc Nested query là một truy vấn bên trong một truy…

Transaction trong SQLite

Transaction trong SQLite

Một transaction là một đơn vị công việc được thực hiện đối với một cơ…

Tìm hiểu View trong SQLite

Tìm hiểu View trong SQLite

Một view không có gì khác hơn một câu lệnh SQLite được lưu trữ trong…

Lệnh TRUNCATE TABLE trong SQLite

Lệnh TRUNCATE TABLE trong SQLite

Thật không may, không có lệnh TRUNCATE TABLE trong SQLite nhưng bạn có thể sử…

Lệnh ALTER TABLE trong SQLite

Lệnh ALTER TABLE trong SQLite

Lệnh ALTER TABLE trong SQLite dùng để sửa đổi một bảng hiện có mà không…

Mệnh đề INDEXED BY trong SQLite

Mệnh đề INDEXED BY trong SQLite

Mệnh đề "INDEXED BY index-name" chỉ định rằng index-name phải được sử dụng để tìm…

Index trong SQLite

Index trong SQLite

Index là bảng tra cứu đặc biệt mà database search engine có thể sử dụng…

Tìm hiểu Trigger trong SQLite

Tìm hiểu Trigger trong SQLite

Trigger trong SQLite là các hàm callback, mà tự động được thực hiện/gọi (performed/invoked) khi…

Cú pháp ALIAS trong SQLite

Cú pháp ALIAS trong SQLite

Bạn có thể đổi tên tạm thời một bảng hoặc một cột bằng cách đặt…

Toán tử UNION trong SQLite

Toán tử UNION trong SQLite

Toán tử UNION trong SQLite được sử dụng để kết hợp các kết quả của…

Lệnh JOIN trong SQLite

Lệnh JOIN trong SQLite

Lệnh JOIN trong SQLite được sử dụng để kết hợp các bản ghi từ hai…

Các ràng buộc Constraint trong SQLite

Các ràng buộc Constraint trong SQLite

Các ràng buộc (Constraints) là các quy tắc được thi hành trên một cột dữ…

Lệnh PRAGMA trong SQLite

Lệnh PRAGMA trong SQLite

Lệnh PRAGMA trong SQLite là một lệnh đặc biệt được sử dụng để kiểm soát…

Từ khóa DISTINCT trong SQLite

Từ khóa DISTINCT trong SQLite

Từ khóa DISTINCT trong SQLite được sử dụng cùng với câu lệnh SELECT để loại…

Mệnh đề HAVING trong SQLite

Mệnh đề HAVING trong SQLite

Mệnh đề HAVING trong SQLite cho phép bạn chỉ định các điều kiện lọc kết…

Top