1
0

fix: 抓包sudo执行

This commit is contained in:
TsMask
2023-10-19 15:43:48 +08:00
parent 5c44f044d7
commit e24f619ef9

View File

@@ -64,7 +64,7 @@ func TcpdumpNeTask(w http.ResponseWriter, r *http.Request) {
filePcapName := fmt.Sprintf("tmp_%s_%s_%d.pcap", body.NeType, body.NeId, time.Now().UnixMilli()) filePcapName := fmt.Sprintf("tmp_%s_%s_%d.pcap", body.NeType, body.NeId, time.Now().UnixMilli())
fileLogName := fmt.Sprintf("tmp_%s_%s_%d.log", body.NeType, body.NeId, time.Now().UnixMilli()) fileLogName := fmt.Sprintf("tmp_%s_%s_%d.log", body.NeType, body.NeId, time.Now().UnixMilli())
writeLog := fmt.Sprintf(" >> %s 2>&1 \ncat %s", fileLogName, fileLogName) // 执行信息写入日志文件放置弹出code 127 writeLog := fmt.Sprintf(" >> %s 2>&1 \ncat %s", fileLogName, fileLogName) // 执行信息写入日志文件放置弹出code 127
cmdStr := fmt.Sprintf("cd /tmp \ntimeout %d tcpdump -i any %s -s0 -w %s", body.Timeout, body.Cmd, filePcapName) cmdStr := fmt.Sprintf("cd /tmp \n%stimeout %d tcpdump -i any %s -s0 -w %s", cmd.SudoHandleCmd(), body.Timeout, body.Cmd, filePcapName)
usernameNe := conf.Get("ne.user").(string) // 网元统一用户 usernameNe := conf.Get("ne.user").(string) // 网元统一用户
sshHost := fmt.Sprintf("%s@%s", usernameNe, neInfo.Ip) sshHost := fmt.Sprintf("%s@%s", usernameNe, neInfo.Ip)
msg, err := cmd.ExecWithCheck("ssh", sshHost, cmdStr+writeLog) msg, err := cmd.ExecWithCheck("ssh", sshHost, cmdStr+writeLog)