Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
itsnebulalol committed Jul 26, 2022
2 parents 6ccf682 + ff523c9 commit de4a792
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 90 deletions.
2 changes: 1 addition & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"context": "..",

// Update the 'dockerFile' property if you aren't using the standard 'Dockerfile' filename.
"dockerFile": "../Dockerfile",
"dockerFile": "../Dockerfile.development",

// Set *default* container specific settings.json values on container create.
"settings": {},
Expand Down
File renamed without changes.
84 changes: 31 additions & 53 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,13 @@
import platform
import argparse
from glob import glob
import time
from subprocess import PIPE, DEVNULL
from getpass import getpass

from utils.copy import Copy
from utils.downloader import DpkgDeb, Ldid
from utils.hash import LdidHash
from utils.installer import Installer

if not (sys.platform == "darwin" and platform.machine().startswith("i")):
from utils.usbmux import USBMux
from paramiko.client import AutoAddPolicy, SSHClient
from paramiko.ssh_exception import AuthenticationException, SSHException, NoValidConnectionsError
from scp import SCPClient
from utils.usbmux import USBMux

""" Functions """

Expand Down Expand Up @@ -331,9 +324,9 @@ def main(args):
copytree(pre_app_path, full_app_path)
print("Changing deb file scripts permissions...")
subprocess.run(
f"chmod 0755 {tmpfolder}/deb/DEBIAN/postrm".split(), stdout=subprocess.DEVNULL)
f"chmod 0755 {tmpfolder}/deb/DEBIAN/postrm".split(), stdout=DEVNULL)
subprocess.run(
f"chmod 0755 {tmpfolder}/deb/DEBIAN/postinst".split(), stdout=subprocess.DEVNULL)
f"chmod 0755 {tmpfolder}/deb/DEBIAN/postinst".split(), stdout=DEVNULL)
if app_executable is not None:
print("Changing app executable permissions...")
exec_path = os.path.join(full_app_path, app_executable)
Expand Down Expand Up @@ -396,7 +389,7 @@ def main(args):
'-Kdata/certificate.p12', '-Upassword', f'{full_app_path}'], stdout=DEVNULL)
else:
subprocess.run("chmod +x ldid".split(),
stdout=subprocess.DEVNULL)
stdout=DEVNULL)
if args.debug:
print(
f"[DEBUG] Running command: ./ldid -S{tmpfolder}/entitlements.plist -M -Kdata/certificate.p12 -Upassword '{full_app_path}'")
Expand All @@ -412,19 +405,15 @@ def main(args):
if file.endswith(".dylib"):
print(f"Signing dylib {file}...")
if ldid_in_path:
if args.debug:
print(
f"[DEBUG] Running command: ldid -Kdata/certificate.p12 -Upassword {frameworks_path}/{file}")

subprocess.run(
['ldid', '-Kdata/certificate.p12', '-Upassword', f'{frameworks_path}/{file}'])
command = 'ldid'
else:
if args.debug:
print(
f"[DEBUG] Running command: ./ldid -Kdata/certificate.p12 -Upassword {frameworks_path}/{file}")
command = './ldid'
if args.debug:
print(
f"[DEBUG] Running command: {command} -Kdev_certificate.p12 -Upassword {frameworks_path}/{file}")

subprocess.run(
['./ldid', '-Kdata/certificate.p12', '-Upassword', f'{frameworks_path}/{file}'])
subprocess.run(
[f'{command}', '-Kdev_certificate.p12', '-Upassword', f'{frameworks_path}/{file}'])

for fpath in glob(frameworks_path + '/*.framework'):
fname = os.path.basename(fpath)
Expand Down Expand Up @@ -460,27 +449,24 @@ def main(args):

# Package the deb file
print("[*] Packaging the deb file...")
out_deb_name = app_name.replace(' ', '')
os.makedirs("output", exist_ok=True)
if Path(f"output/{out_deb_name}.deb").exists():
os.remove(f"output/{out_deb_name}.deb")

global dpkg_cmd
if args.output:
dpkg_cmd = f"dpkg-deb -Zxz --root-owner-group -b {tmpfolder}/deb {args.output}"
path_to_deb = args.output
else:
dpkg_cmd = f"dpkg-deb -Zxz --root-owner-group -b {tmpfolder}/deb output/{out_deb_name}.deb"
path_to_deb = 'output/' + app_name.replace(' ', '') + '.deb'
os.makedirs("output", exist_ok=True)

dpkg_cmd = f"dpkg-deb -Zxz --root-owner-group -b {tmpfolder}/deb {path_to_deb}"

if dpkg_in_path:
if args.debug:
print(f"[DEBUG] Running command: {dpkg_cmd}")

subprocess.run(f"{dpkg_cmd}".split(), stdout=subprocess.DEVNULL)
subprocess.run(f"{dpkg_cmd}".split(), stdout=DEVNULL)
else:
if args.debug:
print(f"[DEBUG] Running command: ./{dpkg_cmd}")

subprocess.run(f"./{dpkg_cmd}".split(), stdout=subprocess.DEVNULL)
subprocess.run(f"./{dpkg_cmd}".split(), stdout=DEVNULL)

is_installed = False
if not args.noinstall:
Expand All @@ -499,7 +485,7 @@ def main(args):
print("Did not find a connected device")
else:
print("Found a connected device")
Installer.install_deb(args, out_deb_name)
Installer.install_deb(args, path_to_deb)
is_installed = True
except ConnectionRefusedError:
print("Did not find a connected device")
Expand All @@ -510,26 +496,22 @@ def main(args):
stdout=PIPE, stderr=PIPE)
if p.returncode == 0 or 'password' in p.stderr.decode():
print("User is in sudoers, using sudo command")
if args.output:
subprocess.run(
f"sudo dpkg -i {args.output}".split(), stdout=PIPE, stderr=PIPE)
else:
subprocess.run(
f"sudo dpkg -i output/{out_deb_name}.deb".split(), stdout=PIPE, stderr=PIPE)
if args.debug:
print(f"[DEBUG] Running command: sudo dpkg -i {path_to_deb}")

subprocess.run(
f"sudo apt-get install -f".split(), stdout=PIPE, stderr=PIPE)
subprocess.run(["sudo", "dpkg", "-i", f"{path_to_deb}"], stdout=PIPE, stderr=PIPE)

subprocess.run(['sudo', 'apt-get', 'install', '-f'], stdout=PIPE, stderr=PIPE)
else:
print("User is not in sudoers, using su instead")
if args.output:
subprocess.run(
f"su root -c 'dpkg -i {args.output}'".split(), stdout=PIPE, stderr=PIPE)
else:
subprocess.run(
f"su root -c 'dpkg -i output/{out_deb_name}.deb'".split(), stdout=PIPE, stderr=PIPE)
if args.debug:
print(f"[DEBUG] Running command: su root -c 'dpkg -i {path_to_deb}")

subprocess.run(
["su", "root", "-c", "'dpkg", "-i", f"{path_to_deb}'"], stdout=PIPE, stderr=PIPE)

subprocess.run(
f"su root -c 'apt-get install -f'".split(), stdout=PIPE, stderr=PIPE)
["su", "root", "-c", "'apt-get install", "-f'"], stdout=PIPE, stderr=PIPE)

# Done!!!
print()
Expand All @@ -542,11 +524,7 @@ def main(args):
print("[*] Copy the newly created deb from the output folder to your jailbroken iDevice and install it!")

print("[*] The app will continue to work when rebooted to stock.")

if args.output:
print(f"[*] Output file: {args.output}")
else:
print(f"[*] Output file: output/{out_deb_name}.deb")
print(f"[*] Output file: {path_to_deb}")


if __name__ == '__main__':
Expand Down
79 changes: 43 additions & 36 deletions utils/installer.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,12 @@

class Installer:

def install_deb(args, out_deb_name):
print(f'[*] Installing {out_deb_name} to the device')
def install_deb(args, path_to_deb):
print(f'[*] Installing {path_to_deb} to the device')
print("Relaying TCP connection")
if args.debug:
print("[DEBUG] Running command: ./utils/tcprelay.py -t 22:2222")

relay = subprocess.Popen(
'./utils/tcprelay.py -t 22:2222'.split(), stdout=DEVNULL, stderr=PIPE)
time.sleep(1)
Expand All @@ -34,58 +35,61 @@ def install_deb(args, out_deb_name):
look_for_keys=False,
compress=True)
with SCPClient(client.get_transport()) as scp:
if args.output:
print(
f"Sending {args.output.split('/')[-1]} to device")
scp.put(f'{args.output}',
remote_path='/var/mobile/Documents')
else:
print(f"Sending {out_deb_name}.deb to device")
scp.put(f'output/{out_deb_name}.deb',
remote_path='/var/mobile/Documents')
print(f"Sending {path_to_deb} to device")
filename = path_to_deb.split("/")[-1]
if args.debug:
print(f"[DEBUG] Copying via scp from {path_to_deb} to /var/mobile/Documents/")

scp.put(f'{path_to_deb}', remote_path='/var/mobile/Documents')
if args.debug:
print(f"[DEBUG] Running command: sudo -nv")

stdin, stdout, stderr = client.exec_command('sudo -nv')
status = stdout.channel.recv_exit_status()
out = stderr.read().decode()

if "password" in out:
print("User is in sudoers, using sudo")
if args.output:
stdin, stdout, stderr = client.exec_command(
f"sudo dpkg -i /var/mobile/Documents/{args.output.split('/')[-1].replace('.deb', '')}.deb",
get_pty=True)
else:
stdin, stdout, stderr = client.exec_command(f'sudo dpkg -i /var/mobile/Documents/{out_deb_name}.deb',
get_pty=True)
password = getpass()
command = f"sudo dpkg -i /var/mobile/Documents/{filename}"
if args.debug:
print(f"[DEBUG] Running command: {command}")

stdin, stdout, stderr = client.exec_command(f"{command}", get_pty=True)
stdin.write(f'{password}\n')
stdin.flush()
print("Installing... this may take some time")
print(stdout.read().decode())

if args.debug:
print(f"[DEBUG] Running command: sudo apt-get install -f")
# for elucubratus bootstrap
streams = client.exec_command('sudo apt -f install', get_pty=True)
streams = client.exec_command('sudo apt-get install -f', get_pty=True)
streams[0].write(f'{password}\n')
streams[0].flush()
print(streams[1].read().decode())
elif status == 0:
print('User has nopasswd set')
if args.output:
output = client.exec_command(f"sudo dpkg -i /var/mobile/Documents/{args.output.split('/')[-1].replace('.deb', '')}.deb")[1]
else:
output = client.exec_command(f'sudo dpkg -i /var/mobile/Documents/{out_deb_name}.deb')[1]
command = f"sudo dpkg -i /var/mobile/Documents/{filename}"
if args.debug:
print(f"[DEBUG] Running command: {command}")

output = client.exec_command(f'{command}')[1]

print("Installing... this may take some time")
print(output.read().decode())
output = client.exec_command('sudo apt -f install')[1].read().decode()
print(output)
if args.debug:
print(f"[DEBUG] Running command: sudo apt-get install -f")

output = client.exec_command('sudo apt-get install -f')[1]
print(output.read().decode())
else:
print('Using su command')
if args.output:
streams = client.exec_command(f"su root -c 'dpkg -i /var/mobile/Documents/{args.output.split('/')[-1].replace('.deb', '')}.deb'",
get_pty=True)
else:
streams = client.exec_command(
f"su root -c 'dpkg -i /var/mobile/Documents/{out_deb_name}.deb'",
get_pty=True)
command = f"su root -c 'dpkg -i /var/mobile/Documents/{filename}'"
if args.debug:
print(f"[DEBUG] Running command: {command}")

streams = client.exec_command(f"{command}", get_pty=True)

output = streams[1].channel.recv(2048).decode()
if "password" in output.lower():
password = getpass()
Expand All @@ -94,15 +98,18 @@ def install_deb(args, out_deb_name):
print("Installing... this may take some time")
print(streams[1].read().decode())
# for elucubratus bootstrap
streams = client.exec_command("su root -c 'apt -f install'", get_pty=True)
streams = client.exec_command("su root -c 'apt-get install -f'", get_pty=True)
streams[0].write(f'{password}\n')
streams[0].flush()
print(streams[1].channel.recv(2048).decode())
else:
print("Installing... this may take some time")
print(streams[1].read().decode())
streams = client.exec_command('sudo apt -f install')
print(streams[1].read().decode())
if args.debug:
print(f"[DEBUG] Running command: sudo apt-get install -f")

output = client.exec_command('sudo apt-get install -f')[1]
print(output.read().decode())
except (SSHException, NoValidConnectionsError, AuthenticationException) as e:
print(e)
finally:
Expand Down

0 comments on commit de4a792

Please sign in to comment.