Documentation ¶
Index ¶
- Constants
- Variables
- func IsDomainName(s string) bool
- func ParseCIDR(s string) (net.IP, []net.IP, error)
- func RandomUserAgent() string
- type Addr
- type Dns
- type HttpClient
- func (c *HttpClient) Get(url string) (*http.Response, error)
- func (c *HttpClient) Headers(k string, v string)
- func (c *HttpClient) Post(url, contentType string, body io.Reader) (resp *http.Response, err error)
- func (c *HttpClient) PostForm(url string, data url.Values) (resp *http.Response, err error)
- func (c *HttpClient) PreDo(method string, url string, body io.Reader) (*http.Response, error)
- func (c *HttpClient) UploadFile(url string, files []UPFile) (resp *http.Response, err error)
- type Msg
- type UPFile
Examples ¶
Constants ¶
const DefaultFileContentType = "application/octet-stream"
Variables ¶
var DefaultHttpClient = &http.Client{Timeout: 5 * time.Second, Transport: &http.Transport{ TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, }, CheckRedirect: nil}
DefaultHttpClient default http client use http.Client timeout 5 Second ignore certificate warnings
var DefaultResolver = &Dns{ NewMsg: NewDefaultMsg, Ns: "223.6.6.6:53", Timeout: 3 * time.Second, }
var NoneCheckRedirect = func(req *http.Request, via []*http.Request) error { return http.ErrUseLastResponse }
var PRIVATE_IPV4 = [3]string{
"10.0.0.0/8",
"172.16.0.0/12",
"192.168.0.0/16",
}
var USER_AGENTS = [8]string{
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:108.0) Gecko/20100101 Firefox/108.0",
"Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.85 Safari/537.36",
"Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.89 Safari/537.36",
"Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.130 Safari/537.36",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML, like Gecko) Version/7.0.3 Safari/7046A194A",
"Mozilla/5.0 (iPad; CPU OS 6_0 like Mac OS X) AppleWebKit/536.26 (KHTML, like Gecko) Version/6.0 Mobile/10A5355d Safari/8536.25",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_6_8) AppleWebKit/537.13+ (KHTML, like Gecko) Version/5.1.7 Safari/534.57.2",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_3) AppleWebKit/534.55.3 (KHTML, like Gecko) Version/5.1.3 Safari/534.53.10",
}
USER_AGENT http header User-Agent's
Functions ¶
func IsDomainName ¶ added in v0.0.7
IsDomainName checks if a string is a presentation-format domain name (currently restricted to hostname-compatible "preferred name" LDH labels and SRV-like "underscore labels"; see golang.org/issue/12421).
Example ¶
package main import ( "fmt" "github.com/sechelper/seclib/network" ) func main() { fmt.Println(network.IsDomainName("secself.com")) // true fmt.Println(network.IsDomainName("www.secself")) // true fmt.Println(network.IsDomainName("secself.com/")) // false fmt.Println(network.IsDomainName("http://secself.com")) // false }
Output:
func ParseCIDR ¶
ParseCIDR parses s as a CIDR notation IP address and prefix length, like "192.0.2.0/24" or "2001:db8::/32", as defined in RFC 4632 and RFC 4291.
It returns the IP address and the network implied by the IP and prefix length. For example, ParseCIDR("192.0.2.1/24") returns the IP address 192.0.2.1 and the network segment. TODO support ipv6
Example ¶
package main import ( "fmt" "github.com/sechelper/seclib/network" "log" ) func main() { ipv4Addr, ipv4NetSegment, err := network.ParseCIDR("192.0.2.1/24") if err != nil { log.Fatal(err) } fmt.Println(ipv4Addr) for i := range ipv4NetSegment { fmt.Println(ipv4NetSegment[i]) } }
Output:
func RandomUserAgent ¶ added in v0.0.9
func RandomUserAgent() string
RandomUserAgent generate random User-Agent
Example ¶
package main import ( "fmt" "github.com/sechelper/seclib/network" ) func main() { for i := 0; i < 10; i++ { fmt.Println(network.RandomUserAgent()) } }
Output:
Types ¶
type Dns ¶ added in v0.0.7
func (*Dns) Exchange ¶ added in v0.0.7
Example ¶
package main import ( "fmt" "github.com/miekg/dns" "github.com/sechelper/seclib/network" "log" "net" ) func main() { var ips []net.IP = nil in, _, err := network.DefaultResolver.Exchange(dns.TypeA, "go-hacker-code.lab.secself.com") if err != nil || in.Answer == nil { log.Fatal(err) } ips = make([]net.IP, 0) for i := range in.Answer { if rr, ok := in.Answer[i].(*dns.A); ok { ips = append(ips, rr.A) } } fmt.Println(ips) }
Output:
func (*Dns) LookupCNAME ¶ added in v0.0.7
Example ¶
package main import ( "fmt" "github.com/sechelper/seclib/network" "log" ) func main() { cname, err := network.DefaultResolver.LookupCNAME("go-hacker-code.lab.secself.com") if err != nil { log.Fatal(err) } fmt.Println(cname) }
Output:
func (*Dns) LookupIP ¶ added in v0.0.7
LookupIP looks up host using the local resolver. It returns a slice of that host's IPv4 and IPv6 addresses.
Example ¶
package main import ( "fmt" "github.com/sechelper/seclib/network" "log" ) func main() { ip, err := network.DefaultResolver.LookupIP("go-hacker-code.lab.secself.com") if err != nil { log.Fatal(err) } fmt.Println(ip) }
Output:
type HttpClient ¶ added in v0.0.14
func (*HttpClient) Get ¶ added in v0.0.14
func (c *HttpClient) Get(url string) (*http.Response, error)
Example ¶
package main import ( "fmt" "github.com/sechelper/seclib/network" ) func main() { c := network.HttpClient{} if reps, err := c.Get("https://go-hacker-code.lab.secself.com/"); err == nil { fmt.Println(reps.StatusCode) } }
Output:
func (*HttpClient) Headers ¶ added in v0.0.14
func (c *HttpClient) Headers(k string, v string)
func (*HttpClient) Post ¶ added in v0.0.14
Example ¶
package main import ( "bytes" "encoding/json" "fmt" "github.com/sechelper/seclib/network" ) func main() { c := network.HttpClient{} data := map[string]string{"username": "password"} body, _ := json.Marshal(data) if reps, err := c.Post("https://go-hacker-code.lab.secself.com/", "application/json", bytes.NewReader(body)); err == nil { fmt.Println(reps.StatusCode) } }
Output:
func (*HttpClient) UploadFile ¶ added in v0.0.14
UploadFile ref https://gist.github.com/andrewmilson/19185aab2347f6ad29f5
Example ¶
package main import ( "fmt" "github.com/sechelper/seclib/network" ) func main() { c := network.HttpClient{} file1 := network.UPFile{Path: "file1.txt", Field: "file"} file2 := network.UPFile{Path: "file2.txt", Field: "file1"} file3 := network.UPFile{Path: "file3.txt", Field: "file2"} _, err := c.UploadFile("http://127.0.0.1:8080/upladMore", []network.UPFile{file1, file2, file3}) if err != nil { fmt.Println(err) return } }
Output:
type Msg ¶ added in v0.0.7
func NewDefaultMsg ¶ added in v0.0.7
func NewDefaultMsg() *Msg