首页
社区
课程
招聘
未解决 [求助]linux密码存放原理:/etc/shadow
发表于: 2020-6-9 13:36 2783

未解决 [求助]linux密码存放原理:/etc/shadow

2020-6-9 13:36
2783

/etc/shadow存放Linux密码,试了可以通过hashcat暴力破解。但是其中原理不明确,资料中总是一笔带过。
比如,将root密码修改为toor,提取shadow中root用户密码:
$6$wFL5ie31$SPxJGXkinCbd9dOJtvXDJLSMIdSwWBrD5dRBuUlS4jeQ2.oWaTNlNyzn/R2pwBjFkC/Jp8QJW.5pLexwycc7U1

 

6:sha-512
salt:wFL5ie31
passwd-hash:SPxJGXkinCbd9dOJtvXDJLSMIdSwWBrD5dRBuUlS4jeQ2.oWaTNlNyzn/R2pwBjFkC/Jp8QJW.5pLexwycc7U1

 

按照上述意思,salt和toor组合后,使用sha-512运算,就可以得到passwd-hash。
但是salt应如何与toor组合?我试着把salt放在最前面、最后面,算出来都与passwd-hash不同。 使用hashcat,却一下就破解出来了。
请教salt与toor组合原理? 这种资料应该去哪查询呢?


[培训]《安卓高级研修班(网课)》月薪三万计划,掌握调试、分析还原ollvm、vmp的方法,定制art虚拟机自动化脱壳的方法

收藏
免费 1
支持
分享
最新回复 (7)
雪    币: 14983
活跃值: (5285)
能力值: ( LV15,RANK:880 )
在线值:
发帖
回帖
粉丝
2
hashcat 开源,直接看源码https://github.com/hashcat/hashcat
2020-6-9 13:42
0
雪    币: 86
活跃值: (171)
能力值: ( LV2,RANK:15 )
在线值:
发帖
回帖
粉丝
3
obaby hashcat 开源,直接看源码https://github.com/hashcat/hashcat
囧,我不知道怎么才能找到我想看的那部分代码
2020-6-9 13:52
0
雪    币: 14983
活跃值: (5285)
能力值: ( LV15,RANK:880 )
在线值:
发帖
回帖
粉丝
4
兽人永不为奴 囧,我不知道怎么才能找到我想看的那部分代码[em_85]
import hashlib,math

def rstr_sha512(text: bytes) -> bytes:
    sha512 = hashlib.sha512()
    sha512.update(text)
    return sha512.digest()

def _extend(source: bytes, size_ref: int) -> bytes :
    extended = b"";
    for i in range(math.floor(size_ref/64)):
        extended += source;
    extended += source[:size_ref % 64]
    return extended;

def _sha512crypt_intermediate(password: bytes,salt: bytes) -> bytes:
    #digest_a = rstr_sha512(password + salt)
    digest_b = rstr_sha512(password + salt + password)
    digest_b_extended = _extend(digest_b,len(password))
    intermediate_input = password + salt + digest_b_extended
    passwd_len = len(password)
    while passwd_len!=0:
        if passwd_len&1 == 1:
            intermediate_input += digest_b
        else:
            intermediate_input += password
        passwd_len >>= 1
    return rstr_sha512(intermediate_input)

def _sha512crypt(password :bytes,salt :bytes,rounds :int) -> bytes:
    digest_a = _sha512crypt_intermediate(password, salt)
    p = _extend(rstr_sha512(password*len(password)),len(password))
    s = _extend(rstr_sha512(salt*(16+digest_a[0])),len(salt))
    digest = digest_a
    for i in range(rounds):
        c_input = b""
        if i&1 :
            c_input += p
        else:
            c_input += digest
        if i % 3:
            c_input += s
        if i % 7:
            c_input += p
        if i & 1:
            c_input += digest
        else:
            c_input += p
        digest = rstr_sha512(c_input)
    return digest

def sha512crypt(password :bytes,salt :bytes, rounds=5000) -> str:
    salt = salt[:16] # max 16 bytes for salt
    input = _sha512crypt(password, salt, rounds)
    tab = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
    order = [ 42, 21, 0,  1,  43, 22, 23, 2,  44, 45, 24, 3,
              4,  46, 25, 26, 5,  47, 48, 27, 6, 7,  49, 28,
              29, 8,  50, 51, 30, 9, 10, 52, 31, 32, 11, 53,
              54, 33, 12, 13, 55, 34, 35, 14, 56, 57, 36, 15,
              16, 58, 37, 38, 17, 59, 60, 39, 18, 19, 61, 40,
              41, 20, 62, 63]
    output = ""
    for i in range(0,len(input),3):
        # special case for the end of the input
        if i+1 >= len(order): # i == 63
            char_1 = input[order[i+0]] & 0b00111111
            char_2 = (input[order[i+0]] & 0b11000000) >> 6
            output += tab[char_1] + tab[char_2]
        else:
            char_1 = input[order[i+0]] & 0b00111111
            char_2 = (((input[order[i+0]] & 0b11000000) >> 6) |
                       (input[order[i+1]] & 0b00001111) << 2)
            char_3 = (
                ((input[order[i+1]] & 0b11110000) >> 4) | 
                    (input[order[i+2]] & 0b00000011) << 4)
            char_4 = (input[order[i+2]] & 0b11111100) >> 2
            output += tab[char_1] + tab[char_2] + tab[char_3] + tab[char_4]
    if rounds!=5000:
        return "$6$rounds={}${}${}".format(rounds,salt.decode("utf-8"),output)
    else:
        return "$6${}${}".format(salt.decode("utf-8"),output)
        
if __name__ == "__main__":
    print(sha512crypt(b"toor",b"wFL5ie31",5000))

https://www.jianshu.com/p/9da78abd6a96

https://samsclass.info/123/proj10/p12-hashcat.htm

原理看这个,不是单轮sha512

2020-6-9 14:13
1
雪    币: 397
活跃值: (799)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
wsy
5

下载带源码的hashcat,进入opencl目录,找对应的算法编号,看对应的cl文件
不是简单的拼接,过程比较复杂
我写过这个代码,现在手头没有


居然上面有人给出来了,真快。

这问题该到密码算法那里问,标准的密码算法问题啊。省的那里老是弄些无聊的话题扯。

最后于 2020-6-9 14:19 被wsy编辑 ,原因:
2020-6-9 14:13
1
雪    币: 86
活跃值: (171)
能力值: ( LV2,RANK:15 )
在线值:
发帖
回帖
粉丝
6
obaby import&nbsp;hashlib,math def&nbsp;rstr_sha512(text:&nbsp;bytes)&nbsp;-&gt;&am ...
感谢 obaby专家。 我资料检索能力太弱了
2020-6-9 14:22
0
雪    币: 86
活跃值: (171)
能力值: ( LV2,RANK:15 )
在线值:
发帖
回帖
粉丝
7
wsy 下载带源码的hashcat,进入opencl目录,找对应的算法编号,看对应的cl文件不是简单的拼接,过程比较复杂我写过这个代码,现在手头没有居然上面有人给出来了,真快。这问题该到密码算法那里问,标准的 ...
网上查的资料说是简单的拼接,误导我...  。 这下我心里至少不纠结了,感谢wsy大佬
2020-6-9 14:23
0
雪    币: 397
活跃值: (799)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
wsy
8
不用客气。
看上面的代码就知道了,虽然我不知道是啥语言写的。
先拼接做一次,然后作5000次,每次怎么拼还要做三次判断。
2020-6-9 14:56
0
游客
登录 | 注册 方可回帖
返回
//