Table des matières
- 2026:
- 2025:
12 billet(s) pour novembre 2026
| Notes conversion JSON YAML | 2026/11/13 11:16 | Jean-Baptiste |
| Git commit perdu | 2026/11/12 18:16 | Jean-Baptiste |
| Notes mojo lang | 2026/11/11 20:34 | Jean-Baptiste |
| Notes rust lang compilation | 2026/11/11 18:35 | Jean-Baptiste |
| Mémoire VSIZE VMSIZE SEGV lang C | 2026/11/11 15:59 | Jean-Baptiste |
| Ansible-navigator utilisation de ansible-vault | 2026/11/06 11:33 | Jean-Baptiste |
| Err Ansible - Module result deserialization failed No start of json char found | 2026/11/06 09:09 | Jean-Baptiste |
| Script Python conversion JSON vers CSV | 2026/11/06 08:14 | Jean-Baptiste |
| Filter Incoming IPv4 Packets Containing IP Options - cve-2026-98432 mitigation - Kernel TCP Use-After-Free | 2026/11/04 21:04 | Jean-Baptiste |
| Notes ZFS | 2026/11/03 18:04 | Jean-Baptiste |
| Diff image container | 2026/11/03 16:30 | Jean-Baptiste |
| Notes processus multi-thread | 2026/11/03 10:59 | Jean-Baptiste |
script - subshells sous-shells - comportement déroutant de bash qu'un débutant doit connaître
Voir :
Exemple variable globale
Exemple bash de problème d'affectation de variable globale
test_gvar1.sh
#! /bin/bash VAR=0 func_1() { echo Hello VAR=4 } echo $VAR echo $(func_1) echo $VAR
$ ./test_gvar1.sh 0 Hello 0
Alors que
test_gvar2.sh
#! /bin/bash VAR=0 func_1() { echo Hello VAR=4 } echo $VAR func_1 echo $VAR
$ ./test_gvar2.sh 0 Hello 4
Dans le 1er exemple la variable n'est pas affectée par la fonction. En effet avec $(nom_de_fonction) bash lance un autre bash et copie la fonction, puis retourne le résultat au bash père.
De cette manière il est impossible par exemple d'implémenter un compteur qui compterait le nombre de fois que la fonction est appelée.
Bien sûr il est possible à la place de faire :
echo "Fonction func appelée à $(date --rfc-3339=second)" >> /tmp/trace.log
Mais ce n'est pas terrible
Voici une solution :
#! /bin/bash VAR=0 func_1() { echo Hello VAR=4 } echo $VAR echo "${ func_1; }" echo $VAR
Autre solution : Utiliser les pointeurs en bash !
#! /bin/bash VAR=0 func_1() { declare -n -x VAR_ref=$1 VAR_ref=4 } echo $VAR func_1 VAR echo $VAR
Exemple de commande exit qui semble ignorée
test_exit1.sh
#! /bin/bash funcA() { echo A echo $(funcB) } funcB() { echo B exit 13 } funcA echo Suite du script
Il est possible de remplacer echo $(funcB) par echo ${ funcB; } mais la sortie de la fonction n'est pas affichée sur la sortie standard
$ ./test_exit1.sh A B Suite du script $ echo $? 0
Alors que :
test_exit2.sh
#! /bin/bash funcA() { echo A funcB } funcB() { echo B exit 13 } funcA echo Suite du script
$ ./test_exit2.sh A B $ echo $? 13
Exemple solution contournement
Une solution simple consiste à ajouter un trap et de remplacer la commande exit par la commande kill $$
test_exit3.sh
#! /bin/bash trap 'exit 13' SIGUSR1 funcA() { echo A echo $(funcB) } funcB() { echo B # exit 13 kill -s SIGUSR1 $$ } funcA echo Suite du script
$ ./test_exit3.sh A B
Autres
Affecter une variable sans créer de sous-shell
echo 'hello' | { read msg; echo "$msg"; }
Go lang - compiler pour windows i386 32bits
Voir aussi :
- Purego - A library for calling C functions from Go without Cgo.
sudo apt-get install gcc-multilib-i686-linux-gnu export GOROOT=$HOME/opt/go-legacy-win7/ export PATH=$HOME/opt/go-legacy-win7/bin/:"$PATH" env GOOS=windows GOARCH=386 CGO_ENABLED=1 CC=i686-w64-mingw32-gcc CXX=i686-w64-mingw32-g++ CGO_LDFLAGS="-lssp" go build -ldflags="-s -w" -o app1.exe main.go
Ou encore avec zig
env CGO_ENABLED=1 GOROOT=~/opt/go-legacy-win7/ GOOS=windows GOARCH=386 CC="zig cc -target i686-linux-musl" ~/opt/go-legacy-win7/bin/go build hello.go
: i686-linux-musl n'est pas cohérent avec GOOS
Test
mkdir -p ~/myapp/prefix export WINEPREFIX=$HOME/myapp/prefix export WINEARCH=win32 export WINEPATH=$HOME/myapp wineboot --init env WINEARCH=win32 wine app1.exe
$ exiftool app1.exe ExifTool Version Number : 13.50 File Name : app1.exe Directory : . File Size : 1266 kB File Modification Date/Time : 2026:04:23 19:18:49+02:00 File Access Date/Time : 2026:04:23 19:19:08+02:00 File Inode Change Date/Time : 2026:04:23 19:18:49+02:00 File Permissions : -rwxrwxr-x File Type : Win32 EXE File Type Extension : exe MIME Type : application/octet-stream Machine Type : Intel 386 or later, and compatibles Time Stamp : 0000:00:00 00:00:00 Image File Characteristics : Executable, No line numbers, No symbols, 32-bit, No debug PE Type : PE32 Linker Version : 2.45 Code Size : 571904 Initialized Data Size : 693248 Uninitialized Data Size : 154624 Entry Point : 0x1460 OS Version : 6.1 Image Version : 1.0 Subsystem Version : 6.1 Subsystem : Windows command line
Réseau - Forger un paquet TCP UDP ou autre
Voir les outils :
- hping3
- tcpreplay tcprewrite
- scapy
To exclude packets 1, 5, 10 to 20 and 30 to 40 from the new file use:
editcap capture.pcapng exclude.pcapng 1 5 10-20 30-40
To select just packets 1, 5, 10 to 20 and 30 to 40 for the new file use:
editcap -r capture.pcapng select.pcapng 1 5 10-20 30-40
Source : https://www.wireshark.org/docs/man-pages/editcap.html
Les modifications d'adresses de tcprewrite se font par plage. Pour changer l'adresse de destination
tcprewrite --dstipmap=10.170.24.203/0:10.0.1.113/0 -C -i filter.cap -o filter-2.cap
le -C est là pour recalculer les checksums UDP ou TCP
Wine Err bcryptprimitives.dll not found - Compilation Croisée Go lang
Étapes à reproduire
Source : https://d3ext.github.io/posts/malware-dev-0/
main.go
package main import ( "fmt" "unsafe" "golang.org/x/sys/windows" ) func main() { user32 := windows.NewLazyDLL("user32.dll") MessageBox := user32.NewProc("MessageBoxW") r, _, _ := MessageBox.Call( 0, uintptr(unsafe.Pointer(windows.StringToUTF16Ptr("Hello World!"))), uintptr(unsafe.Pointer(windows.StringToUTF16Ptr("Example"))), windows.MB_OK, ) fmt.Println("Return code:", r) }
env GOARCH=amd64 GOOS=windows go build main.go
Erreur
$ wine main.exe
it looks like wine32 is missing, you should install it.
multiarch needs to be enabled first. as root, please
execute "dpkg --add-architecture i386 && apt-get update &&
apt-get install wine32:i386"
wine: created the configuration directory '/home/jibe/.wine'
0050:err:ole:StdMarshalImpl_MarshalInterface Failed to create ifstub, hr 0x80004002
0050:err:ole:CoMarshalInterface Failed to marshal the interface {6d5140c1-7436-11ce-8034-00aa006009fa}, hr 0x80004002
0050:err:ole:apartment_get_local_server_stream Failed: 0x80004002
0050:err:ole:start_rpcss Failed to open RpcSs service
0048:err:ole:StdMarshalImpl_MarshalInterface Failed to create ifstub, hr 0x80004002
0048:err:ole:CoMarshalInterface Failed to marshal the interface {6d5140c1-7436-11ce-8034-00aa006009fa}, hr 0x80004002
0048:err:ole:apartment_get_local_server_stream Failed: 0x80004002
wine: failed to open L"C:\\windows\\syswow64\\rundll32.exe": c0000135
wine: configuration in L"/home/jibe/.wine" has been updated.
fatal error: bcryptprimitives.dll not found
runtime: panic before malloc heap initialized
runtime stack:
runtime.throw({0x1400e5c03?, 0x21fd58?})
/usr/lib/go-1.26/src/runtime/panic.go:1229 +0x4d fp=0x21fca8 sp=0x21fc78 pc=0x140076fad
runtime.loadOptionalSyscalls()
/usr/lib/go-1.26/src/runtime/os_windows.go:267 +0x349 fp=0x21fd90 sp=0x21fca8 pc=0x140041229
runtime.osinit()
/usr/lib/go-1.26/src/runtime/os_windows.go:464 +0x3d fp=0x21fe10 sp=0x21fd90 pc=0x14004193d
runtime.rt0_go()
/usr/lib/go-1.26/src/runtime/asm_amd64.s:372 +0x13e fp=0x21fe18 sp=0x21fe10 pc=0x14007b2be
$ env WINEARCH=win64 wine main.exe wine: could not load kernel32.dll, status c0000135 $ mkdir -p ~/myapp/prefix $ env LANG=C WINEPREFIX=$HOME/myapp/prefix WINEARCH=win32 wine main.exe Application could not be started, or no application associated with the specified file. ShellExecuteEx failed: Bad EXE format for Z:\home\jibe\go\winapi\main.exe.
Solution 1
Voir :
Utiliser une ancienne version de Go ou une recompilée pour être compatible avec windows 7 Comme : https://github.com/thongtech/go-legacy-win7
export GOROOT=~/opt/go-legacy-win7/ alias go='~/opt/go-legacy-win7/bin/go' go env |grep '/' rm -rf ~/.cache/go-build go clean -cache -modcache -fuzzcache env GOARCH=amd64 GOOS=windows GOROOT=~/opt/go-legacy-win7/ ~/opt/go-legacy-win7/bin/go build main.go
Solution 2
Patcher le exe avec GoWin7Fixer.exe. Voir : https://github.com/stunndard/golangwin7patch
Solution 3
Mettre à jour Wine
Ou télécharger bcryptprimitives.dll et la déposer dans ~/.wine/drive_c/windows/system32/
Voir : https://packages.debian.org/trixie/amd64/libwine/filelist
Makefile et variables d'environnement
Makefile
include env exe: go build -o app1.exe main.go dll: go build -buildmode=c-shared -o app1.dll main.go clean: rm -f app1.exe app1.dll app1.h call.exe all: exe dll test: exe dll go build call.go wine call.exe
env
cat env export GOOS=windows export GOARCH=amd64 export CGO_ENABLED=1 export CXX=x86_64-w64-mingw32-g++ export CC=x86_64-w64-mingw32-gcc export GOROOT=$(shell printenv HOME)/opt/go-legacy-win7/ export PATH=$(shell printenv HOME)/opt/go-legacy-win7/bin/:$(shell printenv PATH)
