SlideShare ist ein Scribd-Unternehmen logo
1 von 23
Downloaden Sie, um offline zu lesen
Perl Programming
                 Course
            System Programming
             and Administration



Krassimir Berov

I-can.eu
Contents
1. Recommended Modules
2. Running perl
3. Command-line switches
4. Filesystem analysis
5. Mail processing
6. Security notes
Recommended Modules
• In no particular order
  • Archive::Extract - A generic archive extracting
    mechanism
  • Carp - warn of errors (from perspective of caller)
  • Config - access Perl configuration information
  • Config::Extensions - hash lookup of which core
    extensions were built.
  • CPAN - query, download and build perl modules from
    CPAN sites
  • Cwd - get pathname of current working directory
  • Data::Dumper - stringified perl data structures,
    suitable for both printing and eval
Recommended Modules
• In no particular order
  •   Dumpvalue - provides screen dump of Perl data.
  •   Encode - character encodings
  •   ExtUtils::Install - install files from here to there
  •   ExtUtils::Installed - Inventory management of
      installed modules
  •   ExtUtils::Liblist - determine libraries to use and how
      to use them
  •   ExtUtils::MakeMaker - Create a module Makefile
  •   File::Basename - Parse file paths into directory,
      filename and suffix.
  •   File::Compare - Compare files or filehandles
Recommended Modules
• In no particular order
  • File::Copy - Copy files or filehandles
  • File::Find - Traverse a directory tree.
  • File::Path - create or remove directory trees
  • File::Spec - portably perform operations on file
    names
  • File::stat - by-name interface to Perl's built-in stat()
    functions
  • File::Temp - return name and handle of a temporary
    file safely
  • FindBin - Locate directory of original perl script
Recommended Modules
• In no particular order
  • Getopt::Long - Extended processing of command
    line options
  • Getopt::Std - Process single-character switches with
    switch clustering
  • Hash::Util - A selection of general-utility hash
    subroutines
  • IO::* - supply object methods for * handles
  • IPC::* - processes...
  • List::Util - A selection of general-utility list
    subroutines
  • Locale::* - ISO codes, localization etc.
  • MIME::Base64 - Encoding and decoding of base64
    strings
Recommended Modules
• In no particular order
  • Net::* - network programming
  • POSIX - Perl interface to IEEE Std 1003.1
  • Scalar::Util - A selection of general-utility scalar
    subroutines
  • Storable - persistence for Perl data structures
  • Test::More - yet another framework for writing test
    scripts
  • ...
Running perl
• Run a perl program by
  • making it directly executable
  • passing the name of the source file as an argument
    on the command line
• Upon startup, Perl looks for your program in one of
  the following places:
  • Specified line by line via -e or -E switches on the
    command line.
  • Contained in the file specified by the first filename on
    the command line.
  • Passed in implicitly via standard input.
Running perl
• Run a perl program by
  • making it directly executable
  • passing the name of the source file as an argument
    on the command line
• Upon startup, Perl looks for your program in one of
  the following places:
  • Specified line by line via -e or -E switches on the
    command line.
  • Contained in the file specified by the first filename on
    the command line.
  • Passed in implicitly via standard input.
Command-line switches
• execute switch (-e)



 >perl   -e   'print "Hello Worldn" '
 >perl   -e   "print qq{Hello Worldn}" # Windows
 >perl   -e   'for(1..20){print qq|hin|;}'
Command-line switches
• Running code snippets
  • This will tell you of syntax errors immediately,
    but script execution will not start until you send
    Perl an end-of-file character,
  • On Unix systems - CTRL-D at the start of a line
  • under Windows -CTRL-Z at the start of a line.

 >perl
 for(1..20){
 print 'hi'.$/
 }
Command-line switches
• Printing switch (-p)
  • tells Perl to act as a stream editor
  • will read input from STDIN, or from files
    mentioned on the command line, and place each
    line of input into $_.
  • your program is executed, and the contents of $_
    are printed.
  • most commonly used with s///,

 >perl -pe 's/perl/Python/gi' filesed.txt >filesed1.txt
Command-line switches
• Module switch (-M)
  • use modules in the one-liner




 > perl -MData::Dumper -e 'print Dumper(%ENV)'
Command-line switches
• In-place switch (-i)
  • allows you to edit the file in place, overwriting
    the original version
  • a bug in your program can result in data-loss
  • provide an argument to the switch: -i.old to
    create a backup copy of the original file file.old
    and then overwrite the original

 > perl -i.old -pe 's/perl/python/gi' original.txt
Command-line switches
• Check switch (-c)
  • check the program for syntactic errors and to
    exit without executing the file
 > perl -c script.pl


• Warnings switch (-w)
  • runs your program with warnings turned on
• Include switch (-I)
  • additional directories to be searched for
    modules
  • modifies Perl’s special @INC variable.
Filesystem analysis
• Directory separators
  • use File::Spec to perform really OS
    independent operations on directories
  • use IO::Dir for directories manipulation
  • use Cwd to get the current working dir.
 use File::Spec::Functions qw(rel2abs);
 #or
 use File::Spec
 #later...
 $tmpdir = File::Spec->tmpdir();
 $is_case_tolerant = File::Spec->case_tolerant();
Filesystem analysis
• Working with files
  • use File::Copy to copy and move files
  • use unlink() to delete files
  •  use File::Temp to safely create temporary
    files
  • use file-test operators to find information
    about files
  • see: perldoc -f -x
 use File::Copy;
 copy("file1","file2") or die "Copy failed: $!";
 copy("Copy.pm",*STDOUT);
 move("/dev1/fileA","/dev2/fileB");
Filesystem analysis
• Working with files
  • use chmod() to change file permissions
  • use umask() to change default file
    permissions
  • use chown() to change file ownership
  • use File::Find to traverse directory trees
    and recursively manipulate files in them
 use Fcntl;
 umask 0022;
 sysopen(FILE, "runme", O_WRONLY|O_CREAT|O_EXCL, 0777);
 #creates file with permissions 0755
Mail processing
• use Net::SMTP to send simple mail
• use MIME::Lite to send mail with attachments
• use Net::POP3 to retrieve mail
• use Mail::Audit to filter your messages
  use Net::POP3;
  # Constructors
  $pop = Net::POP3->new('pop3host', Timeout => 60);
  if ($pop->login($username, $password) > 0) {
      my $msgnums = $pop->list;
      # hashref of msgnum => size
        foreach my $msgnum (keys %$msgnums) {
            #do something
        }
      }
  $pop->quit;
Security notes
• Taint checking
  • rule: You may not use data derived from
    outside your program to affect something
    else outside your program at least, not by
    accident.
  • all data that comes from external sources
    is tainted


 #!/usr/bin/perl -wT # Taint mode is enabled
Security notes
• Tainted data will be considered
  unsuitable for certain operations:
  • Executing system commands
  • Modifying files
  • Modifying directories
  • Modifying processes
  • Invoking any shell
  • Performing a match in a regular expression
    using the (?{ ... }) construct
  • Executing code using string eval
 #!/usr/bin/perl -wT # Taint mode is enabled
System Programming and
             Administration
• Ressources
  • perldoc perlrun
  • perldoc perlsec
  • http://perltraining.com.au/notes/sysadmin.pdf
  • http://perltraining.com.au/notes/perlsec.pdf
  • etc...
System Programming and
Administration




Questions?

Weitere ähnliche Inhalte

Was ist angesagt?

Course 102: Lecture 12: Basic Text Handling
Course 102: Lecture 12: Basic Text Handling Course 102: Lecture 12: Basic Text Handling
Course 102: Lecture 12: Basic Text Handling Ahmed El-Arabawy
 
Streams, sockets and filters oh my!
Streams, sockets and filters oh my!Streams, sockets and filters oh my!
Streams, sockets and filters oh my!Elizabeth Smith
 
Programming in Computational Biology
Programming in Computational BiologyProgramming in Computational Biology
Programming in Computational BiologyAtreyiB
 
Go for SysAdmins - LISA 2015
Go for SysAdmins - LISA 2015Go for SysAdmins - LISA 2015
Go for SysAdmins - LISA 2015Chris McEniry
 
On the Edge Systems Administration with Golang
On the Edge Systems Administration with GolangOn the Edge Systems Administration with Golang
On the Edge Systems Administration with GolangChris McEniry
 
OSCON2014 : Quick Introduction to System Tools Programming with Go
OSCON2014 : Quick Introduction to System Tools Programming with GoOSCON2014 : Quick Introduction to System Tools Programming with Go
OSCON2014 : Quick Introduction to System Tools Programming with GoChris McEniry
 
PHP from soup to nuts Course Deck
PHP from soup to nuts Course DeckPHP from soup to nuts Course Deck
PHP from soup to nuts Course DeckrICh morrow
 
Writing and using php streams and sockets tek11
Writing and using php streams and sockets   tek11Writing and using php streams and sockets   tek11
Writing and using php streams and sockets tek11Elizabeth Smith
 
PECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life betterPECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life betterZendCon
 
嵌入式Linux課程-GNU Toolchain
嵌入式Linux課程-GNU Toolchain嵌入式Linux課程-GNU Toolchain
嵌入式Linux課程-GNU Toolchain艾鍗科技
 
#Pharo Days 2016 Data Formats and Protocols
#Pharo Days 2016 Data Formats and Protocols#Pharo Days 2016 Data Formats and Protocols
#Pharo Days 2016 Data Formats and ProtocolsPhilippe Back
 
Professional Help for PowerShell Modules
Professional Help for PowerShell ModulesProfessional Help for PowerShell Modules
Professional Help for PowerShell ModulesJune Blender
 

Was ist angesagt? (20)

x86
x86x86
x86
 
Python build your security tools.pdf
Python build your security tools.pdfPython build your security tools.pdf
Python build your security tools.pdf
 
Course 102: Lecture 12: Basic Text Handling
Course 102: Lecture 12: Basic Text Handling Course 102: Lecture 12: Basic Text Handling
Course 102: Lecture 12: Basic Text Handling
 
Cross platform php
Cross platform phpCross platform php
Cross platform php
 
Streams, sockets and filters oh my!
Streams, sockets and filters oh my!Streams, sockets and filters oh my!
Streams, sockets and filters oh my!
 
Python for Penetration testers
Python for Penetration testersPython for Penetration testers
Python for Penetration testers
 
Programming in Computational Biology
Programming in Computational BiologyProgramming in Computational Biology
Programming in Computational Biology
 
Biopython
BiopythonBiopython
Biopython
 
Go for SysAdmins - LISA 2015
Go for SysAdmins - LISA 2015Go for SysAdmins - LISA 2015
Go for SysAdmins - LISA 2015
 
On the Edge Systems Administration with Golang
On the Edge Systems Administration with GolangOn the Edge Systems Administration with Golang
On the Edge Systems Administration with Golang
 
Spl in the wild
Spl in the wildSpl in the wild
Spl in the wild
 
OSCON2014 : Quick Introduction to System Tools Programming with Go
OSCON2014 : Quick Introduction to System Tools Programming with GoOSCON2014 : Quick Introduction to System Tools Programming with Go
OSCON2014 : Quick Introduction to System Tools Programming with Go
 
PHP from soup to nuts Course Deck
PHP from soup to nuts Course DeckPHP from soup to nuts Course Deck
PHP from soup to nuts Course Deck
 
Writing and using php streams and sockets tek11
Writing and using php streams and sockets   tek11Writing and using php streams and sockets   tek11
Writing and using php streams and sockets tek11
 
PECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life betterPECL Picks - Extensions to make your life better
PECL Picks - Extensions to make your life better
 
嵌入式Linux課程-GNU Toolchain
嵌入式Linux課程-GNU Toolchain嵌入式Linux課程-GNU Toolchain
嵌入式Linux課程-GNU Toolchain
 
Pycon Sec
Pycon SecPycon Sec
Pycon Sec
 
#Pharo Days 2016 Data Formats and Protocols
#Pharo Days 2016 Data Formats and Protocols#Pharo Days 2016 Data Formats and Protocols
#Pharo Days 2016 Data Formats and Protocols
 
Linux networking
Linux networkingLinux networking
Linux networking
 
Professional Help for PowerShell Modules
Professional Help for PowerShell ModulesProfessional Help for PowerShell Modules
Professional Help for PowerShell Modules
 

Ähnlich wie Perl Programming Course: System Programming and Administration

Ähnlich wie Perl Programming Course: System Programming and Administration (20)

2. UNIX OS System Architecture easy.pptx
2. UNIX OS System Architecture easy.pptx2. UNIX OS System Architecture easy.pptx
2. UNIX OS System Architecture easy.pptx
 
Linux operating system by Quontra Solutions
Linux operating system by Quontra SolutionsLinux operating system by Quontra Solutions
Linux operating system by Quontra Solutions
 
Linux
LinuxLinux
Linux
 
Linux CLI
Linux CLILinux CLI
Linux CLI
 
Ericas-Linux-Plus-Study-Guide
Ericas-Linux-Plus-Study-GuideEricas-Linux-Plus-Study-Guide
Ericas-Linux-Plus-Study-Guide
 
Bioinformatics p1-perl-introduction v2013
Bioinformatics p1-perl-introduction v2013Bioinformatics p1-perl-introduction v2013
Bioinformatics p1-perl-introduction v2013
 
LinuxCommands (1).pdf
LinuxCommands (1).pdfLinuxCommands (1).pdf
LinuxCommands (1).pdf
 
linux cmds.pptx
linux cmds.pptxlinux cmds.pptx
linux cmds.pptx
 
Linux Fundamentals
Linux FundamentalsLinux Fundamentals
Linux Fundamentals
 
Tanel Poder - Scripts and Tools short
Tanel Poder - Scripts and Tools shortTanel Poder - Scripts and Tools short
Tanel Poder - Scripts and Tools short
 
Lec 10-linux-review
Lec 10-linux-reviewLec 10-linux-review
Lec 10-linux-review
 
Systemcall1
Systemcall1Systemcall1
Systemcall1
 
Linux week 2
Linux week 2Linux week 2
Linux week 2
 
Advanced windows debugging
Advanced windows debuggingAdvanced windows debugging
Advanced windows debugging
 
Linux: Everyting-as-a-service
Linux: Everyting-as-a-serviceLinux: Everyting-as-a-service
Linux: Everyting-as-a-service
 
Operating system enhancements to prevent misuse of systems
Operating system enhancements to prevent misuse of systemsOperating system enhancements to prevent misuse of systems
Operating system enhancements to prevent misuse of systems
 
Unix cmc
Unix cmcUnix cmc
Unix cmc
 
redhat_by_Cbitss.ppt
redhat_by_Cbitss.pptredhat_by_Cbitss.ppt
redhat_by_Cbitss.ppt
 
Unix Shell Script - 2 Days Session.pptx
Unix Shell Script - 2 Days Session.pptxUnix Shell Script - 2 Days Session.pptx
Unix Shell Script - 2 Days Session.pptx
 
Unix
UnixUnix
Unix
 

Mehr von Krasimir Berov (Красимир Беров) (12)

Хешове
ХешовеХешове
Хешове
 
Списъци и масиви
Списъци и масивиСписъци и масиви
Списъци и масиви
 
Скаларни типове данни
Скаларни типове данниСкаларни типове данни
Скаларни типове данни
 
Въведение в Perl
Въведение в PerlВъведение в Perl
Въведение в Perl
 
Processes and threads
Processes and threadsProcesses and threads
Processes and threads
 
Working with databases
Working with databasesWorking with databases
Working with databases
 
Working with text, Regular expressions
Working with text, Regular expressionsWorking with text, Regular expressions
Working with text, Regular expressions
 
Subroutines
SubroutinesSubroutines
Subroutines
 
Syntax
SyntaxSyntax
Syntax
 
Hashes
HashesHashes
Hashes
 
Lists and arrays
Lists and arraysLists and arrays
Lists and arrays
 
Scalar data types
Scalar data typesScalar data types
Scalar data types
 

Kürzlich hochgeladen

Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 

Kürzlich hochgeladen (20)

Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 

Perl Programming Course: System Programming and Administration

  • 1. Perl Programming Course System Programming and Administration Krassimir Berov I-can.eu
  • 2. Contents 1. Recommended Modules 2. Running perl 3. Command-line switches 4. Filesystem analysis 5. Mail processing 6. Security notes
  • 3. Recommended Modules • In no particular order • Archive::Extract - A generic archive extracting mechanism • Carp - warn of errors (from perspective of caller) • Config - access Perl configuration information • Config::Extensions - hash lookup of which core extensions were built. • CPAN - query, download and build perl modules from CPAN sites • Cwd - get pathname of current working directory • Data::Dumper - stringified perl data structures, suitable for both printing and eval
  • 4. Recommended Modules • In no particular order • Dumpvalue - provides screen dump of Perl data. • Encode - character encodings • ExtUtils::Install - install files from here to there • ExtUtils::Installed - Inventory management of installed modules • ExtUtils::Liblist - determine libraries to use and how to use them • ExtUtils::MakeMaker - Create a module Makefile • File::Basename - Parse file paths into directory, filename and suffix. • File::Compare - Compare files or filehandles
  • 5. Recommended Modules • In no particular order • File::Copy - Copy files or filehandles • File::Find - Traverse a directory tree. • File::Path - create or remove directory trees • File::Spec - portably perform operations on file names • File::stat - by-name interface to Perl's built-in stat() functions • File::Temp - return name and handle of a temporary file safely • FindBin - Locate directory of original perl script
  • 6. Recommended Modules • In no particular order • Getopt::Long - Extended processing of command line options • Getopt::Std - Process single-character switches with switch clustering • Hash::Util - A selection of general-utility hash subroutines • IO::* - supply object methods for * handles • IPC::* - processes... • List::Util - A selection of general-utility list subroutines • Locale::* - ISO codes, localization etc. • MIME::Base64 - Encoding and decoding of base64 strings
  • 7. Recommended Modules • In no particular order • Net::* - network programming • POSIX - Perl interface to IEEE Std 1003.1 • Scalar::Util - A selection of general-utility scalar subroutines • Storable - persistence for Perl data structures • Test::More - yet another framework for writing test scripts • ...
  • 8. Running perl • Run a perl program by • making it directly executable • passing the name of the source file as an argument on the command line • Upon startup, Perl looks for your program in one of the following places: • Specified line by line via -e or -E switches on the command line. • Contained in the file specified by the first filename on the command line. • Passed in implicitly via standard input.
  • 9. Running perl • Run a perl program by • making it directly executable • passing the name of the source file as an argument on the command line • Upon startup, Perl looks for your program in one of the following places: • Specified line by line via -e or -E switches on the command line. • Contained in the file specified by the first filename on the command line. • Passed in implicitly via standard input.
  • 10. Command-line switches • execute switch (-e) >perl -e 'print "Hello Worldn" ' >perl -e "print qq{Hello Worldn}" # Windows >perl -e 'for(1..20){print qq|hin|;}'
  • 11. Command-line switches • Running code snippets • This will tell you of syntax errors immediately, but script execution will not start until you send Perl an end-of-file character, • On Unix systems - CTRL-D at the start of a line • under Windows -CTRL-Z at the start of a line. >perl for(1..20){ print 'hi'.$/ }
  • 12. Command-line switches • Printing switch (-p) • tells Perl to act as a stream editor • will read input from STDIN, or from files mentioned on the command line, and place each line of input into $_. • your program is executed, and the contents of $_ are printed. • most commonly used with s///, >perl -pe 's/perl/Python/gi' filesed.txt >filesed1.txt
  • 13. Command-line switches • Module switch (-M) • use modules in the one-liner > perl -MData::Dumper -e 'print Dumper(%ENV)'
  • 14. Command-line switches • In-place switch (-i) • allows you to edit the file in place, overwriting the original version • a bug in your program can result in data-loss • provide an argument to the switch: -i.old to create a backup copy of the original file file.old and then overwrite the original > perl -i.old -pe 's/perl/python/gi' original.txt
  • 15. Command-line switches • Check switch (-c) • check the program for syntactic errors and to exit without executing the file > perl -c script.pl • Warnings switch (-w) • runs your program with warnings turned on • Include switch (-I) • additional directories to be searched for modules • modifies Perl’s special @INC variable.
  • 16. Filesystem analysis • Directory separators • use File::Spec to perform really OS independent operations on directories • use IO::Dir for directories manipulation • use Cwd to get the current working dir. use File::Spec::Functions qw(rel2abs); #or use File::Spec #later... $tmpdir = File::Spec->tmpdir(); $is_case_tolerant = File::Spec->case_tolerant();
  • 17. Filesystem analysis • Working with files • use File::Copy to copy and move files • use unlink() to delete files • use File::Temp to safely create temporary files • use file-test operators to find information about files • see: perldoc -f -x use File::Copy; copy("file1","file2") or die "Copy failed: $!"; copy("Copy.pm",*STDOUT); move("/dev1/fileA","/dev2/fileB");
  • 18. Filesystem analysis • Working with files • use chmod() to change file permissions • use umask() to change default file permissions • use chown() to change file ownership • use File::Find to traverse directory trees and recursively manipulate files in them use Fcntl; umask 0022; sysopen(FILE, "runme", O_WRONLY|O_CREAT|O_EXCL, 0777); #creates file with permissions 0755
  • 19. Mail processing • use Net::SMTP to send simple mail • use MIME::Lite to send mail with attachments • use Net::POP3 to retrieve mail • use Mail::Audit to filter your messages use Net::POP3; # Constructors $pop = Net::POP3->new('pop3host', Timeout => 60); if ($pop->login($username, $password) > 0) { my $msgnums = $pop->list; # hashref of msgnum => size foreach my $msgnum (keys %$msgnums) { #do something } } $pop->quit;
  • 20. Security notes • Taint checking • rule: You may not use data derived from outside your program to affect something else outside your program at least, not by accident. • all data that comes from external sources is tainted #!/usr/bin/perl -wT # Taint mode is enabled
  • 21. Security notes • Tainted data will be considered unsuitable for certain operations: • Executing system commands • Modifying files • Modifying directories • Modifying processes • Invoking any shell • Performing a match in a regular expression using the (?{ ... }) construct • Executing code using string eval #!/usr/bin/perl -wT # Taint mode is enabled
  • 22. System Programming and Administration • Ressources • perldoc perlrun • perldoc perlsec • http://perltraining.com.au/notes/sysadmin.pdf • http://perltraining.com.au/notes/perlsec.pdf • etc...