博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
linux用户密码生成
阅读量:6654 次
发布时间:2019-06-25

本文共 2832 字,大约阅读时间需要 9 分钟。

linux账户保存在/etc/passwd,密码保存在/etc/shadow。

通过man 5 passwd,man 5 shadow可查看文件中各字段含义。

       encrypted password

           Refer to crypt(3) for details on how this string is interpreted.
密码是通过库函数crypt生成的。

1. 函数

       #define _XOPEN_SOURCE       /* See feature_test_macros(7) */

       #include <unistd.h>
       char *crypt(const char *key, const char *salt);
输入参数:key为密码,salt本意为盐,为增加密码难度,加把盐。salt有新旧两种方式:

key is a user's typed password.       salt  is  a two-character string chosen from the set [a–zA–Z0–9./].  This string is used to perturb       the algorithm in one of 4096 different ways.
The glibc2 version of this function supports additional encryption algorithms.       If salt is a character string starting with the characters "$id$" followed by a  string  terminated       by "$":              $id$salt$encrypted       then  instead  of  using  the  DES  machine, id identifies the encryption method used and this then determines how the rest of the password string is interpreted.  The following values of id are supported:              ID  | Method              ─────────────────────────────────────────────────────────              1   | MD5              2a  | Blowfish (not in mainline glibc; added in some                  | Linux distributions)              5   | SHA-256 (since glibc 2.7)              6   | SHA-512 (since glibc 2.7)       So  $5$salt$encrypted  is  an  SHA-256 encoded password and $6$salt$encrypted is an SHA-512 encoded       one.       "salt" stands for the up to 16 characters following "$id$" in the salt.  The encrypted part of  the password string is the actual computed password.  The size of this string is fixed:       MD5     | 22 characters       SHA-256 | 43 characters       SHA-512 | 86 characters       The  characters in "salt" and "encrypted" are drawn from the set [a–zA–Z0–9./].  In the MD5 and SHA implementations the entire key is significant (instead of only the first 8 bytes in DES).

现在linux都实现的是第二中方式的salt。

2. coding

#define _XOPEN_SOURCE#include 
#include
int main(int argc, char*argv[]){ if(argc != 3){ return 0; } printf("%s==%s==%s==\n", argv[0], argv[1], argv[2]); printf("%s\n", crypt(argv[1], argv[2])); return 0;}

创建test用户,密码test123

test:$6$BJIQmFkQ$TnJMVbBoWvE4fBkJ30iJlQwDLxV3wLaZ8pVqrh7N5m0mTWD.vNdRw/uEs8Wu7IB.sfvzBYZUweM6Rd0M43bm61:17285:0:99999:7:::

程序测试

~$gcc crypt.c -lcrypt~$./a.out test $6$BJIQmFkQ$./a.out==test==$==Segmentation fault (core dumped)~$./a.out test "\$6\$BJIQmFkQ\$"./a.out==test==$6$BJIQmFkQ$==$6$BJIQmFkQ$uIMnVVN/FUac.VGm0Ie6g.gWjIRsE0PSNX8ufDcekvmGZ7PtrLVJbrZTlhYplfyEbonrBYpwvHIWGQx9XxeQG/~$./a.out test "BJIQmFkQ"./a.out==test==BJIQmFkQ==BJp/Gyj8SpEnI ~$./a.out test123 "\$6\$BJIQmFkQ\$" ./a.out==test123==$6$BJIQmFkQ$== $6$BJIQmFkQ$TnJMVbBoWvE4fBkJ30iJlQwDLxV3wLaZ8pVqrh7N5m0mTWD.vNdRw/uEs8Wu7IB.sfvzBYZUweM6Rd0M43bm61

 

转载地址:http://bwxto.baihongyu.com/

你可能感兴趣的文章
关于编程语言的一些认识
查看>>
Linux管理查看工具htop、glances、dstat
查看>>
网页中的代码
查看>>
聊聊手游的那些惊喜与惊吓
查看>>
面试中容易问到的网络编程问题
查看>>
linux根文件系统
查看>>
android的线程和进程
查看>>
为什么用Docker,Docker究竟有什么用呢
查看>>
调侃之VNC
查看>>
Guava学习笔记:Google Guava 类库简介
查看>>
个人网站运维上线——服务器介绍
查看>>
java - mySQL
查看>>
读书---《C++程序设计》[任化敏-编写]
查看>>
浅谈Vue响应式(数组变异方法)
查看>>
2012年网络安全前景几何?
查看>>
【C深度剖析】自实现 strcmp strlen strcpy strcat
查看>>
ThinkPHP 系统常量列表
查看>>
有时候xcode不能debug时
查看>>
小白制作星空字
查看>>
004.使用MSCK命令修复Hive表分区
查看>>