SlideShare a Scribd company logo
1 of 46
Minimal Perl Basics for
Pentesters
Sanjeev Jaiswal (Jassi)
Perl Programmer and Security Enthusiast
#nullhyd
Agenda
http://www.aliencoders.org/
•Minimal Perl fundamentals
•CPAN modules a Pentester should know
•Known Perl scripts for Pentesting
•Sample scripts (Demo)
http://www.aliencoders.org/
This is just the beginning…
Perl Fundamentals
http://www.aliencoders.org/
• When you refer a programming language say it Perl
• When you refer a script , let’s say perl
• But never ever say PERL, use perl or Perl
Perl mongers and Larry Wall don’t like it ;-)
Perl has some backronyms though
Practical Extraction and Report Language, or
Pathologically Eclectic Rubbish Lister.
And its Perl not Pearl
http://www.aliencoders.org/
Perl or perl or PERL?
• Try perl -v to check if it’s installed or not
Unix/Linux
• Run curl -L http://xrl.us/installperlnix | bash in terminal
OSX
• Install command line toll Xcode
• Run curl -L http://xrl.us/installperlnix | bash in terminal
Windows
• install strawberry perl or activestate perl
Then install cpan App::cpanminus to install perl modules easily in future
http://www.aliencoders.org/
Installing perl
• perl <perl_program>
• chmod 755 and execute ./<perl_program>
Let’s try something more on CLI
• perl –d <perl_program> #Diagonise more
• perl –c <perl_program> #check if syntax is ok
• perl -e 'print "perl one-linern";'
• perl one-liner examples (palindrome, inplace-editing)
http://www.aliencoders.org/
Executing perl program
• shebang i.e #!
• print, say
• #comment
• $calar, @rray, %ash
• Comparison operators (> or gt <= or le)
• Reference in Perl
• %INC and @INC
http://www.aliencoders.org/
Who’s who in Perl ;)
#!/usr/bin/perl #Shebang starts with #!
use strict;
use warnings;
# It's a comment and its just the basic
my $name = "Sanjeev Jaiswal"; #scalar
my $id = 10; # scalar
my $sal = 100.98; #scalar
my @name = ("Sanjeev", "Jaiswal"); #array
my %hash = ('fname'=>'Sanjeev', 'lname', 'Jaiswal'); #hash
print "$id, $name[0], $hash{'lname}n";
print "$namen" if ( $id < 100 );
http://www.aliencoders.org/
Basic Example in Perl ;)
Loop Control
http://www.aliencoders.org/
•if, if else, if elsif else
•for, foreach
•while, do while
•next, unless, last
•return, exit
http://www.aliencoders.org/
Loop and control structures
while(<>){
next if /^d+/;
last if /^W/;
print $_;
}
print $_ foreach(1 .. 100);
print if(10 <= 10.0);
if($name eq 'sanjeev'){
print "$namen";
} elsif ($id >70){
print "$idn";
} else {
print "not matchedn";
}
http://www.aliencoders.org/
Loop and control structures
Functions to memorize
http://www.aliencoders.org/
•shift , push and chomp
•sort and reverse
•exec, system and eval
•warn, die
•join and split
•keys, values, each
•exists, defined, delete, unlink
http://www.aliencoders.org/
Minimal functions you should know
• chomp (my $u_input = <STDIN>); #chomps the user input
• my $f_elem = shift @array; # assign first element of an array
• push @arr, $elem; # Adding $elem at the last of @arr
• @sorted_num = sort {$a <=> $b} @unsorted_num; #sort integer array
• @reverse_sort = sort {$b <=> $a} @unsorted_num; #reverse sort
• @reverse_sort = reverse sort @unsorted_arr # reverse sort of string array or
• @reverse_sort = sort {$b cmp $a} @unsorted_arr
• warn "Very highn" if($num > 10);
• die "Very lown" if($num < 2);
• system("ls -la", "dir" )
• exec("/bin/cat", "/home.txt");
• `ls -la`; #avoid backtick if possible
• join(/s/ , @array);
• split(/s/, $string);
http://www.aliencoders.org/
Minimal examples ;)
Perl File Handlers
http://www.aliencoders.org/
•open(), close()
•>, >>, <
•+>, +>>, +<
•File testing -e, -f, -d, -s, -m etc.
•opendir, closedir, readdir
http://www.aliencoders.org/
Manipulate file handling
open(FH, "<", "filename") or die "can't open: $!n";
# > for write and >> for append
while ( defined(my $line = <FH>) ) { do something .. }
close(FH);
open(LS, "<", "ls -la|"); # use instead of ``
open(FIND, "find . -type f -name dns_info.pl |-"); #better than previous command
do something if -e $file; # -e means exists, -f is for file and -d for directory
do something if -s >0; #-s is for size and -m means modified
$dir = "/home/sanjeev/";
opendir ( DIR, $dir ) || die "Error in opening directory $dirn";
while( ($file = readdir(DIR))){
next if $file =~ m/.{1,2}/;
print("$filen") if -f $file;
}
closedir(DIR);
http://www.aliencoders.org/
File Handling examples
Perl Special Variables
• $0 – name of perl script being executed
• $^O – O.S.
• $! – current value of errno in scalar and string in list context
• $@ - error message from the last eval, do-FILE, or require command
• $_ - default input and search pattern space
• @_ - arguments passed to the given subroutine
• $$ - process number of the running program
• $? – status returned by the last pipe close, back tick or system command
http://www.aliencoders.org/
Most used special variables
Regular Expression
http://www.aliencoders.org/
• Regex operators: m, s, tr
• Metacharacters: ^, $, ., , |, (, ), [, ], *, +, ?, {, }
• Quantifiers (iterators): *, +, ?, {m}, {m,n}, {m,}
• Characters classes: [], ^(negation), - (ranges)
• Character class abbr: d, D, s, S, w, W,
• Anchors: ^, $, b ,B, A,Z, z
• Modifiers: m,s,i,g,e,x etc.
http://www.aliencoders.org/
Real Power of Perl
 next if $file =~ m/.{1,2}/; #skip if its . or ..
 if($ARGV[0] =~/^(d+.){3}d+$/) { .. } # IPv4
 $word =~ s/^s+|s+$//; #trim a word
 return int( (split /./, $string)[0] ); #string to int conversion
 my $email =~ /^([a-zA-Z][w_.]{6,15})@([a-zA-Z0-9-]+).([a-zA-Z]{2,4})$/;
#email validation
 my ($matched) = $content =~ /$phone_code(.*?)d+/sg ? $1 : 'No Result.';
 my ($alexa_rank) = $content =~ m#globe-sm.jpg(?:.*?)">(.*?)</strong>?#gis
 ($version) = $content =~ /versions+(d+.d+(?:.d+)?)/mig; } # wp-version
 m#wp-(?:admin|content|includes)/(?!plugins|js).*?ver=(d+.d+(?:.d+)?(?:[-
w.]+)?)#mig; }
 $dob =~ #^((?:19|20)dd)[-/.](0[1-9]|1[012])[-/.](0[1-9]|[12][0-9]|3[01])$#;
#yyyy-mm-dd format
http://www.aliencoders.org/
Real Power of Perl
Perl Modules to learn
http://www.aliencoders.org/
• CGI – Handles CGI request and responses
• DBI – for any database related stuffs
• Net::IP – manipulate IPv4/IPv6 address
• Net::RawIP - manipulate raw IP packets with interface to libpcap
• Net::DNS – DNS resolver implemented in Perl
• Net::SNMP - Object oriented interface to SNMP
• IO::Socket - Object interface to socket communications
• WWW::Mechanize - Automating web browsing
• LWP::UserAgent – web user agent class
• http://search.cpan.org/~jabra/ for all scan parsers
http://www.aliencoders.org/
Modules useful for Pentesters
Perl Helpers
http://www.aliencoders.org/
• perldoc perlmodlib – modules with Perl distribution
• perldoc perllocal – Locally installed modules
• perldoc perlfunc – list of perl functions
• perldoc perlop – list of perl operators
• perldoc perl – overview of perl
• perldoc -m Net::Ping – see the code behind it ;)
• perldoc -f map – help for a specific function
• perldoc IO::Socket – documentation for the given module
• man IO::Socket – same as above
• perl -MData::Dumper -e 'print 1 ' -module installed or not
• perl -MCGI -e 'print "$CGI::VERSION n" ' -module version
http://www.aliencoders.org/
Scripts for Pentesting
http://www.aliencoders.org/
• dnsenum, dnswalk, fierce
• nikto - web server scanner
• sqlninja - SQL Server injection and takeover tool
• snmpenum, snmpwalk, snmpcheck
• arp-fingerprint – Fingerpring a system using ARP
• cisco-torch.pl, CAT
• WeBaCoo - Web Backdoor Cookie Script kit
• uniscan - RFI, LFI and RCE, XSS, SQLi vulnerability scanner
• Slowlowris - HTTP DoS Tool
http://www.aliencoders.org/
Perl scripts in Kali/Others
Demo
http://www.aliencoders.org/
•DNS Info
•Header Response Info
•Website Details
•Get WordPress Version
•Simple Port scan
•IP from ifconfig
•Get GHDB list in a file
•Windows OS Version details
http://www.aliencoders.org/
Kickstart with simple scripts
#!/usr/bin/perl
use strict;
use warnings;
use IO::Socket::INET;
my $socket;
my $host = $ARGV[0] || die "Usage: perl $0 <hostname>n";
my @ports = qw(21 22 23 25 53 69 80 110 137 139 143 150 162 443 445);
for(@ports){
my $success = eval {
$socket = IO::Socket::INET->new(
PeerAddr => $host,
PeerPort => $_,
Proto => 'tcp‘ )
};
#If the port was opened, say it was and close it.
if ($success) {
print "Port $_: Openn";
shutdown($socket, 2);
}
};
http://www.aliencoders.org/
Simple Port Scan
use WWW::Mechanize;
use LWP::UserAgent;
my $url = $ARGV[0] || die "Should pass site name $0 <sitename>n";
$url = "http://".$url unless($url =~ m/^http/);
print "# Checking Response Header for generator tagn";
my $meta_version = check_response_header( $url );
print_version( $url, $meta_version) if $meta_version;
print "# Checking readme.html source for the versionn";
my $readme_version = get_site_content( "$url/readme.html" );
print_version( $url, $readme_version ) if $readme_version;
print "# Checking wp-login.php source page for ?ver= instances n";
my $login_ver = get_site_content( "$url/wp-login.php" );
print_version( $url, $login_ver ) if ( $login_ver );
http://www.aliencoders.org/
Find WordPress Version
use LWP::UserAgent; # for web requests
use WWW::Mechanize; # My favourite web scrapper module
$url = "http://".$url unless($url =~ m/^http/);
# Using LWP::UserAgent method 1
my $ua = LWP::UserAgent->new();
$ua->agent('Mozilla/5.0');
# connect and get
my $response = $ua->get($url);
print $response->headers()->as_string;
# Using WWW::Mechanize method 2
my $mech = WWW::Mechanize->new();
my $resp = $mech->get($url);
print $resp->headers->as_string;
http://www.aliencoders.org/
Get Header Response
use WWW::Mechanize;
my $mech = WWW::Mechanize->new();
my $url = "http://www.exploit-db.com/google-dorks/";
$mech->get( $url );
my $link = $mech->find_link( url_regex => qr/ghdb/ );
my ($ghdb_count) = $link->[0] =~ m|ghdb/(d+)/|;
my $exploit_url = "http://www.exploit-db.com/ghdb/";
open FH, "+<", "ghdb.txt" or die "Can't open ghdb.txt: $!n";
chomp( my @ghdb_content = <FH> );
my $present_count = 0;
($present_count) = split(/./, $ghdb_content[$#ghdb_content]) if(scalar @ghdb_content > 1);
binmode(FH, ":utf8");
for( ($present_count + 1) .. $ghdb_count ){
my $final_url = $exploit_url."$_";
my $mc = WWW::Mechanize->new();
$mc->get( $final_url );
my $dork = $mc->content();
my $link = $mc->find_link( url_regex => qr/search|image.*?q=/);
$link->[1] =~ s/[^[:ascii:]]+//g if($link->[1]);
print FH "$_. $link->[1]n" if($link->[1]);
}
close(FH);
http://www.aliencoders.org/
Save GHDB in text file
use Net::DNS;
use Net::IP;
die "Usage: perl $0 [site_name|IP Address]n" unless(scalar $ARGV[0]);
if($ARGV[0] =~/^(d+.){3}d+$/){
$ip_address = new Net::IP($ARGV[0],4);
} else {
$site = $ARGV[0];
$site =~ s#http[s]?://##;
$site =~ s/www.//;
}
my $res = Net::DNS::Resolver->new;
if($site){ show_ip(); show_ns(); show_mx(); show_soa(); }
show_ip_lookup() if($ip_address);
http://www.aliencoders.org/
Get DNS Info of a site
open my $in, "/sbin/ifconfig |";
my (@addrs);
while (my $line = <$in>)
{
if ($line =~ /inet addr:((d+.){3}d+)/)
{
push @addrs, $1;
}
}
close($in);
print "You have the following addresses: n", join("n",@addrs), "n";
http://www.aliencoders.org/
Get IP from ifconfig
Future Scope
http://www.aliencoders.org/
•Can write DoS exploits
•Buffer overflow test
•MITM exploits
•Fuzzying
•Nmap scripts
•RFI,RCE exploits
•Network Pentesting
•Web Attacks automations
•Integrate with RE Tools
•Data Scrapping and many more
http://www.aliencoders.org/
We can do almost everything
Resources
http://www.aliencoders.org/
•http://www.cpan.org/
•http://perldoc.perl.org/
•https://twitter.com/jabra
•http://www.sans.org/
•https://www.kali.org/
•https://www.blackhat.com/
•https://www.owasp.org/index.php/Perl
•http://www.aliencoders.org/forum/Forum-perl
•http://www.iconsdb.com for icons used
http://www.aliencoders.org/
Links you can follow
•Learning Perl by Brian D foy
•Programming Perl by Larry Wall
•Penetration Testing with Perl Douglas Berdeaux
•Network Programming with Perl Lincon D. Stein
•Perl for System Administration David Edelman
http://www.aliencoders.org/
Books you can read
• https://twitter.com/jabra Joshua Abraham
• https://twitter.com/weaknetlabs Douglas Berdeaux
• https://twitter.com/briandfoy_perl Brian D Foy
• https://twitter.com/davorg Dave Cross
• https://twitter.com/timtoady Larry Wall
• https://twitter.com/merlyn Randal L. Schwartz
• https://twitter.com/szabgab Gabor Szabo
http://www.aliencoders.org/
People you can follow
Support and share
http://www.aliencoders.org/
Website: http://www.aliencoders.org/
Facebook: https://www.facebook.com/aliencoders
Slideshare: http://slideshare.net/jassics
Twitter: https://twitter.com/aliencoders
G+: https://plus.google.com/+Aliencoders/
LinkedIn: https://www.linkedin.com/groups/Alien-Coders-4642371
YouTube: http://www.youtube.com/user/jassics
Learning through sharing
Questions
http://www.aliencoders.org/

More Related Content

What's hot

BSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationBSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationWorkhorse Computing
 
Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.Workhorse Computing
 
Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)Kris Wallsmith
 
Mining Ruby Gem vulnerabilities for Fun and No Profit.
Mining Ruby Gem vulnerabilities for Fun and No Profit.Mining Ruby Gem vulnerabilities for Fun and No Profit.
Mining Ruby Gem vulnerabilities for Fun and No Profit.Larry Cashdollar
 
I, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 OverlordsI, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 Overlordsheumann
 
Object Trampoline: Why having not the object you want is what you need.
Object Trampoline: Why having not the object you want is what you need.Object Trampoline: Why having not the object you want is what you need.
Object Trampoline: Why having not the object you want is what you need.Workhorse Computing
 
PHP 7 – What changed internally? (PHP Barcelona 2015)
PHP 7 – What changed internally? (PHP Barcelona 2015)PHP 7 – What changed internally? (PHP Barcelona 2015)
PHP 7 – What changed internally? (PHP Barcelona 2015)Nikita Popov
 
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6Workhorse Computing
 
The Joy of Smartmatch
The Joy of SmartmatchThe Joy of Smartmatch
The Joy of SmartmatchAndrew Shitov
 
Defensive Coding Crash Course Tutorial
Defensive Coding Crash Course TutorialDefensive Coding Crash Course Tutorial
Defensive Coding Crash Course TutorialMark Niebergall
 

What's hot (20)

BSDM with BASH: Command Interpolation
BSDM with BASH: Command InterpolationBSDM with BASH: Command Interpolation
BSDM with BASH: Command Interpolation
 
Smoking docker
Smoking dockerSmoking docker
Smoking docker
 
Get your teeth into Plack
Get your teeth into PlackGet your teeth into Plack
Get your teeth into Plack
 
Perl basics for pentesters part 2
Perl basics for pentesters part 2Perl basics for pentesters part 2
Perl basics for pentesters part 2
 
Perl Basics for Pentesters Part 1
Perl Basics for Pentesters Part 1Perl Basics for Pentesters Part 1
Perl Basics for Pentesters Part 1
 
Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.Perl6 Regexen: Reduce the line noise in your code.
Perl6 Regexen: Reduce the line noise in your code.
 
Perl6 grammars
Perl6 grammarsPerl6 grammars
Perl6 grammars
 
Ruby 2.0
Ruby 2.0Ruby 2.0
Ruby 2.0
 
Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)Introducing Assetic (NYPHP)
Introducing Assetic (NYPHP)
 
Mining Ruby Gem vulnerabilities for Fun and No Profit.
Mining Ruby Gem vulnerabilities for Fun and No Profit.Mining Ruby Gem vulnerabilities for Fun and No Profit.
Mining Ruby Gem vulnerabilities for Fun and No Profit.
 
dotCloud and go
dotCloud and godotCloud and go
dotCloud and go
 
Perl6 in-production
Perl6 in-productionPerl6 in-production
Perl6 in-production
 
Memory Manglement in Raku
Memory Manglement in RakuMemory Manglement in Raku
Memory Manglement in Raku
 
I, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 OverlordsI, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 Overlords
 
Object Trampoline: Why having not the object you want is what you need.
Object Trampoline: Why having not the object you want is what you need.Object Trampoline: Why having not the object you want is what you need.
Object Trampoline: Why having not the object you want is what you need.
 
PHP 7 – What changed internally? (PHP Barcelona 2015)
PHP 7 – What changed internally? (PHP Barcelona 2015)PHP 7 – What changed internally? (PHP Barcelona 2015)
PHP 7 – What changed internally? (PHP Barcelona 2015)
 
Perl 6 by example
Perl 6 by examplePerl 6 by example
Perl 6 by example
 
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
Neatly Hashing a Tree: FP tree-fold in Perl5 & Perl6
 
The Joy of Smartmatch
The Joy of SmartmatchThe Joy of Smartmatch
The Joy of Smartmatch
 
Defensive Coding Crash Course Tutorial
Defensive Coding Crash Course TutorialDefensive Coding Crash Course Tutorial
Defensive Coding Crash Course Tutorial
 

Viewers also liked

《2012 年商品說明(不良營商手法)(修訂)條例》研討會 - 香港海關
《2012 年商品說明(不良營商手法)(修訂)條例》研討會 - 香港海關《2012 年商品說明(不良營商手法)(修訂)條例》研討會 - 香港海關
《2012 年商品說明(不良營商手法)(修訂)條例》研討會 - 香港海關HKAIM
 
Basics of JSON (JavaScript Object Notation) with examples
Basics of JSON (JavaScript Object Notation) with examplesBasics of JSON (JavaScript Object Notation) with examples
Basics of JSON (JavaScript Object Notation) with examplesSanjeev Kumar Jaiswal
 
Delta Sigma Pi Recruiting Video - Siena College
Delta Sigma Pi Recruiting Video - Siena CollegeDelta Sigma Pi Recruiting Video - Siena College
Delta Sigma Pi Recruiting Video - Siena Collegeguest83ecd2
 
Wakoo3
Wakoo3Wakoo3
Wakoo3Bloom
 
Spider photo album
Spider photo albumSpider photo album
Spider photo albumlandml
 
VietnamRealEstate_E-Directory_VN_Q1_2009
VietnamRealEstate_E-Directory_VN_Q1_2009VietnamRealEstate_E-Directory_VN_Q1_2009
VietnamRealEstate_E-Directory_VN_Q1_2009internationalvr
 
Teaching with technology
Teaching with technologyTeaching with technology
Teaching with technologytsmeans
 
eCMO 2010 Unleash the power of mobile advertising
eCMO 2010 Unleash the power of mobile advertisingeCMO 2010 Unleash the power of mobile advertising
eCMO 2010 Unleash the power of mobile advertisingHKAIM
 
Introduction to Educational Media Production
Introduction to Educational Media ProductionIntroduction to Educational Media Production
Introduction to Educational Media ProductionRachabodin Suwannakanthi
 
Sustainability, More Than Survival - ISA Workshop, June 2009, with notes
Sustainability, More Than Survival - ISA Workshop, June 2009,  with notesSustainability, More Than Survival - ISA Workshop, June 2009,  with notes
Sustainability, More Than Survival - ISA Workshop, June 2009, with notesMason International Business Group
 
Fantasmes Vampirs I Altres Monstres
Fantasmes Vampirs I Altres MonstresFantasmes Vampirs I Altres Monstres
Fantasmes Vampirs I Altres MonstresEduardo CONNOLLY
 

Viewers also liked (20)

《2012 年商品說明(不良營商手法)(修訂)條例》研討會 - 香港海關
《2012 年商品說明(不良營商手法)(修訂)條例》研討會 - 香港海關《2012 年商品說明(不良營商手法)(修訂)條例》研討會 - 香港海關
《2012 年商品說明(不良營商手法)(修訂)條例》研討會 - 香港海關
 
Basics of JSON (JavaScript Object Notation) with examples
Basics of JSON (JavaScript Object Notation) with examplesBasics of JSON (JavaScript Object Notation) with examples
Basics of JSON (JavaScript Object Notation) with examples
 
Zipcast test
Zipcast testZipcast test
Zipcast test
 
Hydration for runners
Hydration for runnersHydration for runners
Hydration for runners
 
Delta Sigma Pi Recruiting Video - Siena College
Delta Sigma Pi Recruiting Video - Siena CollegeDelta Sigma Pi Recruiting Video - Siena College
Delta Sigma Pi Recruiting Video - Siena College
 
Wakoo3
Wakoo3Wakoo3
Wakoo3
 
Spider photo album
Spider photo albumSpider photo album
Spider photo album
 
VietnamRealEstate_E-Directory_VN_Q1_2009
VietnamRealEstate_E-Directory_VN_Q1_2009VietnamRealEstate_E-Directory_VN_Q1_2009
VietnamRealEstate_E-Directory_VN_Q1_2009
 
Teaching with technology
Teaching with technologyTeaching with technology
Teaching with technology
 
Erasmus+ uppgift
Erasmus+ uppgiftErasmus+ uppgift
Erasmus+ uppgift
 
Fitted mind factory.pptx
Fitted mind factory.pptxFitted mind factory.pptx
Fitted mind factory.pptx
 
Fountainheads presentation
Fountainheads presentationFountainheads presentation
Fountainheads presentation
 
eCMO 2010 Unleash the power of mobile advertising
eCMO 2010 Unleash the power of mobile advertisingeCMO 2010 Unleash the power of mobile advertising
eCMO 2010 Unleash the power of mobile advertising
 
Introduction to Educational Media Production
Introduction to Educational Media ProductionIntroduction to Educational Media Production
Introduction to Educational Media Production
 
Real Time Image Processing
Real Time Image ProcessingReal Time Image Processing
Real Time Image Processing
 
Beekman5 std ppt_14
Beekman5 std ppt_14Beekman5 std ppt_14
Beekman5 std ppt_14
 
Sustainability, More Than Survival - ISA Workshop, June 2009, with notes
Sustainability, More Than Survival - ISA Workshop, June 2009,  with notesSustainability, More Than Survival - ISA Workshop, June 2009,  with notes
Sustainability, More Than Survival - ISA Workshop, June 2009, with notes
 
MyOpenArchive
MyOpenArchiveMyOpenArchive
MyOpenArchive
 
Final Project
Final ProjectFinal Project
Final Project
 
Fantasmes Vampirs I Altres Monstres
Fantasmes Vampirs I Altres MonstresFantasmes Vampirs I Altres Monstres
Fantasmes Vampirs I Altres Monstres
 

Similar to Perl basics for Pentesters

Similar to Perl basics for Pentesters (20)

Perl Moderno
Perl ModernoPerl Moderno
Perl Moderno
 
Whatsnew in-perl
Whatsnew in-perlWhatsnew in-perl
Whatsnew in-perl
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
My shell
My shellMy shell
My shell
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
IO Streams, Files and Directories
IO Streams, Files and DirectoriesIO Streams, Files and Directories
IO Streams, Files and Directories
 
Starting Out With PHP
Starting Out With PHPStarting Out With PHP
Starting Out With PHP
 
Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In Perl
 
Bash Scripting Workshop
Bash Scripting WorkshopBash Scripting Workshop
Bash Scripting Workshop
 
Introduction to Perl
Introduction to PerlIntroduction to Perl
Introduction to Perl
 
Perl 5.10
Perl 5.10Perl 5.10
Perl 5.10
 
Bioinformatica 29-09-2011-p1-introduction
Bioinformatica 29-09-2011-p1-introductionBioinformatica 29-09-2011-p1-introduction
Bioinformatica 29-09-2011-p1-introduction
 
All I Need to Know I Learned by Writing My Own Web Framework
All I Need to Know I Learned by Writing My Own Web FrameworkAll I Need to Know I Learned by Writing My Own Web Framework
All I Need to Know I Learned by Writing My Own Web Framework
 
10 tips for making Bash a sane programming language
10 tips for making Bash a sane programming language10 tips for making Bash a sane programming language
10 tips for making Bash a sane programming language
 
Modern Perl
Modern PerlModern Perl
Modern Perl
 
Node.js for PHP developers
Node.js for PHP developersNode.js for PHP developers
Node.js for PHP developers
 
Unix 5 en
Unix 5 enUnix 5 en
Unix 5 en
 
Discover Dart(lang) - Meetup 07/12/2016
Discover Dart(lang) - Meetup 07/12/2016Discover Dart(lang) - Meetup 07/12/2016
Discover Dart(lang) - Meetup 07/12/2016
 
Discover Dart - Meetup 15/02/2017
Discover Dart - Meetup 15/02/2017Discover Dart - Meetup 15/02/2017
Discover Dart - Meetup 15/02/2017
 
EC2
EC2EC2
EC2
 

Recently uploaded

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024The Digital Insurer
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...gurkirankumar98700
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 

Recently uploaded (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
Kalyanpur ) Call Girls in Lucknow Finest Escorts Service 🍸 8923113531 🎰 Avail...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 

Perl basics for Pentesters

  • 1. Minimal Perl Basics for Pentesters Sanjeev Jaiswal (Jassi) Perl Programmer and Security Enthusiast #nullhyd
  • 3. •Minimal Perl fundamentals •CPAN modules a Pentester should know •Known Perl scripts for Pentesting •Sample scripts (Demo) http://www.aliencoders.org/ This is just the beginning…
  • 5. • When you refer a programming language say it Perl • When you refer a script , let’s say perl • But never ever say PERL, use perl or Perl Perl mongers and Larry Wall don’t like it ;-) Perl has some backronyms though Practical Extraction and Report Language, or Pathologically Eclectic Rubbish Lister. And its Perl not Pearl http://www.aliencoders.org/ Perl or perl or PERL?
  • 6. • Try perl -v to check if it’s installed or not Unix/Linux • Run curl -L http://xrl.us/installperlnix | bash in terminal OSX • Install command line toll Xcode • Run curl -L http://xrl.us/installperlnix | bash in terminal Windows • install strawberry perl or activestate perl Then install cpan App::cpanminus to install perl modules easily in future http://www.aliencoders.org/ Installing perl
  • 7. • perl <perl_program> • chmod 755 and execute ./<perl_program> Let’s try something more on CLI • perl –d <perl_program> #Diagonise more • perl –c <perl_program> #check if syntax is ok • perl -e 'print "perl one-linern";' • perl one-liner examples (palindrome, inplace-editing) http://www.aliencoders.org/ Executing perl program
  • 8. • shebang i.e #! • print, say • #comment • $calar, @rray, %ash • Comparison operators (> or gt <= or le) • Reference in Perl • %INC and @INC http://www.aliencoders.org/ Who’s who in Perl ;)
  • 9. #!/usr/bin/perl #Shebang starts with #! use strict; use warnings; # It's a comment and its just the basic my $name = "Sanjeev Jaiswal"; #scalar my $id = 10; # scalar my $sal = 100.98; #scalar my @name = ("Sanjeev", "Jaiswal"); #array my %hash = ('fname'=>'Sanjeev', 'lname', 'Jaiswal'); #hash print "$id, $name[0], $hash{'lname}n"; print "$namen" if ( $id < 100 ); http://www.aliencoders.org/ Basic Example in Perl ;)
  • 11. •if, if else, if elsif else •for, foreach •while, do while •next, unless, last •return, exit http://www.aliencoders.org/ Loop and control structures
  • 12. while(<>){ next if /^d+/; last if /^W/; print $_; } print $_ foreach(1 .. 100); print if(10 <= 10.0); if($name eq 'sanjeev'){ print "$namen"; } elsif ($id >70){ print "$idn"; } else { print "not matchedn"; } http://www.aliencoders.org/ Loop and control structures
  • 14. •shift , push and chomp •sort and reverse •exec, system and eval •warn, die •join and split •keys, values, each •exists, defined, delete, unlink http://www.aliencoders.org/ Minimal functions you should know
  • 15. • chomp (my $u_input = <STDIN>); #chomps the user input • my $f_elem = shift @array; # assign first element of an array • push @arr, $elem; # Adding $elem at the last of @arr • @sorted_num = sort {$a <=> $b} @unsorted_num; #sort integer array • @reverse_sort = sort {$b <=> $a} @unsorted_num; #reverse sort • @reverse_sort = reverse sort @unsorted_arr # reverse sort of string array or • @reverse_sort = sort {$b cmp $a} @unsorted_arr • warn "Very highn" if($num > 10); • die "Very lown" if($num < 2); • system("ls -la", "dir" ) • exec("/bin/cat", "/home.txt"); • `ls -la`; #avoid backtick if possible • join(/s/ , @array); • split(/s/, $string); http://www.aliencoders.org/ Minimal examples ;)
  • 17. •open(), close() •>, >>, < •+>, +>>, +< •File testing -e, -f, -d, -s, -m etc. •opendir, closedir, readdir http://www.aliencoders.org/ Manipulate file handling
  • 18. open(FH, "<", "filename") or die "can't open: $!n"; # > for write and >> for append while ( defined(my $line = <FH>) ) { do something .. } close(FH); open(LS, "<", "ls -la|"); # use instead of `` open(FIND, "find . -type f -name dns_info.pl |-"); #better than previous command do something if -e $file; # -e means exists, -f is for file and -d for directory do something if -s >0; #-s is for size and -m means modified $dir = "/home/sanjeev/"; opendir ( DIR, $dir ) || die "Error in opening directory $dirn"; while( ($file = readdir(DIR))){ next if $file =~ m/.{1,2}/; print("$filen") if -f $file; } closedir(DIR); http://www.aliencoders.org/ File Handling examples
  • 20. • $0 – name of perl script being executed • $^O – O.S. • $! – current value of errno in scalar and string in list context • $@ - error message from the last eval, do-FILE, or require command • $_ - default input and search pattern space • @_ - arguments passed to the given subroutine • $$ - process number of the running program • $? – status returned by the last pipe close, back tick or system command http://www.aliencoders.org/ Most used special variables
  • 22. • Regex operators: m, s, tr • Metacharacters: ^, $, ., , |, (, ), [, ], *, +, ?, {, } • Quantifiers (iterators): *, +, ?, {m}, {m,n}, {m,} • Characters classes: [], ^(negation), - (ranges) • Character class abbr: d, D, s, S, w, W, • Anchors: ^, $, b ,B, A,Z, z • Modifiers: m,s,i,g,e,x etc. http://www.aliencoders.org/ Real Power of Perl
  • 23.  next if $file =~ m/.{1,2}/; #skip if its . or ..  if($ARGV[0] =~/^(d+.){3}d+$/) { .. } # IPv4  $word =~ s/^s+|s+$//; #trim a word  return int( (split /./, $string)[0] ); #string to int conversion  my $email =~ /^([a-zA-Z][w_.]{6,15})@([a-zA-Z0-9-]+).([a-zA-Z]{2,4})$/; #email validation  my ($matched) = $content =~ /$phone_code(.*?)d+/sg ? $1 : 'No Result.';  my ($alexa_rank) = $content =~ m#globe-sm.jpg(?:.*?)">(.*?)</strong>?#gis  ($version) = $content =~ /versions+(d+.d+(?:.d+)?)/mig; } # wp-version  m#wp-(?:admin|content|includes)/(?!plugins|js).*?ver=(d+.d+(?:.d+)?(?:[- w.]+)?)#mig; }  $dob =~ #^((?:19|20)dd)[-/.](0[1-9]|1[012])[-/.](0[1-9]|[12][0-9]|3[01])$#; #yyyy-mm-dd format http://www.aliencoders.org/ Real Power of Perl
  • 24. Perl Modules to learn http://www.aliencoders.org/
  • 25. • CGI – Handles CGI request and responses • DBI – for any database related stuffs • Net::IP – manipulate IPv4/IPv6 address • Net::RawIP - manipulate raw IP packets with interface to libpcap • Net::DNS – DNS resolver implemented in Perl • Net::SNMP - Object oriented interface to SNMP • IO::Socket - Object interface to socket communications • WWW::Mechanize - Automating web browsing • LWP::UserAgent – web user agent class • http://search.cpan.org/~jabra/ for all scan parsers http://www.aliencoders.org/ Modules useful for Pentesters
  • 27. • perldoc perlmodlib – modules with Perl distribution • perldoc perllocal – Locally installed modules • perldoc perlfunc – list of perl functions • perldoc perlop – list of perl operators • perldoc perl – overview of perl • perldoc -m Net::Ping – see the code behind it ;) • perldoc -f map – help for a specific function • perldoc IO::Socket – documentation for the given module • man IO::Socket – same as above • perl -MData::Dumper -e 'print 1 ' -module installed or not • perl -MCGI -e 'print "$CGI::VERSION n" ' -module version http://www.aliencoders.org/
  • 29. • dnsenum, dnswalk, fierce • nikto - web server scanner • sqlninja - SQL Server injection and takeover tool • snmpenum, snmpwalk, snmpcheck • arp-fingerprint – Fingerpring a system using ARP • cisco-torch.pl, CAT • WeBaCoo - Web Backdoor Cookie Script kit • uniscan - RFI, LFI and RCE, XSS, SQLi vulnerability scanner • Slowlowris - HTTP DoS Tool http://www.aliencoders.org/ Perl scripts in Kali/Others
  • 31. •DNS Info •Header Response Info •Website Details •Get WordPress Version •Simple Port scan •IP from ifconfig •Get GHDB list in a file •Windows OS Version details http://www.aliencoders.org/ Kickstart with simple scripts
  • 32. #!/usr/bin/perl use strict; use warnings; use IO::Socket::INET; my $socket; my $host = $ARGV[0] || die "Usage: perl $0 <hostname>n"; my @ports = qw(21 22 23 25 53 69 80 110 137 139 143 150 162 443 445); for(@ports){ my $success = eval { $socket = IO::Socket::INET->new( PeerAddr => $host, PeerPort => $_, Proto => 'tcp‘ ) }; #If the port was opened, say it was and close it. if ($success) { print "Port $_: Openn"; shutdown($socket, 2); } }; http://www.aliencoders.org/ Simple Port Scan
  • 33. use WWW::Mechanize; use LWP::UserAgent; my $url = $ARGV[0] || die "Should pass site name $0 <sitename>n"; $url = "http://".$url unless($url =~ m/^http/); print "# Checking Response Header for generator tagn"; my $meta_version = check_response_header( $url ); print_version( $url, $meta_version) if $meta_version; print "# Checking readme.html source for the versionn"; my $readme_version = get_site_content( "$url/readme.html" ); print_version( $url, $readme_version ) if $readme_version; print "# Checking wp-login.php source page for ?ver= instances n"; my $login_ver = get_site_content( "$url/wp-login.php" ); print_version( $url, $login_ver ) if ( $login_ver ); http://www.aliencoders.org/ Find WordPress Version
  • 34. use LWP::UserAgent; # for web requests use WWW::Mechanize; # My favourite web scrapper module $url = "http://".$url unless($url =~ m/^http/); # Using LWP::UserAgent method 1 my $ua = LWP::UserAgent->new(); $ua->agent('Mozilla/5.0'); # connect and get my $response = $ua->get($url); print $response->headers()->as_string; # Using WWW::Mechanize method 2 my $mech = WWW::Mechanize->new(); my $resp = $mech->get($url); print $resp->headers->as_string; http://www.aliencoders.org/ Get Header Response
  • 35. use WWW::Mechanize; my $mech = WWW::Mechanize->new(); my $url = "http://www.exploit-db.com/google-dorks/"; $mech->get( $url ); my $link = $mech->find_link( url_regex => qr/ghdb/ ); my ($ghdb_count) = $link->[0] =~ m|ghdb/(d+)/|; my $exploit_url = "http://www.exploit-db.com/ghdb/"; open FH, "+<", "ghdb.txt" or die "Can't open ghdb.txt: $!n"; chomp( my @ghdb_content = <FH> ); my $present_count = 0; ($present_count) = split(/./, $ghdb_content[$#ghdb_content]) if(scalar @ghdb_content > 1); binmode(FH, ":utf8"); for( ($present_count + 1) .. $ghdb_count ){ my $final_url = $exploit_url."$_"; my $mc = WWW::Mechanize->new(); $mc->get( $final_url ); my $dork = $mc->content(); my $link = $mc->find_link( url_regex => qr/search|image.*?q=/); $link->[1] =~ s/[^[:ascii:]]+//g if($link->[1]); print FH "$_. $link->[1]n" if($link->[1]); } close(FH); http://www.aliencoders.org/ Save GHDB in text file
  • 36. use Net::DNS; use Net::IP; die "Usage: perl $0 [site_name|IP Address]n" unless(scalar $ARGV[0]); if($ARGV[0] =~/^(d+.){3}d+$/){ $ip_address = new Net::IP($ARGV[0],4); } else { $site = $ARGV[0]; $site =~ s#http[s]?://##; $site =~ s/www.//; } my $res = Net::DNS::Resolver->new; if($site){ show_ip(); show_ns(); show_mx(); show_soa(); } show_ip_lookup() if($ip_address); http://www.aliencoders.org/ Get DNS Info of a site
  • 37. open my $in, "/sbin/ifconfig |"; my (@addrs); while (my $line = <$in>) { if ($line =~ /inet addr:((d+.){3}d+)/) { push @addrs, $1; } } close($in); print "You have the following addresses: n", join("n",@addrs), "n"; http://www.aliencoders.org/ Get IP from ifconfig
  • 39. •Can write DoS exploits •Buffer overflow test •MITM exploits •Fuzzying •Nmap scripts •RFI,RCE exploits •Network Pentesting •Web Attacks automations •Integrate with RE Tools •Data Scrapping and many more http://www.aliencoders.org/ We can do almost everything
  • 42. •Learning Perl by Brian D foy •Programming Perl by Larry Wall •Penetration Testing with Perl Douglas Berdeaux •Network Programming with Perl Lincon D. Stein •Perl for System Administration David Edelman http://www.aliencoders.org/ Books you can read
  • 43. • https://twitter.com/jabra Joshua Abraham • https://twitter.com/weaknetlabs Douglas Berdeaux • https://twitter.com/briandfoy_perl Brian D Foy • https://twitter.com/davorg Dave Cross • https://twitter.com/timtoady Larry Wall • https://twitter.com/merlyn Randal L. Schwartz • https://twitter.com/szabgab Gabor Szabo http://www.aliencoders.org/ People you can follow
  • 45. Website: http://www.aliencoders.org/ Facebook: https://www.facebook.com/aliencoders Slideshare: http://slideshare.net/jassics Twitter: https://twitter.com/aliencoders G+: https://plus.google.com/+Aliencoders/ LinkedIn: https://www.linkedin.com/groups/Alien-Coders-4642371 YouTube: http://www.youtube.com/user/jassics Learning through sharing