SQL Injec Ons: Security 2012 João Paulo Barraca
SQL Injec Ons: Security 2012 João Paulo Barraca
Injec*ons
Security
2012
João
Paulo
Barraca
jpbarraca@ua.pt
Current
Web
Environment
• Current
“web
pages”
are
really
web
applica*ons
– Front
end
which
may
run
in
browser
– Server
provides
execu*on
environment
– Backend
which
provides
services
– Database
for
persistent
storage
• Interfaces
connect
the
different
subsystems
– E.g.
HTTP,
REST,
WebSocket,
SQL,
etc..
• Mul*ple
technologies
and
languages
used
– E.g.
Javascript,
PHP,
HTML,
CSS
Current
Web
Environment
hUp://assets.devx.com/ar*clefigs/17059.jpg
SQL
Injec*on:
Bypass
Simple
Password
• Form
data
is
used
to
create
an
SQL
statement
– Without
valida*on!
– SQL
code
in
form
can
be
injected
• SQL
Statement
is
valid
and
always
returns
1
row
if
the
user
exists.
It
is
also
possible
to
find
username.
SQL
Injec*on:
Bypass
Simple
Password
SQL
Injec*on:
Bypass
Complex
Passwords
• SQL
can
store
passwords
in
a
ciphered
format
– Uses
the
PASSWORD
func*on
– Password
stored
in
database
cannot
be
obtained
• Parameter binding:!
– $s->bind_param(“s”,$login);!
– $s->bind_param(“i”,$password);!
• Query
execu*on
– $s-‐>execute();
Mi*ga*on:
Others
• Limit
data
permissions
according
to
user
needs
– Do
not
grant
DROP,
or
Write
methods
for
read
only
applica*on
• Use
stored
procedures
• Isolate
servers
to
reduce
compromise
of
neighbor
hosts
• Configure
error
repor*ng
appropriately
– Detailed
error
repor*ng
for
developers
– Limited
error
repor*ng
for
users