Changeset 227


Ignore:
Timestamp:
10/30/09 03:45:46 (4 years ago)
Author:
jabra
Message:

always print txt to stdout

File:
1 edited

Legend:

Unmodified
Added
Removed
  • fierce2/branch/fierce

    r225 r227  
    6464    } 
    6565} 
     66# handle output calls 
     67sub header_output { 
     68    my ($str) = @_; 
     69    $str = validate($str); 
     70    if ( $format eq 'txt' and $options{output} ) { 
     71        print FILE $str; 
     72    } 
     73    print $str; 
     74} 
     75 
    6676 
    6777# handle output calls 
     
    403413    } 
    404414} 
     415my $include_path_txt = $include_path; 
     416$include_path_txt =~ s/$format/txt/; 
     417# some useful options (see below for full list) 
     418my $config_txt = { 
     419    INCLUDE_PATH => "$include_path_txt", # or list ref 
     420    INTERPOLATE  => 1,                   # expand "$var" in plain text 
     421    POST_CHOMP   => 1,                   # cleanup whitespace 
     422    EVAL_PERL    => 1,                   # evaluate Perl code blocks 
     423}; 
     424# create Template object 
     425my $tt_txt = Template->new($config_txt); 
    405426 
    406427# some useful options (see below for full list) 
     
    411432    EVAL_PERL    => 1,                  # evaluate Perl code blocks 
    412433}; 
    413  
    414434# create Template object 
    415435my $tt = Template->new($config); 
     
    425445); 
    426446 
    427 sub template_output { 
     447sub tt_output_setup { 
    428448    my ( $obj, $result, $template ) = @_; 
    429449 
     
    438458        elasp    => $obj->elasp, 
    439459    }; 
    440  
     460    
     461    ## nmap output style 
    441462    # reference to output text string 
    442463    $tt->process( "$template", $vars, \$obj_output ) 
    443464        || die $tt->error(), "\n"; 
    444     output($obj_output); 
     465 
     466    return $obj_output; 
     467} 
     468 
     469sub tt_output_setup_txt { 
     470    my ( $obj, $result, $template ) = @_; 
     471 
     472    my $obj_output; 
     473 
     474    my $vars = { 
     475        result   => $result, 
     476        start    => $obj->start, 
     477        startstr => $obj->startstr, 
     478        end      => $obj->end, 
     479        endstr   => $obj->endstr, 
     480        elasp    => $obj->elasp, 
     481    }; 
     482    
     483    ## nmap output style 
     484    # reference to output text string 
     485    $tt_txt->process( "$template", $vars, \$obj_output ) 
     486        || die $tt_txt->error(), "\n"; 
     487 
     488 
     489    $obj_output = validate($obj_output); 
     490    return $obj_output; 
     491} 
     492 
     493 
     494sub template_output { 
     495    my ( $output,$output_txt ) = @_; 
     496    $output = validate($output); 
     497    $output_txt = validate($output_txt); 
     498 
     499    output($output); 
     500    if ( defined($filename) ) { 
     501        print $output_txt; 
     502    } 
    445503} 
    446504 
     
    491549    my $iprange_obj = IPrange->new( iprange => \@ipranges ); 
    492550 
    493     print "Finding Nearby IPs ... \n" 
    494         if ( $verbose > 0 or $format eq 'txt' ); 
     551    header_output("Finding Nearby IPs ... \n"); 
    495552    my $find_nearby = tFindNearby->new( 
    496553        search   => $search, 
     
    502559 
    503560    my $find_nearby_result = $find_nearby->result(); 
    504     template_output( $find_nearby, $find_nearby_result, 'find_nearby.tt' ); 
     561 
     562    template_output(  
     563        tt_output_setup(    $find_nearby,  
     564                            $find_nearby_result,  
     565                            'find_nearby.tt' ), 
     566        tt_output_setup_txt(    $find_nearby,  
     567                            $find_nearby_result,  
     568                            'find_nearby.tt' ), 
     569                     
     570                    ) ; 
    505571    exit; 
    506572} 
     
    533599            \$start_domainscan_output ) 
    534600            || die $tt->error(), "\n"; 
    535         output($start_domainscan_output); 
     601        my $start_domainscan_output_txt; 
     602        # reference to output text string 
     603        $tt_txt->process( 'start_domainscan.tt', $start_domainscan_vars, 
     604            \$start_domainscan_output_txt ) 
     605            || die $tt_txt->error(), "\n"; 
     606 
     607        template_output($start_domainscan_output,$start_domainscan_output_txt); 
    536608 
    537609        my ( $zt, $ns, $prefix_bf, $subdomain_bf, $reverse_lookup, $find_mx ); 
     
    545617        my ($find_nearby_result); 
    546618 
    547         print "Nameservers for $dns\n" 
    548             if ( $verbose > 0 or $format eq 'txt' ); 
     619        header_output("Nameservers for $dns\n"); 
    549620        $ns = NameServers->new(); 
    550621        $ns = $ns->execute( $domain, $base ); 
    551622 
    552623        my $ns_result = $ns->result(); 
    553         template_output( $ns, $ns_result, 'ns.tt' ); 
     624        template_output(  
     625            tt_output_setup( $ns, $ns_result, 'ns.tt' ), 
     626            tt_output_setup_txt( $ns, $ns_result, 'ns.tt' ), 
     627                        ); 
    554628 
    555629        if ( grep( !/arin/, $no ) ) { 
     
    566640                $arin_query =~ s/\..*//g; 
    567641            } 
    568             print "ARIN lookup $arin_query\n" 
    569                 if ( $verbose > 0 or $format eq 'txt' ); 
     642            header_output("ARIN lookup $arin_query\n"); 
    570643            my $arin = ARIN->new( query => $arin_query ); 
    571644            $arin = $arin->execute($domain); 
     
    587660            $tt->process( "arin.tt", $arin_vars, \$arin_output ) 
    588661                || die $tt->error(), "\n"; 
    589             output($arin_output); 
    590  
     662            my $arin_output_txt; 
     663 
     664            # reference to output text string 
     665            $tt_txt->process( "arin.tt", $arin_vars, \$arin_output_txt ) 
     666                || die $tt_txt->error(), "\n"; 
     667            template_output($arin_output,$arin_output_txt); 
    591668        } 
    592669 
     
    597674 
    598675        if ( grep( !/zt/, $no ) ) { 
    599             print "Trying Zone Transfer ... \n" 
    600                 if ( $verbose > 0 or $format eq 'txt' ); 
     676            header_output("Trying Zone Transfer ... \n"); 
    601677            $zt = ZoneTransfer->new(); 
    602678            $zt = $zt->execute( $domain, $base, $base->new_dns_resolver ); 
    603679 
    604680            $zt_result = $zt->result(); 
    605             template_output( $zt, $zt_result, 'zt.tt' ); 
     681            template_output( 
     682                    tt_output_setup( $zt, $zt_result, 'zt.tt'), 
     683                    tt_output_setup_txt( $zt, $zt_result, 'zt.tt'), 
     684                ); 
    606685        } 
    607686        unless ( $options{ztstop} and $zt->check == 1 ) { 
     
    612691            if ( grep( !/wildc/, $no ) ) { 
    613692 
    614                 print "Testing for Wildcards ... \n" 
    615                     if ( $verbose > 0 or $format eq 'txt' ); 
     693                header_output("Testing for Wildcards ... \n"); 
    616694 
    617695                $wildcard = CheckWildCard->new(); 
     
    619697 
    620698                $wildcard_result = $wildcard->result(); 
    621                 template_output( $wildcard, $wildcard_result, 'wildcard.tt' ); 
     699                template_output( 
     700                    tt_output_setup( $wildcard, $wildcard_result, 'wildcard.tt' ), 
     701                    tt_output_setup_txt( $wildcard, $wildcard_result, 'wildcard.tt' ), 
     702                ); 
    622703            } 
    623704            unless ($options{wildcstop} 
     
    631712                if ( grep( !/prebf/, $no ) ) { 
    632713 
    633                     print "Trying Prefix Bruteforce ... \n" 
    634                         if ( $verbose > 0 or $format eq 'txt' ); 
     714                    header_output("Trying Prefix Bruteforce ... \n"); 
    635715 
    636716                    $prefix_bf = tBruteForceDNS->new( 
     
    641721 
    642722                    $prefix_bf_result = $prefix_bf->result(); 
    643                     template_output( $prefix_bf, $prefix_bf_result, 
    644                         'prefix_bf.tt' ); 
     723                    template_output( 
     724                            tt_output_setup( $prefix_bf, $prefix_bf_result, 
     725                        'prefix_bf.tt' ), 
     726                            tt_output_setup_txt( $prefix_bf, $prefix_bf_result, 
     727                        'prefix_bf.tt' ), 
     728                    ); 
    645729                } 
    646730                ##################################### 
     
    649733                # 
    650734                if ( grep( !/subbf/, $no ) ) { 
    651                     print "Trying Subdomain Bruteforce ... \n" 
    652                         if ( $verbose > 0 or $format eq 'txt' ); 
     735                    header_output("Trying Subdomain Bruteforce ... \n"); 
    653736 
    654737                    my @subdomain_prefix_list = ( 'www', 'mail' ); 
     
    662745 
    663746                    $subdomain_bf_result = $subdomain_bf->result(); 
    664                     template_output( $subdomain_bf, $subdomain_bf_result, 
    665                         'subdomain_bf.tt' ); 
     747                    template_output( 
     748                        tt_output_setup( $subdomain_bf, $subdomain_bf_result, 
     749                        'subdomain_bf.tt' ), 
     750                         tt_output_setup_txt( $subdomain_bf, $subdomain_bf_result, 
     751                        'subdomain_bf.tt' ), 
     752                 
     753                ); 
    666754                } 
    667755            } 
     
    672760            if ( grep( !/extbf/, $no ) ) { 
    673761 
    674                 print "Trying Extension Bruteforce ... \n" 
    675                     if ( $verbose > 0 or $format eq 'txt' ); 
     762                header_output("Trying Extension Bruteforce ... \n"); 
    676763 
    677764                $ext_bf = tExtensionBruteForceDNS->new( 
     
    679766                $ext_bf        = $ext_bf->execute($domain); 
    680767                $ext_bf_result = $ext_bf->result(); 
    681                 template_output( $ext_bf, $ext_bf_result, 'ext_bf.tt' ); 
     768                template_output( 
     769                    tt_output_setup( $ext_bf, $ext_bf_result, 'ext_bf.tt' ), 
     770                    tt_output_setup_txt( $ext_bf, $ext_bf_result, 'ext_bf.tt' ), 
     771                ); 
    682772            } 
    683773            ###################################### 
     
    687777            if ( grep( !/vhost/, $no ) ) { 
    688778 
    689                 print "Testing for Virtual Hosts ... \n" 
    690                     if ( $verbose > 0 or $format eq 'txt' ); 
     779                header_output("Testing for Virtual Hosts ... \n"); 
    691780 
    692781                my $vhost = tVhost->new(); 
     
    694783 
    695784                $vhost_result = $vhost->result(); 
    696                 template_output( $vhost, $vhost_result, 'vhost.tt' ); 
     785                template_output( 
     786                        tt_output_setup( $vhost, $vhost_result, 'vhost.tt' ), 
     787                        tt_output_setup_txt( $vhost, $vhost_result, 'vhost.tt' ), 
     788                    ); 
    697789            } 
    698790            ################################################ 
     
    702794            if ( grep( !/findmx/, $no ) ) { 
    703795 
    704                 print "Looking for MX records ... \n" 
    705                     if ( $verbose > 0 or $format eq 'txt' ); 
     796                header_output("Looking for MX records ... \n"); 
    706797                $find_mx = tFindMX->new(); 
    707798                $find_mx 
    708799                    = $find_mx->execute( $domain, $base->new_dns_resolver ); 
    709800                $find_mx_result = $find_mx->result(); 
    710                 template_output( $find_mx, $find_mx_result, 'find_mx.tt' ); 
     801                template_output( 
     802                        tt_output_setup( $find_mx, $find_mx_result, 'find_mx.tt' ), 
     803                        tt_output_setup_txt( $find_mx, $find_mx_result, 'find_mx.tt' ), 
     804                    ); 
    711805            } 
    712806            ##################################################### 
     
    716810            if ( grep( !/whois/, $no ) ) { 
    717811 
    718                 print "Performing Whois Lookups ... \n" 
    719                     if ( $verbose > 0 or $format eq 'txt' ); 
     812                header_output("Performing Whois Lookups ... \n"); 
    720813 
    721814                $whois = WhoisLookup->new(); 
     
    723816 
    724817                $whois_result = $whois->result(); 
    725                 template_output( $whois, $whois_result, 'whois.tt' ); 
     818                template_output( 
     819                        tt_output_setup( $whois, $whois_result, 'whois.tt' ), 
     820                        tt_output_setup_txt( $whois, $whois_result, 'whois.tt' ), 
     821                    ); 
    726822            } 
    727823 
     
    735831                    $prefix_cnames = $prefix_bf->cnames; 
    736832                } 
    737                 print "Performing Reverse Lookups ... \n" 
    738                     if ( $verbose > 0 or $format eq 'txt' ); 
     833                header_output("Performing Reverse Lookups ... \n"); 
    739834                $reverse_lookup = tReverseLookup->new( 
    740835                    max_lookups   => $max_lookups, 
     
    744839 
    745840                $reverse_lookup_result = $reverse_lookup->result(); 
    746                 template_output( $reverse_lookup, $reverse_lookup_result, 
    747                     'reverse_lookup.tt' ); 
     841                template_output( 
     842                        tt_output_setup( $reverse_lookup, $reverse_lookup_result,'reverse_lookup.tt' ), 
     843                         tt_output_setup_txt( $reverse_lookup, $reverse_lookup_result,'reverse_lookup.tt' ), 
     844                    ); 
    748845            } 
    749846            ######################################################### 
     
    771868                my $iprange_obj = IPrange->new( iprange => \@ipranges ); 
    772869 
    773                 print "Finding Nearby IPs ... \n" 
    774                     if ( $verbose > 0 or $format eq 'txt' ); 
     870                header_output("Finding Nearby IPs ... \n"); 
    775871                $find_nearby = tFindNearby->new( 
    776872                    search     => $search, 
     
    783879 
    784880                $find_nearby_result = $find_nearby->result(); 
    785                 template_output( $find_nearby, $find_nearby_result, 
    786                     'find_nearby.tt' ); 
     881                template_output( 
     882                    tt_output_setup( $find_nearby, $find_nearby_result, 
     883                    'find_nearby.tt' ), 
     884                    tt_output_setup_txt( $find_nearby, $find_nearby_result, 
     885                    'find_nearby.tt' ), 
     886                ); 
    787887            } 
    788888        } 
     
    806906            || die $tt->error(), 
    807907            "\n"; 
    808         output($end_domainscan_output); 
     908         
     909        my $end_domainscan_output_txt; 
     910        # reference to output text string 
     911        $tt_txt->process( 'end_domainscan.tt', $end_domainscan_vars, 
     912        \$end_domainscan_output_txt ) 
     913        || die $tt_txt->error(), 
     914            "\n"; 
     915 
     916        template_output($end_domainscan_output,$end_domainscan_output_txt); 
    809917    } 
    810918 
     
    825933        \$end_fiercescan_output ) 
    826934        || die $tt->error(), "\n"; 
    827     output($end_fiercescan_output); 
     935     
     936    my $end_fiercescan_output_txt; 
     937    # reference to output text string 
     938    $tt_txt->process( 'end_fiercescan.tt', $end_fiercescan_vars, 
     939    \$end_fiercescan_output_txt ) 
     940    || die $tt_txt->error(), 
     941    "\n"; 
     942 
     943    template_output($end_fiercescan_output); 
    828944} 
    829945else { 
Note: See TracChangeset for help on using the changeset viewer.