Don't Crash When Tor Proxy is Not Up

This commit is contained in:
Sarah Jamie Lewis 2016-07-31 12:05:42 -07:00
parent 76ffa74b5d
commit 7068ce8442
13 changed files with 64 additions and 35 deletions

View File

@ -92,7 +92,7 @@ func main() {
file := *reportFile file := *reportFile
if file != "" { if file != "" {
file := scanReport.HiddenService + "." + *reportFile file = scanReport.HiddenService + "." + *reportFile
} }
if *jsonReport { if *jsonReport {

View File

@ -22,5 +22,7 @@ func (rps *BitcoinProtocolScanner) ScanProtocol(hiddenService string, osc *confi
// TODO: Actual Analysis // TODO: Actual Analysis
report.BitcoinDetected = true report.BitcoinDetected = true
} }
if conn != nil {
conn.Close() conn.Close()
}
} }

View File

@ -31,5 +31,7 @@ func (sps *FTPProtocolScanner) ScanProtocol(hiddenService string, osc *config.On
osc.LogInfo(fmt.Sprintf("Found FTP Banner: %s (%s)", banner, report.FTPFingerprint)) osc.LogInfo(fmt.Sprintf("Found FTP Banner: %s (%s)", banner, report.FTPFingerprint))
} }
} }
if conn != nil {
conn.Close() conn.Close()
}
} }

View File

@ -1,6 +1,7 @@
package protocol package protocol
import ( import (
"crypto/tls"
"fmt" "fmt"
"github.com/s-rah/onionscan/config" "github.com/s-rah/onionscan/config"
"github.com/s-rah/onionscan/report" "github.com/s-rah/onionscan/report"
@ -10,7 +11,6 @@ import (
"io/ioutil" "io/ioutil"
"net/http" "net/http"
"strings" "strings"
"crypto/tls"
) )
type HTTPProtocolScanner struct { type HTTPProtocolScanner struct {
@ -33,7 +33,9 @@ func (hps *HTTPProtocolScanner) ScanProtocol(hiddenService string, osc *config.O
if err != nil { if err != nil {
osc.LogInfo("Failed to connect to service on port 80\n") osc.LogInfo("Failed to connect to service on port 80\n")
report.WebDetected = false report.WebDetected = false
if conn != nil {
conn.Close() conn.Close()
}
} else { } else {
osc.LogInfo("Found potential service on http(80)\n") osc.LogInfo("Found potential service on http(80)\n")
report.WebDetected = true report.WebDetected = true
@ -45,7 +47,6 @@ func (hps *HTTPProtocolScanner) ScanProtocol(hiddenService string, osc *config.O
} }
hps.Client = &http.Client{ hps.Client = &http.Client{
Transport: transportConfig, Transport: transportConfig,
} }
// FIXME This should probably be moved to it's own file now. // FIXME This should probably be moved to it's own file now.
response, err := hps.Client.Get("http://" + hiddenService) response, err := hps.Client.Get("http://" + hiddenService)

View File

@ -22,7 +22,9 @@ func (rps *IRCProtocolScanner) ScanProtocol(hiddenService string, osc *config.On
// TODO: Actual Analysis // TODO: Actual Analysis
report.IRCDetected = true report.IRCDetected = true
} }
if conn != nil {
conn.Close() conn.Close()
}
// IRC // IRC
osc.LogInfo(fmt.Sprintf("Checking %s IRC(6697)\n", hiddenService)) osc.LogInfo(fmt.Sprintf("Checking %s IRC(6697)\n", hiddenService))
@ -34,5 +36,7 @@ func (rps *IRCProtocolScanner) ScanProtocol(hiddenService string, osc *config.On
// TODO: Actual Analysis // TODO: Actual Analysis
report.IRCDetected = true report.IRCDetected = true
} }
if conn != nil {
conn.Close() conn.Close()
}
} }

View File

@ -22,6 +22,8 @@ func (rps *MongoDBProtocolScanner) ScanProtocol(hiddenService string, osc *confi
// TODO: Actual Analysis // TODO: Actual Analysis
report.MongoDBDetected = true report.MongoDBDetected = true
} }
if conn != nil {
conn.Close() conn.Close()
}
} }

View File

@ -22,5 +22,7 @@ func (rps *RicochetProtocolScanner) ScanProtocol(hiddenService string, osc *conf
// TODO: Actual Analysis // TODO: Actual Analysis
report.RicochetDetected = true report.RicochetDetected = true
} }
if conn != nil {
conn.Close() conn.Close()
}
} }

View File

@ -32,5 +32,7 @@ func (sps *SMTPProtocolScanner) ScanProtocol(hiddenService string, osc *config.O
osc.LogInfo(fmt.Sprintf("Found SMTP Banner: %s (%s)", banner, report.SMTPFingerprint)) osc.LogInfo(fmt.Sprintf("Found SMTP Banner: %s (%s)", banner, report.SMTPFingerprint))
} }
} }
if conn != nil {
conn.Close() conn.Close()
}
} }

View File

@ -22,7 +22,9 @@ func (sps *SSHProtocolScanner) ScanProtocol(hiddenService string, osc *config.On
if err != nil { if err != nil {
osc.LogInfo("Failed to connect to service on port 22\n") osc.LogInfo("Failed to connect to service on port 22\n")
report.SSHDetected = false report.SSHDetected = false
if conn != nil {
conn.Close() conn.Close()
}
} else { } else {
// TODO SSH Checking // TODO SSH Checking
report.SSHDetected = true report.SSHDetected = true
@ -48,7 +50,9 @@ func (sps *SSHProtocolScanner) ScanProtocol(hiddenService string, osc *config.On
}, },
} }
ssh.NewClientConn(conn, hiddenService+":22", config) ssh.NewClientConn(conn, hiddenService+":22", config)
if conn != nil {
conn.Close() conn.Close()
}
conn, err = utils.GetNetworkConnection(hiddenService, 22, osc.TorProxyAddress, osc.Timeout) conn, err = utils.GetNetworkConnection(hiddenService, 22, osc.TorProxyAddress, osc.Timeout)
if err == nil { if err == nil {
reader := bufio.NewReader(conn) reader := bufio.NewReader(conn)
@ -58,6 +62,8 @@ func (sps *SSHProtocolScanner) ScanProtocol(hiddenService string, osc *config.On
osc.LogInfo(fmt.Sprintf("Found SSH Banner: %s (%s)", banner)) osc.LogInfo(fmt.Sprintf("Found SSH Banner: %s (%s)", banner))
} }
} }
if conn != nil {
conn.Close() conn.Close()
} }
}
} }

View File

@ -21,7 +21,7 @@ func (sps *TLSProtocolScanner) ScanProtocol(hiddenService string, osc *config.On
osc.LogInfo("Found TLS Endpoint\n") osc.LogInfo("Found TLS Endpoint\n")
report.TLSDetected = true report.TLSDetected = true
config := &tls.Config{ config := &tls.Config{
InsecureSkipVerify:true, InsecureSkipVerify: true,
} }
tlsConn := tls.Client(conn, config) tlsConn := tls.Client(conn, config)
tlsConn.Write([]byte("GET / HTTP/1.1\r\n\r\n")) tlsConn.Write([]byte("GET / HTTP/1.1\r\n\r\n"))
@ -31,5 +31,7 @@ func (sps *TLSProtocolScanner) ScanProtocol(hiddenService string, osc *config.On
} }
tlsConn.Close() tlsConn.Close()
} }
if conn != nil {
conn.Close() conn.Close()
}
} }

View File

@ -22,5 +22,7 @@ func (vncps *VNCProtocolScanner) ScanProtocol(hiddenService string, osc *config.
// TODO: Actual Analysis // TODO: Actual Analysis
report.VNCDetected = true report.VNCDetected = true
} }
if conn != nil {
conn.Close() conn.Close()
}
} }

View File

@ -22,7 +22,9 @@ func (rps *XMPPProtocolScanner) ScanProtocol(hiddenService string, osc *config.O
// TODO: Actual Analysis // TODO: Actual Analysis
report.XMPPDetected = true report.XMPPDetected = true
} }
if conn != nil {
conn.Close() conn.Close()
}
// XMPP // XMPP
osc.LogInfo(fmt.Sprintf("Checking %s XMPP(5223)\n", hiddenService)) osc.LogInfo(fmt.Sprintf("Checking %s XMPP(5223)\n", hiddenService))
conn, err = utils.GetNetworkConnection(hiddenService, 5223, osc.TorProxyAddress, osc.Timeout) conn, err = utils.GetNetworkConnection(hiddenService, 5223, osc.TorProxyAddress, osc.Timeout)
@ -33,5 +35,7 @@ func (rps *XMPPProtocolScanner) ScanProtocol(hiddenService string, osc *config.O
// TODO: Actual Analysis // TODO: Actual Analysis
report.XMPPDetected = true report.XMPPDetected = true
} }
if conn != nil {
conn.Close() conn.Close()
}
} }

View File

@ -1,11 +1,11 @@
package report package report
import ( import (
"crypto/x509"
"encoding/json" "encoding/json"
"github.com/s-rah/onionscan/utils" "github.com/s-rah/onionscan/utils"
"io/ioutil" "io/ioutil"
"time" "time"
"crypto/x509"
) )
type ExifTag struct { type ExifTag struct {