move config to protocol and pass it around instead of onion address

This commit is contained in:
Dan Ballard 2016-04-30 19:44:48 -07:00
parent 58094f810c
commit de0676cca7
11 changed files with 83 additions and 83 deletions

View File

@ -6,6 +6,7 @@ import (
"io/ioutil" "io/ioutil"
"log" "log"
"os" "os"
"github.com/s-rah/onionscan/protocol"
) )
func main() { 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") 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.") 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") 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() flag.Parse()
@ -38,7 +39,7 @@ func main() {
log.SetOutput(ioutil.Discard) log.SetOutput(ioutil.Discard)
} }
onionScan := Configure(*torProxyAddress, *directoryDepth) onionScan := protocol.Configure(*torProxyAddress, *directoryDepth)
report, err := onionScan.Scan(hiddenService) report, err := onionScan.Scan(hiddenService)
if err != nil { if err != nil {

View File

@ -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
}

View File

@ -9,10 +9,10 @@ import (
type BitcoinProtocolScanner struct { 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 // Bitcoin
log.Printf("Checking %s Bitcoin(8333)\n", hiddenService) 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 { if err != nil {
log.Printf("Failed to connect to service on port 8333\n") log.Printf("Failed to connect to service on port 8333\n")
} else { } else {

View File

@ -9,10 +9,10 @@ import (
type FTPProtocolScanner struct { 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 // FTP
log.Printf("Checking %s FTP(22)\n", hiddenService) 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 { if err != nil {
log.Printf("Failed to connect to service on port 21\n") log.Printf("Failed to connect to service on port 21\n")
} else { } else {

View File

@ -22,17 +22,17 @@ var (
"/products", "/products/cat"} "/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 // HTTP
log.Printf("Checking %s http(80)\n", hiddenService) 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 { if err != nil {
log.Printf("Failed to connect to service on port 80\n") log.Printf("Failed to connect to service on port 80\n")
} else { } else {
log.Printf("Found potential service on http(80)\n") log.Printf("Found potential service on http(80)\n")
report.WebDetected = true report.WebDetected = true
dialSocksProxy := socks.DialSocksProxy(socks.SOCKS5, proxyAddress) dialSocksProxy := socks.DialSocksProxy(socks.SOCKS5, os.TorProxyAddress)
transportConfig := &http.Transport{ transportConfig := &http.Transport{
Dial: dialSocksProxy, Dial: dialSocksProxy,
} }
@ -64,7 +64,7 @@ func (hps *HTTPProtocolScanner) ScanProtocol(hiddenService string, proxyAddress
directories := append(CommonDirectories, report.PageReferencedDirectories...) directories := append(CommonDirectories, report.PageReferencedDirectories...)
utils.RemoveDuplicates(&directories) utils.RemoveDuplicates(&directories)
for _, directory := range 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") log.Printf("\n")

View File

@ -9,10 +9,10 @@ import (
type IRCProtocolScanner struct { 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 // IRC
log.Printf("Checking %s IRC(6667)\n", hiddenService) 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 { if err != nil {
log.Printf("Failed to connect to service on port 6667\n") log.Printf("Failed to connect to service on port 6667\n")
} else { } else {

View File

@ -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
}

View File

@ -5,5 +5,5 @@ import (
) )
type ProtocolScanner interface { type ProtocolScanner interface {
ScanProtocol(hiddenService string, proxyAddress string, report *report.OnionScanReport) ScanProtocol(hiddenService string, os *ProtocolConfig, report *report.OnionScanReport)
} }

View File

@ -9,10 +9,10 @@ import (
type RicochetProtocolScanner struct { 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 // Ricochet
log.Printf("Checking %s ricochet(9878)\n", hiddenService) 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 { if err != nil {
log.Printf("Failed to connect to service on port 9878\n") log.Printf("Failed to connect to service on port 9878\n")
} else { } else {

View File

@ -9,10 +9,10 @@ import (
type SMTPProtocolScanner struct { 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 // SMTP
log.Printf("Checking %s SMTP(25)\n", hiddenService) 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 { if err != nil {
log.Printf("Failed to connect to service on port 25\n") log.Printf("Failed to connect to service on port 25\n")
} else { } else {

View File

@ -14,10 +14,10 @@ import (
type SSHProtocolScanner struct { 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 // SSH
log.Printf("Checking %s ssh(22)\n", hiddenService) 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 { if err != nil {
log.Printf("Failed to connect to service on port 22\n") log.Printf("Failed to connect to service on port 22\n")
} else { } else {