How do I configure crosstools-ng sample for cross compiling toolchain for my router? - ssh

I want to cross compile shadowsocks for my router ( netcore q3, made in china) on CentOS 7. So I got crosstools-ng, I ssh into the router, and get following info (The router is on a Tomato Firmware 1.28.0000 MIPSR2-131 K26 Max by shibby), I used How to build a cross compiler for your Raspberry Pi as my reference
$less /proc/cpuinfo
system type : Broadcom BCM53572 chip rev 1 pkg 8
processor : 0
cpu model : MIPS 74K V4.9
BogoMIPS : 149.50
cpu MHz : 300
wait instruction : no
microsecond timers : yes
tlb_entries : 32
extra interrupt vector : no
hardware watchpoint : yes
ASEs implemented : mips16 dsp
shadow register sets : 1
VCED exceptions : not available
VCEI exceptions : not available
unaligned_instructions : 0
I also copied a .so file from /lib
$ scp root#router:/lib/libc.so.0 .
[oglop#localhost tmp]$ readelf -h libc.so.0
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: DYN (Shared object file)
Machine: MIPS R3000
Version: 0x1
Entry point address: 0x6d50
Start of program headers: 52 (bytes into file)
Start of section headers: 260672 (bytes into file)
Flags: 0x50001007, noreorder, pic, cpic, o32, mips32
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 5
Size of section headers: 40 (bytes)
Number of section headers: 18
Section header string table index: 17
files in /lib on the router
root#unknown:/tmp/home/root# ls /lib
ld-uClibc.so.0 libgcc_s.so.1 libutil.so.0
libc.so.0 libm.so.0 modules
libcrypt.so.0 libnsl.so.0 openvpn_plugin_auth_nvram.so
libdl.so.0 libpthread.so.0
Can I get all the information from these two? Which sample should I choose ?
So from the .so file :
endianness : little endian
bitness: ?
abi: ?
target os: linux or bare-metal?
c library: glibc, musl or uClibc ?
...
I guess I should starts with mips-unknown-linux-uclibc and change it to little endian ?
[oglop#localhost tmp]$ ct-ng list-samples | grep mips
[G.X] mips64el-n32-linux-uclibc
[G.X] mips64el-n64-linux-uclibc
[G..] mips-ar2315-linux-gnu
[G..] mipsel-sde-elf
[G..] mipsel-unknown-linux-gnu
[G..] mips-malta-linux-gnu
[G..] mips-unknown-elf
[G..] mips-unknown-linux-uclibc
root#unknown:/tmp/home/root# cat /proc/version
Linux version 2.6.22.19 (root#tomato) (gcc version 4.2.4) #16 Tue Aug 4 00:16:31 CEST 2015
I tried to figure out the libc version tomato uses, but
root#unknown:/tmp/home/root# /lib/libc.so.0
Segmentation fault
root#unknown:/tmp/home/root# ldd --version
-sh: --version: not found
Or Can I get the info I need from tomato source shibby branch on github?

Related

qemu valid dtb and unrecognized/unsupported machine ID

I am following this tutorial to run Raspbian on my Windows PC, but it does not work.
I renamed my system img and kernel to fit the command, but no success.
valid dtb and unrecognized/unsupported machine ID
r1=0x00000183, r2=0x00000100
r2[]=05 00 00 00 01 00 41 54 01 00 00 00 00 10 00 00
Available machine support:
ID (hex) NAME
ffffffff Generic DT based system
ffffffff ARM-Versatile (Device Tree Support)
The command I was executing:
qemu-system-arm -kernel kernel-qemu-4.4.34-jessie -cpu arm1176 -m 256 -M versatilepb -no-reboot -serial stdio -append "root=/dev/sda2 panic=1 rootfstype=ext4 rw init=/bin/bash" -drive "file=2017-03-02-raspbian-jessie.img,index=0,media=disk,format=raw"
You've cut off the first part of the error message, which is confusing. The full text is "Error: invalid dtb and unrecognized/unsupported machine ID".
What the kernel is trying to tell you here is that you must provide it with the correct device tree blob (dtb) file for the board you are running it on. Newer kernels can't boot without a dtb. You need to pass QEMU the correct file via its -dtb option, which in this case is "versatile-pb.dtb". That file should be built when you build the kernel from source, or if you got your kernel from somebody else they should also provide the dtb.

hashcat benchmark not starting at all

I'm trying to start hashcat on Win10 using my GPU AMD RX580.
What I did so far is:
Uninstalled all AMD drivers and rebooted
Started Driver Fusion cleaned all AMD Display drivers and rebooted
Manually removed OpenCL.dll from C:\windows\system32\ and c:\windows\syswow64 and rebooted
Installed AMD Crimsson driver edition - tried 17.8.2, 17.11.1, 17.11.4
My problem:
When I try to start a benchmark for WPA2 hash with PS D:\crack\hashcat-5.1.0> .\hashcat64.exe -m 2500 -b
It starts and just quits without any output:
PS D:\crack\hashcat-5.1.0> .\hashcat64.exe -m 2500 -b
hashcat (v5.1.0) starting in benchmark mode...
Benchmarking uses hand-optimized kernel code by default.
You can use it in your cracking session by setting the -O option.
Note: Using optimized kernel code limits the maximum supported password length.
To disable the optimized kernel code in benchmark mode, use the -w option.
* Device #2: Not a native Intel OpenCL runtime. Expect massive speed loss.
You can use --force to override, but do not report related errors.
OpenCL Platform #1: Advanced Micro Devices, Inc.
================================================
* Device #1: Ellesmere, 3264/4096 MB allocatable, 36MCU
* Device #2: Intel(R) Core(TM) i7-4790 CPU # 3.60GHz, skipped.
Benchmark relevant options:
===========================
* --optimized-kernel-enable
Hashmode: 2500 - WPA-EAPOL-PBKDF2 (Iterations: 4096)
PS D:\crack\hashcat-5.1.0>
Output from hashcat -I:
PS D:\crack\hashcat-5.1.0> .\hashcat64.exe -I
hashcat (v5.1.0) starting...
OpenCL Info:
Platform ID #1
Vendor : Advanced Micro Devices, Inc.
Name : AMD Accelerated Parallel Processing
Version : OpenCL 2.0 AMD-APP (2442.8)
Device ID #1
Type : GPU
Vendor ID : 1
Vendor : Advanced Micro Devices, Inc.
Name : Ellesmere
Version : OpenCL 2.0 AMD-APP (2442.8)
Processor(s) : 36
Clock : 1366
Memory : 3264/4096 MB allocatable
OpenCL Version : OpenCL C 2.0
Driver Version : 2442.8
Device ID #2
Type : CPU
Vendor ID : 128
Vendor : GenuineIntel
Name : Intel(R) Core(TM) i7-4790 CPU # 3.60GHz
Version : OpenCL 1.2 AMD-APP (2442.8)
Processor(s) : 8
Clock : 3599
Memory : 6131/24526 MB allocatable
OpenCL Version : OpenCL C 1.2
Driver Version : 2442.8 (sse2,avx)
PS D:\crack\hashcat-5.1.0>
The same happens if I try to start mask attack.
Other benchmarks seems to work but when it reaches the WPA2 it just returns me to the command prompt:
PS D:\crack\hashcat-5.1.0> .\hashcat64.exe -b
hashcat (v5.1.0) starting in benchmark mode...
Benchmarking uses hand-optimized kernel code by default.
You can use it in your cracking session by setting the -O option.
Note: Using optimized kernel code limits the maximum supported password length.
To disable the optimized kernel code in benchmark mode, use the -w option.
* Device #2: Not a native Intel OpenCL runtime. Expect massive speed loss.
You can use --force to override, but do not report related errors.
OpenCL Platform #1: Advanced Micro Devices, Inc.
================================================
* Device #1: Ellesmere, 3264/4096 MB allocatable, 36MCU
* Device #2: Intel(R) Core(TM) i7-4790 CPU # 3.60GHz, skipped.
Benchmark relevant options:
===========================
* --optimized-kernel-enable
Hashmode: 0 - MD5
Speed.#1.........: 12381.1 MH/s (96.87ms) # Accel:256 Loops:512 Thr:256 Vec:1
Hashmode: 100 - SHA1
Speed.#1.........: 4268.9 MH/s (70.02ms) # Accel:256 Loops:128 Thr:256 Vec:1
Hashmode: 1400 - SHA2-256
Speed.#1.........: 1870.1 MH/s (80.00ms) # Accel:256 Loops:64 Thr:256 Vec:1
Hashmode: 1700 - SHA2-512
Speed.#1.........: 461.1 MH/s (81.22ms) # Accel:128 Loops:32 Thr:256 Vec:1
Hashmode: 2500 - WPA-EAPOL-PBKDF2 (Iterations: 4096)
PS D:\crack\hashcat-5.1.0>
Any idea what could cause this behavior?
It looks like it was a crash in the OpenCL runtime. I have installed the newest Adrenalin Drivers - 19.3.2 , but went into another issue :
PS D:\crack\hashcat-5.1.0> .\hashcat64.exe -b -m 2500
hashcat (v5.1.0) starting in benchmark mode...
Benchmarking uses hand-optimized kernel code by default.
You can use it in your cracking session by setting the -O option.
Note: Using optimized kernel code limits the maximum supported password length.
To disable the optimized kernel code in benchmark mode, use the -w option.
OpenCL Platform #1: Advanced Micro Devices, Inc.
================================================
* Device #1: Ellesmere, 3264/4096 MB allocatable, 36MCU
Benchmark relevant options:
===========================
* --optimized-kernel-enable
Hashmode: 2500 - WPA-EAPOL-PBKDF2 (Iterations: 4096)
* Device #1: ATTENTION! OpenCL kernel self-test failed.
Your device driver installation is probably broken.
See also: https://hashcat.net/faq/wrongdriver
Speed.#1.........: 179.3 kH/s (87.14ms) # Accel:128 Loops:64 Thr:256 Vec:1
Started: Mon Mar 18 19:05:55 2019
Stopped: Mon Mar 18 19:06:26 2019
PS D:\crack\hashcat-5.1.0>
Then I used the --self-test-disable option and it started . I have also created a post in the hashcat forum : https://hashcat.net/forum/thread-8226-post-44141.html#pid44141 in case anyone is interested .

How to set KVM VM use shadow page table?

I want to measure shadow page table performance vs EPT. I know in kvm code path, EPT and shadow page table share some code path. There is a switch to check if EPT is enabled.
So, I turn off EPT, I think this is a way to use shadow page table in KVM VM.
I exec some commands on host:
# cat /sys/module/kvm_intel/parameters/ept
Y //check if EPT is enabled, Yes it is
# rmmod kvm_intel
# modprobe kvm_intel ept=0,vpid=0 //Re-modprobe kvm_intel, but turn off EPT and VPID
# cat /sys/module/kvm_intel/parameters/ept
N // EPT is disabled
# cat /sys/module/kvm_intel/parameters/vpid
Y //VPID is still enabled
After these commads, I expect the EPT is disabled, However, I create a VM with 4 vcpu, but in VM, I use htop in VM only find i vcpu. I don't know why.
So, I turn on ept again, I can see 4 vcpu in vm using htop. But, on another server, I turn off ept, in VM, I still can find 4 vcpu.
In host, I test qemu thread num:
pstree -p | grep qemu
|-qemu-kvm(20594)-+-{qemu-kvm}(20612)
| |-{qemu-kvm}(20613)
| |-{qemu-kvm}(20614)
| |-{qemu-kvm}(20615)
| |-{qemu-kvm}(20618)
| `-{qemu-kvm}(23429)
There are still muti threads.
In KVM VM, I use lscpu to check:
# lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 4
On-line CPU(s) list: 0
Off-line CPU(s) list: 1-3
Thread(s) per core: 1
Core(s) per socket: 1
座: 1
NUMA 节点: 1
厂商 ID: GenuineIntel
CPU 系列: 6
型号: 62
型号名称: Intel(R) Xeon(R) CPU E5-2640 v2 # 2.00GHz
步进: 4
CPU MHz: 1999.999
BogoMIPS: 3999.99
超管理器厂商: KVM
虚拟化类型: 完全
L1d 缓存: 32K
L1i 缓存: 32K
L2 缓存: 4096K
NUMA 节点0 CPU: 0
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl eagerfpu pni pclmulqdq ssse3 cx16 pcid sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm fsgsbase tsc_adjust smep erms xsaveopt
VPID is still enabled cause your command format was incorrect
# modprobe kvm_intel ept=0 vpid=0(Use spaces instead of commas)

How to build FLAT userspace binary for ucLinux on buildroot with arm2010q1 toolchain

I have a buildroot system for cortex-M3 without MMU based on ucLinux kernel 2.6.33. Support for FLAT, ZFLAT, SHARED_FLAT enabled in kernel.
Inside buildroot everything is set to M3 etc.
I have working system with working kernel and busybox (which is only ok binary in userspace). There are no uClibc on system or any other libs.
I'm trying to build simplest userspace app like this: main(){}
I tried with different flags. Latest combination was like this:
^[[7m>>> zpm_t 1.0 Building^[[27m
/usr/bin/make -j5 FLAGS="-c -mthumb -march=armv7 -mfix-cortex-m3-ldrd" EXTRA_LDFLAGS="-Wl,-elf2flt,--static" CC="/mnt/repos/repos/github/nocturn_buildroot/output/host/usr/bin/ccache /mnt/repos/repos/github/nocturn_buildroot/output/host/usr/bin/arm-uclinuxeabi-gcc" LD="/mnt/repos/repos/github/nocturn_buildroot/output/host/usr/bin/arm-uclinuxeabi-ld" HEADERS="-I/mnt/repos/repos/github/nocturn_buildroot/output/target/usr/include/SDL" LIBS="-L/mnt/repos/repos/github/nocturn_buildroot/../nocturn_tools/arm-2010q1/arm-uclinuxeabi/libc/usr/lib" -C /mnt/repos/repos/github/nocturn_buildroot/output/build/zpm_t-1.0 all
make[1]: Entering directory /mnt/repos/repos/github/nocturn_buildroot/output/build/zpm_t-1.0'
/mnt/repos/repos/github/nocturn_buildroot/output/host/usr/bin/ccache /mnt/repos/repos/github/nocturn_buildroot/output/host/usr/bin/arm-uclinuxeabi-gcc -c -mthumb -march=armv7 -mfix-cortex-m3-ldrd -I/mnt/repos/repos/github/nocturn_buildroot/output/target/usr/include/SDL t.c
/mnt/repos/repos/github/nocturn_buildroot/output/host/usr/bin/ccache /mnt/repos/repos/github/nocturn_buildroot/output/host/usr/bin/arm-uclinuxeabi-gcc -Wl,-elf2flt,--static t.o -L/mnt/repos/repos/github/nocturn_buildroot/../nocturn_tools/arm-2010q1/arm-uclinuxeabi/libc/usr/lib -o t
make[1]: Leaving directory/mnt/repos/repos/github/nocturn_buildroot/output/build/zpm_t-1.0'
flat file seems to be ok:
$ arm-uclinuxeabi-flthdr output/target/opt/t
output/target/opt/t
Magic: bFLT
Rev: 4
Build Date: Wed Sep 24 00:28:31 2014
Entry: 0x45
Data Start: 0x1f00
Data End: 0x1f70
BSS End: 0x1fa0
Stack Size: 0x1000
Reloc Start: 0x1f70
Reloc Count: 0x29
Flags: 0x1 ( Load-to-Ram )
But on system I always have a segfault which is not so informative:
/opt # ./t
[ 23.200000]
[ 23.200000]
[ 23.200000] t: fault at 0xa0501dd4 [pc=0xa0501dd4, sp=0xa0503f28]
[ 23.200000] Invalid ISA state
[ 23.200000]
SEGV
What did I miss? It should be something very simple. Also - what to do with uClibc? Should it be compiled into every binary executable or should I place it on the system somehow?
I have linked my app with wrong library. I had to take pre-built one from thumb2 folder inside toolchain (for M3):
LIBS="-L$(TOPDIR)/../tools/arm-2010q1/arm-uclinuxeabi/libc/thumb2/usr/lib"
Just fixing it helps. As I have libc.a and libm.a as static archives - just fixing LIBS is enough. And no flags like -lm needed. During buildroot compilation it takes needed part of static libs and creates a working FLAT binary.

readelf: Error: Not an ELF file - it has the wrong magic bytes at the start

I build a program and it works well(I mean that I can run this program). But when I use "readelf" to check whether there is debug information,errors come:
readelf: Error: Not an ELF file - it has the wrong magic bytes at the start
readelf: Error: test/select: Failed to read file header
My linux distribution is Ubuntu-12. Somebody can help me?
It may not actually be an ELF executable file. There are plenty of things that will run that are not ELF files (such as shell scripts, Perl files, Python py source and pyc compiled files). There are even things that will "run" without having an individual identifiable file at all (aliases or functions in your shell, bash built-ins and such).
I would first execute:
file /path/to/your/file
to see what sort of file it actually is, such as with:
pax> file /bin/ls
/bin/ls: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV),
dynamically linked (uses shared libs), for GNU/Linux 2.6.26,
BuildID[sha1]=0xd3280633faaabf56a14a26693d2f810a32222e51,
stripped
Only if it's recognised as an ELF file should you try to treat it as such.
pax> readelf -h /bin/ls
ELF Header:
Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00
Class: ELF32
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: EXEC (Executable file)
Machine: Intel 80386
Version: 0x1
Entry point address: 0x804c1b4
Start of program headers: 52 (bytes into file)
Start of section headers: 111580 (bytes into file)
Flags: 0x0
Size of this header: 52 (bytes)
Size of program headers: 32 (bytes)
Number of program headers: 9
Size of section headers: 40 (bytes)
Number of section headers: 28
Section header string table index: 27
For what it's worth, I have a backup script which executes just fine but which would fail your readelf assumption:
pax> file backup1.sh
backup1.sh: Bourne-Again shell script, ASCII text executable
pax> readelf -h backup1.sh
readelf: Error: Unable to read in 0x253a bytes of section headers
readelf: Error: Not an ELF file - it has the wrong magic bytes at the start
As to what you do when you find out it isn't ELF format, that depends on what you're trying to ascertain, something you haven't actually specified. If all you want to do is run readelf on it, that won't work unless it's an ELF format file.
If you want a particular piece of information about the executable file, you need to tell us both:
what type it is (from file for example); and
the information you want.