• Python 之 shadow 爆破密码脚本编写


    Linux shadow 爆破脚本

    Linux shadow 爆破初探

    目的是为了明白其shadow爆破原理

    # Linux shadow爆破初探 1
    
    import crypt
    
    #shadow文件中的一条用户数据
    shadow_line = "ghui:$y$j9T$DQ2d2fD138oudY0Xa2wst/$dp/6WvvsTE2l50Iw1l.NvNPTIiJY6lmyB7sygyEj/S3:19618:0:99999:7:::"
    
    print(f"[+] The shadow line is: {shadow_line}")
    
    #  从shadow文件中提取密码密文。
    crypt_text = shadow_line.split(":")[1]
    print(f"[+] The crypt text is: {crypt_text}")
    
    # 从密码密文中,提取盐值
    salt = crypt_text[0:crypt_text.rindex("$")] # rindex("$") 表示最后一次出现 $ 符的位置
    print(f"[+] The salt is: {salt}")
    
    # 从密码字典中,读取密码,假设此时读到的密码为 123456
    password = "123456"
    
    # 把读取的密码与盐值进行加密运算,得到猜测的密码密文
    new_crypt_text = crypt.crypt(password,salt)
    
    # 如果猜测的密码密文与shadow文件中的密码密文一致,说明密码猜对了。
    if new_crypt_text == crypt_text:
        print(f"[+] PASSWORD FOUND: {password}")
    else:
        print(f"[-] PASSWORD NOT FOUND!")
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28

    说明:

    split(“:”)[1] 通过冒号:分隔符对字符串进行切片,并且取第二部分

    ​ **crypt_text.rindex(" " ) ∗ ∗ 函数返回子字符串 ‘ ")** 函数返回子字符串 ` ")函数返回子字符串在字符串变量crypt_text`中最后出现的位置

    image-20230918174600308

    Linux shadow 爆破进阶

    # Linux shadow 爆破 2
    
    from termcolor import colored
    import crypt
    
    shadow_line = "ghui:$y$j9T$DQ2d2fD138oudY0Xa2wst/$dp/6WvvsTE2l50Iw1l.NvNPTIiJY6lmyB7sygyEj/S3:19618:0:99999:7:::"
    
    print(f"[+] The shadow line is: {shadow_line}")
    
    #  从shadow文件中提取密码密文。
    crypt_text = shadow_line.split(":")[1]
    print(f"[+] The crypt text is: {crypt_text}")
    
    # 从密码密文中,提取盐值
    salt = crypt_text[0:crypt_text.rindex("$")] # rindex("$") 表示最后一次出现 $ 符的位置
    print(f"[+] The salt is: {salt}")
    
    # 从密码字典中,读取密码。
    file_path="/home/kali/tools/wordlists/top_password.txt"
    
    with open(file=file_path,mode="r") as f:
        
        for line in f:
            password = line.strip()
            print(f"\r[-] Trying password: {password}",end="")
            
    # 把读取的密码与盐值进行加密运算,得到猜测的密码密文
            new_crypt_text = crypt.crypt(password,salt)
    
    # 如果猜测的密码密文与shadow文件中的密码密文一致,说明密码猜对了。
            if new_crypt_text == crypt_text:
                print(colored(f"\n[+] PASSWORD FOUND: {password}","green"))
                exit()
                
        print(f"[-] PASSWORD NOT FOUND!")
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35

    说明:

    strip() 方法用于移除字符串头尾指定的字符(默认为空格或换行符)

    image-20230918174709373

  • 相关阅读:
    哪个视觉语言模型更优?InstructBLIP、MiniGPT-4?全面评估基准LVLM-eHub告诉你
    图像处理领域之►边缘检测大合集◄【应该是全网仅有的了吧】
    ElasticSearch报错解决
    Devexpress GridControl GridView表中列增加按钮
    java+ssm+springboot医院挂号预约问诊网站系统
    Android Toast居中显示方法二
    巧用 CSS 构建渐变彩色二维码
    10.3 校招 实习 内推 面经
    特殊流&Properties属性集实例遇到的问题及解决方法
    MFC Windows 程序设计[129]之文件拷贝与进度展示
  • 原文地址:https://blog.csdn.net/qq_45953122/article/details/133103948