Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #/!/bin/bash
- # Provide internet to namespace, chroot, start ssh, rdp server.
- #WLAN="wlp2s0" #laptop?
- #WLAN="wlxe84e0624e2a4" #HOME
- WLAN="wlx20e116000c9c" #Office Wifi
- NS=ns0
- IFIN=ifin0
- IFOUT=ifout0
- chroot_dir="/home/debian" # Chroot Dir
- IP="10.10.10"
- IFOUT_IP=$IP.101
- IFIN_IP=$IP.102
- #WLAN_IP=$IP.200
- #:::::::::::::::::::::::::::::::::::::::::::::::
- #set sudo session
- echo "password" | sudo -S echo "Password authenticated."
- # Remove IFNAME / Flush var etc.
- sudo ip netns delete $NS 2>&1 &
- sudo ip link del $IFOUT 2>&1 &
- sudo umount $chroot_dir/proc 2>&1 &
- sudo umount $chroot_dir/dev 2>&1 &
- #::::::::::::::::::::::::::::::::::::::::::::::::
- # Add NS
- sudo ip netns add $NS
- # Add peer veth
- sudo ip link add $IFOUT type veth peer name $IFIN
- #::::::::::::::::::::::::::::::::::::::::::::::::::
- # Set NS to IF IN
- sudo ip link set $IFIN netns $NS
- sudo ip netns exec $NS ip link set lo up
- #:::::::::::::::::::::::::::::::::::::::::::::::::
- #SET IP
- set_ip(){
- sudo ip link set $1 down
- sudo ip addr add $2/24 dev $1
- sudo ip link set $1 up
- }
- # Set IF IP
- set_ip $IFOUT $IFOUT_IP
- set_ip $WLAN $WLAN_IP
- sudo ip netns exec $NS ip link set $IFIN down
- sudo ip netns exec $NS ip addr add $IFIN_IP/24 dev $IFIN
- #sudo ip netns exec $NS ip set $IFIN name eth0
- sudo ip netns exec $NS ip link set $IFIN up
- #::::::::::::::::::::::::::::::::::::::::::::::::::
- # Route rule
- sudo ip netns exec $NS ip route add default via $IFOUT_IP
- #sudo echo 1 > /proc/sys/net/ipv4/ip_forward
- # Flush ip rules
- sudo iptables -P FORWARD DROP
- sudo iptables -F FORWARD
- sudo iptables -t nat -F
- # Set iptables rules #forwarding
- sudo iptables -t nat -A POSTROUTING -s $IFIN_IP/24 -o $WLAN -j MASQUERADE
- sudo iptables -A FORWARD -i $WLAN -o $IFOUT -j ACCEPT
- sudo iptables -A FORWARD -o $WLAN -i $IFOUT -j ACCEPT
- #:::::::::::::::::::::::::::::::::::::::::::::::::::::::
- # Check
- ping_alive(){ echo -e "`sudo ip netns exec $1 fping $2` ( $3 )" ; }
- ping_alive $NS $IFOUT_IP IF_OUT
- ping_alive $NS $IFIN_IP IF_IN
- #ping_alive $NS $WLAN_IP WIFI
- ping_alive $NS 1.1.1.1 Internet
- #::::::::::::::::::::::::::::::::::::::::::::::::::::::
- #Prepare & Chroot
- sudo mount -t proc /proc $chroot_dir/proc
- sudo mount --rbind /dev $chroot_dir/dev
- sudo mount -t devpts /dev/pts $chroot_dir/dev/pts
- sudo mount --rbind /home/user $chroot_dir/home/user
- #display=':10'
- #export DISPLAY=:10
- #screen_resolution=$( xrandr | grep ' connected' | awk '{print $4}' ) ;
- #echo "Entering chroot environment."
- sudo ip netns exec $NS /usr/sbin/chroot $chroot_dir /etc/init.d/ssh start
- sudo ip netns exec $NS /usr/sbin/chroot $chroot_dir /etc/init.d/xrdp restart
- #sudo ip netns exec $NS /usr/sbin/chroot $chroot_dir /usr/bin/bash
- #sudo ip netns exec $NS /usr/sbin/chroot $chroot_dir echo $DISPLAY
- #echo $screen_resolution ;
- #Xnest -ac -geometry $screen_resolution :10 > /dev/null 2>&1 &
- #/usr/bin/wmctrl -r Xnest -b toggle,fullscreen &
- #sudo ip netns exec $NS /usr/sbin/chroot $chroot_dir sudo -u user mate-session
- #echo -e "nameserver 1.1.1.1\nnameserver 8.8.8.8" >> /etc/resolv.conf
- #echo "127.0.0.1 HOSTNAME" >> /etc/hosts
- #/etc/init.d/ssh start
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement