2016-04-12 06:02:06 +00:00
|
|
|
package protocol
|
|
|
|
|
|
|
|
import (
|
|
|
|
"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"}
|
|
|
|
)
|
|
|
|
|
|
|
|
func (hps *HTTPProtocolScanner) ScanProtocol(hiddenService string, proxyAddress string, report *report.OnionScanReport) {
|
2016-04-12 06:02:06 +00:00
|
|
|
|
|
|
|
// HTTP
|
|
|
|
log.Printf("Checking %s http(80)\n", hiddenService)
|
|
|
|
_, err := socks.DialSocksProxy(socks.SOCKS5, proxyAddress)("", 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")
|
2016-04-25 02:46:28 +00:00
|
|
|
report.WebDetected = true
|
2016-04-12 06:02:06 +00:00
|
|
|
dialSocksProxy := socks.DialSocksProxy(socks.SOCKS5, proxyAddress)
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
// Initial Attempt at Resolving Server Type
|
|
|
|
log.Printf("Attempting to Derive Server Type from Headers..\n")
|
|
|
|
report.ServerVersion = response.Header.Get("Server")
|
|
|
|
log.Printf("\tServer Version: %s\n", report.ServerVersion)
|
|
|
|
|
|
|
|
// 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 {
|
|
|
|
hps.ScanPage(hiddenService, directory, report, scans.CheckDirectoryListing)
|
|
|
|
}
|
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)
|
|
|
|
}
|