{"id":20648543,"url":"https://github.com/linuxthor/sixnix","last_synced_at":"2025-04-16T14:53:54.865Z","repository":{"id":19988748,"uuid":"23255973","full_name":"linuxthor/sixnix","owner":"linuxthor","description":"Multifarious x86-64 ELF binary that can be built once and run on six different *nix variants. Behaves differently if running on Linux, BSD or SunOS","archived":false,"fork":false,"pushed_at":"2014-08-23T13:24:49.000Z","size":144,"stargazers_count":14,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-03-29T05:24:06.156Z","etag":null,"topics":["assembly","assembly-language","elf","freebsd","linux","netbsd","openbsd","openindiana"],"latest_commit_sha":null,"homepage":"","language":"Assembly","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/linuxthor.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-08-23T13:07:51.000Z","updated_at":"2024-11-03T23:48:45.000Z","dependencies_parsed_at":"2022-07-22T03:31:59.418Z","dependency_job_id":null,"html_url":"https://github.com/linuxthor/sixnix","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linuxthor%2Fsixnix","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linuxthor%2Fsixnix/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linuxthor%2Fsixnix/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linuxthor%2Fsixnix/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/linuxthor","download_url":"https://codeload.github.com/linuxthor/sixnix/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249252526,"owners_count":21238207,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["assembly","assembly-language","elf","freebsd","linux","netbsd","openbsd","openindiana"],"created_at":"2024-11-16T17:09:15.854Z","updated_at":"2025-04-16T14:53:54.848Z","avatar_url":"https://github.com/linuxthor.png","language":"Assembly","readme":"Sixnix\n======\n\nMutifarious and portable *nix assembly \"Hello World\" that runs unmodified on Intel 64 bit \nversions of:\n\n- Linux\n- OpenBSD\n- FreeBSD\n- Dragonfly BSD\n- NetBSD\n- OpenIndiana (SunOS)\n\nAssemble this to make a binary that prints \"Linux\" on x86-64 Linux, \"BSD\" on x86-64 BSD \nvariants and \"SunOS\" on x86-64 Solaris (tested with OpenIndiana). \n\nAs the Linux x86-64 syscalls are numbered differently than BSD or SunOS a simple test is \nused to determine if we're on Linux; Syscall 6 (sys_close on BSD/SunOS and sys_lstat on \nLinux) is called with the first argument being a pointer to the string /proc/self/stat,on \nLinux we get a return code of 0 as the file exists but on BSD/SunOS this is sys_close  with \nan invalid FD so we get -1. \n\nNext we test for SunOS by attempting to chdir into /system, if unsuccessful we can jump to\nthe BSD code. \n\nStructurally the file is a standard ELF x86-64 binary with the addition of two additional \nmandatory secions '.note.openbsd.ident' for OpenBSD and '.note.netbsd.ident' for NetBSD. \nThe OSABI field in the ELF header must also be set to 0x09 (\"FreeBSD\") for FreeBSD to load \nthe file. \n\nAssemble on Linux with:\n```\nnasm -f elf64 -o sixnix.o sixnix.asm\nld -o sixnix sixnix.o\nelfedit --output-oabi FreeBSD sixnix \n\n$ file sixnix\nsixnix: ELF 64-bit LSB executable, x86-64, version 1 (FreeBSD), statically linked, \nfor OpenBSD, for NetBSD 2.0, not stripped\n\n``` \nLinux:\n```\n$ strace ./sixnix \nexecve(\"./sixnix\", [\"./sixnix\"], [/* 28 vars */]) = 0\nlstat(\"/proc/self/stat\", {st_mode=S_IFREG|0444, st_size=0, ...}) = 0\nwrite(1, \"Linux\\n\", 6Linux\n)                  = 6\n_exit(42)                               = ?\n```\nOpenBSD:\n```\n$ kdump                  \n 26458 ktrace   EMUL  \"native\"\n 26458 ktrace   RET   ktrace 0\n 26458 ktrace   CALL  execve(0x7f7ffffdf53f,0x7f7ffffdf448,0x7f7ffffdf458)\n 26458 ktrace   NAMI  \"/tmp/sixnix\"\n 26458 sixnix   EMUL  \"native\"\n 26458 sixnix   RET   execve 0\n 26458 sixnix   CALL  close(0x6001fc)\n 26458 sixnix   RET   close -1 errno 9 Bad file descriptor\n 26458 sixnix   CALL  chdir(0x6001f4)\n 26458 sixnix   NAMI  \"/system\"\n 26458 sixnix   RET   chdir -1 errno 2 No such file or directory\n 26458 sixnix   CALL  write(0x1,0x600212,0x4)\n 26458 sixnix   GIO   fd 1 wrote 4 bytes\n       \"BSD\n       \"\n 26458 sixnix   RET   write 4\n 26458 sixnix   CALL  exit(0x45)\n```\nFreeBSD:\n```\n$ kdump\n   817 ktrace   RET   ktrace 0\n   817 ktrace   CALL  execve(0x7fffffffdde7,0x7fffffffdbc8,0x7fffffffdbd8)\n   817 ktrace   NAMI  \"./sixnix\"\n   817 sixnix   RET   execve 0\n   817 sixnix   CALL  close(0x6001fc)\n   817 sixnix   RET   close -1 errno 9 Bad file descriptor\n   817 sixnix   CALL  chdir(0x6001f4)\n   817 sixnix   NAMI  \"/system\"\n   817 sixnix   RET   chdir -1 errno 2 No such file or directory\n   817 sixnix   CALL  write(0x1,0x600212,0x4)\n   817 sixnix   GIO   fd 1 wrote 4 bytes\n       \"BSD\n       \"\n   817 sixnix   RET   write 4\n   817 sixnix   CALL  exit(0x45)\n```\nDragonflyBSD\n```\n$ kdump\n  810 ktrace   RET   ktrace 0\n  810 ktrace   CALL  execve(0x7ffffffffab7,0x7ffffffff890,0x7ffffffff8a0)\n  810 ktrace   NAMI  \"./sixnix\"\n  810 sixnix   RET   execve 0\n  810 sixnix   CALL  close(0x6001fc)\n  810 sixnix   RET   close -1 errno 9 Bad file descriptor\n  810 sixnix   CALL  chdir(0x6001f4)\n  810 sixnix   NAMI  \"/system\"\n  810 sixnix   RET   chdir -1 errno 2 No such file or directory\n  810 sixnix   CALL  write(0x1,0x600212,0x4)\n  810 sixnix   GIO   fd 1 wrote 4 bytes\n       \"BSD\n       \"\n  810 sixnix   RET   write 4\n  810 sixnix   CALL  exit(0x45)\n```\nNetBSD\n```\n$ kdump\n   106      1 ktrace   EMUL  \"netbsd\"\n   106      1 ktrace   RET   ktrace 0\n   106      1 ktrace   CALL  execve(0x7f7ffffffe57,0x7f7fffffdc90,0x7f7fffffdca0)\n   106      1 ktrace   NAMI  \"./sixnix\"\n   106      1 sixnix   EMUL  \"netbsd\"\n   106      1 sixnix   RET   execve JUSTRETURN\n   106      1 sixnix   CALL  close(0x6001fc)\n   106      1 sixnix   RET   close -1 errno 9 Bad file descriptor\n   106      1 sixnix   CALL  chdir(0x6001f4)\n   106      1 sixnix   NAMI  \"/system\"\n   106      1 sixnix   RET   chdir -1 errno 2 No such file or directory\n   106      1 sixnix   CALL  write(1,0x600212,4)\n   106      1 sixnix   GIO   fd 1 wrote 4 bytes\n       \"BSD\\n\"\n   106      1 sixnix   RET   write 4\n   106      1 sixnix   CALL  exit(0x45)\n```\nOpenIndiana (SunOS): \n```\n$ truss /tmp/sixnix\nexecve(\"/tmp/sixnix\", 0xFFFFFD7FFFDFFDE8, 0xFFFFFD7FFFDFFDF8)  argc = 1\nclose(6291964)                                  Err#9 EBADF\nchdir(\"/system\")                                = 0\nSunOS\nwrite(1, \" S u n O S\\n\", 6)                     = 6\n_exit(69)\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinuxthor%2Fsixnix","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flinuxthor%2Fsixnix","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinuxthor%2Fsixnix/lists"}