SQL Injec*on We have men*oned security a few *mes now - - PowerPoint PPT Presentation

sql injec on
SMART_READER_LITE
LIVE PREVIEW

SQL Injec*on We have men*oned security a few *mes now - - PowerPoint PPT Presentation

SQL Injec*on We have men*oned security a few *mes now The most important thing to realize as a Web developer / administrator is that hackers


slide-1
SLIDE 1

SQL ¡Injec*on ¡

  • We ¡have ¡men*oned ¡security ¡a ¡few ¡*mes ¡now ¡
  • The ¡most ¡important ¡thing ¡to ¡realize ¡as ¡a ¡Web ¡

developer ¡/ ¡administrator ¡is ¡that ¡hackers ¡are ¡ always ¡trying ¡/ ¡finding ¡new ¡/ ¡unusual ¡ways ¡to ¡ aCack ¡you ¡

  • Ex: ¡SQL ¡Injec*on ¡(hCp://en.wikipedia.org/wiki/SQL_injec*on) ¡ ¡

– One ¡common ¡use ¡of ¡a ¡DB ¡is ¡to ¡search ¡based ¡on ¡input ¡ from ¡the ¡user ¡

  • Ex: ¡Enter ¡name ¡of ¡person ¡you ¡wish ¡to ¡find ¡

– A ¡dangerous ¡assump*on ¡is ¡that ¡the ¡user ¡will ¡always ¡ enter ¡a ¡legi*mate ¡search ¡string ¡

1 ¡

slide-2
SLIDE 2

SQL ¡Injec*on ¡

  • SQL ¡syntax ¡is ¡such ¡the ¡user ¡can ¡actually ¡enter ¡SQL ¡

code ¡into ¡a ¡search ¡string ¡thereby ¡circumven*ng ¡ the ¡original ¡intent ¡of ¡the ¡query ¡

– In ¡some ¡cases, ¡the ¡user ¡can ¡actually ¡be ¡destruc*ve, ¡ changing ¡the ¡DB ¡itself ¡

  • Ex: ¡Consider ¡the ¡following ¡MySQL ¡query ¡in ¡a ¡PHP ¡

script: ¡

$query = "select * from Movies where Movie_name = '$movie'";

  • Assume ¡$movie ¡was ¡extracted ¡from ¡a ¡POST ¡submission ¡

– The ¡intent ¡is ¡that ¡the ¡user ¡will ¡enter ¡a ¡movie ¡name ¡ – What ¡if ¡the ¡user ¡enters ¡SQL ¡syntax? ¡

2 ¡

slide-3
SLIDE 3

SQL ¡Injec*on ¡

  • In ¡some ¡systems ¡the ¡problem ¡can ¡be ¡much ¡worse, ¡due ¡

to ¡allowance ¡of ¡cascading ¡SQL ¡statements ¡in ¡a ¡query ¡

– Ex ¡user ¡input: ¡

' or '1'; drop table Movies; select * from Movies where '1' = '1

– Oh ¡no! ¡

  • Note ¡that ¡this ¡depends ¡on ¡the ¡user ¡knowing ¡the ¡table ¡name ¡– ¡but ¡

it ¡can ¡o\en ¡be ¡guessed ¡

  • Also ¡it ¡depends ¡on ¡system ¡allowing ¡mul*ple ¡statements ¡in ¡a ¡query ¡

– ¡MySQL ¡does ¡not ¡but ¡some ¡do ¡

– See ¡ex21.php ¡ – hCp://xkcd.com/327/ ¡ ¡ ¡

3 ¡

slide-4
SLIDE 4

4 ¡

Authen*ca*on ¡and ¡Authoriza*on ¡

  • Two ¡important ¡issues ¡related ¡to ¡servers ¡are ¡

authen*ca*on ¡and ¡authoriza*on ¡

– They ¡sound ¡similar ¡but ¡have ¡dis*nct ¡meanings ¡ – Authen*ca*on ¡

  • Determining ¡the ¡iden*ty ¡of ¡the ¡party ¡accessing ¡your ¡

site ¡

– Authoriza*on ¡(access ¡control) ¡

  • Determining ¡what ¡the ¡party ¡accessing ¡your ¡site ¡has ¡

access ¡to ¡

slide-5
SLIDE 5

5 ¡

Authen*ca*on ¡and ¡Authoriza*on ¡

– Authen*ca*on ¡can ¡be ¡done ¡in ¡various ¡ways, ¡using ¡ different ¡mechanisms ¡

  • Can ¡be ¡done ¡directly ¡through ¡the ¡Web ¡Server ¡(ex: ¡

Apache) ¡with ¡the ¡mod_auth ¡module ¡

– Can ¡also ¡be ¡done ¡at ¡the ¡"per ¡directory" ¡level ¡(if ¡enabled) ¡ using ¡.htaccess ¡files ¡

  • Can ¡be ¡done ¡at ¡the ¡applica*on ¡level ¡via ¡scripts ¡(ex: ¡PHP ¡

with ¡MySQL) ¡

– You ¡saw ¡this ¡in ¡ex20.php ¡ – You ¡will ¡also ¡be ¡doing ¡this ¡in ¡Assignment ¡2 ¡ – See: ¡ – hCp://en.wikipedia.org/wiki/Authen*ca*on ¡ ¡

slide-6
SLIDE 6

6 ¡

Authen*ca*on ¡and ¡Authoriza*on ¡

  • Authoriza*on ¡o\en ¡relies ¡on ¡authen*ca*on ¡

– Access ¡to ¡files ¡/ ¡directories ¡is ¡only ¡allowed ¡to ¡ authen*cated ¡users ¡(i.e. ¡those ¡who ¡log ¡in) ¡ – However, ¡authoriza*on ¡(or ¡lack ¡thereof) ¡can ¡also ¡ be ¡determined ¡by ¡the ¡user's ¡IP ¡address ¡or ¡even ¡a ¡ version ¡of ¡so\ware ¡ – Note ¡also ¡that ¡different ¡users ¡can ¡have ¡different ¡ authoriza*on ¡levels ¡to ¡the ¡same ¡site ¡ – See: ¡

  • hCp://en.wikipedia.org/wiki/Authoriza*on ¡ ¡
slide-7
SLIDE 7

HTTPS ¡

  • HTTP ¡

– Hypertext ¡Transfer ¡Protocol ¡ – Requests ¡and ¡responses ¡are ¡sent ¡in ¡plaintext ¡ – For ¡many ¡applica*ons ¡this ¡is ¡unacceptable ¡

  • Online ¡purchases ¡
  • Banking ¡ac*vi*es ¡
  • Anything ¡where ¡a ¡password ¡must ¡be ¡entered ¡by ¡the ¡

user ¡

– For ¡security, ¡we ¡need ¡the ¡communica*on ¡to ¡be ¡ encrypted ¡

7 ¡

slide-8
SLIDE 8

HTTPS ¡

  • HTTPS ¡allows ¡for ¡secure ¡communica*on ¡over ¡

the ¡web ¡

– HyperText ¡Transfer ¡Protocol ¡Secure ¡ – All ¡informa*on ¡sent ¡to ¡the ¡server ¡and ¡received ¡ back ¡by ¡the ¡client ¡is ¡encrypted ¡ – Theore*cally, ¡even ¡if ¡a ¡scofflaw ¡snoops ¡and ¡gets ¡ the ¡data ¡he ¡/ ¡she ¡will ¡not ¡be ¡able ¡to ¡decrypt ¡it ¡ – Without ¡gejng ¡into ¡too ¡much ¡theory, ¡let’s ¡look ¡at ¡ the ¡basic ¡idea ¡

8 ¡

slide-9
SLIDE 9

HTTPS ¡

  • Client ¡requests ¡URL ¡
  • Server ¡is ¡authen*cated ¡via ¡a ¡cer*ficate ¡

– To ¡make ¡sure ¡server ¡is ¡legi*mate ¡ – Typically ¡registered ¡by ¡some ¡cer*fying ¡authority ¡

  • Messages ¡back ¡and ¡forth ¡between ¡server ¡and ¡client ¡are ¡

encrypted ¡using ¡TLS/SSL ¡

– There ¡are ¡a ¡lot ¡of ¡interes*ng ¡technical ¡details ¡about ¡TLS ¡/ ¡ SSL ¡

  • Beyond ¡the ¡scope ¡of ¡this ¡course ¡ ¡
  • HTTPS ¡is ¡actually ¡not ¡itself ¡a ¡new ¡protocol ¡

– Simply ¡HTTP ¡on ¡top ¡of ¡TLS/SSL ¡ – Security ¡relies ¡on ¡security ¡of ¡TLS/SSL ¡

9 ¡

slide-10
SLIDE 10

HTTPS ¡

  • For ¡the ¡most ¡part, ¡HTTPS ¡is ¡secure ¡

– As ¡with ¡most ¡CS ¡so\ware, ¡con*nual ¡upda*ng ¡is ¡ cri*cal ¡ – Ex: ¡

  • In ¡Fall ¡2011 ¡a ¡vulnerability ¡was ¡iden*fied ¡

See: ¡hCp://www.informa*onweek.com/news/security/vulnerabili*es/231601759 ¡ ¡ – Since ¡then ¡major ¡browsers ¡have ¡updated ¡to ¡avoid ¡/ ¡mi*gate ¡ this ¡issue ¡

  • More ¡recently ¡the ¡heartbleed ¡bug ¡was ¡found ¡

– See ¡hCp://en.wikipedia.org/wiki/Heartbleed ¡ ¡ ¡

  • See ¡ex20s.php ¡for ¡simple ¡example ¡
  • For ¡more ¡informa*on ¡see: ¡

– hCp://en.wikipedia.org/wiki/HTTP_Secure ¡ ¡ – hCp://en.wikipedia.org/wiki/Transport_Layer_Security ¡ ¡

10 ¡