Hands-On Ethical Hacking and Network Defense, Third Edition 7-1
Chapter 07
Programming for Security Professionals
At a Glance
Instructor’s Manual Table of Contents
Overview
Objectives
Teaching Tips
Quick Quizzes
Hands-On Ethical Hacking and Network Defense, Third Edition 7-2
Lecture Notes
Overview
This chapter introduces basic programming concepts. It starts by explaining the C
programming language syntax and its basic functions. Then, students will learn to create Web
Chapter Objectives
After reading this chapter and completing the exercises, the student will be able to:
Explain basic programming concepts
Write a simple C program
Teaching Tips
Introduction to Computer Programming
1. Explain to students that just as book editors must understand the rules and syntax of the
2. Point out that most colleges don’t teach programming with security in mind. Because of
Programming Fundamentals
1. Review the fundamental concepts of programming: branching, looping, and testing.
Hands-On Ethical Hacking and Network Defense, Third Edition 7-3
Branching, Looping, and Testing (BLT)
1. Explain the following concepts:
a. Function
2. The concepts above are the most basic concepts that your students need to know to
write or understand computer programs.
Teaching
Tip
Find more information about writing pseudocode at:
http://www.csc.calpoly.edu/~jdalbey/SWE/pdl_std.html
Documentation
1. Explain the importance of documenting your programs. Without proper documentation,
it is difficult for programmers to understand their own work, even if it was only written
2. Mention that good documentation helps programmers find bugs in their code.
Teaching
Tip
Java has a standard for documenting Java code called Javadoc. Read
http://www.oracle.com/technetwork/java/javase/documentation/index-jsp-
135444.html for an overview of Javadoc.
Learning the C Language
1. Introduce the C programming language. C was developed by Dennis Ritchie at Bell
2. Explain the role of a compiler when developing applications.
Hands-On Ethical Hacking and Network Defense, Third Edition 7-4
Anatomy of a C Program
1. Using the “Hello, world!” sample program, explain the main components of a C
2. Use Table 7-2 to explain some special characters that can be used when calling the
Declaring Variables
1. Explain the use of variables in your programs to represent numeric or string values.
3. Use Table 7-4 to show some of the conversion specifiers that can be used in C.
Conversion specifiers tells the compiler how to convert the values in a function.
4. Using Table 7-5 and Table 7-6, introduce the mathematical and logical operators
Branching, Looping, and Testing in C
1. Using examples explain how to branch, loop, and test in C. Branching in C is as simple
2. While loops test the condition first and repeat some actions if the condition is true. Do
3. Using the examples of code listed in the text, discuss the construction of each of the
Understanding HTML Basics
1. This section presents some HTML basics. HTML is still the foundation language for
Web development. As a security professional your students need to know how to read
HTML files and recognize when something looks suspicious.
Teaching
Tip
You can visit http://www.w3schools.com/html/ for a complete HTML tutorial.
Hands-On Ethical Hacking and Network Defense, Third Edition 7-5
Creating a Web Page with HTML
1. Explain the anatomy of a HTML Web page. A Web page consists of several HTML
3. Use Figure 7-4 to show a sample of HTML source code. Remember that you can write
Quick Quiz 1
1. Instead of grammatical errors, programmers must deal with what type of errors?
2. A mini program within a main program that carries out a task is known as which of the
following?
A. algorithm
B. bug
C. compiler
D. function
3. True or False: Branching takes you from one area of a program (a function) to another
area.
4. What programming term is used to describe the act of performing a task over and over?
A. branching
B. looping
C. testing
D. documentation
5. An English-like language you can use to help create the structure of your program is
known as which of the following?
A. pseudocode
B. assembly language
C. syntax
D. machine code
Hands-On Ethical Hacking and Network Defense, Third Edition 7-6
Understanding Perl
1. Introduce Practical Extraction and Report Language (Perl) as a powerful scripting
Background on Perl
1. Using Table 7-8, explain the evolution of Perl. Perl was originally developed by Larry
Wall in 1987 and it is supported by almost any platform.
Understanding the Basics of Perl
1. Explain how to display and use the help documentation Perl command (perl -h).
2. Describe the use of the perldoc command. This command displays detailed
Understanding the BLT of Perl
1. Every programming language must have a way to branch, loop, and test. Perl is no
exception. Use Perl code examples to show how Perl handles these BLT functions.
3. Looping in Perl can be accomplished using one of two mechanisms: the for loop or
the while loop.
4. Use Table 7-10 to explain Perl operators. Discuss the example of combining operators
Understanding Object-Oriented Programming
1. This section covers the fundamental concepts of object-oriented programming.
Hands-On Ethical Hacking and Network Defense, Third Edition 7-7
Components of Object-Oriented Programming
1. Using sample code, explain the basic anatomy of an object-oriented program. Classes
are the main structures that hold pieces of data and functions. When writing an object-
oriented program, you create classes to represent the type and behavior of an object.
Objects are instances of classes. Note that you must use the object’s name to invoke any
of its member functions.
Teaching
Tip
Check out http://gd.tuwien.ac.at/languages/c/c++oop-pmueller/ for an
introduction to object-oriented programming using C++.
An Overview of Ruby
2. Using Figure 7-16, demonstrate how to modify exploit shell code in Ruby.
Quick Quiz 2
1. True or False: Perl is the next language of choice after C, for both hackers and security
professionals.
2. Which Perl command gives you a list of parameters used with the perl command?
A. perl p
B. perl ?
C. perl P
D. perl -h
3. In object-oriented programming, what are the structures that hold pieces of data and
functions called?
A. domains
B. components
C. classes
D. shells
4. Which Win API function returns the NetBIOS computer name?
A. NodeName ( )
B. GetOSName ( )
C. DomainName ( )
D. LoginName ( )
5. Which Perl operator is used to perform the exponent function?
A. %
B. !
C. **
D.
Class Discussion Topics
1. Why do you think it is important to program with security in mind? Mention two or
2. What are the advantages and disadvantages of working with APIs when developing
applications?
Additional Projects
1. Ask your students to write a C program that reads a text file and displays its content on
2. Searching a string is very convenient using regular expressions. Perl is one of the few
programming languages that support working with regular expressions. Ask your
Additional Resources
2. Programming with security in mind:
3. Java SE security:
4. Application Programming Interface (API):
5. Perl Debugging Tutorial:
Key Terms
See Glossary for definitions of Key Terms.
algorithm
assembly language
branching
bug
class
compiler
Technical Notes for Activities
Activity 7-1: This activity requires paper and pencil.
Hands-On Ethical Hacking and Network Defense, Third Edition 7-10
Activity 7-2: This activity requires a computer and a classroom Linux CD.
Activity 7-3: This activity requires a computer running Windows.