ComputerSecurityStudent (CSS) [Login] [Join Now]




|UNIX >> Perl Lessons >> Current Page |Views: 5222

(Perl: Lesson 4)

{ Using IF/ELSE Statements To Examine Strings }


Section 0. Background Information
  1. What is Perl
    • Perl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier.  Since then, it has undergone many changes and revisions and become widely popular amongst programmers. Larry Wall continues to oversee development of the core language, and its upcoming version, Perl 6. Perl borrows features from other programming languages including C, shell scripting (sh), AWK, and sed.  The language provides powerful text processing facilities without the arbitrary data length limits of many contemporary Unix tools, facilitating easy manipulation of text files. Perl gained widespread popularity in the late 1990s as a CGI scripting language, in part due to its parsing abilities.

  2. Getting Perl
    • For the purposes of these perl lesson, I will be using a perl package that comes standard on Backtrack, Ubuntu and most flavors of Linux and Unix.
    • However, if you are using Windows, instead of a Linux, Unix or MAC operating system, you still have options.
  3. Pre-Requisite
  4. Lab Notes
    • In this lab we will do the following:
      1. We will download an IF/ELSE program.
      2. We will create a program that takes in standard input and analyzes it with IF/ELSE statements.

  5. Legal Disclaimer
    • As a condition of your use of this Web site, you warrant to computersecuritystudent.com that you will not use this Web site for any purpose that is unlawful or that is prohibited by these terms, conditions, and notices.
    • In accordance with UCC § 2-316, this product is provided with "no warranties, either express or implied." The information contained is provided "as-is", with "no guarantee of merchantability."
    • In addition, this is a teaching website that does not condone malicious behavior of any kind.
    • Your are on notice, that continuing and/or using this lab outside your "own" test environment is considered malicious and is against the law.
    • © 2013 No content replication of any kind is allowed without express written permission.

Section 1. Login to BackTrack
  1. Start Up VMWare Player
    • Instructions:
      1. Click the Start Button
      2. Type Vmplayer in the search box
      3. Click on Vmplayer

     

  2. Open a Virtual Machine
    • Instructions:
      1. Click on Open a Virtual Machine

     

  3. Open the BackTrack5R1 VM
    • Instructions:
      1. Navigate to where the BackTrack5R1 VM is located
      2. Click on on the BackTrack5R1 VM
      3. Click on the Open Button

     

  4. Edit the BackTrack5R1 VM
    • Instructions:
      1. Select BackTrack5R1 VM
      2. Click Edit virtual machine settings

     

  5. Edit Virtual Machine Settings
    • Instructions:
      1. Click on Network Adapter
      2. Click on the Bridged Radio button
      3. Click on the OK Button

     

  6. Play the BackTrack5R1 VM
    • Instructions:
      1. Click on the BackTrack5R1 VM
      2. Click on Play virtual machine

     

  7. Login to BackTrack
    • Instructions:
      1. Login: root
      2. Password: toor or <whatever you changed it to>.

     

  8. Bring up the GNOME
    • Instructions:
      1. Type startx

 

Section 2. Bring up a console terminal
  1. Start up a terminal window
    • Instructions:
      1. Click on the Terminal Window

     

  2. Obtain the IP Address
    • Instructions:
      1. ifconfig -a
    • Note(FYI):
      • My IP address 192.168.1.111.
      • In your case, it will probably be different.

 

Section 3. Download lesson4a.pl
  1. Become the student user and make a directory
    • Instructions:
      1. su - student
      2. mkdir -p perl_lessons
      3. cd perl_lessons

     

  2. Download lesson4a.pl
    • Instructions:
      1. wget http://www.computersecuritystudent.com/UNIX/PERL/lesson4/lesson4a.pl
      2. chmod 700 lesson4a.pl
      3. perl -c lesson4a.pl

     

  3. Run lesson4a.pl
    • Instructions:
      1. ./lesson4a.pl
    • Note(FYI):
      • Before continuing to the proof of lab section.
      • Read each line of the code and examine why each IF/ELSE statement executes the way it does.

     

Section 5. Proof of Lab
  1. Project
    • Instructions:
      1. Write a program called lesson4b.pl
      2. The program should ask you to enter your first name.
        • e.g., print "Enter Your First Name: ";
      3. The program should assign variable $first to standard input
        • e.g., chomp(my $first = <stdin>);
      4. The program should ask you to enter your last name.
        • e.g., print "Enter Your Last Name: ";
      5. The program should assign variable $last to standard input
        • e.g., chomp(my $last = <stdin>);
      6. The program should contain a IF/ELSE statement that performs the following test
        1. If both $first is equal to "John" and $last is equal to "Gray"
        2. e.g., if(($first eq "John")&&($last eq "Gray"))

         

  2. Proof of Lab
    • Instructions
      1. chmod 700 lesson4b.pl
      2. perl -c lesson4b.pl
      3. ./lesson4b.pl
        • Enter Your First Name: John
        • Enter Your Last Name: Smith
      4. ./lesson4b.pl
        • Enter Your First Name: John
        • Enter Your Last Name: Gray
      5. date
      6. echo "Your Name"
        • Put in your actual name in place of "Your Name"
        • e.g., echo "John Gray"
      7. Do a PrtScn, Paste into a word document, and upload to Moodle.
    • Proof Of Lab Instructions:
      1. Press the PrtScn key
      2. Paste into a word document
      3. Upload to Moodle
     


Help ComputerSecurityStudent
pay for continued research,
resources & bandwidth