Last active
May 7, 2020 18:05
-
-
Save v3rlly/1a599c379c4ca0b113efc302b5ba6b0e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
# "sandbox" account to drop network traffic in linux programs | |
# tested on ubuntu 19.10 | |
# ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ | |
# ------------------------------------------------------------------------- | |
# 1. Create a user group that should receive the firewall rule | |
# ------------------------------------------------------------------------- | |
# 'password' is the group password | |
# 'offline' is the name of the group | |
$ sudo groupadd -p password offline | |
# check that the group has been created | |
$ cat /etc/group | grep offline | |
# ------------------------------------------------------------------------- | |
# 2. create a user to run the programs without an internet connection | |
# ------------------------------------------------------------------------- | |
# -m => create the user folder | |
# -g => add user to a group | |
# 'offline' => group | 'off' => user | |
$ sudo useradd -m -g offline off | |
# set a password for the created user | |
$ sudo passwd off | |
# ------------------------------------------------------------------------- | |
# 3. allows the 'off' user to access the running X server | |
# ------------------------------------------------------------------------- | |
$ sudo xhost local:off | |
# ------------------------------------------------------------------------- | |
# 4. Create a rule that drop network traffic for the user group 'offline' | |
# ------------------------------------------------------------------------- | |
$ sudo iptables -I OUTPUT 1 -m owner --gid-owner offline -j DROP | |
# ------------------------------------------------------------------------- | |
# 5. run a program this way => su off -c COMAND | |
# ------------------------------------------------------------------------- | |
# examples | |
$ su off -c firefox | |
# su off -c "python /home/off/codes/hello.py" | |
# su off -c "python /home/off/codes/hello.py" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment