Mar 24, 2009

Database security

Database security is one of the most effective and major security. I am going to write about MySQL and how to supply security of it because it is most popular database in the world. It is often used with PHP, Java, and etc on the Internet.

If it was installed default, there are some vulnerability. Example: root user doesn't have password, and it is befall able to buffer over attacks, so it means default MySQL database is easy to accessible for attackers.

Security requirements:
In order to achieve the highest possible level of security, the installation and configuration of MySQL should be performed in accordance with the following security requirements:

* MySQL database must be executed in a chrooted environment;
* MySQL processes must run under a unique UID/GID that is not used by any other system process;
* Only local access to MySQL will be allowed;
* MySQL root's account must be protected by a hard to guess password;
* The administrator's account will be renamed;
* Anonymous access to the database (by using the nobody account) must be disabled;
* All sample databases and tables must be removed.

Network security:
As with securing a network, securing a database by looking at the various layers that are involved is an effective approach. Security of databases can be defined as preventing unauthorized or accidental disclosure, alteration, or destruction of data.

Network design incorporates the three layers of a Web application running on different servers, usually set apart by firewalls that have specific rules to only let traffic through to the specific port on a specific server at whichever layer that the user is trying to access:

Internet -> Firewall -> Web -> Firewall -> Application -> Firewall -> Database

Something else that it should demonstrate is that it is very costly to implement such a design because firewalls and servers are not cheap. Oftentimes, a sys admin will choose a compromise, combining the application and database servers. This isn’t ideal from a security perspective; nevertheless, it is a vast improvement over leaving a sensitive database facing the Internet directly.

Access Control:
Access to information contained in the tables must be properly regulated. This can be done with control over direct access to the tables, and also through views. Views and privileges assigned to the views can be created to limit users to only see specified portions of data contained within a table.

In order to fully implement a secure MySQL database, it is necessary to learn the MySQL access control system. There are four privilege levels that apply:

1. Global: these privileges apply to all databases on a server.
2. Database: these privileges apply to all tables in a database.
3. Table: these apply to all columns within a table.
4. Column: these apply to individual columns in a table.

The usage of these commands is varied:

GRANT priv_type [(column_list)] [, priv_type [(column_list)] ...]
ON {tbl_name | * | *.* | db_name.*}
TO user_name [IDENTIFIED BY [PASSWORD] 'password']
[, user_name [IDENTIFIED BY 'password'] ...]
[REQUIRE
NONE |
[{SSL| X509}]
[CIPHER cipher [AND]]
[ISSUER issuer [AND]]
[SUBJECT subject]]
[WITH [GRANT OPTION | MAX_QUERIES_PER_HOUR # |
MAX_UPDATES_PER_HOUR # |
MAX_CONNECTIONS_PER_HOUR #]]

REVOKE priv_type [(column_list)] [, priv_type [(column_list)] ...]
ON {tbl_name | * | *.* | db_name.*}
FROM user_name [, user_name ...]


Role-based authentication should be considered when adding access to any database. Typical roles for access include administrator, user, programmer and operator.

Encryption:
The sensitivity of the data will logically determine the need for the use of encryption. There are a few things to consider when thinking about implementing encryption:

1. Will the data stored in the database need to be encrypted or just the user passwords?
2. Will you need to encrypt the data only in the local instance of the database, or do you need to also encrypt the data in transit?

Many of the standard secure database design principles apply to MySQL. Of course, it has many of its own intricacies that need to be understood and audited carefully before any database is fully implemented. Lastly, it is important to keep in mind that other layers of security apply when hosting a database, such as network and operating system security.

In last, I used some internet resources as http://www.securityfocus.com, MYSQL forum, WikiPedia.

Jun 2, 2008

Tomcat-аас болж азаартсан нь

Би ер нь JAVA болон JSP дээр л програмаа бичдэг. Тэгээд үүнээсээ болоод TOMCAT-ийг л вэб сервер болгож ашгилдаг. Тэгсэн чинь саяхан tomcat маань серверийн IP-г муухай азаартуулдаг байна шдээ. Вэб серверээ би нэг дотоод IP болох A1.A2.A3.A4 гэж давиад түүн дээрээ Real IP болох B1.B2.B3.B4 гэсэн IP-г NAT хийгээд интернэтэд байршуулсан юм. Түүнчлэн DNS дээр CCCC.CC гэсэн домайн хаягийг B гэсэн IP руу зааж өгсөн. Гаднаас орж буй систем уул нь A гэсэн IP-г огт мэдэхгүй харин B гэсэн IP-аар л хандах учиртай шүүдээ. C гэсэн домайнаар хандахаар DNS нь B гэсэн IP-г л зааж өгнө.

Вэб браузераар хандаж байгаа үед энэхүү асуудал бидэнд учрахгүй. Харин элдэв HACKING TECHNOLOGY ашиглаж байгаа хүнд бол гаргаж ирээд байнлээ.

жишээ нь:

telnet cccc.cc 80 гэж ороод
HEAD / HTTP/1.0 эсвэл GET / HTTP/1.0
гээд үз
тэгхэд

HTTP/1.1 302 Moved Temporarily
Location: http://A1.A2.A3.A4/index.jsp
Content-Length: 0
Server: Apache-Coyote/1.1
Connection: close

гээд IP-г маань гаргаад ирэндээ. Өөрөөр хэлбэл http://A1.A2.A3.A4/index.jsp гээд A1.A2.A3.A4 IP маань гараад ирлээ.
Ингээд чи баригдав уу!!!


Энийг яаж сэргийлэх вэ?? За эхлээд гол асуудлаа бичье.

telnet www.yahoo.com 80
GET / HTTP/1.0
гээд үзээрэй. Энэ үед URL огт гарч ирэхгүйгээр www.yahoo.com-ийн үндсэн хуудасны HTML SOURCE код гараад ирнэ.

Яагаад минийхийг азаартуулж байж yahoo-г гаргаж ирэхгүй байна??

Вэб браузер дээр http://www.yahoo.com гээ
д үзья. Тэгсэн чинь хуудас маань зүгээр гарч ирч мөн URL нь http://www.yahoo.com/ гээд байна.
За тэгвэл http://cccc.cc/ гээд үзья. Тэгтэл index.jsp-д байгаа миний хийсэн хуудас маань гараад ирлээ. Харин URL дээр
http://cccc.cc/index.jsp болчихсон байна. Яагаад араас нь index.jsp -ийг залгаад байна.

HTTP/1.1 302 Moved Temporarily
Location: http://A1.A2.A3.A4/index.jsp

Content-Length: 0

Server: Apache-Coyote/1.1

Connection: close


Гээд гарч ирээд байгаа нь автоматаар
http://A1.A2.A3.A4/index.jsp гэсэн хаягруу REDIRECT хийгээд байгаа учраас л миний IP гарч ирээд байгаа юм байна. Энэ нь TOMCAT-ийн онцлог ч юм уу BUG ч юм уу.

Энэ асуудлыг өөрийнхөөрөө шийдсэн минь

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class homePage extends HttpServlet{

public void doGet(HttpServletRequest request,HttpServletResponse response)
throws IOException, ServletException{
response.sendRedirect("http://CCCC.CC/index.jsp");
}
}

гэсэн java servlet бичнэ.
Одоо бичсэн servlet ээ тухайн вэбийн web.xml -д зааж өгнө.

гэсэн бичлэг хийнэ.
Одоо харин хуучин гарж байсанаа дахиад үзье
telnet cccc.cc 80

GET
/ HTTP/1.0


HTTP/1.1 302 Moved Temporarily
Location: http://CCCC.CC/index.jsp

Content-Length: 0

Server: Apache-Coyote/1.1

Connection: close

гээд гараад ирлээ. Эврика болчихлоо.
Одоо яасан. Бас нэг асуудал гарлаа.
Би web.xml дээ servlet-н зааж өгөөгүй болхоор үндсэн / ээр нөгөө зураг (*.jpg, *.gif, etc) болон бусад файл маань гарж ирхээ больчихлоо одоо яах вэ?

:((

Санаа зоволтгүй.
web.xml дээ бүх хэргэлдэг файлын өргөтгөлөө tomcat-н ерөнхий web.xml-д заасан MIME ээр болгохоор заагаад л өгчих.

за одоо боллоо. Яг сайхан ажиллаж чадлаа.

Болойшдээ...

My favorite jokes

JOKE #1
- Do you wanna chat?
- I'm busy.
- Hello, busy. I'm Baldan!...

JOKE #2
Boy: "Daddy? How did I come into this world?"
Dad: "Well, my child, some day I'll have to tell you any way.

Boy:"So why not today? Please!"
Dad: "OK, but listen carefully." "Mom and Dad met each other in a cyber cafe. In the restrooms of that cyber cafe, dad connected to mom. Mom at that time made some downloads from dad's memory stick. When dad finished uploading we discovered we used no firewall. Since it was too late to cancel or delete, nine months later we ended up with a virus."

Nov 20, 2006

TOMCAT дээрх бага зэргийн заль

Hi all

Хүмүүст сонирхолтой байх болов уу гээд TOMCAT дээр ашигладаг жижигхэн залийг сонирхуулья.

Ихэнх хүмүүс *.PHP бол php script, *.ASP or *.ASPX бол visual basic or visual javascript, *.html бол статик вэб хуудас, *.JSP бол java servlet гэж мэддэг шүүдээ. Гэтэл энэ бол ердөө л өнгөц харагдах үзэгдэл шүүдээ.

WEB-INF/WEB.XML

гэж байгаа. Эсвэл огт энэ таг байхгүй байгаа. Харин дээрхийг бага зэрэг өөрчлөөд үзийлдаа.

WEB-INF/WEB.XML
Гэж оруулхад name.php файлын ард талд нь JAVA маань нь name_php.java гэсэн servlet үүсгээд ажилж байх болнодоо.

Энэ бас хөөрхөөн заль юмшүүдээ. Яг үүний нэг том жишээ нь http://web2sms.mobinet.mn/index.php бүүр static вэб хуудас зүгээр dynamic байдлаар ажилуулж болно шүүдээ.

filename.html гэдэг нь статик биш dynamic вэб байж магадгүй л гэсэн үг