2016-04-12 06:02:06 +00:00
|
|
|
package protocol
|
|
|
|
|
|
|
|
import (
|
2016-05-03 14:31:56 +00:00
|
|
|
"github.com/s-rah/onionscan/config"
|
2016-04-12 06:02:06 +00:00
|
|
|
"github.com/s-rah/onionscan/report"
|
2016-04-24 17:28:59 +00:00
|
|
|
"github.com/s-rah/onionscan/scans"
|
|
|
|
"github.com/s-rah/onionscan/utils"
|
2016-04-12 06:02:06 +00:00
|
|
|
"h12.me/socks"
|
2016-04-24 17:28:59 +00:00
|
|
|
"io/ioutil"
|
2016-04-12 06:02:06 +00:00
|
|
|
"log"
|
2016-04-24 17:28:59 +00:00
|
|
|
"net/http"
|
2016-04-12 06:02:06 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type HTTPProtocolScanner struct {
|
2016-04-24 17:28:59 +00:00
|
|
|
Client *http.Client
|
2016-04-12 06:02:06 +00:00
|
|
|
}
|
|
|
|
|
2016-04-24 17:28:59 +00:00
|
|
|
var (
|
|
|
|
CommonDirectories = []string{"/style", "/styles", "/css", "/uploads", "/images", "/img", "/static",
|
|
|
|
// Lots of Wordpress installs which don't lock down directory listings
|
|
|
|
"/wp-content/uploads",
|
|
|
|
// Common with torshops created onions
|
|
|
|
"/products", "/products/cat"}
|
|
|
|
)
|
|
|
|
|
2016-05-03 14:31:56 +00:00
|
|
|
func (hps *HTTPProtocolScanner) ScanProtocol(hiddenService string, onionscanConfig *config.OnionscanConfig, report *report.OnionScanReport) {
|
2016-04-12 06:02:06 +00:00
|
|
|
|
|
|
|
// HTTP
|
|
|
|
log.Printf("Checking %s http(80)\n", hiddenService)
|
2016-05-03 14:31:56 +00:00
|
|
|
_, err := socks.DialSocksProxy(socks.SOCKS5, onionscanConfig.TorProxyAddress)("", hiddenService+":80")
|
2016-04-12 06:02:06 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Printf("Failed to connect to service on port 80\n")
|
|
|
|
} else {
|
|
|
|
log.Printf("Found potential service on http(80)\n")
|
2016-04-25 02:46:28 +00:00
|
|
|
report.WebDetected = true
|
2016-05-03 14:31:56 +00:00
|
|
|
dialSocksProxy := socks.DialSocksProxy(socks.SOCKS5, onionscanConfig.TorProxyAddress)
|
2016-04-12 06:02:06 +00:00
|
|
|
transportConfig := &http.Transport{
|
|
|
|
Dial: dialSocksProxy,
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Failed to connect to service on port 80\n")
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-04-25 09:29:27 +00:00
|
|
|
// Reading all http headers
|
|
|
|
log.Printf("HTTP response headers: %s\n", report.ServerVersion)
|
|
|
|
responseHeaders := response.Header
|
|
|
|
for key := range responseHeaders {
|
|
|
|
value := responseHeaders.Get(key)
|
|
|
|
report.AddResponseHeader(key, value)
|
|
|
|
log.Printf("\t%s : %s\n", key, value)
|
|
|
|
}
|
|
|
|
|
|
|
|
report.ServerVersion = responseHeaders.Get("Server")
|
2016-04-12 06:02:06 +00:00
|
|
|
|
|
|
|
// Apache mod-status Check
|
|
|
|
hps.ScanPage(hiddenService, "/server-status", report, scans.ApacheModStatus)
|
|
|
|
hps.ScanPage(hiddenService, "/", report, scans.StandardPageScan)
|
|
|
|
|
2016-04-24 17:28:59 +00:00
|
|
|
log.Printf("\tScanning Common and Referenced Directories\n")
|
|
|
|
directories := append(CommonDirectories, report.PageReferencedDirectories...)
|
|
|
|
utils.RemoveDuplicates(&directories)
|
|
|
|
for _, directory := range directories {
|
2016-05-03 14:31:56 +00:00
|
|
|
hps.ScanPage(hiddenService, directory, report, scans.CheckDirectoryListing(onionscanConfig.DirectoryDepth))
|
2016-04-24 17:28:59 +00:00
|
|
|
}
|
2016-04-12 06:02:06 +00:00
|
|
|
}
|
|
|
|
log.Printf("\n")
|
|
|
|
}
|
|
|
|
|
2016-04-24 17:28:59 +00:00
|
|
|
func (hps *HTTPProtocolScanner) ScanPage(hiddenService string, page string, report *report.OnionScanReport, f func(scans.Scanner, string, int, string, *report.OnionScanReport)) {
|
2016-04-12 06:02:06 +00:00
|
|
|
response, err := hps.Client.Get("http://" + hiddenService + page)
|
|
|
|
if err != nil {
|
|
|
|
log.Printf("Error connecting to %s%s %s\n", hiddenService, page, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer response.Body.Close()
|
|
|
|
contents, _ := ioutil.ReadAll(response.Body)
|
|
|
|
f(hps, page, response.StatusCode, string(contents), report)
|
|
|
|
}
|