diff --git a/main.go b/main.go index 7a86cd0..181a6a0 100644 --- a/main.go +++ b/main.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "log" "os" + "github.com/s-rah/onionscan/protocol" ) func main() { @@ -20,7 +21,7 @@ func main() { simpleReport := flag.Bool("simpleReport", true, "print out a simple report detailing what is wrong and how to fix it, true by default") 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") - directoryDepth := flag.Int("d", 0, "depth of directory scan recursion (default: 0)") + directoryDepth := flag.Int("d", 100, "depth of directory scan recursion (default: 100)") flag.Parse() @@ -38,7 +39,7 @@ func main() { log.SetOutput(ioutil.Discard) } - onionScan := Configure(*torProxyAddress, *directoryDepth) + onionScan := protocol.Configure(*torProxyAddress, *directoryDepth) report, err := onionScan.Scan(hiddenService) if err != nil { diff --git a/onionscan.go b/onionscan.go deleted file mode 100644 index 764d468..0000000 --- a/onionscan.go +++ /dev/null @@ -1,64 +0,0 @@ -package main - -import ( - "github.com/s-rah/onionscan/protocol" - "github.com/s-rah/onionscan/report" - "strings" -) - -type OnionScan struct { - TorProxyAddress string - DirectoryDepth int -} - -func Configure(torProxyAddress string, directoryDepth int) *OnionScan { - onionScan := new(OnionScan) - onionScan.TorProxyAddress = torProxyAddress - onionScan.DirectoryDepth = directoryDepth - return onionScan -} - -func (os *OnionScan) Scan(hiddenService string) (*report.OnionScanReport, error) { - - // Remove Extra Prefix - // TODO: Add support for HTTPS? - if strings.HasPrefix(hiddenService, "http://") { - hiddenService = hiddenService[7:] - } - - if strings.HasSuffix(hiddenService, "/") { - hiddenService = hiddenService[0 : len(hiddenService)-1] - } - - report := report.NewOnionScanReport(hiddenService) - - // HTTP - hps := new(protocol.HTTPProtocolScanner) - hps.ScanProtocol(hiddenService, os.TorProxyAddress, os.DirectoryDepth, report) - - // SSH - sps := new(protocol.SSHProtocolScanner) - sps.ScanProtocol(hiddenService, os.TorProxyAddress, report) - - // Ricochet - rps := new(protocol.RicochetProtocolScanner) - rps.ScanProtocol(hiddenService, os.TorProxyAddress, report) - - // Bitcoin - bps := new(protocol.BitcoinProtocolScanner) - bps.ScanProtocol(hiddenService, os.TorProxyAddress, report) - - //IRC - ips := new(protocol.IRCProtocolScanner) - ips.ScanProtocol(hiddenService, os.TorProxyAddress, report) - - //FTP - fps := new(protocol.FTPProtocolScanner) - fps.ScanProtocol(hiddenService, os.TorProxyAddress, report) - - //SMTP - smps := new(protocol.SMTPProtocolScanner) - smps.ScanProtocol(hiddenService, os.TorProxyAddress, report) - - return report, nil -} diff --git a/protocol/bitcoin_scanner.go b/protocol/bitcoin_scanner.go index fc2ff67..4eeb12b 100644 --- a/protocol/bitcoin_scanner.go +++ b/protocol/bitcoin_scanner.go @@ -9,10 +9,10 @@ import ( type BitcoinProtocolScanner struct { } -func (rps *BitcoinProtocolScanner) ScanProtocol(hiddenService string, proxyAddress string, report *report.OnionScanReport) { +func (rps *BitcoinProtocolScanner) ScanProtocol(hiddenService string, os *ProtocolConfig, report *report.OnionScanReport) { // Bitcoin log.Printf("Checking %s Bitcoin(8333)\n", hiddenService) - _, err := socks.DialSocksProxy(socks.SOCKS5, proxyAddress)("", hiddenService+":8333") + _, err := socks.DialSocksProxy(socks.SOCKS5, os.TorProxyAddress)("", hiddenService+":8333") if err != nil { log.Printf("Failed to connect to service on port 8333\n") } else { diff --git a/protocol/ftp_scanner.go b/protocol/ftp_scanner.go index cd09564..d09fc6b 100644 --- a/protocol/ftp_scanner.go +++ b/protocol/ftp_scanner.go @@ -9,10 +9,10 @@ import ( type FTPProtocolScanner struct { } -func (sps *FTPProtocolScanner) ScanProtocol(hiddenService string, proxyAddress string, report *report.OnionScanReport) { +func (sps *FTPProtocolScanner) ScanProtocol(hiddenService string, os *ProtocolConfig, report *report.OnionScanReport) { // FTP log.Printf("Checking %s FTP(22)\n", hiddenService) - _, err := socks.DialSocksProxy(socks.SOCKS5, proxyAddress)("", hiddenService+":21") + _, err := socks.DialSocksProxy(socks.SOCKS5, os.TorProxyAddress)("", hiddenService+":21") if err != nil { log.Printf("Failed to connect to service on port 21\n") } else { diff --git a/protocol/http_scanner.go b/protocol/http_scanner.go index d8056f5..7d1abb7 100644 --- a/protocol/http_scanner.go +++ b/protocol/http_scanner.go @@ -22,17 +22,17 @@ var ( "/products", "/products/cat"} ) -func (hps *HTTPProtocolScanner) ScanProtocol(hiddenService string, proxyAddress string, directoryDepth int, report *report.OnionScanReport) { +func (hps *HTTPProtocolScanner) ScanProtocol(hiddenService string, os *ProtocolConfig, report *report.OnionScanReport) { // HTTP log.Printf("Checking %s http(80)\n", hiddenService) - _, err := socks.DialSocksProxy(socks.SOCKS5, proxyAddress)("", hiddenService+":80") + _, err := socks.DialSocksProxy(socks.SOCKS5, os.TorProxyAddress)("", hiddenService+":80") if err != nil { log.Printf("Failed to connect to service on port 80\n") } else { log.Printf("Found potential service on http(80)\n") report.WebDetected = true - dialSocksProxy := socks.DialSocksProxy(socks.SOCKS5, proxyAddress) + dialSocksProxy := socks.DialSocksProxy(socks.SOCKS5, os.TorProxyAddress) transportConfig := &http.Transport{ Dial: dialSocksProxy, } @@ -64,7 +64,7 @@ func (hps *HTTPProtocolScanner) ScanProtocol(hiddenService string, proxyAddress directories := append(CommonDirectories, report.PageReferencedDirectories...) utils.RemoveDuplicates(&directories) for _, directory := range directories { - hps.ScanPage(hiddenService, directory, report, scans.CheckDirectoryListing(directoryDepth)) + hps.ScanPage(hiddenService, directory, report, scans.CheckDirectoryListing(os.DirectoryDepth)) } } log.Printf("\n") diff --git a/protocol/irc_scanner.go b/protocol/irc_scanner.go index ae0e9f1..8db7732 100644 --- a/protocol/irc_scanner.go +++ b/protocol/irc_scanner.go @@ -9,10 +9,10 @@ import ( type IRCProtocolScanner struct { } -func (rps *IRCProtocolScanner) ScanProtocol(hiddenService string, proxyAddress string, report *report.OnionScanReport) { +func (rps *IRCProtocolScanner) ScanProtocol(hiddenService string, os *ProtocolConfig, report *report.OnionScanReport) { // IRC log.Printf("Checking %s IRC(6667)\n", hiddenService) - _, err := socks.DialSocksProxy(socks.SOCKS5, proxyAddress)("", hiddenService+":6667") + _, err := socks.DialSocksProxy(socks.SOCKS5, os.TorProxyAddress)("", hiddenService+":6667") if err != nil { log.Printf("Failed to connect to service on port 6667\n") } else { diff --git a/protocol/protocol_config.go b/protocol/protocol_config.go new file mode 100644 index 0000000..7b239b3 --- /dev/null +++ b/protocol/protocol_config.go @@ -0,0 +1,63 @@ +package protocol + +import ( + "github.com/s-rah/onionscan/report" + "strings" +) + +type ProtocolConfig struct { + TorProxyAddress string + DirectoryDepth int +} + +func Configure(torProxyAddress string, directoryDepth int) *ProtocolConfig { + onionScan := new(ProtocolConfig) + onionScan.TorProxyAddress = torProxyAddress + onionScan.DirectoryDepth = directoryDepth + return onionScan +} + +func (os *ProtocolConfig) Scan(hiddenService string) (*report.OnionScanReport, error) { + + // Remove Extra Prefix + // TODO: Add support for HTTPS? + if strings.HasPrefix(hiddenService, "http://") { + hiddenService = hiddenService[7:] + } + + if strings.HasSuffix(hiddenService, "/") { + hiddenService = hiddenService[0 : len(hiddenService)-1] + } + + report := report.NewOnionScanReport(hiddenService) + + // HTTP + hps := new(HTTPProtocolScanner) + hps.ScanProtocol(hiddenService, os, report) + + // SSH + sps := new(SSHProtocolScanner) + sps.ScanProtocol(hiddenService, os, report) + + // Ricochet + rps := new(RicochetProtocolScanner) + rps.ScanProtocol(hiddenService, os, report) + + // Bitcoin + bps := new(BitcoinProtocolScanner) + bps.ScanProtocol(hiddenService, os, report) + + //IRC + ips := new(IRCProtocolScanner) + ips.ScanProtocol(hiddenService, os, report) + + //FTP + fps := new(FTPProtocolScanner) + fps.ScanProtocol(hiddenService, os, report) + + //SMTP + smps := new(SMTPProtocolScanner) + smps.ScanProtocol(hiddenService, os, report) + + return report, nil +} diff --git a/protocol/protocol_scanner.go b/protocol/protocol_scanner.go index 133352b..e09200e 100644 --- a/protocol/protocol_scanner.go +++ b/protocol/protocol_scanner.go @@ -5,5 +5,5 @@ import ( ) type ProtocolScanner interface { - ScanProtocol(hiddenService string, proxyAddress string, report *report.OnionScanReport) + ScanProtocol(hiddenService string, os *ProtocolConfig, report *report.OnionScanReport) } diff --git a/protocol/ricochet_scanner.go b/protocol/ricochet_scanner.go index d2f678b..09d7e65 100644 --- a/protocol/ricochet_scanner.go +++ b/protocol/ricochet_scanner.go @@ -9,10 +9,10 @@ import ( type RicochetProtocolScanner struct { } -func (rps *RicochetProtocolScanner) ScanProtocol(hiddenService string, proxyAddress string, report *report.OnionScanReport) { +func (rps *RicochetProtocolScanner) ScanProtocol(hiddenService string, os *ProtocolConfig, report *report.OnionScanReport) { // Ricochet log.Printf("Checking %s ricochet(9878)\n", hiddenService) - _, err := socks.DialSocksProxy(socks.SOCKS5, proxyAddress)("", hiddenService+":9878") + _, err := socks.DialSocksProxy(socks.SOCKS5, os.TorProxyAddress)("", hiddenService+":9878") if err != nil { log.Printf("Failed to connect to service on port 9878\n") } else { diff --git a/protocol/smtp_scanner.go b/protocol/smtp_scanner.go index 9e5f25a..b467ad9 100644 --- a/protocol/smtp_scanner.go +++ b/protocol/smtp_scanner.go @@ -9,10 +9,10 @@ import ( type SMTPProtocolScanner struct { } -func (sps *SMTPProtocolScanner) ScanProtocol(hiddenService string, proxyAddress string, report *report.OnionScanReport) { +func (sps *SMTPProtocolScanner) ScanProtocol(hiddenService string, os *ProtocolConfig, report *report.OnionScanReport) { // SMTP log.Printf("Checking %s SMTP(25)\n", hiddenService) - _, err := socks.DialSocksProxy(socks.SOCKS5, proxyAddress)("", hiddenService+":25") + _, err := socks.DialSocksProxy(socks.SOCKS5, os.TorProxyAddress)("", hiddenService+":25") if err != nil { log.Printf("Failed to connect to service on port 25\n") } else { diff --git a/protocol/ssh_scanner.go b/protocol/ssh_scanner.go index 668a3d0..57cea23 100644 --- a/protocol/ssh_scanner.go +++ b/protocol/ssh_scanner.go @@ -14,10 +14,10 @@ import ( type SSHProtocolScanner struct { } -func (sps *SSHProtocolScanner) ScanProtocol(hiddenService string, proxyAddress string, report *report.OnionScanReport) { +func (sps *SSHProtocolScanner) ScanProtocol(hiddenService string, os *ProtocolConfig, report *report.OnionScanReport) { // SSH log.Printf("Checking %s ssh(22)\n", hiddenService) - conn, err := socks.DialSocksProxy(socks.SOCKS5, proxyAddress)("", hiddenService+":22") + conn, err := socks.DialSocksProxy(socks.SOCKS5, os.TorProxyAddress)("", hiddenService+":22") if err != nil { log.Printf("Failed to connect to service on port 22\n") } else {