佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1560|回复: 25

你们是怎样提升系统的保安的?

[复制链接]
发表于 5-4-2007 11:52 PM | 显示全部楼层 |阅读模式
欢迎各位大大一起来分享如何提高系统的保安

希望可以让此帖提高我们一些有关知识
回复

使用道具 举报


ADVERTISEMENT

发表于 6-4-2007 12:00 AM | 显示全部楼层
md5

不错一下
回复

使用道具 举报

 楼主| 发表于 6-4-2007 12:00 AM | 显示全部楼层
让我先开始,

我就以系统的最前(Login Window)开始

如果系统有Login的,
我个人认为当User输入错的Password时最好不要用MessageBox来Prompt

因为如果遇到Hacker,会很容易被Trace到,
一两分钟就可以轻而易举的Crack掉Login Window了

比如如果User输入错的Password时系统会Prompt "Invalid Password"之类的
只要在Debugger里寻找"Invalid Password"就可以轻易跳过Password Check了

给个例子:


只要NOP掉00401C7E那一行,就可以跳过了
(我不是在教你们如何破解,只是在提意见如何防止你们的系统被破解,请不要滥用)

[ 本帖最后由 hcong85 于 6-4-2007 12:16 AM 编辑 ]
回复

使用道具 举报

 楼主| 发表于 6-4-2007 12:10 AM | 显示全部楼层
原帖由 红发 于 6-4-2007 12:00 AM 发表
md5

不错一下


怎样用?可不可以给例子啊?
回复

使用道具 举报

 楼主| 发表于 6-4-2007 10:12 PM | 显示全部楼层
接下来要和大家分享的是我如何存密码在Database里


当我一开始学Database时,
我是以Plane Text直接存放在Database里.



后来在老师口中得知 XOR 可以用来做Encryption
于是就开始研究如何Encrypt密码
终于我用 XOR 成功写出Encrypt和Decrypt的Functions

Encrypt 是把密码加入"rivate Key" Encrypt成一个Random的String(当然每次Encrypt出来的都不一样,不然很容易就被人家Decrypt去了)

Decrypt 则是把Encrypt出来的Random String加入用来Encrypt的"rivate Key" Decrypt回原来的密码
学会了Encryption,当然要把它运用在系统里以提高保安啦
在学院的Project里就用了这一招,可惜只得了一个 A-


最近又在佳礼看到exiang大哥说MD5是one way hash code,
很感谢他的那句话教会了我新的存密码的方法
对以前的我来说,CRC32, MD5 之类的东东只是用来测试Data或File有没有被改过或是损坏
现在又多学了一招,
就是把密码算出MD5再存进Database里,
然后每当用户输入密码时我再把他输入的密码算出MD5再和Database里的MD5做比较
这样做会避免了密码被Decrypt,因为MD5是one way hash code,
即使密码的Database被人偷了,他们也那不到密码
即使系统是我们写的,我们也没有办法读取密码.(提高了用户的安心)

今天先分享到这里
如果我有那里说错了记得要纠正我哦
小弟在次先谢过大家用心看我写的帖子

如果有更好的方法也欢迎进来分享

[ 本帖最后由 hcong85 于 7-4-2007 11:20 PM 编辑 ]
回复

使用道具 举报

发表于 7-4-2007 10:54 AM | 显示全部楼层
你看看这个,你可以用这个网页来decrypt MD5

http://www.md5encryption.com/
回复

使用道具 举报

Follow Us
 楼主| 发表于 7-4-2007 06:06 PM | 显示全部楼层
原帖由 max5007 于 7-4-2007 10:54 AM 发表
你看看这个,你可以用这个网页来decrypt MD5

http://www.md5encryption.com/


一开始还真被max大哥你的回复给吓到了,

还好Decrypt不是真的

Enter a word to encrypt MD5 and encrypt SHA1 hashes. Or enter a MD5 hash or SHA1 hash and we will look into our database and try to decrypt MD5 or decrypt SHA1. Basically it is an MD5 encrypter, MD5 decrypter, SHA1 encrypter, and SHA1 decrypter all in one.


max大哥请看红色的字
他们只是把你在那边Encrypt的放在他们的Database
当你要Decrypt时才在他们的Database里找

如果你自己写Program来Encrypt,在那边就不能Decrypt了
除非你Encrypt的String在那边有人Encrypt过
回复

使用道具 举报

发表于 7-4-2007 06:36 PM | 显示全部楼层
encrypt 的方法有很多, 看看 Cryptography 就懂了

什么 Hash-Algorithm (就像楼上提到的 MD5), 什么 Checksum-Algorithm (就像楼上提到的 XOR),
什么 Encryption-Algorithm 等等

我看过一个软件是用打字的速度来 generate code
然后要 decrypt 那些 code 才能进
回复

使用道具 举报


ADVERTISEMENT

发表于 7-4-2007 08:04 PM | 显示全部楼层
好久没有来,一上来就看到有意思的讨论
回楼主,虽然不是破解,
不过中国的数学教授已经破解了 MD5,虽然不可逆转得到原文,
不过却可以以短时间找到“碰撞”
所以在 DB 内存放密码的 MD5 也是不可靠的了,因为可以找到符合的“配对”。
加上目前的处理机越来越快,穷举法
逆转也不是不可能的了。

不过还是需要基于系统的需要吧?
用尽全马的电脑来
逆转破解一个小网站的一个小账户,纯开心,没用呀


详细的小章鱼就不怎么了解了,想知道更多,在网上搜搜王小云应该可以找到不少。


不过小章鱼更喜欢压缩技术,不知那位可以开帖一起研究
研究
回复

使用道具 举报

发表于 7-4-2007 08:15 PM | 显示全部楼层
我在想如果我不放password。

那样人家不就是猜不到

回复

使用道具 举报

发表于 7-4-2007 08:57 PM | 显示全部楼层
原帖由 红发 于 7-4-2007 08:15 PM 发表
我在想如果我不放password。

那样人家不就是猜不到



以无招胜有招
高招高招
回复

使用道具 举报

 楼主| 发表于 7-4-2007 10:11 PM | 显示全部楼层
原帖由 sson 于 7-4-2007 08:04 PM 发表
不过却可以以短时间找到“碰撞”
所以在 DB 内存放密码的 MD5 也是不可靠的了,因为可以找到符合的“配对”。
加上目前的处理机越来越快,穷举法逆转也不是不可能的了。


其实我也有想过会“碰撞”
http://en.wikipedia.org/wiki/MD5
因为不关你算多大的资料,算出来的结果都差不多32Bytes左右而已,
32MB的Combination数量怎么说也多过32B吧(句个Example而已 )
所以碰撞是必然的,
所以我就帖在这里讨论,希望可以借机学到跟好的存放密码的方法


原帖由 sson 于 7-4-2007 08:04 PM 发表
不过小章鱼更喜欢压缩技术,不知那位可以开帖一起研究研究


压缩技术我也有兴趣有空来交流交流
我在想如果把压缩技术当Encryption用有没有可能啊
就是说把密码用自己的验算方法压缩后存放在DB里
安全又省位,
想就容易,做就...


原帖由 红发 于 7-4-2007 08:15 PM 发表
我在想如果我不放password。

那样人家不就是猜不到


酱人家果然是猜不到也,

不过,也不用猜了,没有密码,就是说不用密码也能进了

[ 本帖最后由 hcong85 于 7-4-2007 10:14 PM 编辑 ]
回复

使用道具 举报

发表于 7-4-2007 10:58 PM | 显示全部楼层
我除了密码之外,其他重要数据都不会用MD5^^
我是用几个encrypt的方法加起来一起encrypt,当然你要记住那顺序和你的private key^^
回复

使用道具 举报

发表于 8-4-2007 12:26 AM | 显示全部楼层
原帖由 max5007 于 7-4-2007 10:58 PM 发表
我除了密码之外,其他重要数据都不会用MD5^^
我是用几个encrypt的方法加起来一起encrypt,当然你要记住那顺序和你的private key^^


md5 两次

hacker可能不知道
回复

使用道具 举报

发表于 8-4-2007 12:29 AM | 显示全部楼层
原帖由 hcong85 于 7-4-2007 10:11 PM 发表

酱人家果然是猜不到也,

不过,也不用猜了,没有密码,就是说不用密码也能进了


问题是,就是有人会放password下去

而且,他又那里知道你有放密码呢??
回复

使用道具 举报

 楼主| 发表于 8-4-2007 01:34 AM | 显示全部楼层
原帖由 红发 于 8-4-2007 12:26 AM 发表


md5 两次

hacker可能不知道


如果是要"碰撞",MD5几次都没用,只能限制他们Login的次数,三次不对就停5分钟.




原帖由 红发 于 8-4-2007 12:29 AM 发表


问题是,就是有人会放password下去

而且,他又那里知道你有放密码呢??


攻心计,果然高招
回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 8-4-2007 01:36 AM | 显示全部楼层
原帖由 max5007 于 7-4-2007 10:58 PM 发表
我除了密码之外,其他重要数据都不会用MD5^^
我是用几个encrypt的方法加起来一起encrypt,当然你要记住那顺序和你的private key^^


其他重要数据不用MD5是不是因为不能Decrypt啊??
回复

使用道具 举报

发表于 8-4-2007 09:06 AM | 显示全部楼层
原帖由 hcong85 于 7-4-2007 10:11 PM 发表


其实我也有想过会“碰撞”
http://en.wikipedia.org/wiki/MD5
因为不关你算多大的资料,算出来的结果都差不多32Bytes左右而已,
32MB的Combination数量怎么说也多过32B吧(句个Example而已 )
所以碰撞 ...

你可以加一些盐.... salted password。这里有一段java代码,可以参考一下
基本上,代码里一共重复digest了1000次,最后还用base64把hashedpassword和salt存到db里。


  1. package org.psafix.memopwd;

  2. import java.security.MessageDigest;
  3. import java.security.NoSuchAlgorithmException;
  4. import java.io.IOException;
  5. import sun.misc.BASE64Decoder;
  6. import sun.misc.BASE64Encoder;
  7. import java.sql.*;
  8. import java.util.Arrays;
  9. import java.security.SecureRandom;

  10. public class Owasp {
  11.    private final static int ITERATION_NUMBER = 1000;

  12.    public Owasp() {
  13.    }

  14.    /**
  15.     * Authenticates the user with a given login and password
  16.     * If password and/or login is null then always returns false.
  17.     * If the user does not exist in the database returns false.
  18.     * @param con Connection An open connection to a databse
  19.     * @param login String The login of the user
  20.     * @param password String The password of the user
  21.     * @return boolean Returns true if the user is authenticated, false otherwise
  22.     * @throws SQLException If the database is inconsistent or unavailable (
  23.     *           (Two users with the same login, salt or digested password altered etc.)
  24.     * @throws NoSuchAlgorithmException If the algorithm SHA-1 is not supported by the JVM
  25.     */
  26.    public boolean authenticate(Connection con, String login, String password)
  27.            throws SQLException, NoSuchAlgorithmException{
  28.        boolean authenticated=false;
  29.        PreparedStatement ps = null;
  30.        ResultSet rs = null;
  31.        try {
  32.            boolean userExist = true;
  33.            // INPUT VALIDATION
  34.            if (login==null||password==null){
  35.                // TIME RESISTANT ATTACK
  36.                // Computation time is equal to the time needed by a legitimate user
  37.                userExist = false;
  38.                login="";
  39.                password="";
  40.            }

  41.            ps = con.prepareStatement("SELECT PASSWORD, SALT FROM CREDENTIAL WHERE LOGIN = ?");
  42.            ps.setString(1, login);
  43.            rs = ps.executeQuery();
  44.            String digest, salt;
  45.            if (rs.next()) {
  46.                digest = rs.getString("PASSWORD");
  47.                salt = rs.getString("SALT");
  48.                // DATABASE VALIDATION
  49.                if (digest == null || salt == null) {
  50.                    throw new SQLException("Database inconsistant Salt or Digested Password altered");
  51.                }
  52.                if (rs.next()) { // Should not append, because login is the primary key
  53.                    throw new SQLException("Database inconsistent two CREDENTIALS with the same LOGIN");
  54.                }
  55.            } else { // TIME RESISTANT ATTACK (Even if the user does not exist the
  56.                // Computation time is equal to the time needed for a legitimate user
  57.                digest = "000000000000000000000000000=";
  58.                salt = "00000000000=";
  59.                userExist = false;
  60.            }

  61.            byte[] bDigest = base64ToByte(digest);
  62.            byte[] bSalt = base64ToByte(salt);

  63.            // Compute the new DIGEST
  64.            byte[] proposedDigest = getHash(ITERATION_NUMBER, password, bSalt);

  65.            return Arrays.equals(proposedDigest, bDigest) && userExist;
  66.        } catch (IOException ex){
  67.            throw new SQLException("Database inconsistant Salt or Digested Password altered");
  68.        }
  69.        finally{
  70.            close(rs);
  71.            close(ps);
  72.        }
  73.    }



  74.    /**
  75.     * Inserts a new user in the database
  76.     * @param con Connection An open connection to a databse
  77.     * @param login String The login of the user
  78.     * @param password String The password of the user
  79.     * @return boolean Returns true if the login and password are ok (not null and length(login)<=100
  80.     * @throws SQLException If the database is unavailable
  81.     * @throws NoSuchAlgorithmException If the algorithm SHA-1 or the SecureRandom is not supported by the JVM
  82.     */
  83.    public boolean createUser(Connection con, String login, String password)
  84.            throws SQLException, NoSuchAlgorithmException
  85.    {
  86.        PreparedStatement ps = null;
  87.        try {
  88.            if (login!=null&&password!=null&&login.length()<=100){
  89.                // Uses a secure Random not a simple Random
  90.                SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
  91.                // Salt generation 64 bits long
  92.                byte[] bSalt = new byte[8];
  93.                random.nextBytes(bSalt);
  94.                // Digest computation
  95.                byte[] bDigest = getHash(ITERATION_NUMBER,password,bSalt);
  96.                String sDigest = byteToBase64(bDigest);
  97.                String sSalt = byteToBase64(bSalt);

  98.                ps = con.prepareStatement("INSERT INTO CREDENTIAL (LOGIN, PASSWORD, SALT) VALUES (?,?,?)");
  99.                ps.setString(1,login);
  100.                ps.setString(2,sDigest);
  101.                ps.setString(3,sSalt);
  102.                ps.executeUpdate();
  103.                return true;
  104.            } else {
  105.                return false;
  106.            }
  107.        } finally {
  108.            close(ps);
  109.        }
  110.    }


  111.    /**
  112.     * From a password, a number of iterations and a salt,
  113.     * returns the corresponding digest
  114.     * @param iterationNb int The number of iterations of the algorithm
  115.     * @param password String The password to encrypt
  116.     * @param salt byte[] The salt
  117.     * @return byte[] The digested password
  118.     * @throws NoSuchAlgorithmException If the algorithm doesn't exist
  119.     */
  120.    public byte[] getHash(int iterationNb, String password, byte[] salt) throws NoSuchAlgorithmException {
  121.        MessageDigest digest = MessageDigest.getInstance("SHA-1");
  122.        digest.reset();
  123.        digest.update(salt);
  124.        byte[] input = digest.digest(password.getBytes());
  125.        for (int i = 0; i < iterationNb; i++) {
  126.            digest.reset();
  127.            input = digest.digest(input);
  128.        }
  129.        return input;
  130.    }


  131.    public void creerTable(Connection con) throws SQLException{
  132.        Statement st = null;
  133.        try {
  134.            st = con.createStatement();
  135.            st.execute("CREATE TABLE CREDENTIAL (LOGIN VARCHAR(100) PRIMARY KEY, PASSWORD VARCHAR(32) NOT NULL, SALT VARCHAR(32) NOT NULL)");
  136.        } finally {
  137.            close(st);
  138.        }
  139.    }



  140.    /**
  141.     * Closes the current statement
  142.     * @param ps Statement
  143.     */
  144.    public void close(Statement ps) {
  145.        if (ps!=null){
  146.            try {
  147.                ps.close();
  148.            } catch (SQLException ignore) {
  149.            }
  150.        }
  151.    }

  152.    /**
  153.     * Closes the current resultset
  154.     * @param ps Statement
  155.     */
  156.    public void close(ResultSet rs) {
  157.        if (rs!=null){
  158.            try {
  159.                rs.close();
  160.            } catch (SQLException ignore) {
  161.            }
  162.        }
  163.    }


  164.    /**
  165.     * From a base 64 representation, returns the corresponding byte[]
  166.     * @param data String The base64 representation
  167.     * @return byte[]
  168.     * @throws IOException
  169.     */
  170.    public static byte[] base64ToByte(String data) throws IOException {
  171.        BASE64Decoder decoder = new BASE64Decoder();
  172.        return decoder.decodeBuffer(data);
  173.    }

  174.    /**
  175.     * From a byte[] returns a base 64 representation
  176.     * @param data byte[]
  177.     * @return String
  178.     * @throws IOException
  179.     */
  180.    public static String byteToBase64(byte[] data){
  181.        BASE64Encoder endecoder = new BASE64Encoder();
  182.        return endecoder.encode(data);
  183.    }
  184. }

复制代码


回复

使用道具 举报

 楼主| 发表于 8-4-2007 02:20 PM | 显示全部楼层
原帖由 苦瓜汤 于 8-4-2007 09:06 AM 发表

你可以加一些盐.... salted password。这里有一段java代码,可以参考一下
基本上,代码里一共重复digest了1000次,最后还用base64把hashedpassword和salt存到db里。


package org.psafix.memopwd;

...


好长的代码,看不懂,Java我只学了Basic吧了

可以解释一下吗??
回复

使用道具 举报

发表于 10-4-2007 07:34 PM | 显示全部楼层
原帖由 hcong85 于 8-4-2007 02:20 PM 发表


好长的代码,看不懂,Java我只学了Basic吧了

可以解释一下吗??

salt是一组随机生成的bytes,在把password hash之前,在password中加入这组bytes就可以防止以上所提到的rainbow table核对密码。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 13-9-2025 05:10 PM , Processed in 0.147288 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表