473,383 Members | 1,929 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

Have been hacked ????

My database suddently dissapeared from my ISP. I've logged in and the
database doesn't exist anymore.

I don't know anything about website hacking, so my code is possibly open for
hackers.

I've my local code and would like to know if my code is open for hackers.
I'd like to see if it's possible to drop a database by simply insert mysql
statement in any field (text box or anything). Does anybody know how to
check ?

Bob
Jul 17 '05 #1
6 1702
.oO(Bob Bedford)
I've my local code and would like to know if my code is open for hackers.
I'd like to see if it's possible to drop a database by simply insert mysql
statement in any field (text box or anything). Does anybody know how to
check ?


Google for (Advanced) SQL Injection.

Micha
Jul 17 '05 #2
Thanks for your reply Michael.
I've my local code and would like to know if my code is open for hackers.
I'd like to see if it's possible to drop a database by simply insert mysql
statement in any field (text box or anything). Does anybody know how to
check ?


Google for (Advanced) SQL Injection.

I can't check the injection technique: here is my code:
$colname_Recordset1 = $HTTP_POST_VARS['User'];
$colname_Recordset2 = $HTTP_POST_VARS['Pass'];
$query_Recordset1 = "SELECT * FROM person WHERE User =
\"$colname_Recordset1\" AND Pass = \"$colname2_Recordset1\";";

I insert this (user/pass):
" OR 1="1
" OR 1="1
Now, the query result is:
SELECT * FROM person WHERE User = "\" OR 1=\"1" AND Pass = "\" OR 1=\"1";

How to be sure it can't be hacked ?
Jul 17 '05 #3
Bob Bedford wrote:
Thanks for your reply Michael.
I've my local code and would like to know if my code is open for hackers.
I'd like to see if it's possible to drop a database by simply insert
mysql statement in any field (text box or anything). Does anybody know
how to check ?


Google for (Advanced) SQL Injection.

I can't check the injection technique: here is my code:
$colname_Recordset1 = $HTTP_POST_VARS['User'];
$colname_Recordset2 = $HTTP_POST_VARS['Pass'];
$query_Recordset1 = "SELECT * FROM person WHERE User =
\"$colname_Recordset1\" AND Pass = \"$colname2_Recordset1\";";

I insert this (user/pass):
" OR 1="1
" OR 1="1
Now, the query result is:
SELECT * FROM person WHERE User = "\" OR 1=\"1" AND Pass = "\" OR 1=\"1";

How to be sure it can't be hacked ?


You can *never* *ever* trust data that comes from a post, a get or a cookie,
and must *always* escape quotes in strings (or use database libraries that
do it for you with placeholders in the queries, or via the use of stored
procedures if the DBMS supports them).

So in your example above, you should be doing the following:

$colname_Recordset1 = addslashes($HTTP_POST_VARS['User']);
$colname_Recordset2 = addslashes($HTTP_POST_VARS['Pass']);

OR

$colname_Recordset1 = mysql_escape_string($HTTP_POST_VARS['User']);
$colname_Recordset2 = mysql_escape_string($HTTP_POST_VARS['Pass']);

OR

$colname_Recordset1 = mysql_real_escape_string($HTTP_POST_VARS['User']);
$colname_Recordset2 = mysql_real_escape_string($HTTP_POST_VARS['Pass']);

If it's an integer value you are expecting then cast it as one like so:

$trusted_integer_value = (int)$HTTP_POST_VARS['untrusted_value'];

If you don't do this, someone may be able to figure out how to modify the
query by passing a quote character (especially if any errors such as the
query itself are output to the web page in the event of an error), end the
query so it is valid, and then start another query which deletes all data
from the table, or something else similar.

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #4
.oO(Bob Bedford)
Thanks for your reply Michael.
I've my local code and would like to know if my code is open for hackers.
I'd like to see if it's possible to drop a database by simply insert mysql
statement in any field (text box or anything). Does anybody know how to
check ?
Google for (Advanced) SQL Injection.

I can't check the injection technique: here is my code:
$colname_Recordset1 = $HTTP_POST_VARS['User'];


Use $_POST instead, the old $HTTP_*_VARS arrays are deprecated.
$colname_Recordset2 = $HTTP_POST_VARS['Pass'];
$query_Recordset1 = "SELECT * FROM person WHERE User =
\"$colname_Recordset1\" AND Pass = \"$colname2_Recordset1\";";
Use single quotes around strings in a query. Double quotes are a MySQL
extension to the SQL standard and might not work on all systems.
I insert this (user/pass):
" OR 1="1
" OR 1="1
Now, the query result is:
SELECT * FROM person WHERE User = "\" OR 1=\"1" AND Pass = "\" OR 1=\"1";
Looks like PHP's magic quotes take effect, but I wouldn't rely on that.

In fact in my code I use a kind of input filter function to remove the
magic quotes before my application code gets its hands on the data. This
way I can do all the necessary escaping stuff on my own and don't have
to rely on a particular configuration setting.
How to be sure it can't be hacked ?


Most important rule: Never trust any user-submitted data. Never.
Everything(!) that comes in via GET or POST can be manipulated.
Really everything, even the content of hidden or read-only form fields.

Before using a user-submitted data in a query think about what values
are allowed and validate/adjust accordingly:

* If the field is numeric it's pretty simple, use intval() for casting
to an integer or something like that.

* If one value from a given set of values is allowed, store all allowed
values in an array and use in_array() to check if the submitted value is
an allowed one.

* Strings are a bit more difficult. With MySQL it should be enough to
run the submitted data through mysql_escape_string(), this will escape
all special characters like single quotes. First check the setting of
the magic quotes with get_magic_quotes_gpc() to avoid double escaping.

It would make sense to write some simple functions for handling the
data, so you don't have to write the validation code again and again.

Second important rule: Even if the data made it successfully into the
database doesn't mean the danger is over. Whenever you fetch some data
from your db to re-use it in another query validate again. Otherwise an
attacker might be able to inject code that doesn't work on the first
insert, but on the re-using of the data (second-order SQL injection).

HTH
Micha
Jul 17 '05 #5
Dont know if i am missing something here as i'm a bit of a PhP/SQL
newb but here goes:

Surely if the correct permissions are given to the web user,
tables/databases cannot be dropped?

The account on my machine which is used by webusers is restricted to
select, update, delete etc and drop is most certainly not allowed!

Stop me if i'm missing something obvious :)
Jul 17 '05 #6
Lozarythmic wrote:
Dont know if i am missing something here as i'm a bit of a PhP/SQL
newb but here goes:

Surely if the correct permissions are given to the web user,
tables/databases cannot be dropped?

The account on my machine which is used by webusers is restricted to
select, update, delete etc and drop is most certainly not allowed!

Stop me if i'm missing something obvious :)


Even if you don't have rights to drop a table, you can still do a lot of
damage with delete rights. delete * from tablename is pretty damaging...

--
Chris Hope - The Electric Toolbox - http://www.electrictoolbox.com/
Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: arkain denial | last post by:
this site can't be hacked: http://www.bleacheatingfreaks.com/?ref=Goat_Punisher
13
by: Mike | last post by:
Apparently there is now a way to hide html source code. How it done? For example see: See http://www.eteamz.com/banksblaze/
0
by: Christian Schuhegger | last post by:
Hi, I remember that I've seen some time ago (perhaps a year or so) a project on freshmeat where a guy hacked a postgres c-interface library (i guess it was libpq / or perhaps he just used the...
2
by: codefixer | last post by:
Hello: The phpBB sites are hacked. If you search for "HACKED BY CYBER-ATTACK" on msn.com you will get a list of all the sites hacked. Anyone knows what is the way to clean this up ? Thanks.
5
by: David Carter | last post by:
Hello I switched my computer on today and found that a new login of "ASP.net" had been added, it was a full priviledge account. Can anyone tell me what has happened? I have no idea what ASP is so...
9
by: Alan Silver | last post by:
Hello, I have a user control which I am trying to load dynamically, but am running into problems. I think the problem is because I have two .ascx files that refer to the same .ascx.cs file. A...
8
by: Oski | last post by:
Hello, our server got hacked through a security hole in an open source php chat script. (nothing new so far, ok!) This chat script allowed the user to create a new php script on our server,...
4
by: Michael Rodriguez | last post by:
Is it possible to have a Windows form that is declared as a generic type, i.e.: public partial class DataEntry<T, C: DataEntryBase where T: ... where C: ... I tried that, but it chokes on...
0
by: vikassaxena | last post by:
website was hacked on 24 march , the script the browser is gettting from server was normal but still the the browser shows it's being hacked when after saving the view source i open it on...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.