+ All Categories

Slides

Date post: 04-Jul-2015
Category:
Upload: vti
View: 406 times
Download: 0 times
Share this document with a friend
41
Security issues in Perl web apps Viacheslav Tykhanovskyi May 12, 2012
Transcript
Page 1: Slides

Security issues in Perl web apps

Viacheslav Tykhanovskyi

May 12, 2012

Page 2: Slides
Page 3: Slides

Common web security issues

Page 4: Slides

Validate input data!

Page 5: Slides

SQL injections

use DBI;

use DBIx::Class;

use Rose::DB::Object;

use ObjectDB;

Page 6: Slides

XSS

Blind escaping <, >, ’, " and & is not enough!

I Various HTML attributes (href, refresh metatag, ...)

I Not validated JSON response

I Using template variables in JavaScript code

Escape taking context into account.

Page 7: Slides

XSS

Blind escaping <, >, ’, " and & is not enough!

I Various HTML attributes (href, refresh metatag, ...)

I Not validated JSON response

I Using template variables in JavaScript code

Escape taking context into account.

Page 8: Slides

XSS

Blind escaping <, >, ’, " and & is not enough!

I Various HTML attributes (href, refresh metatag, ...)

I Not validated JSON response

I Using template variables in JavaScript code

Escape taking context into account.

Page 9: Slides

XSS

Blind escaping <, >, ’, " and & is not enough!

I Various HTML attributes (href, refresh metatag, ...)

I Not validated JSON response

I Using template variables in JavaScript code

Escape taking context into account.

Page 10: Slides

XSS

Blind escaping <, >, ’, " and & is not enough!

I Various HTML attributes (href, refresh metatag, ...)

I Not validated JSON response

I Using template variables in JavaScript code

Escape taking context into account.

Page 11: Slides

Cookies

I Sign cookies

I XSS preventing is hard. Set HttpOnly cookieflag for better protection.

Page 12: Slides

Cookies

I Sign cookies

I XSS preventing is hard. Set HttpOnly cookieflag for better protection.

Page 13: Slides

CSRF

Plack::Middleware::CSRF

Page 14: Slides

Path traversal

../../../../../../etc/passwd

I Detect ..

I File::Spec->no_upwards(@paths);

Page 15: Slides

Path traversal

../../../../../../etc/passwd

I Detect ..

I File::Spec->no_upwards(@paths);

Page 16: Slides

Path traversal

../../../../../../etc/passwd

I Detect ..

I File::Spec->no_upwards(@paths);

Page 17: Slides

Perl-specific security issues

Page 18: Slides

I No buffer overflow

I Most system commands are embedded

I Written by smart people

Page 19: Slides

I No buffer overflow

I Most system commands are embedded

I Written by smart people

Page 20: Slides

I No buffer overflow

I Most system commands are embedded

I Written by smart people

Page 21: Slides
Page 22: Slides

use strict;

use warnings;

Page 23: Slides

Tainting

-T

Page 24: Slides

sub is_tainted {

return !eval {

eval("#"

. substr(join("", @_), 0, 0)

);

1

};

}

Page 25: Slides

system()

system("program $arg");

vs

system(’program’, $arg);

Page 26: Slides

open()

open my $fh, ">$file";

vs

open my $fh, ’>’, $file;

Page 27: Slides

eval()

eval "require $class";

load_class("Foo;print ’nice feature!’")

Page 28: Slides

eval()

eval "require $class";

load_class("Foo;print ’nice feature!’")

Page 29: Slides

0

\0

$file = "/bin/ls\0 /etc|";

if (-e $file) {

open my $fh, $file;

}

Page 30: Slides

0

\0

$file = "/bin/ls\0 /etc|";

if (-e $file) {

open my $fh, $file;

}

Page 31: Slides

CGI & ARGV

script.pl?foo

...

$app->run(@ARGV);

...

Page 32: Slides

CGI & ARGV

script.pl?foo

...

$app->run(@ARGV);

...

Page 33: Slides

Regular expressions

if ($string =~ m/$user_supplied_re/) {

...

}

vs

if ($string =~ m/\Q$user_supplied_re\E/) {

...

}

Page 34: Slides

Unicode

utf8

vs

UTF-8

Page 35: Slides

rand()

”rand()” is not cryptographically secure

Page 36: Slides

How to make life easier?

I Use modules from CPAN. Many of them aretime-proved

I Google ”OWASP”

I Follow Best PracticesI Use scanners

I nikto http://cirt.net/nikto2I skipfish http://code.google.com/p/skipfish/I w3af http://w3af.sourceforge.net/

Page 37: Slides

How to make life easier?

I Use modules from CPAN. Many of them aretime-proved

I Google ”OWASP”

I Follow Best PracticesI Use scanners

I nikto http://cirt.net/nikto2I skipfish http://code.google.com/p/skipfish/I w3af http://w3af.sourceforge.net/

Page 38: Slides

How to make life easier?

I Use modules from CPAN. Many of them aretime-proved

I Google ”OWASP”

I Follow Best PracticesI Use scanners

I nikto http://cirt.net/nikto2I skipfish http://code.google.com/p/skipfish/I w3af http://w3af.sourceforge.net/

Page 39: Slides

How to make life easier?

I Use modules from CPAN. Many of them aretime-proved

I Google ”OWASP”

I Follow Best Practices

I Use scannersI nikto http://cirt.net/nikto2I skipfish http://code.google.com/p/skipfish/I w3af http://w3af.sourceforge.net/

Page 40: Slides

How to make life easier?

I Use modules from CPAN. Many of them aretime-proved

I Google ”OWASP”

I Follow Best PracticesI Use scanners

I nikto http://cirt.net/nikto2I skipfish http://code.google.com/p/skipfish/I w3af http://w3af.sourceforge.net/

Page 41: Slides

Questions?


Recommended