binloader
Advanced tools
| Metadata-Version: 2.4 | ||
| Name: binloader | ||
| Version: 0.0.1 | ||
| Summary: Run VIM and Busybox | ||
| Version: 0.0.2 | ||
| Summary: Run VIM and Busybox. Optionally run remote binaries | ||
| Author-email: Ulises <ulises.odysseus22@gmail.com> | ||
| License: GPLv2 | ||
| Project-URL: Homepage, https://github.com/ulisesojeda/binary_loader | ||
| Requires-Python: >=3.6 | ||
| Classifier: Operating System :: POSIX | ||
| Requires-Python: >=3.4 | ||
| Description-Content-Type: text/markdown | ||
| # Run VIM and Busybox as a Python module in Linux/x86_64 systems | ||
| ## Run VIM/Busybox and remote binaries accesible by http/https/ftp as a Python module in Linux/x86_64 systems | ||
@@ -25,3 +26,3 @@ Motivation: run programs not available in restricted environments where | ||
| ```bash | ||
| python -m binloader vim /etc/passwd | ||
| python -m binloader --local vim /etc/passwd | ||
| ``` | ||
@@ -31,5 +32,10 @@ | ||
| ```bash | ||
| python -m binloader busybox uname -a | ||
| python -m binloader --local busybox uname -a | ||
| ``` | ||
| ### Remote binary | ||
| ```bash | ||
| python -m binloader --remote https://github.com/dtschan/vim-static/releases/download/v8.1.1045/vim --app vim /etc/passwd | ||
| ``` | ||
| ### ToDo | ||
@@ -36,0 +42,0 @@ 1. Support for other OS/architectures |
+45
-16
@@ -0,34 +1,63 @@ | ||
| import argparse | ||
| import os | ||
| from pathlib import Path | ||
| import stat | ||
| import sys | ||
| from pathlib import Path | ||
| import urllib.request | ||
| def run(argv): | ||
| app = argv[1] | ||
| args = argv[1:] | ||
| def run_local(app, argv): | ||
| """ | ||
| Execute binary provided by the library | ||
| Parameters: | ||
| app: str = binary name | ||
| argv: [str] = app's arguments | ||
| """ | ||
| cur_dir = Path(__file__).resolve().parent | ||
| binaries = { | ||
| "vim": f"{cur_dir}/binaries/vim_amd64", | ||
| "busybox": f"{cur_dir}/binaries/busybox_amd64", | ||
| "vim": cur_dir / "binaries/vim_amd64", | ||
| "busybox": cur_dir / "binaries/busybox_amd64", | ||
| } | ||
| ram_file = os.memfd_create("ram_file") | ||
| os.chmod(ram_file, stat.S_IEXEC) | ||
| bin_path = binaries[app] | ||
| bin_path.chmod(stat.S_IEXEC) | ||
| os.execv(str(bin_path), [app] + argv) | ||
| f_ram = os.fdopen(ram_file, "wb") | ||
| vim_data = open(binaries[app], "br").read() | ||
| f_ram.write(vim_data) | ||
| os.execv(f"/proc/self/fd/{ram_file}", args) | ||
| def run_remote(url, app, argv): | ||
| """ | ||
| Download and execute remote binary | ||
| Parameters: | ||
| url: str = binary's remote location | ||
| app: str = binary name. To be pass as first argument to execv | ||
| argv: [str] = app's arguments | ||
| """ | ||
| bin_path = "/tmp/binloader_remote" | ||
| urllib.request.urlretrieve(url, bin_path) | ||
| path = Path(bin_path) | ||
| path.chmod(stat.S_IEXEC | stat.S_IREAD | stat.S_IWRITE) | ||
| arguments = [app if app else "binloader"] + argv | ||
| os.execv(str(path), arguments) | ||
| def main(): | ||
| argv = sys.argv | ||
| assert len(argv) > 1, "Missing parameters. At least provide app name" | ||
| run(argv) | ||
| parser = argparse.ArgumentParser() | ||
| parser.add_argument("-l", "--local") | ||
| parser.add_argument("-r", "--remote") | ||
| parser.add_argument("-a", "--app") | ||
| parser.add_argument("rest", nargs=argparse.REMAINDER) | ||
| args = parser.parse_args() | ||
| if args.local: | ||
| run_local(app=args.local, argv=args.rest) | ||
| elif args.remote: | ||
| run_remote(url=args.remote, app=args.app, argv=args.rest) | ||
| else: | ||
| raise ValueError("Invalid option. Use --local/--remote") | ||
| if __name__ == "__main__": | ||
| main() |
+12
-6
| Metadata-Version: 2.4 | ||
| Name: binloader | ||
| Version: 0.0.1 | ||
| Summary: Run VIM and Busybox | ||
| Version: 0.0.2 | ||
| Summary: Run VIM and Busybox. Optionally run remote binaries | ||
| Author-email: Ulises <ulises.odysseus22@gmail.com> | ||
| License: GPLv2 | ||
| Project-URL: Homepage, https://github.com/ulisesojeda/binary_loader | ||
| Requires-Python: >=3.6 | ||
| Classifier: Operating System :: POSIX | ||
| Requires-Python: >=3.4 | ||
| Description-Content-Type: text/markdown | ||
| # Run VIM and Busybox as a Python module in Linux/x86_64 systems | ||
| ## Run VIM/Busybox and remote binaries accesible by http/https/ftp as a Python module in Linux/x86_64 systems | ||
@@ -25,3 +26,3 @@ Motivation: run programs not available in restricted environments where | ||
| ```bash | ||
| python -m binloader vim /etc/passwd | ||
| python -m binloader --local vim /etc/passwd | ||
| ``` | ||
@@ -31,5 +32,10 @@ | ||
| ```bash | ||
| python -m binloader busybox uname -a | ||
| python -m binloader --local busybox uname -a | ||
| ``` | ||
| ### Remote binary | ||
| ```bash | ||
| python -m binloader --remote https://github.com/dtschan/vim-static/releases/download/v8.1.1045/vim --app vim /etc/passwd | ||
| ``` | ||
| ### ToDo | ||
@@ -36,0 +42,0 @@ 1. Support for other OS/architectures |
+6
-3
| [project] | ||
| name = "binloader" | ||
| version = "0.0.1" | ||
| description = "Run VIM and Busybox" | ||
| version = "0.0.2" | ||
| description = "Run VIM and Busybox. Optionally run remote binaries" | ||
| authors = [{ name="Ulises", email="ulises.odysseus22@gmail.com" }] | ||
| readme = "README.md" | ||
| requires-python = ">=3.6" | ||
| requires-python = ">=3.4" | ||
| license = { text = "GPLv2" } | ||
| classifiers = [ | ||
| "Operating System :: POSIX", | ||
| ] | ||
@@ -10,0 +13,0 @@ [project.urls] |
+8
-3
@@ -1,2 +0,2 @@ | ||
| # Run VIM and Busybox as a Python module in Linux/x86_64 systems | ||
| ## Run VIM/Busybox and remote binaries accesible by http/https/ftp as a Python module in Linux/x86_64 systems | ||
@@ -15,3 +15,3 @@ Motivation: run programs not available in restricted environments where | ||
| ```bash | ||
| python -m binloader vim /etc/passwd | ||
| python -m binloader --local vim /etc/passwd | ||
| ``` | ||
@@ -21,5 +21,10 @@ | ||
| ```bash | ||
| python -m binloader busybox uname -a | ||
| python -m binloader --local busybox uname -a | ||
| ``` | ||
| ### Remote binary | ||
| ```bash | ||
| python -m binloader --remote https://github.com/dtschan/vim-static/releases/download/v8.1.1045/vim --app vim /etc/passwd | ||
| ``` | ||
| ### ToDo | ||
@@ -26,0 +31,0 @@ 1. Support for other OS/architectures |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
5807356
0.03%59
73.53%