fix: refactored deprecated ioutil calls to io equivalents

This commit is contained in:
evilsocket 2025-07-12 11:47:43 +02:00
commit 1c78ffa7be
7 changed files with 22 additions and 24 deletions

View file

@ -4,7 +4,6 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"net/http"
"net/url"
"strings"
@ -64,7 +63,7 @@ func (c httpPackage) Request(method string, uri string,
}
defer resp.Body.Close()
raw, err := ioutil.ReadAll(resp.Body)
raw, err := io.ReadAll(resp.Body)
if err != nil {
return httpResponse{Error: err}
}
@ -133,7 +132,7 @@ func httpRequest(call otto.FunctionCall) otto.Value {
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return ReportError("Could not read response: %s", err)
}

View file

@ -5,7 +5,6 @@ import (
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"os"
"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) {
data, err := ioutil.ReadAll(r.Body)
data, err := io.ReadAll(r.Body)
if err != nil {
msg := fmt.Sprintf("invalid file upload: %s", err)
mod.Warning(msg)
@ -402,7 +401,7 @@ func (mod *RestAPI) writeFile(fileName string, w http.ResponseWriter, r *http.Re
return
}
err = ioutil.WriteFile(fileName, data, 0666)
err = os.WriteFile(fileName, data, 0666)
if err != nil {
msg := fmt.Sprintf("can't write to %s: %s", fileName, err)
mod.Warning(msg)

View file

@ -1,10 +1,10 @@
package http_proxy
import (
"io/ioutil"
"io"
"net/http"
"strings"
"strconv"
"strings"
"github.com/elazarl/goproxy"
@ -74,10 +74,10 @@ func (p *HTTPProxy) isScriptInjectable(res *http.Response) (bool, string) {
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()
raw, err := ioutil.ReadAll(res.Body)
raw, err := io.ReadAll(res.Body)
if err != nil {
return err
} 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)))
// 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
}

View file

@ -1,7 +1,7 @@
package http_proxy
import (
"io/ioutil"
"io"
"net/http"
"net/url"
"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
// and perform sslstripping
if s.isContentStrippable(res) {
raw, err := ioutil.ReadAll(res.Body)
raw, err := io.ReadAll(res.Body)
if err != nil {
log.Error("Could not read response body: %s", err)
return
@ -297,9 +297,9 @@ func (s *SSLStripper) Process(res *http.Response, ctx *goproxy.ProxyCtx) {
// reset the response body to the original unread state
// 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.
res.Body = ioutil.NopCloser(strings.NewReader(body))
res.Body = io.NopCloser(strings.NewReader(body))
}
// fix cookies domain + strip "secure" + "httponly" flags

View file

@ -3,7 +3,7 @@ package http_proxy
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"net/http"
"net/url"
"regexp"
@ -201,7 +201,7 @@ func (j *JSRequest) RemoveHeader(name string) {
}
func (j *JSRequest) ReadBody() string {
raw, err := ioutil.ReadAll(j.req.Body)
raw, err := io.ReadAll(j.req.Body)
if err != nil {
return ""
}
@ -209,7 +209,7 @@ func (j *JSRequest) ReadBody() string {
j.Body = string(raw)
j.bodyRead = true
// 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
}

View file

@ -3,7 +3,7 @@ package http_proxy
import (
"bytes"
"fmt"
"io/ioutil"
"io"
"net/http"
"strings"
@ -208,7 +208,7 @@ func (j *JSResponse) ToResponse(req *http.Request) (resp *http.Response) {
func (j *JSResponse) ReadBody() string {
defer j.resp.Body.Close()
raw, err := ioutil.ReadAll(j.resp.Body)
raw, err := io.ReadAll(j.resp.Body)
if err != nil {
return ""
}
@ -217,7 +217,7 @@ func (j *JSResponse) ReadBody() string {
j.bodyRead = true
j.bodyClear = false
// 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
}

View file

@ -4,7 +4,7 @@ import (
"bufio"
"bytes"
"compress/gzip"
"io/ioutil"
"io"
"net"
"net/http"
"strings"
@ -50,7 +50,7 @@ func toSerializableRequest(req *http.Request) HTTPRequest {
body := []byte(nil)
ctype := "?"
if req.Body != nil {
body, _ = ioutil.ReadAll(req.Body)
body, _ = io.ReadAll(req.Body)
}
for name, values := range req.Header {
@ -90,7 +90,7 @@ func toSerializableResponse(res *http.Response) HTTPResponse {
}
if res.Body != nil {
body, _ = ioutil.ReadAll(res.Body)
body, _ = io.ReadAll(res.Body)
}
// attempt decompression, but since this has been parsed by just