zgrab2/modules/http.go
justinbastress a244ec15e6 TLS scan prototype + Travis integration (#25)
* Fix typo

* Actually call init per sender for each goroutine

* split out TLS handling

* Rename tls_handshake; update docs

* fix comments

* format fixes

* merge updates

* fix path

* refactor heartbleed logging (now the same as original zgrab)

* add ScanStatus, update modules to return it

* fix threaded for loop; fix styling of dict literal

* fix compile errors, note un-bubbled handshake error

* initial schema commit

* fix comment

* schema cleanup

* comments

* fix TODOs

* first attempt at docker integration in travis; also add schema validation

* add integration_tests.sh

* need sudo?

* try pip install --user

* revert regression

* add docker service again

* chmod +x integration_tests.sh

* fix path of binary

* Dump output file to stdout

* travis work

* use jp's build-self-contained script

* use go get/go build to get jp

* fix jp path

* switch from bogus regex to wildcard

* do all mysql versions; fix version comparison

* re-enable notifications; fix successful version check log message; comment TryGetScanStatus

* move to conf.d layout for integration tests

* update README

* add missing scripts

* add ./ to path
2017-12-15 09:25:17 -05:00

96 lines
2.7 KiB
Go

package modules
import (
log "github.com/sirupsen/logrus"
"github.com/zmap/zgrab2"
)
type HTTPFlags struct {
zgrab2.BaseFlags
HTTP HTTPOptions `json:"http"`
}
type HTTPOptions struct {
Method string `long:"method" default:"GET" description:"Set HTTP request method type"`
Endpoint string `long:"endpoint" default:"/" description:"Send an HTTP request to an endpoint"`
UserAgent string `long:"user-agent" default:"Mozilla/5.0 zgrab/0.x" description:"Set a custom user agent"`
ProxyDomain string `long:"proxy-domain" description:"Send a CONNECT <domain> first"`
MaxSize int `long:"max-size" default:"256" description:"Max kilobytes to read in response to an HTTP request"`
MaxRedirects int `long:"max-redirects" default:"0" description:"Max number of redirects to follow"`
}
type HTTPRequest struct {
Method string `json:"method,omitempty"`
Endpoint string `json:"endpoint,omitempty"`
UserAgent string `json:"user_agent,omitempty"`
Body string `json:"body,omitempty"`
}
type HTTPResponse struct {
VersionMajor int `json:"version_major,omitempty"`
VersionMinor int `json:"version_minor,omitempty"`
StatusCode int `json:"status_code,omitempty"`
StatusLine string `json:"status_line,omitempty"`
//Headers HTTPHeaders `json:"headers,omitempty"`
Body string `json:"body,omitempty"`
BodySHA256 []byte `json:"body_sha256,omitempty"`
}
type HTTPResults struct {
ProxyRequest *HTTPRequest `json:"connect_request,omitempty"`
ProxyResponse *HTTPResponse `json:"connect_response,omitempty"`
//Response *http.Response `json:"response,omitempty"`
//RedirectResponseChain []*http.Response `json:"redirect_response_chain,omitempty"`
}
type HTTPModule struct {
}
type HTTPScanner struct {
config *HTTPFlags
}
func init() {
var httpModule HTTPModule
_, err := zgrab2.AddCommand("http", "HTTP Banner Grab", "Grab a banner over HTTP", 80, &httpModule)
if err != nil {
log.Fatal(err)
}
}
func (m *HTTPModule) NewFlags() interface{} {
return new(HTTPFlags)
}
func (m *HTTPModule) NewScanner() zgrab2.Scanner {
return new(HTTPScanner)
}
func (f *HTTPFlags) Validate(args []string) error {
return nil
}
func (f *HTTPFlags) Help() string {
return ""
}
func (s *HTTPScanner) Init(flags zgrab2.ScanFlags) error {
fl, _ := flags.(*HTTPFlags)
s.config = fl
return nil
}
func (s *HTTPScanner) InitPerSender(senderID int) error {
return nil
}
func (s *HTTPScanner) GetName() string {
return s.config.Name
}
func (s *HTTPScanner) Scan(t zgrab2.ScanTarget) (zgrab2.ScanStatus, interface{}, error) {
http := HTTPRequest{Method: "Get", Body: "testing"}
ret := HTTPResults{ProxyRequest: &http}
return zgrab2.SCAN_SUCCESS, ret, nil
}