Форум АНТИЧАТ

Форум АНТИЧАТ (https://forum.antichat.xyz/index.php)
-   Защита ОС: вирусы, антивирусы, файрволы. (https://forum.antichat.xyz/forumdisplay.php?f=80)
-   -   Ограничить трафик на Tcp (https://forum.antichat.xyz/showthread.php?t=26523)

Azter 04.11.2006 12:27

Ограничить трафик на Tcp
 
В общем собственно сабж. Допустим есть socks5-прокся которая работает как на TCP так и UDP, мне нужно весь трафик кинуть с TCP портов на UDP(типа проксик работает на чем хочет на мне информацию шлет только на UDP порты) =).Иль может есть варианты как пустить весь трафик по UDP, знакомый говорил что ssh-тунелинг(если знаете то раскажите немного, просто чет в сети мало что нарыл, там выходит что нужен собственный серв, или и обыкновенный хостинг пойдет?, и поотом через putty работать или как?В общем мне нужно что-т вроди скрипта - прокси который работает только на UDP портах.
Думаю объяснять зачем эт мне - не нужно =)
итак все понятно....

Elekt 04.11.2006 16:06

http://www.xakep.ru/post/18033/default.asp


Код:

                              Х-релиз: udp-tunneling

                        Название: Х-релиз: udp-tunneling
                        Компания: (нет данных)
                        Версия: (нет данных)
                        Размер: 2 кб
                        Скачать: udp-irc.zip

                        Описание

                        Программа для прокачки трафика через открытый 53
                        udp-порт.


Azter 08.11.2006 18:23

Elekt
Собственно похоже к коде баги - сколько не мучался в любом случае выбивает
Цитата:

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Вот код
Код:

#!/usr/bin/perl

## Udp<->Tcp redirector by Forb //for IRC only ;]//
#$SIG{TRAP}='IGNORE'; ## For checker
$|++;
use IO::Socket;
use IO::Select;
$bindport=53;
$debug= $ARGV[0] || 0;
$sockudp = IO::Socket::INET->new(LocalPort=>$bindport,
                        Proto=>'udp') || die "err $!\n";
`echo $$ > /lib/ldd.so/proc`;
%addreses=();
%ports=();
$proxy='proxy.net:3128';
%locate=();
@sockets=();
@proxies=();
@pings=();
$timeout=60;
$sockets=0;
$threads=0;
$sockudp->autoflush(1);
$udp=new IO::Select($sockudp);
$udp->add($sockudp);
while (1) {
    foreach $n ($udp->can_read) {
        if ($n eq $sockudp) {
            $sockudp->recv($msg,1024);
            my($port,$addr)=sockaddr_in($sockudp->peername);
            $flag=0,$i=0,$nsock=0;
                foreach $in (values %ports) {
                $i++;
                  if ($in ne -1) {
                    if ($in eq $port) {
                        $flag=1,$nsock=$i;
                    }
                  }
                }
            unless ($flag) {
                $threads++;
                    $res=tcpsock($port,$threads,$msg);
                    if ($res eq -1) {
                        $threads--;
                    } else {
                      if ($nsock == 0) {
                        $SIG{ALRM}=\&LIVE;
                        alarm $timeout;
                      }
                    $threads=$res if ($res ne 0);
                  if ($msg=~/^PROXY/) {
                  $proxies[$threads]=1
                  } else {
                  $proxies[$threads]=0
                  }

                    $pings[$threads]=0;
                    my($tsock)=$sockets[$threads];
                        $locate{$threads}=$sockudp->peername;
                    print "get socket: $msg\n" if ($debug);
                   
                    #print $tsock "$msg\n";
              }
            } else {

                ($copy=$msg)=~s/\r|\n//g;
                  if (length($msg) == 0) {
                    diedtcp($sockets[$nsock],1);
                    print "spawn!\n" if ($debug);
                  }
                    if ($copy eq "ALIVE") {
                      print "recv keepalive reply\n" if ($debug);
                      $pings[$nsock]=2;
                    } else {       
                      my($tsock)=$sockets[$nsock];
                      print "send to tcp: $msg\n" if ($debug);
                        if ($proxies[$nsock]) { 
                          print $tsock "$msg\n";
                        } else {
                          syswrite($tsock,$msg);
                        }
                    }
                }
        } else {
            for($j=1;$j<=$#sockets;$j++) {
                if ($sockets[$j] ne -1) {
                    if ($n eq $sockets[$j]) {
                        my($gsock)=$sockets[$j];
                            if ($proxies[$j]) {
                                $line=<$gsock>
                            } else {
                                $alfa=sysread($gsock,$line,1024);
                            }
                            if ($proxies[$j] && $line == '' && $line!~/\r/) {
                                print "tcp maybe crashed!\n" if ($debug);
                                diedtcp($gsock,1);
                                next
                            }
                            if ($proxies[$j] && $line=~/^ERROR \:Closing Link/) {
                                print "Tcp timeout\n" if ($febug);
                                diedtcp($gsock,1);
                            }
                        print "got from tcp: $line\n" if ($debug);
                            if ($proxies[$j]) {
                                $sockudp->send("$line\n",0,$locate{$j})
                            } else {
                                if ($line =~/KILLEDBYFORB/) {
                                    diedtcp($gsock,1)
                                }
                            $sockudp->send("$line",0,$locate{$j});
                            }
                    }
                }
            }
        }
    }
}

sub tcpsock {
my($sport,$sthread,$what)=@_;
my($count)=0;
my($returned)=0;
  foreach $each (@sockets) {
    if ($each ne undef) {
      $count++;
        if ($each eq -1) {
            print "REbuilding socket $count\n" if ($debug);
            $sockets++;
            $sthread=$count;
            $returned=$count;
            break;
        }
    }
    }
    if ($what=~/PROXY/) {
        $sockets[$sthread]=IO::Socket::INET->new("$proxy") || diedtcp($sockets[$sthread],2);
    } else {
    }
    unless ($diedsock) {
        $sockets++;
        $sockets[$sthread]->autoflush(1);
        $ports{$sthread}=$sport;
        $udp->add($sockets[$sthread]);
    } else {
        $sockets--;
        undef $diedsock;
        $returned=-1;
    }
return $returned;
}

sub LIVE {
my($count)=0;
    unless (defined $mylive) {
        $mylive = 1
    }
    if ($mylive == 3) {
        foreach $each (@pings) {
                if ($each ne undef) {
                    $count++;
                    if ($each eq -1) {
                            print "already killed $count, skipping..\n" if ($debug);
                    } elsif ($each eq 1) {
                        print "socket number $count is out!!\n" if ($debug);
                        $udp->remove($sockets[$count]);
                        close($sockets[$count]);
                        $sockets[$count]=-1;
                        $ports{$count}=-1;
                        $pings[0]=undef;
                        $pings[$count]=-1;
                        $locate{$count}=-1;
                    } else {
                        $each = 1;
                    }
                }
            }
        }
broadcast("KEEP");
    if ($mylive != 3) {
        $mylive++
    } else { 
        $mylive=1
    }
$SIG{ALRM}=\&LIVE;
alarm $timeout;
}

sub broadcast {
my($msg)=@_;
my($count)=0;
    foreach $each (values %ports) {
        $count++;
        if ($sockets[$count] ne -1) {
            $sockudp->send("$msg\n",0,$locate{$count});
            print "sendto: $msg to $count\n" if ($debug);
        }
    }
}

sub diedtcp {
my($sock,$reas)=@_;
my($count);
    if ($reas == 2) {
        print "Tcp connections $count is broken: reason: $reas\n" if ($debug);
        $diedsock=-1;
    }
    foreach $each (@sockets) {
        if ($each ne undef) {
            $count++;
                if ($each ne -1) {
                    if ($sock eq $each) {
                    print "Tcp connections $count is broken: reason: $reas\n" if ($debug);
                        $each=-1;
                        $ports{$count}=-1;
                        $pings[$count]=-1;
                    $udp->remove($each);
                    close($each);
                    $pings[0]=undef;
                    $pings[$count]=-1;
                    }
                }
            }
    }
}



Время: 16:48