Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.49 KB | None | 0 0
  1. #!/usr/bin/perl
  2.  
  3.  
  4. use strict;
  5. use IO::Socket ();
  6. use LWP::UserAgent;
  7. use HTTP::Request;
  8. use URI::Escape;
  9. use POSIX;
  10. fork() and exit();
  11. #setsid();
  12. my ($debug, $PORT, $TOHOST, $TOPORT, $SERVIP, $CLIENTIP, $goodpass, $listen);
  13.  
  14.  
  15. $TOHOST = "chat.idx.pl";
  16. $TOPORT = 6667;
  17. $| = 1;
  18.  
  19.  
  20. $PORT=3225 if (! $PORT);
  21. $listen='0.0.0.0' if (! $listen);
  22.  
  23. ################################################################################################
  24.  
  25. {
  26.  
  27. my %o = ('port' => $PORT,
  28. 'toport' => $TOPORT,
  29. 'tohost' => $TOHOST);
  30.  
  31.  
  32. my $ah = IO::Socket::INET->new('LocalAddr' => $listen,
  33. 'LocalPort' => $PORT,
  34. 'Reuse' => 1,
  35. 'Listen' => 10)
  36. || die "Failed to bind to local socket: $!";
  37.  
  38. $SIG{'CHLD'} = 'IGNORE';
  39. my $num = 0;
  40. while (1) {
  41. my $ch = $ah->accept();
  42. if (!$ch) {
  43. print STDERR "Failed to accept: $!\n";
  44. next;
  45. }
  46.  
  47. ++$num;
  48.  
  49. my $pid = fork();
  50. if (!defined($pid)) {
  51. print STDERR "Failed to fork: $!\n";
  52. } elsif ($pid == 0) {
  53. $ah->close();
  54. Run(\%o, $ch, $num);
  55. } else {
  56. $ch->close();
  57. }
  58. }
  59. }
  60.  
  61.  
  62. sub Run {
  63. my($o, $ch, $num) = @_;
  64. my $th = IO::Socket::INET->new('PeerAddr' => $o->{'tohost'},
  65. 'PeerPort' => $o->{'toport'});
  66.  
  67.  
  68. $SERVIP=$th->sockhost;
  69. $CLIENTIP=$ch->peerhost;
  70.  
  71.  
  72. if (!$th) {
  73. exit 0;
  74. }
  75.  
  76. my ($fh, $nick,$user,$authpass);
  77.  
  78. my $color=1;
  79.  
  80. $ch->autoflush();
  81. $th->autoflush();
  82.  
  83. while ($ch || $th) {
  84.  
  85.  
  86. my $rin = "";
  87.  
  88. vec($rin, fileno($ch), 1) = 1 if $ch;
  89. vec($rin, fileno($th), 1) = 1 if $th;
  90. my($rout, $eout);
  91. select($rout = $rin, undef, $eout = $rin, 120);
  92. if (!$rout && !$eout) {
  93. print STDERR "Child: Timeout, terminating.\n";
  94. }
  95. my $cbuffer = "";
  96. my $tbuffer = "";
  97.  
  98. if ($ch && (vec($eout, fileno($ch), 1) ||
  99. vec($rout, fileno($ch), 1))) {
  100. my $result = sysread($ch, $tbuffer, 1024);
  101.  
  102.  
  103.  
  104. if ($tbuffer=~ /NICK/ && ! $nick) {
  105. $nick=$tbuffer;
  106. $nick=~ s/NICK ~/NICK /s;
  107. $nick=~ s/^.*NICK (.*?)(\r|\n| ).*$/$1/s;
  108.  
  109.  
  110.  
  111.  
  112. if ($tbuffer=~ /USER/) {
  113. $user=$tbuffer;
  114. $user=~ s/USER ~/USER /s;
  115. $user=~ s/^.*USER (.*?)(\r|\n| ).*$/$1/s;
  116.  
  117. my $res = syswrite($th, "NICK $nick\n");
  118. my $res = syswrite($th, "USER $user 8 czat.idx.pl :Chatik 1.2.0\n");
  119. };
  120.  
  121. };
  122.  
  123.  
  124.  
  125.  
  126.  
  127. $tbuffer=~ s/\002(.*?)\002/%Fb%$1%Fn%/sg;
  128.  
  129. $tbuffer=~ s/(\003\d+),\d+/$1/sg;
  130.  
  131. $tbuffer=~ s/\0037([^\d])/%Cc86c00%$1/sg;
  132. $tbuffer=~ s/\00312([^\d])/%C0f2ab1%$1/sg;
  133. $tbuffer=~ s/\0032([^\d])/%C0f2ab1%$1/sg;
  134. $tbuffer=~ s/\0034([^\d])/%Ce40f0f%$1/sg;
  135. $tbuffer=~ s/\00310([^\d])/%C1a866e%$1/sg;
  136. $tbuffer=~ s/\003([^\d])/%C%$1/sg;
  137. #$tbuffer=~ s/\\(\w+)/%I$1%/sg;
  138.  
  139.  
  140. $tbuffer=~ s/\003\d+/%C%/sg;
  141.  
  142.  
  143. if (!defined($result)) {
  144. print STDERR "Child: Error while reading from client: $!\n";
  145. exit 0;
  146. }
  147. if ($result == 0) {
  148. exit 0;
  149. }
  150. }
  151.  
  152. if ($th && (vec($eout, fileno($th), 1) ||
  153. vec($rout, fileno($th), 1))) {
  154. my $result = sysread($th, $cbuffer, 1024);
  155. if (!defined($result)) {
  156. print STDERR "Child: Error while reading from tunnel: $!\n";
  157. exit 0;
  158. }
  159. if ($result == 0) {
  160. exit 0;
  161. }
  162.  
  163.  
  164.  
  165.  
  166. #$cbuffer=~ s/%Cc86c00%/\0037/sg;
  167. #$cbuffer=~ s/%C0f2ab1%/\00312/sg;
  168. #$cbuffer=~ s/%Ce40f0f%/\0034/sg;
  169. #$cbuffer=~ s/%C1a866e%/\00310/sg;
  170. $cbuffer=~ s/%C%/\003/sg;
  171.  
  172.  
  173. $cbuffer=~ s/%C\w+?%//sg;
  174.  
  175.  
  176. $cbuffer=~ s/%Fi/%F/sg;
  177. #$cbuffer=~ s/%Fb(.*?)%/\002/sg;
  178. #$cbuffer=~ s/(\002.*?)%Fn%/$1\002/;
  179.  
  180.  
  181. $cbuffer=~ s/%F.*?%//sg;
  182.  
  183. $cbuffer=~ s/%I(\w+?)%/\{$1}/sg;
  184. $cbuffer=~ s/ą/ą/sg;
  185. $cbuffer=~ s/ź/ż/sg;
  186. $cbuffer=~ s/ć/ć/sg;
  187. $cbuffer=~ s/ę/ę/sg;
  188. $cbuffer=~ s/ż/ż/sg;
  189. $cbuffer=~ s/ś/ś/sg;
  190. $cbuffer=~ s/ł/ł/sg;
  191. $cbuffer=~ s/ó/ó/sg;
  192.  
  193.  
  194. }
  195.  
  196. if ($fh && $tbuffer) {
  197. (print $fh $tbuffer);
  198. }
  199.  
  200. while (my $len = length($tbuffer)) {
  201. my $res = syswrite($th, $tbuffer, $len);
  202. if ($res > 0) {
  203. $tbuffer = substr($tbuffer, $res);
  204. } else {
  205. print STDERR "Child: Failed to write to tunnel: $!\n";
  206. }
  207. }
  208. while (my $len = length($cbuffer)) {
  209. my $res = syswrite($ch, $cbuffer, $len);
  210. if ($res > 0) {
  211. $cbuffer = substr($cbuffer, $res);
  212. } else {
  213. print STDERR "Child: Failed to write to tunnel: $!\n";
  214. }
  215. }
  216. }
  217. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement