NCTU
, Unix Programming
, API hijacking
, library injection
, GitHub
$ make
gcc -g -fPIC -shared -o sandbox.so sandboxso.c -ldl
gcc -g -o sandbox sandbox.c
$ ./sandbox
no command given.
$ ./sandbox -h
usage: ./sandbox [-h] [-p sopath] [-d basedir] [--] cmd [cmd args ...]
-h: this help text
-p: set the path to sandbox.so, default = ./sandbox.so
-d: the base directory that is allowed to access, default = .
--: separate the arguments for sandbox and for the executed command
$ ls
Makefile README.md sandbox sandbox.c sandbox.so sandboxso.c
$ ./sandbox ls
[sandbox] fopen: access to /proc/filesystems is not allowed
[sandbox] fopen: access to /proc/mounts is not allowed
Makefile README.md sandbox sandbox.c sandbox.so sandboxso.c
$ ./sandbox ls -a
./sandbox: invalid option -- 'a'
usage: ./sandbox [-h] [-p sopath] [-d basedir] [--] cmd [cmd args ...]
-h: this help text
-p: set the path to sandbox.so, default = ./sandbox.so
-d: the base directory that is allowed to access, default = .
--: separate the arguments for sandbox and for the executed command
$ ./sandbox -- ls -a
[sandbox] fopen: access to /proc/filesystems is not allowed
[sandbox] fopen: access to /proc/mounts is not allowed
. .. Makefile README.md sandbox sandbox.c sandbox.so sandboxso.c
$ ls /
addons cdrom etc initrd.img.old lib64 media platforms run srv usr vmlinuz.old
bin cfg home lib libx32 mnt proc sbin sys var
boot dev initrd.img lib32 lost+found opt root snap tmp vmlinuz
$ ./sandbox -- ls /
[sandbox] fopen: access to /proc/filesystems is not allowed
[sandbox] fopen: access to /proc/mounts is not allowed
[sandbox] __xstat: access to / is not allowed
[sandbox] opendir: access to / is not allowed
ls: cannot open directory '/'
$ ./sandbox -d / ls /
addons cdrom etc initrd.img.old lib64 media platforms run srv usr vmlinuz.old
bin cfg home lib libx32 mnt proc sbin sys var
boot dev initrd.img lib32 lost+found opt root snap tmp vmlinuz
$ ./sandbox -- ls -la / Makefile
[sandbox] fopen: access to /proc/filesystems is not allowed
[sandbox] fopen: access to /proc/mounts is not allowed
[sandbox] fopen: access to /etc/passwd is not allowed
[sandbox] fopen: access to /etc/group is not allowed
[sandbox] fopen: access to /etc/passwd is not allowed
[sandbox] fopen: access to /etc/group is not allowed
-rw-rw-r-- 1 1000 1000 435 5月 10 14:13 Makefile
[sandbox] opendir: access to / is not allowed
ls: cannot open directory '/'
$ ./sandbox -- ls -la / Makefile >/dev/null
[sandbox] fopen: access to /proc/filesystems is not allowed
[sandbox] fopen: access to /proc/mounts is not allowed
[sandbox] fopen: access to /etc/passwd is not allowed
[sandbox] fopen: access to /etc/group is not allowed
[sandbox] fopen: access to /etc/passwd is not allowed
[sandbox] fopen: access to /etc/group is not allowed
[sandbox] opendir: access to / is not allowed
ls: cannot open directory '/'
$ ./sandbox -- ls -la / Makefile >/dev/null 2>&1
[sandbox] fopen: access to /proc/filesystems is not allowed
[sandbox] fopen: access to /proc/mounts is not allowed
[sandbox] fopen: access to /etc/passwd is not allowed
[sandbox] fopen: access to /etc/group is not allowed
[sandbox] fopen: access to /etc/passwd is not allowed
[sandbox] fopen: access to /etc/group is not allowed
[sandbox] opendir: access to / is not allowed
$ ./sandbox -- sh -c 'ls'
[sandbox] __xstat64: access to /home/swchiu/.local/bin/ls is not allowed
[sandbox] __xstat64: access to /usr/local/sbin/ls is not allowed
[sandbox] __xstat64: access to /usr/local/bin/ls is not allowed
[sandbox] __xstat64: access to /usr/sbin/ls is not allowed
[sandbox] __xstat64: access to /usr/bin/ls is not allowed
[sandbox] __xstat64: access to /sbin/ls is not allowed
[sandbox] __xstat64: access to /bin/ls is not allowed
[sandbox] __xstat64: access to /usr/games/ls is not allowed
[sandbox] __xstat64: access to /usr/local/games/ls is not allowed
[sandbox] __xstat64: access to /snap/bin/ls is not allowed
sh: 1: ls: not found
The return value of each rejected functions is -1
or NULL
depends on the return type of the rejected function.
Besides, the errno
of them are always set to EACCES
.
chdir
chmod
chown
creat
fopen
link
mkdir
open
open64
openat
opendir
readlink
remove
rename
rmdir
stat
__xstat
and __xsata64
symlink
unlink
execl
execle
execlp
execv
execve
execvp
system
School: National Chiao Tung University Name: Shao-Wei Chiu 2020 spring Hw5 Hw6 Hw7
Mar 10, 2022contributed by < rwe0214 > CS:APP Ch10 System-level I/O Unix 中的 file 是一序列的 bytes 所組成,所有的 I/O ( e.g. networks, disks, terminals, ... ) 皆 model as file。 因為這樣 Unix kernel 就可提供一個simple, low-level application interface ( Unix I/O ),達到驅動所有 I/O 一個統一和方便的方法。 10.4 Robust Reading and Writing with the Rio Package 因為 read 和 write 的回傳值為已讀寫完的 bytes 數量,但在連線不穩定(例如網路 socket connect 等等)的情況下,不一定只執行一次 read/write 就可達到預期讀寫完 n bytes 的結果( i.e. short count > 0 ),所以需要基於使用 read/write 來設計更穩定的 I/O function,可分成 unbuffered 和 buffered 兩種。 Unbuffered I/O Function
Apr 27, 2021School: National Chiao Tung University Name: Shao-Wei ( Willy ) Chiu Note: This report was made on Hackmd.io and restricted by the .pdf format, the .gif animation would not display. Please view it on https://hackmd.io/@swchiu/SJQehejA8, thanks. PCA / LDA When dataset's feature space grows into very high dimensions, there would be some useless feature. We prefer to extract the more important features for our dataset. let $$
Dec 30, 2020School: National Chiao Tung University Name: Shao-Wei Chiu Note: This report was made on Hackmd.io and restricted by the .pdf format, the .gif animation would not display. Please view it on https://hackmd.io/@swchiu/BJwOjuc3U, thanks. Kernel K-means Kernel k-means is an approach to k-means algorithm, but mapping the data into higher degree dimentions. And the mapping-function called Kernel. K-means algorithm is that after comparing the data similarity, we cluster the more similarity datas to the same group.
Dec 30, 2020or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up