SlideShare a Scribd company logo
Croatian Perl Workshop 2008 USAGE OF PERL IN PENETRATION TESTINGS Vlatko Košturjak, CISSP, CEH, MBCI, LPI, ... IBM / HULK / Zagreb.pm kost monkey linux dot hr
Perl usage in security Usage of Perl in security every day log parsing, system hardening, system monitoring, ... in forensics log/evidence parsing/analyzing in penetration tests network layer testing application layer testing web application testing buffer overflow helpers fuzzing implementing Proof of Concepts (PoC)
Perl in Security World Monitoring mon, nagios, ...  nodewatch, syswatch, ... Sherpa system security configuration tool File Integrity checkers (think: tripwire) ViperDB, Fcheck, Triplight, ... Honeypots rsucker, honeydsum, mydoom.pl, ... ...
Perl in Penetration World Nikto web vulnerability scanner Metasploit <=2.7 exploit framework Metasploit >= 3.0 in Ruby Fuzzled  - fuzzying framework snoopy simple SNMP security scanner NSS, dnswalk, snark (MiTM), ... ...
Simple TCP portscanner perl -MIO::Socket -e 'for($i=1;$i<65536;$i++) { if (my $s=IO::Socket::INET->new(PeerAddr=>$ARGV[0],PeerPort=>$i,Proto =>'tcp')) { print &quot;$i &quot;; close ($s); } } print &quot;\n&quot;;' Yes, I do Perl golfing....  You can too - try to shorten this if you dare :) whitespace optimization excluded
Simple TCP portscanner perl -MIO::Socket -e 'for($i=1;$i<65536;$i++) { if (my $s=IO::Socket::INET->new(PeerAddr=>$ARGV[0],PeerPort=>$i,Proto =>'tcp')) { print &quot;$i &quot;; close ($s); } } print &quot;\n&quot;;'  localhost Example of running port scanner oneliner:
Generating custom packets #!/usr/bin/perl use Net::RawIP; $raw_net = new Net::RawIP({icmp =>{}}); $raw_net -> set( { ip => { saddr => '192.168.1.1', daddr => '192.168.1.15' },  icmp => { type => 8, data => &quot;41414141414141414141414141414141&quot; } } );  $raw_net -> send(1,1000); Example of generating spoofed ICMP packet
Generating custom protocol testers You can layer up what you have... CPAN modules for almost every protocol It has even for really rare and the old ones Perl is old language, you know... :) Even for SSL based ones ...and then write the part which is custom
Easy MiTM ssl_proxy.pl  MiTM Proof of concept  not working well  Wrote MiTM for socket HTTP HTTPS I'll put it somewhere on the web eventually,  mail me if you need it quicker! :)
Buffer overflow helpers not common vulnerability in Perl from theory to practice from discovery to exploitation some of the methods (not only for buffer overflows...) analyzing source analyzing machine code fuzzying reverse engineering patches ...
Generating vulnerable inputs mostly oneliners to check length of buffer of vulnerable program on command line ./vuln –vulnbuf `perl -e 'print ”A”x1000'` enviroment export VULNENV=`perl -e 'print ”A”x1000'` ./vuln network protocol  perl -e 'print &quot;GET /&quot;.&quot;A&quot;x1000; print &quot; HTTP/1.0\r\n\r\n&quot;' | nc www.vuln.host 80
Writing exploits with Perl Metasploit helper (<= 2.7) Helps you in finding length of vulnerable buffer Generate buffer with Perl helper script perl -I lib -e 'use Pex; print Pex::Text::PatternCreate(1090)' Run debugger (gdb, ollydbg, ...), note EIP  run another Perl helper script with EIP sdk/patternOffset.pl 0x68423768 1090 Too easy It's not just fun any more...
Fuzzying Custom fuzzying CPAN modules for almost every protocol You have to use lower protocol in order to fuzz the protocol itself Using existing helpers Fuzlled have some protocol drivers inside have some good logic for fuzzing I recommend Permutations, manglings, ...
Web vulnerabilities Nikto libwhisker libwww WWW::Mechanize Sockets IO::Socket IO::Socket::SSL
Example usage of Mechanize perl -MWWW::Mechanize -e '$_ = shift; ($y, $i) = m#(http://www\.youtube\.com)/watch\?v=(.+)#; $m = WWW::Mechanize->new; ($t = $m->get(&quot;$y/v/$i&quot;)->request->uri) =~ s/.*&t=(.+)/$1/; $m->get(&quot;$y/get_video?video_id=$i&t=$t&quot;, &quot;:content_file&quot; => &quot;$i.flv&quot;)' author: Peteris Krumins Youtube video ripper - oneliner
Web services vulnerabilities XML XML::Simple LibXML SOAP SOAP::Lite XML RPC RPC::XML Custom protocol no problem :)
Example of custom fuzzying
Example of custom fuzzying 2 PERL script doing MiTM Fuzzying each request and response to client/server
Conclusion You don't want to write vulnerable security programs to test other vulnerabilities You have Encase case ;) or fakebo :)) It's hard to write vulnerable program in Perl at least buffer overflow vulnerable there's still input validation (taint?) You don't want to spend months writing proof of concept (PoC) don't use low level :) except if you're learning... or ..whatever :) use high level language like Perl
References http://www.sans.org http://securityfocus.com http://net-security.org http://packetstormsecurity.nl/ http://www.softpanorama.org/Security/perl_sec_scripts.shtml http://metasploit.org http://www.cirt.net/nikto2 http://www.ioactive.com/tools.html http://www.l0t3k.org/security/tools/honeypot/ http://www.catonmat.net/blog/ ...
Croatian Perl Workshop 2008 ? QUESTIONS (and maybe answers) Vlatko Košturjak, CISSP, CEH, MBCI, LPI, ... IBM / HULK / Zagreb.pm kost monkey linux dot hr

More Related Content

PDF
Possibility of arbitrary code execution by Step-Oriented Programming
PDF
Buffer overflow null
PPTX
Buffer overflow
PDF
[Ruxcon Monthly Sydney 2011] Proprietary Protocols Reverse Engineering : Rese...
PPTX
The Offensive Python - Practical Python for Penetration Testing
PDF
Exploit development 101 - Part 1 - Null Singapore
PPTX
Build reliable, traceable, distributed systems with ZeroMQ
PDF
How to find_vulnerability_in_software
Possibility of arbitrary code execution by Step-Oriented Programming
Buffer overflow null
Buffer overflow
[Ruxcon Monthly Sydney 2011] Proprietary Protocols Reverse Engineering : Rese...
The Offensive Python - Practical Python for Penetration Testing
Exploit development 101 - Part 1 - Null Singapore
Build reliable, traceable, distributed systems with ZeroMQ
How to find_vulnerability_in_software

What's hot (20)

PPT
6 buffer overflows
PDF
ZeroMQ with NodeJS
PPTX
Anatomy of a Buffer Overflow Attack
PPTX
08 - Return Oriented Programming, the chosen one
PDF
Defcon 22-colby-moore-patrick-wardle-synack-drop cam
PDF
Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw
PPTX
Vulnerability, exploit to metasploit
PDF
2014 en breaking_av_software_joxeankoret
PPT
Buffer Overflow Attacks
PPTX
Buffer Overflow Demo by Saurabh Sharma
PPTX
Power of linked list
PDF
Zeromq anatomy & jeromq
PDF
Presentation buffer overflow attacks and theircountermeasures
PPTX
Nmap not only a port scanner by ravi rajput comexpo security awareness meet
PDF
sponsorAVAST-VB2014
PDF
SymfonyCon 2017 php7 performances
PDF
100 bugs in Open Source C/C++ projects
PPTX
Vulnerability desing patterns
PPTX
Эксплуатируем неэксплуатируемые уязвимости SAP
PPTX
Search for Vulnerabilities Using Static Code Analysis
6 buffer overflows
ZeroMQ with NodeJS
Anatomy of a Buffer Overflow Attack
08 - Return Oriented Programming, the chosen one
Defcon 22-colby-moore-patrick-wardle-synack-drop cam
Beginner's Guide to the nmap Scripting Engine - Redspin Engineer, David Shaw
Vulnerability, exploit to metasploit
2014 en breaking_av_software_joxeankoret
Buffer Overflow Attacks
Buffer Overflow Demo by Saurabh Sharma
Power of linked list
Zeromq anatomy & jeromq
Presentation buffer overflow attacks and theircountermeasures
Nmap not only a port scanner by ravi rajput comexpo security awareness meet
sponsorAVAST-VB2014
SymfonyCon 2017 php7 performances
100 bugs in Open Source C/C++ projects
Vulnerability desing patterns
Эксплуатируем неэксплуатируемые уязвимости SAP
Search for Vulnerabilities Using Static Code Analysis
Ad

Similar to Perl Usage In Security and Penetration testing (20)

PPTX
Perl basics for pentesters part 2
KEY
Mojo as a_client
PPT
Perl 1997 Perl As A System Glue
ODP
Modern Web Development with Perl
PDF
Programming the Network with Perl 1st Edition Paul Barry
ODP
Introduction to Web Programming with Perl
KEY
Intro to PSGI and Plack
DOCX
Running Head IMPLEMENTING THE LIST AND SEARCH FEATURES IN THE DIS.docx
ODP
Exploiting the newer perl to improve your plugins
PDF
Asynchronous Programming FTW! 2 (with AnyEvent)
KEY
Plack - LPW 2009
PPT
Perlbal Tutorial
PDF
Vorontsov, golovko ssrf attacks and sockets. smorgasbord of vulnerabilities
PDF
DEF CON 24 - workshop - Craig Young - brainwashing embedded systems
ZIP
Web Apps in Perl - HTTP 101
PPTX
PSGI and Plack from first principles
PPTX
programming language interface i.pptx
PDF
Beijing Perl Workshop 2008 Hiveminder Secret Sauce
PPTX
Buffer Overflows Shesh Jun 3 09
Perl basics for pentesters part 2
Mojo as a_client
Perl 1997 Perl As A System Glue
Modern Web Development with Perl
Programming the Network with Perl 1st Edition Paul Barry
Introduction to Web Programming with Perl
Intro to PSGI and Plack
Running Head IMPLEMENTING THE LIST AND SEARCH FEATURES IN THE DIS.docx
Exploiting the newer perl to improve your plugins
Asynchronous Programming FTW! 2 (with AnyEvent)
Plack - LPW 2009
Perlbal Tutorial
Vorontsov, golovko ssrf attacks and sockets. smorgasbord of vulnerabilities
DEF CON 24 - workshop - Craig Young - brainwashing embedded systems
Web Apps in Perl - HTTP 101
PSGI and Plack from first principles
programming language interface i.pptx
Beijing Perl Workshop 2008 Hiveminder Secret Sauce
Buffer Overflows Shesh Jun 3 09
Ad

More from Vlatko Kosturjak (6)

PPTX
Linux Improvements in Memory Corruption Based Protections
PDF
Porting your favourite cmdline tool to Android
ODP
Getting access to Lantronix devices: exploring treasures of 77FEh at Confiden...
ODP
Cryptography implementation weaknesses: based on true story
ODP
Wonderful world of (distributed) SCM or VCS
ODP
Ripping web accessible .git files
Linux Improvements in Memory Corruption Based Protections
Porting your favourite cmdline tool to Android
Getting access to Lantronix devices: exploring treasures of 77FEh at Confiden...
Cryptography implementation weaknesses: based on true story
Wonderful world of (distributed) SCM or VCS
Ripping web accessible .git files

Recently uploaded (20)

PDF
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
PDF
HCSP-Presales-Campus Network Planning and Design V1.0 Training Material-Witho...
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
CIFDAQ's Market Insight: SEC Turns Pro Crypto
PDF
Transforming Manufacturing operations through Intelligent Integrations
PDF
madgavkar20181017ppt McKinsey Presentation.pdf
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
PDF
Modernizing your data center with Dell and AMD
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Big Data Technologies - Introduction.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Advanced Soft Computing BINUS July 2025.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPT
Teaching material agriculture food technology
PPTX
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
HCSP-Presales-Campus Network Planning and Design V1.0 Training Material-Witho...
Dropbox Q2 2025 Financial Results & Investor Presentation
CIFDAQ's Market Insight: SEC Turns Pro Crypto
Transforming Manufacturing operations through Intelligent Integrations
madgavkar20181017ppt McKinsey Presentation.pdf
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Modernizing your data center with Dell and AMD
Chapter 3 Spatial Domain Image Processing.pdf
Understanding_Digital_Forensics_Presentation.pptx
MYSQL Presentation for SQL database connectivity
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Big Data Technologies - Introduction.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Advanced Soft Computing BINUS July 2025.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
The Rise and Fall of 3GPP – Time for a Sabbatical?
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Teaching material agriculture food technology
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....

Perl Usage In Security and Penetration testing

  • 1. Croatian Perl Workshop 2008 USAGE OF PERL IN PENETRATION TESTINGS Vlatko Košturjak, CISSP, CEH, MBCI, LPI, ... IBM / HULK / Zagreb.pm kost monkey linux dot hr
  • 2. Perl usage in security Usage of Perl in security every day log parsing, system hardening, system monitoring, ... in forensics log/evidence parsing/analyzing in penetration tests network layer testing application layer testing web application testing buffer overflow helpers fuzzing implementing Proof of Concepts (PoC)
  • 3. Perl in Security World Monitoring mon, nagios, ... nodewatch, syswatch, ... Sherpa system security configuration tool File Integrity checkers (think: tripwire) ViperDB, Fcheck, Triplight, ... Honeypots rsucker, honeydsum, mydoom.pl, ... ...
  • 4. Perl in Penetration World Nikto web vulnerability scanner Metasploit <=2.7 exploit framework Metasploit >= 3.0 in Ruby Fuzzled - fuzzying framework snoopy simple SNMP security scanner NSS, dnswalk, snark (MiTM), ... ...
  • 5. Simple TCP portscanner perl -MIO::Socket -e 'for($i=1;$i<65536;$i++) { if (my $s=IO::Socket::INET->new(PeerAddr=>$ARGV[0],PeerPort=>$i,Proto =>'tcp')) { print &quot;$i &quot;; close ($s); } } print &quot;\n&quot;;' Yes, I do Perl golfing.... You can too - try to shorten this if you dare :) whitespace optimization excluded
  • 6. Simple TCP portscanner perl -MIO::Socket -e 'for($i=1;$i<65536;$i++) { if (my $s=IO::Socket::INET->new(PeerAddr=>$ARGV[0],PeerPort=>$i,Proto =>'tcp')) { print &quot;$i &quot;; close ($s); } } print &quot;\n&quot;;' localhost Example of running port scanner oneliner:
  • 7. Generating custom packets #!/usr/bin/perl use Net::RawIP; $raw_net = new Net::RawIP({icmp =>{}}); $raw_net -> set( { ip => { saddr => '192.168.1.1', daddr => '192.168.1.15' }, icmp => { type => 8, data => &quot;41414141414141414141414141414141&quot; } } ); $raw_net -> send(1,1000); Example of generating spoofed ICMP packet
  • 8. Generating custom protocol testers You can layer up what you have... CPAN modules for almost every protocol It has even for really rare and the old ones Perl is old language, you know... :) Even for SSL based ones ...and then write the part which is custom
  • 9. Easy MiTM ssl_proxy.pl MiTM Proof of concept not working well Wrote MiTM for socket HTTP HTTPS I'll put it somewhere on the web eventually, mail me if you need it quicker! :)
  • 10. Buffer overflow helpers not common vulnerability in Perl from theory to practice from discovery to exploitation some of the methods (not only for buffer overflows...) analyzing source analyzing machine code fuzzying reverse engineering patches ...
  • 11. Generating vulnerable inputs mostly oneliners to check length of buffer of vulnerable program on command line ./vuln –vulnbuf `perl -e 'print ”A”x1000'` enviroment export VULNENV=`perl -e 'print ”A”x1000'` ./vuln network protocol perl -e 'print &quot;GET /&quot;.&quot;A&quot;x1000; print &quot; HTTP/1.0\r\n\r\n&quot;' | nc www.vuln.host 80
  • 12. Writing exploits with Perl Metasploit helper (<= 2.7) Helps you in finding length of vulnerable buffer Generate buffer with Perl helper script perl -I lib -e 'use Pex; print Pex::Text::PatternCreate(1090)' Run debugger (gdb, ollydbg, ...), note EIP run another Perl helper script with EIP sdk/patternOffset.pl 0x68423768 1090 Too easy It's not just fun any more...
  • 13. Fuzzying Custom fuzzying CPAN modules for almost every protocol You have to use lower protocol in order to fuzz the protocol itself Using existing helpers Fuzlled have some protocol drivers inside have some good logic for fuzzing I recommend Permutations, manglings, ...
  • 14. Web vulnerabilities Nikto libwhisker libwww WWW::Mechanize Sockets IO::Socket IO::Socket::SSL
  • 15. Example usage of Mechanize perl -MWWW::Mechanize -e '$_ = shift; ($y, $i) = m#(http://www\.youtube\.com)/watch\?v=(.+)#; $m = WWW::Mechanize->new; ($t = $m->get(&quot;$y/v/$i&quot;)->request->uri) =~ s/.*&t=(.+)/$1/; $m->get(&quot;$y/get_video?video_id=$i&t=$t&quot;, &quot;:content_file&quot; => &quot;$i.flv&quot;)' author: Peteris Krumins Youtube video ripper - oneliner
  • 16. Web services vulnerabilities XML XML::Simple LibXML SOAP SOAP::Lite XML RPC RPC::XML Custom protocol no problem :)
  • 17. Example of custom fuzzying
  • 18. Example of custom fuzzying 2 PERL script doing MiTM Fuzzying each request and response to client/server
  • 19. Conclusion You don't want to write vulnerable security programs to test other vulnerabilities You have Encase case ;) or fakebo :)) It's hard to write vulnerable program in Perl at least buffer overflow vulnerable there's still input validation (taint?) You don't want to spend months writing proof of concept (PoC) don't use low level :) except if you're learning... or ..whatever :) use high level language like Perl
  • 20. References http://www.sans.org http://securityfocus.com http://net-security.org http://packetstormsecurity.nl/ http://www.softpanorama.org/Security/perl_sec_scripts.shtml http://metasploit.org http://www.cirt.net/nikto2 http://www.ioactive.com/tools.html http://www.l0t3k.org/security/tools/honeypot/ http://www.catonmat.net/blog/ ...
  • 21. Croatian Perl Workshop 2008 ? QUESTIONS (and maybe answers) Vlatko Košturjak, CISSP, CEH, MBCI, LPI, ... IBM / HULK / Zagreb.pm kost monkey linux dot hr