Skip to content

Execute a file instead of code fragments#25

Open
russkel wants to merge 3 commits into
kmaork:masterfrom
greenroom-robotics:master
Open

Execute a file instead of code fragments#25
russkel wants to merge 3 commits into
kmaork:masterfrom
greenroom-robotics:master

Conversation

@russkel
Copy link
Copy Markdown

@russkel russkel commented Jul 25, 2024

You can now inject a python script path. This seemed easier to manage than trying to get my scripts as arguments on the command line.

Platforms other than Linux are not tested.

Comment thread hypno/api.py
if path is not None and path.exists():
path.unlink()

def inject_py_script(pid: int, python_script: Path, permissions=0o644) -> None:
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much of the logic here is duplicated from above. I think it might be better to keep it as one function, inject_py, and check isinstance(python_code, Path) to determine the logic. Also, I think that instead of modifying injection.c, it would be easier to just read the given file here, and use the contents as code.

Copy link
Copy Markdown
Author

@russkel russkel Jul 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a large script is provided then it will overflow. Also relative imports will not work as expected either presumably. To me it made sense to use the Python API file parsing and execution instead of shoehorning the code into the lib?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I agree about the advantages, but ideally I'd want to enocunter all possible errors before the injection, so they happen in python and not in C in the target process. I also wonder permission-wise, if it's better to use the injector process permissions or the injectee's permissions (and fs, btw, see #18). I will hopefully have more time to think about it later.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I agree about the advantages, but ideally I'd want to enocunter all possible errors before the injection, so they happen in python and not in C in the target process.

Are there more errors this way? I am not sure I understand where the source of errors you're concerned about is.

As for Docker, I am already running into some issues running from within the container and being able to open libc.so. Containerisation always makes things complicated 😅

@kmaork
Copy link
Copy Markdown
Owner

kmaork commented Jul 25, 2024

Thanks for the feature! I fixed CI on master, you can update your branch

@russkel russkel changed the title Inject a file instead of code fragments Execute a file instead of code fragments Jul 25, 2024
@russkel
Copy link
Copy Markdown
Author

russkel commented Jul 29, 2024

Not sure what is going on with the alpine, Mac and Windows tests. Something is causing the process to segfault in some cases, groan.

@kmaork
Copy link
Copy Markdown
Owner

kmaork commented Jul 30, 2024

I'm flying abroad, so sadly I can't help right now, would love to help merge this whenever I can

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants