Programming For Security
Programming For Security
Alosh Bennett
What is computer security?
Protection of information and property from theft and corruption while allowing it to remain
accessible and productive to the intended users.
~wikipedia
Security applies to
Information
Computer System
A resource is secure if it is
Confidential
Integral
Available
Building a secure application
Packet Sniffing
Using packet sniffing you could listen to the data sent by the system
There could be confidential information like passwords
Packet Sniffing
Man in the Middle
Race Condition
Buffer Overflow
SQL Injection
Cross Site Scripting
Hidden Field Manipulation
Cookie Poisoning
Exploit – Packet Sniffing
In desktop scenario,
Consider a trusted program /bin/ssh
Hacker installs /opt/temp/ssh
Hacker changes environment variable $path to /opt/temp
Invoking ‘ssh’ would now invoke the malicious code along with the password you
give
This exploit uses the delay in a program between verifying input and executing.
You start by passing valid input, but change it in between verification and execution
Consider a script to upload assignments to college server
Script allows only .c files and files lesser than 100 KB in size
You want to bypass the check to upload mp3s and movies
Consider following code, is it safe?
cd to upload_directory
for files in dir
if filename does not end with .c or filesize > 100
print("not a valid assignment file")
exit 1
end loop.
for files in dir
upload file to server
end loop.
UserName Type
S H E R O O G U E S T
UserName Type
S H E R O O L I O N A D M I N
select count(*) from users where username = ‘Sheroo’ and password = ‘topsecret’
select count(*) from users where username = ‘Sheroo’ and password = ‘anything’ or 1=1 –- ’
This sql would work for any username, thereby granting him access to any user account
Exploit – SQL Injection
String userName;
String password;
String sql = “select count(*) from users where username = :1 and password = :2 ”;
sql.bind(1, userName);
Sql.bind(2, password);
Exploit – Cross Site Scripting
XSS tries to execute custom javascript on any website by passing javascript snippets
as data
The website displays this data by adding it into html without verification
Consider the following jsp code
<body>
<br>
<%
String name = request.getParameter("name");
out.println("hello "+name);
%>
<br>
</body>
<body>
<br>
hello Sheroo
<br>
</body>
Exploit – Cross Site Scripting
<body>
<br>
hello = <script type="text/javascript">alert('hacked');</script>
<br>
</body>
Any information displayed in an html form could be edited, including hidden fields
and dropdowns
Consider a college site which allows you to download course material for courses you
have registered
When you log in, there would be a dropdown to select the course.
It is possible to edit and add more options to the dropdown from the browser
If hidden fields are used to store critical information like user_id, they could be edited
as well
http://www.securecoding.org/
http://java.sun.com/security/seccodeguide.html
Slides available at
http://www.aloshbennett.in/weblog/
Thank You