add tool to enter vpn
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
#define _GNU_SOURCE
|
||||
|
||||
#include <sched.h>
|
||||
#include <fcntl.h>
|
||||
#include <pwd.h>
|
||||
#include <sched.h>
|
||||
#include <stdio.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main() {
|
||||
char shell[128] = {0};
|
||||
@@ -17,20 +17,20 @@ int main() {
|
||||
|
||||
int fd = open("/run/vpn/net", 0);
|
||||
|
||||
if(fd > 0) {
|
||||
if (fd > 0) {
|
||||
int failure = setns(fd, CLONE_NEWNET);
|
||||
if(failure) {
|
||||
if (failure) {
|
||||
perror("setns /run/vpn/net");
|
||||
}
|
||||
close(fd);
|
||||
if(failure) {
|
||||
if (failure) {
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
perror("open /run/vpn/net");
|
||||
return 1;
|
||||
}
|
||||
execl(shell, shell, NULL);
|
||||
execl("csshell", "bshell", NULL);
|
||||
perror(NULL);
|
||||
return 0;
|
||||
}
|
||||
|
@@ -4,21 +4,21 @@ extern int override_socket(int domain, int type, int protocol);
|
||||
extern int override_setns(int fd, int nstype);
|
||||
|
||||
int socket(int domain, int type, int protocol) {
|
||||
if(domain > 15) {
|
||||
if (domain > 15) {
|
||||
return override_socket(domain, type, protocol);
|
||||
}
|
||||
int fda = override_open("/proc/1/ns/net", 0);
|
||||
int fdb = override_open("/run/netns/vpn", 0);
|
||||
int retval = 0;
|
||||
|
||||
if(fda > 0) {
|
||||
if (fda > 0) {
|
||||
override_setns(fda, 0);
|
||||
override_close(fda);
|
||||
}
|
||||
|
||||
retval = override_socket(domain, type, protocol);
|
||||
|
||||
if(fdb > 0) {
|
||||
if (fdb > 0) {
|
||||
override_setns(fdb, 0);
|
||||
override_close(fdb);
|
||||
}
|
||||
|
@@ -1,19 +1,19 @@
|
||||
#include <sys/mount.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/mount.h>
|
||||
#include <systemd/sd-daemon.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int main() {
|
||||
char mount_path[32] = {0};
|
||||
snprintf(mount_path, sizeof(mount_path), "/proc/%d/ns", getpid());
|
||||
|
||||
int err = mount(mount_path, "/run/vpn", NULL, MS_BIND, NULL);
|
||||
if(err) {
|
||||
if (err) {
|
||||
perror("Error");
|
||||
return 1;
|
||||
}
|
||||
sd_notify(0, "READY=1");
|
||||
while(1) {
|
||||
while (1) {
|
||||
sleep(10);
|
||||
}
|
||||
return 1;
|
||||
|
Reference in New Issue
Block a user