Remote Connection




       aqui le dejo  un Scripts mejor dicho el scanners RDP  este scanners esta en lenguaje Perl 


  1. # Install Dulu Encoding::BER
  2. # Cara nya ketikan di Terminal a/ Command Prompt perl -MCPAN -e shell
  3. # lalu masukan install Encoding::BER
  4. # CODE :
  5. use strict;
  6. use warnings;
  7. use IO::Socket::INET;
  8. use Getopt::Long;
  9. use Encoding::BER;
  10.  
  11. my %rdp_neg_type;
  12. $rdp_neg_type{"01"} = "TYPE_RDP_NEG_REQ";
  13. $rdp_neg_type{"02"} = "TYPE_RDP_NEG_RSP";
  14. $rdp_neg_type{"03"} = "TYPE_RDP_NEG_FAILURE";
  15.  
  16. my %rdp_neg_rsp_flags;
  17. $rdp_neg_rsp_flags{"00"} = "NO_FLAGS_SET";
  18. $rdp_neg_rsp_flags{"01"} = "EXTENDED_CLIENT_DATA_SUPPORTED";
  19. $rdp_neg_rsp_flags{"02"} = "DYNVC_GFX_PROTOCOL_SUPPORTED";
  20.  
  21. my %rdp_neg_protocol;
  22. $rdp_neg_protocol{"00"} = "PROTOCOL_RDP";
  23. $rdp_neg_protocol{"01"} = "PROTOCOL_SSL";
  24. $rdp_neg_protocol{"02"} = "PROTOCOL_HYBRID";
  25.  
  26. my %rdp_neg_failure_code;
  27. $rdp_neg_failure_code{"01"} = "SSL_REQUIRED_BY_SERVER";
  28. $rdp_neg_failure_code{"02"} = "SSL_NOT_ALLOWED_BY_SERVER";
  29. $rdp_neg_failure_code{"03"} = "SSL_CERT_NOT_ON_SERVER";
  30. $rdp_neg_failure_code{"04"} = "INCONSISTENT_FLAGS";
  31. $rdp_neg_failure_code{"05"} = "HYBRID_REQUIRED_BY_SERVER";
  32. $rdp_neg_failure_code{"06"} = "SSL_WITH_USER_AUTH_REQUIRED_BY_SERVER";
  33.  
  34. my %encryption_level;
  35. $encryption_level{"00000000"} = "ENCRYPTION_LEVEL_NONE";
  36. $encryption_level{"00000001"} = "ENCRYPTION_LEVEL_LOW";
  37. $encryption_level{"00000002"} = "ENCRYPTION_LEVEL_CLIENT_COMPATIBLE";
  38. $encryption_level{"00000003"} = "ENCRYPTION_LEVEL_HIGH";
  39. $encryption_level{"00000004"} = "ENCRYPTION_LEVEL_FIPS";
  40.  
  41. my %encryption_method;
  42. $encryption_method{"00000000"} = "ENCRYPTION_METHOD_NONE";
  43. $encryption_method{"00000001"} = "ENCRYPTION_METHOD_40BIT";
  44. $encryption_method{"00000002"} = "ENCRYPTION_METHOD_128BIT";
  45. $encryption_method{"00000008"} = "ENCRYPTION_METHOD_56BIT";
  46. $encryption_method{"00000010"} = "ENCRYPTION_METHOD_FIPS";
  47.  
  48. my %version_meaning;
  49. $version_meaning{"00080001"} = "RDP 4.0 servers";
  50. $version_meaning{"00080004"} = "RDP 5.0, 5.1, 5.2, 6.0, 6.1, 7.0, 7.1, and 8.0 servers";
  51.  
  52. my $enc = Encoding::BER->new(warn => sub{});
  53. my %config;
  54.  
  55. my $VERSION = "0.8-beta";
  56. my $usage = "Starting rdp-sec-check v$VERSION ( http://labs.portcullis.co.uk/application/rdp-sec-check/ )
  57. Copyright (C) 2012 Mark Lowe (mrl\@portcullis-security.com)
  58.  
  59. rdp-sec-check.pl host:port
  60.  
  61. ";
  62. my $debug    = 0;
  63. my $verbose  = 0;
  64. my $help = 0;
  65.  
  66. my $result = GetOptions (
  67.          "verbose"   => \$verbose,
  68.          "debug"     => \$debug,
  69.          "help"      => \$help
  70. );
  71.  
  72. if ($help) {
  73.         print $usage;
  74.         exit 0;
  75. }
  76.  
  77. if ($debug) {
  78.         use Data::Dumper;
  79.         use warnings FATAL => 'all';
  80.         use Carp qw(confess);
  81.         $SIG{ __DIE__ } = sub { confess( @_ ) };
  82. }
  83.  
  84. my $host = shift or die $usage;
  85. my $port = 3389;
  86. if ($host =~ /\s*(\S+):(\d+)\s*/) {
  87.         $host = $1;
  88.         $port = $2;
  89. }
  90. my $ip = resolve($host);
  91. unless (defined($ip)) {
  92.         die "[E] Can't resolve hostname $host\n";
  93. }
  94.  
  95. # flush after every write
  96. $| = 1;
  97.  
  98. my $global_starttime = time;
  99. printf "Starting rdp-sec-check v%s ( http://labs.portcullis.co.uk/application/rdp-sec-check/ ) at %s\n", $VERSION, scalar(localtime);
  100.  
  101. scan_host($host, $ip, $port);
  102.  
  103. print "\n";
  104. printf "rdp-sec-check v%s completed at %s\n", $VERSION, scalar(localtime);
  105. print "\n";
  106.  
  107. sub scan_host {
  108.         my ($host, $ip, $port) = @_;
  109.         print "\n";
  110.         print "Target:    $host\n";
  111.         print "IP:        $ip\n";
  112.         print "Port:      $port\n";
  113.         print "\n";
  114.         print "[+] Connecting to $ip:$port\n" if $debug > 1;
  115.         my $socket;
  116.         my @response;
  117.  
  118.         print "[+] Checking supported protocols\n\n";
  119.         print "[-] Checking if RDP Security (PROTOCOL_RDP) is supported...";
  120.         $socket = get_socket($ip, $port);
  121.         @response = test_std_rdp_security($socket);
  122.         if (scalar @response == 19) {
  123.                 my $type = $rdp_neg_type{sprintf "%02x", ord($response[11])};
  124.                 if ($type eq "TYPE_RDP_NEG_FAILURE") {
  125.                         printf "Not supported - %s\n", $rdp_neg_failure_code{sprintf("%02x", ord($response[15]))};
  126.                         $config{"protocols"}{"PROTOCOL_RDP"} = 0;
  127.                 } else {
  128.                         if ($rdp_neg_protocol{sprintf("%02x", ord($response[15]))} eq "PROTOCOL_RDP") {
  129.                                 print "Supported\n";
  130.                                 $config{"protocols"}{"PROTOCOL_RDP"} = 1;
  131.                         } else {
  132.                                 printf "Not supported.  Negotiated %s\n", $rdp_neg_protocol{sprintf("%02x", ord($response[15]))};
  133.                         }
  134.                 }
  135.         } elsif (scalar @response == 11) {
  136.                 printf "Negotiation ignored - old Windows 2000/XP/2003 system?\n";
  137.                 $config{"protocols"}{"PROTOCOL_RDP"} = 1;
  138.         } else {
  139.                 print "Not supported - unexpected response\n";
  140.                 $config{"protocols"}{"PROTOCOL_RDP"} = 1;
  141.         }
  142.  
  143.         print "[-] Checking if TLS Security (PROTOCOL_SSL) is supported...";
  144.         $socket = get_socket($ip, $port);
  145.         @response = test_tls_security($socket);
  146.         if (scalar @response == 19) {
  147.                 my $type = $rdp_neg_type{sprintf "%02x", ord($response[11])};
  148.                 if ($type eq "TYPE_RDP_NEG_FAILURE") {
  149.                         printf "Not supported - %s\n", $rdp_neg_failure_code{sprintf("%02x", ord($response[15]))};
  150.                         $config{"protocols"}{"PROTOCOL_SSL"} = 0;
  151.                 } else {
  152.                         if ($rdp_neg_protocol{sprintf("%02x", ord($response[15]))} eq "PROTOCOL_SSL") {
  153.                                 print "Supported\n";
  154.                                 $config{"protocols"}{"PROTOCOL_SSL"} = 1;
  155.                         } else {
  156.                                 printf "Not supported.  Negotiated %s\n", $rdp_neg_protocol{sprintf("%02x", ord($response[15]))};
  157.                         }
  158.                 }
  159.         } elsif (scalar @response == 11) {
  160.                 printf "Negotiation ignored - old Windows 2000/XP/2003 system?\n";
  161.                 $config{"protocols"}{"PROTOCOL_SSL"} = 0;
  162.         } else {
  163.                 print "Not supported - unexpected response\n";
  164.                 $config{"protocols"}{"PROTOCOL_SSL"} = 0;
  165.         }
  166.  
  167.         print "[-] Checking if CredSSP Security (PROTOCOL_HYBRID) is supported [uses NLA]...";
  168.         $socket = get_socket($ip, $port);
  169.         @response = test_credssp_security($socket);
  170.         if (scalar @response == 19) {
  171.                 my $type = $rdp_neg_type{sprintf "%02x", ord($response[11])};
  172.                 if ($type eq "TYPE_RDP_NEG_FAILURE") {
  173.                         printf "Not supported - %s\n", $rdp_neg_failure_code{sprintf("%02x", ord($response[15]))};
  174.                         $config{"protocols"}{"PROTOCOL_HYBRID"} = 0;
  175.                 } else {
  176.                         if ($rdp_neg_protocol{sprintf("%02x", ord($response[15]))} eq "PROTOCOL_HYBRID") {
  177.                                 print "Supported\n";
  178.                                 $config{"protocols"}{"PROTOCOL_HYBRID"} = 1;
  179.                         } else {
  180.                                 printf "Not supported.  Negotiated %s\n", $rdp_neg_protocol{sprintf("%02x", ord($response[15]))};
  181.                         }
  182.                 }
  183.         } elsif (scalar @response == 11) {
  184.                 printf "Negotiation ignored - old Windows 2000/XP/2003 system??\n";
  185.                 $config{"protocols"}{"PROTOCOL_HYBRID"} = 0;
  186.         } else {
  187.                 print "Not supported - unexpected response\n";
  188.                 $config{"protocols"}{"PROTOCOL_HYBRID"} = 0;
  189.         }
  190.         print "\n";
  191.         print "[+] Checking RDP Security Layer\n\n";
  192.         foreach my $enc_hex (qw(00 01 02 08 10)) {
  193.                 printf "[-] Checking RDP Security Layer with encryption %s...", $encryption_method{"000000" . $enc_hex};
  194.                 $socket = get_socket($ip, $port);
  195.                 @response = test_classic_rdp_security($socket);
  196.        
  197.                 if (scalar @response == 11) {
  198.                         my @response_mcs = test_mcs_initial_connect($socket, $enc_hex);
  199.                         unless (scalar(@response_mcs) > 8) {
  200.                                 print "Not supported\n";
  201.                                 next;
  202.                         }
  203.                         my $length1 = ord($response_mcs[8]);
  204.                         my $ber_encoded = join("", splice @response_mcs, 7);
  205.                         my $ber = $enc->decode($ber_encoded);
  206.                         my $user_data = $ber->{value}->[3]->{value};
  207.                         my ($sc_core, $sc_sec) = $user_data =~ /\x01\x0c..(.*)\x02\x0c..(.*)/s;
  208.                        
  209.                         my ($version, $client_requested_protocols, $early_capability_flags) = $sc_core =~ /(....)(....)?(....)?/;
  210.                         my ($encryption_method, $encryption_level, $random_length, $server_cert_length) = $sc_sec =~ /(....)(....)(....)(....)/;
  211.                         my $server_cert_length_i = unpack("V", $server_cert_length);
  212.                         my $random_length_i = unpack("V", $random_length);
  213.                         if ("000000" . $enc_hex eq sprintf "%08x", unpack("V", $encryption_method)) {
  214.                                 printf "Supported.  Server encryption level: %s\n", $encryption_level{sprintf "%08x", unpack("V",$encryption_level)};
  215.                                 $config{"encryption_level"}{$encryption_level{sprintf "%08x", unpack("V", $encryption_level)}} = 1;
  216.                                 $config{"encryption_method"}{$encryption_method{sprintf "%08x", unpack("V", $encryption_method)}} = 1;
  217.                                 $config{"protocols"}{"PROTOCOL_RDP"} = 1; # This is the only way the script detects RDP support on 2000/XP
  218.                         } else {
  219.                                 printf "Not supported.  Negotiated %s.  Server encryption level: %s\n", $encryption_method{sprintf "%08x",unpack("V", $encryption_method)}, $encryption_level{sprintf "%08x", unpack("V", $encryption_level)};
  220.                                 $config{"encryption_level"}{$encryption_level{sprintf "%08x", unpack("V", $encryption_level)}} = 0;
  221.                                 $config{"encryption_method"}{$encryption_method{sprintf "%08x", unpack("V", $encryption_method)}} = 0;
  222.                         }
  223.                         my $random = substr $sc_sec, 16, $random_length_i;     
  224.                         my $cert = substr $sc_sec, 16 + $random_length_i, $server_cert_length_i;       
  225.                 } else {
  226.                         print "Not supported\n";
  227.                 }
  228.         }
  229.  
  230.         if ($config{"protocols"}{"PROTOCOL_HYBRID"}) {
  231.                 if ($config{"protocols"}{"PROTOCOL_SSL"} or $config{"protocols"}{"PROTOCOL_RDP"}) {    
  232.                         $config{"issues"}{"NLA_SUPPORTED_BUT_NOT_MANDATED_DOS"} = 1;
  233.                 }
  234.         } else {
  235.                 # is this really a problem?
  236.                 $config{"issues"}{"NLA_NOT_SUPPORTED_DOS"} = 1;
  237.         }
  238.  
  239.         if ($config{"protocols"}{"PROTOCOL_RDP"}) {
  240.                 if ($config{"protocols"}{"PROTOCOL_SSL"} or $config{"protocols"}{"PROTOCOL_HYBRID"}) { 
  241.                         $config{"issues"}{"SSL_SUPPORTED_BUT_NOT_MANDATED_MITM"} = 1;
  242.                 } else {
  243.                         $config{"issues"}{"ONLY_RDP_SUPPORTED_MITM"} = 1;
  244.                 }
  245.  
  246.                 if ($config{"encryption_method"}{"ENCRYPTION_METHOD_40BIT"} or $config{"encryption_method"}{"ENCRYPTION_METHOD_56BIT"}) {
  247.                         $config{"issues"}{"WEAK_RDP_ENCRYPTION_SUPPORTED"} = 1;
  248.                 }
  249.  
  250.                 if ($config{"encryption_method"}{"ENCRYPTION_METHOD_NONE"}) {
  251.                         $config{"issues"}{"NULL_RDP_ENCRYPTION_SUPPORTED"} = 1;
  252.                 }
  253.  
  254.                 if ($config{"encryption_method"}{"ENCRYPTION_METHOD_FIPS"} and ($config{"encryption_method"}{"ENCRYPTION_METHOD_NONE"} or$config{"encryption_method"}{"ENCRYPTION_METHOD_40BIT"} or $config{"encryption_method"}{"ENCRYPTION_METHOD_56BIT"} or$config{"encryption_method"}{"ENCRYPTION_METHOD_128BIT"})) {
  255.                         $config{"issues"}{"FIPS_SUPPORTED_BUT_NOT_MANDATED"} = 1;
  256.                 }
  257.         }
  258.  
  259.         print "\n";
  260.         print "[+] Summary of protocol support\n\n";
  261.         foreach my $protocol (keys(%{$config{"protocols"}})) {
  262.                 printf "[-] $ip:$port supports %-15s: %s\n", $protocol, $config{"protocols"}{$protocol} ? "TRUE" : "FALSE";
  263.         }
  264.  
  265.         print "\n";
  266.         print "[+] Summary of RDP encryption support\n\n";
  267.         foreach my $encryption_level (sort keys(%{$config{"encryption_level"}})) {
  268.                 printf "[-] $ip:$port has encryption level: %s\n", $encryption_level;
  269.         }
  270.         foreach my $encryption_method (sort keys(%encryption_method)) {
  271.                 printf "[-] $ip:$port supports %-25s: %s\n", $encryption_method{$encryption_method}, (defined($config{"encryption_method"}{$encryption_method{$encryption_method}}) and $config{"encryption_method"}{$encryption_method{$encryption_method}}) ? "TRUE" : "FALSE";
  272.         }
  273.  
  274.         print "\n";
  275.         print "[+] Summary of security issues\n\n";
  276.         foreach my $issue (keys(%{$config{"issues"}})) {
  277.                 print "[-] $ip:$port has issue $issue\n";
  278.         }
  279.  
  280.         print Dumper \%config if $debug;
  281. }
  282.  
  283. sub test_std_rdp_security {
  284.         my ($socket) = @_;
  285.         my $string = get_x224_crq_std_rdp_security();
  286.         return do_handshake($socket, $string);
  287. }
  288.  
  289. sub test_tls_security {
  290.         my ($socket) = @_;
  291.         my $string = get_x224_crq_tls_security();
  292.         return do_handshake($socket, $string);
  293. }
  294.  
  295. sub test_credssp_security {
  296.         my ($socket) = @_;
  297.         my $string = get_x224_crq_credssp_security();
  298.         return do_handshake($socket, $string);
  299. }
  300.  
  301. sub test_classic_rdp_security {
  302.         my ($socket) = @_;
  303.         my $string = get_x224_crq_classic();
  304.         return do_handshake($socket, $string);
  305. }
  306.  
  307. sub test_mcs_initial_connect {
  308.         my ($socket, $enc_hex) = @_;
  309.         my $string = get_mcs_initial_connect($enc_hex);
  310.         return do_handshake($socket, $string);
  311. }
  312.  
  313. sub do_handshake {
  314.         my ($socket, $string) = @_;
  315.         print "[+] Sending:\n" if $debug > 1;
  316.         hdump($string) if $debug > 1;
  317.        
  318.         print $socket $string;
  319.        
  320.         my $data;
  321.         $socket->recv($data,4);
  322.         if (length($data) == 4) {
  323.                 print "[+] Received from Server :\n" if $debug > 1;
  324.                 hdump($data) if $debug > 1;
  325.                 my @data = split("", $data);
  326.                 my $length = (ord($data[2]) << 8) + ord($data[3]);
  327.                 printf "[+] Initial length: %d\n", $length if $debug > 1;
  328.                 my $data2 = "";
  329.                 while (length($data) < $length) {
  330.                         $socket->recv($data2,$length - 4);
  331.                         print "[+] Received " . length($data2) . " bytes from Server :\n" if $debug > 1;
  332.                         hdump($data2) if $debug > 1;
  333.                         $data .= $data2;
  334.                 }
  335.                 return split "", $data;
  336.         } else {
  337.                 return undef;
  338.         }
  339. }
  340.  
  341. # http://www.perlmonks.org/?node_id=111481
  342. sub hdump {
  343.     my $offset = 0;
  344.     my(@array,$format);
  345.     foreach my $data (unpack("a16"x(length($_[0])/16)."a*",$_[0])) {
  346.         my($len)=length($data);
  347.         if ($len == 16) {
  348.             @array = unpack('N4', $data);
  349.             $format="0x%08x (%05d)   %08x %08x %08x %08x   %s\n";
  350.         } else {
  351.             @array = unpack('C*', $data);
  352.             $_ = sprintf "%2.2x", $_ for @array;
  353.             push(@array, '  ') while $len++ < 16;
  354.             $format="0x%08x (%05d)" .
  355.                "   %s%s%s%s %s%s%s%s %s%s%s%s %s%s%s%s   %s\n";
  356.         }
  357.         $data =~ tr/\0-\37\177-\377/./;
  358.         printf $format,$offset,$offset,@array,$data;
  359.         $offset += 16;
  360.     }
  361. }
  362.  
  363. sub get_x224_crq_std_rdp_security {
  364.         return get_x224_connection_request("00");
  365. }
  366.  
  367. sub get_x224_crq_tls_security {
  368.         return get_x224_connection_request("01");
  369. }
  370.  
  371. sub get_x224_crq_credssp_security {
  372.         return get_x224_connection_request("03");
  373. }
  374.  
  375. sub get_x224_crq_classic {
  376.         return get_old_connection_request();
  377. }
  378.  
  379. # enc_hex is bitmask of:
  380. # 01 - 40 bit
  381. # 02 - 128 bit
  382. # 08 - 56 bit
  383. # 10 - fips
  384. #
  385. # common value sniffed from wireshark: 03
  386. sub get_mcs_initial_connect {
  387.         my $enc_hex = shift;
  388.         my @packet_hex = qw(
  389.         03 00  01 a2 02 f0 80 7f 65 82
  390.         01 96 04 01 01 04 01 01  01 01 ff 30 20 02 02 00
  391.         22 02 02 00 02 02 02 00  00 02 02 00 01 02 02 00
  392.         00 02 02 00 01 02 02 ff  ff 02 02 00 02 30 20 02
  393.         02 00 01 02 02 00 01 02  02 00 01 02 02 00 01 02
  394.         02 00 00 02 02 00 01 02  02 04 20 02 02 00 02 30
  395.         20 02 02 ff ff 02 02 fc  17 02 02 ff ff 02 02 00
  396.         01 02 02 00 00 02 02 00  01 02 02 ff ff 02 02 00
  397.         02 04 82 01 23 00 05 00  14 7c 00 01 81 1a 00 08
  398.         00 10 00 01 c0 00 44 75  63 61 81 0c 01 c0 d4 00
  399.         04 00 08 00 20 03 58 02  01 ca 03 aa 09 04 00 00
  400.         28 0a 00 00 68 00 6f 00  73 00 74 00 00 00 00 00
  401.         00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
  402.         00 00 00 00 04 00 00 00  00 00 00 00 0c 00 00 00
  403.         00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
  404.         00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
  405.         00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
  406.         00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
  407.         01 ca 01 00 00 00 00 00  18 00 07 00 01 00 00 00
  408.         00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
  409.         00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
  410.         00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
  411.         00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
  412.         04 c0 0c 00 09 00 00 00  00 00 00 00 02 c0 0c 00
  413.         );
  414.         push @packet_hex, $enc_hex;
  415.         push @packet_hex, qw(00 00 00 00 00 00 00  03 c0 20 00 02 00 00 00
  416.         63 6c 69 70 72 64 72 00  c0 a0 00 00 72 64 70 64
  417.         72 00 00 00 80 80 00 00                        
  418.         );
  419.         my $string = join("", @packet_hex);
  420.         $string =~ s/(..)/sprintf("%c", hex($1))/ge;
  421.         return $string;
  422. }
  423.  
  424. # MS-RDPBCGR
  425. sub get_x224_connection_request {
  426.         my $sec = shift;
  427.         my @packet_hex;
  428.         push @packet_hex, qw(03); # tpktHeader - version
  429.         push @packet_hex, qw(00); # tpktHeader - reserved
  430.         push @packet_hex, qw(00 13); # tpktHeader - length
  431.         push @packet_hex, qw(0e); # x224Crq - length
  432.         push @packet_hex, qw(e0); # x224Crq - connection request
  433.         push @packet_hex, qw(00 00); # x224Crq - ??
  434.         push @packet_hex, qw(00 00); # x224Crq - src-ref
  435.         push @packet_hex, qw(00); # x224Crq - class
  436.         push @packet_hex, qw(01); # rdpNegData - type
  437.         push @packet_hex, qw(00); # rdpNegData - flags
  438.         push @packet_hex, qw(08 00); # rdpNegData - length
  439.         push @packet_hex, ($sec, qw(00 00  00)); # rdpNegData - requestedProtocols.  bitmask, little endian: 0=standard rdp security, 1=TLSv1, 2=Hybrid (CredSSP)
  440.  
  441.         my $string = join("", @packet_hex);
  442.         $string =~ s/(..)/sprintf("%c", hex($1))/ge;
  443.         return $string;
  444. }
  445.  
  446. sub get_old_connection_request {
  447.         my @packet_hex = qw(
  448.                 03 00  00 22 1d e0 00 00 00 00
  449.                 00 43 6f 6f 6b 69 65 3a  20 6d 73 74 73 68 61 73
  450.                 68 3d 72 6f 6f 74 0d 0a                        
  451.         );
  452.         my $string = join("", @packet_hex);
  453.         $string =~ s/(..)/sprintf("%c", hex($1))/ge;
  454.         return $string;
  455. }
  456.  
  457. sub get_socket {
  458.         my ($ip, $port) = @_;
  459.         my $socket = new IO::Socket::INET (
  460.                 PeerHost => $ip,
  461.                 PeerPort => $port,
  462.                 Proto => 'tcp',
  463.         ) or die "ERROR in Socket Creation : $!\n";
  464.         return $socket;
  465. }
  466.  
  467. sub print_section {
  468.         my ($string) = @_;
  469.         print "\n=== $string ===\n\n";
  470. }
  471.  
  472. sub resolve {
  473.         my $hostname = shift;
  474.         print "[D] Resolving $hostname\n" if $debug > 0;
  475.         my $ip =  gethostbyname($hostname);
  476.         if (defined($ip)) {
  477.                 return inet_ntoa($ip);
  478.         } else {
  479.                 return undef;
  480.         }
  481. }

0 comentarios:

Publicar un comentario