SlideShare a Scribd company logo
Hands-On Ethical Hacking and Network Defense Chapter 7 Programming for Security Professionals
Objectives Explain basic programming concepts Write a simple C program Explain how Web pages are created with HTML Describe and create basic Perl programs Explain basic object-oriented programming concepts
Introduction to Computer Programming Computer programmers must understand the rules of programming languages Programmers deal with syntax errors One minor mistake and the program will not run Or worse, it will produce unpredictable results Being a good programmer takes time and patience
Computer Programming Fundamentals Fundamental concepts Branching, Looping, and Testing (BLT) Documentation Function Mini program within a main program that carries out a task
Branching, Looping, and Testing (BLT) Branching Takes you from one area of the program to another area Looping Act of performing a task over and over Testing Verifies some condition and returns true or false
A C Program Filename ends in .c It's hard to read at first A single missing semicolon can ruin a program
Comments Comments make code easier to read
Branching and Testing Diagram of branches See links Ch 7b, 7c main() printf() scanf()
Looping
Branching, Looping, and Testing (BLT) Algorithm Defines steps for performing a task Keep it as simple as possible Bug An error that causes unpredictable results Pseudocode English-like language used to create the structure of a program
Pseudocode For Shopping PurchaseIngredients Function Call GetCar Function Call DriveToStore Function Purchase Bacon, Bread, Tomatoes, Lettuce, and Mayonnaise End PurchaseIngredients Function
Documentation Documenting your work is essential Add comments to your programs Comments should explain what you are doing Many programmers find it time consuming and tedious Helps others understand your work
Bugs Industry standard 20 to 30 bugs for every 1000 lines of code (link Ch 7f) Textbook claims a much smaller number without a source Windows 2000 contains almost 50 million lines And fewer than 60,000 bugs (about 1 per 1000 lines) See link Ch 7e for comments in the leaked Win 2000 source code Linux has 0.17 bugs per 1000 lines of code (Link Ch 7f)
Learning the C Language Developed by Dennis Ritchie at Bell Laboratories in 1972 Powerful and concise language UNIX was first written in assembly language and later rewritten in C C++ is an enhancement of the C language C is powerful but dangerous Bugs can crash computers, and it's easy to leave security holes in the code
Assembly Language The binary language hard-wired into the processor is  machine language Assembly Language uses a combination of hexadecimal numbers and expressions Very powerful but hard to use (Link Ch 7g)
Compiling C in Ubuntu Linux Compiler Converts a text-based program (source code) into executable or binary code To prepare Ubuntu Linux for C programming, use this command: sudo apt-get install build-essential   Then you compile a file named "program.c" with this command: gcc program.c –o program.exe
Anatomy of a C Program The first computer program a C student learns "Hello, World!"
Comments Use /* and */ to comment large portions of text Use // for one-line comments
Include #include statement Loads libraries that hold the commands and functions used in your program
Functions A Function Name is always followed by parentheses ( ) Curly Braces { } shows where a function begins and ends main() function Every C program requires a main() function main() is where processing starts
Functions Functions can call other functions Parameters or arguments are optional \n represents a line feed
Declaring Variables A variable represents a numeric or string value You must declare a variable before using it
Variable Types in C
Mathematical Operators The i++ in the example below adds one to the variable i
Mathematical Operators
Logical Operators The i<11 in the example below compares the variable i to 11
Logical Operators
Demonstration: Buffer Overflow
Understanding HTML Basics HTML is a language used to create Web pages HTML files are text files Security professionals often need to examine Web pages Be able to recognize when something looks suspicious
Creating a Web Page Using HTML Create HTML Web page in Notepad View HTML Web page in a Web browser HTML does not use branching, looping, or testing HTML is a static formatting language Rather than a programming language < and > symbols denote HTML tags Each tag has a matching closing tag <HTML> and </HTML>
 
 
 
Understanding Practical Extraction and Report Language (Perl) PERL  Powerful scripting language Used to write scripts and programs for security professionals
Background on Perl Developed by Larry Wall in 1987 Can run on almost any platform *NIX-base OSs already have Perl installed Perl syntax is similar to C Hackers use Perl to write malware Security professionals use Perl to perform repetitive tasks and conduct security monitoring
 
Understanding the Basics of Perl perl –h command  Gives you a list of parameters used with perl
 
Understanding the BLT of Perl Some syntax rules Keyword “sub” is used in front of function names Variables begin with the $ character Comment lines begin with the # character The & character is used when calling a function
Branching in Perl &speak; Calls the subroutine sub speak Defines the subroutine
For Loop in Perl For loop
Testing Conditions in Perl
Understanding Object-Oriented Programming Concepts New programming paradigm There are several languages that support object-oriented programming C++ C# Java Perl 6.0 Object Cobol
Components of Object-Oriented Programming Classes Structures that hold pieces of data and functions The :: symbol Used to separate the name of a class from a member function Example: Employee::GetEmp()
Example of a Class in C++ class Employee { public: char firstname[25]; char lastname[25]; char PlaceOfBirth[30]; [code continues] }; void GetEmp() { // Perform tasks to get employee info [program code goes here] }
Error in textbook C example on page 138 should be this instead

More Related Content

PPTX
Introduction to C Language (By: Shujaat Abbas)
PPSX
Introduction of c language
PPT
Introduction to c_language
PDF
Algorithm pseudocode flowchart program notes
PPTX
introduction to c language
PDF
Computer programming all chapters
PPTX
PPTX
Std 10 computer chapter 10 introduction to c language (part1)
Introduction to C Language (By: Shujaat Abbas)
Introduction of c language
Introduction to c_language
Algorithm pseudocode flowchart program notes
introduction to c language
Computer programming all chapters
Std 10 computer chapter 10 introduction to c language (part1)

What's hot (20)

PPTX
COM1407: Introduction to C Programming
PPTX
Introduction to c programming
PPSX
C programming basics
PPTX
PPT
Brief introduction to the c programming language
PPT
Programming in c
PPTX
Introduction to c language
PPTX
Introduction to C Language
PPT
Introduction to C Programming
PPTX
introduction to c programming language
PDF
C programming
PPTX
INTRODUCTION TO C PROGRAMMING
PPT
Programming Methodology
PPT
C Language
PPTX
C programming
PPT
Programming assignment help
PDF
notes on Programming fundamentals
PPTX
Introduction to C Language
PDF
Cd lab manual
COM1407: Introduction to C Programming
Introduction to c programming
C programming basics
Brief introduction to the c programming language
Programming in c
Introduction to c language
Introduction to C Language
Introduction to C Programming
introduction to c programming language
C programming
INTRODUCTION TO C PROGRAMMING
Programming Methodology
C Language
C programming
Programming assignment help
notes on Programming fundamentals
Introduction to C Language
Cd lab manual
Ad

Viewers also liked (13)

PPTX
Branching in TFS 2010 Part III (End-User Pattern)
PPTX
Branching in TFS 2010 Part V (Sharing Code)
PPT
Ch13 Protecting Networks with Security Devices
PPS
My School In Czernowitz
PPS
Pan American
PPS
Bucovina
PPTX
Branching in TFS 2010 Part II (Third Party Pattern)
PPS
St Petersburg
PPS
Afghanistan
PPT
Ch02 TCP/IP Concepts Review
PPTX
Branching in TFS 2010 Part I (Branching Theory)
PPT
Smooth endoplasmic reticulum
PPT
Assembly Language Programming Of 8085
Branching in TFS 2010 Part III (End-User Pattern)
Branching in TFS 2010 Part V (Sharing Code)
Ch13 Protecting Networks with Security Devices
My School In Czernowitz
Pan American
Bucovina
Branching in TFS 2010 Part II (Third Party Pattern)
St Petersburg
Afghanistan
Ch02 TCP/IP Concepts Review
Branching in TFS 2010 Part I (Branching Theory)
Smooth endoplasmic reticulum
Assembly Language Programming Of 8085
Ad

Similar to Ch07 Programming for Security Professionals (20)

PPTX
C Programming UNIT 1.pptx
DOCX
Srgoc dotnet_new
PPTX
Chap 2 structure of c programming dti2143
PDF
CS8251_QB_answers.pdf
PPTX
A Crash Course in C Part-1
PDF
Introduction of c language
PDF
Chapter 1 - Basic concepts of programming.pdf
PDF
Ch 7: Programming for Security Professionals
PDF
CNIT 123: Ch 7: Programming for Security Professionals
PDF
C class basic programming 1 PPT mayanka (1).pdf
PPTX
Computer Hardware Technology PowerPoint Templates (1).pptx
PDF
Lecture-1&2.pdf Visual Programming C# .net framework
PPT
Unit 2 ppt
DOCX
C programming languag for cse students
PPT
Introduction
PPTX
Unit-2.pptx
PDF
First session quiz
PDF
First session quiz
PDF
Cp week _2.
PPTX
Unit 2 l1
C Programming UNIT 1.pptx
Srgoc dotnet_new
Chap 2 structure of c programming dti2143
CS8251_QB_answers.pdf
A Crash Course in C Part-1
Introduction of c language
Chapter 1 - Basic concepts of programming.pdf
Ch 7: Programming for Security Professionals
CNIT 123: Ch 7: Programming for Security Professionals
C class basic programming 1 PPT mayanka (1).pdf
Computer Hardware Technology PowerPoint Templates (1).pptx
Lecture-1&2.pdf Visual Programming C# .net framework
Unit 2 ppt
C programming languag for cse students
Introduction
Unit-2.pptx
First session quiz
First session quiz
Cp week _2.
Unit 2 l1

More from phanleson (20)

PDF
Learning spark ch01 - Introduction to Data Analysis with Spark
PPT
Firewall - Network Defense in Depth Firewalls
PPT
Mobile Security - Wireless hacking
PPT
Authentication in wireless - Security in Wireless Protocols
PPT
E-Commerce Security - Application attacks - Server Attacks
PPT
Hacking web applications
PPTX
HBase In Action - Chapter 04: HBase table design
PPT
HBase In Action - Chapter 10 - Operations
PPT
Hbase in action - Chapter 09: Deploying HBase
PPTX
Learning spark ch11 - Machine Learning with MLlib
PPTX
Learning spark ch10 - Spark Streaming
PPTX
Learning spark ch09 - Spark SQL
PPT
Learning spark ch07 - Running on a Cluster
PPTX
Learning spark ch06 - Advanced Spark Programming
PPTX
Learning spark ch05 - Loading and Saving Your Data
PPTX
Learning spark ch04 - Working with Key/Value Pairs
PPTX
Learning spark ch01 - Introduction to Data Analysis with Spark
PPT
Hướng Dẫn Đăng Ký LibertaGia - A guide and introduciton about Libertagia
PPT
Lecture 1 - Getting to know XML
PPTX
Lecture 4 - Adding XTHML for the Web
Learning spark ch01 - Introduction to Data Analysis with Spark
Firewall - Network Defense in Depth Firewalls
Mobile Security - Wireless hacking
Authentication in wireless - Security in Wireless Protocols
E-Commerce Security - Application attacks - Server Attacks
Hacking web applications
HBase In Action - Chapter 04: HBase table design
HBase In Action - Chapter 10 - Operations
Hbase in action - Chapter 09: Deploying HBase
Learning spark ch11 - Machine Learning with MLlib
Learning spark ch10 - Spark Streaming
Learning spark ch09 - Spark SQL
Learning spark ch07 - Running on a Cluster
Learning spark ch06 - Advanced Spark Programming
Learning spark ch05 - Loading and Saving Your Data
Learning spark ch04 - Working with Key/Value Pairs
Learning spark ch01 - Introduction to Data Analysis with Spark
Hướng Dẫn Đăng Ký LibertaGia - A guide and introduciton about Libertagia
Lecture 1 - Getting to know XML
Lecture 4 - Adding XTHML for the Web

Recently uploaded (20)

PPTX
Presentation on Janskhiya sthirata kosh.
PDF
Sunset Boulevard Student Revision Booklet
PPTX
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
PDF
LDMMIA Reiki Yoga Workshop 15 MidTerm Review
PPTX
How to Manage Bill Control Policy in Odoo 18
PPTX
Revamp in MTO Odoo 18 Inventory - Odoo Slides
PDF
High Ground Student Revision Booklet Preview
PPTX
UNDER FIVE CLINICS OR WELL BABY CLINICS.pptx
PPTX
Congenital Hypothyroidism pptx
PDF
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
PPTX
Odoo 18 Sales_ Managing Quotation Validity
PDF
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
PDF
What Is Coercive Control? Understanding and Recognizing Hidden Abuse
PPTX
Cardiovascular Pharmacology for pharmacy students.pptx
PPTX
Strengthening open access through collaboration: building connections with OP...
PPTX
How to Manage Loyalty Points in Odoo 18 Sales
PPTX
Skill Development Program For Physiotherapy Students by SRY.pptx
PPTX
Open Quiz Monsoon Mind Game Final Set.pptx
PPTX
vedic maths in python:unleasing ancient wisdom with modern code
PPTX
Introduction and Scope of Bichemistry.pptx
Presentation on Janskhiya sthirata kosh.
Sunset Boulevard Student Revision Booklet
Introduction to Child Health Nursing – Unit I | Child Health Nursing I | B.Sc...
LDMMIA Reiki Yoga Workshop 15 MidTerm Review
How to Manage Bill Control Policy in Odoo 18
Revamp in MTO Odoo 18 Inventory - Odoo Slides
High Ground Student Revision Booklet Preview
UNDER FIVE CLINICS OR WELL BABY CLINICS.pptx
Congenital Hypothyroidism pptx
Origin of periodic table-Mendeleev’s Periodic-Modern Periodic table
Odoo 18 Sales_ Managing Quotation Validity
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
What Is Coercive Control? Understanding and Recognizing Hidden Abuse
Cardiovascular Pharmacology for pharmacy students.pptx
Strengthening open access through collaboration: building connections with OP...
How to Manage Loyalty Points in Odoo 18 Sales
Skill Development Program For Physiotherapy Students by SRY.pptx
Open Quiz Monsoon Mind Game Final Set.pptx
vedic maths in python:unleasing ancient wisdom with modern code
Introduction and Scope of Bichemistry.pptx

Ch07 Programming for Security Professionals

  • 1. Hands-On Ethical Hacking and Network Defense Chapter 7 Programming for Security Professionals
  • 2. Objectives Explain basic programming concepts Write a simple C program Explain how Web pages are created with HTML Describe and create basic Perl programs Explain basic object-oriented programming concepts
  • 3. Introduction to Computer Programming Computer programmers must understand the rules of programming languages Programmers deal with syntax errors One minor mistake and the program will not run Or worse, it will produce unpredictable results Being a good programmer takes time and patience
  • 4. Computer Programming Fundamentals Fundamental concepts Branching, Looping, and Testing (BLT) Documentation Function Mini program within a main program that carries out a task
  • 5. Branching, Looping, and Testing (BLT) Branching Takes you from one area of the program to another area Looping Act of performing a task over and over Testing Verifies some condition and returns true or false
  • 6. A C Program Filename ends in .c It's hard to read at first A single missing semicolon can ruin a program
  • 7. Comments Comments make code easier to read
  • 8. Branching and Testing Diagram of branches See links Ch 7b, 7c main() printf() scanf()
  • 10. Branching, Looping, and Testing (BLT) Algorithm Defines steps for performing a task Keep it as simple as possible Bug An error that causes unpredictable results Pseudocode English-like language used to create the structure of a program
  • 11. Pseudocode For Shopping PurchaseIngredients Function Call GetCar Function Call DriveToStore Function Purchase Bacon, Bread, Tomatoes, Lettuce, and Mayonnaise End PurchaseIngredients Function
  • 12. Documentation Documenting your work is essential Add comments to your programs Comments should explain what you are doing Many programmers find it time consuming and tedious Helps others understand your work
  • 13. Bugs Industry standard 20 to 30 bugs for every 1000 lines of code (link Ch 7f) Textbook claims a much smaller number without a source Windows 2000 contains almost 50 million lines And fewer than 60,000 bugs (about 1 per 1000 lines) See link Ch 7e for comments in the leaked Win 2000 source code Linux has 0.17 bugs per 1000 lines of code (Link Ch 7f)
  • 14. Learning the C Language Developed by Dennis Ritchie at Bell Laboratories in 1972 Powerful and concise language UNIX was first written in assembly language and later rewritten in C C++ is an enhancement of the C language C is powerful but dangerous Bugs can crash computers, and it's easy to leave security holes in the code
  • 15. Assembly Language The binary language hard-wired into the processor is machine language Assembly Language uses a combination of hexadecimal numbers and expressions Very powerful but hard to use (Link Ch 7g)
  • 16. Compiling C in Ubuntu Linux Compiler Converts a text-based program (source code) into executable or binary code To prepare Ubuntu Linux for C programming, use this command: sudo apt-get install build-essential Then you compile a file named &quot;program.c&quot; with this command: gcc program.c –o program.exe
  • 17. Anatomy of a C Program The first computer program a C student learns &quot;Hello, World!&quot;
  • 18. Comments Use /* and */ to comment large portions of text Use // for one-line comments
  • 19. Include #include statement Loads libraries that hold the commands and functions used in your program
  • 20. Functions A Function Name is always followed by parentheses ( ) Curly Braces { } shows where a function begins and ends main() function Every C program requires a main() function main() is where processing starts
  • 21. Functions Functions can call other functions Parameters or arguments are optional \n represents a line feed
  • 22. Declaring Variables A variable represents a numeric or string value You must declare a variable before using it
  • 24. Mathematical Operators The i++ in the example below adds one to the variable i
  • 26. Logical Operators The i<11 in the example below compares the variable i to 11
  • 29. Understanding HTML Basics HTML is a language used to create Web pages HTML files are text files Security professionals often need to examine Web pages Be able to recognize when something looks suspicious
  • 30. Creating a Web Page Using HTML Create HTML Web page in Notepad View HTML Web page in a Web browser HTML does not use branching, looping, or testing HTML is a static formatting language Rather than a programming language < and > symbols denote HTML tags Each tag has a matching closing tag <HTML> and </HTML>
  • 31.  
  • 32.  
  • 33.  
  • 34. Understanding Practical Extraction and Report Language (Perl) PERL Powerful scripting language Used to write scripts and programs for security professionals
  • 35. Background on Perl Developed by Larry Wall in 1987 Can run on almost any platform *NIX-base OSs already have Perl installed Perl syntax is similar to C Hackers use Perl to write malware Security professionals use Perl to perform repetitive tasks and conduct security monitoring
  • 36.  
  • 37. Understanding the Basics of Perl perl –h command Gives you a list of parameters used with perl
  • 38.  
  • 39. Understanding the BLT of Perl Some syntax rules Keyword “sub” is used in front of function names Variables begin with the $ character Comment lines begin with the # character The & character is used when calling a function
  • 40. Branching in Perl &speak; Calls the subroutine sub speak Defines the subroutine
  • 41. For Loop in Perl For loop
  • 43. Understanding Object-Oriented Programming Concepts New programming paradigm There are several languages that support object-oriented programming C++ C# Java Perl 6.0 Object Cobol
  • 44. Components of Object-Oriented Programming Classes Structures that hold pieces of data and functions The :: symbol Used to separate the name of a class from a member function Example: Employee::GetEmp()
  • 45. Example of a Class in C++ class Employee { public: char firstname[25]; char lastname[25]; char PlaceOfBirth[30]; [code continues] }; void GetEmp() { // Perform tasks to get employee info [program code goes here] }
  • 46. Error in textbook C example on page 138 should be this instead