Frida: Difference between revisions
imported>Mic92 improve automation of fhsuserenv |
imported>Mic92 nobody like eggs |
||
Line 37: | Line 37: | ||
which | which | ||
git | git | ||
(python3.withPackages (p: [ p.setuptools ])) | (python3.withPackages (p: [ p.setuptools p.wheel ])) | ||
nodejs | nodejs | ||
perl | perl | ||
Line 51: | Line 51: | ||
(cd frida-gum/bindings/gumjs && yarn install) | (cd frida-gum/bindings/gumjs && yarn install) | ||
# for frida-python | # for frida-python wheel | ||
export FRIDA_VERSION=$(git describe --tags) | export FRIDA_VERSION=$(git describe --tags) | ||
export FRIDA_EXTENSION=$(realpath build/frida-linux-x86_64/${python3.sitePackages}/_frida.so) | export FRIDA_EXTENSION=$(realpath build/frida-linux-x86_64/${python3.sitePackages}/_frida.so) | ||
export SOURCE_DATE_EPOCH="315532800" | |||
''; | ''; | ||
}; | }; | ||
Line 69: | Line 70: | ||
<syntaxHighlight lang=console> | <syntaxHighlight lang=console> | ||
$ cd frida-python/src/ | $ cd frida-python/src/ | ||
$ python setup.py | $ python setup.py bdist_wheel | ||
$ | $ pip install dist/frida-*.whl | ||
</syntaxHighlight> | </syntaxHighlight> | ||
Mic92 has an [https://github.com/Mic92/nur-packages/blob/master/frida-python/default.nix expression] that provides a pre-compiled version of frida using the compiled | Mic92 has an [https://github.com/Mic92/nur-packages/blob/master/frida-python/default.nix expression] that provides a pre-compiled version of frida using the compiled wheel as shown. |
Revision as of 09:50, 1 September 2018
Frida is a dynamic binary instrumentation framework.
Getting it work on NixOS
The project provides pre-compiled binaries that almost work out of the box (when installed via pip install frida
)
However at runtime it unpacks a helper called frida-helper-64
that uses /lib64/ld-linux-x86-64.so.2
as its link-loader.
The error message will be similar to this one:
$ frida-trace -i "recv*" 1
"/run/user/1000/frida-ea4a59ca62f7c8d1d49bd898ec313eeb/frida-helper-64": No such file or directory (os error 2)
Since the helper is not accessible on the filesystem it cannot patched with patchelf. A simple hack is to symlink an arbitrary link loader to this directory:
$ ldd /bin/sh
...
/nix/store/83lrbvbmxrgv7iz49mgd42yvhi473xp6-glibc-2.27/lib/ld-linux-x86-64.so.2 => /nix/store/83lrbvbmxrgv7iz49mgd42yvhi473xp6-glibc-2.27/lib64/ld-linux-x86-64.so.2 (0x00007fa78b289000)
$ ln -s /nix/store/83lrbvbmxrgv7iz49mgd42yvhi473xp6-glibc-2.27/lib/ld-linux-x86-64.so.2 /lib64/ld-linux-x86-64.so.2
Compile from source
Frida provides a pre-compiled SDK. Since it assumes many binaries in /usr/bin/
, the best option
is to use buildFHSUserEnv
:
with import <nixpkgs> {};
let
fhs = pkgs.buildFHSUserEnv {
name = "frida-env";
targetPkgs = pkgs: with pkgs; [
gcc_multi
binutils
gnumake
which
git
(python3.withPackages (p: [ p.setuptools p.wheel ]))
nodejs
perl
curl
glibc_multi
yarn
];
profile = ''
export hardeningDisable=all
# initialize sdk
make
# npm does not frida-gum/bindings/gumjs/node_modules -> bug?
(cd frida-gum/bindings/gumjs && yarn install)
# for frida-python wheel
export FRIDA_VERSION=$(git describe --tags)
export FRIDA_EXTENSION=$(realpath build/frida-linux-x86_64/${python3.sitePackages}/_frida.so)
export SOURCE_DATE_EPOCH="315532800"
'';
};
in fhs.env
Afterwards the build system can be used as documented:
$ make python-64
The python egg can be build then like this:
$ cd frida-python/src/
$ python setup.py bdist_wheel
$ pip install dist/frida-*.whl
Mic92 has an expression that provides a pre-compiled version of frida using the compiled wheel as shown.