Python 黑客 --- 001 UNIX口令破解机

python基于crypto实现加密与解密 其中需要指定加密方式为CBC,补码方式为PKCS7,不过以下代码解密后的内容有部分为乱码,有待解决。 阅读详情

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:crypt —— 验证 Unix 口令的函数 阅读详情

相关推荐

Python学习——例题详解1、字符串简单加密和解密

例如:key = ‘zxcvb’,那么第一次循环next(keys)=‘z’,第二次循环next(keys)=‘x’,第三次循环next(keys)=‘c’,第四次循环next(keys)=‘v’,第五次循环next(keys)=‘b’,第六次循环next(keys)=‘z’……给定字符串text作为明文(要加密的原文,同上述A)和key作为密钥(同上述P),使用按位异或循环处理text的每一个字符达到加密效果,结果就是加密后的密文(同上述加密运算结果17);若要在循环中返回多个值,考虑。

fdhjflbj的博客 1574

Python编程--UNIX口令破解机

Python语言的真正优势在于其拥有大量的标准库和第三方库。编写UNIX口令破解机时,需要使用UNIX计算口令hash的crypt()算法。启动Python解释器,看到Python标准库中自己带有crypt库,要计算一个加密的UNIX口令hash,只需要调用函数crypt.crypt(),并将口令喝salt作为参数传递给它。该函数会以字符串形式返回口令的hash。让我们尝试使用crypt()函数快速计算口令的hash。将库导入之后,将口令“egg”与salt“HX”传递给函数。该函数返回口令的hash–字符

Bruce_xiaowei的博客 427

【Python】简单爆破破解

基于python的简单暴力破解

weixin_54799594的博客 2391

python crypto与crypt的区别

python相关学习资料:https://edu.51cto.com/video/4102.htmlhttps://edu.51cto.com/video/1158.htmlhttps://edu.51cto.com/video/3502.htmlPython中Crypto与Crypt的区别及实现指南 作为一名刚入行...

weixin_37072292的博客 598

Python中的Crypt模块实例

通过使用Crypt模块,您可以轻松地进行密码哈希、密码验证和文件加密等操作,以增加数据的安全性。本文将介绍Crypt模块的使用示例,并提供相应的源代码。Crypt模块提供了一些哈希函数,可以将密码转换为哈希值。函数,它接受一个输入文件、一个输出文件和一个密码作为参数。函数读取输入文件的内容,使用Crypt模块对数据进行加密,并将加密后的数据写入输出文件。函数生成的哈希值与用户输入的密码进行比较,以验证密码的正确性。函数将用户输入的密码与存储的哈希值进行比较,以验证密码的正确性。在上述示例中,我们使用。

DevForge的博客 552

【python】一文带你领略,Python中非常强大的加密库--pycryptodome

PyCryptodome是一个强大的Python加密库,它提供了广泛的加密算法支持,包括对称加密、非对称加密、哈希函数和消息认证码等。本文将结合实际案例,详细介绍PyCryptodome的安装、基本概念、使用场景及示例代码,帮助读者理解和使用这一强大的加密工具。

景天科技苑 2664

python使用Crypto库实现加密解密

python使用Crypto库实现加密解密

huaweichenai的博客 9088

攻防实战之Confluence后利用

这边管理员密码是密文加密在数据库中,解不开,因此解决的思路是将管理员用户密码修改为已知明文密码的密文(这边不能直接在数据库中添加字段,关系型数据库在单表中添加一条字段可能会出现问题),登录上后台以后,添加用户并加入管理员组,最后将管理员密码还原。Confluence的后利用主要问题在于在Linux中搭建时,默认是Confluence用户权限,如下图所示,而confluence在linux中是没有写权限的,这也就是为什么有些人发现可以执行命令但是shell写不进去。至此admin的密码被改为了123123。

weixin_39251927的博客 2716

python crypt模块_Python常见加密模块用法分析【MD5,sha,crypt模块】

本文实例讲述了Python常见加密模块用法。分享给大家供大家参考,具体如下:1. md5模块md5.new([arg]) 返回一个md5对象,如果给出参数,则相当于调用了update(arg)md5.update(arg) 用string参数arg更新md5对象md5.digest() 返回16字节的摘要,由传给update的string生成,摘要没有ascii字符md5.hexdigest() ...

weixin_30262217的博客 1048

光猫改桥接后,一根网线搞定IPTV和上网的保姆级教程(附VLAN配置避坑点)

本文详细介绍了光猫改桥接后如何通过单线复用技术实现IPTV和上网功能共存。从VLAN配置原理到具体操作步骤,包括光猫超级管理员权限获取、VLAN绑定设置及路由器IPTV功能配置,提供了全面的保姆级教程。特别针对常见问题如IPTV信号丢失、网速下降等给出了实用解决方案,帮助用户轻松避坑。

weixin_29927965的博客 1803

RandLA-Net复现SemanticKITTI和S3DIS数据集

RandLA-Net复现KITTI和室内数据集

weixin_48845174的博客 4125

python的crypt模块

·crypt属于单向加密,又称为不可逆加密算法,在加密过程中不使用密钥,明文由系统加密处理成密文,密文无法解密。 ·一般适合于验证,在验证过程中,重新输入明文,并经过同样的加密算法处理,得到相同的密文并被系统重新认证。广泛使用于口令加密,如数据库。 ·crypt()接受两个参数,第一个为需要加密的字符串,第二个为盐值(就是加密干扰值,如果没有提供,则默认由PHP自动生成);返回散列后的字符串或

weixin_35640856的博客 9080

wintab开发例程

 タブレットとスタイラスペンを使うと、パソコンに手書きの線を入力できます。筆圧を入力することができるので毛筆のような表現も可能です。ペンの傾きを入力できる機種もあり、アイデア次第で面白いことに使えそうです。  私は昔(94年頃)、WACOMのタブレットを用いたプログラム開発をしたことがあります。当初A3版ほどの大きさのUDというタブレットを使っていて、その後 ArtPad という小さいサイズの

grass168的专栏 3242

python安装Crypto

python安装Crypto

qq_42473596的博客 1万+

KITTI数据集下载及解析

KITTI数据集下载及解析 版本 更新时间 更新内容 作者 1 V 1.0 xxx 完成主体内容 W. Xiao 2 文章目录KITTI Dataset1 简介1.1 数据采集平台1.2 坐标系2 数据解析2.1 image文件2.2 velodyne文件2.3 calib文件2.4 label文件3 KITTI可视...

u013086672的博客 5万+

SCCM实战指南:从零搭建企业级Windows自动化部署平台

本文提供了一份详细的SCCM实战指南,手把手教你从零搭建企业级Windows自动化部署平台。内容涵盖环境规划、AD架构扩展、SQL Server配置、SCCM主站点安装,以及最终实现操作系统镜像的自动化部署,旨在帮助IT管理员彻底告别手动装机,实现高效、规范的Windows设备批量管理。

weixin_29251337的博客 639

深入理解Python密码学:使用PyCrypto库进行加密和解密

本文深入探讨了如何使用PyCrypto库进行基本的加密和解密操作,包括对称和非对称加密、哈希和消息认证码。此外,我们还讨论了关于随机数生成、会话管理和密钥交换的最佳实践。

4.0啊的博客 7243

STM32电机库(ST-MC-Workbench)实战指南——三电阻电流采样电路参数配置详解

本文详细解析了STM32电机库(ST-MC-Workbench)中三电阻电流采样电路的参数配置方法,涵盖电阻选型、放大增益计算、滤波时间优化等关键步骤。通过实战案例和调试技巧,帮助工程师快速掌握电流采样技术,提升电机控制系统的精度与稳定性。特别针对ST-MC-Workbench界面参数设置提供了详细指导。

weixin_29186249的博客 513

crypt模块的使用

crypt模块 crypt模块(只适用于Unix)实现了单向的DES加密,Unix系统使用这个加密算法来储存密码。python标准库中自带有crypt库。要计算一个加密的UNIX口令hash,只需要调用函数crypt.crypt(),并将口令和salt(盐)传递给它。该函数会以字符串形式返回hash。 (本人windows下python环境多次尝试crypt库的导入均以失败告终,遂在linux环境...

weixin_44253823的博客 2600

【软件系统架构】系列四:嵌入式软件-NPU(神经网络处理器)系统及模板

NPU(Neural Processing Unit) 是专门用于人工神经网络推理与训练的处理器,具备高并行、低功耗、低延迟等特点。它是边缘 AI、自动驾驶、智能摄像头、语音识别等场景中的关键硬件。

moton2017的博客 2255

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

python crypt模块_Python的加密模块md5、sha、crypt使用实例

MD5(Message-Digest Algorithm 5) 模块用于计算信息密文(信息摘要),得出一个128位的密文。sha模块跟md5相似,但生成的是160位的签名。使用方法是相同的。如下实例是使用md5的:# /usr/bin/python# -*- coding:utf-8 -*-import base64try:import hashlibhash = hashlib.md5()exc...

weixin_40005330的博客 337

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

Unix/Linux编程:密码加密和用户认证

理论 Unix的口令文件是 /etc/shadow,而且是一个ASCII文件(:分隔) 该口令的相关信息如下: 只有用户登陆名和加密口令是必须的。其他字段控制口令更改频流。 必须root权限才能查看 下面查看用户登录名相关项目 /* * 返回值: 若成功,返回指针;若出错或者达到文件尾端,返回NULL。 **/ struct spwd *getspnam(const char *name); 但是如果想要查看整个口令文件: #include <shadow.h> /* * 说明: gets

OceanStar的博客 1845

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

Unix 密码破解器

对于我来说,武术的非凡之处在于它的简单。简单是最美的,而武术也没有什么特别之处;以无法为有法,以有限为无限,是为武术最高境界。 Unix 密码破解器需要使用 Python 标准库中的 crypt 模块的 crypt() 函数,只需传入密码和盐就能返回对应的哈希密码值。 PS: 需要注意的是:crypt 模块只能在 xNIX 系统中才能使用,在 Windows 系统中会报错。 程序分为两部分...

猎荒者 694

python Crypt加密和解密

from Crypto.Cipher import AES class DeAesCrypt: """ AES-128-CBC 加/解密, Padding ZERO模式 """ def __init__(self, data, key, pad): """ :param data: 加密后的字符串,或者需要加密的字符串 :param key: 随机的16位字符 :param pad: 填充方式 .

标题 2200

Python文件加密库之cryptography使用详解

在现代信息社会中,数据的安全性变得越来越重要。为了保护敏感信息,文件加密技术被广泛应用。Python的cryptography库提供了强大的加密功能,可以轻松实现文件加密和解密。本文将详细介绍如何使用cryptography库进行文件加密,包含具体的示例代码。

Rocky006的博客 1976
上一篇: ROS Learning-006 beginner_Tutorials 编译ROS程序包
下一篇: ROS Learning-007 beginner_Tutorials ROS节点
AoboSir
博客等级 码龄10年 996粉丝 285原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值