Untitled


SUBMITTED BY: Guest

DATE: May 4, 2014, 7:24 p.m.

FORMAT: Text only

SIZE: 5.5 kB

HITS: 996

  1. #!/usr/bin/perl
  2. # Satanic Socks Server v0.8.031206-perl
  3. # This script is private. Only for SaTaNiC team and friends. Not for sale.
  4. # Coded by drmist/STNC, web: www.stnc.ru.
  5. $auth_enabled = 0;
  6. $auth_login = "user";
  7. $auth_pass = "pass";
  8. $port = 3003;
  9. use IO::Socket::INET;
  10. $SIG{'CHLD'} = 'IGNORE';
  11. $bind = IO::Socket::INET->new(Listen=>10, Reuse=>1, LocalPort=>$port) or die "Can't bind port $port\n";
  12. while($client = $bind->accept()) {
  13. $client->autoflush();
  14. if(fork()){ $client->close(); }
  15. else { $bind->close(); new_client($client); exit(); }
  16. }
  17. sub new_client {
  18. local $t, $i, $buff, $ord, $success;
  19. local $client = $_[0];
  20. sysread($client, $buff, 1);
  21. if(ord($buff) == 5) {
  22. sysread($client, $buff, 1);
  23. $t = ord($buff);
  24. unless(sysread($client, $buff, $t) == $t) { return; }
  25. $success = 0;
  26. for($i = 0; $i < $t; $i++) {
  27. $ord = ord(substr($buff, $i, 1));
  28. if($ord == 0 && !$auth_enabled) {
  29. syswrite($client, "\x05\x00", 2);
  30. $success++;
  31. break;
  32. }
  33. elsif($ord == 2 && $auth_enabled) {
  34. unless(do_auth($client)){ return; }
  35. $success++;
  36. break;
  37. }
  38. }
  39. if($success) {
  40. $t = sysread($client, $buff, 3);
  41. if(substr($buff, 0, 1) == '\x05') {
  42. if(ord(substr($buff, 2, 1)) == 0) { # reserved
  43. ($host, $raw_host) = socks_get_host($client);
  44. if(!$host) { return; }
  45. ($port, $raw_port) = socks_get_port($client);
  46. if(!$port) { return; }
  47. $ord = ord(substr($buff, 1, 1));
  48. $buff = "\x05\x00\x00".$raw_host.$raw_port;
  49. syswrite($client, $buff, length($buff));
  50. socks_do($ord, $client, $host, $port);
  51. }
  52. }
  53. } else { syswrite($client, "\x05\xFF", 2); };
  54. }
  55. $client->close();
  56. }
  57. sub do_auth {
  58. local $buff, $login, $pass;
  59. local $client = $_[0];
  60. syswrite($client, "\x05\x02", 2);
  61. sysread($client, $buff, 1);
  62. if(ord($buff) == 1) {
  63. sysread($client, $buff, 1);
  64. sysread($client, $login, ord($buff));
  65. sysread($client, $buff, 1);
  66. sysread($client, $pass, ord($buff));
  67. if($login eq $auth_login && $pass eq $auth_pass) {
  68. syswrite($client, "\x05\x00", 2);
  69. return 1;
  70. } else { syswrite($client, "\x05\x01", 2); }
  71. }
  72. $client->close();
  73. return 0;
  74. }
  75. sub socks_get_host {
  76. local $client = $_[0];
  77. local $t, $ord, $raw_host;
  78. local $host = "";
  79. sysread($client, $t, 1);
  80. $ord = ord($t);
  81. if($ord == 1) {
  82. sysread($client, $raw_host, 4);
  83. @host = $raw_host =~ /(.)/g;
  84. $host = ord($host[0]).".".ord($host[1]).".".ord($host[2]).".".ord($host[3]);
  85. } elsif($ord == 3) {
  86. sysread($client, $raw_host, 1);
  87. sysread($client, $host, ord($raw_host));
  88. $raw_host .= $host;
  89. } elsif($ord == 4) {
  90. #ipv6 - not supported
  91. }
  92. return ($host, $t.$raw_host);
  93. }
  94. sub socks_get_port {
  95. local $client = $_[0];
  96. local $raw_port, $port;
  97. sysread($client, $raw_port, 2);
  98. $port = ord(substr($raw_port, 0, 1)) << 8 | ord(substr($raw_port, 1, 1));
  99. return ($port, $raw_port);
  100. }
  101. sub socks_do {
  102. local($t, $client, $host, $port) = @_;
  103. if($t == 1) { socks_connect($client, $host, $port); }
  104. elsif($t == 2) { socks_bind($client, $host, $port); }
  105. elsif($t == 3) { socks_udp_associate($client, $host, $port); }
  106. else { return 0; }
  107. return 1;
  108. }
  109. # this part of code was taken from datapipe.pl utility,
  110. # written by CuTTer (cutter[at]real.xakep.ru)
  111. # utility lays on cpan.org
  112. sub socks_connect {
  113. my($client, $host, $port) = @_;
  114. my $target = IO::Socket::INET->new(PeerAddr => $host, PeerPort => $port, Proto => 'tcp', Type => SOCK_STREAM);
  115. unless($target) { return; }
  116. $target->autoflush();
  117. while($client || $target) {
  118. my $rin = "";
  119. vec($rin, fileno($client), 1) = 1 if $client;
  120. vec($rin, fileno($target), 1) = 1 if $target;
  121. my($rout, $eout);
  122. select($rout = $rin, undef, $eout = $rin, 120);
  123. if (!$rout && !$eout) { return; }
  124. my $cbuffer = "";
  125. my $tbuffer = "";
  126. if ($client && (vec($eout, fileno($client), 1) || vec($rout, fileno($client), 1))) {
  127. my $result = sysread($client, $tbuffer, 1024);
  128. if (!defined($result) || !$result) { return; }
  129. }
  130. if ($target && (vec($eout, fileno($target), 1) || vec($rout, fileno($target), 1))) {
  131. my $result = sysread($target, $cbuffer, 1024);
  132. if (!defined($result) || !$result) { return; }
  133. }
  134. if ($fh && $tbuffer) { print $fh $tbuffer; }
  135. while (my $len = length($tbuffer)) {
  136. my $res = syswrite($target, $tbuffer, $len);
  137. if ($res > 0) { $tbuffer = substr($tbuffer, $res); } else { return; }
  138. }
  139. while (my $len = length($cbuffer)) {
  140. my $res = syswrite($client, $cbuffer, $len);
  141. if ($res > 0) { $cbuffer = substr($cbuffer, $res); } else { return; }
  142. }
  143. }
  144. }
  145. sub socks_bind {
  146. my($client, $host, $port) = @_;
  147. # not supported
  148. }
  149. sub socks_udp_associate {
  150. my($client, $host, $port) = @_;
  151. # not supported
  152. }

comments powered by Disqus