1+ # Randomness itself is a give away of exploitation
2+ class MetasploitModule < Msf ::Exploit ::Local
3+ Rank = NormalRanking
4+
5+ include Msf ::Post ::Linux ::System
6+
7+ # TODO get exact apport version after setting up a test environment
8+ # TODO targets in the initialize method and how they work
9+ # TODO other priv esc vectors, startup folders, periodic scripts
10+ # The vunerable version of apport may be available on other systems, distros and versions
11+
12+ def initialize ( info = { } )
13+ super (
14+ update_info (
15+ info ,
16+ 'Name' => 'Ubuntu Xenial Xerus Apport Symlink Hijacking Privilege Escalation ' ,
17+ 'Description' => %q{
18+ On the Ubuntu Xenial Xerus 16.04.7 release the Apport 2.20 crash handler is vulnerable
19+ to symlink injection. Following a crash Apport will write reports to /var/lock/apport/lock,
20+ an attacker who can create a symlink to a privileged directory via /var/lock/apport will be
21+ able to create files with global 0777 permissions. This module exploits this weaknes by writing
22+ payloads to /etc/crontab/ as the root user.
23+
24+ } ,
25+ 'License' => MSF_LICENSE ,
26+ 'Author' => [
27+ 'gardnerapp' # mirageinfosec.cloud
28+ ] ,
29+ 'References' => [
30+ [
31+ 'URL' , 'https://nostarch.com/zero-day' # pg. 59
32+ ]
33+ ] ,
34+ 'Platform' => 'linux' ,
35+ 'Targets' => [
36+ [
37+
38+ ]
39+ ] ,
40+ 'Payload' => {
41+ 'BadChars' => "\x00 "
42+ } ,
43+ 'Privileged' => false ,
44+ 'DisclosureDate' => '' ,
45+ 'DefaultTarget' => 0 ,
46+ 'Notes' => {
47+ 'Stability' => [ CRASH_SAFE ] ,
48+ 'Reliability' => [ REPEATABLE_SESSION ] ,
49+ 'SideEffects' => [ ARTIFACTS_ON_DISK , IOC_IN_LOGS ]
50+ } ,
51+ )
52+ register_options [
53+ OptString . new ( 'Cron Name' , [ true , 'Name of the Crontab file' , Rex ::Text . rand_text_alpha ( rand ( 8 ..12 ) ) ] )
54+ ]
55+ )
56+ end
57+
58+ def check
59+ return CheckCode ::Safe ( 'Platform is not Linux' ) unless session . platform == 'linux'
60+
61+ return CheckCode ::Safe ( 'Target is not Ubuntu' ) unless kernel_version =~ /[uU]buntu/
62+
63+ # Todo check distro version here
64+ # Determine is xenail, and vxenial release version
65+
66+ sys_info = get_sysinfo
67+ puts system_info
68+
69+ distro = sysinfo [ :distro ]
70+ puts distro
71+ version = sysinfo [ :version ]
72+ puts system_info
73+
74+ # Maybe add <||= for the version, need to find out if other kernel versions are vulmerable
75+ if distro != 'Xenial Xerus' || version != '16.04.7'
76+ return CheckCode ::Safe ( 'Target is not the correct Linux distro or kernel version' )
77+ end
78+
79+ # Check apport version
80+ if !command_exists? ( 'apport-cli' )
81+ return CheckCode ::Safe ( 'apport-cli does not appear to be installed or in the $PATH' )
82+ end
83+
84+ apport = cmd_exec ( 'apport-cli --version' ) . to_s
85+
86+ return CheckCode ::Detected ( 'Unable to determine apport version' ) if apport . blank?
87+
88+ version = Rex ::Version . new ( apport . split ( '-' ) . first )
89+
90+ vulnerable = Rex ::Version . new '2.20'
91+ # Were there prior versions of apport which are NOT vulnerableii
92+ # if version < vulnerable return bad
93+ end
94+
95+ def exploit
96+ # Methods for
97+ # symlinking /var/lock/apport to /etc/crontab
98+ # Touching a file to this
99+ # verifying the permissions on the file (root ownership)
100+ # writing payloads
101+ # what type of payloads
102+ end
103+
104+ end
0 commit comments