1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
#!/usr/bin/env perl
use lib '../lib';
use IO::Socket::Socks;
use strict;
# example of using socks bind with FTP active data connection
use constant
{
FTP_HOST => 'host.net',
FTP_PORT => 21,
FTP_USER => 'root',
FTP_PASS => 'lsdadp',
SOCKS_HOST => '195.190.0.20',
SOCKS_PORT => 1080
};
# create control connection
my $primary = IO::Socket::Socks->new(
ConnectAddr => FTP_HOST,
ConnectPort => FTP_PORT,
ProxyAddr => SOCKS_HOST,
ProxyPort => SOCKS_PORT,
SocksVersion => 5,
SocksDebug => 1,
Timeout => 30
) or die $SOCKS_ERROR;
# create data connection
my $secondary = IO::Socket::Socks->new(
BindAddr => FTP_HOST,
BindPort => FTP_PORT,
ProxyAddr => SOCKS_HOST,
ProxyPort => SOCKS_PORT,
SocksVersion => 5,
SocksDebug => 1,
Timeout => 30
) or die $SOCKS_ERROR;
# login to ftp
$primary->syswrite("USER ". FTP_USER ."\015\012");
$primary->getline();
$primary->syswrite("PASS ". FTP_PASS ."\015\012");
$primary->getline();
# get address where socks bind and pass it to the ftp server
my ($host, $port) = $secondary->dst();
$host = SOCKS_HOST if $host eq '0.0.0.0'; # RFC says that if host == '0.0.0.0' it means that it should be replaced by socks host
$primary->syswrite("PORT " . join(',', split (/\./, $host), (map hex, sprintf("%04x", $port) =~ /(..)(..)/)) . "\015\012");
$primary->getline();
$primary->syswrite("LIST /\015\012");
$primary->getline();
# wait connection from ftp server
$secondary->accept()
or die $SOCKS_ERROR;
# print all data received from ftp server
print while <$secondary>;
# close all connections
$secondary->close();
$primary->close();
|