Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: remove refs to deprecated io/ioutil #1437

Merged
merged 3 commits into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions client/command/alias/alias.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package alias
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"strings"

"github.com/bishopfox/sliver/client/assets"
Expand Down Expand Up @@ -115,7 +115,7 @@ func getInstalledManifests() map[string]*AliasManifest {
manifestPaths := assets.GetInstalledAliasManifests()
installedManifests := map[string]*AliasManifest{}
for _, manifestPath := range manifestPaths {
data, err := ioutil.ReadFile(manifestPath)
data, err := os.ReadFile(manifestPath)
if err != nil {
continue
}
Expand Down
9 changes: 4 additions & 5 deletions client/command/alias/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package alias

import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -50,7 +49,7 @@ func AliasesInstallCmd(cmd *cobra.Command, con *console.SliverConsoleClient, arg

// Install an extension from a directory
func installFromDir(aliasLocalPath string, con *console.SliverConsoleClient) {
manifestData, err := ioutil.ReadFile(filepath.Join(aliasLocalPath, ManifestFileName))
manifestData, err := os.ReadFile(filepath.Join(aliasLocalPath, ManifestFileName))
if err != nil {
con.PrintErrorf("Error reading %s: %s", ManifestFileName, err)
return
Expand Down Expand Up @@ -78,7 +77,7 @@ func installFromDir(aliasLocalPath string, con *console.SliverConsoleClient) {
con.PrintErrorf("Error creating alias directory: %s\n", err)
return
}
err = ioutil.WriteFile(filepath.Join(installPath, ManifestFileName), manifestData, 0o600)
err = os.WriteFile(filepath.Join(installPath, ManifestFileName), manifestData, 0o600)
if err != nil {
con.PrintErrorf("Failed to write %s: %s\n", ManifestFileName, err)
forceRemoveAll(installPath)
Expand Down Expand Up @@ -133,7 +132,7 @@ func InstallFromFile(aliasGzFilePath string, autoOverwrite bool, con *console.Sl
con.PrintErrorf("Failed to create alias directory: %s\n", err)
return nil
}
err = ioutil.WriteFile(filepath.Join(installPath, ManifestFileName), manifestData, 0o600)
err = os.WriteFile(filepath.Join(installPath, ManifestFileName), manifestData, 0o600)
if err != nil {
con.PrintErrorf("Failed to write %s: %s\n", ManifestFileName, err)
forceRemoveAll(installPath)
Expand Down Expand Up @@ -166,7 +165,7 @@ func installArtifact(aliasGzFilePath string, installPath, artifactPath string, c
if _, err := os.Stat(artifactDir); os.IsNotExist(err) {
os.MkdirAll(artifactDir, 0o700)
}
err = ioutil.WriteFile(localArtifactPath, data, 0o600)
err = os.WriteFile(localArtifactPath, data, 0o600)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions client/command/dllhijack/dllhijack.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package dllhijack
import (
"context"
"fmt"
"io/ioutil"
"os"

"github.com/spf13/cobra"

Expand Down Expand Up @@ -58,7 +58,7 @@ func DllHijackCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []s
}

if localReferenceFilePath != "" {
localRefData, err = ioutil.ReadFile(localReferenceFilePath)
localRefData, err = os.ReadFile(localReferenceFilePath)
if err != nil {
con.PrintErrorf("Could not load the reference file from the client: %s\n", err)
return
Expand All @@ -70,7 +70,7 @@ func DllHijackCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []s
con.PrintErrorf("please use either --profile or --File")
return
}
targetDLLData, err = ioutil.ReadFile(localFile)
targetDLLData, err = os.ReadFile(localFile)
if err != nil {
con.PrintErrorf("Error: %s\n", err)
return
Expand Down
3 changes: 1 addition & 2 deletions client/command/filesystem/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package filesystem
import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"

Expand Down Expand Up @@ -72,7 +71,7 @@ func UploadCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []stri

dst := remotePath

fileBuf, err := ioutil.ReadFile(src)
fileBuf, err := os.ReadFile(src)
if err != nil {
con.PrintErrorf("%s\n", err)
return
Expand Down
6 changes: 3 additions & 3 deletions client/command/jobs/https.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"context"
"crypto/tls"
"fmt"
"io/ioutil"
"os"
"time"

"github.com/spf13/cobra"
Expand Down Expand Up @@ -92,11 +92,11 @@ func getLocalCertificatePair(cmd *cobra.Command) ([]byte, []byte, error) {
if certPath == "" && keyPath == "" {
return nil, nil, nil
}
cert, err := ioutil.ReadFile(certPath)
cert, err := os.ReadFile(certPath)
if err != nil {
return nil, nil, err
}
key, err := ioutil.ReadFile(keyPath)
key, err := os.ReadFile(keyPath)
if err != nil {
return nil, nil, err
}
Expand Down
3 changes: 1 addition & 2 deletions client/command/processes/procdump.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package processes
import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"time"
Expand Down Expand Up @@ -112,7 +111,7 @@ func PrintProcessDump(dump *sliverpb.ProcessDump, saveTo string, hostname string
var saveToFile *os.File
if saveTo == "" {
tmpFileName := filepath.Base(fmt.Sprintf("procdump_%s_%d_*", hostname, pid))
saveToFile, err = ioutil.TempFile("", tmpFileName)
saveToFile, err = os.CreateTemp("", tmpFileName)
if err != nil {
con.PrintErrorf("Error creating temporary file: %s\n", err)
return
Expand Down
6 changes: 3 additions & 3 deletions client/command/reaction/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package reaction
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"
"path"
"strconv"
"strings"
Expand Down Expand Up @@ -49,13 +49,13 @@ func SaveReactions(reactions []core.Reaction) error {
if err != nil {
return err
}
return ioutil.WriteFile(reactionFilePath, data, 0o600)
return os.WriteFile(reactionFilePath, data, 0o600)
}

// LoadReactions - Save the reactions to the reaction file
func LoadReactions() (int, error) {
reactionFilePath := GetReactionFilePath()
data, err := ioutil.ReadFile(reactionFilePath)
data, err := os.ReadFile(reactionFilePath)
if err != nil {
return 0, err
}
Expand Down
4 changes: 2 additions & 2 deletions client/command/registry/reg-write.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package registry
import (
"context"
"encoding/hex"
"io/ioutil"
"os"
"strconv"
"strings"

Expand Down Expand Up @@ -100,7 +100,7 @@ func RegWriteCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []st
return
}
} else {
v, err = ioutil.ReadFile(binPath)
v, err = os.ReadFile(binPath)
if err != nil {
con.PrintErrorf("%s\n", err)
return
Expand Down
3 changes: 1 addition & 2 deletions client/command/screenshot/screenshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package screenshot
import (
"context"
"fmt"
"io/ioutil"
"os"
"path/filepath"
"time"
Expand Down Expand Up @@ -107,7 +106,7 @@ func PrintScreenshot(screenshot *sliverpb.Screenshot, hostname string, cmd *cobr
var err error
if saveTo == "" {
tmpFileName := filepath.Base(fmt.Sprintf("screenshot_%s_%s_*.png", filepath.Base(hostname), timestamp))
saveToFile, err = ioutil.TempFile("", tmpFileName)
saveToFile, err = os.CreateTemp("", tmpFileName)
if err != nil {
con.PrintErrorf("%s\n", err)
return
Expand Down
6 changes: 3 additions & 3 deletions client/command/shikata-ga-nai/sgn.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package sgn
import (
"context"
"encoding/hex"
"io/ioutil"
"os"
"path/filepath"

"github.com/spf13/cobra"
Expand All @@ -33,7 +33,7 @@ import (
// ShikataGaNaiCmd - Command wrapper for the Shikata Ga Nai shellcode encoder
func ShikataGaNaiCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) {
shellcodeFile := args[0]
rawShellcode, err := ioutil.ReadFile(shellcodeFile)
rawShellcode, err := os.ReadFile(shellcodeFile)
if err != nil {
con.PrintErrorf("Failed to read shellcode file: %s", err)
return
Expand Down Expand Up @@ -73,7 +73,7 @@ func ShikataGaNaiCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args
outputFile += ".sgn"
}

err = ioutil.WriteFile(outputFile, shellcodeResp.Data, 0o644)
err = os.WriteFile(outputFile, shellcodeResp.Data, 0o644)
if err != nil {
con.PrintErrorf("Failed to write shellcode file: %s", err)
return
Expand Down
3 changes: 1 addition & 2 deletions client/command/tasks/fetch.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ package tasks

import (
"context"
"io/ioutil"
"os"
"strings"
"time"
Expand Down Expand Up @@ -782,7 +781,7 @@ func promptSaveToFile(data []byte, con *console.SliverConsoleClient) {
return
}
}
err = ioutil.WriteFile(saveTo, data, 0o600)
err = os.WriteFile(saveTo, data, 0o600)
if err != nil {
con.PrintErrorf("Failed to save file: %s\n", err)
return
Expand Down
3 changes: 1 addition & 2 deletions client/command/update/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"crypto/tls"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
"net/url"
Expand Down Expand Up @@ -120,7 +119,7 @@ func UpdateCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []stri
lastCheck := []byte(fmt.Sprintf("%d", now.Unix()))
appDir := assets.GetRootAppDir()
lastUpdateCheckPath := path.Join(appDir, consts.LastUpdateCheckFileName)
err = ioutil.WriteFile(lastUpdateCheckPath, lastCheck, 0o600)
err = os.WriteFile(lastUpdateCheckPath, lastCheck, 0o600)
if err != nil {
con.Printf("Failed to save update check time %s", err)
}
Expand Down
4 changes: 2 additions & 2 deletions client/command/wireguard/wg-config.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ import (
"context"
"encoding/base64"
"encoding/hex"
"io/ioutil"
"net"
"os"
"strings"
"text/template"

Expand Down Expand Up @@ -95,7 +95,7 @@ func WGConfigCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []st
if !strings.HasSuffix(save, ".conf") {
save += ".conf"
}
err = ioutil.WriteFile(save, output.Bytes(), 0o600)
err = os.WriteFile(save, output.Bytes(), 0o600)
if err != nil {
con.PrintErrorf("Error: %s\n", err)
return
Expand Down
4 changes: 2 additions & 2 deletions client/prelude/bof.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
"bytes"
"context"
"errors"
"io/ioutil"
"os"
"path"

"github.com/bishopfox/sliver/client/assets"
Expand Down Expand Up @@ -139,7 +139,7 @@ func registerLoader(implant ActiveImplant, rpc rpcpb.SliverRPCClient) error {
coffLoaderPath = "COFFLoader.x86.dll"
}
loaderPath := path.Join(assets.GetExtensionsDir(), coffLoaderName, coffLoaderPath)
loaderData, err := ioutil.ReadFile(loaderPath)
loaderData, err := os.ReadFile(loaderPath)
if err != nil {
return err
}
Expand Down
4 changes: 2 additions & 2 deletions client/prelude/bridge.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"io/ioutil"
"io"
"net"
"net/http"
"strings"
Expand Down Expand Up @@ -161,7 +161,7 @@ func requestPayload(target string) ([]byte, error) {
if resp.StatusCode != 200 {
return nil, fmt.Errorf("invalid status code: %d", resp.StatusCode)
}
return ioutil.ReadAll(resp.Body)
return io.ReadAll(resp.Body)
}

func (a *OperatorImplantBridge) refreshBeacon() {
Expand Down
4 changes: 2 additions & 2 deletions client/version/updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package version
import (
"encoding/json"
"errors"
"io/ioutil"
"io"
"net/http"
"os"
"strconv"
Expand Down Expand Up @@ -77,7 +77,7 @@ func CheckForUpdates(client *http.Client, prereleases bool) (*Release, error) {
return nil, err
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
body, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions implant/sliver/forwarder/socks.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ package forwarder
// {{if .Config.WGc2Enabled}}
import (
"fmt"
"io/ioutil"
"io"
"log"
"net"

Expand Down Expand Up @@ -61,7 +61,7 @@ func (s *WGSocksServer) LocalAddr() string {
func (s *WGSocksServer) Start() error {
var err error
server := socks5.NewServer(
socks5.WithLogger(socks5.NewLogger(log.New(ioutil.Discard, "", log.LstdFlags))),
socks5.WithLogger(socks5.NewLogger(log.New(io.Discard, "", log.LstdFlags))),
)
select {
case <-s.done:
Expand Down
5 changes: 2 additions & 3 deletions implant/sliver/netstat/netstat_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"net"
"os"
"path"
Expand Down Expand Up @@ -212,7 +211,7 @@ func getProcName(s []byte) string {
func (p *procFd) iterFdDir() {
// link name is of the form socket:[5860846]
fddir := path.Join(p.base, "/fd")
fi, err := ioutil.ReadDir(fddir)
fi, err := os.ReadDir(fddir)
if err != nil {
return
}
Expand Down Expand Up @@ -252,7 +251,7 @@ func (p *procFd) iterFdDir() {

func extractProcInfo(sktab []SockTabEntry) {
var basedir = "/proc"
fi, err := ioutil.ReadDir(basedir)
fi, err := os.ReadDir(basedir)
if err != nil {
return
}
Expand Down
Loading
Loading