diff --git a/README.md b/README.md index b16d36a..6583063 100644 --- a/README.md +++ b/README.md @@ -212,7 +212,7 @@ let sum = nums.reduce(fn(acc, val) { return acc + val; }, 0); # 21 --- ## 📦 Standard Library Modules -> 📚 **Detailed Documentation:** For complete syntax, parameters, and examples for all 14 built-in modules, visit the [**Modules Catalog (`modules/`)**](./modules/README.md). +> 📚 **Detailed Documentation:** For complete syntax, parameters, and examples for all 15 built-in modules, visit the [**Modules Catalog (`modules/`)**](./modules/README.md). ### 🤖 Universal AI Integration Engine (`ai`) Directly integrate Generative AI from ANY provider in the world natively in AiraLang (OpenAI, DeepSeek, Anthropic Claude, Google Gemini, Groq, OpenRouter, Mistral, Ollama, Perplexity, Cerebras, or custom servers): @@ -235,6 +235,26 @@ say ai.ask("Local offline AI query"); ai.set_endpoint("http://localhost:8000/v1/chat/completions", "token", "my-model"); ``` +### 📱 Native Android Security & Inspection Engine (`android` / `droidsec`) +Engineered natively for mobile penetration testing, device hardening, and zero-dependency static APK security auditing directly on Termux & Android: +```aira +import "android"; + +# 1. Device Security Posture Audit (Root, Bootloader, AVB, Score) +let dev = android.device_info(); +let audit = android.audit_device(); +say "Device: " + dev.brand + " " + dev.model; +say "Security Score: " + audit.security_score + "/100"; +say "Device Posture: " + audit.posture; + +# 2. High-Speed Static APK Security Auditor +let report = android.audit_apk("/sdcard/Download/target.apk"); +say "Package: " + report.package_name; +say "Risk Level: " + report.risk_level; +say "Dangerous Permissions: " + report.dangerous_permissions; +say "Exposed Keys: " + report.hardcoded_secrets; +``` + ### 💖 Cyber-Romance & Proposal Engine (`proposal`) Interactive proposal prank module with automated HTTP 500 server love timeout loop and Lover Accept Checker AI: ```aira diff --git a/modules/README.md b/modules/README.md index 4bbb8b3..363990a 100644 --- a/modules/README.md +++ b/modules/README.md @@ -5,7 +5,7 @@ --- ## 🌟 Overview -AiraLang features 14 built-in standard library modules engineered natively for speed, AI capabilities, cyber security recon, system operations, and developer joy. +AiraLang features 15 built-in standard library modules engineered natively for speed, AI capabilities, cyber security recon, system operations, and developer joy. All modules are loaded natively via the `import` statement: ```aira @@ -19,19 +19,20 @@ import ""; | # | Module | Category | Primary Purpose | Key Methods | |---|---|---|---|---| | 1 | [`ai`](./ai.md) | Artificial Intelligence | Universal LLM engine (OpenAI, DeepSeek, Claude, Gemini, Groq, Ollama, OpenRouter, etc.) | `ask()`, `set_provider()`, `set_endpoint()`, `set_key()`, `providers()` | -| 2 | [`proposal`](./proposal.md) | Fun & Cyber-Prank | Automated HTTP 500 love timeout & AI sentiment checker | `ask()`, `set_key()`, `set_system()`, `wish()`, `set_wish()` | +| 2 | [`android`](./android.md) / `droidsec` | Mobile Security & Recon | Android device integrity audit, root detection, and static APK security analyzer | `device_info()`, `audit_device()`, `audit_apk()`, `audit_package()`, `check_root()` | | 3 | [`sec`](./sec.md) | Cybersecurity | Port scanning, header auditing, subdomain discovery | `scan_ports()`, `audit_headers()`, `subdomains()`, `crack_md5()` | -| 4 | [`http`](./http.md) | Networking | Web requests, REST APIs, and file downloads | `get()`, `post()`, `download()`, `status()` | -| 5 | [`file`](./file.md) | System I/O | Read, write, append, and inspect local files | `read()`, `write()`, `append()`, `exists()`, `delete()` | -| 6 | [`os`](./os.md) | System | Shell commands, environment variables, directories | `cmd()`, `env()`, `cwd()`, `listdir()`, `mkdir()`, `platform()` | -| 7 | [`math`](./math.md) | Mathematics | Math functions, trigonometry, and constants | `sqrt()`, `pow()`, `abs()`, `random()`, `round()`, `pi`, `e` | -| 8 | [`time`](./time.md) | System | Epoch time, timestamps, and execution delays | `now()`, `time()`, `sleep()` | -| 9 | [`json`](./json.md) | Data | Parsing and serialization of JSON payloads | `parse()`, `stringify()`, `mkstring()` | -| 10 | [`crypto`](./crypto.md) | Security | Cryptographic hashes and encoding utilities | `md5()`, `sha256()`, `sha1()`, `base64_encode()`, `base64_decode()` | -| 11 | [`string`](./string.md) | Utilities | Advanced text manipulation and transformation | `split()`, `replace()`, `upper()`, `lower()`, `trim()`, `join()` | -| 12 | [`sqlite`](./sqlite.md) | Database | Lightweight embedded SQL relational database | `open()`, `query()`, `execute()`, `close()` | -| 13 | [`net`](./net.md) | Networking | Host pings, TCP port checks, and IP discovery | `ping()`, `port_open()`, `local_ip()`, `fetch()` | -| 14 | [`thread`](./thread.md) | Concurrency | Thread spawning, worker pools, and parallel execution | `spawn()`, `join()`, `pool()`, `sleep()` | +| 4 | [`proposal`](./proposal.md) | Fun & Cyber-Prank | Automated HTTP 500 love timeout & AI sentiment checker | `ask()`, `set_key()`, `set_system()`, `wish()`, `set_wish()` | +| 5 | [`http`](./http.md) | Networking | Web requests, REST APIs, and file downloads | `get()`, `post()`, `download()`, `status()` | +| 6 | [`file`](./file.md) | System I/O | Read, write, append, and inspect local files | `read()`, `write()`, `append()`, `exists()`, `delete()` | +| 7 | [`os`](./os.md) | System | Shell commands, environment variables, directories | `cmd()`, `env()`, `cwd()`, `listdir()`, `mkdir()`, `platform()` | +| 8 | [`math`](./math.md) | Mathematics | Math functions, trigonometry, and constants | `sqrt()`, `pow()`, `abs()`, `random()`, `round()`, `pi`, `e` | +| 9 | [`time`](./time.md) | System | Epoch time, timestamps, and execution delays | `now()`, `time()`, `sleep()` | +| 10 | [`json`](./json.md) | Data | Parsing and serialization of JSON payloads | `parse()`, `stringify()`, `mkstring()` | +| 11 | [`crypto`](./crypto.md) | Security | Cryptographic hashes and encoding utilities | `md5()`, `sha256()`, `sha1()`, `base64_encode()`, `base64_decode()` | +| 12 | [`string`](./string.md) | Utilities | Advanced text manipulation and transformation | `split()`, `replace()`, `upper()`, `lower()`, `trim()`, `join()` | +| 13 | [`sqlite`](./sqlite.md) | Database | Lightweight embedded SQL relational database | `open()`, `query()`, `execute()`, `close()` | +| 14 | [`net`](./net.md) | Networking | Host pings, TCP port checks, and IP discovery | `ping()`, `port_open()`, `local_ip()`, `fetch()` | +| 15 | [`thread`](./thread.md) | Concurrency | Thread spawning, worker pools, and parallel execution | `spawn()`, `join()`, `pool()`, `sleep()` | --- *Maintained by the AiraLang Core Engineering Team. Created by Adam Eehan.* diff --git a/modules/android.md b/modules/android.md new file mode 100644 index 0000000..368dc0f --- /dev/null +++ b/modules/android.md @@ -0,0 +1,98 @@ +# 📱 `android` Module (AiraLang Native Android Security) + +Native Android security inspection, APK static analysis, and device hardening module engineered specifically for mobile application penetration testing and security auditing directly inside Termux and Linux environments. + +Can be imported as either: +```aira +import "android"; +# or +import "droidsec"; +``` + +--- + +## 🛠️ Functions & Capabilities + +### 1. `android.device_info()` +Returns comprehensive hardware and operating system profile details: +- `brand`: Device brand (e.g. Redmi, Samsung, Google) +- `model`: Device hardware model code +- `manufacturer`: Hardware manufacturer +- `android_version`: Android OS release version (e.g. "16") +- `sdk_version`: Android API level integer (e.g. 36) +- `arch`: CPU architecture (e.g. arm64-v8a) +- `build_type`: OS build variant (e.g. "user", "userdebug") + +```aira +import "android"; +let dev = android.device_info(); +say "Device: " + dev.brand + " " + dev.model; +say "Android Version: " + dev.android_version + " (API " + dev.sdk_version + ")"; +``` + +--- + +### 2. `android.audit_device()` +Performs complete security posture and integrity audit on the host device: +- `is_rooted`: Boolean checking SU binaries (`/system/bin/su`, `/data/local/su`, Magisk paths). +- `bootloader_locked`: Boolean evaluating `ro.boot.flash.locked`. +- `verified_boot`: Android Verified Boot (AVB) state (e.g. "green", "yellow", "orange"). +- `is_debuggable_os`: Boolean checking if OS runs with `ro.debuggable=1`. +- `security_score`: Calculated integer security health score (0 - 100). +- `posture`: Overall rating: `"SECURE"`, `"MODERATE_RISK"`, or `"HIGH_RISK"`. +- `findings`: List of security risks discovered. +- `recommendations`: Hardening recommendations. + +```aira +import "android"; +let audit = android.audit_device(); +say "Device Posture: " + audit.posture; +say "Security Score: " + audit.security_score + "/100"; +say "Root Detected: " + audit.is_rooted; +say "Findings: " + audit.findings; +``` + +--- + +### 3. `android.audit_apk(apk_path)` +High-speed zero-dependency static APK security auditor: +- **Binary AXML String Extractor:** Decodes permissions and configuration flags from compiled `AndroidManifest.xml`. +- **Dangerous Permissions Identifier:** Flags high-risk permissions (SMS, Camera, Location, Audio, Contacts). +- **Security Misconfigurations:** Checks `debuggable`, `allowBackup`, and `usesCleartextTraffic`. +- **DEX Bytecode Key Scanner:** Scans compiled `.dex` files for exposed cloud keys (Google API `AIza...`, AWS `AKIA...`, plaintext HTTP URLs). +- **Signature Audit:** Checks for META-INF signatures and flags insecure Android Debug Keystores. + +```aira +import "android"; +let report = android.audit_apk("/sdcard/Download/target.apk"); +say "Package Name: " + report.package_name; +say "Risk Level: " + report.risk_level; +say "Dangerous Permissions: " + report.dangerous_permissions; +say "Exposed Keys: " + report.hardcoded_secrets; +say "Findings: " + report.findings; +``` + +--- + +### 4. `android.audit_package(package_name)` +Attempts to locate and audit an installed package by name. + +```aira +import "android"; +let report = android.audit_package("com.whatsapp"); +say report; +``` + +--- + +### 5. `android.check_root()` / `android.is_rooted()` +Quick boolean helper returning `true` if root / su binary is detected. + +--- + +### 6. `android.get_prop(prop_name)` +Queries any Android system property via `/system/bin/getprop`: +```aira +import "android"; +say "CPU ABI: " + android.get_prop("ro.product.cpu.abi"); +``` diff --git a/src/cli.py b/src/cli.py index 1562a4e..4626e38 100755 --- a/src/cli.py +++ b/src/cli.py @@ -8,7 +8,7 @@ from lexer import Lexer from parser import Parser from evaluator import Evaluator -VERSION = "1.4.2 (Aira Cyber & AI Edition)" +VERSION = "1.4.3 (Aira Cyber & Android Edition)" AUTHOR = "Adam Eehan (Aira Group of Technology)" ASCII_BANNER = f"""\033[1;36m @@ -21,7 +21,7 @@ ASCII_BANNER = f"""\033[1;36m \033[0m\033[1;30m---------------------------------------------------\033[0m \033[1;32m[+]\033[0m \033[1;37mEngine:\033[0m AiraLang v{VERSION} \033[1;34m[*]\033[0m \033[1;37mCreator:\033[0m {AUTHOR} - \033[1;35m[⚡]\033[0m \033[1;37mModules:\033[0m ai, sec, thread, sqlite, net, crypto + \033[1;35m[⚡]\033[0m \033[1;37mModules:\033[0m android, ai, sec, thread, sqlite, net, crypto \033[1;33m[!]\033[0m Multiline support: open \033[1;32m{{\033[0m will continue on next line. \033[1;33m[!]\033[0m Type \033[1;31m'exit'\033[0m or \033[1;31m'quit'\033[0m to close REPL. \033[1;30m---------------------------------------------------\033[0m diff --git a/src/stdlib_modules.py b/src/stdlib_modules.py index d1f363b..9fe4ddf 100644 --- a/src/stdlib_modules.py +++ b/src/stdlib_modules.py @@ -12,6 +12,10 @@ import urllib.request import urllib.parse import urllib.error import threading +import struct +import zipfile +import re +import subprocess from concurrent.futures import ThreadPoolExecutor class AiraModule: @@ -1048,6 +1052,342 @@ def create_proposal_module(): "set_wish": set_wish }) +def create_android_module(): + DANGEROUS_PERMISSIONS = { + "android.permission.READ_SMS": "Can read SMS messages and OTP verification codes", + "android.permission.RECEIVE_SMS": "Can intercept incoming SMS messages in real-time", + "android.permission.SEND_SMS": "Can send premium SMS messages without user consent", + "android.permission.ACCESS_FINE_LOCATION": "Accesses precise GPS physical coordinates", + "android.permission.ACCESS_COARSE_LOCATION": "Accesses network/cell-tower based location", + "android.permission.ACCESS_BACKGROUND_LOCATION": "Continuously tracks physical location in background", + "android.permission.RECORD_AUDIO": "Can access microphone and record ambient audio", + "android.permission.CAMERA": "Can access camera to capture covert photos or video", + "android.permission.READ_CONTACTS": "Can harvest complete address book and contacts", + "android.permission.WRITE_CONTACTS": "Can modify or delete address book entries", + "android.permission.READ_CALL_LOG": "Can read private phone call logs and history", + "android.permission.WRITE_CALL_LOG": "Can alter or delete telephone call history", + "android.permission.READ_PHONE_STATE": "Can read device IMEI, IMSI, and SIM serials", + "android.permission.READ_EXTERNAL_STORAGE": "Can read media, documents, and downloads on storage", + "android.permission.WRITE_EXTERNAL_STORAGE": "Can write or overwrite arbitrary storage files", + "android.permission.MANAGE_EXTERNAL_STORAGE": "Full filesystem access bypassing Android scoped storage", + "android.permission.SYSTEM_ALERT_WINDOW": "Can draw floating window overlays (Tapjacking risk)", + "android.permission.REQUEST_INSTALL_PACKAGES": "Can silently trigger or sideload unverified APKs", + "android.permission.USE_BIOMETRIC": "Requests biometric fingerprint or face authentication", + "android.permission.BIND_ACCESSIBILITY_SERVICE": "High risk: Can observe screen and simulate user inputs" + } + + def _getprop(prop): + try: + p = subprocess.run(["/system/bin/getprop", str(prop)], capture_output=True, text=True, timeout=2) + return p.stdout.strip() + except Exception: + return "" + + def get_prop(prop_name): + return _getprop(prop_name) + + def device_info(): + sdk_str = _getprop("ro.build.version.sdk") + return { + "brand": _getprop("ro.product.brand") or "Android", + "model": _getprop("ro.product.model") or "Generic Device", + "manufacturer": _getprop("ro.product.manufacturer") or "Unknown", + "android_version": _getprop("ro.build.version.release") or "Unknown", + "sdk_version": int(sdk_str) if sdk_str.isdigit() else 0, + "arch": _getprop("ro.product.cpu.abi") or (os.uname().machine if hasattr(os, "uname") else "unknown"), + "build_type": _getprop("ro.build.type") or "user" + } + + def is_rooted(): + su_paths = [ + "/system/bin/su", "/system/xbin/su", "/sbin/su", + "/data/local/xbin/su", "/data/local/bin/su", "/system/sd/xbin/su", + "/su/bin/su", "/magisk/.core/bin/su", "/data/adb/magisk" + ] + for path in su_paths: + if os.path.exists(path): + return True + try: + p = subprocess.run(["which", "su"], capture_output=True, text=True, timeout=2) + if p.returncode == 0 and p.stdout.strip(): + return True + except Exception: + pass + return False + + def audit_device(): + findings = [] + recommendations = [] + score = 100 + + rooted = is_rooted() + if rooted: + score -= 40 + findings.append("CRITICAL: Root binary or Magisk artifact detected on device.") + recommendations.append("Unroot device or configure Magisk DenyList to protect sensitive data.") + + flash_locked = _getprop("ro.boot.flash.locked") + bootloader_locked = (flash_locked == "1") + if not bootloader_locked and flash_locked: + score -= 25 + findings.append("HIGH: Bootloader is UNLOCKED. Physical device integrity verification is disabled.") + recommendations.append("Lock bootloader to prevent unauthorized physical firmware attacks.") + + avb_state = _getprop("ro.boot.verifiedbootstate") or "unknown" + if avb_state.lower() not in ("green", "unknown", ""): + score -= 20 + findings.append(f"HIGH: Android Verified Boot (AVB) state is {avb_state.upper()} (Tampered system).") + recommendations.append("Reflash official OEM stock firmware to restore Verified Boot trust chain.") + + debuggable = (_getprop("ro.debuggable") == "1") + if debuggable: + score -= 15 + findings.append("MEDIUM: Android OS is built with ro.debuggable=1 (Debug ROM).") + recommendations.append("Switch to official release-keys user build.") + + score = max(0, min(100, score)) + if score >= 85: + posture = "SECURE" + elif score >= 60: + posture = "MODERATE_RISK" + else: + posture = "HIGH_RISK" + + return { + "posture": posture, + "security_score": score, + "is_rooted": rooted, + "bootloader_locked": bootloader_locked, + "verified_boot": avb_state, + "is_debuggable_os": debuggable, + "findings": findings, + "recommendations": recommendations + } + + def _extract_axml_strings(data): + strings = [] + try: + offset = 8 + chunk_type, header_size, chunk_size = struct.unpack("]*)?", dex_content) + for u in http_urls[:10]: + insecure_http_urls.add(u.decode("ascii", errors="ignore")) + except Exception: + pass + + # 3. Inspect META-INF Signatures + cert_files = [f for f in names if f.startswith("META-INF/") and f.endswith((".RSA", ".DSA", ".EC"))] + is_signed = len(cert_files) > 0 + debug_cert = False + for cf in cert_files: + try: + cb = z.read(cf) + if b"Android Debug" in cb or b"CN=Android Debug" in cb: + debug_cert = True + findings.append("CRITICAL: APK signed with insecure Android Debug Keystore!") + risk_score += 40 + except Exception: + pass + + except Exception as e: + return {"error": f"Failed auditing APK: {e}"} + + if len(dangerous_perms) > 5: + risk_score += 20 + findings.append(f"HIGH: Requests {len(dangerous_perms)} high-risk dangerous permissions!") + elif len(dangerous_perms) > 0: + risk_score += 10 + + if hardcoded_secrets: + risk_score += 25 + findings.append(f"HIGH: Identified {len(hardcoded_secrets)} potential hardcoded API/Cloud keys in DEX bytecode!") + + if risk_score >= 50: + risk_level = "CRITICAL" + elif risk_score >= 30: + risk_level = "HIGH" + elif risk_score >= 15: + risk_level = "MEDIUM" + else: + risk_level = "LOW" + + return { + "apk_path": target, + "package_name": package_name, + "risk_level": risk_level, + "risk_score": risk_score, + "is_signed": is_signed, + "debug_certificate": debug_cert, + "flags": flags, + "total_permissions_count": len(all_perms), + "dangerous_permissions": dangerous_perms, + "hardcoded_secrets": hardcoded_secrets, + "insecure_http_urls": list(insecure_http_urls)[:10], + "findings": findings + } + + def audit_package(pkg_name): + pkg = str(pkg_name).strip() + try: + p = subprocess.run(["pm", "path", pkg], capture_output=True, text=True, timeout=3) + out = p.stdout.strip() + if "package:" in out: + apk_path = out.split("package:")[1].split("\n")[0].strip() + if os.path.exists(apk_path): + return audit_apk(apk_path) + except Exception: + pass + + for base_dir in ["/data/app", "/system/app", "/system/priv-app"]: + if os.path.exists(base_dir): + try: + for entry in os.listdir(base_dir): + if pkg in entry: + full = os.path.join(base_dir, entry) + if os.path.isfile(full) and full.endswith(".apk"): + return audit_apk(full) + elif os.path.isdir(full): + for sub in os.listdir(full): + if sub.endswith(".apk"): + return audit_apk(os.path.join(full, sub)) + except Exception: + pass + + return { + "package": pkg, + "status": "not_found", + "message": f"Could not locate APK for '{pkg}'. On unrooted Android, pass direct APK file path to android.audit_apk(path)." + } + + return AiraModule("android", { + "device_info": device_info, + "info": device_info, + "audit_device": audit_device, + "audit": audit_device, + "is_rooted": is_rooted, + "check_root": is_rooted, + "audit_apk": audit_apk, + "audit_package": audit_package, + "get_prop": get_prop + }) + BUILTIN_MODULES = { "file": create_file_module, "os": create_os_module, @@ -1062,6 +1402,8 @@ BUILTIN_MODULES = { "ai": create_ai_module, "sec": create_sec_module, "thread": create_thread_module, - "proposal": create_proposal_module + "proposal": create_proposal_module, + "android": create_android_module, + "droidsec": create_android_module }