Browse Source

tpws : uid option (useful for android)

pull/33/head
bolvan 6 years ago
parent
commit
352f93ced2
  1. BIN
      binaries/aarch64/tpws
  2. BIN
      binaries/armhf/tpws
  3. BIN
      binaries/mips32r1-lsb/tpws
  4. BIN
      binaries/mips32r1-msb/tpws
  5. BIN
      binaries/mips64r2-msb/tpws
  6. BIN
      binaries/ppc/tpws
  7. BIN
      binaries/x86/tpws
  8. BIN
      binaries/x86_64/tpws
  9. 1
      docs/readme.eng.txt
  10. 24
      docs/readme.txt
  11. 74
      tpws/tpws.c

BIN
binaries/aarch64/tpws

Binary file not shown.

BIN
binaries/armhf/tpws

Binary file not shown.

BIN
binaries/mips32r1-lsb/tpws

Binary file not shown.

BIN
binaries/mips32r1-msb/tpws

Binary file not shown.

BIN
binaries/mips64r2-msb/tpws

Binary file not shown.

BIN
binaries/ppc/tpws

Binary file not shown.

BIN
binaries/x86/tpws

Binary file not shown.

BIN
binaries/x86_64/tpws

Binary file not shown.

1
docs/readme.eng.txt

@ -170,6 +170,7 @@ tpws is transparent proxy.
--daemon ; daemonize --daemon ; daemonize
--pidfile=<filename> ; write pid to file --pidfile=<filename> ; write pid to file
--user=<username> ; drop root privs --user=<username> ; drop root privs
--uid=uid[:gid] ; менять uid процесса
The manipulation parameters can be combined in any way. The manipulation parameters can be combined in any way.
There are exceptions: split-pos replaces split-http-req. hostdot and hosttab are mutually exclusive. There are exceptions: split-pos replaces split-http-req. hostdot and hosttab are mutually exclusive.

24
docs/readme.txt

@ -157,6 +157,7 @@ tpws - это transparent proxy.
--daemon ; демонизировать прогу --daemon ; демонизировать прогу
--pidfile=<file> ; сохранить PID в файл --pidfile=<file> ; сохранить PID в файл
--user=<username> ; менять uid процесса --user=<username> ; менять uid процесса
--uid=uid[:gid] ; менять uid процесса
--bind-addr ; на каком адресе слушать. может быть ipv4 или ipv6 адрес. если не указано, то слушает на всех адресах ipv4 и ipv6 --bind-addr ; на каком адресе слушать. может быть ipv4 или ipv6 адрес. если не указано, то слушает на всех адресах ipv4 и ipv6
; если указан ipv6 link local, то требуется указать с какого он интерфейса через --bind-iface6 ; если указан ipv6 link local, то требуется указать с какого он интерфейса через --bind-iface6
--bind-linklocal=prefer|force ; если prefer, то найти link local от iface6. если не найдено - использовать первый адрес любого типа. --bind-linklocal=prefer|force ; если prefer, то найти link local от iface6. если не найдено - использовать первый адрес любого типа.
@ -765,6 +766,29 @@ Openwrt является одной из немногих относительн
--split-pos - единственный параметр, который работает на не-HTTP трафике, все остальное работать не будет. --split-pos - единственный параметр, который работает на не-HTTP трафике, все остальное работать не будет.
Попробуйте, может вам повезет. Попробуйте, может вам повезет.
Android
-------
Без рута забудьте.
Не стоит ждать, что в стоковом ядре будет NFQUEUE или ipset, зато DNAT есть наверняка.
tpws проверен на эмуляторе - он работает.
В android нет /etc/passwd, потому опция --user не будет работать. Вместо нее можно
пользоваться числовыми user id и опцией --uid.
Напишите шелл скрипт с iptables и tpws, запускайте его средствами вашего рут менеджера.
Скрипты автозапуска лежат тут :
magisk : /data/adb/service.d
supersu : /system/su.d
Я не проверял не прибивают ли новые андроиды iptables по своей прихоти в процессе работы
или при подключении/отключении wifi, mobile data, ...
Кто силен в разработке под андроид, думаю будет несложно написать простую програмулину
с выбором опций tpws, которая сможет выбрать tpws нужной архитектуры, запустить его
и добавить iptables. Чтобы была возможность автозапуска (после нее применяем настройки
и сразу exit). И чтобы были кнопки start/stop.
Если кто готов такую програмулину написать - все скажут спасибо.
Тогда любой желающий с рутом сможет парой кликов настроить себе tpws.
Почему стоит вложиться в покупку VPS Почему стоит вложиться в покупку VPS
------------------------------------ ------------------------------------

74
tpws/tpws.c

@ -548,6 +548,7 @@ void exithelp()
" --daemon\t\t\t; daemonize\n" " --daemon\t\t\t; daemonize\n"
" --pidfile=<filename>\t\t; write pid to file\n" " --pidfile=<filename>\t\t; write pid to file\n"
" --user=<username>\t\t; drop root privs\n" " --user=<username>\t\t; drop root privs\n"
" --uid=uid[:gid]\t\t; drop root privs\n"
); );
exit(1); exit(1);
} }
@ -591,19 +592,20 @@ void parse_params(int argc, char *argv[])
{ "port",required_argument,0,0 },// optidx=9 { "port",required_argument,0,0 },// optidx=9
{ "daemon",no_argument,0,0 },// optidx=10 { "daemon",no_argument,0,0 },// optidx=10
{ "user",required_argument,0,0 },// optidx=11 { "user",required_argument,0,0 },// optidx=11
{ "maxconn",required_argument,0,0 },// optidx=12 { "uid",required_argument,0,0 },// optidx=12
{ "hostcase",no_argument,0,0 },// optidx=13 { "maxconn",required_argument,0,0 },// optidx=13
{ "hostspell",required_argument,0,0 },// optidx=14 { "hostcase",no_argument,0,0 },// optidx=14
{ "hostdot",no_argument,0,0 },// optidx=15 { "hostspell",required_argument,0,0 },// optidx=15
{ "hostnospace",no_argument,0,0 },// optidx=16 { "hostdot",no_argument,0,0 },// optidx=16
{ "split-http-req",required_argument,0,0 },// optidx=17 { "hostnospace",no_argument,0,0 },// optidx=17
{ "split-pos",required_argument,0,0 },// optidx=18 { "split-http-req",required_argument,0,0 },// optidx=18
{ "methodspace",no_argument,0,0 },// optidx=19 { "split-pos",required_argument,0,0 },// optidx=19
{ "methodeol",no_argument,0,0 },// optidx=20 { "methodspace",no_argument,0,0 },// optidx=20
{ "hosttab",no_argument,0,0 },// optidx=21 { "methodeol",no_argument,0,0 },// optidx=21
{ "unixeol",no_argument,0,0 },// optidx=22 { "hosttab",no_argument,0,0 },// optidx=22
{ "hostlist",required_argument,0,0 },// optidx=23 { "unixeol",no_argument,0,0 },// optidx=23
{ "pidfile",required_argument,0,0 },// optidx=24 { "hostlist",required_argument,0,0 },// optidx=24
{ "pidfile",required_argument,0,0 },// optidx=25
{ NULL,0,NULL,0 } { NULL,0,NULL,0 }
}; };
while ((v = getopt_long_only(argc, argv, "", long_options, &option_index)) != -1) while ((v = getopt_long_only(argc, argv, "", long_options, &option_index)) != -1)
@ -672,7 +674,15 @@ void parse_params(int argc, char *argv[])
params.gid = pwd->pw_gid; params.gid = pwd->pw_gid;
break; break;
} }
case 12: /* maxconn */ case 12: /* uid */
params.gid=0x7FFFFFFF; // default git. drop gid=0
if (!sscanf(optarg,"%u:%u",&params.uid,&params.gid))
{
fprintf(stderr, "--uid should be : uid[:gid]\n");
exit_clean(1);
}
break;
case 13: /* maxconn */
params.maxconn = atoi(optarg); params.maxconn = atoi(optarg);
if (params.maxconn <= 0) if (params.maxconn <= 0)
{ {
@ -680,10 +690,10 @@ void parse_params(int argc, char *argv[])
exit_clean(1); exit_clean(1);
} }
break; break;
case 13: /* hostcase */ case 14: /* hostcase */
params.hostcase = true; params.hostcase = true;
break; break;
case 14: /* hostspell */ case 15: /* hostspell */
if (strlen(optarg) != 4) if (strlen(optarg) != 4)
{ {
fprintf(stderr, "hostspell must be exactly 4 chars long\n"); fprintf(stderr, "hostspell must be exactly 4 chars long\n");
@ -692,13 +702,13 @@ void parse_params(int argc, char *argv[])
params.hostcase = true; params.hostcase = true;
memcpy(params.hostspell, optarg, 4); memcpy(params.hostspell, optarg, 4);
break; break;
case 15: /* hostdot */ case 16: /* hostdot */
params.hostdot = true; params.hostdot = true;
break; break;
case 16: /* hostnospace */ case 17: /* hostnospace */
params.hostnospace = true; params.hostnospace = true;
break; break;
case 17: /* split-http-req */ case 18: /* split-http-req */
if (!strcmp(optarg, "method")) if (!strcmp(optarg, "method"))
params.split_http_req = split_method; params.split_http_req = split_method;
else if (!strcmp(optarg, "host")) else if (!strcmp(optarg, "host"))
@ -709,7 +719,7 @@ void parse_params(int argc, char *argv[])
exit_clean(1); exit_clean(1);
} }
break; break;
case 18: /* split-pos */ case 19: /* split-pos */
i = atoi(optarg); i = atoi(optarg);
if (i) if (i)
params.split_pos = i; params.split_pos = i;
@ -719,25 +729,25 @@ void parse_params(int argc, char *argv[])
exit_clean(1); exit_clean(1);
} }
break; break;
case 19: /* methodspace */ case 20: /* methodspace */
params.methodspace = true; params.methodspace = true;
break; break;
case 20: /* methodeol */ case 21: /* methodeol */
params.methodeol = true; params.methodeol = true;
break; break;
case 21: /* hosttab */ case 22: /* hosttab */
params.hosttab = true; params.hosttab = true;
break; break;
case 22: /* unixeol */ case 23: /* unixeol */
params.unixeol = true; params.unixeol = true;
break; break;
case 23: /* hostlist */ case 24: /* hostlist */
if (!LoadHostList(&params.hostlist, optarg)) if (!LoadHostList(&params.hostlist, optarg))
exit_clean(1); exit_clean(1);
strncpy(params.hostfile,optarg,sizeof(params.hostfile)); strncpy(params.hostfile,optarg,sizeof(params.hostfile));
params.hostfile[sizeof(params.hostfile)-1]='\0'; params.hostfile[sizeof(params.hostfile)-1]='\0';
break; break;
case 24: /* pidfile */ case 25: /* pidfile */
strncpy(params.pidfile,optarg,sizeof(params.pidfile)); strncpy(params.pidfile,optarg,sizeof(params.pidfile));
params.pidfile[sizeof(params.pidfile)-1]='\0'; params.pidfile[sizeof(params.pidfile)-1]='\0';
break; break;
@ -781,7 +791,7 @@ void daemonize()
bool droproot() bool droproot()
{ {
if (params.uid) if (params.uid || params.gid)
{ {
if (setgid(params.gid)) if (setgid(params.gid))
{ {
@ -1001,16 +1011,18 @@ int main(int argc, char *argv[]) {
goto exiterr; goto exiterr;
} }
if (!droproot()) if (bind(listen_fd, (struct sockaddr *)&salisten, salisten_len) == -1) {
{ perror("bind: ");
goto exiterr; goto exiterr;
} }
if (bind(listen_fd, (struct sockaddr *)&salisten, salisten_len) == -1) { if (!droproot())
perror("bind: "); {
goto exiterr; goto exiterr;
} }
fprintf(stderr,"Running as UID=%u GID=%u\n",getuid(),getgid());
if (listen(listen_fd, BACKLOG) == -1) { if (listen(listen_fd, BACKLOG) == -1) {
perror("listen: "); perror("listen: ");
goto exiterr; goto exiterr;

Loading…
Cancel
Save