2016-04-10 00:04:22 +00:00
package main
import (
"flag"
"fmt"
2016-05-03 14:31:56 +00:00
"github.com/s-rah/onionscan/config"
2016-04-25 09:29:27 +00:00
"github.com/s-rah/onionscan/report"
2016-04-10 00:04:22 +00:00
"io/ioutil"
"log"
"os"
2016-06-07 06:29:29 +00:00
"strings"
2016-04-10 00:04:22 +00:00
)
func main ( ) {
flag . Usage = func ( ) {
fmt . Printf ( "Usage of %s:\n" , os . Args [ 0 ] )
2016-06-07 06:29:29 +00:00
fmt . Printf ( " onionscan [flags] hiddenservice | onionscan [flags] --list list\n" )
2016-04-10 00:04:22 +00:00
flag . PrintDefaults ( )
}
torProxyAddress := flag . String ( "torProxyAddress" , "127.0.0.1:9050" , "the address of the tor proxy to use" )
simpleReport := flag . Bool ( "simpleReport" , true , "print out a simple report detailing what is wrong and how to fix it, true by default" )
2016-06-07 06:29:29 +00:00
reportFile := flag . String ( "reportFile" , "" , "the file destination path for report file - if given, the prefix of the file will be the scanned onion service. If not given, the report will be written to stdout" )
2016-04-10 00:04:22 +00:00
jsonReport := flag . Bool ( "jsonReport" , false , "print out a json report providing a detailed report of the scan." )
verbose := flag . Bool ( "verbose" , false , "print out a verbose log output of the scan" )
2016-05-05 14:32:28 +00:00
directoryDepth := flag . Int ( "depth" , 100 , "depth of directory scan recursion (default: 100)" )
2016-06-07 06:29:29 +00:00
fingerprint := flag . Bool ( "fingerprint" , true , "true disables some deeper scans e.g. directory probing with the aim of just getting a fingerprint of the service." )
list := flag . String ( "list" , "" , "If provided OnionScan will attempt to read from the given list, rather than the provided hidden service" )
timeout := flag . Int ( "timeout" , 120 , "read timeout for connecting to onion services" )
2016-04-10 00:04:22 +00:00
flag . Parse ( )
2016-06-07 06:29:29 +00:00
if len ( flag . Args ( ) ) != 1 && * list == "" {
2016-04-10 00:04:22 +00:00
flag . Usage ( )
os . Exit ( 1 )
}
2016-06-07 06:29:29 +00:00
if ! * simpleReport && ! * jsonReport {
log . Fatalf ( "You must set one of --simpleReport or --jsonReport" )
}
2016-04-10 00:04:22 +00:00
2016-06-07 06:29:29 +00:00
onionsToScan := [ ] string { }
if * list == "" {
onionsToScan = append ( onionsToScan , flag . Args ( ) [ 0 ] )
log . Printf ( "Starting Scan of %s\n" , flag . Args ( ) [ 0 ] )
} else {
content , err := ioutil . ReadFile ( * list )
if err != nil {
log . Fatalf ( "Could not read onion file %s\n" , * list )
}
onions := strings . Split ( string ( content ) , "\n" )
onionsToScan = append ( onionsToScan , onions ... )
log . Printf ( "Starting Scan of %d onion services\n" , len ( onionsToScan ) - 1 )
}
2016-04-10 00:04:22 +00:00
log . Printf ( "This might take a few minutes..\n\n" )
2016-06-07 06:29:29 +00:00
onionScan := new ( OnionScan )
onionScan . Config = config . Configure ( * torProxyAddress , * directoryDepth , * fingerprint , * timeout )
reports := make ( chan * report . OnionScanReport )
2016-04-10 00:04:22 +00:00
if ! * verbose {
log . SetOutput ( ioutil . Discard )
}
2016-06-07 06:29:29 +00:00
count := 0
max := 100
if max > len ( onionsToScan ) - 1 {
max = len ( onionsToScan ) - 1
2016-04-10 00:04:22 +00:00
}
2016-06-07 06:29:29 +00:00
// Run an initial batch of 100 requests (or less...)
for count < max {
go onionScan . Scan ( onionsToScan [ count ] , reports )
count ++
2016-04-10 00:04:22 +00:00
}
2016-06-05 18:54:01 +00:00
2016-06-07 06:29:29 +00:00
received := 0
for received < len ( onionsToScan ) - 1 {
scanReport := <- reports
// After the initial batch, it's one in one out to prevent proxy overload.
if count < len ( onionsToScan ) - 1 {
go onionScan . Scan ( onionsToScan [ count ] , reports )
count ++
}
received ++
2016-06-05 18:54:01 +00:00
2016-06-07 06:29:29 +00:00
if * jsonReport {
report . GenerateJsonReport ( * reportFile , scanReport )
} else if * simpleReport {
report . GenerateSimpleReport ( * reportFile , scanReport )
}
}
2016-04-10 00:04:22 +00:00
}