Skip to content

Commit

Permalink
Don't Crash When Tor Proxy is Not Up
Browse files Browse the repository at this point in the history
  • Loading branch information
s-rah committed Jul 31, 2016
1 parent 76ffa74 commit 7068ce8
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 35 deletions.
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ func main() {
onionScan.Config.LogError(errors.New(scanReport.HiddenService + " timed out"))
}

file := *reportFile
if file != "" {
file := scanReport.HiddenService + "." + *reportFile
file := *reportFile
if file != "" {
file = scanReport.HiddenService + "." + *reportFile
}

if *jsonReport {
Expand Down
4 changes: 3 additions & 1 deletion protocol/bitcoin_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ func (rps *BitcoinProtocolScanner) ScanProtocol(hiddenService string, osc *confi
// TODO: Actual Analysis
report.BitcoinDetected = true
}
conn.Close()
if conn != nil {
conn.Close()
}
}
4 changes: 3 additions & 1 deletion protocol/ftp_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
conn.Close()
if conn != nil {
conn.Close()
}
}
9 changes: 5 additions & 4 deletions protocol/http_scanner.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package protocol

import (
"crypto/tls"
"fmt"
"github.com/s-rah/onionscan/config"
"github.com/s-rah/onionscan/report"
Expand All @@ -10,7 +11,6 @@ import (
"io/ioutil"
"net/http"
"strings"
"crypto/tls"
)

type HTTPProtocolScanner struct {
Expand All @@ -33,19 +33,20 @@ func (hps *HTTPProtocolScanner) ScanProtocol(hiddenService string, osc *config.O
if err != nil {
osc.LogInfo("Failed to connect to service on port 80\n")
report.WebDetected = false
conn.Close()
if conn != nil {
conn.Close()
}
} else {
osc.LogInfo("Found potential service on http(80)\n")
report.WebDetected = true
conn.Close()
dialSocksProxy := socks.DialSocksProxy(socks.SOCKS5, osc.TorProxyAddress)
transportConfig := &http.Transport{
Dial: dialSocksProxy,
Dial: dialSocksProxy,
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}
hps.Client = &http.Client{
Transport: transportConfig,

}
// FIXME This should probably be moved to it's own file now.
response, err := hps.Client.Get("http://" + hiddenService)
Expand Down
8 changes: 6 additions & 2 deletions protocol/irc_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ func (rps *IRCProtocolScanner) ScanProtocol(hiddenService string, osc *config.On
// TODO: Actual Analysis
report.IRCDetected = true
}
conn.Close()
if conn != nil {
conn.Close()
}

// IRC
osc.LogInfo(fmt.Sprintf("Checking %s IRC(6697)\n", hiddenService))
Expand All @@ -34,5 +36,7 @@ func (rps *IRCProtocolScanner) ScanProtocol(hiddenService string, osc *config.On
// TODO: Actual Analysis
report.IRCDetected = true
}
conn.Close()
if conn != nil {
conn.Close()
}
}
4 changes: 3 additions & 1 deletion protocol/mongodb_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ func (rps *MongoDBProtocolScanner) ScanProtocol(hiddenService string, osc *confi
// TODO: Actual Analysis
report.MongoDBDetected = true
}
conn.Close()
if conn != nil {
conn.Close()
}

}
4 changes: 3 additions & 1 deletion protocol/ricochet_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ func (rps *RicochetProtocolScanner) ScanProtocol(hiddenService string, osc *conf
// TODO: Actual Analysis
report.RicochetDetected = true
}
conn.Close()
if conn != nil {
conn.Close()
}
}
4 changes: 3 additions & 1 deletion protocol/smtp_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
conn.Close()
if conn != nil {
conn.Close()
}
}
12 changes: 9 additions & 3 deletions protocol/ssh_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ func (sps *SSHProtocolScanner) ScanProtocol(hiddenService string, osc *config.On
if err != nil {
osc.LogInfo("Failed to connect to service on port 22\n")
report.SSHDetected = false
conn.Close()
if conn != nil {
conn.Close()
}
} else {
// TODO SSH Checking
report.SSHDetected = true
Expand All @@ -48,7 +50,9 @@ func (sps *SSHProtocolScanner) ScanProtocol(hiddenService string, osc *config.On
},
}
ssh.NewClientConn(conn, hiddenService+":22", config)
conn.Close()
if conn != nil {
conn.Close()
}
conn, err = utils.GetNetworkConnection(hiddenService, 22, osc.TorProxyAddress, osc.Timeout)
if err == nil {
reader := bufio.NewReader(conn)
Expand All @@ -58,6 +62,8 @@ func (sps *SSHProtocolScanner) ScanProtocol(hiddenService string, osc *config.On
osc.LogInfo(fmt.Sprintf("Found SSH Banner: %s (%s)", banner))
}
}
conn.Close()
if conn != nil {
conn.Close()
}
}
}
26 changes: 14 additions & 12 deletions protocol/tls_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@ func (sps *TLSProtocolScanner) ScanProtocol(hiddenService string, osc *config.On
osc.LogInfo("Failed to connect to service on port 443\n")
report.TLSDetected = false
} else {
osc.LogInfo("Found TLS Endpoint\n")
osc.LogInfo("Found TLS Endpoint\n")
report.TLSDetected = true
config := &tls.Config{
InsecureSkipVerify:true,
}
tlsConn := tls.Client(conn, config)
tlsConn.Write([]byte("GET / HTTP/1.1\r\n\r\n"))
for _, certificate := range tlsConn.ConnectionState().PeerCertificates {
osc.LogInfo(fmt.Sprintf("Found Certificate %v \n", certificate))
report.Certificates = append(report.Certificates, *certificate)
}
tlsConn.Close()
config := &tls.Config{
InsecureSkipVerify: true,
}
tlsConn := tls.Client(conn, config)
tlsConn.Write([]byte("GET / HTTP/1.1\r\n\r\n"))
for _, certificate := range tlsConn.ConnectionState().PeerCertificates {
osc.LogInfo(fmt.Sprintf("Found Certificate %v \n", certificate))
report.Certificates = append(report.Certificates, *certificate)
}
tlsConn.Close()
}
if conn != nil {
conn.Close()
}
conn.Close()
}
4 changes: 3 additions & 1 deletion protocol/vnc_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,7 @@ func (vncps *VNCProtocolScanner) ScanProtocol(hiddenService string, osc *config.
// TODO: Actual Analysis
report.VNCDetected = true
}
conn.Close()
if conn != nil {
conn.Close()
}
}
8 changes: 6 additions & 2 deletions protocol/xmpp_scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ func (rps *XMPPProtocolScanner) ScanProtocol(hiddenService string, osc *config.O
// TODO: Actual Analysis
report.XMPPDetected = true
}
conn.Close()
if conn != nil {
conn.Close()
}
// XMPP
osc.LogInfo(fmt.Sprintf("Checking %s XMPP(5223)\n", hiddenService))
conn, err = utils.GetNetworkConnection(hiddenService, 5223, osc.TorProxyAddress, osc.Timeout)
Expand All @@ -33,5 +35,7 @@ func (rps *XMPPProtocolScanner) ScanProtocol(hiddenService string, osc *config.O
// TODO: Actual Analysis
report.XMPPDetected = true
}
conn.Close()
if conn != nil {
conn.Close()
}
}
6 changes: 3 additions & 3 deletions report/onionscanreport.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package report

import (
"crypto/x509"
"encoding/json"
"github.com/s-rah/onionscan/utils"
"io/ioutil"
"time"
"crypto/x509"
)

type ExifTag struct {
Expand Down Expand Up @@ -62,8 +62,8 @@ type OnionScanReport struct {
PageTitle string `json:"pageTitle"`
ResponseHeaders map[string]string `json:"responseHeaders"`

// TLS
Certificates []x509.Certificate `json:"certificates"`
// TLS
Certificates []x509.Certificate `json:"certificates"`

//Bitcoin
BitcoinAddresses []string `json:"bitcoinAddresses"`
Expand Down

0 comments on commit 7068ce8

Please sign in to comment.