Beginning Visual Basic 2005 (2006)
.pdf
C
An Introduction to Security
In today’s electronic world, consumers are bombarded with scams via the Internet and e-mail. If you plan to write applications that take advantage of these technologies, you must be aware of fraudulent activity of others. The most rampant activity today is a tactic known as phishing. Here a fraudulent e-mail or pop-up message lures a user to a fake site on the pretext that a breach in bank security or unwanted account activity has made it necessary to “verify” the user’s account information. Tricked users will see a site that looks like their bank’s site but is actually being hosted by criminals in an attempt to bait them into entering their personal and financial information. In these schemes, it is easy for concerned customers to be tricked and enter their card number, social security number, or PIN into the Web forms to avoid their accounts being frozen. Little do they know they are giving away their private information to thieves.
Phishing is not the only scam consumers must deal with; it is one of the most prevalent. As a developer, it is your job to make applications safe. In some cases, features of your application can make it easier for criminals to impersonate your application. Simple things like never asking for personal information that you do not need over e-mail or the Web can make users aware of a scam. For e-mail, you can never assume that e-mail will not be intercepted over the Internet. Make sure you never treat e-mail as a secure means of data transmission.
You must also be aware of security for your Windows applications and assemblies. It seems as though a new hole is found every week in some browser or operating system that allows a hacker to run code on a user’s machine. One way in which this type of attack is commonly accomplished is by a buffer overflow. To give you a simple explanation, hackers discover that a program has memory allocated to store data only up to a certain size. The attacker sends a larger object than the memory allocated. The extra data is not discarded, but rather it gets written to adjacent areas of memory that are intended to store code or the addresses of code. This may corrupt valid allocations of memory, but more important, it installs the attacker’s the malicious code in memory. The victim program runs the attacker’s code as if it were its own, and the damage is done. The root cause of this problem is not one most Visual Basic 2005 developers will encounter, but it should make you aware that people may use your functions in ways you did not intend them to be used.
D
Solutions
Chapter 1 Solution
Exercise 1
To display the text from a text box on a form when the user clicks the button, you add code as highlighted here to the button’s Click event handler:
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click
MessageBox.Show(TextBox1.Text, “Exercise 1”)
End Sub
Chapter 3 Solutions
Exercise 1
The first part of this exercise requires you to declare two Integer variables and set their values and then to perform a math operation on these variables and display the results in a message box. The variables can be declared and set as:
‘Declare variables and set their values Dim intX As Integer = 5
Dim intY As Integer = 10
A math operation can be performed and the results displayed as:
‘Multiply the numbers and display the results MessageBox.Show(“The sum of “ & intX & “ * “ & intY & “ = “ & _
intX * intY, “Exercise 1”)
