Tuesday, 27 March 2012

Bots and Botnets—A Growing Threat and protection Against


What is a Bot?


A "bot" is a type of malware that allows an attacker to take control over an affected computer. Also known as “Web robots”, bots are usually part of a network of infected machines, known as a “botnet”, which is typically made up of victim machines that stretch across the globe
Since a bot infected computer does the bidding of its master, many people refer to these victim machines as “zombies.” The cybercriminals that control these bots are called botherders or botmasters.
Some botnets might have a few hundred or a couple thousand computers, but others have tens and even hundreds of thousands of zombies at their disposal. Many of these computers are infected without their owners' knowledge. Some possible warning signs? A bot might cause your computer to slow down, display mysterious messages, or even crash.

How Bots Work


Bots sneak onto a person’s computer in many ways. Bots often spread themselves across the Internet by searching for vulnerable, unprotected computers to infect. When they find an exposed computer, they quickly infect the machine and then report back to their master. Their goal is then to stay hidden until they are instructed to carry out a task.
After a computer is taken over by a bot, it can be used to carry out a variety of automated tasks, including the following:
Sending Stealing DoS (Denial of Service) Clickfraud
They send
- spam
- viruses
- spyware
They steal personal and private information and communicate it back to the malicious user:
- credit card numbers
- bank credentials
- other sensitive personal information
Launching denial of service (DoS) attacks against a specified target. Cybercriminals extort money from Web site owners, in exchange for regaining control of the compromised sites.

More commonly, however, the systems of everyday users are the targets of these attacks -- for the simple thrill of the botherder.
Fraudsters use bots to boost Web advertising billings by automatically clicking on Internet ads.

Protect Against Bots


To safeguard against malicious bots, security experts at Symantec offer the following advice:
  1. Install top-rated security software (such as Norton 360) and Norton Internet Security.
  2. Configure your software's settings to update automatically.
  3. Increase the security settings on your browser.
  4. Limit your user rights when online.
  5. Never click on attachments unless you can verify the source.
  6. Ensure that your system is patched with the most current Microsoft Windows Update.
  7. Set your computer’s security settings to update automatically, to
    ensure you always have the most current system patches.

botnet (zombie army)


A botnet (also known as a zombie army) is a number of Internet computers that, although their owners are unaware of it, have been set up to forward transmissions (including spam or viruses) to other computers on the Internet. Any such computer is referred to as a zombie - in effect, a computer "robot" or "bot" that serves the wishes of some master spam or virus originator. Most computers compromised in this way are home-based. According to a report from Russian-based Kaspersky Labs, botnets -- not spam, viruses, or worms -- currently pose the biggest threat to the Internet. A report from Symantec came to a similar conclusion.
Computers that are coopted to serve in a zombie army are often those whose owners
fail to provide effective firewalls and other safeguards. An increasing number of home users have high speed connections for computers that may be inadequately protected. A zombie or bot is often created through an Internet port that has been left open and through which a small Trojan horse program can be left for future activation. At a certain time, the zombie army "controller" can unleash the effects of the army by sending a single command, possibly from an Internet Relay Channel (IRC) site.
The computers that form a botnet can be programmed to redirect transmissions to a specific computer, such as a Web site that can be closed down by having to handle too much traffic - a distributed denial-of-service (DDoS) attack - or, in the case of spam distribution, to many computers. The motivation for a zombie master who creates a DDoS attack may be to cripple a competitor. The motivation for a zombie master sending spam is in the money to be made. Both of them rely on unprotected computers that can be turned into zombies.
According to the Symantec Internet Security Threat Report, through the first six months of 2006, there were 4,696,903 active botnet computers.

Secure Your Bank Account



Enlarge picture
Security on the Internet is just a dream and you know it. If a hacker wants to do something, he or she can do it. If one system is secure and cannot be hacked, then they will steal the data of someone who has access to it, and then, do the "work" from the inside. Do you think you're safe just because some sites ask you for
authentication? Let me tell you that not even CAPTCHA is secure. Nothing is.

Have you noticed that when you want to do an online transaction the bank site asks you a lot of stuff so that they properly identify you? They go very deep with these questions. Indeed, this is a good thing, otherwise, anybody that would know a little something about you could easily get into your account. This just makes it a little harder for you to be a victim of cyber-fraud, but it does not make it impossible...

Of course, there is the classic way with the hoax site. The hackers get your data by making you visit a clone page of your bank and all the data you enter will be sent to them. But that's for gullible users, you're much smarter than that. Well, so are some hackers. Some browsers store your data, such as passwords, usernames and stuff like that. If you get infected with malware, the data on your PC will be recorded by that certain virus and sent to the hacker without you even knowing it. And sometimes you don't even need to get a virus, you just need to download some JavaScript from some page. Apart from the code that the site requires, it will also have some code that will make the hacker get access to your cookies, thus using them to transfer money, change a password and stuff like that.

It isn't easy for the average Joe to hack your account, but hackers can do it, if they strive hard enough. So what to do? Well, first thing is to be careful what you click on and the second is to deploy good security measures on your computer!

Friday, 2 March 2012

Getting the recent one month or year records from MySQL table

Some time we have to collect last 7 or 15 days or X days (or month, year or week) data from MySQL table. For example let us find out who are the new members joined in our forum in last week. One shop may be interested in knowing new products added in last one month. What are the books arrived in last one year. Here irrespective of the date values we want the records of last X days from today, or we can say that the records between today and last X days ( month , year or week) are required.

We will use the MySQL function CURDATE() to get the today's date.

To get the difference in today date and previous day or month we have to use the MySQL function DATE_SUB

DATE_SUB is a MySQL function which takes date expression, the interval and the constant to return the date value for further calculation.

Here are some sample queries on how to get the records as per requirements .


select * from dt_tb where `dt` >= DATE_SUB(CURDATE(), INTERVAL 15 DAY)

The above query will return last 15 days records. Note that this query will return all future dates also. To exclude future dates we have to modify the above command a little by using between query to get records. Here is the modified one.

SELECT * FROM dt_tb WHERE `dt` BETWEEN DATE_SUB( CURDATE( ) ,INTERVAL 15 DAY ) AND CURDATE( )

Let us try to get records added in last one month

select * from dt_tb where `dt` >= DATE_SUB(CURDATE(), INTERVAL 1 MONTH)

Here also future records will be returned so we can take care of that by using BETWEEN commands if required.

select * from dt_tb where `dt` >= DATE_SUB(CURDATE(), INTERVAL 1 YEAR)

You can easily make out what the above query will return.

We can collect records between a particular date ranges by using between command and DATE_SUB. Here are some queries to generate records between two date ranges.

select * from dt_tb where `dt` BETWEEN DATE_SUB( CURDATE( ) ,INTERVAL 3 MONTH ) AND DATE_SUB( CURDATE( ) ,INTERVAL 0 MONTH )

This query will return records between last three months. This query again we will modify to get the records between three moths and six months.

select * from dt_tb where `dt` BETWEEN DATE_SUB( CURDATE( ) ,INTERVAL 6 MONTH ) AND DATE_SUB( CURDATE( ) ,INTERVAL 3 MONTH )

Now let us change this to get records between 6 month and 12 month.

select * from dt_tb where `dt` BETWEEN DATE_SUB( CURDATE( ) ,INTERVAL 12 MONTH ) AND DATE_SUB( CURDATE( ) ,INTERVAL 6 MONTH )

With this you can understand how the records between a month range or a year range can be collected from a table. Note that the months ranges are calculated starting from current day. So if we are collecting records of last three months and we are in 15th day of 9th month then records of 15th day of 6th month we will get but the records of 14th day of 6th month will be returning on next query that is between 3 months and 6 months.

Now let us try a different requirement. How to get the records of the working days of the week so far ? If today is Thursday then records from Monday to Thursday should be returned. We will discuss this in our next section >>.

Here is the sql code to create and fill the table with records

CREATE TABLE `dt_tb` ( `id` int(2) NOT NULL auto_increment, `dt` datetime NOT NULL default '0000-00-00 00:00:00', `dt2` date NOT NULL default '0000-00-00', UNIQUE KEY `id` (`id`) ) ENGINE=MyISAM AUTO_INCREMENT=11 DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ;

INSERT INTO `dt_tb` VALUES (1, '2007-02-15 00:00:00', '2005-01-25');
INSERT INTO `dt_tb` VALUES (2, '2007-02-12 23:56:54', '2005-06-12');
INSERT INTO `dt_tb` VALUES (3, '2005-12-08 13:20:10', '2005-06-06');
INSERT INTO `dt_tb` VALUES (5, '2005-02-10 00:00:00', '2006-01-02');
INSERT INTO `dt_tb` VALUES (6, '2006-11-26 00:00:00', '2006-12-25');
INSERT INTO `dt_tb` VALUES (7, '2006-11-26 00:00:00', '2007-02-25');
INSERT INTO `dt_tb` VALUES (8, '2007-10-20 00:00:00', '2007-10-25');
INSERT INTO `dt_tb` VALUES (9, '2007-02-11 00:00:00', '2007-01-25');
INSERT INTO `dt_tb` VALUES (10, '2007-01-22 00:00:00', '2007-01-15');

Collecting records of current date or from last x seconds From Mysql DataBase

We will try to get all records inserted or updated today. We will use the date and time field which stores the date and time data of the records. While comparing we will use MySQL curdate() function which returns today's date. Here is the query.

SELECT * FROM `test_time2` WHERE tm2 = curdate()

Here our tm field stores date data only. If we are storing date and time both then we have to change the query by adding a greater than equal to comparison.

SELECT * FROM `test_time` WHERE tm >= curdate()

This way we can collect records of present date. We can use DATE_SUB() functions to get the records of last 7 days or 15 days or X days.

Getting all records of last 10 minutes or 5 seconds or last one hour.

We can collect records added or updated in last X seconds by using this query.

SELECT * FROM test_time2 WHERE ( unix_timestamp( ) - unix_timestamp( tm ) ) < 5

The above query will return all records updated within last five seconds. This can be changed to X seconds.

You can modify the above query to return records of last one hour or any time multiples in seconds. This is required in preventing spam postings which automatically adds new posts or replies. We can check this by stopping posted within a particular duration.

toLocaleDateString() in JavaScript

We can convert any date object to local string by using toLcaleDateString like this

Date.toLocaleDateString

Here is a sample code

<script type="text/javascript">
var dt= new Date();
document.write(dt + "<br><br>");
document.write(dt.toLocaleDateString());
</script>

The output is here

Fri Mar 02 2012 13:26:30 GMT+0530 (IST)

Friday 02 March 2012

What is the difference between toDateString and toLocaleDateString. Here is a comparison

<script type="text/javascript">
var dt= new Date();
document.write(dt + "<br><br>");
document.write(dt.toDateString() + "<br><br>");
document.write(dt.toLocaleDateString());
</script>

Check different outputs here

Fri Mar 02 2012 13:26:30 GMT+0530 (IST)

Fri Mar 02 2012

Friday 02 March 2012

Real time changing Clock showing date and time in JavaScript

We can show a count down script displaying time left from an event. Say we are running a campaign which is going to end after two days. Here we will display a counter saying days , hours , minutes and seconds left for the event to happen or the campaign to end. This script uses the setTimeout function in the same way as it is used in displaying a changing clock script. Here this setTimeout script triggers another function in every 1000 mill seconds ( or in 1 sec ).

This script uses client side JavaScript to generate the count down clock. The initial value in number of seconds left for the countdown to end will be passed to the function. At the time of page loading the seconds left ( a numeric value ) is collected and based on this value the days , hours, minutes and seconds are calculated and displayed. So this script can be run by linking to a server side script like PHP or ASP and a powerful dynamic script can be developed. Let us not discuss the server side script part and we will only run the script with some numeric value for seconds which is collected at the time of page loads.

The script uses two functions. While the page loads we use the onload event of the body tag and pass a value to the function display_c().

<body onload=display_c(86501);>

Now this value of 86501 ( in Seconds ) is used to calculate the number of days, hours , minutes and seconds left for the event to happen.

Since this value we are going to use it again and again so we kept this in a global variable to use it inside and outside the functions like this

window.start = parseFloat(start);

WE have used windows object to store a variable in global scope to use throughout the page.

Now in each successive call to the function the value of this window.start is decreased by one after displaying the countdown value. The count down value changes after ever second and it gets the value after a short calculation.

window.start= window.start- 1;

The days left is calculated by taking the Math.floor value after dividing total time by 86400. This value of 86400 is the total number of seconds in a day ( 60 second x 60 minutes x 24 hours )

Similar way values of hours , minutes and seconds are calculated. A detail help is kept with comment lines inside the code.

Finally using a span id the count down is displayed.

Getmonth function using date object in JavaScript

We can use Date object in JavaScript to collect the current month by using getMonth function. We will try to print the present month name by using this getMonth function. Note that getMonth function returns number of month from 0 to 11. That is, it will return 0 if the month is January and will return 1 if the month is February and so on. It will return 11 for the month December.

To display the month name in full, we will write one array with all the month names inside it. Then based on the value returned by getMonth function we will display the corresponding element from this month array.

We will connect our button to display the current month in an alert window. Here is the demo.

Here is the code.


<html>
<head>
<title>(Type a title for your page here)</title>
<script type=\"text/javascript\">
function show_now(){
var my_month=new Date()
//var dt = new Date(\"Aug 16, 2005 05:55:00\");

var month_name=new Array(12);
month_name[0]="January"
month_name[1]="February"
month_name[2]="March"
month_name[3]="April"
month_name[4]="May"
month_name[5]="June"
month_name[6]="July"
month_name[7]="August"
month_name[8]="September"
month_name[9]="October"
month_name[10]="November"
month_name[11]="December"

alert ("Current month = " + month_name[my_month.getMonth()]);
}
</script></head>


<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">

<input type=button value="Show Month" onclick="show_now();">

</body>
</html>

Math.abs() in JavaScript

We can remove the sign part of the data and display the absolute value by using abs function. Here is the syntax

Math.abs(x);

Sample code is here

<script language='JavaScript' type='text/JavaScript'>
<!--
document.write(Math.abs(-5)); // output is 5
document.write("<br>");
document.write(Math.abs(5.56)); // output is 5.56
document.write("<br>");
document.write(Math.abs(-2.5)); // output is 2.5
document.write("<br>");
document.write(Math.abs(-1.355)); // output is 1.355
document.write("<br>");
//-->
</script>

abs() math function can also be used with other calculations

document.write(Math.abs(43-64)); // output is 21

Math Round function in JavaScript

We can round off any number with decimal place to an integer value by using round function. If the decimal portion of the number is equal or greater than .5 then the next higher integer is returned or if the number is less than 05 then the number is rounded to next lowest integer.

Here is the syntax.



Math.round(number)



Here are some examples.



document.write (Math.round(2.65));// print 3
document.write (Math.round(7.05));// print 7
document.write (Math.round(-2.65));// print -3
document.write (Math.round(-8.15));// print -8
document.write (Math.round(11.65));// print 12


We can format math number by using round function. Here is an example to format upto two decimal places.
var my_val=11.257;
var my_val=11.254;

document.write (Math.round(my_val*100)/100);

Math function in JavaScript

Math function

JavaScript has some good collection of Math functions to handle various requirements. These functions we can inside our script based on the logic required. We can check a variable if it is a number or we can format a number or we can rounded off a number by using these Math function and can do much more than this. Here are some tutorials on handling math function.

Simple addition

We can add to numbers and display the result like this

var x=2+5
document.write(x);

Subtraction

var x =4-2
document.write(x);

Multiplication

var x=4*9
document.write(x);

Division

var x=12/7;
document.write(x);