mirror of
https://github.com/bettercap/bettercap
synced 2025-08-20 13:33:21 -07:00
fix: refactored deprecated ioutil calls to io equivalents
This commit is contained in:
parent
3440e9999a
commit
1c78ffa7be
7 changed files with 22 additions and 24 deletions
|
@ -4,7 +4,6 @@ import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -64,7 +63,7 @@ func (c httpPackage) Request(method string, uri string,
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
raw, err := ioutil.ReadAll(resp.Body)
|
raw, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return httpResponse{Error: err}
|
return httpResponse{Error: err}
|
||||||
}
|
}
|
||||||
|
@ -133,7 +132,7 @@ func httpRequest(call otto.FunctionCall) otto.Value {
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ReportError("Could not read response: %s", err)
|
return ReportError("Could not read response: %s", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
@ -394,7 +393,7 @@ func (mod *RestAPI) readFile(fileName string, w http.ResponseWriter, r *http.Req
|
||||||
}
|
}
|
||||||
|
|
||||||
func (mod *RestAPI) writeFile(fileName string, w http.ResponseWriter, r *http.Request) {
|
func (mod *RestAPI) writeFile(fileName string, w http.ResponseWriter, r *http.Request) {
|
||||||
data, err := ioutil.ReadAll(r.Body)
|
data, err := io.ReadAll(r.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msg := fmt.Sprintf("invalid file upload: %s", err)
|
msg := fmt.Sprintf("invalid file upload: %s", err)
|
||||||
mod.Warning(msg)
|
mod.Warning(msg)
|
||||||
|
@ -402,7 +401,7 @@ func (mod *RestAPI) writeFile(fileName string, w http.ResponseWriter, r *http.Re
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = ioutil.WriteFile(fileName, data, 0666)
|
err = os.WriteFile(fileName, data, 0666)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
msg := fmt.Sprintf("can't write to %s: %s", fileName, err)
|
msg := fmt.Sprintf("can't write to %s: %s", fileName, err)
|
||||||
mod.Warning(msg)
|
mod.Warning(msg)
|
||||||
|
|
|
@ -1,10 +1,10 @@
|
||||||
package http_proxy
|
package http_proxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/elazarl/goproxy"
|
"github.com/elazarl/goproxy"
|
||||||
|
|
||||||
|
@ -74,10 +74,10 @@ func (p *HTTPProxy) isScriptInjectable(res *http.Response) (bool, string) {
|
||||||
return false, ""
|
return false, ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *HTTPProxy) doScriptInjection(res *http.Response, cType string) (error) {
|
func (p *HTTPProxy) doScriptInjection(res *http.Response, cType string) error {
|
||||||
defer res.Body.Close()
|
defer res.Body.Close()
|
||||||
|
|
||||||
raw, err := ioutil.ReadAll(res.Body)
|
raw, err := io.ReadAll(res.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
} else if html := string(raw); strings.Contains(html, "</head>") {
|
} else if html := string(raw); strings.Contains(html, "</head>") {
|
||||||
|
@ -91,7 +91,7 @@ func (p *HTTPProxy) doScriptInjection(res *http.Response, cType string) (error)
|
||||||
res.Header.Set("Content-Length", strconv.Itoa(len(html)))
|
res.Header.Set("Content-Length", strconv.Itoa(len(html)))
|
||||||
|
|
||||||
// reset the response body to the original unread state
|
// reset the response body to the original unread state
|
||||||
res.Body = ioutil.NopCloser(strings.NewReader(html))
|
res.Body = io.NopCloser(strings.NewReader(html))
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
package http_proxy
|
package http_proxy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
@ -253,7 +253,7 @@ func (s *SSLStripper) Process(res *http.Response, ctx *goproxy.ProxyCtx) {
|
||||||
// if we have a text or html content type, fetch the body
|
// if we have a text or html content type, fetch the body
|
||||||
// and perform sslstripping
|
// and perform sslstripping
|
||||||
if s.isContentStrippable(res) {
|
if s.isContentStrippable(res) {
|
||||||
raw, err := ioutil.ReadAll(res.Body)
|
raw, err := io.ReadAll(res.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Could not read response body: %s", err)
|
log.Error("Could not read response body: %s", err)
|
||||||
return
|
return
|
||||||
|
@ -297,9 +297,9 @@ func (s *SSLStripper) Process(res *http.Response, ctx *goproxy.ProxyCtx) {
|
||||||
|
|
||||||
// reset the response body to the original unread state
|
// reset the response body to the original unread state
|
||||||
// but with just a string reader, this way further calls
|
// but with just a string reader, this way further calls
|
||||||
// to ioutil.ReadAll(res.Body) will just return the content
|
// to ui.ReadAll(res.Body) will just return the content
|
||||||
// we stripped without downloading anything again.
|
// we stripped without downloading anything again.
|
||||||
res.Body = ioutil.NopCloser(strings.NewReader(body))
|
res.Body = io.NopCloser(strings.NewReader(body))
|
||||||
}
|
}
|
||||||
|
|
||||||
// fix cookies domain + strip "secure" + "httponly" flags
|
// fix cookies domain + strip "secure" + "httponly" flags
|
||||||
|
|
|
@ -3,7 +3,7 @@ package http_proxy
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
@ -201,7 +201,7 @@ func (j *JSRequest) RemoveHeader(name string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (j *JSRequest) ReadBody() string {
|
func (j *JSRequest) ReadBody() string {
|
||||||
raw, err := ioutil.ReadAll(j.req.Body)
|
raw, err := io.ReadAll(j.req.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
@ -209,7 +209,7 @@ func (j *JSRequest) ReadBody() string {
|
||||||
j.Body = string(raw)
|
j.Body = string(raw)
|
||||||
j.bodyRead = true
|
j.bodyRead = true
|
||||||
// reset the request body to the original unread state
|
// reset the request body to the original unread state
|
||||||
j.req.Body = ioutil.NopCloser(bytes.NewBuffer(raw))
|
j.req.Body = io.NopCloser(bytes.NewBuffer(raw))
|
||||||
|
|
||||||
return j.Body
|
return j.Body
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@ package http_proxy
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -208,7 +208,7 @@ func (j *JSResponse) ToResponse(req *http.Request) (resp *http.Response) {
|
||||||
func (j *JSResponse) ReadBody() string {
|
func (j *JSResponse) ReadBody() string {
|
||||||
defer j.resp.Body.Close()
|
defer j.resp.Body.Close()
|
||||||
|
|
||||||
raw, err := ioutil.ReadAll(j.resp.Body)
|
raw, err := io.ReadAll(j.resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
@ -217,7 +217,7 @@ func (j *JSResponse) ReadBody() string {
|
||||||
j.bodyRead = true
|
j.bodyRead = true
|
||||||
j.bodyClear = false
|
j.bodyClear = false
|
||||||
// reset the response body to the original unread state
|
// reset the response body to the original unread state
|
||||||
j.resp.Body = ioutil.NopCloser(bytes.NewBuffer(raw))
|
j.resp.Body = io.NopCloser(bytes.NewBuffer(raw))
|
||||||
|
|
||||||
return j.Body
|
return j.Body
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ import (
|
||||||
"bufio"
|
"bufio"
|
||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"io/ioutil"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -50,7 +50,7 @@ func toSerializableRequest(req *http.Request) HTTPRequest {
|
||||||
body := []byte(nil)
|
body := []byte(nil)
|
||||||
ctype := "?"
|
ctype := "?"
|
||||||
if req.Body != nil {
|
if req.Body != nil {
|
||||||
body, _ = ioutil.ReadAll(req.Body)
|
body, _ = io.ReadAll(req.Body)
|
||||||
}
|
}
|
||||||
|
|
||||||
for name, values := range req.Header {
|
for name, values := range req.Header {
|
||||||
|
@ -90,7 +90,7 @@ func toSerializableResponse(res *http.Response) HTTPResponse {
|
||||||
}
|
}
|
||||||
|
|
||||||
if res.Body != nil {
|
if res.Body != nil {
|
||||||
body, _ = ioutil.ReadAll(res.Body)
|
body, _ = io.ReadAll(res.Body)
|
||||||
}
|
}
|
||||||
|
|
||||||
// attempt decompression, but since this has been parsed by just
|
// attempt decompression, but since this has been parsed by just
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue