Advertisement
Doddy

Module DH Tools 0.3

Oct 13th, 2016
482
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6.67 KB | None | 0 0
  1. # Module : DH Tools
  2. # Version : 0.3
  3. # (C) Doddy Hackman 2016
  4.  
  5. package DH_Tools;
  6.  
  7. use LWP::UserAgent;
  8. use Try::Tiny;
  9. use File::Basename;
  10. use URI::Split qw(uri_split uri_join);
  11. use Digest::MD5;
  12. use IO::Socket;
  13.  
  14. my @agents = (
  15. 'Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:25.0) Gecko/20100101 Firefox/25.0',
  16.     'Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14',
  17. 'Mozilla/5.0 (Windows NT 6.2; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1667.0 Safari/537.36',
  18. 'Mozilla/5.0 (compatible; MSIE 10.6; Windows NT 6.1; Trident/5.0; InfoPath.2; SLCC1; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET CLR 2.0.50727) 3gpp-gba UNTRUSTED/1.0',
  19. 'Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.8.1.8pre) Gecko/20070928 Firefox/2.0.0.7 Navigator/9.0RC1',
  20.     'Mozilla/5.0 (Windows; U; MSIE 9.0; WIndows NT 9.0; en-US))',
  21. 'Mozilla/5.0 (Windows NT 6.0; rv:2.0) Gecko/20100101 Firefox/4.0 Opera 12.14',
  22. 'Mozilla/5.0 (Windows; U; Windows NT 6.1; tr-TR) AppleWebKit/533.20.25 (KHTML, like Gecko) Version/5.0.4 Safari/533.20.27'
  23. );
  24.  
  25. my $timeout = "10";
  26.  
  27. sub new {
  28.     my $class = shift;
  29.     my $self = {};
  30.     bless $self,$class;
  31.     return $self;
  32. }
  33.  
  34. sub toma {
  35.    
  36.     my ($self,$page) = @_;
  37.    
  38.     my $contenido = "";
  39.    
  40.     if($page ne "") {
  41.    
  42.         try {
  43.             my $nave = LWP::UserAgent->new;
  44.             $nave->agent( $agents[ rand @agents ] );
  45.             $nave->timeout($timeout);
  46.             $contenido = $nave->get($page)->content;
  47.         } catch {
  48.             $contenido = "Error";
  49.         };
  50.    
  51.     } else {
  52.         $contenido = "Error";
  53.     }
  54.    
  55.     return $contenido;
  56. }
  57.  
  58. sub tomar {
  59.    
  60.     my ($self,$page, $params ) = @_;
  61.    
  62.     my $contenido = "";
  63.    
  64.     if($page ne "" and $params ne "") {
  65.  
  66.         try {    
  67.             my $nave = LWP::UserAgent->new;
  68.             $nave->agent( $agents[ rand @agents ] );
  69.             $nave->timeout($timeout);
  70.             $contenido = $nave->post( $page, [ %{$params} ] )->content;
  71.         } catch {
  72.             $contenido = "Error";
  73.         };
  74.    
  75.     } else {
  76.         $contenido = "Error";
  77.     }
  78.        
  79.     return $contenido;
  80. }
  81.  
  82. sub savefile {
  83.    
  84.     my ($self,$filename,$text) = @_;
  85.  
  86.     my $response = 0;
  87.    
  88.     if($filename ne "" and $text ne "") {
  89.  
  90.         try {
  91.             open( SAVE, ">>" . $filename );
  92.             print SAVE $text . "\n";
  93.             close SAVE;
  94.             $response = 1;
  95.         } catch {
  96.             $response = 0;
  97.         };
  98.    
  99.     } else {
  100.         $response = 0;
  101.     }
  102.    
  103.     return $response;
  104.    
  105. }
  106.  
  107. sub console {
  108.    
  109.     my ($self,$command) = @_;
  110.    
  111.     my $response = "";
  112.    
  113.     if($command ne "") {
  114.         try {
  115.             $response = `$command`;
  116.         } catch {
  117.             $response = "Error";
  118.         };
  119.     } else {
  120.         $response = "Error";
  121.     }
  122.    
  123.     return $response;
  124.    
  125. }
  126.  
  127. sub http_fingerprinting {
  128.    
  129.     my ($self,$page,$option) = @_;
  130.    
  131.     my $response = "";
  132.    
  133.     if($page ne "") {
  134.        
  135.         my $nave = LWP::UserAgent->new;
  136.         $nave->agent( $agents[ rand @agents ] );
  137.         $nave->timeout($timeout);
  138.        
  139.         my $code = $nave->get($page);
  140.        
  141.         if($option eq "single") {
  142.             $response = $response . "[+] Date : " . $code->header('date');
  143.             $response = $response . "\n[+] Server : " . $code->header('server');
  144.             $response = $response . "\n[+] Connection : " . $code->header('connection');
  145.             $response = $response . "\n[+] Content-Type : " . $code->header('content-type');
  146.         } elsif($option eq "full") {
  147.             $response = $code->headers()->as_string();
  148.         } else {
  149.             $response = $code->headers()->as_string();
  150.         }
  151.     } else {
  152.         $response = "Error";
  153.     }
  154.    
  155.     return $response;
  156.    
  157. }
  158.  
  159. sub get_response_code {
  160.    
  161.     my ($self,$page) = @_;
  162.    
  163.     my $contenido = "";
  164.    
  165.     if($page ne "") {
  166.    
  167.         try {
  168.             my $nave = LWP::UserAgent->new;
  169.             $nave->agent( $agents[ rand @agents ] );
  170.             $nave->timeout($timeout);
  171.             $contenido = $nave->get($page)->code;
  172.         } catch {
  173.             $contenido = "Error";
  174.         };
  175.    
  176.     } else {
  177.         $contenido = "Error";
  178.     }
  179.    
  180.     return $contenido;
  181. }
  182.  
  183. sub repes {
  184.     my ($self,@array_to_clean) = @_;
  185.     my @limpio;
  186.     foreach $line (@array_to_clean) {
  187.         push @limpio, $line unless $repe{$line}++;
  188.     }
  189.     return @limpio;
  190. }
  191.  
  192. sub cortar {
  193.     my ($self,@array_to_cut) = @_;
  194.     my @limpio;
  195.     foreach $line (@array_to_cut) {
  196.         if($line=~/(.*?)=(.*?)/) {
  197.             my($parte_uno,$parte_dos) = ($1,$2);
  198.             my $url_ready = $parte_uno . "=";
  199.             push(@limpio,$url_ready);
  200.         }
  201.     }
  202.     return @limpio;
  203. }
  204.  
  205. sub regex {
  206.     my ($self,$code,$deaca,$hastaaca) = @_;
  207.    
  208.     my $response = "";
  209.    
  210.     if($code ne "" and $deaca ne "" and $hastaaca ne "") {
  211.         if($code=~/$deaca(.*?)$hastaaca/) {
  212.             $response = $1;
  213.         } else {
  214.             $response = "";
  215.         }
  216.     } else {
  217.         $response = "";
  218.     }
  219.    
  220.     return $response;
  221. }
  222.  
  223. sub download {
  224.    
  225.     my ($self,$url,$filename) = @_;
  226.    
  227.     my $response = 0;
  228.    
  229.     if($url ne "" and $filename ne "") {
  230.    
  231.         try {
  232.             my $nave = LWP::UserAgent->new;
  233.             $nave->agent( $agents[ rand @agents ] );
  234.             $nave->timeout($timeout);
  235.             if ($nave->mirror($url,$filename)) {
  236.                 if (-f $filename) {
  237.                     $response = 1;
  238.                 } else {
  239.                     $response = 0;
  240.                 }
  241.             } else {
  242.                 $response = 0;
  243.             }
  244.         } catch {
  245.             $response = 0;
  246.         };
  247.    
  248.     } else {
  249.         $response = 0;
  250.     }
  251.    
  252.     return $response;
  253. }
  254.  
  255. sub get_filename_by_url {
  256.    
  257.     my ($self,$page) = @_;
  258.    
  259.     my $filename = "";
  260.    
  261.     if($page ne "") {
  262.         my ($scheme, $auth, $path, $query, $frag) = uri_split($page);
  263.         $filename = basename($path);   
  264.     } else {
  265.         $filename = "";
  266.     }
  267.    
  268.     return $filename;
  269.    
  270. }
  271.  
  272. sub url_split {
  273.    
  274.     my ($self,$page,$option) = @_;
  275.    
  276.     my $response = "";
  277.    
  278.     if($page ne "" and $option ne "") {
  279.         my ($scheme, $auth, $path, $query, $frag) = uri_split($page);  
  280.         if($option eq "scheme") {  
  281.             $response = $scheme;
  282.         } elsif($option eq "auth") {
  283.             $response = $auth;
  284.         } elsif($option eq "path") {
  285.             $response = $path;
  286.         } elsif($option eq "query") {
  287.             $response = $query;
  288.         } elsif($option eq "frag") {
  289.             $response = $frag;
  290.         } else {
  291.             $response = $page;
  292.         }
  293.     } else {
  294.         $response = "";
  295.     }
  296.    
  297.     return $response;
  298.    
  299. }
  300.  
  301. sub md5_encode {
  302.     my ($self,$text) = @_;
  303.     my $response = "";
  304.     if($text ne "") {
  305.          $md5 = Digest::MD5->new;
  306.          $md5->add($text);
  307.          $response = $md5->hexdigest;
  308.     } else {
  309.         $response = "Error";
  310.     }
  311.     return $response;
  312. }
  313.  
  314. sub md5_file_encode {
  315.    
  316.     my ($self,$filename) = @_;
  317.    
  318.     my $response = "";
  319.    
  320.     if(-f $filename) {
  321.         open FILE, "$filename";
  322.         my $md5 = Digest::MD5->new;
  323.         $md5->addfile (*FILE);
  324.         $response = $md5->hexdigest;
  325.         close (FILE);      
  326.     } else {
  327.         $response = "Error";
  328.     }
  329.    
  330.     return $response;
  331.    
  332. }
  333.  
  334. sub get_ip {
  335.    
  336.     my ($self,$hostname) = @_;
  337.    
  338.     my $response = "";
  339.        
  340.     if($hostname ne "") {
  341.        
  342.         try {
  343.             my $handle_socket = gethostbyname($hostname);
  344.             $response = inet_ntoa($handle_socket);
  345.         } catch {
  346.             $response = "Error";
  347.         };
  348.        
  349.     } else {
  350.         $response = "Error";
  351.     }
  352.  
  353.     return $response;
  354.        
  355. }
  356.  
  357. sub destroy
  358. {
  359.    my $self=shift;
  360. }
  361.  
  362. 1;
  363.  
  364. # The End ?
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement