Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable file binary creation #44

Conversation

DesobedienteTecnologico
Copy link
Contributor

🥳 Binary creation is possible using only this command and the commit I made:

cargo build --release --target-dir .

The binary is going to be created under release directory.
The arch will be the same as the host machine. In my case:

rana: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=65b4d3fad4caae109ebab35238a0731124f9b80e, for GNU/Linux 3.2.0, with debug_info, not stripped

@grunch
Copy link
Owner

grunch commented Jul 31, 2023

Hi @DesobedienteTecnologico thanks for your contribution, and I'm sorry I haven't done this yet, you are right that we can generate a binary that way, but I think you need different binaries from differents architectures since your project is a portable set of tools, isn't it?

@DesobedienteTecnologico
Copy link
Contributor Author

Hi @DesobedienteTecnologico thanks for your contribution, and I'm sorry I haven't done this yet, you are right that we can generate a binary that way, but I think you need different binaries from different architectures since your project is a portable set of tools, isn't it?

Hi, well. The tool I'm developing mainly focus on x86_64 (But others can be added at some point undoubtedly). The plan is to be able to add into the Tails image without using persistence (Modifying the SquahsFS) using DTails.

But regardless of that, would be nice to have it build in different arch like ARM64, so people can mine their keys directly on Android using Termux + Rana! :)

As far as I know, we need to compile individually every each arch you would like to have a binary.

The command should contain --target flag, which should be used like that:
cargo build --release --target-dir . --target x86_64-unknown-linux-gnu


Example:

image

image


List of compatibles architectures:

▪️ Architectures
~$ rustc --print target-list
aarch64-apple-darwin
aarch64-apple-ios
aarch64-apple-ios-macabi
aarch64-apple-ios-sim
aarch64-apple-tvos
aarch64-apple-watchos-sim
aarch64-fuchsia
aarch64-kmc-solid_asp3
aarch64-linux-android
aarch64-nintendo-switch-freestanding
aarch64-pc-windows-gnullvm
aarch64-pc-windows-msvc
aarch64-unknown-freebsd
aarch64-unknown-fuchsia
aarch64-unknown-hermit
aarch64-unknown-linux-gnu
aarch64-unknown-linux-gnu_ilp32
aarch64-unknown-linux-musl
aarch64-unknown-linux-ohos
aarch64-unknown-netbsd
aarch64-unknown-none
aarch64-unknown-none-softfloat
aarch64-unknown-nto-qnx710
aarch64-unknown-openbsd
aarch64-unknown-redox
aarch64-unknown-uefi
aarch64-uwp-windows-msvc
aarch64-wrs-vxworks
aarch64_be-unknown-linux-gnu
aarch64_be-unknown-linux-gnu_ilp32
arm-linux-androideabi
arm-unknown-linux-gnueabi
arm-unknown-linux-gnueabihf
arm-unknown-linux-musleabi
arm-unknown-linux-musleabihf
arm64_32-apple-watchos
armeb-unknown-linux-gnueabi
armebv7r-none-eabi
armebv7r-none-eabihf
armv4t-none-eabi
armv4t-unknown-linux-gnueabi
armv5te-none-eabi
armv5te-unknown-linux-gnueabi
armv5te-unknown-linux-musleabi
armv5te-unknown-linux-uclibceabi
armv6-unknown-freebsd
armv6-unknown-netbsd-eabihf
armv6k-nintendo-3ds
armv7-apple-ios
armv7-linux-androideabi
armv7-sony-vita-newlibeabihf
armv7-unknown-freebsd
armv7-unknown-linux-gnueabi
armv7-unknown-linux-gnueabihf
armv7-unknown-linux-musleabi
armv7-unknown-linux-musleabihf
armv7-unknown-linux-ohos
armv7-unknown-linux-uclibceabi
armv7-unknown-linux-uclibceabihf
armv7-unknown-netbsd-eabihf
armv7-wrs-vxworks-eabihf
armv7a-kmc-solid_asp3-eabi
armv7a-kmc-solid_asp3-eabihf
armv7a-none-eabi
armv7a-none-eabihf
armv7k-apple-watchos
armv7r-none-eabi
armv7r-none-eabihf
armv7s-apple-ios
asmjs-unknown-emscripten
avr-unknown-gnu-atmega328
bpfeb-unknown-none
bpfel-unknown-none
hexagon-unknown-linux-musl
i386-apple-ios
i586-pc-nto-qnx700
i586-pc-windows-msvc
i586-unknown-linux-gnu
i586-unknown-linux-musl
i686-apple-darwin
i686-linux-android
i686-pc-windows-gnu
i686-pc-windows-msvc
i686-unknown-freebsd
i686-unknown-haiku
i686-unknown-linux-gnu
i686-unknown-linux-musl
i686-unknown-netbsd
i686-unknown-openbsd
i686-unknown-uefi
i686-uwp-windows-gnu
i686-uwp-windows-msvc
i686-wrs-vxworks
loongarch64-unknown-linux-gnu
m68k-unknown-linux-gnu
mips-unknown-linux-gnu
mips-unknown-linux-musl
mips-unknown-linux-uclibc
mips64-openwrt-linux-musl
mips64-unknown-linux-gnuabi64
mips64-unknown-linux-muslabi64
mips64el-unknown-linux-gnuabi64
mips64el-unknown-linux-muslabi64
mipsel-sony-psp
mipsel-sony-psx
mipsel-unknown-linux-gnu
mipsel-unknown-linux-musl
mipsel-unknown-linux-uclibc
mipsel-unknown-none
mipsisa32r6-unknown-linux-gnu
mipsisa32r6el-unknown-linux-gnu
mipsisa64r6-unknown-linux-gnuabi64
mipsisa64r6el-unknown-linux-gnuabi64
msp430-none-elf
nvptx64-nvidia-cuda
powerpc-unknown-freebsd
powerpc-unknown-linux-gnu
powerpc-unknown-linux-gnuspe
powerpc-unknown-linux-musl
powerpc-unknown-netbsd
powerpc-unknown-openbsd
powerpc-wrs-vxworks
powerpc-wrs-vxworks-spe
powerpc64-ibm-aix
powerpc64-unknown-freebsd
powerpc64-unknown-linux-gnu
powerpc64-unknown-linux-musl
powerpc64-unknown-openbsd
powerpc64-wrs-vxworks
powerpc64le-unknown-freebsd
powerpc64le-unknown-linux-gnu
powerpc64le-unknown-linux-musl
riscv32gc-unknown-linux-gnu
riscv32gc-unknown-linux-musl
riscv32i-unknown-none-elf
riscv32im-unknown-none-elf
riscv32imac-unknown-none-elf
riscv32imac-unknown-xous-elf
riscv32imc-esp-espidf
riscv32imc-unknown-none-elf
riscv64gc-unknown-freebsd
riscv64gc-unknown-fuchsia
riscv64gc-unknown-linux-gnu
riscv64gc-unknown-linux-musl
riscv64gc-unknown-none-elf
riscv64gc-unknown-openbsd
riscv64imac-unknown-none-elf
s390x-unknown-linux-gnu
s390x-unknown-linux-musl
sparc-unknown-linux-gnu
sparc64-unknown-linux-gnu
sparc64-unknown-netbsd
sparc64-unknown-openbsd
sparcv9-sun-solaris
thumbv4t-none-eabi
thumbv5te-none-eabi
thumbv6m-none-eabi
thumbv7a-pc-windows-msvc
thumbv7a-uwp-windows-msvc
thumbv7em-none-eabi
thumbv7em-none-eabihf
thumbv7m-none-eabi
thumbv7neon-linux-androideabi
thumbv7neon-unknown-linux-gnueabihf
thumbv7neon-unknown-linux-musleabihf
thumbv8m.base-none-eabi
thumbv8m.main-none-eabi
thumbv8m.main-none-eabihf
wasm32-unknown-emscripten
wasm32-unknown-unknown
wasm32-wasi
wasm64-unknown-unknown
x86_64-apple-darwin
x86_64-apple-ios
x86_64-apple-ios-macabi
x86_64-apple-tvos
x86_64-apple-watchos-sim
x86_64-fortanix-unknown-sgx
x86_64-fuchsia
x86_64-linux-android
x86_64-pc-nto-qnx710
x86_64-pc-solaris
x86_64-pc-windows-gnu
x86_64-pc-windows-gnullvm
x86_64-pc-windows-msvc
x86_64-sun-solaris
x86_64-unknown-dragonfly
x86_64-unknown-freebsd
x86_64-unknown-fuchsia
x86_64-unknown-haiku
x86_64-unknown-hermit
x86_64-unknown-illumos
x86_64-unknown-l4re-uclibc
x86_64-unknown-linux-gnu
x86_64-unknown-linux-gnux32
x86_64-unknown-linux-musl
x86_64-unknown-netbsd
x86_64-unknown-none
x86_64-unknown-openbsd
x86_64-unknown-redox
x86_64-unknown-uefi
x86_64-uwp-windows-gnu
x86_64-uwp-windows-msvc
x86_64-wrs-vxworks
x86_64h-apple-darwin


As an example. after some test, if we need cross-compile to other architectures, we need to follow this steps:

  1. rustup target add aarch64-unknown-linux-gnu
  2. sudo apt install gcc-aarch64-linux-gnu
  3. export CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc
  4. cargo build --release --target-dir . --target aarch64-unknown-linux-gnu

But so far, only with X86_64 will be great. Thanks

@DesobedienteTecnologico
Copy link
Contributor Author

DesobedienteTecnologico commented Aug 1, 2023

The unique problem we could face is the need of a updated concrete glibc version.
(I got it working nicely in my arch host with glibc 2.37) But probably some old Debian or Ubuntu version can't run it out of the box.

The glibc versions needed to get it running apparently are:

$: objdump -T x86_64-unknown-linux-gnu/release/rana | grep GLIBC | sed 's/.*GLIBC_\([.0-9]*\).*/\1/g' | sort -Vu     
2.2.5
2.3
2.3.2
2.3.4
2.14
2.17
2.18
2.25
2.28
2.32
2.33
2.34

@grunch
Copy link
Owner

grunch commented Aug 1, 2023

The unique problem we could face is the need of a updated concrete glibc version. (I got it working nicely in my arch host with glibc 2.37) But probably some old Debian or Ubuntu version can't run it out of the box.

The glibc versions needed to get it running apparently are:

$: objdump -T x86_64-unknown-linux-gnu/release/rana | grep GLIBC | sed 's/.*GLIBC_\([.0-9]*\).*/\1/g' | sort -Vu     
2.2.5
2.3
2.3.2
2.3.4
2.14
2.17
2.18
2.25
2.28
2.32
2.33
2.34

I think we can avoid this problem using docker, take a look on this

https://www.docker.com/blog/cross-compiling-rust-code-for-multiple-architectures/

@grunch
Copy link
Owner

grunch commented Aug 2, 2023

First cross compiling attempt successful
image

@grunch
Copy link
Owner

grunch commented Aug 2, 2023

And it works... this is fun

photo_2023-08-02_11-05-31

@DesobedienteTecnologico
Copy link
Contributor Author

I got finally a version that do not depend on the gblic libraries!

Static binary file fully working on Tails out of the box, no dependencies:

image

In the following comment I will send you the steps. Quite fun! :)

@DesobedienteTecnologico
Copy link
Contributor Author

Build static version for Linux arch x86_64:

  1. sudo apt install musl musl-tools
  2. rustup target add x86_64-unknown-linux-musl
  3. cargo build --release --target-dir . --target x86_64-unknown-linux-musl

And apparently seems to be reproducible... (Need your confirmation)
acac1759ec56c325394bfdacdbab07c9ca79a5b23266f1903db8ab5bfcd6de7f x86_64-unknown-linux-musl/release/rana

I think with that we could have already a binaries to be released. Thanks!

@DesobedienteTecnologico
Copy link
Contributor Author

Build static version for Linux arch aarch64/amd64 (Smartphones):

Very easy and straightforward: https://github.com/rust-cross/rust-musl-cross#prebuilt-images

@grunch
Copy link
Owner

grunch commented Aug 3, 2023

Hi @DesobedienteTecnologico take a look on this https://github.com/grunch/rana/releases/tag/v0.5.4 and let me know if it works for you.

thank you for your work, your pointed me in the right direction

@DesobedienteTecnologico
Copy link
Contributor Author

Hi @DesobedienteTecnologico take a look on this https://github.com/grunch/rana/releases/tag/v0.5.4 and let me know if it works for you.

thank you for your work, your pointed me in the right direction

I just tried it. So far works well the android version I tried.

The x86_64_unknown_linux_gnu that I tried works BUT if possible I highly recommend you to point musl instead gnu. If you choose GNU that is going to use GNU glibc libraries that are not in Ubuntu Focal (Glibc 2.31) and Debian 10 (Glibc 2.28), so no one can use it out of the box.

image

If you build it against musl it will not depend on glibc libraries and will work without any problem in those Operating systems.

Please consider have a look here:
--target x86_64-unknown-linux-musl

#44 (comment)

@grunch
Copy link
Owner

grunch commented Aug 7, 2023

Build static version for Linux arch x86_64:

1. sudo apt install musl musl-tools

2. rustup target add x86_64-unknown-linux-musl

3. cargo build --release --target-dir . --target x86_64-unknown-linux-musl

And apparently seems to be reproducible... (Need your confirmation) acac1759ec56c325394bfdacdbab07c9ca79a5b23266f1903db8ab5bfcd6de7f x86_64-unknown-linux-musl/release/rana

I think with that we could have already a binaries to be released. Thanks!

did you compiled main branch here?

I got 5278f712e83e17e9da24eedb8b1b8c664ef97335283f1aa957215067e9ca53a9 for x86_64-unknown-linux-musl/rana, do you have any idea what could make hashes didn't match?

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