zoukankan      html  css  js  c++  java
  • Go Pentester

    Building HTTP Clients that interact with a variety of security tools and resources.

    Basic Preparation:

    Go's net/HTTP standard package contains several convenience functions to quickly and easily send POST, GET, and HEAD requests, which are arguably the most common HTTP verbs you'll use.

    Get(url string) (resp *Response, err error)
    Head(url string) (resp *Response, err error)
    Post(url string, bodyType string, body io.Reader) (resp *Response, err error)

    Additional POST request, called PostForm()

    func POSTFORM(url string, data url.Values) (resp *Response, err error)
    

    No convenience functions exist for other HTTP verbs, such as PATCH, PUT, or DELETE. Use these verbs to interact with RESTful APIs.

    Generate a Request using the NewRequest() function.

    func NewRequest(methond, url string, body io.Reader) (resp *Response, err error)
    

    Uses the ioutil.ReadAll() function to read data from the response body.

    package main
    
    import (
    	"fmt"
    	"io/ioutil"
    	"log"
    	"net/http"
    )
    
    func main() {
    	resp, err := http.Get("http://www.bing.com/robots.txt")
    	if err != nil {
    		log.Panicln(err)
    	}
    	// Print HTTP Status
    	fmt.Println(resp.Status)
    
    	//Read and display response body
    	body, err := ioutil.ReadAll(resp.Body)
    	if err != nil {
    		log.Panicln(err)
    	}
    	fmt.Println(string(body))
    	resp.Body.Close()
    }
    

     Structured Response Parsing

    JSON file

    {"Message": "All is good with the world","Status": "Success"}

    Go Parsing codes

    package main
    
    import (
    	"encoding/json"
    	"log"
    	"net/http"
    )
    
    type Status struct {
    	Message string
    	Status string
    }
    
    func main() {
    	res, err := http.Post(
    		"http://IP:PORT/ping",
    		"application/json",
    		nil,
    		)
    	if err != nil {
    		log.Fatalln(err)
    	}
    
    	var status Status
    	if err := json.NewDecoder(res.Body).Decode(&status); err != nil {
    		log.Fatalln(err)
    	}
    	defer res.Body.Close()
    	log.Printf("%s -> %s
    ", status.Status, status.Message)
    }
    

      

    相信未来 - 该面对的绝不逃避,该执著的永不怨悔,该舍弃的不再留念,该珍惜的好好把握。
  • 相关阅读:
    Laravel模型间关系设置分表方法详解
    11个PHP程序员最常犯的MySQL错误
    教你使用swoole监听redis数据
    使用 Docker 环境来开发 PHP,Laradock 系列 1
    tp5 workerman安装不上解决方法
    一种颗粒度很小的 Laravel 路由文件划分方式
    VT 调试环境搭建
    masm32基本配置与写出第一个汇编程序
    [debug] 解决pycharm中无法import自己建立的模块问题
    《Windows内核安全与驱动开发》 7.1&7.2&7.3 串口的过滤
  • 原文地址:https://www.cnblogs.com/keepmoving1113/p/12349955.html
Copyright © 2011-2022 走看看